@indigoai-us/hq-cli 5.345.267 → 5.345.268
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 +16 -0
- package/contracts/host-canary-release.json +7 -7
- package/dist/commands/core-job-notify-native.d.ts +6 -0
- package/dist/commands/core-job-notify-native.js +64 -4
- package/dist/commands/core-jobs-native.js +3 -16
- package/dist/commands/install-global.js +54 -17
- package/dist/lib/daemon/machine-check-owner.js +1 -1
- package/dist/lib/daemon/machine-checks.d.ts +3 -11
- package/dist/lib/daemon/machine-checks.js +4 -15
- package/dist/lib/doctor/checks/codex-wiring.d.ts +4 -2
- package/dist/lib/doctor/checks/codex-wiring.js +70 -13
- package/dist/lib/doctor/checks/fleet-hook-core.d.ts +4 -4
- package/dist/lib/doctor/checks/fleet-hook-core.js +5 -10
- package/dist/lib/doctor/checks/grok-wiring.js +38 -0
- package/dist/lib/doctor/checks/hook-engine.js +0 -2
- package/dist/lib/doctor/checks/host-core.d.ts +1 -1
- package/dist/lib/doctor/checks/host-core.js +8 -38
- package/dist/lib/hook-engine/coverage.d.ts +10 -1
- package/dist/lib/hook-engine/coverage.js +63 -8
- package/dist/lib/hook-engine/fleet-registration.js +7 -4
- package/dist/lib/hook-engine/native-precompact-compatibility.json +7 -1
- package/dist/lib/hook-engine/native-stop-compatibility.json +30 -11
- package/dist/lib/hook-engine/reconcile.d.ts +10 -1
- package/dist/lib/hook-engine/reconcile.js +339 -42
- package/dist/lib/hook-engine/stable-gate.d.ts +43 -0
- package/dist/lib/hook-engine/stable-gate.js +276 -0
- package/dist/lib/hot-channels/fleet-complete.js +2 -2
- package/dist/lib/install/antigravity-targets.js +2 -1
- package/dist/lib/install/claude-targets.d.ts +6 -6
- package/dist/lib/install/claude-targets.js +13 -9
- package/dist/lib/install/codex-targets.d.ts +4 -4
- package/dist/lib/install/codex-targets.js +26 -16
- package/dist/lib/install/hook-target.d.ts +23 -2
- package/dist/lib/install/hook-target.js +89 -16
- package/dist/lib/outpost-identity-env.d.ts +18 -0
- package/dist/lib/outpost-identity-env.js +29 -0
- package/dist/lib/signals/steps/extract.js +46 -12
- package/dist/utils/core-next-kill.d.ts +2 -15
- package/dist/utils/core-next-kill.js +5 -36
- package/dist/utils/hook-engine-rollup.js +0 -1
- package/dist/utils/hook-trust.d.ts +2 -0
- package/dist/utils/hook-trust.js +156 -13
- package/dist/utils/host-registration.d.ts +158 -4
- package/dist/utils/host-registration.js +500 -17
- package/package.json +7 -7
|
@@ -1,16 +1,44 @@
|
|
|
1
|
-
import { existsSync, lstatSync, readFileSync } from 'node:fs';
|
|
1
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { writeConfigAtomic, jsonFormat } from '../../commands/mcp-registration.js';
|
|
3
|
-
import { join } from 'node:path';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
|
-
import { addHqHooks, removeHqHooks, shimPath } from '../install/claude-targets.js';
|
|
5
|
+
import { addHqHooks, isHqHookEntry, removeHqHooks, shimPath } from '../install/claude-targets.js';
|
|
6
6
|
import { legacyHookTarget } from '../install/hook-target.js';
|
|
7
|
-
import { addCodexHooks, removeCodexHooks, codexHookEntry, codexHookTrustKeys } from '../install/codex-targets.js';
|
|
7
|
+
import { addCodexHooks, isAdapterEntry, removeCodexHooks, codexHookEntry, codexHookTrustKeys } from '../install/codex-targets.js';
|
|
8
8
|
import { ANTIGRAVITY_HOOK_EVENTS, ANTIGRAVITY_HOOK_NAME, antigravityTargets, buildAntigravityHqHookSpec, detectAntigravity, removeAntigravityHqHooks, } from '../install/antigravity-targets.js';
|
|
9
|
-
import {
|
|
9
|
+
import { isCoreNextEntry, isNativeEntry } from './registration.js';
|
|
10
10
|
import { userHookSettingsFile } from './registration-identity.js';
|
|
11
|
-
import { coreNextArgs, coreNextCommand, coreNextTargetOrWarn, placeEvent } from '../../utils/host-registration.js';
|
|
12
|
-
import { claudeProjectTarget, forHost, stopCompatibilityHold } from './coverage.js';
|
|
13
|
-
|
|
11
|
+
import { coreNextArgs, coreNextCommand, coreNextCommandWindows, coreNextOffReason, coreNextTargetOrWarn, getCoreNextCandidate, isPortableNativeEntry, isShippedPortableClaudeCommand, placeEvent, portableNativeCommandForPlatform, replaceFileNoFollow, resolvePortableEngineForNativeOnly, shippedPortableClaudeCommand, STABLE_LINK_NAME, } from '../../utils/host-registration.js';
|
|
12
|
+
import { claudeProjectTarget, forHost, isNativeOnlyCoreRoot, stopCompatibilityHold } from './coverage.js';
|
|
13
|
+
import { detectMachineHookHosts, evaluateStableCommit } from './stable-gate.js';
|
|
14
|
+
import { HQ_CLI_NPM_REPAIR_COMMAND } from '../../utils/npm-install-flags.js';
|
|
15
|
+
/** Every Claude Code project event that shipped a master-hook.sh entry in `.claude/settings.json`. */
|
|
16
|
+
export const PROJECT_CLAUDE_HOOK_EVENTS = [
|
|
17
|
+
'PreToolUse',
|
|
18
|
+
'PostToolUse',
|
|
19
|
+
'PreCompact',
|
|
20
|
+
'Stop',
|
|
21
|
+
'SessionStart',
|
|
22
|
+
'UserPromptSubmit',
|
|
23
|
+
'Notification',
|
|
24
|
+
'SubagentStart',
|
|
25
|
+
'SubagentStop',
|
|
26
|
+
'SessionEnd',
|
|
27
|
+
];
|
|
28
|
+
/** Every Codex project event that shipped a `[[hooks.<Event>]]` block in `.codex/config.toml`. */
|
|
29
|
+
export const PROJECT_CODEX_HOOK_EVENTS = [
|
|
30
|
+
{ event: 'SessionStart', matcher: 'startup|resume|clear|compact', timeout: 30, statusMessage: 'Loading HQ context' },
|
|
31
|
+
{ event: 'UserPromptSubmit', timeout: 30, statusMessage: 'Routing HQ prompt' },
|
|
32
|
+
{ event: 'PreToolUse', matcher: '.*', timeout: 30, statusMessage: 'Checking HQ safety rails' },
|
|
33
|
+
{ event: 'PostToolUse', matcher: '.*', timeout: 30, statusMessage: 'Running HQ post-tool hooks' },
|
|
34
|
+
{ event: 'Stop', timeout: 30, statusMessage: 'Wrapping HQ session state' },
|
|
35
|
+
{ event: 'PreCompact', timeout: 30, statusMessage: 'Running HQ pre-compact hooks' },
|
|
36
|
+
{ event: 'SessionEnd', timeout: 3, statusMessage: 'Running HQ session-end hooks' },
|
|
37
|
+
{ event: 'SubagentStop', timeout: 30, statusMessage: 'Running HQ subagent-stop hooks' },
|
|
38
|
+
];
|
|
39
|
+
const CODEX_NATIVE_BEGIN = '# BEGIN HQ NATIVE HOOKS (managed by `hq reindex`)';
|
|
40
|
+
const CODEX_NATIVE_END = '# END HQ NATIVE HOOKS';
|
|
41
|
+
/** The project master-hook command shipped in pre-US-027 HQ's .claude/settings.json. */
|
|
14
42
|
function projectClaudeCommand(event) {
|
|
15
43
|
return 'env BASH_ENV=/dev/null bash "$CLAUDE_PROJECT_DIR/.claude/hooks/master-hook.sh" ' + event;
|
|
16
44
|
}
|
|
@@ -122,27 +150,140 @@ function writeMerged(file, home, merge) {
|
|
|
122
150
|
return written;
|
|
123
151
|
}
|
|
124
152
|
/** Reconcile existing registrations only; reindex must not install a runtime. */
|
|
125
|
-
export function reconcileHookRegistrations(root, home = homedir(), env = process.env, daemonInstalled) {
|
|
153
|
+
export function reconcileHookRegistrations(root, home = homedir(), env = process.env, daemonInstalled, platform = process.platform) {
|
|
126
154
|
const result = { codexUserKeys: [], failures: [] };
|
|
127
155
|
// `core.next` (hq-core-rust US-017) wins over the pinned launcher flag.
|
|
128
156
|
// With it on, an event switches on a host only when the engine covers every
|
|
129
157
|
// hook the old dispatcher runs for it there (`coverage.ts`); its new-core
|
|
130
158
|
// entry then replaces the shell entry, so the engine owns the whole event.
|
|
131
159
|
// Every other event stays on the shell with no new-core entry. With the flag
|
|
132
|
-
// off,
|
|
133
|
-
//
|
|
134
|
-
//
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
160
|
+
// off, the new-core entries are removed and the shell registrations are what
|
|
161
|
+
// they were before the switch (on roots that still ship shell scripts). A
|
|
162
|
+
// failure to set up the new core is one warning and the flag-off path.
|
|
163
|
+
const nativeOnly = isNativeOnlyCoreRoot(root);
|
|
164
|
+
let pointedNativeOnly = false;
|
|
165
|
+
if (!nativeOnly) {
|
|
166
|
+
try {
|
|
167
|
+
const pointed = readFileSync(join(home, '.hq', 'root'), 'utf8').trim();
|
|
168
|
+
if (pointed && isNativeOnlyCoreRoot(pointed))
|
|
169
|
+
pointedNativeOnly = true;
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
// No ~/.hq/root pointer.
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const deferNativeLink = nativeOnly || pointedNativeOnly;
|
|
176
|
+
const rawCoreNext = coreNextTargetOrWarn(home, env, { platform, deferLink: deferNativeLink });
|
|
177
|
+
let claudeNext = null;
|
|
178
|
+
let claudeProjectNext = null;
|
|
179
|
+
let codexNext = null;
|
|
180
|
+
let antigravityNext = null;
|
|
181
|
+
let coreNext = rawCoreNext;
|
|
182
|
+
let stableEngine = !deferNativeLink && rawCoreNext ? rawCoreNext.coreNext : null;
|
|
183
|
+
let stableError = null;
|
|
184
|
+
if (!deferNativeLink) {
|
|
185
|
+
claudeNext = forHost(rawCoreNext, root, 'claude', env);
|
|
186
|
+
claudeProjectNext = claudeProjectTarget(rawCoreNext, claudeNext, root, env);
|
|
187
|
+
codexNext = forHost(rawCoreNext, root, 'codex', env);
|
|
188
|
+
antigravityNext = rawCoreNext;
|
|
189
|
+
}
|
|
190
|
+
else if (rawCoreNext) {
|
|
191
|
+
const candidate = getCoreNextCandidate(rawCoreNext);
|
|
192
|
+
const requiredHosts = [];
|
|
193
|
+
if (existsSync(join(root, '.claude/settings.json')))
|
|
194
|
+
requiredHosts.push('claude');
|
|
195
|
+
const existingHosts = detectMachineHookHosts(root, home, env);
|
|
196
|
+
if (requiredHosts.length === 0 && existingHosts.length === 0)
|
|
197
|
+
requiredHosts.push('claude');
|
|
198
|
+
const optionalHosts = [];
|
|
199
|
+
if (existsSync(join(root, '.codex/config.toml')))
|
|
200
|
+
optionalHosts.push('codex');
|
|
201
|
+
if (detectAntigravity({ home, env, platform }).detected)
|
|
202
|
+
optionalHosts.push('antigravity');
|
|
203
|
+
const decision = evaluateStableCommit({
|
|
204
|
+
rawCoreNext,
|
|
205
|
+
root,
|
|
206
|
+
home,
|
|
207
|
+
env,
|
|
208
|
+
engineVersion: candidate?.engineVersion,
|
|
209
|
+
requiredHosts,
|
|
210
|
+
optionalHosts,
|
|
211
|
+
});
|
|
212
|
+
if (decision.allowed) {
|
|
213
|
+
claudeNext = decision.targets.claude ?? null;
|
|
214
|
+
claudeProjectNext = decision.claudeProject;
|
|
215
|
+
codexNext = decision.targets.codex ?? null;
|
|
216
|
+
antigravityNext = decision.targets.antigravity ?? null;
|
|
217
|
+
try {
|
|
218
|
+
stableEngine = candidate?.commitStable ? candidate.commitStable(decision.acceptedHosts) : rawCoreNext.coreNext;
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
stableError = error.message;
|
|
222
|
+
coreNext = null;
|
|
223
|
+
claudeNext = null;
|
|
224
|
+
claudeProjectNext = null;
|
|
225
|
+
codexNext = null;
|
|
226
|
+
antigravityNext = null;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
// M-1 / M-2: at least one host with HQ hook entries on this machine
|
|
231
|
+
// refused the new engine. Never move `stable` to that engine: emit a
|
|
232
|
+
// clear warning naming the refusing host(s), and fall back only to a
|
|
233
|
+
// previously canary-accepted engine already linked at `stable`, or refuse.
|
|
234
|
+
if (decision.refusalSummary)
|
|
235
|
+
process.stderr.write(`${decision.refusalSummary}\n`);
|
|
236
|
+
coreNext = null;
|
|
237
|
+
claudeNext = null;
|
|
238
|
+
claudeProjectNext = null;
|
|
239
|
+
codexNext = null;
|
|
240
|
+
antigravityNext = null;
|
|
241
|
+
const refusedHost = decision.refusedHosts[0] ?? 'claude';
|
|
242
|
+
const resolution = resolvePortableEngineForNativeOnly(home, {
|
|
243
|
+
platform,
|
|
244
|
+
env,
|
|
245
|
+
host: refusedHost,
|
|
246
|
+
root,
|
|
247
|
+
candidate: candidate
|
|
248
|
+
? {
|
|
249
|
+
...candidate,
|
|
250
|
+
refusedHosts: decision.refusedHosts,
|
|
251
|
+
checkedHosts: decision.checkedHosts,
|
|
252
|
+
}
|
|
253
|
+
: null,
|
|
254
|
+
});
|
|
255
|
+
stableEngine = resolution.stable;
|
|
256
|
+
if (!stableEngine)
|
|
257
|
+
stableError = resolution.refusalReason ?? 'canary gate refused new engine';
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
const existingHosts = detectMachineHookHosts(root, home, env);
|
|
262
|
+
const resolution = resolvePortableEngineForNativeOnly(home, {
|
|
263
|
+
platform,
|
|
264
|
+
env,
|
|
265
|
+
host: existingHosts[0] ?? 'claude',
|
|
266
|
+
root,
|
|
267
|
+
candidate: null,
|
|
268
|
+
requiredHosts: existingHosts,
|
|
269
|
+
});
|
|
270
|
+
stableEngine = resolution.stable;
|
|
271
|
+
if (!stableEngine)
|
|
272
|
+
stableError = resolution.refusalReason ?? 'not installed';
|
|
273
|
+
}
|
|
274
|
+
if (nativeOnly && !stableEngine) {
|
|
275
|
+
result.failures.push(stableError
|
|
276
|
+
? `hook-engine: ${stableError}`
|
|
277
|
+
: `hook-engine: native hook engine unavailable; cannot create ${join(home, '.hq', 'bin', 'hq-hook', STABLE_LINK_NAME)}. Repair: ${HQ_CLI_NPM_REPAIR_COMMAND}`);
|
|
278
|
+
}
|
|
279
|
+
const canWritePortable = Boolean(stableEngine);
|
|
280
|
+
// US-027 M1: legacy shell launcher argv (`hq-hook <Event> --runtime ...`) was
|
|
281
|
+
// removed from `hq-hook` and exits 2 on every event; never write launcher
|
|
282
|
+
// entries from `hq reindex`.
|
|
283
|
+
const native = coreNext;
|
|
143
284
|
const ours = (entry) => isNativeEntry(entry, root) || isCoreNextEntry(entry, root);
|
|
144
285
|
// The shell target install would choose for each host: master-hook for
|
|
145
|
-
// Claude, the adapter for Codex
|
|
286
|
+
// Claude, the adapter for Codex.
|
|
146
287
|
// Resolved only when a registration is rewritten, so the default-off path
|
|
147
288
|
// reads no daemon state.
|
|
148
289
|
const shell = {};
|
|
@@ -151,15 +292,23 @@ export function reconcileHookRegistrations(root, home = homedir(), env = process
|
|
|
151
292
|
const next = host === 'codex' ? codexNext : claudeNext;
|
|
152
293
|
return next ? { ...next, fallback: shellTarget(host) } : shellTarget(host);
|
|
153
294
|
};
|
|
154
|
-
const codexBash = (event) => [codexHookEntry(root, event, 'master').command, codexHookEntry(root, event, 'shim').command];
|
|
295
|
+
const codexBash = (event) => [codexHookEntry(root, event, 'master', platform).command, codexHookEntry(root, event, 'shim', platform).command];
|
|
155
296
|
// Claude Code project files: settings.json and the settings.local.json
|
|
156
297
|
// Claude Code merges over it, together.
|
|
157
298
|
try {
|
|
158
|
-
result.failures.push(...reconcileClaudeProject(root, home, claudeProjectNext,
|
|
299
|
+
result.failures.push(...reconcileClaudeProject(root, home, claudeProjectNext, ours, !!native, canWritePortable));
|
|
159
300
|
}
|
|
160
301
|
catch (error) {
|
|
161
302
|
result.failures.push(`${join(root, '.claude/settings.json')}: ${error.message}`);
|
|
162
303
|
}
|
|
304
|
+
// Codex project config: `.codex/config.toml` (native-only roots whose bash
|
|
305
|
+
// adapter was deleted in US-027, or roots that already carry our managed block).
|
|
306
|
+
try {
|
|
307
|
+
reconcileCodexProject(root, home, codexNext);
|
|
308
|
+
}
|
|
309
|
+
catch (error) {
|
|
310
|
+
result.failures.push(`${join(root, '.codex/config.toml')}: ${error.message}`);
|
|
311
|
+
}
|
|
163
312
|
for (const [file, runtime, global] of [
|
|
164
313
|
[userHookSettingsFile('claude', home, env), 'claude', true],
|
|
165
314
|
[userHookSettingsFile('codex', home, env), 'codex', true],
|
|
@@ -170,6 +319,8 @@ export function reconcileHookRegistrations(root, home = homedir(), env = process
|
|
|
170
319
|
try {
|
|
171
320
|
if (!existsSync(file))
|
|
172
321
|
continue;
|
|
322
|
+
if (nativeOnly && !canWritePortable)
|
|
323
|
+
continue;
|
|
173
324
|
const merge = (doc) => {
|
|
174
325
|
if (!hooksOf(doc))
|
|
175
326
|
return doc;
|
|
@@ -178,12 +329,20 @@ export function reconcileHookRegistrations(root, home = homedir(), env = process
|
|
|
178
329
|
// path with JSON.stringify, Claude with single quotes.
|
|
179
330
|
const onShim = (entry) => typeof entry.command === 'string'
|
|
180
331
|
&& (entry.command.includes(JSON.stringify(shimPath(root))) || entry.command.includes(`'${shimPath(root)}'`));
|
|
181
|
-
|
|
332
|
+
const scope = global && runtime === 'claude' ? 'global' : 'project';
|
|
333
|
+
const legacyOnNativeOnly = (entry) => {
|
|
334
|
+
if (!nativeOnly)
|
|
335
|
+
return false;
|
|
336
|
+
if (isCoreNextEntry(entry, root) || isPortableNativeEntry(entry, runtime, root, scope))
|
|
337
|
+
return false;
|
|
338
|
+
return runtime === 'codex' ? isAdapterEntry(entry, root) : isHqHookEntry(entry, root);
|
|
339
|
+
};
|
|
340
|
+
if (!native && !allEntries(doc).some((entry) => ours(entry) || onShim(entry) || legacyOnNativeOnly(entry)))
|
|
182
341
|
return doc;
|
|
183
342
|
if (global) {
|
|
184
343
|
if ((runtime === 'codex' ? removeCodexHooks(doc, root) : removeHqHooks(doc, root)) === doc)
|
|
185
344
|
return doc;
|
|
186
|
-
return runtime === 'codex' ? addCodexHooks(doc, root, globalTarget('codex')) : addHqHooks(doc, root, globalTarget('claude'));
|
|
345
|
+
return runtime === 'codex' ? addCodexHooks(doc, root, globalTarget('codex'), platform) : addHqHooks(doc, root, globalTarget('claude'), platform);
|
|
187
346
|
}
|
|
188
347
|
// Project hooks.json: only an entry install itself writes is
|
|
189
348
|
// converted. HQ's own project file routes through hook-gate.sh and
|
|
@@ -196,18 +355,23 @@ export function reconcileHookRegistrations(root, home = homedir(), env = process
|
|
|
196
355
|
return { ...kept, command: want.command, ...(want.commandWindows ? { commandWindows: want.commandWindows } : {}) };
|
|
197
356
|
};
|
|
198
357
|
return mapEvents(doc, [], (event, groups) => groups && placeEvent(groups, {
|
|
199
|
-
isShell: (entry) => isNativeEntry(entry, root)
|
|
358
|
+
isShell: (entry) => isNativeEntry(entry, root)
|
|
359
|
+
|| codexBash(event).includes(entry.command)
|
|
360
|
+
|| isPortableNativeEntry(entry, 'codex', root, 'project'),
|
|
200
361
|
isNative: (entry) => isCoreNextEntry(entry, root),
|
|
201
362
|
toShell: (entry) => {
|
|
363
|
+
const target = shellTarget('codex');
|
|
364
|
+
if (target === 'portable' && isCoreNextEntry(entry, root))
|
|
365
|
+
return entry;
|
|
202
366
|
const { command: _command, commandWindows: _windows, ...rest } = entry;
|
|
203
|
-
const want = codexHookEntry(root, event,
|
|
367
|
+
const want = codexHookEntry(root, event, target, platform);
|
|
204
368
|
if (entry.command === want.command && entry.commandWindows === want.commandWindows)
|
|
205
369
|
return entry;
|
|
206
370
|
if (isCoreNextEntry(entry, root) || coreNext)
|
|
207
371
|
return inPlace(entry, want);
|
|
208
372
|
return { ...rest, command: want.command, ...(want.commandWindows ? { commandWindows: want.commandWindows } : {}) };
|
|
209
373
|
},
|
|
210
|
-
toNative: codexNext?.events.includes(event) ? (entry) => inPlace(entry, codexHookEntry(root, event, codexNext)) : null,
|
|
374
|
+
toNative: codexNext?.events.includes(event) ? (entry) => inPlace(entry, codexHookEntry(root, event, codexNext, platform)) : null,
|
|
211
375
|
}));
|
|
212
376
|
};
|
|
213
377
|
// Nothing to change: no write lock, no backup. A file we cannot parse
|
|
@@ -233,7 +397,7 @@ export function reconcileHookRegistrations(root, home = homedir(), env = process
|
|
|
233
397
|
}
|
|
234
398
|
}
|
|
235
399
|
try {
|
|
236
|
-
reconcileAntigravity(root, home, env,
|
|
400
|
+
reconcileAntigravity(root, home, env, antigravityNext, canWritePortable, platform);
|
|
237
401
|
}
|
|
238
402
|
catch (error) {
|
|
239
403
|
result.failures.push(`${antigravityTargets(home).hooksFile}: ${error.message}`);
|
|
@@ -255,7 +419,7 @@ export function reconcileHookRegistrations(root, home = homedir(), env = process
|
|
|
255
419
|
* turn. When `core.next` is off or killed, it removes
|
|
256
420
|
* the `"hq"` entry (if HQ-owned for this root) without creating the file.
|
|
257
421
|
*/
|
|
258
|
-
function reconcileAntigravity(root, home, env, coreNext) {
|
|
422
|
+
function reconcileAntigravity(root, home, env, coreNext, canWritePortable, platform) {
|
|
259
423
|
const hooksFile = antigravityTargets(home).hooksFile;
|
|
260
424
|
const fileExists = existsSync(hooksFile);
|
|
261
425
|
const events = coreNext && coreNext.registrationHosts?.includes('antigravity')
|
|
@@ -279,9 +443,32 @@ function reconcileAntigravity(root, home, env, coreNext) {
|
|
|
279
443
|
const current = fileExists ? readJson(hooksFile) : undefined;
|
|
280
444
|
if (current && merge(current) === current)
|
|
281
445
|
return;
|
|
446
|
+
mkdirSync(dirname(hooksFile), { recursive: true });
|
|
282
447
|
writeMerged(hooksFile, home, merge);
|
|
283
448
|
return;
|
|
284
449
|
}
|
|
450
|
+
if (isNativeOnlyCoreRoot(root)) {
|
|
451
|
+
if (!canWritePortable)
|
|
452
|
+
return;
|
|
453
|
+
const current = fileExists ? readJson(hooksFile) : undefined;
|
|
454
|
+
if (current && current[ANTIGRAVITY_HOOK_NAME] !== undefined)
|
|
455
|
+
return;
|
|
456
|
+
if (coreNextOffReason(home, env, platform) === null)
|
|
457
|
+
return;
|
|
458
|
+
if (!fileExists && !detectAntigravity({ home, env, platform }).detected)
|
|
459
|
+
return;
|
|
460
|
+
const portableEvents = stopCompatibilityHold(root, env) !== null
|
|
461
|
+
? ANTIGRAVITY_HOOK_EVENTS.filter((event) => event !== 'Stop')
|
|
462
|
+
: ANTIGRAVITY_HOOK_EVENTS;
|
|
463
|
+
const hqSpec = buildAntigravityHqHookSpec(portableEvents, (event) => portableNativeCommandForPlatform('antigravity', event, root, 'project', platform));
|
|
464
|
+
mkdirSync(dirname(hooksFile), { recursive: true });
|
|
465
|
+
writeMerged(hooksFile, home, (doc) => {
|
|
466
|
+
if (doc[ANTIGRAVITY_HOOK_NAME] !== undefined)
|
|
467
|
+
return doc;
|
|
468
|
+
return { ...doc, [ANTIGRAVITY_HOOK_NAME]: hqSpec };
|
|
469
|
+
});
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
285
472
|
if (!fileExists)
|
|
286
473
|
return;
|
|
287
474
|
const current = readJson(hooksFile);
|
|
@@ -299,6 +486,12 @@ function hasMasterHook(docs, event) {
|
|
|
299
486
|
const pattern = new RegExp(`master-hook\\.sh["']?\\s+["']?${event}(?![A-Za-z])`);
|
|
300
487
|
return docs.some((doc) => entriesOf(hooksOf(doc)?.[event]).some((entry) => typeof entry.command === 'string' && pattern.test(entry.command)));
|
|
301
488
|
}
|
|
489
|
+
/** Shipped post-US-027 portable `hq-hook` shell command for `event` in `.claude/settings.json`. */
|
|
490
|
+
function isShippedPortableClaudeHook(entry, event) {
|
|
491
|
+
return (typeof entry.command === 'string'
|
|
492
|
+
&& !Array.isArray(entry.args)
|
|
493
|
+
&& isShippedPortableClaudeCommand(entry.command, event));
|
|
494
|
+
}
|
|
302
495
|
/**
|
|
303
496
|
* `.claude/settings.json` and `.claude/settings.local.json` of the HQ root.
|
|
304
497
|
*
|
|
@@ -321,20 +514,28 @@ function hasMasterHook(docs, event) {
|
|
|
321
514
|
*
|
|
322
515
|
* Returns one failure line per file left alone for a reason the user must see.
|
|
323
516
|
*/
|
|
324
|
-
function reconcileClaudeProject(root, home, target,
|
|
517
|
+
function reconcileClaudeProject(root, home, target, ours, active, canWritePortable) {
|
|
325
518
|
const failures = [];
|
|
326
519
|
const file = join(root, '.claude/settings.json');
|
|
327
520
|
const localFile = join(root, '.claude/settings.local.json');
|
|
328
521
|
if (!existsSync(file))
|
|
329
522
|
return failures;
|
|
523
|
+
const nativeOnly = isNativeOnlyCoreRoot(root);
|
|
524
|
+
const noMasterHook = nativeOnly;
|
|
330
525
|
const toShell = (event) => (entry) => {
|
|
331
526
|
const { args, commandWindows: _windows, ...rest } = entry;
|
|
332
527
|
// The event an existing native entry was written for: the first
|
|
333
528
|
// launcher argument, or the one after `run --host claude`.
|
|
334
529
|
const written = Array.isArray(args) ? (args[0] === 'run' ? args[3] : args[0]) : undefined;
|
|
335
530
|
const original = typeof written === 'string' ? written : event;
|
|
336
|
-
if (
|
|
337
|
-
|
|
531
|
+
if (noMasterHook) {
|
|
532
|
+
// Never write deleted master-hook.sh or removed launcher argv on a root
|
|
533
|
+
// without master-hook.sh; preserve an existing core.next entry or fall
|
|
534
|
+
// back to the shipped fail-closed portable sh -c wrapper when stable exists.
|
|
535
|
+
if (isCoreNextEntry(entry, root) || !canWritePortable)
|
|
536
|
+
return entry;
|
|
537
|
+
return { ...rest, command: shippedPortableClaudeCommand(original) };
|
|
538
|
+
}
|
|
338
539
|
return { ...rest, command: projectClaudeCommand(original) };
|
|
339
540
|
};
|
|
340
541
|
// The new-core entry takes the shell entry's place and keeps its other
|
|
@@ -344,17 +545,51 @@ function reconcileClaudeProject(root, home, target, launcher, ours, active) {
|
|
|
344
545
|
return { ...rest, command: target.coreNext, args: coreNextArgs('claude', event, root, 'project') };
|
|
345
546
|
};
|
|
346
547
|
const project = (doc, local, moved) => {
|
|
347
|
-
|
|
548
|
+
const seedNative = nativeOnly && !!target;
|
|
549
|
+
if (!hooksOf(doc) && moved.size === 0 && !seedNative)
|
|
550
|
+
return doc;
|
|
551
|
+
const hasLegacyProjectEntry = noMasterHook && canWritePortable && Object.entries(hooksOf(doc) ?? {}).some(([event, groups]) => entriesOf(groups).some((entry) => entry.command === projectClaudeCommand(event) || isNativeEntry(entry, root)));
|
|
552
|
+
if (!active && moved.size === 0 && !allEntries(doc).some(ours) && !hasLegacyProjectEntry)
|
|
348
553
|
return doc;
|
|
349
|
-
|
|
554
|
+
// When master-hook.sh is absent (US-027) and core.next is off or
|
|
555
|
+
// unavailable, never rewrite existing native entries back to the deleted
|
|
556
|
+
// bash script. If rescue relocated entries into settings.local.json or
|
|
557
|
+
// left legacy master-hook/launcher entries behind, replace them with
|
|
558
|
+
// native/portable entries (never master-hook.sh).
|
|
559
|
+
if (noMasterHook && !target && moved.size === 0 && !hasLegacyProjectEntry)
|
|
350
560
|
return doc;
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
561
|
+
const events = seedNative
|
|
562
|
+
? [...moved.keys(), ...PROJECT_CLAUDE_HOOK_EVENTS]
|
|
563
|
+
: moved.keys();
|
|
564
|
+
return mapEvents(doc, events, (event, groups) => {
|
|
565
|
+
const covered = !!target?.events.includes(event);
|
|
566
|
+
const existing = groups ?? [];
|
|
567
|
+
const hasLegacyInEvent = canWritePortable && entriesOf(existing).some((entry) => entry.command === projectClaudeCommand(event) || isNativeEntry(entry, root));
|
|
568
|
+
if (nativeOnly && !covered && !moved.has(event) && !hasLegacyInEvent)
|
|
569
|
+
return groups;
|
|
570
|
+
const hasNative = entriesOf(existing).some((entry) => isCoreNextEntry(entry, root));
|
|
571
|
+
const isShellEntry = (entry) => entry.command === projectClaudeCommand(event)
|
|
572
|
+
|| isNativeEntry(entry, root)
|
|
573
|
+
|| isShippedPortableClaudeHook(entry, event);
|
|
574
|
+
const hasShell = entriesOf(existing).some(isShellEntry);
|
|
575
|
+
const seededRestore = seedNative && covered && !hasNative && !hasShell && !hasMasterHook([doc, local], event)
|
|
576
|
+
? { type: 'command', command: shippedPortableClaudeCommand(event), timeout: 300 }
|
|
577
|
+
: null;
|
|
578
|
+
const movedRestore = moved.has(event) && !hasMasterHook([doc, local], event)
|
|
579
|
+
? (noMasterHook
|
|
580
|
+
? (isCoreNextEntry(moved.get(event), root)
|
|
581
|
+
? moved.get(event)
|
|
582
|
+
: (canWritePortable ? { type: 'command', command: shippedPortableClaudeCommand(event), timeout: 300 } : null))
|
|
583
|
+
: toShell(event)(moved.get(event)))
|
|
584
|
+
: null;
|
|
585
|
+
return placeEvent(existing, {
|
|
586
|
+
isShell: isShellEntry,
|
|
587
|
+
isNative: (entry) => isCoreNextEntry(entry, root),
|
|
588
|
+
toShell: toShell(event),
|
|
589
|
+
toNative: covered ? toNative(event) : null,
|
|
590
|
+
restore: movedRestore ?? seededRestore,
|
|
591
|
+
});
|
|
592
|
+
});
|
|
358
593
|
};
|
|
359
594
|
// settings.local.json as it can be used: parsed, not a link.
|
|
360
595
|
const readLocal = (report) => {
|
|
@@ -403,4 +638,66 @@ function reconcileClaudeProject(root, home, target, launcher, ours, active) {
|
|
|
403
638
|
}
|
|
404
639
|
return failures;
|
|
405
640
|
}
|
|
641
|
+
/** Format a TOML basic string (escaping `\` and `"`) for `.codex/config.toml`. */
|
|
642
|
+
function tomlString(value) {
|
|
643
|
+
return `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Reconcile `<root>/.codex/config.toml` for post-US-027 native-only roots whose
|
|
647
|
+
* `.codex/hooks/hq-codex-hook-adapter.sh` was removed (or roots already carrying
|
|
648
|
+
* our managed native block). Writes `[[hooks.<Event>]]` entries calling
|
|
649
|
+
* `hq-hook run --host codex <Event> --hq-root <root>` for every covered event in
|
|
650
|
+
* {@link PROJECT_CODEX_HOOK_EVENTS}, preserving all other TOML tables and comments.
|
|
651
|
+
*/
|
|
652
|
+
function reconcileCodexProject(root, home, codexNext) {
|
|
653
|
+
const configToml = join(root, '.codex', 'config.toml');
|
|
654
|
+
if (!existsSync(configToml))
|
|
655
|
+
return;
|
|
656
|
+
const nativeOnly = isNativeOnlyCoreRoot(root);
|
|
657
|
+
const current = readFileSync(configToml, 'utf8');
|
|
658
|
+
const hasManaged = current.includes(CODEX_NATIVE_BEGIN) && current.includes(CODEX_NATIVE_END);
|
|
659
|
+
if (!nativeOnly && !hasManaged)
|
|
660
|
+
return;
|
|
661
|
+
if (!codexNext || codexNext.events.length === 0)
|
|
662
|
+
return;
|
|
663
|
+
const blocks = [];
|
|
664
|
+
for (const spec of PROJECT_CODEX_HOOK_EVENTS) {
|
|
665
|
+
if (!codexNext.events.includes(spec.event))
|
|
666
|
+
continue;
|
|
667
|
+
const command = coreNextCommand(codexNext.coreNext, 'codex', spec.event, root, 'project');
|
|
668
|
+
const lines = [`[[hooks.${spec.event}]]`];
|
|
669
|
+
if (spec.matcher)
|
|
670
|
+
lines.push(`matcher = ${tomlString(spec.matcher)}`);
|
|
671
|
+
lines.push('');
|
|
672
|
+
lines.push(`[[hooks.${spec.event}.hooks]]`);
|
|
673
|
+
lines.push('type = "command"');
|
|
674
|
+
lines.push(`command = ${tomlString(command)}`);
|
|
675
|
+
if (codexNext.coreNext.endsWith('.exe')) {
|
|
676
|
+
const winCmd = coreNextCommandWindows(codexNext.coreNext, 'codex', spec.event, root, 'project');
|
|
677
|
+
lines.push(`commandWindows = ${tomlString(winCmd)}`);
|
|
678
|
+
}
|
|
679
|
+
lines.push(`timeout = ${spec.timeout}`);
|
|
680
|
+
lines.push(`statusMessage = ${tomlString(spec.statusMessage)}`);
|
|
681
|
+
blocks.push(lines.join('\n'));
|
|
682
|
+
}
|
|
683
|
+
if (blocks.length === 0)
|
|
684
|
+
return;
|
|
685
|
+
const managed = `${CODEX_NATIVE_BEGIN}\n${blocks.join('\n\n')}\n${CODEX_NATIVE_END}\n`;
|
|
686
|
+
let base = current;
|
|
687
|
+
if (hasManaged) {
|
|
688
|
+
const start = current.indexOf(CODEX_NATIVE_BEGIN);
|
|
689
|
+
const endIdx = current.indexOf(CODEX_NATIVE_END, start);
|
|
690
|
+
let end = endIdx + CODEX_NATIVE_END.length;
|
|
691
|
+
if (current[end] === '\r' && current[end + 1] === '\n')
|
|
692
|
+
end += 2;
|
|
693
|
+
else if (current[end] === '\n')
|
|
694
|
+
end += 1;
|
|
695
|
+
base = current.slice(0, start) + current.slice(end);
|
|
696
|
+
}
|
|
697
|
+
const trimmed = base.replace(/\s+$/, '');
|
|
698
|
+
const next = trimmed ? `${trimmed}\n\n${managed}` : managed;
|
|
699
|
+
if (next === current)
|
|
700
|
+
return;
|
|
701
|
+
replaceFileNoFollow(configToml, next, home);
|
|
702
|
+
}
|
|
406
703
|
//# sourceMappingURL=reconcile.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type CoreNextTarget } from '../../utils/host-registration.js';
|
|
2
|
+
export declare const MACHINE_HOOK_HOSTS: readonly ["claude", "codex", "grok", "antigravity"];
|
|
3
|
+
export type MachineHookHost = (typeof MACHINE_HOOK_HOSTS)[number];
|
|
4
|
+
/**
|
|
5
|
+
* Every host (`claude`, `codex`, `grok`, `antigravity`) that currently has HQ
|
|
6
|
+
* hook entries on disk on this machine (project or user scope).
|
|
7
|
+
*/
|
|
8
|
+
export declare function detectMachineHookHosts(root: string, home: string, env?: NodeJS.ProcessEnv): MachineHookHost[];
|
|
9
|
+
export interface StableGateDecision {
|
|
10
|
+
allowed: boolean;
|
|
11
|
+
/** Every host required to accept before `stable` may move. */
|
|
12
|
+
checkedHosts: MachineHookHost[];
|
|
13
|
+
/** Every host (required or optional) that accepted the candidate. */
|
|
14
|
+
acceptedHosts: MachineHookHost[];
|
|
15
|
+
/** Required hosts that refused the candidate. */
|
|
16
|
+
refusedHosts: MachineHookHost[];
|
|
17
|
+
/** Per-host narrowed CoreNextTarget results. */
|
|
18
|
+
targets: Partial<Record<MachineHookHost, CoreNextTarget | null>>;
|
|
19
|
+
claudeProject: CoreNextTarget | null;
|
|
20
|
+
/** Operator-facing warning naming the refusing host(s) when `!allowed`. */
|
|
21
|
+
refusalSummary?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Decide whether the shared `<home>/.hq/bin/hq-hook/stable` link may move to
|
|
25
|
+
* `rawCoreNext` (`engineVersion`) on this machine.
|
|
26
|
+
*
|
|
27
|
+
* `requiredHosts` (typically the host(s) being installed/reconciled) is unioned
|
|
28
|
+
* with every host that already has HQ hook entries on disk
|
|
29
|
+
* ([`detectMachineHookHosts`]). `stable` may move only when EVERY host in that
|
|
30
|
+
* union accepts the candidate. `optionalHosts` (such as Codex project config
|
|
31
|
+
* when newly seeding on a fresh root) are evaluated and recorded if accepted,
|
|
32
|
+
* without blocking if they have no entries on disk yet.
|
|
33
|
+
*/
|
|
34
|
+
export declare function evaluateStableCommit(options: {
|
|
35
|
+
rawCoreNext: CoreNextTarget;
|
|
36
|
+
root: string;
|
|
37
|
+
home: string;
|
|
38
|
+
env: NodeJS.ProcessEnv;
|
|
39
|
+
engineVersion?: string;
|
|
40
|
+
requiredHosts: readonly MachineHookHost[];
|
|
41
|
+
optionalHosts?: readonly MachineHookHost[];
|
|
42
|
+
}): StableGateDecision;
|
|
43
|
+
//# sourceMappingURL=stable-gate.d.ts.map
|