@sabaiway/agent-workflow-kit 23.4.0 → 23.4.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/CHANGELOG.md CHANGED
@@ -4,6 +4,23 @@ Semantically versioned ([semver](https://semver.org)), newest first. The `versio
4
4
  is the current release. `upgrade` mode reads a project's `docs/ai/.workflow-version` and applies
5
5
  every `migrations/<version>-<slug>.md` newer than it, in semver order.
6
6
 
7
+ ## 23.4.1 — a check that cannot read its input fails instead of passing (AD-232)
8
+
9
+ **`coverage-check --check` now fails when it cannot read the status of its lcov file, and `review-state --check`,
10
+ `review-state --await` and `commit-guard --check` now fail when they cannot list `docs/plans`.** Before, a permission
11
+ error or a disk error there read as "no lcov file" or "no plan in flight", and the check passed while it had seen
12
+ nothing. Each failure names the path and the error code and exits 1. A file or folder that does not exist means
13
+ what it meant before: nothing to check.
14
+
15
+ - **Plain `review-state` and `review-state --json` also exit 1** when `docs/plans` cannot be listed, and the help
16
+ text of `review-state` and `coverage-check` says so.
17
+ - **No check in the kit's `tools/` reads a file when it is loaded.** The kit's list of its own scripts is read when a
18
+ check first needs it, so a failed read reaches the check as its own failure, never as a crash on start. The changelog
19
+ and known-issues rotations still read `package.json` when they load.
20
+ - **The kit's own tests now run every check command against a failure at each kind of read**, and a check that
21
+ passes under one is a failing test. It found three of the four cases above; `commit-guard --check` shares
22
+ review-state's listing of `docs/plans`.
23
+
7
24
  ## 23.4.0 — the judge's model is a setting you choose once (AD-229)
8
25
 
9
26
  **You now pick the Jev version the judge asks in `/agent-workflow-kit bridge-settings`, from the versions the bridge
package/SKILL.md CHANGED
@@ -3,7 +3,7 @@ name: agent-workflow-kit
3
3
  description: Deploy or upgrade a portable AI-agent memory-and-workflow system in any project. Use when the user wants to bootstrap `docs/ai/` + an entry-point `AGENTS.md` (+ `CLAUDE.md` alias) + cap/archive/index enforcement in a new or existing repo, set up the Memory Map and session protocols, install the docs-rotation pre-commit hook, or run `/agent-workflow-kit` / `/agent-workflow-kit upgrade`. Triggers on phrases like "set up the memory system", "deploy the AI workflow here", "bootstrap docs/ai", "upgrade the workflow". New to the epic, story and task tier? Run `/agent-workflow-kit tier`. A typed decision with a confidence from Jev? Run `/agent-workflow-kit jev`.
4
4
  disable-model-invocation: true
5
5
  metadata:
6
- version: '23.4.0'
6
+ version: '23.4.1'
7
7
  ---
8
8
 
9
9
  # agent-workflow-kit
package/capability.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "schema": 1,
4
4
  "name": "agent-workflow-kit",
5
5
  "kind": "composition-root",
6
- "version": "23.4.0",
6
+ "version": "23.4.1",
7
7
  "provides": [],
8
8
  "roles": {},
9
9
  "detect": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sabaiway/agent-workflow-kit",
3
- "version": "23.4.0",
3
+ "version": "23.4.1",
4
4
  "description": "Portable, cross-agent memory & workflow for AI coding agents — Claude Code, Codex, Cursor, Devin Desktop. One command deploys an AGENTS.md entry point + docs/ai context with cap/archive/index enforcement into any repo.",
5
5
  "keywords": [
6
6
  "ai-agents",
@@ -55,6 +55,7 @@
55
55
  "!tools/**/*.test.mjs",
56
56
  "!tools/manifest/fixtures/**",
57
57
  "!tools/project-rules/fixtures/**",
58
+ "!tools/checker-verdict/**",
58
59
  "!references/scripts/**/*.test.mjs",
59
60
  "!references/scripts/archives/index.mjs",
60
61
  "!references/scripts/test-support/**"
@@ -7,7 +7,7 @@ The **final-run checker** (strip-the-kit D3(c)+(d)) — two deterministic arms o
7
7
  Run `node ${CLAUDE_SKILL_DIR}/tools/coverage-check.mjs --check [--cwd <dir>]`:
8
8
 
9
9
  0. **Attestation precondition (the provenance arm).** An lcov on disk carries no evidence of the tree it came from, so reading one and issuing a verdict certifies whatever happens to be there — the false GREEN direction is the dangerous one, because a line appended AFTER the suite ran has no `DA` entry and therefore reads non-executable ("nothing to cover"). Provenance is a CONSEQUENCE in exactly one context: a `run-gates --final` run deletes the artifact before any gate spawns. That runner mints a random nonce and writes `final-start.attempt` as a ONE-WAY COMMITMENT over `{nonce, tree fingerprint, base}`; the raw nonce rides the environment to this child, which recomputes the commitment and requires the record to carry it. Neither half suffices alone — a bare nonce is unverifiable, a persisted attempt id is reconstructible from public repo state — and the commitment is also the only place the BASE is bound, since no record stores it. The raw nonce is stripped from the red-proof probe environment so no descendant retains a live capability. `attested=` states whether a coverage VERDICT was ISSUED — pass **or** fail — never whether coverage passed: a valid handshake over an lcov that lists uncovered lines still reads `attested=yes` and still exits 1. Outcomes: **attested** → the coverage verdict is issued; **no handshake** → `attested=no` + `NO VERDICT` (exit 0, findings still printed, uncovered lines still exit 1 — the findings contract is unchanged); **a valid handshake over a run that read NO lcov BYTES** (the file is absent, or the path was refused as a non-regular file) → `attested=no` + `NO VERDICT`: the run owned the artifact's lifetime and read nothing, so it certifies NOTHING — reading `yes` there would be the false green this arm exists to close, one layer up. The predicate is the consumed bytes (`lcov-sha256` is a digest, not `none`), never the skip flag, so a refused path can never attest either. The two halves are independent: WITHHOLDING the verdict never changes an exit code — an absent file stays exit 0 (the loud `skipped-no-lcov`), and the refused non-regular path keeps its OWN fail-closed exit 1; **a handshake describing another tree or matching no recorded attempt** → `REFUSED` (exit 1), never a verdict in either direction. One fully anchored `coverage-check: attested=<yes|no>` machine line rides every run, on the same exactly-once contract as the sha line — and a withheld verdict TRAVELS: `run-gates` carries it as `coverage=not-run` on the summary line and names it on the checker's table row, and `core-evidence summary` never renders an unqualified GREEN over a final record that consumed no lcov. Stated residuals, both named rather than implied: (a) an operator who runs both processes can forge the store or the code — the kit's standing self-discipline posture, not a security boundary; (b) **"the run owns the artifact" is exclusive by CONVENTION over the fixed path, not enforced** — a writer outside the run (a second `run-gates`, a hand-run `--only unit-tests`, an orphaned test process) can place foreign evidence between the deletion and the checker's read, and every check then agrees. Closing (b) needs an attempt-unique artifact path, which the runner can name but the declared producer cmd must reference — queued as LCOV-EXCLUSIVE-OWNERSHIP. What this arm removes is the false green that needs no second process and nobody trying: evidence that predates the edit.
10
- 1. **Coverage arm (D3(d)):** every CHANGED executable Node line (`.mjs`/`.cjs`/`.js`, tracked working-vs-HEAD changes + untracked-not-ignored files) must be covered — uncovered lines are LISTED `file:line` and fail; a changed file ABSENT from the lcov map is a file-level red (never "non-executable" by silence); changed out-of-domain files (e.g. `.sh`) and unsupported-source files (e.g. `.ts`) are LISTED — the claim is narrowed honestly, not widened. NO lcov file at the path = a LOUD `skipped-no-lcov` (exit 0, stated — produce the file via the unit-tests gate's lcov reporters); a symlink at the path is a refusal (lstat, no-follow).
10
+ 1. **Coverage arm (D3(d)):** every CHANGED executable Node line (`.mjs`/`.cjs`/`.js`, tracked working-vs-HEAD changes + untracked-not-ignored files) must be covered — uncovered lines are LISTED `file:line` and fail; a changed file ABSENT from the lcov map is a file-level red (never "non-executable" by silence); changed out-of-domain files (e.g. `.sh`) and unsupported-source files (e.g. `.ts`) are LISTED — the claim is narrowed honestly, not widened. NO lcov file at the path (ENOENT) = a LOUD `skipped-no-lcov` (exit 0, stated — produce the file via the unit-tests gate's lcov reporters); any other status failure exits 1 naming the path and the code where it has one; a symlink at the path is a refusal (lstat, no-follow).
11
11
  2. **Red-proof arm (D3(c)):** every authoritative current-base `red-proof` declaration must verify — the bound test file exists (deleted fails), its content sha256 matches the declaration (custody), the test resolves (zero-match fails) and runs green N/N NOW, and the declaration's pre-fix fingerprint differs from the current tree (equal = reuse/forgery, refused). A malformed evidence store fails CLOSED.
12
12
 
13
13
  Wire it as the LAST declared gate in `docs/ai/gates.json` — `run-gates --final` REFUSES a declaration where the canonical coverage-check gate is not last (nothing may run after the checker consumed the lcov) or where its cmd is not ONE plain invocation of the kit's OWN tool (a masked form or a lookalike path never counts).
@@ -24,7 +24,7 @@ import { planFor } from './jev-skill.mjs';
24
24
  import { SKILL_FILES, claudeDirOf, skillAccepted, skillState, skillTargets } from './jev-facts.mjs';
25
25
  import { findOnPath } from './detect-backends.mjs';
26
26
  import { consoleArgv } from './write-lanes.mjs';
27
- import { DEPLOYED_SCRIPTS, INSTALLER_REL, formatPlan, planGitHooks } from './git-hooks.mjs';
27
+ import { readDeployedScripts, INSTALLER_REL, formatPlan, planGitHooks } from './git-hooks.mjs';
28
28
  import { ATTRIBUTION_HIDDEN, ATTRIBUTION_KEY, writeAttribution } from './attribution.mjs';
29
29
  import { globalRemovalOf, planGlobalRemoval } from './hide-footprint.mjs';
30
30
  import { isDirectRun } from './direct-run.mjs';
@@ -234,7 +234,7 @@ export const scopeOf = (variant, facts, deps = {}) => {
234
234
  }
235
235
  if (GIT_VARIANTS.includes(variant)) {
236
236
  // Each deployed path under the kit folder, and each folder on its way below the root.
237
- const copies = variant === 'hook-checks' ? [] : DEPLOYED_SCRIPTS.map(({ deployed }) => join(facts.root, deployed));
237
+ const copies = variant === 'hook-checks' ? [] : readDeployedScripts().map(({ deployed }) => join(facts.root, deployed));
238
238
  directories.splice(0);
239
239
  for (const path of copies) {
240
240
  for (let at = dirname(path); at !== facts.root && covers(facts.root, at) && !directories.includes(at); at = dirname(at)) directories.push(at);
@@ -73,11 +73,12 @@ const checkCoverage = ({ rootTop, lcovPath }) => {
73
73
  let st = null;
74
74
  try {
75
75
  st = lstatSync(lcovPath);
76
- } catch {
77
- st = null;
78
- }
79
- if (st == null) {
80
- return { failures, notes: [`skipped-no-lcov: no lcov file at ${lcovPath} — NO coverage check ran (produce it via the declared unit-tests gate cmd's lcov reporters)`], skipped: true, lcovSha256: null };
76
+ } catch (error) {
77
+ if (error?.code === 'ENOENT') {
78
+ return { failures, notes: [`skipped-no-lcov: no lcov file at ${lcovPath} — NO coverage check ran (produce it via the declared unit-tests gate cmd's lcov reporters)`], skipped: true, lcovSha256: null };
79
+ }
80
+ failures.push(`${lcovPath}: status could not be read (${error?.code ?? 'fs error'})`);
81
+ return { failures, notes, skipped: false, lcovSha256: null };
81
82
  }
82
83
  if (!st.isFile()) {
83
84
  failures.push(`${lcovPath}: not a regular file (a symlink/device is never read — fail closed)`);
@@ -318,9 +319,9 @@ deleted fresh by run-gates --final), lists uncovered CHANGED executable Node lin
318
319
  lists changed out-of-domain files (the coverage claim is narrowed to Node lines), and VERIFIES
319
320
  every current-base red-proof record: bound test present, content hash unchanged, green N/N
320
321
  (AW_CORE_EVIDENCE_RERUNS, default 3), pre-fix fingerprint differing from the current tree.
321
- An absent lcov file is a LOUD skipped-no-lcov (exit 0 — NO coverage check ran, stated); a
322
- symlinked lcov path, an uncovered line, a broken red-proof obligation, or a malformed evidence
323
- store fails (exit 1).
322
+ An absent lcov file (ENOENT) is a LOUD skipped-no-lcov (exit 0 — NO coverage check ran, stated).
323
+ Any other lcov status failure, a symlinked lcov path, an uncovered line, a broken red-proof
324
+ obligation, or a malformed evidence store fails (exit 1).
324
325
 
325
326
  A coverage VERDICT is issued ONLY inside the run that owns the artifact's lifetime: run-gates
326
327
  --final deletes the lcov before any gate spawns and hands this checker an attestation context
@@ -3,11 +3,11 @@ import { lstatSync, readFileSync, readdirSync, unlinkSync } from 'node:fs';
3
3
  import { join, posix } from 'node:path';
4
4
  import { lstatNoFollow } from '../atomic-write.mjs';
5
5
  import { stripGitLocationEnv } from '../git-env.mjs';
6
- import { DEPLOYED_SCRIPTS, KIT_SCRIPTS_DIR, SCRIPTS_DIR } from '../node-evidence.mjs';
6
+ import { readDeployedScripts, KIT_SCRIPTS_DIR, SCRIPTS_DIR } from '../node-evidence.mjs';
7
7
  import { PRIOR_FILES, SCRIPT_PRIORS, digestOf } from '../script-priors.mjs';
8
8
 
9
- const DEPLOYED_BY_NAME = new Map(DEPLOYED_SCRIPTS.map((entry) => [posix.basename(entry.path), entry]));
10
- const COMMAND = DEPLOYED_SCRIPTS.find((entry) => !entry.module);
9
+ const readDeployedByName = () => new Map(readDeployedScripts().map((entry) => [posix.basename(entry.path), entry]));
10
+ const readCommand = () => readDeployedScripts().find((entry) => !entry.module);
11
11
  const normalizeBody = (bytes) => String(bytes).replaceAll('\r\n', '\n');
12
12
  const flatPath = (name) => `${SCRIPTS_DIR}/${name}`;
13
13
  const isRegular = (cwd, rel, lstat) => lstatNoFollow(join(cwd, rel), lstat)?.isFile() === true;
@@ -16,7 +16,7 @@ const errorCode = (error) => error.code ?? error.message;
16
16
  export const isRetiredKitScript = (name, bytes, kitRoot, read = readFileSync) => {
17
17
  const digest = digestOf(normalizeBody(bytes));
18
18
  if (SCRIPT_PRIORS.some((row) => row.file === name && row.digest === digest)) return true;
19
- const entry = DEPLOYED_BY_NAME.get(name);
19
+ const entry = readDeployedByName().get(name);
20
20
  return Boolean(entry && digest === digestOf(normalizeBody(read(join(kitRoot, entry.bundled)))));
21
21
  };
22
22
 
@@ -56,7 +56,7 @@ export const retireScripts = ({ cwd, kitRoot, dryRun = false, deps = {}, placedS
56
56
  const lstat = deps.lstat ?? lstatSync;
57
57
  const read = deps.readFile ?? readFileSync;
58
58
  const standing = (rel) => (dryRun && placedScripts.includes(rel)) || isRegular(cwd, rel, lstat);
59
- const commandStands = standing(COMMAND.deployed);
59
+ const commandStands = standing(readCommand().deployed);
60
60
  const classified = new Map();
61
61
  const removed = [];
62
62
  const lines = [];
@@ -79,8 +79,8 @@ export const retireScripts = ({ cwd, kitRoot, dryRun = false, deps = {}, placedS
79
79
  if (owned === null) continue;
80
80
  classified.set(name, owned ? 'kit' : 'foreign');
81
81
  if (!owned) { lines.push(foreignLine(name)); continue; }
82
- const replacement = DEPLOYED_BY_NAME.get(name);
83
- const missing = !commandStands ? COMMAND.deployed : replacement && !standing(replacement.deployed) ? replacement.deployed : null;
82
+ const replacement = readDeployedByName().get(name);
83
+ const missing = !commandStands ? readCommand().deployed : replacement && !standing(replacement.deployed) ? replacement.deployed : null;
84
84
  if (missing) { lines.push(keptLine(name, missing, dryRun)); continue; }
85
85
  if (!dryRun) {
86
86
  try {
@@ -19,7 +19,7 @@ import { lstatSync, readFileSync } from 'node:fs';
19
19
  import { join, posix } from 'node:path';
20
20
  import { lstatNoFollow, writeContainedFileAtomic, writeProjectFileCreateOnly } from '../atomic-write.mjs';
21
21
  import { bundledImportsOf, composeFailure, composeOutcome, dependenciesFirst, nodeEvidenceRefusal, probeSeedTarget, tmpNote } from '../ensure-ops.mjs';
22
- import { DEPLOYED_SCRIPTS, INSTALLER_REL, KIT_SCRIPTS_DIR, SCRIPTS_DIR } from '../node-evidence.mjs';
22
+ import { readDeployedScripts, INSTALLER_REL, KIT_SCRIPTS_DIR, SCRIPTS_DIR } from '../node-evidence.mjs';
23
23
  import { SCRIPT_PRIORS, classifyDeployedScript } from '../script-priors.mjs';
24
24
  import { VEHICLES_REL } from '../vehicle-settings.mjs';
25
25
  import { retireScripts } from './retired.mjs';
@@ -34,10 +34,6 @@ export const HOOK_CHANNEL = '.claude/hooks/<name>.local.mjs';
34
34
  const ROTATOR = 'archives/archive-decisions.mjs';
35
35
  // The family: every deployed entry outside the specs op's files (its three modules and the command), in manifest order.
36
36
  const SPECS_MODULES = ['spec-schema', 'docs-size', 'test-reporter'];
37
- const FAMILY = DEPLOYED_SCRIPTS.filter((e) => e.module && !SPECS_MODULES.includes(e.module));
38
- // The manifest paths a run of a component that is not accepted judges: the rotator and what it loads.
39
- export const SEED_NAMES = Object.freeze(FAMILY.filter((e) => e.seed).map((e) => e.path));
40
- const FOLDERS = [...new Set([SCRIPTS_DIR, KIT_SCRIPTS_DIR, ...FAMILY.map((e) => posix.dirname(e.deployed))])];
41
37
 
42
38
  const causeOf = (err) => String((err && err.message) || err);
43
39
  const kindOfDir = (st) => (st.isSymbolicLink() ? 'a symlink' : st.isFile() ? 'a regular file' : 'not a directory');
@@ -49,8 +45,9 @@ const wrongKind = (rel, kind) => composeFailure(OP, 'wrong-node-kind', `${rel}:
49
45
  const inWriteOrder = (files) => [...files.filter((f) => f.rel === INSTALLER_REL), ...dependenciesFirst(files.filter((f) => f.rel !== INSTALLER_REL))];
50
46
 
51
47
  // Each folder on the way, lstat-ed without following a link: → { refusal } | {}.
52
- const surveyFolders = (cwd, lstat) => {
53
- for (const rel of FOLDERS) {
48
+ const surveyFolders = (cwd, family, lstat) => {
49
+ const folders = [...new Set([SCRIPTS_DIR, KIT_SCRIPTS_DIR, ...family.map((e) => posix.dirname(e.deployed))])];
50
+ for (const rel of folders) {
54
51
  const st = lstatNoFollow(join(cwd, rel), lstat);
55
52
  if (st !== null && (!st.isDirectory() || st.isSymbolicLink())) return { refusal: wrongKind(`${rel}/`, kindOfDir(st)) };
56
53
  }
@@ -60,13 +57,15 @@ const surveyFolders = (cwd, lstat) => {
60
57
  // → { refusal } | { files, accepted }. A family path of another node kind is judged before the
61
58
  // component, so a linked family file is never placed over.
62
59
  const survey = ({ cwd, kitRoot, deps, read, lstat }) => {
63
- const folders = surveyFolders(cwd, lstat);
60
+ const family = readDeployedScripts().filter((e) => e.module && !SPECS_MODULES.includes(e.module));
61
+ const seedNames = family.filter((e) => e.seed).map((e) => e.path);
62
+ const folders = surveyFolders(cwd, family, lstat);
64
63
  if (folders.refusal) return folders;
65
- const probes = FAMILY.map((e) => ({ path: e.path, rel: e.deployed, bundled: e.bundled, probe: probeSeedTarget(join(cwd, e.deployed), lstat) }));
64
+ const probes = family.map((e) => ({ path: e.path, rel: e.deployed, bundled: e.bundled, probe: probeSeedTarget(join(cwd, e.deployed), lstat) }));
66
65
  const wrong = probes.find((f) => f.probe.wrongKind);
67
66
  if (wrong) return { refusal: wrongKind(wrong.rel, wrong.probe.wrongKind) };
68
67
  const flatInstaller = probeSeedTarget(join(cwd, SCRIPTS_DIR, posix.basename(INSTALLER_REL)), lstat);
69
- const accepted = probes.some((f) => f.probe.present && !SEED_NAMES.includes(f.path)) || (flatInstaller.present && !flatInstaller.wrongKind);
68
+ const accepted = probes.some((f) => f.probe.present && !seedNames.includes(f.path)) || (flatInstaller.present && !flatInstaller.wrongKind);
70
69
  const byPath = new Map();
71
70
  for (const f of probes) {
72
71
  try {
@@ -76,7 +75,7 @@ const survey = ({ cwd, kitRoot, deps, read, lstat }) => {
76
75
  return { refusal: composeFailure(OP, 'bundle-unreadable', `${f.rel}: the bundled script could not be read, so nothing was written — reinstall the kit. ${causeOf(err)}`) };
77
76
  }
78
77
  }
79
- const files = inWriteOrder([...byPath.values()]).filter((f) => accepted || SEED_NAMES.includes(f.path)).map(({ path, rel, bundle, probe }) => {
78
+ const files = inWriteOrder([...byPath.values()]).filter((f) => accepted || seedNames.includes(f.path)).map(({ path, rel, bundle, probe }) => {
80
79
  const bytes = probe.present ? read(join(cwd, rel)) : undefined;
81
80
  return { path, rel, bundle, state: probe.present ? classifyDeployedScript(bytes, path, bundle, deps.priors ?? SCRIPT_PRIORS) : 'absent' };
82
81
  });
@@ -36,7 +36,7 @@ import { GATES_REL } from './gates-declaration.mjs';
36
36
  import { AUTONOMY_REL } from './autonomy-config.mjs';
37
37
  import { VEHICLES_REL } from './vehicle-settings.mjs';
38
38
  import { ENSURE_TOKENS, FAILURE_CAUSES } from './ensure-vocabulary.mjs';
39
- import { DEPLOYED_SCRIPTS, NODE_EVIDENCE, describeNodeProbes, probeNodeEvidence } from './node-evidence.mjs';
39
+ import { readDeployedScripts, NODE_EVIDENCE, describeNodeProbes, probeNodeEvidence } from './node-evidence.mjs';
40
40
  import { classifyDeployedScript } from './script-priors.mjs';
41
41
  import { parseFrontmatter } from '../references/scripts/docs-size/index.mjs';
42
42
 
@@ -233,7 +233,7 @@ export const nodeEvidenceRefusal = (op, cwd, lstat) => {
233
233
  const INDEX_REL = 'docs/ai/index.md';
234
234
  // The docs checker is the docs-size module's one deployed entry: bundled, it is the generator; deployed,
235
235
  // the kept probe. A flat scripts/check-docs-size.mjs is no deployed checker (story S4 reads it).
236
- const CHECKER = DEPLOYED_SCRIPTS.find(({ module }) => module === 'docs-size');
236
+ const readChecker = () => readDeployedScripts().find(({ module }) => module === 'docs-size');
237
237
  const ENSURE_INDEX_OUTCOME = /^ensure-index: (regenerated|already-current)\b/m;
238
238
  const ENSURE_INDEX_REFUSAL = /^ensure-index: (write-refused|probe-failed)\b/m;
239
239
  // The probe has no machine line, so its two ANSWERS are matched against the canonical sentences it
@@ -249,21 +249,21 @@ const describeExit = (result) => (result.signal ? `on signal ${result.signal}` :
249
249
  const bothStreams = (result) => `${String(result.stdout ?? '')}${String(result.stderr ?? '')}`.trim();
250
250
  const describeExitWithOutput = (result, subject = 'it') => `${subject} exited ${describeExit(result)}${bothStreams(result) ? `: ${bothStreams(result)}` : ''}`;
251
251
 
252
- const KEPT_JUDGE = `the project's own checker (${CHECKER.deployed} --check-index)`;
253
- const KEPT_FITS = `in sync under ${KEPT_JUDGE} and within the maxLines it stamps`;
252
+ const describeKeptJudge = () => `the project's own checker (${readChecker().deployed} --check-index)`;
253
+ const describeKeptFits = () => `in sync under ${describeKeptJudge()} and within the maxLines it stamps`;
254
254
  const KEPT_ROUTE = "the spec layer's write of the bundled modules the project's hook loads, then this step again";
255
255
  const KEPT_PROBE_TIMEOUT_MS = 30_000;
256
256
  const countLines = (text) => text.split('\n').length - (text.endsWith('\n') ? 1 : 0);
257
257
  const readStampedCap = (text) => { const value = parseFrontmatter(text)?.maxLines; const cap = value ? Number(value) : NaN; return Number.isNaN(cap) ? undefined : cap; };
258
258
 
259
- const DEPLOYED_BY_PATH = new Map(DEPLOYED_SCRIPTS.map((entry) => [entry.path, entry]));
259
+ const readDeployedByPath = () => new Map(readDeployedScripts().map((entry) => [entry.path, entry]));
260
260
  const RELATIVE_IMPORT = /(?:\bfrom\s*|\bimport\s*\(?\s*)['"](\.{1,2}\/[^'"]+)['"]/g;
261
261
  const pathIn = (root, rel) => join(root, ...rel.split('/'));
262
262
 
263
263
  // The one reading of the family's bundled imports, shared by the index, scripts and specs ops: the deployed
264
264
  // manifest paths `bundle` (the bytes at manifest path `path`) imports by a relative specifier.
265
265
  export const bundledImportsOf = (path, bundle) => [...String(bundle).matchAll(RELATIVE_IMPORT)]
266
- .map(([, spec]) => posix.join(posix.dirname(path), spec)).filter((dep) => DEPLOYED_BY_PATH.has(dep));
266
+ .map(([, spec]) => posix.join(posix.dirname(path), spec)).filter((dep) => readDeployedByPath().has(dep));
267
267
  // Each of `files` ({ path, imports }) after every one of them it imports, by manifest path in code-unit order
268
268
  // otherwise, so each file a run leaves loads. A cycle is a broken bundle, never a silent order.
269
269
  export const dependenciesFirst = (files) => {
@@ -281,10 +281,10 @@ export const dependenciesFirst = (files) => {
281
281
  // The modules the project's hook loads, the checker first: the deployed files of the docs-size and
282
282
  // spec-schema modules, and the shared files the checker reaches through its bundled relative imports.
283
283
  const hookModulesOf = (bundleOf) => {
284
- const reached = new Set([CHECKER.path]);
285
- for (const path of reached) for (const dep of bundledImportsOf(path, bundleOf(DEPLOYED_BY_PATH.get(path)).bytes ?? '')) reached.add(dep);
284
+ const reached = new Set([readChecker().path]);
285
+ for (const path of reached) for (const dep of bundledImportsOf(path, bundleOf(readDeployedByPath().get(path)).bytes ?? '')) reached.add(dep);
286
286
  const loaded = ({ module, path }) => module === 'docs-size' || module === 'spec-schema' || (module === 'shared' && reached.has(path));
287
- return [CHECKER, ...DEPLOYED_SCRIPTS.filter((entry) => entry !== CHECKER && loaded(entry))];
287
+ return [readChecker(), ...readDeployedScripts().filter((entry) => entry !== readChecker() && loaded(entry))];
288
288
  };
289
289
 
290
290
  // A regular file where a folder on the way belongs (ENOTDIR) holds no module.
@@ -293,12 +293,12 @@ const probeHookModule = (cwd, entry, lstat) => { try { return probeSeedTarget(pa
293
293
  // → one { rel, state } per hook module: absent, wrong-kind, bundle-unreadable or the classifier's word.
294
294
  // No deployed checker → that one entry, absent; every kind is probed before any project file is read.
295
295
  const surveyHook = (cwd, kitRoot, read, lstat) => {
296
- const checker = probeHookModule(cwd, CHECKER, lstat);
297
- if (checker.wrongKind || !checker.present) return [{ rel: CHECKER.deployed, state: checker.wrongKind ? 'wrong-kind' : 'absent', wrongKind: checker.wrongKind }];
296
+ const checker = probeHookModule(cwd, readChecker(), lstat);
297
+ if (checker.wrongKind || !checker.present) return [{ rel: readChecker().deployed, state: checker.wrongKind ? 'wrong-kind' : 'absent', wrongKind: checker.wrongKind }];
298
298
  const bundles = new Map();
299
299
  const readBundle = (entry) => { try { return { bytes: read(pathIn(kitRoot, entry.bundled)) }; } catch (err) { return { error: causeOf(err) }; } };
300
300
  const bundleOf = (entry) => (bundles.has(entry.path) ? bundles : bundles.set(entry.path, readBundle(entry))).get(entry.path);
301
- const probes = hookModulesOf(bundleOf).map((entry) => ({ entry, rel: entry.deployed, probe: entry === CHECKER ? checker : probeHookModule(cwd, entry, lstat) }));
301
+ const probes = hookModulesOf(bundleOf).map((entry) => ({ entry, rel: entry.deployed, probe: entry === readChecker() ? checker : probeHookModule(cwd, entry, lstat) }));
302
302
  const wrong = probes.find(({ probe }) => probe.wrongKind);
303
303
  if (wrong) return [{ rel: wrong.rel, state: 'wrong-kind', wrongKind: wrong.probe.wrongKind }];
304
304
  return probes.map(({ entry, rel, probe }) => {
@@ -310,7 +310,7 @@ const surveyHook = (cwd, kitRoot, read, lstat) => {
310
310
  };
311
311
 
312
312
  const judgeKept = ({ cwd, spawn, read, lstat, deps }) => {
313
- const result = spawn(process.execPath, [pathIn(cwd, CHECKER.deployed), '--check-index'], { cwd, encoding: 'utf8', timeout: deps.keptProbeTimeoutMs ?? KEPT_PROBE_TIMEOUT_MS, killSignal: 'SIGKILL' });
313
+ const result = spawn(process.execPath, [pathIn(cwd, readChecker().deployed), '--check-index'], { cwd, encoding: 'utf8', timeout: deps.keptProbeTimeoutMs ?? KEPT_PROBE_TIMEOUT_MS, killSignal: 'SIGKILL' });
314
314
  if (result.error) return { error: `${causeOf(result.error)}${result.signal ? `, killed on signal ${result.signal}` : ''}` };
315
315
  if (result.status !== 0) return { accepted: false, said: describeExitWithOutput(result), half: 'its index check' };
316
316
  const text = lstatNoFollow(join(cwd, INDEX_REL), lstat)?.isFile() ? String(read(join(cwd, INDEX_REL), 'utf8')) : null;
@@ -340,15 +340,15 @@ const putBackIndex = (cwd, found, deps) => {
340
340
 
341
341
  const ensureKeptIndex = ({ cwd, drive, spawn, read, lstat, deps }) => {
342
342
  const judge = () => judgeKept({ cwd, spawn, read, lstat, deps });
343
- const reportUnanswered = (verdict, after) => loud('index', 'index-probe-failed', `${INDEX_REL}: ${KEPT_JUDGE} could not be launched or did not answer in time (${verdict.error}) — ${after}`);
343
+ const reportUnanswered = (verdict, after) => loud('index', 'index-probe-failed', `${INDEX_REL}: ${describeKeptJudge()} could not be launched or did not answer in time (${verdict.error}) — ${after}`);
344
344
  const first = judge();
345
345
  if (first.error) return reportUnanswered(first, 'nothing was written');
346
- if (first.accepted) return ok('index', 'already-current', `${INDEX_REL}: ${KEPT_FITS} — nothing written`);
346
+ if (first.accepted) return ok('index', 'already-current', `${INDEX_REL}: ${describeKeptFits()} — nothing written`);
347
347
  const found = lstatNoFollow(join(cwd, INDEX_REL), lstat) === null ? null : read(join(cwd, INDEX_REL));
348
348
  const restored = found === null ? 'the navigator was put back: found absent, it was removed again' : 'the navigator was put back byte for byte';
349
349
  const restoreThen = (failure, compose) => {
350
350
  const refused = putBackIndex(cwd, found, deps);
351
- return refused === null ? compose() : loud('index', 'write-refused', `${INDEX_REL}: putting the navigator back failed (${refused})${failure ? ` after ${failure}` : ''} — a navigator ${KEPT_JUDGE} rejects may stand; re-read it before re-running`);
351
+ return refused === null ? compose() : loud('index', 'write-refused', `${INDEX_REL}: putting the navigator back failed (${refused})${failure ? ` after ${failure}` : ''} — a navigator ${describeKeptJudge()} rejects may stand; re-read it before re-running`);
352
352
  };
353
353
  const run = drive('--ensure-index');
354
354
  const refusal = String(run.stderr ?? '').match(ENSURE_INDEX_REFUSAL);
@@ -359,19 +359,19 @@ const ensureKeptIndex = ({ cwd, drive, spawn, read, lstat, deps }) => {
359
359
  }
360
360
  let second;
361
361
  try { second = judge(); } catch (err) { return restoreThen(`the navigator could not be read back (${causeOf(err)})`, () => loud('index', 'unexpected-error', `${INDEX_REL}: the navigator could not be read back after the bundled write (${causeOf(err)}) — ${restored}`)); }
362
- if (second.error) return restoreThen(`${KEPT_JUDGE} could not answer (${second.error})`, () => reportUnanswered(second, restored));
363
- if (second.accepted) return ok('index', 'regenerated', `${INDEX_REL}: written by the bundled generator — ${KEPT_FITS}`);
364
- return restoreThen(null, () => ok('index', 'customized-preserved', `${INDEX_REL}: ${KEPT_JUDGE} rejected the bundled render on ${second.half} (${second.said}), and the navigator as found did not pass it either (${first.half}) — ${restored}. The route: ${KEPT_ROUTE}`));
362
+ if (second.error) return restoreThen(`${describeKeptJudge()} could not answer (${second.error})`, () => reportUnanswered(second, restored));
363
+ if (second.accepted) return ok('index', 'regenerated', `${INDEX_REL}: written by the bundled generator — ${describeKeptFits()}`);
364
+ return restoreThen(null, () => ok('index', 'customized-preserved', `${INDEX_REL}: ${describeKeptJudge()} rejected the bundled render on ${second.half} (${second.said}), and the navigator as found did not pass it either (${first.half}) — ${restored}. The route: ${KEPT_ROUTE}`));
365
365
  };
366
366
 
367
367
  const buildKeptDryRunNote = (hook) =>
368
- `a module the project's hook loads (${hook.filter((entry) => entry.state !== 'current').map((entry) => entry.rel).join(', ')}) is not the bundled one: unless the spec-layer step of this run first refreshes every such module, the real run judges the navigator by ${KEPT_JUDGE} and puts back a write it rejects`;
368
+ `a module the project's hook loads (${hook.filter((entry) => entry.state !== 'current').map((entry) => entry.rel).join(', ')}) is not the bundled one: unless the spec-layer step of this run first refreshes every such module, the real run judges the navigator by ${describeKeptJudge()} and puts back a write it rejects`;
369
369
 
370
370
  export const ensureIndex = ({ cwd, kitRoot, dryRun = false, deps = {} }) => {
371
371
  const lstat = deps.lstat ?? lstatSync;
372
372
  const read = deps.readFile ?? readFileSync;
373
373
  const spawn = deps.spawnSync ?? spawnSync;
374
- const generator = pathIn(kitRoot, CHECKER.bundled);
374
+ const generator = pathIn(kitRoot, readChecker().bundled);
375
375
  const drive = (mode) => spawn(process.execPath, [generator, mode, `--root=${cwd}`], { encoding: 'utf8' });
376
376
  const unlaunchable = (result) =>
377
377
  loud('index', 'generator-unlaunchable', `${INDEX_REL}: the bundled generator could not be started, so nothing was probed or written — reinstall the kit. ${causeOf(result.error)}`);
@@ -24,16 +24,12 @@
24
24
  import { readFileSync, lstatSync } from 'node:fs';
25
25
  import { join } from 'node:path';
26
26
  import { lstatNoFollow, writeContainedFileAtomic, writeProjectFileCreateOnly } from './atomic-write.mjs';
27
- import { DEPLOYED_SCRIPTS } from './node-evidence.mjs';
27
+ import { readDeployedScripts } from './node-evidence.mjs';
28
28
  import { SCRIPT_PRIORS, classifyDeployedScript } from './script-priors.mjs';
29
29
  import { bundledImportsOf, composeFailure, composeOutcome, dependenciesFirst, nodeEvidenceRefusal, probeSeedTarget, tmpNote } from './ensure-ops.mjs';
30
30
  import { fileLine, hookLine } from './distribution-files/index.mjs';
31
31
 
32
32
  const OP = 'specs';
33
- const READER = DEPLOYED_SCRIPTS.filter((e) => e.module === 'spec-schema');
34
- const CHECKER = DEPLOYED_SCRIPTS.filter((e) => e.module === 'docs-size');
35
- const REPORTER = DEPLOYED_SCRIPTS.filter((e) => e.module === 'test-reporter');
36
- const COMMAND = DEPLOYED_SCRIPTS.find((e) => !e.module);
37
33
  const STORE_ROOT_REL = 'docs/ai/specs/index.md';
38
34
  const STORE_ROOT_TEMPLATE = ['references', 'templates', 'specs', 'index.md'];
39
35
  const DATE_PLACEHOLDER = '{{DATE}}';
@@ -47,8 +43,13 @@ const wrongKind = (rel, kind) => composeFailure(OP, 'wrong-node-kind', `${rel}:
47
43
 
48
44
  // The bundled side: the pairs, the reporter, the command and their whole import closure in write order → { files } | { refusal }.
49
45
  const readBundles = (kitRoot, read) => {
46
+ const deployed = readDeployedScripts();
47
+ const reader = deployed.filter((e) => e.module === 'spec-schema');
48
+ const checker = deployed.filter((e) => e.module === 'docs-size');
49
+ const reporter = deployed.filter((e) => e.module === 'test-reporter');
50
+ const command = deployed.find((e) => !e.module);
50
51
  const byPath = new Map();
51
- const queue = [...READER, ...CHECKER, ...REPORTER, COMMAND];
52
+ const queue = [...reader, ...checker, ...reporter, command];
52
53
  for (const entry of queue) {
53
54
  if (byPath.has(entry.path)) continue;
54
55
  let bundle;
@@ -59,12 +60,12 @@ const readBundles = (kitRoot, read) => {
59
60
  }
60
61
  const imports = bundledImportsOf(entry.path, bundle);
61
62
  byPath.set(entry.path, { path: entry.path, rel: entry.deployed, bundle, imports });
62
- queue.push(...DEPLOYED_SCRIPTS.filter((e) => imports.includes(e.path)));
63
+ queue.push(...deployed.filter((e) => imports.includes(e.path)));
63
64
  }
64
65
  const of = (entries) => (path) => entries.some((e) => e.path === path);
65
66
  const group = (keep) => dependenciesFirst([...byPath.values()].filter((f) => keep(f.path)));
66
- const own = [READER, CHECKER, REPORTER].map(of);
67
- return { files: [...group((p) => !own.some((is) => is(p)) && p !== COMMAND.path), ...own.flatMap(group), ...group((p) => p === COMMAND.path)] };
67
+ const own = [reader, checker, reporter].map(of);
68
+ return { files: [...group((p) => !own.some((is) => is(p)) && p !== command.path), ...own.flatMap(group), ...group((p) => p === command.path)] };
68
69
  };
69
70
 
70
71
  // Each folder on the way to a pair file or a file it imports, lstat-ed without following a link → a refusal or null.
@@ -17,7 +17,7 @@
17
17
  // side effects on import (the isDirectRun idiom) — tests import the helpers with nothing run.
18
18
 
19
19
  import { existsSync, statSync, readFileSync, lstatSync } from 'node:fs';
20
- import { join, resolve, dirname } from 'node:path';
20
+ import { join, resolve, dirname, posix } from 'node:path';
21
21
  import { fileURLToPath } from 'node:url';
22
22
  import os from 'node:os';
23
23
  import { resolveDir, detectBackends, findOnPath } from './detect-backends.mjs';
@@ -85,8 +85,8 @@ import { toViewModel } from './view-model.mjs';
85
85
  import { render } from './renderers.mjs';
86
86
  // The feature-spec adoption state (contract: kit/spec-adoption) — read-only leaves, no cycle.
87
87
  import { ADOPTION, readDeclineAck, surveySpecAdoption } from './spec-adoption.mjs';
88
- // The kit's one door to the script family: where a deployment holds the decisions rotator.
89
- import { DEPLOYED_SCRIPTS } from './node-evidence.mjs';
88
+ import { KIT_COMMANDS } from '../references/scripts/run.mjs';
89
+ import { KIT_SCRIPTS_DIR } from './node-evidence.mjs';
90
90
 
91
91
  // ── manifestState values — re-export the EXACT public subset family-registry exported before B1 ─────
92
92
  // (the 7 state constants + DISPLAY_NAMES) so every existing importer (uninstall.mjs, the test suites)
@@ -357,7 +357,7 @@ export const ADR_LAYOUT_PATHS = Object.freeze({
357
357
  // The DEPLOYED rotator is the discriminator: the new-scheme file names the store path, the
358
358
  // pre-migration one does not. Never "has decisions.md, lacks adr/" — that shape false-positives a
359
359
  // tree whose NEW rotator already reds its own gate, and every No-Node project.
360
- rotator: DEPLOYED_SCRIPTS.find(({ path }) => path === 'archives/archive-decisions.mjs').deployed,
360
+ rotator: posix.join(KIT_SCRIPTS_DIR, KIT_COMMANDS['archive-decisions']),
361
361
  storeMarker: 'docs/ai/adr',
362
362
  });
363
363
  const ENOENT = 'ENOENT';
@@ -11,7 +11,7 @@ import { spawnSync } from 'node:child_process';
11
11
  import { dirname, join, resolve } from 'node:path';
12
12
  import { fileURLToPath } from 'node:url';
13
13
  import { writeProjectFileCreateOnly } from './atomic-write.mjs';
14
- import { DEPLOYED_SCRIPTS, INSTALLER_REL, NODE_EVIDENCE_SCRIPTS, SCRIPTS_DIR } from './node-evidence.mjs';
14
+ import { readDeployedScripts, INSTALLER_REL, readNodeEvidenceScripts, SCRIPTS_DIR } from './node-evidence.mjs';
15
15
  import { shellQuoteArg } from './repo-lex.mjs';
16
16
  import { GIT_MAX_BUFFER } from './git-env.mjs';
17
17
  import { KIT_COMMAND_PATH, KIT_COMMANDS } from '../references/scripts/run.mjs';
@@ -21,7 +21,7 @@ import { readLayoutSetup } from './source-size-core.mjs';
21
21
 
22
22
  const TOOLS = dirname(fileURLToPath(import.meta.url));
23
23
  export const SCRIPTS_REL = SCRIPTS_DIR;
24
- export { DEPLOYED_SCRIPTS, INSTALLER_REL };
24
+ export { readDeployedScripts, INSTALLER_REL };
25
25
 
26
26
  const EXIT_OK = 0;
27
27
  const EXIT_INCOMPLETE = 1;
@@ -172,7 +172,7 @@ export const planGitHooks = ({ root, variant, toolsDir = TOOLS, lstat = lstatSyn
172
172
  nodes.set(rel, node);
173
173
  return node;
174
174
  };
175
- for (const rel of enforcing ? DEPLOYED_SCRIPTS.map(({ deployed }) => deployed) : [INSTALLER_REL]) {
175
+ for (const rel of enforcing ? readDeployedScripts().map(({ deployed }) => deployed) : [INSTALLER_REL]) {
176
176
  for (const folder of foldersOf(rel)) if (!nodes.has(folder)) (folders.push(folder), probe(folder, isPlainDir, 'a plain directory'));
177
177
  probe(rel, isFile, 'a regular file');
178
178
  }
@@ -180,8 +180,8 @@ export const planGitHooks = ({ root, variant, toolsDir = TOOLS, lstat = lstatSyn
180
180
  if (variant === 'hook-checks') return planHookChecks({ root, toolsDir, installer, installerNode: nodes.get(INSTALLER_REL), lstat, readFile, deps });
181
181
  // A flat evidence name is no copy path: another node kind there is not evidence, never a refusal.
182
182
  const evidence = (rel) => (nodes.has(rel) ? isFile(nodes.get(rel)) : nodes.get(SCRIPTS_REL) !== null && isFile(nodeAt(join(root, rel), lstat)));
183
- const deployed = enforcing && NODE_EVIDENCE_SCRIPTS.some((name) => evidence(`${SCRIPTS_REL}/${name}`));
184
- const copies = enforcing && !deployed ? DEPLOYED_SCRIPTS.map(({ deployed: rel, bundled }) =>
183
+ const deployed = enforcing && readNodeEvidenceScripts().some((name) => evidence(`${SCRIPTS_REL}/${name}`));
184
+ const copies = enforcing && !deployed ? readDeployedScripts().map(({ deployed: rel, bundled }) =>
185
185
  ({ rel, path: join(root, rel), action: 'created', bytes: readFile(join(toolsDir, '..', bundled)) })) : [];
186
186
  const placed = copies.find(({ rel }) => rel === INSTALLER_REL);
187
187
  if (!placed && !isFile(nodes.get(INSTALLER_REL))) throw refusal(`${installer} is absent — nothing here places the hook installer`);
@@ -1,9 +1,10 @@
1
1
  // node-evidence.mjs — does Node PROVABLY run in this project tree? Contract: docs/ai/specs/kit/node-evidence.md.
2
- // Pure over an injectable lstat; no writes, no side effects on import. Dependency-free, Node >= 22.
2
+ // Pure over an injectable lstat; no writes, no reads on import. Dependency-free, Node >= 22.
3
3
 
4
4
  import { lstatSync } from 'node:fs';
5
5
  import { join, posix } from 'node:path';
6
6
  import { readFamily } from '../references/scripts/family.mjs';
7
+ import { KIT_COMMANDS } from '../references/scripts/run.mjs';
7
8
  import { KIT_FOLDER_ROOT } from './source-size-config.mjs';
8
9
 
9
10
  export const NODE_EVIDENCE = Object.freeze({
@@ -17,12 +18,12 @@ export const PACKAGE_JSON_REL = 'package.json';
17
18
  export const SCRIPTS_DIR = 'scripts';
18
19
  export const KIT_SCRIPTS_DIR = KIT_FOLDER_ROOT;
19
20
 
20
- // The kit's one door to the script family: the mirrored manifest's deployed entries, each with its
21
- // manifest path, module and seed flag, its deployed path in the kit folder and its bundled path in this
22
- // kit. A manifest the reader refuses fails this module's import with the reader's message.
23
- export const DEPLOYED_SCRIPTS = Object.freeze(readFamily().filter(({ role }) => role === 'deployed').map(({ path, module, seed }) =>
21
+ export const INSTALLER_REL = posix.join(KIT_SCRIPTS_DIR, KIT_COMMANDS['install-git-hooks']);
22
+
23
+ // The kit's one door to the script family: read at the first call, never at import; refusals escape.
24
+ const familyCache = {};
25
+ export const readDeployedScripts = () => familyCache.deployed ??= Object.freeze(readFamily().filter(({ role }) => role === 'deployed').map(({ path, module, seed }) =>
24
26
  Object.freeze({ path, module, seed, deployed: `${KIT_SCRIPTS_DIR}/${path}`, bundled: `references/scripts/${path}` })));
25
- export const INSTALLER_REL = DEPLOYED_SCRIPTS.find(({ module }) => module === 'git-hooks').deployed;
26
27
 
27
28
  // The nine flat runnable names probed before the kit folder (frozen, so a flat deployment keeps its
28
29
  // evidence), then the deployed manifest paths, sorted — each relative to scripts/.
@@ -38,18 +39,18 @@ const FLAT_SCRIPTS = [
38
39
  'spec-schema.mjs',
39
40
  ];
40
41
  const KIT_UNDER_SCRIPTS = posix.relative(SCRIPTS_DIR, KIT_SCRIPTS_DIR);
41
- export const NODE_EVIDENCE_SCRIPTS = Object.freeze([
42
+ export const readNodeEvidenceScripts = () => familyCache.scripts ??= Object.freeze([
42
43
  ...FLAT_SCRIPTS,
43
- ...DEPLOYED_SCRIPTS.map(({ path }) => path).sort().map((path) => `${KIT_UNDER_SCRIPTS}/${path}`),
44
+ ...readDeployedScripts().map(({ path }) => path).sort().map((path) => `${KIT_UNDER_SCRIPTS}/${path}`),
44
45
  ]);
45
46
 
46
- export const NODE_EVIDENCE_PROBES = Object.freeze([PACKAGE_JSON_REL, ...NODE_EVIDENCE_SCRIPTS.map((name) => `${SCRIPTS_DIR}/${name}`)]);
47
+ export const readNodeEvidenceProbes = () => familyCache.probes ??= Object.freeze([PACKAGE_JSON_REL, ...readNodeEvidenceScripts().map((name) => `${SCRIPTS_DIR}/${name}`)]);
47
48
 
48
49
  const ENOENT = 'ENOENT';
49
50
  const kindOf = (st) => (st.isSymbolicLink() ? 'a symlink' : st.isDirectory() ? 'a directory' : st.isFile() ? 'a regular file' : 'not a regular file');
50
51
 
51
52
  const answer = (state, evidence, wrongKind, extra = {}) =>
52
- Object.freeze({ state, evidence, probed: NODE_EVIDENCE_PROBES, wrongKind: Object.freeze(wrongKind), ...extra });
53
+ Object.freeze({ state, evidence, probed: readNodeEvidenceProbes(), wrongKind: Object.freeze(wrongKind), ...extra });
53
54
 
54
55
  // probeNodeEvidence(cwd, lstat) -> { state, evidence, probed, wrongKind, error? }: the first regular file
55
56
  // among the probes answers; a probe failing with anything but ENOENT answers unreadable at once; a path of
@@ -57,6 +58,7 @@ const answer = (state, evidence, wrongKind, extra = {}) =>
57
58
  // not follow the LEAF but walks THROUGH a symlinked folder, whose files are not this tree's — so scripts/,
58
59
  // the kit folder and each module folder are proven plain, once each, before any script beneath counts.
59
60
  export const probeNodeEvidence = (cwd, lstat = lstatSync) => {
61
+ const probes = readNodeEvidenceProbes();
60
62
  const wrongKind = [];
61
63
  const folders = new Map();
62
64
  const plainFolder = (rel) => {
@@ -79,7 +81,7 @@ export const probeNodeEvidence = (cwd, lstat = lstatSync) => {
79
81
  try {
80
82
  if (probeKind(PACKAGE_JSON_REL, 'file') === 'file') return answer(NODE_EVIDENCE.PACKAGE_JSON, PACKAGE_JSON_REL, wrongKind);
81
83
  if (plainFolder(SCRIPTS_DIR)) {
82
- for (const rel of NODE_EVIDENCE_PROBES.slice(1)) {
84
+ for (const rel of probes.slice(1)) {
83
85
  if (foldersOf(rel).every(plainFolder) && probeKind(rel, 'file') === 'file') return answer(NODE_EVIDENCE.DEPLOYED_SCRIPTS, rel, wrongKind);
84
86
  }
85
87
  }
@@ -93,7 +95,7 @@ export const hasNodeEvidence = (probe) => probe.state === NODE_EVIDENCE.PACKAGE_
93
95
 
94
96
  // The sentence a skip line carries: every probe checked, and what of the wrong kind sat at any of them.
95
97
  export const describeNodeProbes = (probe = null) => {
96
- const probes = `${PACKAGE_JSON_REL} and the kit-seeded ${SCRIPTS_DIR}/ files (${NODE_EVIDENCE_SCRIPTS.join(', ')})`;
98
+ const probes = `${PACKAGE_JSON_REL} and the kit-seeded ${SCRIPTS_DIR}/ files (${readNodeEvidenceScripts().join(', ')})`;
97
99
  const wrong = probe?.wrongKind?.length ? ` — not evidence: ${probe.wrongKind.join('; ')}` : '';
98
100
  return `${probes}${wrong}`;
99
101
  };
@@ -85,7 +85,7 @@ import { nearestExistingDir, worktreesGrantDir, worktreesGrantHoldsHome } from '
85
85
  import { readBundledAgents, writeCheapAgents, EXECUTOR_VEHICLE } from './cheap-agents.mjs';
86
86
  import { ATTRIBUTION_KEY, LEGACY_ATTRIBUTION_KEY, attributionHidesText, effectiveAttribution, readAttributionChoice, wrongTypedKey } from './attribution.mjs';
87
87
  import { planGlobalRemoval } from './hide-footprint.mjs';
88
- import { DEPLOYED_SCRIPTS, INSTALLER_REL, NODE_EVIDENCE, probeNodeEvidence } from './node-evidence.mjs';
88
+ import { readDeployedScripts, INSTALLER_REL, NODE_EVIDENCE, probeNodeEvidence } from './node-evidence.mjs';
89
89
  // The vehicle READINESS comes from the read-only half — the same survey `recipes` and `status` read.
90
90
  import { surveyExecutorVehicle, readExecutorPosture, agentsAccepted, readStamp, readFsDeps, AGENTS_DIR, WORKFLOW_STAMP, EXPECTED_WORKFLOW_VERSION } from './cheap-agents-read.mjs';
91
91
  // The ack store's path, keys, lane registry, fingerprint and guarded reader live in their own leaf
@@ -1064,7 +1064,7 @@ const enforcementOffer = (root, deps) => {
1064
1064
  if (!listings.has(folder)) listings.set(folder, readDir(folder));
1065
1065
  return listings.get(folder).includes(name);
1066
1066
  });
1067
- if (!DEPLOYED_SCRIPTS.every(({ path }) => inBundle(path))) throw new Error(`${bundleRoot}: a runnable enforcement script is missing`);
1067
+ if (!readDeployedScripts().every(({ path }) => inBundle(path))) throw new Error(`${bundleRoot}: a runnable enforcement script is missing`);
1068
1068
  // Evidence none with nothing of the wrong kind already proves the destination clean: every deployed path is a
1069
1069
  // probe, so each is absent and scripts/, the kit folder and each module folder are absent or plain directories.
1070
1070
  if (readHookState(root, deps).state === 'unmanaged') throw new Error(ENFORCEMENT_UNMANAGED_HOOK);
@@ -6,7 +6,7 @@ import { spawnSync } from 'node:child_process';
6
6
  import { detectBackends } from './detect-backends.mjs';
7
7
  import { resolveActivityRecipe, DISPLAY_ALIASES, requiredBackendsForConfiguredRecipe, composeReadiness } from './recipes.mjs';
8
8
  import { loadConfig } from './orchestration-config.mjs';
9
- import { plansInFlight } from './plan-files.mjs';
9
+ import { plansInFlight, readPlanEntries } from './plan-files.mjs';
10
10
  import { GIT_MAX_BUFFER, resolveGitLocation, stripGitLocationEnv, withGitPath } from './git-env.mjs';
11
11
  import {
12
12
  computeTreeFingerprint,
@@ -86,7 +86,8 @@ export const buildState = ({ cwd, env = process.env, detect = detectBackends, su
86
86
  const resolved = resolveActivityRecipe({ config: config ?? {}, readiness: detection, activity: ACTIVITY, slot: SLOT });
87
87
  const obligations = requiredBackendsForConfiguredRecipe({ config: config ?? {}, readiness: detection, detectionFailed: detectionWarning != null });
88
88
  const requiredBackends = obligations.backends;
89
- const plans = plansInFlight(root);
89
+ const entries = readPlanEntries(root);
90
+ const plans = plansInFlight(root, () => entries);
90
91
  // The injected lstat threads through EVERY stat-dependent computation (fingerprint, clean, the
91
92
  // mask count) — a partial injection would let a test observe an inconsistent state.
92
93
  const fingerprint = location.state === 'work-tree' ? computeTreeFingerprint(cwd, { lstat, env }) : null;
@@ -174,7 +174,7 @@ Sandbox-safe: runs fully inside an OS sandbox (fs + git reads, no network) — t
174
174
  Human residual: git commit --no-verify and receipt-file deletion remain possible — this is a
175
175
  self-discipline mechanism, not a security boundary.
176
176
 
177
- Exit codes: 0 pass (or plain report); 1 check failed or config error (loud); 2 usage.`;
177
+ Exit codes: 0 pass (or plain report); 1 check failed, config error or unreadable docs/plans (loud); 2 usage.`;
178
178
 
179
179
  const KNOWN_ARGS = new Set(['--help', '-h', '--check', '--json']);
180
180
 
@@ -2,7 +2,7 @@ import { join, resolve } from 'node:path';
2
2
  import { dirCovers } from './declared-paths.mjs';
3
3
  import { claudeDirOf, quoteArg, skillTargets } from './jev-facts.mjs';
4
4
  import { targetsFor } from './jev-connect.mjs';
5
- import { DEPLOYED_SCRIPTS, INSTALLER_REL } from './node-evidence.mjs';
5
+ import { readDeployedScripts, INSTALLER_REL } from './node-evidence.mjs';
6
6
  import { dqUnsafePath } from './checker-claim.mjs';
7
7
  import { isLineUnsafe } from './source-size-refusal.mjs';
8
8
  import { SOURCE_SIZE_GATE_ID } from './source-size-gate-cmd.mjs';
@@ -112,7 +112,7 @@ const getStartupPaths = ({ env, home, platform }) => targetsFor({
112
112
  }).filter(({ path }) => path !== null).map(({ path }) => path);
113
113
 
114
114
  const preCommitOf = (facts) => join(facts.hooksDir ?? join(facts.root, '.git', 'hooks'), 'pre-commit');
115
- const getEnforcementPaths = (facts) => [...DEPLOYED_SCRIPTS.map(({ deployed }) => join(facts.root, deployed)), preCommitOf(facts)];
115
+ const getEnforcementPaths = (facts) => [...readDeployedScripts().map(({ deployed }) => join(facts.root, deployed)), preCommitOf(facts)];
116
116
  const getGuardPaths = (facts) => [preCommitOf(facts), join(facts.root, INSTALLER_REL)];
117
117
 
118
118
  const formatCommand = (argv) => argv.map(quoteArg).join(' ');