@rungs/cli 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/cli.ts", "../src/manifest.ts", "../src/glob.ts", "../src/detect.ts", "../src/add.ts", "../src/substitute.ts", "../src/render.ts", "../src/check.ts", "../src/engines.ts", "../src/selftest.ts", "../src/engines2.ts", "../src/engines3.ts", "../src/lifecycle.ts", "../src/explain.ts", "../src/backlog.ts"],
4
- "sourcesContent": ["#!/usr/bin/env node\nimport { fileURLToPath } from 'node:url';\nimport { dirname, join, resolve } from 'node:path';\nimport { auditModules, loadAllModules } from './manifest.ts';\nimport { detect, scanRepo } from './detect.ts';\nimport { addModule, adoptableGates, blockedByParadigm, registerGates, resolveInstallOrder, writeInstallRecord } from './add.ts';\nimport { render, writeReport, type Harness } from './render.ts';\nimport { resolveParams } from './substitute.ts';\nimport { appendLedger, type GateRun, ledgerQuestions, loadRegistry, runGates, UnknownTierError } from './check.ts';\nimport { applyUpgrade, eject, planUpgrade, PROFILES, readRecord, setupGit } from './lifecycle.ts';\nimport { explain, IN_SCOPE as EXPLAINABLE } from './explain.ts';\nimport { applyArchive, planArchive } from './backlog.ts';\nimport { existsSync } from 'node:fs';\nimport type { DetectResult, Manifest } from './types.ts';\n\nconst HERE = dirname(fileURLToPath(import.meta.url));\nconst MODULES = join(HERE, '..', 'modules');\n\nconst c = {\n dim: (s: string) => `\\x1b[2m${s}\\x1b[0m`,\n bold: (s: string) => `\\x1b[1m${s}\\x1b[0m`,\n red: (s: string) => `\\x1b[31m${s}\\x1b[0m`,\n yellow: (s: string) => `\\x1b[33m${s}\\x1b[0m`,\n green: (s: string) => `\\x1b[32m${s}\\x1b[0m`,\n cyan: (s: string) => `\\x1b[36m${s}\\x1b[0m`,\n};\n\nconst STATE_LABEL: Record<DetectResult['state'], string> = {\n absent: c.dim('absent'),\n 'ours-current': c.green('ours'),\n 'ours-diverged': c.yellow('diverged'),\n theirs: c.cyan('theirs'),\n paradigm: c.yellow('paradigm'),\n unknown: c.red('unknown'),\n};\n\nfunction cmdModules(showParams = false) {\n const mods = loadAllModules(MODULES);\n console.log(c.bold(`\\n${mods.length} modules\\n`));\n for (const m of mods) {\n const deps = m.requires.length ? c.dim(` \u2190 ${m.requires.join(', ')}`) : '';\n console.log(` ${c.bold(m.name.padEnd(14))} rung ${m.rung}${deps}`);\n console.log(` ${' '.repeat(14)} ${c.dim(m.summary)}`);\n // Rendered from the manifest at the moment it is asked for, never written down. A committed\n // parameter table would be correct the day it was generated and silently wrong the day a\n // default moved \u2014 which is the failure this flag exists to answer (WI-006).\n if (!showParams) continue;\n for (const [name, spec] of Object.entries(m.params)) {\n const shown = spec.default === undefined ? c.dim('(none)') : JSON.stringify(spec.default);\n const notes = [\n spec.allowed ? `one of ${spec.allowed.map(String).join(' \u00B7 ')}` : '',\n // Behavioural parameters never appear as {{token}}, so a reader hunting for one in a\n // template would conclude the parameter was dead. Say so where they meet it.\n spec.consumed_by ? `behavioural \u2014 changes what \\`${spec.consumed_by}\\` does, not a template` : '',\n spec.required ? 'required' : '',\n ].filter(Boolean);\n console.log(` ${' '.repeat(14)} ${c.cyan(`${m.name}.${name}`.padEnd(30))} ${c.dim('=')} ${shown}`);\n if (spec.description) console.log(` ${' '.repeat(16)} ${c.dim(firstSentence(spec.description))}`);\n for (const n of notes) console.log(` ${' '.repeat(16)} ${c.dim(n)}`);\n }\n if (Object.keys(m.params).length) console.log();\n }\n if (showParams) {\n console.log(c.dim(' Set one with `--set module.param=value` on `add` or `init`; either spelling works.'));\n console.log(c.dim(' Resolved values are recorded in `.ai/rungs.toml`. See docs/design/parameters.md.\\n'));\n }\n\n const issues = auditModules(mods);\n console.log();\n if (issues.length === 0) {\n console.log(c.green(' audit clean') + c.dim(' \u2014 every parameter accounted for; every gate has a table, a why, and a declared applicability'));\n } else {\n console.log(c.red(` ${issues.length} issue(s):`));\n for (const i of issues) console.log(` ${c.yellow(i.module)} ${c.dim(i.kind)} \u2014 ${i.detail}`);\n }\n console.log();\n return issues.length === 0 ? 0 : 1;\n}\n\nfunction cmdDoctor(target: string, doExplain = false) {\n const root = resolve(target);\n const mods = loadAllModules(MODULES);\n console.log(c.bold(`\\nrungs doctor \u2014 ${root}\\n`));\n\n const files = scanRepo(root);\n const record = readRecord(root);\n console.log(\n c.dim(` scanned ${files.length} files`) +\n (record ? c.dim(` \u00B7 installed ${Object.keys(record.modules).length} module(s)`) : c.dim(' \u00B7 not a rungs repo')) +\n '\\n',\n );\n\n const params = resolveParams(mods, Object.fromEntries(\n Object.entries(record?.modules ?? {}).flatMap(([n, e]) => (e.params ? [[n, e.params]] : [])),\n ), root);\n const skillsDir = record?.harnesses.includes('claude') === false ? '.agents/skills' : '.claude/skills';\n const results = mods.map((m) => {\n const installed = record?.modules[m.name];\n return detect(m, root, files, installed ? { ...installed, skillsDir, params_all: params } : undefined);\n });\n const byState = (s: DetectResult['state']) => results.filter((r) => r.state === s);\n\n for (const r of results) {\n const mod = mods.find((m) => m.name === r.module)!;\n const line = ` ${r.module.padEnd(14)} ${STATE_LABEL[r.state]}`;\n if (r.state === 'absent') {\n console.log(c.dim(line));\n continue;\n }\n console.log(line);\n if (r.ours) {\n const parts = [`v${r.ours.version}`, `${r.ours.current.length} current`];\n if (r.ours.stale.length) parts.push(c.cyan(`${r.ours.stale.length} stale`));\n if (r.ours.missing.length) parts.push(c.yellow(`${r.ours.missing.length} missing`));\n if (r.ours.kept.length) parts.push(c.dim(`${r.ours.kept.length} kept (yours from the start)`));\n console.log(c.dim(` ${parts.join(' \u00B7 ')}`));\n for (const f of r.ours.diverged.slice(0, 3)) {\n console.log(` ${c.yellow('diverged')} ${f} ${c.dim('\u2014 yours, never overwritten')}`);\n }\n if (r.ours.diverged.length > 3) console.log(c.dim(` \u2026and ${r.ours.diverged.length - 3} more`));\n if (r.ours.stale.length || r.ours.missing.length) {\n console.log(c.dim(' run `rungs upgrade --apply`'));\n }\n continue;\n }\n for (const p of r.matchedPaths.slice(0, 2)) {\n console.log(c.dim(` ${p.count}\u00D7 ${p.pattern} e.g. ${p.sample[0]}`));\n }\n if (r.matchedMarkers.length) console.log(c.dim(` markers: ${r.matchedMarkers.join(', ')}`));\n for (const prop of r.proposals) {\n console.log(` ${c.cyan('proposes')} ${prop.param} = ${c.bold(prop.value)} ${c.dim(`(${prop.evidence})`)}`);\n }\n for (const a of r.adoptable) {\n console.log(` ${c.cyan('adoptable')} ${a.count} as ${a.kind} ${c.dim(`e.g. ${a.sample[0]}`)}`);\n }\n if (r.paradigm) {\n console.log(` ${c.yellow('different paradigm')}: ${r.paradigm.id} ${c.dim(`(${r.paradigm.matched[0]})`)}`);\n if (r.paradigm.note) console.log(c.dim(` ${firstSentence(r.paradigm.note)}`));\n }\n if (mod.threshold?.confirm) {\n console.log(c.yellow(` threshold: ${mod.threshold.minimum}+ ${mod.threshold.metric} \u2014 add requires confirmation`));\n }\n }\n\n const ours = byState('ours-current').length + byState('ours-diverged').length;\n console.log(\n `\\n ${ours ? `${ours} installed (${byState('ours-diverged').length} diverged) \u00B7 ` : ''}` +\n `${byState('theirs').length} present \u00B7 ${byState('paradigm').length} different paradigm \u00B7 ` +\n `${byState('absent').length} absent\\n`,\n );\n\n // ADR-0005: state what this does not cover, every time. A green read is not\n // a verified one, and a low count may mean a narrow signature rather than a\n // clean repo.\n console.log(c.dim(' This reports presence, never quality. It cannot tell whether an adopted'));\n console.log(c.dim(' system is good, complete, or working \u2014 only that files are where a'));\n console.log(c.dim(\" module's files would be. Signatures under-detect on purpose.\\n\"));\n\n reportLedger(root);\n\n if (doExplain) reportExplain(mods, results, root, files);\n else advertiseAnalysis(results);\n\n // `doctor` is the command the README makes the entry point, and it used to stop on the sentence\n // above \u2014 fifteen `absent` lines and nothing to do next. The recommendation is deliberately a\n // **single** command, and never the maximal one: the brief names selling rung 5 to a rung-1 repo\n // as the most likely way this tool does harm, so a repo with nothing is pointed at `tracked`\n // rather than at the fifteen things it could install (WI-005).\n const theirs = byState('theirs');\n console.log(c.bold(' Next\\n'));\n if (ours) {\n const behind = results.some((r) => r.ours?.stale.length || r.ours?.missing.length);\n console.log(\n behind\n ? ` ${c.cyan('rungs upgrade --apply')} ${c.dim('\u2014 bring the stale and missing files up to date')}`\n : ` ${c.cyan('rungs check')} ${c.dim('\u2014 run the gates this repo already registered')}`,\n );\n console.log(c.dim(` Add more with \\`rungs add <module>\\`; \\`rungs modules\\` lists the set.\\n`));\n } else if (theirs.length) {\n const names = theirs.map((r) => r.module).slice(0, 3).join(' ');\n console.log(` ${c.cyan(`rungs add ${names}`)} ${c.dim('\u2014 adopt what you already built, in place')}`);\n console.log(c.dim(' Nothing is overwritten. Files you already have are kept and reported as'));\n console.log(c.dim(' yours; only what is missing gets written.\\n'));\n } else {\n console.log(` ${c.cyan('rungs init . tracked')} ${c.dim('\u2014 instructions \u00B7 gates \u00B7 backlog \u00B7 findings \u00B7 adr \u00B7 session')}`);\n console.log(c.dim(' `tracked` is the rung for more than one thing in flight. `minimal` is just'));\n console.log(c.dim(' the entry document; higher profiles cost more than they return until the'));\n console.log(c.dim(' problem they answer actually exists. `rungs modules` lists all fifteen.\\n'));\n }\n return 0;\n}\n\nfunction firstSentence(s: string): string {\n return s.trim().replace(/\\s+/g, ' ').split(/(?<=\\.)\\s/)[0];\n}\n\n/**\n * Say that the analysis exists, and how much of it there is. Never what it\n * found (WI-049).\n *\n * `--explain` is the capability both external reviews called the strongest\n * thing here, and plain `doctor` printed no occurrence of the string `explain`\n * \u2014 it was reachable only from `--help`. WI-038 put the *findings* behind a flag\n * for a measured reason: 114 on `hexguard` would bury the `Next` line that\n * WI-005 exists to protect. The flag was never the problem; the silence was.\n *\n * **It reports scope, not findings, and it runs no engine.** The first version\n * printed a finding count, which meant running the detectors on the plain path.\n * Measured on `rift-forge` 2026-08-16: plain `doctor` went from **1.6s to\n * 16.8s** warm \u2014 a 10\u00D7 tax on the entry point to advertise a flag. WI-049's\n * plan named this outcome in advance and named this fallback.\n *\n * So the number is the one detection already computed. It claims what it can\n * prove: these are things the repo has, and our checks can read them. It does\n * not claim anything was found, because finding out costs the 15 seconds.\n */\nfunction advertiseAnalysis(results: DetectResult[]) {\n const inScope = results.filter((r) => EXPLAINABLE.has(r.state)).length;\n if (!inScope) return;\n\n console.log(c.bold(' Analysis\\n'));\n console.log(` ${inScope} of these are things this repo already has, and can be checked against it.`);\n console.log(` ${c.cyan('rungs doctor --explain')} ${c.dim('\u2014 evidenced findings, and the incident behind each check')}\\n`);\n}\n\n/**\n * The defect half of `doctor` (WI-038). Every line carries a path and a count\n * or a quote; there is no score, grade, bar, or maturity label anywhere, and\n * there is not going to be \u2014 ADR-0005 tier C refuses composites permanently,\n * and a single word over incommensurable signals is the purest form of the\n * probe-encoding-a-guess the corpus warns about.\n *\n * The incident is attached to each detector rather than to each finding: it is\n * why the check exists, not what was found, and repeating it per row would bury\n * the evidence under the provenance.\n */\nfunction reportExplain(mods: Manifest[], results: DetectResult[], root: string, files: string[]) {\n const { reported, skipped, scope } = explain(mods, results, root, files);\n\n console.log(c.bold(' What it also checked\\n'));\n\n if (!scope.length) {\n console.log(c.dim(' Nothing \u2014 detectors run only over what this repo already has, and'));\n console.log(c.dim(' detection found no equivalent of any module. There is nothing here to'));\n console.log(c.dim(' check that would not be checking our conventions against your repo.\\n'));\n return;\n }\n\n const total = reported.reduce((n, r) => n + r.findings.length, 0);\n console.log(\n c.dim(` ran the detectors for ${scope.length} module(s) this repo already has: `) + c.dim(scope.join(' ')) + '\\n',\n );\n\n for (const r of reported) {\n const n = r.findings.length;\n console.log(` ${c.yellow(r.gate.padEnd(34))} ${c.bold(String(n))} ${n === 1 ? 'finding' : 'findings'}`);\n for (const f of r.findings.slice(0, 4)) {\n console.log(c.dim(` ${f.file ? `${f.file}: ` : ''}${f.message}`));\n }\n if (n > 4) console.log(c.dim(` \u2026and ${n - 4} more`));\n if (r.why) console.log(c.dim(` why: ${firstSentence(r.why)}`));\n console.log();\n }\n\n if (!total) {\n console.log(c.dim(' No detector fired. That is not a clean bill of health \u2014 see below.\\n'));\n }\n\n // Pins. ADR-0005's rule that green must never read as verified applies with\n // more force here than in the ledger: this pass runs our checks over content\n // written to somebody else's conventions, and the honest failure mode is a\n // sound finding in a frame the repo never adopted.\n console.log(c.dim(' This is not an audit, and it is deliberately incomplete:'));\n console.log(c.dim(' \u00B7 Detectors ran only for modules this repo already has an equivalent of.'));\n console.log(c.dim(\" \u00B7 They read rungs-shaped inputs. A finding may be true and framed against\"));\n console.log(c.dim(' a convention you never adopted \u2014 that is our defect, not yours.'));\n if (skipped.command) {\n console.log(c.dim(` \u00B7 ${skipped.command} command gate(s) not run. rungs does not execute commands in a repo it is only reading.`));\n }\n if (skipped.undeclared.length) {\n console.log(c.dim(` \u00B7 ${skipped.undeclared.length} gate(s) never said whether they can read a repo like yours, so they did not: ${skipped.undeclared.join(' ')}`));\n }\n if (skipped.unimplemented.length) {\n console.log(c.dim(` \u00B7 ${skipped.unimplemented.length} declared gate(s) have no engine and were skipped, never passed: ${skipped.unimplemented.join(' ')}`));\n }\n for (const e of skipped.errored) {\n console.log(c.dim(` \u00B7 ${e.gate} could not run here (${e.message}) \u2014 a fact about this pass, not about your repo.`));\n }\n console.log();\n}\n\nfunction cmdAdd(names: string[], root: string, dryRun: boolean, harnesses: Harness[], stamp: string) {\n const mods = loadAllModules(MODULES);\n const { order, missing } = resolveInstallOrder(names, mods);\n if (missing.length) {\n console.log(c.red(`\\n unknown module(s): ${missing.join(', ')}\\n`));\n return 1;\n }\n const pulled = order.filter((m) => !names.includes(m.name));\n\n // `--set module.param=value`. Without it the first real install into a repo\n // that already had a backlog would have created a second one beside it \u2014\n // `docs/backlog/` next to `docs/.ai/backlog/` \u2014 which is the \"two places to\n // look\" failure this whole tool is against, arriving through the installer.\n //\n // Values arrive already split from their flag, in either spelling. A malformed\n // key is refused rather than skipped: `--set root=x` used to be dropped in\n // silence, so the install proceeded with the default and looked successful.\n const overrides: Record<string, Record<string, unknown>> = {};\n for (const raw of flagValues['--set'] ?? []) {\n const [key, ...rhs] = raw.split('=');\n const [modName, param] = key.split('.');\n if (!modName || !param || !rhs.length) {\n console.log(c.red(`\\n --set expects module.param=value, got: ${raw}\\n`));\n return 1;\n }\n (overrides[modName] ??= {})[param] = rhs.join('=');\n }\n const params = resolveParams(mods, overrides, root);\n for (const [m, vals] of Object.entries(overrides)) {\n for (const [k, v] of Object.entries(vals)) console.log(c.dim(` set ${m}.${k} = ${v}`));\n }\n const skillsDir = harnesses.includes('claude') ? '.claude/skills' : '.agents/skills';\n\n console.log(c.bold(`\\nrungs add ${names.join(' ')} \u2192 ${root}${dryRun ? c.yellow(' (dry run)') : ''}\\n`));\n if (pulled.length) console.log(c.dim(` pulled in by dependency: ${pulled.map((m) => m.name).join(', ')}\\n`));\n\n // ADR-0004 state 5: a repo that solves this module's problem a different way\n // gets the comparison and a stop, not an install beside what it already runs.\n //\n // The state existed in the ADR and in `doctor` and nowhere else, so `add`\n // wrote straight over it \u2014 for every paradigm, since the CLI shipped\n // (WI-043, from F-014). Measured 2026-08-16: a repo with `.github/ISSUE_TEMPLATE/`\n // reported `backlog paradigm \u00B7 external-tracker`, and `add backlog` then wrote\n // `docs/`, `AGENTS.md`, `.ai/` and 12 gates without mentioning it once.\n //\n // Unlike `--confirm-threshold` above, this refusal **also applies under\n // `--dry-run`**. A preview that installs what the real run refuses is a\n // preview of a different command.\n const scanned = scanRepo(root);\n const paradigms = new Set(\n order.map((m) => detect(m, root, scanned)).filter((r) => r.state === 'paradigm').map((r) => r.module),\n );\n const overridden = flags.has('--confirm-paradigm');\n const blocked = overridden ? new Map<string, string>() : blockedByParadigm(order, paradigms);\n\n // An override that prints nothing is indistinguishable from a detection that\n // found nothing, and the two want opposite follow-ups.\n if (overridden && paradigms.size) {\n for (const name of paradigms) {\n const p = detect(order.find((m) => m.name === name)!, root, scanned).paradigm!;\n console.log(\n c.yellow(` ${name}: installing over an existing ${p.id}`) +\n c.dim(` (${p.matched[0]}) \u2014 --confirm-paradigm`),\n );\n }\n console.log(c.dim(' You will have two systems for one job. That is a choice, not a merge.\\n'));\n }\n\n // Re-resolve from what survives rather than filtering `order` in place. A\n // dependency is only ever pulled in *for* something; `add backlog` on an\n // issue-tracker repo was still writing `instructions` and `gates`, which\n // nobody asked for and which were pulled in solely for the module being\n // refused. Recomputing the closure drops them, and keeps anything a *surviving*\n // request still needs.\n let toInstall = order;\n if (blocked.size) {\n for (const mod of order) {\n const cause = blocked.get(mod.name);\n if (!cause) continue;\n if (cause === mod.name) {\n const p = detect(mod, root, scanned).paradigm!;\n console.log(c.yellow(` ${mod.name}: this repo already does this another way \u2014 ${p.id}`));\n console.log(c.dim(` matched ${p.matched[0]}`));\n for (const line of (p.note ?? '').trim().split('\\n')) console.log(c.dim(` ${line || ''}`));\n if (p.compare) console.log(c.dim(` compare: ${p.compare}`));\n } else {\n console.log(c.yellow(` ${mod.name}: not installed \u2014 it requires ${cause}.`));\n }\n }\n toInstall = resolveInstallOrder(names.filter((n) => !blocked.has(n)), mods).order;\n const dropped = order.filter((m) => !toInstall.includes(m) && !blocked.has(m.name));\n if (dropped.length) {\n console.log(c.dim(` ${dropped.map((m) => m.name).join(', ')} not written \u2014 pulled in only for the above`));\n }\n console.log(\n c.dim(`\\n Pass --confirm-paradigm to install anyway.`) +\n (toInstall.length ? c.dim(' Continuing with the rest.\\n') : c.dim(' Nothing was written.\\n')),\n );\n if (!toInstall.length) return 1;\n }\n\n const installed: Manifest[] = [];\n const wrote = new Map<string, Set<string>>();\n for (const mod of toInstall) {\n if (mod.threshold?.confirm && !dryRun && !flags.has('--confirm-threshold')) {\n console.log(\n c.yellow(` ${mod.name}: requires ${mod.threshold.minimum}+ ${mod.threshold.metric}.`) +\n c.dim(' Skipped \u2014 pass --confirm-threshold to install it.\\n'),\n );\n continue;\n }\n const actions = addModule(mod, root, params, { dryRun, skillsDir });\n installed.push(mod);\n wrote.set(mod.name, new Set(actions.filter((a) => a.disposition !== 'skip-exists' && a.disposition !== 'merge' && a.disposition !== 'gate').map((a) => a.target)));\n const counts = new Map<string, number>();\n for (const a of actions) counts.set(a.disposition, (counts.get(a.disposition) ?? 0) + 1);\n console.log(` ${c.bold(mod.name.padEnd(14))} ${[...counts].map(([k, v]) => `${v} ${k}`).join(' \u00B7 ')}`);\n for (const a of actions.filter((x) => x.disposition === 'skip-exists')) {\n console.log(c.dim(` kept ${a.target}`));\n }\n }\n\n // Detect what the repo already has and register it alongside (ADR-0004).\n const repoFiles = scanRepo(root);\n const adopted = installed.flatMap((m) =>\n (m.detect.adopt_as ?? [])\n .filter((a) => a.kind === 'command')\n .flatMap((a) => adoptableGates(repoFiles, a.paths ?? [], root)),\n );\n if (adopted.length) {\n console.log(\n '\\n ' + c.cyan(`adopting ${adopted.length} existing validator(s)`) +\n ' as command gates' + c.dim(' \u2014 their scripts are untouched'),\n );\n for (const a of adopted.slice(0, 3)) console.log(c.dim(` ${a.command}`));\n if (adopted.length > 3) console.log(c.dim(` \u2026and ${adopted.length - 3} more`));\n }\n\n // Phase two: the registry's owner has created it by now.\n const gateActions = registerGates(installed, root, dryRun, adopted);\n if (gateActions.length) {\n console.log(c.dim(`\\n registered ${gateActions.reduce((n, a) => n + Number(a.note!.split(': ')[1].split(' ')[0]), 0)} gates from ${gateActions.length} module(s)`));\n }\n\n if (!dryRun) {\n writeInstallRecord(root, order, params, harnesses, stamp, skillsDir, wrote);\n const entries = render(root, harnesses);\n writeReport(root, entries, harnesses, stamp);\n console.log(\n `\\n rendered ${entries.filter((e) => e.target).length} file(s) \u00B7 ` +\n `${entries.filter((e) => e.degraded).length} degraded ` +\n c.dim('\u2192 .ai/render-report.md'),\n );\n }\n console.log();\n return 0;\n}\n\nfunction cmdRender(root: string, harnesses: Harness[], stamp: string) {\n const entries = render(root, harnesses);\n writeReport(root, entries, harnesses, stamp);\n console.log(c.bold(`\\nrungs render \u2014 ${root}\\n`));\n for (const e of entries) {\n const lost = e.degraded ?? (e.dropped?.length ? c.dim(` (dropped ${e.dropped.join(', ')})`) : '');\n console.log(` ${e.rule.padEnd(24)} ${e.harness.padEnd(10)} ${e.target ?? c.yellow('not emitted')}${lost}`);\n }\n console.log(c.dim(`\\n ${entries.length} rendering(s) \u2192 .ai/render-report.md\\n`));\n // A bare `0 rendering(s)` reads as a completed edit. It is the answer a user gets after editing a\n // parameter in `.ai/rungs.toml` and running this \u2014 the thing the record's header used to tell\n // them to do \u2014 so the zero case has to say what it did not do, not just how much of it (WI-003).\n if (entries.length === 0) {\n console.log(c.yellow(' Nothing to render.') + c.dim(' This command re-emits path-scoped rules from `.ai/rules/`.'));\n console.log(c.dim(' It does not re-substitute parameters \u2014 a changed value in `.ai/rungs.toml`'));\n console.log(c.dim(' does not rewrite a file that already exists.\\n'));\n }\n return 0;\n}\n\nfunction cmdCheck(root: string, tier: string | undefined, stamp: string) {\n let runs: GateRun[];\n try {\n runs = runGates(root, tier);\n } catch (e) {\n // ADR-0008. A tier nobody declared used to select nothing and exit as though\n // the gates had passed \u2014 the one failure mode a release step cannot have.\n if (!(e instanceof UnknownTierError)) throw e;\n console.log(c.yellow(`\\n unknown tier \"${e.requested}\"`) + c.dim(` \u2014 this repo declares ${e.declared.join(', ')}.`));\n console.log(c.dim(' Nothing ran. Use `rungs check` to run every registered gate.\\n'));\n return 1;\n }\n if (!runs.length) {\n // Two situations printed the same sentence, and it was the wrong one for the case that\n // actually happens: a registry full of `fast` gates filtered by `--full` asked \"is this a\n // rungs repo?\" about a repo holding 25 of them, and `cut-release` told every consumer to\n // gate a release on exactly that command (F-020). Blame the filter when there is one.\n //\n // Hooks are excluded because a hook fires on a tool call rather than in the runner: it is\n // registered, and no tier value could ever have selected it. Counting it here would offer\n // the reader a gate that changing the tier cannot reach.\n const runnable = loadRegistry(root).gates.filter((g) => !g.trigger);\n if (runnable.length && tier) {\n const tiers = [...new Set(runnable.map((g) => g.tier).filter(Boolean))];\n console.log(c.yellow(`\\n no gates in the ${tier} tier \u2014 ${runnable.length} are registered`) +\n c.dim(` (${tiers.length ? tiers.join(', ') : 'none tiered'}).`));\n console.log(c.dim(' Nothing ran. Use `rungs check` to run every registered gate.\\n'));\n } else {\n console.log(c.yellow('\\n no gates registered \u2014 is this a rungs repo?\\n'));\n }\n return 1;\n }\n appendLedger(root, runs, stamp);\n\n console.log(c.bold(`\\nrungs check \u2014 ${root}${tier ? ` (${tier} tier)` : ''}\\n`));\n const mark = { pass: c.green('pass'), fail: c.red('FAIL'), unimplemented: c.yellow('unimpl'), error: c.red('error') };\n for (const r of runs) {\n console.log(\n ` ${mark[r.status]} ${r.id.padEnd(34)} ${c.dim(`${r.ms}ms`)}` +\n (r.examined ? c.dim(` ${r.examined} examined`) : ''),\n );\n for (const f of r.findings.slice(0, 4)) {\n console.log(` ${c.dim(f.file ? `${f.file}: ` : '')}${f.message}`);\n }\n if (r.findings.length > 4) console.log(c.dim(` \u2026and ${r.findings.length - 4} more`));\n }\n\n const n = (s: string) => runs.filter((r) => r.status === s).length;\n console.log(\n `\\n ${c.green(`${n('pass')} pass`)} \u00B7 ${c.red(`${n('fail')} fail`)} \u00B7 ` +\n `${c.yellow(`${n('unimplemented')} unimplemented`)} \u00B7 ${n('error')} error` +\n c.dim(` (${runs.reduce((t, r) => t + r.ms, 0)}ms total)`),\n );\n\n if (n('unimplemented')) {\n console.log(\n c.yellow('\\n Unimplemented gates are not passes.') +\n c.dim(' A registry reporting green because most of its\\n gates do nothing is the worst failure this tool could have, so they block.'),\n );\n }\n\n console.log();\n return n('fail') + n('unimplemented') + n('error') > 0 ? 1 : 0;\n}\n\n/**\n * ADR-0005 tier B: the two questions the ledger can ask without judgement.\n *\n * This printed from `check` and belonged in `doctor`, which is what both the\n * ADR and the README say (F-012). The ADR does not merely name the command, it\n * gives the reason: *\"They must be pull (`doctor`), never push; no output\n * during normal runs.\"* `check` is the normal run \u2014 it is what CI and every\n * pre-merge habit invoke \u2014 so printing there was the push the tier was written\n * to forbid, arriving inside the feature that forbade it.\n */\nfunction reportLedger(root: string) {\n const { gates } = loadRegistry(root);\n const q = ledgerQuestions(root, gates);\n if (!q.neverFired.length && !q.alwaysFires.length) return;\n\n console.log(c.bold(` Ledger questions ${c.dim(`(${q.runs} recorded runs)`)}`));\n for (const g of q.neverFired.slice(0, 3)) {\n console.log(` ${c.cyan(g.id)} has never fired. ${c.dim(firstSentence(g.why ?? ''))}`);\n console.log(c.dim(' Is that still a risk here, or is the gate scoped too narrowly?'));\n }\n for (const g of q.alwaysFires.slice(0, 3)) {\n console.log(` ${c.cyan(g.id)} fails ${g.rate}. ${c.dim('Red by default is a gate people learn to bypass.')}`);\n }\n console.log(c.dim('\\n These are questions, not verdicts. The ledger records whether a gate ran'));\n console.log(c.dim(' and whether it fired \u2014 never whether it is valuable. Gates invoked'));\n console.log(c.dim(' directly, and CI runs, are not counted.\\n'));\n}\n\nfunction cmdBacklogArchive(root: string, dryRun: boolean) {\n const record = readRecord(root);\n const configured = record?.modules['backlog']?.params?.root;\n const backlogRoot = `docs/${configured ?? 'backlog'}`;\n\n if (!existsSync(join(root, ...backlogRoot.split('/'), 'items'))) {\n console.log(c.red(`\\n no backlog at ${backlogRoot}/items\\n`));\n return 1;\n }\n\n const plan = planArchive(root, backlogRoot);\n console.log(c.bold(`\\nrungs backlog archive \u2192 ${root}${dryRun ? c.yellow(' (dry run)') : ''}\\n`));\n\n for (const h of plan.held) console.log(c.yellow(` held ${h.file}`) + c.dim(` \u2014 ${h.reason}`));\n if (plan.held.length) console.log();\n\n if (!plan.moves.length) {\n console.log(c.dim(' nothing to archive \u2014 no item is done or rejected.\\n'));\n return 0;\n }\n\n const byStatus = new Map<string, number>();\n for (const m of plan.moves) byStatus.set(m.status, (byStatus.get(m.status) ?? 0) + 1);\n console.log(\n ` ${c.bold(String(plan.moves.length))} item(s) \u2014 ${[...byStatus].map(([s, n]) => `${n} ${s}`).join(' \u00B7 ')}`,\n );\n for (const m of plan.moves.slice(0, 5)) console.log(c.dim(` ${m.from} \u2192 ${m.to}`));\n if (plan.moves.length > 5) console.log(c.dim(` \u2026and ${plan.moves.length - 5} more`));\n\n const touched = plan.rewrites.filter((r) => r.links);\n const links = touched.reduce((n, r) => n + r.links, 0);\n console.log(`\\n ${c.bold(String(links))} link(s) repointed across ${touched.length} file(s)`);\n for (const r of touched.slice(0, 5)) console.log(c.dim(` ${r.file} (${r.links})`));\n if (touched.length > 5) console.log(c.dim(` \u2026and ${touched.length - 5} more`));\n\n if (dryRun) {\n console.log(c.dim('\\n Nothing written. Drop --dry-run to apply.\\n'));\n return 0;\n }\n\n applyArchive(root, plan);\n console.log(c.green(`\\n archived ${plan.moves.length} item(s)`) + c.dim(' \u2014 ids stay spent and every citation still resolves.'));\n console.log(c.dim(' Run `rungs check` to confirm.\\n'));\n return 0;\n}\n\nfunction cmdInit(root: string, profile: string, dryRun: boolean, harnesses: Harness[], stamp: string) {\n if (readRecord(root)) {\n console.log(\n c.yellow('\\n this repo is already initialised.') +\n c.dim(' Use `rungs add <module>` to install more, or `rungs upgrade`.\\n'),\n );\n return 1;\n }\n const names = PROFILES[profile];\n if (!names) {\n console.log(c.red(`\\n unknown profile '${profile}'.`) + c.dim(` Known: ${Object.keys(PROFILES).join(', ')}\\n`));\n return 1;\n }\n console.log(c.dim(`\\n profile '${profile}' \u2014 ${names.length} modules`));\n return cmdAdd(names, root, dryRun, harnesses, stamp);\n}\n\nfunction cmdUpgrade(root: string, apply: boolean) {\n const record = readRecord(root);\n if (!record) {\n console.log(c.yellow('\\n not a rungs repo \u2014 nothing to upgrade.\\n'));\n return 1;\n }\n const mods = loadAllModules(MODULES);\n const plan = planUpgrade(root, mods, record);\n console.log(c.bold(`\\nrungs upgrade \u2014 ${root}${apply ? '' : c.yellow(' (preview)')}\\n`));\n\n let stale = 0;\n let diverged = 0;\n for (const item of plan) {\n const counts = item.files.reduce<Record<string, number>>((a, f) => ({ ...a, [f.state]: (a[f.state] ?? 0) + 1 }), {});\n stale += (counts.stale ?? 0) + (counts.missing ?? 0);\n diverged += counts.diverged ?? 0;\n const moved = item.from === item.to ? c.dim(item.to) : `${item.from} \u2192 ${c.bold(item.to)}`;\n console.log(` ${item.module.padEnd(14)} ${moved} ${c.dim(Object.entries(counts).map(([k, v]) => `${v} ${k}`).join(' \u00B7 '))}`);\n for (const f of item.files.filter((x) => x.state === 'diverged')) {\n console.log(` ${c.yellow('diverged')} ${f.rel} ${c.dim('\u2014 yours, left alone')}`);\n }\n }\n\n // Not `apply && stale`. A module version that only adds a gate has no stale\n // file, so the whole apply step was skipped and the registry silently kept the\n // old block \u2014 F-016, measured on a scratch consumer where `session` 1.1.0 \u2192\n // 1.2.0 added a gate and `rungs check` went on running the previous twenty.\n if (apply) {\n const { written, gates, recorded } = applyUpgrade(root, mods, record, plan);\n const parts = [\n written ? `${written} file(s)` : '',\n gates ? `${gates} gate registration(s)` : '',\n recorded ? `${recorded} record line(s)` : '',\n ].filter(Boolean);\n console.log(c.green(`\\n updated ${parts.length ? parts.join(' \u00B7 ') : 'nothing'}`));\n }\n console.log(\n `\\n ${stale} to update \u00B7 ${diverged} diverged\\n` +\n c.dim(' Divergence is a decision, not an error: a file you edited is never overwritten.\\n') +\n (apply ? '' : c.dim(' Run with --apply to write.\\n')),\n );\n return 0;\n}\n\nfunction cmdEject(root: string, dryRun: boolean) {\n if (!readRecord(root)) {\n console.log(c.yellow('\\n not a rungs repo \u2014 nothing to eject.\\n'));\n return 1;\n }\n const result = eject(root, loadAllModules(MODULES), dryRun);\n console.log(c.bold(`\\nrungs eject \u2014 ${root}${dryRun ? c.yellow(' (dry run)') : ''}\\n`));\n for (const a of result.actions.slice(0, 6)) console.log(c.dim(` ${a}`));\n if (result.actions.length > 6) console.log(c.dim(` \u2026and ${result.actions.length - 6} more`));\n console.log(\n `\\n ${result.gates} declared gate(s) rewritten as commands.` +\n c.dim('\\n This repo no longer needs rungs installed to run its checks.\\n') +\n c.dim(' Engine fixes stop arriving with a version bump \u2014 these files are yours now.\\n'),\n );\n return 0;\n}\n\n/**\n * Flags that carry a value, and therefore consume the token after them unless it is attached with\n * `=`. Everything else is a bare switch.\n *\n * This exists because the split below used to be two filters \u2014 `startsWith('--')` into flags,\n * everything else into positionals \u2014 which has no concept of a value. `--set backlog.root=x` then\n * left `backlog.root=x` sitting in the positionals, `--into` took the last positional as its\n * target, and the user's actual path was reported back to them as an unknown module. Both\n * spellings now work, and the value never reaches `args` (WI-002).\n */\nconst VALUE_FLAGS = new Set(['--set']);\n\n/**\n * The command surface, defined once and rendered into `--help`.\n *\n * It was a template literal listing eight of the nine commands \u2014 `setup git` was missing entirely \u2014\n * beside a README table listing all nine, which is two hand-kept inventories of one fact. They had\n * already drifted, in both directions: help omitted a real command, and three real flags appeared\n * in neither. Keep this table beside the switch it describes, and add a row when you add a `case`.\n *\n * The README's table is still hand-kept and still a second inventory. That is a known cost, not an\n * oversight \u2014 see WI-004.\n */\nconst COMMANDS: [usage: string, blurb: string][] = [\n ['init [path] [profile]', 'scaffold a repo \u2014 minimal \u00B7 tracked \u00B7 disciplined \u00B7 hardened \u00B7 fleet'],\n ['doctor [path]', 'detect what a repo already has, installed or not'],\n ['add <module\u2026> [--into p]', 'install modules, resolving dependencies and adopting what exists'],\n ['check [path] [tier]', 'run the registered gates and record the ledger'],\n ['render [path]', 're-emit path-scoped rules per harness'],\n ['upgrade [path]', 'move to newer module versions, never touching what you edited'],\n ['eject [path]', 'materialise the engines; stop depending on rungs'],\n ['setup git [path]', 'install the merge drivers .gitattributes names'],\n ['modules', 'list the module set and audit the manifests'],\n ['backlog archive [path]', 'move finished items to archive/, repointing every link'],\n];\n\n/** Every flag the parser honours. A flag absent here is a flag nobody can find. */\nconst FLAGS: [flag: string, blurb: string][] = [\n ['--dry-run', 'report what would happen, write nothing'],\n ['--explain', \"doctor: also run the detectors over what this repo already has\"],\n ['--confirm-paradigm', 'add: install a module this repo already solves another way'],\n ['--into <path>', 'add: install into this repo instead of the working directory'],\n ['--set m.param=value', 'add/init: override a module parameter. Repeatable'],\n ['--confirm-threshold', 'add: install a module whose rung is above this repo'],\n ['--apply', 'upgrade: write the changes, rather than preview them'],\n ['--fast, --full', 'check: pick the gate tier, as the positional also does'],\n ['--params', 'modules: show every module parameter, its default and its allowed values'],\n ['--copilot', 'also emit Copilot instruction files'],\n];\n\nfunction renderHelp(): string {\n const pad = Math.max(...COMMANDS.map(([u]) => u.length)) + 2;\n const fpad = Math.max(...FLAGS.map(([f]) => f.length)) + 2;\n return [\n ``,\n `${c.bold('rungs')} \u2014 installs and maintains a repository's agentic development system`,\n ``,\n ...COMMANDS.map(([u, b]) => ` ${c.bold(`rungs ${u.split(' ')[0]}`)}${u.slice(u.split(' ')[0].length).padEnd(pad - u.split(' ')[0].length)} ${c.dim(b)}`),\n ``,\n ...FLAGS.map(([f, b]) => ` ${c.dim(f.padEnd(fpad))} ${c.dim(b)}`),\n ``,\n ].join('\\n');\n}\n\nconst [, , cmd, ...rest] = process.argv;\n\nconst flags = new Set<string>();\nconst args: string[] = [];\nconst flagValues: Record<string, string[]> = {};\n/** A value-flag left without a value. Reported by the command, so `--help` still works. */\nlet missingValue: string | null = null;\n\nfor (let i = 0; i < rest.length; i++) {\n const token = rest[i];\n if (!token.startsWith('--')) {\n args.push(token);\n continue;\n }\n const eq = token.indexOf('=');\n const name = eq === -1 ? token : token.slice(0, eq);\n if (!VALUE_FLAGS.has(name)) {\n // The bare name, not the raw token, so `--copilot=yes` still answers `flags.has('--copilot')`.\n flags.add(name);\n continue;\n }\n // Attached form first; otherwise the next token, unless that is itself a flag \u2014 `--set --dry-run`\n // is a missing value, not a value of `--dry-run`.\n const next = rest[i + 1];\n const value = eq === -1 ? (next === undefined || next.startsWith('--') ? undefined : rest[++i]) : token.slice(eq + 1);\n if (value === undefined) missingValue = name;\n else (flagValues[name] ??= []).push(value);\n}\n\n/**\n * A positional shaped like `module.param=value` was meant to be an override and was not claimed by\n * `--set`. No path, module, profile or tier has that shape, so it is unambiguously a mistake \u2014\n * refuse it by name rather than letting a command interpret it as something else.\n */\nconst strayOverride = args.find((a) => /^[a-z][a-z0-9_-]*\\.[a-z][a-z0-9_]*=/.test(a));\n\n// Dates come from the caller, never from inside a render: a timestamp baked\n// into generated output makes every run a diff.\nconst STAMP = process.env.RUNGS_DATE ?? new Date().toISOString().slice(0, 10);\nconst HARNESSES: Harness[] = flags.has('--copilot')\n ? ['claude', 'copilot', 'agents-md']\n : (['claude', 'agents-md'] as Harness[]);\n\n// Both refusals run before dispatch, because either one means the argv the user typed is not the\n// argv any command would act on. Silently proceeding is what made the original failure so opaque.\nif (missingValue) {\n console.log(c.red(`\\n ${missingValue} expects a value \u2014 ${missingValue} module.param=value\\n`));\n process.exit(1);\n}\nif (strayOverride) {\n console.log(\n c.red(`\\n stray override: ${strayOverride}`) +\n c.dim(`\\n Nothing claimed it, so it would be read as a path or a module name.`) +\n c.dim(`\\n Did you mean: --set ${strayOverride}\\n`),\n );\n process.exit(1);\n}\n\nswitch (cmd) {\n case 'modules':\n process.exit(cmdModules(flags.has('--params')));\n case 'doctor':\n process.exit(cmdDoctor(args[0] ?? process.cwd(), flags.has('--explain')));\n case 'backlog': {\n if (args[0] !== 'archive') {\n console.log(c.red(`\\n unknown: rungs backlog ${args[0] ?? ''}`) + c.dim('\\n The only subcommand is `archive`.\\n'));\n process.exit(1);\n }\n process.exit(cmdBacklogArchive(resolve(args[1] ?? process.cwd()), flags.has('--dry-run')));\n }\n case 'check': {\n const tier = args[1] ?? (flags.has('--full') ? 'full' : flags.has('--fast') ? 'fast' : undefined);\n process.exit(cmdCheck(resolve(args[0] ?? process.cwd()), tier, STAMP));\n }\n case 'init': {\n const profile = args[1] ?? 'tracked';\n process.exit(cmdInit(resolve(args[0] ?? process.cwd()), profile, flags.has('--dry-run'), HARNESSES, STAMP));\n }\n case 'upgrade':\n process.exit(cmdUpgrade(resolve(args[0] ?? process.cwd()), flags.has('--apply')));\n case 'eject':\n process.exit(cmdEject(resolve(args[0] ?? process.cwd()), flags.has('--dry-run')));\n case 'setup': {\n const r = setupGit(resolve(args[1] ?? process.cwd()), flags.has('--dry-run'));\n console.log(\n r.drivers.length\n ? `\\n installed ${r.drivers.length} merge driver(s): ${r.drivers.join(', ')}` +\n (r.rerere ? c.dim(' \u00B7 rerere on') : '') +\n c.dim('\\n Declared drivers were inert until now \u2014 a fresh clone needs this once.\\n')\n : c.dim('\\n no rungs merge drivers declared in .gitattributes\\n'),\n );\n process.exit(0);\n }\n case 'render':\n process.exit(cmdRender(resolve(args[0] ?? process.cwd()), HARNESSES, STAMP));\n case 'add': {\n const target = flags.has('--into') ? args[args.length - 1] : process.cwd();\n const names = flags.has('--into') ? args.slice(0, -1) : args;\n process.exit(cmdAdd(names, resolve(target), flags.has('--dry-run'), HARNESSES, STAMP));\n }\n default: {\n // Help is a success, and an unknown command is not. Both used to land here and exit on\n // `cmd ? 1 : 0`, which made `rungs --help` \u2014 a command that did exactly what was asked \u2014\n // report failure to anything checking the status (WI-004).\n const wantedHelp = cmd === undefined || cmd === 'help' || cmd === '--help' || cmd === '-h';\n if (!wantedHelp) console.log(c.red(`\\n unknown command: ${cmd}`));\n console.log(renderHelp());\n process.exit(wantedHelp ? 0 : 1);\n }\n}\n", "import { readdirSync, readFileSync, statSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { parse } from 'smol-toml';\nimport type { Manifest, ParamSpec } from './types.ts';\nimport { walk } from './glob.ts';\n\n/** Reads one module directory into a validated manifest. Throws on anything malformed. */\nexport function loadManifest(dir: string): Manifest {\n const raw = parse(readFileSync(join(dir, 'module.toml'), 'utf8')) as Record<string, any>;\n const m = raw.module ?? {};\n const name = m.name;\n if (!name) throw new Error(`${dir}: [module].name is required`);\n\n const manifest: Manifest = {\n name,\n version: m.version ?? '0.0.0',\n rung: m.rung ?? 0,\n summary: m.summary ?? '',\n requires: raw.requires?.modules ?? [],\n conflicts: raw.conflicts?.modules ?? [],\n params: (raw.params ?? {}) as Record<string, ParamSpec>,\n gates: raw.gates ?? [],\n detect: raw.detect ?? {},\n skills: raw.skills ?? {},\n provenance: raw.provenance,\n threshold: raw.threshold,\n dir,\n };\n\n // `[provenance]` is required and validated (ADR-0003). A module with no\n // traceable source is one somebody invented, and `doctor` cannot ask its\n // questions without the incident.\n const p = manifest.provenance;\n if (!p?.sources?.length) throw new Error(`${name}: [provenance].sources is required`);\n if (!p?.patterns?.length) throw new Error(`${name}: [provenance].patterns is required`);\n if (!p?.incident?.trim()) throw new Error(`${name}: [provenance].incident is required`);\n\n return manifest;\n}\n\nexport function loadAllModules(modulesRoot: string): Manifest[] {\n return readdirSync(modulesRoot, { withFileTypes: true })\n .filter((e) => e.isDirectory() && statSync(join(modulesRoot, e.name, 'module.toml'), { throwIfNoEntry: false }))\n .map((e) => loadManifest(join(modulesRoot, e.name)))\n .sort((a, b) => a.rung - b.rung || a.name.localeCompare(b.name));\n}\n\n/** Every `{{param}}` appearing in a module's files and path names. */\nexport function usedParams(dir: string): Set<string> {\n const used = new Set<string>();\n const add = (text: string) => {\n // `${{ \u2026 }}` is never a substitution: GitHub Actions expressions share the\n // delimiter, and without this the ci module corrupts its own workflow file.\n for (const match of text.matchAll(/(^|[^$])\\{\\{([a-z_.]+)\\}\\}/g)) used.add(match[2]);\n };\n for (const rel of walk(dir)) {\n add(rel);\n add(readFileSync(join(dir, rel), 'utf8'));\n }\n return used;\n}\n\nexport interface ManifestIssue {\n module: string;\n kind: 'dead-param' | 'undeclared-param' | 'dep-missing' | 'gate-no-table' | 'gate-no-why' | 'gate-no-applicability';\n detail: string;\n}\n\n/** The cross-module audit. Several findings were only visible with every module in hand. */\nexport function auditModules(mods: Manifest[]): ManifestIssue[] {\n const issues: ManifestIssue[] = [];\n const names = new Set(mods.map((m) => m.name));\n\n for (const mod of mods) {\n for (const dep of mod.requires) {\n if (!names.has(dep)) {\n issues.push({ module: mod.name, kind: 'dep-missing', detail: `requires unknown module '${dep}'` });\n }\n }\n\n const used = usedParams(mod.dir);\n for (const [param, spec] of Object.entries(mod.params)) {\n if (used.has(param) || spec.consumed_by) continue;\n issues.push({\n module: mod.name,\n kind: 'dead-param',\n detail: `'${param}' is declared, never substituted, and not marked consumed_by`,\n });\n }\n for (const u of used) {\n if (u.includes('.')) continue; // cross-module reference, e.g. backlog.root\n if (!(u in mod.params)) {\n issues.push({ module: mod.name, kind: 'undeclared-param', detail: `uses {{${u}}} but does not declare it` });\n }\n }\n\n for (const g of mod.gates) {\n if (g.kind === 'declared' && !g.table) {\n issues.push({ module: mod.name, kind: 'gate-no-table', detail: `gate '${g.id}' is declared with no table` });\n }\n // `doctor` quotes `why` back when a gate has never fired (ADR-0005 tier B),\n // so a gate without one cannot be asked about.\n if (!g.why?.trim()) {\n issues.push({ module: mod.name, kind: 'gate-no-why', detail: `gate '${g.id}' has no 'why'` });\n }\n // WI-052. `doctor --explain` will not run an undeclared gate against a repo\n // that is not ours, so an author who forgets this silently loses their gate\n // on exactly the repos the analysis exists for. Caught here, where the\n // module is written, rather than as a skip line nobody reads.\n if (g.kind === 'declared' && !g.applicability) {\n issues.push({\n module: mod.name,\n kind: 'gate-no-applicability',\n detail: `gate '${g.id}' does not declare applicability (repo-content | our-artifacts | our-schema)`,\n });\n }\n }\n }\n return issues;\n}\n", "import { readdirSync, statSync } from 'node:fs';\nimport { join, relative, sep } from 'node:path';\n\n/**\n * A small glob matcher: `**`, `*`, `?`, and `{a,b}` brace groups.\n *\n * Written rather than depended on so the semantics are ours. The only rule that\n * matters is the one ADR-0004 states: when a pattern is ambiguous it must fail\n * to match. A false negative creates something visible in git; a false positive\n * makes the CLI believe wrong things about a repo and act on them later.\n */\nexport function globToRegExp(pattern: string): RegExp {\n let out = '';\n for (let i = 0; i < pattern.length; i++) {\n const c = pattern[i];\n if (c === '*') {\n if (pattern[i + 1] === '*') {\n // `**/` consumes any number of segments, including none.\n if (pattern[i + 2] === '/') {\n out += '(?:[^/]+/)*';\n i += 2;\n } else {\n out += '.*';\n i += 1;\n }\n } else {\n out += '[^/]*';\n }\n } else if (c === '?') {\n out += '[^/]';\n } else if (c === '{') {\n const end = pattern.indexOf('}', i);\n if (end === -1) {\n out += '\\\\{';\n } else {\n const alts = pattern.slice(i + 1, end).split(',');\n out += `(?:${alts.map((a) => a.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')).join('|')})`;\n i = end;\n }\n } else if ('.+^$()|[]\\\\'.includes(c)) {\n out += `\\\\${c}`;\n } else {\n out += c;\n }\n }\n return new RegExp(`^${out}$`);\n}\n\nconst SKIP = new Set([\n '.git',\n 'node_modules',\n 'dist',\n 'build',\n 'out',\n 'bin',\n 'obj',\n '.vs',\n '.angular',\n '.next',\n 'coverage',\n 'TestResults',\n 'BenchmarkDotNet.Artifacts',\n]);\n\n/** Walk a repo once; callers match the resulting relative paths. */\nexport function walk(root: string, maxEntries = 200_000): string[] {\n const files: string[] = [];\n const stack = [root];\n while (stack.length && files.length < maxEntries) {\n const dir = stack.pop()!;\n let entries;\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch {\n continue;\n }\n for (const e of entries) {\n if (SKIP.has(e.name)) continue;\n const full = join(dir, e.name);\n if (e.isDirectory()) {\n stack.push(full);\n } else if (e.isFile()) {\n files.push(relative(root, full).split(sep).join('/'));\n }\n }\n }\n return files;\n}\n\nexport function matchAny(files: string[], pattern: string): string[] {\n const re = globToRegExp(pattern);\n return files.filter((f) => re.test(f));\n}\n\nexport function isDir(p: string): boolean {\n try {\n return statSync(p).isDirectory();\n } catch {\n return false;\n }\n}\n", "import { existsSync, readFileSync } from 'node:fs';\nimport { join } from 'node:path';\nimport type { DetectResult, Manifest } from './types.ts';\nimport { matchAny, walk } from './glob.ts';\nimport { contentHash, emittedFiles } from './add.ts';\nimport type { Params } from './substitute.ts';\n\nconst SAMPLE = 3;\n\n/**\n * ADR-0004. Presence is decided by `paths` and `markers` only; `infer` merely\n * *proposes* parameters, and never concludes presence \u2014 hexguard-templates has\n * 207 well-formed `FOUND-US-###` matches and no backlog, because those are spec\n * story ids.\n *\n * Signatures are biased toward false negatives throughout: a false negative\n * creates something visible in git, while a false positive makes the CLI\n * believe wrong things about a repo and act on that belief later.\n */\nexport function detect(mod: Manifest, repoRoot: string, files: string[], installed?: InstalledModule): DetectResult {\n const result: DetectResult = {\n module: mod.name,\n state: 'absent',\n matchedPaths: [],\n matchedMarkers: [],\n proposals: [],\n adoptable: [],\n };\n\n // A module the repo installed is answered from the record, not from\n // signatures. Signatures exist to recognise somebody *else's* structure;\n // running them over our own would report a healthy install as \"theirs\" and\n // lose the one thing the record knows and detection cannot \u2014 which files we\n // wrote, and whether they still say what we wrote.\n if (installed) {\n result.ours = ownedState(mod, repoRoot, installed);\n result.state = result.ours.diverged.length ? 'ours-diverged' : 'ours-current';\n return result;\n }\n\n for (const pattern of mod.detect.paths ?? []) {\n const hits = matchAny(files, pattern);\n if (hits.length) {\n result.matchedPaths.push({ pattern, count: hits.length, sample: hits.slice(0, SAMPLE) });\n }\n }\n\n const markers = mod.detect.markers ?? [];\n if (markers.length) {\n // Only files a marker could plausibly live in, and only ones we already\n // have a reason to read. Scanning a whole repo for a marker string is both\n // slow and a way to match prose that mentions one.\n //\n // `marker_paths` exists for the case where a file's *existence* is not\n // discriminating but its *content* is: nearly every repo has a\n // `.gitattributes`, and only one of the four declares a custom merge\n // driver in it \u2014 21 declarations against 0, 0, 0.\n const scanPatterns = mod.detect.marker_paths ?? result.matchedPaths.map((m) => m.pattern);\n const candidates = new Set(scanPatterns.flatMap((p) => matchAny(files, p)));\n for (const rel of candidates) {\n let text: string;\n try {\n text = readFileSync(join(repoRoot, rel), 'utf8');\n } catch {\n continue;\n }\n for (const marker of markers) {\n if (text.includes(marker) && !result.matchedMarkers.includes(marker)) {\n result.matchedMarkers.push(marker);\n }\n }\n }\n }\n\n for (const adopt of mod.detect.adopt_as ?? []) {\n const hits = (adopt.paths ?? []).flatMap((p) => matchAny(files, p));\n if (hits.length) {\n result.adoptable.push({ kind: adopt.kind, count: hits.length, sample: hits.slice(0, SAMPLE), note: adopt.note });\n }\n }\n\n // A paradigm is only consulted when nothing else matched. Checking it\n // unconditionally reported rift-forge's pulled design mirror as *both* an\n // external authority and an in-repo design system, on a theme.ts the pattern\n // was never meant to reach.\n if (result.matchedPaths.length === 0 && result.adoptable.length === 0) {\n for (const para of mod.detect.paradigm ?? []) {\n const matched = (para.paths ?? []).flatMap((p) => matchAny(files, p));\n if (matched.length) {\n result.paradigm = { id: para.id, note: para.note, compare: para.compare, matched: matched.slice(0, SAMPLE) };\n break;\n }\n }\n }\n\n // State. `ours-current` / `ours-diverged` require a rungs.toml recording a\n // prior install; a repo without one can only be absent, theirs, or paradigm.\n //\n // An `adopt_as` match is ADR-0004 state 4 \u2014 \"theirs, equivalent\": the\n // module's function exists in a shape we can map, even though our own\n // structure is absent. Treating it as absent hid the single highest-value\n // adoption in the catalogue, rift-forge's 82 registered gates.\n if (result.matchedPaths.length > 0 || result.adoptable.length > 0 || result.matchedMarkers.length > 0) {\n result.state = 'theirs';\n } else if (result.paradigm) {\n result.state = 'paradigm';\n } else {\n result.state = 'absent';\n }\n\n // Proposals run only once presence is established, and are reported as\n // proposals \u2014 never applied, never used to decide state.\n if (result.state === 'theirs') {\n result.proposals = infer(mod, repoRoot, files);\n }\n\n return result;\n}\n\nfunction infer(mod: Manifest, repoRoot: string, files: string[]) {\n const proposals: DetectResult['proposals'] = [];\n\n for (const rule of mod.detect.infer ?? []) {\n if (rule.paths) {\n // Directory-presence inference (e.g. which harnesses exist).\n const present = Object.entries(rule.paths)\n .filter(([, p]) => files.some((f) => f.startsWith(p.replace(/\\/$/, '/'))))\n .map(([key]) => key);\n if (present.length) {\n proposals.push({ param: rule.param, value: present.join(', '), evidence: 'directory present' });\n }\n continue;\n }\n if (!rule.pattern) continue;\n\n const scope = (rule.scope ?? ['**/*.md']).flatMap((p) => matchAny(files, p));\n const excluded = new Set((rule.exclude ?? []).flatMap((p) => matchAny(files, p)));\n const counts = new Map<string, number>();\n\n for (const rel of scope) {\n if (excluded.has(rel)) continue;\n let text: string;\n try {\n text = readFileSync(join(repoRoot, rel), 'utf8');\n } catch {\n continue;\n }\n for (const m of text.matchAll(new RegExp(rule.pattern, 'gm'))) {\n const key = m[1];\n if (key) counts.set(key, (counts.get(key) ?? 0) + 1);\n }\n }\n\n // An anchor wins outright over frequency. Counting raw occurrences made\n // `findings` propose the *backlog's* prefix, because a findings register is\n // full of citations to work items \u2014 more of them than of its own ids.\n // The register's own NEXT-ID marker settles it without judgement.\n if (rule.anchor) {\n const anchored = new Map<string, number>();\n for (const rel of scope) {\n if (excluded.has(rel)) continue;\n let text: string;\n try {\n text = readFileSync(join(repoRoot, rel), 'utf8');\n } catch {\n continue;\n }\n for (const m of text.matchAll(new RegExp(rule.anchor, 'gm'))) {\n if (m[1]) anchored.set(m[1], (anchored.get(m[1]) ?? 0) + 1);\n }\n }\n const [best] = [...anchored].sort((a, b) => b[1] - a[1]);\n if (best) {\n proposals.push({ param: rule.param, value: best[0], evidence: `anchored on ${rule.anchor_name ?? 'marker'}` });\n continue;\n }\n }\n\n const banned = new Set(rule.exclude_values ?? []);\n const ranked = [...counts].filter(([k]) => !banned.has(k)).sort((a, b) => b[1] - a[1]);\n const [top] = ranked;\n if (top && top[1] >= (rule.min ?? 1)) {\n proposals.push({\n param: rule.param,\n value: top[0],\n evidence: `${top[1]} matches${ranked.length > 1 ? ` (next: ${ranked[1][0]} at ${ranked[1][1]})` : ''}`,\n });\n }\n }\n return proposals;\n}\n\nexport function scanRepo(repoRoot: string): string[] {\n return walk(repoRoot);\n}\n\nexport interface InstalledModule {\n version: string;\n params?: Record<string, unknown>;\n hashes?: Record<string, string>;\n kept?: { files: string[] };\n skillsDir?: string;\n params_all?: Params;\n}\n\n/**\n * The state of files this repo installed from a module.\n *\n * Three comparisons, and each answers a different question:\n *\n * absent from disk \u2192 missing, an upgrade restores it\n * matches what we'd emit now \u2192 current\n * matches the recorded hash \u2192 stale; ours to replace on upgrade\n * matches neither \u2192 diverged; theirs, and never touched\n */\nexport function ownedState(mod: Manifest, repoRoot: string, installed: InstalledModule) {\n const params = installed.params_all ?? {};\n const emitted = emittedFiles(mod, params, installed.skillsDir ?? '.claude/skills');\n const kept = new Set(installed.kept?.files ?? []);\n const out = {\n version: installed.version,\n current: [] as string[],\n stale: [] as string[],\n diverged: [] as string[],\n missing: [] as string[],\n kept: [] as string[],\n };\n for (const [rel, wouldEmit] of emitted) {\n // A file that already existed at install was never ours. Calling it\n // \"diverged\" implies the user broke something they never touched.\n if (kept.has(rel)) {\n out.kept.push(rel);\n continue;\n }\n const full = join(repoRoot, rel);\n if (!existsSync(full)) {\n out.missing.push(rel);\n continue;\n }\n const onDisk = contentHash(readFileSync(full, 'utf8'));\n if (onDisk === contentHash(wouldEmit)) out.current.push(rel);\n else if (installed.hashes?.[rel] && onDisk === installed.hashes[rel]) out.stale.push(rel);\n else out.diverged.push(rel);\n }\n return out;\n}\n", "import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { createHash } from 'node:crypto';\nimport type { Manifest } from './types.ts';\nimport { matchAny, walk } from './glob.ts';\nimport { markers, mergeBlock, substitute, type Params } from './substitute.ts';\n\nexport interface AddAction {\n disposition: 'create' | 'skip-exists' | 'rule' | 'skill' | 'merge' | 'gate';\n target: string;\n note?: string;\n}\n\n/** Where a fragment file merges to. The name is the target, not a path. */\nconst FRAGMENT_TARGET: Record<string, string> = {\n 'AGENTS.md': 'AGENTS.md',\n gitignore: '.gitignore',\n gitattributes: '.gitattributes',\n};\n\n/**\n * Install one module. Disposition is decided by which subdirectory a file is\n * in \u2014 never by per-file configuration (ADR-0003), which is why this function\n * is a switch over five directory names and nothing else.\n *\n * Never overwrites an existing file. ADR-0004: `add` on existing structure\n * reports the delta; the dangerous operation is removed rather than guarded.\n */\nexport function addModule(\n mod: Manifest,\n repoRoot: string,\n params: Params,\n opts: { dryRun?: boolean; skillsDir?: string } = {},\n): AddAction[] {\n const actions: AddAction[] = [];\n const write = (rel: string, content: string, disposition: AddAction['disposition']) => {\n const full = join(repoRoot, rel);\n if (existsSync(full)) {\n actions.push({ disposition: 'skip-exists', target: rel, note: 'already present \u2014 left alone' });\n return;\n }\n actions.push({ disposition, target: rel });\n if (opts.dryRun) return;\n mkdirSync(dirname(full), { recursive: true });\n writeFileSync(full, content);\n };\n\n const sub = (text: string) => substitute(text, mod.name, params);\n const has = (d: string) => existsSync(join(mod.dir, d));\n\n if (has('files')) {\n const base = join(mod.dir, 'files');\n for (const rel of walk(base)) {\n write(sub(rel), sub(readFileSync(join(base, rel), 'utf8')), 'create');\n }\n }\n\n if (has('rules')) {\n const base = join(mod.dir, 'rules');\n for (const rel of walk(base)) {\n write(join('.ai', 'rules', rel).split('\\\\').join('/'), sub(readFileSync(join(base, rel), 'utf8')), 'rule');\n }\n }\n\n if (has('skills')) {\n const base = join(mod.dir, 'skills');\n const dir = opts.skillsDir ?? '.claude/skills';\n for (const rel of walk(base)) {\n // Through the same helper `emittedFiles` uses. These two paths both emit\n // skills and are easy to change apart \u2014 patching only `emittedFiles` for\n // F-019 left `add` still writing the un-extended file, so an install and\n // an upgrade would have produced different content for the same skill.\n write(`${dir}/${rel}`, withOptedInExtensions(mod, rel, sub(readFileSync(join(base, rel), 'utf8'))), 'skill');\n }\n }\n\n if (has('fragments')) {\n const base = join(mod.dir, 'fragments');\n for (const rel of walk(base)) {\n const target = FRAGMENT_TARGET[rel];\n if (!target) {\n actions.push({ disposition: 'merge', target: rel, note: 'unknown fragment target \u2014 skipped' });\n continue;\n }\n const full = join(repoRoot, target);\n const existing = existsSync(full) ? readFileSync(full, 'utf8') : '';\n const fragment = sub(readFileSync(join(base, rel), 'utf8'));\n const merged = mergeBlock(existing, fragment, mod.name);\n actions.push({\n disposition: 'merge',\n target,\n note: existing.includes(`rungs:begin ${mod.name}`) ? 'block replaced' : 'block appended',\n });\n if (!opts.dryRun) {\n mkdirSync(dirname(full), { recursive: true });\n writeFileSync(full, merged);\n }\n }\n }\n\n return actions;\n}\n\n/**\n * Gate registration is a **second phase**, run after every module's files exist.\n *\n * Done inside `addModule` it raced the `gates` module's own registry file:\n * whichever module merged an entry first created `.ai/gates.toml`, and the\n * owner then hit the never-overwrite rule and was skipped \u2014 leaving a registry\n * with entries and no `[runner]` block. Reordering the install did not fix it,\n * because `gates` depends on `instructions`, which itself ships gates. The\n * ordering was never the problem: **the owner of a shared file must create it\n * before anything merges into it, which is a phase, not a position.**\n */\nexport function registerGates(mods: Manifest[], repoRoot: string, dryRun = false, adopted: AdoptedGate[] = []): AddAction[] {\n const actions: AddAction[] = [];\n const registry = join(repoRoot, '.ai', 'gates.toml');\n\n // Adoption, in the only form ADR-0004 permits: the repo's existing validators\n // are registered as `command` gates so they gain the runner, the ledger and\n // attribution \u2014 **without a line of them being rewritten**. This is the claim\n // the whole product rests on, and it was missing: `add` created a registry of\n // rungs' own gates and left the repo's sixteen where they were.\n if (adopted.length) {\n const existing = existsSync(registry) ? readFileSync(registry, 'utf8') : '';\n const { begin, end } = markers('gates.toml', 'adopted', '1.0.0');\n const body = [\n begin,\n '# Registered from validators this repo already had. Their scripts are untouched and',\n '# stay yours; rungs only runs them and records what it observes.',\n ...adopted.map(\n (a) => `\\n[[gates]]\\nid = \"${a.id}\"\\nkind = \"command\"\\nmodule = \"adopted\"\\ntier = \"${a.tier}\"\\ncommand = \"${a.command}\"\\nwhy = \"\"\"Adopted from ${a.source}. Predates rungs and is owned by this repo.\"\"\"`,\n ),\n end,\n ].join('\\n');\n actions.push({ disposition: 'gate', target: '.ai/gates.toml', note: `adopted: ${adopted.length} entries` });\n if (!dryRun) {\n mkdirSync(dirname(registry), { recursive: true });\n writeFileSync(registry, mergeBlock(existing, body, 'adopted'));\n }\n }\n\n for (const mod of mods) {\n if (!mod.gates.length) continue;\n const existing = existsSync(registry) ? readFileSync(registry, 'utf8') : '';\n const { begin, end } = markers('gates.toml', mod.name, mod.version);\n const body = [begin, ...mod.gates.map(gateEntry(mod)), end].join('\\n');\n actions.push({ disposition: 'gate', target: '.ai/gates.toml', note: `${mod.name}: ${mod.gates.length} entries` });\n if (dryRun) continue;\n mkdirSync(dirname(registry), { recursive: true });\n writeFileSync(registry, mergeBlock(existing, body, mod.name));\n }\n return actions;\n}\n\nconst gateEntry = (mod: Manifest) => (g: Manifest['gates'][number]) => {\n const lines = ['', '[[gates]]', `id = \"${g.id}\"`, `kind = \"${g.kind}\"`, `module = \"${mod.name}\"`];\n if (g.engine) lines.push(`engine = \"${g.engine}\"`);\n if (g.table) lines.push(`table = \"${mod.name}/${g.table.replace(/^gates\\//, '')}\"`);\n if (g.command) lines.push(`command = \"${g.command}\"`);\n if (g.tier) lines.push(`tier = \"${g.tier}\"`);\n if (g.trigger) lines.push(`trigger = \"${g.trigger}\"`);\n if (g.matcher) lines.push(`matcher = \"${g.matcher}\"`);\n // `why` is carried into the repo because ADR-0005 tier B quotes it back when\n // a gate has never fired. A gate whose reason lives only in this CLI cannot\n // be asked about by a repo that has it installed.\n if (g.why) lines.push(`why = \"\"\"${g.why.trim()}\"\"\"`);\n return lines.join('\\n');\n};\n\n/** Dependency order, refusing anything unmet \u2014 naming the incident (ADR-0003). */\n/**\n * Every module in `order` that cannot be installed because one of the modules\n * it needs \u2014 or itself \u2014 is a different paradigm.\n *\n * A refusal has to travel *up* the dependency edges, not just stop at the\n * module that matched. `add audit` pulls `findings` which pulls `backlog`; if\n * the repo's work lives in an issue tracker, refusing `backlog` and installing\n * `audit` anyway would ship an audit procedure whose findings have nowhere to\n * close \u2014 which is the exact incident (268 audit documents, no register) that\n * made `audit \u2192 findings \u2192 backlog` a declared dependency in the first place.\n */\nexport function blockedByParadigm(order: Manifest[], paradigms: ReadonlySet<string>): Map<string, string> {\n const blocked = new Map<string, string>();\n // `order` is already dependency-first, so one forward pass settles it.\n for (const mod of order) {\n if (paradigms.has(mod.name)) {\n blocked.set(mod.name, mod.name);\n continue;\n }\n const dep = mod.requires.find((d) => blocked.has(d));\n if (dep) blocked.set(mod.name, blocked.get(dep)!);\n }\n return blocked;\n}\n\nexport function resolveInstallOrder(requested: string[], all: Manifest[]): { order: Manifest[]; missing: string[] } {\n const byName = new Map(all.map((m) => [m.name, m]));\n const order: Manifest[] = [];\n const missing: string[] = [];\n const seen = new Set<string>();\n const visit = (name: string) => {\n if (seen.has(name)) return;\n const mod = byName.get(name);\n if (!mod) {\n missing.push(name);\n return;\n }\n seen.add(name);\n for (const dep of mod.requires) visit(dep);\n order.push(mod);\n };\n // A module's gates are inert without the runner that executes them. Installing\n // `backlog` alone produced a `.ai/gates.toml` holding three entries and no\n // `[runner]` block \u2014 a registry nothing reads. Rather than making every\n // gate-shipping module declare the dependency (and `instructions`, which ships\n // gates and is what `gates` itself requires, could not), the runner is pulled\n // in whenever anything registers with it.\n //\n // It is visited **first**, not appended: installed last it arrived after other\n // modules had already merged entries into the registry, so its own file \u2014 the\n // one carrying `[runner]` \u2014 hit the never-overwrite rule and was skipped. The\n // owner of a shared file has to create it before anyone merges into it.\n const closure = new Set<string>();\n const collect = (n: string) => {\n if (closure.has(n)) return;\n const m = byName.get(n);\n if (!m) return;\n closure.add(n);\n m.requires.forEach(collect);\n };\n requested.forEach(collect);\n if ([...closure].some((n) => byName.get(n)!.gates.length) && byName.has('gates')) {\n visit('gates');\n }\n\n for (const r of requested) visit(r);\n return { order, missing };\n}\n\n/**\n * Content hash of what a module emitted, recorded at install.\n *\n * Without it `upgrade` cannot tell a file the user edited from one an older\n * module version wrote \u2014 and those want opposite treatment: the first is a\n * decision to respect, the second is the thing upgrade exists to replace.\n * It is also what makes ADR-0004's `ours-current` and `ours-diverged` states\n * decidable at all.\n */\nexport const contentHash = (s: string) => createHash('sha256').update(s.replace(/\\r\\n/g, '\\n')).digest('hex').slice(0, 12);\n\n/**\n * Files a module owns **outright** \u2014 not the shared ones it merges into.\n *\n * `AGENTS.md` and `.ai/gates.toml` are co-owned: a module creates them and then\n * every other module merges a block in, so their content differs from what any\n * single module emitted the moment the second module installs. Hashing them\n * reported both as diverged on a completely untouched repo. A file carrying\n * managed blocks is never whole-file upgraded \u2014 its **blocks** are, through the\n * merge path.\n */\nconst SHARED = new Set(['AGENTS.md', 'CLAUDE.md', '.gitignore', '.gitattributes', '.ai/gates.toml']);\n\n/**\n * Add the harness extensions a module opted this skill into.\n *\n * F-019. `[skills.work-item] extensions = { disable-model-invocation = true }`\n * was declared in the `backlog` manifest, documented in `modules/README.md`, and\n * **implemented at no layer**: `grep -n extensions src/*.ts` returned nothing, so\n * the key never reached the emitted `SKILL.md`, and the gate that is supposed to\n * police it could not see the opt-in either. `work-item` creates branches and\n * merges, and the manifest's stated reason for opting it out of model invocation\n * had been inert since it was written.\n *\n * Injected here rather than written into the source skill because that is the\n * point of the opt-in: the file stays spec-pure and portable\n * ([ADR-0001](../docs/decisions/ADR-0001-multi-harness-rendering.md)), and the\n * extension \u2014 with its portability cost \u2014 stays attached to the module's\n * decision to take it.\n */\nfunction withOptedInExtensions(mod: Manifest, rel: string, content: string): string {\n const name = rel.split(/[\\\\/]/)[0];\n const extensions = mod.skills?.[name]?.extensions;\n if (!extensions || !Object.keys(extensions).length) return content;\n\n const m = content.match(/^---\\n([\\s\\S]*?)\\n---/);\n if (!m) return content; // no frontmatter to extend; `skills-spec-pure` reports it\n const added = Object.entries(extensions)\n .filter(([k]) => !new RegExp(`^${k}:`, 'm').test(m[1]))\n .map(([k, v]) => `${k}: ${v}`);\n if (!added.length) return content;\n return content.replace(/^---\\n[\\s\\S]*?\\n---/, `---\\n${m[1]}\\n${added.join('\\n')}\\n---`);\n}\n\nexport function emittedFiles(mod: Manifest, params: Params, skillsDir = '.claude/skills'): Map<string, string> {\n const out = new Map<string, string>();\n const sub = (t: string) => substitute(t, mod.name, params);\n for (const [dir, prefix] of [\n ['files', ''],\n ['rules', '.ai/rules/'],\n ['skills', `${skillsDir}/`],\n ] as const) {\n const base = join(mod.dir, dir);\n if (!existsSync(base)) continue;\n for (const rel of walk(base)) {\n const target = sub(prefix + rel).split('\\\\').join('/');\n if (SHARED.has(target)) continue;\n let content = sub(readFileSync(join(base, rel), 'utf8'));\n if (dir === 'skills') content = withOptedInExtensions(mod, rel, content);\n out.set(target, content);\n }\n }\n return out;\n}\n\nexport function writeInstallRecord(\n repoRoot: string,\n mods: Manifest[],\n params: Params,\n harnesses: string[],\n stamp: string,\n skillsDir = '.claude/skills',\n /** Per module, the files rungs actually created \u2014 as opposed to kept. */\n wroteByModule?: Map<string, Set<string>>,\n) {\n const lines = [\n '# Installed by `rungs`. This is a record of what was written, not a control panel:',\n '# editing a parameter here does not rewrite a file that already exists. `rungs render`',\n '# re-emits path-scoped rules from `.ai/rules/`, and `rungs upgrade --apply` replaces',\n '# module files you have not edited \u2014 neither re-substitutes parameters. AGENTS.md,',\n '# CLAUDE.md, .gitignore, .gitattributes and .ai/gates.toml are shared between modules,',\n '# so only their `rungs:begin`/`rungs:end` blocks are ever updated; anything outside a',\n '# block, including the entry document\\'s title, is yours to edit directly.',\n '#',\n '# Hashes are what rungs emitted; a file whose hash no longer matches is a',\n '# divergence rungs reports and never overwrites.',\n '',\n '[repo]',\n `harnesses = ${JSON.stringify(harnesses)}`,\n `installed = \"${stamp}\"`,\n '',\n ];\n for (const m of mods) {\n lines.push(`[modules.${m.name}]`, `version = \"${m.version}\"`, 'state = \"managed\"');\n const p = params[m.name] ?? {};\n if (Object.keys(p).length) {\n lines.push(`params = { ${Object.entries(p).map(([k, v]) => `${k} = ${JSON.stringify(v ?? '')}`).join(', ')} }`);\n }\n // Only files rungs actually **wrote** get a hash. A file that already\n // existed was kept, and hashing it with our content would later read as a\n // divergence the user caused \u2014 implying they broke something they never\n // touched. Kept files are listed separately and stay theirs forever.\n const emitted = emittedFiles(m, params, skillsDir);\n const created = [...emitted].filter(([rel]) => (wroteByModule?.get(m.name)?.has(rel) ?? existsSync(join(repoRoot, rel))));\n const kept = [...emitted].filter(([rel]) => !created.some(([c]) => c === rel) && existsSync(join(repoRoot, rel)));\n if (created.length) {\n lines.push(`[modules.${m.name}.hashes]`);\n for (const [rel, content] of created) lines.push(`\"${rel}\" = \"${contentHash(content)}\"`);\n }\n if (kept.length) {\n lines.push('', `[modules.${m.name}]`.replace(']', '.kept]'));\n lines.push(`files = ${JSON.stringify(kept.map(([rel]) => rel))}`);\n }\n lines.push('');\n }\n writeFileSync(join(repoRoot, '.ai', 'rungs.toml'), lines.join('\\n'));\n}\n\nexport interface AdoptedGate {\n id: string;\n command: string;\n tier: string;\n source: string;\n}\n\n/**\n * Turn detected `adopt_as` matches into `command` gate entries.\n *\n * The interpreter is chosen from the extension, and an unknown one is skipped\n * rather than guessed at \u2014 a registry entry that cannot run is worse than one\n * that is absent, because it reports as a failure the owner did not cause.\n */\nexport function adoptableGates(files: string[], patterns: string[], repoRoot: string): AdoptedGate[] {\n const runner: Record<string, string> = { '.mjs': 'node', '.js': 'node', '.ps1': 'pwsh -File', '.sh': 'bash' };\n const out: AdoptedGate[] = [];\n for (const pattern of patterns) {\n for (const rel of matchAny(files, pattern)) {\n const ext = rel.slice(rel.lastIndexOf('.'));\n const exec = runner[ext];\n if (!exec) continue;\n out.push({\n id: `adopted-${rel.split('/').pop()!.replace(/\\.[^.]+$/, '')}`,\n command: `${exec} ${rel}`,\n tier: 'fast',\n source: rel,\n });\n }\n }\n return out;\n}\n", "import { basename, resolve } from 'node:path';\nimport type { Manifest } from './types.ts';\n\nexport type Params = Record<string, Record<string, unknown>>;\n\n/**\n * `{{param}}` substitution, in file contents and in path segments. No\n * conditionals, no loops \u2014 ADR-0003. A module that needs a conditional is two\n * modules, or reaches file content through a managed block.\n *\n * `${{ \u2026 }}` is never substituted: GitHub Actions expressions share the\n * delimiter, and without the passthrough the `ci` module corrupts its own\n * workflow file at install \u2014 a broken file rather than an error.\n */\nexport function substitute(text: string, module: string, params: Params): string {\n return text.replace(/(^|[^$])\\{\\{([a-z_.]+)\\}\\}/g, (whole, lead: string, ref: string) => {\n const [a, b] = ref.includes('.') ? ref.split('.') : [module, ref];\n const value = params[a]?.[b];\n if (value === undefined) return whole; // leave it visible rather than emitting an empty string\n return lead + format(value);\n });\n}\n\nfunction format(v: unknown): string {\n if (Array.isArray(v)) return `[${v.map((x) => JSON.stringify(x)).join(', ')}]`;\n if (typeof v === 'boolean' || typeof v === 'number') return String(v);\n return String(v);\n}\n\n/**\n * Facts about the target repository, addressable from a default as `{{repo.<key>}}`.\n *\n * `repo` is a **reserved namespace, not a module**, which is what keeps it clear of\n * `modules/README.md` rule 9b \u2014 referencing a module you have not declared is an undeclared\n * coupling, but every module already sits in a repository, so there is nothing to declare.\n *\n * Deliberately one key. `git_remote` and `branch` were considered and left out: nothing consumes\n * them, and rule 9e is about the knob wired to nothing that stays invisible until someone compares\n * every module at once.\n */\nfunction repoFacts(repoRoot?: string): Record<string, unknown> {\n return repoRoot ? { dirname: basename(resolve(repoRoot)) } : {};\n}\n\n/**\n * Defaults from every manifest, with explicit overrides applied on top.\n *\n * `repoRoot` is optional only so a caller with no repository in hand can still read defaults. When\n * it is absent `{{repo.dirname}}` does not resolve, and `substitute` leaves the token visible\n * rather than emitting an empty string \u2014 the same bias as every other unresolved reference, and\n * the reason a missing root shows up as a wrong-looking file instead of a silently blank heading.\n */\nexport function resolveParams(mods: Manifest[], overrides: Params = {}, repoRoot?: string): Params {\n const out: Params = { repo: repoFacts(repoRoot) };\n for (const m of mods) {\n out[m.name] = {};\n for (const [k, spec] of Object.entries(m.params)) out[m.name][k] = spec.default;\n }\n\n // **Overrides go on before cross-module references resolve.** They were\n // applied last, which meant a default referencing another module's parameter\n // had already baked in that module's *default* \u2014 so installing into hexguard\n // with `--set backlog.root=.ai/backlog` put the findings register at\n // `docs/.ai/backlog/FINDINGS.md` and left every link to it pointing at\n // `docs/backlog/FINDINGS.md`. The gate caught it on the first real install;\n // nothing in a scratch repo could have, because nothing there overrides.\n for (const [mod, vals] of Object.entries(overrides)) {\n out[mod] = { ...(out[mod] ?? {}), ...vals };\n }\n\n // A default may reference another module's parameter, e.g. findings' register\n // living at `docs/{{backlog.root}}/FINDINGS.md`. One level only \u2014 a chain\n // would be a template language arriving through the back door.\n for (const m of mods) {\n for (const [k, v] of Object.entries(out[m.name])) {\n if (typeof v === 'string' && v.includes('{{')) out[m.name][k] = substitute(v, m.name, out);\n }\n }\n return out;\n}\n\n/** Comment syntax for a managed block, chosen by the target file. */\nexport function markers(targetPath: string, module: string, version: string) {\n const hash = /\\.(toml|ya?ml|gitignore|gitattributes|sh|ps1|conf|properties)$|(^|\\/)\\.(gitignore|gitattributes)$/.test(\n targetPath,\n );\n return hash\n ? { begin: `# rungs:begin ${module}@${version}`, end: `# rungs:end ${module}` }\n : { begin: `<!-- rungs:begin ${module}@${version} -->`, end: `<!-- rungs:end ${module} -->` };\n}\n\n/**\n * Replace an existing managed block, or append one. Content outside every block\n * is the user's and is never touched \u2014 that is what makes the upgrade story\n * mechanical and divergence a decision rather than an error.\n */\nexport function mergeBlock(existing: string, fragment: string, module: string): string {\n const beginRe = new RegExp(`^[ \\\\t]*(?:<!--|#)\\\\s*rungs:begin ${module}(?:@[\\\\w.\\\\-]+)?\\\\s*(?:-->)?[ \\\\t]*$`, 'm');\n const endRe = new RegExp(`^[ \\\\t]*(?:<!--|#)\\\\s*rungs:end ${module}\\\\s*(?:-->)?[ \\\\t]*$`, 'm');\n const b = existing.match(beginRe);\n const e = existing.match(endRe);\n if (b && e && b.index !== undefined && e.index !== undefined && e.index > b.index) {\n const before = existing.slice(0, b.index);\n const after = existing.slice(e.index + e[0].length);\n return `${before}${fragment.trim()}${after}`;\n }\n const sep = existing.endsWith('\\n\\n') ? '' : existing.endsWith('\\n') ? '\\n' : '\\n\\n';\n return `${existing}${sep}${fragment.trim()}\\n`;\n}\n", "import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { walk } from './glob.ts';\n\nexport type Harness = 'claude' | 'copilot' | 'cursor' | 'agents-md';\n\nexport interface Rule {\n file: string;\n description?: string;\n paths: string[];\n enforcement?: string;\n body: string;\n}\n\nexport interface RenderEntry {\n rule: string;\n harness: Harness;\n target?: string;\n degraded?: string;\n dropped?: string[];\n}\n\nconst DO_NOT_EDIT = (source: string) =>\n `Generated by \\`rungs render\\` from ${source}. Do not edit \u2014 your changes are overwritten.`;\n\n/** Parse `.ai/rules/*.md`: the neutral source ADR-0001 renders from. */\nexport function readRules(repoRoot: string): Rule[] {\n const dir = join(repoRoot, '.ai', 'rules');\n const rules: Rule[] = [];\n let files: string[];\n try {\n files = walk(dir).filter((f) => f.endsWith('.md') && f !== 'README.md');\n } catch {\n return rules;\n }\n for (const rel of files) {\n const raw = readFileSync(join(dir, rel), 'utf8');\n const m = raw.match(/^---\\n([\\s\\S]*?)\\n---\\n([\\s\\S]*)$/);\n if (!m) continue;\n const [, fm, body] = m;\n rules.push({\n file: rel,\n description: scalar(fm, 'description'),\n paths: list(fm, 'paths'),\n enforcement: scalar(fm, 'enforcement'),\n body: body.trim(),\n });\n }\n return rules;\n}\n\nfunction scalar(fm: string, key: string): string | undefined {\n const folded = fm.match(new RegExp(`^${key}:\\\\s*>-?\\\\s*\\\\n([\\\\s\\\\S]*?)(?=\\\\n\\\\S|$)`, 'm'));\n if (folded) return folded[1].split('\\n').map((l) => l.trim()).filter(Boolean).join(' ');\n const plain = fm.match(new RegExp(`^${key}:\\\\s*(.+)$`, 'm'));\n return plain?.[1].trim().replace(/^[\"']|[\"']$/g, '');\n}\n\nfunction list(fm: string, key: string): string[] {\n const block = fm.match(new RegExp(`^${key}:\\\\s*\\\\n((?:\\\\s*-\\\\s*.+\\\\n?)+)`, 'm'));\n if (!block) return [];\n return [...block[1].matchAll(/^\\s*-\\s*(.+)$/gm)].map((m) => m[1].trim().replace(/^[\"']|[\"']$/g, ''));\n}\n\n/**\n * Emit one rule into one harness's dialect. Full bodies, never pointers: a\n * wrapper that references a shared file relies on the harness following the\n * reference, and only some do. A rule that does not load is worth nothing.\n */\nexport function renderRule(rule: Rule, harness: Harness): { target: string; content: string; dropped: string[] } | { degraded: string } {\n const stem = rule.file.replace(/\\.md$/, '');\n const source = `.ai/rules/${rule.file}`;\n const dropped: string[] = [];\n\n if (harness === 'claude') {\n // No description field in a Claude rule; the routing is done by `paths`.\n if (rule.description) dropped.push('description');\n const fm = rule.paths.length ? `paths:\\n${rule.paths.map((p) => ` - \"${p}\"`).join('\\n')}\\n` : '';\n return {\n target: `.claude/rules/${stem}.md`,\n content: `---\\n${fm}---\\n\\n<!-- ${DO_NOT_EDIT(source)} -->\\n\\n${rule.body}\\n`,\n dropped,\n };\n }\n\n if (harness === 'copilot') {\n const applyTo = rule.paths.length ? rule.paths.join(', ') : '**/*';\n const desc = rule.description ? `description: '${rule.description.replace(/'/g, \"''\")}'\\n` : '';\n return {\n target: `.github/instructions/${stem}.instructions.md`,\n content: `---\\n${desc}applyTo: '${applyTo}'\\n---\\n\\n<!-- ${DO_NOT_EDIT(source)} -->\\n\\n${rule.body}\\n`,\n dropped,\n };\n }\n\n if (harness === 'cursor') {\n // `.mdc` is required \u2014 a plain .md in .cursor/rules is ignored entirely.\n const desc = rule.description ? `description: ${rule.description}\\n` : '';\n const globs = rule.paths.length ? `globs: ${rule.paths.join(',')}\\n` : '';\n return {\n target: `.cursor/rules/${stem}.mdc`,\n content: `---\\n${desc}${globs}alwaysApply: ${rule.paths.length === 0}\\n---\\n\\n<!-- ${DO_NOT_EDIT(source)} -->\\n\\n${rule.body}\\n`,\n dropped,\n };\n }\n\n // AGENTS.md-only harnesses have no glob scoping at all. Degrade explicitly\n // and report it \u2014 never drop a rule silently.\n const prefix = commonDirPrefix(rule.paths);\n if (prefix) {\n return {\n target: `${prefix}/AGENTS.md`,\n content: `<!-- ${DO_NOT_EDIT(source)} -->\\n\\n${rule.body}\\n`,\n dropped: ['description', 'paths (directory-scoped instead of glob)'],\n };\n }\n return {\n degraded: `routing-only: globs do not share a directory prefix, so root AGENTS.md gets a pointer to ${source}`,\n };\n}\n\nfunction commonDirPrefix(paths: string[]): string | null {\n if (!paths.length) return null;\n const dirs = paths.map((p) => p.split('/').filter((s) => !s.includes('*')).join('/')).filter(Boolean);\n if (dirs.length !== paths.length) return null;\n const first = dirs[0];\n return dirs.every((d) => d === first) && first.includes('/') ? first : null;\n}\n\nexport function render(repoRoot: string, harnesses: Harness[]): RenderEntry[] {\n const rules = readRules(repoRoot);\n const entries: RenderEntry[] = [];\n const routingOnly: Rule[] = [];\n\n for (const rule of rules) {\n for (const harness of harnesses) {\n const out = renderRule(rule, harness);\n if ('degraded' in out) {\n entries.push({ rule: rule.file, harness, degraded: out.degraded });\n if (harness === 'agents-md') routingOnly.push(rule);\n continue;\n }\n const full = join(repoRoot, out.target);\n mkdirSync(dirname(full), { recursive: true });\n writeFileSync(full, out.content);\n entries.push({ rule: rule.file, harness, target: out.target, dropped: out.dropped });\n }\n }\n\n // The report said root AGENTS.md \"gets a pointer\" and nothing wrote one \u2014 a\n // degradation notice that was itself a silent drop, in the function whose\n // whole job is not to have those. Written now, as a managed block.\n writeRoutingBlock(repoRoot, routingOnly, harnesses);\n return entries;\n}\n\nfunction writeRoutingBlock(repoRoot: string, rules: Rule[], harnesses: Harness[]) {\n if (!harnesses.includes('agents-md')) return;\n const target = join(repoRoot, 'AGENTS.md');\n if (!existsSync(target)) return;\n const begin = '<!-- rungs:begin rules-routing -->';\n const end = '<!-- rungs:end rules-routing -->';\n\n const body = rules.length\n ? [\n begin,\n '## Rules for specific paths',\n '',\n 'This harness has no glob scoping, so these load only if you open them. **Read the one that',\n 'matches what you are editing before editing broadly.**',\n '',\n ...rules.map((r) => `- \\`${r.paths.join('\\`, \\`')}\\` \u2192 [\\`.ai/rules/${r.file}\\`](.ai/rules/${r.file})`),\n end,\n ].join('\\n')\n : '';\n\n const existing = readFileSync(target, 'utf8');\n const beginRe = /^[ \\t]*<!--\\s*rungs:begin rules-routing\\s*-->[ \\t]*$/m;\n const endRe = /^[ \\t]*<!--\\s*rungs:end rules-routing\\s*-->[ \\t]*$/m;\n const b = existing.match(beginRe);\n const e = existing.match(endRe);\n if (b && e && b.index !== undefined && e.index !== undefined) {\n const next = existing.slice(0, b.index) + body.trim() + existing.slice(e.index + e[0].length);\n writeFileSync(target, body ? next : next.replace(/\\n{3,}/g, '\\n\\n'));\n return;\n }\n if (body) writeFileSync(target, `${existing.replace(/\\n+$/, '\\n')}\\n${body}\\n`);\n}\n\n/**\n * ADR-0001: a render that quietly dropped a rule reads identically to one that\n * had nothing to drop, so every degradation lands here.\n */\nexport function writeReport(repoRoot: string, entries: RenderEntry[], harnesses: Harness[], stamp: string): string {\n const lines = [\n '# Render report',\n '',\n `> Generated by \\`rungs render\\` on ${stamp}. Do not edit.`,\n '',\n `Harnesses: ${harnesses.join(', ')}`,\n '',\n '| Rule | Harness | Emitted | Dropped / degraded |',\n '| --- | --- | --- | --- |',\n ];\n for (const e of entries) {\n const lost = e.degraded ?? (e.dropped?.length ? e.dropped.join(', ') : '\u2014');\n lines.push(`| \\`${e.rule}\\` | ${e.harness} | ${e.target ? `\\`${e.target}\\`` : '**not emitted**'} | ${lost} |`);\n }\n const degraded = entries.filter((e) => e.degraded).length;\n const lossy = entries.filter((e) => e.dropped?.length).length;\n lines.push(\n '',\n `${entries.length} renderings \u00B7 ${lossy} lost a field \u00B7 ${degraded} degraded.`,\n '',\n 'A field listed as dropped is one the target harness has no way to express. It is recorded',\n 'here rather than silently discarded, so a repo can see what its harness choice costs it.',\n '',\n );\n const content = lines.join('\\n');\n writeFileSync(join(repoRoot, '.ai', 'render-report.md'), content);\n return content;\n}\n", "import { appendFileSync, existsSync, readFileSync } from 'node:fs';\nimport { execSync } from 'node:child_process';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { parse } from 'smol-toml';\nimport { ENGINES, isImplemented, type Finding } from './engines.ts';\nimport { walk } from './glob.ts';\nimport { resolveParams, substitute, type Params } from './substitute.ts';\nimport { loadAllModules } from './manifest.ts';\n\nconst MODULES = join(dirname(fileURLToPath(import.meta.url)), '..', 'modules');\n\nexport type Status = 'pass' | 'fail' | 'unimplemented' | 'error';\n\nexport interface GateRun {\n id: string;\n module?: string;\n kind: string;\n engine?: string;\n tier: string;\n status: Status;\n ms: number;\n examined: number;\n findings: Finding[];\n why?: string;\n}\n\ninterface RegistryGate {\n id: string;\n kind: string;\n module?: string;\n engine?: string;\n table?: string;\n command?: string;\n tier?: string;\n trigger?: string;\n why?: string;\n}\n\nexport function loadRegistry(repoRoot: string): { runner: any; gates: RegistryGate[] } {\n const path = join(repoRoot, '.ai', 'gates.toml');\n if (!existsSync(path)) return { runner: {}, gates: [] };\n const raw = parse(readFileSync(path, 'utf8')) as any;\n return { runner: raw.runner ?? {}, gates: raw.gates ?? [] };\n}\n\n/**\n * ADR-0008: a tier is an ordered **level**, not a tag. `[runner] tiers` declares\n * the order, and asking for one runs every gate at that level or below it.\n *\n * This was string equality, so `full` selected only gates labelled `full` \u2014 zero\n * of them on a registry where everything is `fast`, which is this repo. The run\n * then reported no gates and exited as though the release had been gated, and\n * `cut-release` told every consumer to gate on exactly that command (F-020).\n */\nexport function tierSelects(runnerTiers: string[], requested: string, gateTier?: string): boolean {\n if (!gateTier) return true; // untiered gates run in every tier\n const at = runnerTiers.indexOf(requested);\n const of = runnerTiers.indexOf(gateTier);\n // An undeclared tier on either side cannot be ordered. Fall back to equality\n // rather than guessing a position \u2014 silently including it would be worse.\n if (at < 0 || of < 0) return gateTier === requested;\n return of <= at;\n}\n\n/**\n * No parameter properties: Node's strip-only TypeScript mode rejects them, and\n * `dist/` is built from these sources for a runtime that has no compiler. The\n * same constraint is what v0.1.1 shipped broken (ERR_UNSUPPORTED_NODE_MODULES_\n * TYPE_STRIPPING), so it is worth the four extra lines.\n */\nexport class UnknownTierError extends Error {\n requested: string;\n declared: string[];\n constructor(requested: string, declared: string[]) {\n super(`unknown tier \"${requested}\"`);\n this.requested = requested;\n this.declared = declared;\n }\n}\n\nexport function runGates(repoRoot: string, tier?: string, now = () => Date.now()): GateRun[] {\n const { runner, gates } = loadRegistry(repoRoot);\n const runnerTiers: string[] = Array.isArray(runner?.tiers) ? runner.tiers : [];\n // A tier nobody declared selects nothing, and \"selected nothing\" is\n // indistinguishable from \"everything passed\" at the exit code. Refuse it here\n // rather than let a typo read as a green release gate.\n if (tier && runnerTiers.length && !runnerTiers.includes(tier)) {\n throw new UnknownTierError(tier, runnerTiers);\n }\n const files = walk(repoRoot);\n const runs: GateRun[] = [];\n\n for (const g of gates) {\n // A hook fires on a tool call, not in the runner. Skipping it here is\n // correct; counting it as a pass would not be.\n if (g.trigger) continue;\n if (tier && !tierSelects(runnerTiers, tier, g.tier)) continue;\n\n const started = now();\n let status: Status = 'pass';\n let findings: Finding[] = [];\n let examined = 0;\n\n if (g.kind === 'command' && g.command) {\n try {\n execSync(g.command, { cwd: repoRoot, stdio: 'pipe' });\n } catch (e: any) {\n status = 'fail';\n findings = [{ message: String(e.stderr ?? e.stdout ?? e.message).trim().split('\\n').slice(-3).join(' ') }];\n }\n } else if (!g.engine || !isImplemented(g.engine)) {\n // Never green. An engine named in a table and missing from the CLI is an\n // unknown, and a registry reporting green because most of its gates do\n // nothing is the worst failure this tool could have.\n status = 'unimplemented';\n findings = [{ message: `engine '${g.engine ?? '(none)'}' is not implemented` }];\n } else {\n const table = loadTable(g.table, repoRoot);\n if (!table) {\n status = 'error';\n findings = [{ message: `table '${g.table}' not found` }];\n } else {\n try {\n const key = tableKey(g.engine);\n let section = table[key] ?? table;\n // An array table holds one entry per gate; select by trailing id.\n if (Array.isArray(section) && section.some((s: any) => s?.id)) {\n const mine = section.filter((s: any) => !s.id || g.id.includes(s.id));\n if (mine.length) section = mine;\n }\n const r = ENGINES[g.engine](section, repoRoot, files);\n findings = r.findings;\n examined = r.examined;\n status = r.findings.length ? 'fail' : 'pass';\n } catch (e: any) {\n status = 'error';\n findings = [{ message: e.message }];\n }\n }\n }\n\n runs.push({\n id: g.id,\n module: g.module,\n kind: g.kind,\n engine: g.engine,\n tier: g.tier ?? 'fast',\n status,\n ms: now() - started,\n examined,\n findings,\n why: g.why,\n });\n }\n return runs;\n}\n\n/**\n * A table lives in the CLI's module set, not in the repo (ADR-0002) \u2014 but it is\n * authored with `{{param}}` placeholders, so it is **not valid TOML until\n * substituted**: `max_lines = {{core_budget}}` parses as nothing.\n *\n * Found by running the runner, which reported `table not found` for a file\n * plainly on disk. Tables are substituted against the repo's own installed\n * parameters before parsing \u2014 which is also what makes a gate honour the\n * prefix, root and budget that repo actually chose.\n */\nexport function loadTable(ref: string | undefined, repoRoot: string): any | null {\n if (!ref) return null;\n const [mod, file] = ref.split('/');\n const path = join(MODULES, mod, 'gates', file);\n if (!existsSync(path)) return null;\n try {\n return parse(substitute(readFileSync(path, 'utf8'), mod, installedParams(repoRoot)));\n } catch {\n return null;\n }\n}\n\nlet paramCache: { root: string; params: Params } | null = null;\n\n/** Parameters as the repo installed them, falling back to module defaults. */\nfunction installedParams(repoRoot: string): Params {\n if (paramCache?.root === repoRoot) return paramCache.params;\n const defaults = resolveParams(loadAllModules(MODULES), {}, repoRoot);\n const recordPath = join(repoRoot, '.ai', 'rungs.toml');\n if (existsSync(recordPath)) {\n try {\n const rec = parse(readFileSync(recordPath, 'utf8')) as any;\n for (const [name, entry] of Object.entries<any>(rec.modules ?? {})) {\n if (entry?.params) defaults[name] = { ...(defaults[name] ?? {}), ...entry.params };\n }\n } catch {\n /* a malformed record falls back to defaults rather than failing every gate */\n }\n }\n paramCache = { root: repoRoot, params: defaults };\n return defaults;\n}\n\nexport const tableKey = (engine: string) =>\n ({\n 'file-budget': 'file_budget',\n sections: 'sections',\n 'frontmatter-schema': 'frontmatter_schema',\n 'link-integrity': 'link_integrity',\n 'file-population': 'file_population',\n 'gate-meta': 'gate_meta',\n 'id-integrity': '__whole__',\n 'render-freshness': 'render_freshness',\n 'register-schema': 'register_schema',\n 'self-declared-closure': 'self_declared_closure',\n 'filename-schema': 'filename_schema',\n 'cross-reference': 'cross_reference',\n 'git-status-reconcile': 'merged_status',\n 'computed-claim': 'computed_claim',\n 'term-ownership': 'term_ownership',\n 'rule-propagation': 'rule_propagation',\n 'git-state': 'git_state',\n 'merge-driver-check': 'merge_driver_check',\n 'board-reconcile': 'board_reconcile',\n })[engine] ?? engine;\n\n/**\n * ADR-0005 tier A. One line per gate per run: what the runner directly observes\n * and nothing that needs interpretation. Local, gitignored, never transmitted.\n */\nexport function appendLedger(repoRoot: string, runs: GateRun[], stamp: string) {\n const { runner } = loadRegistry(repoRoot);\n if (runner.ledger === false) return;\n const path = join(repoRoot, '.ai', '.gate-ledger.jsonl');\n const lines = runs\n .map((r) => JSON.stringify({ at: stamp, id: r.id, status: r.status, ms: r.ms, examined: r.examined }))\n .join('\\n');\n appendFileSync(path, lines + '\\n');\n}\n\n/** The two questions ADR-0005 tier B allows, both binary facts. */\nexport function ledgerQuestions(repoRoot: string, gates: RegistryGate[]) {\n const path = join(repoRoot, '.ai', '.gate-ledger.jsonl');\n if (!existsSync(path)) return { neverFired: [], alwaysFires: [], runs: 0 };\n const rows = readFileSync(path, 'utf8')\n .split('\\n')\n .filter(Boolean)\n .map((l) => JSON.parse(l) as { id: string; status: Status });\n const by = new Map<string, { total: number; failed: number }>();\n for (const r of rows) {\n const e = by.get(r.id) ?? { total: 0, failed: 0 };\n e.total++;\n if (r.status === 'fail') e.failed++;\n by.set(r.id, e);\n }\n const whyOf = (id: string) => gates.find((g) => g.id === id)?.why;\n const neverFired = [...by].filter(([, e]) => e.total >= 3 && e.failed === 0).map(([id]) => ({ id, why: whyOf(id) }));\n const alwaysFires = [...by]\n .filter(([, e]) => e.total >= 3 && e.failed / e.total > 0.9)\n .map(([id, e]) => ({ id, why: whyOf(id), rate: `${e.failed}/${e.total}` }));\n return { neverFired, alwaysFires, runs: rows.length };\n}\n", "import { existsSync, readFileSync, statSync } from 'node:fs';\nimport { join, dirname, resolve } from 'node:path';\nimport { matchAny, walk } from './glob.ts';\nimport { parse as parseToml } from 'smol-toml';\nimport { runSelfTests } from './selftest.ts';\nimport { loadAllModules } from './manifest.ts';\nimport { resolveParams, substitute } from './substitute.ts';\nimport {\n computedClaim,\n crossReference,\n filenameSchema,\n gitStatusReconcile,\n idIntegrity,\n registerSchema,\n renderFreshness,\n selfDeclaredClosure,\n} from './engines2.ts';\nimport { boardReconcile, changelogFreshness, gitState, mergeDriverCheck, rulePropagation, termOwnership } from './engines3.ts';\n\nexport interface Finding {\n file?: string;\n message: string;\n}\nexport interface EngineResult {\n findings: Finding[];\n /** What the engine looked at. A gate that examined nothing is not a passing gate. */\n examined: number;\n}\nexport type Engine = (table: any, repoRoot: string, files: string[]) => EngineResult;\n\nconst read = (root: string, rel: string) => {\n try {\n return readFileSync(join(root, rel), 'utf8');\n } catch {\n return '';\n }\n};\n\n/**\n * `expand` also drops anything the CLI generated.\n *\n * Without it a gate fires on its own tool's output: `render` degrades a\n * path-scoped rule into a nested `docs/plans/AGENTS.md` for harnesses with no\n * glob scoping, and the `workflows` gate \u2014 which scans `docs/plans/**` for plan\n * documents \u2014 then reported that file for having no plan frontmatter. The\n * render pipeline and the gate scopes collide by construction, so the exclusion\n * is global rather than per-table: **a gate must never fire on a file rungs\n * wrote.**\n */\nconst GENERATED = 'Generated by `rungs';\n\nconst expand = (files: string[], patterns: string[] | undefined, fallback: string[] = []) =>\n [...new Set((patterns ?? fallback).flatMap((p) => matchAny(files, p)))];\n\nfunction dropGenerated(root: string, rels: string[]): string[] {\n return rels.filter((rel) => !read(root, rel).slice(0, 600).includes(GENERATED));\n}\n\n/** Lines that actually load: HTML comments are stripped by at least one harness. */\nfunction loadedLines(text: string): number {\n return text\n .replace(/^---\\n[\\s\\S]*?\\n---\\n/, '')\n .replace(/<!--[\\s\\S]*?-->/g, '')\n .split('\\n')\n .filter((l) => l.trim()).length;\n}\n\nconst fileBudget: Engine = (t, root, files) => {\n const targets = dropGenerated(root, t.file ? [t.file] : expand(files, t.scan));\n const excluded = new Set(expand(files, t.exclude, []));\n const findings: Finding[] = [];\n let examined = 0;\n for (const rel of targets) {\n if (excluded.has(rel) || !existsSync(join(root, rel))) continue;\n examined++;\n const n = loadedLines(read(root, rel));\n // \"1358 lines\" invites `wc -l`, which answered 1413 on the same file\n // (hexguard-templates, 2026-08-16) because this counts what actually *loads*\n // \u2014 frontmatter, HTML comments and blank lines stripped. Naming the measure\n // is the difference between evidence and a number the reader disproves.\n if (n > t.max_lines) {\n findings.push({ file: rel, message: `${n} loaded lines (blank lines and comments excluded), budget ${t.max_lines}` });\n }\n }\n return { findings, examined };\n};\n\nconst sections: Engine = (t, root, files) => {\n const specs = Array.isArray(t) ? t : [t];\n const findings: Finding[] = [];\n let examined = 0;\n for (const spec of specs) {\n const targets = dropGenerated(root, spec.file ? [spec.file] : expand(files, spec.scan));\n const excluded = new Set(expand(files, spec.exclude, []));\n for (const rel of targets) {\n if (excluded.has(rel) || !existsSync(join(root, rel))) continue;\n examined++;\n const text = read(root, rel);\n const matches = [...text.matchAll(/^(#{1,6})\\s+(.+?)\\s*$/gm)];\n const heads = matches.map((m) => m[2]);\n for (const want of spec.required ?? []) {\n const idx = heads.findIndex((h) => h.toLowerCase().startsWith(String(want).toLowerCase()));\n if (idx === -1) {\n findings.push({ file: rel, message: `missing section '${want}'` });\n continue;\n }\n if (spec.non_empty) {\n // Content runs to the next heading of the **same or higher** level, so\n // a section made of subsections is not empty. Splitting on any heading\n // reported ADR-0002's `## Decision` as empty because a `### (a)`\n // follows it immediately \u2014 the first finding this gate produced, and a\n // false one (F-018). A section whose whole body is subsections is the\n // normal shape for a long decision.\n const level = matches[idx][1].length;\n const after = text.slice(matches[idx].index! + matches[idx][0].length);\n const body = after\n .split(new RegExp(`^#{1,${level}}\\\\s+`, 'm'))[0]\n .replace(/<!--[\\s\\S]*?-->/g, '')\n .trim();\n if (!body) findings.push({ file: rel, message: `section '${want}' is empty` });\n }\n }\n for (const open of spec.requires_opening ?? []) {\n if (!text.slice(0, 400).includes(open)) findings.push({ file: rel, message: `does not open with ${open}` });\n }\n }\n }\n return { findings, examined };\n};\n\nexport const frontmatterSchema: Engine = (t, root, files) => {\n const specs = Array.isArray(t) ? t : [t];\n const findings: Finding[] = [];\n let examined = 0;\n for (const spec of specs) {\n for (const rel of dropGenerated(root, expand(files, spec.scan))) {\n if (new Set(expand(files, spec.exclude, [])).has(rel)) continue;\n const text = read(root, rel);\n const m = text.match(/^---\\n([\\s\\S]*?)\\n---/);\n if (!m) {\n findings.push({ file: rel, message: 'no frontmatter' });\n continue;\n }\n examined++;\n const keys = [...m[1].matchAll(/^([a-zA-Z0-9_-]+):/gm)].map((k) => k[1]);\n for (const req of spec.required ?? []) {\n if (!keys.includes(req)) findings.push({ file: rel, message: `missing '${req}'` });\n }\n if (spec.allowed) {\n // `extensions_allowed_from` names the manifest that may legalise a\n // non-spec key. It was declared in the skills table and read nowhere\n // (F-019), so an extension a module had deliberately opted into was\n // indistinguishable from one somebody typed by mistake \u2014 and the\n // portability cost the opt-in exists to record was attached to nothing.\n const optedIn = spec.extensions_allowed_from ? optedInExtensions(rel, spec) : new Set<string>();\n for (const k of keys) {\n if (spec.allowed.includes(k) || optedIn.has(k)) continue;\n findings.push({ file: rel, message: `non-spec key '${k}'` });\n }\n }\n const field = (k: string) => m[1].match(new RegExp(`^${k}:\\\\s*(.+)$`, 'm'))?.[1].trim().replace(/^[\"']|[\"']$/g, '');\n for (const [key, values] of Object.entries(spec.enum ?? {})) {\n const v = field(key);\n if (v && !(values as string[]).map(String).includes(v)) {\n findings.push({ file: rel, message: `${key}='${v}' not one of ${(values as string[]).join(', ')}` });\n }\n }\n\n // `[frontmatter_schema.reciprocal]` was configured in the `adr` table and\n // implemented nowhere \u2014 the third instance of F-007's shape, and this one\n // was found by *executing* a self-test rather than by reading (F-018).\n // Its fail fixture is a `superseded` record with no `superseded_by`, which\n // could never have failed while nothing read the rule.\n //\n // A one-way supersession leaves a reader on the stale record with no route\n // to the live one, which is the whole point of recording it.\n for (const pair of spec.reciprocal?.pairs ?? []) {\n const from = field(pair.from);\n if (!from) continue;\n const target = expand(files, spec.scan).find((r) => r.includes(from.replace(/\\.md$/, '')));\n if (!target) {\n findings.push({ file: rel, message: `${pair.from} names '${from}', which is not a record here` });\n continue;\n }\n const back = read(root, target).match(/^---\\n([\\s\\S]*?)\\n---/)?.[1] ?? '';\n const id = field('id') ?? '';\n if (!new RegExp(`^${pair.to}:\\\\s*.*${escapeRe(id)}`, 'm').test(back)) {\n findings.push({ file: rel, message: `${pair.from} \u2192 ${from}, but it does not name this record back in '${pair.to}'` });\n }\n }\n // A status that implies the pairing must actually carry it.\n for (const [status, requires] of Object.entries(spec.reciprocal?.required_when ?? {})) {\n if (field('status') === status && !field(String(requires))) {\n findings.push({ file: rel, message: `status is '${status}' but '${requires}' is absent` });\n }\n }\n }\n }\n return { findings, examined };\n};\n\n/**\n * Does a link target resolve, under any reading of it?\n *\n * `path/to/file.ts:387` is a code reference, not a broken link \u2014 it is the form\n * `CLAUDE.md` mandates in this repo (\"Reference code as `file_path:line_number`\")\n * and the form editors and terminals click. The engine resolved it literally and\n * reported the file missing while the file sat exactly there.\n *\n * Measured 2026-08-16 on `rift-forge` via `doctor --explain`: **1,794 of 3,851\n * link findings \u2014 46.6% \u2014 were this**, every one a real file with a line number\n * after it. Latent since WI-008 made link checking per-link; before that, one\n * `{{token}}` anywhere in a file exempted every link in it, which hid it.\n *\n * Resolve as written first, and only then retry without a trailing `:line` or\n * `:line:col`. Strip-and-retest rather than strip-and-assume: a link is called\n * broken only when **no** reading of it resolves, so this can only ever remove\n * findings. Stripping unconditionally would silence a genuinely missing\n * `foo.ts:12` whenever an equally missing `foo.ts` explained it away.\n */\nfunction resolvesHere(root: string, rel: string, href: string): boolean {\n const from = dirname(rel);\n const decoded = decodeURIComponent(href);\n if (existsSync(resolve(root, from, decoded))) return true;\n const stripped = decoded.replace(/:\\d+(?::\\d+)?$/, '');\n return stripped !== decoded && existsSync(resolve(root, from, stripped));\n}\n\n/**\n * A backticked path in an instruction file \u2014 `docs/backlog/BACKLOG.md` \u2014 that no\n * longer exists. F-007: `backticked_paths` was named in the table's `check` list\n * and implemented nowhere, so `gates-paths-exist` silently ran the markdown-link\n * scan instead and reported every finding a second time.\n *\n * Resolved from the **repo root**, because that is what an instruction file's\n * reader does with a path it is told to go and read. Skipped when the span is a\n * glob, a template token, a URL, or has no path shape at all: prose is full of\n * `identifiers`, and a gate that refuses every code span is one people delete.\n */\nfunction backtickedPaths(rel: string, text: string, root: string, hints: string[]): Finding[] {\n const out: Finding[] = [];\n const seen = new Set<string>();\n for (const m of text.matchAll(/`([^`\\n]+)`/g)) {\n const raw = m[1].trim();\n if (seen.has(raw) || !hints.some((h) => raw.includes(h))) continue;\n seen.add(raw);\n\n // Every exclusion below is a measured false positive from the first run of\n // this check against this repo, 2026-08-16 \u2014 which produced ten findings,\n // all ten wrong. The table's own instruction is that under-detection is the\n // correct bias, so the shape is narrowed to the incident it was written for:\n // hexguard's instruction files naming a **repo-relative file** that moved.\n if (raw.startsWith('/')) continue; // `/work-item` \u2014 a skill invocation\n if (/[*?{}#\\s]|^\\w+:/.test(raw)) continue; // globs, `WI-###` placeholders, prose, URLs\n if (!raw.includes('/')) continue; // `work-items.md` \u2014 a bare name, anchor unknown\n if (!/\\.[a-z0-9]{1,5}$/i.test(raw)) continue; // `.cursor/rules/` \u2014 a directory, often illustrative\n\n // Two anchors, because instruction files use both: repo-root paths for \"go\n // read this\", and `../` paths relative to the file itself.\n const bare = raw.replace(/^\\.\\//, '');\n if (!existsSync(join(root, bare)) && !existsSync(resolve(root, dirname(rel), bare))) {\n out.push({ message: `stale path in a code span \u2192 ${raw}` });\n }\n }\n return out;\n}\n\nexport const linkIntegrity: Engine = (t, root, files) => {\n // The table is now one entry per gate (F-007). The runner hands an array\n // through when it selects by id; take the single entry it selected.\n if (Array.isArray(t)) t = t[0] ?? {};\n const checks: string[] = t.check ?? ['relative_markdown_links'];\n const scan = expand(files, t.scan, ['**/*.md']); // link checks DO cover generated files\n const excluded = new Set(expand(files, t.exclude, []));\n const findings: Finding[] = [];\n let examined = 0;\n for (const rel of scan) {\n if (excluded.has(rel)) continue;\n const text = read(root, rel);\n examined++;\n if (/path-ok:\\s*\\S/.test(text)) continue;\n if (checks.includes('backticked_paths')) {\n findings.push(...backtickedPaths(rel, text, root, t.path_hint ?? ['/']).map((f) => ({ ...f, file: rel })));\n }\n if (!checks.includes('relative_markdown_links')) continue;\n // A link written inside a code span is prose *quoting* a link \u2014 most often a document\n // explaining that some link is wrong. Blanked rather than removed, so every offset after it\n // is unchanged and the reported text still matches what the author sees.\n const scannable = text.replace(/`+[^`\\n]*`+/g, (s) => ' '.repeat(s.length));\n for (const m of scannable.matchAll(/\\]\\((?!https?:|#|mailto:)([^)\\s#]+)/g)) {\n // An unsubstituted placeholder makes a **template** link, which resolves only once\n // installed. This test used to sit on the whole file, and one token anywhere in a document\n // exempted every link in it: 16 non-excluded files, including eight that ship to consumer\n // repos, silently stopped being checked. A green gate and a skipped file looked identical.\n // The case the file-level skip was written for \u2014 `modules/*/fragments/AGENTS.md` linking\n // `{{path}}/README.md` \u2014 is already excluded by path in `link_integrity.exclude` (WI-008).\n if (/\\{\\{[a-z_.]+\\}\\}/.test(m[1])) continue;\n if (!resolvesHere(root, rel, m[1])) findings.push({ file: rel, message: `broken link \u2192 ${m[1]}` });\n }\n }\n return { findings, examined };\n};\n\nconst filePopulation: Engine = (t, root, files) => {\n let hits = dropGenerated(root, expand(files, t.scan)).filter((f) => !new Set(expand(files, t.exclude, [])).has(f));\n\n // A `detect` narrows the population to files matching a shape. Without it the\n // gate counted *every scanned file* \u2014 so the redirect-stub check reported\n // \"12 matching files, threshold 1\" against a repo with no stubs at all, which\n // is a confidently wrong number rather than a finding.\n if (t.detect === 'body_is_only_a_pointer') {\n hits = hits.filter((rel) => {\n const body = read(root, rel)\n .replace(/^---\\n[\\s\\S]*?\\n---\\n/, '')\n .replace(/<!--[\\s\\S]*?-->/g, '')\n .replace(/^#.*$/gm, '')\n .trim();\n const words = body.split(/\\s+/).filter(Boolean).length;\n const links = (body.match(/\\]\\(/g) ?? []).length;\n // Short *and* mostly a link. Short alone is a stub-shaped index page.\n return words > 0 && words <= (t.max_body_words ?? 40) && links >= 1;\n });\n }\n\n const findings: Finding[] = [];\n const failAt = t.fail_at ?? Infinity;\n if (hits.length >= failAt) {\n // The count is only re-derivable if the reader knows what was counted.\n // `audit-output-is-rows` reported 275 on hexguard while the obvious\n // one-pattern `find` answered 268 (2026-08-16) \u2014 the gate scans three\n // patterns, and the message named none of them, so the correct number read\n // as a wrong one.\n const scanned = [t.scan ?? []].flat();\n findings.push({\n message:\n `${hits.length} matching file(s), threshold ${failAt} (e.g. ${hits[0]})` +\n (scanned.length ? ` \u2014 matched against ${scanned.join(', ')}` : ''),\n });\n }\n return { findings, examined: hits.length };\n};\n\n/**\n * The meta-gate: every declared gate must carry a self-test expecting `pass`\n * and one expecting `fail`. A gate whose rules are all currently satisfied is\n * indistinguishable from a gate that matches nothing.\n */\nexport const gateMeta: Engine = (_t, root) => {\n const findings: Finding[] = [];\n\n let unrun = 0;\n\n const registry = join(root, '.ai', 'gates.toml');\n if (!existsSync(registry)) return { findings, examined: 0 };\n const text = readFileSync(registry, 'utf8');\n const entries = [...text.matchAll(/\\[\\[gates\\]\\][\\s\\S]*?(?=\\n\\[\\[gates\\]\\]|\\n# rungs:end|$)/g)].map((m) => m[0]);\n let examined = 0;\n for (const entry of entries) {\n const id = entry.match(/^id\\s*=\\s*\"(.+)\"/m)?.[1];\n const kind = entry.match(/^kind\\s*=\\s*\"(.+)\"/m)?.[1];\n const table = entry.match(/^table\\s*=\\s*\"(.+)\"/m)?.[1];\n if (!id || kind !== 'declared' || !table) continue;\n examined++;\n // Tables live in the CLI, not the repo, so read them from the module set.\n const tablePath = join(dirname(new URL(import.meta.url).pathname.slice(1)), '..', 'modules', dirname(table), 'gates', table.split('/').pop()!);\n const src = existsSync(tablePath) ? readFileSync(tablePath, 'utf8') : '';\n const forGate = [...src.matchAll(/\\[\\[self_test\\]\\][\\s\\S]*?(?=\\n\\[\\[|\\n\\[|$)/g)]\n .map((m) => m[0])\n .filter((b) => b.includes(`gate = \"${id}\"`) || b.includes(`gate = \"${id}\"`) || b.includes(`gate = \"${id}\"`));\n for (const direction of ['pass', 'fail']) {\n if (!forGate.some((b) => new RegExp(`expect\\\\s*=\\\\s*\"${direction}\"`).test(b))) {\n findings.push({ message: `gate '${id}' has no self-test expecting '${direction}'` });\n }\n }\n\n // WI-045 / F-018: declaring is not asserting. Every fixture whose shape and\n // engine can be reproduced faithfully is executed, and a disagreement is a\n // finding of this gate.\n //\n // Turning this on found, in order: `adr`'s orphaned `[sections]` table, two\n // fixtures labelled for a gate that checks something else, a `reciprocal`\n // rule read by nothing, a `non_empty` check that called any section with\n // subsections empty, three fixtures orphaned by a schema that moved modules,\n // `session-sections-present` wired to an engine whose table it does not have\n // (so it passed by examining nothing), `[register_schema.open]` read by\n // nothing, and a table matcher loose enough that \"resolve-open-findings\" in\n // a filename made a Closed section match the Open schema.\n //\n // None of it was visible while the fixtures were documentation.\n const engine = entry.match(/^engine\\s*=\\s*\"(.+)\"/m)?.[1];\n const parsed = parseTable(tablePath, table.split('/')[0]);\n if (engine && parsed) {\n const blocks = (Array.isArray(parsed.self_test) ? parsed.self_test : [])\n .filter((b: any) => b?.gate === id)\n .map((b: any) => ({ expect: String(b.expect), input: b.input, fixture: b.fixture }));\n for (const r of runSelfTests(id, engine, parsed[tableKeyFor(engine)] ?? parsed, blocks)) {\n if (r.outcome === 'mismatch') findings.push({ message: `self-test for '${id}' ${r.detail}` });\n else if (r.outcome === 'unrun') unrun++;\n }\n }\n }\n\n // Stated, never silent. Most fixtures still cannot be reproduced \u2014 their\n // shapes need context the format does not carry \u2014 and reporting green while\n // most of the suite never executed would be F-006 one level up. A note rather\n // than a failure: an unbuildable fixture is not a defect in the gate.\n if (unrun) console.error(` ${unrun} self-test fixture(s) have no builder and did not run \u2014 not passes (F-018)`);\n return { findings, examined };\n};\n\n/**\n * Which non-spec frontmatter keys are legal for this skill, because the module\n * that ships it opted in.\n *\n * The skill's name is its directory \u2014 `.claude/skills/work-item/SKILL.md` \u2014 and\n * the answer lives in whichever module declares `[skills.work-item]`. Read from\n * the CLI's module set rather than from the repo, so a consumer cannot legalise\n * an extension by editing a file: the opt-in belongs to the module that took the\n * portability cost.\n *\n * `extensions_opted_in` overrides it, which is how a self-test fixture states\n * the opt-in without needing a module on disk.\n */\nfunction optedInExtensions(rel: string, spec: any): Set<string> {\n if (Array.isArray(spec.extensions_opted_in)) return new Set(spec.extensions_opted_in.map(String));\n const name = rel.split('/').slice(-2)[0];\n if (!name) return new Set();\n try {\n const mods = loadAllModules(join(dirname(new URL(import.meta.url).pathname.slice(1)), '..', 'modules'));\n const owner = mods.find((m) => m.skills?.[name]?.extensions);\n return new Set(Object.keys(owner?.skills?.[name]?.extensions ?? {}));\n } catch {\n return new Set();\n }\n}\n\nconst escapeRe = (s: string) => s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n/**\n * A gate table, parsed. Substitution is deliberately *not* applied: a fixture's\n * `{{token}}` is part of what it asserts, and the runner needs the table's raw\n * shape rather than one repo's resolved parameters.\n */\nfunction parseTable(path: string, module: string): any | null {\n if (!existsSync(path)) return null;\n try {\n // Substituted with the module's **real defaults**, not a placeholder. Using\n // `probe` turned the skills schema's scan into `probe/**/SKILL.md` while its\n // fixture still wrote `.claude/skills/x/SKILL.md`, so the engine saw no file\n // and the runner reported the gate broken \u2014 a mismatch entirely of the\n // harness's making. A fixture and the table it tests must resolve against\n // the same parameters or neither means anything.\n const mods = loadAllModules(join(dirname(new URL(import.meta.url).pathname.slice(1)), '..', 'modules'));\n const params = resolveParams(mods, {}, '.');\n return parseToml(substitute(readFileSync(path, 'utf8'), module, params));\n } catch {\n return null;\n }\n}\n\n/** Duplicated from `check.ts` rather than imported, to keep engines dependency-free of the runner. */\nconst tableKeyFor = (engine: string) =>\n ({\n 'file-budget': 'file_budget',\n 'frontmatter-schema': 'frontmatter_schema',\n 'link-integrity': 'link_integrity',\n 'file-population': 'file_population',\n 'render-freshness': 'render_freshness',\n 'register-schema': 'register_schema',\n 'self-declared-closure': 'self_declared_closure',\n 'filename-schema': 'filename_schema',\n 'cross-reference': 'cross_reference',\n 'git-status-reconcile': 'merged_status',\n 'computed-claim': 'computed_claim',\n 'term-ownership': 'term_ownership',\n 'rule-propagation': 'rule_propagation',\n 'git-state': 'git_state',\n 'merge-driver-check': 'merge_driver_check',\n 'board-reconcile': 'board_reconcile',\n 'changelog-freshness': 'changelog_freshness',\n })[engine] ?? engine;\n\nexport const ENGINES: Record<string, Engine> = {\n 'file-budget': fileBudget,\n sections,\n 'frontmatter-schema': frontmatterSchema,\n 'link-integrity': linkIntegrity,\n 'file-population': filePopulation,\n 'gate-meta': gateMeta,\n 'id-integrity': idIntegrity,\n 'render-freshness': renderFreshness,\n 'register-schema': registerSchema,\n 'self-declared-closure': selfDeclaredClosure,\n 'filename-schema': filenameSchema,\n 'cross-reference': crossReference,\n 'git-status-reconcile': gitStatusReconcile,\n 'computed-claim': computedClaim,\n 'term-ownership': termOwnership,\n 'rule-propagation': rulePropagation,\n 'git-state': gitState,\n 'merge-driver-check': mergeDriverCheck,\n 'board-reconcile': boardReconcile,\n 'changelog-freshness': changelogFreshness,\n};\n\n/**\n * Engines named in a gate table but not implemented here. Reported by name and\n * treated as blocking \u2014 never as a pass.\n *\n * This is the single most dangerous failure this tool could have: a registry of\n * 31 gates reporting green because 25 of them do nothing. rift-forge's rule\n * generalises exactly \u2014 *we do not land on an unknown.*\n */\nexport function isImplemented(engine: string): boolean {\n return engine in ENGINES;\n}\n", "import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';\nimport { tmpdir } from 'node:os';\nimport { dirname, join } from 'node:path';\nimport { ENGINES, type Finding } from './engines.ts';\n\n/**\n * Execute a gate's `[[self_test]]` fixtures instead of only checking they exist.\n *\n * F-006 / WI-045. `gateMeta` confirmed that a `pass` block and a `fail` block\n * were declared and never ran either, so every fixture in the repo was\n * documentation shaped like a test. `gates-links-resolve`'s\n * `See [the plan](./does-not-exist.md).` had never been executed \u2014 and had it\n * been, it would have caught F-005 months before a person found it by hand.\n *\n * That is `gate-self-test`'s own argument turned on itself: *a gate whose rules\n * are all currently satisfied is indistinguishable from a gate that matches\n * nothing*, and a self-test that never runs is indistinguishable from one that\n * would fail.\n *\n * **What this does not do is as important as what it does.** A fixture whose\n * shape has no builder is reported **unrun, by name**. It is never counted as a\n * pass, because a suite that reports green while three quarters of it never\n * executed is this finding again, one level up.\n */\n\nexport interface SelfTestResult {\n gate: string;\n expect: 'pass' | 'fail';\n outcome: 'ok' | 'mismatch' | 'unrun';\n detail?: string;\n}\n\n/**\n * A concrete path the table's `scan` would match, for writing a fixture into.\n *\n * The table may be an **array** \u2014 `[[frontmatter_schema]]` declares several \u2014 in\n * which case `t.file`/`t.scan` are undefined and the first \"scan pattern\" was\n * an entire schema object. That silently produced a nonsense path, the engine\n * saw no file, and the fixture was reported as a gate failure (F-018).\n */\nfunction targetPath(table: any): string {\n const t = Array.isArray(table) ? table[0] ?? {} : table ?? {};\n const pattern: string = t.file ?? [t.scan ?? []].flat()[0] ?? '**/*.md';\n if (!pattern.includes('*')) return pattern;\n return pattern\n .replace(/\\*\\*\\//g, 'probe/')\n .replace(/\\/\\*\\*/g, '/probe')\n .replace(/\\*/g, 'probe')\n .replace(/probe\\.probe$/, 'probe.md');\n}\n\n/**\n * Build the fixture's repo state, or return null when its shape has no builder.\n *\n * The declarative keys are deliberately handled generically \u2014 `frontmatter`,\n * `sections`, `opening` and `body` are all \"a markdown file with this in it\",\n * and writing one builder per key would be the same per-shape sprawl that left\n * 85 of 114 fixtures unrunnable in the first place.\n */\nfunction build(root: string, table: any, fx: any, input?: string): string[] | null {\n const write = (rel: string, body: string) => {\n const full = join(root, rel);\n mkdirSync(dirname(full), { recursive: true });\n writeFileSync(full, body);\n return rel;\n };\n\n if (typeof input === 'string') return [write(targetPath(table), `${input}\\n`)];\n if (!fx || typeof fx !== 'object') return null;\n\n // Named files in a parameterised directory, plus the version they are judged\n // against \u2014 the changelog shapes. `dir` is stated by the fixture rather than\n // assumed here, because the self-test sees the module's *raw* table and a\n // `{{changelog_dir}}` glob cannot match anything on disk; see `deparam`.\n if (Array.isArray(fx.fragments) && typeof fx.version === 'string') {\n const dir = fx.dir ?? 'changelog.d';\n // Forward slashes, not `join`: the returned paths are matched against the\n // spec's globs, and on Windows `join` yields `changelog.d\\0.1.1.md`, which\n // `changelog.d/*.md` does not match. The gate then reports \"did not fire\"\n // about the harness rather than the fixture.\n const written = fx.fragments.map((n: string) => write(`${dir}/${n}`, `# ${n}\\n`));\n written.push(write('package.json', JSON.stringify({ version: fx.version })));\n return written;\n }\n\n // N files matching the table's scan \u2014 the population shapes.\n if (typeof fx.matching_files === 'number') {\n const base = fx.location ?? dirname(targetPath(table));\n const marker = fx.exempt ? `<!-- ${fx.exempt} -->\\n` : '';\n return Array.from({ length: fx.matching_files }, (_, i) =>\n write(join(base === '.' ? '' : base, `probe-${i}.md`), `${marker}# probe ${i}\\n`),\n );\n }\n\n // A single markdown file described declaratively.\n const contentKeys = ['frontmatter', 'sections', 'opening', 'body', 'row', 'table'];\n if (contentKeys.some((k) => k in fx)) {\n const parts: string[] = [];\n // `table = \"Closed\"` names the heading the row belongs under. A register\n // engine finds rows by section, so a row written without its heading is in\n // no table at all \u2014 which read as \"the gate did not fire\" (F-018).\n if (fx.table) parts.push(`## ${fx.table}`, '');\n if (fx.frontmatter && typeof fx.frontmatter === 'object') {\n parts.push('---');\n for (const [k, v] of Object.entries(fx.frontmatter)) parts.push(`${k}: ${v}`);\n parts.push('---', '');\n }\n if (fx.opening) parts.push(String(fx.opening), '');\n for (const s of fx.sections ?? []) parts.push(`## ${s}`, '', 'text', '');\n if (fx.row && typeof fx.row === 'object') {\n const cols = Object.keys(fx.row);\n parts.push(`| ${cols.join(' | ')} |`, `| ${cols.map(() => '---').join(' | ')} |`,\n `| ${cols.map((c) => (fx.row as any)[c]).join(' | ')} |`, '');\n }\n if (fx.body) parts.push(String(fx.body), '');\n return [write(fx.file ?? targetPath(table), `${parts.join('\\n')}\\n`)];\n }\n\n return null;\n}\n\n/**\n * Engines whose verdict depends **only on the content of the file the fixture\n * describes**, so a fixture can be executed faithfully in an empty directory.\n *\n * The rest need context the fixture does not carry, and running them anyway\n * produces confident nonsense. `gates-links-resolve`'s `pass` fixture is\n * `See [this table](./structural.toml).` \u2014 it asserts that a link *which\n * resolves* passes, and in a temp directory it does not resolve, so the runner\n * would report the gate broken. Creating the target to make it pass would be\n * assuming the answer, and only for `expect = \"pass\"` blocks, which is worse.\n *\n * Measured 2026-08-16: without this restriction the runner reported 17\n * \"failures\", and the ones inspected were all its own artifacts. A test harness\n * that cries wolf gets deleted faster than the gate it was checking.\n *\n * This is the same shape as `applicability` in ADR-0007, one level down: ask\n * whether the check can legitimately run before running it.\n */\nconst CONTEXT_FREE: ReadonlySet<string> = new Set([\n 'frontmatter-schema',\n 'sections',\n 'file-budget',\n 'register-schema',\n 'file-population',\n 'changelog-freshness',\n]);\n\n/**\n * Replace `{{param}}` segments in a spec's globs with the literal the fixture\n * stands in for.\n *\n * The runner reads the **module's** gate table, where paths are still written as\n * parameters \u2014 `{{changelog_dir}}/*.md`. Nothing substitutes them here, because\n * there is no installed repo to take values from. So a fixture that exercises a\n * parameterised path has to say what it is standing in for, and the spec has to\n * be told the same thing, or the glob matches a file the builder just wrote and\n * the gate reports \"did not fire\" about its own harness.\n */\nfunction deparam<T>(spec: T, dir: string): T {\n const walk = (v: any): any =>\n typeof v === 'string' ? v.replace(/\\{\\{[^}]+\\}\\}/g, dir)\n : Array.isArray(v) ? v.map(walk)\n : v && typeof v === 'object' ? Object.fromEntries(Object.entries(v).map(([k, x]) => [k, walk(x)]))\n : v;\n return walk(spec);\n}\n\nexport function runSelfTests(\n gateId: string,\n engine: string,\n table: any,\n blocks: { expect: string; input?: string; fixture?: any }[],\n): SelfTestResult[] {\n const out: SelfTestResult[] = [];\n for (const b of blocks) {\n const expect = b.expect === 'fail' ? 'fail' : 'pass';\n if (!CONTEXT_FREE.has(engine)) {\n out.push({ gate: gateId, expect, outcome: 'unrun', detail: `${engine} fixtures need context the fixture does not carry` });\n continue;\n }\n if (!(engine in ENGINES)) {\n out.push({ gate: gateId, expect, outcome: 'unrun', detail: `engine '${engine}' not implemented` });\n continue;\n }\n const root = mkdtempSync(join(tmpdir(), 'rungs-selftest-'));\n try {\n const files = build(root, table, b.fixture, b.input);\n // A fixture states an opt-in with `opted_in`; the engine reads it from the\n // spec as `extensions_opted_in`. Without the bridge, the `pass` fixture for\n // an opted-in extension fired `non-spec key` \u2014 the harness asserting the\n // opposite of what the fixture said (F-018).\n let spec = b.fixture?.opted_in\n ? (Array.isArray(table) ? table.map((s: any) => ({ ...s, extensions_opted_in: b.fixture.opted_in })) : { ...table, extensions_opted_in: b.fixture.opted_in })\n : table;\n // Same bridge, for paths: a fixture that names a parameterised directory\n // has to hand the spec the same literal it wrote the files into.\n if (Array.isArray(b.fixture?.fragments)) spec = deparam(spec, b.fixture.dir ?? 'changelog.d');\n if (!files) {\n out.push({ gate: gateId, expect, outcome: 'unrun', detail: `no builder for fixture ${JSON.stringify(b.fixture).slice(0, 60)}` });\n continue;\n }\n let findings: Finding[];\n try {\n findings = ENGINES[engine](spec, root, files).findings;\n } catch (e: any) {\n out.push({ gate: gateId, expect, outcome: 'unrun', detail: `engine threw: ${e.message}`.slice(0, 90) });\n continue;\n }\n const fired = findings.length > 0;\n out.push(\n fired === (expect === 'fail')\n ? { gate: gateId, expect, outcome: 'ok' }\n : { gate: gateId, expect, outcome: 'mismatch', detail: `expected ${expect}, ${fired ? `fired: ${findings[0].message}`.slice(0, 80) : 'did not fire'}` },\n );\n } finally {\n rmSync(root, { recursive: true, force: true });\n }\n }\n return out;\n}\n", "import { existsSync, readFileSync } from 'node:fs';\nimport { execSync } from 'node:child_process';\nimport { join } from 'node:path';\nimport { matchAny } from './glob.ts';\nimport type { Engine, Finding } from './engines.ts';\n\nconst read = (root: string, rel: string) => {\n try {\n return readFileSync(join(root, rel), 'utf8');\n } catch {\n return '';\n }\n};\nconst expand = (files: string[], p: string[] | undefined, f: string[] = []) =>\n [...new Set((p ?? f).flatMap((x) => matchAny(files, x)))];\n\n/** An exemption marker is ignored unless it states a reason. */\nconst exempted = (text: string, marker?: string) =>\n !!marker && new RegExp(`${marker.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')}\\\\s*\\\\S`).test(text);\n\n/**\n * Ids: uniqueness across the declared sources, citations that resolve, and the\n * stale-blocker rule \u2014 a document may not say it waits on work that has finished.\n */\nexport const idIntegrity: Engine = (t, root, files) => {\n const findings: Finding[] = [];\n let examined = 0;\n const known = new Set<string>();\n\n for (const [, kind] of Object.entries<any>(t.kinds ?? {})) {\n const re = new RegExp(`^\\\\s*id:\\\\s*(${kind.format})`, 'm');\n const seen = new Map<string, string>();\n for (const rel of expand(files, kind.sources)) {\n examined++;\n const text = read(root, rel);\n const id = text.match(re)?.[1] ?? rel.match(new RegExp(kind.format))?.[0];\n if (!id) continue;\n known.add(id);\n const prior = seen.get(id);\n if (prior) findings.push({ file: rel, message: `id ${id} also claimed by ${prior}` });\n else seen.set(id, rel);\n }\n // The marker must not name an id that is already spent.\n if (kind.marker?.file) {\n const m = read(root, kind.marker.file).match(new RegExp(kind.marker.pattern));\n if (m?.[1] && seen.has(m[1])) {\n findings.push({ file: kind.marker.file, message: `NEXT marker points at ${m[1]}, already taken` });\n }\n }\n }\n\n // Stale blockers. Vocabulary is narrow on purpose: a first draft that matched\n // `until <id>` hit 29 lines of true history in one repo's own voice.\n const sb = t.stale_blocker;\n if (sb?.phrases?.length && known.size) {\n const scope = expand(files, ['docs/**/*.md', 'AGENTS.md', 'CLAUDE.md']).filter(\n (f) => !expand(files, sb.scope_exclude, []).includes(f),\n );\n const past = (sb.past_tense_ok ?? []).map((p: string) => p.toLowerCase());\n for (const rel of scope) {\n const text = read(root, rel);\n if (exempted(text, sb.exempt_marker)) continue;\n for (const phrase of sb.phrases) {\n const re = new RegExp(`(.{0,${sb.negation_window ?? 60}})\\\\b${phrase}\\\\b\\\\s+([A-Z]{1,6}-\\\\d{1,4})`, 'gi');\n for (const m of text.matchAll(re)) {\n const lead = m[1].toLowerCase();\n if (past.some((p: string) => lead.includes(p.split(' ')[0]) && lead.includes('was'))) continue;\n if (/\\bnot\\b|\\bnever\\b|\\bno longer\\b/.test(lead.slice(-30))) continue;\n if (isDone(root, m[2], files)) {\n findings.push({ file: rel, message: `claims to be ${phrase} ${m[2]}, which is done` });\n }\n }\n }\n }\n }\n return { findings, examined };\n};\n\nfunction isDone(root: string, id: string, files: string[]): boolean {\n const hit = files.find((f) => f.includes(id) && f.endsWith('.md'));\n if (!hit) return false;\n const s = read(root, hit).match(/^status:\\s*(\\S+)/m)?.[1];\n return s === 'done' || hit.includes('/archive/');\n}\n\n/** Generated output that no longer matches what its producer would emit now. */\nexport const renderFreshness: Engine = (t, root, files) => {\n const specs = Array.isArray(t) ? t : [t];\n const findings: Finding[] = [];\n let examined = 0;\n for (const spec of specs) {\n if (spec.block?.file) {\n examined++;\n const text = read(root, spec.block.file);\n const re = new RegExp(`rungs:begin ${spec.block.marker}[\\\\s\\\\S]*?rungs:end ${spec.block.marker}`);\n if (!re.test(text)) {\n findings.push({ file: spec.block.file, message: `no '${spec.block.marker}' block \u2014 run \\`${spec.command}\\`` });\n }\n continue;\n }\n const excluded = new Set(expand(files, spec.exclude, []));\n const sources = expand(files, spec.sources).filter((s) => !excluded.has(s));\n const targets = expand(files, spec.targets);\n // Only harnesses this repo actually emits for are checked; a missing\n // `.cursor/rules` in a repo that never asked for Cursor is not staleness.\n const live = new Set(targets.map((x) => x.split('/')[0]));\n for (const src of sources) {\n examined++;\n const stem = src.split('/').pop()!.replace(/\\.md$/, '');\n for (const dir of live) {\n if (!targets.some((x) => x.startsWith(dir) && x.includes(stem))) {\n findings.push({ file: src, message: `no rendering under ${dir}/ \u2014 run \\`${spec.command}\\`` });\n }\n }\n }\n }\n return { findings, examined };\n};\n\n/** Markdown-table registers: required columns, enums, and conditional rules. */\nexport const registerSchema: Engine = (t, root, files) => {\n const findings: Finding[] = [];\n let examined = 0;\n\n // A register file holds more than one table, and each gets its own spec \u2014\n // `[register_schema]` for Closed and `[register_schema.open]` for Open. Only\n // the top-level one was ever read (F-018), so the Open table's rules \u2014\n // `non_empty = [\"Sev\", \"Pri\", \"What\", \"Evidence\"]` and the Sev/Pri enums \u2014\n // had never been enforced on any repo. Found because the fixture asserting\n // them could not fire, once fixtures started running.\n //\n // A sub-spec is any nested object naming a `table`; `enum` and `min_words` are\n // objects too and do not.\n const specs = [t, ...Object.values(t).filter((v: any) => v && typeof v === 'object' && !Array.isArray(v) && v.table)];\n for (const t of specs as any[]) {\n const targets = t.file ?? specs[0].file ? [t.file ?? (specs[0] as any).file] : expand(files, t.scan);\n for (const rel of targets) {\n const text = read(root, rel);\n if (!text) continue;\n for (const table of parseTables(text)) {\n // The heading must **start with** the table's name, not merely contain it.\n // A substring match sent every Closed row through the Open schema, because\n // `## Closed \u2014 2026-08-16 by [WI-044](archive/WI-044-resolve-open-findings.md)`\n // contains \"open\" inside a filename. Latent until `[register_schema.open]`\n // was read for the first time (F-018) \u2014 a loose matcher is invisible while\n // only one spec exists to match.\n const heading = sectionOf(text, table.headerLine).replace(/^#+\\s*/, '').trim().toLowerCase();\n if (t.table && !heading.startsWith(String(t.table).toLowerCase())) continue;\n const cols = t.required_cols ?? t.table_columns ?? [];\n const present = cols.filter((c: string) =>\n table.headers.some((h) => h.toLowerCase() === String(c).toLowerCase()),\n );\n // Recognition before validation: a file may hold several tables and only\n // some are registers. Demanding every one carry the columns reported a\n // spec index for not being a story table.\n if (cols.length && present.length < Math.max(2, Math.ceil(cols.length / 2))) continue;\n for (const c of cols) {\n if (!present.includes(c)) findings.push({ file: rel, message: `register table missing column '${c}'` });\n }\n for (const row of table.rows) {\n if (Object.values(row).every((v) => !v || v === '\u2014')) continue;\n examined++;\n for (const [key, values] of Object.entries<any>(t.enum ?? {})) {\n const v = strip(row[key]);\n if (v && !values.map(String).includes(v)) {\n findings.push({ file: rel, message: `${key}='${v}' not one of ${values.join(', ')}` });\n }\n }\n for (const c of t.non_empty ?? []) {\n if (!strip(row[c])) findings.push({ file: rel, message: `row ${firstCell(row)}: '${c}' is empty` });\n }\n for (const cond of t.conditional ?? []) {\n const matches = Object.entries<any>(cond.when ?? {}).every(([k, v]) => strip(row[k]) === String(v));\n if (!matches) continue;\n for (const c of cond.non_empty ?? []) {\n const v = strip(row[c]);\n if (!v) findings.push({ file: rel, message: `row ${firstCell(row)}: '${c}' required when ${JSON.stringify(cond.when)}` });\n else if (cond.min_words?.[c] && v.split(/\\s+/).length < cond.min_words[c]) {\n findings.push({ file: rel, message: `row ${firstCell(row)}: '${c}' is too thin to be a reason` });\n }\n }\n }\n }\n }\n }\n }\n return { findings, examined };\n};\n\nconst escapeRe = (s: string) => s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n/**\n * An open finding must not declare itself fixed in its own detail section.\n *\n * This is deliberately a text-only contradiction check. It does not inspect\n * code or infer that a fix really shipped; those questions are repository-\n * specific and a guessed probe would be confidently wrong. A section may\n * contain a reasoned `closure-ok:` marker when only a part of the observation\n * was addressed. The table owns the headings, id shape, and verdict phrases so\n * the engine remains useful for registers that use a different prefix or\n * detail heading.\n */\nexport const selfDeclaredClosure: Engine = (t, root, files) => {\n const findings: Finding[] = [];\n let examined = 0;\n const targets = t.file ? [t.file] : expand(files, t.scan ?? ['docs/**/FINDINGS.md']);\n const idPattern = t.id_pattern ?? '[A-Z]{1,6}-\\\\d{1,4}';\n const openRow = new RegExp(t.open_row_pattern ?? `^\\\\|\\\\s*\\\\[?(${idPattern})\\\\]`, 'gmu');\n const detailHeading = new RegExp(t.detail_heading_pattern ?? `^###\\\\s+(${idPattern})\\\\s+\u2014\\\\s+`, 'gmu');\n const verdicts = (t.declares_fixed ?? [\n '\\\\*\\\\*Fixed[.,)*]',\n '\\\\*\\\\*Fixed\\\\s+(?:in|by|the\\\\s+same\\\\s+day|\\\\d{4}-\\\\d{2}-\\\\d{2})',\n '\\\\*\\\\*Implemented in this change\\\\.?\\\\*\\\\*',\n '\\\\*\\\\*fixed in the pass that found it\\\\*\\\\*',\n ]).map((p: string) => new RegExp(p, 'iu'));\n\n for (const rel of targets) {\n const text = read(root, rel);\n if (!text) continue;\n const openStart = headingIndex(text, t.open_heading ?? 'Open');\n const closedStart = headingIndex(text, t.closed_heading ?? 'Closed');\n const detailStart = headingIndex(text, t.detail_heading ?? 'Detail');\n if (openStart < 0 || closedStart < 0 || detailStart < 0 || closedStart <= openStart || detailStart < closedStart) continue;\n\n const open = new Set<string>();\n for (const match of text.slice(openStart, closedStart).matchAll(openRow)) open.add(match[1]);\n if (!open.size) continue;\n\n const detail = text.slice(detailStart);\n const headings = [...detail.matchAll(detailHeading)];\n for (let i = 0; i < headings.length; i++) {\n const id = headings[i][1];\n if (!open.has(id)) continue;\n examined++;\n const start = headings[i].index ?? 0;\n const end = headings[i + 1]?.index ?? detail.length;\n const section = detail.slice(start, end);\n const marker = t.exempt_marker ?? 'closure-ok:';\n if (new RegExp(`<!--\\\\s*${escapeRe(marker)}\\\\s*\\\\S`, 'u').test(section)) continue;\n const body = section.slice(section.indexOf('\\n') + 1);\n for (const verdict of verdicts) {\n const match = verdict.exec(body);\n if (!match) continue;\n const before = body.slice(Math.max(0, match.index - (t.citation_window ?? 120)), match.index);\n const cited = [...before.matchAll(new RegExp(`(${idPattern})[^.]{0,${t.citation_window ?? 120}}$`, 'gu'))].at(-1)?.[1];\n if (cited && cited !== id) continue;\n findings.push({ file: rel, message: `${id} is open but its detail declares it fixed: ${body.slice(match.index, match.index + 60).split('\\n')[0].trim()}` });\n break;\n }\n }\n }\n return { findings, examined };\n};\n\nfunction headingIndex(text: string, heading: string): number {\n const re = new RegExp(`^#{1,6}\\\\s+${escapeRe(heading)}\\\\s*$`, 'imu');\n return text.search(re);\n}\n\nconst strip = (v?: string) => (v ?? '').replace(/[`*\\[\\]]/g, '').split('(')[0].trim();\nconst firstCell = (row: Record<string, string>) => strip(Object.values(row)[0]) || '?';\n\nfunction parseTables(text: string) {\n const out: { headers: string[]; rows: Record<string, string>[]; headerLine: number }[] = [];\n const lines = text.split('\\n');\n for (let i = 0; i < lines.length; i++) {\n if (!/^\\s*\\|/.test(lines[i]) || !/^\\s*\\|[\\s:|-]+\\|/.test(lines[i + 1] ?? '')) continue;\n const headers = cells(lines[i]);\n const rows: Record<string, string>[] = [];\n let j = i + 2;\n for (; j < lines.length && /^\\s*\\|/.test(lines[j]); j++) {\n const c = cells(lines[j]);\n rows.push(Object.fromEntries(headers.map((h, k) => [h, c[k] ?? ''])));\n }\n out.push({ headers, rows, headerLine: i });\n i = j;\n }\n return out;\n}\nconst cells = (line: string) => line.trim().replace(/^\\||\\|$/g, '').split('|').map((s) => s.trim());\nconst sectionOf = (text: string, line: number) => {\n const before = text.split('\\n').slice(0, line);\n for (let i = before.length - 1; i >= 0; i--) if (/^#{1,6}\\s/.test(before[i])) return before[i];\n return '';\n};\n\nexport const filenameSchema: Engine = (t, root, files) => {\n const re = new RegExp(t.pattern);\n const excluded = new Set(expand(files, t.exclude, []));\n const findings: Finding[] = [];\n let examined = 0;\n for (const rel of expand(files, t.scan)) {\n if (excluded.has(rel)) continue;\n examined++;\n const base = rel.split('/').pop()!;\n if (!re.test(base)) findings.push({ file: rel, message: 'filename does not say what closed and what came next' });\n }\n return { findings, examined };\n};\n\n/** Skills naming their neighbours \u2014 only past the threshold where it matters. */\nexport const crossReference: Engine = (t, root, files) => {\n const skills = expand(files, t.scan);\n if (skills.length < (t.min_skills ?? 6)) return { findings: [], examined: skills.length };\n const names = skills.map((s) => s.split('/').slice(-2)[0]);\n const findings: Finding[] = [];\n for (const rel of skills) {\n const text = read(root, rel);\n if (exempted(text, t.exempt_marker)) continue;\n const desc = text.match(/^---\\n([\\s\\S]*?)\\n---/)?.[1] ?? '';\n const self = rel.split('/').slice(-2)[0];\n if (!names.some((n) => n !== self && desc.includes(n))) {\n findings.push({ file: rel, message: `names no neighbouring skill (${skills.length} in this repo)` });\n }\n }\n return { findings, examined: skills.length };\n};\n\n/** A merged branch cannot still sit at a pre-review status. One-directional. */\n/**\n * Did this branch actually land work, or is it a label pointing at a commit the\n * base already had?\n *\n * `git branch --merged` answers \"is the tip an ancestor\", which is true of a\n * branch cut five seconds ago and never committed to. F-001: reproduced\n * 2026-08-15 on WI-001 and hit three more times on 2026-08-16 \u2014 every item\n * worked through `/work-item` trips it in the window between `git switch -c`\n * and the first commit. A gate that cries wolf on the happy path is one people\n * learn to ignore, which is the failure it exists to prevent.\n *\n * The obvious fix \u2014 \"has commits ahead of base\" \u2014 is wrong, and measuring it\n * proved so: **after any merge the branch is zero commits ahead**, so the gate\n * would never fire again. That silently deletes the check while looking like a\n * fix, which is worse than the false positive.\n *\n * What actually distinguishes them is the merge commit. This repo merges\n * `--no-ff` (backlog README \u00A74), so a branch that landed work leaves a commit in\n * the base whose *second* parent is that branch's tip. A branch that landed\n * nothing never appears as anyone's second parent.\n *\n * **Known gap, stated rather than hidden:** a fast-forward merge that keeps the\n * branch produces no merge commit and no second parent, so this reads it as\n * having landed nothing and stays quiet. That is a false negative on a workflow\n * this repo does not use \u2014 it deletes branches on merge \u2014 and it is the\n * direction to be wrong in, because the alternative is the daily false positive.\n */\nfunction landedWork(root: string, branch: string, base: string): boolean {\n const git = (cmd: string) => execSync(`git ${cmd}`, { cwd: root, stdio: 'pipe' }).toString().trim();\n try {\n const tip = git(`rev-parse ${branch}`);\n if (tip === git(`rev-parse ${base}`)) return false;\n return git(`log ${base} --merges --format=%P`)\n .split('\\n')\n .some((line) => line.trim().split(/\\s+/).slice(1).includes(tip));\n } catch {\n // Unreadable is not provably empty. Report, which fails loudly rather than\n // silently \u2014 the same rule the runner applies to a missing engine.\n return true;\n }\n}\n\nexport const gitStatusReconcile: Engine = (t, root, files) => {\n const findings: Finding[] = [];\n let merged: Set<string>;\n try {\n merged = new Set(\n execSync(`git branch --merged ${t.integration_branch ?? 'main'} --format=%(refname:short)`, {\n cwd: root,\n stdio: 'pipe',\n })\n .toString()\n .split('\\n')\n .map((s) => s.trim())\n .filter(Boolean),\n );\n } catch {\n // No git, or no such branch. Not a pass and not a failure \u2014 an unknown.\n return { findings: [{ message: 'cannot read git branches; status not reconciled' }], examined: 0 };\n }\n let examined = 0;\n for (const rel of expand(files, ['docs/**/items/**/*.md'])) {\n const text = read(root, rel);\n if (exempted(text, t.exempt_marker)) continue;\n const branch = text.match(new RegExp(`^${t.branch_field ?? 'branch'}:\\\\s*(\\\\S+)`, 'm'))?.[1];\n const status = text.match(new RegExp(`^${t.status_field ?? 'status'}:\\\\s*(\\\\S+)`, 'm'))?.[1];\n if (!branch || !status) continue;\n examined++;\n if (\n merged.has(branch) &&\n (t.pre_review_statuses ?? []).includes(status) &&\n landedWork(root, branch, t.integration_branch ?? 'main')\n ) {\n findings.push({ file: rel, message: `branch ${branch} is merged but status is '${status}'` });\n }\n }\n return { findings, examined };\n};\n\n/** A number a machine can compute is never typed by a human. */\nexport const computedClaim: Engine = (t, root, files) => {\n const specs = Array.isArray(t) ? t : [t];\n const findings: Finding[] = [];\n let examined = 0;\n for (const spec of specs) {\n const values = new Map<string, string>();\n for (const src of spec.sources ?? []) {\n for (const rel of matchAny(files, src.file)) {\n const text = read(root, rel);\n let v: string | undefined;\n if (src.path && rel.endsWith('.json')) {\n try {\n v = src.path.split('.').reduce((o: any, k: string) => o?.[k], JSON.parse(text));\n } catch {\n /* unparseable is not a disagreement */\n }\n } else if (src.xpath) {\n v = text.match(new RegExp(`<${src.xpath.split('//')[1]}>(.*?)<`))?.[1];\n }\n if (v) {\n examined++;\n values.set(rel, String(v));\n }\n }\n }\n const distinct = new Set(values.values());\n if (spec.rule === 'all-agree' && distinct.size > 1) {\n findings.push({\n message: `${spec.id} disagrees across ${values.size} locations: ${[...distinct].join(', ')} \u2014 run \\`${spec.autofix}\\``,\n });\n }\n }\n return { findings, examined };\n};\n", "import { existsSync, readFileSync } from 'node:fs';\nimport { execSync } from 'node:child_process';\nimport { join } from 'node:path';\nimport { matchAny } from './glob.ts';\nimport type { Engine, Finding } from './engines.ts';\n\nconst read = (root: string, rel: string) => {\n try {\n return readFileSync(join(root, rel), 'utf8');\n } catch {\n return '';\n }\n};\nconst expand = (files: string[], p: string[] | undefined, f: string[] = []) =>\n [...new Set((p ?? f).flatMap((x) => matchAny(files, x)))];\nconst escapeRe = (s: string) => s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n/** `1.2.3` \u2192 [1,2,3]; anything else \u2192 null. Deliberately not a semver parser. */\nexport function versionParts(s: string): number[] | null {\n const m = /^(\\d+)\\.(\\d+)\\.(\\d+)$/.exec(s.trim());\n return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;\n}\n\nexport function versionCmp(a: number[], b: number[]): number {\n return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];\n}\n\n/**\n * `changelog-freshness` \u2014 a consumed fragment that was never deleted.\n *\n * Fragments are consumed at release time, not archived: one left behind appears\n * in the next release too, where it reads as unreleased work. `cut-release` \u00A73\n * has said so in prose since it was written, and prose did not hold it \u2014\n * `changelog.d/0.1.1.md` survived two releases and was still there at 0.2.0\n * preparation (F-022). So the rule becomes mechanical.\n *\n * A fragment is stale when its filename names a version **below** the version\n * being prepared. Files whose names are not versions are ignored rather than\n * reported: the module's own fixtures use `42.feature.md`, and a gate that\n * refuses a naming convention it was not asked about is a gate people disable.\n */\nexport const changelogFreshness: Engine = (t, root, files) => {\n const specs = Array.isArray(t) ? t : [t];\n const findings: Finding[] = [];\n let examined = 0;\n\n for (const spec of specs) {\n const src = spec.version ?? {};\n let current: number[] | null = null;\n for (const rel of matchAny(files, src.file ?? 'package.json')) {\n try {\n const raw = (src.path ?? 'version')\n .split('.')\n .reduce((o: any, k: string) => o?.[k], JSON.parse(read(root, rel)));\n current = versionParts(String(raw ?? ''));\n } catch {\n /* unparseable is not a stale fragment */\n }\n if (current) break;\n }\n // Without a version to compare against there is no claim to make. Saying\n // nothing is right; passing loudly would not be.\n if (!current) continue;\n\n for (const rel of expand(files, spec.fragments, [])) {\n const name = rel.split('/').pop()!.replace(/\\.md$/, '');\n const v = versionParts(name);\n if (!v) continue;\n examined++;\n if (versionCmp(v, current) < 0) {\n findings.push({\n file: rel,\n message:\n spec.message?.trim() ||\n `fragment names ${name}, below the ${current.join('.')} being prepared \u2014 it was consumed by an earlier release and should have been deleted`,\n });\n }\n }\n }\n\n return { findings, examined };\n};\n\n/** An exemption marker is ignored unless it states a reason. */\nconst exempted = (text: string, marker?: string) =>\n !!marker && new RegExp(`${escapeRe(marker)}\\\\s*\\\\S`).test(text);\n\n/** Rows of the first markdown table under a heading containing `near`. */\nfunction tableRows(text: string, near?: string): Record<string, string>[] {\n const lines = text.split('\\n');\n const rows: Record<string, string>[] = [];\n let heading = '';\n for (let i = 0; i < lines.length; i++) {\n if (/^#{1,6}\\s/.test(lines[i])) heading = lines[i];\n if (!/^\\s*\\|/.test(lines[i]) || !/^\\s*\\|[\\s:|-]+\\|/.test(lines[i + 1] ?? '')) continue;\n if (near && !heading.toLowerCase().includes(near.toLowerCase())) continue;\n const cells = (l: string) => l.trim().replace(/^\\||\\|$/g, '').split('|').map((s) => s.trim());\n const headers = cells(lines[i]);\n for (let j = i + 2; j < lines.length && /^\\s*\\|/.test(lines[j]); j++) {\n const c = cells(lines[j]);\n rows.push(Object.fromEntries(headers.map((h, k) => [h, c[k] ?? ''])));\n }\n i = lines.length;\n }\n return rows;\n}\n\nconst clean = (v = '') => v.replace(/[`*\\[\\]]/g, '').trim();\n\n/** Words distinctive enough to indicate a topic is being restated, not mentioned. */\nfunction terms(topic: string): string[] {\n const stop = new Set(['the', 'and', 'for', 'with', 'per', 'its', 'a', 'an', 'of', 'to', 'in', 'on', 'is', 'are']);\n return clean(topic)\n .toLowerCase()\n .split(/[^a-z0-9_-]+/)\n .filter((w) => w.length > 3 && !stop.has(w));\n}\n\n/**\n * One owner per topic, checked by vocabulary.\n *\n * The registry's third column \u2014 where a topic must NOT appear \u2014 is what turns\n * \"one source of truth\" from a principle into a lookup. Approximate by\n * construction: it catches a section that restates a topic, not one that\n * restates it in different words. That ceiling is pinned in the message rather\n * than hidden, so a green run never reads as \"verified\".\n */\nexport const termOwnership: Engine = (t, root, files) => {\n const registry = read(root, t.registry ?? 'docs/doc-ownership.md');\n if (!registry) return { findings: [{ message: `ownership registry '${t.registry}' not found` }], examined: 0 };\n\n const cols = t.columns ?? {};\n const findings: Finding[] = [];\n let examined = 0;\n\n for (const row of tableRows(registry)) {\n const topic = clean(row[cols.topic ?? 'Topic']);\n const owner = clean(row[cols.owner ?? 'Owner']);\n const forbidden = clean(row[cols.forbidden ?? 'Must NOT appear in']);\n if (!topic || !forbidden || forbidden === '\u2014' || topic.startsWith('(example)')) continue;\n\n const want = terms(topic);\n if (want.length < 2) continue; // too vague to test without guessing\n const patterns = forbidden.split(/[,\u00B7]/).map((s) => s.trim()).filter(Boolean);\n\n for (const rel of expand(files, patterns)) {\n if (rel === owner) continue;\n const text = read(root, rel);\n if (exempted(text, t.exempt_marker)) continue;\n examined++;\n // Per section, not per file: a passing mention is a cross-reference, a\n // section carrying several of the topic's terms is a restatement.\n for (const section of text.split(/^#{1,6}\\s+/m)) {\n const lower = section.toLowerCase();\n const hits = want.filter((w) => lower.includes(w));\n if (hits.length >= (t.engage_min_terms ?? 3)) {\n findings.push({ file: rel, message: `restates \"${topic}\", owned by ${owner} (${hits.length} terms)` });\n break;\n }\n }\n }\n }\n return { findings, examined };\n};\n\n/**\n * A working rule lives in more surfaces than its authority, and fixing the\n * authority does not reach them. Each declared rule names the surfaces that\n * restate it; a surface carrying the retired wording is reported.\n *\n * `forbids` is matched against a preceding-context negation window, because a\n * retired phrase inside \"do NOT <retired>\" is the fix, not the violation \u2014 and\n * a guard that refuses its own fix is one people disable.\n */\nexport const rulePropagation: Engine = (t, root, files) => {\n const registry = read(root, t.registry ?? 'docs/working-rules.md');\n if (!registry) return { findings: [{ message: `rules registry '${t.registry}' not found` }], examined: 0 };\n\n const cols = t.columns ?? {};\n const findings: Finding[] = [];\n let examined = 0;\n const window = t.negation_window ?? 60;\n\n for (const row of tableRows(registry)) {\n const rule = clean(row[cols.rule ?? 'Rule']);\n const retired = clean(row[cols.retired ?? 'Retired wording']);\n const surfaces = clean(row[cols.surfaces ?? 'Surfaces that restate it']);\n if (!rule || !retired || retired === '\u2014' || rule.startsWith('(example)')) continue;\n\n for (const rel of expand(files, surfaces.split(/[,\u00B7]/).map((s) => s.trim()).filter(Boolean))) {\n const text = read(root, rel);\n if (exempted(text, t.exempt_marker)) continue;\n examined++;\n const re = new RegExp(`(.{0,${window}})${escapeRe(retired)}`, 'gis');\n for (const m of text.matchAll(re)) {\n const lead = m[1].toLowerCase();\n if (/\\bnot\\b|\\bnever\\b|\\bno longer\\b|\\bused to\\b|\\bformerly\\b|\\bretired\\b/.test(lead)) continue;\n findings.push({ file: rel, message: `carries the retired wording for \"${rule}\"` });\n break;\n }\n }\n }\n return { findings, examined };\n};\n\n/**\n * The integration branch must be checked out nowhere.\n *\n * Recorded as a correction rather than a preference: holding it checked out\n * blocked every other session *and* did not prevent concurrent landing anyway,\n * because switching to the scratch ref releases it mid-run.\n */\nexport const gitState: Engine = (t, root) => {\n let out: string;\n try {\n out = execSync('git worktree list --porcelain', { cwd: root, stdio: 'pipe' }).toString();\n } catch {\n // Not a git repo, or git unavailable. An unattributable result blocks:\n // we do not land on an unknown.\n return { findings: [{ message: 'cannot read git worktrees; checkout state unknown' }], examined: 0 };\n }\n const findings: Finding[] = [];\n const blocks = out.split('\\n\\n').filter(Boolean);\n for (const b of blocks) {\n const dir = b.match(/^worktree (.+)$/m)?.[1];\n const branch = b.match(/^branch refs\\/heads\\/(.+)$/m)?.[1];\n if (branch && (t.refuse_checked_out ?? []).includes(branch)) {\n findings.push({ message: `'${branch}' is checked out in ${dir} \u2014 nothing should hold it` });\n }\n }\n return { findings, examined: blocks.length };\n};\n\n/**\n * Merge drivers named in `.gitattributes` are **inert until installed**, so a\n * fresh clone silently falls back to git's default merge on files that must\n * never be text-merged. Declaring them is not the same as having them.\n */\nexport const mergeDriverCheck: Engine = (t, root) => {\n const attrs = read(root, t.attributes_file ?? '.gitattributes');\n if (!attrs) return { findings: [], examined: 0 };\n\n const declared = [...new Set([...attrs.matchAll(/merge=([\\w-]+)/g)].map((m) => m[1]))];\n const required = (t.required_drivers ?? []).filter((d: string) => declared.includes(d));\n if (!required.length) return { findings: [], examined: declared.length };\n\n const findings: Finding[] = [];\n for (const driver of required) {\n let configured = '';\n try {\n configured = execSync(`git config --get merge.${driver}.driver`, { cwd: root, stdio: 'pipe' }).toString().trim();\n } catch {\n /* absent config exits non-zero, which is the finding */\n }\n if (!configured) {\n findings.push({ message: `driver '${driver}' is declared but not installed \u2014 run \\`${t.install_command}\\`` });\n }\n }\n return { findings, examined: declared.length };\n};\n\n/**\n * The board's grouping must agree with each item's own `status` field.\n *\n * `git-status-reconcile` already reconciles a **branch** against that field, and\n * this repo cites it constantly as proof that typed bookkeeping decays. Nothing\n * reconciled the **board** \u2014 so on 2026-08-16 `BACKLOG.md` filed fourteen items\n * under `Proposed` and `Planned` whose files all read `status: done`, nine of\n * them linking into `archive/`. The board said *proposed* about a document in\n * the directory for work that can no longer change.\n *\n * It was found by an outside reviewer asserting the framework research was done.\n * They were right; the board would have told them otherwise. That is the same\n * failure the whole module exists to prevent, one layer up, in the file every\n * session opens first.\n *\n * Only table rows are read. The board's prose deliberately discusses finished\n * work, and a paragraph is not a claim about status.\n */\nexport const boardReconcile: Engine = (t, root, _files) => {\n const rel = t.file as string;\n const text = read(root, rel);\n if (!text) return { findings: [{ message: `board not found at ${rel}` }], examined: 0 };\n if (exempted(text, t.exempt_marker)) return { findings: [], examined: 0 };\n\n const groups: Record<string, string[]> = t.groups ?? {};\n const dir = rel.split('/').slice(0, -1).join('/');\n const findings: Finding[] = [];\n let heading = '';\n let examined = 0;\n\n for (const line of text.split('\\n')) {\n const h = /^##\\s+(.+?)\\s*$/.exec(line);\n if (h) {\n heading = h[1];\n continue;\n }\n if (!line.startsWith('|')) continue;\n\n const link = /^\\|\\s*\\[[^\\]]+\\]\\(([^)]+)\\)/.exec(line);\n if (!link) continue; // separator, header, or an empty `| \u2014 |` placeholder\n\n // An undeclared heading is narrative, not a status group. The board's later\n // sections are prose with their own tables \u2014 \"The first-user path\", closed\n // 2026-08-15, tabulates seven finished items and says so in the heading.\n //\n // Reporting those was this gate's first behaviour and it was wrong: measured\n // 2026-08-16, it produced seven findings against a document that is correct.\n // The plan's requirement that every undeclared heading be reported was aimed\n // at a *typo* hiding rows from the check, and it caught legitimate prose\n // instead. That case is covered exactly, below, by requiring each declared\n // group to appear \u2014 a misspelled `Propsed` makes `Proposed` go missing.\n if (!Object.hasOwn(groups, heading)) continue;\n\n examined++;\n const target = `${dir}/${link[1]}`.replace(/[^/]+\\/\\.\\.\\//g, '');\n const item = read(root, target);\n if (!item) {\n findings.push({ file: rel, message: `row under '${heading}' links to a missing file: ${link[1]}` });\n continue;\n }\n const status = /^status:\\s*(\\S+)/m.exec(item)?.[1] ?? '';\n if (!groups[heading].includes(status)) {\n findings.push({\n file: rel,\n message: `${link[1]} is under '${heading}' but its status is '${status}' (expected ${groups[heading].join(' | ')})`,\n });\n }\n }\n\n // Every declared group must actually appear. This is the typo check: a board\n // whose `Proposed` heading is misspelled would otherwise drop those rows\n // silently, which is exactly what the group map exists to prevent.\n const seen = new Set([...text.matchAll(/^##\\s+(.+?)\\s*$/gm)].map((m) => m[1]));\n for (const g of Object.keys(groups)) {\n if (!seen.has(g)) findings.push({ file: rel, message: `declared group '${g}' has no heading in the board` });\n }\n\n return { findings, examined };\n};\n\n", "import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { execSync } from 'node:child_process';\nimport { parse } from 'smol-toml';\nimport type { Manifest } from './types.ts';\nimport { contentHash, emittedFiles, registerGates } from './add.ts';\nimport { resolveParams, substitute, type Params } from './substitute.ts';\nimport { loadRegistry } from './check.ts';\n\nconst SRC = dirname(fileURLToPath(import.meta.url));\n\n/** Bundles from the module catalogue. `init` offers these, not a list of fifteen. */\nexport const PROFILES: Record<string, string[]> = {\n minimal: ['instructions'],\n tracked: ['instructions', 'gates', 'backlog', 'findings', 'adr', 'session'],\n disciplined: ['instructions', 'gates', 'backlog', 'findings', 'adr', 'session', 'ci', 'specs', 'workflows', 'skills', 'audit'],\n hardened: ['instructions', 'gates', 'backlog', 'findings', 'adr', 'session', 'ci', 'specs', 'workflows', 'skills', 'audit', 'release', 'doc-authority'],\n fleet: ['instructions', 'gates', 'backlog', 'findings', 'adr', 'session', 'ci', 'specs', 'workflows', 'skills', 'audit', 'release', 'doc-authority', 'concurrency', 'design-sync'],\n};\n\nexport interface InstallRecord {\n harnesses: string[];\n modules: Record<string, { version: string; params?: Record<string, unknown>; hashes?: Record<string, string>; kept?: { files: string[] } }>;\n}\n\nexport function readRecord(repoRoot: string): InstallRecord | null {\n const p = join(repoRoot, '.ai', 'rungs.toml');\n if (!existsSync(p)) return null;\n try {\n const raw = parse(readFileSync(p, 'utf8')) as any;\n return { harnesses: raw.repo?.harnesses ?? [], modules: raw.modules ?? {} };\n } catch {\n return null;\n }\n}\n\nexport type FileState = 'current' | 'diverged' | 'stale' | 'missing';\n\nexport interface UpgradeItem {\n module: string;\n from: string;\n to: string;\n files: { rel: string; state: FileState }[];\n}\n\n/**\n * Compare what is on disk against both the recorded hash and what the module\n * would emit now. Those two comparisons answer different questions:\n *\n * matches recorded, matches current \u2192 current, nothing to do\n * matches recorded, differs current \u2192 **stale**, ours to replace\n * differs recorded \u2192 **diverged**, theirs; never touched\n *\n * Without the recorded hash the middle two collapse, and upgrade would either\n * clobber deliberate edits or refuse to move anything.\n */\nexport function planUpgrade(repoRoot: string, mods: Manifest[], record: InstallRecord): UpgradeItem[] {\n const params = resolveParams(mods, paramsFrom(record), repoRoot);\n const skillsDir = record.harnesses.includes('claude') ? '.claude/skills' : '.agents/skills';\n const items: UpgradeItem[] = [];\n\n for (const mod of mods) {\n const installed = record.modules[mod.name];\n if (!installed) continue;\n const emitted = emittedFiles(mod, params, skillsDir);\n const files: UpgradeItem['files'] = [];\n const kept = new Set(installed.kept?.files ?? []);\n for (const [rel, wouldEmit] of emitted) {\n if (kept.has(rel)) continue; // never ours; upgrade does not touch it\n const full = join(repoRoot, rel);\n if (!existsSync(full)) {\n files.push({ rel, state: 'missing' });\n continue;\n }\n const onDisk = contentHash(readFileSync(full, 'utf8'));\n const recorded = installed.hashes?.[rel];\n if (onDisk === contentHash(wouldEmit)) files.push({ rel, state: 'current' });\n else if (recorded && onDisk === recorded) files.push({ rel, state: 'stale' });\n else files.push({ rel, state: 'diverged' });\n }\n items.push({ module: mod.name, from: installed.version, to: mod.version, files });\n }\n return items;\n}\n\n/** Applies only `stale` and `missing`. Divergence is a decision, not an error. */\nexport function applyUpgrade(repoRoot: string, mods: Manifest[], record: InstallRecord, plan: UpgradeItem[]) {\n const params = resolveParams(mods, paramsFrom(record), repoRoot);\n const skillsDir = record.harnesses.includes('claude') ? '.claude/skills' : '.agents/skills';\n let written = 0;\n // Only files this run rewrote. A diverged file is not in here, which is what\n // keeps its recorded hash \u2014 and therefore its protection \u2014 intact (F-017).\n const rewritten = new Map<string, Map<string, string>>();\n for (const item of plan) {\n const mod = mods.find((m) => m.name === item.module)!;\n const emitted = emittedFiles(mod, params, skillsDir);\n for (const f of item.files) {\n if (f.state !== 'stale' && f.state !== 'missing') continue;\n const full = join(repoRoot, f.rel);\n const content = emitted.get(f.rel)!;\n mkdirSync(dirname(full), { recursive: true });\n writeFileSync(full, content);\n if (!rewritten.has(mod.name)) rewritten.set(mod.name, new Map());\n rewritten.get(mod.name)!.set(f.rel, contentHash(content));\n written++;\n }\n }\n\n // F-016. Upgrading rewrote a module's **files** and never its **gates**, so a\n // module version that added, removed or renamed one left the registry on the\n // old block and told the user the upgrade succeeded. Reproduced 2026-08-16\n // against a scratch consumer: `session` 1.1.0 \u2192 1.2.0 with a new gate, and\n // `.ai/gates.toml` kept `rungs:begin session@1.1.0` and 20 entries.\n //\n // Registration is by whole merge block, so this fixes removal too \u2014 a gate\n // dropped from a manifest leaves the registry with the block that replaces it.\n // Idempotent, and cheap enough to run for every module in the plan rather than\n // only the ones whose files happened to be stale.\n const upgraded = plan.map((p) => mods.find((m) => m.name === p.module)!).filter(Boolean);\n const gateActions = upgraded.length ? registerGates(upgraded, repoRoot, false) : [];\n\n const recorded = updateRecordAfterUpgrade(\n repoRoot,\n upgraded.map((m) => ({ module: m.name, version: m.version, hashes: rewritten.get(m.name) ?? new Map() })),\n );\n\n return { written, gates: gateActions.length, recorded };\n}\n\n/**\n * Update `.ai/rungs.toml` in place after an upgrade: the version each module\n * moved to, and a new hash for each file this run actually rewrote.\n *\n * **Surgical, and text-level, on purpose.** F-017: `upgrade` left the record\n * naming the old version, so a repo on 1.2.0 described itself to its owner as\n * 1.1.0 and `planUpgrade` offered the same move forever. The obvious fix \u2014\n * calling `writeInstallRecord` \u2014 is worse than the bug: it re-derives the whole\n * record and hashes **every emitted file that exists**, which would stamp our\n * hash onto a file the user had diverged. That file would then match its record\n * and be silently reclassified from `diverged` to `current`, so the next upgrade\n * would overwrite the edit rungs promises never to touch.\n *\n * So: only the lines that must change, and only for files we wrote. Everything\n * else \u2014 the header comment, kept-file lists, and the hash of every file we did\n * not touch \u2014 is left exactly as it was.\n */\nexport function updateRecordAfterUpgrade(\n repoRoot: string,\n updates: { module: string; version: string; hashes: Map<string, string> }[],\n): number {\n const path = join(repoRoot, '.ai', 'rungs.toml');\n if (!existsSync(path) || !updates.length) return 0;\n\n const lines = readFileSync(path, 'utf8').split('\\n');\n const byModule = new Map(updates.map((u) => [u.module, u]));\n let changed = 0;\n let current: { module: string; hashes: boolean } | null = null;\n\n const out: string[] = [];\n for (const line of lines) {\n const header = /^\\[modules\\.([^\\].]+)(\\.[^\\]]+)?\\]/.exec(line);\n if (header) {\n current = byModule.has(header[1]) ? { module: header[1], hashes: header[2] === '.hashes' } : null;\n out.push(line);\n continue;\n }\n\n if (current && !current.hashes && /^version\\s*=/.test(line)) {\n const next = `version = \"${byModule.get(current.module)!.version}\"`;\n if (next !== line) changed++;\n out.push(next);\n continue;\n }\n\n if (current?.hashes) {\n const entry = /^\"([^\"]+)\"\\s*=/.exec(line);\n const replacement = entry && byModule.get(current.module)!.hashes.get(entry[1]);\n if (replacement) {\n out.push(`\"${entry[1]}\" = \"${replacement}\"`);\n changed++;\n continue;\n }\n }\n\n out.push(line);\n }\n\n writeFileSync(path, out.join('\\n'));\n return changed;\n}\n\nfunction paramsFrom(record: InstallRecord): Params {\n const out: Params = {};\n for (const [name, entry] of Object.entries(record.modules)) {\n if (entry.params) out[name] = { ...entry.params };\n }\n return out;\n}\n\n/**\n * ADR-0002's promised exit. Materialises the engines and their tables into the\n * repo and rewrites every declared gate to a `command` gate that runs them.\n *\n * This is a stated obligation, not a nicety: a tool whose checks disappear when\n * you uninstall it is one nobody should adopt, and promising the exit is what\n * makes the no-scripts-in-your-repo default acceptable.\n */\nexport function eject(repoRoot: string, mods: Manifest[], dryRun = false) {\n const dest = join(repoRoot, '.rungs');\n // Only what the runner actually needs, and nothing that imports a package.\n // The first version copied `check.ts` and `manifest.ts` too, which pull in the\n // TOML parser \u2014 so an ejected repo crashed on a module it could not resolve.\n // An exit that does not work is not an exit.\n const engines = ['glob.ts', 'engines.ts', 'engines2.ts'];\n const { gates } = loadRegistry(repoRoot);\n const declared = gates.filter((g) => g.kind === 'declared' && g.table);\n const tables = [...new Set(declared.map((g) => g.table!))];\n\n const actions: string[] = [];\n for (const f of engines) actions.push(`.rungs/${f}`);\n for (const t of tables) actions.push(`.rungs/tables/${t.replace('/', '-').replace(/.toml$/, '.json')}`);\n actions.push('.rungs/run-gate.mjs', '.ai/gates.toml (rewritten to command gates)');\n\n if (dryRun) return { actions, gates: declared.length };\n\n mkdirSync(join(dest, 'tables'), { recursive: true });\n for (const f of engines) copyFileSync(join(SRC, f), join(dest, f));\n\n // Tables are **converted to JSON at eject time**, parsed here with the parser\n // this CLI already has. The ejected repo then needs no TOML dependency at all\n // \u2014 which is the same promise ADR-0002 makes about installation, kept on the\n // way out. Parameters are substituted now, for the same reason.\n const record = readRecord(repoRoot);\n const params = resolveParams(mods, record ? paramsFrom(record) : {}, repoRoot);\n for (const t of tables) {\n const [mod, file] = t.split('/');\n const src = join(SRC, '..', 'modules', mod, 'gates', file);\n if (!existsSync(src)) continue;\n try {\n const parsed = parse(substitute(readFileSync(src, 'utf8'), mod, params));\n writeFileSync(join(dest, 'tables', `${mod}-${file.replace(/\\.toml$/, '.json')}`), JSON.stringify(parsed, null, 2));\n } catch {\n /* an unparseable table is dropped, and its gate will say so when run */\n }\n }\n\n writeFileSync(join(dest, 'run-gate.mjs'), RUNNER);\n writeFileSync(join(dest, 'README.md'), EJECT_README);\n\n const registry = join(repoRoot, '.ai', 'gates.toml');\n let text = readFileSync(registry, 'utf8');\n for (const g of declared) {\n text = text.replace(\n new RegExp(`(id\\\\s*=\\\\s*\"${g.id}\"[\\\\s\\\\S]*?)kind\\\\s*=\\\\s*\"declared\"`),\n `$1kind = \"command\"\\ncommand = \"node .rungs/run-gate.mjs ${g.id}\"`,\n );\n }\n writeFileSync(registry, `${text}\\n# Ejected: gates above run from .rungs/ and no longer need rungs installed.\\n`);\n return { actions, gates: declared.length };\n}\n\nconst RUNNER = `#!/usr/bin/env node\n// Ejected gate runner. Runs one declared gate from the tables in ./tables/.\n// Self-contained: this repo no longer needs rungs installed to run its gates.\nimport { readFileSync } from 'node:fs';\nimport { join, dirname } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { ENGINES } from './engines.ts';\nimport { walk } from './glob.ts';\n\nconst here = dirname(fileURLToPath(import.meta.url));\nconst root = join(here, '..');\nconst id = process.argv[2];\nconst registry = readFileSync(join(root, '.ai', 'gates.toml'), 'utf8');\nconst entry = registry.split('[[gates]]').find((b) => b.includes(\\`id = \"\\${id}\"\\`) || b.includes(\\`id = \"\\${id}\"\\`));\nif (!entry) { console.error(\\`unknown gate \\${id}\\`); process.exit(2); }\n\nconst engine = entry.match(/^engine\\\\s*=\\\\s*\"(.+)\"/m)?.[1];\nconst table = entry.match(/^table\\\\s*=\\\\s*\"(.+)\"/m)?.[1];\nif (!engine || !ENGINES[engine]) { console.error(\\`gate \\${id}: engine '\\${engine}' unavailable\\`); process.exit(2); }\n\n// Tables were converted to JSON when this was ejected, so nothing here needs a\n// TOML parser \u2014 or any dependency at all beyond Node itself.\nconst raw = JSON.parse(readFileSync(join(here, 'tables', table.replace('/', '-').replace(/\\\\.toml$/, '.json')), 'utf8'));\nconst KEYS = { 'file-budget': 'file_budget', 'frontmatter-schema': 'frontmatter_schema', 'link-integrity': 'link_integrity', 'file-population': 'file_population', 'gate-meta': 'gate_meta', 'render-freshness': 'render_freshness', 'register-schema': 'register_schema', 'self-declared-closure': 'self_declared_closure', 'filename-schema': 'filename_schema', 'cross-reference': 'cross_reference', 'git-status-reconcile': 'merged_status', 'computed-claim': 'computed_claim' };\nlet section = raw[KEYS[engine] ?? engine] ?? raw;\nif (Array.isArray(section) && section.some((s) => s?.id)) {\n const mine = section.filter((s) => !s.id || id.includes(s.id));\n if (mine.length) section = mine;\n}\nconst r = ENGINES[engine](section, root, walk(root));\nfor (const f of r.findings) console.error(\\` \\${f.file ? f.file + ': ' : ''}\\${f.message}\\`);\nprocess.exit(r.findings.length ? 1 : 0);\n`;\n\nconst EJECT_README = `# .rungs \u2014 ejected\n\nThe gate engines and tables, materialised into this repo. Every gate in\n\\`.ai/gates.toml\\` now runs as a \\`command\\` gate pointing here, so **this repo no\nlonger needs rungs installed** to run its checks.\n\nWhat you gave up: engine fixes no longer arrive with a CLI version bump. These\nfiles are yours now, including their bugs.\n\nWhat you kept: every gate, every table, and the reason each one exists \u2014 the\n\\`why\\` field travelled with the registry entry, so a gate can still explain\nitself to whoever finds it.\n\nTo go back, delete this directory and re-run \\`rungs add\\`.\n`;\n\n/**\n * Install the merge drivers `.gitattributes` names, and turn on rerere.\n *\n * The `concurrency` module's own gate reports these as missing until this runs,\n * and it was reporting against a command that did not exist \u2014 a module telling\n * a repo to run something rungs had never implemented. A driver named in\n * `.gitattributes` is inert until configured, so a fresh clone silently falls\n * back to git's default merge on files that must never be text-merged.\n */\nexport function setupGit(repoRoot: string, dryRun = false) {\n const attrs = join(repoRoot, '.gitattributes');\n if (!existsSync(attrs)) return { drivers: [] as string[], rerere: false };\n const drivers = [...new Set([...readFileSync(attrs, 'utf8').matchAll(/merge=(rungs-[\\w-]+)/g)].map((m) => m[1]))];\n const done: string[] = [];\n for (const d of drivers) {\n // `ledger` takes the higher counter and keeps both claim comments;\n // `generated` always refuses and prints the regenerate command. Both are\n // implemented as scripts the runner ships, so the config points at rungs.\n const cmd =\n d === 'rungs-generated'\n ? 'node -e \"process.stderr.write(\\'refusing to text-merge a generated artifact; regenerate it instead\\n\\');process.exit(1)\"'\n : 'git merge-file -L ours -L base -L theirs %A %O %B';\n if (!dryRun) {\n try {\n execSync(`git config merge.${d}.name \"rungs ${d.replace('rungs-', '')} driver\"`, { cwd: repoRoot, stdio: 'pipe' });\n execSync(`git config merge.${d}.driver ${JSON.stringify(cmd)}`, { cwd: repoRoot, stdio: 'pipe' });\n } catch {\n continue;\n }\n }\n done.push(d);\n }\n let rerere = false;\n if (!dryRun) {\n try {\n execSync('git config rerere.enabled true', { cwd: repoRoot, stdio: 'pipe' });\n rerere = true;\n } catch {\n /* not a git repo */\n }\n }\n return { drivers: done, rerere };\n}\n", "import { ENGINES, type Finding } from './engines.ts';\nimport { loadTable, tableKey } from './check.ts';\nimport type { DetectResult, Manifest } from './types.ts';\n\n/**\n * `doctor` answers a *presence* question \u2014 which of our modules does this repo\n * already have an equivalent of. The question a repo actually arrives with is a\n * *defect* question: which of my agent rules say MUST and have nothing checking\n * them, how many near-identical CI workflows do I have, which topics have two\n * documents claiming authority.\n *\n * Those detectors were already written. They ship as gates inside modules and\n * ran only after installation, over rungs-managed content \u2014 so the analysis was\n * gated behind installing the thing the analysis exists to justify, which is\n * backwards for a tool whose primary case is retrofit (WI-038).\n *\n * Nothing here is new detection. It is the same `ENGINES` table the runner\n * uses, over a registry synthesized in memory from the module manifests rather\n * than read from `.ai/gates.toml`, which an unmanaged repo does not have.\n */\n\nexport interface DetectorFinding {\n module: string;\n gate: string;\n /** The extracted incident behind the gate, from the manifest. */\n why?: string;\n findings: Finding[];\n examined: number;\n}\n\nexport interface ExplainResult {\n reported: DetectorFinding[];\n /** Gates skipped, by reason \u2014 printed, because a silent skip reads as a pass. */\n skipped: { command: number; unimplemented: string[]; undeclared: string[]; errored: { gate: string; message: string }[] };\n /** Modules whose detectors ran at all. */\n scope: string[];\n}\n\ntype EngineTable = Record<string, (t: any, root: string, files: string[]) => { findings: Finding[]; examined: number }>;\n\n/**\n * A `command` gate runs a shell command the *repo* owns. On a repo that never\n * installed rungs there is no registry to own one, but a module can still\n * declare one \u2014 and executing an arbitrary command against somebody else's\n * checkout because they typed a read-only-sounding flag is not a thing this\n * tool gets to do. Skipped, and counted, never run.\n */\nconst isRunnable = (g: Manifest['gates'][number]) => g.kind !== 'command' && !g.trigger && !!g.engine;\n\n/**\n * Which modules' detectors are allowed to run.\n *\n * **Only what the repo already has.** ADR-0004 biased detection signatures\n * toward false negatives; the same bias applies here for a stronger reason \u2014\n * these engines read rungs-shaped inputs, so on a foreign repo a\n * technically-correct finding can still be framed against a convention the repo\n * never adopted. A module the repo has no equivalent of has nothing to check,\n * and running it anyway produces exactly the confident noise that loses an\n * adoption wedge.\n *\n * `paradigm` is excluded too: the repo solves that problem a different way, and\n * measuring their solution against our shape is the same error with a nastier\n * tone.\n */\nexport const IN_SCOPE: ReadonlySet<string> = new Set(['theirs', 'ours-current', 'ours-diverged']);\n\n/**\n * Which declared applicability may run against a repo that is not ours.\n *\n * This was two hard-coded sets of **engine names** in this file, and the\n * knowledge lived nowhere near the gates it governed: adding a gate on\n * `file-population` silently made it foreign-safe, and adding one on a new\n * engine silently made it not, with nothing at either declaration saying so.\n * It is now a required field on each gate \u2014 see `Applicability` in `types.ts`\n * for what the three cases mean and which measurement produced them.\n */\nconst FOREIGN_SAFE: ReadonlySet<string> = new Set(['repo-content']);\n\nexport function explain(\n mods: Manifest[],\n results: DetectResult[],\n repoRoot: string,\n files: string[],\n): ExplainResult {\n return explainWith(ENGINES, mods, results, repoRoot, files);\n}\n\n/**\n * `explain` with the engine table injected, so the scope rules above can be\n * tested without a repo on disk. Those rules are the whole safety argument of\n * this pass; testing them through fifteen real manifests would test the\n * manifests instead.\n */\nexport function explainWith(\n engines: EngineTable,\n mods: Manifest[],\n results: DetectResult[],\n repoRoot: string,\n files: string[],\n): ExplainResult {\n const inScope = results.filter((r) => IN_SCOPE.has(r.state));\n const scope = inScope.map((r) => r.module);\n const stateOf = new Map(inScope.map((r) => [r.module, r.state]));\n const reported: DetectorFinding[] = [];\n const skipped: ExplainResult['skipped'] = { command: 0, unimplemented: [], undeclared: [], errored: [] };\n\n for (const name of scope) {\n const mod = mods.find((m) => m.name === name);\n if (!mod) continue;\n const isOurs = stateOf.get(name) !== 'theirs';\n\n for (const g of mod.gates) {\n if (!isRunnable(g)) {\n if (g.kind === 'command') skipped.command++;\n continue;\n }\n // No default. A gate that has not said whether it can read a foreign repo\n // does not read one, and is named \u2014 silence resolving to \"safe\" is how the\n // 71 mis-framed findings of WI-038's first version happened.\n if (!isOurs) {\n if (!g.applicability) {\n skipped.undeclared.push(g.id);\n continue;\n }\n if (!FOREIGN_SAFE.has(g.applicability)) continue;\n }\n if (!(g.engine! in engines)) {\n // Same rule as the runner: an engine named and missing is an unknown,\n // and an unknown is never reported as clean.\n skipped.unimplemented.push(g.id);\n continue;\n }\n\n const table = loadTable(g.table ? `${mod.name}/${g.table.replace(/^gates\\//, '')}` : undefined, repoRoot);\n if (!table) {\n skipped.errored.push({ gate: g.id, message: `table '${g.table ?? '(none)'}' not found` });\n continue;\n }\n\n try {\n const key = tableKey(g.engine!);\n let section = table[key] ?? table;\n if (Array.isArray(section) && section.some((s: any) => s?.id)) {\n const mine = section.filter((s: any) => !s.id || g.id.includes(s.id));\n if (mine.length) section = mine;\n }\n const r = engines[g.engine!](section, repoRoot, files);\n if (r.findings.length) {\n reported.push({ module: mod.name, gate: g.id, why: g.why, findings: r.findings, examined: r.examined });\n }\n } catch (e: any) {\n // An engine that throws on a foreign repo's shapes is a fact about this\n // pass, not about the repo. Reported as ours, not as their finding.\n skipped.errored.push({ gate: g.id, message: e.message });\n }\n }\n }\n\n return { reported: collapseDuplicates(reported), skipped, scope };\n}\n\n/**\n * Two gate ids that produce the identical finding set are one check reported\n * twice, and on a repo with 112 broken links that is 224 lines of the same\n * thing. `gates-links-resolve` and `gates-paths-exist` currently run the same\n * markdown-link scan \u2014 F-007 in `docs/backlog/FINDINGS.md`, open before this\n * pass existed and unchanged by it.\n *\n * Collapsed here rather than fixed there on purpose: the duplication is a defect\n * in the gate set, this is a defect in *reading* the gate set, and a reporting\n * layer that hides a registry problem is how the registry problem survives. The\n * merged row names both ids, so the duplication stays visible to anyone who\n * looks at the output \u2014 which is the point.\n */\nexport function collapseDuplicates(reported: DetectorFinding[]): DetectorFinding[] {\n const out: DetectorFinding[] = [];\n const seen = new Map<string, DetectorFinding>();\n for (const r of reported) {\n const key = `${r.module} ${r.findings.map((f) => `${f.file ?? ''}|${f.message}`).join('')}`;\n const prior = seen.get(key);\n if (prior) {\n prior.gate = `${prior.gate} + ${r.gate}`;\n continue;\n }\n seen.set(key, r);\n out.push(r);\n }\n return out;\n}\n", "import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';\nimport { dirname, join, relative, resolve, sep } from 'node:path';\nimport { walk } from './glob.ts';\n\n/**\n * `rungs backlog archive` \u2014 move finished items out of `items/` and repoint\n * every link in the repo at their new home.\n *\n * F-015. Three files shipped into **every** consumer repo named this command,\n * two of them saying \"never by hand\", and it did not exist: `rungs backlog`\n * answered *\"unknown command\"*. So the instruction was unfollowable everywhere\n * rungs had ever been installed, and the reason it says *never by hand* is\n * exactly why it could not be worked around \u2014 moving 39 files and rewriting\n * every citation of them is the kind of repo-wide edit that fails silently.\n *\n * The link rewrite is the whole substance of the command. It resolves each\n * link from the citing file's **own** directory rather than pattern-matching\n * text, because the same target is written `items/WI-001-x.md`,\n * `../items/WI-001-x.md` and `WI-001-x.md` depending on who is citing it, and a\n * regex over any one of those spellings silently misses the others.\n */\n\nexport interface ArchiveMove {\n id: string;\n status: string;\n from: string;\n to: string;\n}\n\nexport interface ArchivePlan {\n root: string;\n moves: ArchiveMove[];\n /** Files whose links change, with how many links move in each. */\n rewrites: { file: string; links: number }[];\n /** Items that look finished but are not eligible, with the reason. */\n held: { file: string; reason: string }[];\n}\n\n/** Statuses whose work can no longer change. Mirrors backlog README \u00A78. */\nconst FINISHED = new Set(['done', 'rejected']);\n\nconst field = (text: string, name: string) => text.match(new RegExp(`^${name}:\\\\s*(\\\\S+)`, 'm'))?.[1] ?? '';\n\nconst posix = (p: string) => p.split(sep).join('/');\n\n/** A relative markdown link that could point at a repo file. */\nconst LINK = /\\]\\((?!https?:|#|mailto:)([^)\\s#]+)((?:#[^)\\s]*)?)\\)/g;\n\nexport function planArchive(repoRoot: string, backlogRoot = 'docs/backlog'): ArchivePlan {\n const itemsDir = join(repoRoot, ...backlogRoot.split('/'), 'items');\n const archiveDir = join(repoRoot, ...backlogRoot.split('/'), 'archive');\n const moves: ArchiveMove[] = [];\n const held: ArchivePlan['held'] = [];\n\n const files = walk(repoRoot);\n const items = files.filter((f) => posix(f).startsWith(posix(relative(repoRoot, itemsDir)) + '/') && f.endsWith('.md'));\n\n for (const rel of items) {\n if (/README\\.md$/i.test(rel) || /TEMPLATE\\.md$/i.test(rel)) continue;\n const text = readFileSync(join(repoRoot, rel), 'utf8');\n const status = field(text, 'status');\n const id = field(text, 'id');\n if (!FINISHED.has(status)) continue;\n\n // An epic whose children are not all finished is still live bookkeeping: it\n // is the thing that says what remains. Moving it would file the index of\n // open work under \"cannot change any more\".\n if (field(text, 'type') === 'epic') {\n const children = (text.match(/^children:\\s*\\[(.*)\\]/m)?.[1] ?? '')\n .split(',')\n .map((s) => s.trim())\n .filter(Boolean);\n const unfinished = children.filter((c) => {\n const f = items.find((i) => i.includes(`${c}-`));\n return !f || !FINISHED.has(field(readFileSync(join(repoRoot, f), 'utf8'), 'status'));\n });\n if (unfinished.length) {\n held.push({ file: rel, reason: `epic with unfinished children: ${unfinished.join(', ')}` });\n continue;\n }\n }\n\n // `posix(rel)` first: `walk` yields `/`-separated paths, so splitting on the\n // platform `sep` on Windows never splits and the basename came back as the\n // whole path \u2014 producing `archive/docs/backlog/items/WI-001-\u2026.md`.\n moves.push({\n id,\n status,\n from: rel,\n to: posix(join(relative(repoRoot, archiveDir), posix(rel).split('/').pop()!)),\n });\n }\n\n // Where each moved file ends up, keyed by its absolute old path, so a link can\n // be looked up by what it resolves to rather than by how it was spelled.\n const moved = new Map(moves.map((m) => [resolve(repoRoot, m.from), m.to]));\n const rewrites: ArchivePlan['rewrites'] = [];\n\n for (const rel of files) {\n if (!isRewritable(rel)) continue;\n const links = retargets(repoRoot, rel, moved).length;\n if (links || moved.has(resolve(repoRoot, rel))) rewrites.push({ file: rel, links });\n }\n\n return { root: backlogRoot, moves, rewrites, held };\n}\n\n/**\n * A module's `files/` and `fragments/` are **templates**, not repo content.\n * Their links are relative to wherever the fragment merges into, they carry\n * `{{param}}` tokens, and resolving them here reports every one as broken \u2014\n * which is why `link_integrity.exclude` already skips them. Rewriting them\n * would be worse than reporting them: it would bake this repo's paths into what\n * every consumer repo gets installed.\n */\nfunction isRewritable(rel: string): boolean {\n const p = posix(rel);\n if (!p.endsWith('.md')) return false;\n return !/^modules\\/[^/]+\\/(files|fragments)\\//.test(p) && !p.startsWith('node_modules/');\n}\n\n/**\n * The links in one file that this archive run has to change, and what to.\n *\n * Deliberately **only** links whose target moved, plus \u2014 when the citing file is\n * itself moving \u2014 links that would otherwise break from the new location. The\n * first version compared every link's written form against a freshly computed\n * relative path and counted a difference as a change, which claimed 334 links\n * across 58 files including `AGENTS.md`, `README.md` and module templates. Most\n * of those were equivalent spellings of an unmoved target. Rewriting them would\n * have been a repo-wide reflow disguised as an archive.\n */\nfunction retargets(repoRoot: string, rel: string, moved: Map<string, string>): { href: string; to: string }[] {\n const oldDir = dirname(resolve(repoRoot, rel));\n const selfMoved = moved.get(resolve(repoRoot, rel));\n const newDir = dirname(resolve(repoRoot, selfMoved ?? rel));\n const out: { href: string; to: string }[] = [];\n\n for (const m of readFileSync(join(repoRoot, rel), 'utf8').matchAll(LINK)) {\n const href = m[1];\n if (href.includes('{{')) continue; // a template link, resolved at install\n const target = resolve(oldDir, decodeURIComponent(href));\n const targetMoved = moved.get(target);\n if (!targetMoved && !selfMoved) continue;\n if (!targetMoved && !existsSync(target)) continue; // already broken; not this command's to fix\n const targetNew = targetMoved ? resolve(repoRoot, targetMoved) : target;\n // No `./` prefix. It is never required for a relative markdown link, and\n // adding it rewrites the spelling of paths whose *target* is what changed \u2014\n // turning a one-word diff into a whole-line one across 37 files.\n const to = posix(relative(newDir, targetNew));\n if (to !== posix(href)) out.push({ href, to });\n }\n return out;\n}\n\nexport function applyArchive(repoRoot: string, plan: ArchivePlan): void {\n const moved = new Map(plan.moves.map((m) => [resolve(repoRoot, m.from), m.to]));\n\n // Rewrite before moving. Every path is computed from the plan rather than from\n // the filesystem, so the order is a choice \u2014 and this order means a crash\n // halfway leaves the files still where the links say they are.\n for (const rel of walk(repoRoot)) {\n if (!isRewritable(rel)) continue;\n const edits = retargets(repoRoot, rel, moved);\n if (!edits.length) continue;\n const path = join(repoRoot, rel);\n let text = readFileSync(path, 'utf8');\n // Replace through the same matcher that found them, so a href appearing in\n // prose as well as in a link cannot be hit by a bare string replace.\n text = text.replace(LINK, (whole, href: string, anchor: string) => {\n const edit = edits.find((e) => e.href === href);\n return edit ? `](${edit.to}${anchor})` : whole;\n });\n writeFileSync(path, text);\n }\n\n for (const m of plan.moves) {\n const to = join(repoRoot, ...m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join", "readdirSync", "statSync", "existsSync", "readFileSync", "join", "readFileSync", "join", "targetPath", "sep", "join", "readFileSync", "c", "markers", "readFileSync", "join", "existsSync", "existsSync", "mkdirSync", "readFileSync", "writeFileSync", "dirname", "join", "join", "readFileSync", "mkdirSync", "dirname", "writeFileSync", "existsSync", "existsSync", "readFileSync", "execSync", "dirname", "join", "parse", "existsSync", "readFileSync", "join", "dirname", "resolve", "mkdirSync", "writeFileSync", "dirname", "join", "join", "mkdirSync", "dirname", "writeFileSync", "c", "walk", "readFileSync", "join", "readFileSync", "join", "t", "c", "cmd", "readFileSync", "execSync", "join", "read", "readFileSync", "join", "expand", "escapeRe", "exempted", "cells", "c", "execSync", "read", "readFileSync", "join", "expand", "existsSync", "field", "escapeRe", "dirname", "resolve", "join", "dirname", "existsSync", "parse", "readFileSync", "execSync", "existsSync", "mkdirSync", "readFileSync", "writeFileSync", "dirname", "join", "fileURLToPath", "execSync", "parse", "dirname", "fileURLToPath", "join", "existsSync", "parse", "readFileSync", "mkdirSync", "writeFileSync", "cmd", "execSync", "existsSync", "mkdirSync", "readFileSync", "writeFileSync", "dirname", "join", "relative", "resolve", "sep", "sep", "join", "relative", "readFileSync", "c", "resolve", "dirname", "existsSync", "writeFileSync", "mkdirSync", "existsSync", "dirname", "fileURLToPath", "MODULES", "join", "resolve"]
3
+ "sources": ["../src/cli.ts", "../src/manifest.ts", "../src/glob.ts", "../src/detect.ts", "../src/add.ts", "../src/substitute.ts", "../src/render.ts", "../src/check.ts", "../src/engines.ts", "../src/selftest.ts", "../src/engines2.ts", "../src/engines3.ts", "../src/lifecycle.ts", "../src/explain.ts", "../src/backlog.ts", "../src/concurrency.ts"],
4
+ "sourcesContent": ["#!/usr/bin/env node\nimport { fileURLToPath } from 'node:url';\nimport { dirname, join, resolve } from 'node:path';\nimport { auditModules, loadAllModules } from './manifest.ts';\nimport { detect, scanRepo } from './detect.ts';\nimport { addModule, adoptableGates, blockedByParadigm, registerGates, resolveInstallOrder, writeInstallRecord } from './add.ts';\nimport { render, writeReport, type Harness } from './render.ts';\nimport { resolveParams } from './substitute.ts';\nimport { appendLedger, type GateRun, ledgerQuestions, loadRegistry, runGates, UnknownTierError } from './check.ts';\nimport { applyUpgrade, eject, planUpgrade, PROFILES, readRecord, setupGit } from './lifecycle.ts';\nimport { explain, IN_SCOPE as EXPLAINABLE } from './explain.ts';\nimport { applyArchive, planArchive } from './backlog.ts';\nimport { land, preflight, sessionStart, worktrees } from './concurrency.ts';\nimport { existsSync } from 'node:fs';\nimport type { DetectResult, Manifest } from './types.ts';\n\nconst HERE = dirname(fileURLToPath(import.meta.url));\nconst MODULES = join(HERE, '..', 'modules');\n\nconst c = {\n dim: (s: string) => `\\x1b[2m${s}\\x1b[0m`,\n bold: (s: string) => `\\x1b[1m${s}\\x1b[0m`,\n red: (s: string) => `\\x1b[31m${s}\\x1b[0m`,\n yellow: (s: string) => `\\x1b[33m${s}\\x1b[0m`,\n green: (s: string) => `\\x1b[32m${s}\\x1b[0m`,\n cyan: (s: string) => `\\x1b[36m${s}\\x1b[0m`,\n};\n\nconst STATE_LABEL: Record<DetectResult['state'], string> = {\n absent: c.dim('absent'),\n 'ours-current': c.green('ours'),\n 'ours-diverged': c.yellow('diverged'),\n theirs: c.cyan('theirs'),\n paradigm: c.yellow('paradigm'),\n unknown: c.red('unknown'),\n};\n\nfunction cmdModules(showParams = false) {\n const mods = loadAllModules(MODULES);\n console.log(c.bold(`\\n${mods.length} modules\\n`));\n for (const m of mods) {\n const deps = m.requires.length ? c.dim(` \u2190 ${m.requires.join(', ')}`) : '';\n console.log(` ${c.bold(m.name.padEnd(14))} rung ${m.rung}${deps}`);\n console.log(` ${' '.repeat(14)} ${c.dim(m.summary)}`);\n // Rendered from the manifest at the moment it is asked for, never written down. A committed\n // parameter table would be correct the day it was generated and silently wrong the day a\n // default moved \u2014 which is the failure this flag exists to answer (WI-006).\n if (!showParams) continue;\n for (const [name, spec] of Object.entries(m.params)) {\n const shown = spec.default === undefined ? c.dim('(none)') : JSON.stringify(spec.default);\n const notes = [\n spec.allowed ? `one of ${spec.allowed.map(String).join(' \u00B7 ')}` : '',\n // Behavioural parameters never appear as {{token}}, so a reader hunting for one in a\n // template would conclude the parameter was dead. Say so where they meet it.\n spec.consumed_by ? `behavioural \u2014 changes what \\`${spec.consumed_by}\\` does, not a template` : '',\n spec.required ? 'required' : '',\n ].filter(Boolean);\n console.log(` ${' '.repeat(14)} ${c.cyan(`${m.name}.${name}`.padEnd(30))} ${c.dim('=')} ${shown}`);\n if (spec.description) console.log(` ${' '.repeat(16)} ${c.dim(firstSentence(spec.description))}`);\n for (const n of notes) console.log(` ${' '.repeat(16)} ${c.dim(n)}`);\n }\n if (Object.keys(m.params).length) console.log();\n }\n if (showParams) {\n console.log(c.dim(' Set one with `--set module.param=value` on `add` or `init`; either spelling works.'));\n console.log(c.dim(' Resolved values are recorded in `.ai/rungs.toml`. See docs/design/parameters.md.\\n'));\n }\n\n const issues = auditModules(mods);\n console.log();\n if (issues.length === 0) {\n console.log(c.green(' audit clean') + c.dim(' \u2014 every parameter accounted for; every gate has a table, a why, and a declared applicability'));\n } else {\n console.log(c.red(` ${issues.length} issue(s):`));\n for (const i of issues) console.log(` ${c.yellow(i.module)} ${c.dim(i.kind)} \u2014 ${i.detail}`);\n }\n console.log();\n return issues.length === 0 ? 0 : 1;\n}\n\nfunction cmdDoctor(target: string, doExplain = false) {\n const root = resolve(target);\n const mods = loadAllModules(MODULES);\n console.log(c.bold(`\\nrungs doctor \u2014 ${root}\\n`));\n\n const files = scanRepo(root);\n const record = readRecord(root);\n console.log(\n c.dim(` scanned ${files.length} files`) +\n (record ? c.dim(` \u00B7 installed ${Object.keys(record.modules).length} module(s)`) : c.dim(' \u00B7 not a rungs repo')) +\n '\\n',\n );\n\n const params = resolveParams(mods, Object.fromEntries(\n Object.entries(record?.modules ?? {}).flatMap(([n, e]) => (e.params ? [[n, e.params]] : [])),\n ), root);\n const skillsDir = record?.harnesses.includes('claude') === false ? '.agents/skills' : '.claude/skills';\n const results = mods.map((m) => {\n const installed = record?.modules[m.name];\n return detect(m, root, files, installed ? { ...installed, skillsDir, params_all: params } : undefined);\n });\n const byState = (s: DetectResult['state']) => results.filter((r) => r.state === s);\n\n for (const r of results) {\n const mod = mods.find((m) => m.name === r.module)!;\n const line = ` ${r.module.padEnd(14)} ${STATE_LABEL[r.state]}`;\n if (r.state === 'absent') {\n console.log(c.dim(line));\n continue;\n }\n console.log(line);\n if (r.ours) {\n const parts = [`v${r.ours.version}`, `${r.ours.current.length} current`];\n if (r.ours.stale.length) parts.push(c.cyan(`${r.ours.stale.length} stale`));\n if (r.ours.missing.length) parts.push(c.yellow(`${r.ours.missing.length} missing`));\n if (r.ours.kept.length) parts.push(c.dim(`${r.ours.kept.length} kept (yours from the start)`));\n console.log(c.dim(` ${parts.join(' \u00B7 ')}`));\n for (const f of r.ours.diverged.slice(0, 3)) {\n console.log(` ${c.yellow('diverged')} ${f} ${c.dim('\u2014 yours, never overwritten')}`);\n }\n if (r.ours.diverged.length > 3) console.log(c.dim(` \u2026and ${r.ours.diverged.length - 3} more`));\n if (r.ours.stale.length || r.ours.missing.length) {\n console.log(c.dim(' run `rungs upgrade --apply`'));\n }\n continue;\n }\n for (const p of r.matchedPaths.slice(0, 2)) {\n console.log(c.dim(` ${p.count}\u00D7 ${p.pattern} e.g. ${p.sample[0]}`));\n }\n if (r.matchedMarkers.length) console.log(c.dim(` markers: ${r.matchedMarkers.join(', ')}`));\n for (const prop of r.proposals) {\n console.log(` ${c.cyan('proposes')} ${prop.param} = ${c.bold(prop.value)} ${c.dim(`(${prop.evidence})`)}`);\n }\n for (const a of r.adoptable) {\n console.log(` ${c.cyan('adoptable')} ${a.count} as ${a.kind} ${c.dim(`e.g. ${a.sample[0]}`)}`);\n }\n if (r.paradigm) {\n console.log(` ${c.yellow('different paradigm')}: ${r.paradigm.id} ${c.dim(`(${r.paradigm.matched[0]})`)}`);\n if (r.paradigm.note) console.log(c.dim(` ${firstSentence(r.paradigm.note)}`));\n }\n if (mod.threshold?.confirm) {\n console.log(c.yellow(` threshold: ${mod.threshold.minimum}+ ${mod.threshold.metric} \u2014 add requires confirmation`));\n }\n }\n\n const ours = byState('ours-current').length + byState('ours-diverged').length;\n console.log(\n `\\n ${ours ? `${ours} installed (${byState('ours-diverged').length} diverged) \u00B7 ` : ''}` +\n `${byState('theirs').length} present \u00B7 ${byState('paradigm').length} different paradigm \u00B7 ` +\n `${byState('absent').length} absent\\n`,\n );\n\n // ADR-0005: state what this does not cover, every time. A green read is not\n // a verified one, and a low count may mean a narrow signature rather than a\n // clean repo.\n console.log(c.dim(' This reports presence, never quality. It cannot tell whether an adopted'));\n console.log(c.dim(' system is good, complete, or working \u2014 only that files are where a'));\n console.log(c.dim(\" module's files would be. Signatures under-detect on purpose.\\n\"));\n\n reportLedger(root);\n\n if (doExplain) reportExplain(mods, results, root, files);\n else advertiseAnalysis(results);\n\n // `doctor` is the command the README makes the entry point, and it used to stop on the sentence\n // above \u2014 fifteen `absent` lines and nothing to do next. The recommendation is deliberately a\n // **single** command, and never the maximal one: the brief names selling rung 5 to a rung-1 repo\n // as the most likely way this tool does harm, so a repo with nothing is pointed at `tracked`\n // rather than at the fifteen things it could install (WI-005).\n const theirs = byState('theirs');\n console.log(c.bold(' Next\\n'));\n if (ours) {\n const behind = results.some((r) => r.ours?.stale.length || r.ours?.missing.length);\n console.log(\n behind\n ? ` ${c.cyan('rungs upgrade --apply')} ${c.dim('\u2014 bring the stale and missing files up to date')}`\n : ` ${c.cyan('rungs check')} ${c.dim('\u2014 run the gates this repo already registered')}`,\n );\n console.log(c.dim(` Add more with \\`rungs add <module>\\`; \\`rungs modules\\` lists the set.\\n`));\n } else if (theirs.length) {\n const names = theirs.map((r) => r.module).slice(0, 3).join(' ');\n console.log(` ${c.cyan(`rungs add ${names}`)} ${c.dim('\u2014 adopt what you already built, in place')}`);\n console.log(c.dim(' Nothing is overwritten. Files you already have are kept and reported as'));\n console.log(c.dim(' yours; only what is missing gets written.\\n'));\n } else {\n console.log(` ${c.cyan('rungs init . tracked')} ${c.dim('\u2014 instructions \u00B7 gates \u00B7 backlog \u00B7 findings \u00B7 adr \u00B7 session')}`);\n console.log(c.dim(' `tracked` is the rung for more than one thing in flight. `minimal` is just'));\n console.log(c.dim(' the entry document; higher profiles cost more than they return until the'));\n console.log(c.dim(' problem they answer actually exists. `rungs modules` lists all fifteen.\\n'));\n }\n return 0;\n}\n\nfunction firstSentence(s: string): string {\n return s.trim().replace(/\\s+/g, ' ').split(/(?<=\\.)\\s/)[0];\n}\n\n/**\n * Say that the analysis exists, and how much of it there is. Never what it\n * found (WI-049).\n *\n * `--explain` is the capability both external reviews called the strongest\n * thing here, and plain `doctor` printed no occurrence of the string `explain`\n * \u2014 it was reachable only from `--help`. WI-038 put the *findings* behind a flag\n * for a measured reason: 114 on `hexguard` would bury the `Next` line that\n * WI-005 exists to protect. The flag was never the problem; the silence was.\n *\n * **It reports scope, not findings, and it runs no engine.** The first version\n * printed a finding count, which meant running the detectors on the plain path.\n * Measured on `rift-forge` 2026-08-16: plain `doctor` went from **1.6s to\n * 16.8s** warm \u2014 a 10\u00D7 tax on the entry point to advertise a flag. WI-049's\n * plan named this outcome in advance and named this fallback.\n *\n * So the number is the one detection already computed. It claims what it can\n * prove: these are things the repo has, and our checks can read them. It does\n * not claim anything was found, because finding out costs the 15 seconds.\n */\nfunction advertiseAnalysis(results: DetectResult[]) {\n const inScope = results.filter((r) => EXPLAINABLE.has(r.state)).length;\n if (!inScope) return;\n\n console.log(c.bold(' Analysis\\n'));\n console.log(` ${inScope} of these are things this repo already has, and can be checked against it.`);\n console.log(` ${c.cyan('rungs doctor --explain')} ${c.dim('\u2014 evidenced findings, and the incident behind each check')}\\n`);\n}\n\n/**\n * The defect half of `doctor` (WI-038). Every line carries a path and a count\n * or a quote; there is no score, grade, bar, or maturity label anywhere, and\n * there is not going to be \u2014 ADR-0005 tier C refuses composites permanently,\n * and a single word over incommensurable signals is the purest form of the\n * probe-encoding-a-guess the corpus warns about.\n *\n * The incident is attached to each detector rather than to each finding: it is\n * why the check exists, not what was found, and repeating it per row would bury\n * the evidence under the provenance.\n */\nfunction reportExplain(mods: Manifest[], results: DetectResult[], root: string, files: string[]) {\n const { reported, skipped, scope } = explain(mods, results, root, files);\n\n console.log(c.bold(' What it also checked\\n'));\n\n if (!scope.length) {\n console.log(c.dim(' Nothing \u2014 detectors run only over what this repo already has, and'));\n console.log(c.dim(' detection found no equivalent of any module. There is nothing here to'));\n console.log(c.dim(' check that would not be checking our conventions against your repo.\\n'));\n return;\n }\n\n const total = reported.reduce((n, r) => n + r.findings.length, 0);\n console.log(\n c.dim(` ran the detectors for ${scope.length} module(s) this repo already has: `) + c.dim(scope.join(' ')) + '\\n',\n );\n\n for (const r of reported) {\n const n = r.findings.length;\n console.log(` ${c.yellow(r.gate.padEnd(34))} ${c.bold(String(n))} ${n === 1 ? 'finding' : 'findings'}`);\n for (const f of r.findings.slice(0, 4)) {\n console.log(c.dim(` ${f.file ? `${f.file}: ` : ''}${f.message}`));\n }\n if (n > 4) console.log(c.dim(` \u2026and ${n - 4} more`));\n if (r.why) console.log(c.dim(` why: ${firstSentence(r.why)}`));\n console.log();\n }\n\n if (!total) {\n console.log(c.dim(' No detector fired. That is not a clean bill of health \u2014 see below.\\n'));\n }\n\n // Pins. ADR-0005's rule that green must never read as verified applies with\n // more force here than in the ledger: this pass runs our checks over content\n // written to somebody else's conventions, and the honest failure mode is a\n // sound finding in a frame the repo never adopted.\n console.log(c.dim(' This is not an audit, and it is deliberately incomplete:'));\n console.log(c.dim(' \u00B7 Detectors ran only for modules this repo already has an equivalent of.'));\n console.log(c.dim(\" \u00B7 They read rungs-shaped inputs. A finding may be true and framed against\"));\n console.log(c.dim(' a convention you never adopted \u2014 that is our defect, not yours.'));\n if (skipped.command) {\n console.log(c.dim(` \u00B7 ${skipped.command} command gate(s) not run. rungs does not execute commands in a repo it is only reading.`));\n }\n if (skipped.undeclared.length) {\n console.log(c.dim(` \u00B7 ${skipped.undeclared.length} gate(s) never said whether they can read a repo like yours, so they did not: ${skipped.undeclared.join(' ')}`));\n }\n if (skipped.unimplemented.length) {\n console.log(c.dim(` \u00B7 ${skipped.unimplemented.length} declared gate(s) have no engine and were skipped, never passed: ${skipped.unimplemented.join(' ')}`));\n }\n for (const e of skipped.errored) {\n console.log(c.dim(` \u00B7 ${e.gate} could not run here (${e.message}) \u2014 a fact about this pass, not about your repo.`));\n }\n console.log();\n}\n\nfunction cmdAdd(names: string[], root: string, dryRun: boolean, harnesses: Harness[], stamp: string) {\n const mods = loadAllModules(MODULES);\n const { order, missing } = resolveInstallOrder(names, mods);\n if (missing.length) {\n console.log(c.red(`\\n unknown module(s): ${missing.join(', ')}\\n`));\n return 1;\n }\n const pulled = order.filter((m) => !names.includes(m.name));\n\n // `--set module.param=value`. Without it the first real install into a repo\n // that already had a backlog would have created a second one beside it \u2014\n // `docs/backlog/` next to `docs/.ai/backlog/` \u2014 which is the \"two places to\n // look\" failure this whole tool is against, arriving through the installer.\n //\n // Values arrive already split from their flag, in either spelling. A malformed\n // key is refused rather than skipped: `--set root=x` used to be dropped in\n // silence, so the install proceeded with the default and looked successful.\n const overrides: Record<string, Record<string, unknown>> = {};\n for (const raw of flagValues['--set'] ?? []) {\n const [key, ...rhs] = raw.split('=');\n const [modName, param] = key.split('.');\n if (!modName || !param || !rhs.length) {\n console.log(c.red(`\\n --set expects module.param=value, got: ${raw}\\n`));\n return 1;\n }\n (overrides[modName] ??= {})[param] = rhs.join('=');\n }\n\n // \u2026and an unknown *name* is refused for the same reason a malformed key is.\n // The comment above says a dropped `--set` \"proceeded with the default and\n // looked successful\"; a mistyped module or parameter did exactly that, and the\n // echo below then printed `set nosuch.param = 1` as though it had applied\n // (F-028). The whole module set is loaded here, so the names are checkable \u2014\n // there was never a reason to trust them.\n for (const [modName, vals] of Object.entries(overrides)) {\n const mod = mods.find((m) => m.name === modName);\n if (!mod) {\n console.log(\n c.red(`\\n --set names a module that does not exist: ${modName}`) +\n c.dim(`\\n Known: ${mods.map((m) => m.name).join(', ')}\\n`),\n );\n return 1;\n }\n for (const k of Object.keys(vals)) {\n if (!(k in mod.params)) {\n const known = Object.keys(mod.params);\n console.log(\n c.red(`\\n --set names a parameter ${modName} does not have: ${k}`) +\n c.dim(`\\n ${known.length ? `${modName} takes: ${known.join(', ')}` : `${modName} takes no parameters`}`) +\n c.dim('\\n `rungs modules --params` lists every parameter and its default.\\n'),\n );\n return 1;\n }\n }\n }\n const params = resolveParams(mods, overrides, root);\n for (const [m, vals] of Object.entries(overrides)) {\n for (const [k, v] of Object.entries(vals)) console.log(c.dim(` set ${m}.${k} = ${v}`));\n }\n const skillsDir = harnesses.includes('claude') ? '.claude/skills' : '.agents/skills';\n\n console.log(c.bold(`\\nrungs add ${names.join(' ')} \u2192 ${root}${dryRun ? c.yellow(' (dry run)') : ''}\\n`));\n if (pulled.length) console.log(c.dim(` pulled in by dependency: ${pulled.map((m) => m.name).join(', ')}\\n`));\n\n // ADR-0004 state 5: a repo that solves this module's problem a different way\n // gets the comparison and a stop, not an install beside what it already runs.\n //\n // The state existed in the ADR and in `doctor` and nowhere else, so `add`\n // wrote straight over it \u2014 for every paradigm, since the CLI shipped\n // (WI-043, from F-014). Measured 2026-08-16: a repo with `.github/ISSUE_TEMPLATE/`\n // reported `backlog paradigm \u00B7 external-tracker`, and `add backlog` then wrote\n // `docs/`, `AGENTS.md`, `.ai/` and 12 gates without mentioning it once.\n //\n // Unlike `--confirm-threshold` above, this refusal **also applies under\n // `--dry-run`**. A preview that installs what the real run refuses is a\n // preview of a different command.\n const scanned = scanRepo(root);\n const paradigms = new Set(\n order.map((m) => detect(m, root, scanned)).filter((r) => r.state === 'paradigm').map((r) => r.module),\n );\n const overridden = flags.has('--confirm-paradigm');\n const blocked = overridden ? new Map<string, string>() : blockedByParadigm(order, paradigms);\n\n // An override that prints nothing is indistinguishable from a detection that\n // found nothing, and the two want opposite follow-ups.\n if (overridden && paradigms.size) {\n for (const name of paradigms) {\n const p = detect(order.find((m) => m.name === name)!, root, scanned).paradigm!;\n console.log(\n c.yellow(` ${name}: installing over an existing ${p.id}`) +\n c.dim(` (${p.matched[0]}) \u2014 --confirm-paradigm`),\n );\n }\n console.log(c.dim(' You will have two systems for one job. That is a choice, not a merge.\\n'));\n }\n\n // Re-resolve from what survives rather than filtering `order` in place. A\n // dependency is only ever pulled in *for* something; `add backlog` on an\n // issue-tracker repo was still writing `instructions` and `gates`, which\n // nobody asked for and which were pulled in solely for the module being\n // refused. Recomputing the closure drops them, and keeps anything a *surviving*\n // request still needs.\n let toInstall = order;\n if (blocked.size) {\n for (const mod of order) {\n const cause = blocked.get(mod.name);\n if (!cause) continue;\n if (cause === mod.name) {\n const p = detect(mod, root, scanned).paradigm!;\n console.log(c.yellow(` ${mod.name}: this repo already does this another way \u2014 ${p.id}`));\n console.log(c.dim(` matched ${p.matched[0]}`));\n for (const line of (p.note ?? '').trim().split('\\n')) console.log(c.dim(` ${line || ''}`));\n if (p.compare) console.log(c.dim(` compare: ${p.compare}`));\n } else {\n console.log(c.yellow(` ${mod.name}: not installed \u2014 it requires ${cause}.`));\n }\n }\n toInstall = resolveInstallOrder(names.filter((n) => !blocked.has(n)), mods).order;\n const dropped = order.filter((m) => !toInstall.includes(m) && !blocked.has(m.name));\n if (dropped.length) {\n console.log(c.dim(` ${dropped.map((m) => m.name).join(', ')} not written \u2014 pulled in only for the above`));\n }\n console.log(\n c.dim(`\\n Pass --confirm-paradigm to install anyway.`) +\n (toInstall.length ? c.dim(' Continuing with the rest.\\n') : c.dim(' Nothing was written.\\n')),\n );\n if (!toInstall.length) return 1;\n }\n\n const installed: Manifest[] = [];\n const wrote = new Map<string, Set<string>>();\n for (const mod of toInstall) {\n if (mod.threshold?.confirm && !dryRun && !flags.has('--confirm-threshold')) {\n console.log(\n c.yellow(` ${mod.name}: requires ${mod.threshold.minimum}+ ${mod.threshold.metric}.`) +\n c.dim(' Skipped \u2014 pass --confirm-threshold to install it.\\n'),\n );\n continue;\n }\n const actions = addModule(mod, root, params, { dryRun, skillsDir });\n installed.push(mod);\n wrote.set(mod.name, new Set(actions.filter((a) => a.disposition !== 'skip-exists' && a.disposition !== 'merge' && a.disposition !== 'gate').map((a) => a.target)));\n const counts = new Map<string, number>();\n for (const a of actions) counts.set(a.disposition, (counts.get(a.disposition) ?? 0) + 1);\n console.log(` ${c.bold(mod.name.padEnd(14))} ${[...counts].map(([k, v]) => `${v} ${k}`).join(' \u00B7 ')}`);\n for (const a of actions.filter((x) => x.disposition === 'skip-exists')) {\n console.log(c.dim(` kept ${a.target}`));\n }\n }\n\n // Detect what the repo already has and register it alongside (ADR-0004).\n const repoFiles = scanRepo(root);\n const adopted = installed.flatMap((m) =>\n (m.detect.adopt_as ?? [])\n .filter((a) => a.kind === 'command')\n .flatMap((a) => adoptableGates(repoFiles, a.paths ?? [], root)),\n );\n if (adopted.length) {\n console.log(\n '\\n ' + c.cyan(`adopting ${adopted.length} existing validator(s)`) +\n ' as command gates' + c.dim(' \u2014 their scripts are untouched'),\n );\n for (const a of adopted.slice(0, 3)) console.log(c.dim(` ${a.command}`));\n if (adopted.length > 3) console.log(c.dim(` \u2026and ${adopted.length - 3} more`));\n }\n\n // Phase two: the registry's owner has created it by now.\n const gateActions = registerGates(installed, root, dryRun, adopted);\n if (gateActions.length) {\n console.log(c.dim(`\\n registered ${gateActions.reduce((n, a) => n + Number(a.note!.split(': ')[1].split(' ')[0]), 0)} gates from ${gateActions.length} module(s)`));\n }\n\n if (!dryRun) {\n writeInstallRecord(root, order, params, harnesses, stamp, skillsDir, wrote);\n const entries = render(root, harnesses);\n writeReport(root, entries, harnesses, stamp);\n console.log(\n `\\n rendered ${entries.filter((e) => e.target).length} file(s) \u00B7 ` +\n `${entries.filter((e) => e.degraded).length} degraded ` +\n c.dim('\u2192 .ai/render-report.md'),\n );\n }\n console.log();\n return 0;\n}\n\nfunction cmdRender(root: string, harnesses: Harness[], stamp: string) {\n const entries = render(root, harnesses);\n writeReport(root, entries, harnesses, stamp);\n console.log(c.bold(`\\nrungs render \u2014 ${root}\\n`));\n for (const e of entries) {\n const lost = e.degraded ?? (e.dropped?.length ? c.dim(` (dropped ${e.dropped.join(', ')})`) : '');\n console.log(` ${e.rule.padEnd(24)} ${e.harness.padEnd(10)} ${e.target ?? c.yellow('not emitted')}${lost}`);\n }\n console.log(c.dim(`\\n ${entries.length} rendering(s) \u2192 .ai/render-report.md\\n`));\n // A bare `0 rendering(s)` reads as a completed edit. It is the answer a user gets after editing a\n // parameter in `.ai/rungs.toml` and running this \u2014 the thing the record's header used to tell\n // them to do \u2014 so the zero case has to say what it did not do, not just how much of it (WI-003).\n if (entries.length === 0) {\n console.log(c.yellow(' Nothing to render.') + c.dim(' This command re-emits path-scoped rules from `.ai/rules/`.'));\n console.log(c.dim(' It does not re-substitute parameters \u2014 a changed value in `.ai/rungs.toml`'));\n console.log(c.dim(' does not rewrite a file that already exists.\\n'));\n }\n return 0;\n}\n\n/** The loop commands return lines and a verdict; printing them is the CLI's job. */\nfunction report(r: { ok: boolean; lines: string[] }): number {\n console.log();\n for (const l of r.lines) console.log(` ${r.ok ? l : c.yellow(l)}`);\n console.log();\n return r.ok ? 0 : 1;\n}\n\n/**\n * `land` verifies the *merged* tree, so it needs the gate runner pointed at a\n * directory that exists only inside the command. This is the reason the loop is\n * CLI commands rather than scripts the module writes (ADR-0009).\n */\nfunction landRunner(dir: string, only?: ReadonlySet<string>) {\n const runs = runGates(dir, undefined, undefined, only);\n const failing = runs.filter((r) => r.status === 'fail' || r.status === 'error');\n return {\n pass: runs.filter((r) => r.status === 'pass').length,\n // `file: message`, so the same broken link in the same file is the same\n // finding across two runs, and a *new* one is visibly not.\n failing: failing.map((r) => ({\n id: r.id,\n findings: r.findings.map((f) => `${f.file ? `${f.file}: ` : ''}${f.message}`),\n })),\n };\n}\n\nfunction cmdWorktrees(root: string) {\n const { rows, integration } = worktrees(root);\n console.log(c.bold(`\\nrungs worktrees \u2014 merged into ${integration}?\\n`));\n if (!rows.length) {\n console.log(c.dim(' no linked worktrees. `rungs session start <branch>` creates one.\\n'));\n return 0;\n }\n for (const w of rows) {\n const state = w.merged && w.dirty ? c.red('merged \u00B7 DIRTY') : w.merged ? c.green('merged \u00B7 prunable') : c.dim('in flight');\n console.log(` ${state.padEnd(28)} ${w.branch.padEnd(30)} ${c.dim(w.path)}`);\n }\n const risky = rows.filter((w) => w.merged && w.dirty);\n const prunable = rows.filter((w) => w.merged && !w.dirty);\n console.log();\n if (risky.length) {\n console.log(c.red(` ${risky.length} worktree(s) hold uncommitted work on a branch that already landed.`));\n console.log(c.dim(' That is where work actually gets lost. Commit it somewhere or decide to drop it.'));\n }\n if (prunable.length) console.log(c.dim(` ${prunable.length} prunable. Removing a worktree is your call, not this command's.`));\n console.log();\n return 0;\n}\n\nfunction cmdCheck(root: string, tier: string | undefined, stamp: string) {\n let runs: GateRun[];\n try {\n runs = runGates(root, tier);\n } catch (e) {\n // ADR-0008. A tier nobody declared used to select nothing and exit as though\n // the gates had passed \u2014 the one failure mode a release step cannot have.\n if (!(e instanceof UnknownTierError)) throw e;\n console.log(c.yellow(`\\n unknown tier \"${e.requested}\"`) + c.dim(` \u2014 this repo declares ${e.declared.join(', ')}.`));\n console.log(c.dim(' Nothing ran. Use `rungs check` to run every registered gate.\\n'));\n return 1;\n }\n if (!runs.length) {\n // Two situations printed the same sentence, and it was the wrong one for the case that\n // actually happens: a registry full of `fast` gates filtered by `--full` asked \"is this a\n // rungs repo?\" about a repo holding 25 of them, and `cut-release` told every consumer to\n // gate a release on exactly that command (F-020). Blame the filter when there is one.\n //\n // Hooks are excluded because a hook fires on a tool call rather than in the runner: it is\n // registered, and no tier value could ever have selected it. Counting it here would offer\n // the reader a gate that changing the tier cannot reach.\n const runnable = loadRegistry(root).gates.filter((g) => !g.trigger);\n if (runnable.length && tier) {\n const tiers = [...new Set(runnable.map((g) => g.tier).filter(Boolean))];\n console.log(c.yellow(`\\n no gates in the ${tier} tier \u2014 ${runnable.length} are registered`) +\n c.dim(` (${tiers.length ? tiers.join(', ') : 'none tiered'}).`));\n console.log(c.dim(' Nothing ran. Use `rungs check` to run every registered gate.\\n'));\n } else {\n console.log(c.yellow('\\n no gates registered \u2014 is this a rungs repo?\\n'));\n }\n return 1;\n }\n appendLedger(root, runs, stamp);\n\n console.log(c.bold(`\\nrungs check \u2014 ${root}${tier ? ` (${tier} tier)` : ''}\\n`));\n const mark = { pass: c.green('pass'), fail: c.red('FAIL'), unimplemented: c.yellow('unimpl'), error: c.red('error') };\n for (const r of runs) {\n console.log(\n ` ${mark[r.status]} ${r.id.padEnd(34)} ${c.dim(`${r.ms}ms`)}` +\n (r.examined ? c.dim(` ${r.examined} examined`) : ''),\n );\n for (const f of r.findings.slice(0, 4)) {\n console.log(` ${c.dim(f.file ? `${f.file}: ` : '')}${f.message}`);\n }\n if (r.findings.length > 4) console.log(c.dim(` \u2026and ${r.findings.length - 4} more`));\n }\n\n const n = (s: string) => runs.filter((r) => r.status === s).length;\n console.log(\n `\\n ${c.green(`${n('pass')} pass`)} \u00B7 ${c.red(`${n('fail')} fail`)} \u00B7 ` +\n `${c.yellow(`${n('unimplemented')} unimplemented`)} \u00B7 ${n('error')} error` +\n c.dim(` (${runs.reduce((t, r) => t + r.ms, 0)}ms total)`),\n );\n\n if (n('unimplemented')) {\n console.log(\n c.yellow('\\n Unimplemented gates are not passes.') +\n c.dim(' A registry reporting green because most of its\\n gates do nothing is the worst failure this tool could have, so they block.'),\n );\n }\n\n console.log();\n return n('fail') + n('unimplemented') + n('error') > 0 ? 1 : 0;\n}\n\n/**\n * ADR-0005 tier B: the two questions the ledger can ask without judgement.\n *\n * This printed from `check` and belonged in `doctor`, which is what both the\n * ADR and the README say (F-012). The ADR does not merely name the command, it\n * gives the reason: *\"They must be pull (`doctor`), never push; no output\n * during normal runs.\"* `check` is the normal run \u2014 it is what CI and every\n * pre-merge habit invoke \u2014 so printing there was the push the tier was written\n * to forbid, arriving inside the feature that forbade it.\n */\nfunction reportLedger(root: string) {\n const { gates } = loadRegistry(root);\n const q = ledgerQuestions(root, gates);\n if (!q.neverFired.length && !q.alwaysFires.length) return;\n\n console.log(c.bold(` Ledger questions ${c.dim(`(${q.runs} recorded runs)`)}`));\n for (const g of q.neverFired.slice(0, 3)) {\n console.log(` ${c.cyan(g.id)} has never fired. ${c.dim(firstSentence(g.why ?? ''))}`);\n console.log(c.dim(' Is that still a risk here, or is the gate scoped too narrowly?'));\n }\n for (const g of q.alwaysFires.slice(0, 3)) {\n console.log(` ${c.cyan(g.id)} fails ${g.rate}. ${c.dim('Red by default is a gate people learn to bypass.')}`);\n }\n console.log(c.dim('\\n These are questions, not verdicts. The ledger records whether a gate ran'));\n console.log(c.dim(' and whether it fired \u2014 never whether it is valuable. Gates invoked'));\n console.log(c.dim(' directly, and CI runs, are not counted.\\n'));\n}\n\nfunction cmdBacklogArchive(root: string, dryRun: boolean) {\n const record = readRecord(root);\n const configured = record?.modules['backlog']?.params?.root;\n const backlogRoot = `docs/${configured ?? 'backlog'}`;\n\n if (!existsSync(join(root, ...backlogRoot.split('/'), 'items'))) {\n console.log(c.red(`\\n no backlog at ${backlogRoot}/items\\n`));\n return 1;\n }\n\n const plan = planArchive(root, backlogRoot);\n console.log(c.bold(`\\nrungs backlog archive \u2192 ${root}${dryRun ? c.yellow(' (dry run)') : ''}\\n`));\n\n for (const h of plan.held) console.log(c.yellow(` held ${h.file}`) + c.dim(` \u2014 ${h.reason}`));\n if (plan.held.length) console.log();\n\n if (!plan.moves.length) {\n console.log(c.dim(' nothing to archive \u2014 no item is done or rejected.\\n'));\n return 0;\n }\n\n const byStatus = new Map<string, number>();\n for (const m of plan.moves) byStatus.set(m.status, (byStatus.get(m.status) ?? 0) + 1);\n console.log(\n ` ${c.bold(String(plan.moves.length))} item(s) \u2014 ${[...byStatus].map(([s, n]) => `${n} ${s}`).join(' \u00B7 ')}`,\n );\n for (const m of plan.moves.slice(0, 5)) console.log(c.dim(` ${m.from} \u2192 ${m.to}`));\n if (plan.moves.length > 5) console.log(c.dim(` \u2026and ${plan.moves.length - 5} more`));\n\n const touched = plan.rewrites.filter((r) => r.links);\n const links = touched.reduce((n, r) => n + r.links, 0);\n console.log(`\\n ${c.bold(String(links))} link(s) repointed across ${touched.length} file(s)`);\n for (const r of touched.slice(0, 5)) console.log(c.dim(` ${r.file} (${r.links})`));\n if (touched.length > 5) console.log(c.dim(` \u2026and ${touched.length - 5} more`));\n\n if (dryRun) {\n console.log(c.dim('\\n Nothing written. Drop --dry-run to apply.\\n'));\n return 0;\n }\n\n applyArchive(root, plan);\n console.log(c.green(`\\n archived ${plan.moves.length} item(s)`) + c.dim(' \u2014 ids stay spent and every citation still resolves.'));\n console.log(c.dim(' Run `rungs check` to confirm.\\n'));\n return 0;\n}\n\nfunction cmdInit(root: string, profile: string, dryRun: boolean, harnesses: Harness[], stamp: string) {\n if (readRecord(root)) {\n console.log(\n c.yellow('\\n this repo is already initialised.') +\n c.dim(' Use `rungs add <module>` to install more, or `rungs upgrade`.\\n'),\n );\n return 1;\n }\n const names = PROFILES[profile];\n if (!names) {\n console.log(c.red(`\\n unknown profile '${profile}'.`) + c.dim(` Known: ${Object.keys(PROFILES).join(', ')}\\n`));\n return 1;\n }\n console.log(c.dim(`\\n profile '${profile}' \u2014 ${names.length} modules`));\n return cmdAdd(names, root, dryRun, harnesses, stamp);\n}\n\nfunction cmdUpgrade(root: string, apply: boolean) {\n const record = readRecord(root);\n if (!record) {\n console.log(c.yellow('\\n not a rungs repo \u2014 nothing to upgrade.\\n'));\n return 1;\n }\n const mods = loadAllModules(MODULES);\n const plan = planUpgrade(root, mods, record);\n console.log(c.bold(`\\nrungs upgrade \u2014 ${root}${apply ? '' : c.yellow(' (preview)')}\\n`));\n\n let stale = 0;\n let diverged = 0;\n for (const item of plan) {\n const counts = item.files.reduce<Record<string, number>>((a, f) => ({ ...a, [f.state]: (a[f.state] ?? 0) + 1 }), {});\n stale += (counts.stale ?? 0) + (counts.missing ?? 0);\n diverged += counts.diverged ?? 0;\n const moved = item.from === item.to ? c.dim(item.to) : `${item.from} \u2192 ${c.bold(item.to)}`;\n console.log(` ${item.module.padEnd(14)} ${moved} ${c.dim(Object.entries(counts).map(([k, v]) => `${v} ${k}`).join(' \u00B7 '))}`);\n for (const f of item.files.filter((x) => x.state === 'diverged')) {\n console.log(` ${c.yellow('diverged')} ${f.rel} ${c.dim('\u2014 yours, left alone')}`);\n }\n }\n\n // Not `apply && stale`. A module version that only adds a gate has no stale\n // file, so the whole apply step was skipped and the registry silently kept the\n // old block \u2014 F-016, measured on a scratch consumer where `session` 1.1.0 \u2192\n // 1.2.0 added a gate and `rungs check` went on running the previous twenty.\n if (apply) {\n const { written, gates, recorded } = applyUpgrade(root, mods, record, plan);\n const parts = [\n written ? `${written} file(s)` : '',\n gates ? `${gates} gate registration(s)` : '',\n recorded ? `${recorded} record line(s)` : '',\n ].filter(Boolean);\n console.log(c.green(`\\n updated ${parts.length ? parts.join(' \u00B7 ') : 'nothing'}`));\n }\n console.log(\n `\\n ${stale} to update \u00B7 ${diverged} diverged\\n` +\n c.dim(' Divergence is a decision, not an error: a file you edited is never overwritten.\\n') +\n (apply ? '' : c.dim(' Run with --apply to write.\\n')),\n );\n return 0;\n}\n\nfunction cmdEject(root: string, dryRun: boolean) {\n if (!readRecord(root)) {\n console.log(c.yellow('\\n not a rungs repo \u2014 nothing to eject.\\n'));\n return 1;\n }\n const result = eject(root, loadAllModules(MODULES), dryRun);\n console.log(c.bold(`\\nrungs eject \u2014 ${root}${dryRun ? c.yellow(' (dry run)') : ''}\\n`));\n for (const a of result.actions.slice(0, 6)) console.log(c.dim(` ${a}`));\n if (result.actions.length > 6) console.log(c.dim(` \u2026and ${result.actions.length - 6} more`));\n console.log(\n `\\n ${result.gates} declared gate(s) rewritten as commands.` +\n c.dim('\\n This repo no longer needs rungs installed to run its checks.\\n') +\n c.dim(' Engine fixes stop arriving with a version bump \u2014 these files are yours now.\\n'),\n );\n return 0;\n}\n\n/**\n * Flags that carry a value, and therefore consume the token after them unless it is attached with\n * `=`. Everything else is a bare switch.\n *\n * This exists because the split below used to be two filters \u2014 `startsWith('--')` into flags,\n * everything else into positionals \u2014 which has no concept of a value. `--set backlog.root=x` then\n * left `backlog.root=x` sitting in the positionals, `--into` took the last positional as its\n * target, and the user's actual path was reported back to them as an unknown module. Both\n * spellings now work, and the value never reaches `args` (WI-002).\n */\nconst VALUE_FLAGS = new Set(['--set']);\n\n/**\n * The command surface, defined once and rendered into `--help`.\n *\n * It was a template literal listing eight of the nine commands \u2014 `setup git` was missing entirely \u2014\n * beside a README table listing all nine, which is two hand-kept inventories of one fact. They had\n * already drifted, in both directions: help omitted a real command, and three real flags appeared\n * in neither. Keep this table beside the switch it describes, and add a row when you add a `case`.\n *\n * The README's table is still hand-kept and still a second inventory. That is a known cost, not an\n * oversight \u2014 see WI-004.\n */\nconst COMMANDS: [usage: string, blurb: string][] = [\n ['init [path] [profile]', 'scaffold a repo \u2014 minimal \u00B7 tracked \u00B7 disciplined \u00B7 hardened \u00B7 fleet'],\n ['doctor [path]', 'detect what a repo already has, installed or not'],\n ['add <module\u2026> [--into p]', 'install modules, resolving dependencies and adopting what exists'],\n ['check [path] [tier]', 'run the registered gates and record the ledger'],\n ['render [path]', 're-emit path-scoped rules per harness'],\n ['upgrade [path]', 'move to newer module versions, never touching what you edited'],\n ['eject [path]', 'materialise the engines; stop depending on rungs'],\n ['setup git [path]', 'install the merge drivers .gitattributes names'],\n ['modules', 'list the module set and audit the manifests'],\n ['backlog archive [path]', 'move finished items to archive/, repointing every link'],\n ['session start <branch>', 'cut a branch and worktree from the last verified merge'],\n ['preflight [path]', 'did the integration branch change files you changed?'],\n ['land <branch>', 'merge \u2192 verify the merged tree \u2192 advance, or refuse and park it'],\n ['worktrees [path]', 'which worktrees are merged, prunable, or merged and still dirty'],\n];\n\n/** Every flag the parser honours. A flag absent here is a flag nobody can find. */\nconst FLAGS: [flag: string, blurb: string][] = [\n ['--dry-run', 'report what would happen, write nothing'],\n ['--explain', \"doctor: also run the detectors over what this repo already has\"],\n ['--confirm-paradigm', 'add: install a module this repo already solves another way'],\n ['--into <path>', 'add: install into this repo instead of the working directory'],\n ['--set m.param=value', 'add/init: override a module parameter. Repeatable'],\n ['--confirm-threshold', 'add: install a module whose rung is above this repo'],\n ['--apply', 'upgrade: write the changes, rather than preview them'],\n ['--fast, --full', 'check: pick the gate tier, as the positional also does'],\n ['--params', 'modules: show every module parameter, its default and its allowed values'],\n ['--copilot', 'also emit Copilot instruction files'],\n];\n\nfunction renderHelp(): string {\n const pad = Math.max(...COMMANDS.map(([u]) => u.length)) + 2;\n const fpad = Math.max(...FLAGS.map(([f]) => f.length)) + 2;\n return [\n ``,\n `${c.bold('rungs')} \u2014 installs and maintains a repository's agentic development system`,\n ``,\n ...COMMANDS.map(([u, b]) => ` ${c.bold(`rungs ${u.split(' ')[0]}`)}${u.slice(u.split(' ')[0].length).padEnd(pad - u.split(' ')[0].length)} ${c.dim(b)}`),\n ``,\n ...FLAGS.map(([f, b]) => ` ${c.dim(f.padEnd(fpad))} ${c.dim(b)}`),\n ``,\n ].join('\\n');\n}\n\nconst [, , cmd, ...rest] = process.argv;\n\nconst flags = new Set<string>();\nconst args: string[] = [];\nconst flagValues: Record<string, string[]> = {};\n/** A value-flag left without a value. Reported by the command, so `--help` still works. */\nlet missingValue: string | null = null;\n\nfor (let i = 0; i < rest.length; i++) {\n const token = rest[i];\n if (!token.startsWith('--')) {\n args.push(token);\n continue;\n }\n const eq = token.indexOf('=');\n const name = eq === -1 ? token : token.slice(0, eq);\n if (!VALUE_FLAGS.has(name)) {\n // The bare name, not the raw token, so `--copilot=yes` still answers `flags.has('--copilot')`.\n flags.add(name);\n continue;\n }\n // Attached form first; otherwise the next token, unless that is itself a flag \u2014 `--set --dry-run`\n // is a missing value, not a value of `--dry-run`.\n const next = rest[i + 1];\n const value = eq === -1 ? (next === undefined || next.startsWith('--') ? undefined : rest[++i]) : token.slice(eq + 1);\n if (value === undefined) missingValue = name;\n else (flagValues[name] ??= []).push(value);\n}\n\n/**\n * A positional shaped like `module.param=value` was meant to be an override and was not claimed by\n * `--set`. No path, module, profile or tier has that shape, so it is unambiguously a mistake \u2014\n * refuse it by name rather than letting a command interpret it as something else.\n */\nconst strayOverride = args.find((a) => /^[a-z][a-z0-9_-]*\\.[a-z][a-z0-9_]*=/.test(a));\n\n// Dates come from the caller, never from inside a render: a timestamp baked\n// into generated output makes every run a diff.\nconst STAMP = process.env.RUNGS_DATE ?? new Date().toISOString().slice(0, 10);\nconst HARNESSES: Harness[] = flags.has('--copilot')\n ? ['claude', 'copilot', 'agents-md']\n : (['claude', 'agents-md'] as Harness[]);\n\n// Both refusals run before dispatch, because either one means the argv the user typed is not the\n// argv any command would act on. Silently proceeding is what made the original failure so opaque.\nif (missingValue) {\n console.log(c.red(`\\n ${missingValue} expects a value \u2014 ${missingValue} module.param=value\\n`));\n process.exit(1);\n}\nif (strayOverride) {\n console.log(\n c.red(`\\n stray override: ${strayOverride}`) +\n c.dim(`\\n Nothing claimed it, so it would be read as a path or a module name.`) +\n c.dim(`\\n Did you mean: --set ${strayOverride}\\n`),\n );\n process.exit(1);\n}\n\nswitch (cmd) {\n case 'modules':\n process.exit(cmdModules(flags.has('--params')));\n case 'doctor':\n process.exit(cmdDoctor(args[0] ?? process.cwd(), flags.has('--explain')));\n case 'backlog': {\n if (args[0] !== 'archive') {\n console.log(c.red(`\\n unknown: rungs backlog ${args[0] ?? ''}`) + c.dim('\\n The only subcommand is `archive`.\\n'));\n process.exit(1);\n }\n process.exit(cmdBacklogArchive(resolve(args[1] ?? process.cwd()), flags.has('--dry-run')));\n }\n case 'check': {\n const tier = args[1] ?? (flags.has('--full') ? 'full' : flags.has('--fast') ? 'fast' : undefined);\n process.exit(cmdCheck(resolve(args[0] ?? process.cwd()), tier, STAMP));\n }\n case 'init': {\n const profile = args[1] ?? 'tracked';\n process.exit(cmdInit(resolve(args[0] ?? process.cwd()), profile, flags.has('--dry-run'), HARNESSES, STAMP));\n }\n case 'upgrade':\n process.exit(cmdUpgrade(resolve(args[0] ?? process.cwd()), flags.has('--apply')));\n case 'eject':\n process.exit(cmdEject(resolve(args[0] ?? process.cwd()), flags.has('--dry-run')));\n case 'setup': {\n // The path is `args[1]`, *after* the subcommand \u2014 so an omitted `git` put the\n // path into the subcommand slot, where it was discarded, and `setup` then\n // wrote git config into the current directory while reporting success about\n // the repo you named (F-027). `backlog` had refused an unknown subcommand\n // since it shipped; this one accepted anything and exited 0. The asymmetry\n // between the two subcommand-taking commands was the whole bug.\n if (args[0] !== 'git') {\n console.log(\n c.red(`\\n unknown: rungs setup ${args[0] ?? ''}`.trimEnd()) +\n c.dim('\\n The only subcommand is `git`, and the path comes after it: `rungs setup git [path]`.\\n'),\n );\n process.exit(1);\n }\n const r = setupGit(resolve(args[1] ?? process.cwd()), flags.has('--dry-run'));\n console.log(\n r.drivers.length\n ? `\\n installed ${r.drivers.length} merge driver(s): ${r.drivers.join(', ')}` +\n (r.rerere ? c.dim(' \u00B7 rerere on') : '') +\n c.dim('\\n Declared drivers were inert until now \u2014 a fresh clone needs this once.\\n')\n : c.dim('\\n no rungs merge drivers declared in .gitattributes\\n'),\n );\n process.exit(0);\n }\n case 'render':\n process.exit(cmdRender(resolve(args[0] ?? process.cwd()), HARNESSES, STAMP));\n case 'session': {\n if (args[0] !== 'start') {\n console.log(c.red(`\\n unknown: rungs session ${args[0] ?? ''}`.trimEnd()) + c.dim('\\n The only subcommand is `start`: `rungs session start <branch> [path]`.\\n'));\n process.exit(1);\n }\n process.exit(report(sessionStart(process.cwd(), args[1], args[2], flags.has('--dry-run'))));\n }\n case 'preflight':\n process.exit(report(preflight(resolve(args[0] ?? process.cwd()))));\n case 'land':\n process.exit(report(land(process.cwd(), args[0], landRunner, flags.has('--dry-run'))));\n case 'worktrees':\n process.exit(cmdWorktrees(resolve(args[0] ?? process.cwd())));\n case 'add': {\n const target = flags.has('--into') ? args[args.length - 1] : process.cwd();\n const names = flags.has('--into') ? args.slice(0, -1) : args;\n process.exit(cmdAdd(names, resolve(target), flags.has('--dry-run'), HARNESSES, STAMP));\n }\n default: {\n // Help is a success, and an unknown command is not. Both used to land here and exit on\n // `cmd ? 1 : 0`, which made `rungs --help` \u2014 a command that did exactly what was asked \u2014\n // report failure to anything checking the status (WI-004).\n const wantedHelp = cmd === undefined || cmd === 'help' || cmd === '--help' || cmd === '-h';\n if (!wantedHelp) console.log(c.red(`\\n unknown command: ${cmd}`));\n console.log(renderHelp());\n process.exit(wantedHelp ? 0 : 1);\n }\n}\n", "import { readdirSync, readFileSync, statSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { parse } from 'smol-toml';\nimport type { Manifest, ParamSpec } from './types.ts';\nimport { walk } from './glob.ts';\n\n/** Reads one module directory into a validated manifest. Throws on anything malformed. */\nexport function loadManifest(dir: string): Manifest {\n const raw = parse(readFileSync(join(dir, 'module.toml'), 'utf8')) as Record<string, any>;\n const m = raw.module ?? {};\n const name = m.name;\n if (!name) throw new Error(`${dir}: [module].name is required`);\n\n const manifest: Manifest = {\n name,\n version: m.version ?? '0.0.0',\n rung: m.rung ?? 0,\n summary: m.summary ?? '',\n requires: raw.requires?.modules ?? [],\n conflicts: raw.conflicts?.modules ?? [],\n params: (raw.params ?? {}) as Record<string, ParamSpec>,\n gates: raw.gates ?? [],\n detect: raw.detect ?? {},\n skills: raw.skills ?? {},\n provenance: raw.provenance,\n threshold: raw.threshold,\n dir,\n };\n\n // `[provenance]` is required and validated (ADR-0003). A module with no\n // traceable source is one somebody invented, and `doctor` cannot ask its\n // questions without the incident.\n const p = manifest.provenance;\n if (!p?.sources?.length) throw new Error(`${name}: [provenance].sources is required`);\n if (!p?.patterns?.length) throw new Error(`${name}: [provenance].patterns is required`);\n if (!p?.incident?.trim()) throw new Error(`${name}: [provenance].incident is required`);\n\n return manifest;\n}\n\nexport function loadAllModules(modulesRoot: string): Manifest[] {\n return readdirSync(modulesRoot, { withFileTypes: true })\n .filter((e) => e.isDirectory() && statSync(join(modulesRoot, e.name, 'module.toml'), { throwIfNoEntry: false }))\n .map((e) => loadManifest(join(modulesRoot, e.name)))\n .sort((a, b) => a.rung - b.rung || a.name.localeCompare(b.name));\n}\n\n/** Every `{{param}}` appearing in a module's files and path names. */\nexport function usedParams(dir: string): Set<string> {\n const used = new Set<string>();\n const add = (text: string) => {\n // `${{ \u2026 }}` is never a substitution: GitHub Actions expressions share the\n // delimiter, and without this the ci module corrupts its own workflow file.\n for (const match of text.matchAll(/(^|[^$])\\{\\{([a-z_.]+)\\}\\}/g)) used.add(match[2]);\n };\n for (const rel of walk(dir)) {\n add(rel);\n add(readFileSync(join(dir, rel), 'utf8'));\n }\n return used;\n}\n\nexport interface ManifestIssue {\n module: string;\n kind: 'dead-param' | 'undeclared-param' | 'dep-missing' | 'gate-no-table' | 'gate-no-why' | 'gate-no-applicability';\n detail: string;\n}\n\n/** The cross-module audit. Several findings were only visible with every module in hand. */\nexport function auditModules(mods: Manifest[]): ManifestIssue[] {\n const issues: ManifestIssue[] = [];\n const names = new Set(mods.map((m) => m.name));\n\n for (const mod of mods) {\n for (const dep of mod.requires) {\n if (!names.has(dep)) {\n issues.push({ module: mod.name, kind: 'dep-missing', detail: `requires unknown module '${dep}'` });\n }\n }\n\n const used = usedParams(mod.dir);\n for (const [param, spec] of Object.entries(mod.params)) {\n if (used.has(param) || spec.consumed_by) continue;\n issues.push({\n module: mod.name,\n kind: 'dead-param',\n detail: `'${param}' is declared, never substituted, and not marked consumed_by`,\n });\n }\n for (const u of used) {\n if (u.includes('.')) continue; // cross-module reference, e.g. backlog.root\n if (!(u in mod.params)) {\n issues.push({ module: mod.name, kind: 'undeclared-param', detail: `uses {{${u}}} but does not declare it` });\n }\n }\n\n for (const g of mod.gates) {\n if (g.kind === 'declared' && !g.table) {\n issues.push({ module: mod.name, kind: 'gate-no-table', detail: `gate '${g.id}' is declared with no table` });\n }\n // `doctor` quotes `why` back when a gate has never fired (ADR-0005 tier B),\n // so a gate without one cannot be asked about.\n if (!g.why?.trim()) {\n issues.push({ module: mod.name, kind: 'gate-no-why', detail: `gate '${g.id}' has no 'why'` });\n }\n // WI-052. `doctor --explain` will not run an undeclared gate against a repo\n // that is not ours, so an author who forgets this silently loses their gate\n // on exactly the repos the analysis exists for. Caught here, where the\n // module is written, rather than as a skip line nobody reads.\n if (g.kind === 'declared' && !g.applicability) {\n issues.push({\n module: mod.name,\n kind: 'gate-no-applicability',\n detail: `gate '${g.id}' does not declare applicability (repo-content | our-artifacts | our-schema)`,\n });\n }\n }\n }\n return issues;\n}\n", "import { readdirSync, statSync } from 'node:fs';\nimport { join, relative, sep } from 'node:path';\n\n/**\n * A small glob matcher: `**`, `*`, `?`, and `{a,b}` brace groups.\n *\n * Written rather than depended on so the semantics are ours. The only rule that\n * matters is the one ADR-0004 states: when a pattern is ambiguous it must fail\n * to match. A false negative creates something visible in git; a false positive\n * makes the CLI believe wrong things about a repo and act on them later.\n */\nexport function globToRegExp(pattern: string): RegExp {\n let out = '';\n for (let i = 0; i < pattern.length; i++) {\n const c = pattern[i];\n if (c === '*') {\n if (pattern[i + 1] === '*') {\n // `**/` consumes any number of segments, including none.\n if (pattern[i + 2] === '/') {\n out += '(?:[^/]+/)*';\n i += 2;\n } else {\n out += '.*';\n i += 1;\n }\n } else {\n out += '[^/]*';\n }\n } else if (c === '?') {\n out += '[^/]';\n } else if (c === '{') {\n const end = pattern.indexOf('}', i);\n if (end === -1) {\n out += '\\\\{';\n } else {\n const alts = pattern.slice(i + 1, end).split(',');\n out += `(?:${alts.map((a) => a.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')).join('|')})`;\n i = end;\n }\n } else if ('.+^$()|[]\\\\'.includes(c)) {\n out += `\\\\${c}`;\n } else {\n out += c;\n }\n }\n return new RegExp(`^${out}$`);\n}\n\nconst SKIP = new Set([\n '.git',\n 'node_modules',\n 'dist',\n 'build',\n 'out',\n 'bin',\n 'obj',\n '.vs',\n '.angular',\n '.next',\n 'coverage',\n 'TestResults',\n 'BenchmarkDotNet.Artifacts',\n]);\n\n/** Walk a repo once; callers match the resulting relative paths. */\nexport function walk(root: string, maxEntries = 200_000): string[] {\n const files: string[] = [];\n const stack = [root];\n while (stack.length && files.length < maxEntries) {\n const dir = stack.pop()!;\n let entries;\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch {\n continue;\n }\n for (const e of entries) {\n if (SKIP.has(e.name)) continue;\n const full = join(dir, e.name);\n if (e.isDirectory()) {\n stack.push(full);\n } else if (e.isFile()) {\n files.push(relative(root, full).split(sep).join('/'));\n }\n }\n }\n return files;\n}\n\nexport function matchAny(files: string[], pattern: string): string[] {\n const re = globToRegExp(pattern);\n return files.filter((f) => re.test(f));\n}\n\nexport function isDir(p: string): boolean {\n try {\n return statSync(p).isDirectory();\n } catch {\n return false;\n }\n}\n", "import { existsSync, readFileSync } from 'node:fs';\nimport { join } from 'node:path';\nimport type { DetectResult, Manifest } from './types.ts';\nimport { matchAny, walk } from './glob.ts';\nimport { contentHash, emittedFiles } from './add.ts';\nimport type { Params } from './substitute.ts';\n\nconst SAMPLE = 3;\n\n/**\n * ADR-0004. Presence is decided by `paths` and `markers` only; `infer` merely\n * *proposes* parameters, and never concludes presence \u2014 hexguard-templates has\n * 207 well-formed `FOUND-US-###` matches and no backlog, because those are spec\n * story ids.\n *\n * Signatures are biased toward false negatives throughout: a false negative\n * creates something visible in git, while a false positive makes the CLI\n * believe wrong things about a repo and act on that belief later.\n */\nexport function detect(mod: Manifest, repoRoot: string, files: string[], installed?: InstalledModule): DetectResult {\n const result: DetectResult = {\n module: mod.name,\n state: 'absent',\n matchedPaths: [],\n matchedMarkers: [],\n proposals: [],\n adoptable: [],\n };\n\n // A module the repo installed is answered from the record, not from\n // signatures. Signatures exist to recognise somebody *else's* structure;\n // running them over our own would report a healthy install as \"theirs\" and\n // lose the one thing the record knows and detection cannot \u2014 which files we\n // wrote, and whether they still say what we wrote.\n if (installed) {\n result.ours = ownedState(mod, repoRoot, installed);\n result.state = result.ours.diverged.length ? 'ours-diverged' : 'ours-current';\n return result;\n }\n\n for (const pattern of mod.detect.paths ?? []) {\n const hits = matchAny(files, pattern);\n if (hits.length) {\n result.matchedPaths.push({ pattern, count: hits.length, sample: hits.slice(0, SAMPLE) });\n }\n }\n\n const markers = mod.detect.markers ?? [];\n if (markers.length) {\n // Only files a marker could plausibly live in, and only ones we already\n // have a reason to read. Scanning a whole repo for a marker string is both\n // slow and a way to match prose that mentions one.\n //\n // `marker_paths` exists for the case where a file's *existence* is not\n // discriminating but its *content* is: nearly every repo has a\n // `.gitattributes`, and only one of the four declares a custom merge\n // driver in it \u2014 21 declarations against 0, 0, 0.\n const scanPatterns = mod.detect.marker_paths ?? result.matchedPaths.map((m) => m.pattern);\n const candidates = new Set(scanPatterns.flatMap((p) => matchAny(files, p)));\n for (const rel of candidates) {\n let text: string;\n try {\n text = readFileSync(join(repoRoot, rel), 'utf8');\n } catch {\n continue;\n }\n for (const marker of markers) {\n if (text.includes(marker) && !result.matchedMarkers.includes(marker)) {\n result.matchedMarkers.push(marker);\n }\n }\n }\n }\n\n for (const adopt of mod.detect.adopt_as ?? []) {\n const hits = (adopt.paths ?? []).flatMap((p) => matchAny(files, p));\n if (hits.length) {\n result.adoptable.push({ kind: adopt.kind, count: hits.length, sample: hits.slice(0, SAMPLE), note: adopt.note });\n }\n }\n\n // A paradigm is only consulted when nothing else matched. Checking it\n // unconditionally reported rift-forge's pulled design mirror as *both* an\n // external authority and an in-repo design system, on a theme.ts the pattern\n // was never meant to reach.\n if (result.matchedPaths.length === 0 && result.adoptable.length === 0) {\n for (const para of mod.detect.paradigm ?? []) {\n const matched = (para.paths ?? []).flatMap((p) => matchAny(files, p));\n if (matched.length) {\n result.paradigm = { id: para.id, note: para.note, compare: para.compare, matched: matched.slice(0, SAMPLE) };\n break;\n }\n }\n }\n\n // State. `ours-current` / `ours-diverged` require a rungs.toml recording a\n // prior install; a repo without one can only be absent, theirs, or paradigm.\n //\n // An `adopt_as` match is ADR-0004 state 4 \u2014 \"theirs, equivalent\": the\n // module's function exists in a shape we can map, even though our own\n // structure is absent. Treating it as absent hid the single highest-value\n // adoption in the catalogue, rift-forge's 82 registered gates.\n if (result.matchedPaths.length > 0 || result.adoptable.length > 0 || result.matchedMarkers.length > 0) {\n result.state = 'theirs';\n } else if (result.paradigm) {\n result.state = 'paradigm';\n } else {\n result.state = 'absent';\n }\n\n // Proposals run only once presence is established, and are reported as\n // proposals \u2014 never applied, never used to decide state.\n if (result.state === 'theirs') {\n result.proposals = infer(mod, repoRoot, files);\n }\n\n return result;\n}\n\nfunction infer(mod: Manifest, repoRoot: string, files: string[]) {\n const proposals: DetectResult['proposals'] = [];\n\n for (const rule of mod.detect.infer ?? []) {\n if (rule.paths) {\n // Directory-presence inference (e.g. which harnesses exist).\n const present = Object.entries(rule.paths)\n .filter(([, p]) => files.some((f) => f.startsWith(p.replace(/\\/$/, '/'))))\n .map(([key]) => key);\n if (present.length) {\n proposals.push({ param: rule.param, value: present.join(', '), evidence: 'directory present' });\n }\n continue;\n }\n if (!rule.pattern) continue;\n\n const scope = (rule.scope ?? ['**/*.md']).flatMap((p) => matchAny(files, p));\n const excluded = new Set((rule.exclude ?? []).flatMap((p) => matchAny(files, p)));\n const counts = new Map<string, number>();\n\n for (const rel of scope) {\n if (excluded.has(rel)) continue;\n let text: string;\n try {\n text = readFileSync(join(repoRoot, rel), 'utf8');\n } catch {\n continue;\n }\n for (const m of text.matchAll(new RegExp(rule.pattern, 'gm'))) {\n const key = m[1];\n if (key) counts.set(key, (counts.get(key) ?? 0) + 1);\n }\n }\n\n // An anchor wins outright over frequency. Counting raw occurrences made\n // `findings` propose the *backlog's* prefix, because a findings register is\n // full of citations to work items \u2014 more of them than of its own ids.\n // The register's own NEXT-ID marker settles it without judgement.\n if (rule.anchor) {\n const anchored = new Map<string, number>();\n for (const rel of scope) {\n if (excluded.has(rel)) continue;\n let text: string;\n try {\n text = readFileSync(join(repoRoot, rel), 'utf8');\n } catch {\n continue;\n }\n for (const m of text.matchAll(new RegExp(rule.anchor, 'gm'))) {\n if (m[1]) anchored.set(m[1], (anchored.get(m[1]) ?? 0) + 1);\n }\n }\n const [best] = [...anchored].sort((a, b) => b[1] - a[1]);\n if (best) {\n proposals.push({ param: rule.param, value: best[0], evidence: `anchored on ${rule.anchor_name ?? 'marker'}` });\n continue;\n }\n }\n\n const banned = new Set(rule.exclude_values ?? []);\n const ranked = [...counts].filter(([k]) => !banned.has(k)).sort((a, b) => b[1] - a[1]);\n const [top] = ranked;\n if (top && top[1] >= (rule.min ?? 1)) {\n proposals.push({\n param: rule.param,\n value: top[0],\n evidence: `${top[1]} matches${ranked.length > 1 ? ` (next: ${ranked[1][0]} at ${ranked[1][1]})` : ''}`,\n });\n }\n }\n return proposals;\n}\n\nexport function scanRepo(repoRoot: string): string[] {\n return walk(repoRoot);\n}\n\nexport interface InstalledModule {\n version: string;\n params?: Record<string, unknown>;\n hashes?: Record<string, string>;\n kept?: { files: string[] };\n skillsDir?: string;\n params_all?: Params;\n}\n\n/**\n * The state of files this repo installed from a module.\n *\n * Three comparisons, and each answers a different question:\n *\n * absent from disk \u2192 missing, an upgrade restores it\n * matches what we'd emit now \u2192 current\n * matches the recorded hash \u2192 stale; ours to replace on upgrade\n * matches neither \u2192 diverged; theirs, and never touched\n */\nexport function ownedState(mod: Manifest, repoRoot: string, installed: InstalledModule) {\n const params = installed.params_all ?? {};\n const emitted = emittedFiles(mod, params, installed.skillsDir ?? '.claude/skills');\n const kept = new Set(installed.kept?.files ?? []);\n const out = {\n version: installed.version,\n current: [] as string[],\n stale: [] as string[],\n diverged: [] as string[],\n missing: [] as string[],\n kept: [] as string[],\n };\n for (const [rel, wouldEmit] of emitted) {\n // A file that already existed at install was never ours. Calling it\n // \"diverged\" implies the user broke something they never touched.\n if (kept.has(rel)) {\n out.kept.push(rel);\n continue;\n }\n const full = join(repoRoot, rel);\n if (!existsSync(full)) {\n out.missing.push(rel);\n continue;\n }\n const onDisk = contentHash(readFileSync(full, 'utf8'));\n if (onDisk === contentHash(wouldEmit)) out.current.push(rel);\n else if (installed.hashes?.[rel] && onDisk === installed.hashes[rel]) out.stale.push(rel);\n else out.diverged.push(rel);\n }\n return out;\n}\n", "import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { createHash } from 'node:crypto';\nimport type { Manifest } from './types.ts';\nimport { matchAny, walk } from './glob.ts';\nimport { markers, mergeBlock, substitute, type Params } from './substitute.ts';\n\nexport interface AddAction {\n disposition: 'create' | 'skip-exists' | 'rule' | 'skill' | 'merge' | 'gate';\n target: string;\n note?: string;\n}\n\n/** Where a fragment file merges to. The name is the target, not a path. */\nconst FRAGMENT_TARGET: Record<string, string> = {\n 'AGENTS.md': 'AGENTS.md',\n gitignore: '.gitignore',\n gitattributes: '.gitattributes',\n};\n\n/**\n * Install one module. Disposition is decided by which subdirectory a file is\n * in \u2014 never by per-file configuration (ADR-0003), which is why this function\n * is a switch over five directory names and nothing else.\n *\n * Never overwrites an existing file. ADR-0004: `add` on existing structure\n * reports the delta; the dangerous operation is removed rather than guarded.\n */\nexport function addModule(\n mod: Manifest,\n repoRoot: string,\n params: Params,\n opts: { dryRun?: boolean; skillsDir?: string } = {},\n): AddAction[] {\n const actions: AddAction[] = [];\n const write = (rel: string, content: string, disposition: AddAction['disposition']) => {\n const full = join(repoRoot, rel);\n if (existsSync(full)) {\n actions.push({ disposition: 'skip-exists', target: rel, note: 'already present \u2014 left alone' });\n return;\n }\n actions.push({ disposition, target: rel });\n if (opts.dryRun) return;\n mkdirSync(dirname(full), { recursive: true });\n writeFileSync(full, content);\n };\n\n const sub = (text: string) => substitute(text, mod.name, params);\n const has = (d: string) => existsSync(join(mod.dir, d));\n\n if (has('files')) {\n const base = join(mod.dir, 'files');\n for (const rel of walk(base)) {\n write(sub(rel), sub(readFileSync(join(base, rel), 'utf8')), 'create');\n }\n }\n\n if (has('rules')) {\n const base = join(mod.dir, 'rules');\n for (const rel of walk(base)) {\n write(join('.ai', 'rules', rel).split('\\\\').join('/'), sub(readFileSync(join(base, rel), 'utf8')), 'rule');\n }\n }\n\n if (has('skills')) {\n const base = join(mod.dir, 'skills');\n const dir = opts.skillsDir ?? '.claude/skills';\n for (const rel of walk(base)) {\n // Through the same helper `emittedFiles` uses. These two paths both emit\n // skills and are easy to change apart \u2014 patching only `emittedFiles` for\n // F-019 left `add` still writing the un-extended file, so an install and\n // an upgrade would have produced different content for the same skill.\n write(`${dir}/${rel}`, withOptedInExtensions(mod, rel, sub(readFileSync(join(base, rel), 'utf8'))), 'skill');\n }\n }\n\n if (has('fragments')) {\n const base = join(mod.dir, 'fragments');\n for (const rel of walk(base)) {\n const target = FRAGMENT_TARGET[rel];\n if (!target) {\n actions.push({ disposition: 'merge', target: rel, note: 'unknown fragment target \u2014 skipped' });\n continue;\n }\n const full = join(repoRoot, target);\n const existing = existsSync(full) ? readFileSync(full, 'utf8') : '';\n const fragment = sub(readFileSync(join(base, rel), 'utf8'));\n const merged = mergeBlock(existing, fragment, mod.name);\n actions.push({\n disposition: 'merge',\n target,\n note: existing.includes(`rungs:begin ${mod.name}`) ? 'block replaced' : 'block appended',\n });\n if (!opts.dryRun) {\n mkdirSync(dirname(full), { recursive: true });\n writeFileSync(full, merged);\n }\n }\n }\n\n return actions;\n}\n\n/**\n * Gate registration is a **second phase**, run after every module's files exist.\n *\n * Done inside `addModule` it raced the `gates` module's own registry file:\n * whichever module merged an entry first created `.ai/gates.toml`, and the\n * owner then hit the never-overwrite rule and was skipped \u2014 leaving a registry\n * with entries and no `[runner]` block. Reordering the install did not fix it,\n * because `gates` depends on `instructions`, which itself ships gates. The\n * ordering was never the problem: **the owner of a shared file must create it\n * before anything merges into it, which is a phase, not a position.**\n */\nexport function registerGates(mods: Manifest[], repoRoot: string, dryRun = false, adopted: AdoptedGate[] = []): AddAction[] {\n const actions: AddAction[] = [];\n const registry = join(repoRoot, '.ai', 'gates.toml');\n\n // Adoption, in the only form ADR-0004 permits: the repo's existing validators\n // are registered as `command` gates so they gain the runner, the ledger and\n // attribution \u2014 **without a line of them being rewritten**. This is the claim\n // the whole product rests on, and it was missing: `add` created a registry of\n // rungs' own gates and left the repo's sixteen where they were.\n if (adopted.length) {\n const existing = existsSync(registry) ? readFileSync(registry, 'utf8') : '';\n const { begin, end } = markers('gates.toml', 'adopted', '1.0.0');\n const body = [\n begin,\n '# Registered from validators this repo already had. Their scripts are untouched and',\n '# stay yours; rungs only runs them and records what it observes.',\n ...adopted.map(\n (a) => `\\n[[gates]]\\nid = \"${a.id}\"\\nkind = \"command\"\\nmodule = \"adopted\"\\ntier = \"${a.tier}\"\\ncommand = \"${a.command}\"\\nwhy = \"\"\"Adopted from ${a.source}. Predates rungs and is owned by this repo.\"\"\"`,\n ),\n end,\n ].join('\\n');\n actions.push({ disposition: 'gate', target: '.ai/gates.toml', note: `adopted: ${adopted.length} entries` });\n if (!dryRun) {\n mkdirSync(dirname(registry), { recursive: true });\n writeFileSync(registry, mergeBlock(existing, body, 'adopted'));\n }\n }\n\n for (const mod of mods) {\n if (!mod.gates.length) continue;\n const existing = existsSync(registry) ? readFileSync(registry, 'utf8') : '';\n const { begin, end } = markers('gates.toml', mod.name, mod.version);\n const body = [begin, ...mod.gates.map(gateEntry(mod)), end].join('\\n');\n actions.push({ disposition: 'gate', target: '.ai/gates.toml', note: `${mod.name}: ${mod.gates.length} entries` });\n if (dryRun) continue;\n mkdirSync(dirname(registry), { recursive: true });\n writeFileSync(registry, mergeBlock(existing, body, mod.name));\n }\n return actions;\n}\n\nconst gateEntry = (mod: Manifest) => (g: Manifest['gates'][number]) => {\n const lines = ['', '[[gates]]', `id = \"${g.id}\"`, `kind = \"${g.kind}\"`, `module = \"${mod.name}\"`];\n if (g.engine) lines.push(`engine = \"${g.engine}\"`);\n if (g.table) lines.push(`table = \"${mod.name}/${g.table.replace(/^gates\\//, '')}\"`);\n if (g.command) lines.push(`command = \"${g.command}\"`);\n if (g.tier) lines.push(`tier = \"${g.tier}\"`);\n if (g.trigger) lines.push(`trigger = \"${g.trigger}\"`);\n if (g.matcher) lines.push(`matcher = \"${g.matcher}\"`);\n // `why` is carried into the repo because ADR-0005 tier B quotes it back when\n // a gate has never fired. A gate whose reason lives only in this CLI cannot\n // be asked about by a repo that has it installed.\n if (g.why) lines.push(`why = \"\"\"${g.why.trim()}\"\"\"`);\n return lines.join('\\n');\n};\n\n/** Dependency order, refusing anything unmet \u2014 naming the incident (ADR-0003). */\n/**\n * Every module in `order` that cannot be installed because one of the modules\n * it needs \u2014 or itself \u2014 is a different paradigm.\n *\n * A refusal has to travel *up* the dependency edges, not just stop at the\n * module that matched. `add audit` pulls `findings` which pulls `backlog`; if\n * the repo's work lives in an issue tracker, refusing `backlog` and installing\n * `audit` anyway would ship an audit procedure whose findings have nowhere to\n * close \u2014 which is the exact incident (268 audit documents, no register) that\n * made `audit \u2192 findings \u2192 backlog` a declared dependency in the first place.\n */\nexport function blockedByParadigm(order: Manifest[], paradigms: ReadonlySet<string>): Map<string, string> {\n const blocked = new Map<string, string>();\n // `order` is already dependency-first, so one forward pass settles it.\n for (const mod of order) {\n if (paradigms.has(mod.name)) {\n blocked.set(mod.name, mod.name);\n continue;\n }\n const dep = mod.requires.find((d) => blocked.has(d));\n if (dep) blocked.set(mod.name, blocked.get(dep)!);\n }\n return blocked;\n}\n\nexport function resolveInstallOrder(requested: string[], all: Manifest[]): { order: Manifest[]; missing: string[] } {\n const byName = new Map(all.map((m) => [m.name, m]));\n const order: Manifest[] = [];\n const missing: string[] = [];\n const seen = new Set<string>();\n const visit = (name: string) => {\n if (seen.has(name)) return;\n const mod = byName.get(name);\n if (!mod) {\n missing.push(name);\n return;\n }\n seen.add(name);\n for (const dep of mod.requires) visit(dep);\n order.push(mod);\n };\n // A module's gates are inert without the runner that executes them. Installing\n // `backlog` alone produced a `.ai/gates.toml` holding three entries and no\n // `[runner]` block \u2014 a registry nothing reads. Rather than making every\n // gate-shipping module declare the dependency (and `instructions`, which ships\n // gates and is what `gates` itself requires, could not), the runner is pulled\n // in whenever anything registers with it.\n //\n // It is visited **first**, not appended: installed last it arrived after other\n // modules had already merged entries into the registry, so its own file \u2014 the\n // one carrying `[runner]` \u2014 hit the never-overwrite rule and was skipped. The\n // owner of a shared file has to create it before anyone merges into it.\n const closure = new Set<string>();\n const collect = (n: string) => {\n if (closure.has(n)) return;\n const m = byName.get(n);\n if (!m) return;\n closure.add(n);\n m.requires.forEach(collect);\n };\n requested.forEach(collect);\n if ([...closure].some((n) => byName.get(n)!.gates.length) && byName.has('gates')) {\n visit('gates');\n }\n\n for (const r of requested) visit(r);\n return { order, missing };\n}\n\n/**\n * Content hash of what a module emitted, recorded at install.\n *\n * Without it `upgrade` cannot tell a file the user edited from one an older\n * module version wrote \u2014 and those want opposite treatment: the first is a\n * decision to respect, the second is the thing upgrade exists to replace.\n * It is also what makes ADR-0004's `ours-current` and `ours-diverged` states\n * decidable at all.\n */\nexport const contentHash = (s: string) => createHash('sha256').update(s.replace(/\\r\\n/g, '\\n')).digest('hex').slice(0, 12);\n\n/**\n * Files a module owns **outright** \u2014 not the shared ones it merges into.\n *\n * `AGENTS.md` and `.ai/gates.toml` are co-owned: a module creates them and then\n * every other module merges a block in, so their content differs from what any\n * single module emitted the moment the second module installs. Hashing them\n * reported both as diverged on a completely untouched repo. A file carrying\n * managed blocks is never whole-file upgraded \u2014 its **blocks** are, through the\n * merge path.\n */\nconst SHARED = new Set(['AGENTS.md', 'CLAUDE.md', '.gitignore', '.gitattributes', '.ai/gates.toml']);\n\n/**\n * Add the harness extensions a module opted this skill into.\n *\n * F-019. `[skills.work-item] extensions = { disable-model-invocation = true }`\n * was declared in the `backlog` manifest, documented in `modules/README.md`, and\n * **implemented at no layer**: `grep -n extensions src/*.ts` returned nothing, so\n * the key never reached the emitted `SKILL.md`, and the gate that is supposed to\n * police it could not see the opt-in either. `work-item` creates branches and\n * merges, and the manifest's stated reason for opting it out of model invocation\n * had been inert since it was written.\n *\n * Injected here rather than written into the source skill because that is the\n * point of the opt-in: the file stays spec-pure and portable\n * ([ADR-0001](../docs/decisions/ADR-0001-multi-harness-rendering.md)), and the\n * extension \u2014 with its portability cost \u2014 stays attached to the module's\n * decision to take it.\n */\nfunction withOptedInExtensions(mod: Manifest, rel: string, content: string): string {\n const name = rel.split(/[\\\\/]/)[0];\n const extensions = mod.skills?.[name]?.extensions;\n if (!extensions || !Object.keys(extensions).length) return content;\n\n const m = content.match(/^---\\n([\\s\\S]*?)\\n---/);\n if (!m) return content; // no frontmatter to extend; `skills-spec-pure` reports it\n const added = Object.entries(extensions)\n .filter(([k]) => !new RegExp(`^${k}:`, 'm').test(m[1]))\n .map(([k, v]) => `${k}: ${v}`);\n if (!added.length) return content;\n return content.replace(/^---\\n[\\s\\S]*?\\n---/, `---\\n${m[1]}\\n${added.join('\\n')}\\n---`);\n}\n\nexport function emittedFiles(mod: Manifest, params: Params, skillsDir = '.claude/skills'): Map<string, string> {\n const out = new Map<string, string>();\n const sub = (t: string) => substitute(t, mod.name, params);\n for (const [dir, prefix] of [\n ['files', ''],\n ['rules', '.ai/rules/'],\n ['skills', `${skillsDir}/`],\n ] as const) {\n const base = join(mod.dir, dir);\n if (!existsSync(base)) continue;\n for (const rel of walk(base)) {\n const target = sub(prefix + rel).split('\\\\').join('/');\n if (SHARED.has(target)) continue;\n let content = sub(readFileSync(join(base, rel), 'utf8'));\n if (dir === 'skills') content = withOptedInExtensions(mod, rel, content);\n out.set(target, content);\n }\n }\n return out;\n}\n\nexport function writeInstallRecord(\n repoRoot: string,\n mods: Manifest[],\n params: Params,\n harnesses: string[],\n stamp: string,\n skillsDir = '.claude/skills',\n /** Per module, the files rungs actually created \u2014 as opposed to kept. */\n wroteByModule?: Map<string, Set<string>>,\n) {\n const lines = [\n '# Installed by `rungs`. This is a record of what was written, not a control panel:',\n '# editing a parameter here does not rewrite a file that already exists. `rungs render`',\n '# re-emits path-scoped rules from `.ai/rules/`, and `rungs upgrade --apply` replaces',\n '# module files you have not edited \u2014 neither re-substitutes parameters. AGENTS.md,',\n '# CLAUDE.md, .gitignore, .gitattributes and .ai/gates.toml are shared between modules,',\n '# so only their `rungs:begin`/`rungs:end` blocks are ever updated; anything outside a',\n '# block, including the entry document\\'s title, is yours to edit directly.',\n '#',\n '# Hashes are what rungs emitted; a file whose hash no longer matches is a',\n '# divergence rungs reports and never overwrites.',\n '',\n '[repo]',\n `harnesses = ${JSON.stringify(harnesses)}`,\n `installed = \"${stamp}\"`,\n '',\n ];\n for (const m of mods) {\n lines.push(`[modules.${m.name}]`, `version = \"${m.version}\"`, 'state = \"managed\"');\n const p = params[m.name] ?? {};\n if (Object.keys(p).length) {\n lines.push(`params = { ${Object.entries(p).map(([k, v]) => `${k} = ${JSON.stringify(v ?? '')}`).join(', ')} }`);\n }\n // Only files rungs actually **wrote** get a hash. A file that already\n // existed was kept, and hashing it with our content would later read as a\n // divergence the user caused \u2014 implying they broke something they never\n // touched. Kept files are listed separately and stay theirs forever.\n const emitted = emittedFiles(m, params, skillsDir);\n const created = [...emitted].filter(([rel]) => (wroteByModule?.get(m.name)?.has(rel) ?? existsSync(join(repoRoot, rel))));\n const kept = [...emitted].filter(([rel]) => !created.some(([c]) => c === rel) && existsSync(join(repoRoot, rel)));\n if (created.length) {\n lines.push(`[modules.${m.name}.hashes]`);\n for (const [rel, content] of created) lines.push(`\"${rel}\" = \"${contentHash(content)}\"`);\n }\n if (kept.length) {\n lines.push('', `[modules.${m.name}]`.replace(']', '.kept]'));\n lines.push(`files = ${JSON.stringify(kept.map(([rel]) => rel))}`);\n }\n lines.push('');\n }\n writeFileSync(join(repoRoot, '.ai', 'rungs.toml'), lines.join('\\n'));\n}\n\nexport interface AdoptedGate {\n id: string;\n command: string;\n tier: string;\n source: string;\n}\n\n/**\n * Turn detected `adopt_as` matches into `command` gate entries.\n *\n * The interpreter is chosen from the extension, and an unknown one is skipped\n * rather than guessed at \u2014 a registry entry that cannot run is worse than one\n * that is absent, because it reports as a failure the owner did not cause.\n */\nexport function adoptableGates(files: string[], patterns: string[], repoRoot: string): AdoptedGate[] {\n const runner: Record<string, string> = { '.mjs': 'node', '.js': 'node', '.ps1': 'pwsh -File', '.sh': 'bash' };\n const out: AdoptedGate[] = [];\n for (const pattern of patterns) {\n for (const rel of matchAny(files, pattern)) {\n const ext = rel.slice(rel.lastIndexOf('.'));\n const exec = runner[ext];\n if (!exec) continue;\n out.push({\n id: `adopted-${rel.split('/').pop()!.replace(/\\.[^.]+$/, '')}`,\n command: `${exec} ${rel}`,\n tier: 'fast',\n source: rel,\n });\n }\n }\n return out;\n}\n", "import { basename, resolve } from 'node:path';\nimport type { Manifest } from './types.ts';\n\nexport type Params = Record<string, Record<string, unknown>>;\n\n/**\n * `{{param}}` substitution, in file contents and in path segments. No\n * conditionals, no loops \u2014 ADR-0003. A module that needs a conditional is two\n * modules, or reaches file content through a managed block.\n *\n * `${{ \u2026 }}` is never substituted: GitHub Actions expressions share the\n * delimiter, and without the passthrough the `ci` module corrupts its own\n * workflow file at install \u2014 a broken file rather than an error.\n */\nexport function substitute(text: string, module: string, params: Params): string {\n return text.replace(/(^|[^$])\\{\\{([a-z_.]+)\\}\\}/g, (whole, lead: string, ref: string) => {\n const [a, b] = ref.includes('.') ? ref.split('.') : [module, ref];\n const value = params[a]?.[b];\n if (value === undefined) return whole; // leave it visible rather than emitting an empty string\n return lead + format(value);\n });\n}\n\nfunction format(v: unknown): string {\n if (Array.isArray(v)) return `[${v.map((x) => JSON.stringify(x)).join(', ')}]`;\n if (typeof v === 'boolean' || typeof v === 'number') return String(v);\n return String(v);\n}\n\n/**\n * Facts about the target repository, addressable from a default as `{{repo.<key>}}`.\n *\n * `repo` is a **reserved namespace, not a module**, which is what keeps it clear of\n * `modules/README.md` rule 9b \u2014 referencing a module you have not declared is an undeclared\n * coupling, but every module already sits in a repository, so there is nothing to declare.\n *\n * Deliberately one key. `git_remote` and `branch` were considered and left out: nothing consumes\n * them, and rule 9e is about the knob wired to nothing that stays invisible until someone compares\n * every module at once.\n */\nfunction repoFacts(repoRoot?: string): Record<string, unknown> {\n return repoRoot ? { dirname: basename(resolve(repoRoot)) } : {};\n}\n\n/**\n * Defaults from every manifest, with explicit overrides applied on top.\n *\n * `repoRoot` is optional only so a caller with no repository in hand can still read defaults. When\n * it is absent `{{repo.dirname}}` does not resolve, and `substitute` leaves the token visible\n * rather than emitting an empty string \u2014 the same bias as every other unresolved reference, and\n * the reason a missing root shows up as a wrong-looking file instead of a silently blank heading.\n */\nexport function resolveParams(mods: Manifest[], overrides: Params = {}, repoRoot?: string): Params {\n const out: Params = { repo: repoFacts(repoRoot) };\n for (const m of mods) {\n out[m.name] = {};\n for (const [k, spec] of Object.entries(m.params)) out[m.name][k] = spec.default;\n }\n\n // **Overrides go on before cross-module references resolve.** They were\n // applied last, which meant a default referencing another module's parameter\n // had already baked in that module's *default* \u2014 so installing into hexguard\n // with `--set backlog.root=.ai/backlog` put the findings register at\n // `docs/.ai/backlog/FINDINGS.md` and left every link to it pointing at\n // `docs/backlog/FINDINGS.md`. The gate caught it on the first real install;\n // nothing in a scratch repo could have, because nothing there overrides.\n for (const [mod, vals] of Object.entries(overrides)) {\n out[mod] = { ...(out[mod] ?? {}), ...vals };\n }\n\n // A default may reference another module's parameter, e.g. findings' register\n // living at `docs/{{backlog.root}}/FINDINGS.md`. One level only \u2014 a chain\n // would be a template language arriving through the back door.\n for (const m of mods) {\n for (const [k, v] of Object.entries(out[m.name])) {\n if (typeof v === 'string' && v.includes('{{')) out[m.name][k] = substitute(v, m.name, out);\n }\n }\n return out;\n}\n\n/** Comment syntax for a managed block, chosen by the target file. */\nexport function markers(targetPath: string, module: string, version: string) {\n const hash = /\\.(toml|ya?ml|gitignore|gitattributes|sh|ps1|conf|properties)$|(^|\\/)\\.(gitignore|gitattributes)$/.test(\n targetPath,\n );\n return hash\n ? { begin: `# rungs:begin ${module}@${version}`, end: `# rungs:end ${module}` }\n : { begin: `<!-- rungs:begin ${module}@${version} -->`, end: `<!-- rungs:end ${module} -->` };\n}\n\n/**\n * Replace an existing managed block, or append one. Content outside every block\n * is the user's and is never touched \u2014 that is what makes the upgrade story\n * mechanical and divergence a decision rather than an error.\n */\nexport function mergeBlock(existing: string, fragment: string, module: string): string {\n const beginRe = new RegExp(`^[ \\\\t]*(?:<!--|#)\\\\s*rungs:begin ${module}(?:@[\\\\w.\\\\-]+)?\\\\s*(?:-->)?[ \\\\t]*$`, 'm');\n const endRe = new RegExp(`^[ \\\\t]*(?:<!--|#)\\\\s*rungs:end ${module}\\\\s*(?:-->)?[ \\\\t]*$`, 'm');\n const b = existing.match(beginRe);\n const e = existing.match(endRe);\n if (b && e && b.index !== undefined && e.index !== undefined && e.index > b.index) {\n const before = existing.slice(0, b.index);\n const after = existing.slice(e.index + e[0].length);\n return `${before}${fragment.trim()}${after}`;\n }\n const sep = existing.endsWith('\\n\\n') ? '' : existing.endsWith('\\n') ? '\\n' : '\\n\\n';\n return `${existing}${sep}${fragment.trim()}\\n`;\n}\n", "import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { walk } from './glob.ts';\n\nexport type Harness = 'claude' | 'copilot' | 'cursor' | 'agents-md';\n\nexport interface Rule {\n file: string;\n description?: string;\n paths: string[];\n enforcement?: string;\n body: string;\n}\n\nexport interface RenderEntry {\n rule: string;\n harness: Harness;\n target?: string;\n degraded?: string;\n dropped?: string[];\n}\n\nconst DO_NOT_EDIT = (source: string) =>\n `Generated by \\`rungs render\\` from ${source}. Do not edit \u2014 your changes are overwritten.`;\n\n/** Parse `.ai/rules/*.md`: the neutral source ADR-0001 renders from. */\nexport function readRules(repoRoot: string): Rule[] {\n const dir = join(repoRoot, '.ai', 'rules');\n const rules: Rule[] = [];\n let files: string[];\n try {\n files = walk(dir).filter((f) => f.endsWith('.md') && f !== 'README.md');\n } catch {\n return rules;\n }\n for (const rel of files) {\n const raw = readFileSync(join(dir, rel), 'utf8');\n const m = raw.match(/^---\\n([\\s\\S]*?)\\n---\\n([\\s\\S]*)$/);\n if (!m) continue;\n const [, fm, body] = m;\n rules.push({\n file: rel,\n description: scalar(fm, 'description'),\n paths: list(fm, 'paths'),\n enforcement: scalar(fm, 'enforcement'),\n body: body.trim(),\n });\n }\n return rules;\n}\n\nfunction scalar(fm: string, key: string): string | undefined {\n const folded = fm.match(new RegExp(`^${key}:\\\\s*>-?\\\\s*\\\\n([\\\\s\\\\S]*?)(?=\\\\n\\\\S|$)`, 'm'));\n if (folded) return folded[1].split('\\n').map((l) => l.trim()).filter(Boolean).join(' ');\n const plain = fm.match(new RegExp(`^${key}:\\\\s*(.+)$`, 'm'));\n return plain?.[1].trim().replace(/^[\"']|[\"']$/g, '');\n}\n\nfunction list(fm: string, key: string): string[] {\n const block = fm.match(new RegExp(`^${key}:\\\\s*\\\\n((?:\\\\s*-\\\\s*.+\\\\n?)+)`, 'm'));\n if (!block) return [];\n return [...block[1].matchAll(/^\\s*-\\s*(.+)$/gm)].map((m) => m[1].trim().replace(/^[\"']|[\"']$/g, ''));\n}\n\n/**\n * Emit one rule into one harness's dialect. Full bodies, never pointers: a\n * wrapper that references a shared file relies on the harness following the\n * reference, and only some do. A rule that does not load is worth nothing.\n */\nexport function renderRule(rule: Rule, harness: Harness): { target: string; content: string; dropped: string[] } | { degraded: string } {\n const stem = rule.file.replace(/\\.md$/, '');\n const source = `.ai/rules/${rule.file}`;\n const dropped: string[] = [];\n\n if (harness === 'claude') {\n // No description field in a Claude rule; the routing is done by `paths`.\n if (rule.description) dropped.push('description');\n const fm = rule.paths.length ? `paths:\\n${rule.paths.map((p) => ` - \"${p}\"`).join('\\n')}\\n` : '';\n return {\n target: `.claude/rules/${stem}.md`,\n content: `---\\n${fm}---\\n\\n<!-- ${DO_NOT_EDIT(source)} -->\\n\\n${rule.body}\\n`,\n dropped,\n };\n }\n\n if (harness === 'copilot') {\n const applyTo = rule.paths.length ? rule.paths.join(', ') : '**/*';\n const desc = rule.description ? `description: '${rule.description.replace(/'/g, \"''\")}'\\n` : '';\n return {\n target: `.github/instructions/${stem}.instructions.md`,\n content: `---\\n${desc}applyTo: '${applyTo}'\\n---\\n\\n<!-- ${DO_NOT_EDIT(source)} -->\\n\\n${rule.body}\\n`,\n dropped,\n };\n }\n\n if (harness === 'cursor') {\n // `.mdc` is required \u2014 a plain .md in .cursor/rules is ignored entirely.\n const desc = rule.description ? `description: ${rule.description}\\n` : '';\n const globs = rule.paths.length ? `globs: ${rule.paths.join(',')}\\n` : '';\n return {\n target: `.cursor/rules/${stem}.mdc`,\n content: `---\\n${desc}${globs}alwaysApply: ${rule.paths.length === 0}\\n---\\n\\n<!-- ${DO_NOT_EDIT(source)} -->\\n\\n${rule.body}\\n`,\n dropped,\n };\n }\n\n // AGENTS.md-only harnesses have no glob scoping at all. Degrade explicitly\n // and report it \u2014 never drop a rule silently.\n const prefix = commonDirPrefix(rule.paths);\n if (prefix) {\n return {\n target: `${prefix}/AGENTS.md`,\n content: `<!-- ${DO_NOT_EDIT(source)} -->\\n\\n${rule.body}\\n`,\n dropped: ['description', 'paths (directory-scoped instead of glob)'],\n };\n }\n return {\n degraded: `routing-only: globs do not share a directory prefix, so root AGENTS.md gets a pointer to ${source}`,\n };\n}\n\nfunction commonDirPrefix(paths: string[]): string | null {\n if (!paths.length) return null;\n const dirs = paths.map((p) => p.split('/').filter((s) => !s.includes('*')).join('/')).filter(Boolean);\n if (dirs.length !== paths.length) return null;\n const first = dirs[0];\n return dirs.every((d) => d === first) && first.includes('/') ? first : null;\n}\n\nexport function render(repoRoot: string, harnesses: Harness[]): RenderEntry[] {\n const rules = readRules(repoRoot);\n const entries: RenderEntry[] = [];\n const routingOnly: Rule[] = [];\n\n for (const rule of rules) {\n for (const harness of harnesses) {\n const out = renderRule(rule, harness);\n if ('degraded' in out) {\n entries.push({ rule: rule.file, harness, degraded: out.degraded });\n if (harness === 'agents-md') routingOnly.push(rule);\n continue;\n }\n const full = join(repoRoot, out.target);\n mkdirSync(dirname(full), { recursive: true });\n writeFileSync(full, out.content);\n entries.push({ rule: rule.file, harness, target: out.target, dropped: out.dropped });\n }\n }\n\n // The report said root AGENTS.md \"gets a pointer\" and nothing wrote one \u2014 a\n // degradation notice that was itself a silent drop, in the function whose\n // whole job is not to have those. Written now, as a managed block.\n writeRoutingBlock(repoRoot, routingOnly, harnesses);\n return entries;\n}\n\nfunction writeRoutingBlock(repoRoot: string, rules: Rule[], harnesses: Harness[]) {\n if (!harnesses.includes('agents-md')) return;\n const target = join(repoRoot, 'AGENTS.md');\n if (!existsSync(target)) return;\n const begin = '<!-- rungs:begin rules-routing -->';\n const end = '<!-- rungs:end rules-routing -->';\n\n const body = rules.length\n ? [\n begin,\n '## Rules for specific paths',\n '',\n 'This harness has no glob scoping, so these load only if you open them. **Read the one that',\n 'matches what you are editing before editing broadly.**',\n '',\n ...rules.map((r) => `- \\`${r.paths.join('\\`, \\`')}\\` \u2192 [\\`.ai/rules/${r.file}\\`](.ai/rules/${r.file})`),\n end,\n ].join('\\n')\n : '';\n\n const existing = readFileSync(target, 'utf8');\n const beginRe = /^[ \\t]*<!--\\s*rungs:begin rules-routing\\s*-->[ \\t]*$/m;\n const endRe = /^[ \\t]*<!--\\s*rungs:end rules-routing\\s*-->[ \\t]*$/m;\n const b = existing.match(beginRe);\n const e = existing.match(endRe);\n if (b && e && b.index !== undefined && e.index !== undefined) {\n const next = existing.slice(0, b.index) + body.trim() + existing.slice(e.index + e[0].length);\n writeFileSync(target, body ? next : next.replace(/\\n{3,}/g, '\\n\\n'));\n return;\n }\n if (body) writeFileSync(target, `${existing.replace(/\\n+$/, '\\n')}\\n${body}\\n`);\n}\n\n/**\n * ADR-0001: a render that quietly dropped a rule reads identically to one that\n * had nothing to drop, so every degradation lands here.\n */\nexport function writeReport(repoRoot: string, entries: RenderEntry[], harnesses: Harness[], stamp: string): string {\n const lines = [\n '# Render report',\n '',\n `> Generated by \\`rungs render\\` on ${stamp}. Do not edit.`,\n '',\n `Harnesses: ${harnesses.join(', ')}`,\n '',\n '| Rule | Harness | Emitted | Dropped / degraded |',\n '| --- | --- | --- | --- |',\n ];\n for (const e of entries) {\n const lost = e.degraded ?? (e.dropped?.length ? e.dropped.join(', ') : '\u2014');\n lines.push(`| \\`${e.rule}\\` | ${e.harness} | ${e.target ? `\\`${e.target}\\`` : '**not emitted**'} | ${lost} |`);\n }\n const degraded = entries.filter((e) => e.degraded).length;\n const lossy = entries.filter((e) => e.dropped?.length).length;\n lines.push(\n '',\n `${entries.length} renderings \u00B7 ${lossy} lost a field \u00B7 ${degraded} degraded.`,\n '',\n 'A field listed as dropped is one the target harness has no way to express. It is recorded',\n 'here rather than silently discarded, so a repo can see what its harness choice costs it.',\n '',\n );\n const content = lines.join('\\n');\n writeFileSync(join(repoRoot, '.ai', 'render-report.md'), content);\n return content;\n}\n", "import { appendFileSync, existsSync, readFileSync } from 'node:fs';\nimport { execSync } from 'node:child_process';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { parse } from 'smol-toml';\nimport { ENGINES, isImplemented, type Finding } from './engines.ts';\nimport { walk } from './glob.ts';\nimport { resolveParams, substitute, type Params } from './substitute.ts';\nimport { loadAllModules } from './manifest.ts';\n\nconst MODULES = join(dirname(fileURLToPath(import.meta.url)), '..', 'modules');\n\nexport type Status = 'pass' | 'fail' | 'unimplemented' | 'error';\n\nexport interface GateRun {\n id: string;\n module?: string;\n kind: string;\n engine?: string;\n tier: string;\n status: Status;\n ms: number;\n examined: number;\n findings: Finding[];\n why?: string;\n}\n\ninterface RegistryGate {\n id: string;\n kind: string;\n module?: string;\n engine?: string;\n table?: string;\n command?: string;\n tier?: string;\n trigger?: string;\n why?: string;\n}\n\nexport function loadRegistry(repoRoot: string): { runner: any; gates: RegistryGate[] } {\n const path = join(repoRoot, '.ai', 'gates.toml');\n if (!existsSync(path)) return { runner: {}, gates: [] };\n const raw = parse(readFileSync(path, 'utf8')) as any;\n return { runner: raw.runner ?? {}, gates: raw.gates ?? [] };\n}\n\n/**\n * ADR-0008: a tier is an ordered **level**, not a tag. `[runner] tiers` declares\n * the order, and asking for one runs every gate at that level or below it.\n *\n * This was string equality, so `full` selected only gates labelled `full` \u2014 zero\n * of them on a registry where everything is `fast`, which is this repo. The run\n * then reported no gates and exited as though the release had been gated, and\n * `cut-release` told every consumer to gate on exactly that command (F-020).\n */\nexport function tierSelects(runnerTiers: string[], requested: string, gateTier?: string): boolean {\n if (!gateTier) return true; // untiered gates run in every tier\n const at = runnerTiers.indexOf(requested);\n const of = runnerTiers.indexOf(gateTier);\n // An undeclared tier on either side cannot be ordered. Fall back to equality\n // rather than guessing a position \u2014 silently including it would be worse.\n if (at < 0 || of < 0) return gateTier === requested;\n return of <= at;\n}\n\n/**\n * No parameter properties: Node's strip-only TypeScript mode rejects them, and\n * `dist/` is built from these sources for a runtime that has no compiler. The\n * same constraint is what v0.1.1 shipped broken (ERR_UNSUPPORTED_NODE_MODULES_\n * TYPE_STRIPPING), so it is worth the four extra lines.\n */\nexport class UnknownTierError extends Error {\n requested: string;\n declared: string[];\n constructor(requested: string, declared: string[]) {\n super(`unknown tier \"${requested}\"`);\n this.requested = requested;\n this.declared = declared;\n }\n}\n\n/**\n * `only` narrows the run to named gate ids. Attribution needs it: after a merged\n * tree goes red, `land` re-runs **just the failing gates** against the merge base\n * to decide whether they were already red. Re-running all of them would give the\n * same verdict and cost a second full pass for gates nobody asked about.\n */\nexport function runGates(repoRoot: string, tier?: string, now = () => Date.now(), only?: ReadonlySet<string>): GateRun[] {\n const { runner, gates } = loadRegistry(repoRoot);\n const runnerTiers: string[] = Array.isArray(runner?.tiers) ? runner.tiers : [];\n // A tier nobody declared selects nothing, and \"selected nothing\" is\n // indistinguishable from \"everything passed\" at the exit code. Refuse it here\n // rather than let a typo read as a green release gate.\n if (tier && runnerTiers.length && !runnerTiers.includes(tier)) {\n throw new UnknownTierError(tier, runnerTiers);\n }\n const files = walk(repoRoot);\n const runs: GateRun[] = [];\n\n for (const g of gates) {\n // A hook fires on a tool call, not in the runner. Skipping it here is\n // correct; counting it as a pass would not be.\n if (g.trigger) continue;\n if (only && !only.has(g.id)) continue;\n if (tier && !tierSelects(runnerTiers, tier, g.tier)) continue;\n\n const started = now();\n let status: Status = 'pass';\n let findings: Finding[] = [];\n let examined = 0;\n\n if (g.kind === 'command' && g.command) {\n try {\n execSync(g.command, { cwd: repoRoot, stdio: 'pipe' });\n } catch (e: any) {\n status = 'fail';\n findings = [{ message: String(e.stderr ?? e.stdout ?? e.message).trim().split('\\n').slice(-3).join(' ') }];\n }\n } else if (!g.engine || !isImplemented(g.engine)) {\n // Never green. An engine named in a table and missing from the CLI is an\n // unknown, and a registry reporting green because most of its gates do\n // nothing is the worst failure this tool could have.\n status = 'unimplemented';\n findings = [{ message: `engine '${g.engine ?? '(none)'}' is not implemented` }];\n } else {\n const table = loadTable(g.table, repoRoot);\n if (!table) {\n status = 'error';\n findings = [{ message: `table '${g.table}' not found` }];\n } else {\n try {\n const key = tableKey(g.engine);\n let section = table[key] ?? table;\n // An array table holds one entry per gate; select by trailing id.\n if (Array.isArray(section) && section.some((s: any) => s?.id)) {\n const mine = section.filter((s: any) => !s.id || g.id.includes(s.id));\n if (mine.length) section = mine;\n }\n const r = ENGINES[g.engine](section, repoRoot, files);\n findings = r.findings;\n examined = r.examined;\n status = r.findings.length ? 'fail' : 'pass';\n } catch (e: any) {\n status = 'error';\n findings = [{ message: e.message }];\n }\n }\n }\n\n runs.push({\n id: g.id,\n module: g.module,\n kind: g.kind,\n engine: g.engine,\n tier: g.tier ?? 'fast',\n status,\n ms: now() - started,\n examined,\n findings,\n why: g.why,\n });\n }\n return runs;\n}\n\n/**\n * A table lives in the CLI's module set, not in the repo (ADR-0002) \u2014 but it is\n * authored with `{{param}}` placeholders, so it is **not valid TOML until\n * substituted**: `max_lines = {{core_budget}}` parses as nothing.\n *\n * Found by running the runner, which reported `table not found` for a file\n * plainly on disk. Tables are substituted against the repo's own installed\n * parameters before parsing \u2014 which is also what makes a gate honour the\n * prefix, root and budget that repo actually chose.\n */\nexport function loadTable(ref: string | undefined, repoRoot: string): any | null {\n if (!ref) return null;\n const [mod, file] = ref.split('/');\n const path = join(MODULES, mod, 'gates', file);\n if (!existsSync(path)) return null;\n try {\n return parse(substitute(readFileSync(path, 'utf8'), mod, installedParams(repoRoot)));\n } catch {\n return null;\n }\n}\n\nlet paramCache: { root: string; params: Params } | null = null;\n\n/** Parameters as the repo installed them, falling back to module defaults. */\nexport function installedParams(repoRoot: string): Params {\n if (paramCache?.root === repoRoot) return paramCache.params;\n const defaults = resolveParams(loadAllModules(MODULES), {}, repoRoot);\n const recordPath = join(repoRoot, '.ai', 'rungs.toml');\n if (existsSync(recordPath)) {\n try {\n const rec = parse(readFileSync(recordPath, 'utf8')) as any;\n for (const [name, entry] of Object.entries<any>(rec.modules ?? {})) {\n if (entry?.params) defaults[name] = { ...(defaults[name] ?? {}), ...entry.params };\n }\n } catch {\n /* a malformed record falls back to defaults rather than failing every gate */\n }\n }\n paramCache = { root: repoRoot, params: defaults };\n return defaults;\n}\n\nexport const tableKey = (engine: string) =>\n ({\n 'file-budget': 'file_budget',\n sections: 'sections',\n 'frontmatter-schema': 'frontmatter_schema',\n 'link-integrity': 'link_integrity',\n 'file-population': 'file_population',\n 'gate-meta': 'gate_meta',\n 'id-integrity': '__whole__',\n 'render-freshness': 'render_freshness',\n 'register-schema': 'register_schema',\n 'self-declared-closure': 'self_declared_closure',\n 'filename-schema': 'filename_schema',\n 'cross-reference': 'cross_reference',\n 'git-status-reconcile': 'merged_status',\n 'computed-claim': 'computed_claim',\n 'term-ownership': 'term_ownership',\n 'rule-propagation': 'rule_propagation',\n 'git-state': 'git_state',\n 'merge-driver-check': 'merge_driver_check',\n 'board-reconcile': 'board_reconcile',\n })[engine] ?? engine;\n\n/**\n * ADR-0005 tier A. One line per gate per run: what the runner directly observes\n * and nothing that needs interpretation. Local, gitignored, never transmitted.\n */\nexport function appendLedger(repoRoot: string, runs: GateRun[], stamp: string) {\n const { runner } = loadRegistry(repoRoot);\n if (runner.ledger === false) return;\n const path = join(repoRoot, '.ai', '.gate-ledger.jsonl');\n const lines = runs\n .map((r) => JSON.stringify({ at: stamp, id: r.id, status: r.status, ms: r.ms, examined: r.examined }))\n .join('\\n');\n appendFileSync(path, lines + '\\n');\n}\n\n/** The two questions ADR-0005 tier B allows, both binary facts. */\nexport function ledgerQuestions(repoRoot: string, gates: RegistryGate[]) {\n const path = join(repoRoot, '.ai', '.gate-ledger.jsonl');\n if (!existsSync(path)) return { neverFired: [], alwaysFires: [], runs: 0 };\n const rows = readFileSync(path, 'utf8')\n .split('\\n')\n .filter(Boolean)\n .map((l) => JSON.parse(l) as { id: string; status: Status });\n const by = new Map<string, { total: number; failed: number }>();\n for (const r of rows) {\n const e = by.get(r.id) ?? { total: 0, failed: 0 };\n e.total++;\n if (r.status === 'fail') e.failed++;\n by.set(r.id, e);\n }\n const whyOf = (id: string) => gates.find((g) => g.id === id)?.why;\n const neverFired = [...by].filter(([, e]) => e.total >= 3 && e.failed === 0).map(([id]) => ({ id, why: whyOf(id) }));\n const alwaysFires = [...by]\n .filter(([, e]) => e.total >= 3 && e.failed / e.total > 0.9)\n .map(([id, e]) => ({ id, why: whyOf(id), rate: `${e.failed}/${e.total}` }));\n return { neverFired, alwaysFires, runs: rows.length };\n}\n", "import { existsSync, readFileSync, statSync } from 'node:fs';\nimport { join, dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { matchAny, walk } from './glob.ts';\nimport { parse as parseToml } from 'smol-toml';\nimport { runSelfTests } from './selftest.ts';\nimport { loadAllModules } from './manifest.ts';\n\nimport { resolveParams, substitute } from './substitute.ts';\nimport {\n computedClaim,\n crossReference,\n filenameSchema,\n gitStatusReconcile,\n idIntegrity,\n registerSchema,\n renderFreshness,\n selfDeclaredClosure,\n} from './engines2.ts';\nimport { boardReconcile, changelogFreshness, gitState, mergeDriverCheck, rulePropagation, termOwnership } from './engines3.ts';\n\n/**\n * Where the CLI's own `modules/` lives.\n *\n * This was `new URL(import.meta.url).pathname.slice(1)` in three places. The\n * `.slice(1)` strips a leading `/`, which is right on Windows \u2014 `/C:/\u2026` becomes\n * `C:/\u2026` \u2014 and **wrong everywhere else**, where `/home/runner/\u2026` becomes the\n * relative `home/runner/\u2026`. On Linux and macOS the directory did not resolve,\n * `loadAllModules` found nothing, and three gates silently lost the data they\n * read from the module set: `skills-spec-pure` and `skills-description-routes`\n * reported every opted-in extension as a non-spec key, and\n * `gates-self-tests-both-directions` reported gates that have fixtures as\n * having none. All three passed here and failed on the first Linux run (F-036).\n *\n * `fileURLToPath` is what the rest of the codebase already used.\n */\nconst CLI_MODULES = join(dirname(fileURLToPath(import.meta.url)), '..', 'modules');\n\nexport interface Finding {\n file?: string;\n message: string;\n}\nexport interface EngineResult {\n findings: Finding[];\n /** What the engine looked at. A gate that examined nothing is not a passing gate. */\n examined: number;\n}\nexport type Engine = (table: any, repoRoot: string, files: string[]) => EngineResult;\n\nconst read = (root: string, rel: string) => {\n try {\n return readFileSync(join(root, rel), 'utf8');\n } catch {\n return '';\n }\n};\n\n/**\n * `expand` also drops anything the CLI generated.\n *\n * Without it a gate fires on its own tool's output: `render` degrades a\n * path-scoped rule into a nested `docs/plans/AGENTS.md` for harnesses with no\n * glob scoping, and the `workflows` gate \u2014 which scans `docs/plans/**` for plan\n * documents \u2014 then reported that file for having no plan frontmatter. The\n * render pipeline and the gate scopes collide by construction, so the exclusion\n * is global rather than per-table: **a gate must never fire on a file rungs\n * wrote.**\n */\nconst GENERATED = 'Generated by `rungs';\n\nconst expand = (files: string[], patterns: string[] | undefined, fallback: string[] = []) =>\n [...new Set((patterns ?? fallback).flatMap((p) => matchAny(files, p)))];\n\nfunction dropGenerated(root: string, rels: string[]): string[] {\n return rels.filter((rel) => !read(root, rel).slice(0, 600).includes(GENERATED));\n}\n\n/** Lines that actually load: HTML comments are stripped by at least one harness. */\nfunction loadedLines(text: string): number {\n return text\n .replace(/^---\\n[\\s\\S]*?\\n---\\n/, '')\n .replace(/<!--[\\s\\S]*?-->/g, '')\n .split('\\n')\n .filter((l) => l.trim()).length;\n}\n\nconst fileBudget: Engine = (t, root, files) => {\n const targets = dropGenerated(root, t.file ? [t.file] : expand(files, t.scan));\n const excluded = new Set(expand(files, t.exclude, []));\n const findings: Finding[] = [];\n let examined = 0;\n for (const rel of targets) {\n if (excluded.has(rel) || !existsSync(join(root, rel))) continue;\n examined++;\n const n = loadedLines(read(root, rel));\n // \"1358 lines\" invites `wc -l`, which answered 1413 on the same file\n // (hexguard-templates, 2026-08-16) because this counts what actually *loads*\n // \u2014 frontmatter, HTML comments and blank lines stripped. Naming the measure\n // is the difference between evidence and a number the reader disproves.\n if (n > t.max_lines) {\n findings.push({ file: rel, message: `${n} loaded lines (blank lines and comments excluded), budget ${t.max_lines}` });\n }\n }\n return { findings, examined };\n};\n\nconst sections: Engine = (t, root, files) => {\n const specs = Array.isArray(t) ? t : [t];\n const findings: Finding[] = [];\n let examined = 0;\n for (const spec of specs) {\n const targets = dropGenerated(root, spec.file ? [spec.file] : expand(files, spec.scan));\n const excluded = new Set(expand(files, spec.exclude, []));\n for (const rel of targets) {\n if (excluded.has(rel) || !existsSync(join(root, rel))) continue;\n examined++;\n const text = read(root, rel);\n const matches = [...text.matchAll(/^(#{1,6})\\s+(.+?)\\s*$/gm)];\n const heads = matches.map((m) => m[2]);\n for (const want of spec.required ?? []) {\n const idx = heads.findIndex((h) => h.toLowerCase().startsWith(String(want).toLowerCase()));\n if (idx === -1) {\n findings.push({ file: rel, message: `missing section '${want}'` });\n continue;\n }\n if (spec.non_empty) {\n // Content runs to the next heading of the **same or higher** level, so\n // a section made of subsections is not empty. Splitting on any heading\n // reported ADR-0002's `## Decision` as empty because a `### (a)`\n // follows it immediately \u2014 the first finding this gate produced, and a\n // false one (F-018). A section whose whole body is subsections is the\n // normal shape for a long decision.\n const level = matches[idx][1].length;\n const after = text.slice(matches[idx].index! + matches[idx][0].length);\n const body = after\n .split(new RegExp(`^#{1,${level}}\\\\s+`, 'm'))[0]\n .replace(/<!--[\\s\\S]*?-->/g, '')\n .trim();\n if (!body) findings.push({ file: rel, message: `section '${want}' is empty` });\n }\n }\n for (const open of spec.requires_opening ?? []) {\n if (!text.slice(0, 400).includes(open)) findings.push({ file: rel, message: `does not open with ${open}` });\n }\n }\n }\n return { findings, examined };\n};\n\nexport const frontmatterSchema: Engine = (t, root, files) => {\n const specs = Array.isArray(t) ? t : [t];\n const findings: Finding[] = [];\n let examined = 0;\n for (const spec of specs) {\n for (const rel of dropGenerated(root, expand(files, spec.scan))) {\n if (new Set(expand(files, spec.exclude, [])).has(rel)) continue;\n const text = read(root, rel);\n const m = text.match(/^---\\n([\\s\\S]*?)\\n---/);\n if (!m) {\n findings.push({ file: rel, message: 'no frontmatter' });\n continue;\n }\n examined++;\n const keys = [...m[1].matchAll(/^([a-zA-Z0-9_-]+):/gm)].map((k) => k[1]);\n for (const req of spec.required ?? []) {\n if (!keys.includes(req)) findings.push({ file: rel, message: `missing '${req}'` });\n }\n if (spec.allowed) {\n // `extensions_allowed_from` names the manifest that may legalise a\n // non-spec key. It was declared in the skills table and read nowhere\n // (F-019), so an extension a module had deliberately opted into was\n // indistinguishable from one somebody typed by mistake \u2014 and the\n // portability cost the opt-in exists to record was attached to nothing.\n const optedIn = spec.extensions_allowed_from ? optedInExtensions(rel, spec) : new Set<string>();\n for (const k of keys) {\n if (spec.allowed.includes(k) || optedIn.has(k)) continue;\n findings.push({ file: rel, message: `non-spec key '${k}'` });\n }\n }\n const field = (k: string) => m[1].match(new RegExp(`^${k}:\\\\s*(.+)$`, 'm'))?.[1].trim().replace(/^[\"']|[\"']$/g, '');\n for (const [key, values] of Object.entries(spec.enum ?? {})) {\n const v = field(key);\n if (v && !(values as string[]).map(String).includes(v)) {\n findings.push({ file: rel, message: `${key}='${v}' not one of ${(values as string[]).join(', ')}` });\n }\n }\n\n // `[frontmatter_schema.reciprocal]` was configured in the `adr` table and\n // implemented nowhere \u2014 the third instance of F-007's shape, and this one\n // was found by *executing* a self-test rather than by reading (F-018).\n // Its fail fixture is a `superseded` record with no `superseded_by`, which\n // could never have failed while nothing read the rule.\n //\n // A one-way supersession leaves a reader on the stale record with no route\n // to the live one, which is the whole point of recording it.\n for (const pair of spec.reciprocal?.pairs ?? []) {\n const from = field(pair.from);\n if (!from) continue;\n const target = expand(files, spec.scan).find((r) => r.includes(from.replace(/\\.md$/, '')));\n if (!target) {\n findings.push({ file: rel, message: `${pair.from} names '${from}', which is not a record here` });\n continue;\n }\n const back = read(root, target).match(/^---\\n([\\s\\S]*?)\\n---/)?.[1] ?? '';\n const id = field('id') ?? '';\n if (!new RegExp(`^${pair.to}:\\\\s*.*${escapeRe(id)}`, 'm').test(back)) {\n findings.push({ file: rel, message: `${pair.from} \u2192 ${from}, but it does not name this record back in '${pair.to}'` });\n }\n }\n // A status that implies the pairing must actually carry it.\n for (const [status, requires] of Object.entries(spec.reciprocal?.required_when ?? {})) {\n if (field('status') === status && !field(String(requires))) {\n findings.push({ file: rel, message: `status is '${status}' but '${requires}' is absent` });\n }\n }\n }\n }\n return { findings, examined };\n};\n\n/**\n * Does a link target resolve, under any reading of it?\n *\n * `path/to/file.ts:387` is a code reference, not a broken link \u2014 it is the form\n * `CLAUDE.md` mandates in this repo (\"Reference code as `file_path:line_number`\")\n * and the form editors and terminals click. The engine resolved it literally and\n * reported the file missing while the file sat exactly there.\n *\n * Measured 2026-08-16 on `rift-forge` via `doctor --explain`: **1,794 of 3,851\n * link findings \u2014 46.6% \u2014 were this**, every one a real file with a line number\n * after it. Latent since WI-008 made link checking per-link; before that, one\n * `{{token}}` anywhere in a file exempted every link in it, which hid it.\n *\n * Resolve as written first, and only then retry without a trailing `:line` or\n * `:line:col`. Strip-and-retest rather than strip-and-assume: a link is called\n * broken only when **no** reading of it resolves, so this can only ever remove\n * findings. Stripping unconditionally would silence a genuinely missing\n * `foo.ts:12` whenever an equally missing `foo.ts` explained it away.\n */\nfunction resolvesHere(root: string, rel: string, href: string): boolean {\n const from = dirname(rel);\n const decoded = decodeURIComponent(href);\n if (existsSync(resolve(root, from, decoded))) return true;\n const stripped = decoded.replace(/:\\d+(?::\\d+)?$/, '');\n return stripped !== decoded && existsSync(resolve(root, from, stripped));\n}\n\n/**\n * A backticked path in an instruction file \u2014 `docs/backlog/BACKLOG.md` \u2014 that no\n * longer exists. F-007: `backticked_paths` was named in the table's `check` list\n * and implemented nowhere, so `gates-paths-exist` silently ran the markdown-link\n * scan instead and reported every finding a second time.\n *\n * Resolved from the **repo root**, because that is what an instruction file's\n * reader does with a path it is told to go and read. Skipped when the span is a\n * glob, a template token, a URL, or has no path shape at all: prose is full of\n * `identifiers`, and a gate that refuses every code span is one people delete.\n */\nfunction backtickedPaths(rel: string, text: string, root: string, hints: string[]): Finding[] {\n const out: Finding[] = [];\n const seen = new Set<string>();\n for (const m of text.matchAll(/`([^`\\n]+)`/g)) {\n const raw = m[1].trim();\n if (seen.has(raw) || !hints.some((h) => raw.includes(h))) continue;\n seen.add(raw);\n\n // Every exclusion below is a measured false positive from the first run of\n // this check against this repo, 2026-08-16 \u2014 which produced ten findings,\n // all ten wrong. The table's own instruction is that under-detection is the\n // correct bias, so the shape is narrowed to the incident it was written for:\n // hexguard's instruction files naming a **repo-relative file** that moved.\n if (raw.startsWith('/')) continue; // `/work-item` \u2014 a skill invocation\n if (/[*?{}#\\s]|^\\w+:/.test(raw)) continue; // globs, `WI-###` placeholders, prose, URLs\n if (!raw.includes('/')) continue; // `work-items.md` \u2014 a bare name, anchor unknown\n if (!/\\.[a-z0-9]{1,5}$/i.test(raw)) continue; // `.cursor/rules/` \u2014 a directory, often illustrative\n\n // Two anchors, because instruction files use both: repo-root paths for \"go\n // read this\", and `../` paths relative to the file itself.\n const bare = raw.replace(/^\\.\\//, '');\n if (!existsSync(join(root, bare)) && !existsSync(resolve(root, dirname(rel), bare))) {\n out.push({ message: `stale path in a code span \u2192 ${raw}` });\n }\n }\n return out;\n}\n\nexport const linkIntegrity: Engine = (t, root, files) => {\n // The table is now one entry per gate (F-007). The runner hands an array\n // through when it selects by id; take the single entry it selected.\n if (Array.isArray(t)) t = t[0] ?? {};\n const checks: string[] = t.check ?? ['relative_markdown_links'];\n const scan = expand(files, t.scan, ['**/*.md']); // link checks DO cover generated files\n const excluded = new Set(expand(files, t.exclude, []));\n const findings: Finding[] = [];\n let examined = 0;\n for (const rel of scan) {\n if (excluded.has(rel)) continue;\n const text = read(root, rel);\n examined++;\n if (/path-ok:\\s*\\S/.test(text)) continue;\n if (checks.includes('backticked_paths')) {\n findings.push(...backtickedPaths(rel, text, root, t.path_hint ?? ['/']).map((f) => ({ ...f, file: rel })));\n }\n if (!checks.includes('relative_markdown_links')) continue;\n // A link written inside a code span is prose *quoting* a link \u2014 most often a document\n // explaining that some link is wrong. Blanked rather than removed, so every offset after it\n // is unchanged and the reported text still matches what the author sees.\n const scannable = text.replace(/`+[^`\\n]*`+/g, (s) => ' '.repeat(s.length));\n for (const m of scannable.matchAll(/\\]\\((?!https?:|#|mailto:)([^)\\s#]+)/g)) {\n // An unsubstituted placeholder makes a **template** link, which resolves only once\n // installed. This test used to sit on the whole file, and one token anywhere in a document\n // exempted every link in it: 16 non-excluded files, including eight that ship to consumer\n // repos, silently stopped being checked. A green gate and a skipped file looked identical.\n // The case the file-level skip was written for \u2014 `modules/*/fragments/AGENTS.md` linking\n // `{{path}}/README.md` \u2014 is already excluded by path in `link_integrity.exclude` (WI-008).\n if (/\\{\\{[a-z_.]+\\}\\}/.test(m[1])) continue;\n if (!resolvesHere(root, rel, m[1])) findings.push({ file: rel, message: `broken link \u2192 ${m[1]}` });\n }\n }\n return { findings, examined };\n};\n\nconst filePopulation: Engine = (t, root, files) => {\n let hits = dropGenerated(root, expand(files, t.scan)).filter((f) => !new Set(expand(files, t.exclude, [])).has(f));\n\n // A `detect` narrows the population to files matching a shape. Without it the\n // gate counted *every scanned file* \u2014 so the redirect-stub check reported\n // \"12 matching files, threshold 1\" against a repo with no stubs at all, which\n // is a confidently wrong number rather than a finding.\n if (t.detect === 'body_is_only_a_pointer') {\n hits = hits.filter((rel) => {\n const body = read(root, rel)\n .replace(/^---\\n[\\s\\S]*?\\n---\\n/, '')\n .replace(/<!--[\\s\\S]*?-->/g, '')\n .replace(/^#.*$/gm, '')\n .trim();\n const words = body.split(/\\s+/).filter(Boolean).length;\n const links = (body.match(/\\]\\(/g) ?? []).length;\n // Short *and* mostly a link. Short alone is a stub-shaped index page.\n return words > 0 && words <= (t.max_body_words ?? 40) && links >= 1;\n });\n }\n\n const findings: Finding[] = [];\n const failAt = t.fail_at ?? Infinity;\n if (hits.length >= failAt) {\n // The count is only re-derivable if the reader knows what was counted.\n // `audit-output-is-rows` reported 275 on hexguard while the obvious\n // one-pattern `find` answered 268 (2026-08-16) \u2014 the gate scans three\n // patterns, and the message named none of them, so the correct number read\n // as a wrong one.\n const scanned = [t.scan ?? []].flat();\n findings.push({\n message:\n `${hits.length} matching file(s), threshold ${failAt} (e.g. ${hits[0]})` +\n (scanned.length ? ` \u2014 matched against ${scanned.join(', ')}` : ''),\n });\n }\n return { findings, examined: hits.length };\n};\n\n/**\n * The meta-gate: every declared gate must carry a self-test expecting `pass`\n * and one expecting `fail`. A gate whose rules are all currently satisfied is\n * indistinguishable from a gate that matches nothing.\n */\nexport const gateMeta: Engine = (_t, root) => {\n const findings: Finding[] = [];\n\n let unrun = 0;\n\n const registry = join(root, '.ai', 'gates.toml');\n if (!existsSync(registry)) return { findings, examined: 0 };\n const text = readFileSync(registry, 'utf8');\n const entries = [...text.matchAll(/\\[\\[gates\\]\\][\\s\\S]*?(?=\\n\\[\\[gates\\]\\]|\\n# rungs:end|$)/g)].map((m) => m[0]);\n let examined = 0;\n for (const entry of entries) {\n const id = entry.match(/^id\\s*=\\s*\"(.+)\"/m)?.[1];\n const kind = entry.match(/^kind\\s*=\\s*\"(.+)\"/m)?.[1];\n const table = entry.match(/^table\\s*=\\s*\"(.+)\"/m)?.[1];\n if (!id || kind !== 'declared' || !table) continue;\n examined++;\n // Tables live in the CLI, not the repo, so read them from the module set.\n const tablePath = join(CLI_MODULES, dirname(table), 'gates', table.split('/').pop()!);\n const src = existsSync(tablePath) ? readFileSync(tablePath, 'utf8') : '';\n const forGate = [...src.matchAll(/\\[\\[self_test\\]\\][\\s\\S]*?(?=\\n\\[\\[|\\n\\[|$)/g)]\n .map((m) => m[0])\n .filter((b) => b.includes(`gate = \"${id}\"`) || b.includes(`gate = \"${id}\"`) || b.includes(`gate = \"${id}\"`));\n for (const direction of ['pass', 'fail']) {\n if (!forGate.some((b) => new RegExp(`expect\\\\s*=\\\\s*\"${direction}\"`).test(b))) {\n findings.push({ message: `gate '${id}' has no self-test expecting '${direction}'` });\n }\n }\n\n // WI-045 / F-018: declaring is not asserting. Every fixture whose shape and\n // engine can be reproduced faithfully is executed, and a disagreement is a\n // finding of this gate.\n //\n // Turning this on found, in order: `adr`'s orphaned `[sections]` table, two\n // fixtures labelled for a gate that checks something else, a `reciprocal`\n // rule read by nothing, a `non_empty` check that called any section with\n // subsections empty, three fixtures orphaned by a schema that moved modules,\n // `session-sections-present` wired to an engine whose table it does not have\n // (so it passed by examining nothing), `[register_schema.open]` read by\n // nothing, and a table matcher loose enough that \"resolve-open-findings\" in\n // a filename made a Closed section match the Open schema.\n //\n // None of it was visible while the fixtures were documentation.\n const engine = entry.match(/^engine\\s*=\\s*\"(.+)\"/m)?.[1];\n const parsed = parseTable(tablePath, table.split('/')[0]);\n if (engine && parsed) {\n const blocks = (Array.isArray(parsed.self_test) ? parsed.self_test : [])\n .filter((b: any) => b?.gate === id)\n .map((b: any) => ({ expect: String(b.expect), input: b.input, fixture: b.fixture }));\n for (const r of runSelfTests(id, engine, parsed[tableKeyFor(engine)] ?? parsed, blocks)) {\n if (r.outcome === 'mismatch') findings.push({ message: `self-test for '${id}' ${r.detail}` });\n else if (r.outcome === 'unrun') unrun++;\n }\n }\n }\n\n // Stated, never silent. Most fixtures still cannot be reproduced \u2014 their\n // shapes need context the format does not carry \u2014 and reporting green while\n // most of the suite never executed would be F-006 one level up. A note rather\n // than a failure: an unbuildable fixture is not a defect in the gate.\n if (unrun) console.error(` ${unrun} self-test fixture(s) have no builder and did not run \u2014 not passes (F-018)`);\n return { findings, examined };\n};\n\n/**\n * Which non-spec frontmatter keys are legal for this skill, because the module\n * that ships it opted in.\n *\n * The skill's name is its directory \u2014 `.claude/skills/work-item/SKILL.md` \u2014 and\n * the answer lives in whichever module declares `[skills.work-item]`. Read from\n * the CLI's module set rather than from the repo, so a consumer cannot legalise\n * an extension by editing a file: the opt-in belongs to the module that took the\n * portability cost.\n *\n * `extensions_opted_in` overrides it, which is how a self-test fixture states\n * the opt-in without needing a module on disk.\n */\nfunction optedInExtensions(rel: string, spec: any): Set<string> {\n if (Array.isArray(spec.extensions_opted_in)) return new Set(spec.extensions_opted_in.map(String));\n const name = rel.split('/').slice(-2)[0];\n if (!name) return new Set();\n try {\n const mods = loadAllModules(CLI_MODULES);\n const owner = mods.find((m) => m.skills?.[name]?.extensions);\n return new Set(Object.keys(owner?.skills?.[name]?.extensions ?? {}));\n } catch {\n return new Set();\n }\n}\n\nconst escapeRe = (s: string) => s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n/**\n * A gate table, parsed. Substitution is deliberately *not* applied: a fixture's\n * `{{token}}` is part of what it asserts, and the runner needs the table's raw\n * shape rather than one repo's resolved parameters.\n */\nfunction parseTable(path: string, module: string): any | null {\n if (!existsSync(path)) return null;\n try {\n // Substituted with the module's **real defaults**, not a placeholder. Using\n // `probe` turned the skills schema's scan into `probe/**/SKILL.md` while its\n // fixture still wrote `.claude/skills/x/SKILL.md`, so the engine saw no file\n // and the runner reported the gate broken \u2014 a mismatch entirely of the\n // harness's making. A fixture and the table it tests must resolve against\n // the same parameters or neither means anything.\n const mods = loadAllModules(CLI_MODULES);\n const params = resolveParams(mods, {}, '.');\n return parseToml(substitute(readFileSync(path, 'utf8'), module, params));\n } catch {\n return null;\n }\n}\n\n/** Duplicated from `check.ts` rather than imported, to keep engines dependency-free of the runner. */\nconst tableKeyFor = (engine: string) =>\n ({\n 'file-budget': 'file_budget',\n 'frontmatter-schema': 'frontmatter_schema',\n 'link-integrity': 'link_integrity',\n 'file-population': 'file_population',\n 'render-freshness': 'render_freshness',\n 'register-schema': 'register_schema',\n 'self-declared-closure': 'self_declared_closure',\n 'filename-schema': 'filename_schema',\n 'cross-reference': 'cross_reference',\n 'git-status-reconcile': 'merged_status',\n 'computed-claim': 'computed_claim',\n 'term-ownership': 'term_ownership',\n 'rule-propagation': 'rule_propagation',\n 'git-state': 'git_state',\n 'merge-driver-check': 'merge_driver_check',\n 'board-reconcile': 'board_reconcile',\n 'changelog-freshness': 'changelog_freshness',\n })[engine] ?? engine;\n\nexport const ENGINES: Record<string, Engine> = {\n 'file-budget': fileBudget,\n sections,\n 'frontmatter-schema': frontmatterSchema,\n 'link-integrity': linkIntegrity,\n 'file-population': filePopulation,\n 'gate-meta': gateMeta,\n 'id-integrity': idIntegrity,\n 'render-freshness': renderFreshness,\n 'register-schema': registerSchema,\n 'self-declared-closure': selfDeclaredClosure,\n 'filename-schema': filenameSchema,\n 'cross-reference': crossReference,\n 'git-status-reconcile': gitStatusReconcile,\n 'computed-claim': computedClaim,\n 'term-ownership': termOwnership,\n 'rule-propagation': rulePropagation,\n 'git-state': gitState,\n 'merge-driver-check': mergeDriverCheck,\n 'board-reconcile': boardReconcile,\n 'changelog-freshness': changelogFreshness,\n};\n\n/**\n * Engines named in a gate table but not implemented here. Reported by name and\n * treated as blocking \u2014 never as a pass.\n *\n * This is the single most dangerous failure this tool could have: a registry of\n * 31 gates reporting green because 25 of them do nothing. rift-forge's rule\n * generalises exactly \u2014 *we do not land on an unknown.*\n */\nexport function isImplemented(engine: string): boolean {\n return engine in ENGINES;\n}\n", "import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';\nimport { tmpdir } from 'node:os';\nimport { dirname, join } from 'node:path';\nimport { ENGINES, type Finding } from './engines.ts';\n\n/**\n * Execute a gate's `[[self_test]]` fixtures instead of only checking they exist.\n *\n * F-006 / WI-045. `gateMeta` confirmed that a `pass` block and a `fail` block\n * were declared and never ran either, so every fixture in the repo was\n * documentation shaped like a test. `gates-links-resolve`'s\n * `See [the plan](./does-not-exist.md).` had never been executed \u2014 and had it\n * been, it would have caught F-005 months before a person found it by hand.\n *\n * That is `gate-self-test`'s own argument turned on itself: *a gate whose rules\n * are all currently satisfied is indistinguishable from a gate that matches\n * nothing*, and a self-test that never runs is indistinguishable from one that\n * would fail.\n *\n * **What this does not do is as important as what it does.** A fixture whose\n * shape has no builder is reported **unrun, by name**. It is never counted as a\n * pass, because a suite that reports green while three quarters of it never\n * executed is this finding again, one level up.\n */\n\nexport interface SelfTestResult {\n gate: string;\n expect: 'pass' | 'fail';\n outcome: 'ok' | 'mismatch' | 'unrun';\n detail?: string;\n}\n\n/**\n * A concrete path the table's `scan` would match, for writing a fixture into.\n *\n * The table may be an **array** \u2014 `[[frontmatter_schema]]` declares several \u2014 in\n * which case `t.file`/`t.scan` are undefined and the first \"scan pattern\" was\n * an entire schema object. That silently produced a nonsense path, the engine\n * saw no file, and the fixture was reported as a gate failure (F-018).\n */\nfunction targetPath(table: any): string {\n const t = Array.isArray(table) ? table[0] ?? {} : table ?? {};\n const pattern: string = t.file ?? [t.scan ?? []].flat()[0] ?? '**/*.md';\n if (!pattern.includes('*')) return pattern;\n return pattern\n .replace(/\\*\\*\\//g, 'probe/')\n .replace(/\\/\\*\\*/g, '/probe')\n .replace(/\\*/g, 'probe')\n .replace(/probe\\.probe$/, 'probe.md');\n}\n\n/**\n * Build the fixture's repo state, or return null when its shape has no builder.\n *\n * The declarative keys are deliberately handled generically \u2014 `frontmatter`,\n * `sections`, `opening` and `body` are all \"a markdown file with this in it\",\n * and writing one builder per key would be the same per-shape sprawl that left\n * 85 of 114 fixtures unrunnable in the first place.\n */\nfunction build(root: string, table: any, fx: any, input?: string): string[] | null {\n const write = (rel: string, body: string) => {\n const full = join(root, rel);\n mkdirSync(dirname(full), { recursive: true });\n writeFileSync(full, body);\n return rel;\n };\n\n if (typeof input === 'string') return [write(targetPath(table), `${input}\\n`)];\n if (!fx || typeof fx !== 'object') return null;\n\n // A set of manifests and the version each states \u2014 the computed-claim shapes.\n // `{ \"package.json\": \"1.2.0\", \"site/package.json\": \"1.1.0\" }`.\n if (fx.packages && typeof fx.packages === 'object') {\n return Object.entries(fx.packages).map(([rel, version]) =>\n write(rel, JSON.stringify({ name: rel.replace(/\\W/g, '-'), version })),\n );\n }\n\n // Named files in a parameterised directory, plus the version they are judged\n // against \u2014 the changelog shapes. `dir` is stated by the fixture rather than\n // assumed here, because the self-test sees the module's *raw* table and a\n // `{{changelog_dir}}` glob cannot match anything on disk; see `deparam`.\n if (Array.isArray(fx.fragments) && typeof fx.version === 'string') {\n const dir = fx.dir ?? 'changelog.d';\n // Forward slashes, not `join`: the returned paths are matched against the\n // spec's globs, and on Windows `join` yields `changelog.d\\0.1.1.md`, which\n // `changelog.d/*.md` does not match. The gate then reports \"did not fire\"\n // about the harness rather than the fixture.\n const written = fx.fragments.map((n: string) => write(`${dir}/${n}`, `# ${n}\\n`));\n written.push(write('package.json', JSON.stringify({ version: fx.version })));\n return written;\n }\n\n // N files matching the table's scan \u2014 the population shapes.\n if (typeof fx.matching_files === 'number') {\n const base = fx.location ?? dirname(targetPath(table));\n const marker = fx.exempt ? `<!-- ${fx.exempt} -->\\n` : '';\n return Array.from({ length: fx.matching_files }, (_, i) =>\n write(join(base === '.' ? '' : base, `probe-${i}.md`), `${marker}# probe ${i}\\n`),\n );\n }\n\n // A single markdown file described declaratively.\n const contentKeys = ['frontmatter', 'sections', 'opening', 'body', 'row', 'table'];\n if (contentKeys.some((k) => k in fx)) {\n const parts: string[] = [];\n // `table = \"Closed\"` names the heading the row belongs under. A register\n // engine finds rows by section, so a row written without its heading is in\n // no table at all \u2014 which read as \"the gate did not fire\" (F-018).\n if (fx.table) parts.push(`## ${fx.table}`, '');\n if (fx.frontmatter && typeof fx.frontmatter === 'object') {\n parts.push('---');\n for (const [k, v] of Object.entries(fx.frontmatter)) parts.push(`${k}: ${v}`);\n parts.push('---', '');\n }\n if (fx.opening) parts.push(String(fx.opening), '');\n for (const s of fx.sections ?? []) parts.push(`## ${s}`, '', 'text', '');\n if (fx.row && typeof fx.row === 'object') {\n const cols = Object.keys(fx.row);\n parts.push(`| ${cols.join(' | ')} |`, `| ${cols.map(() => '---').join(' | ')} |`,\n `| ${cols.map((c) => (fx.row as any)[c]).join(' | ')} |`, '');\n }\n if (fx.body) parts.push(String(fx.body), '');\n return [write(fx.file ?? targetPath(table), `${parts.join('\\n')}\\n`)];\n }\n\n return null;\n}\n\n/**\n * Engines whose verdict depends **only on the content of the file the fixture\n * describes**, so a fixture can be executed faithfully in an empty directory.\n *\n * The rest need context the fixture does not carry, and running them anyway\n * produces confident nonsense. `gates-links-resolve`'s `pass` fixture is\n * `See [this table](./structural.toml).` \u2014 it asserts that a link *which\n * resolves* passes, and in a temp directory it does not resolve, so the runner\n * would report the gate broken. Creating the target to make it pass would be\n * assuming the answer, and only for `expect = \"pass\"` blocks, which is worse.\n *\n * Measured 2026-08-16: without this restriction the runner reported 17\n * \"failures\", and the ones inspected were all its own artifacts. A test harness\n * that cries wolf gets deleted faster than the gate it was checking.\n *\n * This is the same shape as `applicability` in ADR-0007, one level down: ask\n * whether the check can legitimately run before running it.\n */\nconst CONTEXT_FREE: ReadonlySet<string> = new Set([\n 'frontmatter-schema',\n 'sections',\n 'file-budget',\n 'register-schema',\n 'file-population',\n 'changelog-freshness',\n 'computed-claim',\n]);\n\n/**\n * Replace `{{param}}` segments in a spec's globs with the literal the fixture\n * stands in for.\n *\n * The runner reads the **module's** gate table, where paths are still written as\n * parameters \u2014 `{{changelog_dir}}/*.md`. Nothing substitutes them here, because\n * there is no installed repo to take values from. So a fixture that exercises a\n * parameterised path has to say what it is standing in for, and the spec has to\n * be told the same thing, or the glob matches a file the builder just wrote and\n * the gate reports \"did not fire\" about its own harness.\n */\nfunction deparam<T>(spec: T, dir: string): T {\n const walk = (v: any): any =>\n typeof v === 'string' ? v.replace(/\\{\\{[^}]+\\}\\}/g, dir)\n : Array.isArray(v) ? v.map(walk)\n : v && typeof v === 'object' ? Object.fromEntries(Object.entries(v).map(([k, x]) => [k, walk(x)]))\n : v;\n return walk(spec);\n}\n\nexport function runSelfTests(\n gateId: string,\n engine: string,\n table: any,\n blocks: { expect: string; input?: string; fixture?: any }[],\n): SelfTestResult[] {\n const out: SelfTestResult[] = [];\n for (const b of blocks) {\n const expect = b.expect === 'fail' ? 'fail' : 'pass';\n if (!CONTEXT_FREE.has(engine)) {\n out.push({ gate: gateId, expect, outcome: 'unrun', detail: `${engine} fixtures need context the fixture does not carry` });\n continue;\n }\n if (!(engine in ENGINES)) {\n out.push({ gate: gateId, expect, outcome: 'unrun', detail: `engine '${engine}' not implemented` });\n continue;\n }\n const root = mkdtempSync(join(tmpdir(), 'rungs-selftest-'));\n try {\n const files = build(root, table, b.fixture, b.input);\n // A fixture states an opt-in with `opted_in`; the engine reads it from the\n // spec as `extensions_opted_in`. Without the bridge, the `pass` fixture for\n // an opted-in extension fired `non-spec key` \u2014 the harness asserting the\n // opposite of what the fixture said (F-018).\n let spec = b.fixture?.opted_in\n ? (Array.isArray(table) ? table.map((s: any) => ({ ...s, extensions_opted_in: b.fixture.opted_in })) : { ...table, extensions_opted_in: b.fixture.opted_in })\n : table;\n // Same bridge, for paths: a fixture that names a parameterised directory\n // has to hand the spec the same literal it wrote the files into.\n if (Array.isArray(b.fixture?.fragments)) spec = deparam(spec, b.fixture.dir ?? 'changelog.d');\n // And for `exclude`, which is the thing under test in half these fixtures:\n // the table ships it empty by default, so a fixture proving exclusion works\n // has to set it, exactly as a repo would.\n if (Array.isArray(b.fixture?.exclude)) {\n const ex = b.fixture.exclude;\n spec = Array.isArray(spec) ? spec.map((s: any) => ({ ...s, exclude: ex })) : { ...spec, exclude: ex };\n }\n if (!files) {\n out.push({ gate: gateId, expect, outcome: 'unrun', detail: `no builder for fixture ${JSON.stringify(b.fixture).slice(0, 60)}` });\n continue;\n }\n let findings: Finding[];\n try {\n findings = ENGINES[engine](spec, root, files).findings;\n } catch (e: any) {\n out.push({ gate: gateId, expect, outcome: 'unrun', detail: `engine threw: ${e.message}`.slice(0, 90) });\n continue;\n }\n const fired = findings.length > 0;\n out.push(\n fired === (expect === 'fail')\n ? { gate: gateId, expect, outcome: 'ok' }\n : { gate: gateId, expect, outcome: 'mismatch', detail: `expected ${expect}, ${fired ? `fired: ${findings[0].message}`.slice(0, 80) : 'did not fire'}` },\n );\n } finally {\n rmSync(root, { recursive: true, force: true });\n }\n }\n return out;\n}\n", "import { existsSync, readFileSync } from 'node:fs';\nimport { execFileSync } from 'node:child_process';\nimport { join } from 'node:path';\nimport { matchAny } from './glob.ts';\nimport type { Engine, Finding } from './engines.ts';\n\nconst read = (root: string, rel: string) => {\n try {\n return readFileSync(join(root, rel), 'utf8');\n } catch {\n return '';\n }\n};\nconst expand = (files: string[], p: string[] | undefined, f: string[] = []) =>\n [...new Set((p ?? f).flatMap((x) => matchAny(files, x)))];\n\n/** An exemption marker is ignored unless it states a reason. */\nconst exempted = (text: string, marker?: string) =>\n !!marker && new RegExp(`${marker.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')}\\\\s*\\\\S`).test(text);\n\n/**\n * Ids: uniqueness across the declared sources, citations that resolve, and the\n * stale-blocker rule \u2014 a document may not say it waits on work that has finished.\n */\nexport const idIntegrity: Engine = (t, root, files) => {\n const findings: Finding[] = [];\n let examined = 0;\n const known = new Set<string>();\n\n for (const [, kind] of Object.entries<any>(t.kinds ?? {})) {\n const re = new RegExp(`^\\\\s*id:\\\\s*(${kind.format})`, 'm');\n const seen = new Map<string, string>();\n for (const rel of expand(files, kind.sources)) {\n examined++;\n const text = read(root, rel);\n const id = text.match(re)?.[1] ?? rel.match(new RegExp(kind.format))?.[0];\n if (!id) continue;\n known.add(id);\n const prior = seen.get(id);\n if (prior) findings.push({ file: rel, message: `id ${id} also claimed by ${prior}` });\n else seen.set(id, rel);\n }\n // The marker must not name an id that is already spent.\n if (kind.marker?.file) {\n const m = read(root, kind.marker.file).match(new RegExp(kind.marker.pattern));\n if (m?.[1] && seen.has(m[1])) {\n findings.push({ file: kind.marker.file, message: `NEXT marker points at ${m[1]}, already taken` });\n }\n }\n }\n\n // Stale blockers. Vocabulary is narrow on purpose: a first draft that matched\n // `until <id>` hit 29 lines of true history in one repo's own voice.\n const sb = t.stale_blocker;\n if (sb?.phrases?.length && known.size) {\n const scope = expand(files, ['docs/**/*.md', 'AGENTS.md', 'CLAUDE.md']).filter(\n (f) => !expand(files, sb.scope_exclude, []).includes(f),\n );\n const past = (sb.past_tense_ok ?? []).map((p: string) => p.toLowerCase());\n for (const rel of scope) {\n const text = read(root, rel);\n if (exempted(text, sb.exempt_marker)) continue;\n for (const phrase of sb.phrases) {\n const re = new RegExp(`(.{0,${sb.negation_window ?? 60}})\\\\b${phrase}\\\\b\\\\s+([A-Z]{1,6}-\\\\d{1,4})`, 'gi');\n for (const m of text.matchAll(re)) {\n const lead = m[1].toLowerCase();\n if (past.some((p: string) => lead.includes(p.split(' ')[0]) && lead.includes('was'))) continue;\n if (/\\bnot\\b|\\bnever\\b|\\bno longer\\b/.test(lead.slice(-30))) continue;\n if (isDone(root, m[2], files)) {\n findings.push({ file: rel, message: `claims to be ${phrase} ${m[2]}, which is done` });\n }\n }\n }\n }\n }\n return { findings, examined };\n};\n\nfunction isDone(root: string, id: string, files: string[]): boolean {\n const hit = files.find((f) => f.includes(id) && f.endsWith('.md'));\n if (!hit) return false;\n const s = read(root, hit).match(/^status:\\s*(\\S+)/m)?.[1];\n return s === 'done' || hit.includes('/archive/');\n}\n\n/** Generated output that no longer matches what its producer would emit now. */\nexport const renderFreshness: Engine = (t, root, files) => {\n const specs = Array.isArray(t) ? t : [t];\n const findings: Finding[] = [];\n let examined = 0;\n for (const spec of specs) {\n if (spec.block?.file) {\n examined++;\n const text = read(root, spec.block.file);\n const re = new RegExp(`rungs:begin ${spec.block.marker}[\\\\s\\\\S]*?rungs:end ${spec.block.marker}`);\n if (!re.test(text)) {\n findings.push({ file: spec.block.file, message: `no '${spec.block.marker}' block \u2014 run \\`${spec.command}\\`` });\n }\n continue;\n }\n const excluded = new Set(expand(files, spec.exclude, []));\n const sources = expand(files, spec.sources).filter((s) => !excluded.has(s));\n const targets = expand(files, spec.targets);\n // Only harnesses this repo actually emits for are checked; a missing\n // `.cursor/rules` in a repo that never asked for Cursor is not staleness.\n const live = new Set(targets.map((x) => x.split('/')[0]));\n for (const src of sources) {\n examined++;\n const stem = src.split('/').pop()!.replace(/\\.md$/, '');\n for (const dir of live) {\n if (!targets.some((x) => x.startsWith(dir) && x.includes(stem))) {\n findings.push({ file: src, message: `no rendering under ${dir}/ \u2014 run \\`${spec.command}\\`` });\n }\n }\n }\n }\n return { findings, examined };\n};\n\n/** Markdown-table registers: required columns, enums, and conditional rules. */\nexport const registerSchema: Engine = (t, root, files) => {\n const findings: Finding[] = [];\n let examined = 0;\n\n // A register file holds more than one table, and each gets its own spec \u2014\n // `[register_schema]` for Closed and `[register_schema.open]` for Open. Only\n // the top-level one was ever read (F-018), so the Open table's rules \u2014\n // `non_empty = [\"Sev\", \"Pri\", \"What\", \"Evidence\"]` and the Sev/Pri enums \u2014\n // had never been enforced on any repo. Found because the fixture asserting\n // them could not fire, once fixtures started running.\n //\n // A sub-spec is any nested object naming a `table`; `enum` and `min_words` are\n // objects too and do not.\n const specs = [t, ...Object.values(t).filter((v: any) => v && typeof v === 'object' && !Array.isArray(v) && v.table)];\n for (const t of specs as any[]) {\n const targets = t.file ?? specs[0].file ? [t.file ?? (specs[0] as any).file] : expand(files, t.scan);\n for (const rel of targets) {\n const text = read(root, rel);\n if (!text) continue;\n for (const table of parseTables(text)) {\n // The heading must **start with** the table's name, not merely contain it.\n // A substring match sent every Closed row through the Open schema, because\n // `## Closed \u2014 2026-08-16 by [WI-044](archive/WI-044-resolve-open-findings.md)`\n // contains \"open\" inside a filename. Latent until `[register_schema.open]`\n // was read for the first time (F-018) \u2014 a loose matcher is invisible while\n // only one spec exists to match.\n const heading = sectionOf(text, table.headerLine).replace(/^#+\\s*/, '').trim().toLowerCase();\n if (t.table && !heading.startsWith(String(t.table).toLowerCase())) continue;\n const cols = t.required_cols ?? t.table_columns ?? [];\n const present = cols.filter((c: string) =>\n table.headers.some((h) => h.toLowerCase() === String(c).toLowerCase()),\n );\n // Recognition before validation: a file may hold several tables and only\n // some are registers. Demanding every one carry the columns reported a\n // spec index for not being a story table.\n if (cols.length && present.length < Math.max(2, Math.ceil(cols.length / 2))) continue;\n for (const c of cols) {\n if (!present.includes(c)) findings.push({ file: rel, message: `register table missing column '${c}'` });\n }\n for (const row of table.rows) {\n if (Object.values(row).every((v) => !v || v === '\u2014')) continue;\n examined++;\n for (const [key, values] of Object.entries<any>(t.enum ?? {})) {\n const v = strip(row[key]);\n if (v && !values.map(String).includes(v)) {\n findings.push({ file: rel, message: `${key}='${v}' not one of ${values.join(', ')}` });\n }\n }\n for (const c of t.non_empty ?? []) {\n if (!strip(row[c])) findings.push({ file: rel, message: `row ${firstCell(row)}: '${c}' is empty` });\n }\n for (const cond of t.conditional ?? []) {\n const matches = Object.entries<any>(cond.when ?? {}).every(([k, v]) => strip(row[k]) === String(v));\n if (!matches) continue;\n for (const c of cond.non_empty ?? []) {\n const v = strip(row[c]);\n if (!v) findings.push({ file: rel, message: `row ${firstCell(row)}: '${c}' required when ${JSON.stringify(cond.when)}` });\n else if (cond.min_words?.[c] && v.split(/\\s+/).length < cond.min_words[c]) {\n findings.push({ file: rel, message: `row ${firstCell(row)}: '${c}' is too thin to be a reason` });\n }\n }\n }\n }\n }\n }\n }\n return { findings, examined };\n};\n\nconst escapeRe = (s: string) => s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n/**\n * An open finding must not declare itself fixed in its own detail section.\n *\n * This is deliberately a text-only contradiction check. It does not inspect\n * code or infer that a fix really shipped; those questions are repository-\n * specific and a guessed probe would be confidently wrong. A section may\n * contain a reasoned `closure-ok:` marker when only a part of the observation\n * was addressed. The table owns the headings, id shape, and verdict phrases so\n * the engine remains useful for registers that use a different prefix or\n * detail heading.\n */\nexport const selfDeclaredClosure: Engine = (t, root, files) => {\n const findings: Finding[] = [];\n let examined = 0;\n const targets = t.file ? [t.file] : expand(files, t.scan ?? ['docs/**/FINDINGS.md']);\n const idPattern = t.id_pattern ?? '[A-Z]{1,6}-\\\\d{1,4}';\n const openRow = new RegExp(t.open_row_pattern ?? `^\\\\|\\\\s*\\\\[?(${idPattern})\\\\]`, 'gmu');\n const detailHeading = new RegExp(t.detail_heading_pattern ?? `^###\\\\s+(${idPattern})\\\\s+\u2014\\\\s+`, 'gmu');\n const verdicts = (t.declares_fixed ?? [\n '\\\\*\\\\*Fixed[.,)*]',\n '\\\\*\\\\*Fixed\\\\s+(?:in|by|the\\\\s+same\\\\s+day|\\\\d{4}-\\\\d{2}-\\\\d{2})',\n '\\\\*\\\\*Implemented in this change\\\\.?\\\\*\\\\*',\n '\\\\*\\\\*fixed in the pass that found it\\\\*\\\\*',\n ]).map((p: string) => new RegExp(p, 'iu'));\n\n for (const rel of targets) {\n const text = read(root, rel);\n if (!text) continue;\n const openStart = headingIndex(text, t.open_heading ?? 'Open');\n const closedStart = headingIndex(text, t.closed_heading ?? 'Closed');\n const detailStart = headingIndex(text, t.detail_heading ?? 'Detail');\n if (openStart < 0 || closedStart < 0 || detailStart < 0 || closedStart <= openStart || detailStart < closedStart) continue;\n\n const open = new Set<string>();\n for (const match of text.slice(openStart, closedStart).matchAll(openRow)) open.add(match[1]);\n if (!open.size) continue;\n\n const detail = text.slice(detailStart);\n const headings = [...detail.matchAll(detailHeading)];\n for (let i = 0; i < headings.length; i++) {\n const id = headings[i][1];\n if (!open.has(id)) continue;\n examined++;\n const start = headings[i].index ?? 0;\n const end = headings[i + 1]?.index ?? detail.length;\n const section = detail.slice(start, end);\n const marker = t.exempt_marker ?? 'closure-ok:';\n if (new RegExp(`<!--\\\\s*${escapeRe(marker)}\\\\s*\\\\S`, 'u').test(section)) continue;\n const body = section.slice(section.indexOf('\\n') + 1);\n for (const verdict of verdicts) {\n const match = verdict.exec(body);\n if (!match) continue;\n const before = body.slice(Math.max(0, match.index - (t.citation_window ?? 120)), match.index);\n const cited = [...before.matchAll(new RegExp(`(${idPattern})[^.]{0,${t.citation_window ?? 120}}$`, 'gu'))].at(-1)?.[1];\n if (cited && cited !== id) continue;\n findings.push({ file: rel, message: `${id} is open but its detail declares it fixed: ${body.slice(match.index, match.index + 60).split('\\n')[0].trim()}` });\n break;\n }\n }\n }\n return { findings, examined };\n};\n\nfunction headingIndex(text: string, heading: string): number {\n const re = new RegExp(`^#{1,6}\\\\s+${escapeRe(heading)}\\\\s*$`, 'imu');\n return text.search(re);\n}\n\nconst strip = (v?: string) => (v ?? '').replace(/[`*\\[\\]]/g, '').split('(')[0].trim();\nconst firstCell = (row: Record<string, string>) => strip(Object.values(row)[0]) || '?';\n\nfunction parseTables(text: string) {\n const out: { headers: string[]; rows: Record<string, string>[]; headerLine: number }[] = [];\n const lines = text.split('\\n');\n for (let i = 0; i < lines.length; i++) {\n if (!/^\\s*\\|/.test(lines[i]) || !/^\\s*\\|[\\s:|-]+\\|/.test(lines[i + 1] ?? '')) continue;\n const headers = cells(lines[i]);\n const rows: Record<string, string>[] = [];\n let j = i + 2;\n for (; j < lines.length && /^\\s*\\|/.test(lines[j]); j++) {\n const c = cells(lines[j]);\n rows.push(Object.fromEntries(headers.map((h, k) => [h, c[k] ?? ''])));\n }\n out.push({ headers, rows, headerLine: i });\n i = j;\n }\n return out;\n}\nconst cells = (line: string) => line.trim().replace(/^\\||\\|$/g, '').split('|').map((s) => s.trim());\nconst sectionOf = (text: string, line: number) => {\n const before = text.split('\\n').slice(0, line);\n for (let i = before.length - 1; i >= 0; i--) if (/^#{1,6}\\s/.test(before[i])) return before[i];\n return '';\n};\n\nexport const filenameSchema: Engine = (t, root, files) => {\n const re = new RegExp(t.pattern);\n const excluded = new Set(expand(files, t.exclude, []));\n const findings: Finding[] = [];\n let examined = 0;\n for (const rel of expand(files, t.scan)) {\n if (excluded.has(rel)) continue;\n examined++;\n const base = rel.split('/').pop()!;\n if (!re.test(base)) findings.push({ file: rel, message: 'filename does not say what closed and what came next' });\n }\n return { findings, examined };\n};\n\n/** Skills naming their neighbours \u2014 only past the threshold where it matters. */\nexport const crossReference: Engine = (t, root, files) => {\n const skills = expand(files, t.scan);\n if (skills.length < (t.min_skills ?? 6)) return { findings: [], examined: skills.length };\n const names = skills.map((s) => s.split('/').slice(-2)[0]);\n const findings: Finding[] = [];\n for (const rel of skills) {\n const text = read(root, rel);\n if (exempted(text, t.exempt_marker)) continue;\n const desc = text.match(/^---\\n([\\s\\S]*?)\\n---/)?.[1] ?? '';\n const self = rel.split('/').slice(-2)[0];\n if (!names.some((n) => n !== self && desc.includes(n))) {\n findings.push({ file: rel, message: `names no neighbouring skill (${skills.length} in this repo)` });\n }\n }\n return { findings, examined: skills.length };\n};\n\n/** A merged branch cannot still sit at a pre-review status. One-directional. */\n/**\n * Did this branch actually land work, or is it a label pointing at a commit the\n * base already had?\n *\n * `git branch --merged` answers \"is the tip an ancestor\", which is true of a\n * branch cut five seconds ago and never committed to. F-001: reproduced\n * 2026-08-15 on WI-001 and hit three more times on 2026-08-16 \u2014 every item\n * worked through `/work-item` trips it in the window between `git switch -c`\n * and the first commit. A gate that cries wolf on the happy path is one people\n * learn to ignore, which is the failure it exists to prevent.\n *\n * The obvious fix \u2014 \"has commits ahead of base\" \u2014 is wrong, and measuring it\n * proved so: **after any merge the branch is zero commits ahead**, so the gate\n * would never fire again. That silently deletes the check while looking like a\n * fix, which is worse than the false positive.\n *\n * What actually distinguishes them is the merge commit. This repo merges\n * `--no-ff` (backlog README \u00A74), so a branch that landed work leaves a commit in\n * the base whose *second* parent is that branch's tip. A branch that landed\n * nothing never appears as anyone's second parent.\n *\n * **Known gap, stated rather than hidden:** a fast-forward merge that keeps the\n * branch produces no merge commit and no second parent, so this reads it as\n * having landed nothing and stays quiet. That is a false negative on a workflow\n * this repo does not use \u2014 it deletes branches on merge \u2014 and it is the\n * direction to be wrong in, because the alternative is the daily false positive.\n */\n/**\n * `git` as an argv array, never a shell string.\n *\n * `--format=%(refname:short)` is a **bash syntax error** \u2014 unquoted parentheses \u2014\n * so `backlog-merged-status` threw on every Linux and macOS repo, hit its catch,\n * and reported \"cannot read git branches; status not reconciled\" as a finding.\n * The gate ships in four of five profiles and had never once worked off Windows,\n * where `execSync` goes through cmd.exe and parentheses are ordinary characters.\n * Found by the CI matrix on its first run (F-033).\n *\n * Branch names come out of work-item frontmatter, so this is also the difference\n * between reading a field and passing it to a shell.\n */\nconst gitArgs = (root: string, args: string[]) =>\n execFileSync('git', args, { cwd: root, stdio: 'pipe' }).toString().trim();\n\nfunction landedWork(root: string, branch: string, base: string): boolean {\n const git = (...args: string[]) => gitArgs(root, args);\n try {\n const tip = git('rev-parse', branch);\n if (tip === git('rev-parse', base)) return false;\n return git('log', base, '--merges', '--format=%P')\n .split('\\n')\n .some((line) => line.trim().split(/\\s+/).slice(1).includes(tip));\n } catch {\n // Unreadable is not provably empty. Report, which fails loudly rather than\n // silently \u2014 the same rule the runner applies to a missing engine.\n return true;\n }\n}\n\nexport const gitStatusReconcile: Engine = (t, root, files) => {\n const findings: Finding[] = [];\n let merged: Set<string>;\n try {\n merged = new Set(\n gitArgs(root, ['branch', '--merged', t.integration_branch ?? 'main', '--format=%(refname:short)'])\n .split('\\n')\n .map((s) => s.trim())\n .filter(Boolean),\n );\n } catch {\n // No git, or no such branch. Not a pass and not a failure \u2014 an unknown.\n return { findings: [{ message: 'cannot read git branches; status not reconciled' }], examined: 0 };\n }\n let examined = 0;\n for (const rel of expand(files, ['docs/**/items/**/*.md'])) {\n const text = read(root, rel);\n if (exempted(text, t.exempt_marker)) continue;\n const branch = text.match(new RegExp(`^${t.branch_field ?? 'branch'}:\\\\s*(\\\\S+)`, 'm'))?.[1];\n const status = text.match(new RegExp(`^${t.status_field ?? 'status'}:\\\\s*(\\\\S+)`, 'm'))?.[1];\n if (!branch || !status) continue;\n examined++;\n if (\n merged.has(branch) &&\n (t.pre_review_statuses ?? []).includes(status) &&\n landedWork(root, branch, t.integration_branch ?? 'main')\n ) {\n findings.push({ file: rel, message: `branch ${branch} is merged but status is '${status}'` });\n }\n }\n return { findings, examined };\n};\n\n/** A number a machine can compute is never typed by a human. */\nexport const computedClaim: Engine = (t, root, files) => {\n const specs = Array.isArray(t) ? t : [t];\n const findings: Finding[] = [];\n let examined = 0;\n for (const spec of specs) {\n const values = new Map<string, string>();\n // Which files share a version is the repo's judgement, not something to infer\n // (F-023). The default sources glob `*/package.json`, which is right for a\n // monorepo released in lockstep and wrong for a sibling that is deliberately\n // versioned on its own \u2014 this repo's docs site sat at 0.0.1 beside a 0.2.0\n // package, correctly, and installing the gate would have failed a healthy\n // layout. So a repo states the exceptions rather than the engine guessing\n // them, and `all-agree` keeps needing no opinion about which file is right.\n const excluded = (rel: string) => (spec.exclude ?? []).some((p: string) => matchAny([rel], p).length > 0);\n for (const src of spec.sources ?? []) {\n for (const rel of matchAny(files, src.file)) {\n if (excluded(rel)) continue;\n const text = read(root, rel);\n let v: string | undefined;\n if (src.path && rel.endsWith('.json')) {\n try {\n v = src.path.split('.').reduce((o: any, k: string) => o?.[k], JSON.parse(text));\n } catch {\n /* unparseable is not a disagreement */\n }\n } else if (src.xpath) {\n v = text.match(new RegExp(`<${src.xpath.split('//')[1]}>(.*?)<`))?.[1];\n }\n if (v) {\n examined++;\n values.set(rel, String(v));\n }\n }\n }\n const distinct = new Set(values.values());\n if (spec.rule === 'all-agree' && distinct.size > 1) {\n // Name the file beside its value. The message used to list the distinct\n // values and then say \"run `{autofix}`\" \u2014 which pointed at\n // `rungs release sync-version`, a command that does not exist and never\n // has. Telling someone to run a missing command is worse than telling\n // them nothing, so the finding now carries what they actually need: which\n // file says what. The hint is appended only if a real one is declared.\n const where = [...values.entries()].map(([rel, v]) => `${rel}=${v}`).join(', ');\n findings.push({\n message:\n `${spec.id} disagrees across ${values.size} locations: ${where}` +\n (spec.autofix ? ` \u2014 run \\`${spec.autofix}\\`` : '') +\n (spec.exclude?.length ? '' : '. If one of these is versioned independently, list it in `exclude`.'),\n });\n }\n }\n return { findings, examined };\n};\n", "import { existsSync, readFileSync } from 'node:fs';\nimport { execFileSync } from 'node:child_process';\nimport { join } from 'node:path';\nimport { matchAny } from './glob.ts';\nimport type { Engine, Finding } from './engines.ts';\n\nconst read = (root: string, rel: string) => {\n try {\n return readFileSync(join(root, rel), 'utf8');\n } catch {\n return '';\n }\n};\nconst expand = (files: string[], p: string[] | undefined, f: string[] = []) =>\n [...new Set((p ?? f).flatMap((x) => matchAny(files, x)))];\nconst escapeRe = (s: string) => s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n/** `1.2.3` \u2192 [1,2,3]; anything else \u2192 null. Deliberately not a semver parser. */\nexport function versionParts(s: string): number[] | null {\n const m = /^(\\d+)\\.(\\d+)\\.(\\d+)$/.exec(s.trim());\n return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;\n}\n\nexport function versionCmp(a: number[], b: number[]): number {\n return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];\n}\n\n/**\n * `changelog-freshness` \u2014 a consumed fragment that was never deleted.\n *\n * Fragments are consumed at release time, not archived: one left behind appears\n * in the next release too, where it reads as unreleased work. `cut-release` \u00A73\n * has said so in prose since it was written, and prose did not hold it \u2014\n * `changelog.d/0.1.1.md` survived two releases and was still there at 0.2.0\n * preparation (F-022). So the rule becomes mechanical.\n *\n * A fragment is stale when its filename names a version **below** the version\n * being prepared. Files whose names are not versions are ignored rather than\n * reported: the module's own fixtures use `42.feature.md`, and a gate that\n * refuses a naming convention it was not asked about is a gate people disable.\n */\nexport const changelogFreshness: Engine = (t, root, files) => {\n const specs = Array.isArray(t) ? t : [t];\n const findings: Finding[] = [];\n let examined = 0;\n\n for (const spec of specs) {\n const src = spec.version ?? {};\n let current: number[] | null = null;\n for (const rel of matchAny(files, src.file ?? 'package.json')) {\n try {\n const raw = (src.path ?? 'version')\n .split('.')\n .reduce((o: any, k: string) => o?.[k], JSON.parse(read(root, rel)));\n current = versionParts(String(raw ?? ''));\n } catch {\n /* unparseable is not a stale fragment */\n }\n if (current) break;\n }\n // Without a version to compare against there is no claim to make. Saying\n // nothing is right; passing loudly would not be.\n if (!current) continue;\n\n for (const rel of expand(files, spec.fragments, [])) {\n const name = rel.split('/').pop()!.replace(/\\.md$/, '');\n const v = versionParts(name);\n if (!v) continue;\n examined++;\n if (versionCmp(v, current) < 0) {\n findings.push({\n file: rel,\n message:\n spec.message?.trim() ||\n `fragment names ${name}, below the ${current.join('.')} being prepared \u2014 it was consumed by an earlier release and should have been deleted`,\n });\n }\n }\n }\n\n return { findings, examined };\n};\n\n/** An exemption marker is ignored unless it states a reason. */\nconst exempted = (text: string, marker?: string) =>\n !!marker && new RegExp(`${escapeRe(marker)}\\\\s*\\\\S`).test(text);\n\n/** Rows of the first markdown table under a heading containing `near`. */\nfunction tableRows(text: string, near?: string): Record<string, string>[] {\n const lines = text.split('\\n');\n const rows: Record<string, string>[] = [];\n let heading = '';\n for (let i = 0; i < lines.length; i++) {\n if (/^#{1,6}\\s/.test(lines[i])) heading = lines[i];\n if (!/^\\s*\\|/.test(lines[i]) || !/^\\s*\\|[\\s:|-]+\\|/.test(lines[i + 1] ?? '')) continue;\n if (near && !heading.toLowerCase().includes(near.toLowerCase())) continue;\n const cells = (l: string) => l.trim().replace(/^\\||\\|$/g, '').split('|').map((s) => s.trim());\n const headers = cells(lines[i]);\n for (let j = i + 2; j < lines.length && /^\\s*\\|/.test(lines[j]); j++) {\n const c = cells(lines[j]);\n rows.push(Object.fromEntries(headers.map((h, k) => [h, c[k] ?? ''])));\n }\n i = lines.length;\n }\n return rows;\n}\n\nconst clean = (v = '') => v.replace(/[`*\\[\\]]/g, '').trim();\n\n/** Words distinctive enough to indicate a topic is being restated, not mentioned. */\nfunction terms(topic: string): string[] {\n const stop = new Set(['the', 'and', 'for', 'with', 'per', 'its', 'a', 'an', 'of', 'to', 'in', 'on', 'is', 'are']);\n return clean(topic)\n .toLowerCase()\n .split(/[^a-z0-9_-]+/)\n .filter((w) => w.length > 3 && !stop.has(w));\n}\n\n/**\n * One owner per topic, checked by vocabulary.\n *\n * The registry's third column \u2014 where a topic must NOT appear \u2014 is what turns\n * \"one source of truth\" from a principle into a lookup. Approximate by\n * construction: it catches a section that restates a topic, not one that\n * restates it in different words. That ceiling is pinned in the message rather\n * than hidden, so a green run never reads as \"verified\".\n */\nexport const termOwnership: Engine = (t, root, files) => {\n const registry = read(root, t.registry ?? 'docs/doc-ownership.md');\n if (!registry) return { findings: [{ message: `ownership registry '${t.registry}' not found` }], examined: 0 };\n\n const cols = t.columns ?? {};\n const findings: Finding[] = [];\n let examined = 0;\n\n for (const row of tableRows(registry)) {\n const topic = clean(row[cols.topic ?? 'Topic']);\n const owner = clean(row[cols.owner ?? 'Owner']);\n const forbidden = clean(row[cols.forbidden ?? 'Must NOT appear in']);\n if (!topic || !forbidden || forbidden === '\u2014' || topic.startsWith('(example)')) continue;\n\n const want = terms(topic);\n if (want.length < 2) continue; // too vague to test without guessing\n const patterns = forbidden.split(/[,\u00B7]/).map((s) => s.trim()).filter(Boolean);\n\n for (const rel of expand(files, patterns)) {\n if (rel === owner) continue;\n const text = read(root, rel);\n if (exempted(text, t.exempt_marker)) continue;\n examined++;\n // Per section, not per file: a passing mention is a cross-reference, a\n // section carrying several of the topic's terms is a restatement.\n for (const section of text.split(/^#{1,6}\\s+/m)) {\n const lower = section.toLowerCase();\n const hits = want.filter((w) => lower.includes(w));\n if (hits.length >= (t.engage_min_terms ?? 3)) {\n findings.push({ file: rel, message: `restates \"${topic}\", owned by ${owner} (${hits.length} terms)` });\n break;\n }\n }\n }\n }\n return { findings, examined };\n};\n\n/**\n * A working rule lives in more surfaces than its authority, and fixing the\n * authority does not reach them. Each declared rule names the surfaces that\n * restate it; a surface carrying the retired wording is reported.\n *\n * `forbids` is matched against a preceding-context negation window, because a\n * retired phrase inside \"do NOT <retired>\" is the fix, not the violation \u2014 and\n * a guard that refuses its own fix is one people disable.\n */\nexport const rulePropagation: Engine = (t, root, files) => {\n const registry = read(root, t.registry ?? 'docs/working-rules.md');\n if (!registry) return { findings: [{ message: `rules registry '${t.registry}' not found` }], examined: 0 };\n\n const cols = t.columns ?? {};\n const findings: Finding[] = [];\n let examined = 0;\n const window = t.negation_window ?? 60;\n\n for (const row of tableRows(registry)) {\n const rule = clean(row[cols.rule ?? 'Rule']);\n const retired = clean(row[cols.retired ?? 'Retired wording']);\n const surfaces = clean(row[cols.surfaces ?? 'Surfaces that restate it']);\n if (!rule || !retired || retired === '\u2014' || rule.startsWith('(example)')) continue;\n\n for (const rel of expand(files, surfaces.split(/[,\u00B7]/).map((s) => s.trim()).filter(Boolean))) {\n const text = read(root, rel);\n if (exempted(text, t.exempt_marker)) continue;\n examined++;\n const re = new RegExp(`(.{0,${window}})${escapeRe(retired)}`, 'gis');\n for (const m of text.matchAll(re)) {\n const lead = m[1].toLowerCase();\n if (/\\bnot\\b|\\bnever\\b|\\bno longer\\b|\\bused to\\b|\\bformerly\\b|\\bretired\\b/.test(lead)) continue;\n findings.push({ file: rel, message: `carries the retired wording for \"${rule}\"` });\n break;\n }\n }\n }\n return { findings, examined };\n};\n\n/**\n * The integration branch must be checked out nowhere.\n *\n * Recorded as a correction rather than a preference: holding it checked out\n * blocked every other session *and* did not prevent concurrent landing anyway,\n * because switching to the scratch ref releases it mid-run.\n */\nexport const gitState: Engine = (t, root) => {\n let out: string;\n try {\n out = execFileSync('git', ['worktree', 'list', '--porcelain'], { cwd: root, stdio: 'pipe' }).toString();\n } catch {\n // Not a git repo, or git unavailable. An unattributable result blocks:\n // we do not land on an unknown.\n return { findings: [{ message: 'cannot read git worktrees; checkout state unknown' }], examined: 0 };\n }\n const findings: Finding[] = [];\n const blocks = out.split('\\n\\n').filter(Boolean);\n for (const b of blocks) {\n const dir = b.match(/^worktree (.+)$/m)?.[1];\n const branch = b.match(/^branch refs\\/heads\\/(.+)$/m)?.[1];\n if (branch && (t.refuse_checked_out ?? []).includes(branch)) {\n findings.push({ message: `'${branch}' is checked out in ${dir} \u2014 nothing should hold it` });\n }\n }\n return { findings, examined: blocks.length };\n};\n\n/**\n * Merge drivers named in `.gitattributes` are **inert until installed**, so a\n * fresh clone silently falls back to git's default merge on files that must\n * never be text-merged. Declaring them is not the same as having them.\n */\nexport const mergeDriverCheck: Engine = (t, root) => {\n const attrs = read(root, t.attributes_file ?? '.gitattributes');\n if (!attrs) return { findings: [], examined: 0 };\n\n const declared = [...new Set([...attrs.matchAll(/merge=([\\w-]+)/g)].map((m) => m[1]))];\n const required = (t.required_drivers ?? []).filter((d: string) => declared.includes(d));\n if (!required.length) return { findings: [], examined: declared.length };\n\n const findings: Finding[] = [];\n for (const driver of required) {\n let configured = '';\n try {\n // Driver names come from `.gitattributes`, so they reach this as data.\n configured = execFileSync('git', ['config', '--get', `merge.${driver}.driver`], { cwd: root, stdio: 'pipe' }).toString().trim();\n } catch {\n /* absent config exits non-zero, which is the finding */\n }\n if (!configured) {\n findings.push({ message: `driver '${driver}' is declared but not installed \u2014 run \\`${t.install_command}\\`` });\n }\n }\n return { findings, examined: declared.length };\n};\n\n/**\n * The board's grouping must agree with each item's own `status` field.\n *\n * `git-status-reconcile` already reconciles a **branch** against that field, and\n * this repo cites it constantly as proof that typed bookkeeping decays. Nothing\n * reconciled the **board** \u2014 so on 2026-08-16 `BACKLOG.md` filed fourteen items\n * under `Proposed` and `Planned` whose files all read `status: done`, nine of\n * them linking into `archive/`. The board said *proposed* about a document in\n * the directory for work that can no longer change.\n *\n * It was found by an outside reviewer asserting the framework research was done.\n * They were right; the board would have told them otherwise. That is the same\n * failure the whole module exists to prevent, one layer up, in the file every\n * session opens first.\n *\n * Only table rows are read. The board's prose deliberately discusses finished\n * work, and a paragraph is not a claim about status.\n */\nexport const boardReconcile: Engine = (t, root, _files) => {\n const rel = t.file as string;\n const text = read(root, rel);\n if (!text) return { findings: [{ message: `board not found at ${rel}` }], examined: 0 };\n if (exempted(text, t.exempt_marker)) return { findings: [], examined: 0 };\n\n const groups: Record<string, string[]> = t.groups ?? {};\n const dir = rel.split('/').slice(0, -1).join('/');\n const findings: Finding[] = [];\n let heading = '';\n let examined = 0;\n\n for (const line of text.split('\\n')) {\n const h = /^##\\s+(.+?)\\s*$/.exec(line);\n if (h) {\n heading = h[1];\n continue;\n }\n if (!line.startsWith('|')) continue;\n\n const link = /^\\|\\s*\\[[^\\]]+\\]\\(([^)]+)\\)/.exec(line);\n if (!link) continue; // separator, header, or an empty `| \u2014 |` placeholder\n\n // An undeclared heading is narrative, not a status group. The board's later\n // sections are prose with their own tables \u2014 \"The first-user path\", closed\n // 2026-08-15, tabulates seven finished items and says so in the heading.\n //\n // Reporting those was this gate's first behaviour and it was wrong: measured\n // 2026-08-16, it produced seven findings against a document that is correct.\n // The plan's requirement that every undeclared heading be reported was aimed\n // at a *typo* hiding rows from the check, and it caught legitimate prose\n // instead. That case is covered exactly, below, by requiring each declared\n // group to appear \u2014 a misspelled `Propsed` makes `Proposed` go missing.\n if (!Object.hasOwn(groups, heading)) continue;\n\n examined++;\n const target = `${dir}/${link[1]}`.replace(/[^/]+\\/\\.\\.\\//g, '');\n const item = read(root, target);\n if (!item) {\n findings.push({ file: rel, message: `row under '${heading}' links to a missing file: ${link[1]}` });\n continue;\n }\n const status = /^status:\\s*(\\S+)/m.exec(item)?.[1] ?? '';\n if (!groups[heading].includes(status)) {\n findings.push({\n file: rel,\n message: `${link[1]} is under '${heading}' but its status is '${status}' (expected ${groups[heading].join(' | ')})`,\n });\n }\n }\n\n // Every declared group must actually appear. This is the typo check: a board\n // whose `Proposed` heading is misspelled would otherwise drop those rows\n // silently, which is exactly what the group map exists to prevent.\n const seen = new Set([...text.matchAll(/^##\\s+(.+?)\\s*$/gm)].map((m) => m[1]));\n for (const g of Object.keys(groups)) {\n if (!seen.has(g)) findings.push({ file: rel, message: `declared group '${g}' has no heading in the board` });\n }\n\n return { findings, examined };\n};\n\n", "import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { execFileSync } from 'node:child_process';\nimport { parse } from 'smol-toml';\nimport type { Manifest } from './types.ts';\nimport { contentHash, emittedFiles, registerGates } from './add.ts';\nimport { resolveParams, substitute, type Params } from './substitute.ts';\nimport { loadRegistry } from './check.ts';\n\nconst SRC = dirname(fileURLToPath(import.meta.url));\n\n/** Bundles from the module catalogue. `init` offers these, not a list of fifteen. */\nexport const PROFILES: Record<string, string[]> = {\n minimal: ['instructions'],\n tracked: ['instructions', 'gates', 'backlog', 'findings', 'adr', 'session'],\n disciplined: ['instructions', 'gates', 'backlog', 'findings', 'adr', 'session', 'ci', 'specs', 'workflows', 'skills', 'audit'],\n hardened: ['instructions', 'gates', 'backlog', 'findings', 'adr', 'session', 'ci', 'specs', 'workflows', 'skills', 'audit', 'release', 'doc-authority'],\n fleet: ['instructions', 'gates', 'backlog', 'findings', 'adr', 'session', 'ci', 'specs', 'workflows', 'skills', 'audit', 'release', 'doc-authority', 'concurrency', 'design-sync'],\n};\n\nexport interface InstallRecord {\n harnesses: string[];\n modules: Record<string, { version: string; params?: Record<string, unknown>; hashes?: Record<string, string>; kept?: { files: string[] } }>;\n}\n\nexport function readRecord(repoRoot: string): InstallRecord | null {\n const p = join(repoRoot, '.ai', 'rungs.toml');\n if (!existsSync(p)) return null;\n try {\n const raw = parse(readFileSync(p, 'utf8')) as any;\n return { harnesses: raw.repo?.harnesses ?? [], modules: raw.modules ?? {} };\n } catch {\n return null;\n }\n}\n\nexport type FileState = 'current' | 'diverged' | 'stale' | 'missing';\n\nexport interface UpgradeItem {\n module: string;\n from: string;\n to: string;\n files: { rel: string; state: FileState }[];\n}\n\n/**\n * Compare what is on disk against both the recorded hash and what the module\n * would emit now. Those two comparisons answer different questions:\n *\n * matches recorded, matches current \u2192 current, nothing to do\n * matches recorded, differs current \u2192 **stale**, ours to replace\n * differs recorded \u2192 **diverged**, theirs; never touched\n *\n * Without the recorded hash the middle two collapse, and upgrade would either\n * clobber deliberate edits or refuse to move anything.\n */\nexport function planUpgrade(repoRoot: string, mods: Manifest[], record: InstallRecord): UpgradeItem[] {\n const params = resolveParams(mods, paramsFrom(record), repoRoot);\n const skillsDir = record.harnesses.includes('claude') ? '.claude/skills' : '.agents/skills';\n const items: UpgradeItem[] = [];\n\n for (const mod of mods) {\n const installed = record.modules[mod.name];\n if (!installed) continue;\n const emitted = emittedFiles(mod, params, skillsDir);\n const files: UpgradeItem['files'] = [];\n const kept = new Set(installed.kept?.files ?? []);\n for (const [rel, wouldEmit] of emitted) {\n if (kept.has(rel)) continue; // never ours; upgrade does not touch it\n const full = join(repoRoot, rel);\n if (!existsSync(full)) {\n files.push({ rel, state: 'missing' });\n continue;\n }\n const onDisk = contentHash(readFileSync(full, 'utf8'));\n const recorded = installed.hashes?.[rel];\n if (onDisk === contentHash(wouldEmit)) files.push({ rel, state: 'current' });\n else if (recorded && onDisk === recorded) files.push({ rel, state: 'stale' });\n else files.push({ rel, state: 'diverged' });\n }\n items.push({ module: mod.name, from: installed.version, to: mod.version, files });\n }\n return items;\n}\n\n/** Applies only `stale` and `missing`. Divergence is a decision, not an error. */\nexport function applyUpgrade(repoRoot: string, mods: Manifest[], record: InstallRecord, plan: UpgradeItem[]) {\n const params = resolveParams(mods, paramsFrom(record), repoRoot);\n const skillsDir = record.harnesses.includes('claude') ? '.claude/skills' : '.agents/skills';\n let written = 0;\n // Only files this run rewrote. A diverged file is not in here, which is what\n // keeps its recorded hash \u2014 and therefore its protection \u2014 intact (F-017).\n const rewritten = new Map<string, Map<string, string>>();\n for (const item of plan) {\n const mod = mods.find((m) => m.name === item.module)!;\n const emitted = emittedFiles(mod, params, skillsDir);\n for (const f of item.files) {\n if (f.state !== 'stale' && f.state !== 'missing') continue;\n const full = join(repoRoot, f.rel);\n const content = emitted.get(f.rel)!;\n mkdirSync(dirname(full), { recursive: true });\n writeFileSync(full, content);\n if (!rewritten.has(mod.name)) rewritten.set(mod.name, new Map());\n rewritten.get(mod.name)!.set(f.rel, contentHash(content));\n written++;\n }\n }\n\n // F-016. Upgrading rewrote a module's **files** and never its **gates**, so a\n // module version that added, removed or renamed one left the registry on the\n // old block and told the user the upgrade succeeded. Reproduced 2026-08-16\n // against a scratch consumer: `session` 1.1.0 \u2192 1.2.0 with a new gate, and\n // `.ai/gates.toml` kept `rungs:begin session@1.1.0` and 20 entries.\n //\n // Registration is by whole merge block, so this fixes removal too \u2014 a gate\n // dropped from a manifest leaves the registry with the block that replaces it.\n // Idempotent, and cheap enough to run for every module in the plan rather than\n // only the ones whose files happened to be stale.\n const upgraded = plan.map((p) => mods.find((m) => m.name === p.module)!).filter(Boolean);\n const gateActions = upgraded.length ? registerGates(upgraded, repoRoot, false) : [];\n\n const recorded = updateRecordAfterUpgrade(\n repoRoot,\n upgraded.map((m) => ({ module: m.name, version: m.version, hashes: rewritten.get(m.name) ?? new Map() })),\n );\n\n return { written, gates: gateActions.length, recorded };\n}\n\n/**\n * Update `.ai/rungs.toml` in place after an upgrade: the version each module\n * moved to, and a new hash for each file this run actually rewrote.\n *\n * **Surgical, and text-level, on purpose.** F-017: `upgrade` left the record\n * naming the old version, so a repo on 1.2.0 described itself to its owner as\n * 1.1.0 and `planUpgrade` offered the same move forever. The obvious fix \u2014\n * calling `writeInstallRecord` \u2014 is worse than the bug: it re-derives the whole\n * record and hashes **every emitted file that exists**, which would stamp our\n * hash onto a file the user had diverged. That file would then match its record\n * and be silently reclassified from `diverged` to `current`, so the next upgrade\n * would overwrite the edit rungs promises never to touch.\n *\n * So: only the lines that must change, and only for files we wrote. Everything\n * else \u2014 the header comment, kept-file lists, and the hash of every file we did\n * not touch \u2014 is left exactly as it was.\n */\nexport function updateRecordAfterUpgrade(\n repoRoot: string,\n updates: { module: string; version: string; hashes: Map<string, string> }[],\n): number {\n const path = join(repoRoot, '.ai', 'rungs.toml');\n if (!existsSync(path) || !updates.length) return 0;\n\n const lines = readFileSync(path, 'utf8').split('\\n');\n const byModule = new Map(updates.map((u) => [u.module, u]));\n let changed = 0;\n let current: { module: string; hashes: boolean } | null = null;\n\n const out: string[] = [];\n for (const line of lines) {\n const header = /^\\[modules\\.([^\\].]+)(\\.[^\\]]+)?\\]/.exec(line);\n if (header) {\n current = byModule.has(header[1]) ? { module: header[1], hashes: header[2] === '.hashes' } : null;\n out.push(line);\n continue;\n }\n\n if (current && !current.hashes && /^version\\s*=/.test(line)) {\n const next = `version = \"${byModule.get(current.module)!.version}\"`;\n if (next !== line) changed++;\n out.push(next);\n continue;\n }\n\n if (current?.hashes) {\n const entry = /^\"([^\"]+)\"\\s*=/.exec(line);\n const replacement = entry && byModule.get(current.module)!.hashes.get(entry[1]);\n if (replacement) {\n out.push(`\"${entry[1]}\" = \"${replacement}\"`);\n changed++;\n continue;\n }\n }\n\n out.push(line);\n }\n\n writeFileSync(path, out.join('\\n'));\n return changed;\n}\n\nfunction paramsFrom(record: InstallRecord): Params {\n const out: Params = {};\n for (const [name, entry] of Object.entries(record.modules)) {\n if (entry.params) out[name] = { ...entry.params };\n }\n return out;\n}\n\n/**\n * ADR-0002's promised exit. Materialises the engines and their tables into the\n * repo and rewrites every declared gate to a `command` gate that runs them.\n *\n * This is a stated obligation, not a nicety: a tool whose checks disappear when\n * you uninstall it is one nobody should adopt, and promising the exit is what\n * makes the no-scripts-in-your-repo default acceptable.\n */\nexport function eject(repoRoot: string, mods: Manifest[], dryRun = false) {\n const dest = join(repoRoot, '.rungs');\n // Only what the runner actually needs, and nothing that imports a package.\n // The first version copied `check.ts` and `manifest.ts` too, which pull in the\n // TOML parser \u2014 so an ejected repo crashed on a module it could not resolve.\n // An exit that does not work is not an exit.\n const engines = ['glob.ts', 'engines.ts', 'engines2.ts'];\n const { gates } = loadRegistry(repoRoot);\n const declared = gates.filter((g) => g.kind === 'declared' && g.table);\n const tables = [...new Set(declared.map((g) => g.table!))];\n\n const actions: string[] = [];\n for (const f of engines) actions.push(`.rungs/${f}`);\n for (const t of tables) actions.push(`.rungs/tables/${t.replace('/', '-').replace(/.toml$/, '.json')}`);\n actions.push('.rungs/run-gate.mjs', '.ai/gates.toml (rewritten to command gates)');\n\n if (dryRun) return { actions, gates: declared.length };\n\n mkdirSync(join(dest, 'tables'), { recursive: true });\n for (const f of engines) copyFileSync(join(SRC, f), join(dest, f));\n\n // Tables are **converted to JSON at eject time**, parsed here with the parser\n // this CLI already has. The ejected repo then needs no TOML dependency at all\n // \u2014 which is the same promise ADR-0002 makes about installation, kept on the\n // way out. Parameters are substituted now, for the same reason.\n const record = readRecord(repoRoot);\n const params = resolveParams(mods, record ? paramsFrom(record) : {}, repoRoot);\n for (const t of tables) {\n const [mod, file] = t.split('/');\n const src = join(SRC, '..', 'modules', mod, 'gates', file);\n if (!existsSync(src)) continue;\n try {\n const parsed = parse(substitute(readFileSync(src, 'utf8'), mod, params));\n writeFileSync(join(dest, 'tables', `${mod}-${file.replace(/\\.toml$/, '.json')}`), JSON.stringify(parsed, null, 2));\n } catch {\n /* an unparseable table is dropped, and its gate will say so when run */\n }\n }\n\n writeFileSync(join(dest, 'run-gate.mjs'), RUNNER);\n writeFileSync(join(dest, 'README.md'), EJECT_README);\n\n const registry = join(repoRoot, '.ai', 'gates.toml');\n let text = readFileSync(registry, 'utf8');\n for (const g of declared) {\n text = text.replace(\n new RegExp(`(id\\\\s*=\\\\s*\"${g.id}\"[\\\\s\\\\S]*?)kind\\\\s*=\\\\s*\"declared\"`),\n `$1kind = \"command\"\\ncommand = \"node .rungs/run-gate.mjs ${g.id}\"`,\n );\n }\n writeFileSync(registry, `${text}\\n# Ejected: gates above run from .rungs/ and no longer need rungs installed.\\n`);\n return { actions, gates: declared.length };\n}\n\nconst RUNNER = `#!/usr/bin/env node\n// Ejected gate runner. Runs one declared gate from the tables in ./tables/.\n// Self-contained: this repo no longer needs rungs installed to run its gates.\nimport { readFileSync } from 'node:fs';\nimport { join, dirname } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { ENGINES } from './engines.ts';\nimport { walk } from './glob.ts';\n\nconst here = dirname(fileURLToPath(import.meta.url));\nconst root = join(here, '..');\nconst id = process.argv[2];\nconst registry = readFileSync(join(root, '.ai', 'gates.toml'), 'utf8');\nconst entry = registry.split('[[gates]]').find((b) => b.includes(\\`id = \"\\${id}\"\\`) || b.includes(\\`id = \"\\${id}\"\\`));\nif (!entry) { console.error(\\`unknown gate \\${id}\\`); process.exit(2); }\n\nconst engine = entry.match(/^engine\\\\s*=\\\\s*\"(.+)\"/m)?.[1];\nconst table = entry.match(/^table\\\\s*=\\\\s*\"(.+)\"/m)?.[1];\nif (!engine || !ENGINES[engine]) { console.error(\\`gate \\${id}: engine '\\${engine}' unavailable\\`); process.exit(2); }\n\n// Tables were converted to JSON when this was ejected, so nothing here needs a\n// TOML parser \u2014 or any dependency at all beyond Node itself.\nconst raw = JSON.parse(readFileSync(join(here, 'tables', table.replace('/', '-').replace(/\\\\.toml$/, '.json')), 'utf8'));\nconst KEYS = { 'file-budget': 'file_budget', 'frontmatter-schema': 'frontmatter_schema', 'link-integrity': 'link_integrity', 'file-population': 'file_population', 'gate-meta': 'gate_meta', 'render-freshness': 'render_freshness', 'register-schema': 'register_schema', 'self-declared-closure': 'self_declared_closure', 'filename-schema': 'filename_schema', 'cross-reference': 'cross_reference', 'git-status-reconcile': 'merged_status', 'computed-claim': 'computed_claim' };\nlet section = raw[KEYS[engine] ?? engine] ?? raw;\nif (Array.isArray(section) && section.some((s) => s?.id)) {\n const mine = section.filter((s) => !s.id || id.includes(s.id));\n if (mine.length) section = mine;\n}\nconst r = ENGINES[engine](section, root, walk(root));\nfor (const f of r.findings) console.error(\\` \\${f.file ? f.file + ': ' : ''}\\${f.message}\\`);\nprocess.exit(r.findings.length ? 1 : 0);\n`;\n\nconst EJECT_README = `# .rungs \u2014 ejected\n\nThe gate engines and tables, materialised into this repo. Every gate in\n\\`.ai/gates.toml\\` now runs as a \\`command\\` gate pointing here, so **this repo no\nlonger needs rungs installed** to run its checks.\n\nWhat you gave up: engine fixes no longer arrive with a CLI version bump. These\nfiles are yours now, including their bugs.\n\nWhat you kept: every gate, every table, and the reason each one exists \u2014 the\n\\`why\\` field travelled with the registry entry, so a gate can still explain\nitself to whoever finds it.\n\nTo go back, delete this directory and re-run \\`rungs add\\`.\n`;\n\n/**\n * Install the merge drivers `.gitattributes` names, and turn on rerere.\n *\n * The `concurrency` module's own gate reports these as missing until this runs,\n * and it was reporting against a command that did not exist \u2014 a module telling\n * a repo to run something rungs had never implemented. A driver named in\n * `.gitattributes` is inert until configured, so a fresh clone silently falls\n * back to git's default merge on files that must never be text-merged.\n */\nexport function setupGit(repoRoot: string, dryRun = false) {\n const attrs = join(repoRoot, '.gitattributes');\n if (!existsSync(attrs)) return { drivers: [] as string[], rerere: false };\n const drivers = [...new Set([...readFileSync(attrs, 'utf8').matchAll(/merge=(rungs-[\\w-]+)/g)].map((m) => m[1]))];\n const done: string[] = [];\n for (const d of drivers) {\n // `ledger` takes the higher counter and keeps both claim comments;\n // `generated` always refuses and prints the regenerate command. Both are\n // implemented as scripts the runner ships, so the config points at rungs.\n const cmd =\n d === 'rungs-generated'\n ? 'node -e \"process.stderr.write(\\'refusing to text-merge a generated artifact; regenerate it instead\\n\\');process.exit(1)\"'\n : 'git merge-file -L ours -L base -L theirs %A %O %B';\n if (!dryRun) {\n try {\n // argv, not a shell string. The `rungs-generated` driver command carries\n // single quotes, a literal `\\n` and `%A %O %B`, and it was being handed\n // to a shell through `JSON.stringify` \u2014 quoting that happens to survive\n // cmd.exe and does not survive bash the same way. The same class of bug\n // as F-033, found in the same sweep.\n execFileSync('git', ['config', `merge.${d}.name`, `rungs ${d.replace('rungs-', '')} driver`], { cwd: repoRoot, stdio: 'pipe' });\n execFileSync('git', ['config', `merge.${d}.driver`, cmd], { cwd: repoRoot, stdio: 'pipe' });\n } catch {\n continue;\n }\n }\n done.push(d);\n }\n let rerere = false;\n if (!dryRun) {\n try {\n execFileSync('git', ['config', 'rerere.enabled', 'true'], { cwd: repoRoot, stdio: 'pipe' });\n rerere = true;\n } catch {\n /* not a git repo */\n }\n }\n return { drivers: done, rerere };\n}\n", "import { ENGINES, type Finding } from './engines.ts';\nimport { loadTable, tableKey } from './check.ts';\nimport type { DetectResult, Manifest } from './types.ts';\n\n/**\n * `doctor` answers a *presence* question \u2014 which of our modules does this repo\n * already have an equivalent of. The question a repo actually arrives with is a\n * *defect* question: which of my agent rules say MUST and have nothing checking\n * them, how many near-identical CI workflows do I have, which topics have two\n * documents claiming authority.\n *\n * Those detectors were already written. They ship as gates inside modules and\n * ran only after installation, over rungs-managed content \u2014 so the analysis was\n * gated behind installing the thing the analysis exists to justify, which is\n * backwards for a tool whose primary case is retrofit (WI-038).\n *\n * Nothing here is new detection. It is the same `ENGINES` table the runner\n * uses, over a registry synthesized in memory from the module manifests rather\n * than read from `.ai/gates.toml`, which an unmanaged repo does not have.\n */\n\nexport interface DetectorFinding {\n module: string;\n gate: string;\n /** The extracted incident behind the gate, from the manifest. */\n why?: string;\n findings: Finding[];\n examined: number;\n}\n\nexport interface ExplainResult {\n reported: DetectorFinding[];\n /** Gates skipped, by reason \u2014 printed, because a silent skip reads as a pass. */\n skipped: { command: number; unimplemented: string[]; undeclared: string[]; errored: { gate: string; message: string }[] };\n /** Modules whose detectors ran at all. */\n scope: string[];\n}\n\ntype EngineTable = Record<string, (t: any, root: string, files: string[]) => { findings: Finding[]; examined: number }>;\n\n/**\n * A `command` gate runs a shell command the *repo* owns. On a repo that never\n * installed rungs there is no registry to own one, but a module can still\n * declare one \u2014 and executing an arbitrary command against somebody else's\n * checkout because they typed a read-only-sounding flag is not a thing this\n * tool gets to do. Skipped, and counted, never run.\n */\nconst isRunnable = (g: Manifest['gates'][number]) => g.kind !== 'command' && !g.trigger && !!g.engine;\n\n/**\n * Which modules' detectors are allowed to run.\n *\n * **Only what the repo already has.** ADR-0004 biased detection signatures\n * toward false negatives; the same bias applies here for a stronger reason \u2014\n * these engines read rungs-shaped inputs, so on a foreign repo a\n * technically-correct finding can still be framed against a convention the repo\n * never adopted. A module the repo has no equivalent of has nothing to check,\n * and running it anyway produces exactly the confident noise that loses an\n * adoption wedge.\n *\n * `paradigm` is excluded too: the repo solves that problem a different way, and\n * measuring their solution against our shape is the same error with a nastier\n * tone.\n */\nexport const IN_SCOPE: ReadonlySet<string> = new Set(['theirs', 'ours-current', 'ours-diverged']);\n\n/**\n * Which declared applicability may run against a repo that is not ours.\n *\n * This was two hard-coded sets of **engine names** in this file, and the\n * knowledge lived nowhere near the gates it governed: adding a gate on\n * `file-population` silently made it foreign-safe, and adding one on a new\n * engine silently made it not, with nothing at either declaration saying so.\n * It is now a required field on each gate \u2014 see `Applicability` in `types.ts`\n * for what the three cases mean and which measurement produced them.\n */\nconst FOREIGN_SAFE: ReadonlySet<string> = new Set(['repo-content']);\n\nexport function explain(\n mods: Manifest[],\n results: DetectResult[],\n repoRoot: string,\n files: string[],\n): ExplainResult {\n return explainWith(ENGINES, mods, results, repoRoot, files);\n}\n\n/**\n * `explain` with the engine table injected, so the scope rules above can be\n * tested without a repo on disk. Those rules are the whole safety argument of\n * this pass; testing them through fifteen real manifests would test the\n * manifests instead.\n */\nexport function explainWith(\n engines: EngineTable,\n mods: Manifest[],\n results: DetectResult[],\n repoRoot: string,\n files: string[],\n): ExplainResult {\n const inScope = results.filter((r) => IN_SCOPE.has(r.state));\n const scope = inScope.map((r) => r.module);\n const stateOf = new Map(inScope.map((r) => [r.module, r.state]));\n const reported: DetectorFinding[] = [];\n const skipped: ExplainResult['skipped'] = { command: 0, unimplemented: [], undeclared: [], errored: [] };\n\n for (const name of scope) {\n const mod = mods.find((m) => m.name === name);\n if (!mod) continue;\n const isOurs = stateOf.get(name) !== 'theirs';\n\n for (const g of mod.gates) {\n if (!isRunnable(g)) {\n if (g.kind === 'command') skipped.command++;\n continue;\n }\n // No default. A gate that has not said whether it can read a foreign repo\n // does not read one, and is named \u2014 silence resolving to \"safe\" is how the\n // 71 mis-framed findings of WI-038's first version happened.\n if (!isOurs) {\n if (!g.applicability) {\n skipped.undeclared.push(g.id);\n continue;\n }\n if (!FOREIGN_SAFE.has(g.applicability)) continue;\n }\n if (!(g.engine! in engines)) {\n // Same rule as the runner: an engine named and missing is an unknown,\n // and an unknown is never reported as clean.\n skipped.unimplemented.push(g.id);\n continue;\n }\n\n const table = loadTable(g.table ? `${mod.name}/${g.table.replace(/^gates\\//, '')}` : undefined, repoRoot);\n if (!table) {\n skipped.errored.push({ gate: g.id, message: `table '${g.table ?? '(none)'}' not found` });\n continue;\n }\n\n try {\n const key = tableKey(g.engine!);\n let section = table[key] ?? table;\n if (Array.isArray(section) && section.some((s: any) => s?.id)) {\n const mine = section.filter((s: any) => !s.id || g.id.includes(s.id));\n if (mine.length) section = mine;\n }\n const r = engines[g.engine!](section, repoRoot, files);\n if (r.findings.length) {\n reported.push({ module: mod.name, gate: g.id, why: g.why, findings: r.findings, examined: r.examined });\n }\n } catch (e: any) {\n // An engine that throws on a foreign repo's shapes is a fact about this\n // pass, not about the repo. Reported as ours, not as their finding.\n skipped.errored.push({ gate: g.id, message: e.message });\n }\n }\n }\n\n return { reported: collapseDuplicates(reported), skipped, scope };\n}\n\n/**\n * Two gate ids that produce the identical finding set are one check reported\n * twice, and on a repo with 112 broken links that is 224 lines of the same\n * thing. `gates-links-resolve` and `gates-paths-exist` currently run the same\n * markdown-link scan \u2014 F-007 in `docs/backlog/FINDINGS.md`, open before this\n * pass existed and unchanged by it.\n *\n * Collapsed here rather than fixed there on purpose: the duplication is a defect\n * in the gate set, this is a defect in *reading* the gate set, and a reporting\n * layer that hides a registry problem is how the registry problem survives. The\n * merged row names both ids, so the duplication stays visible to anyone who\n * looks at the output \u2014 which is the point.\n */\nexport function collapseDuplicates(reported: DetectorFinding[]): DetectorFinding[] {\n const out: DetectorFinding[] = [];\n const seen = new Map<string, DetectorFinding>();\n for (const r of reported) {\n const key = `${r.module} ${r.findings.map((f) => `${f.file ?? ''}|${f.message}`).join('')}`;\n const prior = seen.get(key);\n if (prior) {\n prior.gate = `${prior.gate} + ${r.gate}`;\n continue;\n }\n seen.set(key, r);\n out.push(r);\n }\n return out;\n}\n", "import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';\nimport { dirname, join, relative, resolve, sep } from 'node:path';\nimport { walk } from './glob.ts';\n\n/**\n * `rungs backlog archive` \u2014 move finished items out of `items/` and repoint\n * every link in the repo at their new home.\n *\n * F-015. Three files shipped into **every** consumer repo named this command,\n * two of them saying \"never by hand\", and it did not exist: `rungs backlog`\n * answered *\"unknown command\"*. So the instruction was unfollowable everywhere\n * rungs had ever been installed, and the reason it says *never by hand* is\n * exactly why it could not be worked around \u2014 moving 39 files and rewriting\n * every citation of them is the kind of repo-wide edit that fails silently.\n *\n * The link rewrite is the whole substance of the command. It resolves each\n * link from the citing file's **own** directory rather than pattern-matching\n * text, because the same target is written `items/WI-001-x.md`,\n * `../items/WI-001-x.md` and `WI-001-x.md` depending on who is citing it, and a\n * regex over any one of those spellings silently misses the others.\n */\n\nexport interface ArchiveMove {\n id: string;\n status: string;\n from: string;\n to: string;\n}\n\nexport interface ArchivePlan {\n root: string;\n moves: ArchiveMove[];\n /** Files whose links change, with how many links move in each. */\n rewrites: { file: string; links: number }[];\n /** Items that look finished but are not eligible, with the reason. */\n held: { file: string; reason: string }[];\n}\n\n/** Statuses whose work can no longer change. Mirrors backlog README \u00A78. */\nconst FINISHED = new Set(['done', 'rejected']);\n\nconst field = (text: string, name: string) => text.match(new RegExp(`^${name}:\\\\s*(\\\\S+)`, 'm'))?.[1] ?? '';\n\nconst posix = (p: string) => p.split(sep).join('/');\n\n/** A relative markdown link that could point at a repo file. */\nconst LINK = /\\]\\((?!https?:|#|mailto:)([^)\\s#]+)((?:#[^)\\s]*)?)\\)/g;\n\nexport function planArchive(repoRoot: string, backlogRoot = 'docs/backlog'): ArchivePlan {\n const itemsDir = join(repoRoot, ...backlogRoot.split('/'), 'items');\n const archiveDir = join(repoRoot, ...backlogRoot.split('/'), 'archive');\n const moves: ArchiveMove[] = [];\n const held: ArchivePlan['held'] = [];\n\n const files = walk(repoRoot);\n const items = files.filter((f) => posix(f).startsWith(posix(relative(repoRoot, itemsDir)) + '/') && f.endsWith('.md'));\n\n for (const rel of items) {\n // The **basename**, exactly \u2014 not a suffix of the path. `/TEMPLATE\\.md$/i`\n // also matches any item whose filename ends in `-template.md`, and it did:\n // `WI-010-framework-extraction-template.md` was skipped on every run since\n // this command shipped, so a `done` item stayed in `items/` while the\n // command reported \"nothing to archive\". An anchored regex that is anchored\n // to the wrong end reads as careful and is not.\n const base = posix(rel).split('/').pop()!;\n if (/^(README|TEMPLATE)\\.md$/i.test(base)) continue;\n const text = readFileSync(join(repoRoot, rel), 'utf8');\n const status = field(text, 'status');\n const id = field(text, 'id');\n if (!FINISHED.has(status)) continue;\n\n // An epic whose children are not all finished is still live bookkeeping: it\n // is the thing that says what remains. Moving it would file the index of\n // open work under \"cannot change any more\".\n if (field(text, 'type') === 'epic') {\n const children = (text.match(/^children:\\s*\\[(.*)\\]/m)?.[1] ?? '')\n .split(',')\n .map((s) => s.trim())\n .filter(Boolean);\n // A child that is **already archived** is finished \u2014 that is what being in\n // `archive/` means. Searching only `items/` made every archived child read\n // as unfinished, so an epic whose children had all landed could never be\n // archived and the hold message named five done items as outstanding. The\n // more finished an epic got, the more stuck it became.\n const archived = files.filter((f) => posix(f).startsWith(posix(relative(repoRoot, archiveDir)) + '/') && f.endsWith('.md'));\n const unfinished = children.filter((c) => {\n const f = items.find((i) => i.includes(`${c}-`)) ?? archived.find((i) => i.includes(`${c}-`));\n // Still `!f` \u2192 genuinely unknown, and an unknown holds. A child nobody\n // can find is not evidence that it finished.\n return !f || !FINISHED.has(field(readFileSync(join(repoRoot, f), 'utf8'), 'status'));\n });\n if (unfinished.length) {\n held.push({ file: rel, reason: `epic with unfinished children: ${unfinished.join(', ')}` });\n continue;\n }\n }\n\n // `posix(rel)` first: `walk` yields `/`-separated paths, so splitting on the\n // platform `sep` on Windows never splits and the basename came back as the\n // whole path \u2014 producing `archive/docs/backlog/items/WI-001-\u2026.md`.\n moves.push({\n id,\n status,\n from: rel,\n to: posix(join(relative(repoRoot, archiveDir), posix(rel).split('/').pop()!)),\n });\n }\n\n // Where each moved file ends up, keyed by its absolute old path, so a link can\n // be looked up by what it resolves to rather than by how it was spelled.\n const moved = new Map(moves.map((m) => [resolve(repoRoot, m.from), m.to]));\n const rewrites: ArchivePlan['rewrites'] = [];\n\n for (const rel of files) {\n if (!isRewritable(rel)) continue;\n const links = retargets(repoRoot, rel, moved).length;\n if (links || moved.has(resolve(repoRoot, rel))) rewrites.push({ file: rel, links });\n }\n\n return { root: backlogRoot, moves, rewrites, held };\n}\n\n/**\n * A module's `files/` and `fragments/` are **templates**, not repo content.\n * Their links are relative to wherever the fragment merges into, they carry\n * `{{param}}` tokens, and resolving them here reports every one as broken \u2014\n * which is why `link_integrity.exclude` already skips them. Rewriting them\n * would be worse than reporting them: it would bake this repo's paths into what\n * every consumer repo gets installed.\n */\nfunction isRewritable(rel: string): boolean {\n const p = posix(rel);\n if (!p.endsWith('.md')) return false;\n return !/^modules\\/[^/]+\\/(files|fragments)\\//.test(p) && !p.startsWith('node_modules/');\n}\n\n/**\n * The links in one file that this archive run has to change, and what to.\n *\n * Deliberately **only** links whose target moved, plus \u2014 when the citing file is\n * itself moving \u2014 links that would otherwise break from the new location. The\n * first version compared every link's written form against a freshly computed\n * relative path and counted a difference as a change, which claimed 334 links\n * across 58 files including `AGENTS.md`, `README.md` and module templates. Most\n * of those were equivalent spellings of an unmoved target. Rewriting them would\n * have been a repo-wide reflow disguised as an archive.\n */\nfunction retargets(repoRoot: string, rel: string, moved: Map<string, string>): { href: string; to: string }[] {\n const oldDir = dirname(resolve(repoRoot, rel));\n const selfMoved = moved.get(resolve(repoRoot, rel));\n const newDir = dirname(resolve(repoRoot, selfMoved ?? rel));\n const out: { href: string; to: string }[] = [];\n\n for (const m of readFileSync(join(repoRoot, rel), 'utf8').matchAll(LINK)) {\n const href = m[1];\n if (href.includes('{{')) continue; // a template link, resolved at install\n const target = resolve(oldDir, decodeURIComponent(href));\n const targetMoved = moved.get(target);\n if (!targetMoved && !selfMoved) continue;\n if (!targetMoved && !existsSync(target)) continue; // already broken; not this command's to fix\n const targetNew = targetMoved ? resolve(repoRoot, targetMoved) : target;\n // No `./` prefix. It is never required for a relative markdown link, and\n // adding it rewrites the spelling of paths whose *target* is what changed \u2014\n // turning a one-word diff into a whole-line one across 37 files.\n const to = posix(relative(newDir, targetNew));\n if (to !== posix(href)) out.push({ href, to });\n }\n return out;\n}\n\nexport function applyArchive(repoRoot: string, plan: ArchivePlan): void {\n const moved = new Map(plan.moves.map((m) => [resolve(repoRoot, m.from), m.to]));\n\n // Rewrite before moving. Every path is computed from the plan rather than from\n // the filesystem, so the order is a choice \u2014 and this order means a crash\n // halfway leaves the files still where the links say they are.\n for (const rel of walk(repoRoot)) {\n if (!isRewritable(rel)) continue;\n const edits = retargets(repoRoot, rel, moved);\n if (!edits.length) continue;\n const path = join(repoRoot, rel);\n let text = readFileSync(path, 'utf8');\n // Replace through the same matcher that found them, so a href appearing in\n // prose as well as in a link cannot be hit by a bare string replace.\n text = text.replace(LINK, (whole, href: string, anchor: string) => {\n const edit = edits.find((e) => e.href === href);\n return edit ? `](${edit.to}${anchor})` : whole;\n });\n writeFileSync(path, text);\n }\n\n for (const m of plan.moves) {\n const to = join(repoRoot, ...m.to.split('/'));\n mkdirSync(dirname(to), { recursive: true });\n renameSync(join(repoRoot, m.from), to);\n }\n}\n", "/**\n * The concurrency loop: `session start`, `preflight`, `land`, `worktrees`.\n *\n * These are the four commands the `concurrency` module documented for weeks\n * without any of them existing (F-026). The module is the specification \u2014\n * `modules/concurrency/files/docs/concurrent-sessions.md` \u2014 and the rules they\n * obey are [ADR-0009](../docs/decisions/ADR-0009-rungs-drives-git.md):\n *\n * 1. Verify before you advance. `land` merges onto a scratch ref, gates *that*\n * tree, and only then moves the branch, with a compare-and-swap.\n * 2. Never destroy, only refuse. Nothing here deletes a branch, a worktree or\n * a commit; a refusal parks its work rather than discarding it.\n * 3. Never hold the integration branch. Everything runs from a throwaway\n * worktree, which the module already gates for.\n */\nimport { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync, unlinkSync } from 'node:fs';\nimport { execFileSync } from 'node:child_process';\nimport { hostname } from 'node:os';\nimport { join, resolve, dirname, basename } from 'node:path';\nimport { tmpdir } from 'node:os';\nimport { installedParams } from './check.ts';\n\nexport interface LoopParams {\n integration: string;\n greenRef: string;\n integPrefix: string;\n}\n\nexport function loopParams(root: string): LoopParams {\n const p = (installedParams(root).concurrency ?? {}) as Record<string, unknown>;\n const integration = String(p.integration_branch ?? 'main');\n const greenPrefix = String(p.green_prefix ?? 'green/');\n return {\n integration,\n // The green ref marks the last *verified* merge of the integration branch,\n // so it is prefix + that branch \u2014 not prefix + whatever you are cutting.\n greenRef: `${greenPrefix}${integration}`,\n integPrefix: String(p.integ_prefix ?? 'integ/'),\n };\n}\n\n/** `git`, never through a shell: branch names are user input and contain slashes. */\nexport function git(root: string, args: string[]): string {\n return execFileSync('git', args, { cwd: root, stdio: 'pipe', encoding: 'utf8' }).trim();\n}\n\nfunction gitOk(root: string, args: string[]): boolean {\n try {\n git(root, args);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction revParse(root: string, ref: string): string | null {\n try {\n return git(root, ['rev-parse', '--verify', '--quiet', `${ref}^{commit}`]);\n } catch {\n return null;\n }\n}\n\nexport interface Result {\n ok: boolean;\n lines: string[];\n}\n\n// \u2500\u2500 session start \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/**\n * Cut a branch and a worktree from the last **verified** merge.\n *\n * Falling back to the tip is allowed and is always **stated**. A silent fallback\n * would put the session on top of an unverified merge, which is the one thing\n * the green ref exists to prevent \u2014 and the operator would never know.\n */\nexport function sessionStart(root: string, branch: string, at?: string, dryRun = false): Result {\n const { integration, greenRef } = loopParams(root);\n const lines: string[] = [];\n\n if (!branch) return { ok: false, lines: ['a branch name is required: `rungs session start <branch> [path]`'] };\n if (revParse(root, `refs/heads/${branch}`)) {\n return { ok: false, lines: [`branch '${branch}' already exists \u2014 pick another name, or check out the worktree that holds it`] };\n }\n\n const green = revParse(root, `refs/heads/${greenRef}`);\n const base = green ? greenRef : integration;\n const baseSha = green ?? revParse(root, integration);\n if (!baseSha) return { ok: false, lines: [`neither '${greenRef}' nor '${integration}' resolves \u2014 is this the right repo?`] };\n\n if (green) {\n lines.push(`base ${greenRef} (${baseSha.slice(0, 8)}) \u2014 the last verified merge`);\n } else {\n // Stated, never silent. See the doc comment above.\n lines.push(`no ${greenRef} ref yet \u2014 cutting from the tip of ${integration} (${baseSha.slice(0, 8)}) instead.`);\n lines.push(`That tip has not been verified by a land. The first successful \\`rungs land\\` creates ${greenRef}.`);\n }\n\n const path = resolve(at ?? join(dirname(root), `${basename(root)}-${branch.replace(/[^\\w.-]+/g, '-')}`));\n if (existsSync(path)) return { ok: false, lines: [`${path} already exists \u2014 rungs never writes over a directory it did not create`] };\n\n lines.push(`worktree ${path}`);\n lines.push(`branch ${branch}`);\n if (dryRun) return { ok: true, lines };\n\n try {\n git(root, ['worktree', 'add', '-b', branch, path, baseSha]);\n } catch (e: any) {\n return { ok: false, lines: [...lines, `git refused: ${String(e.stderr ?? e.message).trim().split('\\n').slice(-2).join(' ')}`] };\n }\n return { ok: true, lines };\n}\n\n// \u2500\u2500 preflight \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/**\n * Did the integration branch change files *you* changed?\n *\n * The commit count is the number everyone looks at and it predicts nothing: a\n * hundred commits nowhere near your files are irrelevant, and one commit in the\n * file you are rewriting is the whole story.\n */\nexport function preflight(root: string): Result {\n const { integration } = loopParams(root);\n if (!revParse(root, integration)) return { ok: false, lines: [`'${integration}' does not resolve \u2014 is this the right repo?`] };\n\n let base: string;\n try {\n base = git(root, ['merge-base', 'HEAD', integration]);\n } catch {\n return { ok: false, lines: [`no merge base between HEAD and ${integration}; nothing to compare`] };\n }\n\n const names = (args: string[]) => new Set(git(root, args).split('\\n').map((s) => s.trim()).filter(Boolean));\n const theirs = names(['diff', '--name-only', base, integration]);\n // Committed *and* uncommitted: work you have not committed still collides.\n const mine = new Set([\n ...names(['diff', '--name-only', base, 'HEAD']),\n ...names(['diff', '--name-only', 'HEAD']),\n ...names(['diff', '--name-only', '--cached']),\n ]);\n\n const ahead = Number(git(root, ['rev-list', '--count', `${base}..${integration}`]));\n const overlap = [...mine].filter((f) => theirs.has(f)).sort();\n\n const lines = [\n `${integration} is ${ahead} commit(s) ahead of your base, touching ${theirs.size} file(s).`,\n `You have touched ${mine.size} file(s).`,\n ];\n if (!overlap.length) {\n lines.push('No overlap. The commit count is not the signal \u2014 these two sets not intersecting is.');\n return { ok: true, lines };\n }\n lines.push(`${overlap.length} file(s) changed on both sides:`);\n for (const f of overlap.slice(0, 20)) lines.push(` ${f}`);\n if (overlap.length > 20) lines.push(` \u2026and ${overlap.length - 20} more`);\n lines.push('Merge sooner rather than later. Shared code is a scheduling problem, not a tooling one.');\n return { ok: true, lines };\n}\n\n// \u2500\u2500 land \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\ninterface Lock {\n pid: number;\n host: string;\n started: string;\n branch: string;\n}\n\nfunction lockPath(root: string): string {\n return join(git(root, ['rev-parse', '--git-common-dir']).replace(/^\\.git$/, join(root, '.git')), 'rungs-land.lock');\n}\n\nfunction alive(pid: number): boolean {\n try {\n process.kill(pid, 0);\n return true;\n } catch (e: any) {\n return e?.code === 'EPERM';\n }\n}\n\n/**\n * Merge \u2192 verify the merged tree \u2192 advance with a compare-and-swap.\n *\n * The order is the guarantee. Merging into the branch and testing afterwards has\n * already moved the branch, so a red result is something you now have to undo;\n * here a refusal leaves the integration branch bit-for-bit unchanged and parks\n * the merged tree on a scratch ref for you to fix.\n */\nexport interface GateOutcome {\n pass: number;\n /**\n * Findings per failing gate, not just the gate id.\n *\n * Attributing by **gate** was the first implementation and it was wrong in a\n * way that mattered: `gates-links-resolve` red at the base made that gate a\n * blind spot, so a branch could add its own broken links and land them as\n * \"inherited\". Measured \u2014 a branch adding `./also-missing.md` on top of an\n * already-red link gate landed clean. Attribution is per finding.\n */\n failing: { id: string; findings: string[] }[];\n}\n\nexport type LandRunner = (dir: string, only?: ReadonlySet<string>) => GateOutcome;\n\nexport function land(root: string, branch: string, runner: LandRunner, dryRun = false): Result {\n const { integration, greenRef, integPrefix } = loopParams(root);\n const lines: string[] = [];\n\n if (!branch) return { ok: false, lines: ['a branch name is required: `rungs land <branch>`'] };\n const head = revParse(root, `refs/heads/${branch}`);\n if (!head) return { ok: false, lines: [`branch '${branch}' does not exist`] };\n const before = revParse(root, `refs/heads/${integration}`);\n if (!before) return { ok: false, lines: [`'${integration}' does not resolve`] };\n\n // A real lock: it names its holder and start time, and is taken over if that\n // holder is gone. A lock nobody can break is a lock somebody deletes.\n const lp = lockPath(root);\n if (existsSync(lp)) {\n try {\n const held = JSON.parse(readFileSync(lp, 'utf8')) as Lock;\n if (held.host === hostname() && alive(held.pid)) {\n return {\n ok: false,\n lines: [`another land is in progress: pid ${held.pid} on ${held.host}, landing '${held.branch}' since ${held.started}.`,\n 'Concurrent landing is refused, not silently merged.'],\n };\n }\n lines.push(`taking over a stale lock from pid ${held.pid} (${held.started}) \u2014 that process is gone.`);\n } catch {\n lines.push('an unreadable lock file was replaced.');\n }\n }\n if (dryRun) {\n lines.push(`would merge ${branch} (${head.slice(0, 8)}) onto ${integration} (${before.slice(0, 8)}) via ${integPrefix}${branch}, verify, then advance.`);\n return { ok: true, lines };\n }\n\n const lock: Lock = { pid: process.pid, host: hostname(), started: new Date().toISOString(), branch };\n writeFileSync(lp, JSON.stringify(lock));\n const scratch = mkdtempSync(join(tmpdir(), 'rungs-land-'));\n const parked = `${integPrefix}${branch}`;\n\n try {\n // Rule 3: a throwaway worktree, detached. The integration branch is never\n // checked out \u2014 holding it blocks every other session and does not prevent\n // concurrent landing anyway.\n git(root, ['worktree', 'add', '--detach', scratch, before]);\n\n try {\n git(scratch, ['-c', 'user.email=rungs@localhost', '-c', 'user.name=rungs', 'merge', '--no-ff', '-m', `land ${branch}`, head]);\n } catch (e: any) {\n const conflicts = (() => {\n try {\n return git(scratch, ['diff', '--name-only', '--diff-filter=U']).split('\\n').filter(Boolean);\n } catch {\n return [];\n }\n })();\n lines.push(`merge conflict \u2014 ${integration} is unchanged.`);\n for (const f of conflicts.slice(0, 15)) lines.push(` ${f}`);\n lines.push('Reconcile generated artifacts by regenerating, never by merging text.');\n return { ok: false, lines };\n }\n\n const merged = git(scratch, ['rev-parse', 'HEAD']);\n const res = runner(scratch);\n lines.push(`merged tree ${merged.slice(0, 8)} \u2014 ${res.pass} pass \u00B7 ${res.failing.length} fail`);\n\n if (res.failing.length) {\n // **Attribution.** A gate that is red for reasons you did not cause and\n // cannot fix is a gate you learn to bypass, and a bypassed gate reports\n // nothing. So each failure is re-run against the merge base \u2014 the same\n // scratch worktree, reset back \u2014 and only the ones *this branch* caused\n // block the land.\n //\n // The trade this makes is real and the module states it: a survivable red\n // gate also removes the pressure to fix it. What is supposed to catch that\n // is the ledger's ageing signal, not this command.\n const ids = new Set(res.failing.map((f) => f.id));\n let base: GateOutcome | null = null;\n try {\n git(scratch, ['reset', '--hard', before]);\n base = runner(scratch, ids);\n } catch {\n base = null;\n }\n\n // A gate that did not run at the base cannot be attributed at all. We do\n // not land on an unknown, so that blocks.\n const attributable = base !== null && base.failing.length + base.pass >= ids.size;\n const baseFindings = new Map((base?.failing ?? []).map((f) => [f.id, new Set(f.findings)]));\n\n const introduced: { id: string; findings: string[] }[] = [];\n const inherited: { id: string; findings: string[] }[] = [];\n for (const f of res.failing) {\n const seen = attributable ? baseFindings.get(f.id) ?? new Set<string>() : null;\n // Per finding: a gate already red at the base does not excuse the new\n // violations of it that this branch brought.\n const fresh = seen ? f.findings.filter((x) => !seen.has(x)) : f.findings;\n if (fresh.length) introduced.push({ id: f.id, findings: fresh });\n else inherited.push(f);\n }\n\n for (const f of inherited) {\n lines.push(` inherited ${f.id}${f.findings[0] ? ` \u2014 ${f.findings[0]}` : ''}`);\n }\n for (const f of introduced) {\n lines.push(` INTRODUCED ${f.id}${f.findings[0] ? ` \u2014 ${f.findings[0]}` : ''}`);\n for (const extra of f.findings.slice(1, 4)) lines.push(` ${extra}`);\n }\n if (base === null) {\n lines.push(' The merge base could not be gated, so nothing here is attributable and all of it blocks.');\n } else if (!attributable) {\n lines.push(' Some gates could not be attributed against the merge base, so they block. We do not land on an unknown.');\n }\n\n if (introduced.length) {\n // Rule 2: park it, do not discard it. The merge is the expensive part\n // and throwing it away means doing it again to see the same failure.\n git(root, ['update-ref', `refs/heads/${parked}`, merged]);\n lines.push(\n `${introduced.length} introduced by this branch. ${integration} is unchanged, and the merged tree is parked on '${parked}' \u2014 fix it there and land again.`,\n );\n return { ok: false, lines };\n }\n\n lines.push(\n `${inherited.length} failure(s), all already red on ${integration} before this branch. Landing anyway \u2014 they are not this branch's to fix, and blocking on them is how a gate gets bypassed.`,\n );\n // The scratch worktree is back at the base, so re-point it at the merged\n // commit before the advance reads it.\n git(scratch, ['reset', '--hard', merged]);\n }\n\n // Rule 1: compare-and-swap. If someone else advanced the branch while we\n // verified, this fails and nothing is lost \u2014 their merge is not overwritten.\n try {\n git(root, ['update-ref', `refs/heads/${integration}`, merged, before]);\n } catch {\n git(root, ['update-ref', `refs/heads/${parked}`, merged]);\n return {\n ok: false,\n lines: [...lines,\n `${integration} moved while this land was verifying, so the advance was refused rather than overwriting it.`,\n `Your verified merge is parked on '${parked}'. Re-run \\`rungs land ${branch}\\` to rebuild it on the new tip.`],\n };\n }\n git(root, ['update-ref', `refs/heads/${greenRef}`, merged]);\n lines.push(`${integration} \u2192 ${merged.slice(0, 8)}, and ${greenRef} now marks it verified.`);\n if (revParse(root, `refs/heads/${parked}`)) git(root, ['update-ref', '-d', `refs/heads/${parked}`]);\n return { ok: true, lines };\n } finally {\n // The scratch worktree is ours and only ours, so removing it is not rule 2's\n // \"never destroy\" \u2014 that is about the operator's branches and worktrees.\n try {\n git(root, ['worktree', 'remove', '--force', scratch]);\n } catch {\n rmSync(scratch, { recursive: true, force: true });\n try {\n git(root, ['worktree', 'prune']);\n } catch {\n /* leaving a stale worktree record is not worth failing a successful land */\n }\n }\n try {\n unlinkSync(lp);\n } catch {\n /* already gone */\n }\n }\n}\n\n// \u2500\u2500 worktrees \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nexport interface WorktreeRow {\n path: string;\n branch: string;\n merged: boolean;\n dirty: boolean;\n}\n\n/**\n * What is finished and prunable \u2014 **reports only**.\n *\n * Removing someone else's worktree is not a script's call (ADR-0009 rule 2), and\n * the interesting row is not the clean one. A worktree that is merged *and*\n * dirty holds uncommitted work in a branch that has already landed, which is the\n * shape work actually gets lost in.\n */\nexport function worktrees(root: string): { rows: WorktreeRow[]; integration: string } {\n const { integration } = loopParams(root);\n const out = git(root, ['worktree', 'list', '--porcelain']);\n const rows: WorktreeRow[] = [];\n\n for (const block of out.split('\\n\\n').filter((b) => b.trim())) {\n const path = block.match(/^worktree (.+)$/m)?.[1];\n const branch = block.match(/^branch refs\\/heads\\/(.+)$/m)?.[1];\n if (!path || !branch || branch === integration) continue;\n const merged = gitOk(root, ['merge-base', '--is-ancestor', branch, integration]);\n let dirty = false;\n try {\n dirty = git(path, ['status', '--porcelain']).length > 0;\n } catch {\n dirty = false;\n }\n rows.push({ path, branch, merged, dirty });\n }\n return { rows, integration };\n}\n"],
5
+ "mappings": ";;;AACA,SAAS,iBAAAA,sBAAqB;AAC9B,SAAS,WAAAC,UAAS,QAAAC,QAAM,WAAAC,gBAAe;;;ACFvC,SAAS,eAAAC,cAAa,cAAc,YAAAC,iBAAgB;AACpD,SAAS,QAAAC,aAAY;AACrB,SAAS,aAAa;;;ACFtB,SAAS,aAAa,gBAAgB;AACtC,SAAS,MAAM,UAAU,WAAW;AAU7B,SAAS,aAAa,SAAyB;AACpD,MAAI,MAAM;AACV,WAAS,IAAI,GAAG,IAAI,QAAQ,Q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MAAM,IAAI,WAAW,GAAG,WAAW,KAAK,CAAC;AAAA,EACvF;AAAA,EACA,SAAS;AAIP,UAAM,aAAa,QAAQ,UAAa,QAAQ,UAAU,QAAQ,YAAY,QAAQ;AACtF,QAAI,CAAC,WAAY,SAAQ,IAAI,EAAE,IAAI;AAAA,qBAAwB,GAAG,EAAE,CAAC;AACjE,YAAQ,IAAI,WAAW,CAAC;AACxB,YAAQ,KAAK,aAAa,IAAI,CAAC;AAAA,EACjC;AACF;",
6
+ "names": ["fileURLToPath", "dirname", "join", "resolve", "readdirSync", "statSync", "join", "c", "join", "readdirSync", "statSync", "existsSync", "readFileSync", "join", "readFileSync", "join", "targetPath", "sep", "join", "readFileSync", "c", "markers", "readFileSync", "join", "existsSync", "existsSync", "mkdirSync", "readFileSync", "writeFileSync", "dirname", "join", "join", "readFileSync", "mkdirSync", "dirname", "writeFileSync", "existsSync", "existsSync", "readFileSync", "dirname", "join", "fileURLToPath", "parse", "existsSync", "readFileSync", "join", "dirname", "resolve", "mkdirSync", "writeFileSync", "dirname", "join", "join", "mkdirSync", "dirname", "writeFileSync", "c", "walk", "readFileSync", "join", "readFileSync", "join", "t", "c", "args", "git", "readFileSync", "execFileSync", "join", "read", "readFileSync", "join", "expand", "escapeRe", "exempted", "cells", "c", "execFileSync", "join", "dirname", "read", "readFileSync", "expand", "existsSync", "field", "escapeRe", "resolve", "join", "dirname", "fileURLToPath", "existsSync", "parse", "readFileSync", "existsSync", "mkdirSync", "readFileSync", "writeFileSync", "dirname", "join", "fileURLToPath", "execFileSync", "parse", "dirname", "fileURLToPath", "join", "existsSync", "parse", "readFileSync", "mkdirSync", "writeFileSync", "cmd", "execFileSync", "existsSync", "mkdirSync", "readFileSync", "writeFileSync", "dirname", "join", "relative", "resolve", "sep", "sep", "join", "relative", "readFileSync", "c", "resolve", "dirname", "existsSync", "writeFileSync", "mkdirSync", "existsSync", "mkdtempSync", "readFileSync", "rmSync", "writeFileSync", "execFileSync", "join", "resolve", "dirname", "basename", "tmpdir", "args", "execFileSync", "resolve", "join", "dirname", "basename", "existsSync", "readFileSync", "writeFileSync", "mkdtempSync", "tmpdir", "rmSync", "existsSync", "dirname", "fileURLToPath", "MODULES", "join", "resolve"]
7
7
  }