@indigoai-us/hq-cli 5.345.267 → 5.345.269

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +12 -0
  3. package/contracts/host-canary-release.json +7 -7
  4. package/dist/commands/core-job-notify-native.d.ts +6 -0
  5. package/dist/commands/core-job-notify-native.js +64 -4
  6. package/dist/commands/core-jobs-native.js +3 -16
  7. package/dist/commands/install-global.js +54 -17
  8. package/dist/lib/daemon/machine-check-owner.js +1 -1
  9. package/dist/lib/daemon/machine-checks.d.ts +3 -11
  10. package/dist/lib/daemon/machine-checks.js +4 -15
  11. package/dist/lib/daemon/run.js +12 -0
  12. package/dist/lib/doctor/checks/codex-wiring.d.ts +4 -2
  13. package/dist/lib/doctor/checks/codex-wiring.js +70 -13
  14. package/dist/lib/doctor/checks/fleet-hook-core.d.ts +4 -4
  15. package/dist/lib/doctor/checks/fleet-hook-core.js +5 -10
  16. package/dist/lib/doctor/checks/grok-wiring.js +38 -0
  17. package/dist/lib/doctor/checks/hook-engine.js +0 -2
  18. package/dist/lib/doctor/checks/host-core.d.ts +1 -1
  19. package/dist/lib/doctor/checks/host-core.js +8 -38
  20. package/dist/lib/hook-engine/coverage.d.ts +10 -1
  21. package/dist/lib/hook-engine/coverage.js +63 -8
  22. package/dist/lib/hook-engine/fleet-registration.js +7 -4
  23. package/dist/lib/hook-engine/native-precompact-compatibility.json +7 -1
  24. package/dist/lib/hook-engine/native-stop-compatibility.json +30 -11
  25. package/dist/lib/hook-engine/reconcile.d.ts +10 -1
  26. package/dist/lib/hook-engine/reconcile.js +339 -42
  27. package/dist/lib/hook-engine/stable-gate.d.ts +43 -0
  28. package/dist/lib/hook-engine/stable-gate.js +276 -0
  29. package/dist/lib/hot-channels/fleet-complete.js +2 -2
  30. package/dist/lib/install/antigravity-targets.js +2 -1
  31. package/dist/lib/install/claude-targets.d.ts +6 -6
  32. package/dist/lib/install/claude-targets.js +13 -9
  33. package/dist/lib/install/codex-targets.d.ts +4 -4
  34. package/dist/lib/install/codex-targets.js +26 -16
  35. package/dist/lib/install/hook-target.d.ts +23 -2
  36. package/dist/lib/install/hook-target.js +89 -16
  37. package/dist/lib/outpost-identity-env.d.ts +18 -0
  38. package/dist/lib/outpost-identity-env.js +29 -0
  39. package/dist/lib/signals/steps/extract.js +46 -12
  40. package/dist/utils/core-next-kill.d.ts +2 -15
  41. package/dist/utils/core-next-kill.js +5 -36
  42. package/dist/utils/hook-engine-crash.d.ts +86 -0
  43. package/dist/utils/hook-engine-crash.js +325 -0
  44. package/dist/utils/hook-engine-rollup.d.ts +8 -3
  45. package/dist/utils/hook-engine-rollup.js +0 -1
  46. package/dist/utils/hook-trust.d.ts +2 -0
  47. package/dist/utils/hook-trust.js +156 -13
  48. package/dist/utils/host-registration.d.ts +158 -4
  49. package/dist/utils/host-registration.js +500 -17
  50. package/dist/utils/version-gate.d.ts +42 -4
  51. package/dist/utils/version-gate.js +84 -25
  52. package/package.json +7 -7
@@ -136,39 +136,96 @@ export function detectCodexAdapter(hqRoot) {
136
136
  };
137
137
  }
138
138
  const wiredEvents = [];
139
+ const nativeEvents = [];
139
140
  const hooks = doc?.hooks;
140
141
  if (hooks && typeof hooks === "object" && !Array.isArray(hooks)) {
141
142
  for (const [event, entries] of Object.entries(hooks)) {
142
143
  if (!Array.isArray(entries))
143
144
  continue;
144
- const routed = entries.some((entry) => {
145
+ let routedAdapter = false;
146
+ let routedNative = false;
147
+ for (const entry of entries) {
145
148
  const inner = entry?.hooks;
146
149
  if (!Array.isArray(inner))
147
- return false;
148
- return inner.some((hook) => {
150
+ continue;
151
+ for (const hook of inner) {
149
152
  const command = hook?.command;
150
- return (typeof command === "string" &&
151
- command.includes(CODEX_ADAPTER_BASENAME));
152
- });
153
- });
154
- if (routed)
153
+ if (typeof command !== "string")
154
+ continue;
155
+ if (command.includes(CODEX_ADAPTER_BASENAME))
156
+ routedAdapter = true;
157
+ else if (command.includes("hq-hook") && command.includes("--host") && command.includes("codex"))
158
+ routedNative = true;
159
+ }
160
+ }
161
+ if (routedAdapter)
155
162
  wiredEvents.push(event);
163
+ else if (routedNative)
164
+ nativeEvents.push(event);
156
165
  }
157
166
  }
167
+ if (wiredEvents.length > 0) {
168
+ return {
169
+ detected: true,
170
+ mode: "adapter",
171
+ configPresent: true,
172
+ configParseError: null,
173
+ wiredEvents,
174
+ };
175
+ }
176
+ if (nativeEvents.length > 0) {
177
+ return {
178
+ detected: true,
179
+ mode: "native",
180
+ configPresent: true,
181
+ configParseError: null,
182
+ wiredEvents: nativeEvents,
183
+ };
184
+ }
158
185
  return {
159
- detected: wiredEvents.length > 0,
186
+ detected: false,
160
187
  configPresent: true,
161
188
  configParseError: null,
162
- wiredEvents,
189
+ wiredEvents: [],
163
190
  };
164
191
  }
165
192
  /**
166
- * Grade a tree whose `.codex/config.toml` routes events through the adapter:
167
- * the adapter script and its dispatch library, event coverage, leftover legacy
168
- * artifacts, and now-obsolete allowed-divergence entries.
193
+ * Grade a tree whose `.codex/config.toml` routes events through the adapter
194
+ * (or native `hq-hook` on post-US-027 roots):
195
+ * the adapter script and its dispatch library (adapter mode), event coverage,
196
+ * leftover legacy artifacts, and now-obsolete allowed-divergence entries.
169
197
  */
170
198
  function checkAdapterWiring(hqRoot, adapter, allowed) {
171
199
  const results = [];
200
+ if (adapter.mode === "native") {
201
+ results.push({
202
+ status: "PASS",
203
+ checkId: "hooks.codex.adapter",
204
+ target: path.join(".codex", "config.toml"),
205
+ message: "Codex hooks route directly through native hq-hook (.codex/config.toml); no bash adapter required.",
206
+ });
207
+ const wired = new Set(adapter.wiredEvents);
208
+ for (const event of REQUIRED_ADAPTER_EVENTS) {
209
+ if (wired.has(event)) {
210
+ results.push({
211
+ status: "PASS",
212
+ checkId: "hooks.codex.registration",
213
+ target: event,
214
+ message: `Codex ${event} routes through native hq-hook (.codex/config.toml).`,
215
+ });
216
+ }
217
+ else {
218
+ results.push({
219
+ status: "FAIL",
220
+ checkId: "hooks.codex.registration",
221
+ target: event,
222
+ message: `Codex ${event} is not wired to native hq-hook in .codex/config.toml.`,
223
+ remediation: "Run `hq reindex` to register native Codex hooks in .codex/config.toml.",
224
+ });
225
+ }
226
+ }
227
+ return results;
228
+ }
172
229
  const adapterRelPath = path.join(".codex", "hooks", CODEX_ADAPTER_BASENAME);
173
230
  const adapterPath = path.join(hqRoot, adapterRelPath);
174
231
  const adapterState = fileState(adapterPath);
@@ -3,10 +3,10 @@ import { type FleetHost } from '../../hook-engine/fleet-registration.js';
3
3
  import type { CheckResult } from '../types.js';
4
4
  /**
5
5
  * One result per hq-fleet profile: per event, which core the bot runtime uses
6
- * (`native`, `shell`, or `shell fallback` under a kill switch) and on which
7
- * host (`fleet-local` or `agents-v2`). A native entry passes only when the
8
- * engine advertises its host and covers every old hook for the event, and its
9
- * fallback is that host's exact adapter command.
6
+ * (`native` or `shell`) and on which host (`fleet-local` or `agents-v2`). A
7
+ * native entry passes only when the engine advertises its host and covers
8
+ * every old hook for the event, and its fallback is that host's exact adapter
9
+ * command.
10
10
  */
11
11
  export declare function fleetHookCoreResults(home: string, env: NodeJS.ProcessEnv, inspect?: (engine: string, host: FleetHost) => EngineCapabilities): CheckResult[];
12
12
  //# sourceMappingURL=fleet-hook-core.d.ts.map
@@ -2,7 +2,7 @@
2
2
  import * as fs from 'node:fs';
3
3
  import * as path from 'node:path';
4
4
  import { load } from 'js-yaml';
5
- import { coreNextKillReason, missingEvaluators } from '../../../utils/host-registration.js';
5
+ import { missingEvaluators } from '../../../utils/host-registration.js';
6
6
  import { FLEET_ADAPTERS, FLEET_EVENTS, isFleetHost, literalArgv, fallbackProblem, inspectFleetEngine } from '../../hook-engine/fleet-registration.js';
7
7
  import { uncoveredHooks } from '../../hook-engine/coverage.js';
8
8
  /** The Fleet host whose shell adapter `argv` runs, if any. */
@@ -17,10 +17,10 @@ function shellHost(argv) {
17
17
  }
18
18
  /**
19
19
  * One result per hq-fleet profile: per event, which core the bot runtime uses
20
- * (`native`, `shell`, or `shell fallback` under a kill switch) and on which
21
- * host (`fleet-local` or `agents-v2`). A native entry passes only when the
22
- * engine advertises its host and covers every old hook for the event, and its
23
- * fallback is that host's exact adapter command.
20
+ * (`native` or `shell`) and on which host (`fleet-local` or `agents-v2`). A
21
+ * native entry passes only when the engine advertises its host and covers
22
+ * every old hook for the event, and its fallback is that host's exact adapter
23
+ * command.
24
24
  */
25
25
  export function fleetHookCoreResults(home, env, inspect = (engine, host) => inspectFleetEngine(engine, home, undefined, undefined, undefined, host)) {
26
26
  const base = env.HQ_FLEET_HOME?.trim() || path.join(home, '.hq-fleet');
@@ -69,11 +69,6 @@ export function fleetHookCoreResults(home, env, inspect = (engine, host) => insp
69
69
  for (const argv of native) {
70
70
  const host = argv[3];
71
71
  const value = (flag) => { const index = argv.indexOf(flag); return index < 0 ? undefined : argv[index + 1]; };
72
- const killed = coreNextKillReason(home, env);
73
- if (killed) {
74
- cores[event] = 'shell fallback';
75
- problems.push(`${event}: kill switch is on (${killed}); re-render the profile`);
76
- }
77
72
  let fallback;
78
73
  try {
79
74
  fallback = JSON.parse(value('--fleet-fallback') ?? 'null');
@@ -34,6 +34,32 @@ const GROK_BRIDGE_FILES = ["hq-hq-bridge.sh", "hq-hq-bridge.json"];
34
34
  export function checkGrokWiring(context, options = {}) {
35
35
  const grokDir = path.join(context.hqRoot, ".grok", "hooks");
36
36
  const bridgeDir = options.bridgeDir ?? path.join(os.homedir(), ".grok", "hooks");
37
+ const nativeBridge = nativeBridgeEvents(bridgeDir);
38
+ const legacyAbsent = !fileState(path.join(grokDir, "hq-grok.json")).present &&
39
+ !fileState(path.join(grokDir, "hq-grok-hook-adapter.sh")).present;
40
+ if (legacyAbsent && nativeBridge !== null) {
41
+ return [
42
+ {
43
+ status: "NA",
44
+ checkId: "hooks.grok.scope",
45
+ target: "grok",
46
+ message: "Grok hook checks are wiring only (registration, native bridge presence); live Grok hook execution is verified only when the doctor runs under the Grok host.",
47
+ },
48
+ {
49
+ status: "PASS",
50
+ checkId: "hooks.grok.registration",
51
+ target: path.join(bridgeDir, "hq-hq-bridge.json"),
52
+ message: `User-global Grok bridge registers native hq-hook across ${nativeBridge} event${nativeBridge === 1 ? "" : "s"}.`,
53
+ },
54
+ {
55
+ status: "PASS",
56
+ checkId: "hooks.grok.adapter",
57
+ target: path.join(bridgeDir, "hq-hq-bridge.json"),
58
+ message: "Grok routes directly through native hq-hook (no bash adapter required).",
59
+ },
60
+ checkBridge(bridgeDir),
61
+ ];
62
+ }
37
63
  return [
38
64
  {
39
65
  status: "NA",
@@ -46,6 +72,18 @@ export function checkGrokWiring(context, options = {}) {
46
72
  checkBridge(bridgeDir),
47
73
  ];
48
74
  }
75
+ function nativeBridgeEvents(bridgeDir) {
76
+ try {
77
+ const raw = fs.readFileSync(path.join(bridgeDir, "hq-hq-bridge.json"), "utf8");
78
+ const parsed = JSON.parse(raw);
79
+ const commands = collectCommands(parsed);
80
+ const native = commands.filter((command) => command.includes("hq-hook") && command.includes("--host") && command.includes("grok"));
81
+ return native.length > 0 ? native.length : null;
82
+ }
83
+ catch {
84
+ return null;
85
+ }
86
+ }
49
87
  function checkRegistration(registrationPath) {
50
88
  let raw;
51
89
  try {
@@ -17,8 +17,6 @@ function pathPresent(filePath) {
17
17
  function isStrictModeActive(env) {
18
18
  const engineEnv = env.HQ_HOOK_ENGINE?.trim().toLowerCase();
19
19
  const home = env.HOME || env.USERPROFILE || homedir();
20
- if (engineEnv === 'off' || pathPresent(join(home, '.hq', 'hook-engine.off')))
21
- return false;
22
20
  if (engineEnv === 'strict')
23
21
  return true;
24
22
  return pathPresent(join(home, '.hq', 'hook-engine.strict'));
@@ -38,7 +38,7 @@ export interface EventCore {
38
38
  * fix. With the flag on, an event left on the old dispatcher says why.
39
39
  */
40
40
  export declare function hostCoreResults(root: string, options?: HostCoreOptions): CheckResult[];
41
- /** Flag and kill-switch state, shown once. */
41
+ /** Flag state, shown once. */
42
42
  export declare function coreSwitchResult(options?: HostCoreOptions): CheckResult;
43
43
  /** The family `hq doctor` prints. */
44
44
  export declare function hostCoreFamily(context: CheckContext, options?: HostCoreOptions): Promise<FamilyRun>;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * `hq doctor`: which core each host on this machine is using, per event, and
3
- * why (hq-core-rust US-017). Reads the registration files `hq reindex` writes
4
- * and the kill switch, and writes nothing. When an event is registered to the
3
+ * why (hq-core-rust US-017). Reads the registration files `hq reindex` writes,
4
+ * and writes nothing. When an event is registered to the
5
5
  * new core, or the flag is on, it starts the engine once (`--version` and
6
6
  * `capabilities --json`) to see which evaluators it has. An event registered
7
7
  * to a new core that is missing, does not run, or lacks the event's guards is
@@ -16,7 +16,7 @@ import { isAdapterEntry } from '../../install/codex-targets.js';
16
16
  import { antigravityEventEntries, antigravityTargets } from '../../install/antigravity-targets.js';
17
17
  import { claudeProjectAdapterHold, stopCompatibilityHold, uncoveredHooks } from '../../hook-engine/coverage.js';
18
18
  import { masterHookPath, shimPath } from '../../install/claude-targets.js';
19
- import { CORE_NEXT_FLAG, CORE_NEXT_KILL_ENV, CORE_NEXT_KILL_FILE, ENGINE_KILL_ENV, ENGINE_KILL_FILE, REQUIRED_EVALUATORS, STABLE_LINK_NAME, coreNextEnabled, coreNextKillReason, coreNextTargetFor, missingEvaluators, probeEngine, } from '../../../utils/host-registration.js';
19
+ import { CORE_NEXT_FLAG, REQUIRED_EVALUATORS, STABLE_LINK_NAME, coreNextEnabled, coreNextTargetFor, missingEvaluators, probeEngine, } from '../../../utils/host-registration.js';
20
20
  import { fleetHookCoreResults } from './fleet-hook-core.js';
21
21
  import { HOOKS_FAMILY_ID } from '../registry.js';
22
22
  export const HOST_CORE_FAMILY_ID = 'host-core';
@@ -109,7 +109,6 @@ export function hostCoreResults(root, options = {}) {
109
109
  const platform = options.platform ?? process.platform;
110
110
  const probe = options.probe ?? probeEngine;
111
111
  const flagOn = coreNextEnabled(env);
112
- const killedBy = coreNextKillReason(home, env);
113
112
  const probed = new Map();
114
113
  const capabilities = (engine) => {
115
114
  let found = probed.get(engine);
@@ -161,8 +160,6 @@ export function hostCoreResults(root, options = {}) {
161
160
  const oldCore = (event, host, scope) => {
162
161
  if (!flagOn)
163
162
  return { status: 'PASS', reason: `flag ${CORE_NEXT_FLAG} is off` };
164
- if (killedBy)
165
- return { status: 'PASS', reason: `the kill switch is on (${killedBy})` };
166
163
  if (platform === 'win32')
167
164
  return { status: 'PASS', reason: 'Windows keeps the old registration until US-022' };
168
165
  if (!REQUIRED_EVALUATORS[event])
@@ -239,11 +236,8 @@ export function hostCoreResults(root, options = {}) {
239
236
  // the engine must do every hook the old dispatcher runs for it here.
240
237
  const shell = kinds.filter((k) => k !== 'new-core');
241
238
  let verdict;
242
- if (killedBy) {
243
- verdict = { status: 'FAIL', reason: `the kill switch is on (${killedBy}) but this event is still registered to the new core; run hq reindex to remove the new-core entry` };
244
- }
245
- else if (shell.length > 0) {
246
- verdict = { status: 'FAIL', reason: `registered to the new core beside the ${shell.map((k) => label(k, target.host)).join(', ')}, so both run and the kill switch would run the old dispatcher twice` };
239
+ if (shell.length > 0) {
240
+ verdict = { status: 'FAIL', reason: `registered to the new core beside the ${shell.map((k) => label(k, target.host)).join(', ')}, so both run` };
247
241
  }
248
242
  else if (all.filter((k) => k === 'new-core').length > 1) {
249
243
  verdict = { status: 'WARN', reason: 'registered to the new core more than once, so its checks run twice' };
@@ -299,7 +293,7 @@ export function hostCoreResults(root, options = {}) {
299
293
  message: `${target.host} (${target.scope}): ${summary}`,
300
294
  details: { ...(cores.length === 1 ? { core: cores[0] } : {}), cores, events },
301
295
  ...(failed.length > 0
302
- ? { remediation: `Run hq reindex: it puts ${failed.join(', ')} back on the old dispatcher when the new core cannot take them, or repairs the ${STABLE_LINK_NAME} link. It also puts an event back on the old dispatcher when the new core no longer covers every hook the old dispatcher runs for it, leaves one registration per event, and removes the new-core entries while the kill switch is on. Until then those events run no HQ hook, a new core without their guards, hooks twice, or none of the hooks the new core does not cover.` }
296
+ ? { remediation: `Run hq reindex: it puts ${failed.join(', ')} back on the old dispatcher when the new core cannot take them, or repairs the ${STABLE_LINK_NAME} link. It also puts an event back on the old dispatcher when the new core no longer covers every hook the old dispatcher runs for it and leaves one registration per event. Until then those events run no HQ hook, a new core without their guards, hooks twice, or none of the hooks the new core does not cover.` }
303
297
  : mixed.length > 0
304
298
  ? { remediation: 'Run hq reindex to leave one HQ registration per event.' }
305
299
  : {}),
@@ -316,36 +310,12 @@ function eventEntries(doc, host) {
316
310
  return [];
317
311
  return Object.entries(hooks).map(([event, groups]) => [event, hookEntries({ hooks: { [event]: groups } })]);
318
312
  }
319
- /** Flag and kill-switch state, shown once. */
313
+ /** Flag state, shown once. */
320
314
  export function coreSwitchResult(options = {}) {
321
315
  const env = options.env ?? process.env;
322
- const home = options.home ?? env.HOME ?? os.homedir();
323
316
  const on = coreNextEnabled(env);
324
- const killedBy = [
325
- /^(off|0|false|no)$/i.test((env[CORE_NEXT_KILL_ENV] ?? '').trim()) ? `${CORE_NEXT_KILL_ENV}=${env[CORE_NEXT_KILL_ENV]}` : '',
326
- /^off$/i.test((env[ENGINE_KILL_ENV] ?? '').trim()) ? `${ENGINE_KILL_ENV}=${env[ENGINE_KILL_ENV]}` : '',
327
- exists(path.join(home, CORE_NEXT_KILL_FILE)) ? path.join(home, CORE_NEXT_KILL_FILE) : '',
328
- exists(path.join(home, ENGINE_KILL_FILE)) ? path.join(home, ENGINE_KILL_FILE) : '',
329
- ].filter(Boolean);
330
317
  const flag = `flag ${CORE_NEXT_FLAG} is ${on ? 'on' : 'off'}`;
331
- const kill = killedBy.length
332
- ? `; kill switch on (${killedBy.join(', ')}): new-core registrations hand each event to the old dispatcher, and hq reindex removes them`
333
- : '';
334
- // The engine reads the kill switch from each hook's own environment; this
335
- // check and hq reindex read it from theirs.
336
- const hostEnv = on || killedBy.length
337
- ? `. ${CORE_NEXT_KILL_ENV} or ${ENGINE_KILL_ENV} set only in a host's environment (for example Claude Code settings env) is honored by the engine at run time only; hq reindex and this check do not see it, so use the file ${path.join('~', CORE_NEXT_KILL_FILE)} to switch the registrations back`
338
- : '';
339
- return { status: 'PASS', checkId: 'host-core:switch', message: `${flag}${kill}${hostEnv}`, details: { flag: on, killSwitch: killedBy } };
340
- }
341
- function exists(file) {
342
- try {
343
- fs.lstatSync(file);
344
- return true;
345
- }
346
- catch {
347
- return false;
348
- }
318
+ return { status: 'PASS', checkId: 'host-core:switch', message: flag, details: { flag: on } };
349
319
  }
350
320
  /** The family `hq doctor` prints. */
351
321
  export async function hostCoreFamily(context, options = {}) {
@@ -1,4 +1,4 @@
1
- import type { CoreNextHost, CoreNextTarget } from '../../utils/host-registration.js';
1
+ import { type CoreNextHost, type CoreNextTarget } from '../../utils/host-registration.js';
2
2
  /** Stands for the hook list when it cannot be read; never covered. */
3
3
  export declare const UNREADABLE = "(the old dispatcher hook list could not be read)";
4
4
  /** One item of a Git config file as git 2.50 reads it: a section header, or a variable under the last one. */
@@ -166,6 +166,15 @@ export declare function coversKey(key: string): {
166
166
  * order, each id once. The same as covers_hosts.rs `claims_on`.
167
167
  */
168
168
  export declare function coveredOn(covers: Readonly<Record<string, readonly string[]>> | undefined, event: string, host: CoreNextHost): string[];
169
+ /**
170
+ * True for a post-US-027 native-only HQ root, keyed on the core version
171
+ * declared in `core/core.yaml` (`hookDispatcherVersion >= 2` or `hqVersion`
172
+ * major `>= 17`) rather than on the absence of retired files on disk (which
173
+ * `hq rescue` may leave behind before cleanup). `hq reindex` still enforces
174
+ * `shellHooks` against `COVERS` for custom hooks, but skips sha256 pin holds
175
+ * for deleted bash dispatchers and adapters.
176
+ */
177
+ export declare function isNativeOnlyCoreRoot(root: string): boolean;
169
178
  /** The old dispatcher's hooks for `event` on `host` that the engine does not cover. */
170
179
  export declare function uncoveredHooks(root: string, host: CoreNextHost, event: string, covers: Readonly<Record<string, readonly string[]>> | undefined, env?: NodeJS.ProcessEnv): string[];
171
180
  /**
@@ -26,6 +26,7 @@
26
26
  import { createHash } from 'node:crypto';
27
27
  import * as fs from 'node:fs';
28
28
  import * as path from 'node:path';
29
+ import { isShippedPortableClaudeCommand } from '../../utils/host-registration.js';
29
30
  import { isCoreNextEntry } from './registration.js';
30
31
  import { CLASSIFYING_ADAPTER_CORE_SHA256, RELEASED_CLASSIFYING_ADAPTER_CORE_SHA256 } from './adapter-core-pin.js';
31
32
  const CRATE_POLICY_FALLBACKS = {
@@ -1559,9 +1560,12 @@ export function shellHooks(root, host, event) {
1559
1560
  for (const group of Array.isArray(registered) ? registered : []) {
1560
1561
  for (const entry of Array.isArray(group?.hooks) ? group.hooks : []) {
1561
1562
  const command = entry?.command;
1562
- // HQ's own entry for the event (master-hook, or the Claude Code
1563
- // new-core entry that took its place) is the dispatcher counted above.
1564
- if (typeof command !== 'string' || command.includes('master-hook.sh') || isCoreNextEntry(entry, root))
1563
+ // HQ's own entry for the event (master-hook, shipped portable hq-hook,
1564
+ // or the Claude Code new-core entry that took its place) is the dispatcher counted above.
1565
+ if (typeof command !== 'string'
1566
+ || command.includes('master-hook.sh')
1567
+ || (!Array.isArray(entry.args) && isShippedPortableClaudeCommand(command, event))
1568
+ || isCoreNextEntry(entry, root))
1565
1569
  continue;
1566
1570
  out.push(`settings:${command}`);
1567
1571
  }
@@ -1686,6 +1690,55 @@ export function coveredOn(covers, event, host) {
1686
1690
  }
1687
1691
  return out;
1688
1692
  }
1693
+ function coreYamlU32(text, key) {
1694
+ for (const raw of text.split(/\r?\n/)) {
1695
+ const line = raw.split('#')[0]?.trim() ?? '';
1696
+ if (!line.startsWith(`${key}:`))
1697
+ continue;
1698
+ const val = line.slice(key.length + 1).trim().replace(/^["']|["']$/g, '');
1699
+ if (/^\d+$/.test(val))
1700
+ return Number.parseInt(val, 10);
1701
+ }
1702
+ return null;
1703
+ }
1704
+ function coreYamlHqMajor(text) {
1705
+ for (const raw of text.split(/\r?\n/)) {
1706
+ const line = raw.split('#')[0]?.trim() ?? '';
1707
+ if (!line.startsWith('hqVersion:'))
1708
+ continue;
1709
+ const val = line.slice('hqVersion:'.length).trim().replace(/^["']|["']$/g, '').replace(/^v/, '');
1710
+ const match = /^(\d+)\./.exec(val);
1711
+ if (match)
1712
+ return Number.parseInt(match[1], 10);
1713
+ }
1714
+ return null;
1715
+ }
1716
+ /**
1717
+ * True for a post-US-027 native-only HQ root, keyed on the core version
1718
+ * declared in `core/core.yaml` (`hookDispatcherVersion >= 2` or `hqVersion`
1719
+ * major `>= 17`) rather than on the absence of retired files on disk (which
1720
+ * `hq rescue` may leave behind before cleanup). `hq reindex` still enforces
1721
+ * `shellHooks` against `COVERS` for custom hooks, but skips sha256 pin holds
1722
+ * for deleted bash dispatchers and adapters.
1723
+ */
1724
+ export function isNativeOnlyCoreRoot(root) {
1725
+ const coreYamlPath = path.join(root, 'core', 'core.yaml');
1726
+ if (!regularFile(coreYamlPath) || !regularFile(path.join(root, '.claude', 'hooks', 'hook-registry.json'))) {
1727
+ return false;
1728
+ }
1729
+ let text;
1730
+ try {
1731
+ text = fs.readFileSync(coreYamlPath, 'utf8');
1732
+ }
1733
+ catch {
1734
+ return false;
1735
+ }
1736
+ const dispatcherVersion = coreYamlU32(text, 'hookDispatcherVersion');
1737
+ if (dispatcherVersion !== null && dispatcherVersion >= 2)
1738
+ return true;
1739
+ const major = coreYamlHqMajor(text);
1740
+ return major !== null && major >= 17;
1741
+ }
1689
1742
  /** The old dispatcher's hooks for `event` on `host` that the engine does not cover. */
1690
1743
  export function uncoveredHooks(root, host, event, covers, env = process.env) {
1691
1744
  const hooks = shellHooks(root, host, event);
@@ -1693,6 +1746,8 @@ export function uncoveredHooks(root, host, event, covers, env = process.env) {
1693
1746
  return [UNREADABLE];
1694
1747
  const covered = coveredOn(covers, event, host);
1695
1748
  const missing = hooks.filter((hook) => !covered.some((claim) => claimCovers(claim, hook)));
1749
+ if (isNativeOnlyCoreRoot(root))
1750
+ return missing;
1696
1751
  if (event === 'Stop' && covered.includes('master-hook:Stop')) {
1697
1752
  const hold = stopCompatibilityHold(root, env);
1698
1753
  if (hold)
@@ -1866,7 +1921,7 @@ export const SESSION_START_PINS = [
1866
1921
  ['core/scripts/hqd-hook-flag-cache-lib.sh', ['061d264460408e9eaf43fdf0fdde662c906a9a7dacb4e7a591e684bca28c138a']],
1867
1922
  ['core/scripts/hq-session.sh', ['db701162f71b53fd2188974d2f46c58250593dde1252d65b36e6d02b9a765fe7', '02a37c5dbf4fb5af27cc64d0f271121e990758b757a479f60e9ce099f4d65ded', 'd4d4aef60ff8b095e3abcc817598f376d3c2de8d59758c3ed6dd40d4aa4b11fb']],
1868
1923
  ['core/scripts/lib/session-id.sh', ['2ebbc50893c7c601a111b9e8f9945afeac88f552d7caeec09c4096f4c27a833d', 'd6a04155571ec53edd853878cebaba5a5bab93801a73e356499440c1cd009c71']],
1869
- ['core/scripts/lib/session-scope-capability.sh', ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead']],
1924
+ ['core/scripts/lib/session-scope-capability.sh', ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead', '498ffa6e4342c79eecb0c1fddec56ba03e169bb627b2da8f8ef2f09f55954b38']],
1870
1925
  ['core/scripts/resolve-company.sh', ['00d6fa069f574a86087c77daa44887a2617446d4300d5daebecc9bfb5d81abe7']],
1871
1926
  ];
1872
1927
  /**
@@ -1968,7 +2023,7 @@ export const FLEET_LOCAL_PRE_TOOL_USE_PINS = [
1968
2023
  ],
1969
2024
  missing: 'allowed',
1970
2025
  },
1971
- { relative: 'core/scripts/lib/session-scope-capability.sh', accepted: ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead'], missing: 'allowed' },
2026
+ { relative: 'core/scripts/lib/session-scope-capability.sh', accepted: ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead', '498ffa6e4342c79eecb0c1fddec56ba03e169bb627b2da8f8ef2f09f55954b38'], missing: 'allowed' },
1972
2027
  ];
1973
2028
  /**
1974
2029
  * Why fleet-local PreToolUse must stay on the shell adapter in `root`: a present file of
@@ -2208,7 +2263,7 @@ export const PRE_TOOL_USE_DISPATCHER_PINS = [
2208
2263
  { relative: 'core/scripts/lib/epochrealtime.sh', accepted: ['4c9205520dba31533c95eea145f6068ba626885c342c2aa1f232a7237d046cdf'] },
2209
2264
  { relative: 'core/scripts/lib/perl-child-locale.sh', accepted: ['18e6b9d0e22874eea00ecc868b4dcfebbc3bb42434d8d0c81b20baec1194df2e'] },
2210
2265
  { relative: 'core/scripts/lib/session-id.sh', accepted: ['2ebbc50893c7c601a111b9e8f9945afeac88f552d7caeec09c4096f4c27a833d', 'd6a04155571ec53edd853878cebaba5a5bab93801a73e356499440c1cd009c71'] },
2211
- { relative: 'core/scripts/lib/session-scope-capability.sh', accepted: ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead'] },
2266
+ { relative: 'core/scripts/lib/session-scope-capability.sh', accepted: ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead', '498ffa6e4342c79eecb0c1fddec56ba03e169bb627b2da8f8ef2f09f55954b38'] },
2212
2267
  { relative: 'core/scripts/resolve-hq-root.sh', accepted: ['188e99c7c60bc9909290a666d6f3b93387ae6cf68f2eeb41fd24c2dea62a5240'] },
2213
2268
  ];
2214
2269
  /**
@@ -2629,7 +2684,7 @@ export const PROMPT_COMPANY_BIND_PINS = [
2629
2684
  },
2630
2685
  { relative: 'core/scripts/hq-session.sh', accepted: ['db701162f71b53fd2188974d2f46c58250593dde1252d65b36e6d02b9a765fe7', '02a37c5dbf4fb5af27cc64d0f271121e990758b757a479f60e9ce099f4d65ded', 'd4d4aef60ff8b095e3abcc817598f376d3c2de8d59758c3ed6dd40d4aa4b11fb'] },
2631
2686
  { relative: 'core/scripts/lib/session-id.sh', accepted: ['2ebbc50893c7c601a111b9e8f9945afeac88f552d7caeec09c4096f4c27a833d', 'd6a04155571ec53edd853878cebaba5a5bab93801a73e356499440c1cd009c71'] },
2632
- { relative: 'core/scripts/lib/session-scope-capability.sh', accepted: ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead'] },
2687
+ { relative: 'core/scripts/lib/session-scope-capability.sh', accepted: ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead', '498ffa6e4342c79eecb0c1fddec56ba03e169bb627b2da8f8ef2f09f55954b38'] },
2633
2688
  ];
2634
2689
  /**
2635
2690
  * Why UserPromptSubmit must stay on the shell registration in `root`: the native
@@ -2732,7 +2787,7 @@ export function postToolUseAdapterHold(root, host) {
2732
2787
  return null;
2733
2788
  }
2734
2789
  /** The session-scope-capability.sh master-hook's Task-agent pin is modelled on (crates/hq-hook/src/scope/session.rs `SUBAGENT_PIN_LIB_SHA256`). */
2735
- export const SUBAGENT_SCOPE_LIBRARY = { relative: 'core/scripts/lib/session-scope-capability.sh', accepted: ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead'] };
2790
+ export const SUBAGENT_SCOPE_LIBRARY = { relative: 'core/scripts/lib/session-scope-capability.sh', accepted: ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead', '498ffa6e4342c79eecb0c1fddec56ba03e169bb627b2da8f8ef2f09f55954b38'] };
2736
2791
  /**
2737
2792
  * Why SubagentStart or SubagentStop (`event`) must stay on the shell registration in `root`: the
2738
2793
  * native master work (crates/hq-hook/src/lifecycle_master.rs `begin`) refuses every such event that
@@ -13,7 +13,7 @@ import * as fs from 'node:fs';
13
13
  import * as path from 'node:path';
14
14
  import { checkStableEngine, coreNextOffReason, capableEvents, probeEngine, missingEvaluators, resolveCoreNextEngine } from '../../utils/host-registration.js';
15
15
  import { verifyHookEngine } from './resolve.js';
16
- import { forHost, uncoveredHooks } from './coverage.js';
16
+ import { forHost, isNativeOnlyCoreRoot, uncoveredHooks } from './coverage.js';
17
17
  import { quotePosix } from './registration.js';
18
18
  export const FLEET_EVENTS = { pre_tool_call: 'PreToolUse', post_tool_call: 'PostToolUse', pre_llm_call: 'UserPromptSubmit', on_session_start: 'SessionStart', pre_verify: 'Stop', on_session_finalize: 'SessionEnd', subagent_stop: 'SubagentStop' };
19
19
  /** Literal POSIX argv only. Never expands variables or executes shell syntax. */
@@ -171,15 +171,18 @@ export function fleetRegistrationPlan(root, fallbacks, options) {
171
171
  caps = undefined;
172
172
  }
173
173
  const target = caps ? forHost({ coreNext: engine, events: capableEvents(caps), covers: caps.covers }, root, host, env) : null;
174
+ const nativeOnly = isNativeOnlyCoreRoot(root);
174
175
  const events = {};
175
176
  for (const [event, canonical] of Object.entries(FLEET_EVENTS)) {
176
177
  const fallback = fallbacks[event] ?? [];
177
178
  if (!Array.isArray(fallback) || !fallback.every(arg => typeof arg === 'string'))
178
179
  throw new Error(`${event}: fallback must be an argv vector`);
179
- const problem = fallbackProblem(fallback, host, event);
180
+ const problem = nativeOnly && fallback.length === 0 ? null : fallbackProblem(fallback, host, event);
180
181
  const covered = !reason && !problem && target?.events.includes(canonical);
181
- const nativeArgv = [engine, 'run', '--host', host, event, '--hq-root', root, '--fleet-fallback', JSON.stringify(fallback)];
182
- const handBack = covered && caps ? engineHandBack(caps, nativeArgv, env, options.handBackQuery) : null;
182
+ const nativeArgv = fallback.length > 0
183
+ ? [engine, 'run', '--host', host, event, '--hq-root', root, '--fleet-fallback', JSON.stringify(fallback)]
184
+ : [engine, 'run', '--host', host, event, '--hq-root', root];
185
+ const handBack = covered && caps && fallback.length > 0 ? engineHandBack(caps, nativeArgv, env, options.handBackQuery) : null;
183
186
  const native = covered && !handBack;
184
187
  const argv = native ? nativeArgv : fallback;
185
188
  const why = native ? 'complete evaluator and hook coverage' : handBack ?? reason ?? problem ?? (caps && missingEvaluators(caps, canonical)?.length ? 'required evaluators are missing' : `uncovered hooks: ${uncoveredHooks(root, host, canonical, caps?.covers, env).join(', ')}`);
@@ -161,6 +161,7 @@
161
161
  ],
162
162
  ".claude/hooks/hook-timeout-probe.sh": [
163
163
  "167003cbe1207144572365d78dbca4e285d5889885d1332b99c58081035c24be",
164
+ "3529d40c72f5da406ec324f5a37546ce8755da4f0889dacfdb496c7adb3bd2e7",
164
165
  "3c5716f75fa21f238e19ff82f57181dbd1501e7bf2b0628416173ca694ab2e5d",
165
166
  "3c72f4b8610beabbd43f96cad1752e50f94a91ed9f7706bbd91ed85c106e2faf",
166
167
  "51762806ca5d2cef64c654c3b8a19a92abc95e69da19e4e5156dc43ad0f7bda3",
@@ -209,6 +210,7 @@
209
210
  "baae190dc352bc85e1d452027d46b7a0703f8dc56a9c496adedbd7a767b3c8ce",
210
211
  "cb03a3e05f90ab95c5152c29ea6361528d63d1e3eb66aea11df80dfac3d41d61",
211
212
  "d89b30e5c8017b68db1d093c91dd9aa6a00605855a3eb94fc311b8f729e13833",
213
+ "da5296ec24dece22b694c406d5a5a4aa53b0491110c4fd1779ed25d9ea2daebe",
212
214
  "e6d7b86b58a0d325938817d4318a6fbebdcd153ce680398514451c6684f781b0",
213
215
  "e750ab8b96cefcac007088f1fb583ff56af8a1169666656518b862296a149f0c",
214
216
  "e8f2f3d22d44b1909e3b1fe9e10d023d273bc2f856ded9fea76b6f3a9c52f9c2",
@@ -297,7 +299,8 @@
297
299
  "e2286d05303df29a656ea71ed160385d669c4e47c1dc168c349d660e18a17dc2",
298
300
  "efc23d2ccbfad6b70580617a7f5bb4e1e314a41bcee5c5a251c094b54cd07fbc",
299
301
  "f8591f1728b4ec848fd3455032c09dcd66a1e7813a7910c99b0cae3f7fcf96d0",
300
- "f8f2e3dd853332fd009bb0836c81c717a2892ed71ee94150427290dd4c8ab57f"
302
+ "f8f2e3dd853332fd009bb0836c81c717a2892ed71ee94150427290dd4c8ab57f",
303
+ "fab0ada24e4ac09e05eb5293a795f7f2bde4d58b47ac5112bfc8a5ad4900eda5"
301
304
  ],
302
305
  "core/scripts/lib/session-scope-capability.sh": [
303
306
  "038670d6973a1dc14da63b742a7c90c47a032916e8c8d072147456977da1a298",
@@ -306,6 +309,7 @@
306
309
  "148375c67f8cc7d059f6eb36ec507f8f3f3cb05cad2f81229748fb20af21755b",
307
310
  "3194d664e3840dcbf48a2d5681feb7cd299bd6f60d296337c70d8042d60886c2",
308
311
  "388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead",
312
+ "498ffa6e4342c79eecb0c1fddec56ba03e169bb627b2da8f8ef2f09f55954b38",
309
313
  "5d4c619a55db0de6ff210a3aa0e99aa92fb5795a3290dcfcafc141e3ad3894b6",
310
314
  "743d9438922f0bcc29f09b38f159b4fd686cc2ba15390602ef7b7f1d8db9ac26",
311
315
  "9ea044084200e5f2d1f47477ffeaf591a87b406e9bf48c8fd6e24c551c799fc1",
@@ -343,6 +347,7 @@
343
347
  "1ca40fbd5a58474ab801384becdd5c58340adf8d5c678d41fd7b867aa06136c4",
344
348
  "1e38462b0ee9075da598da7bf8589238bf4884b8433ee391f1278ea82f8fe8dc",
345
349
  "3017517bbcd618be5162c621105c229aeba66fea1c39f6dd744416029f0448b5",
350
+ "32c5c8d50cae02e8850bf08bfbd7ff4b614fa178902b27dfb342ac210a9ef7ab",
346
351
  "5f116978283ba812ba72290736af767dbf41e9b80f7985d919f23d185c4eb17d",
347
352
  "70d56899659145c75024138919043b8f0a77c1ec6c3949ae97f66a5cbf582e4b",
348
353
  "81197d6c024845d955acab7d9a0a74e5a1a2fb54e3cfbd95f0bc15d846b4e3f6",
@@ -371,6 +376,7 @@
371
376
  "8e54096bce6e3f2017e70264bef2e94c08024f26c6d917fc7c0ff285d50c36c4",
372
377
  "ab289ac0af680fe3bcacb110302ca8b998bdc33c6f94321d42bd04a344163eed",
373
378
  "c96c7c92dd4986de20a889e04a64aebe876791fbb5189beabbf6a2c14e6b435b",
379
+ "d1d7e7d0231131afc1a49547018207e9bf4df03808aca3fda8f25fedade15b2f",
374
380
  "e15d5d0f94824748d0ab9ceff10c6c4e2a853cd7ed2452bf9e97f11efcb1c823",
375
381
  "fb798116f1428e3c9a613947930874572c8556287d54470343ee33e6d9fa7854"
376
382
  ],