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

View on GitHub
import { reflectionFiles, limits, isObject } from './config.ts';
import { message } from './text.ts';
import { existsSync, readFileSync, readdirSync } from 'node:fs';
import { join } from 'node:path';
import { BackendError } from './backend.ts';
import { CeilingReached } from './session.ts';
import type { Backend, Cli } from './backend.ts';
import type { Harness } from './identity.ts';
import { sameSession, traceKey, validateEvidence, validateRange } from './evidence.ts';
import type { Evidence } from './evidence.ts';
import type { Trace } from './harvest.ts';
import { checkContract, firstObject, reference } from './model-json.ts';
import { loadRenderBudgets, renderHeader, renderTrace, truncate } from './render.ts';
import { readCalls } from './calls.ts';
import { loadLocalSettings } from './local-settings.ts';
import { privateDirectory, writeJson } from './store.ts';

export type Outcome = 'success' | 'fail' | 'unknown';
export interface KeyRange { line_start: number; line_end: number; why: string }
export interface Label { decision: 'keep' | 'drop'; outcome: Outcome; reason: string; evidence: Evidence[]; key_ranges: KeyRange[]; labeled_by: string; model: string }
export interface LabelOutput extends Omit<Label, 'labeled_by' | 'model'> { notes: string }

export function labelPaths(store: string): Map<string, string> {
  const paths = new Map<string, string>();
  function walk(directory: string): void {
    if (!existsSync(directory)) return;
    for (const entry of readdirSync(directory, { withFileTypes: true })) {
      const path = join(directory, entry.name);
      if (entry.isDirectory()) walk(path);
      else if (/\.v\d+\.json$/.test(entry.name)) {
        const trace: Trace = JSON.parse(readFileSync(path, 'utf8'));
        paths.set(traceKey(trace), path.replace(/\.json$/, '.label.json'));
      }
    }
  }
  walk(join(store, reflectionFiles.raw));
  return paths;
}
export function readLabels(store: string): Map<string, Label> {
  const labels = new Map<string, Label>();
  for (const [key, path] of labelPaths(store)) if (existsSync(path)) labels.set(key, JSON.parse(readFileSync(path, 'utf8')));
  return labels;
}
export function validateLabel(value: unknown, trace: Trace, earlier: readonly Trace[]): LabelOutput {
  checkContract(value, 'labeler');
  // The shipped contract checks the complete external shape before this assertion.
  const output = value as LabelOutput;
  validateEvidence(output.evidence, [trace, ...earlier]);
  for (const range of output.key_ranges) validateRange(trace, range.line_start, range.line_end);
  return output;
}
function previousHeader(trace: Trace, all: readonly Trace[], labels: ReadonlyMap<string, Label>): { traces: Trace[]; text: string } {
  const traces = all.filter(item => sameSession(trace, item) && item.version < trace.version).sort((a, b) => a.version - b.version);
  const previous = traces.map(item => ({ trace_id: item.trace_id,
    typed_lines: renderTrace(item, loadRenderBudgets()).records.filter(record => {
      if (record.harness_shaped) return false;
      const source = item.records.find(row => row.line_number === record.line_number);
      if (!source) return false;
      const payload = item.agent_id === 'codex' ? source.record.payload : source.record.message;
      if (!payload || typeof payload !== 'object' || !('role' in payload) || payload.role !== 'user') return false;
      const content = 'content' in payload ? payload.content : undefined;
      return typeof source.user_text === 'string' || typeof content === 'string'
        || (Array.isArray(content) && content.every(block => block && typeof block === 'object'
          && 'type' in block && ['text', 'input_text', 'output_text'].includes(String(block.type))));
    }),
    label: labels.get(traceKey(item)) ?? null }));
  return { traces, text: truncate(JSON.stringify(previous), limits.chunkCharacters) };
}
export function eventLines(trace: Trace): Set<number> {
  const lines = new Set(readCalls(trace).filter(call => call.failed).map(call => call.line_end));
  const rendered = renderTrace(trace, loadRenderBudgets());
  const records = new Map(trace.records.map(record => [record.line_number, record]));
  for (const row of rendered.records) {
    const item = records.get(row.line_number);
    const message = item?.record[trace.agent_id === 'codex' ? 'payload' : 'message'];
    if (!isObject(message) || message.role !== 'user' || row.harness_shaped) continue;
    if (Array.isArray(message.content) && message.content.some(block => isObject(block) && block.type === 'tool_result')) continue;
    lines.add(row.line_number);
  }
  return lines;
}

function labelTrace(trace: Trace, all: readonly Trace[], labels: ReadonlyMap<string, Label>, backend: Backend, cwd: string, cli: Cli,
  maxChars: number, windowLines: number): LabelOutput {
  const previous = previousHeader(trace, all, labels);
  const prefix = `${reference('labeler.md')}\n${reference('labeler.schema.json')}\n${renderHeader(trace)}\nprevious_versions: ${previous.text}\n`;
  const rendered = renderTrace(trace, loadRenderBudgets());
  const events = eventLines(trace);
  const ordered = [...events].sort((a, b) => a - b);
  let event = 0;
  const full = rendered.body.length + prefix.length <= maxChars;
  const selected = rendered.records.filter(row => {
    if (full || !ordered.length) return true;
    while (event < ordered.length && ordered[event] < row.line_number - windowLines) event++;
    return ordered[event] <= row.line_number + windowLines;
  });
  const inputs: string[] = [];
  let body = '';
  for (const row of selected) {
    const line = row.text.length > maxChars - prefix.length ? truncate(row.text, maxChars - prefix.length - 40) : row.text;
    if (body && prefix.length + body.length + line.length > maxChars) { inputs.push(prefix + body); body = ''; }
    body += line;
  }
  if (body || !inputs.length) inputs.push(prefix + body);
  const outputs: LabelOutput[] = [];
  for (const [index, input] of inputs.entries()) {
    writeJson(join(cwd, reflectionFiles.labelerInput), { trace_id: trace.trace_id, window: index, input });
    const stdout = backend.spawn({ cli, cwd, input, kind: 'labeler' }).stdout;
    writeJson(join(cwd, reflectionFiles.labelerOutput), { trace_id: trace.trace_id, window: index, stdout });
    try { outputs.push(validateLabel(firstObject(stdout), trace, previous.traces)); }
    catch (error) { throw new BackendError('labeler-invalid-response', String(error)); }
  }
  return { decision: outputs.some(output => output.decision === 'keep') ? 'keep' : 'drop',
    outcome: outputs.some(output => output.outcome === 'fail') ? 'fail'
      : outputs.some(output => output.outcome === 'success') ? 'success' : 'unknown',
    reason: outputs.map(output => output.reason).join('; '), notes: outputs.map(output => output.notes).join('; '),
    evidence: outputs.flatMap(output => output.evidence), key_ranges: outputs.flatMap(output => output.key_ranges) };
}
export interface LabelWrite { path: string; label: Label }
// Return every new decision for the caller to persist beside its trace before cloud upload.
// With `labelerOn` false no CLI runs: each pending session is kept with an unknown outcome, the same
// shape a failed labeler leaves, so the upload can still send it.
export function labelHalf(store: string, runId: string, half: Harness | null, cli: Cli | null, traces: readonly Trace[],
  backend: Backend, log: string[], allTraces: readonly Trace[] = traces, labelerOn = true): { labels: Map<string, Label>; writes: LabelWrite[] } {
  const working = readLabels(store);
  const targets = labelPaths(store);
  const labels = new Map<string, Label>();
  const writes: LabelWrite[] = [];
  const settings = loadLocalSettings(store, log);
  const pending = traces.filter(item => (half === null || item.agent_id === half) && !working.get(traceKey(item))?.decision)
    .map(trace => ({ trace, priority: eventLines(trace).size }))
    .sort((a, b) => b.priority - a.priority).map(item => item.trace);
  const available = new Map<Cli, boolean>();
  for (const trace of pending) {
    const selectedCli: Cli = cli ?? (trace.agent_id === 'claude-code' ? 'claude' : trace.agent_id);
    const key = traceKey(trace);
    const path = targets.get(key);
    if (!path) throw new Error(message('rawPathMissing', { key }));
    let label: Label;
    if (!labelerOn) {
      label = { decision: 'keep', outcome: 'unknown', reason: 'labeler-off', evidence: [], key_ranges: [], labeled_by: '', model: '' };
      writes.push({ path, label });
      labels.set(key, label); working.set(key, label);
      continue;
    }
    const cwd = join(store, reflectionFiles.staging, runId, trace.agent_id);
    privateDirectory(cwd);
    if (!available.has(selectedCli)) available.set(selectedCli, !backend.preflight || backend.preflight(selectedCli, cwd));
    try {
      if (!available.get(selectedCli)) throw new BackendError('labeler-unavailable');
      const output = labelTrace(trace, allTraces, working, backend, cwd, selectedCli,
        settings.labeler_input_max_chars, settings.labeler_event_window_lines);
      const { notes: _notes, ...fields } = output;
      label = { ...fields, labeled_by: selectedCli, model: '' };
    } catch (error) {
      if (!(error instanceof BackendError) && !(error instanceof CeilingReached)) throw error;
      const reason = error instanceof BackendError ? error.reason : error.ceiling;
      label = { decision: 'keep', outcome: 'unknown', reason, evidence: [], key_ranges: [], labeled_by: selectedCli, model: '' };
      log.push(`${trace.trace_id}: ${label.reason}; labeler_${selectedCli}`);
    }
    writes.push({ path, label });
    labels.set(key, label); working.set(key, label);
  }
  return { labels, writes };
}
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 CodeCodexVerifiedInstall
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