Skip to content

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

rem-reflect

Unverified

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

View on GitHub
import { test } from 'node:test';
import type { TestContext } from 'node:test';
import assert from 'node:assert/strict';
import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { spawnSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import { run } from './rem-reflect.ts';
import { stationCell } from './config.ts';
import { cloudStepGate, localConsent } from './cloud.ts';
import type { Config } from './config.ts';
import { appendRows } from './lessons.ts';
import { git } from './store.ts';
import {
  tmp, fixtureConfig, fixtureCheckout, makeStore, FixtureBackend, writeStationSettings, stationSettings,
  writeCodexSession, codexMeta, codexUser, codexAssistant, codexFailedTest,
} from './test-helpers.ts';

const MT = new Date('2026-09-07T00:00:00Z').getTime();
const NIGHT = new Date('2026-09-08T00:00:00Z');

function useEnv(t: TestContext, vars: Record<string, string>): void {
  for (const [key, value] of Object.entries(vars)) {
    const before = process.env[key];
    process.env[key] = value;
    t.after(() => { if (before === undefined) delete process.env[key]; else process.env[key] = before; });
  }
}
function cfg(): Config { return fixtureConfig({ claude_root: tmp('c'), codex_root: tmp('x') }); }
// The failed `pytest` is the external verdict a session needs before the Local First writer is asked about it.
function codexTrace(config: Config): void {
  writeCodexSession(config.codex_root, 'cx', [codexMeta('cx', '/n'), codexUser('do it'), codexAssistant('ok'), codexFailedTest()], MT);
}
function stagingFile(store: string, name: string): string | undefined {
  return readdirSync(join(store, 'staging'), { recursive: true }).map(String).find(path => path.endsWith(name));
}
function labelFiles(store: string): string[] {
  return readdirSync(join(store, 'raw'), { recursive: true }).map(String).filter(p => p.endsWith('.label.json'));
}
function nightRun(t: TestContext, mode: string, rows: Record<string, Record<string, string>> = {}, env: Record<string, string> = {}) {
  useEnv(t, { SNO_PROFILE_DIR: writeStationSettings(mode, rows), ...env });
  const config = cfg();
  const store = makeStore(config);
  codexTrace(config);
  const backend = new FixtureBackend();
  const result = run(store, NIGHT, 'u', backend);
  return { store, backend, result, labeler: backend.calls.filter(call => call.kind === 'labeler').length };
}

test('the cell comes from the file for the current mode, and a missing file, mode, row or value says which', () => {
  const profile = writeStationSettings('rem-enhanced', { R3: { 'local-first': 'off', 'agent-native': 'sno-gpu', 'rem-enhanced': 'off' } });
  assert.equal(stationCell('R2', { SNO_PROFILE_DIR: profile }), 'host');
  assert.equal(stationCell('R3', { SNO_PROFILE_DIR: profile }), 'off');
  const empty = tmp('empty-profile');
  assert.throws(() => stationCell('R2', { SNO_PROFILE_DIR: empty }), /settings unavailable: .*settings\.json: file missing; run sno setup/);
  const write = (body: string) => { const dir = tmp('bad-profile'); writeFileSync(join(dir, 'settings.json'), body); return dir; };
  assert.throws(() => stationCell('R2', { SNO_PROFILE_DIR: write('{') }), /not valid JSON/);
  assert.throws(() => stationCell('R2', { SNO_PROFILE_DIR: write(JSON.stringify({ modelCalls: {} })) }), /mode is missing or unknown/);
  assert.throws(() => stationCell('R4', { SNO_PROFILE_DIR: write(JSON.stringify({ mode: 'agent-native', modelCalls: { R2: {} } })) }), /modelCalls\.R4 is missing/);
  assert.throws(() => stationCell('R2', { SNO_PROFILE_DIR: write(stationSettings('agent-native', { R2: { 'agent-native': 'cloud' } })) }),
    /modelCalls\.R2\.agent-native is not off, host or sno-gpu/);
});

test('local-first labels nothing, uploads nothing and says why', t => {
  const { store, backend, result, labeler } = nightRun(t, 'local-first');
  assert.equal(result.code, 0, result.lines.join('\n'));
  assert.equal(labeler, 0, 'no labeler process');
  assert.equal(backend.calls.filter(call => call.kind === 'writer').length, 1, 'its own CLI is asked once for a lesson');
  assert.equal(stagingFile(store, 'cloud-request.json'), undefined, 'no upload');
  assert.equal(labelFiles(store).length, 0);
  assert.match(readFileSync(join(store, 'staging', readdirSync(join(store, 'staging'))[0], 'run.log'), 'utf8'), /R2 labeling off; R3 upload skipped: local-first mode/);
});

test('agent-native at full consent labels on its own CLI and uploads the labeled session', t => {
  const { store, result, labeler } = nightRun(t, 'agent-native');
  assert.equal(result.code, 0, result.lines.join('\n'));
  assert.equal(labeler, 1);
  assert.ok(stagingFile(store, 'cloud-request.json'), 'the session went to the cloud');
  assert.match(readFileSync(join(store, 'raw', labelFiles(store)[0]), 'utf8'), /"decision": "keep"/);
  assert.match(readFileSync(join(store, 'staging', readdirSync(join(store, 'staging'))[0], 'run.log'), 'utf8'), /R2 labeling runs; R3 upload sends/);
});

test('below full consent the CLI rejection leaves local labeling and the day successful', async t => {
  for (const mode of ['agent-native', 'rem-enhanced']) {
    await t.test(mode, sub => {
      const { store, labeler, result } = nightRun(sub, mode, {}, { REM_TEST_CONSENT: 'metadata-only' });
      assert.equal(result.code, 0);
      assert.equal(labeler, 1, 'local labeler still runs');
      assert.ok(stagingFile(store, 'cloud-request.json'), 'request retained after CLI rejects consent');
      assert.match(result.lines.join('\n'), /cloud run .* send failed: .*upload rejected: consent metadata-only/);
    });
  }
});

test('the mode controls sharing even when the old upload cell is off', t => {
  const { store, labeler } = nightRun(t, 'agent-native', { R3: { 'local-first': 'off', 'agent-native': 'off', 'rem-enhanced': 'off' } });
  assert.equal(labeler, 1);
  assert.ok(stagingFile(store, 'cloud-request.json'));
});

test('with the labeling cell off the session still uploads, kept with an unknown outcome and no CLI turn', t => {
  const { store, result, labeler } = nightRun(t, 'agent-native', { R2: { 'local-first': 'off', 'agent-native': 'off', 'rem-enhanced': 'off' } });
  assert.equal(result.code, 0, result.lines.join('\n'));
  assert.equal(labeler, 0);
  const sent = stagingFile(store, 'cloud-request.json');
  assert.ok(sent, 'the upload went ahead');
  const batch = JSON.parse(readFileSync(join(store, 'staging', sent), 'utf8'));
  assert.equal(batch.halves.flatMap((half: { sessions: unknown[] }) => half.sessions).length, 1);
  const label = JSON.parse(readFileSync(join(store, 'raw', labelFiles(store)[0]), 'utf8'));
  assert.deepEqual([label.decision, label.outcome, label.reason], ['keep', 'unknown', 'labeler-off']);
});

test('a missing settings file runs no model, uploads nothing and the report names the file', t => {
  useEnv(t, { SNO_PROFILE_DIR: tmp('empty-profile') });
  const config = cfg();
  const store = makeStore(config);
  codexTrace(config);
  const backend = new FixtureBackend();
  const result = run(store, NIGHT, 'u', backend);
  assert.equal(result.code, 0);
  assert.equal(backend.calls.filter(call => call.kind === 'labeler').length, 0);
  assert.equal(stagingFile(store, 'cloud-request.json'), undefined);
  const report = readFileSync(join(store, 'staging', readdirSync(join(store, 'staging'))[0], 'REPORT.md'), 'utf8');
  assert.match(report, /No-upload: settings unavailable: .*settings\.json: file missing; run sno setup/);
});

test('a session whose CLI fails its health check is kept unlabeled without any labeler turn', t => {
  useEnv(t, { SNO_PROFILE_DIR: writeStationSettings('agent-native') });
  const config = cfg();
  const store = makeStore(config);
  codexTrace(config);
  const backend = new FixtureBackend({ preflight: () => false });
  const result = run(store, NIGHT, 'u', backend);
  assert.equal(result.code, 0);
  assert.match(result.lines.join('\n'), /labeler-unavailable; labeler_codex/);
  assert.match(readFileSync(join(store, 'raw', labelFiles(store)[0]), 'utf8'), /"decision": "keep"/);
  assert.equal(backend.calls.filter(call => call.kind === 'labeler').length, 0);
  assert.equal(backend.calls.filter(call => call.kind === 'preflight').length, 1, 'the health check runs with no model named');
});

test('a long session is labeled in bounded windows around its owner messages', t => {
  useEnv(t, { SNO_PROFILE_DIR: writeStationSettings('agent-native') });
  const config = cfg();
  const store = makeStore(config);
  const turns = Array.from({ length: 9 }, (_, i) => codexUser(`turn ${i} ${'x'.repeat(40_000)}`));
  writeCodexSession(config.codex_root, 'big', [codexMeta('big', '/n'), ...turns, codexAssistant('ok')], MT);
  const backend = new FixtureBackend();
  const r = run(store, NIGHT, 'u', backend);
  assert.equal(r.code, 0);
  const labeler = backend.calls.filter(c => c.kind === 'labeler');
  assert.ok(labeler.length > 1, 'the full session needs multiple windows');
  assert.ok(labeler.every(c => c.input.length <= 120000));
  assert.equal(labeler[0].cli, 'codex');
  assert.equal(labelFiles(store).length, 1);
  const second = new FixtureBackend();
  run(store, new Date('2026-09-09T00:00:00Z'), 'u', second);
  assert.equal(second.calls.filter(c => c.kind === 'labeler').length, 0, 'the next run does not retry it');
});

// The first prompt's cloud lookup: a shim `sno` records every request that would leave the machine.
function firstPrompt(t: TestContext, mode: string, consent: string, rows: Record<string, Record<string, string>> = {}, profile?: string) {
  const checkout = fixtureCheckout();
  const store = makeStore(fixtureConfig());
  appendRows(join(store, 'wiki/lessons.jsonl'), [{ lesson_id: 'L-1', status: 'accepted', 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('r4-bin');
  const requests = join(bin, 'requests.jsonl');
  const sno = join(bin, 'sno');
  writeFileSync(sno, '#!/usr/bin/env node\nconst fs=require("node:fs");\nconst a=process.argv.slice(2).join(" ");\nif(a==="station consent --json"){console.log(JSON.stringify({consent:process.env.CONSENT}));process.exit(0);}\nfs.appendFileSync(process.env.RECALL_REQUESTS, fs.readFileSync(0,"utf8")+"\\n");\nconsole.log(JSON.stringify({lesson_ids:["L-1"]}));\n');
  chmodSync(sno, 0o755);
  const env = { ...process.env, REM_REFLECT_STORE: store, RECALL_REQUESTS: requests, CONSENT: consent,
    SNO_PROFILE_DIR: profile ?? writeStationSettings(mode, rows), PATH: `${bin}:${process.env.PATH ?? ''}` };
  const command = fileURLToPath(new URL('./rem-reflect.ts', import.meta.url));
  const prompt = (session: string) => spawnSync(process.execPath, [command, 'recall', '--agent', 'codex', '--first-message'],
    { input: JSON.stringify({ session_id: session, cwd: checkout, prompt: 'broken build' }), encoding: 'utf8', env });
  return { store, requests, prompt, sent: () => (existsSync(requests) ? readFileSync(requests, 'utf8').trim().split('\n').length : 0) };
}

test('the first-prompt lookup reaches the cloud only when its cell is sno-gpu and consent is full', t => {
  const sent = firstPrompt(t, 'agent-native', 'full');
  const answer = sent.prompt('s1');
  assert.equal(answer.status, 0, answer.stderr);
  assert.match(answer.stdout, /read the compiler error/);
  assert.equal(sent.sent(), 1);
  for (const [name, args] of [['local-first mode', ['local-first', 'full']], ['metadata-only consent', ['agent-native', 'metadata-only']],
    ['cell off', ['agent-native', 'full', { R4: { 'local-first': 'off', 'agent-native': 'off', 'rem-enhanced': 'off' } }]]] as const) {
    const blocked = firstPrompt(t, args[0], args[1], args.length === 3 ? args[2] : {});
    const first = blocked.prompt('s1');
    assert.equal(first.status, 0, `${name}: the prompt is never blocked`);
    assert.equal(first.stdout, '', name);
    assert.equal(blocked.sent(), 0, `${name}: nothing left the machine`);
    const usage = readFileSync(join(blocked.store, 'ledger/usage.jsonl'), 'utf8');
    assert.match(usage, /"type":"first-message-recall","session_id":"s1".*"call":"R4","skipped":/, name);
    blocked.prompt('s1');
    assert.equal(readFileSync(join(blocked.store, 'ledger/usage.jsonl'), 'utf8').trim().split('\n').length, 1, `${name}: a later prompt in the session is not a first prompt again`);
  }
});

test('the first-prompt lookup with no settings file sends nothing, records the missing file and never fails the prompt', t => {
  const missing = firstPrompt(t, 'agent-native', 'full', {}, tmp('empty-profile'));
  const first = missing.prompt('s1');
  assert.equal(first.status, 0);
  assert.equal(first.stdout, '');
  assert.equal(missing.sent(), 0);
  assert.match(readFileSync(join(missing.store, 'ledger/usage.jsonl'), 'utf8'), /"skipped":"settings unavailable: .*settings\.json: file missing; run sno setup"/);
});

test('consent is read from `sno station consent --json`, so the plain output becoming a sentence no longer blocks the lookup', t => {
  const bin = tmp('consent-bin');
  // The installed sno (1.1.13) prints a sentence without --json; the JSON form keeps the bare level.
  writeFileSync(join(bin, 'sno'), '#!/bin/sh\ncase "$*" in\n"station consent") echo "Uploads: full. Sno receives usage counts, the sessions and skills Self Learning reads, and more. Change it with sno station consent off, metadata-only or full.";;\n"station consent --json") echo \'{"consent":"full"}\';;\n*) exit 2;;\nesac\n');
  chmodSync(join(bin, '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; });
  assert.equal(localConsent(), 'full');
  assert.deepEqual(cloudStepGate('R4'), { send: true });
});
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