@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
@@ -23,12 +23,40 @@
23
23
  * MAX_PAYLOAD_BYTES. A payload outside `sources/`, missing or unreadable falls
24
24
  * back to the pointer alone, and the reason is warned and kept on the signal.
25
25
  *
26
+ * Runtime: Claude Code (`claude -p`) by default, exactly as before. When the
27
+ * Executive bot (the bot whose runtime the pass already reads for its
28
+ * signed-out wording) is a Codex bot with `signalsRuntime: "bot"` in bot.json
29
+ * (`hq bot set <name> --signals-runtime bot`), the pass runs on Codex
30
+ * instead, through `runRuntimeTurn`, the turn runner a Daily Brief job uses.
31
+ * The argv and environment differ from a DM turn on purpose, because the
32
+ * documents are untrusted (see codexSignalsArgs and codexSignalsEnv). The
33
+ * opt-in defaults off so the first Codex runs can be compared with Claude's.
34
+ * When it is on, a failed Codex run is a Codex failure (`codex-*` codes); it
35
+ * never falls back to Claude.
36
+ *
26
37
  * Billing: policy hq-no-headless-print-subscription-billing forbids headless
27
- * `claude -p` in general. This is its allowed case, per the owner decision of
28
- * 2026-10-21: the owner's own `claude` login, on their own machine, in a
29
- * bounded single-turn call. Cloud Claude is not the bot brain, and no model is
30
- * called from the poller itself. Do not reuse this pass for a shared, fleet or
31
- * hosted identity.
38
+ * `claude -p` / `codex exec` in general.
39
+ * - Claude: this is its allowed case, per the owner decision of 2026-10-21:
40
+ * the owner's own `claude` login, on their own machine, in a bounded
41
+ * single-turn call.
42
+ * - Codex: narrow exception hq-signals-pass-codex-exec-narrow-exception (owner
43
+ * decision 2026-11-15). It holds only while the Codex call is
44
+ * 1. a single bounded turn (one `codex exec`, a per-document timeout),
45
+ * 2. with every Codex tool and feature off (codexLockdownFlags in
46
+ * signals/codex-lockdown.ts: shell, apps, plugins, hooks, multi-agent,
47
+ * web search, browser and computer use, bundled skills),
48
+ * 3. with no network (`permissions.*.network.enabled=false`),
49
+ * 4. with read access limited to the empty temp dir plus the codex install
50
+ * dir, never $HOME, ~/.hq, or a parent of either
51
+ * (resolveCodexLockdownTarget),
52
+ * 5. under an environment allowlist (CODEX_SIGNALS_ENV_ALLOWLIST).
53
+ * The login is the bot's own Codex login dir (never the owner's ~/.codex,
54
+ * and not available for an HQ Fleet Runtime bot), used in place so Codex's
55
+ * own refresh lock applies; the pass never copies or writes it.
56
+ * A change that loosens any of these is outside the exception;
57
+ * signals-pass.codex.test.ts pins all five.
58
+ * Cloud Claude is not the bot brain, and no model is called from the poller
59
+ * itself. Do not reuse this pass for a shared, fleet or hosted identity.
32
60
  *
33
61
  * Failures: a pass that fails keeps the real class as its ledger code (see
34
62
  * SignalsPassErrorCode), and writes the provider's own reason, redacted and
@@ -47,18 +75,26 @@
47
75
  * BAD_OUTPUT_STOP_AFTER × BAD_OUTPUT_ATTEMPTS when every reply is unusable.
48
76
  */
49
77
  import type { BotRuntimeId } from "../bot/config.js";
78
+ import { type SpawnLike } from "../bot/runtime/index.js";
50
79
  import type { HotChannelRunResult, WriteGuard } from "./loop.js";
80
+ /** The tools the pass can run on. */
81
+ export type SignalsRuntimeId = "claude" | "codex";
82
+ /** What went wrong, whatever the tool. */
83
+ export type SignalsFailureClass = "usage-limit" | "logged-out" | "timeout" | "provider-error" | "bad-output";
51
84
  /**
52
- * Ledger `error` values a failed pass records:
53
- * - `claude-usage-limit`: the account's plan has no usage left.
54
- * - `claude-logged-out`: no usable sign-in.
55
- * - `claude-timeout`: the call ran past its budget.
56
- * - `claude-provider-error`: claude reported or exited with some other error.
57
- * - `claude-bad-output`: claude finished cleanly and its reply is unusable.
58
- * - `claude-logged-out-codex-bot`: claude is missing or signed out, and the
59
- * main bot runs on Codex (see CODEX_BOT_NEEDS_CLAUDE_TEXT).
85
+ * Ledger `error` values a failed pass records, `{tool}-{class}` with the tool
86
+ * the pass ran on (`claude-*` on Claude Code, `codex-*` on a Codex bot that
87
+ * opted in):
88
+ * - `*-usage-limit`: the account's plan has no usage left.
89
+ * - `*-logged-out`: no usable sign-in, or the tool could not start.
90
+ * - `*-timeout`: the call ran past its budget.
91
+ * - `*-provider-error`: the tool reported or exited with some other error.
92
+ * - `*-bad-output`: the tool finished cleanly and its reply is unusable.
93
+ * - `claude-logged-out-codex-bot`: claude is missing or signed out, the main
94
+ * bot runs on Codex, and signals still run on Claude Code because the bot
95
+ * has not opted in (see CODEX_BOT_NEEDS_CLAUDE_TEXT).
60
96
  */
61
- export type SignalsPassErrorCode = "claude-usage-limit" | "claude-logged-out" | "claude-logged-out-codex-bot" | "claude-timeout" | "claude-provider-error" | "claude-bad-output";
97
+ export type SignalsPassErrorCode = `${SignalsRuntimeId}-${SignalsFailureClass}` | "claude-logged-out-codex-bot";
62
98
  /**
63
99
  * A pass failure the run ledger records as `status: failed` with `error` set
64
100
  * to the code. Any other error thrown from the pass is a crash.
@@ -70,13 +106,35 @@ export declare class SignalsPassError extends Error {
70
106
  /** Set on bad output that another call cannot fix, so the document is not sent again. */
71
107
  noRetry: boolean;
72
108
  constructor(code: SignalsPassErrorCode, message: string);
109
+ /** The failure class without the tool: `bad-output` for both `claude-bad-output` and `codex-bad-output`. */
110
+ get failure(): SignalsFailureClass;
73
111
  }
74
112
  /**
75
- * What the owner of a Codex main bot is told when this pass finds claude
76
- * missing or signed out. The pass always runs Claude Code, whatever the main
77
- * bot runs.
113
+ * How to sign Claude Code in for signals. The desktop app comes first: its
114
+ * Settings → AI tools pane lists Claude Code with one button: "Connect
115
+ * Claude" when the CLI is installed, "Install Claude" when it is not
116
+ * (hq-desktop-app-src packages/ui/src/settings/AgentsSettingsPane.svelte).
117
+ * The terminal command is the fallback.
118
+ */
119
+ export declare const CLAUDE_SIGN_IN_STEPS: string;
120
+ /** The same steps for Codex: the pane's Codex row has "Connect Codex" / "Install Codex". */
121
+ export declare const CODEX_SIGN_IN_STEPS: string;
122
+ /** The sign-in steps for the tool the pass runs on. */
123
+ export declare function signalsSignInSteps(runtime: SignalsRuntimeId): string;
124
+ /** The command that switches one bot's signals to its own Codex. */
125
+ export declare function codexBotSignalsOptInCommand(botName: string): string;
126
+ /**
127
+ * What the owner of a Codex main bot is told when this pass, on Claude Code,
128
+ * finds claude missing or signed out: sign Claude Code in. The DM does not
129
+ * offer moving signals to Codex, because whether that is possible depends on
130
+ * the bot (an HQ Fleet Runtime bot cannot, and a bot needs its own Codex
131
+ * login); `hq bot status` offers it where the bot qualifies.
78
132
  */
79
133
  export declare const CODEX_BOT_NEEDS_CLAUDE_TEXT: string;
134
+ /** What the owner is told when this pass finds claude signed out on any other bot. */
135
+ export declare const CLAUDE_SIGNED_OUT_TEXT: string;
136
+ /** What the owner of a Codex bot that runs signals on Codex is told when Codex is missing or signed out. */
137
+ export declare const CODEX_SIGNED_OUT_TEXT: string;
80
138
  /** Signal types the pass accepts; the same type folders existing signals use. */
81
139
  export declare const SIGNAL_TYPES: readonly ["action_item", "commitment", "decision", "key_point", "participant_contribution", "question", "risk", "summary"];
82
140
  export type SignalType = (typeof SIGNAL_TYPES)[number];
@@ -151,6 +209,32 @@ export interface ClaudeSignalsPassOptions {
151
209
  * CODEX_BOT_NEEDS_CLAUDE_TEXT. Unset: the failure is reported as is.
152
210
  */
153
211
  botRuntime?: () => BotRuntimeId | null;
212
+ /**
213
+ * The bot's `signalsRuntime: "bot"` opt-in. When it answers true and
214
+ * `botRuntime` answers codex, the pass runs on Codex (see the file header).
215
+ * Unset, false, a throw, or any other bot runtime: Claude Code. Read once,
216
+ * when the first document is about to be sent.
217
+ */
218
+ useBotRuntime?: () => boolean;
219
+ /**
220
+ * The environment the bot's own turns use (its login choice applied), for
221
+ * the Codex sign-in check and the Codex turn. Defaults to `env`. A throw (a
222
+ * bot set to its own login that has none) fails the pass as
223
+ * `codex-logged-out`; no other login is used.
224
+ */
225
+ botRuntimeEnv?: () => NodeJS.ProcessEnv;
226
+ /** The `codex` CLI for the Codex runtime; the bot runtime's own lookup by default. */
227
+ codexBin?: string;
228
+ /** Test seam: the spawn used for the sign-in check and the Codex turn. */
229
+ runtimeSpawn?: SpawnLike;
230
+ /**
231
+ * Told what the pass saw of the Claude login: true after a preflight that
232
+ * passed, false when the pass failed signed out. Unset: nothing is recorded.
233
+ * `hq bot` and `hq sources sync` pass `recordSignalsPassClaudeLogin` here
234
+ * (signals-claude-login.ts), which `hq bot status` reads. Must not throw.
235
+ * Only a pass on Claude Code reports; a pass on Codex does not.
236
+ */
237
+ onClaudeLogin?: (signedIn: boolean) => void;
154
238
  }
155
239
  /** Why the pass sent claude the pointer alone. */
156
240
  export type PayloadFallbackReason = "payload-out-of-bounds" | "payload-missing" | "payload-unreadable";
@@ -214,12 +298,54 @@ export declare function splitFrontmatter(text: string): {
214
298
  * document's own `.raw.json` sidecar and the body is the content.
215
299
  */
216
300
  export declare function buildSignalsInput(vaultRoot: string, file: string): Promise<SignalsInput>;
301
+ /**
302
+ * Sort a failed Codex turn (a RuntimeError from runRuntimeTurn) into a failure
303
+ * class. Only the error Codex reported, or stderr, is quoted; a RuntimeError
304
+ * whose excerpt is a tail of ordinary output never decides the class and is
305
+ * never quoted, because that output is built from the document.
306
+ */
307
+ export declare function classifyCodexFailure(err: unknown, item: {
308
+ file: string;
309
+ }, timeoutMs: number, elapsedMs: number): SignalsPassError;
217
310
  /**
218
311
  * Parse `claude -p --output-format json` output into signals. The envelope's
219
312
  * `result` must itself be one JSON object, optionally inside a single code
220
313
  * fence; nothing is scraped out of prose.
221
314
  */
222
315
  export declare function parseClaudeSignals(stdout: string): ParsedSignal[];
316
+ /**
317
+ * Parse the model's final reply text into signals, for either tool: one JSON
318
+ * object, optionally inside a single code fence; nothing is scraped out of
319
+ * prose. Claude's reply is its envelope's `result`; Codex's is its last agent
320
+ * message (`codex exec -o`). Same schema and the same per-document cap.
321
+ */
322
+ export declare function parseSignalsReply(reply: string, runtime: SignalsRuntimeId): ParsedSignal[];
323
+ /** The Codex permission profile a signals turn runs under. */
324
+ export declare const CODEX_SIGNALS_PROFILE = "hq_signals_pass";
325
+ /**
326
+ * The lockdown is the signals engine's shared one (signals/codex-lockdown.ts):
327
+ * the same disabled features and config, environment allowlist, real-binary
328
+ * lookup past HQ's wrappers, and install-dir grant checks as the extract step.
329
+ */
330
+ export declare const CODEX_SIGNALS_DISABLED_FEATURES: readonly string[];
331
+ export declare const CODEX_SIGNALS_ENV_ALLOWLIST: readonly string[];
332
+ /**
333
+ * argv for one Codex signals turn. The prompt and document go on stdin (`-`),
334
+ * which keeps a 200 KB payload off argv. `--ignore-user-config` drops
335
+ * config.toml (MCP servers, settings), `--ignore-rules` drops execpolicy allow
336
+ * rules, `--ephemeral` keeps no session, `-a never` asks no one,
337
+ * codexLockdownFlags turns every tool feature, web search and bundled skills
338
+ * off, and the permission profile (codexLockdownFilesystem) reads only the
339
+ * platform minimum, the codex install and the empty turn dir, writes
340
+ * nothing, and has no network. The reply comes back in the `-o` file.
341
+ */
342
+ export declare function codexSignalsArgs(input: {
343
+ turnDir: string;
344
+ outputFile: string;
345
+ /** resolveCodexLockdownTarget's install dir. */
346
+ installDir: string;
347
+ model?: string;
348
+ }): string[];
223
349
  /** `sha256(source_ref \n type \n title)`: the same signal from the same source keeps its id. */
224
350
  export declare function signalId(sourceRef: string, type: string, title: string): string;
225
351
  /**
@@ -1,5 +1,9 @@
1
1
  import { prepareSignalPublication, flushSignalPublications } from "../bot/jobs/signal-to-lane.js";
2
2
  import { isRuntimeUsageLimit } from "../bot/runtime-failure.js";
3
+ import { createCodexRuntime, defaultSpawn, runRuntimeTurn, RuntimeError } from "../bot/runtime/index.js";
4
+ import { CODEX_LOCKDOWN_DISABLED_FEATURES, CODEX_LOCKDOWN_ENV_ALLOWLIST, codexLockdownEnv, codexLockdownFilesystem, codexLockdownFlags, lockdownHomes, resolveCodexLockdownTarget, } from "../signals/codex-lockdown.js";
5
+ import { checkRuntimeSignIn } from "../bot/runtime-sign-in-check.js";
6
+ import { isRuntimeSignInFailure } from "../bot/runtime-sign-in.js";
3
7
  import { redactErrorText } from "../../utils/redact-error-text.js";
4
8
  import { acquireSyncLock } from "./sync-lock.js";
5
9
  import { spawn } from "node:child_process";
@@ -27,14 +31,49 @@ export class SignalsPassError extends Error {
27
31
  this.name = "SignalsPassError";
28
32
  this.code = code;
29
33
  }
34
+ /** The failure class without the tool: `bad-output` for both `claude-bad-output` and `codex-bad-output`. */
35
+ get failure() {
36
+ return this.code === "claude-logged-out-codex-bot" ? "logged-out" : this.code.replace(/^(?:claude|codex)-/, "");
37
+ }
38
+ }
39
+ /**
40
+ * How to sign Claude Code in for signals. The desktop app comes first: its
41
+ * Settings → AI tools pane lists Claude Code with one button: "Connect
42
+ * Claude" when the CLI is installed, "Install Claude" when it is not
43
+ * (hq-desktop-app-src packages/ui/src/settings/AgentsSettingsPane.svelte).
44
+ * The terminal command is the fallback.
45
+ */
46
+ export const CLAUDE_SIGN_IN_STEPS = "Open HQ, go to Settings → AI tools, and use the Claude Code button there (Connect Claude, or Install Claude if it is not installed yet). " +
47
+ "Or run `claude auth login` in a terminal on this computer.";
48
+ /** The same steps for Codex: the pane's Codex row has "Connect Codex" / "Install Codex". */
49
+ export const CODEX_SIGN_IN_STEPS = "Open HQ, go to Settings → AI tools, and use the Codex button there (Connect Codex, or Install Codex if it is not installed yet). " +
50
+ "Or run `codex login` in a terminal on this computer.";
51
+ /** The sign-in steps for the tool the pass runs on. */
52
+ export function signalsSignInSteps(runtime) {
53
+ return runtime === "codex" ? CODEX_SIGN_IN_STEPS : CLAUDE_SIGN_IN_STEPS;
54
+ }
55
+ /** Documents the pass could not run stay queued; said in every signed-out message. */
56
+ const QUEUED_DOCS_TEXT = "The documents waiting for signals stay queued and run once Claude Code is signed in.";
57
+ /** The command that switches one bot's signals to its own Codex. */
58
+ export function codexBotSignalsOptInCommand(botName) {
59
+ return `hq bot set ${botName} --signals-runtime bot`;
30
60
  }
31
61
  /**
32
- * What the owner of a Codex main bot is told when this pass finds claude
33
- * missing or signed out. The pass always runs Claude Code, whatever the main
34
- * bot runs.
62
+ * What the owner of a Codex main bot is told when this pass, on Claude Code,
63
+ * finds claude missing or signed out: sign Claude Code in. The DM does not
64
+ * offer moving signals to Codex, because whether that is possible depends on
65
+ * the bot (an HQ Fleet Runtime bot cannot, and a bot needs its own Codex
66
+ * login); `hq bot status` offers it where the bot qualifies.
35
67
  */
36
- export const CODEX_BOT_NEEDS_CLAUDE_TEXT = "Your main bot runs on Codex, but signals from hot-channel sync need Claude Code, which is not installed or not signed in on this computer. " +
37
- "Sign in to Claude Code here (`claude auth login`).";
68
+ export const CODEX_BOT_NEEDS_CLAUDE_TEXT = "Your main bot runs on Codex, but signals from hot-channel sync on this computer run on Claude Code, which is not installed or not signed in here. " +
69
+ `To run them, sign Claude Code in: ${CLAUDE_SIGN_IN_STEPS} ` +
70
+ "The documents waiting for signals stay queued and run once Claude Code is signed in.";
71
+ /** What the owner is told when this pass finds claude signed out on any other bot. */
72
+ export const CLAUDE_SIGNED_OUT_TEXT = "Signals from hot-channel sync need Claude Code, which is not signed in on this computer. " +
73
+ `${CLAUDE_SIGN_IN_STEPS} ${QUEUED_DOCS_TEXT}`;
74
+ /** What the owner of a Codex bot that runs signals on Codex is told when Codex is missing or signed out. */
75
+ export const CODEX_SIGNED_OUT_TEXT = "Signals from hot-channel sync run on your bot's Codex, which is not installed or not signed in on this computer. " +
76
+ `${CODEX_SIGN_IN_STEPS} The documents waiting for signals stay queued and run once Codex is signed in.`;
38
77
  /** Signal types the pass accepts; the same type folders existing signals use. */
39
78
  export const SIGNAL_TYPES = [
40
79
  "action_item",
@@ -400,6 +439,38 @@ function classifyClaudeExit(run) {
400
439
  const reason = `${envelopeText}\n${run.stderr}`.trim();
401
440
  return classifyClaudeError(`${plainStdout}\n${reason}`.trim(), `claude exited with code ${String(run.code)}`, reason);
402
441
  }
442
+ /** The line the bot's spawn appends to stderr when it stopped a call for running past its budget. */
443
+ const TURN_TIMEOUT_MARK = /runtime turn exceeded \d+ ?ms/;
444
+ /**
445
+ * Sort a failed Codex turn (a RuntimeError from runRuntimeTurn) into a failure
446
+ * class. Only the error Codex reported, or stderr, is quoted; a RuntimeError
447
+ * whose excerpt is a tail of ordinary output never decides the class and is
448
+ * never quoted, because that output is built from the document.
449
+ */
450
+ export function classifyCodexFailure(err, item, timeoutMs, elapsedMs) {
451
+ if (!(err instanceof RuntimeError)) {
452
+ return new SignalsPassError("codex-provider-error", `codex call failed${providerReason(err instanceof Error ? err.message : String(err))}`);
453
+ }
454
+ if (!err.started)
455
+ return new SignalsPassError("codex-logged-out", `codex could not start${providerReason(err.message)}`);
456
+ if (TURN_TIMEOUT_MARK.test(err.stderrFull ?? "") || (err.exitCode === null && elapsedMs >= timeoutMs)) {
457
+ return new SignalsPassError("codex-timeout", `codex timed out after ${timeoutMs}ms on ${item.file}`);
458
+ }
459
+ // Exit 0 with no agent message (parseOutput): nothing to parse, and the same document would do the same again.
460
+ if (err.exitCode === null && /^codex produced no reply/.test(err.message)) {
461
+ const bad = new SignalsPassError("codex-bad-output", "codex finished with no reply");
462
+ bad.noRetry = true;
463
+ return bad;
464
+ }
465
+ const reported = err.excerptIsOutputTail ? "" : err.stderrExcerpt;
466
+ const text = `${err.message}\n${reported}`;
467
+ if (isRuntimeUsageLimit(text))
468
+ return new SignalsPassError("codex-usage-limit", `codex is out of usage${providerReason(reported)}`);
469
+ if (isRuntimeSignInFailure(text) || CLAUDE_LOGGED_OUT_RE.test(reported)) {
470
+ return new SignalsPassError("codex-logged-out", `codex reported it is not logged in${providerReason(reported)}`);
471
+ }
472
+ return new SignalsPassError("codex-provider-error", `codex exited with code ${String(err.exitCode)}${providerReason(reported)}`);
473
+ }
403
474
  /**
404
475
  * Parse `claude -p --output-format json` output into signals. The envelope's
405
476
  * `result` must itself be one JSON object, optionally inside a single code
@@ -423,7 +494,16 @@ export function parseClaudeSignals(stdout) {
423
494
  if (typeof env.result !== "string") {
424
495
  throw new SignalsPassError("claude-bad-output", "claude envelope has no result text");
425
496
  }
426
- let text = env.result.trim();
497
+ return parseSignalsReply(env.result, "claude");
498
+ }
499
+ /**
500
+ * Parse the model's final reply text into signals, for either tool: one JSON
501
+ * object, optionally inside a single code fence; nothing is scraped out of
502
+ * prose. Claude's reply is its envelope's `result`; Codex's is its last agent
503
+ * message (`codex exec -o`). Same schema and the same per-document cap.
504
+ */
505
+ export function parseSignalsReply(reply, runtime) {
506
+ let text = reply.trim();
427
507
  const fence = /^```(?:json)?\n([\s\S]*)\n```$/.exec(text);
428
508
  if (fence)
429
509
  text = fence[1].trim();
@@ -436,13 +516,13 @@ export function parseClaudeSignals(stdout) {
436
516
  // must be that sentence, so prose about a limit stays bad output, and the
437
517
  // reply is not quoted because it is stdout.
438
518
  if (text.length <= MAX_LIMIT_SENTENCE_CHARS && LIMIT_SENTENCE_REPLY.test(text) && isRuntimeUsageLimit(text)) {
439
- throw new SignalsPassError("claude-usage-limit", "claude is out of usage: its whole reply was a limit sentence");
519
+ throw new SignalsPassError(`${runtime}-usage-limit`, `${runtime} is out of usage: its whole reply was a limit sentence`);
440
520
  }
441
- throw new SignalsPassError("claude-bad-output", "claude result is not JSON");
521
+ throw new SignalsPassError(`${runtime}-bad-output`, `${runtime} result is not JSON`);
442
522
  }
443
523
  const signals = body?.signals;
444
524
  if (!Array.isArray(signals)) {
445
- throw new SignalsPassError("claude-bad-output", "claude result has no signals list");
525
+ throw new SignalsPassError(`${runtime}-bad-output`, `${runtime} result has no signals list`);
446
526
  }
447
527
  return signals.slice(0, MAX_SIGNALS_PER_DOC).map((raw, i) => {
448
528
  const s = raw;
@@ -452,14 +532,59 @@ export function parseClaudeSignals(stdout) {
452
532
  typeof s.title !== "string" ||
453
533
  s.title.trim().length === 0 ||
454
534
  typeof s.body !== "string") {
455
- throw new SignalsPassError("claude-bad-output", `claude signal ${i} has the wrong shape`);
535
+ throw new SignalsPassError(`${runtime}-bad-output`, `${runtime} signal ${i} has the wrong shape`);
456
536
  }
457
537
  if (s.update !== undefined && (typeof s.update !== "string" || !/^[a-f0-9]{64}$/.test(s.update))) {
458
- throw new SignalsPassError("claude-bad-output", `claude signal ${i} has an invalid update id`);
538
+ throw new SignalsPassError(`${runtime}-bad-output`, `${runtime} signal ${i} has an invalid update id`);
459
539
  }
460
540
  return { type: s.type, title: s.title.trim(), body: s.body.trim(), ...(s.update ? { update: s.update } : {}) };
461
541
  });
462
542
  }
543
+ /** The Codex permission profile a signals turn runs under. */
544
+ export const CODEX_SIGNALS_PROFILE = "hq_signals_pass";
545
+ /**
546
+ * The lockdown is the signals engine's shared one (signals/codex-lockdown.ts):
547
+ * the same disabled features and config, environment allowlist, real-binary
548
+ * lookup past HQ's wrappers, and install-dir grant checks as the extract step.
549
+ */
550
+ export const CODEX_SIGNALS_DISABLED_FEATURES = CODEX_LOCKDOWN_DISABLED_FEATURES;
551
+ export const CODEX_SIGNALS_ENV_ALLOWLIST = CODEX_LOCKDOWN_ENV_ALLOWLIST;
552
+ /**
553
+ * argv for one Codex signals turn. The prompt and document go on stdin (`-`),
554
+ * which keeps a 200 KB payload off argv. `--ignore-user-config` drops
555
+ * config.toml (MCP servers, settings), `--ignore-rules` drops execpolicy allow
556
+ * rules, `--ephemeral` keeps no session, `-a never` asks no one,
557
+ * codexLockdownFlags turns every tool feature, web search and bundled skills
558
+ * off, and the permission profile (codexLockdownFilesystem) reads only the
559
+ * platform minimum, the codex install and the empty turn dir, writes
560
+ * nothing, and has no network. The reply comes back in the `-o` file.
561
+ */
562
+ export function codexSignalsArgs(input) {
563
+ const profile = CODEX_SIGNALS_PROFILE;
564
+ return [
565
+ "-a",
566
+ "never",
567
+ "exec",
568
+ "--json",
569
+ "--skip-git-repo-check",
570
+ "--ephemeral",
571
+ "--ignore-user-config",
572
+ "--ignore-rules",
573
+ ...codexLockdownFlags(),
574
+ "-C",
575
+ input.turnDir,
576
+ "-o",
577
+ input.outputFile,
578
+ "-c",
579
+ `default_permissions=${JSON.stringify(profile)}`,
580
+ "-c",
581
+ `permissions.${profile}.filesystem=${codexLockdownFilesystem(input.installDir, input.turnDir)}`,
582
+ "-c",
583
+ `permissions.${profile}.network.enabled=false`,
584
+ ...(input.model ? ["-m", input.model] : []),
585
+ "-",
586
+ ];
587
+ }
463
588
  /** `sha256(source_ref \n type \n title)`: the same signal from the same source keeps its id. */
464
589
  export function signalId(sourceRef, type, title) {
465
590
  return createHash("sha256").update(`${sourceRef}\n${type}\n${title}`).digest("hex");
@@ -565,6 +690,7 @@ export function createClaudeSignalsPass(options) {
565
690
  let preflight;
566
691
  let prompt;
567
692
  let docsSent = 0;
693
+ const runtimeSpawn = options.runtimeSpawn ?? defaultSpawn;
568
694
  const codexBot = () => {
569
695
  try {
570
696
  return options.botRuntime?.() === "codex";
@@ -574,7 +700,112 @@ export function createClaudeSignalsPass(options) {
574
700
  return false;
575
701
  }
576
702
  };
703
+ /** The tool this pass runs on, decided once per pass (see the file header). */
704
+ let runtimeChoice;
705
+ const signalsRuntime = () => {
706
+ if (runtimeChoice === undefined) {
707
+ let optedIn = false;
708
+ try {
709
+ optedIn = options.useBotRuntime?.() === true;
710
+ }
711
+ catch {
712
+ // An unreadable opt-in keeps today's behaviour.
713
+ }
714
+ runtimeChoice = optedIn && codexBot() ? "codex" : "claude";
715
+ }
716
+ return runtimeChoice;
717
+ };
718
+ let codexSession;
719
+ const codexSetup = async () => {
720
+ if (codexSession)
721
+ return codexSession;
722
+ let base;
723
+ try {
724
+ base = options.botRuntimeEnv?.() ?? env;
725
+ }
726
+ catch (err) {
727
+ throw new SignalsPassError("codex-logged-out", `codex login is not usable: ${providerReason(err instanceof Error ? err.message : String(err)).replace(/^: /, "")}`);
728
+ }
729
+ // botRuntimeEnv is signalsCodexLogin's environment (signals-runtime.ts),
730
+ // the one gate for which login may be used; it always sets CODEX_HOME.
731
+ const codexHome = base.CODEX_HOME?.trim();
732
+ if (!codexHome)
733
+ throw new SignalsPassError("codex-logged-out", "codex login is not usable: no Codex login dir was given for the bot");
734
+ const target = resolveCodexLockdownTarget(options.codexBin ?? "codex", {
735
+ envPath: base.PATH,
736
+ homes: lockdownHomes(base),
737
+ hqRoot: options.hqRoot,
738
+ loginDir: codexHome,
739
+ });
740
+ if (!target.ok)
741
+ throw new SignalsPassError("codex-logged-out", `codex could not start: ${target.error}`);
742
+ const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "hq-signals-codex-home-"));
743
+ const home = path.join(tempRoot, "home");
744
+ await fs.mkdir(home, { mode: 0o700 });
745
+ codexSession = {
746
+ binary: target.binary,
747
+ installDir: target.installDir,
748
+ env: codexLockdownEnv(base, { home, codexHome }),
749
+ tempRoot,
750
+ };
751
+ return codexSession;
752
+ };
753
+ /** End of pass: the temp HOME goes. Never throws; the login is never touched. */
754
+ const codexTeardown = async () => {
755
+ const session = codexSession;
756
+ codexSession = undefined;
757
+ if (!session)
758
+ return;
759
+ await fs.rm(session.tempRoot, { recursive: true, force: true }).catch(() => undefined);
760
+ };
761
+ /**
762
+ * The bot's Codex runtime with the real binary, minus the model fallback:
763
+ * on a "model requires a newer version" refusal, runRuntimeTurn would run
764
+ * `codex --version` and `codex debug models` outside the lockdown argv and
765
+ * then send the turn again on other models. The exception allows one
766
+ * bounded turn, so a refusal is a failed call (`codex-provider-error`).
767
+ */
768
+ const codexRuntimeFor = (session) => ({
769
+ ...createCodexRuntime(),
770
+ binary: session.binary,
771
+ resolveBinary: undefined,
772
+ fallbackModelsAfterVersionMismatch: undefined,
773
+ });
774
+ /**
775
+ * Every codex process this pass starts gets the allowlist and nothing else:
776
+ * the turn runner and the sign-in check add keys of their own
777
+ * (HQ_NO_ENSURE_HQ_DESKTOP, TMPDIR), which are dropped here.
778
+ */
779
+ const codexSpawn = (command, args, spawnOptions) => {
780
+ const allowed = {};
781
+ for (const key of CODEX_SIGNALS_ENV_ALLOWLIST) {
782
+ if (spawnOptions.env[key] !== undefined)
783
+ allowed[key] = spawnOptions.env[key];
784
+ }
785
+ return runtimeSpawn(command, args, { ...spawnOptions, env: allowed });
786
+ };
787
+ const tellLogin = (signedIn) => {
788
+ // The record is Claude Code's login; a pass on Codex has nothing to add to it.
789
+ if (signalsRuntime() !== "claude")
790
+ return;
791
+ try {
792
+ options.onClaudeLogin?.(signedIn);
793
+ }
794
+ catch {
795
+ // A report only; it never changes the pass's outcome.
796
+ }
797
+ };
577
798
  const checkLogin = async () => {
799
+ await (signalsRuntime() === "codex" ? checkCodexLogin() : checkClaudeLogin());
800
+ tellLogin(true);
801
+ };
802
+ /**
803
+ * The Claude preflight, unchanged from before the Codex option: a hung
804
+ * `claude auth status` is claude-timeout at once, a CLI that cannot start or
805
+ * exits non-zero is signed out, `loggedIn: false` is signed out, any other
806
+ * exit 0 is signed in.
807
+ */
808
+ const checkClaudeLogin = async () => {
578
809
  const run = await runBounded(claude, ["auth", "status"], { timeoutMs: authTimeoutMs, cwd: claudeCwd, env });
579
810
  if (run.timedOut)
580
811
  throw new SignalsPassError("claude-timeout", "claude auth status timed out");
@@ -592,6 +823,26 @@ export function createClaudeSignalsPass(options) {
592
823
  // A plain-text status with exit 0 means logged in.
593
824
  }
594
825
  };
826
+ /**
827
+ * The Codex preflight: the bot's own runtime sign-in check
828
+ * (runtime-sign-in-check.ts, `codex login status`) in the turn's own
829
+ * environment. Signed out, or a CLI that cannot start, stops the pass
830
+ * before any document is sent.
831
+ */
832
+ const checkCodexLogin = async () => {
833
+ const session = await codexSetup();
834
+ const check = await checkRuntimeSignIn({
835
+ runtime: codexRuntimeFor(session),
836
+ env: session.env,
837
+ cwd: session.env.HOME ?? claudeCwd,
838
+ spawn: codexSpawn,
839
+ timeoutMs: authTimeoutMs,
840
+ now,
841
+ });
842
+ if (check.signedIn === false || check.couldNotStart) {
843
+ throw new SignalsPassError("codex-logged-out", "codex is not logged in (codex login status failed)");
844
+ }
845
+ };
595
846
  const runWorklist = async (args) => runBounded("bash", [worklist, ...args], {
596
847
  timeoutMs: WORKLIST_TIMEOUT_MS,
597
848
  cwd: options.hqRoot,
@@ -682,7 +933,7 @@ export function createClaudeSignalsPass(options) {
682
933
  return await extractOnce(item, input);
683
934
  }
684
935
  catch (err) {
685
- if (!(err instanceof SignalsPassError) || err.code !== "claude-bad-output")
936
+ if (!(err instanceof SignalsPassError) || err.failure !== "bad-output")
686
937
  throw err;
687
938
  if (err.noRetry || attempt >= BAD_OUTPUT_ATTEMPTS)
688
939
  throw err;
@@ -690,7 +941,57 @@ export function createClaudeSignalsPass(options) {
690
941
  }
691
942
  }
692
943
  };
693
- const extractOnce = async (item, input) => {
944
+ const extractOnce = (item, input) => signalsRuntime() === "codex" ? extractOnceCodex(item, input) : extractOnceClaude(item, input);
945
+ /**
946
+ * One Codex call through the bot runtime's turn runner, the one a Daily
947
+ * Brief job goes through (runRuntimeTurn), with the isolated argv of
948
+ * codexSignalsArgs. The reply is the last agent message.
949
+ */
950
+ const extractOnceCodex = async (item, input) => {
951
+ prompt ??= fs.readFile(promptFile, "utf8");
952
+ const instructions = await prompt;
953
+ const session = await codexSetup();
954
+ const base = codexRuntimeFor(session);
955
+ const turnEnv = session.env;
956
+ const turnDir = await fs.mkdtemp(path.join(os.tmpdir(), "hq-signals-codex-"));
957
+ const stdin = `${instructions.trimEnd()}\n\n--- document ---\n${input.text}`;
958
+ const runtime = {
959
+ ...base,
960
+ buildArgs: (turn, scratch) => codexSignalsArgs({
961
+ turnDir,
962
+ outputFile: scratch.outputFile,
963
+ installDir: session.installDir,
964
+ ...(turn.model ? { model: turn.model } : {}),
965
+ }),
966
+ stdinInput: () => stdin,
967
+ spawnProtocol: undefined,
968
+ parseStreamLine: undefined,
969
+ };
970
+ const startedAt = Date.now();
971
+ let reply;
972
+ try {
973
+ reply = (await runRuntimeTurn(runtime, { prompt: input.text, systemPrompt: instructions, systemPromptFile: "", cwd: turnDir, autoApprove: false, env: turnEnv }, { spawnImpl: codexSpawn, timeoutMs })).text;
974
+ }
975
+ catch (err) {
976
+ throw classifyCodexFailure(err, item, timeoutMs, Date.now() - startedAt);
977
+ }
978
+ finally {
979
+ await fs.rm(turnDir, { recursive: true, force: true }).catch(() => undefined);
980
+ }
981
+ try {
982
+ return parseSignalsReply(reply, "codex");
983
+ }
984
+ catch (err) {
985
+ if (err instanceof SignalsPassError && err.failure === "bad-output") {
986
+ // Only sizes: the reply is model output built from the document.
987
+ const bad = new SignalsPassError("codex-bad-output", `${err.message} (reply ${Buffer.byteLength(reply)} bytes)`);
988
+ bad.noRetry = reply.trim().length === 0;
989
+ throw bad;
990
+ }
991
+ throw err;
992
+ }
993
+ };
994
+ const extractOnceClaude = async (item, input) => {
694
995
  prompt ??= fs.readFile(promptFile, "utf8");
695
996
  const run = await runBounded(claude, ["-p", await prompt, ...CLAUDE_ISOLATION_ARGS, "--output-format", "json", "--max-turns", "1"], {
696
997
  timeoutMs,
@@ -779,7 +1080,7 @@ export function createClaudeSignalsPass(options) {
779
1080
  let badInARow = 0;
780
1081
  const badOutputFailure = () => badDocs === 1 && badOutput !== undefined
781
1082
  ? badOutput
782
- : new SignalsPassError("claude-bad-output", `${badDocs} documents had unusable claude replies; first: ${badOutput?.message ?? ""}`);
1083
+ : new SignalsPassError(`${signalsRuntime()}-bad-output`, `${badDocs} documents had unusable ${signalsRuntime()} replies; first: ${badOutput?.message ?? ""}`);
783
1084
  const byChannel = new Map();
784
1085
  // The adapter's own channel is listed even when this run landed nothing
785
1086
  // there, so items an earlier run left over the cap still get processed.
@@ -829,7 +1130,7 @@ export function createClaudeSignalsPass(options) {
829
1130
  signals = await extract(item, input);
830
1131
  }
831
1132
  catch (err) {
832
- if (!(err instanceof SignalsPassError) || err.code !== "claude-bad-output")
1133
+ if (!(err instanceof SignalsPassError) || err.failure !== "bad-output")
833
1134
  throw err;
834
1135
  // One document's unusable reply must not hold back the documents
835
1136
  // behind it. It stays unmarked (or pending) for a later run, and the
@@ -866,8 +1167,11 @@ export function createClaudeSignalsPass(options) {
866
1167
  }
867
1168
  catch (caught) {
868
1169
  let err = caught;
869
- if (err instanceof SignalsPassError && err.code === "claude-logged-out" && codexBot()) {
870
- err = new SignalsPassError("claude-logged-out-codex-bot", CODEX_BOT_NEEDS_CLAUDE_TEXT);
1170
+ if (err instanceof SignalsPassError && err.code === "claude-logged-out") {
1171
+ tellLogin(false);
1172
+ // Still on Claude Code because the Codex bot has not opted in.
1173
+ if (codexBot())
1174
+ err = new SignalsPassError("claude-logged-out-codex-bot", CODEX_BOT_NEEDS_CLAUDE_TEXT);
871
1175
  }
872
1176
  if (err instanceof SignalsPassError) {
873
1177
  err.written = progress.written;
@@ -875,6 +1179,9 @@ export function createClaudeSignalsPass(options) {
875
1179
  }
876
1180
  throw err;
877
1181
  }
1182
+ finally {
1183
+ await codexTeardown();
1184
+ }
878
1185
  return progress.written;
879
1186
  };
880
1187
  }