@holmes-lab/holmes-kit 0.34.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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,34 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
  <!-- @implements A-SPEC-209 -->
8
+ ## [0.35.0] - 2026-10-02
9
+
10
+ ### Changed
11
+
12
+ - **The pre-edit evidence gate follows new files and the RED commit** (A-SPEC-278.2/278.3). Persisted
13
+ `maintenance_analyze` evidence now records the request (up to 4,096 characters) and normalized `changedFiles`
14
+ (up to 512 entries). These explicit paths can cover a file that does not yet exist at HEAD. An analysis from
15
+ an ancestor at most 20 commits back remains usable when every intervening changed file is predicted or
16
+ explicitly named by the analysis. The gate remains advisory and continues to report content drift.
17
+ - **Read-only loops, prose, and commit messages are recognized by the shell gate** (A-SPEC-728.2).
18
+ A read-only `for` loop using only its own variable, a prose literal containing spaces, or a `git commit`
19
+ message mentioning `.ax` no longer counts as a governance-state write.
20
+
21
+ ### Fixed
22
+
23
+ - **File redirects using `>&` or `>|` reach the protected-write classifier** (A-SPEC-728.1). Descriptor
24
+ duplication and closure such as `2>&1`, `>&2`, and `>&-` keep their existing interpretation.
25
+ - **The ART-4 static test counter reads literals, aliases, and suite skips correctly** (A-SPEC-750). A
26
+ single-pass lexer prevents comment-like text inside strings, templates, or regular expressions from erasing
27
+ test declarations. Same-file test aliases are counted, and quoted `describe.skip` text no longer discards a
28
+ file. Across 648 test files the counter matches the TypeScript AST oracle; no file counts fewer than before.
29
+ - **A passing test run records the tree captured before execution** (A-SPEC-128.1). Files added or edited
30
+ during a run remain changes for the next run instead of entering `last-green` as already tested.
31
+ - **Parallel tests avoid three measured sources of interference** (A-SPEC-749/749.1, A-SPEC-162.1,
32
+ A-SPEC-651.6/651.7). All 72 migrated wall-clock bounds scale against reference work measured at the assertion
33
+ (factor 1–8); the supervisor swap test changes a package copy instead of the repository build ID; and test
34
+ Git commands disable detached auto-maintenance that could race fixture cleanup.
35
+
8
36
  ## [0.34.0] - 2026-10-01
9
37
 
10
38
  ### Added
package/README.md CHANGED
@@ -23,6 +23,7 @@ Measured at `173b99650442` (specs `sha256:215f84d4e9f4`) — reproduce with `hol
23
23
 
24
24
  ### 🛡️ Currently Supported Features (Production Features)
25
25
 
26
+ - **Maintenance evidence survives the RED commit, and test evidence records what ran** *(new in 0.35.0)*: persisted `maintenance_analyze` evidence includes the request and explicit `changedFiles`, allowing the pre-edit advisory to cover named new files and analyses up to 20 ancestor commits back when every intervening change is covered. A passing `test_run` records the tree captured before execution, so edits made during a run remain unverified changes. The static test counter handles literals and same-file aliases, and recognizes suite skips only in code. The shared shell gate accepts read-only loops, prose literals, and commit messages mentioning `.ax`, and classifies file redirects using `>&` and `>|` as protected writes where applicable.
26
27
  - 📖 **Reading `.ax` from the shell is a read, and a docs fix does not re-run the whole release suite** *(new in 0.34.0)*: the gate splits shell commands at operators outside quotes and substitutions, judges every command substitution it would run, and knows literal `cd`, `pwd`, `sleep`, `seq`, `pgrep`, clock-reading `date`, `git -C` and `while`/`until` loops — so `grep "a\|b" .ax/…`, `f=$(find .ax/specs …)` or `until grep -q … .ax/…; do sleep 20; done` no longer file an approval request, while every write form is still refused (and `echo "$(sh -c …)"` now is). `sed -i` is judged by the files it edits, not by the words in its script. After a full release lane, `node scripts/verify-release.js --inherit-release-test-lane` lets a commit that changes only `README.md` or unshipped `docs/` files publish on the full lane's receipt by running just the docs tests; the publish check recomputes that diff with git. `requirement_triage` counts a lineage with sub-slices as approved, and an autoreload MCP launcher exits when its client goes away.
27
28
  - 🗜️ **Large answers are compressed, not cut, and new requirements are not blocked by a guess** *(new in 0.33.0)*: `spec_list`, `review_status` and `reverse_scan` answer by default with a compressed view — duplicates removed, digests dropped, what needs action first, anything left out counted with a note — and `detail: "full"` (or paging, or `spec_list({ ids })` for one spec) gives the complete answer. `requirement_triage` confirms a lineage only when both of its channels agree and the lineage mentions every code identifier the request names, so a requirement next to a finished one, or on an install without a semantic layer, can still be admitted. `maintenance_analyze` judges a Korean or Japanese request against unreadable files by its words and, on the cloud tier, by meaning; the pre-edit gate finds the analysis the session persisted; `spec_approve` names a spec's blockers instead of queueing an approval nobody could use; and `holmes-kit autonomy status`/`off` read the project default in `.mcp.json`, so `off` never claims OFF while autonomous approval is still on.
28
29
  - 🔎 **The analysis tools decide on evidence about the request, and say what they could not decide** *(new in 0.32.0)*: measured on two repositories by point-in-time replay, `maintenance_analyze` had answered `ambiguous` for every request because a shell script anywhere in the tree counted against it — the classification now counts an unreadable language only when the change touches it, while the test scope stays as conservative as before (relaxing it too let narrowed scopes miss the commit's own tests). `confidence` carries `confidenceCalibrated: false`; persisted evidence records why a scope was `full` and `maintenance_calibration` reports how often each cause occurred; candidate specs come in relevance order. `requirement_triage` answers in summaries by default (`detail: "full"` for document text), counts semantic coverage over documents that can have a vector, and gives `existing-change`/`fulfilled` only when its lexical and semantic channels agree on the first-ranked lineage — a lineage the request cites is listed first but a citation is not evidence — otherwise `ambiguous`, which leaves a new requirement possible.
package/dist/.build-id CHANGED
@@ -1 +1 @@
1
- d1018322-muosc0k6
1
+ 7dd2aa11-muqzdhr1
@@ -37,10 +37,11 @@ exports.isLowRiskTarget = isLowRiskTarget;
37
37
  exports.evaluateEditEvidence = evaluateEditEvidence;
38
38
  exports.preEditEvidenceDecision = preEditEvidenceDecision;
39
39
  exports.loadEditEvidence = loadEditEvidence;
40
- // @implements A-SPEC-279, A-SPEC-278.1
40
+ // @implements A-SPEC-279, A-SPEC-278.1, A-SPEC-278.2, A-SPEC-278.3
41
41
  // @implements A-SPEC-278
42
42
  // @implements A-SPEC-277
43
43
  // @implements A-SPEC-276
44
+ const node_child_process_1 = require("node:child_process");
44
45
  const fs = __importStar(require("node:fs"));
45
46
  const crypto = __importStar(require("node:crypto"));
46
47
  const path = __importStar(require("node:path"));
@@ -272,7 +273,11 @@ function newestPersistedAnalysis(projectRoot, target, currentHead) {
272
273
  catch {
273
274
  return null;
274
275
  }
276
+ const newer = (a, b) => b === null || String(a.recordedAt ?? '') > String(b.recordedAt ?? '');
275
277
  let best = null;
278
+ const older = [];
279
+ let targetIsNew;
280
+ const isNew = () => (targetIsNew ??= !gitOk(projectRoot, ['cat-file', '-e', `${currentHead}:${target}`]));
276
281
  for (const { file } of entries.sort((a, b) => b.mtime - a.mtime).slice(0, PERSISTED_SCAN_LIMIT)) {
277
282
  let candidate;
278
283
  try {
@@ -281,14 +286,94 @@ function newestPersistedAnalysis(projectRoot, target, currentHead) {
281
286
  catch {
282
287
  continue;
283
288
  }
284
- if (candidate?.graphBasis?.head !== currentHead)
289
+ if (!Array.isArray(candidate?.predicted?.files) || typeof candidate?.graphBasis?.head !== 'string')
285
290
  continue;
286
- if (!Array.isArray(candidate?.predicted?.files) || !candidate.predicted.files.includes(target))
291
+ if (candidate.graphBasis.head !== currentHead) {
292
+ older.push(candidate);
287
293
  continue;
288
- if (best === null || String(candidate.recordedAt ?? '') > String(best.recordedAt ?? ''))
294
+ }
295
+ if (!coversTarget(candidate, target, isNew))
296
+ continue;
297
+ if (newer(candidate, best))
289
298
  best = candidate;
290
299
  }
291
- return best;
300
+ if (best)
301
+ return best;
302
+ // @implements A-SPEC-278.2 (rule 2) — an analysis at an ancestor ≤ 20 commits back still describes this tree when every
303
+ // file changed since it was predicted or named by its request (the RED commit adds only the request-named test). The
304
+ // copy carries the current head so the basis is not reported as drifted; the target's own digest still is.
305
+ const lineage = new Map();
306
+ for (const candidate of older.sort((a, b) => String(b.recordedAt ?? '').localeCompare(String(a.recordedAt ?? '')))) {
307
+ const a = candidate.graphBasis.head;
308
+ if (!coversTarget(candidate, target, isNew))
309
+ continue;
310
+ if (!lineage.has(a)) {
311
+ if (lineage.size >= LINEAGE_HEADS_MAX)
312
+ break;
313
+ lineage.set(a, unchangedOutside(projectRoot, a, currentHead, candidate));
314
+ }
315
+ if (lineage.get(a))
316
+ return { ...candidate, graphBasis: { ...candidate.graphBasis, head: currentHead } };
317
+ }
318
+ return null;
319
+ }
320
+ /** @implements A-SPEC-278.2 — distinct ancestor heads examined per judgement (each costs three bounded git calls). */
321
+ const LINEAGE_HEADS_MAX = 8;
322
+ const LINEAGE_DEPTH_MAX = 20;
323
+ /** The analysis request names `rel` as a whole path (not as part of a longer one). */
324
+ function requestNames(candidate, rel) {
325
+ // @implements A-SPEC-278.3 — a file the caller listed in changedFiles is named exactly, whatever the request text says.
326
+ const listed = candidate.changedFiles;
327
+ if (rel !== '' && Array.isArray(listed) && listed.includes(rel))
328
+ return true;
329
+ const request = candidate.request;
330
+ if (typeof request !== 'string' || rel === '')
331
+ return false;
332
+ let at = request.indexOf(rel);
333
+ while (at >= 0) {
334
+ const before = at === 0 ? '' : request[at - 1];
335
+ const after = request[at + rel.length] ?? '';
336
+ if (!/[\w./-]/.test(before) && !/[\w/-]/.test(after) && !(after === '.' && /[\w]/.test(request[at + rel.length + 1] ?? '')))
337
+ return true;
338
+ at = request.indexOf(rel, at + 1);
339
+ }
340
+ return false;
341
+ }
342
+ /** @implements A-SPEC-278.2 (rule 1) — predicted, or a file new at HEAD that the request names. */
343
+ function coversTarget(candidate, target, isNew) {
344
+ if (candidate.predicted.files.includes(target))
345
+ return true;
346
+ return requestNames(candidate, target) && isNew();
347
+ }
348
+ function unchangedOutside(projectRoot, ancestor, head, candidate) {
349
+ if (!/^[0-9a-f]{7,64}$/i.test(ancestor) || !gitOk(projectRoot, ['merge-base', '--is-ancestor', ancestor, head]))
350
+ return false;
351
+ const count = Number(gitText(projectRoot, ['rev-list', '--count', `${ancestor}..${head}`]));
352
+ if (!Number.isInteger(count) || count < 1 || count > LINEAGE_DEPTH_MAX)
353
+ return false;
354
+ const changed = gitText(projectRoot, ['diff', '--name-only', '--no-renames', ancestor, head]);
355
+ if (changed === null)
356
+ return false;
357
+ return changed.split('\n').filter(Boolean).every((f) => candidate.predicted.files.includes(f) || requestNames(candidate, f));
358
+ }
359
+ const GIT_TIMEOUT_MS = 5000;
360
+ const GIT_MAX_BUFFER = 1024 * 1024;
361
+ function gitOk(cwd, args) {
362
+ try {
363
+ (0, node_child_process_1.execFileSync)('git', ['-C', cwd, ...args], { timeout: GIT_TIMEOUT_MS, maxBuffer: GIT_MAX_BUFFER, stdio: ['ignore', 'pipe', 'ignore'] });
364
+ return true;
365
+ }
366
+ catch {
367
+ return false;
368
+ }
369
+ }
370
+ function gitText(cwd, args) {
371
+ try {
372
+ return (0, node_child_process_1.execFileSync)('git', ['-C', cwd, ...args], { timeout: GIT_TIMEOUT_MS, maxBuffer: GIT_MAX_BUFFER, stdio: ['ignore', 'pipe', 'ignore'], encoding: 'utf8' }).trim();
373
+ }
374
+ catch {
375
+ return null;
376
+ }
292
377
  }
293
378
  /**
294
379
  * @implements A-SPEC-278
@@ -154,6 +154,11 @@ function redirectTokenTester(tail) {
154
154
  let i = text.indexOf('>');
155
155
  while (i >= 0) {
156
156
  let j = i + 1;
157
+ // @implements A-SPEC-728.1 — one `&` or `|` right after `>` belongs to the operator (`>&`, `>|`): it ended the
158
+ // target token at once, so `echo x >& .ax/ledger/…` was `confirm` here (measured on 0.33.0 and 0.34.0).
159
+ const dup = text[j] === '&';
160
+ if (dup || text[j] === '|')
161
+ j++;
157
162
  while (j < text.length && /\s/.test(text[j]))
158
163
  j++;
159
164
  if (text[j] === '"' || text[j] === "'")
@@ -161,7 +166,9 @@ function redirectTokenTester(tail) {
161
166
  let k = j;
162
167
  while (k < text.length && !/[\s;&|]/.test(text[k]))
163
168
  k++;
164
- if (t.test(text.slice(j, k)))
169
+ const token = text.slice(j, k);
170
+ // `>&2`, `>& 2`, `>&-` duplicate or close a descriptor; they name no file.
171
+ if (!(dup && /^(?:\d+|-)$/.test(token)) && t.test(token))
165
172
  return true;
166
173
  // A `>` ending the token targets the NEXT token (after blanks); one inside it sees a suffix.
167
174
  i = text.indexOf('>', k > i + 1 && text[k - 1] === '>' ? k - 1 : Math.max(k, i + 1));
@@ -16,6 +16,12 @@ export declare function rmCommandTargets(cmd: string): string[];
16
16
  export declare function normalizeWindowsPathSpellings(cmd: string): string;
17
17
  export declare function scopeAxToProject(cmd: string, projectRoot?: string): string;
18
18
  export declare function normalizeCommandPaths(cmd: string, followCd?: boolean): string;
19
+ /**
20
+ * @implements A-SPEC-728.2 — the classifier's own read judgement of a whole shell text, loops included, for the identity
21
+ * layer: a `for` loop whose body only reads its variable's files names no mutation target with its word list.
22
+ */
23
+ export declare function shellTextOnlyReads(text: string): boolean;
24
+ export declare function stripCommitMessages(cmd: string): string;
19
25
  /**
20
26
  * @implements A-SPEC-125.1
21
27
  * Reversibility axis: can the action's effect be undone? Conservative default —
@@ -37,6 +37,8 @@ exports.rmCommandTargets = rmCommandTargets;
37
37
  exports.normalizeWindowsPathSpellings = normalizeWindowsPathSpellings;
38
38
  exports.scopeAxToProject = scopeAxToProject;
39
39
  exports.normalizeCommandPaths = normalizeCommandPaths;
40
+ exports.shellTextOnlyReads = shellTextOnlyReads;
41
+ exports.stripCommitMessages = stripCommitMessages;
40
42
  exports.classifyReversibility = classifyReversibility;
41
43
  exports.classifyArchitectureReversal = classifyArchitectureReversal;
42
44
  exports.classifySecret = classifySecret;
@@ -1476,6 +1478,26 @@ function isIndexRestoreClause(clause) {
1476
1478
  }
1477
1479
  return false;
1478
1480
  }
1481
+ /**
1482
+ * @implements A-SPEC-728.2 — the classifier's own read judgement of a whole shell text, loops included, for the identity
1483
+ * layer: a `for` loop whose body only reads its variable's files names no mutation target with its word list.
1484
+ */
1485
+ function shellTextOnlyReads(text) {
1486
+ return clausesAreReads(splitShellClauses(text), (c) => clauseIsRead(c, isReadOnlyShellClause));
1487
+ }
1488
+ /**
1489
+ * @implements A-SPEC-728.2 — a `git commit` message is text, not a path: `git commit -m "… .ax/specs …"` was refused as "not
1490
+ * recognisably read-only" (measured 2026-10-01). The values of `-m`/`--message`/`--message=`/`-F`/`--file` in a `git …
1491
+ * commit` segment are blanked before the `.ax` rules read the command. A double-quoted value holding `$` or a backtick (a
1492
+ * substitution runs), an unquoted value's redirect (`-m x>FILE`), and a pathspec stay as written.
1493
+ */
1494
+ const COMMIT_SEGMENT_RE = /(\bgit\b(?:\s+(?:-C|-c)\s+\S+|\s+--no-pager)*\s+commit\b)([^;&|\n]*)/g;
1495
+ const COMMIT_MESSAGE_RE = /(\s(?:-[a-zA-Z]*[mF]|--message|--file))(=|\s+)("(?:[^"\\$`]|\\[^$`])*"|'[^']*'|[^\s;&|<>()$`"']+)/g;
1496
+ function stripCommitMessages(cmd) {
1497
+ if (!/\bcommit\b/.test(cmd))
1498
+ return cmd;
1499
+ return cmd.replace(COMMIT_SEGMENT_RE, (_, head, rest) => head + rest.replace(COMMIT_MESSAGE_RE, '$1$2""'));
1500
+ }
1479
1501
  /**
1480
1502
  * A shell command that touches a protected governance path and is not recognisably read-only.
1481
1503
  *
@@ -1542,10 +1564,12 @@ function classifyReversibilityAsWritten(action) {
1542
1564
  // @implements A-SPEC-728 (round 9) — the cd-flattened text AND the text as written: flattening
1543
1565
  // followed a cd the shell never ran (`cd /nonexistent && true; echo x > .ax/ledger/p.jsonl` became an
1544
1566
  // other-project path and was allowed — measured). Judging both only ever adds refusals.
1545
- const flat = scopeAxToProject(normalizeCommandPaths(cmd), action.projectRoot);
1546
- const asWritten = scopeAxToProject(normalizeCommandPaths(cmd, false), action.projectRoot);
1567
+ // A-SPEC-728.2 — a commit message is text the `.ax` rules do not read.
1568
+ const axCmd = stripCommitMessages(cmd);
1569
+ const flat = scopeAxToProject(normalizeCommandPaths(axCmd), action.projectRoot);
1570
+ const asWritten = scopeAxToProject(normalizeCommandPaths(axCmd, false), action.projectRoot);
1547
1571
  // Round 10: and with every segment at the base the certain-cd model gives it (a second cd into .ax).
1548
- const bySegment = action.projectRoot ? scopeAxToProject(normalizeCommandPaths(segmentFlattened(cmd, action.projectRoot, action.cwd ?? action.projectRoot), false), action.projectRoot) : asWritten;
1572
+ const bySegment = action.projectRoot ? scopeAxToProject(normalizeCommandPaths(segmentFlattened(axCmd, action.projectRoot, action.cwd ?? action.projectRoot), false), action.projectRoot) : asWritten;
1549
1573
  const ncmd = [...new Set([flat, asWritten, bySegment])].join('\n');
1550
1574
  // @implements A-SPEC-737 — one reason served all four channels, so an interpreter READ was refused as
1551
1575
  // a "removal command" and the author could not tell what to change. Each channel names itself.
@@ -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;
@@ -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,
@@ -115,6 +115,15 @@ export declare function accountChangedFiles(changedFiles: string[], scanEntry: (
115
115
  implementsSpecs: string[];
116
116
  symbolCount: number;
117
117
  } | undefined): ChangedFileAccount;
118
+ /**
119
+ * @implements A-SPEC-750 — one left-to-right pass over source, replacing the regex passes that stripped comments, then
120
+ * strings, in sequence (a `/*`, `//` or backtick inside a literal began a comment or a template there and swallowed the
121
+ * real case heads up to the next closer — measured 2026-10-01: 72 test files counted fewer cases than Jest ran).
122
+ * Strings become `""`, a template keeps only its `${…}` code, comments become a space, and (when `js`) a regex literal
123
+ * becomes `/x/`. A failed regex attempt disables attempts until the end of that line, so a long line costs one pass.
124
+ * Without `js`, a backtick string is a raw string with no interpolation and `/` is never a regex.
125
+ */
126
+ export declare function stripCode(src: string, js: boolean): string;
118
127
  /** Frameworks this counter understands, for diagnostics and tests. */
119
128
  export declare const SUPPORTED_TEST_FRAMEWORKS: string[];
120
129
  export declare function countTestCases(source: string, filePath?: string): number;
@@ -36,11 +36,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.SUPPORTED_TEST_FRAMEWORKS = void 0;
37
37
  exports.architectureGoverningFiles = architectureGoverningFiles;
38
38
  exports.accountChangedFiles = accountChangedFiles;
39
+ exports.stripCode = stripCode;
39
40
  exports.countTestCases = countTestCases;
40
41
  exports.extractAnchors = extractAnchors;
41
42
  exports.scanTestAnchors = scanTestAnchors;
42
43
  exports.computeTestScope = computeTestScope;
43
- // @implements A-SPEC-121.2, A-SPEC-734
44
+ // @implements A-SPEC-121.2, A-SPEC-734, A-SPEC-750
44
45
  const anchor_ids_1 = require("./anchor-ids");
45
46
  const fs = __importStar(require("node:fs"));
46
47
  const path = __importStar(require("node:path"));
@@ -143,11 +144,282 @@ function accountChangedFiles(changedFiles, scanEntry) {
143
144
  * wrappers or aliasing can still fabricate heads. Execution proof is the test RUNNER's job
144
145
  * (planTestRun/runTestScope); this counter only stops declared coverage over an absent/empty suite.
145
146
  */
146
- /** Strip block/line comments and string literals from C-family source. */
147
- const stripCFamily = (src) => src
148
- .replace(/\/\*[\s\S]*?\*\//g, ' ') // block comments
149
- .replace(/(^|[^:])\/\/[^\n]*/g, '$1 ') // line comments (not ://)
150
- .replace(/'(?:\\.|[^'\\\n])*'|"(?:\\.|[^"\\\n])*"|`(?:\\.|[^`\\])*`/g, '""');
147
+ /** Keywords after which a `/` starts a regex literal rather than a division. */
148
+ const REGEX_AFTER_KEYWORD = new Set(['return', 'typeof', 'instanceof', 'in', 'of', 'new', 'delete', 'void', 'throw', 'case', 'do',
149
+ 'else', 'yield', 'await']);
150
+ // Character classes by code: a regex test per character made the lexer seven times slower than the regex counter it
151
+ // replaces (measured 2026-10-02: 170 ms against 25 ms over the 648-file tree).
152
+ const isIdentStart = (cc) => (cc >= 97 && cc <= 122) || (cc >= 65 && cc <= 90) || cc === 95 || cc === 36 || cc > 127;
153
+ const isIdentPart = (cc) => isIdentStart(cc) || (cc >= 48 && cc <= 57);
154
+ const isSpace = (cc) => cc === 32 || cc === 10 || cc === 9 || cc === 13 || cc === 11 || cc === 12 || cc === 160;
155
+ const PLAIN_RUN = /[^/'"`{}]+/y;
156
+ /** Whether a `/` after the run src[from, to) may start a regex: by the run's last significant token, else `prev`. */
157
+ function regexOkAfterRun(src, from, to, prev) {
158
+ let k = to - 1;
159
+ while (k >= from && isSpace(src.charCodeAt(k)))
160
+ k--;
161
+ if (k < from)
162
+ return prev;
163
+ const cc = src.charCodeAt(k);
164
+ if (cc === 41 || cc === 93)
165
+ return false;
166
+ if (!isIdentPart(cc))
167
+ return true;
168
+ let w = k;
169
+ while (w > from && isIdentPart(src.charCodeAt(w - 1)))
170
+ w--;
171
+ const first = src.charCodeAt(w);
172
+ if (first >= 48 && first <= 57)
173
+ return false;
174
+ // Only a short word can be a keyword: slicing every identifier would cost more than the whole lexer.
175
+ return k - w < 10 && REGEX_AFTER_KEYWORD.has(src.slice(w, k + 1));
176
+ }
177
+ /** Index just past a quoted string starting at `i`; a string ends at its quote or at a newline. */
178
+ function endOfQuoted(src, i, quote) {
179
+ for (let j = i + 1; j < src.length; j++) {
180
+ const ch = src[j];
181
+ if (ch === '\\') {
182
+ j++;
183
+ continue;
184
+ }
185
+ if (ch === quote)
186
+ return j + 1;
187
+ if (ch === '\n')
188
+ return j;
189
+ }
190
+ return src.length;
191
+ }
192
+ /** From inside a template, the index after its closing backtick, or after the next `${` (interp = true). */
193
+ function scanTemplate(src, j) {
194
+ for (; j < src.length; j++) {
195
+ const ch = src[j];
196
+ if (ch === '\\') {
197
+ j++;
198
+ continue;
199
+ }
200
+ if (ch === '`')
201
+ return { next: j + 1, interp: false };
202
+ if (ch === '$' && src[j + 1] === '{')
203
+ return { next: j + 2, interp: true };
204
+ }
205
+ return { next: src.length, interp: false };
206
+ }
207
+ /** Index just past a regex literal starting at `i`, or -1 when none closes before the line ends. */
208
+ function endOfRegex(src, i) {
209
+ let inClass = false;
210
+ for (let j = i + 1; j < src.length; j++) {
211
+ const ch = src[j];
212
+ if (ch === '\n' || ch === '\r')
213
+ return -1;
214
+ if (ch === '\\') {
215
+ j++;
216
+ continue;
217
+ }
218
+ if (ch === '[')
219
+ inClass = true;
220
+ else if (ch === ']')
221
+ inClass = false;
222
+ else if (ch === '/' && !inClass) {
223
+ let k = j + 1;
224
+ while (k < src.length && /[A-Za-z]/.test(src[k]))
225
+ k++;
226
+ return k;
227
+ }
228
+ }
229
+ return -1;
230
+ }
231
+ /**
232
+ * @implements A-SPEC-750 — one left-to-right pass over source, replacing the regex passes that stripped comments, then
233
+ * strings, in sequence (a `/*`, `//` or backtick inside a literal began a comment or a template there and swallowed the
234
+ * real case heads up to the next closer — measured 2026-10-01: 72 test files counted fewer cases than Jest ran).
235
+ * Strings become `""`, a template keeps only its `${…}` code, comments become a space, and (when `js`) a regex literal
236
+ * becomes `/x/`. A failed regex attempt disables attempts until the end of that line, so a long line costs one pass.
237
+ * Without `js`, a backtick string is a raw string with no interpolation and `/` is never a regex.
238
+ */
239
+ function stripCode(src, js) {
240
+ const out = [];
241
+ const n = src.length;
242
+ let i = 0;
243
+ let start = 0;
244
+ let regexOk = true;
245
+ let regexOffUntil = -1;
246
+ const interp = [];
247
+ const emit = (text, next) => { out.push(src.slice(start, i), text); i = next; start = next; };
248
+ const template = (from, lead) => {
249
+ const t = scanTemplate(src, from);
250
+ if (t.interp) {
251
+ emit(lead + '${', t.next);
252
+ interp.push(0);
253
+ regexOk = true;
254
+ }
255
+ else {
256
+ emit(lead + '`', t.next);
257
+ regexOk = false;
258
+ }
259
+ };
260
+ while (i < n) {
261
+ const c = src[i];
262
+ if (c === '/' && src[i + 1] === '/') {
263
+ const e = src.indexOf('\n', i);
264
+ emit(' ', e < 0 ? n : e);
265
+ continue;
266
+ }
267
+ if (c === '/' && src[i + 1] === '*') {
268
+ const e = src.indexOf('*/', i + 2);
269
+ emit(' ', e < 0 ? n : e + 2);
270
+ continue;
271
+ }
272
+ if (c === '"' || c === "'") {
273
+ emit('""', endOfQuoted(src, i, c));
274
+ regexOk = false;
275
+ continue;
276
+ }
277
+ if (c === '`') {
278
+ if (js) {
279
+ template(i + 1, '`');
280
+ continue;
281
+ }
282
+ let j = i + 1;
283
+ while (j < n && src[j] !== '`')
284
+ j += src[j] === '\\' ? 2 : 1;
285
+ emit('""', Math.min(n, j + 1));
286
+ regexOk = false;
287
+ continue;
288
+ }
289
+ if (js && c === '}' && interp.length > 0 && interp[interp.length - 1] === 0) {
290
+ interp.pop();
291
+ template(i + 1, '}');
292
+ continue;
293
+ }
294
+ if (js && c === '/' && regexOk && i >= regexOffUntil) {
295
+ const e = endOfRegex(src, i);
296
+ if (e > 0) {
297
+ emit('/x/', e);
298
+ regexOk = false;
299
+ continue;
300
+ }
301
+ const nl = src.indexOf('\n', i);
302
+ regexOffUntil = nl < 0 ? n : nl;
303
+ i++;
304
+ regexOk = true;
305
+ continue;
306
+ }
307
+ // Everything but the six characters that open or close a literal, a comment or a brace is copied as one run; only
308
+ // its last significant token matters, for whether a following `/` may start a regex.
309
+ PLAIN_RUN.lastIndex = i;
310
+ if (PLAIN_RUN.test(src)) {
311
+ const j = PLAIN_RUN.lastIndex;
312
+ regexOk = regexOkAfterRun(src, i, j, regexOk);
313
+ i = j;
314
+ continue;
315
+ }
316
+ if (c === '{' && interp.length > 0)
317
+ interp[interp.length - 1]++;
318
+ else if (c === '}' && interp.length > 0)
319
+ interp[interp.length - 1]--;
320
+ regexOk = true;
321
+ i++;
322
+ }
323
+ out.push(src.slice(start, n));
324
+ return out.join('');
325
+ }
326
+ /** Index after spaces, tabs and newlines. */
327
+ function skipSpace(code, j) {
328
+ while (j < code.length && /\s/.test(code[j]))
329
+ j++;
330
+ return j;
331
+ }
332
+ /** Index just past the group opened at `j` (`(`, `[`, `{` or a stripped template), or the end of the code. */
333
+ function skipGroup(code, j) {
334
+ if (code[j] === '`') {
335
+ for (j++; j < code.length; j++) {
336
+ if (code[j] === '`')
337
+ return j + 1;
338
+ if (code[j] === '$' && code[j + 1] === '{')
339
+ j = skipGroup(code, j + 1) - 1;
340
+ }
341
+ return code.length;
342
+ }
343
+ let depth = 0;
344
+ for (; j < code.length; j++) {
345
+ const ch = code[j];
346
+ if (ch === '`') {
347
+ j = skipGroup(code, j) - 1;
348
+ continue;
349
+ }
350
+ if (ch === '(' || ch === '[' || ch === '{')
351
+ depth++;
352
+ else if (ch === ')' || ch === ']' || ch === '}') {
353
+ if (--depth === 0)
354
+ return j + 1;
355
+ }
356
+ }
357
+ return code.length;
358
+ }
359
+ const JEST_HEADS = ['it', 'test', 'fit'];
360
+ // @implements A-SPEC-653 — the platform helpers of A-SPEC-220.3 (`posixOnly('why')(…)`) are heads too: a POSIX-only suite
361
+ // written with the REPORTING skip must not read as "no real cases". `.skip` on a helper is still not a head.
362
+ const JEST_HELPERS = new Set(['posixOnly', 'posixOnlyNonRoot', 'posixOnlyWithCommand', 'win32Only']);
363
+ // @implements A-SPEC-750 — searched in the stripped CODE: a skip token inside a string or a comment (this counter's own tests
364
+ // hold several) no longer forfeits the file; one in code, including an alias line or any computed access, still does.
365
+ const JEST_SUITE_SKIP = /(?<![\w$.])describe\s*(?:\.\s*skip(?![\w$])|\[)|(?<![\w$])xdescribe(?![\w$])/;
366
+ const JEST_ALIAS_HINT = /=\s*(?:it|test|fit|posixOnly|posixOnlyNonRoot|posixOnlyWithCommand|win32Only)(?![\w$])/;
367
+ const JEST_ALIAS = /(?<![\w$.])(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*(?::[^=;]*)?=\s*(it|test|fit|posixOnly|posixOnlyNonRoot|posixOnlyWithCommand|win32Only)(?![\w$])/g;
368
+ /**
369
+ * Jest cases in stripped code: a standalone `it|test|fit` (or a same-file alias of one, or of a platform helper call)
370
+ * followed by `(`, or by `.each(…)(` / `.each` + template + `(`. Method calls (`re.test(`) never match: the head must not
371
+ * follow a `.`. `it.skip(`/`it.todo(`/`xit(` never match, so nothing is subtracted.
372
+ */
373
+ function jestCount(code) {
374
+ if (JEST_SUITE_SKIP.test(code))
375
+ return 0;
376
+ const direct = new Set(JEST_HEADS);
377
+ // Most files bind no alias; the declaration scan below visits every `const`, so it runs only when an alias can exist.
378
+ if (JEST_ALIAS_HINT.test(code))
379
+ for (const m of code.matchAll(JEST_ALIAS)) {
380
+ let j = m.index + m[0].length;
381
+ if (JEST_HELPERS.has(m[2])) {
382
+ j = skipSpace(code, j);
383
+ if (code[j] !== '(')
384
+ continue;
385
+ j = skipGroup(code, j);
386
+ }
387
+ while (j < code.length && (code[j] === ' ' || code[j] === '\t'))
388
+ j++;
389
+ if (j >= code.length || ';,\n\r}'.includes(code[j]))
390
+ direct.add(m[1]);
391
+ }
392
+ const names = [...direct, ...[...JEST_HELPERS].filter((h) => !direct.has(h))].map((s) => s.replace(/\$/g, '\\$'));
393
+ let cases = 0;
394
+ for (const m of code.matchAll(new RegExp(`(?<![\\w$.])(?:${names.join('|')})(?![\\w$])`, 'g'))) {
395
+ let j = m.index + m[0].length;
396
+ if (!direct.has(m[0])) {
397
+ j = skipSpace(code, j);
398
+ if (code[j] !== '(')
399
+ continue;
400
+ j = skipGroup(code, j);
401
+ }
402
+ j = skipSpace(code, j);
403
+ if (code[j] === '(') {
404
+ cases++;
405
+ continue;
406
+ }
407
+ if (code[j] !== '.')
408
+ continue;
409
+ let k = skipSpace(code, j + 1);
410
+ if (!code.startsWith('each', k) || /[\w$]/.test(code[k + 4] ?? ''))
411
+ continue;
412
+ k = skipSpace(code, k + 4);
413
+ if (code[k] !== '(' && code[k] !== '`')
414
+ continue;
415
+ k = skipSpace(code, skipGroup(code, k));
416
+ if (code[k] === '(')
417
+ cases++;
418
+ }
419
+ return cases;
420
+ }
421
+ /** Strip block/line comments and string literals from C-family source (no regex literals, no interpolation). */
422
+ const stripCFamily = (src) => stripCode(src, false);
151
423
  /** Strip `#` comments, docstrings and string literals from Python source. */
152
424
  const stripPython = (src) => src
153
425
  .replace(/'''[\s\S]*?'''|"""[\s\S]*?"""/g, '""') // docstrings first — they may contain #
@@ -168,14 +440,10 @@ const FRAMEWORKS = [
168
440
  {
169
441
  id: 'jest',
170
442
  ext: /\.(ts|mts|cts|tsx|jsx|js|mjs|cjs)$/i,
171
- strip: stripCFamily,
172
- suiteSkip: /\bdescribe\s*(?:\.\s*skip|\[\s*['"]skip['"]\s*\])|\bxdescribe\b/,
173
- // Head must be a STANDALONE identifier (not `.test(`/`.it(` method calls) followed directly by
174
- // `(` or by `.each(...)(`: `it.skip(`/`it.todo(`/`xit(` never match — no subtraction needed.
175
- // @implements A-SPEC-653 — the platform helpers of A-SPEC-220.3 (`posixOnly('why')(…)`) are heads too:
176
- // a POSIX-only suite written with the REPORTING skip must not read as "no real cases" (measured: that
177
- // is why two suites had used a bare early return instead). `.skip` on a helper is still not a head.
178
- head: /(?<![.\w])(?:it|test|fit|(?:posixOnly|posixOnlyNonRoot|posixOnlyWithCommand|win32Only)\s*\([^)]*\))(?:\s*\.\s*each\s*\([^)]*\)\s*)?\s*\(/g,
443
+ strip: (src) => stripCode(src, true),
444
+ suiteSkip: JEST_SUITE_SKIP,
445
+ head: /(?!)/g,
446
+ count: (src) => jestCount(stripCode(src, true)),
179
447
  },
180
448
  {
181
449
  id: 'pytest',
@@ -246,6 +514,8 @@ const ruleFor = (filePath) => (filePath && FRAMEWORKS.find((f) => f.ext.test(fil
246
514
  exports.SUPPORTED_TEST_FRAMEWORKS = FRAMEWORKS.map((f) => f.id);
247
515
  function countTestCases(source, filePath) {
248
516
  const rule = ruleFor(filePath);
517
+ if (rule.count)
518
+ return rule.count(source);
249
519
  const stripped = rule.strip(source);
250
520
  // Suite-skip detection runs on the ORIGINAL source: string-stripping turns `describe['skip'](`
251
521
  // into `describe[""](`, hiding the marker (round-2 test caught this). Comments are already
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "//": "@implements A-SPEC-209",
3
3
  "name": "@holmes-lab/holmes-kit",
4
- "version": "0.34.0",
4
+ "version": "0.35.0",
5
5
  "description": "Holmes-Kit — deterministic Agentic Software Engineering (ASE) harness with causal traceability (spec chain + D-CPG + RTM + phase guardrail)",
6
6
  "main": "dist/holmes/mcp/server.js",
7
7
  "types": "dist/holmes/mcp/server.d.ts",