@indigoai-us/hq-cli 5.345.251 → 5.345.253

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 (188) hide show
  1. package/CHANGELOG.md +153 -0
  2. package/assets/scaffold/core/scripts/hq-session.sh +9 -0
  3. package/contracts/host-canary-release.json +9 -3
  4. package/dist/command-catalog.generated.d.ts +269 -1
  5. package/dist/command-catalog.generated.js +330 -1
  6. package/dist/command-registration-plan.d.ts +6 -0
  7. package/dist/command-registration-plan.js +1 -0
  8. package/dist/commands/bot.js +7 -2
  9. package/dist/commands/ci-intake.d.ts +15 -0
  10. package/dist/commands/ci-intake.js +252 -0
  11. package/dist/commands/ci-metrics.d.ts +8 -0
  12. package/dist/commands/ci-metrics.js +55 -0
  13. package/dist/commands/ci.d.ts +13 -0
  14. package/dist/commands/ci.js +10 -0
  15. package/dist/commands/core-bucket-c-work-mesh-offer-native.js +1 -1
  16. package/dist/commands/core-hq-session-binding.d.ts +140 -0
  17. package/dist/commands/core-hq-session-binding.js +363 -0
  18. package/dist/commands/core-hq-session-native.d.ts +23 -0
  19. package/dist/commands/core-hq-session-native.js +59 -9
  20. package/dist/commands/core-stop-autosave.js +1 -1
  21. package/dist/commands/core.js +10 -0
  22. package/dist/commands/doctor.d.ts +5 -1
  23. package/dist/commands/doctor.js +42 -5
  24. package/dist/commands/files.d.ts +62 -0
  25. package/dist/commands/files.js +250 -9
  26. package/dist/commands/install-global.js +4 -2
  27. package/dist/commands/logout.js +4 -0
  28. package/dist/commands/ontology-graph.d.ts +2 -0
  29. package/dist/commands/ontology-graph.js +33 -0
  30. package/dist/commands/report.js +35 -2
  31. package/dist/commands/storage-gate.js +1 -1
  32. package/dist/commands/vault-retention-flag.js +2 -1
  33. package/dist/commands/whoami.js +1 -1
  34. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +238 -221
  35. package/dist/hq-cloud-sync-runner/package.json +1 -1
  36. package/dist/index.js +3 -1
  37. package/dist/lib/agent-kit/inbox-poll-backoff-flag.js +1 -1
  38. package/dist/lib/agent-kit/mcp/tools.js +48 -0
  39. package/dist/lib/bot/fleet-bots-update-pass.js +1 -1
  40. package/dist/lib/bot/fleet-cron.d.ts +50 -0
  41. package/dist/lib/bot/fleet-cron.js +173 -32
  42. package/dist/lib/bot/fleet-local.d.ts +18 -0
  43. package/dist/lib/bot/fleet-local.js +51 -5
  44. package/dist/lib/bot/inbox-poll-backoff-flag.js +1 -1
  45. package/dist/lib/bot/signals-engine-flag.d.ts +1 -1
  46. package/dist/lib/bot/signals-engine-flag.js +1 -1
  47. package/dist/lib/cli-invite-nudge.js +1 -1
  48. package/dist/lib/client-version.d.ts +2 -0
  49. package/dist/lib/client-version.js +24 -0
  50. package/dist/lib/company-flag-gate.d.ts +30 -0
  51. package/dist/lib/company-flag-gate.js +104 -0
  52. package/dist/lib/core-utils/hook-timeout-debug-context-flag.js +1 -1
  53. package/dist/lib/daemon/flag.js +2 -1
  54. package/dist/lib/daemon/legacy-journal-gate.js +3 -1
  55. package/dist/lib/daemon/run.js +4 -3
  56. package/dist/lib/daemon/shared-flag-reads.js +1 -1
  57. package/dist/lib/delivery/migrations.d.ts +32 -1
  58. package/dist/lib/delivery/migrations.js +69 -8
  59. package/dist/lib/doctor/checks/host-core.js +22 -4
  60. package/dist/lib/doctor/checks/jq.d.ts +27 -6
  61. package/dist/lib/doctor/checks/jq.js +46 -8
  62. package/dist/lib/doctor/client-health-reason-codes-flag.js +1 -1
  63. package/dist/lib/doctor/fix/refresh-sync-handoff.d.ts +1 -1
  64. package/dist/lib/doctor/fix/refresh-sync-handoff.js +1 -1
  65. package/dist/lib/flag-client-gate-headers.d.ts +38 -0
  66. package/dist/lib/flag-client-gate-headers.js +62 -0
  67. package/dist/lib/flag-client-headers.d.ts +15 -0
  68. package/dist/lib/flag-client-headers.js +25 -0
  69. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  70. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  71. package/dist/lib/flag-registry-worker.js +35 -0
  72. package/dist/lib/flag-registry.d.ts +1 -20
  73. package/dist/lib/flag-registry.js +5 -81
  74. package/dist/lib/hook-engine/adapter-core-pin.d.ts +30 -0
  75. package/dist/lib/hook-engine/adapter-core-pin.js +30 -0
  76. package/dist/lib/hook-engine/coverage.d.ts +65 -1
  77. package/dist/lib/hook-engine/coverage.js +173 -8
  78. package/dist/lib/hook-engine/reconcile.js +3 -2
  79. package/dist/lib/hot-channels/prompts/signals-pass.md +20 -0
  80. package/dist/lib/hot-channels/signal-changes.d.ts +228 -0
  81. package/dist/lib/hot-channels/signal-changes.js +683 -0
  82. package/dist/lib/hot-channels/signals-pass.d.ts +24 -0
  83. package/dist/lib/hot-channels/signals-pass.js +232 -12
  84. package/dist/lib/lanes/outpost-worktree-pruner-flag.d.ts +1 -1
  85. package/dist/lib/lanes/outpost-worktree-pruner-flag.js +1 -1
  86. package/dist/lib/lanes/registry-flag.js +2 -1
  87. package/dist/lib/lanes/spawn.js +11 -1
  88. package/dist/lib/mesh/live/binding-intent.d.ts +61 -0
  89. package/dist/lib/mesh/live/binding-intent.js +201 -0
  90. package/dist/lib/mesh/live/binding-receipt.d.ts +157 -0
  91. package/dist/lib/mesh/live/binding-receipt.js +365 -0
  92. package/dist/lib/mesh/live/company-flag-refresh.js +1 -1
  93. package/dist/lib/mesh/live/daemon/doctor-telemetry.d.ts +39 -0
  94. package/dist/lib/mesh/live/daemon/doctor-telemetry.js +58 -0
  95. package/dist/lib/mesh/live/daemon/install.js +2 -1
  96. package/dist/lib/mesh/live/daemon/presence.js +9 -0
  97. package/dist/lib/mesh/live/daemon/run.d.ts +3 -0
  98. package/dist/lib/mesh/live/daemon/run.js +33 -1
  99. package/dist/lib/ontology-graph/lineage/index.d.ts +401 -0
  100. package/dist/lib/ontology-graph/lineage/index.js +1027 -0
  101. package/dist/lib/ontology-graph/model/index.d.ts +54 -0
  102. package/dist/lib/ontology-graph/model/index.js +112 -0
  103. package/dist/lib/ontology-graph/model/pass-tasks.d.ts +75 -0
  104. package/dist/lib/ontology-graph/model/pass-tasks.js +166 -0
  105. package/dist/lib/ontology-graph/model/pass.d.ts +6 -0
  106. package/dist/lib/ontology-graph/model/pass.js +9 -2
  107. package/dist/lib/ontology-graph/model/pending-items.d.ts +8 -0
  108. package/dist/lib/ontology-graph/model/pending-items.js +24 -1
  109. package/dist/lib/ontology-graph/model/step.d.ts +1 -1
  110. package/dist/lib/ontology-graph/model/tasks.d.ts +11 -3
  111. package/dist/lib/ontology-graph/model/tasks.js +20 -7
  112. package/dist/lib/ontology-graph/read/brief.js +41 -6
  113. package/dist/lib/ontology-graph/read/index.d.ts +4 -0
  114. package/dist/lib/ontology-graph/read/index.js +173 -29
  115. package/dist/lib/ontology-graph/read/lineage.d.ts +101 -0
  116. package/dist/lib/ontology-graph/read/lineage.js +262 -0
  117. package/dist/lib/ontology-graph/replay/buffered-store.js +17 -0
  118. package/dist/lib/ontology-graph/replay/engine.d.ts +32 -1
  119. package/dist/lib/ontology-graph/replay/engine.js +213 -8
  120. package/dist/lib/ontology-graph/replay/extractors.d.ts +26 -0
  121. package/dist/lib/ontology-graph/replay/extractors.js +25 -1
  122. package/dist/lib/ontology-graph/replay/index.d.ts +2 -0
  123. package/dist/lib/ontology-graph/replay/index.js +9 -3
  124. package/dist/lib/ontology-graph/replay/signal-changes.d.ts +118 -0
  125. package/dist/lib/ontology-graph/replay/signal-changes.js +687 -0
  126. package/dist/lib/ontology-graph/schema/decision-status.d.ts +18 -0
  127. package/dist/lib/ontology-graph/schema/decision-status.js +20 -0
  128. package/dist/lib/ontology-graph/schema/index.d.ts +1 -0
  129. package/dist/lib/ontology-graph/schema/index.js +1 -0
  130. package/dist/lib/ontology-graph/setup/index.js +13 -3
  131. package/dist/lib/search-index/index.d.ts +33 -1
  132. package/dist/lib/search-index/index.js +180 -25
  133. package/dist/lib/search-index/qmd-exit-diagnostics.d.ts +7 -0
  134. package/dist/lib/search-index/qmd-exit-diagnostics.js +25 -1
  135. package/dist/lib/signals/adapters-catalog.js +1 -1
  136. package/dist/lib/smart-ci/cost.d.ts +72 -0
  137. package/dist/lib/smart-ci/cost.js +120 -0
  138. package/dist/lib/smart-ci/github.d.ts +112 -0
  139. package/dist/lib/smart-ci/github.js +267 -0
  140. package/dist/lib/smart-ci/intake.d.ts +288 -0
  141. package/dist/lib/smart-ci/intake.js +1078 -0
  142. package/dist/lib/smart-ci/ledger.d.ts +218 -0
  143. package/dist/lib/smart-ci/ledger.js +527 -0
  144. package/dist/lib/smart-ci/metrics.d.ts +137 -0
  145. package/dist/lib/smart-ci/metrics.js +249 -0
  146. package/dist/lib/smart-ci/records.d.ts +265 -0
  147. package/dist/lib/smart-ci/records.js +281 -0
  148. package/dist/lib/smart-ci/reducer.d.ts +67 -0
  149. package/dist/lib/smart-ci/reducer.js +261 -0
  150. package/dist/lib/sync-core/engine-holds.d.ts +15 -0
  151. package/dist/lib/sync-core/engine-holds.js +104 -11
  152. package/dist/lib/sync-core/engine-home.d.ts +3 -0
  153. package/dist/lib/sync-core/engine-home.js +41 -1
  154. package/dist/lib/sync-core/flag.js +2 -1
  155. package/dist/lib/sync-core/hand-back.d.ts +1 -0
  156. package/dist/lib/sync-core/hand-back.js +7 -2
  157. package/dist/lib/sync-core/legacy-journal-export-child.js +5 -3
  158. package/dist/lib/sync-core/legacy-journal-export.d.ts +23 -4
  159. package/dist/lib/sync-core/legacy-journal-export.js +120 -55
  160. package/dist/lib/sync-core/reconcile.d.ts +2 -1
  161. package/dist/lib/sync-core/reconcile.js +40 -7
  162. package/dist/lib/sync-invalid-entity-warning.js +2 -1
  163. package/dist/lib/windows/install-followup.d.ts +41 -0
  164. package/dist/lib/windows/install-followup.js +87 -0
  165. package/dist/lib/windows/jq.d.ts +59 -0
  166. package/dist/lib/windows/jq.js +154 -3
  167. package/dist/lib/windows/user-path.d.ts +5 -0
  168. package/dist/lib/windows/user-path.js +1 -1
  169. package/dist/lib/work-context/auto-bind.d.ts +12 -0
  170. package/dist/lib/work-context/auto-bind.js +49 -3
  171. package/dist/lib/work-context/organize.d.ts +4 -2
  172. package/dist/lib/work-context/organize.js +18 -8
  173. package/dist/lib/work-context/reconcile.js +16 -1
  174. package/dist/main.js +12 -1
  175. package/dist/utils/client-health-contract.d.ts +30 -0
  176. package/dist/utils/client-health-contract.js +111 -0
  177. package/dist/utils/client-health.d.ts +5 -2
  178. package/dist/utils/client-health.js +74 -5
  179. package/dist/utils/exclusive-lock.d.ts +5 -1
  180. package/dist/utils/exclusive-lock.js +9 -2
  181. package/dist/utils/host-registration.d.ts +7 -0
  182. package/dist/utils/host-registration.js +10 -1
  183. package/dist/utils/pid.d.ts +31 -0
  184. package/dist/utils/pid.js +65 -0
  185. package/dist/utils/resident-package-preload.js +12 -4
  186. package/dist/utils/sentry-fingerprint.js +3 -0
  187. package/package.json +10 -8
  188. package/scripts/install-hook-engine.mjs +5 -3
@@ -5,6 +5,39 @@ import { createFlagClient } from "@indigoai-us/hq-flags-client";
5
5
  import { decodeJwtClaims } from "./daemon/machine-token-identity.js";
6
6
  const data = workerData;
7
7
  const endpoint = data.endpoint;
8
+ /**
9
+ * Client-gate headers for hq-pro `src/flags/client-gates.ts`. This worker runs
10
+ * as `new Worker(source, { eval: true })` with no module URL, so it must not
11
+ * import cli-version.ts (which reads package.json relative to its own file) and
12
+ * keeps its imports to the ones above. The parent passes the version in
13
+ * workerData. `flag-client-gate-headers.ts` is the main-thread copy of this
14
+ * logic; flag-registry-worker-client-gate-headers.test.ts runs this one.
15
+ * A missing or unusable version sends no x-hq-client-version header (the
16
+ * server stores null and fails gated rows closed); the request still goes out.
17
+ */
18
+ function clientGateFetch() {
19
+ const base = globalThis.fetch;
20
+ if (typeof base !== "function")
21
+ return undefined;
22
+ const gate = {};
23
+ const version = typeof data.clientVersion === "string" ? data.clientVersion.trim() : "";
24
+ if (version.length > 0 && version.length <= 64)
25
+ gate["x-hq-client-version"] = version;
26
+ gate["x-hq-client-platform"] = process.platform === "win32" ? "windows" : process.platform;
27
+ return ((input, init) => {
28
+ const headers = {};
29
+ const given = init?.headers;
30
+ if (Array.isArray(given))
31
+ for (const [key, value] of given)
32
+ headers[key] = value;
33
+ else if (given instanceof Headers)
34
+ given.forEach((value, key) => { headers[key] = value; });
35
+ else if (given)
36
+ Object.assign(headers, given);
37
+ return base(input, { ...init, headers: { ...headers, ...gate } });
38
+ });
39
+ }
40
+ const gatedFetch = clientGateFetch();
8
41
  const COMPANY_UID_RE = /^cmp_[A-Za-z0-9]{3,128}$/;
9
42
  const COMPANY_SLUG_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
10
43
  async function refresh() {
@@ -26,6 +59,7 @@ async function refresh() {
26
59
  getToken: () => idToken,
27
60
  refreshIntervalMs: 0,
28
61
  onError: () => { },
62
+ ...(gatedFetch ? { fetch: gatedFetch } : {}),
29
63
  });
30
64
  await client.ready();
31
65
  const snapshot = client.snapshot();
@@ -41,6 +75,7 @@ async function refresh() {
41
75
  getToken: () => idToken,
42
76
  refreshIntervalMs: 0,
43
77
  onError: () => { },
78
+ ...(gatedFetch ? { fetch: gatedFetch } : {}),
44
79
  });
45
80
  try {
46
81
  await personClient.ready();
@@ -6,7 +6,7 @@
6
6
  * keep a short-lived, offline CLI alive until the client's network deadline.
7
7
  */
8
8
  import { type WorkerOptions } from "node:worker_threads";
9
- import { createFlagClient, type FlagClient, type FlagLookupOptions, type FlagResolution, type FlagSnapshot } from "@indigoai-us/hq-flags-client";
9
+ import { type FlagClient, type FlagLookupOptions, type FlagSnapshot } from "@indigoai-us/hq-flags-client";
10
10
  type FlagRegistrySentry = Pick<typeof import("@sentry/node"), "captureException" | "withScope">;
11
11
  export { resolveProcessFlagCompanyContext } from "./process-flag-company-context.js";
12
12
  export type { ProcessFlagCompanyContext } from "./process-flag-company-context.js";
@@ -35,11 +35,6 @@ export interface FlagRegistryDependencies {
35
35
  forceRefresh?: boolean;
36
36
  captureWorkerFailure?: (error: Error, tags: Record<string, string>) => void;
37
37
  }
38
- export interface CompanyFlagGateDependencies {
39
- endpoint?: string;
40
- requestTimeoutMs?: number;
41
- createClient?: typeof createFlagClient;
42
- }
43
38
  /** Extract only a CLI-level --company option; values after `--` belong to child commands. */
44
39
  export declare function explicitCompanyScopeFromArgv(argv: readonly string[]): string | undefined;
45
40
  /** Wait briefly for the current company refresh to persist or report completion. */
@@ -64,20 +59,6 @@ export declare function refreshFlagRegistrySnapshot(timeoutMs?: number): Promise
64
59
  * falls through to the exact legacy predicate owned by the caller.
65
60
  */
66
61
  export declare function resolveFlagGate(reader: FlagReader | null | undefined, flagKey: string, lookup: FlagLookupOptions, legacyFallback: () => boolean, env?: NodeJS.ProcessEnv): boolean;
67
- /** Resolve one explicit company's flag without relying on process-wide binding. */
68
- export declare function resolveCompanyFlagGate(companyUid: string, idToken: string, flagKey: string, lookup: FlagLookupOptions, legacyFallback: () => boolean, dependencies?: CompanyFlagGateDependencies): Promise<boolean>;
69
- /**
70
- * Read one explicit company's flag and say whether the registry answered.
71
- *
72
- * Returns the evaluator's resolution when the registry snapshot loaded (an
73
- * absent row resolves to `lookup.fallback`, source "fallback"), a
74
- * "local-override" resolution when the process sets one, and null when the
75
- * registry could not be read: no company uid or token, a client error, a
76
- * timeout, or a failed load. Callers that keep a last-known value (ingest
77
- * kill switches) use the null to tell an unreadable registry from an answer.
78
- * Bounded by the client's request timeout, like `resolveCompanyFlagGate`.
79
- */
80
- export declare function readCompanyFlag(companyUid: string, idToken: string, flagKey: string, lookup: FlagLookupOptions, dependencies?: CompanyFlagGateDependencies): Promise<FlagResolution | null>;
81
62
  /** Resolve a process gate against the shared snapshot reader, when configured. */
82
63
  export declare function resolveProcessFlagGate(flagKey: string, lookup: FlagLookupOptions, legacyFallback: () => boolean, companyUid?: string, options?: {
83
64
  acceptStaleSnapshot?: boolean;
@@ -6,7 +6,8 @@
6
6
  * keep a short-lived, offline CLI alive until the client's network deadline.
7
7
  */
8
8
  import { Worker } from "node:worker_threads";
9
- import { createFlagClient, isFlagSnapshot, readLocalOverride, resolveFlag, } from "@indigoai-us/hq-flags-client";
9
+ import { isFlagSnapshot, readLocalOverride, resolveFlag, } from "@indigoai-us/hq-flags-client";
10
+ import { readClientVersion } from "./client-version.js";
10
11
  import { resolveFlagRegistryEndpoint, } from "./flag-registry-endpoint.js";
11
12
  import { FLAG_REGISTRY_WORKER_SOURCE } from "./flag-registry-worker-source.generated.js";
12
13
  import { resolveFlagSnapshotCompanyUid, resolveProcessFlagCompanyContext } from "./process-flag-company-context.js";
@@ -214,6 +215,9 @@ export function kickFlagRegistryReadiness(dependencies = {}) {
214
215
  ...((companyUid || company.companySlug) && dependencies.idToken
215
216
  ? { idToken: dependencies.idToken }
216
217
  : {}),
218
+ // The eval'd worker has no module URL and cannot read package.json
219
+ // itself; it sends this as x-hq-client-version (none when unreadable).
220
+ clientVersion: readClientVersion(),
217
221
  },
218
222
  eval: true,
219
223
  };
@@ -333,86 +337,6 @@ export function resolveFlagGate(reader, flagKey, lookup, legacyFallback, env = p
333
337
  return localOverrideOrFallback(flagKey, legacyFallback, env);
334
338
  }
335
339
  }
336
- /** Resolve one explicit company's flag without relying on process-wide binding. */
337
- export async function resolveCompanyFlagGate(companyUid, idToken, flagKey, lookup, legacyFallback, dependencies = {}) {
338
- const localOverride = processLocalOverride(flagKey);
339
- if (localOverride !== null)
340
- return localOverride;
341
- const targetCompanyUid = normalizedCompanyUid(companyUid);
342
- if (!targetCompanyUid || idToken.trim() === "") {
343
- return localOverrideOrFallback(flagKey, legacyFallback);
344
- }
345
- let client;
346
- try {
347
- client = (dependencies.createClient ?? createFlagClient)({
348
- endpoint: resolveFlagRegistryEndpoint(dependencies.endpoint, process.env),
349
- getToken: () => idToken,
350
- companyUid: targetCompanyUid,
351
- refreshIntervalMs: 0,
352
- requestTimeoutMs: dependencies.requestTimeoutMs ?? 1_200,
353
- onError: (error) => {
354
- const errorClass = error instanceof Error ? error.name : "unknown";
355
- console.error(`hq: Could not resolve a company flag (${errorClass}); using its fallback.`);
356
- },
357
- });
358
- await client.ready();
359
- return resolveFlagGate(client, flagKey, lookup, legacyFallback);
360
- }
361
- catch (error) {
362
- const errorClass = error instanceof Error ? error.name : "unknown";
363
- console.error(`hq: Could not resolve a company flag (${errorClass}); using its fallback.`);
364
- return localOverrideOrFallback(flagKey, legacyFallback);
365
- }
366
- finally {
367
- client?.close();
368
- }
369
- }
370
- /**
371
- * Read one explicit company's flag and say whether the registry answered.
372
- *
373
- * Returns the evaluator's resolution when the registry snapshot loaded (an
374
- * absent row resolves to `lookup.fallback`, source "fallback"), a
375
- * "local-override" resolution when the process sets one, and null when the
376
- * registry could not be read: no company uid or token, a client error, a
377
- * timeout, or a failed load. Callers that keep a last-known value (ingest
378
- * kill switches) use the null to tell an unreadable registry from an answer.
379
- * Bounded by the client's request timeout, like `resolveCompanyFlagGate`.
380
- */
381
- export async function readCompanyFlag(companyUid, idToken, flagKey, lookup, dependencies = {}) {
382
- const localOverride = processLocalOverride(flagKey);
383
- if (localOverride !== null)
384
- return { value: localOverride, source: "local-override" };
385
- const targetCompanyUid = normalizedCompanyUid(companyUid);
386
- if (!targetCompanyUid || idToken.trim() === "")
387
- return null;
388
- let client;
389
- try {
390
- client = (dependencies.createClient ?? createFlagClient)({
391
- endpoint: resolveFlagRegistryEndpoint(dependencies.endpoint, process.env),
392
- getToken: () => idToken,
393
- companyUid: targetCompanyUid,
394
- refreshIntervalMs: 0,
395
- requestTimeoutMs: dependencies.requestTimeoutMs ?? 1_200,
396
- onError: (error) => {
397
- const errorClass = error instanceof Error ? error.name : "unknown";
398
- console.error(`hq: Could not read a company flag (${errorClass}).`);
399
- },
400
- });
401
- await client.ready();
402
- // ready() resolves after a failed load too; no snapshot means no answer.
403
- if (client.snapshot() === null)
404
- return null;
405
- return client.explain(flagKey, lookup);
406
- }
407
- catch (error) {
408
- const errorClass = error instanceof Error ? error.name : "unknown";
409
- console.error(`hq: Could not read a company flag (${errorClass}).`);
410
- return null;
411
- }
412
- finally {
413
- client?.close();
414
- }
415
- }
416
340
  /** Resolve a process gate against the shared snapshot reader, when configured. */
417
341
  export function resolveProcessFlagGate(flagKey, lookup, legacyFallback, companyUid, options = {}) {
418
342
  const defaultOnKillSwitch = options.killSwitchWithoutCompany === true;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The one place the classifying `core/scripts/lib/hook-adapter-core.sh`
3
+ * revision is pinned (hq-core-staging #2119, ITEM 502 / 502b): the revision
4
+ * whose `hqad_classify_exec` reads both `run --host claude <Event> --hq-root
5
+ * <root> [--global]` and the `stable` symlink alias in `.claude/settings.json`
6
+ * as `master\t<Event>`.
7
+ *
8
+ * Every list that names this revision reads it from here:
9
+ * - TypeScript: `CODEX_POST_TOOL_USE_GENERATIONS`, `GROK_POST_TOOL_USE_GENERATIONS`,
10
+ * `FLEET_LOCAL_ADAPTER_CORE` and `CLASSIFYING_ADAPTER_CORE_HASHES` (coverage.ts);
11
+ * - Rust: `crates/hq-hook/src/adapter_core_pin.rs` reads this file at build
12
+ * time (`include_str!`), and `post_hooks/codex.rs` `POST_TOOL_USE_GENERATIONS`,
13
+ * `post_hooks/grok.rs` `ADAPTER_GENERATIONS` and `host/fleet/local_pre.rs`
14
+ * `RELEASED_CORE_SHA256` use that constant.
15
+ * `coverage-adapter-core-pin.test.ts` and the Rust `adapter_core_pin` tests
16
+ * fail when any of them carries the hash as a literal or the fixture bytes
17
+ * stop hashing to it.
18
+ *
19
+ * To re-pin (after hq-core-staging #2119 merges): set the hash on the export
20
+ * line below (keep it on one line, single-quoted: the Rust build parses it),
21
+ * replace the bytes at `CLASSIFYING_ADAPTER_CORE_FIXTURE` with the merged
22
+ * file, and update that file's record in test/fixtures/PROVENANCE.md.
23
+ */
24
+ export declare const CLASSIFYING_ADAPTER_CORE_SHA256 = "cf1abd5c832722d26a46ced0694e8a3cd0d70ff30194a03fb2ce989289a8621c";
25
+ /** Released v16.0.51 revision, accepted by the Claude project adapter hold and by the fleet-local and agents-v2 ports. */
26
+ export declare const RELEASED_CLASSIFYING_ADAPTER_CORE_SHA256 = "09f5a3e05db016257f4515cf7e0101a9a34368a04c975337a5ce22f8dfe3dfb0";
27
+ export declare const RELEASED_CLASSIFYING_ADAPTER_CORE_FIXTURE = "adapter-stable-alias-16.0.51/core/scripts/lib/hook-adapter-core.sh";
28
+ /** The fixture copy of the pinned revision, under crates/hq-hook/tests/fixtures. */
29
+ export declare const CLASSIFYING_ADAPTER_CORE_FIXTURE = "adapter-stable-alias/core/scripts/lib/hook-adapter-core.sh";
30
+ //# sourceMappingURL=adapter-core-pin.d.ts.map
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The one place the classifying `core/scripts/lib/hook-adapter-core.sh`
3
+ * revision is pinned (hq-core-staging #2119, ITEM 502 / 502b): the revision
4
+ * whose `hqad_classify_exec` reads both `run --host claude <Event> --hq-root
5
+ * <root> [--global]` and the `stable` symlink alias in `.claude/settings.json`
6
+ * as `master\t<Event>`.
7
+ *
8
+ * Every list that names this revision reads it from here:
9
+ * - TypeScript: `CODEX_POST_TOOL_USE_GENERATIONS`, `GROK_POST_TOOL_USE_GENERATIONS`,
10
+ * `FLEET_LOCAL_ADAPTER_CORE` and `CLASSIFYING_ADAPTER_CORE_HASHES` (coverage.ts);
11
+ * - Rust: `crates/hq-hook/src/adapter_core_pin.rs` reads this file at build
12
+ * time (`include_str!`), and `post_hooks/codex.rs` `POST_TOOL_USE_GENERATIONS`,
13
+ * `post_hooks/grok.rs` `ADAPTER_GENERATIONS` and `host/fleet/local_pre.rs`
14
+ * `RELEASED_CORE_SHA256` use that constant.
15
+ * `coverage-adapter-core-pin.test.ts` and the Rust `adapter_core_pin` tests
16
+ * fail when any of them carries the hash as a literal or the fixture bytes
17
+ * stop hashing to it.
18
+ *
19
+ * To re-pin (after hq-core-staging #2119 merges): set the hash on the export
20
+ * line below (keep it on one line, single-quoted: the Rust build parses it),
21
+ * replace the bytes at `CLASSIFYING_ADAPTER_CORE_FIXTURE` with the merged
22
+ * file, and update that file's record in test/fixtures/PROVENANCE.md.
23
+ */
24
+ export const CLASSIFYING_ADAPTER_CORE_SHA256 = 'cf1abd5c832722d26a46ced0694e8a3cd0d70ff30194a03fb2ce989289a8621c';
25
+ /** Released v16.0.51 revision, accepted by the Claude project adapter hold and by the fleet-local and agents-v2 ports. */
26
+ export const RELEASED_CLASSIFYING_ADAPTER_CORE_SHA256 = '09f5a3e05db016257f4515cf7e0101a9a34368a04c975337a5ce22f8dfe3dfb0';
27
+ export const RELEASED_CLASSIFYING_ADAPTER_CORE_FIXTURE = 'adapter-stable-alias-16.0.51/core/scripts/lib/hook-adapter-core.sh';
28
+ /** The fixture copy of the pinned revision, under crates/hq-hook/tests/fixtures. */
29
+ export const CLASSIFYING_ADAPTER_CORE_FIXTURE = 'adapter-stable-alias/core/scripts/lib/hook-adapter-core.sh';
30
+ //# sourceMappingURL=adapter-core-pin.js.map
@@ -185,6 +185,21 @@ export declare const SESSION_START_PINS: ReadonlyArray<readonly [string, readonl
185
185
  * any revision it does not rebuild. Null when every file matches.
186
186
  */
187
187
  export declare function sessionStartHold(root: string): string | null;
188
+ /**
189
+ * The script revisions the native SessionStart `migrate-policy-triggers` port rebuilds
190
+ * (`crates/hq-hook/src/session_start_ss1/migrate_triggers.rs`: `SCRIPT_SHA256`,
191
+ * `FORWARDER_SHA256`, `FORWARDER_LIB_SHA256`; hq-core v16.0.47 through v16.0.50).
192
+ * A missing script is skipped silently by both master-hook and the native port, so only a
193
+ * present file whose hash is outside the accepted set holds SessionStart on master-hook.
194
+ */
195
+ export declare const MIGRATE_POLICY_TRIGGERS_PINS: ReadonlyArray<readonly [string, readonly string[]]>;
196
+ /**
197
+ * Why SessionStart must stay on master-hook for `migrate-policy-triggers` in `root`: the hook
198
+ * script is present on disk and either it or its forwarder/library is not a pinned revision.
199
+ * Absent hook script (or absent forwarder) is a silent no-op on both shell and native, so it
200
+ * does not hold. Null when every present pinned file matches.
201
+ */
202
+ export declare function migratePolicyTriggersHold(root: string): string | null;
188
203
  /**
189
204
  * The one Codex adapter pair the native Codex SubagentStop is modelled on (hq-core v16.0.47):
190
205
  * `ADAPTER_RELEASES` and `ADAPTER_CORE_RELEASES` in crates/hq-hook/src/post_hooks/codex.rs.
@@ -342,7 +357,7 @@ export declare function mergedWriteGuardHold(root: string, event: string): strin
342
357
  */
343
358
  export declare function preToolUseHold(root: string, host: CoreNextHost, hooks?: readonly string[]): string | null;
344
359
  /**
345
- * The scripts the native first-prompt company bind rebuilds, each at one revision:
360
+ * The scripts the native first-prompt company bind rebuilds:
346
361
  * `MENTION_LIBS` in crates/hq-hook/src/prompt_company_mention/bind.rs, then `SCRIPTS`, `ID_LIBS` and
347
362
  * `CAPABILITY_LIBS` in crates/hq-hook/src/session_set/mod.rs.
348
363
  */
@@ -410,4 +425,53 @@ export declare function subagentScopeLibraryHold(root: string, event: string): s
410
425
  /** Records the environment `target` was resolved under; returns `target`. */
411
426
  export declare function resolvedUnder<T extends CoreNextTarget | null>(target: T, env: NodeJS.ProcessEnv): T;
412
427
  export declare function forHost(target: CoreNextTarget | null, root: string, host: CoreNextHost, env?: NodeJS.ProcessEnv): CoreNextTarget | null;
428
+ /**
429
+ * Revisions of `core/scripts/lib/hook-adapter-core.sh` whose `hqad_classify_exec`
430
+ * classifies both `run --host claude <Event> --hq-root <root> [--global]` and the
431
+ * `stable` symlink alias as `master\t<Event>` (hq-core-staging #2119, ITEM 502/502b).
432
+ * Both the released revision and the current pin are recorded in `adapter-core-pin.ts`.
433
+ */
434
+ export declare const CLASSIFYING_ADAPTER_CORE_HASHES: readonly string[];
435
+ /**
436
+ * Returns whether the HQ root's `core/scripts/lib/hook-adapter-core.sh` is a
437
+ * pinned revision known to classify new-core `run --host claude` and `stable`
438
+ * entries in `.claude/settings.json`.
439
+ */
440
+ export declare function adapterCoreClassifiesNewCore(root: string): boolean;
441
+ /** The Codex and Grok Build shell adapters present in `root`; each reads `<root>/.claude/settings.json`. */
442
+ export declare function presentAdapterHosts(root: string): Array<'codex' | 'grok'>;
443
+ /**
444
+ * Why `event` must stay on `master-hook.sh` in `<root>/.claude/settings.json`
445
+ * (which adapter hosts hold it there), or null when it may switch (ITEM 502 /
446
+ * 502b). The Codex and Grok Build shell
447
+ * adapters find their master record in that file through
448
+ * `core/scripts/lib/hook-adapter-core.sh`, and an unpatched revision sees only
449
+ * `master-hook.sh` entries. So while a present adapter host keeps any event
450
+ * that reads those entries on its shell adapter, the Claude Code project entry
451
+ * stays on master-hook.sh, whatever holds the host there: its canary (failed,
452
+ * missing, stale, or a hook-started reindex keeping the host's current core),
453
+ * a coverage hold for that one event (SubagentStop on Codex), or no new core
454
+ * at all (flag off, kill switch). `--skip-host-canary-gate` passes every
455
+ * canary but leaves the coverage holds, so it cannot switch such an event
456
+ * either.
457
+ *
458
+ * Grok Build StopCancelled and StopFailure, which its adapter runs as the
459
+ * settings.json `Stop` entries, are not tied to Claude Code `Stop` here: their
460
+ * own switch already reads whether master-hook is among those entries
461
+ * ([`grokStopObserveUncovered`]), so they follow the Claude Code entry rather
462
+ * than hold it (tying them both ways would hold both forever).
463
+ *
464
+ * `hq reindex` ([`claudeProjectTarget`]) and `hq doctor`
465
+ * (`host-core:claude-project`) both answer from here: each asks what the
466
+ * adapter hosts' own reindex registers, through [`forHost`] on the same target.
467
+ *
468
+ * User-level `~/.claude/settings.json` is never read by the Codex or Grok
469
+ * adapters and is unaffected.
470
+ */
471
+ export declare function claudeProjectAdapterHold(root: string, event: string, coreNext: CoreNextTarget | null, env?: NodeJS.ProcessEnv): string | null;
472
+ /**
473
+ * `claudeNext` narrowed for `<root>/.claude/settings.json` to the events
474
+ * [`claudeProjectAdapterHold`] lets switch; null when none does.
475
+ */
476
+ export declare function claudeProjectTarget(coreNext: CoreNextTarget | null, claudeNext: CoreNextTarget | null, root: string, env?: NodeJS.ProcessEnv): CoreNextTarget | null;
413
477
  //# sourceMappingURL=coverage.d.ts.map
@@ -27,6 +27,7 @@ import { createHash } from 'node:crypto';
27
27
  import * as fs from 'node:fs';
28
28
  import * as path from 'node:path';
29
29
  import { isCoreNextEntry } from './registration.js';
30
+ import { CLASSIFYING_ADAPTER_CORE_SHA256, RELEASED_CLASSIFYING_ADAPTER_CORE_SHA256 } from './adapter-core-pin.js';
30
31
  /**
31
32
  * Read a policy file that ships beside this module (src/ and dist/ alike; scripts/copy-schemas.mjs copies
32
33
  * them to dist/). Not a JSON import: import attributes need Node 20.10, and `engines` allows Node 20.0, where
@@ -1700,7 +1701,7 @@ export function uncoveredHooks(root, host, event, covers, env = process.env) {
1700
1701
  if (hold)
1701
1702
  missing.push(`(native SubagentStop compatibility: ${hold})`);
1702
1703
  }
1703
- if (event === 'SessionStart' && covered.includes('master-hook:SessionStart')) {
1704
+ if (event === 'SessionStart' && (covered.includes('master-hook:SessionStart') || covered.includes('agents-v2-adapter:SessionStart'))) {
1704
1705
  const hold = sessionStartHold(root);
1705
1706
  if (hold)
1706
1707
  missing.push(`(native SessionStart compatibility: ${hold})`);
@@ -1742,6 +1743,11 @@ export function uncoveredHooks(root, host, event, covers, env = process.env) {
1742
1743
  if (hold)
1743
1744
  missing.push(`(native ${event} compatibility: ${hold})`);
1744
1745
  }
1746
+ if (event === 'SessionStart' && covered.includes('migrate-policy-triggers')) {
1747
+ const hold = migratePolicyTriggersHold(root);
1748
+ if (hold)
1749
+ missing.push(`(native SessionStart compatibility: ${hold})`);
1750
+ }
1745
1751
  if (host === 'agents-v2' && event === 'PreToolUse' && covered.includes('agents-v2-adapter:PreToolUse')) {
1746
1752
  const hold = sessionStartHold(root);
1747
1753
  if (hold)
@@ -1761,7 +1767,7 @@ export function uncoveredHooks(root, host, event, covers, env = process.env) {
1761
1767
  export const SESSION_START_PINS = [
1762
1768
  ['core/scripts/hqd-hook-shim.sh', ['ab289ac0af680fe3bcacb110302ca8b998bdc33c6f94321d42bd04a344163eed', 'ee5e9fe729eb7e51f87b5f90cdc020be865f5b6b35ac0b5758587546b35715c0']],
1763
1769
  ['core/scripts/hqd-hook-flag-cache-lib.sh', ['061d264460408e9eaf43fdf0fdde662c906a9a7dacb4e7a591e684bca28c138a']],
1764
- ['core/scripts/hq-session.sh', ['db701162f71b53fd2188974d2f46c58250593dde1252d65b36e6d02b9a765fe7', '02a37c5dbf4fb5af27cc64d0f271121e990758b757a479f60e9ce099f4d65ded']],
1770
+ ['core/scripts/hq-session.sh', ['db701162f71b53fd2188974d2f46c58250593dde1252d65b36e6d02b9a765fe7', '02a37c5dbf4fb5af27cc64d0f271121e990758b757a479f60e9ce099f4d65ded', 'd4d4aef60ff8b095e3abcc817598f376d3c2de8d59758c3ed6dd40d4aa4b11fb']],
1765
1771
  ['core/scripts/lib/session-id.sh', ['2ebbc50893c7c601a111b9e8f9945afeac88f552d7caeec09c4096f4c27a833d']],
1766
1772
  ['core/scripts/lib/session-scope-capability.sh', ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead']],
1767
1773
  ['core/scripts/resolve-company.sh', ['00d6fa069f574a86087c77daa44887a2617446d4300d5daebecc9bfb5d81abe7']],
@@ -1789,6 +1795,59 @@ export function sessionStartHold(root) {
1789
1795
  }
1790
1796
  return null;
1791
1797
  }
1798
+ /**
1799
+ * The script revisions the native SessionStart `migrate-policy-triggers` port rebuilds
1800
+ * (`crates/hq-hook/src/session_start_ss1/migrate_triggers.rs`: `SCRIPT_SHA256`,
1801
+ * `FORWARDER_SHA256`, `FORWARDER_LIB_SHA256`; hq-core v16.0.47 through v16.0.50).
1802
+ * A missing script is skipped silently by both master-hook and the native port, so only a
1803
+ * present file whose hash is outside the accepted set holds SessionStart on master-hook.
1804
+ */
1805
+ export const MIGRATE_POLICY_TRIGGERS_PINS = [
1806
+ [
1807
+ '.claude/hooks/migrate-policy-triggers-if-changed.sh',
1808
+ [
1809
+ '4f4cf879bf31750a87386de0db5efa6d166116da629cf2d31819b7a21faa8335',
1810
+ '1a01eb3c4a46bd04cc6ed7d5c465405343200b3baf391b2d1f4f393577d639f2',
1811
+ ],
1812
+ ],
1813
+ [
1814
+ 'core/scripts/migrate-policy-triggers.sh',
1815
+ ['9fac89fba7cc04d31aed493aee9d1a43670c0d3e570675e01be466ebe156cee6'],
1816
+ ],
1817
+ [
1818
+ 'core/scripts/lib/forwarder.sh',
1819
+ ['a030068f482cac2ecbfad90394fd7bcd1e24926e9179bcec5c770076ad6e4fc4'],
1820
+ ],
1821
+ ];
1822
+ /**
1823
+ * Why SessionStart must stay on master-hook for `migrate-policy-triggers` in `root`: the hook
1824
+ * script is present on disk and either it or its forwarder/library is not a pinned revision.
1825
+ * Absent hook script (or absent forwarder) is a silent no-op on both shell and native, so it
1826
+ * does not hold. Null when every present pinned file matches.
1827
+ */
1828
+ export function migratePolicyTriggersHold(root) {
1829
+ const hookPath = path.join(root, MIGRATE_POLICY_TRIGGERS_PINS[0][0]);
1830
+ if (!fs.existsSync(hookPath))
1831
+ return null;
1832
+ for (const [index, [relative, shas]] of MIGRATE_POLICY_TRIGGERS_PINS.entries()) {
1833
+ const file = path.join(root, relative);
1834
+ if (index === 1 && !fs.existsSync(file))
1835
+ return null;
1836
+ let bytes;
1837
+ try {
1838
+ if (!fs.statSync(file).isFile())
1839
+ return `unreadable SessionStart file ${relative}`;
1840
+ bytes = fs.readFileSync(file);
1841
+ }
1842
+ catch {
1843
+ return `unreadable SessionStart file ${relative}`;
1844
+ }
1845
+ if (!shas.includes(createHash('sha256').update(bytes).digest('hex'))) {
1846
+ return `unmodeled SessionStart file ${relative}`;
1847
+ }
1848
+ }
1849
+ return null;
1850
+ }
1792
1851
  /**
1793
1852
  * The one Codex adapter pair the native Codex SubagentStop is modelled on (hq-core v16.0.47):
1794
1853
  * `ADAPTER_RELEASES` and `ADAPTER_CORE_RELEASES` in crates/hq-hook/src/post_hooks/codex.rs.
@@ -1894,7 +1953,7 @@ export const GROK_STOP_OBSERVE_SESSION_ID_LEAF = 'b373b582a906b0993a3ce56aa43c1e
1894
1953
  */
1895
1954
  export const GROK_STOP_OBSERVE_SESSION_ID_PIN = {
1896
1955
  relative: 'core/scripts/lib/session-id.sh',
1897
- accepted: ['2ebbc50893c7c601a111b9e8f9945afeac88f552d7caeec09c4096f4c27a833d'],
1956
+ accepted: ['2ebbc50893c7c601a111b9e8f9945afeac88f552d7caeec09c4096f4c27a833d', 'd6a04155571ec53edd853878cebaba5a5bab93801a73e356499440c1cd009c71'],
1898
1957
  missing: 'allowed',
1899
1958
  };
1900
1959
  /**
@@ -1958,7 +2017,14 @@ export function grokPreToolUseHold(root, shadow) {
1958
2017
  * d6a04155; every other file is one revision.
1959
2018
  */
1960
2019
  export const PRE_TOOL_USE_DISPATCHER_PINS = [
1961
- { relative: '.claude/hooks/hook-gate.sh', accepted: ['a443b481d895e74b46743548d049644ab011b1e5cb8ae3fcb8da1a6a169cd364'] },
2020
+ {
2021
+ relative: '.claude/hooks/hook-gate.sh',
2022
+ accepted: [
2023
+ 'a443b481d895e74b46743548d049644ab011b1e5cb8ae3fcb8da1a6a169cd364',
2024
+ 'fab0ada24e4ac09e05eb5293a795f7f2bde4d58b47ac5112bfc8a5ad4900eda5',
2025
+ '4dd7f5296934d4488c137c9a485d4c9d55b597ee3aa2ceb6dbc3afdb0d3c1a74',
2026
+ ],
2027
+ },
1962
2028
  { relative: '.claude/hooks/hook-timeout-probe.sh', accepted: ['ae5c40212c088044205e246a5715a53f52c28f4021e798bd7a74df6ba570113b'] },
1963
2029
  { relative: '.claude/hooks/hook-timeout-watchdog.sh', accepted: ['3017517bbcd618be5162c621105c229aeba66fea1c39f6dd744416029f0448b5'] },
1964
2030
  { relative: '.claude/hooks/machine-check-owner.sh', accepted: ['04ee93b3669470930732a2f6f7d9f0011fe7221d3ee0fe706b8f468cd30da16d'] },
@@ -2153,13 +2219,19 @@ export function preToolUseHold(root, host, hooks = []) {
2153
2219
  ?? (host === 'claude' ? pinnedFilesHold(root, 'PreToolUse', PRE_TOOL_USE_IMAGE_GUARD_PINS) : null);
2154
2220
  }
2155
2221
  /**
2156
- * The scripts the native first-prompt company bind rebuilds, each at one revision:
2222
+ * The scripts the native first-prompt company bind rebuilds:
2157
2223
  * `MENTION_LIBS` in crates/hq-hook/src/prompt_company_mention/bind.rs, then `SCRIPTS`, `ID_LIBS` and
2158
2224
  * `CAPABILITY_LIBS` in crates/hq-hook/src/session_set/mod.rs.
2159
2225
  */
2160
2226
  export const PROMPT_COMPANY_BIND_PINS = [
2161
- { relative: 'core/scripts/lib/prompt-company-mention.sh', accepted: ['6c68e31d0605db272a6b922e361d1e7659ab77e96faaf613c62afa192aef4ee0'] },
2162
- { relative: 'core/scripts/hq-session.sh', accepted: ['db701162f71b53fd2188974d2f46c58250593dde1252d65b36e6d02b9a765fe7', '02a37c5dbf4fb5af27cc64d0f271121e990758b757a479f60e9ce099f4d65ded'] },
2227
+ {
2228
+ relative: 'core/scripts/lib/prompt-company-mention.sh',
2229
+ accepted: [
2230
+ '6c68e31d0605db272a6b922e361d1e7659ab77e96faaf613c62afa192aef4ee0',
2231
+ '6cb4ec8619305729dd9d38d9c2dbfb6de42ac64e234eebb6d83995b2b4216ad4',
2232
+ ],
2233
+ },
2234
+ { relative: 'core/scripts/hq-session.sh', accepted: ['db701162f71b53fd2188974d2f46c58250593dde1252d65b36e6d02b9a765fe7', '02a37c5dbf4fb5af27cc64d0f271121e990758b757a479f60e9ce099f4d65ded', 'd4d4aef60ff8b095e3abcc817598f376d3c2de8d59758c3ed6dd40d4aa4b11fb'] },
2163
2235
  { relative: 'core/scripts/lib/session-id.sh', accepted: ['2ebbc50893c7c601a111b9e8f9945afeac88f552d7caeec09c4096f4c27a833d'] },
2164
2236
  { relative: 'core/scripts/lib/session-scope-capability.sh', accepted: ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead'] },
2165
2237
  ];
@@ -2186,6 +2258,7 @@ export function promptCompanyBindHold(root) {
2186
2258
  * (crates/hq-hook/src/gate/facts.rs `accepted_hook_lib_sha256`).
2187
2259
  */
2188
2260
  export const POLICY_GATE_REVISIONS = [
2261
+ { revision: 'Core16_0_51', gate: 'ca58a94859eae0a345c11c8d9c59303eb76350dc1cf223391037d21979c28718', hookLibs: ['9133295e5ce523bf8355a093bbea5a1c19682ec42b59ab6b626dffbc33544f3f'] },
2189
2262
  { revision: 'Staging2018', gate: '1bc4df8eaabded175804d2effba704c93b439df05c0867f85bb27f5dcfbc7914', hookLibs: ['9133295e5ce523bf8355a093bbea5a1c19682ec42b59ab6b626dffbc33544f3f'] },
2190
2263
  { revision: 'Core16_0_48Beta90', gate: 'a2879dfe692233f5953bac86672947bbd82f3c5247292f3efcb80f16c3d2c6b1', hookLibs: ['9133295e5ce523bf8355a093bbea5a1c19682ec42b59ab6b626dffbc33544f3f', '49c337ceccf0a2d7c2a64f6b1de8c3c4d1da507bc5d7afcd01ed292e1f25abf7', 'be7ca74b2524afba56fefd530bf46cbd1dd39a4c181b6a64c87e124b29bdebe7'] },
2191
2264
  { revision: 'Core16_0_48Beta68', gate: '6005f2315210c31daf0c870b768303bfd15f58f3416c52b6e02da9bcb430e9bb', hookLibs: ['c3eb950f80aea21d3f8ad2bc0f76656e6c5a39a5197b4d985aa03d13144fc8a7'] },
@@ -2217,15 +2290,21 @@ const ADAPTER_CORE = 'core/scripts/lib/hook-adapter-core.sh';
2217
2290
  export const CODEX_POST_TOOL_USE_GENERATIONS = [
2218
2291
  ['3c3196254614df7b14dccad507dcee3299fa8cf9c163a6903eac2d86fb2159c5', '98da450068af022eb1eee5420a4eca98867b91690e57316ee565eb7788fb6e7a'],
2219
2292
  ['a3178b59e633310f3cc39a8c257ff58863169696ffda04dc6ea93a34a5db05ef', '940bb5a0a268929a4cd3f88b61a0ce619f0fdf64e5d3f25f7f18da35df466ab5'],
2293
+ ['a3178b59e633310f3cc39a8c257ff58863169696ffda04dc6ea93a34a5db05ef', CLASSIFYING_ADAPTER_CORE_SHA256],
2220
2294
  ];
2221
2295
  /** The (Grok adapter, hook-adapter-core.sh) pairs of crates/hq-hook/src/post_hooks/grok.rs `ADAPTER_GENERATIONS`. */
2222
2296
  export const GROK_POST_TOOL_USE_GENERATIONS = [
2223
2297
  ['56d5ce126646589e4ca5b2a2a29f9e11900891d1c791310d23fef757aae02904', '98da450068af022eb1eee5420a4eca98867b91690e57316ee565eb7788fb6e7a'],
2224
2298
  ['f9664658ba328e2d8107c1e0b58ef797d892811130a21ba7d6fd6f83d17a4a9d', 'e750ab8b96cefcac007088f1fb583ff56af8a1169666656518b862296a149f0c'],
2225
2299
  ['b9075b2f96a6ef8d2ba9675e32ce5881d50522da4eca02b69e6dc8bcd57efddf', '940bb5a0a268929a4cd3f88b61a0ce619f0fdf64e5d3f25f7f18da35df466ab5'],
2300
+ ['b9075b2f96a6ef8d2ba9675e32ce5881d50522da4eca02b69e6dc8bcd57efddf', CLASSIFYING_ADAPTER_CORE_SHA256],
2226
2301
  ];
2227
2302
  /** The hook-adapter-core.sh revisions of crates/hq-hook/src/host/fleet/local_pre.rs `RELEASED_CORE_SHA256`. */
2228
- export const FLEET_LOCAL_ADAPTER_CORE = ['940bb5a0a268929a4cd3f88b61a0ce619f0fdf64e5d3f25f7f18da35df466ab5'];
2303
+ export const FLEET_LOCAL_ADAPTER_CORE = [
2304
+ '940bb5a0a268929a4cd3f88b61a0ce619f0fdf64e5d3f25f7f18da35df466ab5',
2305
+ RELEASED_CLASSIFYING_ADAPTER_CORE_SHA256,
2306
+ CLASSIFYING_ADAPTER_CORE_SHA256,
2307
+ ];
2229
2308
  /**
2230
2309
  * Why PostToolUse must stay on the shell adapter of `host` in `root`: the native adapter work
2231
2310
  * refuses the root's adapter scripts. Null for a host with no adapter pin, and where the native
@@ -2354,4 +2433,90 @@ export function forHost(target, root, host, env) {
2354
2433
  return null;
2355
2434
  return { ...target, events };
2356
2435
  }
2436
+ /**
2437
+ * Revisions of `core/scripts/lib/hook-adapter-core.sh` whose `hqad_classify_exec`
2438
+ * classifies both `run --host claude <Event> --hq-root <root> [--global]` and the
2439
+ * `stable` symlink alias as `master\t<Event>` (hq-core-staging #2119, ITEM 502/502b).
2440
+ * Both the released revision and the current pin are recorded in `adapter-core-pin.ts`.
2441
+ */
2442
+ export const CLASSIFYING_ADAPTER_CORE_HASHES = [
2443
+ RELEASED_CLASSIFYING_ADAPTER_CORE_SHA256,
2444
+ CLASSIFYING_ADAPTER_CORE_SHA256,
2445
+ ];
2446
+ /**
2447
+ * Returns whether the HQ root's `core/scripts/lib/hook-adapter-core.sh` is a
2448
+ * pinned revision known to classify new-core `run --host claude` and `stable`
2449
+ * entries in `.claude/settings.json`.
2450
+ */
2451
+ export function adapterCoreClassifiesNewCore(root) {
2452
+ try {
2453
+ const bytes = fs.readFileSync(path.join(root, ADAPTER_CORE));
2454
+ const hash = createHash('sha256').update(bytes).digest('hex');
2455
+ return CLASSIFYING_ADAPTER_CORE_HASHES.includes(hash);
2456
+ }
2457
+ catch {
2458
+ return false;
2459
+ }
2460
+ }
2461
+ /** The Codex and Grok Build shell adapters present in `root`; each reads `<root>/.claude/settings.json`. */
2462
+ export function presentAdapterHosts(root) {
2463
+ const hosts = [];
2464
+ if (fs.existsSync(path.join(root, CODEX_ADAPTER)))
2465
+ hosts.push('codex');
2466
+ if (fs.existsSync(path.join(root, GROK_ADAPTER)))
2467
+ hosts.push('grok');
2468
+ return hosts;
2469
+ }
2470
+ /**
2471
+ * Why `event` must stay on `master-hook.sh` in `<root>/.claude/settings.json`
2472
+ * (which adapter hosts hold it there), or null when it may switch (ITEM 502 /
2473
+ * 502b). The Codex and Grok Build shell
2474
+ * adapters find their master record in that file through
2475
+ * `core/scripts/lib/hook-adapter-core.sh`, and an unpatched revision sees only
2476
+ * `master-hook.sh` entries. So while a present adapter host keeps any event
2477
+ * that reads those entries on its shell adapter, the Claude Code project entry
2478
+ * stays on master-hook.sh, whatever holds the host there: its canary (failed,
2479
+ * missing, stale, or a hook-started reindex keeping the host's current core),
2480
+ * a coverage hold for that one event (SubagentStop on Codex), or no new core
2481
+ * at all (flag off, kill switch). `--skip-host-canary-gate` passes every
2482
+ * canary but leaves the coverage holds, so it cannot switch such an event
2483
+ * either.
2484
+ *
2485
+ * Grok Build StopCancelled and StopFailure, which its adapter runs as the
2486
+ * settings.json `Stop` entries, are not tied to Claude Code `Stop` here: their
2487
+ * own switch already reads whether master-hook is among those entries
2488
+ * ([`grokStopObserveUncovered`]), so they follow the Claude Code entry rather
2489
+ * than hold it (tying them both ways would hold both forever).
2490
+ *
2491
+ * `hq reindex` ([`claudeProjectTarget`]) and `hq doctor`
2492
+ * (`host-core:claude-project`) both answer from here: each asks what the
2493
+ * adapter hosts' own reindex registers, through [`forHost`] on the same target.
2494
+ *
2495
+ * User-level `~/.claude/settings.json` is never read by the Codex or Grok
2496
+ * adapters and is unaffected.
2497
+ */
2498
+ export function claudeProjectAdapterHold(root, event, coreNext, env) {
2499
+ const hosts = presentAdapterHosts(root);
2500
+ if (hosts.length === 0 || adapterCoreClassifiesNewCore(root))
2501
+ return null;
2502
+ const held = hosts.filter((host) => {
2503
+ const next = forHost(coreNext, root, host, env);
2504
+ return !next || !next.events.includes(event);
2505
+ });
2506
+ if (held.length === 0)
2507
+ return null;
2508
+ return `${held.join(' and ')} keep${held.length === 1 ? 's' : ''} ${event} on the shell adapter, whose unpatched ${ADAPTER_CORE} reads only master-hook.sh entries`;
2509
+ }
2510
+ /**
2511
+ * `claudeNext` narrowed for `<root>/.claude/settings.json` to the events
2512
+ * [`claudeProjectAdapterHold`] lets switch; null when none does.
2513
+ */
2514
+ export function claudeProjectTarget(coreNext, claudeNext, root, env) {
2515
+ if (!claudeNext)
2516
+ return null;
2517
+ const events = claudeNext.events.filter((event) => claudeProjectAdapterHold(root, event, coreNext, env) === null);
2518
+ if (events.length === claudeNext.events.length)
2519
+ return claudeNext;
2520
+ return events.length > 0 ? { ...claudeNext, events } : null;
2521
+ }
2357
2522
  //# sourceMappingURL=coverage.js.map
@@ -8,7 +8,7 @@ import { addCodexHooks, removeCodexHooks, codexHookEntry, codexHookTrustKeys } f
8
8
  import { engineArgs, isCoreNextEntry, isNativeEntry, registrationEngine } from './registration.js';
9
9
  import { userHookSettingsFile } from './registration-identity.js';
10
10
  import { coreNextArgs, coreNextTargetOrWarn, placeEvent } from '../../utils/host-registration.js';
11
- import { forHost } from './coverage.js';
11
+ import { claudeProjectTarget, forHost } from './coverage.js';
12
12
  /** The project master-hook command shipped in HQ's .claude/settings.json. */
13
13
  function projectClaudeCommand(event) {
14
14
  return 'env BASH_ENV=/dev/null bash "$CLAUDE_PROJECT_DIR/.claude/hooks/master-hook.sh" ' + event;
@@ -135,6 +135,7 @@ export function reconcileHookRegistrations(root, home = homedir(), env = process
135
135
  // flag-off path.
136
136
  const coreNext = coreNextTargetOrWarn(home, env);
137
137
  const claudeNext = forHost(coreNext, root, 'claude', env);
138
+ const claudeProjectNext = claudeProjectTarget(coreNext, claudeNext, root, env);
138
139
  const codexNext = forHost(coreNext, root, 'codex', env);
139
140
  const launcher = registrationEngine(home, env);
140
141
  const native = coreNext ?? (launcher ? { engine: launcher } : null);
@@ -153,7 +154,7 @@ export function reconcileHookRegistrations(root, home = homedir(), env = process
153
154
  // Claude Code project files: settings.json and the settings.local.json
154
155
  // Claude Code merges over it, together.
155
156
  try {
156
- result.failures.push(...reconcileClaudeProject(root, home, claudeNext, launcher, ours, !!native));
157
+ result.failures.push(...reconcileClaudeProject(root, home, claudeProjectNext, launcher, ours, !!native));
157
158
  }
158
159
  catch (error) {
159
160
  result.failures.push(`${join(root, '.claude/settings.json')}: ${error.message}`);