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/backend.ts

View on GitHub
import { spawnSync } from 'node:child_process';
import { randomUUID } from 'node:crypto';
import type { SpawnSyncOptionsWithStringEncoding } from 'node:child_process';
import { chmodSync, copyFileSync, existsSync, mkdirSync, rmSync, symlinkSync } from 'node:fs';
import { homedir } from 'node:os';
import { dirname, join } from 'node:path';
import { isObject } from './config.ts';
import type { Config } from './config.ts';
import { message } from './text.ts';
import type { Harness } from './identity.ts';
import { CeilingReached, ceilings } from './session.ts';

export type Cli = 'claude' | 'codex' | 'hermes' | 'openclaw' | 'cursor';
// `kind` records the call role without inferring it from the prompt shape.
export interface SpawnRequest { cli: Cli; model?: string; provider?: string; cwd: string; input: string; kind?: 'labeler' | 'model' | 'preflight' }
export interface Backend {
  spawn(request: SpawnRequest): { stdout: string };
  // A trivial health check of the CLI (optionally under a model). True when the CLI answered.
  preflight?(cli: Cli, cwd: string, model?: string): boolean;
}
export class BackendError extends Error {
  reason: 'labeler-timeout' | 'labeler-unavailable' | 'labeler-invalid-response';
  // `detail` (a spawn error code, or the exit status and a stderr head) goes into the message only, so
  // a log line explains the failure while `reason` stays the exact token labels and filters match on.
  constructor(reason: BackendError['reason'], detail?: string) { super(detail ? `${reason} (${detail})` : reason); this.reason = reason; }
}
export function otherCli(half: Harness): Cli { return half === 'claude-code' ? 'codex' : 'claude'; }

// Kill a child's whole process group so no grandchild outlives the run. A detached child is
// its own group leader, so its pgid equals its pid; -pid signals every member still alive.
function killGroup(pid: number | undefined): void {
  if (!pid) return;
  try { process.kill(-pid, 'SIGKILL'); } catch { /* the group is already gone */ }
}

// Only Cursor needs a temporary home; the other agents keep the mainline login mechanism.
export function seedLoopHomes(store: string, config: Config, log: string[]): void {
  if (existsSync(config.cursor_root)) seedCursorHome(join(store, '.loop-home', 'cursor'), log);
}

// The build contract's isolated Cursor home, measured to fire none of the user's Cursor hooks and to keep the run's
// transcript out of the real ~/.cursor: the login (a copy of ~/.config/cursor/auth.json on Linux, a link to the login
// keychains on macOS) and a link to ~/.local/share, where cursor-agent is installed.
function seedCursorHome(target: string, log: string[]): void {
  const home = homedir();
  const links = ['.local/share', ...(process.platform === 'darwin' ? ['Library/Keychains'] : [])];
  for (const part of links) {
    mkdirSync(dirname(join(target, part)), { recursive: true, mode: 0o700 });
    rmSync(join(target, part), { force: true });
    symlinkSync(join(home, part), join(target, part));
  }
  if (process.platform === 'darwin') return;
  const source = join(home, '.config', 'cursor', 'auth.json');
  const login = join(target, '.config', 'cursor', 'auth.json');
  if (!existsSync(source)) { rmSync(login, { force: true }); log.push(message('credentialMissing', { cli: 'cursor', path: source })); return; }
  mkdirSync(dirname(login), { recursive: true, mode: 0o700 });
  copyFileSync(source, login);
  chmodSync(login, 0o600);
}

// The real CLI backend. Each call runs in its own process group with a per-call deadline;
// on timeout the group is killed and a `per-call-timeout` ceiling is thrown so the run stops with no
// child left behind. Each turn uses the owner's own login in place: a copied login that renews invalidates
// the original, so the loop never copies one.
export class RealBackend implements Backend {
  private readonly perCallMs: number;
  private readonly loopHomeBase: string | undefined;
  constructor(perCallMs: number = ceilings.perCallMs, options: { loopHomeBase?: string } = {}) {
    this.perCallMs = perCallMs;
    this.loopHomeBase = options.loopHomeBase;
  }
  // A trivial health check: a one-word prompt under a short deadline. The CLI is healthy when the
  // CLI exits zero; a timeout or non-zero exit is a failed preflight.
  preflight(cli: Cli, cwd: string, model?: string): boolean {
    try { this.spawn({ cli, model, cwd, input: 'reply with ok', kind: 'preflight' }); return true; }
    catch (error) { if (error instanceof CeilingReached) throw error; return false; }
  }
  // Keeps the owner's interactive setup out of a turn and saves no session for the next night to harvest.
  // Claude loads no user, project or local settings (hooks, plugins, output style, model pin; the turn's working
  // directory has no local settings) and no MCP server. Codex loads no config.toml (hook trust, MCP, model pin),
  // so no hook runs.
  isolation(cli: Cli): string[] {
    return cli === 'claude'
      ? ['--setting-sources', 'local', '--strict-mcp-config', '--no-session-persistence']
      : ['--ignore-user-config', '--ephemeral'];
  }
  // The prompt goes to the CLI on stdin, never as an argument: a reading-phase prompt bundles several
  // traces and pages (hundreds of KB) and one argv element is capped at 128 KB on Linux (E2BIG).
  // `claude -p` with no positional prompt reads stdin; `codex exec -` reads stdin.
  spawn({ cli, model, provider, cwd, input }: SpawnRequest): { stdout: string } {
    const stationAgent = cli === 'hermes' || cli === 'openclaw';
    if (stationAgent) input = `[sno-oneshot] Station one-shot run, not a user session.\n${input}`;
    const args = cli === 'claude' ? ['-p', '--output-format', 'text', '--allowedTools', 'Read,Grep,Glob', ...this.isolation(cli)]
      : cli === 'codex' ? ['exec', '--skip-git-repo-check', ...this.isolation(cli), '-']
        : cli === 'hermes' ? ['chat', '--query-file', '-', '--oneshot', '-Q', '--ignore-user-config', '--ignore-rules']
          : cli === 'cursor' ? ['-p', '--trust', '--mode', 'ask', '--output-format', 'json']
            : ['agent', '--agent', 'main', '--session-id', `sno-oneshot-${randomUUID()}`, '-m', input, '--json'];
    if (model) args.push(cli === 'hermes' ? '-m' : '--model', model);
    if (cli === 'hermes' && provider) args.push('--provider', provider);
    const options = {
      cwd, env: cli === 'cursor' && this.loopHomeBase ? { ...process.env, HOME: join(this.loopHomeBase, 'cursor') } : undefined, encoding: 'utf8', input,
      timeout: stationAgent ? Math.min(this.perCallMs, 280_000) : this.perCallMs, killSignal: 'SIGKILL', detached: true,
      stdio: ['pipe', 'pipe', 'pipe'], maxBuffer: 64 * 1024 * 1024,
    } satisfies SpawnSyncOptionsWithStringEncoding & { detached: boolean };
    const child = spawnSync(cli === 'cursor' ? 'cursor-agent' : cli, args, options);
    // cursor-agent leaves a language server running after it exits (observed); its group goes with it.
    if (cli === 'cursor') killGroup(child.pid);
    if (child.error) {
      if (isObject(child.error) && child.error.code === 'ETIMEDOUT') { killGroup(child.pid); throw new CeilingReached('per-call-timeout'); }
      throw new BackendError('labeler-unavailable', isObject(child.error) && typeof child.error.code === 'string' ? child.error.code : String(child.error));
    }
    // A non-zero exit is a failed CLI, not usable output: a CLI that is not logged in exits non-zero
    // ("Not logged in" for Claude, HTTP 401 for Codex), which must fail preflight so its harness degrades.
    if (child.status !== 0) {
      // Over SSH on macOS the Cursor CLI cannot open the login keychain; that is a login failure, not a model failure.
      const detail = cli === 'cursor' && /keychain is locked/.test(`${child.stderr}${child.stdout}`) ? 'Cursor CLI login unreadable (keychain locked)'
        : `exit ${child.status}: ${(child.stderr ?? '').trim().split('\n')[0].slice(0, 200)}`;
      throw new BackendError('labeler-unavailable', detail);
    }
    if (cli === 'cursor') {
      let answer: unknown;
      try { answer = JSON.parse(child.stdout); } catch { throw new BackendError('labeler-invalid-response', 'cursor-agent: output is not JSON'); }
      if (!isObject(answer) || answer.is_error === true || typeof answer.result !== 'string') {
        throw new BackendError('labeler-invalid-response', 'cursor-agent: no successful result');
      }
      return { stdout: answer.result };
    }
    if (cli !== 'openclaw') return { stdout: child.stdout ?? '' };
    let answer: unknown;
    try { answer = JSON.parse(child.stdout); }
    catch { throw new BackendError('labeler-invalid-response', 'openclaw: invalid JSON'); }
    if (!isObject(answer) || answer.status !== 'ok' || !isObject(answer.result) || !Array.isArray(answer.result.payloads)) {
      throw new BackendError('labeler-invalid-response', 'openclaw: no successful result.payloads');
    }
    const parts = answer.result.payloads.filter(isObject);
    if (parts.some(part => part.isError === true)) throw new BackendError('labeler-unavailable', 'openclaw: error payload');
    const stdout = parts.map(part => typeof part.text === 'string' ? part.text : '').filter(Boolean).join('\n');
    if (!stdout) throw new BackendError('labeler-invalid-response', 'openclaw: empty answer');
    return { stdout };
  }
}
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