@indigoai-us/hq-cli 5.345.219 → 5.345.221

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 (199) hide show
  1. package/CHANGELOG.md +170 -0
  2. package/dist/command-catalog.generated.d.ts +169 -3
  3. package/dist/command-catalog.generated.js +206 -3
  4. package/dist/commands/auth.js +4 -1
  5. package/dist/commands/bot-runtime.d.ts +18 -5
  6. package/dist/commands/bot-runtime.js +29 -12
  7. package/dist/commands/bot.d.ts +85 -0
  8. package/dist/commands/bot.js +245 -16
  9. package/dist/commands/cloud.d.ts +16 -0
  10. package/dist/commands/cloud.js +112 -102
  11. package/dist/commands/core-checkpoint-native.d.ts +13 -0
  12. package/dist/commands/core-checkpoint-native.js +167 -52
  13. package/dist/commands/core-hook-registration-plan.js +5 -4
  14. package/dist/commands/core-stop-autosave.d.ts +21 -0
  15. package/dist/commands/core-stop-autosave.js +300 -0
  16. package/dist/commands/core.js +2 -0
  17. package/dist/commands/daemon.d.ts +5 -0
  18. package/dist/commands/daemon.js +52 -9
  19. package/dist/commands/doctor-usage.d.ts +5 -0
  20. package/dist/commands/doctor-usage.js +25 -0
  21. package/dist/commands/env.d.ts +49 -4
  22. package/dist/commands/env.js +355 -5
  23. package/dist/commands/integrations.js +84 -3
  24. package/dist/commands/lanes-shared.d.ts +3 -0
  25. package/dist/commands/lanes.d.ts +3 -0
  26. package/dist/commands/lanes.js +87 -3
  27. package/dist/commands/packs.js +23 -0
  28. package/dist/commands/pkg-update.d.ts +6 -0
  29. package/dist/commands/pkg-update.js +15 -7
  30. package/dist/commands/run.js +55 -45
  31. package/dist/commands/sources.js +4 -3
  32. package/dist/commands/sync-core.d.ts +1 -0
  33. package/dist/commands/sync-core.js +77 -3
  34. package/dist/commands/whoami.js +96 -80
  35. package/dist/lib/bot/config.d.ts +17 -0
  36. package/dist/lib/bot/config.js +13 -0
  37. package/dist/lib/bot/fleet-cron.js +29 -4
  38. package/dist/lib/bot/fleet-local.d.ts +30 -2
  39. package/dist/lib/bot/fleet-local.js +60 -1
  40. package/dist/lib/bot/grok-login-scope.d.ts +36 -0
  41. package/dist/lib/bot/grok-login-scope.js +93 -0
  42. package/dist/lib/bot/inflight.d.ts +9 -0
  43. package/dist/lib/bot/jobs/hot-signal-sync.d.ts +51 -0
  44. package/dist/lib/bot/jobs/hot-signal-sync.js +90 -9
  45. package/dist/lib/bot/legacy-provider-login.d.ts +32 -9
  46. package/dist/lib/bot/legacy-provider-login.js +28 -22
  47. package/dist/lib/bot/run.d.ts +29 -5
  48. package/dist/lib/bot/run.js +203 -1
  49. package/dist/lib/bot/runtime-sign-in-check.js +6 -1
  50. package/dist/lib/bot/runtime-sign-in.d.ts +2 -0
  51. package/dist/lib/bot/signals-try-now.d.ts +76 -0
  52. package/dist/lib/bot/signals-try-now.js +111 -0
  53. package/dist/lib/capacity/collectors/claude-oauth.d.ts +22 -3
  54. package/dist/lib/capacity/collectors/claude-oauth.js +78 -22
  55. package/dist/lib/capacity/scheduler.d.ts +8 -0
  56. package/dist/lib/capacity/scheduler.js +5 -2
  57. package/dist/lib/core-utils/sentry-report.js +2 -0
  58. package/dist/lib/daemon/machine-checks.d.ts +22 -1
  59. package/dist/lib/daemon/machine-checks.js +54 -12
  60. package/dist/lib/daemon/run.js +71 -8
  61. package/dist/lib/daemon/runtime-notifications.d.ts +7 -0
  62. package/dist/lib/daemon/runtime-notifications.js +50 -0
  63. package/dist/lib/daemon/stop-autosave-lock.d.ts +19 -0
  64. package/dist/lib/daemon/stop-autosave-lock.js +166 -0
  65. package/dist/lib/daemon/stop-autosave.d.ts +28 -0
  66. package/dist/lib/daemon/stop-autosave.js +111 -0
  67. package/dist/lib/daemon/stop-diagnostics.d.ts +11 -0
  68. package/dist/lib/daemon/stop-diagnostics.js +136 -0
  69. package/dist/lib/daemon/stop-job-executor.d.ts +19 -0
  70. package/dist/lib/daemon/stop-job-executor.js +126 -0
  71. package/dist/lib/daemon/stop-jobs.d.ts +93 -0
  72. package/dist/lib/daemon/stop-jobs.js +599 -0
  73. package/dist/lib/doctor/checks/fleet-hook-core.d.ts +9 -1
  74. package/dist/lib/doctor/checks/fleet-hook-core.js +39 -15
  75. package/dist/lib/doctor/checks/host-core.js +1 -1
  76. package/dist/lib/environment/access-probes.d.ts +234 -0
  77. package/dist/lib/environment/access-probes.js +918 -0
  78. package/dist/lib/environment/profile.d.ts +15 -2
  79. package/dist/lib/environment/profile.js +55 -20
  80. package/dist/lib/environment/rfc3339.d.ts +8 -0
  81. package/dist/lib/environment/rfc3339.js +26 -0
  82. package/dist/lib/environment/work-requirements.d.ts +169 -0
  83. package/dist/lib/environment/work-requirements.js +389 -0
  84. package/dist/lib/hook-engine/coverage.d.ts +137 -7
  85. package/dist/lib/hook-engine/coverage.js +1424 -4
  86. package/dist/lib/hook-engine/fleet-registration.d.ts +17 -5
  87. package/dist/lib/hook-engine/fleet-registration.js +53 -17
  88. package/dist/lib/hook-engine/git-stop-config.json +513 -0
  89. package/dist/lib/hook-engine/native-stop-compatibility.json +311 -0
  90. package/dist/lib/hook-engine/reconcile.js +2 -2
  91. package/dist/lib/hot-channels/alert.d.ts +10 -1
  92. package/dist/lib/hot-channels/alert.js +38 -8
  93. package/dist/lib/hot-channels/signals-claude-login.d.ts +53 -0
  94. package/dist/lib/hot-channels/signals-claude-login.js +96 -0
  95. package/dist/lib/hot-channels/signals-pass.d.ts +143 -17
  96. package/dist/lib/hot-channels/signals-pass.js +324 -17
  97. package/dist/lib/hot-channels/signals-runtime.d.ts +30 -0
  98. package/dist/lib/hot-channels/signals-runtime.js +82 -0
  99. package/dist/lib/install/hook-target.js +1 -1
  100. package/dist/lib/lanes/host-capacity.d.ts +26 -2
  101. package/dist/lib/lanes/host-capacity.js +17 -2
  102. package/dist/lib/lanes/host-compute.d.ts +90 -0
  103. package/dist/lib/lanes/host-compute.js +185 -0
  104. package/dist/lib/lanes/index.d.ts +2 -0
  105. package/dist/lib/lanes/index.js +1 -0
  106. package/dist/lib/lanes/reconcile.js +22 -1
  107. package/dist/lib/lanes/resource-usage.d.ts +155 -0
  108. package/dist/lib/lanes/resource-usage.js +589 -0
  109. package/dist/lib/lanes/run-size.d.ts +46 -0
  110. package/dist/lib/lanes/run-size.js +197 -0
  111. package/dist/lib/lanes/store.js +27 -0
  112. package/dist/lib/lanes/throttle.d.ts +36 -1
  113. package/dist/lib/lanes/throttle.js +47 -10
  114. package/dist/lib/lanes/types.d.ts +40 -0
  115. package/dist/lib/lanes/types.js +2 -2
  116. package/dist/lib/lanes/watcher.js +13 -4
  117. package/dist/lib/lanes/worker-process.d.ts +25 -2
  118. package/dist/lib/lanes/worker-process.js +71 -19
  119. package/dist/lib/placement/match.d.ts +192 -0
  120. package/dist/lib/placement/match.js +667 -0
  121. package/dist/lib/safe-store.d.ts +14 -0
  122. package/dist/lib/safe-store.js +77 -4
  123. package/dist/lib/search-index/index.d.ts +88 -4
  124. package/dist/lib/search-index/index.js +299 -25
  125. package/dist/lib/search-index/max-doc-bytes.d.ts +17 -6
  126. package/dist/lib/search-index/max-doc-bytes.js +48 -23
  127. package/dist/lib/signals/codex-lockdown.d.ts +79 -0
  128. package/dist/lib/signals/codex-lockdown.js +271 -0
  129. package/dist/lib/signals/codex-login.d.ts +37 -0
  130. package/dist/lib/signals/codex-login.js +83 -0
  131. package/dist/lib/signals/engine.d.ts +28 -0
  132. package/dist/lib/signals/engine.js +77 -0
  133. package/dist/lib/signals/reply.d.ts +48 -0
  134. package/dist/lib/signals/reply.js +94 -12
  135. package/dist/lib/signals/run-record.js +6 -1
  136. package/dist/lib/signals/settings.d.ts +5 -0
  137. package/dist/lib/signals/settings.js +2 -0
  138. package/dist/lib/signals/steps/adapters.js +6 -0
  139. package/dist/lib/signals/steps/extract.d.ts +135 -12
  140. package/dist/lib/signals/steps/extract.js +416 -84
  141. package/dist/lib/signals/steps/types.d.ts +21 -0
  142. package/dist/lib/sync-core/engine-home.d.ts +41 -2
  143. package/dist/lib/sync-core/engine-home.js +132 -19
  144. package/dist/lib/sync-core/reconcile.js +1 -1
  145. package/dist/lib/sync-core/release-compare.d.ts +7 -0
  146. package/dist/lib/sync-core/release-compare.js +16 -0
  147. package/dist/lib/sync-core/release.d.ts +2 -1
  148. package/dist/lib/sync-core/release.js +2 -10
  149. package/dist/lib/sync-core/rollout-state.d.ts +2 -1
  150. package/dist/lib/sync-core/rollout-state.js +5 -2
  151. package/dist/lib/sync-core/vault-uid.d.ts +2 -0
  152. package/dist/lib/sync-core/vault-uid.js +4 -0
  153. package/dist/run/schema-env-overrides.d.ts +24 -0
  154. package/dist/run/schema-env-overrides.js +72 -0
  155. package/dist/schemas/hq-work-requirements.v1.schema.json +145 -0
  156. package/dist/utils/auth-session-check.d.ts +16 -0
  157. package/dist/utils/auth-session-check.js +16 -0
  158. package/dist/utils/client-health-contract.d.ts +6 -0
  159. package/dist/utils/client-health-contract.js +13 -0
  160. package/dist/utils/client-health.d.ts +7 -0
  161. package/dist/utils/client-health.js +22 -1
  162. package/dist/utils/command-usage.d.ts +40 -0
  163. package/dist/utils/command-usage.js +61 -0
  164. package/dist/utils/duplicate-command-usage.d.ts +72 -0
  165. package/dist/utils/duplicate-command-usage.js +125 -0
  166. package/dist/utils/host-registration.d.ts +1 -1
  167. package/dist/utils/host-registration.js +6 -1
  168. package/dist/utils/resident-package-preload.js +4 -0
  169. package/dist/utils/sentry-fingerprint.js +9 -0
  170. package/dist/utils/windows-bash.d.ts +2 -0
  171. package/dist/utils/windows-bash.js +2 -1
  172. package/package.json +15 -10
  173. package/scripts/bench-core-compare.mjs +313 -0
  174. package/scripts/bench-core.mjs +399 -12
  175. package/scripts/check-function-manifest.mjs +121 -7
  176. package/dist/commands/__fixtures__/access-vault.d.ts +0 -95
  177. package/dist/commands/__fixtures__/access-vault.js +0 -166
  178. package/dist/commands/__fixtures__/make-tar.d.ts +0 -38
  179. package/dist/commands/__fixtures__/make-tar.js +0 -102
  180. package/dist/commands/secrets-public-types.test-d.d.ts +0 -2
  181. package/dist/commands/secrets-public-types.test-d.js +0 -18
  182. package/dist/lib/decisions/fixtures/us001.d.ts +0 -137
  183. package/dist/lib/decisions/fixtures/us001.js +0 -21
  184. package/dist/lib/doctor/__testing__/fake-hq-tree.d.ts +0 -226
  185. package/dist/lib/doctor/__testing__/fake-hq-tree.js +0 -408
  186. package/dist/lib/doctor/__testing__/run-doctor.d.ts +0 -8
  187. package/dist/lib/doctor/__testing__/run-doctor.js +0 -69
  188. package/dist/lib/fingerprint/fixtures.d.ts +0 -19
  189. package/dist/lib/fingerprint/fixtures.js +0 -61
  190. package/dist/lib/hot-channels/adapters/__fixtures__/dummy.d.ts +0 -33
  191. package/dist/lib/hot-channels/adapters/__fixtures__/dummy.js +0 -53
  192. package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.d.ts +0 -38
  193. package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.js +0 -64
  194. package/dist/lib/mesh/live/daemon/mqtt-events.test-d.d.ts +0 -2
  195. package/dist/lib/mesh/live/daemon/mqtt-events.test-d.js +0 -10
  196. package/dist/lib/test-utils/isolated-flag-company-context.d.ts +0 -3
  197. package/dist/lib/test-utils/isolated-flag-company-context.js +0 -18
  198. package/scripts/hook-engine-manifest.mjs +0 -22
  199. package/scripts/mesh-daemon-if-stale.mjs +0 -20
@@ -1,408 +0,0 @@
1
- /**
2
- * buildFakeHqTree — a reusable test harness that materialises a fake HQ tree in
3
- * the OS temp directory from a declarative spec.
4
- *
5
- * Every `hq doctor` check is fundamentally a function of the on-disk shape of an
6
- * HQ tree: which hooks exist, whether they are executable, whether they are
7
- * registered in settings, which `hook-gate.sh` profiles list them, and whether
8
- * the Codex mirror still matches its Claude original. This helper lets a test
9
- * declare that shape — including its deliberately-broken variants — and get back
10
- * a throwaway tree plus a manifest describing exactly what was written, without
11
- * ever touching the real HQ tree.
12
- *
13
- * Design notes:
14
- * - Everything is written under a `mkdtempSync` root inside `os.tmpdir()`. The
15
- * real HQ tree is never read or written.
16
- * - The root path is canonicalised with `realpathSync` so callers can assert
17
- * containment under the temp dir on platforms (macOS) where the temp dir is
18
- * a symlink (`/var` -> `/private/var`).
19
- * - Cleanup is automatic: the first build registers a single `process` exit
20
- * handler that removes every tracked root, so nothing survives a test run,
21
- * including on test failure. `tree.cleanup()` is also exposed for eager
22
- * removal, and is idempotent.
23
- *
24
- * The reference for this pattern is core/scripts/test-codex-hook-adapter.sh,
25
- * which stands up a throwaway HQ tree with `mktemp -d` and stubbed hook scripts.
26
- */
27
- import { spawnSync } from "node:child_process";
28
- import * as fs from "node:fs";
29
- import * as os from "node:os";
30
- import * as path from "node:path";
31
- /** Canonical ordering of the gate profiles. */
32
- export const GATE_PROFILES = [
33
- "minimal",
34
- "standard",
35
- "strict",
36
- ];
37
- const DEFAULT_HOOK_BODY = "#!/bin/bash\ncat >/dev/null\nexit 0\n";
38
- const EXECUTABLE_MODE = 0o755;
39
- const NON_EXECUTABLE_MODE = 0o644;
40
- const DEFAULT_PREFIX = "hq-doctor-fake-";
41
- /** The lifecycle events the shipped `.codex/config.toml` wires. */
42
- const ADAPTER_DEFAULT_EVENTS = [
43
- "SessionStart",
44
- "UserPromptSubmit",
45
- "PreToolUse",
46
- "PostToolUse",
47
- "Stop",
48
- "SubagentStop",
49
- "PreCompact",
50
- "SessionEnd",
51
- ];
52
- // --- Automatic cleanup registry ------------------------------------------------
53
- const trackedRoots = new Set();
54
- let exitHandlerRegistered = false;
55
- /** Remove every fake HQ tree still on disk. Safe to call repeatedly. */
56
- export function cleanupAllFakeHqTrees() {
57
- for (const root of trackedRoots) {
58
- removeTree(root);
59
- }
60
- trackedRoots.clear();
61
- }
62
- /** The set of tree roots this process is still tracking for cleanup. */
63
- export function trackedFakeHqTreeRoots() {
64
- return [...trackedRoots];
65
- }
66
- function removeTree(root) {
67
- try {
68
- fs.rmSync(root, { recursive: true, force: true });
69
- }
70
- catch {
71
- // Best-effort: never let cleanup throw and mask a test's real failure.
72
- }
73
- }
74
- /**
75
- * Register a single process-exit handler that sweeps every tracked root. Bound
76
- * once (guarded by a module flag) so repeated builds do not pile up listeners.
77
- * `exit` fires on normal completion and after a failed test run alike, which is
78
- * what guarantees no temp dir survives.
79
- */
80
- function ensureExitHandler() {
81
- if (exitHandlerRegistered)
82
- return;
83
- exitHandlerRegistered = true;
84
- process.on("exit", cleanupAllFakeHqTrees);
85
- }
86
- // --- Builder -------------------------------------------------------------------
87
- /**
88
- * Materialise a fake HQ tree from `spec` and return its root, manifest, and a
89
- * cleanup handle. The tree lives under `os.tmpdir()` and is swept automatically
90
- * when the process exits.
91
- */
92
- export function buildFakeHqTree(spec = {}) {
93
- ensureExitHandler();
94
- const prefix = spec.prefix ?? DEFAULT_PREFIX;
95
- const root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), prefix)));
96
- trackedRoots.add(root);
97
- const claudeHooksDir = path.join(root, ".claude", "hooks");
98
- const codexHooksDir = path.join(root, ".codex", "hooks");
99
- fs.mkdirSync(claudeHooksDir, { recursive: true });
100
- fs.mkdirSync(codexHooksDir, { recursive: true });
101
- // A `core/` directory is what marks this as an HQ tree for later root
102
- // discovery; cheap to add and keeps the fixture realistic.
103
- fs.mkdirSync(path.join(root, "core", "scripts"), { recursive: true });
104
- const adapterSpec = spec.codexAdapter === true ? {} : (spec.codexAdapter ?? null);
105
- const hookSpecs = spec.hooks ?? [];
106
- const hookEntries = hookSpecs.map((hook) =>
107
- // Adapter-architecture trees have no per-hook mirrors unless a hook
108
- // explicitly declares one (to model a pre-adapter leftover).
109
- writeHook(claudeHooksDir, codexHooksDir, hook, adapterSpec === null));
110
- // hook-gate.sh carries the three profile lists, aggregated across every
111
- // hook's `profiles`. Legacy trees mirror it to `.codex/hooks/` too; adapter
112
- // trees run the Claude gate directly, so no mirror is written there.
113
- const gateSource = renderHookGate(hookEntries);
114
- const claudeHookGatePath = path.join(claudeHooksDir, "hook-gate.sh");
115
- const codexHookGatePath = path.join(codexHooksDir, "hook-gate.sh");
116
- writeScript(claudeHookGatePath, gateSource, EXECUTABLE_MODE);
117
- if (adapterSpec === null) {
118
- writeScript(codexHookGatePath, gateSource, EXECUTABLE_MODE);
119
- }
120
- const claudeSettingsPath = path.join(root, ".claude", "settings.json");
121
- fs.writeFileSync(claudeSettingsPath, JSON.stringify(renderClaudeSettings(hookEntries, spec.claudeSettings), null, 2) + "\n");
122
- const codexHooksJsonPath = path.join(root, ".codex", "hooks.json");
123
- if (adapterSpec === null || adapterSpec.legacyHooksJson) {
124
- fs.writeFileSync(codexHooksJsonPath, JSON.stringify(renderCodexHooksJson(root, hookEntries), null, 2) + "\n");
125
- }
126
- const adapterPaths = writeCodexAdapter(root, codexHooksDir, adapterSpec);
127
- const grok = writeGrok(root, spec.grok);
128
- let gitInitialised = false;
129
- if (spec.git) {
130
- gitInitialised = initGitRepo(root);
131
- }
132
- const manifest = {
133
- root,
134
- claudeSettingsPath,
135
- claudeHooksDir,
136
- claudeHookGatePath,
137
- codexHooksJsonPath,
138
- codexHooksDir,
139
- codexHookGatePath,
140
- codexConfigTomlPath: adapterPaths.configTomlPath,
141
- codexAdapterPath: adapterPaths.adapterPath,
142
- grokDir: grok.dir,
143
- grokAdapterPath: grok.adapterPath,
144
- grokRegistrationPath: grok.registrationPath,
145
- grokBridgeInstalled: grok.bridgeInstalled,
146
- gitInitialised,
147
- hooks: hookEntries,
148
- };
149
- let cleaned = false;
150
- const cleanup = () => {
151
- if (cleaned)
152
- return;
153
- cleaned = true;
154
- removeTree(root);
155
- trackedRoots.delete(root);
156
- };
157
- return {
158
- root,
159
- manifest,
160
- path: (...segments) => path.join(root, ...segments),
161
- cleanup,
162
- };
163
- }
164
- // --- Hook materialisation ------------------------------------------------------
165
- function writeHook(claudeHooksDir, codexHooksDir, hook, defaultMirror) {
166
- const claudeBody = hook.body ?? DEFAULT_HOOK_BODY;
167
- const present = hook.present !== false;
168
- const registered = hook.registered !== false;
169
- const events = hook.events ?? ["SessionStart", "PreToolUse"];
170
- const profiles = hook.profiles ?? [...GATE_PROFILES];
171
- const scriptPath = path.join(claudeHooksDir, `${hook.id}.sh`);
172
- let mode = null;
173
- let executable = false;
174
- if (present) {
175
- const targetMode = resolveMode(hook.mode, hook.executable);
176
- writeScript(scriptPath, claudeBody, targetMode);
177
- mode = statMode(scriptPath);
178
- executable = isExecutable(mode);
179
- }
180
- const codex = writeCodexMirror(codexHooksDir, hook, claudeBody, defaultMirror);
181
- return {
182
- id: hook.id,
183
- scriptPath,
184
- present,
185
- mode,
186
- executable,
187
- registered,
188
- events,
189
- matcher: hook.matcher ?? null,
190
- profiles,
191
- codex,
192
- };
193
- }
194
- function writeCodexMirror(codexHooksDir, hook, claudeBody, defaultMirror) {
195
- // `codex: false` => a Claude hook with no Codex counterpart. An undeclared
196
- // mirror defaults to healthy on legacy trees and to absent on adapter trees.
197
- if (hook.codex === false)
198
- return null;
199
- if (hook.codex === undefined && !defaultMirror)
200
- return null;
201
- const codexSpec = hook.codex ?? {};
202
- const present = codexSpec.present !== false;
203
- const registered = codexSpec.registered !== false;
204
- const body = codexSpec.body ?? claudeBody;
205
- const drifted = body !== claudeBody;
206
- const scriptPath = path.join(codexHooksDir, `${hook.id}.sh`);
207
- let mode = null;
208
- let executable = false;
209
- if (present) {
210
- const targetMode = resolveMode(codexSpec.mode, codexSpec.executable);
211
- writeScript(scriptPath, body, targetMode);
212
- mode = statMode(scriptPath);
213
- executable = isExecutable(mode);
214
- }
215
- return { scriptPath, present, mode, executable, registered, drifted };
216
- }
217
- function renderClaudeSettings(hooks, extra) {
218
- const events = {};
219
- for (const hook of hooks) {
220
- if (!hook.registered)
221
- continue;
222
- const command = `bash "$CLAUDE_PROJECT_DIR/.claude/hooks/hook-gate.sh" ${hook.id} ` +
223
- `"$CLAUDE_PROJECT_DIR/.claude/hooks/${hook.id}.sh"`;
224
- for (const event of hook.events) {
225
- (events[event] ??= []).push(makeSettingsEntry(command, hook.matcher ?? undefined));
226
- }
227
- }
228
- return { ...extra, hooks: events };
229
- }
230
- function renderCodexHooksJson(root, hooks) {
231
- const events = {};
232
- for (const hook of hooks) {
233
- if (!hook.codex || !hook.codex.registered)
234
- continue;
235
- const gate = `${root}/.codex/hooks/hook-gate.sh`;
236
- const script = `${root}/.codex/hooks/${hook.id}.sh`;
237
- const command = `'${gate}' ${hook.id} '${script}'`;
238
- for (const event of hook.events) {
239
- (events[event] ??= []).push(makeSettingsEntry(command, hook.matcher ?? undefined));
240
- }
241
- }
242
- return { hooks: events };
243
- }
244
- function makeSettingsEntry(command, matcher) {
245
- const entry = {
246
- hooks: [{ type: "command", command, timeout: 5 }],
247
- };
248
- if (matcher)
249
- entry.matcher = matcher;
250
- return entry;
251
- }
252
- /**
253
- * Render a self-contained `hook-gate.sh` whose three profile functions list the
254
- * hook ids assigned to each profile, modelled on the real gate in
255
- * `.claude/hooks/hook-gate.sh`. Self-contained so the fixture never has to
256
- * source the real HQ tree.
257
- */
258
- function renderHookGate(hooks) {
259
- const byProfile = {
260
- minimal: [],
261
- standard: [],
262
- strict: [],
263
- };
264
- for (const hook of hooks) {
265
- for (const profile of hook.profiles) {
266
- byProfile[profile].push(hook.id);
267
- }
268
- }
269
- const fns = GATE_PROFILES.map((profile) => renderProfileFunction(profile, byProfile[profile])).join("\n\n");
270
- return `#!/bin/bash
271
- # Fake hook-gate.sh generated by buildFakeHqTree (test fixture — not the real gate).
272
- set -euo pipefail
273
-
274
- if [ $# -lt 2 ]; then
275
- echo "USAGE: hook-gate.sh <hook-id> <actual-hook-script> [args...]" >&2
276
- exit 1
277
- fi
278
-
279
- HOOK_ID="$1"
280
- HOOK_SCRIPT="$2"
281
- shift 2
282
-
283
- PROFILE="\${HQ_HOOK_PROFILE:-standard}"
284
-
285
- ${fns}
286
-
287
- should_run=0
288
- case "$PROFILE" in
289
- minimal)
290
- if is_in_minimal_profile "$HOOK_ID"; then should_run=1; fi
291
- ;;
292
- standard)
293
- if is_in_standard_profile "$HOOK_ID"; then should_run=1; fi
294
- ;;
295
- strict)
296
- if is_in_strict_profile "$HOOK_ID"; then should_run=1; fi
297
- ;;
298
- *)
299
- echo "ERROR: Unknown profile '$PROFILE'. Use minimal|standard|strict" >&2
300
- exit 1
301
- ;;
302
- esac
303
-
304
- if [ "$should_run" -eq 0 ]; then
305
- exit 0
306
- fi
307
-
308
- exec "$HOOK_SCRIPT" "$@"
309
- `;
310
- }
311
- function renderProfileFunction(profile, ids) {
312
- const caseBlock = ids.length > 0 ? ` ${ids.join("|")})\n return 0\n ;;\n` : "";
313
- return `is_in_${profile}_profile() {
314
- case "$1" in
315
- ${caseBlock} *)
316
- return 1
317
- ;;
318
- esac
319
- }`;
320
- }
321
- /**
322
- * Materialise the adapter-architecture wiring: `.codex/config.toml` routing the
323
- * spec'd events to `hq-codex-hook-adapter.sh`, the adapter script itself, and
324
- * the `core/scripts/lib/hook-adapter-core.sh` dispatch library it sources —
325
- * mirroring the shape the hq-core release ships.
326
- */
327
- function writeCodexAdapter(root, codexHooksDir, spec) {
328
- if (spec === null)
329
- return { configTomlPath: null, adapterPath: null };
330
- const events = spec.events ?? [...ADAPTER_DEFAULT_EVENTS];
331
- const adapterPath = path.join(codexHooksDir, "hq-codex-hook-adapter.sh");
332
- const command = `exec /bin/bash "$PWD/.codex/hooks/hq-codex-hook-adapter.sh"`;
333
- const blocks = events.map((event) => `[[hooks.${event}]]\n\n[[hooks.${event}.hooks]]\ntype = "command"\ncommand = '${command}'\ntimeout = 30\n`);
334
- const configTomlPath = path.join(root, ".codex", "config.toml");
335
- fs.writeFileSync(configTomlPath, `[features]\nhooks = true\n\n${blocks.join("\n")}`);
336
- if (spec.adapterPresent !== false) {
337
- writeScript(adapterPath, "#!/bin/bash\ncat >/dev/null\nexit 0\n", spec.adapterExecutable === false ? NON_EXECUTABLE_MODE : EXECUTABLE_MODE);
338
- }
339
- if (spec.dispatchLibPresent !== false) {
340
- const libPath = path.join(root, "core", "scripts", "lib");
341
- fs.mkdirSync(libPath, { recursive: true });
342
- fs.writeFileSync(path.join(libPath, "hook-adapter-core.sh"), "# fake hook-adapter-core.sh (test fixture)\n");
343
- }
344
- return { configTomlPath, adapterPath };
345
- }
346
- function writeGrok(root, spec) {
347
- const absent = {
348
- dir: null,
349
- adapterPath: null,
350
- registrationPath: null,
351
- bridgeInstalled: false,
352
- };
353
- if (spec === false)
354
- return absent;
355
- const grokSpec = spec ?? {};
356
- if (grokSpec.present === false)
357
- return absent;
358
- const dir = path.join(root, ".grok", "hooks");
359
- fs.mkdirSync(dir, { recursive: true });
360
- const adapterPath = path.join(dir, "hq-grok-hook-adapter.sh");
361
- writeScript(adapterPath, "#!/bin/bash\ncat >/dev/null\nexit 0\n", grokSpec.adapterExecutable === false ? NON_EXECUTABLE_MODE : EXECUTABLE_MODE);
362
- const registrationPath = path.join(dir, "hq-grok.json");
363
- const registration = {
364
- hooks: {
365
- PreToolUse: [
366
- {
367
- hooks: [
368
- { type: "command", command: "./hq-grok-hook-adapter.sh", timeout: 30 },
369
- ],
370
- },
371
- ],
372
- },
373
- };
374
- fs.writeFileSync(registrationPath, JSON.stringify(registration, null, 2) + "\n");
375
- return {
376
- dir,
377
- adapterPath,
378
- registrationPath,
379
- bridgeInstalled: grokSpec.bridgeInstalled !== false,
380
- };
381
- }
382
- // --- git -----------------------------------------------------------------------
383
- function initGitRepo(root) {
384
- // Seed a git repo the way the reference harness does, without shelling out
385
- // for identity config: write it straight into .git/config.
386
- const res = spawnSync("git", ["init", "-q", "-b", "main"], { cwd: root });
387
- if (res.status !== 0)
388
- return false;
389
- fs.appendFileSync(path.join(root, ".git", "config"), "[user]\n\temail = fake-hq-tree@example.com\n\tname = fake-hq-tree\n[commit]\n\tgpgsign = false\n");
390
- return true;
391
- }
392
- // --- Low-level helpers ---------------------------------------------------------
393
- function resolveMode(explicit, executable) {
394
- if (explicit !== undefined)
395
- return explicit & 0o777;
396
- return executable === false ? NON_EXECUTABLE_MODE : EXECUTABLE_MODE;
397
- }
398
- function writeScript(target, body, mode) {
399
- fs.writeFileSync(target, body);
400
- fs.chmodSync(target, mode);
401
- }
402
- function statMode(target) {
403
- return fs.statSync(target).mode & 0o777;
404
- }
405
- function isExecutable(mode) {
406
- return mode !== null && (mode & 0o111) !== 0;
407
- }
408
- //# sourceMappingURL=fake-hq-tree.js.map
@@ -1,8 +0,0 @@
1
- import { type RunDoctorOptions, type RunDoctorResult } from "../../../commands/doctor.js";
2
- /**
3
- * Run doctor tests against synthetic state. The production registry normally
4
- * reads local HQ work-context, sync, daemon, and session state; tests must not
5
- * inspect the developer's HOME or request the live integrations inventory.
6
- */
7
- export declare function runDoctorForTest(options?: RunDoctorOptions): Promise<RunDoctorResult>;
8
- //# sourceMappingURL=run-doctor.d.ts.map
@@ -1,69 +0,0 @@
1
- import * as fs from "node:fs";
2
- import * as os from "node:os";
3
- import * as path from "node:path";
4
- import { runDoctor as runDoctorCommand, } from "../../../commands/doctor.js";
5
- import { createAnywhereFamily } from "../checks/anywhere.js";
6
- import { createJqFamily } from "../checks/jq.js";
7
- import { createTempHomesFamily } from "../checks/temp-homes.js";
8
- import { createDefaultRegistry } from "../registry.js";
9
- /**
10
- * Run doctor tests against synthetic state. The production registry normally
11
- * reads local HQ work-context, sync, daemon, and session state; tests must not
12
- * inspect the developer's HOME or request the live integrations inventory.
13
- */
14
- export async function runDoctorForTest(options = {}) {
15
- const home = fs.mkdtempSync(path.join(os.tmpdir(), "hq-doctor-test-home-"));
16
- const homeRoot = path.parse(home).root;
17
- const homeDrive = homeRoot.endsWith(path.sep) ? homeRoot.slice(0, -1) : homeRoot;
18
- const homePath = home.slice(homeDrive.length);
19
- const isolatedEnv = {
20
- HOME: home,
21
- USERPROFILE: home,
22
- HOMEDRIVE: process.platform === "win32" ? homeDrive : undefined,
23
- HOMEPATH: process.platform === "win32" ? homePath : undefined,
24
- HQ_ROOT: undefined,
25
- HQ_STATE_DIR: path.join(home, ".hq"),
26
- HQ_MACHINE_TOKEN_STATE_DIR: path.join(home, ".hq", "work-mesh", "daemon"),
27
- HQ_MACHINE_CREDS_FILE: undefined,
28
- HQ_AGENT_DIR: path.join(home, ".hq-agent"),
29
- HQ_BOTS_ROOT: path.join(home, ".hq", "bots"),
30
- HQ_DAEMON_DIR: path.join(home, ".hq", "daemon"),
31
- HQ_WORK_CONTEXT_ROOT: path.join(home, ".hq", "work-context"),
32
- HQ_WORK_MESH_ROOT: path.join(home, ".hq", "work-mesh"),
33
- HQ_RUNTIME_MARKER_FILE: path.join(home, "runtime.json"),
34
- HQ_FLEET_CONFIG_FILE: path.join(home, ".hq-fleet", "config.yaml"),
35
- };
36
- const originalEnv = new Map(Object.keys(isolatedEnv).map((key) => [key, process.env[key]]));
37
- try {
38
- for (const [key, value] of Object.entries(isolatedEnv)) {
39
- if (value === undefined)
40
- delete process.env[key];
41
- else
42
- process.env[key] = value;
43
- }
44
- let registry = options.registry;
45
- if (!registry) {
46
- registry = createDefaultRegistry();
47
- // Command tests exercise doctor rendering and exit behavior offline. The
48
- // real person preference is covered in the anywhere-family tests.
49
- registry.register(createAnywhereFamily({ personSettingReader: async () => false }));
50
- // The temp-homes family walks the machine's real temp folders; scan
51
- // none here. Its behaviour is covered with fake trees in its own tests.
52
- registry.register(createTempHomesFamily({ roots: [] }));
53
- // The jq family reads the machine's real PATH; stub a present jq so
54
- // full-doctor tests do not depend on jq being installed here.
55
- registry.register(createJqFamily({ platform: process.platform, findJq: () => "/usr/bin/jq", readVersion: () => "jq-1.8.2" }));
56
- }
57
- return await runDoctorCommand({ ...options, registry, integrations: false });
58
- }
59
- finally {
60
- for (const [key, value] of originalEnv) {
61
- if (value === undefined)
62
- delete process.env[key];
63
- else
64
- process.env[key] = value;
65
- }
66
- fs.rmSync(home, { recursive: true, force: true });
67
- }
68
- }
69
- //# sourceMappingURL=run-doctor.js.map
@@ -1,19 +0,0 @@
1
- /**
2
- * Shared fingerprint test vectors. hq-pro (US-006) copies this list so the CLI
3
- * and the server agree on what a valid fingerprint is.
4
- */
5
- import type { FingerprintParts } from "./format.js";
6
- export interface ValidFingerprintVector {
7
- name: string;
8
- parts: FingerprintParts;
9
- value: string;
10
- }
11
- export interface InvalidFingerprintVector {
12
- name: string;
13
- value: string;
14
- }
15
- export declare const FINGERPRINT_TEST_VECTORS: {
16
- valid: ValidFingerprintVector[];
17
- invalid: InvalidFingerprintVector[];
18
- };
19
- //# sourceMappingURL=fixtures.d.ts.map
@@ -1,61 +0,0 @@
1
- export const FINGERPRINT_TEST_VECTORS = {
2
- valid: [
3
- {
4
- name: "person on a laptop",
5
- parts: {
6
- company: "indigo",
7
- identityUid: "prs_01J8ZK4Q7M2N3P4R5S6T7V8W9X",
8
- hostKind: "laptop",
9
- machineId: "e3ef5a5a-f51d-435d-90b9-dd876caa249b",
10
- sessionId: "fabb19c9-95a7-48a4-9a95-f77e28d0e3db",
11
- },
12
- value: "hqfp1:indigo:prs_01J8ZK4Q:laptop.e3ef5a5a:fabb19c9",
13
- },
14
- {
15
- name: "agent on a fleet box",
16
- parts: {
17
- company: "acme",
18
- identityUid: "agt_01JA0000000000000000000000",
19
- hostKind: "fleet",
20
- machineId: "0123456789abcdef",
21
- sessionId: "sess-1",
22
- },
23
- value: "hqfp1:acme:agt_01JA0000:fleet.01234567:sess-1",
24
- },
25
- {
26
- name: "outpost with no company",
27
- parts: {
28
- company: null,
29
- identityUid: "prs_01J8ZK4Q7M2N3P4R5S6T7V8W9X",
30
- hostKind: "outpost",
31
- machineId: "ABCDEF12-0000-0000-0000-000000000000",
32
- sessionId: null,
33
- },
34
- value: "hqfp1:-:prs_01J8ZK4Q:outpost.abcdef12:-",
35
- },
36
- {
37
- name: "session only",
38
- parts: {
39
- company: null,
40
- identityUid: null,
41
- hostKind: null,
42
- machineId: null,
43
- sessionId: "abcdefgh12345",
44
- },
45
- value: "hqfp1:-:-:-:abcdefgh",
46
- },
47
- ],
48
- invalid: [
49
- { name: "empty", value: "" },
50
- { name: "wrong prefix", value: "hqfp2:indigo:prs_01J8ZK4Q:laptop.e3ef5a5a:fabb19c9" },
51
- { name: "too few fields", value: "hqfp1:indigo:prs_01J8ZK4Q:laptop.e3ef5a5a" },
52
- { name: "too many fields", value: "hqfp1:indigo:prs_01J8ZK4Q:laptop.e3ef5a5a:fabb19c9:x" },
53
- { name: "bad identity prefix", value: "hqfp1:indigo:usr_01J8ZK4Q:laptop.e3ef5a5a:fabb19c9" },
54
- { name: "short identity", value: "hqfp1:indigo:prs_01J8:laptop.e3ef5a5a:fabb19c9" },
55
- { name: "bad host kind", value: "hqfp1:indigo:prs_01J8ZK4Q:desktop.e3ef5a5a:fabb19c9" },
56
- { name: "non-hex machine", value: "hqfp1:indigo:prs_01J8ZK4Q:laptop.zzzzzzzz:fabb19c9" },
57
- { name: "long session", value: "hqfp1:indigo:prs_01J8ZK4Q:laptop.e3ef5a5a:fabb19c9x" },
58
- { name: "empty field", value: "hqfp1::prs_01J8ZK4Q:laptop.e3ef5a5a:fabb19c9" },
59
- ],
60
- };
61
- //# sourceMappingURL=fixtures.js.map
@@ -1,33 +0,0 @@
1
- /**
2
- * Test-only fifth hot channel (hot-signal-sync US-016).
3
- *
4
- * This file and `dummy.catalog.json` beside it are everything a new poll
5
- * channel needs: the adapter is typed only against `../../contract.js`, and
6
- * `contract.e2e.test.ts` runs it through the shared loop, landing, signals
7
- * pass and run ledger without any change to those modules.
8
- *
9
- * It is never registered in the production registry. Only the e2e test
10
- * imports it, and it registers it in a registry of its own.
11
- */
12
- import type { PollHotChannelAdapter } from "../../contract.js";
13
- /** The one provider tool the dummy channel calls through the gateway. */
14
- export declare const DUMMY_LIST_TOOL = "dummy_list_events";
15
- /** One recorded item as the dummy provider's list tool returns it. */
16
- export interface DummyItem {
17
- id: string;
18
- rev: string;
19
- author: string;
20
- kind: string;
21
- space: string;
22
- at: string;
23
- title: string;
24
- body: string;
25
- audience: string[];
26
- }
27
- /** The dummy list tool's page shape. */
28
- export interface DummyListResult {
29
- items: DummyItem[];
30
- next: string | null;
31
- }
32
- export declare function createDummyAdapter(): PollHotChannelAdapter;
33
- //# sourceMappingURL=dummy.d.ts.map
@@ -1,53 +0,0 @@
1
- /**
2
- * Test-only fifth hot channel (hot-signal-sync US-016).
3
- *
4
- * This file and `dummy.catalog.json` beside it are everything a new poll
5
- * channel needs: the adapter is typed only against `../../contract.js`, and
6
- * `contract.e2e.test.ts` runs it through the shared loop, landing, signals
7
- * pass and run ledger without any change to those modules.
8
- *
9
- * It is never registered in the production registry. Only the e2e test
10
- * imports it, and it registers it in a registry of its own.
11
- */
12
- /** The one provider tool the dummy channel calls through the gateway. */
13
- export const DUMMY_LIST_TOOL = "dummy_list_events";
14
- const WEEK_MS = 7 * 24 * 60 * 60 * 1000;
15
- function toEvent(item) {
16
- return {
17
- providerId: item.id,
18
- version: item.rev,
19
- who: item.author,
20
- what: item.kind,
21
- where: item.space,
22
- when: item.at,
23
- audience: [...item.audience],
24
- title: item.title,
25
- body: item.body,
26
- raw: item,
27
- };
28
- }
29
- export function createDummyAdapter() {
30
- return {
31
- id: "dummy",
32
- channel: "dummy",
33
- transport: "poll",
34
- hotEventTypes: ["item.created", "item.updated"],
35
- catchUpWindow: { maxLookbackMs: WEEK_MS },
36
- tokenScope: { provider: "dummy", scopes: ["items:read"] },
37
- suggestionRule: { kind: "recent-activity", withinMs: WEEK_MS, minEvents: 1 },
38
- async fetch(cursor, ctx) {
39
- if (!ctx.gateway)
40
- throw new Error("the dummy channel needs a gateway connection");
41
- const page = (await ctx.gateway.call(DUMMY_LIST_TOOL, {
42
- since: ctx.since,
43
- cursor,
44
- }));
45
- return {
46
- events: page.items.map(toEvent),
47
- cursor: page.next ?? cursor,
48
- hasMore: page.next !== null,
49
- };
50
- },
51
- };
52
- }
53
- //# sourceMappingURL=dummy.js.map