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

View on GitHub
// Cursor as a session source and a lesson-recall target. Rows follow the measured Cursor transcript shape
// (`{"role","message":{"content":[…]}}` plus `{"type":"turn_ended"}`, no timestamps, no tool output).
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readlinkSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { harvest } from './harvest.ts';
import type { Trace } from './harvest.ts';
import { buildCloudBatch } from './cloud.ts';
import { loadRenderBudgets, renderTrace } from './render.ts';
import { BackendError, RealBackend } from './backend.ts';
import { run } from './rem-reflect.ts';
import { appendRows } from './lessons.ts';
import { emptyState, git } from './store.ts';
import { DAY, fixtureCheckout, fixtureConfig, makeStore, setMtime, tmp } from './test-helpers.ts';

const COMMAND = fileURLToPath(new URL('./rem-reflect.ts', import.meta.url));

function writeTranscript(root: string, project: string, id: string, mtimeMs: number): string {
  const dir = join(root, project, 'agent-transcripts', id);
  mkdirSync(dir, { recursive: true });
  const path = join(dir, `${id}.jsonl`);
  const rows = [
    { role: 'user', message: { content: [{ type: 'text', text: '<timestamp>Thursday, Oct 8, 2026, 1:57 PM (UTC-7)</timestamp>\n<user_query>\nAppend a line to note.txt\n</user_query>' }] } },
    { role: 'assistant', message: { content: [{ type: 'text', text: 'Appending it now.' },
      { type: 'tool_use', name: 'Shell', input: { command: "printf 'x\\n' >> note.txt", description: 'Append to note.txt' } }] } },
    { role: 'assistant', message: { content: [{ type: 'text', text: 'Done.' }] } },
    { type: 'turn_ended', status: 'success' },
  ];
  writeFileSync(path, rows.map(row => JSON.stringify(row)).join('\n') + '\n');
  setMtime(path, mtimeMs);
  return path;
}

function writeConversation(profile: string, id: string, project: string | null): void {
  mkdirSync(join(profile, 'cursor', 'conversations'), { recursive: true });
  writeFileSync(join(profile, 'cursor', 'conversations', `${id}.json`), JSON.stringify({ conversation_id: id, surface: 'ide', project }));
}

test('harvest collects Cursor conversations: the recorded repository scopes one, a conversation with no record is unscoped', () => {
  const checkout = fixtureCheckout();
  const config = fixtureConfig({ cursor_root: tmp('cursor-projects') });
  const profile = process.env.SNO_PROFILE_DIR ?? '';
  const now = new Date('2026-10-10T12:00:00Z');
  writeTranscript(config.cursor_root, 'Users-u-repoA', 'conv-scoped', now.getTime() - DAY);
  writeTranscript(config.cursor_root, 'Users-u-repoB', 'conv-unscoped', now.getTime() - DAY);
  writeConversation(profile, 'conv-scoped', checkout);
  const store = tmp('store');
  const { traces } = harvest(store, config, emptyState(), 'u', now);
  const byId = new Map(traces.map(trace => [trace.session_id, trace]));
  assert.deepEqual([...byId.keys()].sort(), ['conv-scoped', 'conv-unscoped']);
  const scoped = byId.get('conv-scoped');
  assert.ok(scoped);
  assert.equal(scoped.agent_id, 'cursor');
  assert.equal(scoped.project_id, 'github.com/example/project');
  assert.equal(byId.get('conv-unscoped')?.project_id, 'user-level');
  assert.equal(scoped.records.length, 3, 'the user row and both assistant rows are kept; turn_ended is skipped');
  assert.equal(scoped.skipped_records, 1);
  assert.equal(scoped.trivial, false, 'a tool call makes the conversation non-trivial');
  assert.ok(existsSync(join(store, 'raw', 'u', 'github.com', 'example', 'project', 'cursor', 'conv-scoped.v1.json')));
  const rendered = renderTrace(scoped, loadRenderBudgets()).records.map(row => row.text);
  assert.equal(rendered[0], '2: user Append a line to note.txt\n', 'the typed text, without the timestamp wrapper');
  assert.match(rendered[1], /Shell .*note\.txt/);
});

function lessonStore(): { store: string; checkout: string } {
  const checkout = fixtureCheckout();
  const store = makeStore(fixtureConfig());
  appendRows(join(store, 'wiki/lessons.jsonl'), [{ lesson_id: 'L-cursor', 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']);
  return { store, checkout };
}

function recallRun(store: string, args: string[], input: unknown, env: NodeJS.ProcessEnv = {}) {
  return spawnSync(process.execPath, [COMMAND, 'recall', ...args], { input: JSON.stringify(input), encoding: 'utf8',
    env: { ...process.env, REM_REFLECT_STORE: store, ...env } });
}

function usageRows(store: string): Record<string, unknown>[] {
  const path = join(store, 'ledger/usage.jsonl');
  return existsSync(path) ? readFileSync(path, 'utf8').split('\n').filter(Boolean).map(line => JSON.parse(line) as Record<string, unknown>) : [];
}

test('recall --agent cursor answers in Cursor form, scoped by the git root of the first workspace folder', () => {
  const { store, checkout } = lessonStore();
  const sub = join(checkout, 'skills');
  const start = recallRun(store, ['--agent', 'cursor'], { conversation_id: 'c-1', session_id: 'c-1', hook_event_name: 'sessionStart',
    cursor_version: '3.24.9', workspace_roots: [sub, '/elsewhere'], transcript_path: null });
  assert.equal(start.status, 0);
  const answer = JSON.parse(start.stdout) as { additional_context: string };
  assert.match(answer.additional_context, /L-cursor/);
  assert.match(answer.additional_context, /read the compiler error/);
  const shown = usageRows(store).find(row => row.type === 'shown' && row.session_id === 'c-1');
  assert.equal(shown?.agent_id, 'cursor');
  assert.equal(shown?.project_id, 'github.com/example/project');

  const outside = recallRun(store, ['--agent', 'cursor'], { conversation_id: 'c-2', workspace_roots: [tmp('not-a-repo')] });
  assert.equal(outside.status, 0);
  assert.equal(outside.stdout.trim(), '{}');
  assert.match(outside.stderr, /no git work tree/);

  const noStore = recallRun(join(tmp('gone'), 'store'), ['--agent', 'cursor'], { conversation_id: 'c-3', workspace_roots: [checkout] });
  assert.equal(noStore.status, 0, 'a Cursor hook never fails the conversation');
  assert.equal(noStore.stdout.trim(), '{}');
  assert.equal(noStore.stderr, '', 'before the first nightly run the mainline recall emits no error');
});

test('the Cursor first-prompt hook brings the lesson index once when no session start showed it', () => {
  const { store, checkout } = lessonStore();
  const prompt = (text: string) => recallRun(store, ['--agent', 'cursor', '--first-message'],
    { conversation_id: 'ide-first', hook_event_name: 'beforeSubmitPrompt', prompt: text, workspace_roots: [checkout] });
  const first = prompt('fix the broken build please');
  assert.equal(first.status, 0);
  assert.match((JSON.parse(first.stdout) as { additional_context: string }).additional_context, /L-cursor/);
  const second = prompt('and now the tests');
  assert.equal(second.status, 0);
  assert.equal(second.stdout.trim(), '{}', 'the index is not repeated on a later prompt');

  const started = recallRun(store, ['--agent', 'cursor'], { conversation_id: 'cli-run', workspace_roots: [checkout] });
  assert.match(started.stdout, /L-cursor/);
  const afterStart = recallRun(store, ['--agent', 'cursor', '--first-message'],
    { conversation_id: 'cli-run', prompt: 'fix the broken build please', workspace_roots: [checkout] });
  assert.equal(afterStart.stdout.trim(), '{}', 'a conversation whose session start showed the index does not get it twice');
});

test('a Claude-format recall hook run by the Cursor IDE does nothing, while a real Claude Code session still recalls', () => {
  const { store, checkout } = lessonStore();
  const before = usageRows(store).length;
  const inCursor = recallRun(store, ['--agent', 'claude-code'], { conversation_id: 'c-9', session_id: 'c-9',
    hook_event_name: 'sessionStart', cursor_version: '3.23.23', workspace_roots: [checkout] });
  assert.equal(inCursor.status, 0);
  assert.equal(inCursor.stdout, '');
  const inCursorFirst = recallRun(store, ['--agent', 'claude-code', '--first-message'], { session_id: 'c-9', prompt: 'broken build',
    hook_event_name: 'beforeSubmitPrompt', cursor_version: '3.23.23', workspace_roots: [checkout] });
  assert.equal(inCursorFirst.stdout, '');
  assert.equal(usageRows(store).length, before, 'nothing is recorded for a Cursor-shaped input');
  const claude = recallRun(store, ['--agent', 'claude-code'], { session_id: 'claude-1', cwd: checkout });
  assert.match(claude.stdout, /L-cursor/);
});

test('recall install writes the two Cursor entries once, in place, and keeps entries another program wrote', () => {
  const home = tmp('cursor-install-home');
  mkdirSync(join(home, '.cursor'));
  const foreign = { command: '/opt/orca/hook.sh beforeSubmitPrompt' };
  writeFileSync(join(home, '.cursor', 'hooks.json'), JSON.stringify({ version: 1, other: 'kept',
    hooks: { beforeSubmitPrompt: [foreign, { command: 'sno rem-reflect recall --agent cursor --first-message', timeout: 2 }],
      stop: [{ command: '/opt/orca/hook.sh stop' }] } }));
  const bin = tmp('sno-bin');
  writeFileSync(join(bin, 'sno'), '#!/bin/sh\n', { mode: 0o755 });
  const env = { ...process.env, HOME: home, PATH: `${bin}:${process.env.PATH ?? ''}` };
  const install = () => spawnSync(process.execPath, [COMMAND, 'recall', 'install'], { encoding: 'utf8', env });
  assert.equal(install().status, 0);
  const second = install();
  assert.equal(second.status, 0, second.stderr);
  const file = JSON.parse(readFileSync(join(home, '.cursor', 'hooks.json'), 'utf8')) as Record<string, unknown> & { hooks: Record<string, unknown[]> };
  assert.equal(file.version, 1);
  assert.equal(file.other, 'kept');
  assert.deepEqual(file.hooks.sessionStart, [{ command: `'${bin}/sno' rem-reflect recall --agent cursor`, timeout: 15 }]);
  assert.deepEqual(file.hooks.beforeSubmitPrompt, [foreign, { command: `'${bin}/sno' rem-reflect recall --agent cursor --first-message`, timeout: 8 }],
    'the earlier bare-sno entry is replaced in place');
  assert.deepEqual(file.hooks.stop, [{ command: '/opt/orca/hook.sh stop' }]);

  const fresh = tmp('cursor-fresh-home');
  assert.equal(spawnSync(process.execPath, [COMMAND, 'recall', 'install'], { encoding: 'utf8', env: { ...env, HOME: fresh } }).status, 0);
  assert.equal(Object.keys((JSON.parse(readFileSync(join(fresh, '.cursor', 'hooks.json'), 'utf8')) as { hooks: object }).hooks).length, 2);
});

test('a Cursor labeling turn runs cursor-agent in the isolated home with the prompt on stdin and returns its result', () => {
  const home = tmp('cursor-user-home');
  mkdirSync(join(home, '.config', 'cursor'), { recursive: true });
  mkdirSync(join(home, '.local', 'share'), { recursive: true });
  writeFileSync(join(home, '.config', 'cursor', 'auth.json'), '{"accessToken":"t"}');
  const config = fixtureConfig({ cursor_root: tmp('cursor-projects') });
  const store = makeStore(config);
  const previousHome = process.env.HOME;
  process.env.HOME = home;
  try { assert.equal(run(store, new Date('2026-10-10T12:00:00Z'), 'u').code, 0); } finally { process.env.HOME = previousHome; }
  const loopHome = join(store, '.loop-home', 'cursor');
  // The login is a copy of auth.json on Linux; on macOS it lives in the login keychains, which are linked instead.
  if (process.platform === 'darwin') {
    assert.equal(readlinkSync(join(loopHome, 'Library', 'Keychains')), join(home, 'Library', 'Keychains'));
    assert.equal(existsSync(join(loopHome, '.config', 'cursor', 'auth.json')), false, 'no auth.json copy on macOS');
  } else {
    assert.equal(readFileSync(join(loopHome, '.config', 'cursor', 'auth.json'), 'utf8'), '{"accessToken":"t"}');
  }
  assert.equal(lstatSync(join(loopHome, '.local', 'share')).isSymbolicLink(), true);
  assert.equal(readlinkSync(join(loopHome, '.local', 'share')), join(home, '.local', 'share'));

  const bin = tmp('cursor-bin');
  const record = join(bin, 'call.json');
  writeFileSync(join(bin, 'cursor-agent'), `#!/usr/bin/env node
const fs = require('node:fs');
fs.writeFileSync(${JSON.stringify(record)}, JSON.stringify({ args: process.argv.slice(2), home: process.env.HOME, stdin: fs.readFileSync(0, 'utf8') }));
const helper = require('node:child_process').spawn('sleep', ['300'], { stdio: 'ignore' });
helper.unref();
fs.writeFileSync(${JSON.stringify(record)} + '.child', String(helper.pid));
if (process.env.FAKE_CURSOR === 'keychain') { process.stderr.write('Error: Your macOS login keychain is locked\\n'); process.exit(1); }
console.log(JSON.stringify(process.env.FAKE_CURSOR === 'error' ? { type: 'result', is_error: true, result: 'x' }
  : { type: 'result', subtype: 'success', is_error: false, result: '{"keep":true}', session_id: 's' }));
`);
  chmodSync(join(bin, 'cursor-agent'), 0o755);
  const previousPath = process.env.PATH;
  process.env.PATH = `${bin}:${previousPath ?? ''}`;
  try {
    const backend = new RealBackend(10_000, { loopHomeBase: join(store, '.loop-home') });
    assert.equal(backend.spawn({ cli: 'cursor', cwd: bin, input: 'label this session' }).stdout, '{"keep":true}');
    const call = JSON.parse(readFileSync(record, 'utf8')) as { args: string[]; home: string; stdin: string };
    assert.deepEqual(call.args, ['-p', '--trust', '--mode', 'ask', '--output-format', 'json']);
    assert.equal(call.home, loopHome);
    assert.equal(call.stdin, 'label this session');
    const helperPid = Number(readFileSync(`${record}.child`, 'utf8'));
    let helperState = '';
    const deadline = Date.now() + 1000;
    do {
      helperState = spawnSync('ps', ['-o', 'stat=', '-p', String(helperPid)], { encoding: 'utf8' }).stdout.trim();
      if (!helperState || helperState.startsWith('Z')) break;
      Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 10);
    } while (Date.now() < deadline);
    assert.equal(helperState === '' || helperState.startsWith('Z'), true, 'the helper is absent or terminated, never running');
    process.env.FAKE_CURSOR = 'error';
    assert.throws(() => backend.spawn({ cli: 'cursor', cwd: bin, input: 'x' }), (error: unknown) =>
      error instanceof BackendError && error.reason === 'labeler-invalid-response');
    process.env.FAKE_CURSOR = 'keychain';
    assert.throws(() => backend.spawn({ cli: 'cursor', cwd: bin, input: 'x' }), (error: unknown) =>
      error instanceof BackendError && error.reason === 'labeler-unavailable' && /Cursor CLI login unreadable \(keychain locked\)/.test(error.message));
  } finally {
    delete process.env.FAKE_CURSOR;
    process.env.PATH = previousPath;
  }
});

test('the cloud batch carries a cursor half only when a Cursor session is uploaded', () => {
  const config = fixtureConfig();
  const store = makeStore(config);
  const make = (agent: 'codex' | 'cursor', session: string): Trace => ({
    user_id: 'u', project_id: 'p', agent_id: agent, source_harness: agent, originator: agent,
    trace_id: `${session}.v1`, session_id: session, version: 1, source_path: '/source', source_line_range: [1, 2],
    source_mtime: Date.parse('2026-10-09T00:00:00Z'), skipped_records: 0, skipped_blocks: 0, redactions: 0, trivial: false,
    skills_loaded: [], records: [{ line_number: 2, source_line: 1, record: agent === 'codex'
      ? { type: 'response_item', payload: { type: 'message', role: 'assistant', content: [{ type: 'output_text', text: 'done' }] } }
      : { type: 'assistant', message: { role: 'assistant', content: [{ type: 'text', text: 'done' }] } } }],
  });
  const labelsFor = (traces: Trace[]) => new Map(traces.map(row => [`u/${row.agent_id}/${row.trace_id}`, {
    decision: 'keep' as const, outcome: 'fail' as const, reason: 'r', evidence: [], key_ranges: [], labeled_by: row.agent_id, model: 'm' }]));
  const codexOnly = [make('codex', 'x-1')];
  assert.deepEqual(buildCloudBatch(store, config, '20261010-0100', codexOnly, labelsFor(codexOnly), false).halves.map(half => half.harness), ['codex']);
  const both = [make('codex', 'x-1'), make('cursor', 'c-1')];
  const batch = buildCloudBatch(store, config, '20261010-0100', both, labelsFor(both), false);
  assert.deepEqual(batch.halves.map(half => half.harness), ['codex', 'cursor']);
  assert.deepEqual(batch.halves[1].sessions.map(row => row.trace_id), ['c-1.v1']);
});
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