@holmes-lab/holmes-kit 0.30.0 → 0.31.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.
Files changed (139) hide show
  1. package/CHANGELOG.md +505 -0
  2. package/README.md +10 -1
  3. package/bin/holmes-hook-antigravity.js +4 -0
  4. package/bin/holmes-kit.js +4 -0
  5. package/bin/holmes-pre-push.js +3 -0
  6. package/bin/holmes-stop-antigravity.js +4 -0
  7. package/dist/.build-id +1 -1
  8. package/dist/holmes/cli/agents.d.ts +41 -0
  9. package/dist/holmes/cli/agents.js +382 -2
  10. package/dist/holmes/cli/attest.d.ts +2 -0
  11. package/dist/holmes/cli/attest.js +66 -15
  12. package/dist/holmes/cli/ci-gate.js +16 -1
  13. package/dist/holmes/cli/claude-switches.d.ts +95 -0
  14. package/dist/holmes/cli/claude-switches.js +967 -0
  15. package/dist/holmes/cli/codex-hooks.d.ts +77 -0
  16. package/dist/holmes/cli/codex-hooks.js +802 -0
  17. package/dist/holmes/cli/codex-oracle.d.ts +194 -0
  18. package/dist/holmes/cli/codex-oracle.js +1245 -0
  19. package/dist/holmes/cli/codex-toml.d.ts +35 -0
  20. package/dist/holmes/cli/codex-toml.js +321 -52
  21. package/dist/holmes/cli/doctor.d.ts +98 -8
  22. package/dist/holmes/cli/doctor.js +1328 -94
  23. package/dist/holmes/cli/index.js +26 -11
  24. package/dist/holmes/cli/init.d.ts +11 -0
  25. package/dist/holmes/cli/init.js +736 -44
  26. package/dist/holmes/cli/mcp-launcher.d.ts +64 -6
  27. package/dist/holmes/cli/mcp-launcher.js +189 -6
  28. package/dist/holmes/cli/mcp-version.js +13 -2
  29. package/dist/holmes/cli/settings-merge.js +8 -2
  30. package/dist/holmes/cli/upgrade.d.ts +18 -0
  31. package/dist/holmes/cli/upgrade.js +129 -24
  32. package/dist/holmes/cli/workspace-scope.d.ts +22 -0
  33. package/dist/holmes/cli/workspace-scope.js +375 -0
  34. package/dist/holmes/cpg/cpg-scanner.d.ts +29 -0
  35. package/dist/holmes/cpg/cpg-scanner.js +403 -3
  36. package/dist/holmes/cpg/cycle-detect.js +2 -1
  37. package/dist/holmes/cpg/forbidden-edges.js +9 -2
  38. package/dist/holmes/cpg/required-calls.js +8 -1
  39. package/dist/holmes/governance/constitution-debt.js +3 -2
  40. package/dist/holmes/governance/constitution.js +15 -3
  41. package/dist/holmes/governance/provenance-chain.js +3 -2
  42. package/dist/holmes/governance/push-gate-runner.js +4 -3
  43. package/dist/holmes/guardrail/dependency-delta.js +4 -3
  44. package/dist/holmes/guardrail/linear-match.d.ts +57 -0
  45. package/dist/holmes/guardrail/linear-match.js +256 -0
  46. package/dist/holmes/guardrail/risk-classifier.d.ts +6 -7
  47. package/dist/holmes/guardrail/risk-classifier.js +931 -44
  48. package/dist/holmes/guardrail/risk-types.d.ts +6 -0
  49. package/dist/holmes/guardrail/scope-judgment.d.ts +4 -24
  50. package/dist/holmes/guardrail/scope-judgment.js +100 -23
  51. package/dist/holmes/guardrail/shell-words.d.ts +42 -0
  52. package/dist/holmes/guardrail/shell-words.js +1720 -0
  53. package/dist/holmes/guardrail/write-target.d.ts +168 -3
  54. package/dist/holmes/guardrail/write-target.js +2379 -87
  55. package/dist/holmes/hooks/adapters/antigravity.d.ts +3 -1
  56. package/dist/holmes/hooks/adapters/antigravity.js +115 -11
  57. package/dist/holmes/hooks/pre-tool-use.d.ts +32 -6
  58. package/dist/holmes/hooks/pre-tool-use.js +923 -87
  59. package/dist/holmes/hooks/rtm-refresh-child.js +3 -1
  60. package/dist/holmes/hooks/rtm-refresh.js +8 -4
  61. package/dist/holmes/hooks/session-start.d.ts +10 -0
  62. package/dist/holmes/hooks/session-start.js +31 -7
  63. package/dist/holmes/hooks/stop.d.ts +2 -1
  64. package/dist/holmes/hooks/stop.js +197 -91
  65. package/dist/holmes/mcp/approval-commit.d.ts +5 -6
  66. package/dist/holmes/mcp/approval-commit.js +18 -2
  67. package/dist/holmes/mcp/elicit-approval.js +4 -2
  68. package/dist/holmes/mcp/handlers/graph-operations.js +3 -2
  69. package/dist/holmes/mcp/handlers/maintenance-analysis.js +11 -5
  70. package/dist/holmes/mcp/handlers/maintenance-evidence.js +3 -2
  71. package/dist/holmes/mcp/handlers/phase-queries.d.ts +22 -7
  72. package/dist/holmes/mcp/handlers/phase-queries.js +81 -2
  73. package/dist/holmes/mcp/handlers/requirement-triage.js +5 -3
  74. package/dist/holmes/mcp/handlers/review-evidence.js +8 -2
  75. package/dist/holmes/mcp/handlers/slice-orchestration.d.ts +11 -0
  76. package/dist/holmes/mcp/handlers/slice-orchestration.js +115 -16
  77. package/dist/holmes/mcp/handlers/spec-approval.d.ts +9 -0
  78. package/dist/holmes/mcp/handlers/spec-approval.js +110 -17
  79. package/dist/holmes/mcp/handlers/spec-authoring.js +17 -2
  80. package/dist/holmes/mcp/handlers/spec-queries.d.ts +39 -3
  81. package/dist/holmes/mcp/handlers/spec-queries.js +114 -7
  82. package/dist/holmes/mcp/handlers/test-execution.js +9 -3
  83. package/dist/holmes/mcp/handlers.d.ts +81 -9
  84. package/dist/holmes/mcp/handlers.js +70 -23
  85. package/dist/holmes/mcp/harness-attestation.d.ts +20 -0
  86. package/dist/holmes/mcp/harness-attestation.js +179 -0
  87. package/dist/holmes/mcp/requirement-triage-evidence.d.ts +36 -0
  88. package/dist/holmes/mcp/requirement-triage-evidence.js +160 -4
  89. package/dist/holmes/mcp/server.js +20 -1
  90. package/dist/holmes/mcp/tool-schemas.js +26 -9
  91. package/dist/holmes/mcp/validate-args.js +12 -0
  92. package/dist/holmes/project/bounded-io.d.ts +102 -0
  93. package/dist/holmes/project/bounded-io.js +212 -0
  94. package/dist/holmes/project/change-source.js +3 -1
  95. package/dist/holmes/project/ci-runs.js +3 -2
  96. package/dist/holmes/project/ignore.d.ts +31 -2
  97. package/dist/holmes/project/ignore.js +409 -50
  98. package/dist/holmes/project/regular-file-guard.d.ts +13 -0
  99. package/dist/holmes/project/regular-file-guard.js +149 -0
  100. package/dist/holmes/project/root.js +12 -3
  101. package/dist/holmes/reverse/anchor.js +4 -3
  102. package/dist/holmes/reverse/scan.js +6 -2
  103. package/dist/holmes/review/commit-text.js +3 -2
  104. package/dist/holmes/review/condition-hunk-replay.js +3 -2
  105. package/dist/holmes/review/failed-test-names.js +13 -10
  106. package/dist/holmes/review/findings.js +3 -1
  107. package/dist/holmes/review/kills-check.js +6 -1
  108. package/dist/holmes/review/point-in-time-replay.js +5 -4
  109. package/dist/holmes/review/replay-corpus.js +5 -4
  110. package/dist/holmes/review/run-replay.js +3 -2
  111. package/dist/holmes/review/temporal-prior.js +3 -2
  112. package/dist/holmes/review/test-evidence.js +3 -2
  113. package/dist/holmes/review/test-outcomes.js +3 -2
  114. package/dist/holmes/review/test-runner.d.ts +6 -0
  115. package/dist/holmes/review/test-runner.js +36 -15
  116. package/dist/holmes/rtm/advisory-outcomes.js +3 -2
  117. package/dist/holmes/rtm/anchor-ids.js +42 -2
  118. package/dist/holmes/rtm/file-anchors.js +4 -1
  119. package/dist/holmes/rtm/ftt-fulfilment.js +8 -3
  120. package/dist/holmes/rtm/git-changes.js +3 -1
  121. package/dist/holmes/rtm/graph-store.js +3 -2
  122. package/dist/holmes/rtm/test-scope.js +9 -4
  123. package/dist/holmes/spec/compat-impact.d.ts +25 -4
  124. package/dist/holmes/spec/compat-impact.js +682 -11
  125. package/dist/holmes/spec/entity-git-snapshot.js +3 -2
  126. package/dist/holmes/spec/entity-integration.js +3 -2
  127. package/dist/holmes/spec/entity-renumber-transaction.d.ts +19 -0
  128. package/dist/holmes/spec/entity-renumber-transaction.js +79 -6
  129. package/dist/holmes/spec/remote-spec-refs.js +3 -2
  130. package/dist/holmes/spec/renumber.js +25 -10
  131. package/dist/holmes/spec/spec-parser.js +9 -3
  132. package/dist/holmes/spec/yaml-scalar.js +2 -2
  133. package/dist/holmes/update/refresh.d.ts +5 -0
  134. package/dist/holmes/update/refresh.js +26 -1
  135. package/dist/holmes/update/update-notice.d.ts +6 -0
  136. package/dist/holmes/update/update-notice.js +18 -1
  137. package/dist/holmes/update/upgrade-plan.d.ts +28 -0
  138. package/dist/holmes/update/upgrade-plan.js +31 -2
  139. package/package.json +11 -4
@@ -72,7 +72,8 @@ function externalImportsOf(source, lang) {
72
72
  // A from-clause ENDS some line — any non-quote prefix, so prettier's `} from 'pkg'` is caught.
73
73
  for (const m of src.matchAll(/^[^'"`\n]*\bfrom\s*['"]([^'"\n]+)['"]/gm))
74
74
  add(m[1]);
75
- for (const m of src.matchAll(/^\s*import\s*['"]([^'"\n]+)['"]/gm))
75
+ // A-SPEC-733 (round 12 census): `[ \t]*` at a multi-line anchor, never `\s*` (a blank run is rescanned from every line).
76
+ for (const m of src.matchAll(/^[ \t]*import\s*['"]([^'"\n]+)['"]/gm))
76
77
  add(m[1]); // side-effect import
77
78
  // require()/dynamic import() are position-free, so reject matches sitting inside a string
78
79
  // literal (quote parity before the match on its line) and method calls (`loader.require`).
@@ -97,13 +98,13 @@ function externalImportsOf(source, lang) {
97
98
  if (pkg !== '' && !PY_STDLIB.has(pkg))
98
99
  out.add(pkg);
99
100
  };
100
- for (const m of src.matchAll(/^\s*import\s+(.+)$/gm)) {
101
+ for (const m of src.matchAll(/^[ \t]*import[ \t]+(.+)$/gm)) {
101
102
  // `import a, b as c` — every comma part counts; sanitize each to a leading dotted name so a
102
103
  // trailing `;`/comment fragment can never fabricate a package token.
103
104
  for (const part of m[1].split(','))
104
105
  add(/^[A-Za-z_][\w.]*/.exec(part.trim())?.[0]);
105
106
  }
106
- for (const m of src.matchAll(/^\s*from\s+([.\w]+)\s+import\b/gm))
107
+ for (const m of src.matchAll(/^[ \t]*from[ \t]+([.\w]+)[ \t]+import\b/gm))
107
108
  add(m[1]);
108
109
  }
109
110
  }
@@ -0,0 +1,57 @@
1
+ export interface Tester {
2
+ test(text: string): boolean;
3
+ }
4
+ /**
5
+ * @implements A-SPEC-733 (round 8) — `s` without its trailing run of `chars`, in one backward pass.
6
+ * `s.replace(/[set]+$/, '')` restarts at every position of a long run that is not at the end
7
+ * (80 KB: 2.8–3.7 s, measured); the answer is the same.
8
+ */
9
+ export declare function trimTrailing(s: string, chars: string): string;
10
+ /**
11
+ * `HEAD [^SEP]* TAIL`: TAIL anywhere after the first HEAD of a SEP-free piece. TAIL also sees the
12
+ * separator that ends the piece, exactly as the regex did (`(?:\s|$)` matches a newline separator;
13
+ * `$` matches only at the very end).
14
+ */
15
+ export declare function headThenTail(head: RegExp, sep: RegExp, tail: RegExp): Tester;
16
+ /**
17
+ * `HEAD [^PIECE_SEP]* MID [^LINE_SEP]* TAIL`: MID after the first HEAD of a piece, then TAIL anywhere
18
+ * later on the same line. The earliest qualifying MID on a line leaves the longest remainder, so the
19
+ * TAIL is tested once per line.
20
+ */
21
+ export declare function headMidTail(head: RegExp, pieceSep: RegExp, mid: RegExp, lineSep: RegExp, tail: RegExp): Tester;
22
+ /**
23
+ * The paths a `HEAD [^;|&]*? PATH` extraction regex would find, as a SUPERSET, in linear time. The
24
+ * lazy regex tried the path alternatives at every position after every HEAD — quadratic on a
25
+ * repeated HEAD or one long token (110 s measured at 200 KB). Per `;|&`-free piece, after the first
26
+ * HEAD (and MID, when given), every candidate the regex could capture is returned: each quoted span
27
+ * whose content ends with PATH (trailing blanks dropped), and each unquoted run of path characters up
28
+ * to its last PATH occurrence that ends on a word boundary. More candidates only ever mean more
29
+ * judgment, never less.
30
+ */
31
+ export declare function pathsAfter(text: string, head: RegExp, path: string, mid?: RegExp): string[];
32
+ /**
33
+ * `> \s* ['"]? [^\s;&|]* TAIL` (a redirect whose target token contains TAIL), linear: each redirect
34
+ * target token is scanned once; a `>` inside a token already scanned can only see a suffix of it,
35
+ * and a suffix holds no TAIL match the whole token did not.
36
+ */
37
+ export declare function redirectTokenTester(tail: RegExp): Tester;
38
+ /**
39
+ * @implements A-SPEC-728 (rule 37) — `open(…, 'w')`: an `open(` whose call, before its first `)`, passes a
40
+ * writing mode. The regex `\bopen\s*\([^)]*,\s*['"]MODE['"]` rescanned to the next `)` from every `open(`, so
41
+ * `open(,open(,…` without a `)` was quadratic (198 KB: 3.0 s of a 4.2 s verdict — measured); this decides the same.
42
+ */
43
+ export declare function openForWriting(ignoreCase?: boolean): Tester;
44
+ /**
45
+ * @implements A-SPEC-728 (rule 38) — whether spec text sets `status: approved`, deciding exactly what
46
+ * `/^\s*status\s*:\s*["']?approved["']?\s*(?:#.*)?$/im` decided, in one pass: with the `m` flag `\s*` crossed newlines from
47
+ * every line start, so 48 KB of blank lines took 1.6 s and 250 KB the 20 s deadline (measured). A `status` counts when the
48
+ * whitespace before it reaches the text's start or a line end; after `approved` (and an optional quote) the whitespace
49
+ * reaches a line end or the end, or a `#` comment.
50
+ */
51
+ export declare function setsApprovedStatus(text: string): boolean;
52
+ /**
53
+ * @implements A-SPEC-728 (rule 39) — a URL without its query and fragment, deciding what `url.replace(/[?#].*$/, '')` decided
54
+ * in one pass: `.` stops at a line end and `$` is the text's end, so the cut is at the first `?` or `#` after the last line
55
+ * end, and the regex rescanned to that line end from every earlier `?` (120,000 of them took 8.9 s — measured).
56
+ */
57
+ export declare function stripUrlTail(url: string): string;
@@ -0,0 +1,256 @@
1
+ "use strict";
2
+ // @implements A-SPEC-733, A-SPEC-728
3
+ // Linear forms of the `HEAD[^SEP]*TAIL` regex shape the gate uses everywhere. A backtracking engine
4
+ // restarts that shape at every HEAD and rescans to the next separator, so a command that repeats
5
+ // HEAD (`node node node …`) costs O(n²): 200 KB took 3–5 s, and a hook verdict that arrives after the
6
+ // 30 s timeout lets the call through (round 5, measured). Every tester here decides exactly what the
7
+ // regex decided, in one pass per separator-free piece: the FIRST head in a piece leaves the longest
8
+ // suffix, so if any head is followed by TAIL, the first one is.
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.trimTrailing = trimTrailing;
11
+ exports.headThenTail = headThenTail;
12
+ exports.headMidTail = headMidTail;
13
+ exports.pathsAfter = pathsAfter;
14
+ exports.redirectTokenTester = redirectTokenTester;
15
+ exports.openForWriting = openForWriting;
16
+ exports.setsApprovedStatus = setsApprovedStatus;
17
+ exports.stripUrlTail = stripUrlTail;
18
+ /**
19
+ * @implements A-SPEC-733 (round 8) — `s` without its trailing run of `chars`, in one backward pass.
20
+ * `s.replace(/[set]+$/, '')` restarts at every position of a long run that is not at the end
21
+ * (80 KB: 2.8–3.7 s, measured); the answer is the same.
22
+ */
23
+ function trimTrailing(s, chars) {
24
+ let e = s.length;
25
+ while (e > 0 && chars.includes(s[e - 1]))
26
+ e--;
27
+ return e === s.length ? s : s.slice(0, e);
28
+ }
29
+ const once = (re) => new RegExp(re.source, re.flags.replace(/[gy]/g, ''));
30
+ /** The SEP-free pieces of `text`, each with the separator that ended it ('' for the last). */
31
+ function pieces(text, sep) {
32
+ const g = new RegExp(sep.source, `${sep.flags.replace(/[gy]/g, '')}g`);
33
+ const out = [];
34
+ let start = 0;
35
+ for (const m of text.matchAll(g)) {
36
+ const at = m.index ?? 0;
37
+ if (m[0].length === 0)
38
+ continue;
39
+ out.push({ start, body: text.slice(start, at), ender: m[0] });
40
+ start = at + m[0].length;
41
+ }
42
+ out.push({ start, body: text.slice(start), ender: '' });
43
+ return out;
44
+ }
45
+ /**
46
+ * `HEAD [^SEP]* TAIL`: TAIL anywhere after the first HEAD of a SEP-free piece. TAIL also sees the
47
+ * separator that ends the piece, exactly as the regex did (`(?:\s|$)` matches a newline separator;
48
+ * `$` matches only at the very end).
49
+ */
50
+ function headThenTail(head, sep, tail) {
51
+ const h = once(head), t = once(tail);
52
+ return {
53
+ test(text) {
54
+ for (const p of pieces(text, sep)) {
55
+ const m = h.exec(p.body);
56
+ if (m && t.test(p.body.slice(m.index + m[0].length) + p.ender))
57
+ return true;
58
+ }
59
+ return false;
60
+ },
61
+ };
62
+ }
63
+ /**
64
+ * `HEAD [^PIECE_SEP]* MID [^LINE_SEP]* TAIL`: MID after the first HEAD of a piece, then TAIL anywhere
65
+ * later on the same line. The earliest qualifying MID on a line leaves the longest remainder, so the
66
+ * TAIL is tested once per line.
67
+ */
68
+ function headMidTail(head, pieceSep, mid, lineSep, tail) {
69
+ const h = once(head), md = once(mid), t = once(tail);
70
+ return {
71
+ test(text) {
72
+ for (const line of pieces(text, lineSep)) {
73
+ let from = -1;
74
+ for (const p of pieces(line.body, pieceSep)) {
75
+ const hm = h.exec(p.body);
76
+ if (!hm)
77
+ continue;
78
+ const mm = md.exec(p.body.slice(hm.index + hm[0].length));
79
+ if (mm) {
80
+ from = p.start + hm.index + hm[0].length + mm.index + mm[0].length;
81
+ break;
82
+ }
83
+ }
84
+ if (from >= 0 && t.test(line.body.slice(from) + line.ender))
85
+ return true;
86
+ }
87
+ return false;
88
+ },
89
+ };
90
+ }
91
+ const isWord = (c) => c !== undefined && /\w/.test(c);
92
+ /**
93
+ * The paths a `HEAD [^;|&]*? PATH` extraction regex would find, as a SUPERSET, in linear time. The
94
+ * lazy regex tried the path alternatives at every position after every HEAD — quadratic on a
95
+ * repeated HEAD or one long token (110 s measured at 200 KB). Per `;|&`-free piece, after the first
96
+ * HEAD (and MID, when given), every candidate the regex could capture is returned: each quoted span
97
+ * whose content ends with PATH (trailing blanks dropped), and each unquoted run of path characters up
98
+ * to its last PATH occurrence that ends on a word boundary. More candidates only ever mean more
99
+ * judgment, never less.
100
+ */
101
+ function pathsAfter(text, head, path, mid) {
102
+ const h = once(head);
103
+ const md = mid ? once(mid) : undefined;
104
+ const quotedEnd = new RegExp(`(?:${path})\\s*$`);
105
+ const inRun = new RegExp(path, 'g');
106
+ const out = [];
107
+ for (const p of pieces(text, /[;|&]/)) {
108
+ const hm = h.exec(p.body);
109
+ if (!hm)
110
+ continue;
111
+ let from = hm.index + hm[0].length;
112
+ if (md) {
113
+ const mm = md.exec(p.body.slice(from));
114
+ if (!mm)
115
+ continue;
116
+ from += mm.index + mm[0].length;
117
+ }
118
+ const rest = p.body.slice(from);
119
+ for (const q of ['"', "'"]) {
120
+ let i = rest.indexOf(q);
121
+ while (i >= 0) {
122
+ const j = rest.indexOf(q, i + 1);
123
+ if (j < 0)
124
+ break;
125
+ const content = rest.slice(i + 1, j);
126
+ if (quotedEnd.test(content))
127
+ out.push(content.trimEnd());
128
+ i = j; // every quote may open the next span, as the regex tried every position
129
+ }
130
+ }
131
+ for (const run of rest.matchAll(/[^\s;|&'"<>]+/g)) {
132
+ const r = run[0];
133
+ let end = -1;
134
+ for (const m of r.matchAll(inRun)) {
135
+ const e = (m.index ?? 0) + m[0].length;
136
+ if (m[0].length > 0 && isWord(r[e - 1]) !== isWord(r[e]))
137
+ end = e;
138
+ }
139
+ if (end > 0)
140
+ out.push(r.slice(0, end));
141
+ }
142
+ }
143
+ return out;
144
+ }
145
+ /**
146
+ * `> \s* ['"]? [^\s;&|]* TAIL` (a redirect whose target token contains TAIL), linear: each redirect
147
+ * target token is scanned once; a `>` inside a token already scanned can only see a suffix of it,
148
+ * and a suffix holds no TAIL match the whole token did not.
149
+ */
150
+ function redirectTokenTester(tail) {
151
+ const t = once(tail);
152
+ return {
153
+ test(text) {
154
+ let i = text.indexOf('>');
155
+ while (i >= 0) {
156
+ let j = i + 1;
157
+ while (j < text.length && /\s/.test(text[j]))
158
+ j++;
159
+ if (text[j] === '"' || text[j] === "'")
160
+ j++;
161
+ let k = j;
162
+ while (k < text.length && !/[\s;&|]/.test(text[k]))
163
+ k++;
164
+ if (t.test(text.slice(j, k)))
165
+ return true;
166
+ // A `>` ending the token targets the NEXT token (after blanks); one inside it sees a suffix.
167
+ i = text.indexOf('>', k > i + 1 && text[k - 1] === '>' ? k - 1 : Math.max(k, i + 1));
168
+ }
169
+ return false;
170
+ },
171
+ };
172
+ }
173
+ /**
174
+ * @implements A-SPEC-728 (rule 37) — `open(…, 'w')`: an `open(` whose call, before its first `)`, passes a
175
+ * writing mode. The regex `\bopen\s*\([^)]*,\s*['"]MODE['"]` rescanned to the next `)` from every `open(`, so
176
+ * `open(,open(,…` without a `)` was quadratic (198 KB: 3.0 s of a 4.2 s verdict — measured); this decides the same.
177
+ */
178
+ function openForWriting(ignoreCase = false) {
179
+ const f = ignoreCase ? 'i' : '';
180
+ return headThenTail(new RegExp(String.raw `\bopen\s*\(`, f), /\)/, new RegExp(String.raw `,\s*['"](?:[wax]\+?[bt]?|r\+[bt]?)['"]`, f));
181
+ }
182
+ const SPACE = /\s/;
183
+ const LINE_END_CHAR = (c) => c === '\n' || c === '\r' || c === '
' || c === '
';
184
+ /** `word` (ASCII letters, lower case) at `at`, compared as a case-insensitive RegExp literal compares. */
185
+ const wordAt = (text, at, word) => {
186
+ if (at + word.length > text.length)
187
+ return false;
188
+ for (let k = 0; k < word.length; k++)
189
+ if ((text.charCodeAt(at + k) | 0x20) !== word.charCodeAt(k))
190
+ return false;
191
+ return true;
192
+ };
193
+ /**
194
+ * @implements A-SPEC-728 (rule 38) — whether spec text sets `status: approved`, deciding exactly what
195
+ * `/^\s*status\s*:\s*["']?approved["']?\s*(?:#.*)?$/im` decided, in one pass: with the `m` flag `\s*` crossed newlines from
196
+ * every line start, so 48 KB of blank lines took 1.6 s and 250 KB the 20 s deadline (measured). A `status` counts when the
197
+ * whitespace before it reaches the text's start or a line end; after `approved` (and an optional quote) the whitespace
198
+ * reaches a line end or the end, or a `#` comment.
199
+ */
200
+ function setsApprovedStatus(text) {
201
+ const n = text.length;
202
+ for (let k = 0; k + 6 <= n; k++) {
203
+ if (!wordAt(text, k, 'status'))
204
+ continue;
205
+ let j = k - 1;
206
+ let lineStart = j < 0;
207
+ while (j >= 0 && SPACE.test(text[j])) {
208
+ if (LINE_END_CHAR(text[j])) {
209
+ lineStart = true;
210
+ break;
211
+ }
212
+ j--;
213
+ }
214
+ if (j < 0)
215
+ lineStart = true;
216
+ if (!lineStart)
217
+ continue;
218
+ let i = k + 6;
219
+ while (i < n && SPACE.test(text[i]))
220
+ i++;
221
+ if (text[i] !== ':')
222
+ continue;
223
+ i++;
224
+ while (i < n && SPACE.test(text[i]))
225
+ i++;
226
+ if (text[i] === '"' || text[i] === "'")
227
+ i++;
228
+ if (!wordAt(text, i, 'approved'))
229
+ continue;
230
+ i += 8;
231
+ if (text[i] === '"' || text[i] === "'")
232
+ i++;
233
+ while (i < n && SPACE.test(text[i]) && !LINE_END_CHAR(text[i]))
234
+ i++;
235
+ if (i >= n || LINE_END_CHAR(text[i]) || text[i] === '#')
236
+ return true;
237
+ }
238
+ return false;
239
+ }
240
+ /**
241
+ * @implements A-SPEC-728 (rule 39) — a URL without its query and fragment, deciding what `url.replace(/[?#].*$/, '')` decided
242
+ * in one pass: `.` stops at a line end and `$` is the text's end, so the cut is at the first `?` or `#` after the last line
243
+ * end, and the regex rescanned to that line end from every earlier `?` (120,000 of them took 8.9 s — measured).
244
+ */
245
+ function stripUrlTail(url) {
246
+ let from = 0;
247
+ for (let i = url.length - 1; i >= 0; i--)
248
+ if (LINE_END_CHAR(url[i])) {
249
+ from = i + 1;
250
+ break;
251
+ }
252
+ for (let i = from; i < url.length; i++)
253
+ if (url[i] === '?' || url[i] === '#')
254
+ return url.slice(0, i);
255
+ return url;
256
+ }
@@ -15,18 +15,17 @@ export declare function rmCommandTargets(cmd: string): string[];
15
15
  */
16
16
  export declare function normalizeWindowsPathSpellings(cmd: string): string;
17
17
  export declare function scopeAxToProject(cmd: string, projectRoot?: string): string;
18
- /**
19
- * Normalize a command string for protected-path matching: collapse `//` runs and `./` segments so
20
- * `./.ax//ledger/x` matches the same rules as `.ax/ledger/x` (adversarial probe: those forms slipped
21
- * every protected-path regex). Also flattens a leading `cd <dir> &&` so a cd-relative write
22
- * (`cd .ax/ledger && cat > provenance.jsonl`) is seen against its real directory.
23
- */
24
- export declare function normalizeCommandPaths(cmd: string): string;
18
+ export declare function normalizeCommandPaths(cmd: string, followCd?: boolean): string;
25
19
  /**
26
20
  * @implements A-SPEC-125.1
27
21
  * Reversibility axis: can the action's effect be undone? Conservative default —
28
22
  * unknown kinds and ambiguous (tracked===undefined) states never resolve to 'auto'.
29
23
  */
24
+ /**
25
+ * @implements A-SPEC-728 (round 24) — the command is judged as written AND as the shell joins it (quote removal of plain
26
+ * words, an `eval`/`-c` program's escaped words): `r''m -rf /usr/local`, `r\m -rf .git`, `g''it reset --hard` were allowed
27
+ * while their plain forms were denied (measured). The stricter verdict stands.
28
+ */
30
29
  export declare function classifyReversibility(action: RiskAction): AxisVerdict;
31
30
  /**
32
31
  * @implements A-SPEC-125.1