@indigoai-us/hq-cli 5.345.236 → 5.345.237

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 (91) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/command-catalog.generated.d.ts +1 -1
  3. package/dist/command-catalog.generated.js +1 -1
  4. package/dist/commands/bot.js +9 -0
  5. package/dist/commands/daemon.d.ts +1 -0
  6. package/dist/commands/daemon.js +70 -6
  7. package/dist/commands/deploy-app-db.js +4 -19
  8. package/dist/commands/deploy-app-upload.js +66 -40
  9. package/dist/commands/deploy-mutations.js +24 -16
  10. package/dist/commands/deploy-runtime-bindings.js +7 -26
  11. package/dist/commands/deploy-ssr.js +5 -24
  12. package/dist/commands/mesh.js +6 -2
  13. package/dist/commands/signals-run.d.ts +43 -2
  14. package/dist/commands/signals-run.js +85 -7
  15. package/dist/commands/sync-core.d.ts +7 -0
  16. package/dist/commands/sync-core.js +52 -3
  17. package/dist/lib/bot/continuity.d.ts +21 -2
  18. package/dist/lib/bot/continuity.js +48 -19
  19. package/dist/lib/bot/fleet-cron.js +6 -0
  20. package/dist/lib/bot/fleet-local.d.ts +11 -1
  21. package/dist/lib/bot/fleet-local.js +21 -1
  22. package/dist/lib/bot/fleet-state.d.ts +129 -0
  23. package/dist/lib/bot/fleet-state.js +669 -0
  24. package/dist/lib/bot/promote.d.ts +9 -3
  25. package/dist/lib/bot/promote.js +115 -16
  26. package/dist/lib/daemon/catalog.d.ts +13 -0
  27. package/dist/lib/daemon/catalog.js +32 -6
  28. package/dist/lib/daemon/lanes-reconcile-status.d.ts +0 -4
  29. package/dist/lib/daemon/lanes-reconcile-status.js +2 -12
  30. package/dist/lib/daemon/lanes-reconcile-watcher.d.ts +1 -1
  31. package/dist/lib/daemon/lanes-reconcile-watcher.js +2 -1
  32. package/dist/lib/daemon/legacy-handover.d.ts +38 -0
  33. package/dist/lib/daemon/legacy-handover.js +117 -0
  34. package/dist/lib/daemon/mesh-owner.js +2 -1
  35. package/dist/lib/daemon/run.d.ts +18 -1
  36. package/dist/lib/daemon/run.js +85 -12
  37. package/dist/lib/daemon/selfcheck.d.ts +28 -0
  38. package/dist/lib/daemon/selfcheck.js +86 -15
  39. package/dist/lib/deploy-api.d.ts +1 -1
  40. package/dist/lib/deploy-api.js +2 -1
  41. package/dist/lib/deploy-identity.d.ts +18 -0
  42. package/dist/lib/deploy-identity.js +179 -0
  43. package/dist/lib/hot-channels/alert.js +13 -6
  44. package/dist/lib/hot-channels/fleet-complete.d.ts +89 -0
  45. package/dist/lib/hot-channels/fleet-complete.js +157 -0
  46. package/dist/lib/hot-channels/run.js +2 -1
  47. package/dist/lib/hot-channels/signals-claude-login.d.ts +3 -2
  48. package/dist/lib/hot-channels/signals-claude-login.js +6 -1
  49. package/dist/lib/hot-channels/signals-pass-failure.d.ts +29 -0
  50. package/dist/lib/hot-channels/signals-pass-failure.js +36 -0
  51. package/dist/lib/hot-channels/signals-pass.d.ts +49 -2
  52. package/dist/lib/hot-channels/signals-pass.js +188 -12
  53. package/dist/lib/hot-channels/signals-runtime.d.ts +6 -3
  54. package/dist/lib/hot-channels/signals-runtime.js +11 -2
  55. package/dist/lib/lanes/reconcile-result.d.ts +5 -0
  56. package/dist/lib/lanes/reconcile-result.js +20 -2
  57. package/dist/lib/lanes/reconcile.js +12 -3
  58. package/dist/lib/mesh/live/emit.js +25 -6
  59. package/dist/lib/mesh/live/flush.js +119 -15
  60. package/dist/lib/mesh/live/reporting-privacy.d.ts +41 -0
  61. package/dist/lib/mesh/live/reporting-privacy.js +147 -1
  62. package/dist/lib/mesh/live/spool.d.ts +16 -0
  63. package/dist/lib/mesh/live/spool.js +45 -0
  64. package/dist/lib/signals/engine.d.ts +17 -3
  65. package/dist/lib/signals/engine.js +28 -9
  66. package/dist/lib/signals/failure-alert.d.ts +33 -1
  67. package/dist/lib/signals/failure-alert.js +72 -5
  68. package/dist/lib/signals/owner-notice.d.ts +94 -0
  69. package/dist/lib/signals/owner-notice.js +233 -0
  70. package/dist/lib/signals/reply.d.ts +7 -0
  71. package/dist/lib/signals/reply.js +23 -3
  72. package/dist/lib/signals/steps/adapters.d.ts +51 -2
  73. package/dist/lib/signals/steps/adapters.js +213 -7
  74. package/dist/lib/signals/steps/extract.js +18 -4
  75. package/dist/lib/signals/steps/types.d.ts +63 -1
  76. package/dist/lib/signals/steps/types.js +32 -0
  77. package/dist/lib/sync-core/engine-auth.d.ts +35 -0
  78. package/dist/lib/sync-core/engine-auth.js +96 -0
  79. package/dist/lib/sync-core/engine-home.d.ts +6 -0
  80. package/dist/lib/sync-core/engine-home.js +12 -0
  81. package/dist/lib/sync-core/rollout-state.d.ts +1 -0
  82. package/dist/lib/sync-core/rollout-state.js +3 -0
  83. package/dist/lib/vault-sync-switches.d.ts +7 -0
  84. package/dist/lib/vault-sync-switches.js +56 -0
  85. package/dist/lib/work-context/errors.d.ts +12 -0
  86. package/dist/lib/work-context/errors.js +15 -0
  87. package/dist/lib/work-context/organize.js +6 -1
  88. package/dist/lib/work-context/reconcile.js +20 -1
  89. package/dist/utils/resident-package-preload.js +34 -4
  90. package/docs/anywhere-runtime.md +6 -0
  91. package/package.json +7 -7
@@ -1,6 +1,7 @@
1
1
  import type { BotRuntimeId } from "../bot/config.js";
2
2
  import { type SpawnLike } from "../bot/runtime/index.js";
3
3
  import type { HotChannelRunResult, WriteGuard } from "./loop.js";
4
+ import { type FleetCompleteTarget } from "./fleet-complete.js";
4
5
  /** The tools the pass can run on. */
5
6
  export type SignalsRuntimeId = "claude" | "codex";
6
7
  /** What went wrong, whatever the tool. */
@@ -18,7 +19,7 @@ export type SignalsFailureClass = "usage-limit" | "logged-out" | "timeout" | "pr
18
19
  * bot runs on Codex, and signals still run on Claude Code because the bot
19
20
  * has not opted in (see CODEX_BOT_NEEDS_CLAUDE_TEXT).
20
21
  */
21
- export type SignalsPassErrorCode = `${SignalsRuntimeId}-${SignalsFailureClass}` | "claude-logged-out-codex-bot";
22
+ export type SignalsPassErrorCode = `${SignalsRuntimeId}-${SignalsFailureClass}` | "claude-logged-out-codex-bot" | "bot-logged-out" | "bot-api-key-login";
22
23
  /**
23
24
  * A pass failure the run ledger records as `status: failed` with `error` set
24
25
  * to the code. Any other error thrown from the pass is a crash.
@@ -41,6 +42,8 @@ export declare class SignalsPassError extends Error {
41
42
  * The terminal command is the fallback.
42
43
  */
43
44
  export declare const CLAUDE_SIGN_IN_STEPS: string;
45
+ export declare const BOT_SIGNED_OUT_TEXT = "The Executive bot's own login needs renewing. Open its profile in HQ, go to Brain, and reconnect its subscription login. Waiting documents stay queued.";
46
+ export declare const BOT_API_KEY_TEXT = "The Executive bot is using an API key. Open its profile in HQ, go to Brain, and connect its Claude or ChatGPT subscription instead. Waiting documents stay queued.";
44
47
  /** The same steps for Codex: the pane's Codex row has "Connect Codex" / "Install Codex". */
45
48
  export declare const CODEX_SIGN_IN_STEPS: string;
46
49
  /** The sign-in steps for the tool the pass runs on. */
@@ -73,6 +76,33 @@ export type SignalType = (typeof SIGNAL_TYPES)[number];
73
76
  * sign-in; `--safe-mode` keeps auth working (checked on Claude Code 2.1.308).
74
77
  */
75
78
  export declare const CLAUDE_ISOLATION_ARGS: readonly string[];
79
+ /**
80
+ * The only variables a `claude` spawn of the pass (the `auth status`
81
+ * preflight and every `claude -p` turn) receives from the parent environment.
82
+ * The pass bills to the subscription login Claude Code keeps (its keychain
83
+ * entry or CLAUDE_CONFIG_DIR, or a CLAUDE_CODE_OAUTH_TOKEN subscription
84
+ * token), never to an API key. In `-p` mode Claude Code prefers
85
+ * ANTHROPIC_API_KEY over that login, and ANTHROPIC_AUTH_TOKEN,
86
+ * ANTHROPIC_BASE_URL, CLAUDE_CODE_USE_BEDROCK and CLAUDE_CODE_USE_VERTEX send
87
+ * the turn to another account or provider, so the environment is an
88
+ * allowlist (like CODEX_SIGNALS_ENV_ALLOWLIST) rather than a list of removals:
89
+ * a variable not named here never reaches claude.
90
+ */
91
+ export declare const CLAUDE_SIGNALS_ENV_ALLOWLIST: readonly string[];
92
+ /** `base` cut down to CLAUDE_SIGNALS_ENV_ALLOWLIST: the environment of every `claude` spawn of the pass. */
93
+ export declare function claudeSignalsEnv(base: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
94
+ /**
95
+ * Why a `claude auth status` reply is not a subscription login, or null when
96
+ * it is (or when the reply does not say). An API key (`authMethod: api_key`,
97
+ * any `apiKeySource`), a Bedrock or Vertex provider (`authMethod:
98
+ * third_party`, or an `apiProvider` other than `firstParty`) all bill
99
+ * somewhere other than the user's subscription. Exported for tests.
100
+ */
101
+ export declare function claudeApiKeyLogin(status: {
102
+ authMethod?: unknown;
103
+ apiProvider?: unknown;
104
+ apiKeySource?: unknown;
105
+ }): string | null;
76
106
  /** Per-document `claude -p` budget (policy indigo-executors-bound-all-waits). */
77
107
  export declare const DEFAULT_SIGNALS_TIMEOUT_MS = 120000;
78
108
  /** Budget for the `claude auth status` preflight. */
@@ -147,6 +177,13 @@ export interface ClaudeSignalsPassOptions {
147
177
  * `codex-logged-out`; no other login is used.
148
178
  */
149
179
  botRuntimeEnv?: () => NodeJS.ProcessEnv;
180
+ /**
181
+ * The HQ Fleet Executive bot whose own login the pass runs on (see the file
182
+ * header and fleet-complete.ts), or null when it is not a Fleet bot or its
183
+ * helper is not installed. Read once, when the first document is about to
184
+ * be sent. Unset, null or a throw: the paths below, as before.
185
+ */
186
+ fleetComplete?: () => FleetCompleteTarget | null;
150
187
  /** The `codex` CLI for the Codex runtime; the bot runtime's own lookup by default. */
151
188
  codexBin?: string;
152
189
  /** Test seam: the spawn used for the sign-in check and the Codex turn. */
@@ -158,7 +195,17 @@ export interface ClaudeSignalsPassOptions {
158
195
  * (signals-claude-login.ts), which `hq bot status` reads. Must not throw.
159
196
  * Only a pass on Claude Code reports; a pass on Codex does not.
160
197
  */
161
- onClaudeLogin?: (signedIn: boolean) => void;
198
+ onClaudeLogin?: (signedIn: boolean | null) => void;
199
+ /**
200
+ * Told each time the pass sends one document to its tool, after the login
201
+ * check passed, with the tool it runs on. Bad-output retries of the same
202
+ * document are not counted again. `hq signals run` counts these for its run
203
+ * record (engine, account, model turns). Unset: nothing is reported. A throw
204
+ * is ignored.
205
+ */
206
+ onDocumentSent?: (runtime: SignalsRuntimeId) => void;
207
+ /** Login actually selected, including a fallback before its preflight. */
208
+ onLoginRoute?: (route: "fleet" | "claude-cli" | "codex-bot") => void;
162
209
  }
163
210
  /** Why the pass sent claude the pointer alone. */
164
211
  export type PayloadFallbackReason = "payload-out-of-bounds" | "payload-missing" | "payload-unreadable";
@@ -24,7 +24,17 @@ import { prepareSignalPublication, flushSignalPublications } from "../bot/jobs/s
24
24
  * MAX_PAYLOAD_BYTES. A payload outside `sources/`, missing or unreadable falls
25
25
  * back to the pointer alone, and the reason is warned and kept on the signal.
26
26
  *
27
- * Runtime: Claude Code (`claude -p`) by default, exactly as before. When the
27
+ * Runtime: an HQ Fleet Executive bot's own login first (fleet-complete.ts).
28
+ * When `fleetComplete` names a Claude or Codex Fleet bot whose
29
+ * `hq-fleet-local` helper is installed, every document goes through
30
+ * `hq-fleet-local complete`: one locked-down turn with the login the bot
31
+ * answers chat with, never an API key and never a separate `claude auth
32
+ * login`. The `claude` CLI preflight is not run and Claude Code's login is not
33
+ * reported. Only when the helper is missing (not such a bot, not installed, or
34
+ * a helper release with no `complete` command) does the pass fall back to the
35
+ * paths below.
36
+ *
37
+ * Otherwise: Claude Code (`claude -p`), exactly as before. When the
28
38
  * Executive bot (the bot whose runtime the pass already reads for its
29
39
  * signed-out wording) is a Codex bot with `signalsRuntime: "bot"` in bot.json
30
40
  * (`hq bot set <name> --signals-runtime bot`), the pass runs on Codex
@@ -93,6 +103,7 @@ import * as yaml from "js-yaml";
93
103
  import { audienceKey, COMPANY_AUDIENCE_KEY } from "./audience.js";
94
104
  import { assertVaultPath } from "../signals/write-guard.js";
95
105
  import { assertPayloadRef, assertSafeSegment, writeFileAtomic } from "./landing.js";
106
+ import { fleetFailureClass, fleetFailureMessage, runFleetComplete } from "./fleet-complete.js";
96
107
  /**
97
108
  * A pass failure the run ledger records as `status: failed` with `error` set
98
109
  * to the code. Any other error thrown from the pass is a crash.
@@ -110,6 +121,8 @@ export class SignalsPassError extends Error {
110
121
  }
111
122
  /** The failure class without the tool: `bad-output` for both `claude-bad-output` and `codex-bad-output`. */
112
123
  get failure() {
124
+ if (this.code === "bot-logged-out" || this.code === "bot-api-key-login")
125
+ return "logged-out";
113
126
  return this.code === "claude-logged-out-codex-bot" ? "logged-out" : this.code.replace(/^(?:claude|codex)-/, "");
114
127
  }
115
128
  }
@@ -122,6 +135,8 @@ export class SignalsPassError extends Error {
122
135
  */
123
136
  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). " +
124
137
  "Or run `claude auth login` in a terminal on this computer.";
138
+ export const BOT_SIGNED_OUT_TEXT = "The Executive bot's own login needs renewing. Open its profile in HQ, go to Brain, and reconnect its subscription login. Waiting documents stay queued.";
139
+ export const BOT_API_KEY_TEXT = "The Executive bot is using an API key. Open its profile in HQ, go to Brain, and connect its Claude or ChatGPT subscription instead. Waiting documents stay queued.";
125
140
  /** The same steps for Codex: the pane's Codex row has "Connect Codex" / "Install Codex". */
126
141
  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). " +
127
142
  "Or run `codex login` in a terminal on this computer.";
@@ -182,6 +197,69 @@ export const CLAUDE_ISOLATION_ARGS = [
182
197
  "--setting-sources",
183
198
  "",
184
199
  ];
200
+ /**
201
+ * The only variables a `claude` spawn of the pass (the `auth status`
202
+ * preflight and every `claude -p` turn) receives from the parent environment.
203
+ * The pass bills to the subscription login Claude Code keeps (its keychain
204
+ * entry or CLAUDE_CONFIG_DIR, or a CLAUDE_CODE_OAUTH_TOKEN subscription
205
+ * token), never to an API key. In `-p` mode Claude Code prefers
206
+ * ANTHROPIC_API_KEY over that login, and ANTHROPIC_AUTH_TOKEN,
207
+ * ANTHROPIC_BASE_URL, CLAUDE_CODE_USE_BEDROCK and CLAUDE_CODE_USE_VERTEX send
208
+ * the turn to another account or provider, so the environment is an
209
+ * allowlist (like CODEX_SIGNALS_ENV_ALLOWLIST) rather than a list of removals:
210
+ * a variable not named here never reaches claude.
211
+ */
212
+ export const CLAUDE_SIGNALS_ENV_ALLOWLIST = [
213
+ "PATH",
214
+ "HOME",
215
+ "USER",
216
+ "LOGNAME",
217
+ "SHELL",
218
+ "TMPDIR",
219
+ "LANG",
220
+ "LC_ALL",
221
+ "LC_CTYPE",
222
+ "TERM",
223
+ "CLAUDE_CONFIG_DIR",
224
+ "CLAUDE_CODE_OAUTH_TOKEN",
225
+ "XDG_CONFIG_HOME",
226
+ "HTTPS_PROXY",
227
+ "HTTP_PROXY",
228
+ "NO_PROXY",
229
+ "https_proxy",
230
+ "http_proxy",
231
+ "no_proxy",
232
+ "NODE_EXTRA_CA_CERTS",
233
+ "SSL_CERT_FILE",
234
+ "SSL_CERT_DIR",
235
+ ];
236
+ /** `base` cut down to CLAUDE_SIGNALS_ENV_ALLOWLIST: the environment of every `claude` spawn of the pass. */
237
+ export function claudeSignalsEnv(base) {
238
+ const allowed = {};
239
+ for (const key of CLAUDE_SIGNALS_ENV_ALLOWLIST) {
240
+ if (base[key] !== undefined)
241
+ allowed[key] = base[key];
242
+ }
243
+ return allowed;
244
+ }
245
+ /**
246
+ * Why a `claude auth status` reply is not a subscription login, or null when
247
+ * it is (or when the reply does not say). An API key (`authMethod: api_key`,
248
+ * any `apiKeySource`), a Bedrock or Vertex provider (`authMethod:
249
+ * third_party`, or an `apiProvider` other than `firstParty`) all bill
250
+ * somewhere other than the user's subscription. Exported for tests.
251
+ */
252
+ export function claudeApiKeyLogin(status) {
253
+ if (status.authMethod === "api_key")
254
+ return "authMethod api_key";
255
+ if (status.authMethod === "third_party")
256
+ return "authMethod third_party";
257
+ if (typeof status.apiKeySource === "string" && status.apiKeySource.trim() !== "")
258
+ return "an API key source";
259
+ if (typeof status.apiProvider === "string" && status.apiProvider !== "firstParty")
260
+ return `apiProvider ${status.apiProvider}`;
261
+ return null;
262
+ }
185
263
  /** Per-document `claude -p` budget (policy indigo-executors-bound-all-waits). */
186
264
  export const DEFAULT_SIGNALS_TIMEOUT_MS = 120_000;
187
265
  /** Budget for the `claude auth status` preflight. */
@@ -760,6 +838,9 @@ export function createClaudeSignalsPass(options) {
760
838
  const promptFile = options.promptFile ?? defaultPromptFile();
761
839
  const now = options.now ?? (() => new Date());
762
840
  const env = options.env ?? process.env;
841
+ // Every claude spawn (preflight and turns) gets only the allowlist, so an
842
+ // API key or provider switch in the parent environment never bills the turn.
843
+ const claudeEnv = claudeSignalsEnv(env);
763
844
  const warn = options.warn ?? ((message) => void process.stderr.write(`${message}\n`));
764
845
  const vaultRoot = path.join(options.hqRoot, "companies", options.company);
765
846
  // claude runs outside the HQ tree so it loads no HQ project context or hooks.
@@ -777,9 +858,30 @@ export function createClaudeSignalsPass(options) {
777
858
  return false;
778
859
  }
779
860
  };
861
+ /**
862
+ * The Fleet Executive bot this pass runs on, read once (undefined until
863
+ * then). Set to null when its helper turns out to have no `complete`
864
+ * command, so the rest of the pass uses the paths below.
865
+ */
866
+ let fleetChoice;
867
+ const fleet = () => {
868
+ if (fleetChoice === undefined) {
869
+ try {
870
+ fleetChoice = options.fleetComplete?.() ?? null;
871
+ }
872
+ catch {
873
+ // An unreadable bot or Fleet install keeps today's paths.
874
+ fleetChoice = null;
875
+ }
876
+ }
877
+ return fleetChoice;
878
+ };
780
879
  /** The tool this pass runs on, decided once per pass (see the file header). */
781
880
  let runtimeChoice;
782
881
  const signalsRuntime = () => {
882
+ const target = fleet();
883
+ if (target)
884
+ return target.runtime;
783
885
  if (runtimeChoice === undefined) {
784
886
  let optedIn = false;
785
887
  try {
@@ -862,28 +964,44 @@ export function createClaudeSignalsPass(options) {
862
964
  return runtimeSpawn(command, args, { ...spawnOptions, env: allowed });
863
965
  };
864
966
  const tellLogin = (signedIn) => {
865
- // The record is Claude Code's login; a pass on Codex has nothing to add to it.
866
- if (signalsRuntime() !== "claude")
867
- return;
967
+ // null retires a stale Claude Code record when this pass uses another login.
868
968
  try {
869
- options.onClaudeLogin?.(signedIn);
969
+ options.onClaudeLogin?.(fleet() || signalsRuntime() !== "claude" ? null : signedIn);
870
970
  }
871
971
  catch {
872
972
  // A report only; it never changes the pass's outcome.
873
973
  }
874
974
  };
875
975
  const checkLogin = async () => {
876
- await (signalsRuntime() === "codex" ? checkCodexLogin() : checkClaudeLogin());
877
- tellLogin(true);
976
+ try {
977
+ options.onLoginRoute?.(fleet() ? "fleet" : signalsRuntime() === "codex" ? "codex-bot" : "claude-cli");
978
+ }
979
+ catch { /* Reporting must not fail the pass. */ }
980
+ // A Fleet bot's login is checked by its first turn: the helper answers
981
+ // signed_out before any request when the bot cannot sign in.
982
+ if (fleet()) {
983
+ tellLogin(true);
984
+ return;
985
+ }
986
+ if (signalsRuntime() === "codex") {
987
+ tellLogin(false);
988
+ await checkCodexLogin();
989
+ }
990
+ else {
991
+ await checkClaudeLogin();
992
+ tellLogin(true);
993
+ }
878
994
  };
879
995
  /**
880
996
  * The Claude preflight, unchanged from before the Codex option: a hung
881
997
  * `claude auth status` is claude-timeout at once, a CLI that cannot start or
882
998
  * exits non-zero is signed out, `loggedIn: false` is signed out, any other
883
- * exit 0 is signed in.
999
+ * exit 0 is signed in. A login that is an API key or a Bedrock/Vertex
1000
+ * provider (claudeApiKeyLogin) is refused as signed out: the pass runs only
1001
+ * on the subscription login, never an API key.
884
1002
  */
885
1003
  const checkClaudeLogin = async () => {
886
- const run = await runBounded(claude, ["auth", "status"], { timeoutMs: authTimeoutMs, cwd: claudeCwd, env });
1004
+ const run = await runBounded(claude, ["auth", "status"], { timeoutMs: authTimeoutMs, cwd: claudeCwd, env: claudeEnv });
887
1005
  if (run.timedOut)
888
1006
  throw new SignalsPassError("claude-timeout", "claude auth status timed out");
889
1007
  if (run.spawnError !== undefined || run.code !== 0) {
@@ -893,6 +1011,10 @@ export function createClaudeSignalsPass(options) {
893
1011
  const status = JSON.parse(run.stdout);
894
1012
  if (status.loggedIn === false)
895
1013
  throw new SignalsPassError("claude-logged-out", "claude is not logged in");
1014
+ const apiKey = status && typeof status === "object" ? claudeApiKeyLogin(status) : null;
1015
+ if (apiKey) {
1016
+ throw new SignalsPassError("claude-logged-out", `claude is signed in with an API key or another provider (${apiKey}), not a Claude subscription login; the signals pass never uses an API key`);
1017
+ }
896
1018
  }
897
1019
  catch (err) {
898
1020
  if (err instanceof SignalsPassError)
@@ -1018,7 +1140,55 @@ export function createClaudeSignalsPass(options) {
1018
1140
  }
1019
1141
  }
1020
1142
  };
1021
- const extractOnce = (item, input) => signalsRuntime() === "codex" ? extractOnceCodex(item, input) : extractOnceClaude(item, input);
1143
+ const extractOnce = async (item, input) => {
1144
+ const target = fleet();
1145
+ if (target) {
1146
+ const signals = await extractOnceFleet(target, item, input);
1147
+ if (signals !== null)
1148
+ return signals;
1149
+ // The helper cannot run a completion: the rest of the pass, this
1150
+ // document included, uses the paths below, starting with their own
1151
+ // login preflight.
1152
+ fleetChoice = null;
1153
+ await checkLogin();
1154
+ }
1155
+ return signalsRuntime() === "codex" ? extractOnceCodex(item, input) : extractOnceClaude(item, input);
1156
+ };
1157
+ /**
1158
+ * One turn on the Fleet bot's own login (fleet-complete.ts). Null when the
1159
+ * helper is missing or has no `complete` command. The reply is model output
1160
+ * built from the document: it is parsed, and only its size is ever logged.
1161
+ */
1162
+ const extractOnceFleet = async (target, item, input) => {
1163
+ prompt ??= fs.readFile(promptFile, "utf8");
1164
+ const instructions = await prompt;
1165
+ const stdin = `${instructions.trimEnd()}\n\n--- document ---\n${input.text}`;
1166
+ const result = await runFleetComplete(target, stdin, { timeoutMs, env, cwd: claudeCwd, run: runBounded });
1167
+ if (result.kind === "missing") {
1168
+ warn(`signals pass: ${result.reason}; using the ${claude} CLI instead`);
1169
+ return null;
1170
+ }
1171
+ const runtime = target.runtime;
1172
+ if (result.kind === "error") {
1173
+ const failure = fleetFailureClass(result.code);
1174
+ const detail = failure === "timeout" ? ` after ${timeoutMs}ms on ${item.file}` : "";
1175
+ const code = result.code === "api_key_login" ? "bot-api-key-login" : failure === "logged-out" ? "bot-logged-out" : `${runtime}-${failure}`;
1176
+ const err = new SignalsPassError(code, fleetFailureMessage(target, result.code, detail));
1177
+ // An empty reply would be empty again.
1178
+ if (failure === "bad-output")
1179
+ err.noRetry = true;
1180
+ throw err;
1181
+ }
1182
+ try {
1183
+ return parseSignalsReply(result.text, runtime);
1184
+ }
1185
+ catch (err) {
1186
+ if (err instanceof SignalsPassError && err.failure === "bad-output") {
1187
+ throw new SignalsPassError(`${runtime}-bad-output`, `${err.message} (reply ${Buffer.byteLength(result.text)} bytes)`);
1188
+ }
1189
+ throw err;
1190
+ }
1191
+ };
1022
1192
  /**
1023
1193
  * One Codex call through the bot runtime's turn runner, the one a Daily
1024
1194
  * Brief job goes through (runRuntimeTurn), with the isolated argv of
@@ -1074,7 +1244,7 @@ export function createClaudeSignalsPass(options) {
1074
1244
  timeoutMs,
1075
1245
  input: input.text,
1076
1246
  cwd: claudeCwd,
1077
- env,
1247
+ env: claudeEnv,
1078
1248
  });
1079
1249
  if (run.timedOut)
1080
1250
  throw new SignalsPassError("claude-timeout", `claude timed out after ${timeoutMs}ms on ${item.file}`);
@@ -1198,6 +1368,12 @@ export function createClaudeSignalsPass(options) {
1198
1368
  preflight ??= checkLogin();
1199
1369
  await preflight;
1200
1370
  docsSent += 1;
1371
+ try {
1372
+ options.onDocumentSent?.(signalsRuntime());
1373
+ }
1374
+ catch {
1375
+ // A report only; it never changes the pass's outcome.
1376
+ }
1201
1377
  const input = await buildSignalsInput(vaultRoot, item.file);
1202
1378
  if (input.fallback !== undefined) {
1203
1379
  warn(`signals pass: ${item.file}: ${input.fallback} for payload_ref ${JSON.stringify(input.fallbackRef)}; sent the pointer only`);
@@ -1244,7 +1420,7 @@ export function createClaudeSignalsPass(options) {
1244
1420
  }
1245
1421
  catch (caught) {
1246
1422
  let err = caught;
1247
- if (err instanceof SignalsPassError && err.code === "claude-logged-out") {
1423
+ if (err instanceof SignalsPassError && err.code === "claude-logged-out" && !fleet()) {
1248
1424
  tellLogin(false);
1249
1425
  // Still on Claude Code because the Codex bot has not opted in.
1250
1426
  if (codexBot())
@@ -1,8 +1,11 @@
1
1
  /**
2
2
  * Which bot the hot-channel signals pass takes its runtime from, and which
3
- * Codex login it uses.
3
+ * login it uses.
4
4
  *
5
- * The pass runs on Claude Code unless the Executive bot is a Codex bot whose
5
+ * When the Executive bot is a Claude or Codex HQ Fleet bot with its
6
+ * hq-fleet-local helper installed, the pass runs on that bot's own login
7
+ * (fleet-complete.ts). Otherwise it runs on Claude Code unless the
8
+ * Executive bot is a Codex bot whose
6
9
  * bot.json has `signalsRuntime: "bot"` (signalsPassRuntime in bot/config.ts).
7
10
  * Both `hq bot run` (the hot-signal-sync job) and `hq sources sync` use the
8
11
  * Executive bot, the bot whose runtime the pass already read for its wording
@@ -14,7 +17,7 @@
14
17
  import { signalsCodexLogin, type SignalsCodexLogin } from "../signals/codex-login.js";
15
18
  import type { ClaudeSignalsPassOptions } from "./signals-pass.js";
16
19
  export { signalsCodexLogin, type SignalsCodexLogin } from "../signals/codex-login.js";
17
- export type SignalsRuntimeOptions = Required<Pick<ClaudeSignalsPassOptions, "botRuntime" | "useBotRuntime" | "botRuntimeEnv">>;
20
+ export type SignalsRuntimeOptions = Required<Pick<ClaudeSignalsPassOptions, "botRuntime" | "useBotRuntime" | "botRuntimeEnv" | "fleetComplete">>;
18
21
  /**
19
22
  * signalsCodexLogin, plus the extract step's refusal of a login folder that
20
23
  * holds files Codex would load as instructions (AGENTS.md,
@@ -1,8 +1,11 @@
1
1
  /**
2
2
  * Which bot the hot-channel signals pass takes its runtime from, and which
3
- * Codex login it uses.
3
+ * login it uses.
4
4
  *
5
- * The pass runs on Claude Code unless the Executive bot is a Codex bot whose
5
+ * When the Executive bot is a Claude or Codex HQ Fleet bot with its
6
+ * hq-fleet-local helper installed, the pass runs on that bot's own login
7
+ * (fleet-complete.ts). Otherwise it runs on Claude Code unless the
8
+ * Executive bot is a Codex bot whose
6
9
  * bot.json has `signalsRuntime: "bot"` (signalsPassRuntime in bot/config.ts).
7
10
  * Both `hq bot run` (the hot-signal-sync job) and `hq sources sync` use the
8
11
  * Executive bot, the bot whose runtime the pass already read for its wording
@@ -16,6 +19,7 @@ import { resolveExecutiveBot } from "../bot/executive.js";
16
19
  import { botsRoot } from "../bot/paths.js";
17
20
  import { signalsCodexLogin } from "../signals/codex-login.js";
18
21
  import { codexHomeInstructions } from "../signals/steps/extract.js";
22
+ import { fleetCompleteTarget } from "./fleet-complete.js";
19
23
  // The shared login rule lives in signals/codex-login.ts; re-exported for callers here.
20
24
  export { signalsCodexLogin } from "../signals/codex-login.js";
21
25
  /**
@@ -41,6 +45,10 @@ export function signalsPassCodexLogin(dir, config, base = process.env) {
41
45
  /** The options for a pass that runs on the bot in `dir`. */
42
46
  export function botSignalsRuntimeOptions(dir, base = process.env) {
43
47
  return {
48
+ // A Claude or Codex HQ Fleet bot: the pass runs on the bot's own login
49
+ // through its installed hq-fleet-local helper (fleet-complete.ts). Null
50
+ // for any other bot, or when the helper is not installed.
51
+ fleetComplete: () => fleetCompleteTarget(dir),
44
52
  botRuntime: () => {
45
53
  const config = readBotConfig(dir);
46
54
  return config && isBotRuntimeId(config.runtime) ? config.runtime : null;
@@ -69,6 +77,7 @@ export function executiveSignalsRuntimeOptions(root = botsRoot(), base = process
69
77
  return bot ? botSignalsRuntimeOptions(bot.dir, base) : null;
70
78
  };
71
79
  return {
80
+ fleetComplete: () => executive()?.fleetComplete() ?? null,
72
81
  botRuntime: () => executive()?.botRuntime() ?? null,
73
82
  useBotRuntime: () => executive()?.useBotRuntime() ?? false,
74
83
  botRuntimeEnv: () => {
@@ -5,6 +5,11 @@ export interface ReconcilePassResult {
5
5
  message: string;
6
6
  }[];
7
7
  }
8
+ type ReconcileFailureCode = "reconcile_step_failed" | "story_ledger_missing" | "story_close_ledger_read_failed";
9
+ export declare function recordReconcileFailure(result: ReconcilePassResult, code: ReconcileFailureCode): void;
10
+ /** Only this module constructs a diagnostic from a closed set of codes. */
11
+ export declare function reconcileFailureText(error: unknown): string;
8
12
  /** Preserve CLI exit semantics while letting the daemon report failures to its watcher. */
9
13
  export declare function finishReconcilePass(summary: ReconcilePassResult, mode: "cli" | "daemon", exit?: (code: number) => void): void;
14
+ export {};
10
15
  //# sourceMappingURL=reconcile-result.d.ts.map
@@ -1,10 +1,28 @@
1
+ // Keep daemon diagnostics off the public CLI summary and separate from ordinary skips.
2
+ const failureCodes = new WeakMap();
3
+ export function recordReconcileFailure(result, code) {
4
+ let codes = failureCodes.get(result);
5
+ if (!codes) {
6
+ codes = new Set();
7
+ failureCodes.set(result, codes);
8
+ }
9
+ codes.add(code);
10
+ }
11
+ class ReconcilePassError extends Error {
12
+ }
13
+ /** Only this module constructs a diagnostic from a closed set of codes. */
14
+ export function reconcileFailureText(error) {
15
+ return error instanceof ReconcilePassError ? error.message : "unexpected_reconcile_error";
16
+ }
1
17
  /** Preserve CLI exit semantics while letting the daemon report failures to its watcher. */
2
18
  export function finishReconcilePass(summary, mode, exit = (code) => process.exit(code)) {
3
19
  if (summary.ok)
4
20
  return;
5
21
  if (mode === "daemon") {
6
- const detail = summary.errors?.map((error) => `${error.code ?? "unknown"}: ${error.message}`).join("; ") ?? "unknown reconcile error";
7
- throw new Error(`In-process lanes reconcile failed: ${detail}`);
22
+ const codes = new Set(failureCodes.get(summary));
23
+ if (summary.errors?.length)
24
+ codes.add("reconcile_step_failed");
25
+ throw new ReconcilePassError([...codes].join(", ") || "unknown_reconcile_error");
8
26
  }
9
27
  exit(1);
10
28
  }
@@ -48,6 +48,7 @@ import { createLaneMesh, emitLaneDecisionEvents, emitLaneTerminalStateEvent, lan
48
48
  import { activeLaneStories, laneStories, terminalEnvelopeStoryStatus } from "./stories.js";
49
49
  import { applyStorySwitchEnvelope } from "./story-switch.js";
50
50
  import { readProjectStoryStates } from "./story-ledger.js";
51
+ import { recordReconcileFailure } from "./reconcile-result.js";
51
52
  import { decideEnvelopeRepair, envelopeQuestionIds, routeProviderFailure } from "./watcher.js";
52
53
  import { liveOwnerMaxMs, lockFileContents, reclaimStaleLock } from "./stale-lock.js";
53
54
  import { PROVIDER_REJECTED_REASON, providerRejectionDetails, readProviderRejection, } from "./provider-rejection.js";
@@ -136,10 +137,11 @@ function emptySummary(dryRun) {
136
137
  heartbeat_at: null,
137
138
  };
138
139
  }
139
- function markDirty(summary, skip) {
140
+ function markDirty(summary, skip, code = "reconcile_step_failed") {
140
141
  summary.skipped.push(skip);
141
142
  summary.ok = false;
142
- logSkip(skip);
143
+ recordReconcileFailure(summary, code);
144
+ process.stderr.write(`hq runners reconcile: ${code}\n`);
143
145
  }
144
146
  function isMissingPathError(error) {
145
147
  const code = error?.code;
@@ -631,7 +633,14 @@ async function closeInterruptedDoneStoryWorkers(hqRoot, lanes, questions, summar
631
633
  ledger = laneStoryLedgerIsClosed(hqRoot, lane);
632
634
  }
633
635
  catch (err) {
634
- markDirty(summary, { kind: "lane", id: lane.lane_id, why: `story close ledger read failed: ${err instanceof Error ? err.message : String(err)}` });
636
+ const code = err instanceof LanesError && err.error === "story_ledger_missing"
637
+ ? "story_ledger_missing"
638
+ : "story_close_ledger_read_failed";
639
+ markDirty(summary, {
640
+ kind: "lane",
641
+ id: lane.lane_id,
642
+ why: `story close ledger read failed: ${err instanceof Error ? err.message : String(err)}`,
643
+ }, code);
635
644
  continue;
636
645
  }
637
646
  if (!ledger.closed)
@@ -1,4 +1,4 @@
1
- import { hasWorkMeshEventCompanyBinding, mayEmitConversation, workMeshSwitchDisabled } from "./reporting-privacy.js";
1
+ import { anywhereOffSince, eventDatedSince, hasWorkMeshEventCompanyBinding, logAnywhereOffSinceAhead, mayEmitConversation, operatorAllowsHqAnywhere, workMeshSwitchDisabled, } from "./reporting-privacy.js";
2
2
  import { hqAnywhereRuntimeLocallyDisabled } from "../../anywhere-runtime-flag-key.js";
3
3
  /**
4
4
  * Direct-emit orchestration (owner decision 2026-09-08). One invocation:
@@ -93,13 +93,32 @@ export async function emitEvents(deps) {
93
93
  rejections: [],
94
94
  };
95
95
  const env = deps.env ?? process.env;
96
+ // Events kept back because the member switched HQ Anywhere off. They wait
97
+ // in the retry file, as before. Empty unless HQ Anywhere is off.
98
+ let withheld = [];
99
+ let sendable = combined;
96
100
  if (hqAnywhereRuntimeLocallyDisabled(env) || (deps.reportingAllowed && !(await deps.reportingAllowed()))) {
97
- const written = writeEmitRetry(deps.workMeshRoot, combined, retryMax);
98
- return { ...summary, attempted: 0, retained: written.written,
99
- retryDepth: written.written, droppedOverflow: written.dropped };
101
+ // The member's HQ Anywhere switch does not stop a session with a verified
102
+ // company binding. The operator's switch stops everything.
103
+ // Events stored before this machine first saw HQ Anywhere off were held
104
+ // back by the member's opt-out; while it stays off they wait.
105
+ let bound = [];
106
+ if (operatorAllowsHqAnywhere(env)) {
107
+ const offSinceMs = anywhereOffSince(deps.workMeshRoot, now);
108
+ logAnywhereOffSinceAhead(deps.workMeshRoot, offSinceMs, now().getTime(), deps.log);
109
+ bound = combined.filter(event => eventDatedSince(event, offSinceMs) && hasWorkMeshEventCompanyBinding(event, env));
110
+ }
111
+ if (bound.length === 0) {
112
+ const written = writeEmitRetry(deps.workMeshRoot, combined, retryMax);
113
+ return { ...summary, attempted: 0, retained: written.written,
114
+ retryDepth: written.written, droppedOverflow: written.dropped };
115
+ }
116
+ const sending = new Set(bound);
117
+ withheld = combined.filter(event => !sending.has(event));
118
+ sendable = bound;
100
119
  }
101
120
  const meshDisabled = workMeshSwitchDisabled(env);
102
- const allowed = combined.filter(event => {
121
+ const allowed = sendable.filter(event => {
103
122
  const code = meshDisabled && !hasWorkMeshEventCompanyBinding(event, env)
104
123
  ? "WORK_MESH_DISABLED"
105
124
  : !mayEmitConversation(event, env) ? "PERSONAL_OR_UNATTRIBUTED" : undefined;
@@ -113,7 +132,7 @@ export async function emitEvents(deps) {
113
132
  return false;
114
133
  });
115
134
  summary.attempted = allowed.length;
116
- const keep = [];
135
+ const keep = [...withheld];
117
136
  let anyPosted = false;
118
137
  for (let i = 0; i < allowed.length; i += MESH_EVENTS_BATCH_MAX) {
119
138
  const chunk = allowed.slice(i, i + MESH_EVENTS_BATCH_MAX);