@skathio/somi 2.2.2 → 3.0.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.
Files changed (128) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +8 -2
  3. package/.copilot-extension/extension.json +9 -8
  4. package/.copilot-extension/marketplace.json +2 -2
  5. package/README.md +45 -33
  6. package/VERSION +1 -1
  7. package/agents/architecture-reviewer.md +16 -0
  8. package/agents/atlas.md +102 -0
  9. package/agents/coder.md +66 -22
  10. package/agents/designer.md +20 -16
  11. package/agents/discovery-analyst.md +6 -5
  12. package/agents/impact.md +97 -0
  13. package/agents/incident.md +96 -0
  14. package/agents/plan-reviewer.md +70 -0
  15. package/agents/planner.md +77 -20
  16. package/agents/pr.md +101 -0
  17. package/agents/refactor-designer.md +82 -0
  18. package/agents/refactorer.md +30 -24
  19. package/agents/reviewer.md +28 -25
  20. package/agents/sdlc-reviewer.md +69 -0
  21. package/agents/security-reviewer.md +17 -0
  22. package/agents/somi.md +204 -153
  23. package/agents/test-strategist.md +16 -1
  24. package/commands/adopt.md +21 -7
  25. package/commands/architecture-review.md +8 -5
  26. package/commands/atlas.md +24 -72
  27. package/commands/code-loop.md +46 -15
  28. package/commands/code-parallel.md +6 -4
  29. package/commands/code.md +29 -21
  30. package/commands/debug.md +17 -11
  31. package/commands/design.md +48 -31
  32. package/commands/discover.md +26 -16
  33. package/commands/impact.md +16 -54
  34. package/commands/incident.md +22 -55
  35. package/commands/plan-loop.md +43 -17
  36. package/commands/plan.md +64 -26
  37. package/commands/pr.md +19 -66
  38. package/commands/refactor-design.md +98 -0
  39. package/commands/refactor.md +22 -23
  40. package/commands/release-readiness.md +16 -7
  41. package/commands/review-panel.md +31 -10
  42. package/commands/review.md +21 -14
  43. package/commands/security-review.md +12 -3
  44. package/commands/ship-loop.md +71 -54
  45. package/commands/ship.md +17 -13
  46. package/commands/test-strategy.md +6 -4
  47. package/commands/upgrade.md +10 -8
  48. package/examples/discovery-example.md +2 -2
  49. package/examples/sample-consumer/CLAUDE.md +41 -7
  50. package/examples/sample-consumer/README.md +36 -22
  51. package/hooks/lib/common.mjs +66 -20
  52. package/hooks/post-tool/audit-log.mjs +7 -11
  53. package/hooks/post-tool/lint-changed-files.mjs +8 -11
  54. package/hooks/pre-tool/block-dangerous-bash.mjs +32 -44
  55. package/hooks/pre-tool/block-secret-writes.mjs +6 -9
  56. package/hooks/pre-tool/gate-dep-install.mjs +18 -27
  57. package/hooks/pre-tool/guard-protected-paths.mjs +9 -11
  58. package/hooks/session-start/detect-repo-instructions.mjs +21 -23
  59. package/hooks/user-prompt-submit/inject-workflow-context.mjs +190 -42
  60. package/mcp.json +10 -0
  61. package/package.json +5 -2
  62. package/rules/CLAUDE.md +22 -19
  63. package/scripts/check-links.mjs +218 -0
  64. package/scripts/check-session-artefacts.mjs +149 -0
  65. package/scripts/check-size-budget.mjs +137 -0
  66. package/scripts/generate-digest.mjs +176 -0
  67. package/scripts/lib/cost-ceiling.mjs +317 -0
  68. package/scripts/lib/cost-model.mjs +95 -0
  69. package/scripts/lib/dispatch-resolver.mjs +224 -0
  70. package/scripts/lib/mcp-project-root.mjs +183 -0
  71. package/scripts/size-budget-overrides.json +74 -0
  72. package/scripts/somi-check.mjs +6 -13
  73. package/scripts/somi-dispatch.mjs +141 -0
  74. package/scripts/somi-findings.mjs +4 -5
  75. package/scripts/somi-loop.mjs +181 -13
  76. package/scripts/somi-mcp.mjs +357 -0
  77. package/scripts/validate.sh +690 -29
  78. package/skills/clean-code/SKILL.md +1 -1
  79. package/skills/plan-review/SKILL.md +79 -0
  80. package/skills/rules/SKILL.md +47 -0
  81. package/skills/sdlc-process/SKILL.md +74 -0
  82. package/skills/somi-dispatch/SKILL.md +220 -0
  83. package/skills/somi-routing/SKILL.md +31 -6
  84. package/skills/{test-strategy → testing-playbook}/SKILL.md +1 -1
  85. package/templates/ATLAS.md.tmpl +4 -4
  86. package/templates/BRIEF.md.tmpl +23 -22
  87. package/templates/DECISIONS.md.tmpl +1 -0
  88. package/templates/DESIGN.md.tmpl +5 -5
  89. package/templates/DIARY.md.tmpl +10 -5
  90. package/templates/DOD.md.tmpl +24 -0
  91. package/templates/PROGRESS.md.tmpl +3 -16
  92. package/templates/SOMI-README.md.tmpl +3 -3
  93. package/tests/hooks/cases/inject-workflow-context.json +120 -7
  94. package/tests/hooks/run.sh +20 -11
  95. package/tests/scripts/check-links.sh +105 -0
  96. package/tests/scripts/check-session-artefacts.sh +60 -0
  97. package/tests/scripts/check-size-budget.sh +71 -0
  98. package/tests/scripts/checkpoint-gate.sh +90 -0
  99. package/tests/scripts/convergence-runner.sh +1510 -0
  100. package/tests/scripts/cost-ceiling.sh +343 -0
  101. package/tests/scripts/cost-model.sh +192 -0
  102. package/tests/scripts/dispatch-guard.sh +108 -0
  103. package/tests/scripts/dispatch-reference-gate.sh +173 -0
  104. package/tests/scripts/eval-runner.sh +3691 -0
  105. package/tests/scripts/evals-packaging.sh +117 -0
  106. package/tests/scripts/fixtures/legacy-shard-no-schema.json +50 -0
  107. package/tests/scripts/generate-digest.sh +180 -0
  108. package/tests/scripts/goldens/loop-state-breach.json +1 -0
  109. package/tests/scripts/goldens/loop-state-done.json +1 -0
  110. package/tests/scripts/goldens/somi-loop.json +1 -1
  111. package/tests/scripts/lib/adr-shape.mjs +41 -0
  112. package/tests/scripts/lib/checkpoint-gate.mjs +54 -0
  113. package/tests/scripts/lib/digest-marker-coupling.mjs +52 -0
  114. package/tests/scripts/lib/dispatch-reference-gate.mjs +112 -0
  115. package/tests/scripts/lib/multipass-dependence.mjs +192 -0
  116. package/tests/scripts/lib/multipass-source-identity.mjs +243 -0
  117. package/tests/scripts/lib/reference-pair.mjs +61 -0
  118. package/tests/scripts/lib/retirement-gate.mjs +167 -0
  119. package/tests/scripts/lib/shell-embedded-js.mjs +47 -0
  120. package/tests/scripts/lib/somi-mcp-client.mjs +102 -0
  121. package/tests/scripts/lib/somi-mcp-tests.mjs +401 -0
  122. package/tests/scripts/lib/somi-mcp-tool-schema.mjs +38 -0
  123. package/tests/scripts/retirement-gate.sh +287 -0
  124. package/tests/scripts/review-panel-seats.sh +32 -0
  125. package/tests/scripts/run.sh +184 -2
  126. package/tests/scripts/somi-agent-dispatch-contract.sh +195 -0
  127. package/tests/scripts/somi-dispatch.sh +354 -0
  128. package/tests/scripts/somi-mcp.sh +12 -0
@@ -1,9 +1,7 @@
1
1
  // hooks/lib/common.mjs — shared helpers for somi hooks.
2
2
  //
3
- // Node port of hooks/lib/common.sh (node-runtime-port, phase 2, iteration 2.1).
4
3
  // Zero-dependency: stdlib only (node:fs, node:path). No jq, no bash — every
5
- // hook port (2.2-2.9) imports named exports from this module instead of
6
- // `source`-ing a shell file.
4
+ // hook imports named exports from this module instead of `source`-ing a shell file.
7
5
  //
8
6
  // Hooks receive a JSON payload on stdin describing the tool invocation, and may
9
7
  // emit a JSON response on stdout to control the harness. Output schema is
@@ -26,6 +24,7 @@
26
24
 
27
25
  import fs from 'node:fs';
28
26
  import path from 'node:path';
27
+ import { fileURLToPath } from 'node:url';
29
28
 
30
29
  // Thrown by denyPretool() (and available to any hook that needs an early,
31
30
  // non-local exit) to unwind to the hook's own top-level handler — mirrors
@@ -36,8 +35,8 @@ import path from 'node:path';
36
35
  // the signal carries an explicit code rather than a hard-coded 0 in case a
37
36
  // future hook needs a different one.
38
37
  //
39
- // Deliberately NOT using process.exit() here: scripts/somi-loop.mjs (1.1,
40
- // reviewer-blessed) established the precedent that process.exit() risks
38
+ // Deliberately NOT using process.exit() here: scripts/somi-loop.mjs
39
+ // established the precedent that process.exit() risks
41
40
  // truncating buffered stdout/stderr on a pipe if Node hasn't finished
42
41
  // flushing yet — exactly the scenario denyPretool()/contextOutput() create
43
42
  // (a console.log() immediately followed by an exit). Throwing + a top-level
@@ -51,7 +50,7 @@ export class HookExit extends Error {
51
50
  }
52
51
 
53
52
  // Runs a hook's main() and translates a thrown HookExit into process.exitCode.
54
- // The standard wrapper every hook port (2.2-2.9) should use at its top level,
53
+ // The standard wrapper every hook should use at its top level,
55
54
  // so denyPretool()'s early-exit contract works without each hook file
56
55
  // re-declaring the same try/catch boilerplate (the somi-loop.mjs/
57
56
  // somi-findings.mjs/somi-check.mjs precedent, centralized here since EVERY
@@ -75,17 +74,64 @@ export function runHook(main) {
75
74
  // SOMI_AUDIT_LOG, below) can arrive as the literal string
76
75
  // "${CLAUDE_PROJECT_DIR}/...". Without this guard, a path built from that
77
76
  // literal would create a directory named `${CLAUDE_PROJECT_DIR}` in the repo
78
- // root. This guard is duplicated across 5+ bash files (context.md §2,
79
- // brief.md §3) — centralized here as the ONE copy every hook port imports,
80
- // rather than re-duplicating the `.includes('${')` check per file. (Note:
81
- // scripts/*.mjs — a separate module graph, out of this iteration's scope —
82
- // still carry their own copy; unifying those is a follow-up, not this pass.)
77
+ // root. This guard is duplicated across 5+ bash files — centralized
78
+ // here as the ONE copy every hook imports, rather than re-duplicating the
79
+ // `.includes('${')` check per file. (Note: scripts/*.mjs — a separate module
80
+ // graph — still carry their own copy; unifying those is a follow-up.)
83
81
  export function projectRoot() {
84
82
  let base = process.env.CLAUDE_PROJECT_DIR || process.cwd();
85
83
  if (base.includes('${')) base = process.cwd();
86
84
  return base;
87
85
  }
88
86
 
87
+ // plugin_root() — the directory containing SoMi's OWN shipped content (rules/, skills/, etc.),
88
+ // as distinct from projectRoot() above (the CONSUMING project's root). A hook needs this to read
89
+ // rules/CLAUDE.md's digest regardless of whether SoMi is running as an installed plugin, a
90
+ // vendored copy, or this repo's own dev/test checkout.
91
+ //
92
+ // Resolution order, EACH candidate existence-validated, not merely presence-checked — accepted
93
+ // only if `<candidate>/rules/CLAUDE.md` is actually readable, else the search continues to the
94
+ // next candidate:
95
+ // (a) CLAUDE_PLUGIN_ROOT — Claude Code's documented, confirmed-exported plugin-install path.
96
+ // (b) SOMI_VENDOR_ROOT — a vendored-install convention, set via `.claude/settings.json`'s `env`
97
+ // block. This repo's OWN `.claude/settings.json` sets it to a path
98
+ // (`${CLAUDE_PROJECT_DIR}/.claude/plugins/somi`) that does not exist here — a
99
+ // presence-only chain would accept this branch, find nothing inside it, and never reach
100
+ // (c), silently delivering an empty digest in this repo's own dogfooding sessions while
101
+ // appearing to work everywhere validate.sh's checks pass. Existence-validation is exactly
102
+ // what prevents that.
103
+ // (c) import.meta.url, walked up two levels — this file lives at
104
+ // `<plugin-root>/hooks/lib/common.mjs`, the same relative-import pattern every hook port
105
+ // already uses for '../lib/common.mjs' itself. The final fallback; what this repo's own
106
+ // dev/test invocations (including tests/hooks/run.sh) actually exercise today.
107
+ //
108
+ // Same unexpanded-`${...}`-variable guard as projectRoot()/auditLogPath() above, applied to EACH
109
+ // env-var candidate independently — a host can fail to expand either one, or both, independent
110
+ // of the other.
111
+ //
112
+ // Returns null if no candidate resolves (not expected in practice — (c) always resolves inside a
113
+ // real checkout of this repo — but callers must not assume a non-null result; see
114
+ // inject-workflow-context.mjs's buildTier2Digest(), which fails safe to an empty Tier 2 rather
115
+ // than throwing).
116
+ export function pluginRoot() {
117
+ const candidates = [];
118
+ const claudePluginRoot = process.env.CLAUDE_PLUGIN_ROOT;
119
+ if (claudePluginRoot && !claudePluginRoot.includes('${')) candidates.push(claudePluginRoot);
120
+ const somiVendorRoot = process.env.SOMI_VENDOR_ROOT;
121
+ if (somiVendorRoot && !somiVendorRoot.includes('${')) candidates.push(somiVendorRoot);
122
+ const here = path.dirname(fileURLToPath(import.meta.url)); // <plugin-root>/hooks/lib
123
+ candidates.push(path.join(here, '..', '..'));
124
+
125
+ for (const candidate of candidates) {
126
+ try {
127
+ if (fs.statSync(path.join(candidate, 'rules', 'CLAUDE.md')).isFile()) return candidate;
128
+ } catch {
129
+ // ENOENT, EACCES, or a non-file at that path — not a usable candidate; try the next one.
130
+ }
131
+ }
132
+ return null;
133
+ }
134
+
89
135
  // Read the full JSON payload from stdin once, parse it. Tolerates empty or
90
136
  // invalid input the way `somi::field`'s jq call does (`2>/dev/null || true`
91
137
  // — no crash, just nothing to extract): returns null rather than throwing,
@@ -187,7 +233,7 @@ export function config(fieldPath) {
187
233
  // jq's "// empty" on a generator (`.dep_install.allow[]? // empty`)
188
234
  // drops null/false elements from the output stream element-by-element —
189
235
  // it does NOT stringify them to "null"/"false" (verified against real
190
- // jq: F-29). A stray null/false entry in a committed config array is
236
+ // jq). A stray null/false entry in a committed config array is
191
237
  // silently skipped, matching that.
192
238
  return cur
193
239
  .filter((v) => v !== null && v !== false)
@@ -197,7 +243,7 @@ export function config(fieldPath) {
197
243
  return typeof cur === 'string' ? cur : JSON.stringify(cur);
198
244
  }
199
245
 
200
- // Append a structured line to the audit log. Frozen contract (spec.md §9):
246
+ // Append a structured line to the audit log. Frozen contract:
201
247
  // "timestamp\tkind\ttool\tdetail\n", byte-exact — any deviation here is a
202
248
  // regression, not a style choice.
203
249
  export function audit(payload, kind, detail) {
@@ -255,17 +301,17 @@ export function contextOutput(event, context) {
255
301
  // the same pattern a second time just to recover the substring it already
256
302
  // matched.
257
303
  //
258
- // FIRST-MATCH-ONLY CONTRACT (F-28): both wrappers strip the "g"/"y" flags
304
+ // FIRST-MATCH-ONLY CONTRACT: both wrappers strip the "g"/"y" flags
259
305
  // from every pattern before matching, UNCONDITIONALLY — even if the
260
306
  // caller's own RegExp carries one. `.exec()` on a /g or /y regex is
261
307
  // STATEFUL: it advances the object's own `lastIndex` on every call, so
262
- // running the SAME pattern object through `matchesAny` twice (e.g. 2.9
308
+ // running the SAME pattern object through `matchesAny` twice (e.g. block-dangerous-bash.mjs
263
309
  // scans its whole pattern list against the raw command, then again against
264
310
  // the quote-stripped copy — block-dangerous-bash.sh:166-167) could silently
265
311
  // return null on the second call even though the string still matches.
266
312
  // Bash's `[[ =~ ]]` has no equivalent statefulness, so this would be a
267
- // NEW failure mode the port introduces into the security substrate 2.9
268
- // depends on. Rather than trust every pattern literal across 2.2-2.9 to
313
+ // NEW failure mode the port introduces into the security substrate that
314
+ // hook depends on. Rather than trust every pattern literal across the hooks to
269
315
  // never accidentally carry "g"/"y", toRegExp() makes the hazard
270
316
  // unrepresentable: the effective flags are always normalized to exclude
271
317
  // "g"/"y" first, so neither wrapper's returned RegExp is ever stateful
@@ -296,12 +342,12 @@ export function matchesAny(str, patterns) {
296
342
  // nocasematch` is an AMBIENT property of the matching operation, not a
297
343
  // per-pattern annotation — the bash ERE pattern strings themselves have no
298
344
  // case-flag syntax at all. Centralizing the flag here means a pattern added
299
- // to a nocase list in a future hook port can never silently end up
345
+ // to a nocase list in a future hook can never silently end up
300
346
  // case-sensitive from one missing "/i" on one literal; the guarantee lives
301
347
  // in which function you called, not in every pattern's own flags.
302
348
  //
303
349
  // ASCII-only, by construction of JS's own /i semantics — NOT by any bespoke
304
- // folding logic here (1.2's F-23 precedent: bash's nocasematch is
350
+ // folding logic here (bash's nocasematch is
305
351
  // ASCII-only for these pattern classes, and Unicode-aware case folding can
306
352
  // introduce surprises C-locale regex/`tr` never would). JS's /i flag
307
353
  // WITHOUT the /u flag already refuses to fold a non-ASCII input character
@@ -312,7 +358,7 @@ export function matchesAny(str, patterns) {
312
358
  // form is < U+0080 but the character itself is >= U+0080, the algorithm
313
359
  // returns the character UNCHANGED instead of folding it — the exact guard
314
360
  // `String.prototype.toLowerCase()` lacks, which is what made
315
- // normalizeTitle's İstanbul/café cases (somi-findings.mjs, F-23) a real
361
+ // normalizeTitle's İstanbul/café cases (somi-findings.mjs) a real
316
362
  // bug. The one residual gap: two DIFFERENT non-ASCII characters Unicode
317
363
  // considers case-equivalent to each other (e.g. é/É) would still fold under
318
364
  // JS's /i, where bash's C-locale nocasematch would not — moot for every
@@ -2,20 +2,17 @@
2
2
  // hooks/post-tool/audit-log.mjs — PostToolUse hook (matcher: *) — record every tool call to
3
3
  // the SOMI audit log.
4
4
  //
5
- // Node port of hooks/post-tool/audit-log.sh (node-runtime-port, phase 2, iteration 2.6).
6
- // The simplest hook in the corpus: append-only, no decision logic beyond field extraction
7
- // already ported in 2.1 (../lib/common.mjs). Pairs with the BLOCK entries written from
5
+ // The simplest hook in the corpus: append-only, no decision logic beyond the field extraction
6
+ // in ../lib/common.mjs. Pairs with the BLOCK entries written from
8
7
  // pre-tool hooks: gives you a single log to grep for "what did the agent actually do during
9
8
  // this session?" Sensitive arguments are trimmed; we record tool name, status, and a short
10
9
  // summary.
11
10
  //
12
- // Line format is the frozen contract (spec.md §9): "timestamp\tkind\ttool\tdetail\n",
11
+ // Line format is a frozen contract: "timestamp\tkind\ttool\tdetail\n",
13
12
  // byte-exact — common.mjs's audit() owns that shape; this file only builds `detail`.
14
13
  //
15
- // TRUNCATION-BOUNDARY NOTE (F-14, phase-2-hooks-port.md, iteration 2.6): bash's
16
- // `head -c 240` truncates at exactly 240 BYTES, not characters — verified directly against
17
- // the unmodified bash original before this port existed (see progress.md/diary.md, 2.6):
18
- // a 271-byte compact tool_input truncates to exactly 240 bytes, dropping the tail including
14
+ // TRUNCATION-BOUNDARY NOTE: the original bash hook's `head -c 240` truncates at exactly 240
15
+ // BYTES, not characters — verified directly against that original: a 271-byte compact tool_input truncates to exactly 240 bytes, dropping the tail including
19
16
  // the closing `"}`. truncateBytes() below reproduces that byte-exact cut via a UTF-8 Buffer
20
17
  // slice (Buffer.from(str, 'utf8').subarray(0, 240)), NOT a UTF-16-code-unit `.slice(0, 240)`
21
18
  // — the latter would cut at the wrong BYTE position for any non-ASCII content before the
@@ -35,9 +32,8 @@
35
32
  // bash original nor this port escapes a tab/newline that happens to be embedded IN the
36
33
  // summary content itself (e.g. a Bash command containing a literal tab byte, verified
37
34
  // directly: it lands as a real 0x09 byte in the audit line, silently misaligning any
38
- // naive `split('\t')` consumer). Preserved as-is — this is pre-existing bash behavior, not
39
- // port-introduced, and D2 (behavior preservation) governs this hook; escaping would be a
40
- // behavior change out of this iteration's scope.
35
+ // naive `split('\t')` consumer). Preserved as-is: it is inherited bash behavior, and the
36
+ // hook's contract is to keep that behavior, so escaping would be a behavior change.
41
37
 
42
38
  import { readPayload, field, audit, runHook } from '../lib/common.mjs';
43
39
 
@@ -2,9 +2,8 @@
2
2
  // hooks/post-tool/lint-changed-files.mjs — PostToolUse hook (matcher: Write|Edit) —
3
3
  // best-effort lint of just-changed files.
4
4
  //
5
- // Node port of hooks/post-tool/lint-changed-files.sh (node-runtime-port, phase 2,
6
- // iteration 2.5). Imports the shared read/context/projectRoot helpers from
7
- // ../lib/common.mjs (2.1, reviewer-blessed) rather than reimplementing them.
5
+ // Imports the shared read/context/projectRoot helpers from ../lib/common.mjs rather than
6
+ // reimplementing them.
8
7
  //
9
8
  // Runs the project's configured linter on the touched file, if one is available,
10
9
  // keyed off file extension + presence of a config file. Result is informational —
@@ -17,7 +16,7 @@
17
16
  // --- PROJECT_ROOT resolution: guarded projectRoot(), not bash's raw pattern ------
18
17
  // bash: `PROJECT_ROOT="${CLAUDE_PROJECT_DIR:-$PWD}"` — no `${...}`-unexpanded-
19
18
  // literal guard on THIS specific line (unlike most other ported hooks' PROJECT_ROOT
20
- // lines, context.md §2). Using common.mjs's projectRoot() here anyway (which DOES
19
+ // lines). Using common.mjs's projectRoot() here anyway (which DOES
21
20
  // carry the guard) is a deliberate, safe-direction improvement, not a silent
22
21
  // behavior change: if a host ever fails to expand `${CLAUDE_PROJECT_DIR}` before
23
22
  // setting it, bash's un-guarded line would set PROJECT_ROOT to that literal
@@ -27,7 +26,7 @@
27
26
  // best-effort no-op). The guarded projectRoot() falls back to `process.cwd()` in
28
27
  // that same scenario instead, so this port degrades to "no lint delegate ran" for
29
28
  // the broken-host case rather than crashing — strictly safer, and consistent with
30
- // 2.1's centralization intent (every port imports the one guarded helper rather
29
+ // the centralization intent (every hook imports the one guarded helper rather
31
30
  // than re-duplicating bash's un-guarded line).
32
31
  //
33
32
  // --- run_if_present() -> runIfPresent(), combined with the `command -v` gate ----
@@ -68,10 +67,8 @@
68
67
  // cheap, best-effort side note. If a real run exceeds it, spawnSync sets
69
68
  // `result.error`, which `runIfPresent`'s swallow-everything contract already
70
69
  // treats as "nothing to report" — an over-the-cap linter run degrades to silence,
71
- // not a crash. This establishes the explicit-maxBuffer convention 1.1's review
72
- // asked Phase 2's first output-capturing hook to set
73
- // (`.somi/reviews/node-runtime-port/2026-07-06-1.1-pass1-approve.md`); later hook
74
- // ports that capture subprocess output should follow this precedent.
70
+ // not a crash. This is the explicit-maxBuffer convention; any hook that captures
71
+ // subprocess output should follow it.
75
72
  //
76
73
  // --- command-substitution trailing-newline stripping -----------------------------
77
74
  // bash builds LINT_OUTPUT via `"$(...)"` command substitution, which
@@ -151,8 +148,8 @@ function hasEslintConfig(root) {
151
148
  // PROJECT_ROOT/ prefix (a no-op if PATH_INPUT doesn't actually start with it,
152
149
  // matching bash's `#`-prefix-removal no-op-on-no-match behavior), take the
153
150
  // directory component, wrap as a `go vet` package pattern. Uses platform-default
154
- // path.dirname (posix on Linux/macOS) — same Windows-backslash caveat 2.2/2.3
155
- // already flagged and deferred (F-32-class divergence, not fixed here either).
151
+ // path.dirname (posix on Linux/macOS) — same Windows-backslash caveat the
152
+ // other path-handling hooks already flag and defer (not fixed here either).
156
153
  function goVetPackageArg(pathInput, root) {
157
154
  const prefix = root.endsWith(path.sep) ? root : root + path.sep;
158
155
  const rel = pathInput.startsWith(prefix) ? pathInput.slice(prefix.length) : pathInput;
@@ -2,27 +2,20 @@
2
2
  // hooks/pre-tool/block-dangerous-bash.mjs — PreToolUse hook (matcher: Bash) — block clearly
3
3
  // dangerous shell commands.
4
4
  //
5
- // Node port of hooks/pre-tool/block-dangerous-bash.sh (node-runtime-port, phase 2,
6
- // iteration 2.9 — the work item's named highest-risk file, brief.md §3/§8). Imports the
7
- // shared read/deny/matching helpers from ../lib/common.mjs (2.1, reviewer-blessed)
8
- // rather than reimplementing them.
5
+ // The highest-risk hook in the set: a wrong translation here silently under-gates. Imports the
6
+ // shared read/deny/matching helpers from ../lib/common.mjs rather than reimplementing them.
9
7
  //
10
8
  // This is a deterministic guardrail, not a policy debate. It catches the
11
9
  // common-and-catastrophic class of mistakes; nuanced cases are the human's call. Block
12
10
  // list focuses on irreversible / system-destructive / supply-chain shapes, plus
13
11
  // shell-level writes to secret-bearing paths — the Bash-side complement of
14
- // block-secret-writes.mjs (2.2), whose Write|Edit matcher a redirect / tee / sed -i /
12
+ // block-secret-writes.mjs, whose Write|Edit matcher a redirect / tee / sed -i /
15
13
  // cp / mv would otherwise bypass entirely. Intentionally conservative — false positives
16
14
  // cost less than false negatives here.
17
15
  //
18
- // COUNT CORRECTION (verified by direct read — `awk` over the array literal, not
19
- // inherited from the phase file's/brief's stated "19"): the bash original's
20
- // DANGEROUS_PATTERNS array holds 23 case-sensitive patterns, not 19 — same class of
21
- // miscount 2.4 found and corrected for DEP_ADD_PATTERNS (18→19), just larger here. All
22
- // 23 are ported below, plus the 5 case-insensitive SQL patterns (that count IS
23
- // accurate) and the 4 secret-write patterns. "Port ALL of the patterns" wins over an
24
- // inherited miscount, per 2.4's precedent; phases/02-hooks-port.md's iteration-2.9 scope
25
- // line is corrected alongside this port (see the diary entry for this pass).
16
+ // PATTERN COUNT (verified by direct read — `awk` over the array literal): the original bash
17
+ // DANGEROUS_PATTERNS array holds 23 case-sensitive patterns, not 19. All 23 are ported below,
18
+ // plus the 5 case-insensitive SQL patterns and the 4 secret-write patterns.
26
19
  //
27
20
  // ERE→RegExp translation rules applied uniformly (verified pattern-by-pattern, not by a
28
21
  // blanket find-and-replace across the whole set — every one of the 23+5+4 patterns
@@ -35,11 +28,11 @@
35
28
  // U+2028/U+2029, U+FEFF, other Zs). A wider POSITIVE \s can
36
29
  // only make this hook MATCH (and therefore block) a
37
30
  // broader set of verb/argument separators than bash would —
38
- // over-gating, never under-gating. Same argument 2.4 made
39
- // for gate-dep-install, and it is sound for this direction.
40
- // [^[:space:]] → [^ \t\n\r\f\v] NOT [^\s] (F-40, Major, fixed at 2.9 pass 2 after
41
- // the security review caught it — a prior version of this
42
- // file used [^\s] here and was WRONG). Negation INVERTS the
31
+ // over-gating, never under-gating. Same argument
32
+ // as gate-dep-install, and it is sound for this direction.
33
+ // [^[:space:]] → [^ \t\n\r\f\v] NOT [^\s] (an earlier version of this
34
+ // file used [^\s] here and was WRONG; a security review
35
+ // caught it). Negation INVERTS the
43
36
  // superset relationship above: \s ⊋ [[:space:]] means
44
37
  // [^\s] ⊊ [^[:space:]] — the negated JS class matches FEWER
45
38
  // characters than bash's negated POSIX class, so a pattern
@@ -84,11 +77,10 @@
84
77
  // where the same caveat was checked and found inert because those files only ever
85
78
  // match basenames or already-tokenized argument text, never raw command-string content).
86
79
  //
87
- // RE-DERIVED AT 2.9 PASS 2 (F-39, Blocker) — the paragraph that used to sit here claimed
88
- // "POSIX ERE '.' matches every byte except '\n'" and translated '.*' to '[^\n]*'. That
89
- // claim is WRONG for what this file actually needs: it is grep/awk-with-REG_NEWLINE
90
- // semantics, not bash `[[ =~ ]]` semantics, and the security review caught the gap it
91
- // produced. Re-derived from first principles, not restated:
80
+ // An earlier version of this file claimed "POSIX ERE '.' matches every byte except '\n'" and
81
+ // translated '.*' to '[^\n]*'. That claim is WRONG for what this file actually needs: it is
82
+ // grep/awk-with-REG_NEWLINE semantics, not bash `[[ =~ ]]` semantics, and a security review
83
+ // caught the gap it produced. Derived from first principles:
92
84
  //
93
85
  // bash's `[[ "$c" =~ $pattern ]]` calls glibc `regexec()` WITHOUT the `REG_NEWLINE`
94
86
  // flag. REG_NEWLINE is what makes '.' refuse a newline (and makes '^'/'$' match at
@@ -108,8 +100,8 @@
108
100
  // `--no-verify` disables somi's own commit/push safety hooks, and multi-line commit
109
101
  // messages are completely routine, so this was a live gap, not a theoretical one. A CR
110
102
  // (not LF) embedded in the same position happens to still be excluded by `[^\n]` too
111
- // (CR isn't `\n`), which is why the pass-1 CR-embedded regression probes passed and gave
112
- // false confidence — LF was the actual break, and pass 1 had no LF fixture.
103
+ // (CR isn't `\n`), which is why a CR-embedded probe passes and gives false confidence —
104
+ // LF is the actual break, so keep an LF case in the fixtures.
113
105
  //
114
106
  // Every other '.' in this file is an ESCAPED '\.' (a literal dot character, e.g.
115
107
  // `mkfs\.`), unaffected by this caveat in either engine — checked by hand per
@@ -122,11 +114,8 @@
122
114
  // to `\/`. No pattern here uses a backtick or `${`, so String.raw is safe throughout.
123
115
  //
124
116
  // SECRET_WRITE_PATTERNS mirrors block-secret-writes.mjs's SECRET_PATTERNS set
125
- // (block-secret-writes.mjs's SECRET_PATTERNS / block-dangerous-bash.sh:86) — "kept in
126
- // sync by comment convention, not code sharing" today (context.md §2). Preserved as a
127
- // deliberate duplication in this port; do not unify the two lists — that would be a
128
- // scope-creeping refactor beyond this behavior-preserving port (same convention 2.2
129
- // already flagged as a future-refactor target).
117
+ // — kept in sync by comment convention, not code sharing. The duplication is deliberate:
118
+ // unifying the two lists is a separate refactor, not part of an unrelated change.
130
119
  //
131
120
  // check_secret_writes' capture-before-internal-test discipline is preserved exactly
132
121
  // (see checkSecretWrites below): the matched substring is read into a local `matched`
@@ -167,7 +156,7 @@ const DANGEROUS_PATTERNS = [
167
156
 
168
157
  // device / partition writes (bash:45-47)
169
158
  new RegExp(String.raw`>\s*/dev/(sd[a-z]|nvme|hd[a-z]|disk)`), // #6
170
- new RegExp(String.raw`dd\s+if=[^]*\s+of=/dev/(sd[a-z]|nvme|hd[a-z]|disk)`), // #7 dot-semantics: .*→[^]* (F-39)
159
+ new RegExp(String.raw`dd\s+if=[^]*\s+of=/dev/(sd[a-z]|nvme|hd[a-z]|disk)`), // #7 dot-semantics: .*→[^]*
171
160
  new RegExp(String.raw`mkfs(\.|\s)`), // #8
172
161
 
173
162
  // supply-chain / remote-exec one-liners (bash:50-53)
@@ -178,22 +167,22 @@ const DANGEROUS_PATTERNS = [
178
167
 
179
168
  // destructive git ops on protected branches (bash:57-64). Covers --force, -f,
180
169
  // --force-with-lease (with or without =value), and refspec form (origin HEAD:main).
181
- new RegExp(String.raw`git\s+push\s+(-{1,2}force|-f)([\s=]|$)[^]*[\s:](main|master|trunk|release)(\s|$)`), // #13 dot-semantics (F-39)
182
- new RegExp(String.raw`git\s+push\s+--force-with-lease([\s=][^ \t\n\r\f\v]*)?\s[^]*[\s:](main|master|trunk|release)(\s|$)`), // #14 dot-semantics + negated-class (F-39, F-40)
170
+ new RegExp(String.raw`git\s+push\s+(-{1,2}force|-f)([\s=]|$)[^]*[\s:](main|master|trunk|release)(\s|$)`), // #13 dot-semantics
171
+ new RegExp(String.raw`git\s+push\s+--force-with-lease([\s=][^ \t\n\r\f\v]*)?\s[^]*[\s:](main|master|trunk|release)(\s|$)`), // #14 dot-semantics + negated-class
183
172
  // force-push via +refspec — no --force flag involved (`git push origin +main`, `+HEAD:main`)
184
173
  new RegExp(String.raw`git\s+push\s+[^;&|]*\s\+(main|master|trunk|release)([\s:]|$)`), // #15
185
- new RegExp(String.raw`git\s+push\s+[^;&|]*\s\+[^ \t\n\r\f\v]*:(main|master|trunk|release)(\s|$)`), // #16 negated-class (F-40)
174
+ new RegExp(String.raw`git\s+push\s+[^;&|]*\s\+[^ \t\n\r\f\v]*:(main|master|trunk|release)(\s|$)`), // #16 negated-class
186
175
  new RegExp(String.raw`git\s+branch\s+-D\s+(main|master|trunk)`), // #17
187
176
  new RegExp(String.raw`git\s+reset\s+--hard\s+(origin/)?(main|master|trunk)`), // #18
188
177
  new RegExp(String.raw`git\s+clean\s+-[fdx]+\s`), // #19
189
178
 
190
179
  // process / permission ops (bash:67-68)
191
180
  new RegExp(String.raw`chmod\s+-R\s+777\s+/`), // #20
192
- new RegExp(String.raw`chown\s+-R\s+[^]*\s+/`), // #21 dot-semantics: .*→[^]* (F-39)
181
+ new RegExp(String.raw`chown\s+-R\s+[^]*\s+/`), // #21 dot-semantics: .*→[^]*
193
182
 
194
183
  // skipping safety checks (only block when used in commit/push context) (bash:71-72)
195
- new RegExp(String.raw`git\s+commit\s+[^]*--no-verify`), // #22 dot-semantics (F-39)
196
- new RegExp(String.raw`git\s+push\s+[^]*--no-verify`), // #23 dot-semantics (F-39)
184
+ new RegExp(String.raw`git\s+commit\s+[^]*--no-verify`), // #22 dot-semantics
185
+ new RegExp(String.raw`git\s+push\s+[^]*--no-verify`), // #23 dot-semantics
197
186
  ];
198
187
 
199
188
  // Case-insensitive patterns (bash:76-82, 5 entries — SQL keywords arrive lowercase
@@ -219,9 +208,8 @@ const DANGEROUS_PATTERNS = [
219
208
  // reordering the alternation LONGEST-FIRST (`production` before `prod`; `public` has
220
209
  // no prefix relationship with either, so its position doesn't matter) — this changes
221
210
  // nothing about WHICH inputs match, only WHICH substring an ambiguous input's match
222
- // reports, restoring exact parity with bash's leftmost-longest result. Audited every
223
- // other alternation group in this file for the same prefix-collision shape (see the
224
- // diary for the full audit): `(main|master|trunk|release)`,
211
+ // reports, restoring exact parity with bash's leftmost-longest result. Every other
212
+ // alternation group in this file was audited for the same prefix-collision shape: `(main|master|trunk|release)`,
225
213
  // `(sd[a-z]|nvme|hd[a-z]|disk)`, `(rsa|ed25519|ecdsa|dsa)`,
226
214
  // `(local|production|prod|staging|secret)` (already longest-first in bash's own
227
215
  // source), `(-{1,2}force|-f)` (protected by a mandatory boundary character after the
@@ -239,7 +227,7 @@ const DANGEROUS_PATTERNS_NOCASE = [
239
227
  // Secret-bearing basename alternation (bash:86). A regex-source FRAGMENT, not a
240
228
  // standalone pattern — interpolated into each of the 4 SECRET_WRITE_PATTERNS below,
241
229
  // exactly as bash interpolates `${SECRET_BASENAME}` into 4 array entries.
242
- const SECRET_BASENAME = String.raw`(\.env(\.(local|production|prod|staging|secret))?|id_(rsa|ed25519|ecdsa|dsa)|[^ \t\n\r\f\v]*\.(pem|key|p12|pfx|jks)|[^ \t\n\r\f\v]*(-key|-credentials)\.json|service-account[^ \t\n\r\f\v]*\.json|\.netrc|\.pgpass|[^ \t\n\r\f\v]*secrets?\.(ya?ml|json))`; // negated-class fixed (F-40)
230
+ const SECRET_BASENAME = String.raw`(\.env(\.(local|production|prod|staging|secret))?|id_(rsa|ed25519|ecdsa|dsa)|[^ \t\n\r\f\v]*\.(pem|key|p12|pfx|jks)|[^ \t\n\r\f\v]*(-key|-credentials)\.json|service-account[^ \t\n\r\f\v]*\.json|\.netrc|\.pgpass|[^ \t\n\r\f\v]*secrets?\.(ya?ml|json))`; // negated-class
243
231
 
244
232
  // Shell-level writes to secret paths (bash:90-95): redirection, tee, in-place sed,
245
233
  // cp/mv onto the target. Matched against the quote-stripped command, same as bash.
@@ -248,7 +236,7 @@ const SECRET_WRITE_PATTERNS = [
248
236
  new RegExp(String.raw`(^|[\s|;&])tee\s+(-[a-zA-Z]+\s+)*([^ \t\n\r\f\v]*/)?${SECRET_BASENAME}(\s|$)`),
249
237
  new RegExp(String.raw`(^|[\s|;&])sed\s+[^|;&]*-i[^|;&]*\s([^ \t\n\r\f\v]*/)?${SECRET_BASENAME}(\s|$)`),
250
238
  new RegExp(String.raw`(^|[\s|;&])(cp|mv)\s+[^|;&]*\s([^ \t\n\r\f\v]*/)?${SECRET_BASENAME}(\s|$)`),
251
- ]; // negated-class prefix groups fixed (F-40)
239
+ ]; // negated-class prefix groups
252
240
 
253
241
  // Explicit example/template files are fine — same exception as block-secret-writes.mjs.
254
242
  const EXAMPLE_ENV_RE = /\.env\.(example|sample|template|dist)/;
@@ -306,7 +294,7 @@ Bash-side twin of the Write/Edit secret guard — do not work around either sile
306
294
  // Gate regex (bash:141) — unchanged translation rules from DANGEROUS_PATTERNS above,
307
295
  // no dot-semantics concern (no '.'/'.*' in this one):
308
296
  const BARE_FORCE_PUSH_GATE_RE = new RegExp(
309
- String.raw`git\s+push(\s+[^;&|]*)?\s(-f|--force(-with-lease(=[^ \t\n\r\f\v]*)?)?)(\s|$)`, // negated-class fixed (F-40)
297
+ String.raw`git\s+push(\s+[^;&|]*)?\s(-f|--force(-with-lease(=[^ \t\n\r\f\v]*)?)?)(\s|$)`, // negated-class
310
298
  );
311
299
 
312
300
  // This is NOT a regex port — bash:144-156 is a small procedural parser (word-split the
@@ -320,7 +308,7 @@ const BARE_FORCE_PUSH_GATE_RE = new RegExp(
320
308
  //
321
309
  // bash: for tok in $after_push (IFS word-splitting; bash ALSO performs unquoted
322
310
  // pathname/glob expansion here, deliberately NOT reproduced — same judgment
323
- // call gate-dep-install.mjs's tokensAfterVerb() made (2.4): glob expansion
311
+ // call gate-dep-install.mjs's tokensAfterVerb() made: glob expansion
324
312
  // would make the gate's outcome depend on the hook process's cwd/filesystem
325
313
  // state, a strictly worse property for a security control, and no realistic
326
314
  // git-push argument or fixture exercises it).
@@ -2,19 +2,16 @@
2
2
  // hooks/pre-tool/block-secret-writes.mjs — PreToolUse hook (matcher: Write|Edit) — block
3
3
  // writes to secret-bearing paths.
4
4
  //
5
- // Node port of hooks/pre-tool/block-secret-writes.sh (node-runtime-port, phase 2,
6
- // iteration 2.2). Imports the shared read/deny/context helpers from ../lib/common.mjs
7
- // (2.1, reviewer-blessed) rather than reimplementing them.
5
+ // Imports the shared read/deny/context helpers from ../lib/common.mjs rather than
6
+ // reimplementing them.
8
7
  //
9
8
  // We block any attempt to write/edit files that are likely to hold real secrets. If the
10
9
  // user genuinely needs to bootstrap a `.env`, they can do it themselves or explicitly add
11
10
  // an override in their settings.local.json.
12
11
  //
13
- // SECRET_PATTERNS mirrors block-dangerous-bash.sh's SECRET_BASENAME set
14
- // (block-dangerous-bash.sh:86) — "kept in sync by comment convention, not code sharing"
15
- // today (context.md §2). Preserved as a deliberate duplication in this port; do not
16
- // unify the two lists — that would be a scope-creeping refactor beyond this
17
- // behavior-preserving port (flagged as a future-refactor target, same as today).
12
+ // SECRET_PATTERNS mirrors the secret-basename set in block-dangerous-bash.mjs, kept in sync
13
+ // by comment convention rather than code sharing. The duplication is deliberate: unifying the
14
+ // two lists is a separate refactor, not something to fold into an unrelated change.
18
15
  //
19
16
  // ERE→RegExp translation note: every pattern below is basename-only, pure-ASCII, and
20
17
  // uses only anchors, escaped literal dots, and `?`/`*` quantifiers (plus one bare `.`
@@ -25,7 +22,7 @@
25
22
  // raw COMMAND-STRING content — irrelevant here, since every pattern below matches a
26
23
  // normalized file-path BASENAME extracted from the JSON payload, never raw content, and
27
24
  // no realistic basename contains a line-terminator character for that divergence to bite.
28
- // One platform sensitivity 2.3+ must inherit knowingly: path.basename() is posix-vs-win32
25
+ // One platform sensitivity later hooks must inherit knowingly: path.basename() is posix-vs-win32
29
26
  // separator-aware (on Windows, `C:\Users\me\.env` → `.env` → DENY, where bash basename on
30
27
  // Linux treats `\` as a regular character → allow). For THIS hook the Windows behavior is
31
28
  // strictly safer; for path-heavier hooks (guard-protected-paths) the same divergence could
@@ -2,9 +2,8 @@
2
2
  // hooks/pre-tool/gate-dep-install.mjs — PreToolUse hook (matcher: Bash) — gate
3
3
  // dependency-adding commands.
4
4
  //
5
- // Node port of hooks/pre-tool/gate-dep-install.sh (node-runtime-port, phase 2,
6
- // iteration 2.4). Imports the shared read/deny/audit/config helpers from
7
- // ../lib/common.mjs (2.1, reviewer-blessed) rather than reimplementing them.
5
+ // Imports the shared read/deny/audit/config helpers from ../lib/common.mjs rather than
6
+ // reimplementing them.
8
7
  //
9
8
  // Adding a runtime dependency crosses a trust boundary: it imports unreviewed code,
10
9
  // expands attack surface, and creates a long-term maintenance obligation. The coder
@@ -16,21 +15,18 @@
16
15
  // respecting reinstalls (bare `npm install`, `yarn install`, etc.) are allowed — those
17
16
  // don't add deps, they materialize what's already declared.
18
17
  //
19
- // COUNT CORRECTION (verified by direct read, not inherited from the phase file's
20
- // prose): the bash original's DEP_ADD_PATTERNS array holds 19 patterns, not 18 — and
21
- // the trailing "generic curl-to-installer" trio (brew/apt/apt-get) sits outside the
22
- // six named package-manager ecosystems the file's own comments group (js: npm/yarn/
23
- // pnpm/bun; python: pip/pipx/uv/poetry/conda; rust/go/ruby/php: cargo/go/gem/bundle/
24
- // composer). All 19 are ported below — "port ALL of the patterns" wins over an
25
- // inherited miscount; the phase file's iteration-2.4 scope line is corrected
26
- // alongside this port (see the diary entry for this pass).
18
+ // PATTERN COUNT (verified by direct read): the original bash DEP_ADD_PATTERNS array holds 19
19
+ // patterns, not 18 — the trailing "generic curl-to-installer" trio (brew/apt/apt-get) sits
20
+ // outside the six named package-manager ecosystems the file's own comments group (js: npm/
21
+ // yarn/pnpm/bun; python: pip/pipx/uv/poetry/conda; rust/go/ruby/php: cargo/go/gem/bundle/
22
+ // composer). All 19 are ported below.
27
23
  //
28
24
  // ERE→RegExp translation notes:
29
25
  // - `[[:space:]]` → `\s`. NOT byte-identical: POSIX `[[:space:]]` matches exactly
30
26
  // the 6 ASCII whitespace bytes (space/tab/newline/CR/FF/VT); JS `\s` matches those
31
27
  // same 6 PLUS additional Unicode whitespace (U+00A0, U+2028, U+2029, U+FEFF, and
32
28
  // other Unicode Zs-category characters) — a strict SUPERSET, not the dot-narrowing
33
- // divergence 2.9 has to worry about. Direction matters: a wider `\s` can only make
29
+ // divergence block-dangerous-bash.mjs has to worry about. Direction matters: a wider `\s` can only make
34
30
  // this hook MATCH (and therefore gate) a *broader* set of verb/package-argument
35
31
  // separators than bash would — the safe direction for a security-adjacent gate.
36
32
  // The widening DOES produce observable fail-closed decision divergences on some
@@ -44,7 +40,7 @@
44
40
  // - `[^[:space:]]` → `[^\s]`: same superset relationship, applied to the negated
45
41
  // class (excludes slightly more from "package token" chars) — same safe direction.
46
42
  // - Bare/unescaped `.` or `.*` wildcard (the live POSIX-vs-JS `.` line-terminator
47
- // divergence that matters for block-dangerous-bash.sh, 2.9): NONE of this file's
43
+ // divergence that matters for block-dangerous-bash.mjs): NONE of this file's
48
44
  // 19 patterns use one. The only `.` occurrences are the escaped literal
49
45
  // `\.txt` in the `pip install -r ...txt` pattern — an escaped dot means "literal
50
46
  // dot", identical in ERE and JS regex syntax, so there is no line-terminator
@@ -59,7 +55,7 @@
59
55
  // FIRST-MATCH-WINS / single-decision semantics: bash's per-pattern loop body ends in
60
56
  // either `exit 0` (ALLOW, audited) or `somi::deny_pretool` (which itself calls
61
57
  // `exit 0` — see common.sh:89) — so only the FIRST pattern to match the command is
62
- // ever evaluated; the loop never reaches a second pattern. `matchesAny()` (2.1)
58
+ // ever evaluated; the loop never reaches a second pattern. `matchesAny()`
63
59
  // returns the first-matching pattern's `RegExpExecArray` in array order, reproducing
64
60
  // this exactly, and `m[0]` is the `${BASH_REMATCH[0]}` equivalent interpolated into
65
61
  // the deny message.
@@ -74,7 +70,7 @@
74
70
  // land on the same false/true outcome — verified case-by-case, not assumed.
75
71
  //
76
72
  // COMPOUND-COMMAND REFUSAL (config_allows_dep → configAllowsDep, the security-relevant
77
- // detail this iteration was told to preserve exactly): the allowlist prefix-match only
73
+ // detail that must be preserved exactly): the allowlist prefix-match only
78
74
  // ever applies to the RAW, unmodified `$CMD`/`cmd` string — bash tests
79
75
  // `[[ "$c" == *';'* || "$c" == *'&'* || "$c" == *'|'* ]]` against the WHOLE command
80
76
  // text (not just the matched substring) and refuses the allow (returns 1 / false) if
@@ -84,8 +80,7 @@
84
80
  // in the same order, before any tokenization happens — not simplified to a regex or a
85
81
  // "look compound" heuristic.
86
82
  //
87
- // TOKENIZATION judgment call (named per this iteration's "check exactly what bash
88
- // checks" instruction, not a silent default): bash's `for tok in $c` performs BOTH
83
+ // TOKENIZATION judgment call (named here, not a silent default): bash's `for tok in $c` performs BOTH
89
84
  // IFS word-splitting AND pathname (glob) expansion on the unquoted `$c` — a token
90
85
  // containing `*`/`?`/`[...]` could silently expand against files in the hook's cwd,
91
86
  // making the allowlist check's actual token set depend on the filesystem at hook-run
@@ -96,8 +91,7 @@
96
91
  // whitespace), which is the behavior this hook's allowlist logic actually depends on.
97
92
  //
98
93
  // DISCOVERED DIVERGENCE, decided explicitly (differential-probe finding, not a silent
99
- // default — same category of call as 2.7's prune-list decision and 2.8's regex-
100
- // widening decision): the bash original's `${BASH_REMATCH[0]}` interpolation in its
94
+ // default): the bash original's `${BASH_REMATCH[0]}` interpolation in its
101
95
  // deny message is CORRUPTED whenever `.somi/config.json`'s `dep_install.allow` is
102
96
  // configured (non-empty) and the command is denied via a non-compound path. Root
103
97
  // cause, confirmed by isolated repro: `$BASH_REMATCH` is a bash GLOBAL, not scoped to
@@ -116,18 +110,15 @@
116
110
  // `$BASH_REMATCH` — confirmed by differential probe, zero divergence there).
117
111
  // This corrupted text is NOT reproduced here. Reasons: (1) no fixture in
118
112
  // `tests/hooks/cases/gate-dep-install.json` asserts `expect_reason` at all, so no
119
- // pinned contract is broken; (2) D2's behavior-preservation contract is scoped to
120
- // "identical exit codes and stdout SHAPES" (decisions.md D2) — the shape is identical,
121
- // only this one interpolated substring's content differs, and only on an untested
122
- // path; (3) reproducing it would mean deliberately shipping a message that names the
113
+ // pinned contract is broken; (2) the behavior-preservation contract covers "identical exit
114
+ // codes and stdout SHAPES" — the shape is identical, only this one interpolated substring's
115
+ // content differs, and only on an untested path; (3) reproducing it would mean deliberately shipping a message that names the
123
116
  // wrong thing as "the dependency" in a security-relevant, audit-logged, user-facing
124
117
  // deny reason — strictly worse for the human/agent reading it, not a feature. This
125
118
  // port always interpolates the REAL `DEP_ADD_PATTERNS` match (`m[0]` from the outer
126
119
  // `matchesAny` call, captured once and never touched by `configAllowsDep`), for every
127
- // deny path, allow-list-configured or not. Flagged here and in the diary for explicit
128
- // reviewer sign-off, per this iteration's "verify precisely, do not simplify or
129
- // improve" instruction for `config_allows_dep` — this is the one place a literal
130
- // bug-for-bug port was deliberately NOT chosen, named rather than silent.
120
+ // deny path, allow-list-configured or not. This is the one place a literal bug-for-bug port
121
+ // was deliberately NOT chosen, named here rather than left silent.
131
122
  import { readPayload, field, denyPretool, audit, matchesAny, runHook, config } from '../lib/common.mjs';
132
123
 
133
124
  // Patterns for "add a new dependency". A trailing package argument is required;