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/first-message.test.ts

View on GitHub
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
import { chmodSync, mkdirSync, rmSync, readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { appendRows } from './lessons.ts';
import { firstMessageRecall } from './recall.ts';
import { verdictCommand } from './adopt.ts';
import { git } from './store.ts';
import { fixtureCheckout, fixtureConfig, makeStore, tmp } from './test-helpers.ts';

test('first owner message returns ranked context once and logs a later network failure without stdout', () => {
  const checkout = fixtureCheckout();
  const store = makeStore(fixtureConfig());
  appendRows(join(store, 'wiki/lessons.jsonl'), [{ lesson_id: 'L-1', status: 'candidate', listed: true, verification: { accepted: true }, applies_to: 'general',
    situation: { task_type: 'fix', trigger: 'broken build', tools: [] }, advice: 'read the compiler error' }]);
  git(store, ['add', '--all']);
  git(store, ['commit', '--quiet', '-m', 'lesson']);
  const bin = tmp('recall-bin');
  const executable = join(bin, 'sno');
  const requests = join(bin, 'requests.jsonl');
  writeFileSync(executable, '#!/usr/bin/env node\nconst fs=require("node:fs");\nif(process.argv.slice(2).join(" ")==="station consent --json"){console.log(JSON.stringify({consent:"full"}));process.exit(0);}\nfs.appendFileSync(process.env.RECALL_REQUESTS, fs.readFileSync(0,"utf8")+"\\n");\nif(process.env.RECALL_FAIL==="1") process.exit(7);\nif(process.env.RECALL_FAIL==="timeout") setTimeout(()=>{},1000); else console.log(JSON.stringify({lesson_ids:["L-1"]}));\n');
  chmodSync(executable, 0o755);
  const command = fileURLToPath(new URL('./rem-reflect.ts', import.meta.url));
  const run = (session: string, fail = '') => spawnSync(process.execPath,
    [command, 'recall', '--agent', 'codex', '--first-message'], {
      input: JSON.stringify({ session_id: session, cwd: checkout, prompt: 'broken build' }), encoding: 'utf8',
      env: { ...process.env, REM_REFLECT_STORE: store, RECALL_REQUESTS: requests,
        RECALL_FAIL: fail, PATH: `${bin}:${process.env.PATH ?? ''}` },
    });
  const first = run('session-1');
  assert.equal(first.status, 0);
  const output = JSON.parse(first.stdout).hookSpecificOutput;
  assert.equal(output.hookEventName, 'UserPromptSubmit');
  assert.match(output.additionalContext, /L-1:/);
  assert.match(output.additionalContext, /read the compiler error/);
  assert.deepEqual(JSON.parse(readFileSync(requests, 'utf8').trim()), { project_id: 'github.com/example/project',
    message: 'broken build', lessons: [{ lesson_id: 'L-1', situation: { task_type: 'fix', trigger: 'broken build', tools: [] },
      advice: 'read the compiler error' }] });
  const again = run('session-1');
  assert.equal(again.stdout, '');
  assert.equal(readFileSync(requests, 'utf8').trim().split('\n').length, 1);
  const failed = run('session-2', '1');
  assert.equal(failed.status, 0);
  assert.equal(failed.stdout, '');
  assert.match(readFileSync(join(store, 'ledger/usage.jsonl'), 'utf8'), /"type":"first-message-recall-failed","session_id":"session-2"/);
  writeFileSync(join(store, 'settings.local.json'), JSON.stringify({ version: 'test', labeler_input_max_chars: 120000,
    labeler_event_window_lines: 60, recall_timeout_ms: 30 }));
  const timedOut = run('session-3', 'timeout');
  assert.equal(timedOut.status, 0);
  assert.equal(timedOut.stdout, '');
  assert.match(readFileSync(join(store, 'ledger/usage.jsonl'), 'utf8'), /"type":"first-message-recall-failed","session_id":"session-3"/);
});

test('first-message recall sends only recallable lessons and records the selected ones as shown', () => {
  const checkout = fixtureCheckout();
  const store = makeStore(fixtureConfig());
  const base = { situation: { task_type: 'batch', trigger: 'duplicate keys', tools: [] }, advice: 'check key uniqueness first' };
  appendRows(join(store, 'wiki/lessons.jsonl'), [
    { ...base, lesson_id: 'L-verified', status: 'candidate', listed: true, verification: { accepted: true }, applies_to: 'general' },
    { ...base, lesson_id: 'L-unverified', status: 'candidate', listed: true, applies_to: 'general' },
  ]);
  git(store, ['add', '--all']);
  git(store, ['commit', '--quiet', '-m', 'lessons']);
  const bin = tmp('recall-echo-bin');
  const requests = join(bin, 'requests.jsonl');
  // The substitute for the cloud recall selects every lesson it is sent.
  writeFileSync(join(bin, 'sno'), '#!/usr/bin/env node\nconst fs=require("node:fs");\nif(process.argv.slice(2).join(" ")==="station consent --json"){console.log(JSON.stringify({consent:"full"}));process.exit(0);}\nconst r=JSON.parse(fs.readFileSync(0,"utf8"));\nfs.appendFileSync(process.env.RECALL_REQUESTS, JSON.stringify(r)+"\\n");\nconsole.log(JSON.stringify({lesson_ids:r.lessons.map(l=>l.lesson_id)}));\n');
  chmodSync(join(bin, 'sno'), 0o755);
  const result = spawnSync(process.execPath, [fileURLToPath(new URL('./rem-reflect.ts', import.meta.url)), 'recall', '--agent', 'codex', '--first-message'], {
    input: JSON.stringify({ session_id: 'session-9', cwd: checkout, prompt: 'run the batch' }), encoding: 'utf8',
    env: { ...process.env, REM_REFLECT_STORE: store, RECALL_REQUESTS: requests, PATH: `${bin}:${process.env.PATH ?? ''}` },
  });
  assert.equal(result.status, 0, result.stderr);
  assert.deepEqual(JSON.parse(readFileSync(requests, 'utf8').trim()).lessons.map((l: { lesson_id: string }) => l.lesson_id), ['L-verified']);
  const shown = readFileSync(join(store, 'ledger/usage.jsonl'), 'utf8').trim().split('\n').map(line => JSON.parse(line))
    .filter(row => row.type === 'shown');
  assert.deepEqual(shown.map(row => [row.session_id, row.lesson_ids]), [['session-9', ['L-verified']]]);
});


test('local approval reaches the next prompt after first-message recall and reappears after compact', () => {
  const checkout = fixtureCheckout();
  const store = makeStore(fixtureConfig());
  const base = { situation: { task_type: 'fix', trigger: 'write an answer', tools: [] },
    advice: 'write the answer in decimal', expected_result: 'a decimal output', success_criteria: 'result is decimal',
    project_id: 'github.com/example/project', listed: true, count: 2, created_run: '20261103', helped: 0, harmful: 0 };
  appendRows(join(store, 'wiki/lessons.jsonl'), [
    { ...base, lesson_id: 'L-local', status: 'candidate', applies_to: 'general' },
    { ...base, lesson_id: 'L-foreign', status: 'accepted', applies_to: 'project:other' },
    { ...base, lesson_id: 'L-verified-only', status: 'candidate', applies_to: 'general', verification: { accepted: true } },
  ]);
  git(store, ['add', 'wiki/lessons.jsonl']);
  git(store, ['commit', '--quiet', '-m', 'candidate']);
  const input = { session_id: 'already-running', cwd: checkout, prompt: 'continue' };
  // The ordinary first-message selection already ran while the lesson was a candidate.
  writeFileSync(join(store, 'ledger/usage.jsonl'), JSON.stringify({ type: 'first-message-recall', session_id: input.session_id }) + '\n'
    + JSON.stringify({ type: 'shown', session_id: input.session_id, lesson_ids: ['L-local'] }) + '\n');
  assert.equal(verdictCommand(store, 'accept', 'L-local').code, 0);
  const next = firstMessageRecall(store, 'codex', input);
  const context = JSON.parse(next.lines.join('\n')).hookSpecificOutput.additionalContext;
  assert.match(context, /write the answer in decimal/);
  assert.match(context, /a decimal output/);
  assert.doesNotMatch(context, /L-foreign|L-verified-only/);
  assert.deepEqual(firstMessageRecall(store, 'codex', input).lines, [], 'the same approval is not composed again');
  const compact = firstMessageRecall(store, 'codex', { ...input, prompt: undefined, hook_event_name: 'PostCompact' });
  assert.match(JSON.parse(compact.lines.join('\n')).hookSpecificOutput.additionalContext, /write the answer in decimal/);
  assert.deepEqual(firstMessageRecall(store, 'codex', input).lines, [], 'postcompact delivery is not duplicated by next prompt');
  assert.equal(verdictCommand(store, 'reject', 'L-local').code, 0);
  assert.doesNotMatch(firstMessageRecall(store, 'codex', { ...input, hook_event_name: 'PostCompact' }).lines.join('\n'), /L-local/, 'a rejected lesson is not restored');
  assert.equal(verdictCommand(store, 'accept', 'L-local', new Date(), false, true).code, 0);
  assert.match(firstMessageRecall(store, 'codex', input).lines.join('\n'), /write the answer in decimal/);
  // A broken usage destination must not turn the auxiliary failure into lost context.
  rmSync(join(store, 'ledger/usage.jsonl'));
  mkdirSync(join(store, 'ledger/usage.jsonl'));
  const unmeasured = firstMessageRecall(store, 'codex', { ...input, hook_event_name: 'PostCompact' });
  assert.match(unmeasured.lines.join('\n'), /write the answer in decimal/);
  assert.match(unmeasured.stderr?.join('\n') ?? '', /usage/);
});

test('a compaction restart through the plain SessionStart hook resends every recallable lesson', () => {
  const checkout = fixtureCheckout();
  const store = makeStore(fixtureConfig());
  const ids = Array.from({ length: 11 }, (_, i) => `L-${i}`);
  appendRows(join(store, 'wiki/lessons.jsonl'), ids.map(id => ({ lesson_id: id, status: 'accepted', listed: true, applies_to: 'general',
    situation: { task_type: 'fix', trigger: `trigger ${id}`, tools: [] }, advice: `advice for ${id}` })));
  appendRows(join(store, 'wiki/lessons.jsonl'), [{ lesson_id: 'L-verified', status: 'candidate', listed: true, verification: { accepted: true },
    applies_to: 'general', situation: { task_type: 'fix', trigger: 'trigger verified', tools: [] }, advice: 'advice for L-verified' }]);
  ids.push('L-verified');
  git(store, ['add', '--all']);
  git(store, ['commit', '--quiet', '-m', 'lessons']);
  writeFileSync(join(store, 'ledger/usage.jsonl'), JSON.stringify({ type: 'first-message-recall', session_id: 'compacted' }) + '\n'
    + JSON.stringify({ type: 'shown', session_id: 'compacted', lesson_ids: ids }) + '\n');
  const result = spawnSync(process.execPath, [fileURLToPath(new URL('./rem-reflect.ts', import.meta.url)), 'recall', '--agent', 'claude-code'], {
    input: JSON.stringify({ session_id: 'compacted', cwd: checkout, hook_event_name: 'SessionStart', source: 'compact' }), encoding: 'utf8',
    env: { ...process.env, REM_REFLECT_STORE: store },
  });
  assert.equal(result.status, 0, result.stderr);
  for (const id of ids) assert.match(result.stdout, new RegExp(`advice for ${id}\\b`));
});
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