Docs/Skills and code/skill script-cohort-analysis

.claude/skills/script-cohort-analysis/scripts/ledger.js

Code38 lines1.9 KBSkill: script-cohort-analysis

What the file says about itself

Hypothesis ledger: post-hoc ideas become pre-registered tests on the NEXT cohort. node ledger.js list [--ledger <path>] node ledger.js add --ledger <path> --statement "..." --question "..." [--direction 1|-1] [--origin <runDir>] node…

#!/usr/bin/env node
// Hypothesis ledger: post-hoc ideas become pre-registered tests on the NEXT cohort.
//   node ledger.js list   [--ledger <path>]
//   node ledger.js add    --ledger <path> --statement "..." --question "..." [--direction 1|-1] [--origin <runDir>]
//   node ledger.js retire --ledger <path> --id H-003 --reason "..."
const fs = require('fs');
const path = require('path');
const { readJson, writeJson, parseArgs } = require('./lib');

const [cmd] = process.argv.slice(2);
const args = parseArgs(process.argv.slice(3));
const ledgerPath = path.resolve(args.ledger || '_script_ledger.json');
const ledger = fs.existsSync(ledgerPath) ? readJson(ledgerPath) : { hypotheses: [] };

if (cmd === 'add') {
  if (!args.statement || !args.question) { console.error('--statement and --question are required'); process.exit(1); }
  const id = `H-${String(ledger.hypotheses.length + 1).padStart(3, '0')}`;
  ledger.hypotheses.push({
    id, statement: args.statement, rater_question: args.question,
    direction: Number(args.direction || 1), origin: args.origin || null,
    status: 'untested', created_at: new Date().toISOString(), tests: [],
  });
  writeJson(ledgerPath, ledger);
  console.log(`Added ${id} to ${ledgerPath}`);
} else if (cmd === 'retire') {
  const h = ledger.hypotheses.find((x) => x.id === args.id);
  if (!h) { console.error(`no ${args.id}`); process.exit(1); }
  h.status = 'retired'; h.retired_reason = args.reason || '';
  writeJson(ledgerPath, ledger);
  console.log(`Retired ${args.id}`);
} else {
  if (!ledger.hypotheses.length) console.log(`(empty ledger at ${ledgerPath})`);
  for (const h of ledger.hypotheses) {
    const t = (h.tests || []).map((x) => `${path.basename(x.cohort)}:${x.verdict}(rho ${x.rho === null ? '—' : x.rho.toFixed(2)})`).join(', ');
    console.log(`${h.id} [${h.status}] ${h.statement}\n    tests: ${t || 'none yet'}`);
  }
}

Shown as it is in the repository at build time (2026-11-03); the home directory appears as <home>. If this page and the file differ, the file is right. Back to the catalogue.