@holmes-lab/holmes-kit 0.35.21 → 0.35.22

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
@@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
  <!-- @implements A-SPEC-209 -->
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.35.22] - 2026-10-16
11
+
12
+ Upgrading: run `holmes-kit runtime-binding setup` again so the hooks run this build, then `holmes-kit doctor`. A `codex
13
+ stop gate` WARN means Codex sessions in that workspace end without the Holmes Stop gate; its fix line names the
14
+ `--activate-hooks codex` setup and the one-time `/hooks` trust.
15
+
16
+ ### Fixed
17
+
18
+ - **`runtime-binding remove` no longer rewrites harness wiring** (A-SPEC-752.11). Removing a workspace with no Codex
19
+ project files planned setup's whole wiring and chose to rewrite the shared user-level Codex Stop entry; where Codex
20
+ had switched that entry off, removal was refused ("re-run with --activate-hooks codex", a flag remove does not take)
21
+ and the binding stayed. Remove now changes only the registry, the router programs and the receipt, and the receipt
22
+ forgets the removed workspace's rows and identity — except rows of a workspace nested inside it that stays bound
23
+ (A-SPEC-752.12, 752.13).
24
+ - **doctor names a Codex workspace with no Stop gate** (A-SPEC-769.19). New row `codex stop gate`: WARN when Codex runs
25
+ the Holmes PreToolUse gate for the workspace but no Holmes Stop gate, naming each switched-off Holmes Stop entry and
26
+ warning when its timeout is below 75 s (switched on as it stands, Codex would kill the Stop before its deadline). Only
27
+ Codex routers with a trust record in the Codex user config count, and an entry wired but not yet trusted is named
28
+ (A-SPEC-769.20, 769.21). The `stop hook timeout` row still counts only the Stop hooks that run.
29
+
10
30
  ## [0.35.21] - 2026-10-16
11
31
 
12
32
  Upgrading: restart every session and MCP server (the MCP freshness bridge keeps its slow-git memory per process), and
package/README.md CHANGED
@@ -9,8 +9,8 @@
9
9
  <!-- holmes-kit:attest:begin -->
10
10
  ![traced files](.ax/badges/traced.svg)
11
11
 
12
- **440/442** source files (99.5%) trace to an approved spec · **797/860** approved A-SPECs (92.6%) are anchored from code.
13
- Measured at `6d468ae1591a` (specs `sha256:a0c4f70f8d10`) — reproduce with `holmes-kit attest`.
12
+ **440/442** source files (99.5%) trace to an approved spec · **803/866** approved A-SPECs (92.7%) are anchored from code.
13
+ Measured at `bc705710c89e` (specs `sha256:9ddf0c3d9cee`) — reproduce with `holmes-kit attest`.
14
14
  <!-- holmes-kit:attest:end -->
15
15
 
16
16
  ---
package/dist/.build-id CHANGED
@@ -1 +1 @@
1
- e064e7aa-mvafty6m
1
+ 8dd234f5-mvb0beqr
@@ -227,6 +227,29 @@ export declare function stopHookTimeoutCheck(target: string, opts?: {
227
227
  codexConfigPath?: string;
228
228
  claudeUserSettings?: string | null;
229
229
  agyUserHooks?: string;
230
+ /** A-SPEC-769.19: filled by the same reading for `codexStopGateCheck`; no verdict of this row depends on it. */
231
+ codexGate?: CodexGateReading;
232
+ }): Check | null;
233
+ /** A-SPEC-769.19 — what the stop-hook reading saw of the Holmes Codex gates for one workspace. */
234
+ export type CodexGateReading = {
235
+ codexPre: boolean;
236
+ codexStop: boolean;
237
+ dormant: {
238
+ file: string;
239
+ timeout: number | null;
240
+ }[];
241
+ untrusted: string[];
242
+ };
243
+ /**
244
+ * Codex runs the Holmes PreToolUse gate here but no Holmes Stop gate: Codex sessions end without the constitution
245
+ * check. Measured 2026-10-16 in the dev root (user Stop switched off at timeout 30, project `Stop: []`). No row when no
246
+ * Holmes Codex PreToolUse gate runs — that is a workspace Codex does not govern, not a half-wired one.
247
+ */
248
+ export declare function codexStopGateCheck(target: string, opts?: {
249
+ home?: string;
250
+ codexConfigPath?: string;
251
+ claudeUserSettings?: string | null;
252
+ agyUserHooks?: string;
230
253
  }): Check | null;
231
254
  export declare function ciMatrixCheck(target: string): Check | null;
232
255
  /**
@@ -53,6 +53,7 @@ exports.wiringSpawnCheck = wiringSpawnCheck;
53
53
  exports.mcpProbeEnv = mcpProbeEnv;
54
54
  exports.pushGateCheck = pushGateCheck;
55
55
  exports.stopHookTimeoutCheck = stopHookTimeoutCheck;
56
+ exports.codexStopGateCheck = codexStopGateCheck;
56
57
  exports.ciMatrixCheck = ciMatrixCheck;
57
58
  exports.checksJson = checksJson;
58
59
  exports.formatChecks = formatChecks;
@@ -69,7 +70,7 @@ exports.semanticCoverageCheck = semanticCoverageCheck;
69
70
  exports.semanticTierVerdict = semanticTierVerdict;
70
71
  exports.detectTreeKeyTemporary = detectTreeKeyTemporary;
71
72
  // @implements A-SPEC-751.4, A-SPEC-733, A-SPEC-727, A-SPEC-721, A-SPEC-738, A-SPEC-734, A-SPEC-751, A-SPEC-751.2
72
- // @implements A-SPEC-704, A-SPEC-710, A-SPEC-712, A-SPEC-769.14, A-SPEC-769.16, A-SPEC-769.17, A-SPEC-769.18
73
+ // @implements A-SPEC-704, A-SPEC-710, A-SPEC-712, A-SPEC-769.14, A-SPEC-769.16, A-SPEC-769.17, A-SPEC-769.18, A-SPEC-769.19, A-SPEC-769.20, A-SPEC-769.21
73
74
  const doctor_guidance_1 = require("./doctor-guidance");
74
75
  // @implements A-SPEC-264, A-SPEC-423, A-SPEC-549.1, A-SPEC-590
75
76
  // @implements A-SPEC-594
@@ -2359,6 +2360,9 @@ async function runDoctor(packageRoot, target, opts, extraChecks) {
2359
2360
  const st = stopHookTimeoutCheck(target ?? process.cwd(), { ...(opts?.codexConfigPath ? { codexConfigPath: opts.codexConfigPath } : {}) }); // @implements A-SPEC-769.12, A-SPEC-769.13
2360
2361
  if (st)
2361
2362
  checks.push(st);
2363
+ const cg = codexStopGateCheck(target ?? process.cwd(), { ...(opts?.codexConfigPath ? { codexConfigPath: opts.codexConfigPath } : {}) }); // @implements A-SPEC-769.19
2364
+ if (cg)
2365
+ checks.push(cg);
2362
2366
  }
2363
2367
  checks.push(...(0, worktree_readiness_1.worktreeReadinessChecks)(packageRoot, target ?? process.cwd(), { agent: opts?.agent, codexConfigPath: opts?.codexConfigPath }));
2364
2368
  if (extraChecks) {
@@ -2698,6 +2702,12 @@ function stopHookTimeoutCheck(target, opts = {}) {
2698
2702
  try {
2699
2703
  if (!fs.existsSync(path.join(target, '.ax')))
2700
2704
  return null;
2705
+ const gateReading = opts.codexGate;
2706
+ // @implements A-SPEC-769.20 — only a Codex router or the kernel is a Codex gate.
2707
+ const isCodexPre = (cmd) => typeof cmd === 'string'
2708
+ && /dist[/\\]holmes[/\\]hooks[/\\]pre-tool-use\.js|[/\\]\.holmes[/\\]runtime[/\\]codex-pre-tool-use\.js/.test(cmd);
2709
+ const isCodexStop = (cmd) => typeof cmd === 'string'
2710
+ && /dist[/\\]holmes[/\\]hooks[/\\]stop\.js|[/\\]\.holmes[/\\]runtime[/\\]codex-stop\.js/.test(cmd);
2701
2711
  const { STOP_HOOK_TIMEOUT_SECONDS } = require('../runtime/hook-process');
2702
2712
  // @implements A-SPEC-769.13 — only Holmes's own Stop routes count: the kernel, the Antigravity bin, or a runtime
2703
2713
  // router under `.holmes/runtime`. A user's own `stop.js` is not ours (and setup refuses to rewrite it).
@@ -2726,6 +2736,7 @@ function stopHookTimeoutCheck(target, opts = {}) {
2726
2736
  const codexConfig = opts.codexConfigPath ?? (opts.home !== undefined ? path.join(opts.home, '.codex', 'config.toml') : (0, codex_toml_1.defaultCodexConfigPath)());
2727
2737
  const norm = (s) => process.platform === 'win32' ? s.toLowerCase() : s;
2728
2738
  const off = new Set();
2739
+ const trusted = new Set();
2729
2740
  for (const config of [codexConfig, path.join(target, '.codex', 'config.toml')]) {
2730
2741
  let raw;
2731
2742
  try {
@@ -2741,6 +2752,12 @@ function stopHookTimeoutCheck(target, opts = {}) {
2741
2752
  for (const [key, value] of Object.entries(state))
2742
2753
  if (value && value.enabled === false)
2743
2754
  off.add(norm(key));
2755
+ // @implements A-SPEC-769.20 — Codex runs a hook only with a trust record for its key.
2756
+ // @implements A-SPEC-769.21 — read from the user config only: a record the repository carries is not the user's trust.
2757
+ if (config === codexConfig)
2758
+ for (const [key, value] of Object.entries(state))
2759
+ if (value && typeof value.trusted_hash === 'string')
2760
+ trusted.add(norm(key));
2744
2761
  }
2745
2762
  const aliases = (file) => {
2746
2763
  const out = new Set([file]);
@@ -2752,10 +2769,31 @@ function stopHookTimeoutCheck(target, opts = {}) {
2752
2769
  return [...out];
2753
2770
  };
2754
2771
  for (const file of [path.join(path.dirname(codexConfig), 'hooks.json'), path.join(target, '.codex', 'hooks.json')]) {
2755
- const groups = json(file)?.hooks?.Stop;
2772
+ const doc = json(file);
2773
+ const groups = doc?.hooks?.Stop;
2774
+ const names = aliases(file);
2775
+ // @implements A-SPEC-769.19 — which Holmes Codex gates run here, and which Holmes Stop entries are switched off.
2776
+ if (gateReading) {
2777
+ const isOff = (event, i, j) => names.some((n) => off.has(norm(`${n}:${event}:${i}:${j}`)));
2778
+ const isTrusted = (event, i, j) => names.some((n) => trusted.has(norm(`${n}:${event}:${i}:${j}`)));
2779
+ const pre = doc?.hooks?.PreToolUse;
2780
+ if (Array.isArray(pre) && pre.some((g, i) => Array.isArray(g?.hooks)
2781
+ && g.hooks.some((h, j) => isCodexPre(h?.command) && !isOff('pre_tool_use', i, j) && isTrusted('pre_tool_use', i, j))))
2782
+ gateReading.codexPre = true;
2783
+ if (Array.isArray(groups))
2784
+ groups.forEach((g, i) => (Array.isArray(g?.hooks) ? g.hooks : []).forEach((h, j) => {
2785
+ if (!isCodexStop(h?.command))
2786
+ return;
2787
+ if (isOff('stop', i, j))
2788
+ gateReading.dormant.push({ file, timeout: typeof h?.timeout === 'number' ? h.timeout : null });
2789
+ else if (!isTrusted('stop', i, j))
2790
+ gateReading.untrusted.push(file);
2791
+ else
2792
+ gateReading.codexStop = true;
2793
+ }));
2794
+ }
2756
2795
  if (!Array.isArray(groups))
2757
2796
  continue;
2758
- const names = aliases(file);
2759
2797
  const runs = groups.some((g, i) => Array.isArray(g?.hooks) && g.hooks.some((h, j) => isHolmesStop(h?.command) && short(h?.timeout) && !names.some((n) => off.has(norm(`${n}:stop:${i}:${j}`)))));
2760
2798
  if (runs)
2761
2799
  stale.push({ file, harness: 'codex' });
@@ -2830,6 +2868,18 @@ function stopHookTimeoutCheck(target, opts = {}) {
2830
2868
  continue;
2831
2869
  }
2832
2870
  const stops = doc?.hooks?.Stop;
2871
+ // @implements A-SPEC-769.19 — an enabled Holmes plugin snapshot's gates count as running ones.
2872
+ if (gateReading) {
2873
+ const keyOf = (event) => `${plugin}@${vendor}:${path.relative(base ?? at, f).split(path.sep).join('/')}:${event}:`;
2874
+ const runsAny = (list, event, isOurs) => Array.isArray(list)
2875
+ && list.some((g, i) => handlers(g).some((h, j) => isOurs(h?.command)
2876
+ && !off.has(norm(`${keyOf(event)}${i}:${j}`)) && !(Array.isArray(g?.hooks) ? false : off.has(norm(`${keyOf(event)}${i}`)))
2877
+ && (trusted.has(norm(`${keyOf(event)}${i}:${j}`)) || (!Array.isArray(g?.hooks) && trusted.has(norm(`${keyOf(event)}${i}`))))));
2878
+ if (runsAny(doc?.hooks?.PreToolUse, 'pre_tool_use', isCodexPre))
2879
+ gateReading.codexPre = true;
2880
+ if (runsAny(stops, 'stop', isCodexStop))
2881
+ gateReading.codexStop = true;
2882
+ }
2833
2883
  if (!Array.isArray(stops))
2834
2884
  continue;
2835
2885
  const prefix = `${plugin}@${vendor}:${path.relative(base ?? at, f).split(path.sep).join('/')}:stop:`;
@@ -2876,6 +2926,40 @@ function stopHookTimeoutCheck(target, opts = {}) {
2876
2926
  return null;
2877
2927
  } // diagnosis must never crash doctor
2878
2928
  }
2929
+ // @implements A-SPEC-769.19
2930
+ /**
2931
+ * Codex runs the Holmes PreToolUse gate here but no Holmes Stop gate: Codex sessions end without the constitution
2932
+ * check. Measured 2026-10-16 in the dev root (user Stop switched off at timeout 30, project `Stop: []`). No row when no
2933
+ * Holmes Codex PreToolUse gate runs — that is a workspace Codex does not govern, not a half-wired one.
2934
+ */
2935
+ function codexStopGateCheck(target, opts = {}) {
2936
+ try {
2937
+ const reading = { codexPre: false, codexStop: false, dormant: [], untrusted: [] };
2938
+ if (stopHookTimeoutCheck(target, { ...opts, codexGate: reading }) === null)
2939
+ return null;
2940
+ if (!reading.codexPre)
2941
+ return null;
2942
+ // @implements A-SPEC-769.20 — a trust record is required; whether it still matches the entry is Codex's to judge.
2943
+ if (reading.codexStop)
2944
+ return { name: 'codex stop gate', level: 'PASS', detail: 'Codex has trusted Holmes PreToolUse and Stop gates for this workspace (an entry changed since it was trusted needs /hooks trust again)' };
2945
+ const { STOP_HOOK_TIMEOUT_SECONDS } = require('../runtime/hook-process');
2946
+ const short = reading.dormant.filter((d) => d.timeout !== null && d.timeout < STOP_HOOK_TIMEOUT_SECONDS);
2947
+ const named = reading.dormant.map((d) => `${d.file}${d.timeout === null ? '' : ` (timeout ${d.timeout} s)`}`);
2948
+ return {
2949
+ name: 'codex stop gate', level: 'WARN',
2950
+ detail: 'Codex runs the Holmes PreToolUse gate here but no Holmes Stop gate — Codex sessions end without the Stop check'
2951
+ + (reading.untrusted.length ? `; wired but not yet trusted in Codex (/hooks): ${[...new Set(reading.untrusted)].join(', ')}` : '')
2952
+ + (named.length ? `; switched off in Codex: ${named.join(', ')}` : '')
2953
+ + (short.length ? `; switched on as it stands, a timeout below ${STOP_HOOK_TIMEOUT_SECONDS} s lets Codex kill the Stop before its 60 s deadline answers` : ''),
2954
+ fix: `Operator: holmes-kit runtime-binding setup --workspace ${target} --package <checkout> --release-package <install> --activate-hooks codex`
2955
+ + ` (or the runtime_binding tool with activate_hooks: ['codex']) writes a project Stop at ${STOP_HOOK_TIMEOUT_SECONDS} s; then trust it once with /hooks in Codex`
2956
+ + (short.length ? `. Before switching a listed entry back on instead, raise its timeout to ${STOP_HOOK_TIMEOUT_SECONDS}` : ''),
2957
+ };
2958
+ }
2959
+ catch {
2960
+ return null;
2961
+ } // diagnosis must never crash doctor
2962
+ }
2879
2963
  // @implements A-SPEC-664
2880
2964
  // The CI matrix as doctor sees it: PASS only for a green row at HEAD; everything else is a WARN that
2881
2965
  // says exactly what the ledger says — "not run" when there is no row, the failed suites when red,
@@ -42,7 +42,7 @@ exports.codexDuplicateRoutes = codexDuplicateRoutes;
42
42
  exports.runtimeBindingStatus = runtimeBindingStatus;
43
43
  exports.runRuntimeBinding = runRuntimeBinding;
44
44
  exports.trackedWorkspacePaths = trackedWorkspacePaths;
45
- // @implements A-SPEC-769.10, A-SPEC-752.10, A-SPEC-752.9, A-SPEC-751.5, A-SPEC-751.6, A-SPEC-751, A-SPEC-752, A-SPEC-752.7, A-SPEC-752.8
45
+ // @implements A-SPEC-769.10, A-SPEC-752.11, A-SPEC-752.12, A-SPEC-752.13, A-SPEC-752.10, A-SPEC-752.9, A-SPEC-751.5, A-SPEC-751.6, A-SPEC-751, A-SPEC-752, A-SPEC-752.7, A-SPEC-752.8
46
46
  const fs = __importStar(require("node:fs"));
47
47
  const os = __importStar(require("node:os"));
48
48
  const path = __importStar(require("node:path"));
@@ -557,187 +557,191 @@ function runRuntimeBinding(opts) {
557
557
  delete ours.Stop;
558
558
  add(file, json({ ...doc, 'holmes-kit': ours }));
559
559
  };
560
- try {
561
- toml(codexConfig, true);
562
- toml(path.join(root, '.codex/config.toml'), false);
563
- const userNativeState = (0, codex_toml_1.parseCodexConfig)(readOptional(codexConfig) ?? '');
564
- const normalized = (s) => process.platform === 'win32' ? s.toLowerCase() : s;
565
- const globalAliases = new Set([codexHooks]);
566
- if (fs.existsSync(codexHooks)) {
567
- globalAliases.add(fs.realpathSync(codexHooks));
568
- globalAliases.add(fs.realpathSync.native(codexHooks));
569
- }
570
- if (userNativeState.ok)
571
- for (const [key, state] of Object.entries(userNativeState.doc.hooks?.state ?? {})) {
572
- if (!object(state) || state.enabled !== false)
573
- continue;
574
- for (const file of globalAliases) {
575
- if (normalized(key).startsWith(normalized(`${file}:`)))
576
- disabledGlobalKeys.add(key.slice(file.length + 1));
577
- }
578
- }
579
- const codexFiles = [codexHooks, path.join(root, '.codex/hooks.json')];
580
- const codexDocs = codexFiles.map((f) => document(readOptional(f), f));
581
- // @implements A-SPEC-752.9 — Codex keys a hook's enable state by position (<file>:<event>:<group>:<hook>). Measured
582
- // 2026-10-05: the plan removed two Holmes groups from the user file and wrote one at index 0, whose key said
583
- // `enabled = false`; the gate was written and never ran. A gate the plan writes is looked up by its own key.
584
- const planCodex = (forced) => {
585
- codexProjectEvents.clear();
586
- const events = codexFiles.map(() => new Set());
587
- for (const event of ['PreToolUse', 'Stop']) {
588
- const existing = codexDocs.findIndex((d, source) => Array.isArray(d.hooks?.[event])
589
- && d.hooks[event].some((g, group) => Array.isArray(g?.hooks)
590
- && g.hooks.some((h, hook) => owns(h?.command) && !disabledGlobalCodex(codexFiles[source], event, group, hook))));
591
- // Explicit development activation adds missing lifecycles only to this project.
592
- // Filling an empty user lifecycle would also activate every consumer workspace.
593
- const empty = codexDocs.findIndex((d) => Array.isArray(d.hooks?.[event]) && d.hooks[event].length === 0);
594
- const owner = forced.has(event) ? 1 : existing >= 0 ? existing : activate.has('codex') ? 1 : empty >= 0 ? empty : 0;
595
- events[owner].add(event);
596
- if (owner === 1)
597
- codexProjectEvents.add(event);
560
+ // @implements A-SPEC-752.11 — removal plans no harness wiring: every harness entry calls the same router programs and
561
+ // the router reads the registry live, so dropping the binding is the whole act. Measured 2026-10-16: remove planned
562
+ // setup's wiring for a workspace with no Codex project files and chose to rewrite the shared, switched-off user Stop.
563
+ if (opts.operation === 'setup')
564
+ try {
565
+ toml(codexConfig, true);
566
+ toml(path.join(root, '.codex/config.toml'), false);
567
+ const userNativeState = (0, codex_toml_1.parseCodexConfig)(readOptional(codexConfig) ?? '');
568
+ const normalized = (s) => process.platform === 'win32' ? s.toLowerCase() : s;
569
+ const globalAliases = new Set([codexHooks]);
570
+ if (fs.existsSync(codexHooks)) {
571
+ globalAliases.add(fs.realpathSync(codexHooks));
572
+ globalAliases.add(fs.realpathSync.native(codexHooks));
598
573
  }
599
- codexFiles.forEach((f, i) => native(f, 'codex', events[i]));
600
- return events;
601
- };
602
- const switchedOffKeys = [];
603
- for (const configFile of [codexConfig, path.join(root, '.codex/config.toml')]) {
604
- const configState = (0, codex_toml_1.parseCodexConfig)(readOptional(configFile) ?? '');
605
- if (configState.ok)
606
- for (const [key, state] of Object.entries(configState.doc.hooks?.state ?? {}))
607
- if (object(state) && state.enabled === false)
608
- switchedOffKeys.push(key);
609
- }
610
- const gatesSwitchedOff = (events) => {
611
- const found = [];
612
- codexFiles.forEach((file, source) => {
613
- const doc = document(planned.get(file)?.after ?? readOptional(file), file);
614
- // An entry that already stood there, switched off, is not something this plan writes: doctor reports it.
615
- const standing = document(readOptional(file), file);
616
- const aliases = new Set([file]);
617
- if (fs.existsSync(file)) {
618
- aliases.add(fs.realpathSync(file));
619
- aliases.add(fs.realpathSync.native(file));
620
- }
621
- for (const [event, keyEvent, entry] of [['PreToolUse', 'pre_tool_use', 'pre-tool-use'], ['Stop', 'stop', 'stop']]) {
622
- if (!events[source].has(event) || !Array.isArray(doc.hooks?.[event]))
574
+ if (userNativeState.ok)
575
+ for (const [key, state] of Object.entries(userNativeState.doc.hooks?.state ?? {})) {
576
+ if (!object(state) || state.enabled !== false)
623
577
  continue;
624
- doc.hooks[event].forEach((g, i) => (Array.isArray(g?.hooks) ? g.hooks : []).forEach((h, j) => {
625
- if (h?.command !== command('codex', entry))
626
- return;
627
- if (JSON.stringify(standing.hooks?.[event]?.[i]?.hooks?.[j]) === JSON.stringify(h))
628
- return;
629
- const key = switchedOffKeys.find((k) => [...aliases].some((alias) => normalized(k) === normalized(`${alias}:${keyEvent}:${i}:${j}`)));
630
- if (key !== undefined)
631
- found.push({ source, event, key });
632
- }));
578
+ for (const file of globalAliases) {
579
+ if (normalized(key).startsWith(normalized(`${file}:`)))
580
+ disabledGlobalKeys.add(key.slice(file.length + 1));
581
+ }
633
582
  }
634
- });
635
- return found;
636
- };
637
- let codexEvents = planCodex(new Set());
638
- // Explicit activation may use the project file; nothing else may choose another place on its own.
639
- const toProject = new Set(gatesSwitchedOff(codexEvents).filter((g) => g.source === 0 && activate.has('codex')).map((g) => g.event));
640
- if (toProject.size > 0)
641
- codexEvents = planCodex(toProject);
642
- for (const gate of gatesSwitchedOff(codexEvents)) {
643
- conflicts.push(`the Codex ${gate.event} gate would be written where Codex has it switched off (${gate.key} is enabled = false), so it would not run; `
644
- + (gate.source === 0 && !activate.has('codex')
645
- ? "re-run with --activate-hooks codex to write this workspace's project hooks file, or switch that hook on in Codex (/hooks) and preview again"
646
- : 'switch that hook on in Codex (/hooks) and preview again'));
647
- }
648
- // Native disabled state is indexed by source/group/hook. Keeping its bytes while moving
649
- // the disabled gate would silently enable it. Refuse that migration, never mint trust.
650
- // Keep each layer's disabled keys: a project enable override does not change
651
- // the user-level disabled state consumed by other workspaces.
652
- const nativeStates = [];
653
- for (const configFile of [codexConfig, path.join(root, '.codex/config.toml')]) {
654
- const configState = (0, codex_toml_1.parseCodexConfig)(readOptional(configFile) ?? '');
655
- if (configState.ok)
656
- nativeStates.push(...Object.entries(configState.doc.hooks?.state ?? {}));
657
- }
658
- for (const hookFile of codexFiles) {
659
- const oldHooks = document(readOptional(hookFile), hookFile);
660
- const newHooks = document(planned.get(hookFile)?.after ?? readOptional(hookFile), hookFile);
661
- const norm = (s) => process.platform === 'win32' ? s.toLowerCase() : s;
662
- const paths = new Set([hookFile]);
663
- if (fs.existsSync(hookFile)) {
664
- paths.add(fs.realpathSync(hookFile));
665
- paths.add(fs.realpathSync.native(hookFile));
583
+ const codexFiles = [codexHooks, path.join(root, '.codex/hooks.json')];
584
+ const codexDocs = codexFiles.map((f) => document(readOptional(f), f));
585
+ // @implements A-SPEC-752.9 — Codex keys a hook's enable state by position (<file>:<event>:<group>:<hook>). Measured
586
+ // 2026-10-05: the plan removed two Holmes groups from the user file and wrote one at index 0, whose key said
587
+ // `enabled = false`; the gate was written and never ran. A gate the plan writes is looked up by its own key.
588
+ const planCodex = (forced) => {
589
+ codexProjectEvents.clear();
590
+ const events = codexFiles.map(() => new Set());
591
+ for (const event of ['PreToolUse', 'Stop']) {
592
+ const existing = codexDocs.findIndex((d, source) => Array.isArray(d.hooks?.[event])
593
+ && d.hooks[event].some((g, group) => Array.isArray(g?.hooks)
594
+ && g.hooks.some((h, hook) => owns(h?.command) && !disabledGlobalCodex(codexFiles[source], event, group, hook))));
595
+ // Explicit development activation adds missing lifecycles only to this project.
596
+ // Filling an empty user lifecycle would also activate every consumer workspace.
597
+ const empty = codexDocs.findIndex((d) => Array.isArray(d.hooks?.[event]) && d.hooks[event].length === 0);
598
+ const owner = forced.has(event) ? 1 : existing >= 0 ? existing : activate.has('codex') ? 1 : empty >= 0 ? empty : 0;
599
+ events[owner].add(event);
600
+ if (owner === 1)
601
+ codexProjectEvents.add(event);
602
+ }
603
+ codexFiles.forEach((f, i) => native(f, 'codex', events[i]));
604
+ return events;
605
+ };
606
+ const switchedOffKeys = [];
607
+ for (const configFile of [codexConfig, path.join(root, '.codex/config.toml')]) {
608
+ const configState = (0, codex_toml_1.parseCodexConfig)(readOptional(configFile) ?? '');
609
+ if (configState.ok)
610
+ for (const [key, state] of Object.entries(configState.doc.hooks?.state ?? {}))
611
+ if (object(state) && state.enabled === false)
612
+ switchedOffKeys.push(key);
666
613
  }
667
- for (const [key, state] of nativeStates) {
668
- if (!object(state) || state.enabled !== false)
669
- continue;
670
- for (const file of paths)
614
+ const gatesSwitchedOff = (events) => {
615
+ const found = [];
616
+ codexFiles.forEach((file, source) => {
617
+ const doc = document(planned.get(file)?.after ?? readOptional(file), file);
618
+ // An entry that already stood there, switched off, is not something this plan writes: doctor reports it.
619
+ const standing = document(readOptional(file), file);
620
+ const aliases = new Set([file]);
621
+ if (fs.existsSync(file)) {
622
+ aliases.add(fs.realpathSync(file));
623
+ aliases.add(fs.realpathSync.native(file));
624
+ }
671
625
  for (const [event, keyEvent, entry] of [['PreToolUse', 'pre_tool_use', 'pre-tool-use'], ['Stop', 'stop', 'stop']]) {
672
- const prefix = `${file}:${keyEvent}:`;
673
- if (!norm(key).startsWith(norm(prefix)))
626
+ if (!events[source].has(event) || !Array.isArray(doc.hooks?.[event]))
674
627
  continue;
675
- const indices = key.slice(prefix.length).match(/^(\d+):(\d+)$/);
676
- if (!indices)
677
- continue;
678
- const i = Number(indices[1]);
679
- const j = Number(indices[2]);
680
- const old = oldHooks.hooks?.[event]?.[i]?.hooks?.[j];
681
- const replacement = newHooks.hooks?.[event]?.[i]?.hooks?.[j];
682
- if (old && JSON.stringify(replacement) !== JSON.stringify(old)
683
- && !(owns(old.command) && replacement?.command === command('codex', entry))) {
684
- throw new Error('A disabled Codex hook would move to a different native state key; review the hook layout before migration');
628
+ doc.hooks[event].forEach((g, i) => (Array.isArray(g?.hooks) ? g.hooks : []).forEach((h, j) => {
629
+ if (h?.command !== command('codex', entry))
630
+ return;
631
+ if (JSON.stringify(standing.hooks?.[event]?.[i]?.hooks?.[j]) === JSON.stringify(h))
632
+ return;
633
+ const key = switchedOffKeys.find((k) => [...aliases].some((alias) => normalized(k) === normalized(`${alias}:${keyEvent}:${i}:${j}`)));
634
+ if (key !== undefined)
635
+ found.push({ source, event, key });
636
+ }));
637
+ }
638
+ });
639
+ return found;
640
+ };
641
+ let codexEvents = planCodex(new Set());
642
+ // Explicit activation may use the project file; nothing else may choose another place on its own.
643
+ const toProject = new Set(gatesSwitchedOff(codexEvents).filter((g) => g.source === 0 && activate.has('codex')).map((g) => g.event));
644
+ if (toProject.size > 0)
645
+ codexEvents = planCodex(toProject);
646
+ for (const gate of gatesSwitchedOff(codexEvents)) {
647
+ conflicts.push(`the Codex ${gate.event} gate would be written where Codex has it switched off (${gate.key} is enabled = false), so it would not run; `
648
+ + (gate.source === 0 && !activate.has('codex')
649
+ ? "re-run with --activate-hooks codex to write this workspace's project hooks file, or switch that hook on in Codex (/hooks) and preview again"
650
+ : 'switch that hook on in Codex (/hooks) and preview again'));
651
+ }
652
+ // Native disabled state is indexed by source/group/hook. Keeping its bytes while moving
653
+ // the disabled gate would silently enable it. Refuse that migration, never mint trust.
654
+ // Keep each layer's disabled keys: a project enable override does not change
655
+ // the user-level disabled state consumed by other workspaces.
656
+ const nativeStates = [];
657
+ for (const configFile of [codexConfig, path.join(root, '.codex/config.toml')]) {
658
+ const configState = (0, codex_toml_1.parseCodexConfig)(readOptional(configFile) ?? '');
659
+ if (configState.ok)
660
+ nativeStates.push(...Object.entries(configState.doc.hooks?.state ?? {}));
661
+ }
662
+ for (const hookFile of codexFiles) {
663
+ const oldHooks = document(readOptional(hookFile), hookFile);
664
+ const newHooks = document(planned.get(hookFile)?.after ?? readOptional(hookFile), hookFile);
665
+ const norm = (s) => process.platform === 'win32' ? s.toLowerCase() : s;
666
+ const paths = new Set([hookFile]);
667
+ if (fs.existsSync(hookFile)) {
668
+ paths.add(fs.realpathSync(hookFile));
669
+ paths.add(fs.realpathSync.native(hookFile));
670
+ }
671
+ for (const [key, state] of nativeStates) {
672
+ if (!object(state) || state.enabled !== false)
673
+ continue;
674
+ for (const file of paths)
675
+ for (const [event, keyEvent, entry] of [['PreToolUse', 'pre_tool_use', 'pre-tool-use'], ['Stop', 'stop', 'stop']]) {
676
+ const prefix = `${file}:${keyEvent}:`;
677
+ if (!norm(key).startsWith(norm(prefix)))
678
+ continue;
679
+ const indices = key.slice(prefix.length).match(/^(\d+):(\d+)$/);
680
+ if (!indices)
681
+ continue;
682
+ const i = Number(indices[1]);
683
+ const j = Number(indices[2]);
684
+ const old = oldHooks.hooks?.[event]?.[i]?.hooks?.[j];
685
+ const replacement = newHooks.hooks?.[event]?.[i]?.hooks?.[j];
686
+ if (old && JSON.stringify(replacement) !== JSON.stringify(old)
687
+ && !(owns(old.command) && replacement?.command === command('codex', entry))) {
688
+ throw new Error('A disabled Codex hook would move to a different native state key; review the hook layout before migration');
689
+ }
685
690
  }
691
+ }
692
+ }
693
+ native(path.join(root, agents_1.CODEX_PLUGIN_DIR, 'hooks.json'), 'codex', false);
694
+ // @implements A-SPEC-751.6 — after the Codex lifecycles are planned, so the entry joins the planned document.
695
+ codexFiles.forEach((f) => routeSessionStart(f, codexSessionStartCommand));
696
+ if (activate.has('codex'))
697
+ addCodexSessionStart(codexFiles[1]);
698
+ const claudeFiles = [path.join(home, '.claude/settings.json'), path.join(root, '.claude/settings.local.json'), path.join(root, '.claude/settings.json')];
699
+ const claudeDocs = claudeFiles.map((f) => document(readOptional(f), f));
700
+ const claudeEvents = claudeFiles.map(() => new Set());
701
+ for (const event of ['PreToolUse', 'Stop']) {
702
+ const existing = claudeDocs.findIndex((d) => Array.isArray(d.hooks?.[event]) && d.hooks[event].some((g) => Array.isArray(g?.hooks) && g.hooks.some((h) => owns(h?.command))));
703
+ const empty = claudeDocs.findIndex((d) => Array.isArray(d.hooks?.[event]) && d.hooks[event].length === 0);
704
+ // Keep an existing owner; otherwise honor an explicit empty source before creating a lifecycle.
705
+ claudeEvents[existing >= 0 ? existing : activate.has('claude') ? 1 : empty >= 0 ? empty : 1].add(event);
706
+ }
707
+ claudeFiles.forEach((f, i) => native(f, 'claude', claudeEvents[i]));
708
+ claudeFiles.forEach((f) => routeSessionStart(f));
709
+ mcp(path.join(root, '.mcp.json'), 'claude');
710
+ mcp(path.join(root, '.agents/mcp_config.json'), 'antigravity');
711
+ const agyUser = (0, agents_1.agyUserHooksPath)(home);
712
+ const agyFiles = [agyUser, path.join(root, '.agents/hooks.json')];
713
+ const agyDocs = agyFiles.map((f) => document(readOptional(f), f)['holmes-kit']);
714
+ const agyEvents = agyFiles.map(() => new Set());
715
+ for (const event of ['PreToolUse', 'Stop']) {
716
+ const existing = agyDocs.findIndex((d, i) => object(d) && Array.isArray(d[event]) && d[event].length > 0
717
+ && !(activate.has('antigravity') && i === 0 && d.enabled === false));
718
+ const empty = agyDocs.findIndex((d) => object(d) && Array.isArray(d[event]) && d[event].length === 0);
719
+ agyEvents[existing >= 0 ? existing : activate.has('antigravity') ? 1 : empty >= 0 ? empty : 1].add(event);
720
+ }
721
+ agyFiles.forEach((f, i) => agy(f, agyEvents[i]));
722
+ // Installed plugin snapshots are independently loaded. Never imply changing the checkout copy suppresses them.
723
+ const plugins = path.join(path.dirname(codexConfig), 'plugins');
724
+ const cache = path.join(plugins, 'cache');
725
+ if (fs.existsSync(cache)) {
726
+ const vendors = fs.readdirSync(cache, { withFileTypes: true }).filter((d) => d.isDirectory() && /holmes/i.test(d.name));
727
+ const visit = (at, depth) => {
728
+ if (depth > 3)
729
+ return;
730
+ for (const d of fs.readdirSync(at, { withFileTypes: true })) {
731
+ const f = path.join(at, d.name);
732
+ if (d.isDirectory())
733
+ visit(f, depth + 1);
734
+ else if (d.isFile() && d.name === 'hooks.json' && /pre-tool-use|holmes-hook|holmes-stop/.test((0, binding_1.readBounded)(f)))
735
+ conflicts.push(`Cached Holmes hook source needs native plugin activation review: ${f}`);
686
736
  }
737
+ };
738
+ for (const vendor of vendors)
739
+ visit(path.join(cache, vendor.name), 0);
687
740
  }
688
741
  }
689
- native(path.join(root, agents_1.CODEX_PLUGIN_DIR, 'hooks.json'), 'codex', false);
690
- // @implements A-SPEC-751.6 — after the Codex lifecycles are planned, so the entry joins the planned document.
691
- codexFiles.forEach((f) => routeSessionStart(f, codexSessionStartCommand));
692
- if (activate.has('codex'))
693
- addCodexSessionStart(codexFiles[1]);
694
- const claudeFiles = [path.join(home, '.claude/settings.json'), path.join(root, '.claude/settings.local.json'), path.join(root, '.claude/settings.json')];
695
- const claudeDocs = claudeFiles.map((f) => document(readOptional(f), f));
696
- const claudeEvents = claudeFiles.map(() => new Set());
697
- for (const event of ['PreToolUse', 'Stop']) {
698
- const existing = claudeDocs.findIndex((d) => Array.isArray(d.hooks?.[event]) && d.hooks[event].some((g) => Array.isArray(g?.hooks) && g.hooks.some((h) => owns(h?.command))));
699
- const empty = claudeDocs.findIndex((d) => Array.isArray(d.hooks?.[event]) && d.hooks[event].length === 0);
700
- // Keep an existing owner; otherwise honor an explicit empty source before creating a lifecycle.
701
- claudeEvents[existing >= 0 ? existing : activate.has('claude') ? 1 : empty >= 0 ? empty : 1].add(event);
702
- }
703
- claudeFiles.forEach((f, i) => native(f, 'claude', claudeEvents[i]));
704
- claudeFiles.forEach((f) => routeSessionStart(f));
705
- mcp(path.join(root, '.mcp.json'), 'claude');
706
- mcp(path.join(root, '.agents/mcp_config.json'), 'antigravity');
707
- const agyUser = (0, agents_1.agyUserHooksPath)(home);
708
- const agyFiles = [agyUser, path.join(root, '.agents/hooks.json')];
709
- const agyDocs = agyFiles.map((f) => document(readOptional(f), f)['holmes-kit']);
710
- const agyEvents = agyFiles.map(() => new Set());
711
- for (const event of ['PreToolUse', 'Stop']) {
712
- const existing = agyDocs.findIndex((d, i) => object(d) && Array.isArray(d[event]) && d[event].length > 0
713
- && !(activate.has('antigravity') && i === 0 && d.enabled === false));
714
- const empty = agyDocs.findIndex((d) => object(d) && Array.isArray(d[event]) && d[event].length === 0);
715
- agyEvents[existing >= 0 ? existing : activate.has('antigravity') ? 1 : empty >= 0 ? empty : 1].add(event);
742
+ catch (e) {
743
+ conflicts.push(e.message);
716
744
  }
717
- agyFiles.forEach((f, i) => agy(f, agyEvents[i]));
718
- // Installed plugin snapshots are independently loaded. Never imply changing the checkout copy suppresses them.
719
- const plugins = path.join(path.dirname(codexConfig), 'plugins');
720
- const cache = path.join(plugins, 'cache');
721
- if (fs.existsSync(cache)) {
722
- const vendors = fs.readdirSync(cache, { withFileTypes: true }).filter((d) => d.isDirectory() && /holmes/i.test(d.name));
723
- const visit = (at, depth) => {
724
- if (depth > 3)
725
- return;
726
- for (const d of fs.readdirSync(at, { withFileTypes: true })) {
727
- const f = path.join(at, d.name);
728
- if (d.isDirectory())
729
- visit(f, depth + 1);
730
- else if (d.isFile() && d.name === 'hooks.json' && /pre-tool-use|holmes-hook|holmes-stop/.test((0, binding_1.readBounded)(f)))
731
- conflicts.push(`Cached Holmes hook source needs native plugin activation review: ${f}`);
732
- }
733
- };
734
- for (const vendor of vendors)
735
- visit(path.join(cache, vendor.name), 0);
736
- }
737
- }
738
- catch (e) {
739
- conflicts.push(e.message);
740
- }
741
745
  add(destination, after);
742
746
  const manifestPath = path.join(dir, 'installation.json');
743
747
  const receipt = readOptional(manifestPath);
@@ -772,9 +776,21 @@ function runRuntimeBinding(opts) {
772
776
  // file leaves the receipt — and with it the plan — as it was.
773
777
  for (const c of planned.values())
774
778
  recorded.set(c.path, { path: c.path, digest: digest(wiringViewOf(c.path, c.after)) });
775
- // Same-path builds still need a new reviewed plan. Legacy receipts gain identity only via apply.
776
- runtimeIdentities[root] = { packageRoot: selection.packageRoot, buildId: selection.buildId,
777
- releasePackageRoot: next.releasePackageRoot, releaseBuild };
779
+ // @implements A-SPEC-752.11 — the receipt forgets a removed workspace: its rows and its identity.
780
+ if (opts.operation === 'remove') {
781
+ // @implements A-SPEC-752.12, A-SPEC-752.13 — a row inside a workspace that stays bound AND is nested inside the
782
+ // removed root is that workspace's; a remaining parent of the removed root does not keep the removed root's rows.
783
+ for (const p of [...recorded.keys()]) {
784
+ if ((0, binding_1.inside)(root, p) && !next.bindings.some((b) => (0, binding_1.inside)(root, b.workspaceRoot) && (0, binding_1.inside)(b.workspaceRoot, p)))
785
+ recorded.delete(p);
786
+ }
787
+ delete runtimeIdentities[root];
788
+ }
789
+ else {
790
+ // Same-path builds still need a new reviewed plan. Legacy receipts gain identity only via apply.
791
+ runtimeIdentities[root] = { packageRoot: selection.packageRoot, buildId: selection.buildId,
792
+ releasePackageRoot: next.releasePackageRoot, releaseBuild };
793
+ }
778
794
  add(manifestPath, json({ version: 1, files: [...recorded.values()], runtimeIdentities }));
779
795
  const changes = [...planned.values()].filter((c) => c.before !== c.after);
780
796
  const planDigest = (0, runtime_binding_approval_1.runtimePlanDigest)({ operation: opts.operation, root, selection, releasePackageRoot: next.releasePackageRoot,
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.35.21",
4
+ "version": "0.35.22",
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",