@holmes-lab/holmes-kit 0.35.21 → 0.35.23
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 +40 -0
- package/README.md +2 -2
- package/dist/.build-id +1 -1
- package/dist/holmes/cli/doctor.d.ts +23 -0
- package/dist/holmes/cli/doctor.js +87 -3
- package/dist/holmes/cli/index.js +2 -1
- package/dist/holmes/cli/runtime-binding-approval.d.ts +6 -1
- package/dist/holmes/cli/runtime-binding-approval.js +13 -8
- package/dist/holmes/cli/runtime-binding.d.ts +4 -2
- package/dist/holmes/cli/runtime-binding.js +257 -181
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,46 @@ 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.23] - 2026-10-17
|
|
11
|
+
|
|
12
|
+
Upgrading: run `holmes-kit runtime-binding setup` again so the hooks run this build. A binding whose workspace was
|
|
13
|
+
emptied or deleted can now be removed: run `holmes-kit runtime-binding remove --workspace <path>` from a governed
|
|
14
|
+
workspace and grant the request it queues there; with several dead bindings, remove them one at a time.
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- **`runtime-binding remove` works on a workspace that is no longer a governed project** (A-SPEC-752.14). Removing a
|
|
19
|
+
workspace whose `.ax` was deleted failed with "Cannot queue governance-wiring approval: no-project", and a workspace
|
|
20
|
+
whose directory was gone could not be named at all — a dead binding could only be deleted from the operator registry
|
|
21
|
+
by hand. For a workspace without `.ax` the approval is now queued, granted and consumed in the governed workspace the
|
|
22
|
+
operator runs `remove` from (the request still names the removed workspace); with none, remove is refused and nothing
|
|
23
|
+
is written — no `.ax` is planted in the removed workspace any more (A-SPEC-752.15).
|
|
24
|
+
- **One vanished binding no longer blocks the removal of another** (A-SPEC-752.15, 752.16, 752.17). Remove sets aside
|
|
25
|
+
every binding whose workspace directory is gone, validates the rest as before, and writes the set-aside ones back
|
|
26
|
+
unchanged, so each dead binding can be removed in turn; their receipt rows stay with them. A vanished binding is
|
|
27
|
+
matched by resolved path, duplicate spellings of one root are refused, and a remove that matches nothing of its own
|
|
28
|
+
says "Nothing registered".
|
|
29
|
+
|
|
30
|
+
## [0.35.22] - 2026-10-16
|
|
31
|
+
|
|
32
|
+
Upgrading: run `holmes-kit runtime-binding setup` again so the hooks run this build, then `holmes-kit doctor`. A `codex
|
|
33
|
+
stop gate` WARN means Codex sessions in that workspace end without the Holmes Stop gate; its fix line names the
|
|
34
|
+
`--activate-hooks codex` setup and the one-time `/hooks` trust.
|
|
35
|
+
|
|
36
|
+
### Fixed
|
|
37
|
+
|
|
38
|
+
- **`runtime-binding remove` no longer rewrites harness wiring** (A-SPEC-752.11). Removing a workspace with no Codex
|
|
39
|
+
project files planned setup's whole wiring and chose to rewrite the shared user-level Codex Stop entry; where Codex
|
|
40
|
+
had switched that entry off, removal was refused ("re-run with --activate-hooks codex", a flag remove does not take)
|
|
41
|
+
and the binding stayed. Remove now changes only the registry, the router programs and the receipt, and the receipt
|
|
42
|
+
forgets the removed workspace's rows and identity — except rows of a workspace nested inside it that stays bound
|
|
43
|
+
(A-SPEC-752.12, 752.13).
|
|
44
|
+
- **doctor names a Codex workspace with no Stop gate** (A-SPEC-769.19). New row `codex stop gate`: WARN when Codex runs
|
|
45
|
+
the Holmes PreToolUse gate for the workspace but no Holmes Stop gate, naming each switched-off Holmes Stop entry and
|
|
46
|
+
warning when its timeout is below 75 s (switched on as it stands, Codex would kill the Stop before its deadline). Only
|
|
47
|
+
Codex routers with a trust record in the Codex user config count, and an entry wired but not yet trusted is named
|
|
48
|
+
(A-SPEC-769.20, 769.21). The `stop hook timeout` row still counts only the Stop hooks that run.
|
|
49
|
+
|
|
10
50
|
## [0.35.21] - 2026-10-16
|
|
11
51
|
|
|
12
52
|
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
|

|
|
11
11
|
|
|
12
|
-
**440/442** source files (99.5%) trace to an approved spec · **
|
|
13
|
-
Measured at `
|
|
12
|
+
**440/442** source files (99.5%) trace to an approved spec · **807/870** approved A-SPECs (92.7%) are anchored from code.
|
|
13
|
+
Measured at `3fe5cc250195` (specs `sha256:974cd643361c`) — reproduce with `holmes-kit attest`.
|
|
14
14
|
<!-- holmes-kit:attest:end -->
|
|
15
15
|
|
|
16
16
|
---
|
package/dist/.build-id
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
87aa7994-mvb6lrt9
|
|
@@ -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
|
|
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,
|
package/dist/holmes/cli/index.js
CHANGED
|
@@ -364,7 +364,8 @@ async function main(argv) {
|
|
|
364
364
|
registryPath: typeof flags.registry === 'string' ? flags.registry : defaultRuntimeRegistry(),
|
|
365
365
|
packageRoot: typeof flags.package === 'string' ? flags.package : undefined,
|
|
366
366
|
releasePackageRoot: typeof flags['release-package'] === 'string' ? flags['release-package'] : undefined, dryRun: flags['dry-run'] === true, approval: readApproval(),
|
|
367
|
-
activateHooks: typeof activate === 'string' ? (activate === 'all' ? ['claude', 'codex', 'antigravity'] : activate.split(',')) : undefined
|
|
367
|
+
activateHooks: typeof activate === 'string' ? (activate === 'all' ? ['claude', 'codex', 'antigravity'] : activate.split(',')) : undefined,
|
|
368
|
+
approvalRoot: process.cwd() }); // A-SPEC-752.14
|
|
368
369
|
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
369
370
|
return 0;
|
|
370
371
|
}
|
|
@@ -4,4 +4,9 @@ export declare function runtimePlanDigest(identity: unknown, changes: {
|
|
|
4
4
|
before: string | null;
|
|
5
5
|
after: string;
|
|
6
6
|
}[]): string;
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @implements A-SPEC-752.14 — `approvalRoot` is the governed workspace whose queue, grants and ledger hold the decision;
|
|
9
|
+
* it differs from `root` only for the remove of a workspace that is no longer a governed project. The request target
|
|
10
|
+
* still names `root`, so the operator's list shows what the plan is about.
|
|
11
|
+
*/
|
|
12
|
+
export declare function applyApprovedRuntimePlan(root: string, subject: string, envApproval: Approval | undefined, check: () => void, apply: () => void, approvalRoot?: string): void;
|
|
@@ -35,7 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.runtimePlanDigest = runtimePlanDigest;
|
|
37
37
|
exports.applyApprovedRuntimePlan = applyApprovedRuntimePlan;
|
|
38
|
-
// @implements A-SPEC-752
|
|
38
|
+
// @implements A-SPEC-752, A-SPEC-752.14
|
|
39
39
|
const path = __importStar(require("node:path"));
|
|
40
40
|
const node_crypto_1 = require("node:crypto");
|
|
41
41
|
const risk_gate_1 = require("../guardrail/risk-gate");
|
|
@@ -50,8 +50,13 @@ function runtimePlanDigest(identity, changes) {
|
|
|
50
50
|
.sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
51
51
|
return `sha256:${hash(JSON.stringify({ identity, files }))}`;
|
|
52
52
|
}
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
/**
|
|
54
|
+
* @implements A-SPEC-752.14 — `approvalRoot` is the governed workspace whose queue, grants and ledger hold the decision;
|
|
55
|
+
* it differs from `root` only for the remove of a workspace that is no longer a governed project. The request target
|
|
56
|
+
* still names `root`, so the operator's list shows what the plan is about.
|
|
57
|
+
*/
|
|
58
|
+
function applyApprovedRuntimePlan(root, subject, envApproval, check, apply, approvalRoot = root) {
|
|
59
|
+
const ledgerDir = path.join(approvalRoot, '.ax/ledger');
|
|
55
60
|
const ledger = new ledger_store_1.FileLedgerStore(ledgerDir);
|
|
56
61
|
// Official grants use request ids as nonces. A new plan, or retry after an attempted
|
|
57
62
|
// application, needs a distinct request identity; revoking never erases spent history.
|
|
@@ -66,18 +71,18 @@ function applyApprovedRuntimePlan(root, subject, envApproval, check, apply) {
|
|
|
66
71
|
const now = new Date().toISOString();
|
|
67
72
|
if (envApproval && (0, risk_gate_1.approvalCovers)(envApproval, { kind: action.kind, target: root }, now))
|
|
68
73
|
return { approval: envApproval, source: 'env' };
|
|
69
|
-
const refused = new Set((0, approval_grants_1.refusedGrantReasons)(
|
|
70
|
-
const approval = (0, approval_grants_1.readGrants)(
|
|
74
|
+
const refused = new Set((0, approval_grants_1.refusedGrantReasons)(approvalRoot, action, now).map((r) => r.nonce));
|
|
75
|
+
const approval = (0, approval_grants_1.readGrants)(approvalRoot).grants.find((g) => g.subject === subject
|
|
71
76
|
&& !refused.has(g.nonce) && (0, risk_gate_1.approvalCovers)(g, action, now));
|
|
72
77
|
return approval ? { approval, source: 'grant' } : undefined;
|
|
73
78
|
};
|
|
74
79
|
const request = () => {
|
|
75
|
-
const result = (0, approval_queue_1.enqueueApprovalRequestDetailed)(
|
|
80
|
+
const result = (0, approval_queue_1.enqueueApprovalRequestDetailed)(approvalRoot, { ...action, risk: 'high',
|
|
76
81
|
why: `Review runtime-binding --dry-run for plan ${subject}; approve this exact wiring plan and retry the same command. Native trust is separate.` });
|
|
77
82
|
const id = (0, approval_queue_1.approvalRequestId)(action.kind, target);
|
|
78
83
|
if (result.reason !== 'written' && result.reason !== 'duplicate')
|
|
79
84
|
throw new Error(`Cannot queue governance-wiring approval: ${result.reason}; nothing installed`);
|
|
80
|
-
throw new Error(`governance-wiring approval required for plan ${subject}; request ${id}. In this workspace run holmes-kit approve --list, then holmes-kit approve --grant ${id} and retry the same runtime-binding command. If an old decision remains, revoke it and retry to request the current plan.`);
|
|
85
|
+
throw new Error(`governance-wiring approval required for plan ${subject}; request ${id}. In ${approvalRoot === root ? 'this workspace' : `the workspace ${approvalRoot}`} run holmes-kit approve --list, then holmes-kit approve --grant ${id} and retry the same runtime-binding command. If an old decision remains, revoke it and retry to request the current plan.`);
|
|
81
86
|
};
|
|
82
87
|
check();
|
|
83
88
|
if (!resolve())
|
|
@@ -97,6 +102,6 @@ function applyApprovedRuntimePlan(root, subject, envApproval, check, apply) {
|
|
|
97
102
|
}
|
|
98
103
|
apply();
|
|
99
104
|
if (resolved.source === 'grant' && nonce)
|
|
100
|
-
(0, approval_grants_1.consumeGrantFile)(
|
|
105
|
+
(0, approval_grants_1.consumeGrantFile)(approvalRoot, nonce);
|
|
101
106
|
});
|
|
102
107
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RuntimeHarness, RuntimeEntry } from '../runtime/binding';
|
|
1
|
+
import type { RuntimeHarness, RuntimeEntry, RuntimeSelection } from '../runtime/binding';
|
|
2
2
|
import type { Approval } from '../guardrail/risk-gate';
|
|
3
3
|
export declare const defaultRuntimeRegistry: () => string;
|
|
4
4
|
export interface RuntimeBindingOptions {
|
|
@@ -14,6 +14,8 @@ export interface RuntimeBindingOptions {
|
|
|
14
14
|
activateHooks?: string[];
|
|
15
15
|
/** @implements A-SPEC-752.10 — the digest a reviewer was shown; a plan that computes to another one is not applied. */
|
|
16
16
|
expectedPlanDigest?: string;
|
|
17
|
+
/** @implements A-SPEC-752.14 — where the operator runs remove (CLI: cwd); holds the approval of a workspace without `.ax`. */
|
|
18
|
+
approvalRoot?: string;
|
|
17
19
|
}
|
|
18
20
|
export declare function runtimeHookCommand(registryPath: string, harness: RuntimeHarness, entry: RuntimeEntry): string;
|
|
19
21
|
/**
|
|
@@ -50,7 +52,7 @@ export declare function codexDuplicateRoutes(codexHome: string, workspace: strin
|
|
|
50
52
|
export declare function runtimeBindingStatus(registryPath: string, workspace: string, opts?: {
|
|
51
53
|
codexHome?: string;
|
|
52
54
|
}): {
|
|
53
|
-
selection:
|
|
55
|
+
selection: RuntimeSelection;
|
|
54
56
|
conflicts: string[];
|
|
55
57
|
drift: {
|
|
56
58
|
path: string;
|
|
@@ -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.14, A-SPEC-752.15, A-SPEC-752.16, A-SPEC-752.17, 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"));
|
|
@@ -310,14 +310,50 @@ function runRuntimeBinding(opts) {
|
|
|
310
310
|
if (['binding.js', 'dispatch.js', 'hook-process.js', 'installation.json'].includes(path.basename(opts.registryPath))
|
|
311
311
|
|| /^(?:claude|codex|antigravity)-(?:mcp|pre-tool-use|stop|session-start)\.js$/.test(path.basename(opts.registryPath)))
|
|
312
312
|
throw new Error('Registry filename conflicts with an installed runtime file');
|
|
313
|
-
|
|
314
|
-
|
|
313
|
+
// @implements A-SPEC-752.14 — a remove may name a workspace whose directory is gone (measured: G0GnMK); its root is
|
|
314
|
+
// resolved without the directory, and the remove proceeds only for what the registry or the receipt still records.
|
|
315
|
+
const vanished = opts.operation === 'remove' && path.isAbsolute(opts.workspace) && !fs.existsSync(opts.workspace);
|
|
316
|
+
const root = vanished ? canonicalFuture(opts.workspace) : (0, binding_1.workspaceRoot)(opts.workspace);
|
|
317
|
+
if (!vanished && (0, binding_1.canonicalDirectory)(opts.workspace) !== root)
|
|
315
318
|
throw new Error('Register the workspace root, not a subdirectory');
|
|
316
319
|
const destination = canonicalFuture(opts.registryPath);
|
|
317
320
|
if (destination !== opts.registryPath || (0, binding_1.inside)(root, destination))
|
|
318
321
|
throw new Error('Operator registry must be canonical and outside the workspace');
|
|
319
322
|
const before = readOptional(opts.registryPath);
|
|
320
|
-
|
|
323
|
+
// @implements A-SPEC-752.14, A-SPEC-752.15, A-SPEC-752.16 — a vanished binding fails registry validation (its directory
|
|
324
|
+
// cannot be canonicalised), so remove sets aside the removed workspace's binding and every binding whose WORKSPACE is
|
|
325
|
+
// gone, validates the rest as before, and writes the vanished others back unchanged: it unbinds only what the operator
|
|
326
|
+
// named. The written registry obeys the schema's limits (count, no duplicate roots).
|
|
327
|
+
let vanishedBound = false;
|
|
328
|
+
let previous = null;
|
|
329
|
+
let keptVanished = [];
|
|
330
|
+
let setAside = [];
|
|
331
|
+
if (before !== null && opts.operation === 'remove') {
|
|
332
|
+
try {
|
|
333
|
+
const raw = JSON.parse(before);
|
|
334
|
+
const all = Array.isArray(raw?.bindings) ? raw.bindings : [];
|
|
335
|
+
const gone = (b) => typeof b?.workspaceRoot === 'string' && typeof b?.packageRoot === 'string'
|
|
336
|
+
&& path.isAbsolute(b.workspaceRoot) && path.isAbsolute(b.packageRoot) && !fs.existsSync(b.workspaceRoot);
|
|
337
|
+
// A-SPEC-752.17: a hand-edited spelling (`w/`, `x/../w`) of a root is the same root.
|
|
338
|
+
const resolved = (b) => typeof b?.workspaceRoot === 'string' && path.isAbsolute(b.workspaceRoot) ? path.resolve(b.workspaceRoot) : b?.workspaceRoot;
|
|
339
|
+
vanishedBound = all.some((b) => resolved(b) === root);
|
|
340
|
+
const kept = all.filter((b) => resolved(b) !== root);
|
|
341
|
+
if (kept.length > 1000)
|
|
342
|
+
throw new Error('Invalid runtime registry schema');
|
|
343
|
+
if (new Set(kept.map(resolved)).size !== kept.length)
|
|
344
|
+
throw new Error('Duplicate runtime binding');
|
|
345
|
+
setAside = kept.filter(gone);
|
|
346
|
+
// In the registry's own order: a living binding as validation spells it, a vanished one exactly as it was.
|
|
347
|
+
if (setAside.length)
|
|
348
|
+
keptVanished = kept.map((b) => gone(b) ? b : { workspaceRoot: b?.workspaceRoot, packageRoot: b?.packageRoot });
|
|
349
|
+
previous = (0, binding_1.validateRegistry)({ ...raw, bindings: Array.isArray(raw?.bindings) ? kept.filter((b) => !gone(b)) : raw?.bindings });
|
|
350
|
+
}
|
|
351
|
+
catch (e) {
|
|
352
|
+
throw new Error(`Cannot use runtime registry ${opts.registryPath}: ${e.message}. Repair runtime-binding setup.`);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
else if (before !== null)
|
|
356
|
+
previous = (0, binding_1.readRuntimeRegistry)(opts.registryPath);
|
|
321
357
|
if (opts.operation === 'setup' && (!opts.packageRoot || !opts.releasePackageRoot))
|
|
322
358
|
throw new Error('setup requires --package and --release-package');
|
|
323
359
|
if (opts.operation === 'remove' && !previous)
|
|
@@ -328,15 +364,18 @@ function runRuntimeBinding(opts) {
|
|
|
328
364
|
bindings: [...(previous?.bindings ?? []).filter((b) => b.workspaceRoot !== root), { workspaceRoot: root, packageRoot: (0, binding_1.canonicalDirectory)(opts.packageRoot) }],
|
|
329
365
|
} : { ...previous, bindings: previous.bindings.filter((b) => b.workspaceRoot !== root) };
|
|
330
366
|
(0, binding_1.validateRegistry)(next);
|
|
331
|
-
for (const binding of next.bindings) {
|
|
367
|
+
for (const binding of [...next.bindings, ...setAside]) {
|
|
332
368
|
if ((0, binding_1.inside)(binding.workspaceRoot, destination) || (0, binding_1.inside)(binding.packageRoot, destination))
|
|
333
369
|
throw new Error('Operator registry must be outside registered checkouts');
|
|
334
370
|
}
|
|
335
371
|
if ((0, binding_1.inside)(next.releasePackageRoot, destination))
|
|
336
372
|
throw new Error('Operator registry must be outside the release package');
|
|
337
373
|
const releaseBuild = (0, binding_1.verifyRuntime)(next.releasePackageRoot);
|
|
338
|
-
|
|
339
|
-
const
|
|
374
|
+
// A vanished workspace is no longer bound after the remove: it selects the release runtime, without probing the directory.
|
|
375
|
+
const selection = vanished
|
|
376
|
+
? { mode: 'release', workspaceRoot: root, packageRoot: next.releasePackageRoot, buildId: releaseBuild, specsRoot: path.join(root, '.ax', 'specs') }
|
|
377
|
+
: (0, binding_1.selectRuntime)(next, { cwd: root });
|
|
378
|
+
const after = `${JSON.stringify(keptVanished.length ? { ...next, bindings: keptVanished } : next, null, 2)}\n`;
|
|
340
379
|
const planned = new Map();
|
|
341
380
|
const conflicts = [];
|
|
342
381
|
const add = (file, content) => {
|
|
@@ -557,187 +596,191 @@ function runRuntimeBinding(opts) {
|
|
|
557
596
|
delete ours.Stop;
|
|
558
597
|
add(file, json({ ...doc, 'holmes-kit': ours }));
|
|
559
598
|
};
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
continue;
|
|
574
|
-
for (const file of globalAliases) {
|
|
575
|
-
if (normalized(key).startsWith(normalized(`${file}:`)))
|
|
576
|
-
disabledGlobalKeys.add(key.slice(file.length + 1));
|
|
577
|
-
}
|
|
599
|
+
// @implements A-SPEC-752.11 — removal plans no harness wiring: every harness entry calls the same router programs and
|
|
600
|
+
// the router reads the registry live, so dropping the binding is the whole act. Measured 2026-10-16: remove planned
|
|
601
|
+
// setup's wiring for a workspace with no Codex project files and chose to rewrite the shared, switched-off user Stop.
|
|
602
|
+
if (opts.operation === 'setup')
|
|
603
|
+
try {
|
|
604
|
+
toml(codexConfig, true);
|
|
605
|
+
toml(path.join(root, '.codex/config.toml'), false);
|
|
606
|
+
const userNativeState = (0, codex_toml_1.parseCodexConfig)(readOptional(codexConfig) ?? '');
|
|
607
|
+
const normalized = (s) => process.platform === 'win32' ? s.toLowerCase() : s;
|
|
608
|
+
const globalAliases = new Set([codexHooks]);
|
|
609
|
+
if (fs.existsSync(codexHooks)) {
|
|
610
|
+
globalAliases.add(fs.realpathSync(codexHooks));
|
|
611
|
+
globalAliases.add(fs.realpathSync.native(codexHooks));
|
|
578
612
|
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
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);
|
|
598
|
-
}
|
|
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]))
|
|
613
|
+
if (userNativeState.ok)
|
|
614
|
+
for (const [key, state] of Object.entries(userNativeState.doc.hooks?.state ?? {})) {
|
|
615
|
+
if (!object(state) || state.enabled !== false)
|
|
623
616
|
continue;
|
|
624
|
-
|
|
625
|
-
if (
|
|
626
|
-
|
|
627
|
-
|
|
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
|
-
}));
|
|
617
|
+
for (const file of globalAliases) {
|
|
618
|
+
if (normalized(key).startsWith(normalized(`${file}:`)))
|
|
619
|
+
disabledGlobalKeys.add(key.slice(file.length + 1));
|
|
620
|
+
}
|
|
633
621
|
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
paths.add(fs.realpathSync(hookFile));
|
|
665
|
-
paths.add(fs.realpathSync.native(hookFile));
|
|
622
|
+
const codexFiles = [codexHooks, path.join(root, '.codex/hooks.json')];
|
|
623
|
+
const codexDocs = codexFiles.map((f) => document(readOptional(f), f));
|
|
624
|
+
// @implements A-SPEC-752.9 — Codex keys a hook's enable state by position (<file>:<event>:<group>:<hook>). Measured
|
|
625
|
+
// 2026-10-05: the plan removed two Holmes groups from the user file and wrote one at index 0, whose key said
|
|
626
|
+
// `enabled = false`; the gate was written and never ran. A gate the plan writes is looked up by its own key.
|
|
627
|
+
const planCodex = (forced) => {
|
|
628
|
+
codexProjectEvents.clear();
|
|
629
|
+
const events = codexFiles.map(() => new Set());
|
|
630
|
+
for (const event of ['PreToolUse', 'Stop']) {
|
|
631
|
+
const existing = codexDocs.findIndex((d, source) => Array.isArray(d.hooks?.[event])
|
|
632
|
+
&& d.hooks[event].some((g, group) => Array.isArray(g?.hooks)
|
|
633
|
+
&& g.hooks.some((h, hook) => owns(h?.command) && !disabledGlobalCodex(codexFiles[source], event, group, hook))));
|
|
634
|
+
// Explicit development activation adds missing lifecycles only to this project.
|
|
635
|
+
// Filling an empty user lifecycle would also activate every consumer workspace.
|
|
636
|
+
const empty = codexDocs.findIndex((d) => Array.isArray(d.hooks?.[event]) && d.hooks[event].length === 0);
|
|
637
|
+
const owner = forced.has(event) ? 1 : existing >= 0 ? existing : activate.has('codex') ? 1 : empty >= 0 ? empty : 0;
|
|
638
|
+
events[owner].add(event);
|
|
639
|
+
if (owner === 1)
|
|
640
|
+
codexProjectEvents.add(event);
|
|
641
|
+
}
|
|
642
|
+
codexFiles.forEach((f, i) => native(f, 'codex', events[i]));
|
|
643
|
+
return events;
|
|
644
|
+
};
|
|
645
|
+
const switchedOffKeys = [];
|
|
646
|
+
for (const configFile of [codexConfig, path.join(root, '.codex/config.toml')]) {
|
|
647
|
+
const configState = (0, codex_toml_1.parseCodexConfig)(readOptional(configFile) ?? '');
|
|
648
|
+
if (configState.ok)
|
|
649
|
+
for (const [key, state] of Object.entries(configState.doc.hooks?.state ?? {}))
|
|
650
|
+
if (object(state) && state.enabled === false)
|
|
651
|
+
switchedOffKeys.push(key);
|
|
666
652
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
653
|
+
const gatesSwitchedOff = (events) => {
|
|
654
|
+
const found = [];
|
|
655
|
+
codexFiles.forEach((file, source) => {
|
|
656
|
+
const doc = document(planned.get(file)?.after ?? readOptional(file), file);
|
|
657
|
+
// An entry that already stood there, switched off, is not something this plan writes: doctor reports it.
|
|
658
|
+
const standing = document(readOptional(file), file);
|
|
659
|
+
const aliases = new Set([file]);
|
|
660
|
+
if (fs.existsSync(file)) {
|
|
661
|
+
aliases.add(fs.realpathSync(file));
|
|
662
|
+
aliases.add(fs.realpathSync.native(file));
|
|
663
|
+
}
|
|
671
664
|
for (const [event, keyEvent, entry] of [['PreToolUse', 'pre_tool_use', 'pre-tool-use'], ['Stop', 'stop', 'stop']]) {
|
|
672
|
-
|
|
673
|
-
if (!norm(key).startsWith(norm(prefix)))
|
|
665
|
+
if (!events[source].has(event) || !Array.isArray(doc.hooks?.[event]))
|
|
674
666
|
continue;
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
667
|
+
doc.hooks[event].forEach((g, i) => (Array.isArray(g?.hooks) ? g.hooks : []).forEach((h, j) => {
|
|
668
|
+
if (h?.command !== command('codex', entry))
|
|
669
|
+
return;
|
|
670
|
+
if (JSON.stringify(standing.hooks?.[event]?.[i]?.hooks?.[j]) === JSON.stringify(h))
|
|
671
|
+
return;
|
|
672
|
+
const key = switchedOffKeys.find((k) => [...aliases].some((alias) => normalized(k) === normalized(`${alias}:${keyEvent}:${i}:${j}`)));
|
|
673
|
+
if (key !== undefined)
|
|
674
|
+
found.push({ source, event, key });
|
|
675
|
+
}));
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
return found;
|
|
679
|
+
};
|
|
680
|
+
let codexEvents = planCodex(new Set());
|
|
681
|
+
// Explicit activation may use the project file; nothing else may choose another place on its own.
|
|
682
|
+
const toProject = new Set(gatesSwitchedOff(codexEvents).filter((g) => g.source === 0 && activate.has('codex')).map((g) => g.event));
|
|
683
|
+
if (toProject.size > 0)
|
|
684
|
+
codexEvents = planCodex(toProject);
|
|
685
|
+
for (const gate of gatesSwitchedOff(codexEvents)) {
|
|
686
|
+
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; `
|
|
687
|
+
+ (gate.source === 0 && !activate.has('codex')
|
|
688
|
+
? "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"
|
|
689
|
+
: 'switch that hook on in Codex (/hooks) and preview again'));
|
|
690
|
+
}
|
|
691
|
+
// Native disabled state is indexed by source/group/hook. Keeping its bytes while moving
|
|
692
|
+
// the disabled gate would silently enable it. Refuse that migration, never mint trust.
|
|
693
|
+
// Keep each layer's disabled keys: a project enable override does not change
|
|
694
|
+
// the user-level disabled state consumed by other workspaces.
|
|
695
|
+
const nativeStates = [];
|
|
696
|
+
for (const configFile of [codexConfig, path.join(root, '.codex/config.toml')]) {
|
|
697
|
+
const configState = (0, codex_toml_1.parseCodexConfig)(readOptional(configFile) ?? '');
|
|
698
|
+
if (configState.ok)
|
|
699
|
+
nativeStates.push(...Object.entries(configState.doc.hooks?.state ?? {}));
|
|
700
|
+
}
|
|
701
|
+
for (const hookFile of codexFiles) {
|
|
702
|
+
const oldHooks = document(readOptional(hookFile), hookFile);
|
|
703
|
+
const newHooks = document(planned.get(hookFile)?.after ?? readOptional(hookFile), hookFile);
|
|
704
|
+
const norm = (s) => process.platform === 'win32' ? s.toLowerCase() : s;
|
|
705
|
+
const paths = new Set([hookFile]);
|
|
706
|
+
if (fs.existsSync(hookFile)) {
|
|
707
|
+
paths.add(fs.realpathSync(hookFile));
|
|
708
|
+
paths.add(fs.realpathSync.native(hookFile));
|
|
709
|
+
}
|
|
710
|
+
for (const [key, state] of nativeStates) {
|
|
711
|
+
if (!object(state) || state.enabled !== false)
|
|
712
|
+
continue;
|
|
713
|
+
for (const file of paths)
|
|
714
|
+
for (const [event, keyEvent, entry] of [['PreToolUse', 'pre_tool_use', 'pre-tool-use'], ['Stop', 'stop', 'stop']]) {
|
|
715
|
+
const prefix = `${file}:${keyEvent}:`;
|
|
716
|
+
if (!norm(key).startsWith(norm(prefix)))
|
|
717
|
+
continue;
|
|
718
|
+
const indices = key.slice(prefix.length).match(/^(\d+):(\d+)$/);
|
|
719
|
+
if (!indices)
|
|
720
|
+
continue;
|
|
721
|
+
const i = Number(indices[1]);
|
|
722
|
+
const j = Number(indices[2]);
|
|
723
|
+
const old = oldHooks.hooks?.[event]?.[i]?.hooks?.[j];
|
|
724
|
+
const replacement = newHooks.hooks?.[event]?.[i]?.hooks?.[j];
|
|
725
|
+
if (old && JSON.stringify(replacement) !== JSON.stringify(old)
|
|
726
|
+
&& !(owns(old.command) && replacement?.command === command('codex', entry))) {
|
|
727
|
+
throw new Error('A disabled Codex hook would move to a different native state key; review the hook layout before migration');
|
|
728
|
+
}
|
|
685
729
|
}
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
native(path.join(root, agents_1.CODEX_PLUGIN_DIR, 'hooks.json'), 'codex', false);
|
|
733
|
+
// @implements A-SPEC-751.6 — after the Codex lifecycles are planned, so the entry joins the planned document.
|
|
734
|
+
codexFiles.forEach((f) => routeSessionStart(f, codexSessionStartCommand));
|
|
735
|
+
if (activate.has('codex'))
|
|
736
|
+
addCodexSessionStart(codexFiles[1]);
|
|
737
|
+
const claudeFiles = [path.join(home, '.claude/settings.json'), path.join(root, '.claude/settings.local.json'), path.join(root, '.claude/settings.json')];
|
|
738
|
+
const claudeDocs = claudeFiles.map((f) => document(readOptional(f), f));
|
|
739
|
+
const claudeEvents = claudeFiles.map(() => new Set());
|
|
740
|
+
for (const event of ['PreToolUse', 'Stop']) {
|
|
741
|
+
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))));
|
|
742
|
+
const empty = claudeDocs.findIndex((d) => Array.isArray(d.hooks?.[event]) && d.hooks[event].length === 0);
|
|
743
|
+
// Keep an existing owner; otherwise honor an explicit empty source before creating a lifecycle.
|
|
744
|
+
claudeEvents[existing >= 0 ? existing : activate.has('claude') ? 1 : empty >= 0 ? empty : 1].add(event);
|
|
745
|
+
}
|
|
746
|
+
claudeFiles.forEach((f, i) => native(f, 'claude', claudeEvents[i]));
|
|
747
|
+
claudeFiles.forEach((f) => routeSessionStart(f));
|
|
748
|
+
mcp(path.join(root, '.mcp.json'), 'claude');
|
|
749
|
+
mcp(path.join(root, '.agents/mcp_config.json'), 'antigravity');
|
|
750
|
+
const agyUser = (0, agents_1.agyUserHooksPath)(home);
|
|
751
|
+
const agyFiles = [agyUser, path.join(root, '.agents/hooks.json')];
|
|
752
|
+
const agyDocs = agyFiles.map((f) => document(readOptional(f), f)['holmes-kit']);
|
|
753
|
+
const agyEvents = agyFiles.map(() => new Set());
|
|
754
|
+
for (const event of ['PreToolUse', 'Stop']) {
|
|
755
|
+
const existing = agyDocs.findIndex((d, i) => object(d) && Array.isArray(d[event]) && d[event].length > 0
|
|
756
|
+
&& !(activate.has('antigravity') && i === 0 && d.enabled === false));
|
|
757
|
+
const empty = agyDocs.findIndex((d) => object(d) && Array.isArray(d[event]) && d[event].length === 0);
|
|
758
|
+
agyEvents[existing >= 0 ? existing : activate.has('antigravity') ? 1 : empty >= 0 ? empty : 1].add(event);
|
|
759
|
+
}
|
|
760
|
+
agyFiles.forEach((f, i) => agy(f, agyEvents[i]));
|
|
761
|
+
// Installed plugin snapshots are independently loaded. Never imply changing the checkout copy suppresses them.
|
|
762
|
+
const plugins = path.join(path.dirname(codexConfig), 'plugins');
|
|
763
|
+
const cache = path.join(plugins, 'cache');
|
|
764
|
+
if (fs.existsSync(cache)) {
|
|
765
|
+
const vendors = fs.readdirSync(cache, { withFileTypes: true }).filter((d) => d.isDirectory() && /holmes/i.test(d.name));
|
|
766
|
+
const visit = (at, depth) => {
|
|
767
|
+
if (depth > 3)
|
|
768
|
+
return;
|
|
769
|
+
for (const d of fs.readdirSync(at, { withFileTypes: true })) {
|
|
770
|
+
const f = path.join(at, d.name);
|
|
771
|
+
if (d.isDirectory())
|
|
772
|
+
visit(f, depth + 1);
|
|
773
|
+
else if (d.isFile() && d.name === 'hooks.json' && /pre-tool-use|holmes-hook|holmes-stop/.test((0, binding_1.readBounded)(f)))
|
|
774
|
+
conflicts.push(`Cached Holmes hook source needs native plugin activation review: ${f}`);
|
|
686
775
|
}
|
|
776
|
+
};
|
|
777
|
+
for (const vendor of vendors)
|
|
778
|
+
visit(path.join(cache, vendor.name), 0);
|
|
687
779
|
}
|
|
688
780
|
}
|
|
689
|
-
|
|
690
|
-
|
|
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);
|
|
716
|
-
}
|
|
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);
|
|
781
|
+
catch (e) {
|
|
782
|
+
conflicts.push(e.message);
|
|
736
783
|
}
|
|
737
|
-
}
|
|
738
|
-
catch (e) {
|
|
739
|
-
conflicts.push(e.message);
|
|
740
|
-
}
|
|
741
784
|
add(destination, after);
|
|
742
785
|
const manifestPath = path.join(dir, 'installation.json');
|
|
743
786
|
const receipt = readOptional(manifestPath);
|
|
@@ -772,9 +815,27 @@ function runRuntimeBinding(opts) {
|
|
|
772
815
|
// file leaves the receipt — and with it the plan — as it was.
|
|
773
816
|
for (const c of planned.values())
|
|
774
817
|
recorded.set(c.path, { path: c.path, digest: digest(wiringViewOf(c.path, c.after)) });
|
|
775
|
-
//
|
|
776
|
-
|
|
777
|
-
|
|
818
|
+
// @implements A-SPEC-752.11 — the receipt forgets a removed workspace: its rows and its identity.
|
|
819
|
+
if (opts.operation === 'remove') {
|
|
820
|
+
// A-SPEC-752.17: a row owned by a binding nested inside the root is that binding's, not the root's.
|
|
821
|
+
const keptInside = [...next.bindings, ...setAside].filter((b) => (0, binding_1.inside)(root, path.resolve(b.workspaceRoot)));
|
|
822
|
+
if (vanished && !vanishedBound && runtimeIdentities[root] === undefined
|
|
823
|
+
&& ![...recorded.keys()].some((p) => (0, binding_1.inside)(root, p) && !keptInside.some((b) => (0, binding_1.inside)(path.resolve(b.workspaceRoot), p))))
|
|
824
|
+
throw new Error(`Nothing registered for ${root}; nothing written`);
|
|
825
|
+
// @implements A-SPEC-752.12, A-SPEC-752.13 — a row inside a workspace that stays bound AND is nested inside the
|
|
826
|
+
// removed root is that workspace's; a remaining parent of the removed root does not keep the removed root's rows.
|
|
827
|
+
for (const p of [...recorded.keys()]) {
|
|
828
|
+
// A-SPEC-752.16: a set-aside binding stays in the written registry, so it stays bound here too.
|
|
829
|
+
if ((0, binding_1.inside)(root, p) && ![...next.bindings, ...setAside].some((b) => (0, binding_1.inside)(root, b.workspaceRoot) && (0, binding_1.inside)(b.workspaceRoot, p)))
|
|
830
|
+
recorded.delete(p);
|
|
831
|
+
}
|
|
832
|
+
delete runtimeIdentities[root];
|
|
833
|
+
}
|
|
834
|
+
else {
|
|
835
|
+
// Same-path builds still need a new reviewed plan. Legacy receipts gain identity only via apply.
|
|
836
|
+
runtimeIdentities[root] = { packageRoot: selection.packageRoot, buildId: selection.buildId,
|
|
837
|
+
releasePackageRoot: next.releasePackageRoot, releaseBuild };
|
|
838
|
+
}
|
|
778
839
|
add(manifestPath, json({ version: 1, files: [...recorded.values()], runtimeIdentities }));
|
|
779
840
|
const changes = [...planned.values()].filter((c) => c.before !== c.after);
|
|
780
841
|
const planDigest = (0, runtime_binding_approval_1.runtimePlanDigest)({ operation: opts.operation, root, selection, releasePackageRoot: next.releasePackageRoot,
|
|
@@ -796,6 +857,21 @@ function runRuntimeBinding(opts) {
|
|
|
796
857
|
throw new Error('Runtime build changed since preview');
|
|
797
858
|
};
|
|
798
859
|
check();
|
|
860
|
+
// @implements A-SPEC-752.14 — a workspace without `.ax` has no approval queue or ledger: its remove is approved in the
|
|
861
|
+
// governed workspace the operator runs it from (measured: pilot64's emptied H0 refused with "no-project").
|
|
862
|
+
let approvalRoot = root;
|
|
863
|
+
if (opts.operation === 'remove' && !fs.existsSync(path.join(root, '.ax'))) {
|
|
864
|
+
let governed = null;
|
|
865
|
+
try {
|
|
866
|
+
const at = opts.approvalRoot === undefined ? null : (0, binding_1.workspaceRoot)(opts.approvalRoot);
|
|
867
|
+
if (at !== null && at !== root && fs.existsSync(path.join(at, '.ax')))
|
|
868
|
+
governed = at;
|
|
869
|
+
}
|
|
870
|
+
catch { /* an unresolvable approval root is no governed workspace */ }
|
|
871
|
+
if (governed === null)
|
|
872
|
+
throw new Error(`${root} is no longer a governed project (no .ax); run runtime-binding remove from a governed workspace — its approval queue takes the request; nothing written`);
|
|
873
|
+
approvalRoot = governed;
|
|
874
|
+
}
|
|
799
875
|
if (changes.length > 0)
|
|
800
876
|
(0, runtime_binding_approval_1.applyApprovedRuntimePlan)(root, planDigest, opts.approval, check, () => {
|
|
801
877
|
let written = 0;
|
|
@@ -822,7 +898,7 @@ function runRuntimeBinding(opts) {
|
|
|
822
898
|
catch (e) {
|
|
823
899
|
throw new Error(`Runtime setup incomplete after ${written} file(s): ${e.message}; run status and preview setup again`);
|
|
824
900
|
}
|
|
825
|
-
});
|
|
901
|
+
}, approvalRoot);
|
|
826
902
|
}
|
|
827
903
|
// @implements A-SPEC-752.7 — outside the plan digest: what git tracks is not part of the reviewed wiring plan.
|
|
828
904
|
const trackedChanges = trackedWorkspacePaths(root, changes.map((c) => c.path));
|
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.
|
|
4
|
+
"version": "0.35.23",
|
|
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",
|