@holmes-lab/holmes-kit 0.33.0 → 0.35.0

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.
@@ -54,6 +54,7 @@ const fs = __importStar(require("node:fs"));
54
54
  const os = __importStar(require("node:os"));
55
55
  const path = __importStar(require("node:path"));
56
56
  const linear_match_1 = require("./linear-match");
57
+ const risk_classifier_1 = require("./risk-classifier");
57
58
  const write_target_1 = require("./write-target");
58
59
  const NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*/;
59
60
  /**
@@ -653,6 +654,17 @@ const mentionsWiring = (text) => {
653
654
  // Rule 46: one memo — the single-slot one beside it made each defence untestable alone.
654
655
  return remembered(wiringAnswers, text, mentionsWiringUncached);
655
656
  };
657
+ /**
658
+ * @implements A-SPEC-728.2 — a quoted literal can be a computed target only when it is path-shaped: no whitespace after
659
+ * trimming, or a whole quoted path (rooted, relative-dotted, a drive letter, or a wiring file name first). A Markdown
660
+ * table row or a sentence that mentions `.ax` is prose (measured 2026-10-01: a docs rewrite was refused for one).
661
+ */
662
+ const pathShapedLiteral = (literal) => {
663
+ const t = literal.trim();
664
+ if (t === '')
665
+ return false;
666
+ return !/\s/.test(t) || /^(?:[/~]|\.{1,2}[/\\]|[A-Za-z]:[\\/])/.test(t) || write_target_1.WIRING_FILE_NAMES.some((n) => t.toLowerCase().startsWith(n));
667
+ };
656
668
  const mentionsWiringUncached = (text) => {
657
669
  const t = text.toLowerCase();
658
670
  if (write_target_1.WIRING_FILE_NAMES.some((n) => t.includes(n)) || /(^|[^\w.-])\.(?:claude|agents|codex|ax)(?![\w-])/.test(t))
@@ -943,7 +955,7 @@ function harnessWiringActOf(root, base, segmentText, fullText, env = process.env
943
955
  // A computed target in a program that quotes a wiring path (`p=".mcp.json"; os.remove(p)`).
944
956
  if (computed) {
945
957
  for (const m of program.matchAll(QUOTED_LITERAL))
946
- if (mentionsWiring(m[2]))
958
+ if (pathShapedLiteral(m[2]) && mentionsWiring(m[2]))
947
959
  return `${m[2]} (the target of a mutating call is computed from it)`;
948
960
  }
949
961
  return null;
@@ -1604,6 +1616,7 @@ function harnessWiringActOfCommand(root, command, env = process.env, home = os.h
1604
1616
  if (command.length > exports.MAX_COMMAND) {
1605
1617
  return mentionsWiring(command) || /[$\\`'"{*?[]/.test(command) ? 'a command too large to judge that could name a wiring file' : null;
1606
1618
  }
1619
+ command = readLoopWordsNeutral(command);
1607
1620
  const run = () => {
1608
1621
  const loop = forLoopAct(root, command, env, home, startBase, depth, baseUnknown);
1609
1622
  if (loop)
@@ -1691,6 +1704,44 @@ const PATHS_JUDGED_MAX = 65_536;
1691
1704
  const PATHS_CHARS_MAX = 16 * 1024 * 1024;
1692
1705
  let pathsJudged = null;
1693
1706
  const FOR_RE = /(?:^|[\s;&|(])for[ \t]+([A-Za-z_]\w{0,63})[ \t]+in[ \t]+([^;\n]{0,1024})[;\n]\s*do\b/g;
1707
+ /**
1708
+ * @implements A-SPEC-728.2 — a `for` loop whose whole text the classifier judges a read (every body command a read form,
1709
+ * the variable only an argument — `"$f"` as a command is not a read) names no mutation target with its word list:
1710
+ * `for f in .ax/specs/…; do echo "---- $f"; cat "$f"; done` was refused as moving or deleting governance state (measured
1711
+ * 2026-10-01). The words are replaced before the identity rule reads the command; a word list holding a substitution, a
1712
+ * redirect or a pipe is left as written, and so is a loop the classifier does not call a read.
1713
+ */
1714
+ const READ_LOOP_WORDS = '__read_loop_words__';
1715
+ function readLoopWordsNeutral(command) {
1716
+ if (!/\bfor\b/.test(command) || !/\bdone\b/.test(command))
1717
+ return command;
1718
+ let out = command;
1719
+ let loops = 0;
1720
+ for (const m of command.matchAll(FOR_RE)) {
1721
+ if (++loops > 16)
1722
+ break;
1723
+ const words = m[2];
1724
+ if (/[$`<>()|&]/.test(words) || words.trim() === '')
1725
+ continue;
1726
+ const head = m[0].search(/for[ \t]/);
1727
+ const start = (m.index ?? 0) + head;
1728
+ const bodyStart = (m.index ?? 0) + m[0].length;
1729
+ const end = command.indexOf('done', bodyStart);
1730
+ if (end < 0)
1731
+ continue;
1732
+ const loop = command.slice(start, end + 4);
1733
+ // Only the loop's own variable, whole: a body that also reads another variable (`echo $a $b $c` inside three loops)
1734
+ // can assemble a word only substitution shows, and keeps the A-SPEC-728 rule 37 judgement.
1735
+ const own = new RegExp(String.raw `\$(?:\{${m[1]}\}|${m[1]}(?!\w))`, 'g');
1736
+ if (/[$`]/.test(command.slice(bodyStart, end).replace(own, '')))
1737
+ continue;
1738
+ if (!(0, risk_classifier_1.shellTextOnlyReads)(loop))
1739
+ continue;
1740
+ const at = loop.indexOf(words);
1741
+ out = out.replace(loop, `${loop.slice(0, at)}${READ_LOOP_WORDS}${loop.slice(at + words.length)}`);
1742
+ }
1743
+ return out;
1744
+ }
1694
1745
  function forLoopAct(root, command, env, home, startBase, depth, baseUnknown) {
1695
1746
  if (depth > 4)
1696
1747
  return null;
@@ -11,6 +11,18 @@ export declare function resolveRmSignals(command: string, cwd: string, projectRo
11
11
  * malformed input as absent) is testable at the layer that owns it.
12
12
  */
13
13
  export declare function readApprovalFromEnv(): Approval | undefined;
14
+ /**
15
+ * @implements A-SPEC-732 (round 5) — the command as a shell would resolve its words: quotes and
16
+ * backslash escapes removed, `.`/`..` path segments resolved, case folded (macOS paths are
17
+ * case-insensitive). Measured allowed before: `dist/holmes/mcp/./server.js`, `dist/holmes/../holmes/
18
+ * mcp/server.js`, `DIST/…`, a quoted command word, `holmes\-mcp`. Linear: one pass per word.
19
+ */
20
+ /**
21
+ * @implements A-SPEC-747 — the files a `sed` with an in-place flag writes: its non-option operands, minus the script.
22
+ * The script is the first non-option operand unless `-e`/`--expression`/`-f`/`--file` supplied it; BSD's `-i ''` takes
23
+ * the empty word as its suffix. Words are read quote-aware; an operand that is only a glob or a variable still counts.
24
+ */
25
+ export declare function sedInPlaceFiles(text: string): string[];
14
26
  /**
15
27
  * @implements A-SPEC-732 (round 2) — the PreToolUse output. For `approval_commit` an unobjected call
16
28
  * carries no decision: an `allow` would pre-empt the harness's own sensitive-tool confirmation, the
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.DEFAULT_SPECS_DIR = void 0;
37
37
  exports.resolveRmSignals = resolveRmSignals;
38
38
  exports.readApprovalFromEnv = readApprovalFromEnv;
39
+ exports.sedInPlaceFiles = sedInPlaceFiles;
39
40
  exports.hookOutputFor = hookOutputFor;
40
41
  exports.dumpsEnvInCommandPosition = dumpsEnvInCommandPosition;
41
42
  exports.normalizeHookInput = normalizeHookInput;
@@ -46,7 +47,7 @@ exports.gateErrorDecision = gateErrorDecision;
46
47
  exports.wiredSpecsDir = wiredSpecsDir;
47
48
  exports.evaluateHook = evaluateHook;
48
49
  exports.readSpecsSync = readSpecsSync;
49
- // @implements A-SPEC-278, A-SPEC-733, A-SPEC-734
50
+ // @implements A-SPEC-278, A-SPEC-733, A-SPEC-734, A-SPEC-747
50
51
  // @implements A-SPEC-549.3 — the hook's deny reasons are English here; hooks-english.test.ts drives
51
52
  // evaluateHook in this file to prove it.
52
53
  // @implements A-SPEC-643
@@ -386,6 +387,52 @@ const LOCAL_SERVER_RUN = /(?:^|[\s;&|(])(?:exec\s+)?(?:node|nodejs|bun|deno|tsx|
386
387
  * case-insensitive). Measured allowed before: `dist/holmes/mcp/./server.js`, `dist/holmes/../holmes/
387
388
  * mcp/server.js`, `DIST/…`, a quoted command word, `holmes\-mcp`. Linear: one pass per word.
388
389
  */
390
+ /**
391
+ * @implements A-SPEC-747 — the files a `sed` with an in-place flag writes: its non-option operands, minus the script.
392
+ * The script is the first non-option operand unless `-e`/`--expression`/`-f`/`--file` supplied it; BSD's `-i ''` takes
393
+ * the empty word as its suffix. Words are read quote-aware; an operand that is only a glob or a variable still counts.
394
+ */
395
+ function sedInPlaceFiles(text) {
396
+ const toks = text.match(/"[^"]*"|'[^']*'|\S+/g) ?? [];
397
+ const unq = (t) => t.replace(/^(['"])(.*)\1$/s, '$2');
398
+ const files = [];
399
+ for (let i = 0; i < toks.length; i++) {
400
+ if (!/(^|\/)g?sed$/.test(unq(toks[i])))
401
+ continue;
402
+ const args = [];
403
+ let j = i + 1;
404
+ for (; j < toks.length && !/^(?:\|\|?|&&?|;)$/.test(toks[j]) && !/^[0-9]*[<>]/.test(toks[j]); j++)
405
+ args.push(toks[j]);
406
+ i = j - 1;
407
+ const inPlace = args.some((a) => /^--in-place(=|$)/.test(unq(a)) || /^-[^-]*[iI]/.test(unq(a)));
408
+ if (!inPlace)
409
+ continue;
410
+ let scriptGiven = false;
411
+ const operands = [];
412
+ for (let k = 0; k < args.length; k++) {
413
+ const a = args[k];
414
+ const u = unq(a);
415
+ if (u === '-e' || u === '--expression' || u === '-f' || u === '--file') {
416
+ scriptGiven = true;
417
+ k++;
418
+ continue;
419
+ }
420
+ if (/^--(?:expression|file)=/.test(u)) {
421
+ scriptGiven = true;
422
+ continue;
423
+ }
424
+ if ((u === '-i' || u === '-I') && (args[k + 1] === "''" || args[k + 1] === '""')) {
425
+ k++;
426
+ continue;
427
+ }
428
+ if (u.startsWith('-') && u.length > 1)
429
+ continue;
430
+ operands.push(u);
431
+ }
432
+ files.push(...(scriptGiven ? operands : operands.slice(1)));
433
+ }
434
+ return files;
435
+ }
389
436
  function normalizedCommand(command) {
390
437
  return command.replace(/\\(.)/g, '$1').replace(/["']/g, '').toLowerCase().split(/(\s+)/).map((word) => {
391
438
  if (!word.includes('/'))
@@ -1415,12 +1462,18 @@ function evaluateHook(input, specsDir, opts) {
1415
1462
  // @implements A-SPEC-463 — same quoted-space fix as the config rule; `EXT_TAIL` is the
1416
1463
  // extension part and `pathAlt` supplies the prefix and the quoting alternatives.
1417
1464
  const EXT_TAIL = `\\.${CODE_EXT}`;
1465
+ const CODE_TAIL_RE_SED = new RegExp(`${EXT_TAIL}$`);
1418
1466
  const candidates = [];
1419
1467
  const CODE_REDIRECT = new RegExp(`(?:>{1,2}|\\btee\\b(?:\\s+-a)?\\s)\\s*${pathAlt(EXT_TAIL)}`, 'g');
1420
1468
  for (const seg of segments) {
1421
1469
  collectSeg(seg, CODE_REDIRECT, candidates);
1422
1470
  collectPaths(seg, /\btouch\s+/, EXT_TAIL, candidates);
1423
- collectPaths(seg, /\bsed\b/, EXT_TAIL, candidates, /\s-i\b/);
1471
+ // @implements A-SPEC-747 — only sed's FILE operands are written; its script is not. Every code-named word of a
1472
+ // `sed -i` segment was a candidate, so `sed -i '' 's#a.test.ts#src/x.ts#' <outside>/notes.md` was denied as a
1473
+ // project code write (measured 2026-10-01).
1474
+ for (const raw of sedInPlaceFiles(seg.text))
1475
+ if (CODE_TAIL_RE_SED.test(raw))
1476
+ candidates.push({ raw, base: seg.base });
1424
1477
  }
1425
1478
  // @implements A-SPEC-449 — the copy/move family. The CONFIG rule has carried it since
1426
1479
  // A-SPEC-191 §28 ("a gate that names one syntax for an act is a gate over that syntax, not
@@ -34,7 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.createMaintenanceAnalysisHandlers = createMaintenanceAnalysisHandlers;
37
- // @implements A-SPEC-745, A-SPEC-741, A-SPEC-741.1, A-SPEC-612, A-SPEC-100.2, A-SPEC-128, A-SPEC-189, A-SPEC-267, A-SPEC-268, A-SPEC-269, A-SPEC-277, A-SPEC-283, A-SPEC-290, A-SPEC-292, A-SPEC-293, A-SPEC-378, A-SPEC-388, A-SPEC-418, A-SPEC-478, A-SPEC-571.2, A-SPEC-573.4, A-SPEC-578.5, A-SPEC-734
37
+ // @implements A-SPEC-745, A-SPEC-741, A-SPEC-741.1, A-SPEC-612, A-SPEC-100.2, A-SPEC-128, A-SPEC-189, A-SPEC-267, A-SPEC-268, A-SPEC-269, A-SPEC-277, A-SPEC-283, A-SPEC-290, A-SPEC-292, A-SPEC-293, A-SPEC-378, A-SPEC-388, A-SPEC-418, A-SPEC-478, A-SPEC-571.2, A-SPEC-573.4, A-SPEC-578.5, A-SPEC-734, A-SPEC-278.3
38
38
  const fs = __importStar(require("node:fs"));
39
39
  const path = __importStar(require("node:path"));
40
40
  const node_child_process_1 = require("node:child_process");
@@ -281,7 +281,9 @@ function createMaintenanceAnalysisHandlers(context) {
281
281
  // The artifact takes the WHOLE analysis, never the bounded one below: a file has no
282
282
  // context window, and the calibration that scores this prediction must score what the
283
283
  // product actually predicted.
284
- result.persistedTo = (0, maintenance_evidence_1.writeArtifact)(path.join(root, maintenance_evidence_1.EVIDENCE_DIR), (0, maintenance_evidence_1.artifactFrom)(analysis, new Date().toISOString(), fileDigests));
284
+ result.persistedTo = (0, maintenance_evidence_1.writeArtifact)(path.join(root, maintenance_evidence_1.EVIDENCE_DIR), (0, maintenance_evidence_1.artifactFrom)(analysis, new Date().toISOString(), fileDigests,
285
+ // @implements A-SPEC-278.3 — the request and the caller's changed files travel with the prediction.
286
+ { request: a.request, changedFiles: a.changedFiles }));
285
287
  }
286
288
  // @implements A-SPEC-578.5 — the response, and only the response, is bounded. Measured
287
289
  // 2026-09-09: the full shape is 187,174 characters (~47k tokens) and the harness refuses
@@ -160,6 +160,11 @@ function createTestExecutionHandlers(context) {
160
160
  finally {
161
161
  g.close();
162
162
  }
163
+ // @implements A-SPEC-128.1 — the baseline is the tree this run TESTED, so it is hashed before the runner starts:
164
+ // hashed afterwards, a test file written during a passing run and an edit made during it entered last-green as
165
+ // green, and the next scoped run skipped them as unchanged (measured 2026-10-01).
166
+ const ig = (0, ignore_1.loadIgnore)(root); // parse .gitignore ONCE, not per file (round-10)
167
+ const testedTree = (0, change_source_1.hashTree)(root, { isIgnored: (p) => ig.isIgnored(p) });
163
168
  const result = (0, test_runner_1.runTestScope)(testScope, root);
164
169
  const anchors = (0, test_scope_1.scanTestAnchors)(root);
165
170
  const executedByAspec = (0, test_evidence_1.computeExecutedByAspec)(result.executedByFile ?? {}, anchors);
@@ -206,8 +211,7 @@ function createTestExecutionHandlers(context) {
206
211
  if (verified) {
207
212
  baseline = a.mark ?? context.defaultBaseline;
208
213
  // A-SPEC-256.2 round-4 — surfaced to the report below
209
- const ig = (0, ignore_1.loadIgnore)(root); // parse .gitignore ONCE, not per file (round-10)
210
- (0, baseline_1.writeBaseline)(root, baseline, (0, change_source_1.hashTree)(root, { isIgnored: (p) => ig.isIgnored(p) }));
214
+ (0, baseline_1.writeBaseline)(root, baseline, testedTree);
211
215
  }
212
216
  return { tier: testScope.tier, mode: result.mode, passed: result.passed, skipped: result.skipped,
213
217
  ranFiles: result.ranFiles, executedByAspec, tail: result.tail,
@@ -77,6 +77,18 @@ export interface EvidenceArtifact {
77
77
  compatibilityAssessed: boolean;
78
78
  };
79
79
  outcome?: EvidenceOutcome;
80
+ /**
81
+ * @implements A-SPEC-278.3 — what the caller asked and which files it said it would change. The pre-edit gate covers a
82
+ * new file the request names (A-SPEC-278.2), which it could not do while the artifact kept no request. Optional: older
83
+ * artifacts read as before.
84
+ */
85
+ request?: string;
86
+ changedFiles?: string[];
87
+ }
88
+ /** What the caller supplied to the analysis, recorded beside the prediction (A-SPEC-278.3). */
89
+ export interface AnalysisIntake {
90
+ request?: string;
91
+ changedFiles?: string[];
80
92
  }
81
93
  /**
82
94
  * A digest reaches the filesystem as a filename, and it arrives from an MCP caller. Refuse anything
@@ -84,8 +96,11 @@ export interface EvidenceArtifact {
84
96
  * turn "record an outcome" into an arbitrary-path write.
85
97
  */
86
98
  export declare function digestFilename(digest: string): string;
99
+ /** A-SPEC-278.3 bounds: the request is free text from the caller, and the list is whatever it passed. */
100
+ export declare const INTAKE_REQUEST_MAX = 4096;
101
+ export declare const INTAKE_CHANGED_FILES_MAX = 512;
87
102
  /** Project an analysis into the durable prediction record. Pure: the caller supplies the clock. */
88
- export declare function artifactFrom(analysis: MaintenanceAnalysis, recordedAt: string, fileDigests?: Record<string, string>): EvidenceArtifact;
103
+ export declare function artifactFrom(analysis: MaintenanceAnalysis, recordedAt: string, fileDigests?: Record<string, string>, intake?: AnalysisIntake): EvidenceArtifact;
89
104
  /**
90
105
  * Persist an artifact, addressed by its digest. Re-running the same analysis is a re-run, not a
91
106
  * reason to forget what actually happened, so an outcome already recorded at this digest survives.
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.EVIDENCE_DIR = exports.EVIDENCE_ARTIFACT_SCHEMA = void 0;
36
+ exports.INTAKE_CHANGED_FILES_MAX = exports.INTAKE_REQUEST_MAX = exports.EVIDENCE_DIR = exports.EVIDENCE_ARTIFACT_SCHEMA = void 0;
37
37
  exports.digestFilename = digestFilename;
38
38
  exports.artifactFrom = artifactFrom;
39
39
  exports.writeArtifact = writeArtifact;
@@ -43,7 +43,7 @@ exports.openArtifacts = openArtifacts;
43
43
  exports.closeOpenArtifacts = closeOpenArtifacts;
44
44
  exports.scopeCauses = scopeCauses;
45
45
  exports.computeCalibration = computeCalibration;
46
- // @implements A-SPEC-744, A-SPEC-740, A-SPEC-724.1, A-SPEC-271
46
+ // @implements A-SPEC-744, A-SPEC-740, A-SPEC-724.1, A-SPEC-271, A-SPEC-278.3
47
47
  // @implements A-SPEC-268
48
48
  const fs = __importStar(require("node:fs"));
49
49
  const path = __importStar(require("node:path"));
@@ -76,9 +76,35 @@ function digestFilename(digest) {
76
76
  function sortedUnique(values) {
77
77
  return [...new Set(values)].sort((a, b) => a.localeCompare(b));
78
78
  }
79
+ /** A-SPEC-278.3 bounds: the request is free text from the caller, and the list is whatever it passed. */
80
+ exports.INTAKE_REQUEST_MAX = 4096;
81
+ exports.INTAKE_CHANGED_FILES_MAX = 512;
82
+ /** Repository-relative and `/`-separated, as the gate compares them; at most INTAKE_CHANGED_FILES_MAX entries. */
83
+ function intakeRecord(intake) {
84
+ if (!intake)
85
+ return {};
86
+ const out = {};
87
+ if (typeof intake.request === 'string')
88
+ out.request = intake.request.slice(0, exports.INTAKE_REQUEST_MAX);
89
+ if (Array.isArray(intake.changedFiles)) {
90
+ const files = [];
91
+ for (const raw of intake.changedFiles) {
92
+ if (typeof raw !== 'string')
93
+ continue;
94
+ const rel = raw.replace(/\\/g, '/').replace(/^(?:\.\/)+/, '');
95
+ if (rel !== '' && !files.includes(rel))
96
+ files.push(rel);
97
+ if (files.length === exports.INTAKE_CHANGED_FILES_MAX)
98
+ break;
99
+ }
100
+ out.changedFiles = files;
101
+ }
102
+ return out;
103
+ }
79
104
  /** Project an analysis into the durable prediction record. Pure: the caller supplies the clock. */
80
- function artifactFrom(analysis, recordedAt, fileDigests = {}) {
105
+ function artifactFrom(analysis, recordedAt, fileDigests = {}, intake) {
81
106
  return {
107
+ ...intakeRecord(intake),
82
108
  artifactSchema: exports.EVIDENCE_ARTIFACT_SCHEMA,
83
109
  digest: analysis.evidenceDigest,
84
110
  recordedAt,
@@ -7,6 +7,8 @@ export declare const AUTORELOAD_ENV = "HOLMES_MCP_AUTORELOAD";
7
7
  * spawn" stops quickly while "one OOM under load" restarts freely.
8
8
  */
9
9
  export declare const MAX_CONSECUTIVE_SILENT_DEATHS = 5;
10
+ /** @implements A-SPEC-666.1 — how long a child may take to leave after its input closes before it is killed. */
11
+ export declare const INPUT_END_GRACE_MS = 2000;
10
12
  export declare function autoreloadEnabled(env: NodeJS.ProcessEnv): boolean;
11
13
  /**
12
14
  * Whether the child may be replaced right now.
@@ -85,6 +87,12 @@ export declare class Supervisor {
85
87
  private givenUp;
86
88
  constructor(repoRoot: string, onSwap?: ((from: string, to: string, replayed: number) => void) | undefined);
87
89
  start(stdin: NodeJS.ReadableStream, stdout: NodeJS.WritableStream): void;
90
+ /**
91
+ * @implements A-SPEC-666.1 — close the child's input rather than kill it, so a request forwarded just before the
92
+ * end is still read (killing at once dropped it — measured by the corner case); a child that does not leave on its
93
+ * own within the grace period is killed. Never restarted afterwards (`givenUp`).
94
+ */
95
+ private endInput;
88
96
  private forward;
89
97
  private swap;
90
98
  private spawnChild;
@@ -33,11 +33,11 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.Supervisor = exports.MAX_CONSECUTIVE_SILENT_DEATHS = exports.AUTORELOAD_ENV = void 0;
36
+ exports.Supervisor = exports.INPUT_END_GRACE_MS = exports.MAX_CONSECUTIVE_SILENT_DEATHS = exports.AUTORELOAD_ENV = void 0;
37
37
  exports.autoreloadEnabled = autoreloadEnabled;
38
38
  exports.shouldSwap = shouldSwap;
39
39
  exports.createResponseCounter = createResponseCounter;
40
- // @implements A-SPEC-721, A-SPEC-162
40
+ // @implements A-SPEC-721, A-SPEC-162, A-SPEC-666.1
41
41
  const node_child_process_1 = require("node:child_process");
42
42
  const path = __importStar(require("node:path"));
43
43
  const basis_1 = require("./basis");
@@ -50,6 +50,8 @@ exports.AUTORELOAD_ENV = 'HOLMES_MCP_AUTORELOAD';
50
50
  * spawn" stops quickly while "one OOM under load" restarts freely.
51
51
  */
52
52
  exports.MAX_CONSECUTIVE_SILENT_DEATHS = 5;
53
+ /** @implements A-SPEC-666.1 — how long a child may take to leave after its input closes before it is killed. */
54
+ exports.INPUT_END_GRACE_MS = 2000;
53
55
  function autoreloadEnabled(env) {
54
56
  const v = env[exports.AUTORELOAD_ENV];
55
57
  return typeof v === 'string' && v.trim() !== '';
@@ -181,6 +183,34 @@ class Supervisor {
181
183
  this.forward(line, stdout);
182
184
  }
183
185
  });
186
+ // @implements A-SPEC-666.1 — the client is gone when its input ends. Listening for `data` only, the launcher
187
+ // ran on as an orphan (PPID 1, four hours, observed 2026-10-01): the pipe to the live child kept the event loop
188
+ // alive. Complete lines were already forwarded above; a partial trailing line has no one to answer it.
189
+ stdin.on('end', () => this.endInput());
190
+ stdin.on('close', () => this.endInput());
191
+ }
192
+ /**
193
+ * @implements A-SPEC-666.1 — close the child's input rather than kill it, so a request forwarded just before the
194
+ * end is still read (killing at once dropped it — measured by the corner case); a child that does not leave on its
195
+ * own within the grace period is killed. Never restarted afterwards (`givenUp`).
196
+ */
197
+ endInput() {
198
+ if (this.givenUp)
199
+ return;
200
+ this.expectedExit = true;
201
+ this.givenUp = true;
202
+ const child = this.child;
203
+ if (child === undefined)
204
+ return;
205
+ try {
206
+ child.stdin.end();
207
+ }
208
+ catch { /* already closed */ }
209
+ const timer = setTimeout(() => { try {
210
+ child.kill();
211
+ }
212
+ catch { /* already gone */ } }, exports.INPUT_END_GRACE_MS);
213
+ timer.unref();
184
214
  }
185
215
  forward(line, stdout) {
186
216
  const trimmed = line.trim();
@@ -4,12 +4,14 @@ exports.canonicalRequirementDocument = void 0;
4
4
  exports.requestIdentifiers = requestIdentifiers;
5
5
  exports.triageRequirements = triageRequirements;
6
6
  exports.requirementSemanticCoverage = requirementSemanticCoverage;
7
- // @implements A-SPEC-713.1, A-SPEC-713.2, A-SPEC-713.3, A-SPEC-742, A-SPEC-713
7
+ // @implements A-SPEC-713.1, A-SPEC-713.2, A-SPEC-713.3, A-SPEC-713.4, A-SPEC-742, A-SPEC-713
8
8
  /** Pure, conservative lifecycle triage over governed requirement documents. */
9
9
  const semantic_retrieval_1 = require("./semantic-retrieval");
10
10
  const localize_1 = require("../rtm/localize");
11
11
  const vector_coverage_1 = require("../semantic/vector-coverage");
12
12
  const CODE_FILE = /\.(ts|tsx|js|mjs|cjs|py|go|rs|java|cs|rb|sh|json|ya?ml|toml|md)$/i;
13
+ /** @implements A-SPEC-713.4 — the kinds an approved lineage has among its live documents. */
14
+ const LINEAGE_KINDS = ['REQ', 'H-SPEC', 'A-SPEC', 'T-SPEC'];
13
15
  /**
14
16
  * @implements A-SPEC-713.2 — the code identifiers a request names: snake_case, camelCase/PascalCase,
15
17
  * paths and code or config file names. Spec ids are pointers (removed first), URLs and kebab-case prose
@@ -196,7 +198,12 @@ function triageCore(input) {
196
198
  const textLower = row.text.toLowerCase();
197
199
  const contentTerms = promptTerms.filter((term) => textLower.includes(term));
198
200
  const operational = input.evidence?.[row.reqId] ?? {};
199
- const approved = row.docs.length === 4 && row.docs.every((d) => d.status === 'approved');
201
+ // @implements A-SPEC-713.4 — judged by the documents, not their count: `length === 4` left 62 of 672 fully
202
+ // approved lineages here (8 of 671 in jarvis) unapproved because they carry sub-slices or retired documents,
203
+ // and counted REQ, H-SPEC and two A-SPECs without any T-SPEC as approved.
204
+ const live = row.docs.filter((d) => d.status !== 'outdated');
205
+ const kinds = new Set(live.map((d) => d.type));
206
+ const approved = live.every((d) => d.status === 'approved') && LINEAGE_KINDS.every((kind) => kinds.has(kind));
200
207
  const anchors = [...new Set(operational.implementationAnchors ?? [])].sort();
201
208
  const reasons = [
202
209
  ...(cited ? ['cited'] : []),
@@ -16,6 +16,12 @@ export interface ReleaseTestLaneReceipt {
16
16
  pattern: string;
17
17
  reason: string;
18
18
  }>;
19
+ /** @implements A-SPEC-748 — present only on a receipt a docs-only commit inherited from a FULL lane receipt. */
20
+ inheritedFrom?: {
21
+ head: string;
22
+ completedAt: string;
23
+ digest: string;
24
+ };
19
25
  digest: string;
20
26
  }
21
27
  export type ReleaseTestLaneValidation = {
@@ -27,8 +33,54 @@ export type ReleaseTestLaneValidation = {
27
33
  };
28
34
  /** Persist only evidence whose scope is explicit and bounded; callers cannot choose its path. */
29
35
  export declare function writeReleaseTestLaneReceipt(root: string, input: Omit<ReleaseTestLaneReceipt, 'schema' | 'digest'>): ReleaseTestLaneReceipt | null;
36
+ /** @implements A-SPEC-748 — the last FULL lane receipt, kept beside the current one (git-ignored like it). */
37
+ export declare const RELEASE_TEST_LANE_FULL_FILE: string;
38
+ /**
39
+ * @implements A-SPEC-748 — the tests an inherited receipt runs: every test that reads the repository's own README or
40
+ * docs/, plus the docs-currency, publish-docs-gate and packaging tests. A ratchet test fails when a new reader is missing.
41
+ */
42
+ export declare const REQUIRED_DOCS_TESTS: readonly string[];
43
+ export interface LaneChange {
44
+ status: string;
45
+ paths: string[];
46
+ }
47
+ export interface LaneGit {
48
+ isAncestor(base: string, head: string): boolean;
49
+ changes(base: string, head: string): LaneChange[] | null;
50
+ }
51
+ /**
52
+ * @implements A-SPEC-748 — every path of every change (both sides of a rename or copy) must be `README.md` or under
53
+ * `docs/`, and none may be shipped (equal to, or under a directory entry of, package.json `files`).
54
+ */
55
+ export declare function inheritablePaths(changes: readonly LaneChange[], shipped: readonly string[]): {
56
+ ok: true;
57
+ } | {
58
+ ok: false;
59
+ path: string;
60
+ };
61
+ /** @implements A-SPEC-748 — the two git questions inheritance asks, answered by git in `root`; `null`/false when git cannot. */
62
+ export declare function laneGit(root: string): LaneGit;
63
+ /**
64
+ * @implements A-SPEC-748 — record a receipt for HEAD by inheriting the kept full lane receipt: refused unless the full
65
+ * receipt is valid, fresh and an ancestor, every change since it is inheritable, and the required docs tests pass.
66
+ */
67
+ export declare function inheritReleaseTestLane(root: string, head: string, opts: {
68
+ git: LaneGit;
69
+ shipped: readonly string[];
70
+ runDocsTests: (files: readonly string[]) => boolean;
71
+ now?: number;
72
+ }): {
73
+ ok: true;
74
+ receipt: ReleaseTestLaneReceipt;
75
+ } | {
76
+ ok: false;
77
+ reason: string;
78
+ };
30
79
  /** Read the sole project-local receipt and fail closed for every missing or unprovable condition. */
31
- export declare function validateReleaseTestLaneReceipt(root: string, head: string, now?: number): ReleaseTestLaneValidation;
80
+ export declare function validateReleaseTestLaneReceipt(root: string, head: string, now?: number, inherit?: {
81
+ git: LaneGit;
82
+ shipped: readonly string[];
83
+ }): ReleaseTestLaneValidation;
32
84
  export declare function outcomesFilename(replica: string): string;
33
85
  export declare function isOutcomesFilename(name: string): boolean;
34
86
  /**