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.tsscript23.5 KB
scripts/local-settings.tsscript1.4 KB
scripts/local-writer.tsscript12.7 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/selftest/observe-journey.mjs

View on GitHub
// the usage-statistics rows rem-reflect sends through `sno observe append`,
// driven through the real CLI entry (`rem-reflect.ts run|accept|reject`) on the fixture store.
// With the recording `sno` shim first on PATH, every call lands as one argv line (after `observe`) in
// REM_OBSERVE_CAPTURE; with no `sno` on PATH at all, the commands must exit as they
// did before the emitters existed and the run's run.log must name the missing program once.
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { skillRoots } from '../config.ts';
import { existingTraces } from '../harvest.ts';
import { readLabels } from '../labeler.ts';
import { readLedger } from '../ledger.ts';
import { skillImpact } from '../report.ts';
import {
  tmp, makeConfig, makeStore, writeInstalledSkill, stationSettings,
  writeClaudeSession, claudeUser, claudeAssistant, writeCodexSession, codexMeta, codexUser, codexAssistant,
} from '../test-helpers.ts';

const CLI = fileURLToPath(new URL('../rem-reflect.ts', import.meta.url));
const BIN = fileURLToPath(new URL('./bin', import.meta.url));
const DAY1 = '2026-09-15T00:00:00Z', DAY2 = '2026-09-16T00:00:00Z', DAY3 = '2026-09-17T00:00:00Z';
const RUN1 = '20260915-0000', RUN2 = '20260916-0000', RUN3 = '20260917-0000';
const SRC_MT = new Date('2026-09-14T00:00:00Z').getTime();
const SELF_MT = new Date('2026-09-15T06:00:00Z').getTime();
// `run --now 2026-09-15T00:00:00Z` on a fresh store and `accept <run>/claude-code` on a store
// holding that pending proposal. The consent read fails first in both, as it did then.
const NO_SNO_RUN_EXIT = 0;
const NO_SNO_ACCEPT_EXIT = 0;
const cleanup = [];

// One fixture: a HOME whose .claude/.codex are the harvest roots, three sessions per harness,
// three installed skills per harness, logged-in CLIs, the Sno Station settings file, and a pre-made store.
function fixture() {
  const home = tmp('observe-home');
  const claudeHome = join(home, '.claude'), codexHome = join(home, '.codex');
  for (const name of ['heartbeat', 'second-skill', 'nested-skill']) {
    writeInstalledSkill(claudeHome, name);
    writeInstalledSkill(codexHome, name);
  }
  writeFileSync(join(claudeHome, '.credentials.json'), '{"claude":"fixture-token"}');
  writeFileSync(join(codexHome, 'auth.json'), '{"codex":"fixture-token"}');
  mkdirSync(join(home, '.sno'), { recursive: true });
  writeFileSync(join(home, '.sno', 'settings.json'), stationSettings('rem-enhanced'));
  const config = makeConfig({
    claude_home: claudeHome, codex_home: codexHome,
    claude_root: join(claudeHome, 'projects'), codex_root: join(codexHome, 'sessions'),
    project_names: {}, time_zone: 'UTC',
  });
  for (let i = 0; i < 3; i++) {
    writeClaudeSession(config.claude_root, 'proj', `cc${i}`,
      [claudeUser('/n', `cc${i}`, 'do it'), claudeAssistant('/n', `cc${i}`, [{ type: 'text', text: 'ok' }])], SRC_MT + i);
    writeCodexSession(config.codex_root, `cx${i}`,
      [codexMeta(`cx${i}`, '/n'), codexUser('do it'), codexAssistant('ok')], SRC_MT + i, `2026/09/1${i + 4}`, `2026-09-1${i + 4}T00-00-00`);
  }
  const store = makeStore(config);
  cleanup.push(home, store);
  return { home, config, store, capture: join(home, 'observe.log') };
}

// A PATH holding node, git, the shell tools the loop reaches and the claude/codex shims,
// but no `sno` of any kind.
function noSnoBin() {
  const dir = tmp('observe-nosno-bin');
  cleanup.push(dir);
  for (const prog of ['git', 'sh', 'bash', 'env', 'cat', 'uname', 'dirname', 'basename', 'mkdir', 'rm', 'cp', 'mv',
    'ln', 'chmod', 'mktemp', 'date', 'sort', 'grep', 'sed', 'head', 'tail', 'wc', 'tr', 'cut', 'readlink']) {
    const real = spawnSync('bash', ['-c', `command -v ${prog}`], { encoding: 'utf8' }).stdout.trim();
    if (real) symlinkSync(real, join(dir, prog));
  }
  symlinkSync(process.execPath, join(dir, 'node'));
  for (const shim of ['claude', 'codex', 'shim-core.cjs']) copyFileSync(join(BIN, shim), join(dir, shim));
  const probe = spawnSync(join(dir, 'bash'), ['-c', 'command -v sno'], { env: { PATH: dir }, encoding: 'utf8' });
  assert.notEqual(probe.status, 0, `the no-sno PATH still resolves sno: ${probe.stdout}`);
  return dir;
}

function cli(fx, args, path, extra = {}) {
  const env = { ...process.env, PATH: path, HOME: fx.home, CLAUDE_CONFIG_DIR: join(fx.home, '.claude'),
    CODEX_HOME: join(fx.home, '.codex'), SNO_PROFILE_DIR: join(fx.home, '.sno'), REM_REFLECT_STORE: fx.store, REM_SHIM_MTIME: String(SELF_MT),
    REM_OBSERVE_CAPTURE: fx.capture, REM_SNO_CAPTURE: join(fx.home, 'cloud-requests.jsonl') };
  delete env.REM_SELFTEST;
  delete env.CLAUDECODE;
  Object.assign(env, extra);
  const result = spawnSync(process.execPath, ['--experimental-strip-types', CLI, ...args],
    { env, encoding: 'utf8', timeout: 120_000 });
  return { code: result.status, out: `${result.stdout}${result.stderr}` };
}

// The `sno observe append` rows captured since the previous call, as { event, fields }.
function reader(fx) {
  let seen = 0;
  return () => {
    const text = existsSync(fx.capture) ? readFileSync(fx.capture, 'utf8') : '';
    const fresh = text.slice(seen);
    seen = text.length;
    return fresh.split('\n').filter(Boolean).map(line => {
      const [sub, event, ...args] = line.split(' ');
      assert.equal(sub, 'append', `unexpected observe call: ${line}`);
      return { event, fields: Object.fromEntries(args.map(arg => {
        const match = /^--([a-z_]+)=(.*)$/.exec(arg);
        assert.ok(match, `argument is not --field=value: ${arg} in ${line}`);
        return [match[1], match[2]];
      })) };
    });
  };
}
const only = (rows, event) => rows.filter(row => row.event === event).map(row => row.fields);
const show = (rows) => JSON.stringify(rows);
const status = (store) => JSON.parse(readFileSync(join(store, 'state.json'), 'utf8')).last_terminal?.status;

// --- with `sno` on PATH -------------------------------------------------------------------------
const withSno = `${BIN}:${process.env.PATH}`;
const a = fixture();
const fresh = reader(a);

const run1 = cli(a, ['run', '--trigger', 'timer', '--now', DAY1], withSno);
assert.equal(run1.code, 0, `run --trigger timer exits 0:\n${run1.out}`);
assert.ok(['success', 'no_action'].includes(status(a.store)), `day one terminal is success or no_action, got ${status(a.store)}`);
let rows = fresh();
const harvested = existingTraces(a.store).length;
assert.equal(harvested, 6, 'the fixture harvest read six sessions');
const [runRow, ...extraRuns] = only(rows, 'rsi.run');
assert.ok(runRow && !extraRuns.length, `one rsi.run row: ${show(rows)}`);
assert.deepEqual(Object.keys(runRow).sort(), ['agent', 'duration_ms', 'outcome', 'sessions_read', 'trigger'], show(rows));
assert.ok(rows.every(row => row.fields.agent === 'codex'), `every row outside Claude Code names codex: ${show(rows)}`);
assert.equal(runRow.trigger, 'timer');
assert.equal(runRow.outcome, 'ok');
assert.equal(runRow.sessions_read, String(harvested), 'sessions_read is the harvested count');
assert.match(runRow.duration_ms, /^[1-9][0-9]*$/, 'duration_ms is a whole number above 0');

const pending = readLedger(a.store).filter(row => row.type === 'proposal' && row.run_id === RUN1 && row.verdict === 'pending');
assert.equal(pending.length, 2, 'the fixture cloud answer staged one proposal per half');
assert.deepEqual(only(rows, 'rsi.proposal'), [{
  agent: 'codex', level: 'user', proposal_count: String(pending.length), skills_touched: String(new Set(pending.map(row => row.target)).size),
}], `one rsi.proposal row counting this run's pending proposals and distinct targets: ${show(rows)}`);
const response = JSON.parse(readFileSync(join(a.store, 'staging', RUN1, 'cloud-response.json'), 'utf8'));
const issued = response.halves.reduce((sum, half) => sum + half.lessons.length, 0);
assert.deepEqual(only(rows, 'rsi.lesson'), [{ agent: 'codex', level: 'user', count: String(issued) }],
  `one rsi.lesson row per run counting the lessons the cloud issued (${issued}): ${show(rows)}`);

const accept = cli(a, ['accept', `${RUN1}/claude-code`], withSno, { CLAUDECODE: '1' });
assert.equal(accept.code, 0, `accept exits 0:\n${accept.out}`);
const afterAccept = fresh();
assert.deepEqual(only(afterAccept, 'rsi.verdict'),
  [{ agent: 'claude-code', level: 'user', accepted: '1', rejected: '0', tbd: '0' }], show(afterAccept));
const reject = cli(a, ['reject', `${RUN1}/codex`], withSno);
assert.equal(reject.code, 0, `reject exits 0:\n${reject.out}`);
const afterReject = fresh();
assert.deepEqual(only(afterReject, 'rsi.verdict'),
  [{ agent: 'codex', level: 'user', accepted: '0', rejected: '1', tbd: '0' }], show(afterReject));

// The run report or acceptance step records rsi.impact. Either way,
// accept plus the next run carry exactly one row per adopted unit, with skillImpact()'s counts.
const run2 = cli(a, ['run', '--trigger', 'timer', '--now', DAY2], withSno);
assert.equal(run2.code, 0, `day two exits 0:\n${run2.out}`);
const afterRun2 = fresh();
const impactRows = [...afterAccept, ...afterReject, ...afterRun2].filter(row => row.fields.agent === 'codex');
const expected = [...new Map(skillImpact(skillRoots(a.config), existingTraces(a.store), readLabels(a.store), readLedger(a.store))
  .map(row => [row.unit, {
    agent: 'codex', level: 'user', skill_name: row.unit,
    before_sessions: String(row.loaded_before.traces), before_failures: String(row.loaded_before.fail),
    after_sessions: String(row.loaded_after.traces), after_failures: String(row.loaded_after.fail),
  }])).values()];
assert.deepEqual(expected.map(row => row.skill_name), ['heartbeat'], 'the accepted proposal adopted one unit');
assert.deepEqual(only(impactRows, 'rsi.impact'), expected, `one rsi.impact per adopted unit: ${show(impactRows)}`);
assert.equal(only(afterRun2, 'rsi.run')[0]?.trigger, 'timer', show(afterRun2));

const run3 = cli(a, ['run', '--now', DAY3], withSno);
assert.equal(run3.code, 0, `a run without --trigger exits 0:\n${run3.out}`);
const afterRun3 = fresh();
assert.equal(only(afterRun3, 'rsi.run')[0]?.trigger, 'manual', `--trigger defaults to manual: ${show(afterRun3)}`);
for (const id of [RUN1, RUN2, RUN3]) {
  const log = readFileSync(join(a.store, 'staging', id, 'run.log'), 'utf8');
  assert.doesNotMatch(log, /not found/, `a run with sno on PATH logs no missing program (${id})`);
}

// --- with `sno observe append` exiting 2 for rsi.run -----------------------------------------------------
const d = fixture();
const runD = cli(d, ['run', '--trigger', 'timer', '--now', DAY1], withSno, { REM_OBSERVE_FAIL: 'rsi.run' });
const e = fixture();
const runE = cli(e, ['run', '--trigger', 'timer', '--now', DAY1], withSno);
const normal = (fx, out) => out.replaceAll(fx.home, '<home>').replaceAll(fx.store, '<store>');
assert.equal(runD.code, runE.code, `a failed append leaves the exit code:\n${runD.out}`);
assert.equal(normal(d, runD.out), normal(e, runE.out), 'a failed append leaves the output unchanged');
const logD = readFileSync(join(d.store, 'staging', RUN1, 'run.log'), 'utf8');
const logE = readFileSync(join(e.store, 'staging', RUN1, 'run.log'), 'utf8');
assert.equal(logD.split('\n').length - logE.split('\n').length, 1, `the failed append adds one log line:\n${logD}`);
assert.equal(readFileSync(d.capture, 'utf8').split('\n').some(line => line.startsWith('append error')), false,
  'rem-reflect sends no error event of its own');

// --- with no `sno` anywhere on PATH -------------------------------------------------------------
const noSno = noSnoBin();
const b = fixture();
const runB = cli(b, ['run', '--trigger', 'timer', '--now', DAY1], noSno);
assert.equal(runB.code, NO_SNO_RUN_EXIT, `run without sno exits as before the emitters (${NO_SNO_RUN_EXIT}):\n${runB.out}`);
const logB = readFileSync(join(b.store, 'staging', RUN1, 'run.log'), 'utf8');
// A failed upload no longer stops the run, so both the rsi.proposal and the rsi.run rows reach the missing program.
assert.equal(logB.split('\n').filter(line => line.includes('sno: not found')).length, 2,
  `run.log carries one "sno: not found" line per emitted row:\n${logB}`);

const c = fixture();
const runC = cli(c, ['run', '--trigger', 'timer', '--now', DAY1], withSno);
assert.equal(runC.code, 0, `staging a pending proposal for the no-sno accept:\n${runC.out}`);
const acceptC = cli(c, ['accept', `${RUN1}/claude-code`], noSno);
assert.equal(acceptC.code, NO_SNO_ACCEPT_EXIT, `accept without sno exits as before the emitters (${NO_SNO_ACCEPT_EXIT}):\n${acceptC.out}`);

for (const dir of cleanup) rmSync(dir, { recursive: true, force: true });
console.log('OBSERVE JOURNEY OK');
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 CodeCodexVerifiedInstall
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: 323kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 323kUpdated 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: 323kUpdated Claude CodeCodexVerifiedInstall