@indigoai-us/hq-cli 5.345.235 → 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 (94) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/command-catalog.generated.d.ts +76 -1
  3. package/dist/command-catalog.generated.js +93 -1
  4. package/dist/command-registration-plan.d.ts +6 -0
  5. package/dist/command-registration-plan.js +1 -0
  6. package/dist/commands/bot.js +9 -0
  7. package/dist/commands/daemon.d.ts +1 -0
  8. package/dist/commands/daemon.js +70 -6
  9. package/dist/commands/deploy-app-db.js +4 -19
  10. package/dist/commands/deploy-app-upload.js +66 -40
  11. package/dist/commands/deploy-mutations.js +24 -16
  12. package/dist/commands/deploy-runtime-bindings.d.ts +3 -0
  13. package/dist/commands/deploy-runtime-bindings.js +116 -0
  14. package/dist/commands/deploy-ssr.js +5 -24
  15. package/dist/commands/mesh.js +6 -2
  16. package/dist/commands/signals-run.d.ts +43 -2
  17. package/dist/commands/signals-run.js +85 -7
  18. package/dist/commands/sync-core.d.ts +7 -0
  19. package/dist/commands/sync-core.js +52 -3
  20. package/dist/lib/bot/continuity.d.ts +21 -2
  21. package/dist/lib/bot/continuity.js +48 -19
  22. package/dist/lib/bot/fleet-cron.js +6 -0
  23. package/dist/lib/bot/fleet-local.d.ts +11 -1
  24. package/dist/lib/bot/fleet-local.js +21 -1
  25. package/dist/lib/bot/fleet-state.d.ts +129 -0
  26. package/dist/lib/bot/fleet-state.js +669 -0
  27. package/dist/lib/bot/promote.d.ts +9 -3
  28. package/dist/lib/bot/promote.js +115 -16
  29. package/dist/lib/daemon/catalog.d.ts +13 -0
  30. package/dist/lib/daemon/catalog.js +32 -6
  31. package/dist/lib/daemon/lanes-reconcile-status.d.ts +0 -4
  32. package/dist/lib/daemon/lanes-reconcile-status.js +2 -12
  33. package/dist/lib/daemon/lanes-reconcile-watcher.d.ts +1 -1
  34. package/dist/lib/daemon/lanes-reconcile-watcher.js +2 -1
  35. package/dist/lib/daemon/legacy-handover.d.ts +38 -0
  36. package/dist/lib/daemon/legacy-handover.js +117 -0
  37. package/dist/lib/daemon/mesh-owner.js +2 -1
  38. package/dist/lib/daemon/run.d.ts +18 -1
  39. package/dist/lib/daemon/run.js +85 -12
  40. package/dist/lib/daemon/selfcheck.d.ts +28 -0
  41. package/dist/lib/daemon/selfcheck.js +86 -15
  42. package/dist/lib/deploy-api.d.ts +2 -2
  43. package/dist/lib/deploy-api.js +4 -2
  44. package/dist/lib/deploy-identity.d.ts +18 -0
  45. package/dist/lib/deploy-identity.js +179 -0
  46. package/dist/lib/hot-channels/alert.js +13 -6
  47. package/dist/lib/hot-channels/fleet-complete.d.ts +89 -0
  48. package/dist/lib/hot-channels/fleet-complete.js +157 -0
  49. package/dist/lib/hot-channels/run.js +2 -1
  50. package/dist/lib/hot-channels/signals-claude-login.d.ts +3 -2
  51. package/dist/lib/hot-channels/signals-claude-login.js +6 -1
  52. package/dist/lib/hot-channels/signals-pass-failure.d.ts +29 -0
  53. package/dist/lib/hot-channels/signals-pass-failure.js +36 -0
  54. package/dist/lib/hot-channels/signals-pass.d.ts +49 -2
  55. package/dist/lib/hot-channels/signals-pass.js +188 -12
  56. package/dist/lib/hot-channels/signals-runtime.d.ts +6 -3
  57. package/dist/lib/hot-channels/signals-runtime.js +11 -2
  58. package/dist/lib/lanes/reconcile-result.d.ts +5 -0
  59. package/dist/lib/lanes/reconcile-result.js +20 -2
  60. package/dist/lib/lanes/reconcile.js +12 -3
  61. package/dist/lib/mesh/live/emit.js +25 -6
  62. package/dist/lib/mesh/live/flush.js +119 -15
  63. package/dist/lib/mesh/live/reporting-privacy.d.ts +41 -0
  64. package/dist/lib/mesh/live/reporting-privacy.js +147 -1
  65. package/dist/lib/mesh/live/spool.d.ts +16 -0
  66. package/dist/lib/mesh/live/spool.js +45 -0
  67. package/dist/lib/signals/engine.d.ts +17 -3
  68. package/dist/lib/signals/engine.js +28 -9
  69. package/dist/lib/signals/failure-alert.d.ts +33 -1
  70. package/dist/lib/signals/failure-alert.js +72 -5
  71. package/dist/lib/signals/owner-notice.d.ts +94 -0
  72. package/dist/lib/signals/owner-notice.js +233 -0
  73. package/dist/lib/signals/reply.d.ts +7 -0
  74. package/dist/lib/signals/reply.js +23 -3
  75. package/dist/lib/signals/steps/adapters.d.ts +51 -2
  76. package/dist/lib/signals/steps/adapters.js +213 -7
  77. package/dist/lib/signals/steps/extract.js +18 -4
  78. package/dist/lib/signals/steps/types.d.ts +63 -1
  79. package/dist/lib/signals/steps/types.js +32 -0
  80. package/dist/lib/sync-core/engine-auth.d.ts +35 -0
  81. package/dist/lib/sync-core/engine-auth.js +96 -0
  82. package/dist/lib/sync-core/engine-home.d.ts +6 -0
  83. package/dist/lib/sync-core/engine-home.js +12 -0
  84. package/dist/lib/sync-core/rollout-state.d.ts +1 -0
  85. package/dist/lib/sync-core/rollout-state.js +3 -0
  86. package/dist/lib/vault-sync-switches.d.ts +7 -0
  87. package/dist/lib/vault-sync-switches.js +56 -0
  88. package/dist/lib/work-context/errors.d.ts +12 -0
  89. package/dist/lib/work-context/errors.js +15 -0
  90. package/dist/lib/work-context/organize.js +6 -1
  91. package/dist/lib/work-context/reconcile.js +20 -1
  92. package/dist/utils/resident-package-preload.js +34 -4
  93. package/docs/anywhere-runtime.md +6 -0
  94. package/package.json +7 -7
@@ -0,0 +1,179 @@
1
+ import { delegatedMachineSessionFilePath, loadDelegatedMachineSession, loadMachineCreds, mintMachineTokens, } from "@indigoai-us/hq-cloud";
2
+ import { DEFAULT_COGNITO, cognitoSubjectFromToken, ensureCognitoIdToken, ensureCognitoToken, ensureMachineSessionTokens, isMachineCredsFileEnvSet, loadCachedTokens, refreshActivePersonTokens, resolveCognitoTokenSource, withMachineTokenStateDir, } from "../utils/cognito-session.js";
3
+ import { decodeJwtPayload } from "../utils/person-token-cache.js";
4
+ export class DeployIdentityError extends Error {
5
+ }
6
+ const PERSON = { tokenSource: "person", interactive: false };
7
+ const PERSON_REJECTED = "The deploy service rejected your sign-in. Run hq login and try again.";
8
+ const MACHINE_REJECTED = "The deploy service rejected the configured machine identity. Check its enrollment and company scope.";
9
+ const DELEGATED_REJECTED = "The deploy service rejected the delegated identity. Restart the Outpost job with a fresh session.";
10
+ function sameSubject(first, second, companion = false) {
11
+ const original = cognitoSubjectFromToken(first);
12
+ const next = cognitoSubjectFromToken(second);
13
+ const originalClaims = decodeJwtPayload(first);
14
+ const nextClaims = decodeJwtPayload(second);
15
+ const issuer = originalClaims?.iss;
16
+ if (original.sub === null || original.sub !== next.sub
17
+ || typeof issuer !== "string" || !issuer || issuer !== nextClaims?.iss) {
18
+ return false;
19
+ }
20
+ // The deploy producer uses the delegated operator when authorizing an Outpost.
21
+ if (originalClaims?.["custom:delegatedSub"] !== nextClaims?.["custom:delegatedSub"])
22
+ return false;
23
+ if (companion) {
24
+ return original.entityUid === next.entityUid || !original.entityUid || !next.entityUid;
25
+ }
26
+ return original.entityUid === next.entityUid
27
+ && originalClaims?.["custom:entityType"] === nextClaims?.["custom:entityType"];
28
+ }
29
+ function validateCredentials(credentials, companion) {
30
+ const issuer = decodeJwtPayload(credentials.bearer)?.iss;
31
+ if (!cognitoSubjectFromToken(credentials.bearer).sub || typeof issuer !== "string" || !issuer) {
32
+ throw new DeployIdentityError("Could not identify the HQ deploy session.");
33
+ }
34
+ if (companion && (!credentials.companion || !sameSubject(credentials.bearer, credentials.companion, true))) {
35
+ throw new DeployIdentityError("Deploy and HQ Pro sign-ins must belong to the same person. Run hq login and try again.");
36
+ }
37
+ return credentials;
38
+ }
39
+ function scopeHeaders(scope) {
40
+ if ((scope.company !== undefined) === (scope.personal === true)) {
41
+ throw new DeployIdentityError("Choose exactly one of --company <slug> or --personal.");
42
+ }
43
+ if (scope.company === undefined)
44
+ return { "X-HQ-Deploy-Scope": "personal" };
45
+ if (!/^[a-z0-9][a-z0-9-]{0,62}$/.test(scope.company)) {
46
+ throw new DeployIdentityError("Invalid company slug.");
47
+ }
48
+ return { "X-Org-Slug": scope.company };
49
+ }
50
+ function machineIdentityRequired() {
51
+ return [process.env.HQ_REQUIRE_MACHINE_IDENTITY, process.env.HQ_MACHINE_AUTH_REQUIRED]
52
+ .some((value) => ["1", "true", "yes"].includes(value?.trim().toLowerCase() ?? ""));
53
+ }
54
+ function personSource(includeCompanion) {
55
+ return {
56
+ rejected: PERSON_REJECTED,
57
+ async load() {
58
+ try {
59
+ const bearer = await ensureCognitoToken(PERSON);
60
+ return includeCompanion ? { bearer, companion: await ensureCognitoIdToken(PERSON) } : { bearer };
61
+ }
62
+ catch {
63
+ throw new DeployIdentityError("Could not get an HQ sign-in for hq-deploy. Run hq login and try again.");
64
+ }
65
+ },
66
+ async recover(current) {
67
+ if (delegatedMachineSessionFilePath() !== null || machineIdentityRequired() || isMachineCredsFileEnvSet()) {
68
+ throw new DeployIdentityError(PERSON_REJECTED);
69
+ }
70
+ const cached = loadCachedTokens();
71
+ if (!cached || !sameSubject(current.bearer, cached.accessToken))
72
+ throw new DeployIdentityError(PERSON_REJECTED);
73
+ const refreshed = await refreshActivePersonTokens(cached);
74
+ return {
75
+ bearer: refreshed.accessToken,
76
+ ...(includeCompanion ? { companion: refreshed.idToken } : {}),
77
+ };
78
+ },
79
+ };
80
+ }
81
+ function machineKey(creds) {
82
+ return JSON.stringify([
83
+ creds.username, creds.entityType, creds.entityUid, creds.clientId, creds.region,
84
+ creds.runtime, creds.hostKeyPath, creds.apiBaseUrl,
85
+ ]);
86
+ }
87
+ function machineSource() {
88
+ const creds = loadMachineCreds();
89
+ if (!creds || creds.delegated)
90
+ throw new DeployIdentityError(MACHINE_REJECTED);
91
+ const pinned = machineKey(creds);
92
+ function selectedMachine() {
93
+ const current = loadMachineCreds();
94
+ if (!current || current.delegated || machineKey(current) !== pinned) {
95
+ throw new DeployIdentityError(MACHINE_REJECTED);
96
+ }
97
+ return current;
98
+ }
99
+ return {
100
+ rejected: MACHINE_REJECTED,
101
+ async load() {
102
+ try {
103
+ const { idToken } = await ensureMachineSessionTokens();
104
+ selectedMachine();
105
+ if (creds.entityUid && cognitoSubjectFromToken(idToken).entityUid !== creds.entityUid) {
106
+ throw new DeployIdentityError(MACHINE_REJECTED);
107
+ }
108
+ return { bearer: idToken };
109
+ }
110
+ catch {
111
+ throw new DeployIdentityError(MACHINE_REJECTED);
112
+ }
113
+ },
114
+ async recover() {
115
+ const refreshed = await withMachineTokenStateDir(() => mintMachineTokens(DEFAULT_COGNITO, selectedMachine()));
116
+ selectedMachine();
117
+ return { bearer: refreshed.idToken };
118
+ },
119
+ };
120
+ }
121
+ function delegatedSource(path) {
122
+ async function load() {
123
+ const session = delegatedMachineSessionFilePath() === path ? loadDelegatedMachineSession() : null;
124
+ if (!session || session.expiresAt <= Date.now()
125
+ || cognitoSubjectFromToken(session.idToken).entityUid !== session.entityUid) {
126
+ throw new DeployIdentityError("The delegated Outpost session is missing, invalid, or expired. Restart the Outpost job.");
127
+ }
128
+ return { bearer: session.idToken };
129
+ }
130
+ return { load, recover: load, rejected: DELEGATED_REJECTED };
131
+ }
132
+ /** Pin the selected principal and scope for the lifetime of a deploy command. */
133
+ export async function openDeployIdentity(scope, options = {}) {
134
+ const headers = scopeHeaders(scope);
135
+ const delegation = delegatedMachineSessionFilePath();
136
+ const machine = delegation !== null || machineIdentityRequired() || isMachineCredsFileEnvSet()
137
+ || resolveCognitoTokenSource() === "machine";
138
+ if (machine && (options.personOnly || options.companion)) {
139
+ throw new DeployIdentityError("This deploy operation requires a person identity. Sign in as the authorized operator.");
140
+ }
141
+ if (machine && scope.personal) {
142
+ throw new DeployIdentityError("Personal deploy scope requires a person identity. Choose an authorized company scope for a machine deploy.");
143
+ }
144
+ const companion = options.companion === true;
145
+ const source = delegation !== null ? delegatedSource(delegation)
146
+ : machine ? machineSource() : personSource(companion);
147
+ let credentials = validateCredentials(await source.load(), companion);
148
+ let recovered = false;
149
+ return async (send, { recoverUnauthorized = true } = {}) => {
150
+ const request = (auth) => send(auth.bearer, {
151
+ ...headers,
152
+ ...(auth.companion ? { "X-HQ-Pro-Authorization": "Bearer " + auth.companion } : {}),
153
+ });
154
+ const prior = credentials;
155
+ const rejected = await request(prior);
156
+ if (rejected.status !== 401)
157
+ return rejected;
158
+ void rejected.body?.cancel().catch(() => undefined);
159
+ if (!recoverUnauthorized || recovered)
160
+ throw new DeployIdentityError(source.rejected);
161
+ recovered = true;
162
+ try {
163
+ const refreshed = validateCredentials(await source.recover(prior), companion);
164
+ if (refreshed.bearer === prior.bearer || !sameSubject(prior.bearer, refreshed.bearer)) {
165
+ throw new DeployIdentityError(source.rejected);
166
+ }
167
+ credentials = refreshed;
168
+ }
169
+ catch {
170
+ throw new DeployIdentityError(source.rejected);
171
+ }
172
+ const response = await request(credentials);
173
+ if (response.status !== 401)
174
+ return response;
175
+ void response.body?.cancel().catch(() => undefined);
176
+ throw new DeployIdentityError(source.rejected);
177
+ };
178
+ }
179
+ //# sourceMappingURL=deploy-identity.js.map
@@ -17,12 +17,15 @@ import * as fs from "node:fs";
17
17
  import * as path from "node:path";
18
18
  import { assertNotIntegrationSecretsPath, personDirName } from "./cursors.js";
19
19
  import { writeFileAtomic } from "./landing.js";
20
- import { CLAUDE_SIGNED_OUT_TEXT, CODEX_BOT_NEEDS_CLAUDE_TEXT, CODEX_SIGNED_OUT_TEXT } from "./signals-pass.js";
21
- const CODEX_BOT_NEEDS_CLAUDE_CODE = "claude-logged-out-codex-bot";
22
- const CLAUDE_SIGNED_OUT_CODE = "claude-logged-out";
23
- const CODEX_SIGNED_OUT_CODE = "codex-logged-out";
20
+ import { BOT_SIGNED_OUT_TEXT, BOT_API_KEY_TEXT, CLAUDE_SIGNED_OUT_TEXT, CODEX_BOT_NEEDS_CLAUDE_TEXT, CODEX_SIGNED_OUT_TEXT } from "./signals-pass.js";
21
+ import * as passFailure from "./signals-pass-failure.js";
22
+ // The codes live in a module with no imports, so the signals engine's adapters
23
+ // step can read them without loading this one. Typed here as pass codes.
24
+ const CODEX_BOT_NEEDS_CLAUDE_CODE = passFailure.CODEX_BOT_NEEDS_CLAUDE_CODE;
25
+ const CLAUDE_SIGNED_OUT_CODE = passFailure.CLAUDE_SIGNED_OUT_CODE;
26
+ const CODEX_SIGNED_OUT_CODE = passFailure.CODEX_SIGNED_OUT_CODE;
24
27
  /** Pass failures that mean the tool signals run on (Claude Code, or a Codex bot's Codex) is signed out or missing on this computer. */
25
- export const SIGNED_OUT_SIGNALS_CODES = new Set([CLAUDE_SIGNED_OUT_CODE, CODEX_BOT_NEEDS_CLAUDE_CODE, CODEX_SIGNED_OUT_CODE]);
28
+ export const SIGNED_OUT_SIGNALS_CODES = passFailure.SIGNED_OUT_SIGNALS_CODES;
26
29
  /** A failed ledger line whose pass found its tool signed out. */
27
30
  export function isSignedOutSignalsFailure(entry) {
28
31
  return entry.status === "failed" && entry.error !== null && SIGNED_OUT_SIGNALS_CODES.has(entry.error);
@@ -67,7 +70,11 @@ export function formatSignalsFailureAlert(entry, options = {}) {
67
70
  if (entry.error)
68
71
  lines.push(`Error: ${entry.error}`);
69
72
  // Name the tool the pass ran on, and how to fix it on this computer.
70
- if (entry.error === CODEX_BOT_NEEDS_CLAUDE_CODE)
73
+ if (entry.error === "bot-logged-out")
74
+ lines.push(BOT_SIGNED_OUT_TEXT);
75
+ else if (entry.error === "bot-api-key-login")
76
+ lines.push(BOT_API_KEY_TEXT);
77
+ else if (entry.error === CODEX_BOT_NEEDS_CLAUDE_CODE)
71
78
  lines.push(CODEX_BOT_NEEDS_CLAUDE_TEXT);
72
79
  else if (entry.error === CLAUDE_SIGNED_OUT_CODE)
73
80
  lines.push(CLAUDE_SIGNED_OUT_TEXT);
@@ -0,0 +1,89 @@
1
+ /**
2
+ * The signals pass on an HQ Fleet Executive bot's own login.
3
+ *
4
+ * An HQ Fleet bot answers chat with the login its runtime resolves for it: its
5
+ * own sign-in, or the person's Claude or ChatGPT subscription sign-in when its
6
+ * login is "default". `hq-fleet-local complete` (hq-fleet-local,
7
+ * single-turn completion) makes one locked-down model turn with exactly that
8
+ * login: prompt on stdin, no tools, memory, context files or session, one
9
+ * request, one JSON object out. It never uses an API key (`api_key_login`).
10
+ *
11
+ * So the pass needs no `claude auth login` of its own: if the bot can chat,
12
+ * signals can run. This is the default for a Claude or Codex Fleet Executive
13
+ * bot. The pass falls back to the `claude` CLI only when the helper is
14
+ * missing: the bot is not a Claude or Codex Fleet bot, its helper is not
15
+ * installed, or the installed helper release has no `complete` command yet.
16
+ *
17
+ * Policy: hq-signals-pass-codex-exec-narrow-exception point 3 (owner decision
18
+ * 2026-11-15, widened to this Fleet turn; owner instruction 2026-11-18 that the
19
+ * turn uses the bot's own login). The turn's lockdown lives in the helper; this
20
+ * module only names the bot and its profile, sends the prompt on stdin, and
21
+ * reads the one JSON line back. The reply text is model output built from the
22
+ * document, so it is parsed and never logged.
23
+ */
24
+ import { type BotConfig } from "../bot/config.js";
25
+ import type { BoundedRun, SignalsFailureClass, SignalsRuntimeId } from "./signals-pass.js";
26
+ /** The bot, profile and helper one Fleet signals turn runs with. */
27
+ export interface FleetCompleteTarget {
28
+ /** `<runtime>/bin/hq-fleet-local` of the bot's installed HQ Fleet runtime. */
29
+ helper: string;
30
+ /** The bot's HQ Fleet profile folder. */
31
+ profileDir: string;
32
+ /** The bot's agent id, as its profile.json names it. */
33
+ botId: string;
34
+ /** Ledger family for failure codes: `codex-*` for a Codex bot, `claude-*` otherwise. */
35
+ runtime: SignalsRuntimeId;
36
+ /** The bot's name, for messages. */
37
+ botName: string;
38
+ }
39
+ /** Largest prompt the helper accepts (its hard limit, 1 MiB). */
40
+ export declare const FLEET_COMPLETE_MAX_PROMPT_BYTES: number;
41
+ /** The error codes `hq-fleet-local complete` prints, each with a fixed message. */
42
+ export type FleetCompleteErrorCode = "invalid_request" | "too_large" | "invalid_profile" | "signed_out" | "api_key_login" | "rate_limited" | "out_of_usage" | "provider_error" | "empty_response" | "timeout" | "runtime_unavailable" | "internal_error";
43
+ export type FleetCompleteResult = {
44
+ kind: "text";
45
+ text: string;
46
+ } | {
47
+ kind: "error";
48
+ code: FleetCompleteErrorCode | "unknown";
49
+ timedOut?: boolean;
50
+ }
51
+ /** The helper cannot run a completion at all: fall back to the `claude` CLI. */
52
+ | {
53
+ kind: "missing";
54
+ reason: string;
55
+ };
56
+ /**
57
+ * The Fleet target for the bot in `dir`, or null when the pass should keep
58
+ * today's `claude` CLI path: no readable bot.json, not an HQ Fleet bot, or its
59
+ * profile, runtime or helper is not installed on this computer.
60
+ */
61
+ export declare function fleetCompleteTargetFor(config: Pick<BotConfig, "name" | "agentUid" | "runtime" | "engine"> | null, deps?: {
62
+ fleetHome?: string;
63
+ platform?: NodeJS.Platform;
64
+ }): FleetCompleteTarget | null;
65
+ /** fleetCompleteTargetFor for the bot folder `dir`, read when the pass asks. */
66
+ export declare function fleetCompleteTarget(dir: string): FleetCompleteTarget | null;
67
+ export type BoundedRunner = (command: string, args: readonly string[], options: {
68
+ timeoutMs: number;
69
+ input?: string;
70
+ cwd?: string;
71
+ env?: NodeJS.ProcessEnv;
72
+ }) => Promise<BoundedRun>;
73
+ /** argv for one completion. The prompt never goes on argv. */
74
+ export declare function fleetCompleteArgs(target: FleetCompleteTarget, timeoutMs: number): string[];
75
+ /**
76
+ * Run one completion. Reads only the helper's single JSON line; stderr is used
77
+ * only to tell an older helper (no `complete` command) from a failure.
78
+ */
79
+ export declare function runFleetComplete(target: FleetCompleteTarget, prompt: string, options: {
80
+ timeoutMs: number;
81
+ env: NodeJS.ProcessEnv;
82
+ cwd: string;
83
+ run: BoundedRunner;
84
+ }): Promise<FleetCompleteResult>;
85
+ /** The pass's failure class for a helper error code. */
86
+ export declare function fleetFailureClass(code: FleetCompleteErrorCode | "unknown"): SignalsFailureClass;
87
+ /** A log-safe message for a helper error: the code and the fix, never provider text. */
88
+ export declare function fleetFailureMessage(target: FleetCompleteTarget, code: FleetCompleteErrorCode | "unknown", detail: string): string;
89
+ //# sourceMappingURL=fleet-complete.d.ts.map
@@ -0,0 +1,157 @@
1
+ /**
2
+ * The signals pass on an HQ Fleet Executive bot's own login.
3
+ *
4
+ * An HQ Fleet bot answers chat with the login its runtime resolves for it: its
5
+ * own sign-in, or the person's Claude or ChatGPT subscription sign-in when its
6
+ * login is "default". `hq-fleet-local complete` (hq-fleet-local,
7
+ * single-turn completion) makes one locked-down model turn with exactly that
8
+ * login: prompt on stdin, no tools, memory, context files or session, one
9
+ * request, one JSON object out. It never uses an API key (`api_key_login`).
10
+ *
11
+ * So the pass needs no `claude auth login` of its own: if the bot can chat,
12
+ * signals can run. This is the default for a Claude or Codex Fleet Executive
13
+ * bot. The pass falls back to the `claude` CLI only when the helper is
14
+ * missing: the bot is not a Claude or Codex Fleet bot, its helper is not
15
+ * installed, or the installed helper release has no `complete` command yet.
16
+ *
17
+ * Policy: hq-signals-pass-codex-exec-narrow-exception point 3 (owner decision
18
+ * 2026-11-15, widened to this Fleet turn; owner instruction 2026-11-18 that the
19
+ * turn uses the bot's own login). The turn's lockdown lives in the helper; this
20
+ * module only names the bot and its profile, sends the prompt on stdin, and
21
+ * reads the one JSON line back. The reply text is model output built from the
22
+ * document, so it is parsed and never logged.
23
+ */
24
+ import { readBotConfig, HQ_FLEET_RUNTIME_ENGINE_ID } from "../bot/config.js";
25
+ import { fleetLocalHelper } from "../bot/fleet-local.js";
26
+ /** Largest prompt the helper accepts (its hard limit, 1 MiB). */
27
+ export const FLEET_COMPLETE_MAX_PROMPT_BYTES = 1024 * 1024;
28
+ /** The helper's own `--timeout` ceiling, in seconds. */
29
+ const FLEET_COMPLETE_MAX_TIMEOUT_S = 600;
30
+ /** Time the helper gets on top of its own timeout to start, kill its worker and answer. */
31
+ const FLEET_COMPLETE_GRACE_MS = 20_000;
32
+ /**
33
+ * The Fleet target for the bot in `dir`, or null when the pass should keep
34
+ * today's `claude` CLI path: no readable bot.json, not an HQ Fleet bot, or its
35
+ * profile, runtime or helper is not installed on this computer.
36
+ */
37
+ export function fleetCompleteTargetFor(config, deps = {}) {
38
+ if (!config || config.engine?.id !== HQ_FLEET_RUNTIME_ENGINE_ID)
39
+ return null;
40
+ // Claude and Codex bots only. `complete` answers a Grok profile (its
41
+ // chat_completions transport has no one-request guard there yet) with
42
+ // invalid_profile, so a Grok Executive bot keeps today's claude CLI path.
43
+ if (config.runtime !== "claude" && config.runtime !== "codex")
44
+ return null;
45
+ if (typeof config.agentUid !== "string" || !/^agt_[A-Za-z0-9_-]+$/.test(config.agentUid))
46
+ return null;
47
+ const installed = fleetLocalHelper(config.agentUid, deps);
48
+ if (!installed)
49
+ return null;
50
+ return {
51
+ helper: installed.helper,
52
+ profileDir: installed.profileDir,
53
+ botId: config.agentUid,
54
+ runtime: config.runtime,
55
+ botName: config.name,
56
+ };
57
+ }
58
+ /** fleetCompleteTargetFor for the bot folder `dir`, read when the pass asks. */
59
+ export function fleetCompleteTarget(dir) {
60
+ return fleetCompleteTargetFor(readBotConfig(dir));
61
+ }
62
+ /** argv for one completion. The prompt never goes on argv. */
63
+ export function fleetCompleteArgs(target, timeoutMs) {
64
+ const seconds = Math.min(FLEET_COMPLETE_MAX_TIMEOUT_S, Math.max(1, Math.ceil(timeoutMs / 1000)));
65
+ return [
66
+ "complete",
67
+ "--profile",
68
+ target.profileDir,
69
+ "--bot-id",
70
+ target.botId,
71
+ "--timeout",
72
+ String(seconds),
73
+ "--max-prompt-bytes",
74
+ String(FLEET_COMPLETE_MAX_PROMPT_BYTES),
75
+ ];
76
+ }
77
+ const ERROR_CODES = new Set([
78
+ "invalid_request",
79
+ "too_large",
80
+ "invalid_profile",
81
+ "signed_out",
82
+ "api_key_login",
83
+ "rate_limited",
84
+ "out_of_usage",
85
+ "provider_error",
86
+ "empty_response",
87
+ "timeout",
88
+ "runtime_unavailable",
89
+ "internal_error",
90
+ ]);
91
+ /** An argparse refusal of the `complete` subcommand: a helper release from before it. */
92
+ const NO_COMPLETE_COMMAND = /invalid choice: '?complete'?/;
93
+ /**
94
+ * Run one completion. Reads only the helper's single JSON line; stderr is used
95
+ * only to tell an older helper (no `complete` command) from a failure.
96
+ */
97
+ export async function runFleetComplete(target, prompt, options) {
98
+ const run = await options.run(target.helper, fleetCompleteArgs(target, options.timeoutMs), {
99
+ timeoutMs: options.timeoutMs + FLEET_COMPLETE_GRACE_MS,
100
+ input: prompt,
101
+ cwd: options.cwd,
102
+ env: options.env,
103
+ });
104
+ if (run.spawnError !== undefined)
105
+ return { kind: "missing", reason: "the hq-fleet-local helper could not start" };
106
+ if (run.timedOut)
107
+ return { kind: "error", code: "timeout", timedOut: true };
108
+ const lines = run.stdout.split("\n").filter((line) => line.trim().length > 0);
109
+ let payload;
110
+ if (lines.length === 1) {
111
+ try {
112
+ payload = JSON.parse(lines[0]);
113
+ }
114
+ catch {
115
+ payload = undefined;
116
+ }
117
+ }
118
+ if (payload === undefined) {
119
+ if (run.code === 2 && NO_COMPLETE_COMMAND.test(run.stderr)) {
120
+ return { kind: "missing", reason: "the installed hq-fleet-local has no complete command" };
121
+ }
122
+ return { kind: "error", code: "unknown" };
123
+ }
124
+ const value = payload;
125
+ if (run.code === 0 && typeof value.text === "string")
126
+ return { kind: "text", text: value.text };
127
+ const code = value.error && typeof value.error.code === "string" ? value.error.code : "";
128
+ return { kind: "error", code: ERROR_CODES.has(code) ? code : "unknown" };
129
+ }
130
+ /** The pass's failure class for a helper error code. */
131
+ export function fleetFailureClass(code) {
132
+ switch (code) {
133
+ case "signed_out":
134
+ case "api_key_login":
135
+ return "logged-out";
136
+ case "rate_limited":
137
+ case "out_of_usage":
138
+ return "usage-limit";
139
+ case "timeout":
140
+ return "timeout";
141
+ case "empty_response":
142
+ return "bad-output";
143
+ default:
144
+ return "provider-error";
145
+ }
146
+ }
147
+ /** A log-safe message for a helper error: the code and the fix, never provider text. */
148
+ export function fleetFailureMessage(target, code, detail) {
149
+ if (code === "signed_out") {
150
+ return `${target.botName}'s own model login is not usable (hq-fleet-local complete: signed_out). Signals run on the login ${target.botName} answers chat with; sign ${target.botName} in again (hq bot auth ${target.botName}) and the queued documents run on the next pass`;
151
+ }
152
+ if (code === "api_key_login") {
153
+ return `${target.botName} signs in with an API key, and signals run only on a subscription sign-in (hq-fleet-local complete: api_key_login). Sign ${target.botName} in with a Claude or ChatGPT subscription (hq bot auth ${target.botName})`;
154
+ }
155
+ return `hq-fleet-local complete failed (${code})${detail}`;
156
+ }
157
+ //# sourceMappingURL=fleet-complete.js.map
@@ -19,6 +19,7 @@ import { createVaultCursorStore } from "./cursors.js";
19
19
  import { cursorFilePath } from "./cursors.js";
20
20
  import { runHotChannelSync } from "./ledger.js";
21
21
  import { connectionSelection, meetingsSelection } from "./selection.js";
22
+ import { SIGNALS_PASS_FAILED_PREFIX } from "./signals-pass-failure.js";
22
23
  /** Token-scope providers served from the HQ vault: no external connection. */
23
24
  /**
24
25
  * The bare, lowercased provider id used to match a connection against a
@@ -340,7 +341,7 @@ export async function runOnDemandSync(input) {
340
341
  status: failed || passFailure !== null ? "failed" : "ok",
341
342
  landed: result?.landed ?? 0,
342
343
  duplicates: result?.duplicates ?? 0,
343
- message: result?.error?.message ?? (passFailure !== null ? `signals pass failed: ${passFailure}` : null),
344
+ message: result?.error?.message ?? (passFailure !== null ? `${SIGNALS_PASS_FAILED_PREFIX}${passFailure}` : null),
344
345
  };
345
346
  if (p.app)
346
347
  outcome.tokenLevel = tokenLevelOf(p.app);
@@ -17,6 +17,7 @@ export interface SignalsClaudeLogin {
17
17
  signedIn: boolean;
18
18
  checkedAt: string;
19
19
  source: SignalsClaudeLoginSource;
20
+ loginRoute?: "claude-cli";
20
21
  /** When the login was first seen signed out, while it still is. */
21
22
  signedOutSince?: string;
22
23
  }
@@ -27,7 +28,7 @@ export declare function readSignalsClaudeLogin(file?: string): SignalsClaudeLogi
27
28
  * Record what a pass just saw. Never throws: the record is a report, and a
28
29
  * failed write must not fail a signals run.
29
30
  */
30
- export declare function recordSignalsClaudeLogin(signedIn: boolean, now?: () => Date, file?: string): void;
31
+ export declare function recordSignalsClaudeLogin(signedIn: boolean | null, now?: () => Date, file?: string): void;
31
32
  /** One live `claude auth status` answer for `hq bot status`. */
32
33
  export interface ClaudeLoginNow {
33
34
  /** null when the check could not tell (`error` says why). */
@@ -49,5 +50,5 @@ export declare function checkClaudeLoginNow(options?: {
49
50
  now?: () => Date;
50
51
  }): Promise<ClaudeLoginNow>;
51
52
  /** The `onClaudeLogin` reporter `hq sources sync` and `hq bot` give the signals pass. */
52
- export declare function recordSignalsPassClaudeLogin(signedIn: boolean): void;
53
+ export declare function recordSignalsPassClaudeLogin(signedIn: boolean | null): void;
53
54
  //# sourceMappingURL=signals-claude-login.d.ts.map
@@ -31,6 +31,7 @@ export function readSignalsClaudeLogin(file = signalsClaudeLoginPath()) {
31
31
  signedIn: parsed.signedIn,
32
32
  checkedAt: parsed.checkedAt,
33
33
  source: "signals-pass",
34
+ ...(parsed.loginRoute === "claude-cli" ? { loginRoute: "claude-cli" } : {}),
34
35
  ...(!parsed.signedIn && typeof parsed.signedOutSince === "string" ? { signedOutSince: parsed.signedOutSince } : {}),
35
36
  };
36
37
  }
@@ -45,10 +46,14 @@ export function readSignalsClaudeLogin(file = signalsClaudeLoginPath()) {
45
46
  */
46
47
  export function recordSignalsClaudeLogin(signedIn, now = () => new Date(), file = signalsClaudeLoginPath()) {
47
48
  try {
49
+ if (signedIn === null) {
50
+ fs.rmSync(file, { force: true });
51
+ return;
52
+ }
48
53
  const at = now().toISOString();
49
54
  const previous = readSignalsClaudeLogin(file);
50
55
  const signedOutSince = signedIn ? undefined : previous && !previous.signedIn ? (previous.signedOutSince ?? previous.checkedAt) : at;
51
- const record = { v: 1, signedIn, checkedAt: at, source: "signals-pass", ...(signedOutSince ? { signedOutSince } : {}) };
56
+ const record = { loginRoute: "claude-cli", v: 1, signedIn, checkedAt: at, source: "signals-pass", ...(signedOutSince ? { signedOutSince } : {}) };
52
57
  fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
53
58
  const tmp = `${file}.${process.pid}.${Date.now()}.tmp`;
54
59
  fs.writeFileSync(tmp, `${JSON.stringify(record, null, 2)}\n`, { mode: 0o600 });
@@ -0,0 +1,29 @@
1
+ /**
2
+ * How a hot-channel sync reports a signals pass that failed after its adapter
3
+ * landed sources, and which pass failures mean the tool is signed out.
4
+ *
5
+ * This module imports nothing, on purpose. `signals/steps/adapters.ts` reads
6
+ * these values, and it must not statically import `alert.ts`, `run.ts` or
7
+ * `signals-pass.ts`: those reach `bot/jobs/hot-signal-sync.ts`, which imports
8
+ * the signals engine, which reads the adapters step while it loads.
9
+ */
10
+ /** Signals from hot-channel sync run on Claude Code, which is missing or signed out here. */
11
+ export declare const CLAUDE_SIGNED_OUT_CODE = "claude-logged-out";
12
+ /** The same, on a computer whose main bot runs on Codex and has not opted signals in to it. */
13
+ export declare const CODEX_BOT_NEEDS_CLAUDE_CODE = "claude-logged-out-codex-bot";
14
+ /** Signals run on the bot's Codex, which is missing or signed out here. */
15
+ export declare const CODEX_SIGNED_OUT_CODE = "codex-logged-out";
16
+ /** Pass failures that mean the tool signals run on (Claude Code, or a Codex bot's Codex) is signed out or missing on this computer. */
17
+ export declare const SIGNED_OUT_SIGNALS_CODES: ReadonlySet<string>;
18
+ /** How a `failed` sync outcome's message starts when the adapter landed its sources and the signals pass then failed. */
19
+ export declare const SIGNALS_PASS_FAILED_PREFIX = "signals pass failed: ";
20
+ /**
21
+ * The signals pass failure behind a `failed` sync outcome (a
22
+ * `SignalsPassErrorCode`, or another error's message), or null when the
23
+ * adapter itself failed or the outcome did not fail.
24
+ */
25
+ export declare function signalsPassFailureOf(outcome: {
26
+ status: string;
27
+ message: string | null;
28
+ }): string | null;
29
+ //# sourceMappingURL=signals-pass-failure.d.ts.map
@@ -0,0 +1,36 @@
1
+ /**
2
+ * How a hot-channel sync reports a signals pass that failed after its adapter
3
+ * landed sources, and which pass failures mean the tool is signed out.
4
+ *
5
+ * This module imports nothing, on purpose. `signals/steps/adapters.ts` reads
6
+ * these values, and it must not statically import `alert.ts`, `run.ts` or
7
+ * `signals-pass.ts`: those reach `bot/jobs/hot-signal-sync.ts`, which imports
8
+ * the signals engine, which reads the adapters step while it loads.
9
+ */
10
+ /** Signals from hot-channel sync run on Claude Code, which is missing or signed out here. */
11
+ export const CLAUDE_SIGNED_OUT_CODE = "claude-logged-out";
12
+ /** The same, on a computer whose main bot runs on Codex and has not opted signals in to it. */
13
+ export const CODEX_BOT_NEEDS_CLAUDE_CODE = "claude-logged-out-codex-bot";
14
+ /** Signals run on the bot's Codex, which is missing or signed out here. */
15
+ export const CODEX_SIGNED_OUT_CODE = "codex-logged-out";
16
+ /** Pass failures that mean the tool signals run on (Claude Code, or a Codex bot's Codex) is signed out or missing on this computer. */
17
+ export const SIGNED_OUT_SIGNALS_CODES = new Set([
18
+ "bot-logged-out",
19
+ "bot-api-key-login",
20
+ CLAUDE_SIGNED_OUT_CODE,
21
+ CODEX_BOT_NEEDS_CLAUDE_CODE,
22
+ CODEX_SIGNED_OUT_CODE,
23
+ ]);
24
+ /** How a `failed` sync outcome's message starts when the adapter landed its sources and the signals pass then failed. */
25
+ export const SIGNALS_PASS_FAILED_PREFIX = "signals pass failed: ";
26
+ /**
27
+ * The signals pass failure behind a `failed` sync outcome (a
28
+ * `SignalsPassErrorCode`, or another error's message), or null when the
29
+ * adapter itself failed or the outcome did not fail.
30
+ */
31
+ export function signalsPassFailureOf(outcome) {
32
+ if (outcome.status !== "failed" || !outcome.message?.startsWith(SIGNALS_PASS_FAILED_PREFIX))
33
+ return null;
34
+ return outcome.message.slice(SIGNALS_PASS_FAILED_PREFIX.length);
35
+ }
36
+ //# sourceMappingURL=signals-pass-failure.js.map