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

View on GitHub
import { reflectionFiles, skillRoots } from './config.ts';
import type { Config } from './config.ts';
import { basename, join } from 'node:path';
import { message } from './text.ts';
import { payloadInfo } from './catalogue.ts';
import { traceKey } from './evidence.ts';
import { existingTraces } from './harvest.ts';
import type { Trace } from './harvest.ts';
import { readLabels } from './labeler.ts';
import type { Label } from './labeler.ts';
import { readLedger } from './ledger.ts';
import { readLessons } from './lessons.ts';
import { readPages } from './pages.ts';
import { observe } from './observe.ts';

const DAY = 86_400_000;
interface Counts { traces: number; fail: number; unknown: number }
function countsText(c: Counts): string { return `{traces: ${c.traces}, fail: ${c.fail}, unknown: ${c.unknown}}`; }

// count trace versions that load `payload` and whose session started in [lo, hi), split by
// the labeler's outcome. `skills_loaded` holds the resolved payload path, so matching on the adopted
// payload path picks the exact payload, not the unit directory or a sibling payload.
function countLoaded(traces: readonly Trace[], labels: ReadonlyMap<string, Label>, payloads: readonly string[], lo: number, hi: number): Counts {
  const counts: Counts = { traces: 0, fail: 0, unknown: 0 };
  for (const trace of traces) {
    if (trace.source_mtime < lo || trace.source_mtime >= hi || !payloads.some(payload => trace.skills_loaded.includes(payload))) continue;
    counts.traces++;
    const outcome = labels.get(traceKey(trace))?.outcome ?? 'unknown';
    if (outcome === 'fail') counts.fail++;
    if (outcome === 'unknown') counts.unknown++;
  }
  return counts;
}

export interface Adoption { unit: string; id: string; target: string; at: number }
// Every unit this loop adopted into: an Accepted skill proposal, or an accepted skill-scoped lesson.
export function adoptions(ledger: readonly Record<string, unknown>[]): Adoption[] {
  const result: Adoption[] = [];
  for (const row of ledger) {
    const at = typeof row.at === 'string' ? Date.parse(row.at) : NaN;
    if (row.type === 'verdict' && row.verdict === 'Accepted' && typeof row.target === 'string' && Number.isFinite(at)) {
      result.push({ unit: basename(row.target), id: String(row.proposal_id ?? ''), target: row.target, at });
    }
    if (row.type === 'lesson-verdict' && row.status === 'accepted' && row.adopted === true && typeof row.target === 'string' && Number.isFinite(at)) {
      result.push({ unit: basename(row.target), id: String(row.lesson_id ?? ''), target: row.target, at });
    }
  }
  return result;
}

// the Skill impact subsection and the proposer's outcome summary share this shape.
export function skillImpact(roots: readonly string[], traces: readonly Trace[], labels: ReadonlyMap<string, Label>,
  ledger: readonly Record<string, unknown>[]): { unit: string; id: string; loaded_before: Counts; loaded_after: Counts }[] {
  return adoptions(ledger).map(adoption => {
    const payloads = roots.map(root => join(root, adoption.unit));
    const name = payloads.map(path => payloadInfo(path).name).find(Boolean);
    return {
      unit: name || adoption.unit, id: adoption.id,
      loaded_before: countLoaded(traces, labels, payloads, adoption.at - 14 * DAY, adoption.at),
      loaded_after: countLoaded(traces, labels, payloads, adoption.at, Number.MAX_SAFE_INTEGER),
    };
  });
}

// The last verdict recorded for a proposal id, with the date it was set.
function lastVerdict(ledger: readonly Record<string, unknown>[], id: string): { verdict: string; at: number; had: Set<string> } | undefined {
  const rows = ledger.filter(row => row.type === 'verdict' && row.proposal_id === id);
  if (!rows.length) return undefined;
  const last = rows[rows.length - 1];
  return { verdict: String(last.verdict), at: typeof last.at === 'string' ? Date.parse(last.at) : 0, had: new Set(rows.map(row => String(row.verdict))) };
}

// a TBD proposal is flagged when, since its verdict, a page was created or patched whose
// skill_target is the unit or a `fail` trace lists the unit in skills_loaded.
function newEvidence(config: Config, traces: readonly Trace[], labels: ReadonlyMap<string, Label>,
  target: string, since: number, pages: readonly { skill_target: string | null; last_seen: string }[]): string[] {
  const ids: string[] = [];
  const targets = skillRoots(config).map(root => join(root, basename(target)));
  for (const trace of traces) {
    if (trace.source_mtime <= since || !targets.some(path => trace.skills_loaded.includes(path))) continue;
    if ((labels.get(traceKey(trace))?.outcome ?? 'unknown') === 'fail') ids.push(trace.trace_id);
  }
  for (const page of pages) {
    if (page.skill_target === target && Date.parse(page.last_seen) > since) ids.push('page');
  }
  return ids;
}

export interface ReportInput {
  store: string; config: Config; runId: string; notice: string; ceiling?: string | null;
  labelerLines: readonly string[]; harvested: number; reflectionReport: readonly string[];
}
export function buildReport(input: ReportInput): string {
  const { store, config } = input;
  const ledger = readLedger(store);
  const labels = readLabels(store);
  const traces = existingTraces(store, () => false);
  const lessons = readLessons(store);
  const pages = readPages(store).map(page => ({ skill_target: page.skill_target, last_seen: page.last_seen }));

  // TBD queue: proposals whose latest verdict is TBD, then lessons parked at tbd.
  const tbd: string[] = [];
  const proposalIds = [...new Set(ledger.filter(row => row.type === 'proposal').map(row => String(row.proposal_id)))];
  for (const id of proposalIds) {
    const last = lastVerdict(ledger, id);
    if (!last || last.verdict !== 'TBD') continue;
    const proposal = ledger.filter(row => row.type === 'proposal' && row.proposal_id === id).pop()!;
    const target = String(proposal.target ?? '');
    const ids = target ? newEvidence(config, traces, labels, target, last.at, pages) : [];
    tbd.push(message('tbdProposalLine', { id, kind: String(proposal.kind ?? ''), target,
      evidence: ids.length ? message('tbdNewEvidence', { ids: ids.join(', ') }) : '' }));
  }
  for (const lesson of lessons.filter(row => row.status === 'tbd')) {
    const reason = String(ledger.filter(row => row.type === 'lesson-verdict' && row.lesson_id === lesson.lesson_id).pop()?.reason ?? '');
    tbd.push(message('tbdLessonLine', { id: lesson.lesson_id, status: 'tbd', reason, evidence: '' }));
  }

  // Skill impact subsection.
  const impactRows = skillImpact(skillRoots(config), traces, labels, ledger);
  for (const row of new Map(impactRows.map(row => [row.unit, row])).values()) {
    observe('rsi.impact', { level: 'user', skill_name: row.unit,
      before_sessions: row.loaded_before.traces, before_failures: row.loaded_before.fail,
      after_sessions: row.loaded_after.traces, after_failures: row.loaded_after.fail,
    }, join(store, reflectionFiles.staging, input.runId, reflectionFiles.runLog));
  }
  const impact = impactRows.map(row =>
    message('skillImpactLine', { unit: row.unit, id: row.id, before: countsText(row.loaded_before), after: countsText(row.loaded_after) }));

  // Re-check list: proposals adopted then re-parked, and lessons under review.
  const recheck: string[] = [];
  for (const id of proposalIds) {
    const last = lastVerdict(ledger, id);
    if (last && last.verdict === 'TBD' && last.had.has('Accepted')) recheck.push(message('recheckProposal', { id, status: 'TBD' }));
  }
  for (const lesson of lessons.filter(row => row.status === 'under_review')) recheck.push(message('recheckLesson', { id: lesson.lesson_id }));

  // status block order: interruption notice, then the ceiling that stopped the run.
  const lines = [
    ...(input.notice ? [input.notice, ''] : []),
    ...(input.ceiling ? [message('ceilingStopped', { ceiling: input.ceiling }), ''] : []),
    `# Run ${input.runId}`, '',
    ...input.labelerLines, ...(input.labelerLines.length ? [''] : []),
    `Harvested trace versions: ${input.harvested}`, '',
    ...input.reflectionReport,
    message('tbdHeading'), ...(tbd.length ? tbd : [message('none')]), '',
    message('skillImpactHeading'), ...(impact.length ? impact : [message('none')]), '',
    message('recheckHeading'), ...(recheck.length ? recheck : [message('none')]), '',
  ];
  return lines.join('\n');
}
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