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

View on GitHub
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { chmodSync, existsSync, readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { run } from './rem-reflect.ts';
import { reflect } from './reflect.ts';
import { readLabels } from './labeler.ts';
import { appendRows } from './lessons.ts';
import { reflectionFiles } from './config.ts';
import { readState } from './store.ts';
import { tmp, fixtureConfig, makeStore, FixtureBackend,
  writeCodexSession, codexMeta, codexUser, codexAssistant } from './test-helpers.ts';

test('a long trace gets one persisted keep decision on its own CLI', () => {
  const config = fixtureConfig({ claude_root: tmp('c'), codex_root: tmp('x') });
  const store = makeStore(config);
  writeCodexSession(config.codex_root, 'big', [
    codexMeta('big', '/n', { originator: 'codex_exec' }), codexUser('start the task'),
    codexAssistant('Z'.repeat(60_000)), codexUser('more'), codexAssistant('done'),
  ], Date.parse('2026-09-07T00:00:00Z'));
  const backend = new FixtureBackend();
  const result = run(store, new Date('2026-09-08T00:00:00Z'), 'u', backend);
  assert.equal(result.code, 0);
  const labels = readLabels(store);
  assert.equal(labels.size, 1);
  const [label] = [...labels.values()];
  assert.equal(label.labeled_by, 'codex');
  assert.equal(label.decision, 'keep');
  assert.deepEqual(backend.calls.filter(call => call.kind === 'labeler').map(call => call.cli), ['codex']);
});

test('a failed upload preserves a successful day and the next day retries the saved batch without relabeling', t => {
  const bin = tmp('retry-bin');
  const script = join(bin, 'sno');
  const marker = join(bin, 'failed-once');
  const first = join(bin, 'first.json');
  const second = join(bin, 'second.json');
  writeFileSync(script, `#!/usr/bin/env node
const fs = require('node:fs');
const args = process.argv.slice(2).join(' ');
if (args === 'station consent --json') { console.log(JSON.stringify({ consent: 'full' })); process.exit(0); }
if (args !== 'rem judge --json') process.exit(2);
const input = fs.readFileSync(0, 'utf8');
if (!fs.existsSync(${JSON.stringify(marker)})) {
  fs.writeFileSync(${JSON.stringify(first)}, input);
  fs.writeFileSync(${JSON.stringify(marker)}, '1');
  console.error('temporary cloud outage'); process.exit(2);
}
const batch = JSON.parse(input);
if (batch.run_id === '20260908-0000') fs.writeFileSync(${JSON.stringify(second)}, input);
console.log(JSON.stringify({schema_version:1,run_id:batch.run_id,history_acknowledged:true,history_links:[],
  halves:batch.halves.map(half=>({harness:half.harness,attention:[],pages:[],lessons:[],proposals:[],read_judgments:[],log_entry:'no supported change'}))}));
`);
  chmodSync(script, 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 config = fixtureConfig({ claude_root: tmp('c'), codex_root: tmp('x') });
  const store = makeStore(config);
  writeCodexSession(config.codex_root, 'cx', [codexMeta('cx', '/n'), codexUser('do it'), codexAssistant('ok')], Date.parse('2026-09-07T00:00:00Z'));
  const today = new Date('2026-09-08T00:00:00Z');
  const firstBackend = new FixtureBackend();
  const failed = run(store, today, 'u', firstBackend);
  assert.equal(failed.code, 0);
  assert.equal(readState(store).last_terminal?.status, 'success');
  assert.match(failed.lines.join('\n'), /cloud run 20260908-0000 send failed: .*temporary cloud outage/);
  const report = readFileSync(join(store, 'staging', '20260908-0000', 'REPORT.md'), 'utf8');
  assert.equal(firstBackend.calls.filter(call => call.kind === 'labeler').length, 1);
  assert.equal(existsSync(first), true);

  const secondBackend = new FixtureBackend();
  const sameDay = run(store, today, 'u', secondBackend);
  assert.match(sameDay.lines.join('\n'), /already succeeded/);
  assert.equal(existsSync(second), false);
  const resumed = run(store, new Date('2026-09-09T00:00:00Z'), 'u', secondBackend);
  assert.equal(resumed.code, 0, resumed.lines.join('\n'));
  assert.equal(secondBackend.calls.filter(call => call.kind === 'labeler').length, 0);
  assert.equal(readFileSync(second, 'utf8'), readFileSync(first, 'utf8'), 'the same persisted batch reached the cloud');
  assert.equal(JSON.parse(readFileSync(second, 'utf8')).halves[0].sessions.length, 1);
  assert.equal(readFileSync(join(store, 'staging', '20260908-0000', 'REPORT.md'), 'utf8'), report);
});

test('eligible lessons show their advice and both accept commands, while no eligible lesson shows neither command', t => {
  const bin = tmp('report-bin');
  const sno = join(bin, 'sno');
  writeFileSync(sno, '#!/bin/sh\n[ "$*" = "station consent --json" ] && { echo \'{"consent":"full"}\'; exit 0; }\nexit 2\n');
  chmodSync(sno, 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 config = fixtureConfig({ claude_root: tmp('c'), codex_root: tmp('x') });
  const store = makeStore(config);
  const situation = { task_type: 'debug', trigger: 'a repeated failure', tools: [] };
  appendRows(join(store, reflectionFiles.lessons), [{
    lesson_id: 'L-report', page_id: 'pg-report', status: 'candidate', count: 1, helped: 0, harmful: 0,
    measured: false, created_run: '20260923-0000', project_id: 'p', agent_id: 'codex', user_id: 'u', skill_target: null,
    scenario: situation, situation, advice: 'check the exact failure before retrying', because: 'blind retries repeat it',
    applies_to: 'project:p', polarity: 'from_failure', evidence: [], counter_examples: 'not searched', listed: true,
  }]);
  const report = reflect(store, config, '20260923-0000', new FixtureBackend(), [], new Date('2026-09-23T00:00:00Z')).report.join('\n');
  assert.match(report, /L-report: check the exact failure before retrying/);
  assert.match(report, /sno rem-reflect accept L-report(?:\n|$)/);
  assert.match(report, /sno rem-reflect accept L-report --all-projects/);

  const empty = makeStore(config);
  const emptyReport = reflect(empty, config, '20260923-0100', new FixtureBackend(), [], new Date('2026-09-23T01:00:00Z')).report.join('\n');
  assert.doesNotMatch(emptyReport, /sno rem-reflect accept/);
});

test('the report counts the last seven nights of the effect signal chain from the usage and judgment rows', t => {
  const bin = tmp('signal-bin');
  const sno = join(bin, 'sno');
  writeFileSync(sno, '#!/bin/sh\n[ "$*" = "station consent --json" ] && { echo \'{"consent":"full"}\'; exit 0; }\nexit 2\n');
  chmodSync(sno, 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 config = fixtureConfig({ claude_root: tmp('c'), codex_root: tmp('x') });
  const store = makeStore(config);
  const now = new Date('2026-10-22T06:00:00Z');
  const recent = '2026-10-20T10:00:00Z';
  const old = '2026-10-01T10:00:00Z';
  appendRows(join(store, reflectionFiles.usage), [
    { type: 'shown', session_id: 'a', lesson_ids: ['L-1'], time: recent },
    { type: 'shown', session_id: 'a', lesson_ids: ['L-2'], time: recent },
    { type: 'shown', session_id: 'b', lesson_ids: ['L-1'], time: recent },
    { type: 'shown', session_id: 'z', lesson_ids: ['L-1'], time: old },
    { type: 'read', session_id: 'a', lesson_id: 'L-1', time: recent },
    { type: 'read', session_id: 'z', lesson_id: 'L-1', time: old },
    { type: 'first-message-recall', session_id: 'a', call: 'R4', time: recent },
    { type: 'first-message-recall', session_id: 'b', call: 'R4', time: recent },
    { type: 'first-message-recall', session_id: 'c', call: 'R4', skipped: 'consent off', time: recent },
    { type: 'first-message-recall-skipped', session_id: 'b', until: '2026-10-21T00:00:00Z', time: recent },
    { type: 'first-message-recall-skipped', session_id: 'd', until: '2026-10-21T00:00:00Z', time: recent },
    { type: 'first-message-recall-failed', session_id: 'e', error: 'Error: spawnSync sno ETIMEDOUT', time: recent },
    { type: 'first-message-recall-failed', session_id: 'f', error: 'exit 7', time: recent },
  ]);
  appendRows(join(store, reflectionFiles.ledger), [
    { type: 'lesson-judgment', run_id: '20261020-1906', trace_id: 'a.v1', lesson_id: 'L-1', followed: 'yes', effect: 'helped', basis: 'shown' },
    { type: 'lesson-judgment', run_id: '20261021-1906', trace_id: 'b.v1', lesson_id: 'L-1', followed: 'yes', effect: 'harmful', basis: 'read' },
    { type: 'lesson-judgment', run_id: '20261021-1906', trace_id: 'b.v1', lesson_id: 'L-2', followed: 'no', effect: 'neutral', basis: 'shown' },
    { type: 'lesson-judgment', run_id: '20261001-1906', trace_id: 'z.v1', lesson_id: 'L-1', followed: 'yes', effect: 'helped', basis: 'read' },
  ]);
  const report = reflect(store, config, '20261022-0600', new FixtureBackend(), [], now).report;
  assert.ok(report.includes('Sessions shown lessons at start: 2'), report.join('\n'));
  assert.ok(report.includes('Full lesson reads: 1'), report.join('\n'));
  assert.ok(report.includes('Judgments: 3 (helped 1, harmful 1; basis shown 2, read 1)'), report.join('\n'));
  assert.ok(report.includes('Cloud recall: sent 2 / allowance refused 2 / timed out 1'), report.join('\n'));
});
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