@holmes-lab/holmes-kit 0.35.0 → 0.35.2
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 +108 -0
- package/README.md +7 -0
- package/dist/.build-id +1 -1
- package/dist/holmes/cli/approve.js +9 -2
- package/dist/holmes/cli/codex-oracle.js +36 -2
- package/dist/holmes/cli/doctor.d.ts +14 -1
- package/dist/holmes/cli/doctor.js +355 -72
- package/dist/holmes/cli/index.d.ts +1 -1
- package/dist/holmes/cli/index.js +38 -5
- package/dist/holmes/cli/init.d.ts +2 -0
- package/dist/holmes/cli/init.js +37 -1
- package/dist/holmes/cli/runtime-binding-approval.d.ts +7 -0
- package/dist/holmes/cli/runtime-binding-approval.js +102 -0
- package/dist/holmes/cli/runtime-binding.d.ts +45 -0
- package/dist/holmes/cli/runtime-binding.js +630 -0
- package/dist/holmes/governance/approval-grants.d.ts +7 -0
- package/dist/holmes/governance/approval-grants.js +8 -2
- package/dist/holmes/governance/approval-queue.d.ts +2 -0
- package/dist/holmes/governance/approval-queue.js +11 -4
- package/dist/holmes/governance/autonomy.d.ts +9 -0
- package/dist/holmes/governance/autonomy.js +65 -13
- package/dist/holmes/guardrail/risk-classifier.js +76 -26
- package/dist/holmes/guardrail/shell-argument-roles.d.ts +15 -0
- package/dist/holmes/guardrail/shell-argument-roles.js +209 -0
- package/dist/holmes/guardrail/shell-syntax.d.ts +20 -0
- package/dist/holmes/guardrail/shell-syntax.js +489 -0
- package/dist/holmes/guardrail/shell-words.d.ts +2 -18
- package/dist/holmes/guardrail/shell-words.js +15 -441
- package/dist/holmes/guardrail/write-target.d.ts +54 -0
- package/dist/holmes/guardrail/write-target.js +327 -1
- package/dist/holmes/guardrail/write-verb-word.d.ts +13 -0
- package/dist/holmes/guardrail/write-verb-word.js +55 -0
- package/dist/holmes/hooks/pre-tool-use.d.ts +14 -0
- package/dist/holmes/hooks/pre-tool-use.js +391 -66
- package/dist/holmes/mcp/handlers/spec-approval.js +14 -2
- package/dist/holmes/mcp/handlers.d.ts +9 -1
- package/dist/holmes/mcp/handlers.js +6 -4
- package/dist/holmes/mcp/harness-attestation.d.ts +10 -1
- package/dist/holmes/mcp/harness-attestation.js +70 -3
- package/dist/holmes/mcp/operator-recovery.d.ts +9 -0
- package/dist/holmes/mcp/operator-recovery.js +66 -0
- package/dist/holmes/mcp/server.js +6 -3
- package/dist/holmes/runtime/binding.d.ts +30 -0
- package/dist/holmes/runtime/binding.js +164 -0
- package/dist/holmes/runtime/dispatch.d.ts +9 -0
- package/dist/holmes/runtime/dispatch.js +169 -0
- package/dist/holmes/runtime/hook-process.d.ts +11 -0
- package/dist/holmes/runtime/hook-process.js +130 -0
- package/docs/install-guide.md +65 -0
- package/package.json +1 -1
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.defaultRuntimeRegistry = void 0;
|
|
37
|
+
exports.runtimeHookCommand = runtimeHookCommand;
|
|
38
|
+
exports.wiringViewOf = wiringViewOf;
|
|
39
|
+
exports.registryWiringOwnership = registryWiringOwnership;
|
|
40
|
+
exports.registryOwnedWiring = registryOwnedWiring;
|
|
41
|
+
exports.runtimeBindingStatus = runtimeBindingStatus;
|
|
42
|
+
exports.runRuntimeBinding = runRuntimeBinding;
|
|
43
|
+
exports.trackedWorkspacePaths = trackedWorkspacePaths;
|
|
44
|
+
// @implements A-SPEC-751, A-SPEC-752, A-SPEC-752.7, A-SPEC-752.8
|
|
45
|
+
const fs = __importStar(require("node:fs"));
|
|
46
|
+
const os = __importStar(require("node:os"));
|
|
47
|
+
const path = __importStar(require("node:path"));
|
|
48
|
+
const node_crypto_1 = require("node:crypto");
|
|
49
|
+
const bounded_io_1 = require("../project/bounded-io");
|
|
50
|
+
const smol_toml_1 = require("smol-toml");
|
|
51
|
+
const binding_1 = require("../runtime/binding");
|
|
52
|
+
const runtime_binding_approval_1 = require("./runtime-binding-approval");
|
|
53
|
+
const codex_toml_1 = require("./codex-toml");
|
|
54
|
+
const codex_hooks_1 = require("./codex-hooks");
|
|
55
|
+
const agents_1 = require("./agents");
|
|
56
|
+
const defaultRuntimeRegistry = () => path.join(os.homedir(), '.holmes', 'runtime', 'bindings.json');
|
|
57
|
+
exports.defaultRuntimeRegistry = defaultRuntimeRegistry;
|
|
58
|
+
const digest = (s) => (0, node_crypto_1.createHash)('sha256').update(s).digest('hex');
|
|
59
|
+
const object = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
60
|
+
const json = (v) => `${JSON.stringify(v, null, 2)}\n`;
|
|
61
|
+
function readOptional(file) {
|
|
62
|
+
try {
|
|
63
|
+
return (0, binding_1.readBounded)(file);
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
if (e.code === 'ENOENT')
|
|
67
|
+
return null;
|
|
68
|
+
throw e;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function document(raw, file) {
|
|
72
|
+
const parsed = raw === null ? {} : JSON.parse(raw);
|
|
73
|
+
if (!object(parsed))
|
|
74
|
+
throw new Error(`Invalid configuration object: ${file}`);
|
|
75
|
+
return parsed;
|
|
76
|
+
}
|
|
77
|
+
function canonicalFuture(file) {
|
|
78
|
+
let at = path.resolve(file);
|
|
79
|
+
const suffix = [];
|
|
80
|
+
while (!fs.existsSync(at)) {
|
|
81
|
+
suffix.unshift(path.basename(at));
|
|
82
|
+
const parent = path.dirname(at);
|
|
83
|
+
if (parent === at)
|
|
84
|
+
throw new Error(`Cannot resolve destination ${file}`);
|
|
85
|
+
at = parent;
|
|
86
|
+
}
|
|
87
|
+
return path.join(fs.realpathSync.native(at), ...suffix);
|
|
88
|
+
}
|
|
89
|
+
function quote(word) {
|
|
90
|
+
if (process.platform === 'win32') {
|
|
91
|
+
if (/["%\r\n!]/.test(word))
|
|
92
|
+
throw new Error('Hook path cannot be represented safely by this Windows shell');
|
|
93
|
+
return `"${word}"`;
|
|
94
|
+
}
|
|
95
|
+
return `'${word.replace(/'/g, `'\\''`)}'`;
|
|
96
|
+
}
|
|
97
|
+
function runtimeHookCommand(registryPath, harness, entry) {
|
|
98
|
+
const file = path.join(path.dirname(registryPath), `${harness}-${entry}.js`);
|
|
99
|
+
if (harness !== 'antigravity')
|
|
100
|
+
return `${quote(process.execPath)} ${quote(file)}`;
|
|
101
|
+
const node = (0, agents_1.shortPathIfSpaced)(process.execPath);
|
|
102
|
+
const script = (0, agents_1.shortPathIfSpaced)(file);
|
|
103
|
+
if (/\s/.test(node) || /\s/.test(script))
|
|
104
|
+
throw new Error('Antigravity needs a no-space operator destination (or a resolvable Windows short path)');
|
|
105
|
+
if (![node, script].every((s) => agents_1.AGY_LITERAL_PATH.test(s.replace(/\\/g, '/'))))
|
|
106
|
+
throw new Error('Antigravity needs shell-safe literal Node and operator paths');
|
|
107
|
+
return `${node.replace(/\\/g, '/')} ${script.replace(/\\/g, '/')}`;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* @implements A-SPEC-752.5 — what the receipt records about a file. Claude Code rewrites its own settings file (measured
|
|
111
|
+
* 2026-10-04: a model switch), so a whole-byte digest called an unrelated edit changed wiring and gave a reviewed plan
|
|
112
|
+
* another digest. For that file the receipt is about a view of the document; every other file is recorded whole.
|
|
113
|
+
* A list of keys to keep missed ones that switch Holmes off, so the view names what it drops (A-SPEC-752.6).
|
|
114
|
+
*/
|
|
115
|
+
function wiringViewOf(file, content) {
|
|
116
|
+
const name = path.basename(file);
|
|
117
|
+
if ((name !== 'settings.json' && name !== 'settings.local.json') || path.basename(path.dirname(file)) !== '.claude')
|
|
118
|
+
return content;
|
|
119
|
+
let doc;
|
|
120
|
+
try {
|
|
121
|
+
doc = JSON.parse(content);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return content;
|
|
125
|
+
}
|
|
126
|
+
if (!object(doc))
|
|
127
|
+
return content;
|
|
128
|
+
// @implements A-SPEC-752.6 — everything but `model`, the one key measured to change with no wiring change.
|
|
129
|
+
const { model: _model, ...rest } = doc;
|
|
130
|
+
return JSON.stringify(rest);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* @implements A-SPEC-752.8 — whether the installation receipt beside the operator registry lists `file`, and whether the
|
|
134
|
+
* file still matches it. Measured 2026-10-04: init rewrote the user-level Codex files a setup plan had written, because
|
|
135
|
+
* nothing outside this module read the receipt. No registry, no receipt, or a receipt that cannot be read owns nothing.
|
|
136
|
+
*/
|
|
137
|
+
function registryWiringOwnership(file, registryPath = (0, exports.defaultRuntimeRegistry)()) {
|
|
138
|
+
const none = { owned: false, matches: false };
|
|
139
|
+
try {
|
|
140
|
+
const manifest = readOptional(path.join(path.dirname(registryPath), 'installation.json'));
|
|
141
|
+
if (manifest === null)
|
|
142
|
+
return none;
|
|
143
|
+
const rows = JSON.parse(manifest).files;
|
|
144
|
+
if (!Array.isArray(rows))
|
|
145
|
+
return none;
|
|
146
|
+
const wanted = canonicalFuture(file);
|
|
147
|
+
for (const row of rows) {
|
|
148
|
+
if (!object(row) || typeof row.path !== 'string' || typeof row.digest !== 'string')
|
|
149
|
+
return none;
|
|
150
|
+
if (row.path !== wanted && row.path !== file)
|
|
151
|
+
continue;
|
|
152
|
+
const current = readOptional(row.path);
|
|
153
|
+
return { owned: true, matches: current !== null && (digest(wiringViewOf(row.path, current)) === row.digest || digest(current) === row.digest) };
|
|
154
|
+
}
|
|
155
|
+
return none;
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return none;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function registryOwnedWiring(file, registryPath) {
|
|
162
|
+
return registryWiringOwnership(file, registryPath).owned;
|
|
163
|
+
}
|
|
164
|
+
function runtimeBindingStatus(registryPath, workspace) {
|
|
165
|
+
const selection = (0, binding_1.selectRuntime)((0, binding_1.readRuntimeRegistry)(registryPath), { cwd: workspace });
|
|
166
|
+
const manifest = readOptional(path.join(path.dirname(registryPath), 'installation.json'));
|
|
167
|
+
const conflicts = [];
|
|
168
|
+
if (manifest === null)
|
|
169
|
+
conflicts.push('No installation receipt; registry selection alone does not establish wiring');
|
|
170
|
+
else {
|
|
171
|
+
const rows = document(manifest, 'installation.json').files;
|
|
172
|
+
if (!Array.isArray(rows))
|
|
173
|
+
throw new Error('Invalid runtime installation receipt');
|
|
174
|
+
for (const row of rows) {
|
|
175
|
+
if (!object(row) || typeof row.path !== 'string' || typeof row.digest !== 'string')
|
|
176
|
+
throw new Error('Invalid installation file record');
|
|
177
|
+
const current = readOptional(row.path);
|
|
178
|
+
// A-SPEC-752.5: the view's digest, or the whole file's for a row written before the view existed.
|
|
179
|
+
if (current === null || (digest(wiringViewOf(row.path, current)) !== row.digest && digest(current) !== row.digest))
|
|
180
|
+
conflicts.push(`Wiring changed or incomplete: ${row.path}`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return { selection, conflicts, activation: 'unverified' };
|
|
184
|
+
}
|
|
185
|
+
function runRuntimeBinding(opts) {
|
|
186
|
+
if (opts.activateHooks !== undefined && (!Array.isArray(opts.activateHooks)
|
|
187
|
+
|| opts.activateHooks.some((h) => !['claude', 'codex', 'antigravity'].includes(h))
|
|
188
|
+
|| opts.operation !== 'setup'))
|
|
189
|
+
throw new Error('Hook activation requires setup and supported harness selectors');
|
|
190
|
+
const activate = new Set(opts.activateHooks ?? []);
|
|
191
|
+
if (opts.operation === 'status')
|
|
192
|
+
return runtimeBindingStatus(opts.registryPath, opts.workspace);
|
|
193
|
+
if (opts.operation !== 'setup' && opts.operation !== 'remove')
|
|
194
|
+
throw new Error('runtime-binding expects setup, status or remove');
|
|
195
|
+
if (!path.isAbsolute(opts.registryPath))
|
|
196
|
+
throw new Error('Registry path must be absolute');
|
|
197
|
+
if (['binding.js', 'dispatch.js', 'hook-process.js', 'installation.json'].includes(path.basename(opts.registryPath))
|
|
198
|
+
|| /^(?:claude|codex|antigravity)-(?:mcp|pre-tool-use|stop)\.js$/.test(path.basename(opts.registryPath)))
|
|
199
|
+
throw new Error('Registry filename conflicts with an installed runtime file');
|
|
200
|
+
const root = (0, binding_1.workspaceRoot)(opts.workspace);
|
|
201
|
+
if ((0, binding_1.canonicalDirectory)(opts.workspace) !== root)
|
|
202
|
+
throw new Error('Register the workspace root, not a subdirectory');
|
|
203
|
+
const destination = canonicalFuture(opts.registryPath);
|
|
204
|
+
if (destination !== opts.registryPath || (0, binding_1.inside)(root, destination))
|
|
205
|
+
throw new Error('Operator registry must be canonical and outside the workspace');
|
|
206
|
+
const before = readOptional(opts.registryPath);
|
|
207
|
+
const previous = before === null ? null : (0, binding_1.readRuntimeRegistry)(opts.registryPath);
|
|
208
|
+
if (opts.operation === 'setup' && (!opts.packageRoot || !opts.releasePackageRoot))
|
|
209
|
+
throw new Error('setup requires --package and --release-package');
|
|
210
|
+
if (opts.operation === 'remove' && !previous)
|
|
211
|
+
throw new Error('No runtime registry to remove from');
|
|
212
|
+
const next = opts.operation === 'setup' ? {
|
|
213
|
+
version: 1,
|
|
214
|
+
releasePackageRoot: (0, binding_1.canonicalDirectory)(opts.releasePackageRoot),
|
|
215
|
+
bindings: [...(previous?.bindings ?? []).filter((b) => b.workspaceRoot !== root), { workspaceRoot: root, packageRoot: (0, binding_1.canonicalDirectory)(opts.packageRoot) }],
|
|
216
|
+
} : { ...previous, bindings: previous.bindings.filter((b) => b.workspaceRoot !== root) };
|
|
217
|
+
(0, binding_1.validateRegistry)(next);
|
|
218
|
+
for (const binding of next.bindings) {
|
|
219
|
+
if ((0, binding_1.inside)(binding.workspaceRoot, destination) || (0, binding_1.inside)(binding.packageRoot, destination))
|
|
220
|
+
throw new Error('Operator registry must be outside registered checkouts');
|
|
221
|
+
}
|
|
222
|
+
if ((0, binding_1.inside)(next.releasePackageRoot, destination))
|
|
223
|
+
throw new Error('Operator registry must be outside the release package');
|
|
224
|
+
const releaseBuild = (0, binding_1.verifyRuntime)(next.releasePackageRoot);
|
|
225
|
+
const selection = (0, binding_1.selectRuntime)(next, { cwd: root });
|
|
226
|
+
const after = `${JSON.stringify(next, null, 2)}\n`;
|
|
227
|
+
const planned = new Map();
|
|
228
|
+
const conflicts = [];
|
|
229
|
+
const add = (file, content) => {
|
|
230
|
+
if (canonicalFuture(file) !== path.resolve(file))
|
|
231
|
+
throw new Error(`Configuration symlink conflict: ${file}`);
|
|
232
|
+
const old = readOptional(file);
|
|
233
|
+
planned.set(file, { path: file, before: old, after: content });
|
|
234
|
+
};
|
|
235
|
+
const dir = path.dirname(destination);
|
|
236
|
+
const installer = opts.installerPackageRoot ?? path.resolve(__dirname, '../../..');
|
|
237
|
+
for (const name of ['binding', 'dispatch', 'hook-process']) {
|
|
238
|
+
const source = path.join(installer, 'dist/holmes/runtime', `${name}.js`);
|
|
239
|
+
add(path.join(dir, `${name}.js`), (0, binding_1.readBounded)(source));
|
|
240
|
+
}
|
|
241
|
+
const wrappers = new Map();
|
|
242
|
+
for (const harness of ['claude', 'codex', 'antigravity']) {
|
|
243
|
+
for (const entry of ['mcp', 'pre-tool-use', 'stop']) {
|
|
244
|
+
const file = path.join(dir, `${harness}-${entry}.js`);
|
|
245
|
+
add(file, `// @implements A-SPEC-751\nrequire('./dispatch.js').runDispatch(${JSON.stringify({ registryPath: destination, harness, entry })});\n`);
|
|
246
|
+
wrappers.set(`${harness}:${entry}`, file);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const command = (harness, entry) => runtimeHookCommand(destination, harness, entry);
|
|
250
|
+
const owns = (cmd) => {
|
|
251
|
+
if (typeof cmd !== 'string')
|
|
252
|
+
return false;
|
|
253
|
+
if ((0, codex_hooks_1.holmesKernelScript)(cmd))
|
|
254
|
+
return true;
|
|
255
|
+
if ([...wrappers.keys()].some((key) => { const [h, e] = key.split(':'); return cmd === command(h, e); }))
|
|
256
|
+
return true;
|
|
257
|
+
if (/holmes|pre-tool-use\.js|stop\.js/i.test(cmd))
|
|
258
|
+
throw new Error(`Unknown Holmes wrapper requires explicit migration: ${cmd}`);
|
|
259
|
+
return false;
|
|
260
|
+
};
|
|
261
|
+
const native = (file, harness, primary) => {
|
|
262
|
+
const hasPrimary = typeof primary === 'boolean' ? primary : primary.size > 0;
|
|
263
|
+
const raw = readOptional(file);
|
|
264
|
+
if (raw === null && !hasPrimary)
|
|
265
|
+
return;
|
|
266
|
+
const doc = document(raw, file);
|
|
267
|
+
if (doc.hooks !== undefined && !object(doc.hooks))
|
|
268
|
+
throw new Error(`Invalid hooks configuration: ${file}`);
|
|
269
|
+
const hooks = { ...(doc.hooks ?? {}) };
|
|
270
|
+
for (const event of ['PreToolUse', 'Stop']) {
|
|
271
|
+
if (hooks[event] !== undefined && !Array.isArray(hooks[event]))
|
|
272
|
+
throw new Error(`Invalid hook groups: ${file}`);
|
|
273
|
+
const groups = [];
|
|
274
|
+
for (const [groupIndex, g] of (hooks[event] ?? []).entries()) {
|
|
275
|
+
// Older project plugin generators wrote Stop as a flat command list. Migrate only
|
|
276
|
+
// that known legacy source; the active user hooks retain the native grouped schema.
|
|
277
|
+
if (file === path.join(root, agents_1.CODEX_PLUGIN_DIR, 'hooks.json') && !hasPrimary && event === 'Stop'
|
|
278
|
+
&& object(g) && g.type === 'command' && typeof g.command === 'string' && g.hooks === undefined) {
|
|
279
|
+
if (!owns(g.command))
|
|
280
|
+
groups.push(g);
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
if (!object(g) || !Array.isArray(g.hooks))
|
|
284
|
+
throw new Error(`Invalid hook group: ${file}`);
|
|
285
|
+
const keep = g.hooks.filter((h, hookIndex) => {
|
|
286
|
+
if (!object(h))
|
|
287
|
+
throw new Error(`Invalid hook entry: ${file}`);
|
|
288
|
+
return !owns(h.command) || (harness === 'codex' && codexProjectEvents.has(event)
|
|
289
|
+
&& disabledGlobalCodex(file, event, groupIndex, hookIndex));
|
|
290
|
+
});
|
|
291
|
+
if (keep.length)
|
|
292
|
+
groups.push({ ...g, hooks: keep });
|
|
293
|
+
}
|
|
294
|
+
const explicitlyEmpty = Array.isArray(hooks[event]) && hooks[event].length === 0;
|
|
295
|
+
if ((!explicitlyEmpty || activate.has(harness)) && (typeof primary === 'boolean' ? primary : primary.has(event)))
|
|
296
|
+
groups.push({ ...(event === 'PreToolUse' ? { matcher: '.*' } : {}), hooks: [{ type: 'command', command: command(harness, event === 'PreToolUse' ? 'pre-tool-use' : 'stop'), timeout: 30 }] });
|
|
297
|
+
if (groups.length || hooks[event] !== undefined)
|
|
298
|
+
hooks[event] = groups;
|
|
299
|
+
}
|
|
300
|
+
add(file, json({ ...doc, hooks }));
|
|
301
|
+
};
|
|
302
|
+
const mcp = (file, harness) => {
|
|
303
|
+
const doc = document(readOptional(file), file);
|
|
304
|
+
if (doc.mcpServers !== undefined && !object(doc.mcpServers))
|
|
305
|
+
throw new Error(`Invalid MCP configuration: ${file}`);
|
|
306
|
+
const servers = doc.mcpServers ?? {};
|
|
307
|
+
const old = servers['holmes-kit'] ?? {};
|
|
308
|
+
if (!object(old) || (old.env !== undefined && !object(old.env)))
|
|
309
|
+
throw new Error(`Invalid Holmes MCP entry: ${file}`);
|
|
310
|
+
assertMcpOwner(old, file);
|
|
311
|
+
const env = { ...(old.env ?? {}) };
|
|
312
|
+
delete env.HOLMES_SPECS;
|
|
313
|
+
add(file, json({ ...doc, mcpServers: { ...servers, 'holmes-kit': { ...old, command: process.execPath, args: [wrappers.get(`${harness}:mcp`)], env } } }));
|
|
314
|
+
};
|
|
315
|
+
const home = opts.home ?? os.homedir();
|
|
316
|
+
function assertMcpOwner(old, file) {
|
|
317
|
+
if (Object.keys(old).length === 0)
|
|
318
|
+
return;
|
|
319
|
+
const node = typeof old.command === 'string' && /(?:^|[/\\])node(?:\.exe)?$/.test(old.command);
|
|
320
|
+
const args = old.args;
|
|
321
|
+
const direct = Array.isArray(args) && args.length === 1 && typeof args[0] === 'string'
|
|
322
|
+
&& (/(?:^|[/\\])bin[/\\]holmes-mcp\.js$/.test(args[0]) || [...wrappers.values()].includes(args[0]));
|
|
323
|
+
const pinned = old.command === 'npx' && Array.isArray(args) && args.length === 4 && args[0] === '-y' && args[1] === '-p'
|
|
324
|
+
&& typeof args[2] === 'string' && /^@holmes-lab\/holmes-kit@[^\s]+$/.test(args[2]) && args[3] === 'holmes-mcp';
|
|
325
|
+
if (!(node && direct) && !pinned)
|
|
326
|
+
throw new Error(`Unknown MCP wrapper requires explicit migration: ${file}`);
|
|
327
|
+
}
|
|
328
|
+
const codexConfig = opts.home ? path.join(home, '.codex/config.toml') : (0, codex_toml_1.defaultCodexConfigPath)();
|
|
329
|
+
const codexHooks = opts.home ? path.join(home, '.codex/hooks.json') : (0, codex_hooks_1.defaultCodexHooksPath)();
|
|
330
|
+
const disabledGlobalKeys = new Set();
|
|
331
|
+
const codexProjectEvents = new Set();
|
|
332
|
+
const disabledGlobalCodex = (file, event, group, hook) => file === codexHooks
|
|
333
|
+
&& disabledGlobalKeys.has(`${event === 'PreToolUse' ? 'pre_tool_use' : 'stop'}:${group}:${hook}`);
|
|
334
|
+
const toml = (file, primary) => {
|
|
335
|
+
const raw = readOptional(file);
|
|
336
|
+
if (raw === null && !primary)
|
|
337
|
+
return;
|
|
338
|
+
const parsed = (0, codex_toml_1.parseCodexConfig)(raw ?? '');
|
|
339
|
+
if (!parsed.ok)
|
|
340
|
+
throw new Error(`Invalid configuration ${file}: ${parsed.reason}`);
|
|
341
|
+
const old = parsed.doc.mcp_servers?.['holmes-kit'];
|
|
342
|
+
if (old === undefined && !primary)
|
|
343
|
+
return;
|
|
344
|
+
if (old !== undefined && !object(old))
|
|
345
|
+
throw new Error(`Invalid Holmes MCP entry: ${file}`);
|
|
346
|
+
if (old?.env !== undefined && !object(old.env))
|
|
347
|
+
throw new Error(`Invalid MCP environment: ${file}`);
|
|
348
|
+
assertMcpOwner(old ?? {}, file);
|
|
349
|
+
const env = { ...(old?.env ?? {}) };
|
|
350
|
+
delete env.HOLMES_SPECS;
|
|
351
|
+
const block = (0, smol_toml_1.stringify)({ mcp_servers: { 'holmes-kit': { ...old, command: process.execPath, args: [wrappers.get('codex:mcp')], env } } });
|
|
352
|
+
const merged = (0, codex_toml_1.mergeCodexToml)(raw, block);
|
|
353
|
+
if (!(0, codex_toml_1.parseCodexConfig)(merged).ok)
|
|
354
|
+
throw new Error(`Cannot safely merge configuration ${file}`);
|
|
355
|
+
add(file, merged);
|
|
356
|
+
};
|
|
357
|
+
const agy = (file, primary) => {
|
|
358
|
+
const raw = readOptional(file);
|
|
359
|
+
if (raw === null && !primary.size)
|
|
360
|
+
return;
|
|
361
|
+
const doc = document(raw, file);
|
|
362
|
+
const old = doc['holmes-kit'];
|
|
363
|
+
if (old === undefined && !primary.size)
|
|
364
|
+
return;
|
|
365
|
+
if (old !== undefined && !object(old))
|
|
366
|
+
throw new Error(`Invalid Antigravity configuration: ${file}`);
|
|
367
|
+
for (const event of ['PreToolUse', 'Stop']) {
|
|
368
|
+
if (old?.[event] === undefined)
|
|
369
|
+
continue;
|
|
370
|
+
if (!Array.isArray(old[event]))
|
|
371
|
+
throw new Error(`Invalid Antigravity hook list: ${file}`);
|
|
372
|
+
for (const group of old[event]) {
|
|
373
|
+
if (!object(group))
|
|
374
|
+
throw new Error(`Invalid Antigravity hook: ${file}`);
|
|
375
|
+
const entries = event === 'PreToolUse' ? group.hooks : [group];
|
|
376
|
+
if (!Array.isArray(entries))
|
|
377
|
+
throw new Error(`Invalid Antigravity hook group: ${file}`);
|
|
378
|
+
for (const h of entries) {
|
|
379
|
+
const cmd = h?.command;
|
|
380
|
+
const direct = typeof cmd === 'string' && /^(?:node|[^\s]+[/\\]node(?:\.exe)?) [^\s]+[/\\]bin[/\\]holmes-(?:hook|stop)-antigravity\.js$/.test(cmd);
|
|
381
|
+
if (!direct && cmd !== command('antigravity', event === 'PreToolUse' ? 'pre-tool-use' : 'stop'))
|
|
382
|
+
throw new Error(`Unknown Antigravity wrapper requires explicit migration: ${file}`);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
// Preserve the native enable switch and fields other than our lifecycle entries.
|
|
387
|
+
const ours = { ...old };
|
|
388
|
+
if (activate.has('antigravity') && primary.size)
|
|
389
|
+
ours.enabled = true;
|
|
390
|
+
if (primary.has('PreToolUse')) {
|
|
391
|
+
ours.PreToolUse = !activate.has('antigravity') && Array.isArray(old?.PreToolUse) && old.PreToolUse.length === 0 ? [] : [{ matcher: '*', hooks: [{ command: command('antigravity', 'pre-tool-use') }] }];
|
|
392
|
+
}
|
|
393
|
+
else if (!(Array.isArray(old?.PreToolUse) && old.PreToolUse.length === 0))
|
|
394
|
+
delete ours.PreToolUse;
|
|
395
|
+
if (primary.has('Stop'))
|
|
396
|
+
ours.Stop = !activate.has('antigravity') && Array.isArray(old?.Stop) && old.Stop.length === 0 ? [] : [{ command: command('antigravity', 'stop') }];
|
|
397
|
+
else if (!(Array.isArray(old?.Stop) && old.Stop.length === 0))
|
|
398
|
+
delete ours.Stop;
|
|
399
|
+
add(file, json({ ...doc, 'holmes-kit': ours }));
|
|
400
|
+
};
|
|
401
|
+
try {
|
|
402
|
+
toml(codexConfig, true);
|
|
403
|
+
toml(path.join(root, '.codex/config.toml'), false);
|
|
404
|
+
const userNativeState = (0, codex_toml_1.parseCodexConfig)(readOptional(codexConfig) ?? '');
|
|
405
|
+
const normalized = (s) => process.platform === 'win32' ? s.toLowerCase() : s;
|
|
406
|
+
const globalAliases = new Set([codexHooks]);
|
|
407
|
+
if (fs.existsSync(codexHooks)) {
|
|
408
|
+
globalAliases.add(fs.realpathSync(codexHooks));
|
|
409
|
+
globalAliases.add(fs.realpathSync.native(codexHooks));
|
|
410
|
+
}
|
|
411
|
+
if (userNativeState.ok)
|
|
412
|
+
for (const [key, state] of Object.entries(userNativeState.doc.hooks?.state ?? {})) {
|
|
413
|
+
if (!object(state) || state.enabled !== false)
|
|
414
|
+
continue;
|
|
415
|
+
for (const file of globalAliases) {
|
|
416
|
+
if (normalized(key).startsWith(normalized(`${file}:`)))
|
|
417
|
+
disabledGlobalKeys.add(key.slice(file.length + 1));
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
const codexFiles = [codexHooks, path.join(root, '.codex/hooks.json')];
|
|
421
|
+
const codexDocs = codexFiles.map((f) => document(readOptional(f), f));
|
|
422
|
+
const codexEvents = codexFiles.map(() => new Set());
|
|
423
|
+
for (const event of ['PreToolUse', 'Stop']) {
|
|
424
|
+
const existing = codexDocs.findIndex((d, source) => Array.isArray(d.hooks?.[event])
|
|
425
|
+
&& d.hooks[event].some((g, group) => Array.isArray(g?.hooks)
|
|
426
|
+
&& g.hooks.some((h, hook) => owns(h?.command) && !disabledGlobalCodex(codexFiles[source], event, group, hook))));
|
|
427
|
+
// Explicit development activation adds missing lifecycles only to this project.
|
|
428
|
+
// Filling an empty user lifecycle would also activate every consumer workspace.
|
|
429
|
+
const empty = codexDocs.findIndex((d) => Array.isArray(d.hooks?.[event]) && d.hooks[event].length === 0);
|
|
430
|
+
const owner = existing >= 0 ? existing : activate.has('codex') ? 1 : empty >= 0 ? empty : 0;
|
|
431
|
+
codexEvents[owner].add(event);
|
|
432
|
+
if (owner === 1)
|
|
433
|
+
codexProjectEvents.add(event);
|
|
434
|
+
}
|
|
435
|
+
codexFiles.forEach((f, i) => native(f, 'codex', codexEvents[i]));
|
|
436
|
+
// Native disabled state is indexed by source/group/hook. Keeping its bytes while moving
|
|
437
|
+
// the disabled gate would silently enable it. Refuse that migration, never mint trust.
|
|
438
|
+
// Keep each layer's disabled keys: a project enable override does not change
|
|
439
|
+
// the user-level disabled state consumed by other workspaces.
|
|
440
|
+
const nativeStates = [];
|
|
441
|
+
for (const configFile of [codexConfig, path.join(root, '.codex/config.toml')]) {
|
|
442
|
+
const configState = (0, codex_toml_1.parseCodexConfig)(readOptional(configFile) ?? '');
|
|
443
|
+
if (configState.ok)
|
|
444
|
+
nativeStates.push(...Object.entries(configState.doc.hooks?.state ?? {}));
|
|
445
|
+
}
|
|
446
|
+
for (const hookFile of codexFiles) {
|
|
447
|
+
const oldHooks = document(readOptional(hookFile), hookFile);
|
|
448
|
+
const newHooks = document(planned.get(hookFile)?.after ?? readOptional(hookFile), hookFile);
|
|
449
|
+
const norm = (s) => process.platform === 'win32' ? s.toLowerCase() : s;
|
|
450
|
+
const paths = new Set([hookFile]);
|
|
451
|
+
if (fs.existsSync(hookFile)) {
|
|
452
|
+
paths.add(fs.realpathSync(hookFile));
|
|
453
|
+
paths.add(fs.realpathSync.native(hookFile));
|
|
454
|
+
}
|
|
455
|
+
for (const [key, state] of nativeStates) {
|
|
456
|
+
if (!object(state) || state.enabled !== false)
|
|
457
|
+
continue;
|
|
458
|
+
for (const file of paths)
|
|
459
|
+
for (const [event, keyEvent, entry] of [['PreToolUse', 'pre_tool_use', 'pre-tool-use'], ['Stop', 'stop', 'stop']]) {
|
|
460
|
+
const prefix = `${file}:${keyEvent}:`;
|
|
461
|
+
if (!norm(key).startsWith(norm(prefix)))
|
|
462
|
+
continue;
|
|
463
|
+
const indices = key.slice(prefix.length).match(/^(\d+):(\d+)$/);
|
|
464
|
+
if (!indices)
|
|
465
|
+
continue;
|
|
466
|
+
const i = Number(indices[1]);
|
|
467
|
+
const j = Number(indices[2]);
|
|
468
|
+
const old = oldHooks.hooks?.[event]?.[i]?.hooks?.[j];
|
|
469
|
+
const replacement = newHooks.hooks?.[event]?.[i]?.hooks?.[j];
|
|
470
|
+
if (old && JSON.stringify(replacement) !== JSON.stringify(old)
|
|
471
|
+
&& !(owns(old.command) && replacement?.command === command('codex', entry))) {
|
|
472
|
+
throw new Error('A disabled Codex hook would move to a different native state key; review the hook layout before migration');
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
native(path.join(root, agents_1.CODEX_PLUGIN_DIR, 'hooks.json'), 'codex', false);
|
|
478
|
+
const claudeFiles = [path.join(home, '.claude/settings.json'), path.join(root, '.claude/settings.local.json'), path.join(root, '.claude/settings.json')];
|
|
479
|
+
const claudeDocs = claudeFiles.map((f) => document(readOptional(f), f));
|
|
480
|
+
const claudeEvents = claudeFiles.map(() => new Set());
|
|
481
|
+
for (const event of ['PreToolUse', 'Stop']) {
|
|
482
|
+
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))));
|
|
483
|
+
const empty = claudeDocs.findIndex((d) => Array.isArray(d.hooks?.[event]) && d.hooks[event].length === 0);
|
|
484
|
+
// Keep an existing owner; otherwise honor an explicit empty source before creating a lifecycle.
|
|
485
|
+
claudeEvents[existing >= 0 ? existing : activate.has('claude') ? 1 : empty >= 0 ? empty : 1].add(event);
|
|
486
|
+
}
|
|
487
|
+
claudeFiles.forEach((f, i) => native(f, 'claude', claudeEvents[i]));
|
|
488
|
+
mcp(path.join(root, '.mcp.json'), 'claude');
|
|
489
|
+
mcp(path.join(root, '.agents/mcp_config.json'), 'antigravity');
|
|
490
|
+
const agyUser = (0, agents_1.agyUserHooksPath)(home);
|
|
491
|
+
const agyFiles = [agyUser, path.join(root, '.agents/hooks.json')];
|
|
492
|
+
const agyDocs = agyFiles.map((f) => document(readOptional(f), f)['holmes-kit']);
|
|
493
|
+
const agyEvents = agyFiles.map(() => new Set());
|
|
494
|
+
for (const event of ['PreToolUse', 'Stop']) {
|
|
495
|
+
const existing = agyDocs.findIndex((d, i) => object(d) && Array.isArray(d[event]) && d[event].length > 0
|
|
496
|
+
&& !(activate.has('antigravity') && i === 0 && d.enabled === false));
|
|
497
|
+
const empty = agyDocs.findIndex((d) => object(d) && Array.isArray(d[event]) && d[event].length === 0);
|
|
498
|
+
agyEvents[existing >= 0 ? existing : activate.has('antigravity') ? 1 : empty >= 0 ? empty : 1].add(event);
|
|
499
|
+
}
|
|
500
|
+
agyFiles.forEach((f, i) => agy(f, agyEvents[i]));
|
|
501
|
+
// Installed plugin snapshots are independently loaded. Never imply changing the checkout copy suppresses them.
|
|
502
|
+
const plugins = path.join(path.dirname(codexConfig), 'plugins');
|
|
503
|
+
const cache = path.join(plugins, 'cache');
|
|
504
|
+
if (fs.existsSync(cache)) {
|
|
505
|
+
const vendors = fs.readdirSync(cache, { withFileTypes: true }).filter((d) => d.isDirectory() && /holmes/i.test(d.name));
|
|
506
|
+
const visit = (at, depth) => {
|
|
507
|
+
if (depth > 3)
|
|
508
|
+
return;
|
|
509
|
+
for (const d of fs.readdirSync(at, { withFileTypes: true })) {
|
|
510
|
+
const f = path.join(at, d.name);
|
|
511
|
+
if (d.isDirectory())
|
|
512
|
+
visit(f, depth + 1);
|
|
513
|
+
else if (d.isFile() && d.name === 'hooks.json' && /pre-tool-use|holmes-hook|holmes-stop/.test((0, binding_1.readBounded)(f)))
|
|
514
|
+
conflicts.push(`Cached Holmes hook source needs native plugin activation review: ${f}`);
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
for (const vendor of vendors)
|
|
518
|
+
visit(path.join(cache, vendor.name), 0);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
catch (e) {
|
|
522
|
+
conflicts.push(e.message);
|
|
523
|
+
}
|
|
524
|
+
add(destination, after);
|
|
525
|
+
const manifestPath = path.join(dir, 'installation.json');
|
|
526
|
+
const receipt = readOptional(manifestPath);
|
|
527
|
+
const recorded = new Map();
|
|
528
|
+
const runtimeIdentities = {};
|
|
529
|
+
if (receipt !== null) {
|
|
530
|
+
const previousReceipt = document(receipt, manifestPath);
|
|
531
|
+
const rows = previousReceipt.files;
|
|
532
|
+
if (!Array.isArray(rows))
|
|
533
|
+
throw new Error('Invalid runtime installation receipt');
|
|
534
|
+
for (const row of rows) {
|
|
535
|
+
if (!object(row) || typeof row.path !== 'string' || !path.isAbsolute(row.path) || typeof row.digest !== 'string')
|
|
536
|
+
throw new Error('Invalid installation file record');
|
|
537
|
+
// A shared registry retains the wiring of every previously installed workspace.
|
|
538
|
+
recorded.set(row.path, { path: row.path, digest: row.digest });
|
|
539
|
+
}
|
|
540
|
+
if (previousReceipt.runtimeIdentities !== undefined) {
|
|
541
|
+
if (!object(previousReceipt.runtimeIdentities))
|
|
542
|
+
throw new Error('Invalid runtime identity receipt');
|
|
543
|
+
for (const [workspace, identity] of Object.entries(previousReceipt.runtimeIdentities)) {
|
|
544
|
+
if (!path.isAbsolute(workspace) || !object(identity)
|
|
545
|
+
|| typeof identity.packageRoot !== 'string' || !path.isAbsolute(identity.packageRoot)
|
|
546
|
+
|| typeof identity.releasePackageRoot !== 'string' || !path.isAbsolute(identity.releasePackageRoot)
|
|
547
|
+
|| typeof identity.buildId !== 'string' || !identity.buildId.trim()
|
|
548
|
+
|| typeof identity.releaseBuild !== 'string' || !identity.releaseBuild.trim())
|
|
549
|
+
throw new Error('Invalid runtime identity receipt');
|
|
550
|
+
runtimeIdentities[workspace] = identity;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
// A-SPEC-752.5: a row records the wiring view of the planned content, so an unrelated rewrite of a Claude settings
|
|
555
|
+
// file leaves the receipt — and with it the plan — as it was.
|
|
556
|
+
for (const c of planned.values())
|
|
557
|
+
recorded.set(c.path, { path: c.path, digest: digest(wiringViewOf(c.path, c.after)) });
|
|
558
|
+
// Same-path builds still need a new reviewed plan. Legacy receipts gain identity only via apply.
|
|
559
|
+
runtimeIdentities[root] = { packageRoot: selection.packageRoot, buildId: selection.buildId,
|
|
560
|
+
releasePackageRoot: next.releasePackageRoot, releaseBuild };
|
|
561
|
+
add(manifestPath, json({ version: 1, files: [...recorded.values()], runtimeIdentities }));
|
|
562
|
+
const changes = [...planned.values()].filter((c) => c.before !== c.after);
|
|
563
|
+
const planDigest = (0, runtime_binding_approval_1.runtimePlanDigest)({ operation: opts.operation, root, selection, releasePackageRoot: next.releasePackageRoot,
|
|
564
|
+
releaseBuild, activateHooks: [...activate].sort() }, changes);
|
|
565
|
+
if (!opts.dryRun) {
|
|
566
|
+
if (conflicts.length)
|
|
567
|
+
throw new Error(`Runtime configuration conflicts; nothing written: ${conflicts.join('; ')}`);
|
|
568
|
+
// Check the entire reviewed snapshot before the first write, then again at each atomic replacement.
|
|
569
|
+
const check = () => {
|
|
570
|
+
for (const c of planned.values())
|
|
571
|
+
if (canonicalFuture(c.path) !== c.path || readOptional(c.path) !== c.before)
|
|
572
|
+
throw new Error(`Configuration changed since preview: ${c.path}`);
|
|
573
|
+
if ((0, binding_1.verifyRuntime)(selection.packageRoot) !== selection.buildId || (0, binding_1.verifyRuntime)(next.releasePackageRoot) !== releaseBuild)
|
|
574
|
+
throw new Error('Runtime build changed since preview');
|
|
575
|
+
};
|
|
576
|
+
check();
|
|
577
|
+
if (changes.length > 0)
|
|
578
|
+
(0, runtime_binding_approval_1.applyApprovedRuntimePlan)(root, planDigest, opts.approval, check, () => {
|
|
579
|
+
let written = 0;
|
|
580
|
+
try {
|
|
581
|
+
for (const c of changes) {
|
|
582
|
+
if (canonicalFuture(c.path) !== c.path || readOptional(c.path) !== c.before)
|
|
583
|
+
throw new Error(`Configuration changed during setup: ${c.path}`);
|
|
584
|
+
fs.mkdirSync(path.dirname(c.path), { recursive: true, mode: 0o700 });
|
|
585
|
+
const tmp = `${c.path}.${(0, node_crypto_1.randomUUID)()}.tmp`;
|
|
586
|
+
try {
|
|
587
|
+
const mode = c.before === null ? 0o600 : fs.statSync(c.path).mode & 0o777;
|
|
588
|
+
fs.writeFileSync(tmp, c.after, { flag: 'wx', mode });
|
|
589
|
+
fs.renameSync(tmp, c.path);
|
|
590
|
+
written++;
|
|
591
|
+
}
|
|
592
|
+
finally {
|
|
593
|
+
try {
|
|
594
|
+
fs.unlinkSync(tmp);
|
|
595
|
+
}
|
|
596
|
+
catch { /* renamed or never created */ }
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
catch (e) {
|
|
601
|
+
throw new Error(`Runtime setup incomplete after ${written} file(s): ${e.message}; run status and preview setup again`);
|
|
602
|
+
}
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
// @implements A-SPEC-752.7 — outside the plan digest: what git tracks is not part of the reviewed wiring plan.
|
|
606
|
+
const trackedChanges = trackedWorkspacePaths(root, changes.map((c) => c.path));
|
|
607
|
+
return { dryRun: opts.dryRun, changes, conflicts, selection, planDigest, activation: 'unverified', trackedChanges,
|
|
608
|
+
...(trackedChanges.length ? { trackedAdvice: `${trackedChanges.length} changed file(s) are tracked by git and now hold this machine's paths; do not commit them — keep them local with: git update-index --skip-worktree ${trackedChanges.join(' ')} (a release check otherwise sees a dirty tree)` } : {}) };
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* @implements A-SPEC-752.7 — which of `files` lie inside `root` and are tracked by git, relative to `root` and sorted.
|
|
612
|
+
* Measured 2026-10-04: setup rewrote committed wiring files with machine paths and the release check was the first to
|
|
613
|
+
* say so. No work tree, no git, a timeout or a failure all read as "none": this report never fails for it.
|
|
614
|
+
*/
|
|
615
|
+
function trackedWorkspacePaths(root, files, env = process.env) {
|
|
616
|
+
const rel = files.filter((f) => (0, binding_1.inside)(root, f) && f !== root).map((f) => path.relative(root, f));
|
|
617
|
+
if (rel.length === 0)
|
|
618
|
+
return [];
|
|
619
|
+
try {
|
|
620
|
+
// The shared bounded child (A-SPEC-734): a timeout, a large buffer, and the blocked-root memory.
|
|
621
|
+
const r = (0, bounded_io_1.gitOnce)(root, ['-C', root, 'ls-files', '-z', '--', ...rel], 'worktree', { env });
|
|
622
|
+
if (r.error || r.status !== 0 || typeof r.stdout !== 'string')
|
|
623
|
+
return [];
|
|
624
|
+
const wanted = new Set(rel.map((p) => p.split(path.sep).join('/')));
|
|
625
|
+
return r.stdout.split('\0').filter((p) => wanted.has(p)).sort();
|
|
626
|
+
}
|
|
627
|
+
catch {
|
|
628
|
+
return [];
|
|
629
|
+
}
|
|
630
|
+
}
|
|
@@ -43,7 +43,14 @@ export type BoundGrant = Approval & {
|
|
|
43
43
|
workspace?: string;
|
|
44
44
|
subject?: string;
|
|
45
45
|
requestedBy?: string;
|
|
46
|
+
lifetime?: 'until-used';
|
|
46
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* @implements A-SPEC-532.5 — the `expires` a subject-bound grant carries: it keeps the field every grant must have
|
|
50
|
+
* (a grant is narrow: scope, expires, nonce) and the comparison every consumer already makes, while the grant's
|
|
51
|
+
* `lifetime: 'until-used'` says in words that no time limit was meant.
|
|
52
|
+
*/
|
|
53
|
+
export declare const GRANT_NO_EXPIRY = "9999-12-31T23:59:59.999Z";
|
|
47
54
|
export type BindingRefusal = 'foreign-workspace' | 'stale-subject';
|
|
48
55
|
/** @implements A-SPEC-649 — the grants that WOULD cover this action but are refused by their binding, by name. */
|
|
49
56
|
export declare function refusedGrantReasons(root: string, action: {
|