Skip to content

sno-ai/sno-station-skills / skills/R-recursive-self-improvement/rem-reflect/skill

rem-reflect

Verified

Self Learning from this machine's Claude Code, Codex, Hermes, OpenClaw and Cursor sessions. Decide skill changes and lessons with accept/reject/tbd; recall lessons at session start.

FileKindSize
SKILL.mdskill md14.1 KB
references/labeler.mdmarkdown1.2 KB
references/labeler.schema.jsonconfig1.7 KB
references/local-settings.jsonconfig126 B
references/local-writer.schema.jsonconfig2.3 KB
references/proposal.schema.jsonconfig3.2 KB
references/render.jsonconfig245 B
references/signals.jsonconfig71 B
references/text.jsonconfig4.0 KB
scripts/adopt.test.tsscript13.0 KB
scripts/adopt.tsscript14.3 KB
scripts/agent-sessions.tsscript9.1 KB
scripts/allowance-fallback.test.tsscript16.0 KB
scripts/allowance-request-isolation.test.tsscript7.1 KB
scripts/backend.tsscript9.1 KB
scripts/calls.tsscript8.6 KB
scripts/catalogue-cloud.test.tsscript1.5 KB
scripts/catalogue.tsscript3.2 KB
scripts/chunk.tsscript2.1 KB
scripts/cloud-apply.test.tsscript25.2 KB
scripts/cloud-batch.test.tsscript11.2 KB
scripts/cloud-day.test.tsscript6.8 KB
scripts/cloud-verdict.test.tsscript12.1 KB
scripts/cloud-wait.test.tsscript1.3 KB
scripts/cloud.tsscript24.4 KB
scripts/config.tsscript8.1 KB
scripts/cursor.test.tsscript16.1 KB
scripts/cursor.tsscript6.7 KB
scripts/evidence.tsscript1.5 KB
scripts/first-message.test.tsscript10.3 KB
scripts/harvest.test.tsscript16.5 KB
scripts/harvest.tsscript22.6 KB
scripts/hermes-openclaw.test.tsscript25.6 KB
scripts/identity.test.tsscript3.3 KB
scripts/identity.tsscript3.5 KB
scripts/installed-roots.test.tsscript11.0 KB
scripts/journey-adopt-lesson.test.tsscript4.1 KB
scripts/journey-ops.test.tsscript8.0 KB
scripts/labeler.test.tsscript3.6 KB
scripts/labeler.tsscript9.5 KB
scripts/ledger.tsscript2.1 KB
scripts/lessons.tsscript4.7 KB
scripts/local-filter.test.tsscript3.9 KB
scripts/local-first-output.test.tsscript22.1 KB
scripts/local-settings.tsscript1.4 KB
scripts/local-writer.tsscript12.6 KB
scripts/login-in-place.test.tsscript5.8 KB
scripts/model-json.tsscript4.1 KB
scripts/no-network.test.tsscript5.0 KB
scripts/observe.tsscript1.4 KB
scripts/page-journey.test.tsscript6.7 KB
scripts/pages.test.tsscript4.1 KB
scripts/pages.tsscript4.8 KB
scripts/proposer-loop.test.tsscript1.5 KB
scripts/proposer-validate.test.tsscript9.1 KB
scripts/proposer.tsscript8.7 KB
scripts/recall-hook.test.tsscript20.9 KB
scripts/recall.test.tsscript31.4 KB
scripts/recall.tsscript18.2 KB
scripts/reflect.test.tsscript9.3 KB
scripts/reflect.tsscript14.3 KB
scripts/rem-reflectexecutablescript823 B
scripts/rem-reflect.tsscript17.8 KB
scripts/render-chunk.test.tsscript7.2 KB
scripts/render.tsscript9.7 KB
scripts/report.tsscript8.2 KB
scripts/run-status.test.tsscript19.1 KB
scripts/sampling.test.tsscript2.1 KB
scripts/sampling.tsscript915 B
scripts/selftest-guard.test.tsscript4.2 KB
scripts/selftest/bin/claudeexecutablescript94 B
scripts/selftest/bin/codexexecutablescript93 B
scripts/selftest/bin/shim-core.cjsscript4.6 KB
scripts/selftest/bin/snoexecutablescript5.7 KB
scripts/selftest/fixtures/hermes-session-export.jsonlother1.5 KB
scripts/selftest/fixtures/openclaw-events.jsonlother3.7 KB
scripts/selftest/fixtures/verdict-traces.jsonconfig16.6 KB
scripts/selftest/journey-e2e.shexecutablescript1.4 KB
scripts/selftest/journey.mjsscript9.5 KB
scripts/selftest/observe-journey.mjsscript12.5 KB
scripts/selftest/run-selftest.shexecutablescript7.0 KB
scripts/selftest/spawn-python.mjsexecutablescript765 B
scripts/session.test.tsscript5.2 KB
scripts/session.tsscript251 B
scripts/signal-local.test.tsscript7.0 KB
scripts/skill-impact.test.tsscript6.2 KB
scripts/station-settings.test.tsscript13.6 KB
scripts/store-memory.test.tsscript3.4 KB
scripts/store.tsscript7.7 KB
scripts/test-helpers.tsscript15.3 KB
scripts/text.tsscript760 B
scripts/trigger.test.tsscript3.6 KB
scripts/trigger.tsscript2.5 KB
scripts/verdicts.test.tsscript8.1 KB
scripts/verdicts.tsscript8.0 KB

scripts/cloud-batch.test.ts

View on GitHub
import { test } from 'node:test';
import { saveLocalSettings } from './local-settings.ts';
import assert from 'node:assert/strict';
import { chmodSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { buildCloudBatch, sendCloudBatch } from './cloud.ts';
import { chunkRendering } from './chunk.ts';
import { appendLedger } from './ledger.ts';
import type { Trace, StoredRecord } from './harvest.ts';
import { renderTrace, loadRenderBudgets } from './render.ts';
import { fixtureConfig, makeStore, tmp, writeInstalledSkill } from './test-helpers.ts';
import { fileURLToPath } from 'node:url';

function trace(session: string): Trace {
  const records: StoredRecord[] = [2, 3, 4, 5, 6].map((line, index) => ({
    line_number: line, source_line: line,
    record: { type: 'response_item', payload: { type: 'message', role: 'assistant', content: [{ type: 'output_text', text: `${session}-${index}-` + 'x'.repeat(15_000) }] } },
  }));
  return {
    user_id: 'local-u', project_id: 'p', agent_id: 'codex', source_harness: 'codex', originator: 'codex',
    trace_id: `${session}.v1`, session_id: session, version: 1, source_path: '/source', source_line_range: [1, 6],
    source_mtime: Date.parse('2026-09-21T00:00:00Z'), records, skipped_records: 0, skipped_blocks: 0,
    redactions: 0, trivial: false, skills_loaded: [],
  };
}

test('cloud batch sends every retained chunk, complete installed skill bodies, and only relevant actual reads', () => {
  const config = fixtureConfig();
  const first = writeInstalledSkill(config.claude_home, 'batch-first', 'FIRST-BODY-' + 'a'.repeat(1200));
  const second = writeInstalledSkill(config.codex_home, 'batch-second', 'SECOND-BODY-' + 'b'.repeat(1300));
  const store = makeStore(config);
  const retained = [trace('kept-a'), trace('kept-b')];
  const usage = join(store, 'ledger', 'usage.jsonl');
  mkdirSync(join(store, 'ledger'), { recursive: true });
  writeFileSync(usage, [
    { type: 'shown', session_id: 'kept-a', lesson_ids: ['L-a', 'L-b'] },
    { type: 'shown', session_id: 'kept-a', agent_id: 'codex', lesson_ids: ['L-b', 'L-c'] },
    { type: 'shown', session_id: 'kept-b', lesson_ids: [] },
    { type: 'shown', session_id: 'not-uploaded', lesson_ids: ['L-x'] },
    { type: 'read', session_id: 'kept-a', lesson_id: 'L-used' },
    { type: 'read', session_id: 'not-uploaded', lesson_id: 'L-irrelevant' },
  ].map(row => JSON.stringify(row)).join('\n') + '\n');
  const labels = new Map(retained.map(row => [`local-u/codex/${row.trace_id}`, {
    decision: 'keep' as const, outcome: 'fail' as const, reason: 'the task failed',
    evidence: [], key_ranges: [], labeled_by: 'codex', model: 'local-model',
  }]));

  const batch = buildCloudBatch(store, config, '20260921-0100', retained, labels, false);

  assert.equal(batch.halves.length, 1);
  assert.deepEqual(batch.halves[0].sessions.map(row => row.trace_id), retained.map(row => row.trace_id));
  for (const [index, row] of batch.halves[0].sessions.entries()) {
    const expected = chunkRendering(retained[index].trace_id, renderTrace(retained[index], loadRenderBudgets()));
    assert.ok(expected.length > 1, 'this fixture really exercises multi-chunk upload');
    assert.deepEqual(row.chunks.map(chunk => chunk.text), expected.map(chunk => chunk.text));
    assert.equal(row.local_outcome, 'fail');
    assert.equal(row.local_reason, 'the task failed');
  }
  const byPath = new Map(batch.catalogue.map(item => [item.path, item]));
  assert.match(byPath.get(join(first, 'SKILL.md'))?.skill_md ?? '', /FIRST-BODY-a{1200}/);
  assert.match(byPath.get(join(second, 'SKILL.md'))?.skill_md ?? '', /SECOND-BODY-b{1300}/);
  assert.equal(byPath.get(join(first, 'SKILL.md'))?.skill_md, readFileSync(join(first, 'SKILL.md'), 'utf8'));
  assert.deepEqual(batch.halves[0].sessions.map(row => row.external_verdicts), [[], []], 'a session without calls uploads no verdicts');
  assert.deepEqual(batch.usage_reads, [{ session_id: 'kept-a', lesson_id: 'L-used' }]);
  assert.deepEqual(batch.usage_shown, [{ session_id: 'kept-a', lesson_ids: ['L-a', 'L-b', 'L-c'] }]);
  assert.equal('history' in batch, false);

  appendLedger(store, { type: 'proposal', proposal_id: 'old-proposal', verdict: 'pending' });
  appendLedger(store, { type: 'verdict', proposal_id: 'old-proposal', verdict: 'Rejected' });
  const firstBatch = buildCloudBatch(store, config, '20260921-0100', retained, labels, true);
  assert.deepEqual(firstBatch.history?.proposals.map(row => row.proposal_id), ['old-proposal']);
  assert.deepEqual(firstBatch.history?.skill_impact_rows.map(row => row.verdict), ['Rejected']);
});

test('a lost cloud answer leaves the exact batch for the next entry to replay under its original id', t => {
  const config = fixtureConfig();
  const store = makeStore(config);
  const bin = tmp('sno-bin');
  const capture = join(bin, 'requests.jsonl');
  const executable = join(bin, 'sno');
  writeFileSync(executable, [
    '#!/usr/bin/env node',
    "const fs = require('node:fs');",
    "const raw = fs.readFileSync(0, 'utf8');",
    "const path = process.env.REM_REQUEST_CAPTURE;",
    "const first = !fs.existsSync(path);",
    "fs.appendFileSync(path, JSON.stringify(raw) + '\\n');",
    "if (first) { console.error('response lost'); process.exit(1); }",
    "const batch = JSON.parse(raw);",
    "console.log(JSON.stringify({schema_version:1,run_id:batch.run_id,history_acknowledged:true,history_links:[],halves:[],settings_version:'v1',local:{labeler_input_max_chars:120000,labeler_event_window_lines:60,recall_timeout_ms:5000}}));",
  ].join('\n') + '\n');
  chmodSync(executable, 0o755);
  const oldPath = process.env.PATH;
  const oldCapture = process.env.REM_REQUEST_CAPTURE;
  process.env.PATH = `${bin}:${oldPath ?? ''}`;
  process.env.REM_REQUEST_CAPTURE = capture;
  t.after(() => {
    if (oldPath === undefined) delete process.env.PATH; else process.env.PATH = oldPath;
    if (oldCapture === undefined) delete process.env.REM_REQUEST_CAPTURE; else process.env.REM_REQUEST_CAPTURE = oldCapture;
  });

  const firstBatch = { schema_version: 1, run_id: '20260921-0100', halves: [], catalogue: [], usage_reads: [], usage_shown: [], outcome_summary: {} };
  assert.throws(() => sendCloudBatch(store, firstBatch), /response lost/);
  const replacement = { ...firstBatch, run_id: '20260921-0300', outcome_summary: { changed: true } };
  const response = sendCloudBatch(store, replacement);
  assert.equal(response.run_id, firstBatch.run_id);
  saveLocalSettings(store, response);
  assert.deepEqual(JSON.parse(readFileSync(join(store, 'settings.local.json'), 'utf8')),
    { version: 'v1', labeler_input_max_chars: 120000, labeler_event_window_lines: 60, recall_timeout_ms: 5000 });
  const requests = readFileSync(capture, 'utf8').trim().split('\n').map(row => JSON.parse(row) as string);
  assert.equal(requests.length, 2);
  assert.equal(requests[1], requests[0], 'the complete stdin bytes, not a rebuilt batch, are replayed');
});

test('a request holding half of an emoji reaches sno as well-formed JSON text', t => {
  const config = fixtureConfig();
  const store = makeStore(config);
  const bin = tmp('sno-bin');
  const capture = join(bin, 'stdin.txt');
  const executable = join(bin, 'sno');
  writeFileSync(executable, [
    '#!/usr/bin/env node',
    "const fs = require('node:fs');",
    "const raw = fs.readFileSync(0, 'utf8');",
    "fs.writeFileSync(process.env.REM_REQUEST_CAPTURE, raw);",
    "const batch = JSON.parse(raw);",
    "console.log(JSON.stringify({schema_version:1,run_id:batch.run_id,history_acknowledged:true,history_links:[],halves:[]}));",
  ].join('\n') + '\n');
  chmodSync(executable, 0o755);
  const oldPath = process.env.PATH;
  const oldCapture = process.env.REM_REQUEST_CAPTURE;
  process.env.PATH = `${bin}:${oldPath ?? ''}`;
  process.env.REM_REQUEST_CAPTURE = capture;
  t.after(() => {
    if (oldPath === undefined) delete process.env.PATH; else process.env.PATH = oldPath;
    if (oldCapture === undefined) delete process.env.REM_REQUEST_CAPTURE; else process.env.REM_REQUEST_CAPTURE = oldCapture;
  });
  const batch = { schema_version: 1, run_id: '20260923-0000', halves: [{ text: 'React with \ud83d[… 12 characters omitted …]' }, { signature: 'patch\0skills/peer-review/skill' }],
    catalogue: [], usage_reads: [], usage_shown: [], outcome_summary: {} };
  sendCloudBatch(store, batch);
  assert.doesNotMatch(readFileSync(capture, 'utf8'), /\\u[dD][89abAB][0-9a-fA-F]{2}(?!\\u[dD][c-fC-F])/);
  // the cloud's JSON column refuses NUL, which older proposal signatures and some session text carry
  assert.doesNotMatch(readFileSync(capture, 'utf8'), /\\u0000/);
});

test('an answered batch keeps only what later nights read, so the store does not grow by the session text every night', t => {
  // Each night's request kept every uploaded session's text after the cloud answered it (up to ~29 MB a night, never removed).
  const config = fixtureConfig();
  const store = makeStore(config);
  const bin = tmp('sno-bin');
  const executable = join(bin, 'sno');
  writeFileSync(executable, [
    '#!/usr/bin/env node',
    "const batch = JSON.parse(require('node:fs').readFileSync(0, 'utf8'));",
    "console.log(JSON.stringify({schema_version:1,run_id:batch.run_id,history_acknowledged:true,history_links:[],halves:[],settings_version:'v1',local:{labeler_input_max_chars:120000,labeler_event_window_lines:60,recall_timeout_ms:5000}}));",
  ].join('\n') + '\n');
  chmodSync(executable, 0o755);
  const oldPath = process.env.PATH;
  process.env.PATH = `${bin}:${oldPath ?? ''}`;
  t.after(() => { if (oldPath === undefined) delete process.env.PATH; else process.env.PATH = oldPath; });
  const catalogue = [{ name: 'heartbeat', path: 'claude/heartbeat/SKILL.md', skill_md: 'name: heartbeat' }];
  const batch = { schema_version: 1, run_id: '20260921-0100', catalogue, usage_reads: [], usage_shown: [], outcome_summary: {},
    halves: [{ harness: 'codex', sessions: [{ session_id: 's1', version: 2, chunks: [{ text: 'secret session text '.repeat(1000) }] }] }] };
  sendCloudBatch(store, batch);
  const saved = readFileSync(join(store, 'staging', '20260921-0100', 'cloud-request.json'), 'utf8');
  assert.doesNotMatch(saved, /secret session text/);
  assert.deepEqual(JSON.parse(saved), { schema_version: 1, run_id: '20260921-0100', catalogue,
    halves: [{ harness: 'codex', sessions: [{ session_id: 's1', version: 2 }] }] });
});

test('the upload carries the code-computed verdicts of a real session beside its calls', () => {
  const config = fixtureConfig();
  const store = makeStore(config);
  const fixtures = JSON.parse(readFileSync(fileURLToPath(new URL('./selftest/fixtures/verdict-traces.json', import.meta.url)), 'utf8')) as Record<string, Trace>;
  const real = fixtures.claude_vitest;
  const labels = new Map([[`${real.user_id}/claude-code/${real.trace_id}`, { decision: 'keep' as const, outcome: 'success' as const, reason: 'tests pass',
    evidence: [], key_ranges: [], labeled_by: 'claude', model: 'local-model' }]]);
  const session = buildCloudBatch(store, config, '20261022-0100', [real], labels, false).halves[0].sessions[0];
  assert.deepEqual(session.external_verdicts.map(item => [item.line, item.kind, item.passed]), [[184, 'test', false], [202, 'test', true]]);
  assert.match(session.external_verdicts[1].command, /npx vitest run/);
  assert.equal(session.calls.length, 2);
});
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexUnverifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall