@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.
Files changed (45) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/contracts/host-canary-release.json +7 -7
  3. package/dist/commands/core-job-notify-native.d.ts +6 -0
  4. package/dist/commands/core-job-notify-native.js +64 -4
  5. package/dist/commands/core-jobs-native.js +3 -16
  6. package/dist/commands/install-global.js +54 -17
  7. package/dist/lib/daemon/machine-check-owner.js +1 -1
  8. package/dist/lib/daemon/machine-checks.d.ts +3 -11
  9. package/dist/lib/daemon/machine-checks.js +4 -15
  10. package/dist/lib/doctor/checks/codex-wiring.d.ts +4 -2
  11. package/dist/lib/doctor/checks/codex-wiring.js +70 -13
  12. package/dist/lib/doctor/checks/fleet-hook-core.d.ts +4 -4
  13. package/dist/lib/doctor/checks/fleet-hook-core.js +5 -10
  14. package/dist/lib/doctor/checks/grok-wiring.js +38 -0
  15. package/dist/lib/doctor/checks/hook-engine.js +0 -2
  16. package/dist/lib/doctor/checks/host-core.d.ts +1 -1
  17. package/dist/lib/doctor/checks/host-core.js +8 -38
  18. package/dist/lib/hook-engine/coverage.d.ts +10 -1
  19. package/dist/lib/hook-engine/coverage.js +63 -8
  20. package/dist/lib/hook-engine/fleet-registration.js +7 -4
  21. package/dist/lib/hook-engine/native-precompact-compatibility.json +7 -1
  22. package/dist/lib/hook-engine/native-stop-compatibility.json +30 -11
  23. package/dist/lib/hook-engine/reconcile.d.ts +10 -1
  24. package/dist/lib/hook-engine/reconcile.js +339 -42
  25. package/dist/lib/hook-engine/stable-gate.d.ts +43 -0
  26. package/dist/lib/hook-engine/stable-gate.js +276 -0
  27. package/dist/lib/hot-channels/fleet-complete.js +2 -2
  28. package/dist/lib/install/antigravity-targets.js +2 -1
  29. package/dist/lib/install/claude-targets.d.ts +6 -6
  30. package/dist/lib/install/claude-targets.js +13 -9
  31. package/dist/lib/install/codex-targets.d.ts +4 -4
  32. package/dist/lib/install/codex-targets.js +26 -16
  33. package/dist/lib/install/hook-target.d.ts +23 -2
  34. package/dist/lib/install/hook-target.js +89 -16
  35. package/dist/lib/outpost-identity-env.d.ts +18 -0
  36. package/dist/lib/outpost-identity-env.js +29 -0
  37. package/dist/lib/signals/steps/extract.js +46 -12
  38. package/dist/utils/core-next-kill.d.ts +2 -15
  39. package/dist/utils/core-next-kill.js +5 -36
  40. package/dist/utils/hook-engine-rollup.js +0 -1
  41. package/dist/utils/hook-trust.d.ts +2 -0
  42. package/dist/utils/hook-trust.js +156 -13
  43. package/dist/utils/host-registration.d.ts +158 -4
  44. package/dist/utils/host-registration.js +500 -17
  45. package/package.json +7 -7
package/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [5.345.268] — 2026-11-29
6
+ - Isolate `SCCACHE_SERVER_PORT` and local `SCCACHE_DIR` per runner (`beaker` -> port `4226` / `hq-sccache/beaker`, `beaker-2` -> port `4227` / `hq-sccache/beaker-2`) in all Beaker `Configure sccache (Beaker)` workflow steps so concurrent `beaker` and `beaker-2` jobs on the same Windows host do not collide on `127.0.0.1:4226` or share a local cache directory.
7
+ - Speed up hq-hook builds on the Beaker Windows runners: the release-tag Windows job builds in the workspace target folder again instead of a per-runner folder outside the checkout, and the release-tag, train build-archive and train Clippy jobs on Beaker use the machine-local compiler cache instead of the shared S3 cache, which those jobs could only read and which held no Beaker builds.
8
+ - Rebalance hq-hook Windows Beaker test shards from measured per-binary durations with exact-cover checks, schedule the main Windows baseline behind an immediate-exit freshness and train-priority gate aligned with `beaker-baseline.mjs`, and ignore gate-skipped baseline runs in baseline readers.
9
+ - Declare scalar `test:` fields on the `auto-checkpoint-git-submodule` and `auto-checkpoint-git-gitlink-fails` rows in `US-049-auto-checkpoint/conditional-differences.yaml` and drop the stale `ledger-reference-baseline.tsv` entry left behind by #4226.
10
+ - Native auto-checkpoint now reads repositories that hold nested repositories (gitlinks, with or without `.gitmodules`) as `git status` does, so PostToolUse calls in an HQ root with nested repos no longer stop with "the repository has submodules".
11
+ - On Windows, the native `block-hq-worktree-session` port finds `node.exe` on Git Bash's tool folders again (a #4111 regression used a `:`-separated, exact-name lookup), so it refuses with the flag-service reason when the legacy flag reader would ask the service. Four Windows-only hq-hook tests no longer depend on the runner: the command-guard reference bash gets Git Bash's hook `PATH`, the custom-hook job test drives `--custom-hooks` instead of the removed launcher, and the scope breaker test expects the Windows credential-guard refusal where that guard runs first.
12
+ - `hq core job notify` now delivers scheduled-job alerts on Outposts where the job owner is the box's own user id (`OUTPOST_USER_ID`) and `hq whoami` cannot map it to an email, which includes every company Outpost. It reads the owner email from `OUTPOST_OWNER_EMAIL` or `OWNER_EMAIL` in the process env or in `/etc/outpost/codex-identity.env`. When no email is found, the result reports `"reason":"unresolved_owner_id"`.
13
+ - Native scope check now matches the hq-core 16.0.53 script for Windows interpreter path arguments, directory-changing shell commands, env/genv options, command substitutions inside text, path-led message values, remote positions, and unquoted or piped arguments.
14
+ - Changed: the host canary record shipped with the CLI is rebuilt on the final 5.345.268 engine.
15
+ - Changed: the host canary record shipped with the CLI is refreshed for the 5.345.268 release build.
16
+ - Signals: when the extract step runs on a bot's own login, a helper that started and then errored now fails only that item instead of moving the rest of the run to the Claude command-line login. An item too large for the bot's helper runs alone on the command-line path, and later items stay on the bot's login; if the command-line login is signed out, only that item fails and the run continues. The bot sign-in message now names the provider (`hq bot auth <bot> --provider <provider>`).
17
+ - Speed up the batch-train script tests: the test driver caches each workflow file's js-yaml parse by content, so the 264 scenarios run 4 js-yaml parses instead of about 480. Same scenarios and assertions.
18
+ - Removed: Remove the engine bridge CLI, shadow mode, hash-pin manifest, and `block-hq-grep` hook port from `hq-hook` (US-027) while keeping `block-hq-grep` in `COVERS` for older core compatibility and registering native `hq-hook` entries across Claude, Codex, Grok, and fleet roots without legacy shell scripts.
19
+ - Removed: Remove the hook-engine and `core.next` kill switches (`HQ_CORE_NEXT=off|0|false|no`, `~/.hq/state/core-next.off`, `HQ_HOOK_ENGINE=off`, `~/.hq/hook-engine.off`) and legacy `master-hook.sh` hand-off paths so registered hooks always run natively through `hq-hook`.
20
+
5
21
  ## [5.345.267] — 2026-11-29
6
22
  - Speed up `scope_bash` tests on Windows by reusing the test binary when already outside an HQ tree and evaluating large spelling matrices in-process.
7
23
  - Update the legacy journal gate test fixture to use the current sync-core release.
@@ -1,24 +1,24 @@
1
1
  {
2
2
  "schema": "hq.host-canary-release.v1",
3
- "cliVersion": "5.345.267",
3
+ "cliVersion": "5.345.268",
4
4
  "hosts": {
5
5
  "claude": [
6
6
  {
7
7
  "passed": true,
8
- "at": "2026-11-29T01:51:00.420Z",
9
- "engineVersion": "0.3.1+hq.5.345.267.src.c375d0eb695aa9f21ff586e2e2ba338378e314b5403cca2f42a102a095ba2e48",
8
+ "at": "2026-11-29T15:40:03.563Z",
9
+ "engineVersion": "0.3.1+hq.5.345.268.src.1bc679792c3384cb9e00562515a145b7a3c05a3692fda4f61b0989900ce7470d",
10
10
  "gateSha256": "a2879dfe692233f5953bac86672947bbd82f3c5247292f3efcb80f16c3d2c6b1"
11
11
  },
12
12
  {
13
13
  "passed": true,
14
- "at": "2026-11-29T01:51:20.915Z",
15
- "engineVersion": "0.3.1+hq.5.345.267.src.c375d0eb695aa9f21ff586e2e2ba338378e314b5403cca2f42a102a095ba2e48",
14
+ "at": "2026-11-29T15:40:24.985Z",
15
+ "engineVersion": "0.3.1+hq.5.345.268.src.1bc679792c3384cb9e00562515a145b7a3c05a3692fda4f61b0989900ce7470d",
16
16
  "gateSha256": "ca58a94859eae0a345c11c8d9c59303eb76350dc1cf223391037d21979c28718"
17
17
  },
18
18
  {
19
19
  "passed": true,
20
- "at": "2026-11-29T01:52:01.744Z",
21
- "engineVersion": "0.3.1+hq.5.345.267.src.c375d0eb695aa9f21ff586e2e2ba338378e314b5403cca2f42a102a095ba2e48",
20
+ "at": "2026-11-29T15:41:04.610Z",
21
+ "engineVersion": "0.3.1+hq.5.345.268.src.1bc679792c3384cb9e00562515a145b7a3c05a3692fda4f61b0989900ce7470d",
22
22
  "gateSha256": "ecdbab7c2e0a1d94eb9c98f15e760390f215bc7115a217ded24b4275322722d2"
23
23
  }
24
24
  ]
@@ -16,6 +16,12 @@ export type JobNotifyDependencies = {
16
16
  * `hq whoami` (hq-core-rust US-036). Default: src/lib/daemon/whoami-cache.ts.
17
17
  */
18
18
  daemonWhoami?: (json: boolean) => string | null;
19
+ /**
20
+ * The Outpost identity env file read for the box's user id and owner email
21
+ * (default /etc/outpost/codex-identity.env). Skipped when
22
+ * HQ_JOB_SKIP_SYSTEM_IDENTITY=1.
23
+ */
24
+ identityFile?: string;
19
25
  env: Environment;
20
26
  cwd: string;
21
27
  now: () => Date;
@@ -7,6 +7,7 @@ import { spawnSync } from "node:child_process";
7
7
  import { load } from "js-yaml";
8
8
  import { serializeJqJson } from "../lib/core-utils/jq-json-serializer.js";
9
9
  import { registerCoreJobLeaf } from "./core-job-native-utils.js";
10
+ import { OUTPOST_IDENTITY_ENV_FILE, parseOutpostIdentityAssignments } from "../lib/outpost-identity-env.js";
10
11
  const USAGE = [
11
12
  "hq-job-notify.sh — dm-only remediation alerts for Outpost scheduled jobs (US-006).",
12
13
  "",
@@ -210,7 +211,7 @@ const COGNITO_SUB = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{1
210
211
  function cachedWhoami(deps, json) {
211
212
  return (deps.daemonWhoami ?? ((asJson) => daemonWhoamiOutput(asJson, deps.env)))(json);
212
213
  }
213
- function resolveCognitoOwner(owner, deps) {
214
+ function whoamiOwnerEmail(owner, deps) {
214
215
  if (!deps.commandExists("hq"))
215
216
  return "";
216
217
  let parsed;
@@ -235,6 +236,63 @@ function resolveCognitoOwner(owner, deps) {
235
236
  }
236
237
  return "";
237
238
  }
239
+ function identityValue(value) {
240
+ const trimmed = (value ?? "").trim();
241
+ return trimmed === "null" ? "" : trimmed;
242
+ }
243
+ function identityFileSource(deps) {
244
+ const empty = { userId: "", emails: [] };
245
+ if (deps.env.HQ_JOB_SKIP_SYSTEM_IDENTITY === "1")
246
+ return empty;
247
+ let contents;
248
+ try {
249
+ contents = deps.readFile(deps.identityFile ?? OUTPOST_IDENTITY_ENV_FILE);
250
+ }
251
+ catch {
252
+ return empty;
253
+ }
254
+ const last = {};
255
+ // Later assignments win, as when the file is sourced by a shell.
256
+ for (const { key, value } of parseOutpostIdentityAssignments(contents))
257
+ last[key] = value;
258
+ return {
259
+ userId: identityValue(last.OUTPOST_USER_ID),
260
+ emails: [identityValue(last.OUTPOST_OWNER_EMAIL), identityValue(last.OWNER_EMAIL)],
261
+ };
262
+ }
263
+ /**
264
+ * The box's own owner email when `owner` is this Outpost's user id
265
+ * (OUTPOST_USER_ID), from the process env or the Outpost identity env file.
266
+ * Company Outposts and machine sessions whose cached token carries no
267
+ * delegated owner resolve here. An email is used only from a source whose own
268
+ * OUTPOST_USER_ID equals the owner, and nothing resolves when the env and the
269
+ * file name different user ids.
270
+ */
271
+ function outpostIdentityOwnerEmail(owner, deps) {
272
+ const target = owner.toLowerCase();
273
+ const envSource = {
274
+ userId: identityValue(deps.env.OUTPOST_USER_ID),
275
+ emails: [identityValue(deps.env.OUTPOST_OWNER_EMAIL), identityValue(deps.env.OWNER_EMAIL)],
276
+ };
277
+ const named = [envSource, identityFileSource(deps)].filter((source) => source.userId);
278
+ if (named.length === 0 || named.some((source) => source.userId.toLowerCase() !== target))
279
+ return "";
280
+ for (const source of named) {
281
+ const email = source.emails.find((candidate) => EMAIL_RECIPIENT.test(candidate));
282
+ if (email)
283
+ return email;
284
+ }
285
+ return "";
286
+ }
287
+ function resolveCognitoOwner(owner, deps) {
288
+ const fromWhoami = whoamiOwnerEmail(owner, deps);
289
+ if (fromWhoami)
290
+ return { recipient: fromWhoami, via: "hq whoami" };
291
+ const fromIdentity = outpostIdentityOwnerEmail(owner, deps);
292
+ if (fromIdentity)
293
+ return { recipient: fromIdentity, via: "the Outpost identity env" };
294
+ return { recipient: "", via: "" };
295
+ }
238
296
  function normalizedEpoch(value) {
239
297
  if (!/^-?\d+$/.test(value))
240
298
  throw new Error(`invalid HQ_JOB_NOTIFY_NOW_EPOCH: ${value}`);
@@ -303,11 +361,12 @@ export function runJobNotify(argv, options = {}) {
303
361
  let recipient = owner;
304
362
  const cognitoOwner = Boolean(owner) && COGNITO_SUB.test(owner);
305
363
  if (cognitoOwner) {
306
- recipient = resolveCognitoOwner(owner, deps);
364
+ const resolved = resolveCognitoOwner(owner, deps);
365
+ recipient = resolved.recipient;
307
366
  if (recipient)
308
- log(`owner ${owner} is a Cognito user id — delivering to ${recipient}`);
367
+ log(`owner ${owner} is a Cognito user id — delivering to ${recipient} (from ${resolved.via})`);
309
368
  else {
310
- log(`owner ${owner} is a Cognito user id that hq dm cannot address and hq whoami does not report it — set the job owner to an email or prs_ uid (logged only); never fails the job`);
369
+ log(`owner ${owner} is a Cognito user id that hq dm cannot address, and neither hq whoami nor the Outpost identity env maps it to an email — set the job owner to an email or prs_ uid (logged only); never fails the job`);
311
370
  deps.appendFile(deliveryLog, '{"delivered":false,"reason":"unresolved_owner_id"}\n');
312
371
  }
313
372
  }
@@ -400,6 +459,7 @@ export function runJobNotify(argv, options = {}) {
400
459
  kind,
401
460
  owner,
402
461
  ...(cognitoOwner ? { recipient: recipient || null } : {}),
462
+ ...(cognitoOwner && !recipient ? { reason: "unresolved_owner_id" } : {}),
403
463
  channel_unimplemented: channelUnimplemented === 1,
404
464
  deliver_rc: deliverRc,
405
465
  }, "compact"));
@@ -9,6 +9,7 @@ import { serializeJqJson } from "../lib/core-utils/jq-json-serializer.js";
9
9
  import { resolveLiveRoot } from "../utils/hq-roots.js";
10
10
  import { describeCoreCommand } from "./core-command-catalog.js";
11
11
  import { runScheduleParse } from "./core-jobs-schedule.js";
12
+ import { OUTPOST_IDENTITY_ENV_FILE, parseOutpostIdentityAssignments } from "../lib/outpost-identity-env.js";
12
13
  export { detectHostTimezone, runScheduleParse } from "./core-jobs-schedule.js";
13
14
  const VALIDATE_USAGE = "usage: jobs-validate.sh <file-or-dir> [file-or-dir...]\n";
14
15
  function isValidCronField(value, minimum, maximum) {
@@ -451,26 +452,12 @@ function shellText(value) {
451
452
  return String(value);
452
453
  }
453
454
  function parseIdentityAssignments(contents) {
454
- const values = [];
455
- for (const line of contents.split(/\r?\n/)) {
456
- const assignment = /^\s*(?:export\s+)?(OUTPOST_USER_ID|OUTPOST_OWNER_EMAIL|OWNER_EMAIL)\s*=\s*(.*?)\s*$/.exec(line);
457
- if (!assignment)
458
- continue;
459
- let value = assignment[2] ?? "";
460
- if ((value.startsWith("'") && value.endsWith("'")) || (value.startsWith('"') && value.endsWith('"'))) {
461
- value = value.slice(1, -1);
462
- }
463
- else {
464
- value = value.replace(/\s+#.*$/, "");
465
- }
466
- values.push(value);
467
- }
468
- return values;
455
+ return parseOutpostIdentityAssignments(contents).map((assignment) => assignment.value);
469
456
  }
470
457
  function identityFileTokens(options) {
471
458
  if (process.env.HQ_JOB_SKIP_SYSTEM_IDENTITY === "1")
472
459
  return [];
473
- const filename = "/etc/outpost/codex-identity.env";
460
+ const filename = OUTPOST_IDENTITY_ENV_FILE;
474
461
  try {
475
462
  const contents = options.identityFileReader
476
463
  ? options.identityFileReader(filename)
@@ -1,4 +1,7 @@
1
- import { hookTargetFor } from '../lib/install/hook-target.js';
1
+ import { resolveInstallHookTarget } from '../lib/install/hook-target.js';
2
+ import { isNativeOnlyCoreRoot } from '../lib/hook-engine/coverage.js';
3
+ import { HQ_CLI_NPM_REPAIR_COMMAND } from '../utils/npm-install-flags.js';
4
+ import { resolvePortableEngineForNativeOnly } from '../utils/host-registration.js';
2
5
  /**
3
6
  * `hq install --global --runtime claude` / `hq uninstall --global --runtime claude`
4
7
  * (hq-anywhere-runtime US-005).
@@ -138,16 +141,39 @@ function canonical(v) {
138
141
  : val);
139
142
  }
140
143
  /** JSON settings format whose verify step checks every HQ hook is registered. */
141
- function settingsInstallFormat(hqRoot, target) {
144
+ function settingsInstallFormat(hqRoot, target, platform = process.platform) {
142
145
  return {
143
146
  ...jsonFormat,
144
147
  emptyDoc: () => ({}),
145
148
  assertEntry(doc) {
146
- if (!hasAllHqHooks(doc, hqRoot, target))
149
+ if (!hasAllHqHooks(doc, hqRoot, target, platform))
147
150
  throw new Error('HQ hooks not present after write');
148
151
  },
149
152
  };
150
153
  }
154
+ /**
155
+ * When writing a portable native wrapper for a native-only HQ root, ensure
156
+ * `<home>/.hq/bin/hq-hook/stable` exists and points to an accepted engine
157
+ * before writing any host settings. When `core.next` is on and the host canary
158
+ * gate refused the new engine (M-2), falls back only to a previously accepted
159
+ * engine already linked at `stable` and never links the refused engine.
160
+ * Refuses clearly when no accepted engine is available so global install never
161
+ * writes a wrapper that blocks every session or runs a canary-refused engine.
162
+ */
163
+ function ensurePortableEngineOrThrow(hqRoot, home, target, env, host, platform, refusedCandidate) {
164
+ if (target !== 'portable')
165
+ return;
166
+ const resolution = resolvePortableEngineForNativeOnly(home, {
167
+ platform,
168
+ env,
169
+ host,
170
+ root: hqRoot,
171
+ candidate: refusedCandidate ?? null,
172
+ });
173
+ if (!resolution.stable) {
174
+ throw Object.assign(new Error(`Cannot install HQ global hooks for native-only HQ root ${hqRoot}: ${resolution.refusalReason ?? `repair with: ${HQ_CLI_NPM_REPAIR_COMMAND}`}`), { expected: true });
175
+ }
176
+ }
151
177
  /**
152
178
  * Removal format: verifies no HQ hook remains, and serializes a doc that equals
153
179
  * the pre-install document back to the ORIGINAL bytes (byte-identical uninstall).
@@ -347,7 +373,10 @@ function readState(t) {
347
373
  function assertHqRoot(hqRoot) {
348
374
  if (!path.isAbsolute(hqRoot))
349
375
  throw new Error(`HQ root must be absolute: ${hqRoot}`);
350
- for (const p of [charterPath(hqRoot), masterHookPath(hqRoot)]) {
376
+ const required = isNativeOnlyCoreRoot(hqRoot)
377
+ ? [charterPath(hqRoot)]
378
+ : [charterPath(hqRoot), masterHookPath(hqRoot)];
379
+ for (const p of required) {
351
380
  if (!fs.existsSync(p))
352
381
  throw new Error(`${hqRoot} is not an HQ checkout (missing ${p})`);
353
382
  }
@@ -419,10 +448,11 @@ export function installGlobalClaude(opts) {
419
448
  const marketplaceNeedsAdd = !!pluginSource && existingMarketplace === undefined;
420
449
  const pluginAdded = !!pluginSource && (prior?.plugin?.pluginAdded === true || pluginNeedsInstall);
421
450
  const marketplaceAdded = !!pluginSource && (prior?.plugin?.marketplaceAdded === true || marketplaceNeedsAdd);
422
- const hookTarget = hookTargetFor(hqRoot, home, opts.daemonInstalled, env);
451
+ const platform = opts.platform ?? process.platform;
452
+ const { target: hookTarget, refusedCandidate } = resolveInstallHookTarget(hqRoot, home, opts.daemonInstalled, env, 'claude', platform);
423
453
  const settingsNext = pluginSource
424
454
  ? cleanupRoots.reduce((doc, root) => removeHqHooks(doc, root), settingsDoc)
425
- : addHqHooks(settingsDoc, hqRoot, hookTarget);
455
+ : addHqHooks(settingsDoc, hqRoot, hookTarget, platform);
426
456
  const skillLinksToRemove = [...new Set(pluginSource
427
457
  ? cleanupRoots.flatMap((root) => hqSkillLinksForRoot(t.skillsDir, root))
428
458
  : cleanupRoots.flatMap((root) => hqCompanySkillLinksForRoot(t.skillsDir, root)))];
@@ -468,6 +498,8 @@ export function installGlobalClaude(opts) {
468
498
  log(`Would run: claude plugin marketplace add --scope user ${pluginSource.sourceDir}; claude plugin install --scope user -y ${pluginSource.pluginId}`);
469
499
  return touched;
470
500
  }
501
+ if (!pluginSource)
502
+ ensurePortableEngineOrThrow(hqRoot, home, hookTarget, env, 'claude', platform, refusedCandidate);
471
503
  if (pluginSource && (marketplaceNeedsAdd || pluginNeedsInstall)) {
472
504
  let marketplaceMayNeedRollback = false;
473
505
  try {
@@ -555,8 +587,8 @@ export function installGlobalClaude(opts) {
555
587
  writeConfigAtomic({
556
588
  target: t.settingsJson,
557
589
  pack: HQ_ANYWHERE_PACK,
558
- format: settingsInstallFormat(hqRoot, hookTarget),
559
- merge: (doc) => addHqHooks(doc, hqRoot, hookTarget),
590
+ format: settingsInstallFormat(hqRoot, hookTarget, platform),
591
+ merge: (doc) => addHqHooks(doc, hqRoot, hookTarget, platform),
560
592
  assertName: 'hooks',
561
593
  env: { home },
562
594
  });
@@ -607,7 +639,7 @@ export function installGlobalClaude(opts) {
607
639
  if (pluginSource)
608
640
  log(` plugin: ${pluginSource.pluginId} installed from ${pluginSource.sourceDir}; direct hooks and MCP entries removed`);
609
641
  else {
610
- log(` hooks: ${typeof hookTarget === 'object' ? ('coreNext' in hookTarget ? hookTarget.coreNext : hookTarget.engine) : hookTarget === 'shim' ? 'hqd-hook-shim.sh' : 'master-hook.sh'} registered in ${t.settingsJson}`);
642
+ log(` hooks: ${typeof hookTarget === 'object' ? ('coreNext' in hookTarget ? hookTarget.coreNext : hookTarget.engine) : hookTarget === 'portable' ? 'hq-hook (portable)' : hookTarget === 'shim' ? 'hqd-hook-shim.sh' : 'master-hook.sh'} registered in ${t.settingsJson}`);
611
643
  log(` MCP: "${HQ_MCP_SERVER_NAME}" registered in ${t.claudeJson}`);
612
644
  }
613
645
  log(` registry: ${seeded.length} manifest entr${seeded.length === 1 ? 'y' : 'ies'} seeded`);
@@ -792,17 +824,20 @@ function readCodexState(t) {
792
824
  function assertCodexHqRoot(hqRoot) {
793
825
  if (!path.isAbsolute(hqRoot))
794
826
  throw new Error(`HQ root must be absolute: ${hqRoot}`);
795
- for (const p of [codexCharterSource(hqRoot), codexAdapterPath(hqRoot)]) {
827
+ const required = isNativeOnlyCoreRoot(hqRoot)
828
+ ? [codexCharterSource(hqRoot)]
829
+ : [codexCharterSource(hqRoot), codexAdapterPath(hqRoot)];
830
+ for (const p of required) {
796
831
  if (!fs.existsSync(p))
797
832
  throw new Error(`${hqRoot} is not an HQ checkout (missing ${p})`);
798
833
  }
799
834
  }
800
- function hooksInstallFormat(hqRoot, target) {
835
+ function hooksInstallFormat(hqRoot, target, platform = process.platform) {
801
836
  return {
802
837
  ...jsonFormat,
803
838
  emptyDoc: () => ({}),
804
839
  assertEntry(doc) {
805
- if (!hasAllCodexHooks(doc, hqRoot, target))
840
+ if (!hasAllCodexHooks(doc, hqRoot, target, platform))
806
841
  throw new Error('HQ Codex hooks not present after write');
807
842
  },
808
843
  };
@@ -850,10 +885,11 @@ export function installGlobalCodex(opts) {
850
885
  }
851
886
  const skills = planSkills(hqRoot, t);
852
887
  const companySkillLinksToRemove = [...new Set(cleanupRoots.flatMap((root) => hqCompanySkillLinksForRoot(t.skillsDir, root)))];
888
+ const platform = opts.platform ?? process.platform;
853
889
  const hooksOld = readOrNull(t.hooksJson);
854
890
  const hooksDoc = readConfigDoc(t.hooksJson, jsonFormat).doc;
855
- const hookTarget = hookTargetFor(hqRoot, home, opts.daemonInstalled, env, 'codex');
856
- const hooksNext = addCodexHooks(hooksDoc, hqRoot, hookTarget);
891
+ const { target: hookTarget, refusedCandidate } = resolveInstallHookTarget(hqRoot, home, opts.daemonInstalled, env, 'codex', platform);
892
+ const hooksNext = addCodexHooks(hooksDoc, hqRoot, hookTarget, platform);
857
893
  const tomlOld = readOrNull(t.configToml);
858
894
  const tomlDoc = readConfigDoc(t.configToml, codexConfigFormat).doc;
859
895
  const codexServers = tomlDoc.value.mcp_servers;
@@ -903,6 +939,7 @@ export function installGlobalCodex(opts) {
903
939
  log(lineDiff(codexConfigFormat.serialize(tomlDoc), codexConfigFormat.serialize(tomlNext)));
904
940
  return touched;
905
941
  }
942
+ ensurePortableEngineOrThrow(hqRoot, home, hookTarget, env, 'codex', platform, refusedCandidate);
906
943
  // Skill links go first so a link failure leaves no pointer or AGENTS.md
907
944
  // block behind (see installGlobalClaude).
908
945
  const skillsDirExisted = fs.existsSync(t.skillsDir);
@@ -945,8 +982,8 @@ export function installGlobalCodex(opts) {
945
982
  writeConfigAtomic({
946
983
  target: t.hooksJson,
947
984
  pack: HQ_ANYWHERE_PACK,
948
- format: hooksInstallFormat(hqRoot, hookTarget),
949
- merge: (doc) => addCodexHooks(doc, hqRoot, hookTarget),
985
+ format: hooksInstallFormat(hqRoot, hookTarget, platform),
986
+ merge: (doc) => addCodexHooks(doc, hqRoot, hookTarget, platform),
950
987
  assertName: 'hooks',
951
988
  env: { home },
952
989
  });
@@ -986,7 +1023,7 @@ export function installGlobalCodex(opts) {
986
1023
  log(` skills linked: ${skills.link.length} new, ${skills.already.length} already present, ${skills.skipped.length} skipped`);
987
1024
  reportSkillCopies(linkKinds, log);
988
1025
  reportSkippedSkills(skills, log, false);
989
- log(` hooks: ${typeof hookTarget === 'object' ? ('coreNext' in hookTarget ? hookTarget.coreNext : hookTarget.engine) : hookTarget === 'shim' ? shimPath(hqRoot) : codexAdapterPath(hqRoot)} registered in ${t.hooksJson}`);
1026
+ log(` hooks: ${typeof hookTarget === 'object' ? ('coreNext' in hookTarget ? hookTarget.coreNext : hookTarget.engine) : hookTarget === 'portable' ? 'hq-hook (portable)' : hookTarget === 'shim' ? shimPath(hqRoot) : codexAdapterPath(hqRoot)} registered in ${t.hooksJson}`);
990
1027
  log(` MCP: "${HQ_MCP_SERVER_NAME}" registered in ${t.configToml}`);
991
1028
  return touched;
992
1029
  }
@@ -46,7 +46,7 @@ function decideOwner(env, home, now, platform) {
46
46
  if (platform === "win32")
47
47
  return { owner: "legacy", reason: "windows: machine checks need /bin/bash" };
48
48
  if (!machineChecksScheduleOn(env, home))
49
- return { owner: "legacy", reason: "core.next is off or a kill switch is set" };
49
+ return { owner: "legacy", reason: "core.next is off" };
50
50
  const sessionRoot = env.HQ_ROOT?.trim();
51
51
  let daemonRoot;
52
52
  try {
@@ -155,20 +155,12 @@ export declare const MACHINE_CHECKS_INTERVAL_MS: number;
155
155
  export declare const MACHINE_CHECKS_MIN_INTERVAL_MS: number;
156
156
  /** Use the same offline flag decision as hook registration. */
157
157
  export declare const machineChecksCoreNextOn: typeof coreNextEnabled;
158
- /**
159
- * A switch that sends this machine back to the old hook core is set:
160
- * HQ_CORE_NEXT is off, 0, false or no; HQ_HOOK_ENGINE is off (both trimmed,
161
- * any ASCII case); or `<home>/.hq/state/core-next.off` or
162
- * `<home>/.hq/hook-engine.off` exists (any file type, a link counts). These
163
- * are the switches the hook engine checks.
164
- */
165
- export declare function machineChecksKillSwitchSet(env: NodeJS.ProcessEnv, home: string): boolean;
166
158
  /**
167
159
  * The daemon's schedule runs when the new hook core (`core.next`) is on for
168
- * this machine and no kill switch is set, so the checks leave the hook path
169
- * exactly when the machine moves to the new core and nothing runs twice.
160
+ * this machine, so the checks leave the hook path when the machine moves to
161
+ * the new core and nothing runs twice.
170
162
  */
171
- export declare function machineChecksScheduleOn(env: NodeJS.ProcessEnv, home: string): boolean;
163
+ export declare function machineChecksScheduleOn(env: NodeJS.ProcessEnv, _home: string): boolean;
172
164
  export interface MachineCheckScheduleOptions {
173
165
  env: NodeJS.ProcessEnv;
174
166
  /** The home folder that holds the kill-switch files. */
@@ -37,7 +37,6 @@ import { createHash } from "node:crypto";
37
37
  import * as fs from "node:fs";
38
38
  import * as path from "node:path";
39
39
  import { coreNextEnabled } from "../../utils/core-next-flag.js";
40
- import { coreNextKillReason } from "../../utils/core-next-kill.js";
41
40
  import { isExcludedWindowsBash, resolveWindowsBash } from "../../utils/windows-bash.js";
42
41
  import { anyNativeSessionStartRegistered } from "./machine-check-registration.js";
43
42
  import { nativeNoticeLedgerUsable, nativeNoticeShownFingerprints } from "./native-notice-ledger.js";
@@ -428,23 +427,13 @@ export const MACHINE_CHECKS_INTERVAL_MS = 60 * 60_000;
428
427
  export const MACHINE_CHECKS_MIN_INTERVAL_MS = 15 * 60_000;
429
428
  /** Use the same offline flag decision as hook registration. */
430
429
  export const machineChecksCoreNextOn = coreNextEnabled;
431
- /**
432
- * A switch that sends this machine back to the old hook core is set:
433
- * HQ_CORE_NEXT is off, 0, false or no; HQ_HOOK_ENGINE is off (both trimmed,
434
- * any ASCII case); or `<home>/.hq/state/core-next.off` or
435
- * `<home>/.hq/hook-engine.off` exists (any file type, a link counts). These
436
- * are the switches the hook engine checks.
437
- */
438
- export function machineChecksKillSwitchSet(env, home) {
439
- return coreNextKillReason(home, env) !== null;
440
- }
441
430
  /**
442
431
  * The daemon's schedule runs when the new hook core (`core.next`) is on for
443
- * this machine and no kill switch is set, so the checks leave the hook path
444
- * exactly when the machine moves to the new core and nothing runs twice.
432
+ * this machine, so the checks leave the hook path when the machine moves to
433
+ * the new core and nothing runs twice.
445
434
  */
446
- export function machineChecksScheduleOn(env, home) {
447
- return !machineChecksKillSwitchSet(env, home) && machineChecksCoreNextOn(env);
435
+ export function machineChecksScheduleOn(env, _home) {
436
+ return machineChecksCoreNextOn(env);
448
437
  }
449
438
  /**
450
439
  * The checks to commit in this batch: each whose last result (the results
@@ -55,13 +55,15 @@ export interface CodexWiringOptions {
55
55
  }
56
56
  /** What {@link detectCodexAdapter} learned about `.codex/config.toml`. */
57
57
  export interface CodexAdapterDetection {
58
- /** True when at least one config.toml hook command routes to the adapter. */
58
+ /** True when at least one config.toml hook command routes to the adapter or native hq-hook. */
59
59
  detected: boolean;
60
+ /** Whether `.codex/config.toml` routes via the legacy bash adapter or native `hq-hook`. */
61
+ mode?: "adapter" | "native";
60
62
  /** Whether `.codex/config.toml` exists and was readable. */
61
63
  configPresent: boolean;
62
64
  /** TOML parse failure, when the file exists but could not be parsed. */
63
65
  configParseError: string | null;
64
- /** Events whose config.toml command references the adapter script. */
66
+ /** Events whose config.toml command references the adapter script or native hq-hook. */
65
67
  wiredEvents: string[];
66
68
  }
67
69
  /**
@@ -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');