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

View on GitHub
import {
  appendFileSync, chmodSync, closeSync, existsSync, fsyncSync, linkSync, mkdirSync, openSync,
  readFileSync, renameSync, unlinkSync, writeFileSync,
} from 'node:fs';
import { dirname, join } from 'node:path';
import { randomUUID } from 'node:crypto';
import { execFileSync } from 'node:child_process';
import { isObject, loadConfig } from './config.ts';
import type { Config } from './config.ts';

export type TerminalStatus = 'success' | 'no_action' | 'failed' | 'timed_out' | 'no_backend';
export interface RunStart { id: string; date: string }
export interface Terminal extends RunStart { status: TerminalStatus }
export interface Pending { failures: number; status: 'pending' | 'unparseable' }
export interface State {
  cursors: Record<string, number>;
  pending: Record<string, Pending>;
  last_start: RunStart | null;
  last_terminal: Terminal | null;
}
export interface Lock {
  pid: number;
  command: string;
  id: string;
}

export function emptyState(): State {
  return { cursors: {}, pending: {}, last_start: null, last_terminal: null };
}

export function privateDirectory(path: string): void {
  if (!existsSync(path)) {
    privateDirectory(dirname(path));
    mkdirSync(path, { mode: 0o700 });
  }
}

export function atomicWrite(path: string, bytes: string | Buffer): void {
  privateDirectory(dirname(path));
  const temporary = join(dirname(path), `.tmp-${randomUUID()}`);
  const fd = openSync(temporary, 'wx', 0o600);
  try { writeFileSync(fd, bytes); fsyncSync(fd); }
  finally { closeSync(fd); }
  try { renameSync(temporary, path); }
  finally { if (existsSync(temporary)) unlinkSync(temporary); }
}

export function writeJson(path: string, value: unknown): void {
  atomicWrite(path, `${JSON.stringify(value, null, 2)}\n`);
}

export function git(store: string, args: string[]): string {
  return execFileSync('git', [
    '-C', store, '-c', 'core.hooksPath=/dev/null', '-c', 'commit.gpgSign=false',
    '-c', 'user.name=rem-reflect', '-c', 'user.email=rem-reflect@localhost', ...args,
  ], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], timeout: 30_000, maxBuffer: 256 * 1024 * 1024 });
}

export function headRevision(store: string): string | undefined {
  if (!existsSync(join(store, '.git'))) return undefined;
  try { return git(store, ['rev-parse', '--verify', 'HEAD']).trim(); }
  catch { return undefined; }
}

export function readHead(store: string, path: string, revision: string | undefined = headRevision(store)): string | undefined {
  if (!revision) return undefined;
  const files = git(store, ['ls-tree', '-r', '--name-only', '-z', revision]).split('\0');
  if (!files.includes(path)) return undefined;
  return git(store, ['show', `${revision}:${path}`]);
}

function isStart(value: unknown): value is RunStart {
  return isObject(value) && typeof value.id === 'string' && /^\d{8}-\d{4}$/.test(value.id)
    && typeof value.date === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(value.date);
}

// Read what is readable and drop what is not. This file is the loop's own bookkeeping, so a single
// malformed entry is dropped so re-harvesting one session does not stop later runs.
export function parseState(text: string): State {
  const value: unknown = JSON.parse(text);
  const state = emptyState();
  if (!isObject(value)) return state;
  if (isObject(value.cursors)) {
    for (const [key, cursor] of Object.entries(value.cursors)) {
      if (typeof cursor === 'number' && Number.isFinite(cursor)) state.cursors[key] = cursor;
    }
  }
  if (isObject(value.pending)) {
    for (const [key, pending] of Object.entries(value.pending)) {
      if (!isObject(pending) || !['pending', 'unparseable'].includes(String(pending.status))) continue;
      const failures = typeof pending.failures === 'number' && Number.isInteger(pending.failures) && pending.failures > 0 ? pending.failures : 1;
      state.pending[key] = { failures, status: pending.status as Pending['status'] };
    }
  }
  if (isStart(value.last_start)) state.last_start = value.last_start;
  const terminal = value.last_terminal;
  if (isStart(terminal) && isObject(terminal)
    && ['success', 'no_action', 'failed', 'timed_out', 'no_backend'].includes(String(terminal.status))) {
    state.last_terminal = { ...terminal, status: terminal.status as TerminalStatus };
  }
  return state;
}

export function readState(store: string): State {
  const path = join(store, 'state.json');
  return existsSync(path) ? parseState(readFileSync(path, 'utf8')) : emptyState();
}

export function writeState(store: string, state: State): void {
  writeJson(join(store, 'state.json'), state);
}

export function initializeStore(store: string, config: Config, state: State): void {
  chmodSync(store, 0o700);
  for (const directory of ['raw', 'wiki/patterns', 'ledger', 'staging']) {
    privateDirectory(join(store, directory));
    chmodSync(join(store, directory), 0o700);
  }
  git(store, ['init', '--quiet']);
  if (!existsSync(join(store, '.gitignore'))) atomicWrite(join(store, '.gitignore'), 'run.lock\n.recovery-lock\n.tmp-*\n.loop-home/\n');
  if (!existsSync(join(store, 'config.json'))) writeJson(join(store, 'config.json'), config);
  if (!existsSync(join(store, 'state.json'))) writeState(store, state);
}

export function processAlive(pid: number): boolean {
  try { process.kill(pid, 0); return true; }
  catch (error) {
    if (isObject(error) && error.code === 'ESRCH') return false;
    return true;
  }
}

export function readLock(store: string): Lock | undefined {
  let text: string;
  try { text = readFileSync(join(store, 'run.lock'), 'utf8'); }
  catch (error) {
    if (isObject(error) && error.code === 'ENOENT') return undefined;
    throw error;
  }
  const value: unknown = JSON.parse(text);
  if (!isObject(value) || !Number.isInteger(value.pid) || typeof value.pid !== 'number' || value.pid <= 0
    || typeof value.command !== 'string' || typeof value.id !== 'string') throw new Error('run.lock: invalid holder');
  return { pid: value.pid, command: value.command, id: value.id };
}

// A lock whose holder is gone is stale. Delete it and let the next reflection run take over.
export function takeOverLock(store: string, lock: Lock): boolean {
  const prior = readLock(store);
  if (prior && !processAlive(prior.pid)) { try { unlinkSync(join(store, 'run.lock')); } catch { /* already gone */ } }
  return tryLock(store, lock);
}

export function tryLock(store: string, lock: Lock): boolean {
  const temporary = join(store, `.tmp-${randomUUID()}`);
  atomicWrite(temporary, `${JSON.stringify(lock)}\n`);
  try { linkSync(temporary, join(store, 'run.lock')); return true; }
  catch (error) {
    if (isObject(error) && error.code === 'EEXIST') return false;
    throw error;
  } finally { unlinkSync(temporary); }
}

export function releaseLock(store: string): void {
  const lock = readLock(store);
  if (lock?.pid !== process.pid) throw new Error('run.lock: ownership changed; refusing release');
  unlinkSync(join(store, 'run.lock'));
}

export function commitStore(store: string, message: string, command: string = 'run', files: string[] = []): boolean {
  try {
    if (command === 'run') {
      const owned = ['raw', 'wiki', 'ledger', 'staging', 'state.json', 'config.json', 'identity.json', '.gitignore']
        .filter(path => existsSync(join(store, path)));
      git(store, ['add', '--all', '--', ...owned]);
    }
    else if (files.length) {
      if (files.includes('ledger/usage.jsonl')) throw new Error('verdict command cannot stage ledger/usage.jsonl');
      git(store, ['add', '--', ...files]);
    }
    if (!git(store, ['diff', '--cached', '--name-only']).trim()) return false;
    git(store, ['commit', '--quiet', '-m', message]);
    return true;
  } catch (error) {
    const stderr = isObject(error) && typeof error.stderr === 'string' ? error.stderr : '';
    if (/index\.lock|another git process/.test(stderr)) return false;
    throw error;
  }
}
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