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

View on GitHub
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { spawnSync, type SpawnSyncReturns } from 'node:child_process';
import { chmodSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { verdictCommand } from './adopt.ts';
import { reflectionFiles } from './config.ts';
import { appendLedger, readLedger } from './ledger.ts';
import { appendRows, readLessons } from './lessons.ts';
import { git, writeJson } from './store.ts';
import { applyCloudResponse } from './cloud.ts';
import { fixtureConfig, makeStore, tmp } from './test-helpers.ts';

const NOW = new Date('2026-09-23T00:00:00Z');

function lesson(id: string, appliesTo: string, advice = `advice ${id}`): Record<string, unknown> {
  const situation = { task_type: 'debug', trigger: `trigger ${id}`, tools: [] };
  return { lesson_id: id, page_id: `pg-${id}`, status: 'candidate', count: 1, helped: 0, harmful: 0,
    measured: false, created_run: '20260923-0000', project_id: 'github.com/example/project', agent_id: 'codex', user_id: 'u',
    skill_target: null, scenario: situation, situation, advice, because: `because ${id}`, applies_to: appliesTo,
    polarity: 'from_failure', evidence: [], counter_examples: { searched: true, traces_checked: ['t.v1'], found: [] },
    listed: true, judgment_id: `j-${id}` };
}

function commandHarness(store: string): { run(args: string[]): SpawnSyncReturns<string>; bin: string } {
  const bin = tmp('adopt-bin');
  const sno = join(bin, 'sno');
  writeFileSync(sno, '#!/bin/sh\n[ "$*" = "station consent --json" ] && { echo \'{"consent":"off"}\'; exit 0; }\nexit 2\n');
  chmodSync(sno, 0o755);
  const entry = join(import.meta.dirname, 'rem-reflect.ts');
  return { bin, run: (args: string[]) => spawnSync(process.execPath, ['--experimental-strip-types', entry, ...args], {
    encoding: 'utf8', env: { ...process.env, PATH: `${bin}:${process.env.PATH ?? ''}`, REM_REFLECT_STORE: store },
  }) };
}

test('running with no arguments prints the usage and exits 0; an unknown command exits 2', () => {
  const harness = commandHarness(makeStore(fixtureConfig()));
  const bare = harness.run([]);
  assert.equal(bare.status, 0, bare.stderr);
  assert.match(bare.stdout, /Usage: sno rem-reflect/);
  assert.equal(harness.run(['nonsense']).status, 2);
});

test('verdict command refuses values outside accept, reject, and tbd', () => {
  const store = makeStore(fixtureConfig());
  const result = verdictCommand(store, 'Parked', '20260908-0000/codex');
  assert.equal(result.code, 2);
  assert.match(result.lines.join('\n'), /unknown verdict: Parked/);
});

test('verdict command names a proposal id that does not exist', () => {
  const store = makeStore(fixtureConfig());
  const result = verdictCommand(store, 'accept', '20260908-0000/codex');
  assert.equal(result.code, 1);
  assert.match(result.lines.join('\n'), /no such proposal/);
});

test('plain accept keeps project scope while --all-projects records a general lesson and promoted pending verdict', () => {
  const store = makeStore(fixtureConfig());
  appendRows(join(store, reflectionFiles.lessons), [
    lesson('L-project', 'project:github.com/example/project'),
    lesson('L-promoted', 'project:github.com/example/project'),
  ]);
  const { run } = commandHarness(store);

  const plain = run(['accept', 'L-project']);
  assert.equal(plain.status, 0, plain.stderr);
  const promoted = run(['accept', 'L-promoted', '--all-projects']);
  assert.equal(promoted.status, 0, promoted.stderr);

  const lessons = new Map(readLessons(store).map(row => [row.lesson_id, row]));
  const projectLesson = lessons.get('L-project');
  assert.ok(projectLesson, 'plain accept stores the lesson');
  assert.equal(projectLesson.status, 'accepted');
  assert.equal(projectLesson.applies_to, 'project:github.com/example/project');
  assert.equal(lessons.get('L-promoted')?.applies_to, 'general');
  const pending = readLedger(store).filter(row => row.type === 'cloud-verdict' && row.status === 'pending');
  const projectPending = pending.find(row => row.judgment_id === 'j-L-project');
  assert.ok(projectPending, 'plain accept stores the linked pending cloud verdict');
  assert.equal(projectPending.applies_to, undefined);
  assert.equal(pending.find(row => row.judgment_id === 'j-L-promoted')?.applies_to, 'general');
});

test('an accepted project lesson can be promoted once to all projects', () => {
  const store = makeStore(fixtureConfig());
  appendRows(join(store, reflectionFiles.lessons), [lesson('L-late-promotion', 'project:github.com/example/project')]);
  const { run } = commandHarness(store);

  const plain = run(['accept', 'L-late-promotion']);
  assert.equal(plain.status, 0, plain.stderr);
  const promoted = run(['accept', 'L-late-promotion', '--all-projects']);
  assert.equal(promoted.status, 0, promoted.stderr);
  assert.equal(readLessons(store).find(row => row.lesson_id === 'L-late-promotion')?.applies_to,
    'general');
  assert.equal(readLedger(store).some(row => row.type === 'cloud-verdict' && row.judgment_id === 'j-L-late-promotion'
    && row.applies_to === 'general'), true);
  const before = readFileSync(join(store, reflectionFiles.lessons), 'utf8');
  const ledgerBefore = readLedger(store);
  assert.equal(run(['accept', 'L-late-promotion', '--all-projects']).status, 0);
  assert.equal(readFileSync(join(store, reflectionFiles.lessons), 'utf8'), before);
  assert.deepEqual(readLedger(store), ledgerBefore);
});

test('plain accept of a skill lesson keeps it in its project without editing SKILL.md; promotion adopts it user-wide', () => {
  const config = fixtureConfig();
  const store = makeStore(config);
  const target = join(config.claude_home, 'skills', 'heartbeat');
  const copies = [config.claude_home, config.codex_home].map(home => join(home, 'skills', 'heartbeat', 'SKILL.md'));
  const before = copies.map(path => readFileSync(path, 'utf8'));
  appendRows(join(store, reflectionFiles.lessons), [
    lesson('L-skill-project', `skill:${target}`, 'project-only reminder'),
    lesson('L-skill-general', `skill:${target}`, 'all-project reminder'),
  ]);
  const { run } = commandHarness(store);

  const plain = run(['accept', 'L-skill-project']);
  assert.equal(plain.status, 0, plain.stderr);
  assert.deepEqual(copies.map(path => readFileSync(path, 'utf8')), before, 'plain accept does not edit either installed skill');
  assert.equal(readLessons(store).find(row => row.lesson_id === 'L-skill-project')?.applies_to, 'project:github.com/example/project');

  const promoted = run(['accept', 'L-skill-general', '--all-projects']);
  assert.equal(promoted.status, 0, promoted.stderr);
  for (const path of copies) assert.match(readFileSync(path, 'utf8'), /all-project reminder/);
  assert.equal(readLessons(store).find(row => row.lesson_id === 'L-skill-general')?.applies_to, 'general');
});

test('--all-projects is refused for reject, tbd, and proposal ids without appending a row', () => {
  const store = makeStore(fixtureConfig());
  appendRows(join(store, reflectionFiles.lessons), [lesson('L-reject', 'project:p'), lesson('L-tbd', 'project:p')]);
  appendLedger(store, { type: 'proposal', proposal_id: '20260923-0000/codex', run_id: '20260923-0000', half: 'codex',
    kind: 'no_action', target: null, region: null, purpose: { summary: 'none', page_ids: [] }, verdict: 'pending' });
  const { run } = commandHarness(store);
  for (const args of [
    ['reject', 'L-reject', '--all-projects'],
    ['tbd', 'L-tbd', '--all-projects'],
    ['accept', '20260923-0000/codex', '--all-projects'],
  ]) {
    const lessonsBefore = readFileSync(join(store, reflectionFiles.lessons), 'utf8');
    const ledgerBefore = readFileSync(join(store, reflectionFiles.ledger), 'utf8');
    const result = run(args);
    assert.notEqual(result.status, 0);
    assert.match(result.stderr, /--all-projects.*only.*lesson.*accept|--all-projects.*lesson.*accept.*only/i);
    assert.equal(readFileSync(join(store, reflectionFiles.lessons), 'utf8'), lessonsBefore);
    assert.equal(readFileSync(join(store, reflectionFiles.ledger), 'utf8'), ledgerBefore);
  }
});

test('a lesson verdict and second run ignore a legacy global lock while run.lock still blocks the second run', () => {
  const store = makeStore(fixtureConfig());
  appendRows(join(store, reflectionFiles.lessons), [lesson('L-during-run', 'project:github.com/example/project')]);
  const holder = { pid: process.pid, command: 'run', id: '20260923-0000' };
  writeFileSync(join(store, 'run.lock'), `${JSON.stringify(holder)}\n`);
  const legacy = `${JSON.stringify({ pid: process.pid, command: 'legacy-global', id: 'legacy-holder' })}\n`;
  writeFileSync(join(store, '.lock'), legacy);
  const { run } = commandHarness(store);

  const accepted = run(['accept', 'L-during-run']);
  assert.equal(accepted.status, 0, accepted.stderr);
  assert.equal(readLessons(store).find(row => row.lesson_id === 'L-during-run')?.status, 'accepted');
  assert.equal(readFileSync(join(store, '.lock'), 'utf8'), legacy, 'accept ignores and preserves the legacy lock bytes');

  const second = run(['run', '--now', '2026-09-23T01:00:00Z']);
  assert.equal(second.status, 0, second.stderr);
  assert.match(second.stdout, /lock held by run 20260923-0000/);
  assert.equal(readFileSync(join(store, '.lock'), 'utf8'), legacy, 'run ignores and preserves the legacy lock bytes');
});

test('ordinary accept succeeds and leaves appended rows for the next commit when git is busy', () => {
  const store = makeStore(fixtureConfig());
  appendRows(join(store, reflectionFiles.lessons), [lesson('L-git-busy', 'project:github.com/example/project')]);
  const before = git(store, ['rev-parse', 'HEAD']).trim();
  const indexLock = join(store, '.git', 'index.lock');
  writeFileSync(indexLock, 'held by fixture\n');
  const { run } = commandHarness(store);

  try {
    const started = Date.now();
    const accepted = run(['accept', 'L-git-busy']);
    assert.equal(accepted.status, 0, accepted.stderr);
    assert.ok(Date.now() - started < 2000, 'accept returns promptly while git is busy');
    assert.equal(readLessons(store).find(row => row.lesson_id === 'L-git-busy')?.status, 'accepted');
    assert.ok(readLedger(store).some(row => row.type === 'cloud-verdict' && row.judgment_id === 'j-L-git-busy'
      && row.status === 'pending'));
    assert.equal(git(store, ['rev-parse', 'HEAD']).trim(), before, 'accept does not require or claim a new commit');
  } finally {
    unlinkSync(indexLock);
  }
});

test('plain accept keeps a user-wide lesson user-wide, --this-project moves it to its project, and an agent scope becomes the project', () => {
  const store = makeStore(fixtureConfig());
  appendRows(join(store, reflectionFiles.lessons), [lesson('L-user-wide', 'general'), lesson('L-moved', 'general'),
    lesson('L-old-agent', 'agent:codex')]);
  const { run } = commandHarness(store);
  const scopeAfter = (args: string[]): string | undefined => {
    const result = run(args);
    assert.equal(result.status, 0, result.stderr);
    return readLessons(store).find(row => row.lesson_id === args[1])?.applies_to;
  };
  assert.equal(scopeAfter(['accept', 'L-user-wide']), 'general');
  assert.equal(scopeAfter(['accept', 'L-moved', '--this-project']), 'project:github.com/example/project');
  assert.equal(scopeAfter(['accept', 'L-old-agent']), 'project:github.com/example/project');
  assert.equal(run(['reject', 'L-user-wide', '--this-project']).status, 2);
});

test('replaying an older cloud answer does not undo an accepted lesson or its promotion', () => {
  const config = fixtureConfig();
  const store = makeStore(config);
  const decided = { ...lesson('L-decided', 'general'), status: 'accepted', judgment_id: 'j-new' };
  appendRows(join(store, reflectionFiles.lessons), [decided]);
  const response = { schema_version: 1 as const, run_id: '20260921-0100', history_acknowledged: true, history_links: [],
    halves: [{ harness: 'codex', attention: [], pages: [], proposals: [], read_judgments: [], log_entry: 'old',
      lessons: [{ judgment_id: 'j-old', lesson: lesson('L-decided', 'project:github.com/example/project') }] }] };
  writeJson(join(store, 'staging', response.run_id, 'cloud-request.json'), {
    schema_version: 1, run_id: response.run_id, halves: [], catalogue: [], usage_reads: [], outcome_summary: {} });
  applyCloudResponse(store, config, response as never);
  const latest = readLessons(store).filter(row => row.lesson_id === 'L-decided').pop();
  assert.equal(latest?.status, 'accepted');
  assert.equal(latest?.applies_to, 'general');
});

test('accepting a lesson known to the cloud only through a history link sends its verdict', () => {
  const store = makeStore(fixtureConfig());
  const old = lesson('L-history', 'project:github.com/example/project');
  delete old.judgment_id;
  appendRows(join(store, reflectionFiles.lessons), [old]);
  appendLedger(store, { type: 'cloud-link', kind: 'lesson', local_id: 'L-history', judgment_id: 'j-history' });
  const { run } = commandHarness(store);
  const result = run(['accept', 'L-history', '--all-projects']);
  assert.equal(result.status, 0, result.stderr);
  const pending = readLedger(store).filter(row => row.type === 'cloud-verdict' && row.judgment_id === 'j-history');
  assert.equal(pending.length, 1);
  assert.equal(pending[0].applies_to, 'general');
});
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