@indigoai-us/hq-cli 5.345.247 → 5.345.250

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 (284) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/assets/lanes-hooks/hq-lanes-drain.sh +1 -1
  3. package/contracts/host-canary-release.json +14 -0
  4. package/dist/command-catalog.generated.d.ts +1198 -0
  5. package/dist/command-catalog.generated.js +1476 -0
  6. package/dist/command-registration-plan.d.ts +6 -0
  7. package/dist/command-registration-plan.js +1 -0
  8. package/dist/commands/core-job-run-native.js +4 -0
  9. package/dist/commands/core-knowledge-prefs.d.ts +1 -1
  10. package/dist/commands/core-knowledge-prefs.js +1 -16
  11. package/dist/commands/core.js +0 -2
  12. package/dist/commands/daemon.js +21 -0
  13. package/dist/commands/lanes-hold.js +7 -7
  14. package/dist/commands/lanes-resume.js +2 -2
  15. package/dist/commands/lanes-review.js +1 -1
  16. package/dist/commands/lanes-session-start.d.ts +1 -1
  17. package/dist/commands/lanes-session-start.js +3 -3
  18. package/dist/commands/lanes-shared.d.ts +1 -1
  19. package/dist/commands/lanes.d.ts +2 -2
  20. package/dist/commands/lanes.js +50 -50
  21. package/dist/commands/mesh.d.ts +25 -0
  22. package/dist/commands/mesh.js +48 -8
  23. package/dist/commands/ontology-graph.d.ts +63 -0
  24. package/dist/commands/ontology-graph.js +470 -0
  25. package/dist/commands/sync-core.js +6 -0
  26. package/dist/fast-scaffold.js +1 -3
  27. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +281 -256
  28. package/dist/hq-cloud-sync-runner/package.json +1 -1
  29. package/dist/index.d.ts +8 -0
  30. package/dist/index.js +48 -1
  31. package/dist/lanes-monitor-check-argv.d.ts +1 -1
  32. package/dist/lanes-monitor-check-argv.js +1 -1
  33. package/dist/lanes-monitor-check-fast.d.ts +1 -1
  34. package/dist/lanes-monitor-check-fast.js +1 -1
  35. package/dist/lanes-session-start-argv.d.ts +1 -1
  36. package/dist/lanes-session-start-argv.js +1 -1
  37. package/dist/lib/capacity/sign-in.d.ts +1 -1
  38. package/dist/lib/capacity/sign-in.js +1 -1
  39. package/dist/lib/daemon/hook-requests-conduct-link.js +2 -2
  40. package/dist/lib/daemon/installed-cli-restart.d.ts +57 -0
  41. package/dist/lib/daemon/installed-cli-restart.js +114 -0
  42. package/dist/lib/daemon/lanes-monitor-state.d.ts +2 -2
  43. package/dist/lib/daemon/lanes-monitor-state.js +2 -2
  44. package/dist/lib/daemon/legacy-journal-gate.d.ts +32 -0
  45. package/dist/lib/daemon/legacy-journal-gate.js +102 -0
  46. package/dist/lib/daemon/machine-checks.d.ts +7 -0
  47. package/dist/lib/daemon/machine-checks.js +10 -0
  48. package/dist/lib/daemon/merge-sections.d.ts +3 -3
  49. package/dist/lib/daemon/merge-sections.js +7 -7
  50. package/dist/lib/daemon/remote-control-pools.js +1 -1
  51. package/dist/lib/daemon/run.d.ts +3 -1
  52. package/dist/lib/daemon/run.js +49 -6
  53. package/dist/lib/daemon/state-file.d.ts +1 -1
  54. package/dist/lib/daemon/state-file.js +1 -1
  55. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  56. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  57. package/dist/lib/flag-snapshot-file.d.ts +2 -0
  58. package/dist/lib/flag-snapshot-file.js +118 -48
  59. package/dist/lib/hook-engine/canary-gate.d.ts +57 -3
  60. package/dist/lib/hook-engine/canary-gate.js +138 -6
  61. package/dist/lib/hook-engine/coverage.d.ts +82 -13
  62. package/dist/lib/hook-engine/coverage.js +214 -18
  63. package/dist/lib/hook-engine/registration-identity.d.ts +5 -0
  64. package/dist/lib/hook-engine/registration-identity.js +1 -1
  65. package/dist/lib/hook-engine/resolve.d.ts +23 -0
  66. package/dist/lib/hook-engine/resolve.js +48 -1
  67. package/dist/lib/hook-engine/stable-heal.d.ts +87 -0
  68. package/dist/lib/hook-engine/stable-heal.js +214 -0
  69. package/dist/lib/hot-channels/graph-context.d.ts +105 -0
  70. package/dist/lib/hot-channels/graph-context.js +380 -0
  71. package/dist/lib/hot-channels/signals-pass.js +27 -1
  72. package/dist/lib/lanes/claude-credential.d.ts +1 -1
  73. package/dist/lib/lanes/claude-credential.js +1 -1
  74. package/dist/lib/lanes/delivery-core.d.ts +1 -1
  75. package/dist/lib/lanes/delivery-core.js +1 -1
  76. package/dist/lib/lanes/delivery.d.ts +10 -10
  77. package/dist/lib/lanes/delivery.js +8 -8
  78. package/dist/lib/lanes/dropbox.d.ts +1 -1
  79. package/dist/lib/lanes/dropbox.js +1 -1
  80. package/dist/lib/lanes/hooks-install.js +2 -2
  81. package/dist/lib/lanes/index.d.ts +1 -1
  82. package/dist/lib/lanes/index.js +1 -1
  83. package/dist/lib/lanes/monitor.js +1 -1
  84. package/dist/lib/lanes/quota-notice.js +1 -1
  85. package/dist/lib/lanes/quota.d.ts +1 -1
  86. package/dist/lib/lanes/quota.js +1 -1
  87. package/dist/lib/lanes/repo-merge-hold.d.ts +2 -2
  88. package/dist/lib/lanes/repo-merge-hold.js +2 -2
  89. package/dist/lib/lanes/spawn.d.ts +4 -4
  90. package/dist/lib/lanes/spawn.js +5 -5
  91. package/dist/lib/mesh/live/company-flag-refresh.d.ts +61 -0
  92. package/dist/lib/mesh/live/company-flag-refresh.js +159 -0
  93. package/dist/lib/mesh/live/company-reporting-gaps.d.ts +61 -0
  94. package/dist/lib/mesh/live/company-reporting-gaps.js +238 -0
  95. package/dist/lib/mesh/live/daemon/duplicate-unit.d.ts +156 -0
  96. package/dist/lib/mesh/live/daemon/duplicate-unit.js +616 -0
  97. package/dist/lib/mesh/live/daemon/run.d.ts +13 -0
  98. package/dist/lib/mesh/live/daemon/run.js +35 -2
  99. package/dist/lib/mesh/live/direct-drain.js +1 -1
  100. package/dist/lib/mesh/live/emit.d.ts +3 -0
  101. package/dist/lib/mesh/live/emit.js +32 -9
  102. package/dist/lib/mesh/live/flush.d.ts +3 -0
  103. package/dist/lib/mesh/live/flush.js +115 -32
  104. package/dist/lib/mesh/live/liveness-carry.d.ts +1 -1
  105. package/dist/lib/mesh/live/liveness-carry.js +1 -1
  106. package/dist/lib/mesh/live/reporting-privacy.d.ts +119 -3
  107. package/dist/lib/mesh/live/reporting-privacy.js +235 -11
  108. package/dist/lib/mesh/live/spool.d.ts +17 -2
  109. package/dist/lib/mesh/live/spool.js +22 -6
  110. package/dist/lib/ontology-graph/legacy/coverage.d.ts +67 -0
  111. package/dist/lib/ontology-graph/legacy/coverage.js +192 -0
  112. package/dist/lib/ontology-graph/legacy/index.d.ts +199 -0
  113. package/dist/lib/ontology-graph/legacy/index.js +1150 -0
  114. package/dist/lib/ontology-graph/legacy/parse.d.ts +49 -0
  115. package/dist/lib/ontology-graph/legacy/parse.js +126 -0
  116. package/dist/lib/ontology-graph/legacy/report.d.ts +14 -0
  117. package/dist/lib/ontology-graph/legacy/report.js +254 -0
  118. package/dist/lib/ontology-graph/legacy/verb-map.d.ts +35 -0
  119. package/dist/lib/ontology-graph/legacy/verb-map.js +84 -0
  120. package/dist/lib/ontology-graph/lint/checks.d.ts +140 -0
  121. package/dist/lib/ontology-graph/lint/checks.js +717 -0
  122. package/dist/lib/ontology-graph/lint/coverage.d.ts +106 -0
  123. package/dist/lib/ontology-graph/lint/coverage.js +241 -0
  124. package/dist/lib/ontology-graph/lint/daily-job.d.ts +259 -0
  125. package/dist/lib/ontology-graph/lint/daily-job.js +595 -0
  126. package/dist/lib/ontology-graph/lint/index.d.ts +65 -0
  127. package/dist/lib/ontology-graph/lint/index.js +176 -0
  128. package/dist/lib/ontology-graph/model/files.d.ts +20 -0
  129. package/dist/lib/ontology-graph/model/files.js +89 -0
  130. package/dist/lib/ontology-graph/model/index.d.ts +65 -0
  131. package/dist/lib/ontology-graph/model/index.js +100 -0
  132. package/dist/lib/ontology-graph/model/pass-tasks.d.ts +156 -0
  133. package/dist/lib/ontology-graph/model/pass-tasks.js +345 -0
  134. package/dist/lib/ontology-graph/model/pass.d.ts +109 -0
  135. package/dist/lib/ontology-graph/model/pass.js +958 -0
  136. package/dist/lib/ontology-graph/model/runner.d.ts +50 -0
  137. package/dist/lib/ontology-graph/model/runner.js +160 -0
  138. package/dist/lib/ontology-graph/model/step.d.ts +197 -0
  139. package/dist/lib/ontology-graph/model/step.js +526 -0
  140. package/dist/lib/ontology-graph/model/tasks.d.ts +183 -0
  141. package/dist/lib/ontology-graph/model/tasks.js +349 -0
  142. package/dist/lib/ontology-graph/not-implemented.d.ts +5 -0
  143. package/dist/lib/ontology-graph/not-implemented.js +8 -0
  144. package/dist/lib/ontology-graph/org/compare.d.ts +28 -0
  145. package/dist/lib/ontology-graph/org/compare.js +239 -0
  146. package/dist/lib/ontology-graph/org/derive.d.ts +67 -0
  147. package/dist/lib/ontology-graph/org/derive.js +359 -0
  148. package/dist/lib/ontology-graph/org/index.d.ts +102 -0
  149. package/dist/lib/ontology-graph/org/index.js +630 -0
  150. package/dist/lib/ontology-graph/org/load.d.ts +31 -0
  151. package/dist/lib/ontology-graph/org/load.js +476 -0
  152. package/dist/lib/ontology-graph/org/role.d.ts +38 -0
  153. package/dist/lib/ontology-graph/org/role.js +268 -0
  154. package/dist/lib/ontology-graph/org/structure.d.ts +63 -0
  155. package/dist/lib/ontology-graph/org/structure.js +437 -0
  156. package/dist/lib/ontology-graph/org/text.d.ts +97 -0
  157. package/dist/lib/ontology-graph/org/text.js +321 -0
  158. package/dist/lib/ontology-graph/org/types.d.ts +457 -0
  159. package/dist/lib/ontology-graph/org/types.js +80 -0
  160. package/dist/lib/ontology-graph/pages/index.d.ts +64 -0
  161. package/dist/lib/ontology-graph/pages/index.js +193 -0
  162. package/dist/lib/ontology-graph/pages/render.d.ts +144 -0
  163. package/dist/lib/ontology-graph/pages/render.js +688 -0
  164. package/dist/lib/ontology-graph/proposals/apply.d.ts +109 -0
  165. package/dist/lib/ontology-graph/proposals/apply.js +468 -0
  166. package/dist/lib/ontology-graph/proposals/group.d.ts +63 -0
  167. package/dist/lib/ontology-graph/proposals/group.js +232 -0
  168. package/dist/lib/ontology-graph/proposals/index.d.ts +173 -0
  169. package/dist/lib/ontology-graph/proposals/index.js +474 -0
  170. package/dist/lib/ontology-graph/proposals/model.d.ts +162 -0
  171. package/dist/lib/ontology-graph/proposals/model.js +196 -0
  172. package/dist/lib/ontology-graph/proposals/org-chart.d.ts +82 -0
  173. package/dist/lib/ontology-graph/proposals/org-chart.js +340 -0
  174. package/dist/lib/ontology-graph/read/brief.d.ts +26 -0
  175. package/dist/lib/ontology-graph/read/brief.js +254 -0
  176. package/dist/lib/ontology-graph/read/graph-index.d.ts +76 -0
  177. package/dist/lib/ontology-graph/read/graph-index.js +198 -0
  178. package/dist/lib/ontology-graph/read/index.d.ts +59 -0
  179. package/dist/lib/ontology-graph/read/index.js +803 -0
  180. package/dist/lib/ontology-graph/read/member.d.ts +7 -0
  181. package/dist/lib/ontology-graph/read/member.js +34 -0
  182. package/dist/lib/ontology-graph/read/names.d.ts +49 -0
  183. package/dist/lib/ontology-graph/read/names.js +297 -0
  184. package/dist/lib/ontology-graph/read/reader-setting.d.ts +19 -0
  185. package/dist/lib/ontology-graph/read/reader-setting.js +62 -0
  186. package/dist/lib/ontology-graph/read/test-graph.d.ts +37 -0
  187. package/dist/lib/ontology-graph/read/test-graph.js +150 -0
  188. package/dist/lib/ontology-graph/replay/buffered-store.d.ts +33 -0
  189. package/dist/lib/ontology-graph/replay/buffered-store.js +50 -0
  190. package/dist/lib/ontology-graph/replay/config.d.ts +41 -0
  191. package/dist/lib/ontology-graph/replay/config.js +105 -0
  192. package/dist/lib/ontology-graph/replay/engine.d.ts +146 -0
  193. package/dist/lib/ontology-graph/replay/engine.js +1240 -0
  194. package/dist/lib/ontology-graph/replay/extractors.d.ts +59 -0
  195. package/dist/lib/ontology-graph/replay/extractors.js +1555 -0
  196. package/dist/lib/ontology-graph/replay/index.d.ts +91 -0
  197. package/dist/lib/ontology-graph/replay/index.js +220 -0
  198. package/dist/lib/ontology-graph/replay/listing-manifest.d.ts +66 -0
  199. package/dist/lib/ontology-graph/replay/listing-manifest.js +242 -0
  200. package/dist/lib/ontology-graph/replay/member.d.ts +19 -0
  201. package/dist/lib/ontology-graph/replay/member.js +65 -0
  202. package/dist/lib/ontology-graph/replay/mentions.d.ts +58 -0
  203. package/dist/lib/ontology-graph/replay/mentions.js +239 -0
  204. package/dist/lib/ontology-graph/replay/readers.d.ts +98 -0
  205. package/dist/lib/ontology-graph/replay/readers.js +1251 -0
  206. package/dist/lib/ontology-graph/replay/rules.d.ts +127 -0
  207. package/dist/lib/ontology-graph/replay/rules.js +374 -0
  208. package/dist/lib/ontology-graph/replay/scope.d.ts +35 -0
  209. package/dist/lib/ontology-graph/replay/scope.js +115 -0
  210. package/dist/lib/ontology-graph/replay/transcripts.d.ts +39 -0
  211. package/dist/lib/ontology-graph/replay/transcripts.js +224 -0
  212. package/dist/lib/ontology-graph/replay/util.d.ts +55 -0
  213. package/dist/lib/ontology-graph/replay/util.js +256 -0
  214. package/dist/lib/ontology-graph/resolve/entity-index.d.ts +159 -0
  215. package/dist/lib/ontology-graph/resolve/entity-index.js +652 -0
  216. package/dist/lib/ontology-graph/resolve/index.d.ts +113 -0
  217. package/dist/lib/ontology-graph/resolve/index.js +214 -0
  218. package/dist/lib/ontology-graph/resolve/machine.d.ts +34 -0
  219. package/dist/lib/ontology-graph/resolve/machine.js +95 -0
  220. package/dist/lib/ontology-graph/resolve/normalize.d.ts +35 -0
  221. package/dist/lib/ontology-graph/resolve/normalize.js +124 -0
  222. package/dist/lib/ontology-graph/resolve/org-chart.d.ts +107 -0
  223. package/dist/lib/ontology-graph/resolve/org-chart.js +578 -0
  224. package/dist/lib/ontology-graph/resolve/org-layer.d.ts +78 -0
  225. package/dist/lib/ontology-graph/resolve/org-layer.js +159 -0
  226. package/dist/lib/ontology-graph/resolve/org-seed.d.ts +141 -0
  227. package/dist/lib/ontology-graph/resolve/org-seed.js +631 -0
  228. package/dist/lib/ontology-graph/resolve/org-sources.d.ts +165 -0
  229. package/dist/lib/ontology-graph/resolve/org-sources.js +634 -0
  230. package/dist/lib/ontology-graph/resolve/roster.d.ts +76 -0
  231. package/dist/lib/ontology-graph/resolve/roster.js +226 -0
  232. package/dist/lib/ontology-graph/resolve/seed.d.ts +267 -0
  233. package/dist/lib/ontology-graph/resolve/seed.js +1198 -0
  234. package/dist/lib/ontology-graph/resolve/upsert.d.ts +58 -0
  235. package/dist/lib/ontology-graph/resolve/upsert.js +139 -0
  236. package/dist/lib/ontology-graph/resolve/writer.d.ts +128 -0
  237. package/dist/lib/ontology-graph/resolve/writer.js +351 -0
  238. package/dist/lib/ontology-graph/schema/authority.d.ts +107 -0
  239. package/dist/lib/ontology-graph/schema/authority.js +186 -0
  240. package/dist/lib/ontology-graph/schema/default-schema.d.ts +10 -0
  241. package/dist/lib/ontology-graph/schema/default-schema.js +242 -0
  242. package/dist/lib/ontology-graph/schema/grammar.d.ts +57 -0
  243. package/dist/lib/ontology-graph/schema/grammar.js +409 -0
  244. package/dist/lib/ontology-graph/schema/index.d.ts +12 -0
  245. package/dist/lib/ontology-graph/schema/index.js +10 -0
  246. package/dist/lib/ontology-graph/schema/validate.d.ts +13 -0
  247. package/dist/lib/ontology-graph/schema/validate.js +132 -0
  248. package/dist/lib/ontology-graph/store/files.d.ts +34 -0
  249. package/dist/lib/ontology-graph/store/files.js +207 -0
  250. package/dist/lib/ontology-graph/store/fs.d.ts +30 -0
  251. package/dist/lib/ontology-graph/store/fs.js +101 -0
  252. package/dist/lib/ontology-graph/store/graph-store.d.ts +14 -0
  253. package/dist/lib/ontology-graph/store/graph-store.js +520 -0
  254. package/dist/lib/ontology-graph/store/index.d.ts +18 -0
  255. package/dist/lib/ontology-graph/store/index.js +15 -0
  256. package/dist/lib/ontology-graph/store/ingest.d.ts +37 -0
  257. package/dist/lib/ontology-graph/store/ingest.js +323 -0
  258. package/dist/lib/ontology-graph/store/paths.d.ts +114 -0
  259. package/dist/lib/ontology-graph/store/paths.js +232 -0
  260. package/dist/lib/ontology-graph/types.d.ts +1190 -0
  261. package/dist/lib/ontology-graph/types.js +131 -0
  262. package/dist/lib/secret-scan/gitleaks-rules.generated.js +1 -1
  263. package/dist/lib/sync-core/engine-holds.d.ts +1 -1
  264. package/dist/lib/sync-core/engine-holds.js +12 -2
  265. package/dist/lib/sync-core/hand-back.d.ts +2 -1
  266. package/dist/lib/sync-core/hand-back.js +16 -2
  267. package/dist/lib/sync-core/legacy-journal-export-child.d.ts +2 -0
  268. package/dist/lib/sync-core/legacy-journal-export-child.js +24 -0
  269. package/dist/lib/sync-core/legacy-journal-export.d.ts +39 -0
  270. package/dist/lib/sync-core/legacy-journal-export.js +241 -0
  271. package/dist/lib/sync-core/legacy-journal-reader.d.ts +15 -0
  272. package/dist/lib/sync-core/legacy-journal-reader.js +56 -0
  273. package/dist/lib/sync-core/reconcile.d.ts +3 -0
  274. package/dist/lib/sync-core/reconcile.js +43 -3
  275. package/dist/utils/cli-telemetry.d.ts +1 -0
  276. package/dist/utils/cli-telemetry.js +6 -3
  277. package/dist/utils/frontmatter.d.ts +14 -0
  278. package/dist/utils/frontmatter.js +18 -0
  279. package/dist/utils/hook-engine-rollup.d.ts +96 -0
  280. package/dist/utils/hook-engine-rollup.js +725 -0
  281. package/dist/utils/interactive-caller.js +1 -1
  282. package/package.json +9 -9
  283. package/scripts/install-hook-engine.mjs +4 -0
  284. package/assets/scaffold/core/scripts/knowledge-prefs.sh +0 -55
@@ -1716,6 +1716,12 @@ export function uncoveredHooks(root, host, event, covers, env = process.env) {
1716
1716
  if (hold)
1717
1717
  missing.push(`(native PreToolUse compatibility: ${hold})`);
1718
1718
  }
1719
+ if (event === 'PreToolUse' && covered.includes('master-hook:PreToolUse')) {
1720
+ const hold = preToolUseHold(root, host, hooks);
1721
+ const reason = hold ? `(native PreToolUse compatibility: ${hold})` : null;
1722
+ if (reason && !missing.includes(reason))
1723
+ missing.push(reason);
1724
+ }
1719
1725
  // The native natural-language-router runs where the registry lists it; its claim and master-hook's switch the event.
1720
1726
  if (event === 'UserPromptSubmit' && covered.includes('master-hook:UserPromptSubmit') && covered.includes('natural-language-router') && hooks.includes('natural-language-router')) {
1721
1727
  const hold = promptCompanyBindHold(root);
@@ -1895,28 +1901,218 @@ export const GROK_PRE_TOOL_USE_ADAPTER_PINS = [
1895
1901
  { relative: '.grok/hooks/hq-grok-hook-adapter.sh', accepted: ['b9075b2f96a6ef8d2ba9675e32ce5881d50522da4eca02b69e6dc8bcd57efddf'], missing: 'allowed' },
1896
1902
  { relative: 'core/scripts/lib/hook-adapter-core.sh', accepted: ['940bb5a0a268929a4cd3f88b61a0ce619f0fdf64e5d3f25f7f18da35df466ab5'], missing: 'allowed' },
1897
1903
  ];
1898
- /**
1899
- * The merged-write-guard-shadow wrapper and its .cjs the native Grok member models
1900
- * (crates/hq-hook/src/merged_write_guard.rs `SCRIPT_SHA256` 63ddff4a and `CJS_SHA256` 225e5c89; the
1901
- * released 742870a2 and 6f65f2b9, which pretool_merged_write_guard.rs models by the wrapper's
1902
- * sha256). A root without them runs no shadow row, so a missing file is not held.
1903
- */
1904
- export const GROK_SHADOW_GUARD_PINS = [
1905
- { relative: '.claude/hooks/merged-write-guard-shadow.sh', accepted: ['63ddff4a40e861d8d922b0701863259a3cedbffaf6d44a94d837865e62cca6ac', '742870a2ada4f9357320f7708fca7363be6d81fde374948b59873c327a7d7206'], missing: 'allowed' },
1906
- { relative: '.claude/hooks/merged-write-guard-shadow.cjs', accepted: ['225e5c89501ab87965db46e6520c0fd8d08ec5e9745068a2e7324e64f7360884', '6f65f2b9425612f9b2ec2590dace82585230210dcd69a124a9cdeb0116ea7f30'], missing: 'allowed' },
1907
- ];
1908
1904
  /**
1909
1905
  * Why Grok PreToolUse must stay on the shell adapter in `root`: the adapter or its library is not the
1910
1906
  * pair the native work is modelled on, or (when `shadow`, the registry lists the claimed
1911
- * merged-write-guard-shadow row) the wrapper or its .cjs is not a revision the native member
1912
- * models. Unlike the other holds there is no run-time refusal to mirror: on another adapter the
1913
- * native side would answer with the v16.0.50 model, so the hold is the only guard. A missing file is
1914
- * not held: the hold guards against another revision. The merge-hold shim is not pinned:
1915
- * the claimed merge-gates-ready member reads hold records, never the shim.
1907
+ * merged-write-guard-shadow row) the shadow companions are not a set the native member accepts
1908
+ * (`mergedWriteGuardHold`). For the adapter there is no run-time refusal to mirror: on another
1909
+ * adapter the native side would answer with the v16.0.50 model, so the hold is the only guard, and a
1910
+ * missing adapter file is not held. The merge-hold shim is not pinned: the claimed
1911
+ * merge-gates-ready member reads hold records, never the shim.
1916
1912
  */
1917
1913
  export function grokPreToolUseHold(root, shadow) {
1918
1914
  return pinnedFilesHold(root, 'PreToolUse', GROK_PRE_TOOL_USE_ADAPTER_PINS)
1919
- ?? (shadow ? pinnedFilesHold(root, 'PreToolUse', GROK_SHADOW_GUARD_PINS) : null);
1915
+ ?? (shadow ? mergedWriteGuardHold(root, 'PreToolUse') : null);
1916
+ }
1917
+ /**
1918
+ * The dispatcher files the native PreToolUse master model reproduces, in its check order:
1919
+ * crates/hq-hook/src/pre_tool_use_master.rs `DISPATCHER_PINS`. master-hook.sh is v16.0.48 (1a2439ae),
1920
+ * v16.0.50 (774bca73) or v16.0.49 (d5049d5f); every other file is one revision.
1921
+ */
1922
+ export const PRE_TOOL_USE_DISPATCHER_PINS = [
1923
+ { relative: '.claude/hooks/hook-gate.sh', accepted: ['a443b481d895e74b46743548d049644ab011b1e5cb8ae3fcb8da1a6a169cd364'] },
1924
+ { relative: '.claude/hooks/hook-timeout-probe.sh', accepted: ['ae5c40212c088044205e246a5715a53f52c28f4021e798bd7a74df6ba570113b'] },
1925
+ { relative: '.claude/hooks/hook-timeout-watchdog.sh', accepted: ['3017517bbcd618be5162c621105c229aeba66fea1c39f6dd744416029f0448b5'] },
1926
+ { relative: '.claude/hooks/machine-check-owner.sh', accepted: ['04ee93b3669470930732a2f6f7d9f0011fe7221d3ee0fe706b8f468cd30da16d'] },
1927
+ {
1928
+ relative: '.claude/hooks/master-hook.sh',
1929
+ accepted: [
1930
+ '1a2439aee50652c5143ccd18561a0aa84a1e94848d02c1aa1c99157f70023f29',
1931
+ '774bca73a2e806b4d9ad96b803525bdf25afd2265d63c9216881aa4ced403f16',
1932
+ 'd5049d5fb38d2b33467d493a4a136df8f6d9021c29e722df0d1e6a17d7f452ab',
1933
+ ],
1934
+ },
1935
+ { relative: '.claude/hooks/turn-timing.sh', accepted: ['97c70a3251225ba9e469e41fd3fe2341cfe2936490f54571d2ca16de8e766443'] },
1936
+ { relative: 'core/scripts/hook-lib.sh', accepted: ['9133295e5ce523bf8355a093bbea5a1c19682ec42b59ab6b626dffbc33544f3f'] },
1937
+ { relative: 'core/scripts/hq-anywhere-runtime-flag.cjs', accepted: ['8a484cef83d383b440462798ac13e26d132e10bbe509b47e0eb1a3d0db76b2b4'] },
1938
+ { relative: 'core/scripts/hqd-hook-flag-cache-lib.sh', accepted: ['061d264460408e9eaf43fdf0fdde662c906a9a7dacb4e7a591e684bca28c138a'] },
1939
+ { relative: 'core/scripts/hqd-hook-shim.sh', accepted: ['ab289ac0af680fe3bcacb110302ca8b998bdc33c6f94321d42bd04a344163eed'] },
1940
+ { relative: 'core/scripts/lib/advisory-cap.sh', accepted: ['ab80b2a3f63a5955db392eaff4e54fed88d20130e96ca5c2a0945a3ea146d39b'] },
1941
+ { relative: 'core/scripts/lib/epochrealtime.sh', accepted: ['4c9205520dba31533c95eea145f6068ba626885c342c2aa1f232a7237d046cdf'] },
1942
+ { relative: 'core/scripts/lib/hook-adapter-core.sh', accepted: ['940bb5a0a268929a4cd3f88b61a0ce619f0fdf64e5d3f25f7f18da35df466ab5'] },
1943
+ { relative: 'core/scripts/lib/perl-child-locale.sh', accepted: ['18e6b9d0e22874eea00ecc868b4dcfebbc3bb42434d8d0c81b20baec1194df2e'] },
1944
+ { relative: 'core/scripts/lib/session-id.sh', accepted: ['2ebbc50893c7c601a111b9e8f9945afeac88f552d7caeec09c4096f4c27a833d'] },
1945
+ { relative: 'core/scripts/lib/session-scope-capability.sh', accepted: ['388ffef43cfe05810c38ce377245d0d86f415b4009b21a008bca8897be0c9ead'] },
1946
+ { relative: 'core/scripts/resolve-hq-root.sh', accepted: ['188e99c7c60bc9909290a666d6f3b93387ae6cf68f2eeb41fd24c2dea62a5240'] },
1947
+ ];
1948
+ /** The Codex adapter the model reproduces on Codex only (pre_tool_use_master.rs `CODEX_ADAPTER_PIN`). */
1949
+ export const PRE_TOOL_USE_CODEX_ADAPTER_PIN = {
1950
+ relative: '.codex/hooks/hq-codex-hook-adapter.sh',
1951
+ accepted: ['a3178b59e633310f3cc39a8c257ff58863169696ffda04dc6ea93a34a5db05ef'],
1952
+ };
1953
+ /**
1954
+ * The claimed vault-write guard's script and the companions it reads (crates/hq-hook/src/ports.rs
1955
+ * `HOOK_SCRIPT_SHA256` and `HOOK_COMPANION_SHA256` for enforce-vault-write-access). Its arithmetic
1956
+ * library is left out, as in `CLAIMED_MEMBER_IGNORES`: the claimed member does not read it. The
1957
+ * credential guard holds that file.
1958
+ */
1959
+ export const PRE_TOOL_USE_VAULT_GUARD_PINS = [
1960
+ { relative: '.claude/hooks/enforce-vault-write-access.sh', accepted: ['1a139c4d45c687cce355333f445b7b1d6e0848f72c1f1fbae11229db93213dd9'] },
1961
+ {
1962
+ relative: 'core/scripts/hook-lib.sh',
1963
+ accepted: [
1964
+ '9133295e5ce523bf8355a093bbea5a1c19682ec42b59ab6b626dffbc33544f3f',
1965
+ 'df3d8ddc15a0c179227c9ba7f855c040973fcee249673156d08b2e2ff2c850b8',
1966
+ 'b971dae4a2b82bfa5b31782e54717115abaf052457fb1a546893d04cae43adbb',
1967
+ ],
1968
+ },
1969
+ { relative: '.claude/hooks/enforce-vault-write-access-flag.cjs', accepted: ['87dbddf1867296562ce76096c47869bca5c1a6a262b526421ac96aecfef90c45'] },
1970
+ ];
1971
+ /**
1972
+ * The credential guard's script revisions, each with the arithmetic library its port follows
1973
+ * (ports.rs `HOOK_SCRIPT_SHA256`, `HOOK_COMPANION_SHA256` and `COMPANION_SCRIPT_BINDINGS`): the
1974
+ * 16.0.48 script 6512581d and its 16.0.51-beta.44 successor 5064061f only with e90d160f, every
1975
+ * other revision only with 0566180c.
1976
+ */
1977
+ export const PRE_TOOL_USE_CREDENTIAL_GUARD_GENERATIONS = [
1978
+ ['25f5507cc97bfe700a8505f59463b4f42280c60d4733110c0a5faabb87cda4f3', '0566180ce52bed559d57a08247bf39c8ec1cec6b7e271da496d0c09077fc6f57'],
1979
+ ['0555a4bda2bbf5c4aa47f4bec2641e0db629d8b59a1042c8bee85adebd505c8f', '0566180ce52bed559d57a08247bf39c8ec1cec6b7e271da496d0c09077fc6f57'],
1980
+ ['72296f0148eb32e1c00e34099109d919ea7cd22ae5e81517e95298a7f237498a', '0566180ce52bed559d57a08247bf39c8ec1cec6b7e271da496d0c09077fc6f57'],
1981
+ ['30015cbcae48b7227d3e271dd73235b2eac8d7b86955ac653d30ca3c377bc599', '0566180ce52bed559d57a08247bf39c8ec1cec6b7e271da496d0c09077fc6f57'],
1982
+ ['6512581d1200558d4ef78dfb11eca4a92f663042c6b0b11b2e6664762139e2a0', 'e90d160fed02cbcf7e33aed679233af5a9cf9f9a87dd979aba04493a37c00ec8'],
1983
+ ['5064061fd64da6d56c0c974c0719f6729b23dba9ab1a768e1ba70d5a9645c8ae', 'e90d160fed02cbcf7e33aed679233af5a9cf9f9a87dd979aba04493a37c00ec8'],
1984
+ ];
1985
+ const CREDENTIAL_GUARD = '.claude/hooks/block-credential-file-read.sh';
1986
+ const CREDENTIAL_ARITH_LIB = '.claude/hooks/bash-arith-subst-guard-lib.sh';
1987
+ /**
1988
+ * The native policy-frontmatter check's evaluator scripts, in the order it reads them
1989
+ * (crates/hq-hook/src/policy_frontmatter.rs `EVAL_TRIGGER_SHA256`, `FORWARDER_LIB_SHA256`,
1990
+ * `FLOOR_LIB_SHA256`). Each is read only once the one before it is on its pin; a missing file
1991
+ * gives the same evaluator-unavailable answer bash gave (or skips the floor check), so it is not
1992
+ * held.
1993
+ */
1994
+ export const PRE_TOOL_USE_FRONTMATTER_EVALUATOR_PINS = [
1995
+ { relative: 'core/scripts/eval-trigger.sh', accepted: ['0066d89590f96855d800cdce2b883f265eaa6b92ac3fbc6649b82bf768772328'], missing: 'allowed' },
1996
+ { relative: 'core/scripts/lib/forwarder.sh', accepted: ['a030068f482cac2ecbfad90394fd7bcd1e24926e9179bcec5c770076ad6e4fc4'], missing: 'allowed' },
1997
+ { relative: 'core/scripts/lib/hq-cli-floor.sh', accepted: ['d5087c69c33250a71dee35174c259e0a301cee1cd02110a1df5e5ca9d6334fac'], missing: 'allowed' },
1998
+ ];
1999
+ /** The native image rule's script (ports.rs `HOOK_SCRIPT_SHA256` image-context-guard) and the hook-lib.sh revisions it accepts. */
2000
+ export const PRE_TOOL_USE_IMAGE_GUARD_PINS = [
2001
+ { relative: '.claude/hooks/image-context-guard.sh', accepted: ['3580ee355d642012df30daa153fff368e6440dbdfea1ebee02ecd27f8f1eb45d'], missing: 'allowed' },
2002
+ {
2003
+ relative: 'core/scripts/hook-lib.sh',
2004
+ accepted: [
2005
+ 'df3d8ddc15a0c179227c9ba7f855c040973fcee249673156d08b2e2ff2c850b8',
2006
+ 'c5c8153f1e6cead7a2cbfc9085788f26970efc79752660ff2c308112622a5c8e',
2007
+ 'b971dae4a2b82bfa5b31782e54717115abaf052457fb1a546893d04cae43adbb',
2008
+ '9133295e5ce523bf8355a093bbea5a1c19682ec42b59ab6b626dffbc33544f3f',
2009
+ ],
2010
+ missing: 'allowed',
2011
+ },
2012
+ ];
2013
+ const MERGED_WRITE_WRAPPER = '.claude/hooks/merged-write-guard-shadow.sh';
2014
+ const MERGED_WRITE_HELPER = '.claude/hooks/merged-write-guard-shadow.cjs';
2015
+ /**
2016
+ * The companion sets of the native merged-write-guard-shadow member
2017
+ * (crates/hq-hook/src/merged_write_guard.rs and merged_write_guard/release_1649.rs). The wrapper's
2018
+ * sha256 picks the set and never refuses by itself: the v16.0.49 wrapper (742870a2) picks
2019
+ * `released`, any other wrapper `legacy`. In a set the helper .cjs, when listed, must match; each
2020
+ * guard may be missing (bash exits 127) but not another revision; hook-lib.sh is read only once a
2021
+ * guard is on its pin, and must then be the set's library.
2022
+ */
2023
+ export const MERGED_WRITE_GUARD_SETS = {
2024
+ releasedWrapper: '742870a2ada4f9357320f7708fca7363be6d81fde374948b59873c327a7d7206',
2025
+ released: {
2026
+ helper: '6f65f2b9425612f9b2ec2590dace82585230210dcd69a124a9cdeb0116ea7f30',
2027
+ guards: [
2028
+ ['.claude/hooks/block-core-writes-bash.sh', '0b4ce070ef18595bd8ee794e2f364720854170a63eb0eb5999e135ada4d1b497'],
2029
+ ['.claude/hooks/block-core-writes.sh', 'a39061417bf31cf251c661ebc3e5bc87ee1bb2424a0552d2aeb266eec3d29fcc'],
2030
+ ['core/hooks/PreToolUse/10-Edit,Write,MultiEdit--block-repo-edits-use-worktree.sh', 'c4c0786ff75ef466f3cd6068e3d54b3fd68c3e3cfabb98debfe1de770523526c'],
2031
+ ],
2032
+ hookLib: '9133295e5ce523bf8355a093bbea5a1c19682ec42b59ab6b626dffbc33544f3f',
2033
+ },
2034
+ legacy: {
2035
+ helper: null,
2036
+ guards: [
2037
+ ['.claude/hooks/block-core-writes-bash.sh', '1c52342ab3030c1ee5540341dd1c8f6dbe7721c300d900c4947d98f1407638b2'],
2038
+ ['.claude/hooks/block-core-writes.sh', 'e6c14f48c38bd01ed0f2120fd7c18022fd7dd0dac18ed09f2307414a5646932f'],
2039
+ ['core/hooks/PreToolUse/10-Edit,Write,MultiEdit--block-repo-edits-use-worktree.sh', 'c4c0786ff75ef466f3cd6068e3d54b3fd68c3e3cfabb98debfe1de770523526c'],
2040
+ ],
2041
+ hookLib: 'df3d8ddc15a0c179227c9ba7f855c040973fcee249673156d08b2e2ff2c850b8',
2042
+ },
2043
+ };
2044
+ /** The sha256 of `relative` under `root`, or null when it is not a regular file or cannot be read. */
2045
+ function fileSha256(root, relative) {
2046
+ const file = path.join(root, relative);
2047
+ if (!regularFile(file))
2048
+ return null;
2049
+ try {
2050
+ return createHash('sha256').update(fs.readFileSync(file)).digest('hex');
2051
+ }
2052
+ catch {
2053
+ return null;
2054
+ }
2055
+ }
2056
+ /**
2057
+ * Why the native merged-write-guard-shadow member would refuse a call in `root` (reported for
2058
+ * `event`), or null: see [`MERGED_WRITE_GUARD_SETS`]. A root with no wrapper runs no row. The member
2059
+ * reads these files only for a session whose shadow marker is on, which `hq reindex` cannot know,
2060
+ * so the hold assumes it is.
2061
+ */
2062
+ export function mergedWriteGuardHold(root, event) {
2063
+ if (!regularFile(path.join(root, MERGED_WRITE_WRAPPER)))
2064
+ return null;
2065
+ const set = fileSha256(root, MERGED_WRITE_WRAPPER) === MERGED_WRITE_GUARD_SETS.releasedWrapper ? MERGED_WRITE_GUARD_SETS.released : MERGED_WRITE_GUARD_SETS.legacy;
2066
+ if (set.helper) {
2067
+ const hold = pinnedFilesHold(root, event, [{ relative: MERGED_WRITE_HELPER, accepted: [set.helper] }]);
2068
+ if (hold)
2069
+ return hold;
2070
+ }
2071
+ const guards = pinnedFilesHold(root, event, set.guards.map(([relative, sha]) => ({ relative, accepted: [sha], missing: 'allowed' })));
2072
+ if (guards)
2073
+ return guards;
2074
+ if (!set.guards.some(([relative]) => regularFile(path.join(root, relative))))
2075
+ return null;
2076
+ return pinnedFilesHold(root, event, [{ relative: HOOK_LIB, accepted: [set.hookLib] }]);
2077
+ }
2078
+ /**
2079
+ * Why PreToolUse must stay on the old dispatcher in `root` on `host` once `master-hook:PreToolUse`
2080
+ * is claimed there (`hooks`: the old dispatcher's PreToolUse hooks there). Each part mirrors a
2081
+ * run-time refusal of the native PreToolUse:
2082
+ * - the files it reproduces at pinned revisions (pre_tool_use_master.rs `hold_pins`,
2083
+ * `changed_files_on`, checked by `guard_refusal_in` before any member): missing, not a regular
2084
+ * file or another revision, or the credential guard's script and library not a bound pair. The
2085
+ * Codex adapter is read on Codex only;
2086
+ * - the policy enforcement gate beside the hook-lib.sh its revision accepts (the injector runs it
2087
+ * on Bash calls whatever the registry lists), as for PostToolUse;
2088
+ * - the policy-frontmatter evaluator scripts;
2089
+ * - the merged-write-guard-shadow companions, where the registry lists that row;
2090
+ * - on Claude Code, the image rule's script.
2091
+ * Null when the native PreToolUse accepts every file.
2092
+ */
2093
+ export function preToolUseHold(root, host, hooks = []) {
2094
+ const files = host === 'codex' ? [...PRE_TOOL_USE_DISPATCHER_PINS, PRE_TOOL_USE_CODEX_ADAPTER_PIN] : PRE_TOOL_USE_DISPATCHER_PINS;
2095
+ const credential = PRE_TOOL_USE_CREDENTIAL_GUARD_GENERATIONS;
2096
+ const evaluator = () => {
2097
+ for (const pin of PRE_TOOL_USE_FRONTMATTER_EVALUATOR_PINS) {
2098
+ if (!regularFile(path.join(root, pin.relative)))
2099
+ return null;
2100
+ const hold = pinnedFilesHold(root, 'PreToolUse', [pin]);
2101
+ if (hold)
2102
+ return hold;
2103
+ }
2104
+ return null;
2105
+ };
2106
+ return pinnedFilesHold(root, 'PreToolUse', files)
2107
+ ?? pinnedFilesHold(root, 'PreToolUse', PRE_TOOL_USE_VAULT_GUARD_PINS)
2108
+ ?? pinnedFilesHold(root, 'PreToolUse', [
2109
+ { relative: CREDENTIAL_GUARD, accepted: [...new Set(credential.map(([script]) => script))] },
2110
+ { relative: CREDENTIAL_ARITH_LIB, accepted: [...new Set(credential.map(([, lib]) => lib))] },
2111
+ ], credential)
2112
+ ?? policyGateHold(root, 'PreToolUse')
2113
+ ?? evaluator()
2114
+ ?? (hooks.includes('merged-write-guard-shadow') ? mergedWriteGuardHold(root, 'PreToolUse') : null)
2115
+ ?? (host === 'claude' ? pinnedFilesHold(root, 'PreToolUse', PRE_TOOL_USE_IMAGE_GUARD_PINS) : null);
1920
2116
  }
1921
2117
  /**
1922
2118
  * The scripts the native first-prompt company bind rebuilds, each at one revision:
@@ -1967,14 +2163,14 @@ const HOOK_LIB = 'core/scripts/hook-lib.sh';
1967
2163
  * a listed revision, or a hook-lib.sh that revision does not accept. As there, a root with no gate
1968
2164
  * script runs no gate (no hold) and a root with no hook-lib.sh is not refused for it.
1969
2165
  */
1970
- export function policyGateHold(root) {
2166
+ export function policyGateHold(root, event = 'PostToolUse') {
1971
2167
  if (!regularFile(path.join(root, POLICY_GATE)))
1972
2168
  return null;
1973
2169
  const files = [
1974
2170
  { relative: POLICY_GATE, accepted: POLICY_GATE_REVISIONS.map(({ gate }) => gate) },
1975
2171
  { relative: HOOK_LIB, accepted: POLICY_GATE_REVISIONS.flatMap(({ hookLibs }) => hookLibs), missing: 'allowed' },
1976
2172
  ];
1977
- return pinnedFilesHold(root, 'PostToolUse', files, POLICY_GATE_REVISIONS.flatMap(({ gate, hookLibs }) => hookLibs.map((lib) => [gate, lib])));
2173
+ return pinnedFilesHold(root, event, files, POLICY_GATE_REVISIONS.flatMap(({ gate, hookLibs }) => hookLibs.map((lib) => [gate, lib])));
1978
2174
  }
1979
2175
  const CODEX_ADAPTER = '.codex/hooks/hq-codex-hook-adapter.sh';
1980
2176
  const GROK_ADAPTER = '.grok/hooks/hq-grok-hook-adapter.sh';
@@ -8,6 +8,11 @@ export interface NativeTarget {
8
8
  */
9
9
  export declare function launcherRoot(root: string): string;
10
10
  export declare function engineArgs(root: string, event: string, runtime: 'claude' | 'codex', global?: boolean): string[];
11
+ /**
12
+ * The `--hq-root` value of an HQ entry: the argument after it in exec form,
13
+ * or the single-quoted word after it in a POSIX or PowerShell command string.
14
+ */
15
+ export declare function hqRootArgument(entry: Record<string, unknown>): string | undefined;
11
16
  /**
12
17
  * True when an entry's `--hq-root` names this HQ root: the same spelling
13
18
  * (trailing separators aside), or another spelling of the same folder
@@ -17,7 +17,7 @@ export function engineArgs(root, event, runtime, global = false) {
17
17
  * The `--hq-root` value of an HQ entry: the argument after it in exec form,
18
18
  * or the single-quoted word after it in a POSIX or PowerShell command string.
19
19
  */
20
- function hqRootArgument(entry) {
20
+ export function hqRootArgument(entry) {
21
21
  if (Array.isArray(entry.args)) {
22
22
  const i = entry.args.indexOf('--hq-root');
23
23
  const value = i >= 0 ? entry.args[i + 1] : undefined;
@@ -26,6 +26,29 @@ export declare function assertPinnedHookEngineMatches(engine: EnginePackage): vo
26
26
  export declare function findHookEngine(options?: EngineOptions): EnginePackage | null;
27
27
  /** Never truncate or replace a running Windows executable. */
28
28
  export declare function installHookEngine(options?: EngineOptions): string | null;
29
+ /** A `stable` link that no longer names the engine this CLI pins. */
30
+ export interface StaleStableEngine {
31
+ /** `~/.hq/bin/hq-hook/stable`. */
32
+ stable: string;
33
+ /** The engine this CLI pins. */
34
+ pinned: string;
35
+ /** The version folder the link resolves to now; null when it dangles (that folder is gone). */
36
+ resolved: string | null;
37
+ }
38
+ /**
39
+ * Read only. The `stable` link core.next registrations name, when it is a link
40
+ * that does not resolve to this CLI's pinned engine: an update pinned a new
41
+ * engine and nothing has re-run the gated reconcile (`hq reindex`) yet. Null
42
+ * when there is no link (core.next was never switched on), when `stable` is not
43
+ * a link (the doctor reports that), when this platform has no engine package,
44
+ * or when the link names the pinned engine.
45
+ *
46
+ * Only `hq reindex` moves the link: it re-checks the new engine against the
47
+ * host canary gate, its capabilities and the holds before a host keeps its
48
+ * new-core registrations. Moving it anywhere else would let those
49
+ * registrations run an engine nothing checked.
50
+ */
51
+ export declare function staleStableEngine(options?: EngineOptions): StaleStableEngine | null;
29
52
  /** master-hook.sh reads this one-line file with shell builtins to find the
30
53
  * pinned engine without starting Node (US-021 bridge). It always names the
31
54
  * engine of the CLI that wrote it, so a CLI update retargets it. */
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from 'node:module';
2
2
  import { spawnSync } from 'node:child_process';
3
- import { cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, readlinkSync, renameSync, rmSync, rmdirSync, unlinkSync, writeFileSync } from 'node:fs';
3
+ import { cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, rmdirSync, unlinkSync, writeFileSync } from 'node:fs';
4
4
  import { homedir } from 'node:os';
5
5
  import { dirname, join } from 'node:path';
6
6
  const require = createRequire(import.meta.url);
@@ -115,6 +115,53 @@ export function installHookEngine(options = {}) {
115
115
  writeHookEnginePointer(engine.pinned, options);
116
116
  return engine.pinned;
117
117
  }
118
+ /**
119
+ * Read only. The `stable` link core.next registrations name, when it is a link
120
+ * that does not resolve to this CLI's pinned engine: an update pinned a new
121
+ * engine and nothing has re-run the gated reconcile (`hq reindex`) yet. Null
122
+ * when there is no link (core.next was never switched on), when `stable` is not
123
+ * a link (the doctor reports that), when this platform has no engine package,
124
+ * or when the link names the pinned engine.
125
+ *
126
+ * Only `hq reindex` moves the link: it re-checks the new engine against the
127
+ * host canary gate, its capabilities and the holds before a host keeps its
128
+ * new-core registrations. Moving it anywhere else would let those
129
+ * registrations run an engine nothing checked.
130
+ */
131
+ export function staleStableEngine(options = {}) {
132
+ const stable = join(options.home ?? homedir(), '.hq', 'bin', 'hq-hook', 'stable');
133
+ try {
134
+ if (!lstatSync(stable).isSymbolicLink())
135
+ return null;
136
+ }
137
+ catch (error) {
138
+ if (error.code === 'ENOENT')
139
+ return null;
140
+ throw error;
141
+ }
142
+ const engine = findHookEngine(options);
143
+ if (!engine)
144
+ return null;
145
+ let resolved;
146
+ try {
147
+ resolved = realpathSync(stable);
148
+ }
149
+ catch (error) {
150
+ if (error.code !== 'ENOENT')
151
+ throw error;
152
+ resolved = null;
153
+ }
154
+ // The link names the version folder (host-registration.ts linkStableEngine).
155
+ let folder = engine.pinnedDirectory;
156
+ try {
157
+ folder = realpathSync(engine.pinnedDirectory);
158
+ }
159
+ catch (error) {
160
+ if (error.code !== 'ENOENT')
161
+ throw error;
162
+ }
163
+ return resolved === folder ? null : { stable, pinned: engine.pinned, resolved };
164
+ }
118
165
  /** master-hook.sh reads this one-line file with shell builtins to find the
119
166
  * pinned engine without starting Node (US-021 bridge). It always names the
120
167
  * engine of the CLI that wrote it, so a CLI update retargets it. */
@@ -0,0 +1,87 @@
1
+ /**
2
+ * After an update, heal the `stable` link core.next registrations name by
3
+ * re-running the gated reconcile, never by moving the link directly.
4
+ *
5
+ * `npm install -g @indigoai-us/hq-cli` pins the new engine and rewrites the
6
+ * `current` pointer. `stable` keeps naming the previous engine until
7
+ * `hq reindex` runs; until then read-only resolution refuses it and the doctor
8
+ * fails. The first real `hq` command after an update starts `hq reindex
9
+ * --repo-root <root>` in the background for each HQ root this machine
10
+ * registers on the new core. That is the same reconcile a person runs by hand:
11
+ * the host canary gate, the engine's capabilities and the holds decide per host
12
+ * whether its registrations stay on the new core or go back to the old
13
+ * dispatcher, and it moves `stable`. Until it has run, `stable` keeps the
14
+ * previous engine, which passed its own checks.
15
+ *
16
+ * The postinstall moves nothing ([`staleStableEngine`] only reports).
17
+ *
18
+ * The roots come from the `--hq-root` arguments in the user-scope hook files,
19
+ * so this starts an unattended `hq reindex` in any folder named there. That is
20
+ * no new boundary: only someone who can already write those files (and so
21
+ * already choose what every hook runs) can plant a root.
22
+ *
23
+ * `fleet-local` registrations are not host-canary gated (by design; see
24
+ * host-registration.ts `hostCanaryGate`), so on a fleet box the heal moves them
25
+ * to the new engine at the first command after an update, as a manual
26
+ * reindex would.
27
+ */
28
+ import { type SpawnOptions } from 'node:child_process';
29
+ import { type EngineOptions, type StaleStableEngine } from './resolve.js';
30
+ /** Set in the reindex the heal starts, so that process does not start another. */
31
+ export declare const STABLE_HEAL_ENV = "HQ_STABLE_HEAL";
32
+ /**
33
+ * Removed from the reindex's environment so the host canary gate applies in
34
+ * full: host-registration.ts `REINDEX_FROM_HOOK_ENV` (keeps every host on its
35
+ * current core) and canary-gate.ts `SKIP_CANARY_GATE_ENV` (bypasses the gate).
36
+ * Spelled out here so the start-up path does not load those modules;
37
+ * stable-heal.test.ts checks they match.
38
+ */
39
+ export declare const GATE_WEAKENING_ENV: readonly ["HQ_REINDEX_FROM_HOOK", "HQ_SKIP_HOST_CANARY_GATE"];
40
+ /** A heal for the same pinned engine is not started again within this window. */
41
+ export declare const STABLE_HEAL_RETRY_MS: number;
42
+ export interface StableHealOptions {
43
+ home?: string;
44
+ env?: NodeJS.ProcessEnv;
45
+ cwd?: string;
46
+ platform?: NodeJS.Platform;
47
+ /** Engine lookup overrides (tests). */
48
+ lookup?: Pick<EngineOptions, 'arch' | 'version' | 'resolvePackage'>;
49
+ now?: () => number;
50
+ /** The Node executable and the CLI entry the reindex runs with. */
51
+ execPath?: string;
52
+ cliEntry?: string;
53
+ spawn?: (command: string, args: readonly string[], options: SpawnOptions) => {
54
+ unref(): void;
55
+ };
56
+ }
57
+ export interface StableHealResult {
58
+ stale: StaleStableEngine | null;
59
+ /** The HQ roots a reindex was started for; empty when none was started. */
60
+ roots: string[];
61
+ /** Why no reindex was started, when stale and none was. */
62
+ skipped?: string;
63
+ }
64
+ /**
65
+ * The HQ roots to reconcile: each root a user-scope hook file (Claude Code,
66
+ * Codex, Grok Build) registers on the new core, and this machine's HQ root
67
+ * (`HQ_ROOT`, the root around the current folder, or the installer's record),
68
+ * whose project files and fleet profiles may name `stable` too. Only existing
69
+ * folders, each once.
70
+ */
71
+ export declare function stableHealRoots(home: string, env: NodeJS.ProcessEnv, cwd: string, platform: NodeJS.Platform): string[];
72
+ /**
73
+ * Append a heal that threw to `~/.hq/logs/stable-heal.log`. The command the
74
+ * person ran goes on, and stderr stays clean for the hooks that call hq; the
75
+ * doctor still reports the stale link until a reindex moves it.
76
+ */
77
+ export declare function recordStableHealFailure(error: unknown, home?: string, now?: number): void;
78
+ /**
79
+ * Start the gated reconcile for every HQ root when `stable` no longer names
80
+ * this CLI's pinned engine. Once per pinned engine per hour, whatever the
81
+ * outcome, so a reindex that cannot finish (another holds the root's lock, the
82
+ * gate refuses) does not run on every command. The child runs plain
83
+ * `hq reindex --repo-root <root> --lock-timeout 0` one root after another,
84
+ * with the variables that would weaken the gate removed from its environment.
85
+ */
86
+ export declare function healStableEngine(options?: StableHealOptions): StableHealResult;
87
+ //# sourceMappingURL=stable-heal.d.ts.map