@indigoai-us/hq-cli 5.345.220 → 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 (138) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/dist/command-catalog.generated.d.ts +144 -2
  3. package/dist/command-catalog.generated.js +175 -2
  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 +39 -2
  8. package/dist/commands/bot.js +140 -11
  9. package/dist/commands/core-stop-autosave.d.ts +21 -0
  10. package/dist/commands/core-stop-autosave.js +300 -0
  11. package/dist/commands/core.js +2 -0
  12. package/dist/commands/daemon.d.ts +5 -0
  13. package/dist/commands/daemon.js +31 -7
  14. package/dist/commands/doctor-usage.d.ts +5 -0
  15. package/dist/commands/doctor-usage.js +25 -0
  16. package/dist/commands/env.d.ts +49 -4
  17. package/dist/commands/env.js +355 -5
  18. package/dist/commands/lanes-shared.d.ts +3 -0
  19. package/dist/commands/lanes.d.ts +3 -0
  20. package/dist/commands/lanes.js +87 -3
  21. package/dist/commands/sources.js +3 -3
  22. package/dist/commands/sync-core.d.ts +1 -0
  23. package/dist/commands/sync-core.js +77 -3
  24. package/dist/commands/whoami.js +96 -80
  25. package/dist/lib/bot/config.d.ts +17 -0
  26. package/dist/lib/bot/config.js +13 -0
  27. package/dist/lib/bot/fleet-cron.js +24 -2
  28. package/dist/lib/bot/fleet-local.d.ts +30 -2
  29. package/dist/lib/bot/fleet-local.js +60 -1
  30. package/dist/lib/bot/grok-login-scope.d.ts +36 -0
  31. package/dist/lib/bot/grok-login-scope.js +93 -0
  32. package/dist/lib/bot/legacy-provider-login.d.ts +32 -9
  33. package/dist/lib/bot/legacy-provider-login.js +28 -22
  34. package/dist/lib/bot/runtime-sign-in-check.js +6 -1
  35. package/dist/lib/bot/runtime-sign-in.d.ts +2 -0
  36. package/dist/lib/core-utils/sentry-report.js +2 -0
  37. package/dist/lib/daemon/machine-checks.d.ts +22 -1
  38. package/dist/lib/daemon/machine-checks.js +54 -12
  39. package/dist/lib/daemon/run.js +66 -8
  40. package/dist/lib/daemon/stop-autosave-lock.d.ts +19 -0
  41. package/dist/lib/daemon/stop-autosave-lock.js +166 -0
  42. package/dist/lib/daemon/stop-autosave.d.ts +28 -0
  43. package/dist/lib/daemon/stop-autosave.js +111 -0
  44. package/dist/lib/daemon/stop-diagnostics.d.ts +11 -0
  45. package/dist/lib/daemon/stop-diagnostics.js +136 -0
  46. package/dist/lib/daemon/stop-job-executor.d.ts +19 -0
  47. package/dist/lib/daemon/stop-job-executor.js +126 -0
  48. package/dist/lib/daemon/stop-jobs.d.ts +93 -0
  49. package/dist/lib/daemon/stop-jobs.js +599 -0
  50. package/dist/lib/doctor/checks/fleet-hook-core.js +1 -1
  51. package/dist/lib/doctor/checks/host-core.js +1 -1
  52. package/dist/lib/environment/access-probes.d.ts +234 -0
  53. package/dist/lib/environment/access-probes.js +918 -0
  54. package/dist/lib/environment/profile.d.ts +15 -2
  55. package/dist/lib/environment/profile.js +55 -20
  56. package/dist/lib/environment/rfc3339.d.ts +8 -0
  57. package/dist/lib/environment/rfc3339.js +26 -0
  58. package/dist/lib/environment/work-requirements.d.ts +169 -0
  59. package/dist/lib/environment/work-requirements.js +389 -0
  60. package/dist/lib/hook-engine/coverage.d.ts +137 -7
  61. package/dist/lib/hook-engine/coverage.js +1424 -4
  62. package/dist/lib/hook-engine/fleet-registration.js +2 -2
  63. package/dist/lib/hook-engine/git-stop-config.json +513 -0
  64. package/dist/lib/hook-engine/native-stop-compatibility.json +311 -0
  65. package/dist/lib/hook-engine/reconcile.js +2 -2
  66. package/dist/lib/hot-channels/alert.d.ts +2 -2
  67. package/dist/lib/hot-channels/alert.js +8 -5
  68. package/dist/lib/hot-channels/signals-pass.d.ts +126 -17
  69. package/dist/lib/hot-channels/signals-pass.js +296 -17
  70. package/dist/lib/hot-channels/signals-runtime.d.ts +30 -0
  71. package/dist/lib/hot-channels/signals-runtime.js +82 -0
  72. package/dist/lib/install/hook-target.js +1 -1
  73. package/dist/lib/lanes/host-capacity.d.ts +26 -2
  74. package/dist/lib/lanes/host-capacity.js +17 -2
  75. package/dist/lib/lanes/host-compute.d.ts +90 -0
  76. package/dist/lib/lanes/host-compute.js +185 -0
  77. package/dist/lib/lanes/index.d.ts +2 -0
  78. package/dist/lib/lanes/index.js +1 -0
  79. package/dist/lib/lanes/reconcile.js +22 -1
  80. package/dist/lib/lanes/resource-usage.d.ts +155 -0
  81. package/dist/lib/lanes/resource-usage.js +589 -0
  82. package/dist/lib/lanes/run-size.d.ts +46 -0
  83. package/dist/lib/lanes/run-size.js +197 -0
  84. package/dist/lib/lanes/store.js +27 -0
  85. package/dist/lib/lanes/throttle.d.ts +36 -1
  86. package/dist/lib/lanes/throttle.js +47 -10
  87. package/dist/lib/lanes/types.d.ts +40 -0
  88. package/dist/lib/lanes/types.js +2 -2
  89. package/dist/lib/lanes/watcher.js +13 -4
  90. package/dist/lib/lanes/worker-process.d.ts +25 -2
  91. package/dist/lib/lanes/worker-process.js +71 -19
  92. package/dist/lib/placement/match.d.ts +192 -0
  93. package/dist/lib/placement/match.js +667 -0
  94. package/dist/lib/safe-store.d.ts +14 -0
  95. package/dist/lib/safe-store.js +77 -4
  96. package/dist/lib/search-index/index.d.ts +88 -4
  97. package/dist/lib/search-index/index.js +288 -24
  98. package/dist/lib/search-index/max-doc-bytes.d.ts +17 -6
  99. package/dist/lib/search-index/max-doc-bytes.js +48 -23
  100. package/dist/lib/signals/codex-lockdown.d.ts +79 -0
  101. package/dist/lib/signals/codex-lockdown.js +271 -0
  102. package/dist/lib/signals/codex-login.d.ts +37 -0
  103. package/dist/lib/signals/codex-login.js +83 -0
  104. package/dist/lib/signals/engine.d.ts +27 -0
  105. package/dist/lib/signals/engine.js +70 -0
  106. package/dist/lib/signals/reply.js +22 -1
  107. package/dist/lib/signals/run-record.js +6 -1
  108. package/dist/lib/signals/settings.d.ts +5 -0
  109. package/dist/lib/signals/settings.js +2 -0
  110. package/dist/lib/signals/steps/extract.d.ts +85 -9
  111. package/dist/lib/signals/steps/extract.js +317 -68
  112. package/dist/lib/signals/steps/types.d.ts +2 -0
  113. package/dist/lib/sync-core/engine-home.d.ts +35 -1
  114. package/dist/lib/sync-core/engine-home.js +119 -16
  115. package/dist/lib/sync-core/rollout-state.d.ts +2 -1
  116. package/dist/lib/sync-core/rollout-state.js +5 -2
  117. package/dist/lib/sync-core/vault-uid.d.ts +2 -0
  118. package/dist/lib/sync-core/vault-uid.js +4 -0
  119. package/dist/schemas/hq-work-requirements.v1.schema.json +145 -0
  120. package/dist/utils/auth-session-check.d.ts +16 -0
  121. package/dist/utils/auth-session-check.js +16 -0
  122. package/dist/utils/client-health-contract.d.ts +6 -0
  123. package/dist/utils/client-health-contract.js +13 -0
  124. package/dist/utils/client-health.d.ts +7 -0
  125. package/dist/utils/client-health.js +22 -1
  126. package/dist/utils/command-usage.d.ts +40 -0
  127. package/dist/utils/command-usage.js +61 -0
  128. package/dist/utils/duplicate-command-usage.d.ts +72 -0
  129. package/dist/utils/duplicate-command-usage.js +125 -0
  130. package/dist/utils/host-registration.js +2 -1
  131. package/dist/utils/resident-package-preload.js +4 -0
  132. package/dist/utils/sentry-fingerprint.js +9 -0
  133. package/dist/utils/windows-bash.d.ts +2 -0
  134. package/dist/utils/windows-bash.js +2 -1
  135. package/package.json +9 -8
  136. package/scripts/bench-core-compare.mjs +313 -0
  137. package/scripts/bench-core.mjs +399 -12
  138. package/scripts/check-function-manifest.mjs +116 -3
@@ -341,9 +341,27 @@ def classify(out, err, code):
341
341
  text = ANSI.sub('', (err or '') + '\n' + (out or ''))
342
342
  if re.search(r"HQ session has expired|not signed in to HQ|Sign in to HQ first|run .hq login", text, re.I):
343
343
  return 'you are signed out of HQ', FIXES['hq_signed_out']
344
- # Before the plain claude checks: a Codex main bot is told why Claude Code is needed.
344
+ # Before the plain claude checks: a Codex main bot whose signals still run
345
+ # on Claude Code is pointed at running them on its own Codex.
345
346
  if re.search(r'claude-logged-out-codex-bot', text, re.I):
346
- return "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", FIXES['codex_bot_needs_claude']
347
+ return "your main bot runs on Codex, but signals from hot-channel sync run on Claude Code, which is not installed or not signed in on this computer", FIXES['codex_bot_needs_claude']
348
+ # A Codex bot that runs signals on its own Codex (signalsRuntime "bot").
349
+ if re.search(r'codex could not start:.*\bENOENT\b|spawn codex ENOENT', text, re.I):
350
+ return 'Codex is not installed on this computer', FIXES['codex_signed_out']
351
+ if re.search(r'codex-logged-out|codex (reported it )?is not logged in|codex could not start|codex login is not usable', text, re.I):
352
+ return 'Codex is signed out on this computer', FIXES['codex_signed_out']
353
+ codex_timed_out = re.search(r'codex timed out after \d+ ?ms on (\S+)', text, re.I)
354
+ if codex_timed_out or re.search(r'codex-timeout', text, re.I):
355
+ key = codex_timed_out.group(1).rstrip('.,;:)\'"') if codex_timed_out else ''
356
+ if re.match(r'^sources/[A-Za-z0-9._/-]+\.md$', key) and '..' not in key:
357
+ return 'Codex ran out of time on one document', FIXES['claude_timeout_key'].replace('KEY', key)
358
+ return 'Codex ran out of time on one document', FIXES['claude_timeout']
359
+ if re.search(r'codex-usage-limit|codex is out of usage', text, re.I):
360
+ return 'Codex is out of usage on this account', FIXES['codex_usage_limit']
361
+ if re.search(r'codex-bad-output', text, re.I):
362
+ return 'Codex gave replies the signals step could not read', FIXES['claude_bad_output']
363
+ if re.search(r'codex-provider-error', text, re.I):
364
+ return 'Codex reported an error', FIXES['claude_provider_error']
347
365
  if re.search(r'claude could not start:.*\bENOENT\b|spawn claude ENOENT', text, re.I):
348
366
  return 'Claude Code is not installed on this computer', FIXES['claude_missing']
349
367
  if re.search(r'claude-logged-out|claude (reported it )?is not logged in|claude could not start', text, re.I):
@@ -443,7 +461,11 @@ export function renderFleetHotSignalSyncScript(input) {
443
461
  // The desktop app first (Settings → AI tools lists Claude Code with a
444
462
  // "Connect Claude" or "Install Claude" button), the terminal as the fallback.
445
463
  claude_signed_out: claudeSignInFix,
464
+ // A Fleet bot's signals run on Claude Code (an HQ Fleet Runtime bot cannot lend its Codex login), so the fix is the Claude sign-in.
446
465
  codex_bot_needs_claude: claudeSignInFix,
466
+ // Settings → AI tools lists Codex with a "Connect Codex" or "Install Codex" button.
467
+ codex_signed_out: `open HQ, go to Settings → AI tools, and use the Codex button there (Connect Codex, or Install Codex if it is not installed yet). Or run \`${signInCommand("codex")}\` in a terminal on this computer.`,
468
+ codex_usage_limit: `wait for your Codex usage to reset, then run \`hq sources signals --company ${input.company} --since DATE\` to build the missing signals.`,
447
469
  claude_missing: `install Claude Code (\`npm install -g @anthropic-ai/claude-code\`), then run \`${signInCommand("claude")}\`.`,
448
470
  claude_timeout_key: `run \`hq sources signals --company ${input.company} --key KEY\` to retry that document.`,
449
471
  claude_timeout: "the next run retries the document.",
@@ -1,5 +1,6 @@
1
1
  import { type BotEngineMetadata, type BotRuntimeId } from "./config.js";
2
2
  import type { BotMachineCreds } from "./creds.js";
3
+ import { type GrokSiblingLogin } from "./grok-login-scope.js";
3
4
  import { type FleetPython } from "./fleet-python.js";
4
5
  import { vaultApiFetch } from "../../utils/vault-api.js";
5
6
  import type { LocalBotPromotionRuntime } from "./promote.js";
@@ -376,7 +377,7 @@ export declare const spawnFleetAuth: FleetAuthSpawn;
376
377
  export declare const FLEET_GROK_CLI_IMPORT_MIN_VERSION = "0.4.31-local.13";
377
378
  export declare function fleetReleaseImportsGrokCli(version: string | null | undefined): boolean;
378
379
  export declare function fleetLocalProfileEngineVersion(agentUid: string, deps?: Pick<FleetLocalControlDeps, "fleetHome">): string | null;
379
- export declare function authenticateFleetLocalBot(input: FleetLocalAuthInput, deps?: FleetLocalControlDeps & {
380
+ export declare function authenticateFleetLocalBot(input: FleetLocalAuthInput, deps?: XaiOauthLoginGateDeps & {
380
381
  control?: FleetLocalStartControl;
381
382
  spawnAuth?: FleetAuthSpawn;
382
383
  writeStderr?: (text: string) => void;
@@ -481,6 +482,33 @@ export type FleetLocalAsyncRun = (executable: string, args: string[], options: R
481
482
  export declare function fleetLocalProviderAuthStatusAsync(agentUid: string, provider: string, deps?: FleetLocalControlDeps & {
482
483
  runAsync?: FleetLocalAsyncRun;
483
484
  }): Promise<FleetLocalProviderAuthStatus | null>;
485
+ /** The runtime provider id of the helper's Grok account (OAuth) sign-in. */
486
+ export declare const XAI_OAUTH_RUNTIME_PROVIDER = "xai-oauth";
487
+ /**
488
+ * Whether `hq bot auth --provider <provider>` runs the helper's Grok account
489
+ * sign-in: the name resolves to the xAI OAuth preset (grok, xai, xai-oauth,
490
+ * in any case) and no API key is given. Decided on the resolved runtime
491
+ * provider, never on the name typed.
492
+ */
493
+ export declare function fleetAuthUsesXaiOauthLogin(provider: string, apiKey?: string): boolean;
494
+ export interface XaiOauthLoginGateDeps extends FleetLocalControlDeps {
495
+ /** Where the bot folders are (default: the bots root). */
496
+ botsRoot?: string;
497
+ /** The helper's word on a bot's Grok sign-in (default: the helper is asked). */
498
+ grokStatus?: (agentUid: string) => FleetLocalProviderAuthStatus | null;
499
+ }
500
+ /**
501
+ * Asked right before every Grok account sign-in the helper runs for a bot:
502
+ * may the helper copy from every bot it could copy from? The other Fleet
503
+ * profiles are scanned now, never from a cache, and the bot's company scope
504
+ * is read from its own bot.json. `blocked` means no.
505
+ */
506
+ export declare function xaiOauthLoginHeldBack(agentUid: string, deps?: XaiOauthLoginGateDeps): GrokSiblingLogin;
507
+ /** What to tell the owner when a Grok account sign-in is held back, and how to clear it. */
508
+ export declare function xaiOauthLoginRefusal(held: GrokSiblingLogin, opts?: {
509
+ name?: string;
510
+ fleetHome?: string;
511
+ }): string;
484
512
  /**
485
513
  * Sign a bot in from a login already on this computer, without a browser:
486
514
  * the helper imports the Codex CLI login (CODEX_HOME, else ~/.codex) or
@@ -488,7 +516,7 @@ export declare function fleetLocalProviderAuthStatusAsync(agentUid: string, prov
488
516
  * environment (a bot's own Codex home). The profile's provider is already
489
517
  * the runtime's preset from the bootstrap; this re-renders and checks it.
490
518
  */
491
- export declare function importFleetLocalProviderLogin(agentUid: string, runtime: "codex" | "grok", deps?: FleetLocalControlDeps, opts?: {
519
+ export declare function importFleetLocalProviderLogin(agentUid: string, runtime: "codex" | "grok", deps?: XaiOauthLoginGateDeps, opts?: {
492
520
  env?: Record<string, string>;
493
521
  }): {
494
522
  runtimeProvider: string;
@@ -8,6 +8,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
8
8
  import { HQ_FLEET_RUNTIME_ENGINE_ID, } from "./config.js";
9
9
  import { withBotLock } from "./lock.js";
10
10
  import { downloadFleetFileFromSources, fileSha256 } from "./fleet-download.js";
11
+ import { grokLoginFromScan, localBotLoginScopes } from "./grok-login-scope.js";
11
12
  import { ensureFleetPython, fleetUvEnv } from "./fleet-python.js";
12
13
  import semver from "semver";
13
14
  import { CLI_VERSION } from "../../cli-version.js";
@@ -1599,6 +1600,9 @@ export async function authenticateFleetLocalBot(input, deps = {}) {
1599
1600
  if (!provider.oauth && !input.apiKey) {
1600
1601
  throw expectedError(`Pass --api-key and provide ${provider.runtimeProvider} credentials on stdin.`);
1601
1602
  }
1603
+ // Every caller and every spelling of the provider passes here on its way to the helper's `auth login`.
1604
+ if (provider.oauth && !input.apiKey && provider.runtimeProvider === XAI_OAUTH_RUNTIME_PROVIDER)
1605
+ assertXaiOauthLoginAllowed(input.agentUid, deps);
1602
1606
  const run = deps.run ?? execFileSync;
1603
1607
  const files = fleetLocalExecutables(input.agentUid, deps);
1604
1608
  const authArgs = provider.oauth && !input.apiKey
@@ -2208,6 +2212,58 @@ export async function fleetLocalProviderAuthStatusAsync(agentUid, provider, deps
2208
2212
  return null;
2209
2213
  }
2210
2214
  }
2215
+ /** The runtime provider id of the helper's Grok account (OAuth) sign-in. */
2216
+ export const XAI_OAUTH_RUNTIME_PROVIDER = "xai-oauth";
2217
+ /**
2218
+ * Whether `hq bot auth --provider <provider>` runs the helper's Grok account
2219
+ * sign-in: the name resolves to the xAI OAuth preset (grok, xai, xai-oauth,
2220
+ * in any case) and no API key is given. Decided on the resolved runtime
2221
+ * provider, never on the name typed.
2222
+ */
2223
+ export function fleetAuthUsesXaiOauthLogin(provider, apiKey) {
2224
+ if (apiKey)
2225
+ return false;
2226
+ const known = providerProfiles[provider.trim().toLowerCase()];
2227
+ return known !== undefined && known.oauth && known.runtimeProvider === XAI_OAUTH_RUNTIME_PROVIDER;
2228
+ }
2229
+ /**
2230
+ * Asked right before every Grok account sign-in the helper runs for a bot:
2231
+ * may the helper copy from every bot it could copy from? The other Fleet
2232
+ * profiles are scanned now, never from a cache, and the bot's company scope
2233
+ * is read from its own bot.json. `blocked` means no.
2234
+ */
2235
+ export function xaiOauthLoginHeldBack(agentUid, deps = {}) {
2236
+ const others = listFleetLocalProfiles(deps).filter((profile) => profile.agentUid.toLowerCase() !== agentUid.toLowerCase());
2237
+ if (others.length === 0)
2238
+ return grokLoginFromScan({ holders: [], uids: [], unanswered: [] }, agentUid, null, () => null);
2239
+ const status = deps.grokStatus ?? ((uid) => fleetLocalProviderAuthStatus(uid, XAI_OAUTH_RUNTIME_PROVIDER, deps));
2240
+ const holders = [];
2241
+ const unanswered = [];
2242
+ for (const profile of others) {
2243
+ const found = status(profile.agentUid);
2244
+ if (found === null)
2245
+ unanswered.push(profile.agentUid);
2246
+ else if (found.authenticated && found.authType === "oauth")
2247
+ holders.push(profile.agentUid);
2248
+ }
2249
+ const scopeOf = localBotLoginScopes(deps.botsRoot);
2250
+ return grokLoginFromScan({ holders, uids: others.map((profile) => profile.agentUid), unanswered }, agentUid, scopeOf(agentUid), scopeOf);
2251
+ }
2252
+ /** What to tell the owner when a Grok account sign-in is held back, and how to clear it. */
2253
+ export function xaiOauthLoginRefusal(held, opts = {}) {
2254
+ const bot = opts.name ?? "<name>";
2255
+ const profiles = path.join(opts.fleetHome ?? fleetHome(), "profiles");
2256
+ return (`${opts.name ? `${opts.name} was not signed in to Grok` : "No Grok account sign-in was started"}: ${held.detail}. ` +
2257
+ "The HQ Fleet helper would copy that bot's Grok sign-in instead of asking for a new one. " +
2258
+ `A bot counts as a different or unknown company when it is a bot of another company, a personal bot (for a company bot), or a profile folder under ${profiles} left behind by a bot that is no longer in hq bot list. ` +
2259
+ "To clear it, remove the leftover profile folder, or remove the other bot with hq bot rm. " +
2260
+ `Or sign in with an xAI API key: hq bot auth ${bot} --provider grok --api-key reads the key from stdin (paste the key and press Ctrl-D, or pipe it in).`);
2261
+ }
2262
+ function assertXaiOauthLoginAllowed(agentUid, deps) {
2263
+ const held = xaiOauthLoginHeldBack(agentUid, deps);
2264
+ if (held.blocked)
2265
+ throw expectedError(xaiOauthLoginRefusal(held, deps.fleetHome ? { fleetHome: deps.fleetHome } : {}));
2266
+ }
2211
2267
  /** The helper waits this long for a sign-in import before the move counts as failed. */
2212
2268
  const FLEET_PROVIDER_IMPORT_TIMEOUT_MS = 60_000;
2213
2269
  /**
@@ -2218,7 +2274,10 @@ const FLEET_PROVIDER_IMPORT_TIMEOUT_MS = 60_000;
2218
2274
  * the runtime's preset from the bootstrap; this re-renders and checks it.
2219
2275
  */
2220
2276
  export function importFleetLocalProviderLogin(agentUid, runtime, deps = {}, opts = {}) {
2221
- const provider = runtime === "grok" ? "xai-oauth" : "openai-codex";
2277
+ const provider = runtime === "grok" ? XAI_OAUTH_RUNTIME_PROVIDER : "openai-codex";
2278
+ // Scanned again here, right before the helper copies: the earlier check may be minutes old.
2279
+ if (provider === XAI_OAUTH_RUNTIME_PROVIDER)
2280
+ assertXaiOauthLoginAllowed(agentUid, deps);
2222
2281
  const run = deps.run ?? execFileSync;
2223
2282
  const files = fleetLocalExecutables(agentUid, deps);
2224
2283
  const env = opts.env ? { ...process.env, ...opts.env } : undefined;
@@ -0,0 +1,36 @@
1
+ import { type BotConfig, type BotKind } from "./config.js";
2
+ import type { LegacyProviderLogin } from "./legacy-convert.js";
3
+ /**
4
+ * Whose Grok sign-in a bot may share: "personal" for a personal bot (it acts
5
+ * as its owner), "company:<slugs>" for a company bot. Null when a company
6
+ * bot names no company, which matches nothing.
7
+ */
8
+ export type BotLoginScope = string | null;
9
+ export declare function newBotLoginScope(kind: BotKind, companies: readonly string[]): BotLoginScope;
10
+ export declare function botLoginScope(config: Pick<BotConfig, "kind" | "companies" | "workerId">): BotLoginScope;
11
+ /**
12
+ * The scope of each bot on this computer, by agent id, read from the bot
13
+ * folders' bot.json. An id with no readable bot.json, or one that two folders
14
+ * give different scopes, has no known scope.
15
+ */
16
+ export declare function localBotLoginScopes(root?: string): (agentUid: string) => BotLoginScope;
17
+ /**
18
+ * A sibling-login answer. `blocked`: another bot here holds, or may hold, a
19
+ * Grok sign-in this bot may not share. The helper copies the first sign-in it
20
+ * finds, so no Grok sign-in may be imported for this bot while that is so.
21
+ */
22
+ export interface GrokSiblingLogin extends LegacyProviderLogin {
23
+ blocked?: true;
24
+ }
25
+ /**
26
+ * The answer for one bot from a scan of the others. `holders` hold a Grok
27
+ * OAuth login, `unanswered` are bots the helper could not answer for, `uids`
28
+ * is every bot with a Fleet profile. Reusable only when another bot holds a
29
+ * login and every other bot that holds one, or may hold one, has `scope`.
30
+ */
31
+ export declare function grokLoginFromScan(scan: {
32
+ holders: string[];
33
+ uids: string[];
34
+ unanswered: string[];
35
+ }, exclude: string, scope: BotLoginScope, scopeOf: (agentUid: string) => BotLoginScope): GrokSiblingLogin;
36
+ //# sourceMappingURL=grok-login-scope.d.ts.map
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Which bots may share a Grok sign-in on this computer.
3
+ *
4
+ * The HQ Fleet helper (0.4.31) copies the first other bot's Grok OAuth login
5
+ * it finds, in profile-folder order, before it reads the Grok CLI login or
6
+ * asks for a new sign-in, and it knows nothing of companies. hq-cli cannot
7
+ * choose the bot it copies from, so the rule here is about every bot it
8
+ * could copy from. This module reads only bot.json files; the callers hand
9
+ * it the helper's yes or no per bot.
10
+ */
11
+ import * as fs from "node:fs";
12
+ import * as path from "node:path";
13
+ import { effectiveBotCompanies, effectiveBotKind, readBotConfig } from "./config.js";
14
+ import { botsRoot } from "./paths.js";
15
+ export function newBotLoginScope(kind, companies) {
16
+ if (kind === "personal")
17
+ return "personal";
18
+ const slugs = [...new Set(companies.map((slug) => slug.trim()).filter(Boolean))].sort();
19
+ return slugs.length ? `company:${slugs.join(",")}` : null;
20
+ }
21
+ export function botLoginScope(config) {
22
+ return newBotLoginScope(effectiveBotKind(config), effectiveBotCompanies(config));
23
+ }
24
+ /**
25
+ * The scope of each bot on this computer, by agent id, read from the bot
26
+ * folders' bot.json. An id with no readable bot.json, or one that two folders
27
+ * give different scopes, has no known scope.
28
+ */
29
+ export function localBotLoginScopes(root = botsRoot()) {
30
+ const scopes = new Map();
31
+ let entries = [];
32
+ try {
33
+ entries = fs.readdirSync(root, { withFileTypes: true });
34
+ }
35
+ catch {
36
+ /* no bots here */
37
+ }
38
+ for (const entry of entries) {
39
+ if (!entry.isDirectory())
40
+ continue;
41
+ // readBotConfig answers null for a folder with no readable bot.json.
42
+ const config = readBotConfig(path.join(root, entry.name));
43
+ if (!config)
44
+ continue;
45
+ const uid = config.agentUid.toLowerCase();
46
+ const scope = botLoginScope(config);
47
+ scopes.set(uid, scopes.has(uid) && scopes.get(uid) !== scope ? null : scope);
48
+ }
49
+ return (agentUid) => scopes.get(agentUid.toLowerCase()) ?? null;
50
+ }
51
+ /**
52
+ * The answer for one bot from a scan of the others. `holders` hold a Grok
53
+ * OAuth login, `unanswered` are bots the helper could not answer for, `uids`
54
+ * is every bot with a Fleet profile. Reusable only when another bot holds a
55
+ * login and every other bot that holds one, or may hold one, has `scope`.
56
+ */
57
+ export function grokLoginFromScan(scan, exclude, scope, scopeOf) {
58
+ const other = (agentUid) => agentUid.toLowerCase() !== exclude.toLowerCase();
59
+ // Fail closed: a missing scope on either side never matches.
60
+ const outside = (agentUid) => scope === null || scopeOf(agentUid) !== scope;
61
+ const holders = scan.holders.filter(other);
62
+ const others = scan.uids.filter(other);
63
+ const unanswered = scan.unanswered.filter(other);
64
+ const outsideHolders = holders.filter(outside);
65
+ if (outsideHolders.length) {
66
+ return {
67
+ readable: false,
68
+ blocked: true,
69
+ detail: `${outsideHolders.length} other HQ Fleet bot(s) on this computer are signed in to Grok for a different or unknown company, and a bot shares a Grok sign-in only within its own company`,
70
+ };
71
+ }
72
+ const allUnanswered = `the HQ Fleet helper could not say whether any of the ${others.length} other Fleet bot(s) on this computer is signed in to Grok`;
73
+ const outsideUnanswered = unanswered.filter(outside);
74
+ if (outsideUnanswered.length) {
75
+ return {
76
+ readable: false,
77
+ blocked: true,
78
+ detail: unanswered.length === others.length
79
+ ? allUnanswered
80
+ : `the HQ Fleet helper could not say whether ${outsideUnanswered.length} other Fleet bot(s) of a different or unknown company on this computer are signed in to Grok`,
81
+ };
82
+ }
83
+ if (holders.length)
84
+ return { readable: true, detail: `the Grok sign-in of HQ Fleet bot ${holders[0]} on this computer` };
85
+ if (others.length && unanswered.length === others.length) {
86
+ return { readable: false, detail: allUnanswered };
87
+ }
88
+ return {
89
+ readable: false,
90
+ detail: others.length ? `none of the ${others.length} other HQ Fleet bot(s) on this computer is signed in to Grok` : "no other HQ Fleet bot on this computer is signed in to Grok",
91
+ };
92
+ }
93
+ //# sourceMappingURL=grok-login-scope.js.map
@@ -1,6 +1,8 @@
1
1
  import type { BotConfig } from "./config.js";
2
2
  import { type FleetLocalProviderAuthStatus } from "./fleet-local.js";
3
3
  import type { LegacyProviderLogin, LegacyProviderLoginProbe } from "./legacy-convert.js";
4
+ import { type BotLoginScope, type GrokSiblingLogin } from "./grok-login-scope.js";
5
+ export { botLoginScope, localBotLoginScopes, newBotLoginScope, type BotLoginScope, type GrokSiblingLogin } from "./grok-login-scope.js";
4
6
  export declare function codexCliAuthPath(home: string): string;
5
7
  /** The `exp` claim of a JWT, in seconds, or null when the token has none that reads. */
6
8
  export declare function jwtExpiry(token: string): number | null;
@@ -23,6 +25,10 @@ export interface GrokLoginProbeDeps {
23
25
  profileDir: string;
24
26
  }>;
25
27
  status?: (agentUid: string) => FleetLocalProviderAuthStatus | null;
28
+ /** The company scope of the bot that would share a login. Without one, no other bot's login counts. */
29
+ scope?: BotLoginScope;
30
+ /** The company scope of a bot here; null when it is not known. */
31
+ scopeOf?: (agentUid: string) => BotLoginScope;
26
32
  }
27
33
  /** The helper asks the keychain per profile, so one list of bots shares a scan this long. */
28
34
  export declare const GROK_HOLDER_SCAN_TTL_MS = 30000;
@@ -33,31 +39,48 @@ export interface GrokLoginProbeAsyncDeps {
33
39
  profileDir: string;
34
40
  }>;
35
41
  status?: (agentUid: string) => Promise<FleetLocalProviderAuthStatus | null>;
42
+ scope?: BotLoginScope;
43
+ scopeOf?: (agentUid: string) => BotLoginScope;
36
44
  }
37
- export declare function grokLoginReadableHereAsync(exclude: string, deps?: GrokLoginProbeAsyncDeps): Promise<LegacyProviderLogin>;
38
- /** Mirrors the helper's `_existing_machine_oauth`: another Fleet bot here holds a Grok OAuth login. */
39
- export declare function grokLoginReadableHere(exclude: string, deps?: GrokLoginProbeDeps, now?: number): LegacyProviderLogin;
45
+ export declare function grokLoginReadableHereAsync(exclude: string, deps?: GrokLoginProbeAsyncDeps): Promise<GrokSiblingLogin>;
46
+ /**
47
+ * Whether the helper's `_existing_machine_oauth` would give this bot a Grok
48
+ * login it may share. The helper copies the first other bot's login it finds
49
+ * and knows nothing of companies, so the answer is yes only when another
50
+ * Fleet bot here holds a Grok OAuth login and every other bot that holds one,
51
+ * or that the helper could not answer for, has the company scope `deps.scope`.
52
+ */
53
+ export declare function grokLoginReadableHere(exclude: string, deps?: GrokLoginProbeDeps, now?: number): GrokSiblingLogin;
40
54
  export declare const GROK_CLI_AUTH_ISSUER = "https://auth.x.ai";
41
55
  export declare const FLEET_XAI_OAUTH_CLIENT_ID = "b1a00492-073a-47ea-816f-4c329264a828";
42
56
  export declare function grokCliAuthPath(homedir?: string, env?: NodeJS.ProcessEnv): string;
43
57
  export declare function grokCliLoginReadable(homedir?: string, env?: NodeJS.ProcessEnv): LegacyProviderLogin;
44
58
  export declare function fleetHelperSharesGrokCliLogin(): boolean;
45
59
  export interface GrokSignInDeps {
46
- sibling?: () => LegacyProviderLogin;
60
+ sibling?: () => GrokSiblingLogin;
47
61
  cli?: () => LegacyProviderLogin;
48
62
  cliImport?: boolean;
63
+ /** The company scope of the bot that would sign in. Without one, no other bot's login counts. */
64
+ scope?: BotLoginScope;
49
65
  }
50
- export declare function grokSignInReusableHere(exclude: string, deps?: GrokSignInDeps): LegacyProviderLogin;
51
- /** The live probe for a bot: Codex from its login home, Grok from the Grok CLI or the other Fleet bots here. */
52
- export declare function legacyProviderLoginProbe(dir: string, config: Pick<BotConfig, "name" | "agentUid" | "runtime" | "runtimeAuth" | "hqRoot">): LegacyProviderLoginProbe;
66
+ /**
67
+ * A Grok sign-in the helper would import for a bot of company scope `deps.scope`.
68
+ * The helper tries the other Fleet bots before the Grok CLI login, so a
69
+ * blocked sibling answer also rules out the Grok CLI login.
70
+ */
71
+ export declare function grokSignInReusableHere(exclude: string, deps?: GrokSignInDeps): GrokSiblingLogin;
72
+ /** The live probe for a bot: Codex from its login home, Grok from the Grok CLI or the other Fleet bots of its company here. */
73
+ export declare function legacyProviderLoginProbe(dir: string, config: Pick<BotConfig, "name" | "agentUid" | "runtime" | "runtimeAuth" | "hqRoot" | "kind" | "companies" | "workerId">): LegacyProviderLoginProbe;
53
74
  export type FleetSignInProvider = "chatgpt" | "grok";
54
75
  export interface FleetSignInHereDeps {
55
76
  env?: NodeJS.ProcessEnv;
56
77
  homedir?: string;
57
- grok?: () => LegacyProviderLogin;
78
+ grok?: () => GrokSiblingLogin;
58
79
  grokCli?: () => LegacyProviderLogin;
59
80
  grokCliImport?: boolean;
60
81
  now?: number;
82
+ /** The company scope of the bot that would sign in. Without one, no other bot's Grok sign-in counts. */
83
+ scope?: BotLoginScope;
61
84
  }
62
- export declare function fleetSignInReusableHere(provider: FleetSignInProvider, deps?: FleetSignInHereDeps): LegacyProviderLogin;
85
+ export declare function fleetSignInReusableHere(provider: FleetSignInProvider, deps?: FleetSignInHereDeps): GrokSiblingLogin;
63
86
  //# sourceMappingURL=legacy-provider-login.d.ts.map
@@ -6,7 +6,10 @@
6
6
  * ~/.codex/auth.json) with a refreshable, unexpired token. A bot with its
7
7
  * own Codex login (hq bot login) or a capacity account imports from that
8
8
  * home instead, so the account it answered with comes along.
9
- * - Grok: the helper copies another Fleet bot's Grok login, and from release
9
+ * - Grok: the helper copies another Fleet bot's Grok login. It takes the
10
+ * first one it finds, whatever company that bot belongs to, so the check
11
+ * here says yes only when every bot it could copy from has this bot's
12
+ * company scope. From release
10
13
  * 0.4.31 (local builds from 0.4.31-local.13) also shares the Grok CLI login
11
14
  * in <GROK_HOME>/auth.json, else ~/.grok/auth.json (a record for the
12
15
  * runtime's xAI client with a refresh token). Its own
@@ -20,6 +23,8 @@ import * as fs from "node:fs";
20
23
  import * as os from "node:os";
21
24
  import * as path from "node:path";
22
25
  import { cachedFleetLocalTargetRelease, fleetLocalProviderAuthStatus, fleetLocalProviderAuthStatusAsync, fleetReleaseImportsGrokCli, listFleetLocalProfiles } from "./fleet-local.js";
26
+ import { botLoginScope, grokLoginFromScan, localBotLoginScopes } from "./grok-login-scope.js";
27
+ export { botLoginScope, localBotLoginScopes, newBotLoginScope } from "./grok-login-scope.js";
23
28
  import { botOwnAuthHome, botRuntimeAuth, capacityAccountHome } from "./runtime-auth.js";
24
29
  export function codexCliAuthPath(home) {
25
30
  return path.join(home, "auth.json");
@@ -124,26 +129,17 @@ export async function grokLoginReadableHereAsync(exclude, deps = {}) {
124
129
  else if (found.authenticated && found.authType === "oauth")
125
130
  holders.push(agentUid);
126
131
  });
127
- return grokLoginFromScan({ holders, uids: profiles.map((profile) => profile.agentUid), unanswered }, exclude);
132
+ return grokLoginFromScan({ holders, uids: profiles.map((profile) => profile.agentUid), unanswered }, exclude, deps.scope ?? null, deps.scopeOf ?? localBotLoginScopes());
128
133
  }
129
- /** Mirrors the helper's `_existing_machine_oauth`: another Fleet bot here holds a Grok OAuth login. */
134
+ /**
135
+ * Whether the helper's `_existing_machine_oauth` would give this bot a Grok
136
+ * login it may share. The helper copies the first other bot's login it finds
137
+ * and knows nothing of companies, so the answer is yes only when another
138
+ * Fleet bot here holds a Grok OAuth login and every other bot that holds one,
139
+ * or that the helper could not answer for, has the company scope `deps.scope`.
140
+ */
130
141
  export function grokLoginReadableHere(exclude, deps = {}, now = Date.now()) {
131
- return grokLoginFromScan(grokHolders(deps, now), exclude);
132
- }
133
- function grokLoginFromScan(scan, exclude) {
134
- const other = (agentUid) => agentUid.toLowerCase() !== exclude.toLowerCase();
135
- const holder = scan.holders.find(other);
136
- if (holder)
137
- return { readable: true, detail: `the Grok sign-in of HQ Fleet bot ${holder} on this computer` };
138
- const others = scan.uids.filter(other);
139
- const unanswered = scan.unanswered.filter(other);
140
- if (others.length && unanswered.length === others.length) {
141
- return { readable: false, detail: `the HQ Fleet helper could not say whether any of the ${others.length} other Fleet bot(s) on this computer is signed in to Grok` };
142
- }
143
- return {
144
- readable: false,
145
- detail: others.length ? `none of the ${others.length} other HQ Fleet bot(s) on this computer is signed in to Grok` : "no other HQ Fleet bot on this computer is signed in to Grok",
146
- };
142
+ return grokLoginFromScan(grokHolders(deps, now), exclude, deps.scope ?? null, deps.scopeOf ?? localBotLoginScopes());
147
143
  }
148
144
  export const GROK_CLI_AUTH_ISSUER = "https://auth.x.ai";
149
145
  export const FLEET_XAI_OAUTH_CLIENT_ID = "b1a00492-073a-47ea-816f-4c329264a828";
@@ -181,21 +177,30 @@ export function fleetHelperSharesGrokCliLogin() {
181
177
  return false;
182
178
  }
183
179
  }
180
+ /**
181
+ * A Grok sign-in the helper would import for a bot of company scope `deps.scope`.
182
+ * The helper tries the other Fleet bots before the Grok CLI login, so a
183
+ * blocked sibling answer also rules out the Grok CLI login.
184
+ */
184
185
  export function grokSignInReusableHere(exclude, deps = {}) {
186
+ const sibling = (deps.sibling ?? (() => grokLoginReadableHere(exclude, { scope: deps.scope ?? null })))();
187
+ if (sibling.blocked)
188
+ return sibling;
185
189
  if (deps.cliImport ?? fleetHelperSharesGrokCliLogin()) {
186
190
  const cli = (deps.cli ?? (() => grokCliLoginReadable()))();
187
191
  if (cli.readable)
188
192
  return cli;
189
193
  }
190
- return (deps.sibling ?? (() => grokLoginReadableHere(exclude)))();
194
+ return sibling;
191
195
  }
192
- /** The live probe for a bot: Codex from its login home, Grok from the Grok CLI or the other Fleet bots here. */
196
+ /** The live probe for a bot: Codex from its login home, Grok from the Grok CLI or the other Fleet bots of its company here. */
193
197
  export function legacyProviderLoginProbe(dir, config) {
194
198
  return (runtime) => {
195
199
  if (runtime === "grok") {
196
200
  if (config.runtimeAuth?.grok !== undefined)
197
201
  return { readable: false, detail: "it uses its own Grok login, which HQ Fleet Local cannot import" };
198
- return grokSignInReusableHere(config.agentUid);
202
+ const login = grokSignInReusableHere(config.agentUid, { scope: botLoginScope(config) });
203
+ return { readable: login.readable, detail: login.detail };
199
204
  }
200
205
  const home = legacyCodexHome(dir, config);
201
206
  if ("error" in home)
@@ -207,6 +212,7 @@ export function legacyProviderLoginProbe(dir, config) {
207
212
  export function fleetSignInReusableHere(provider, deps = {}) {
208
213
  if (provider === "grok") {
209
214
  return grokSignInReusableHere("", {
215
+ scope: deps.scope ?? null,
210
216
  ...(deps.grok ? { sibling: deps.grok } : {}),
211
217
  cli: deps.grokCli ?? (() => grokCliLoginReadable(deps.homedir ?? os.homedir(), deps.env ?? process.env)),
212
218
  ...(deps.grokCliImport !== undefined ? { cliImport: deps.grokCliImport } : {}),
@@ -47,7 +47,12 @@ export async function checkRuntimeSignIn(opts) {
47
47
  }
48
48
  catch (err) {
49
49
  const message = err instanceof Error ? err.message : String(err);
50
- return { signedIn: null, checkedAt, detail: `${opts.runtime.id} ${status.args.join(" ")} could not run: ${message.slice(0, 200)}` };
50
+ return {
51
+ signedIn: null,
52
+ checkedAt,
53
+ detail: `${opts.runtime.id} ${status.args.join(" ")} could not run: ${message.slice(0, 200)}`,
54
+ couldNotStart: true,
55
+ };
51
56
  }
52
57
  }
53
58
  //# sourceMappingURL=runtime-sign-in-check.js.map
@@ -37,6 +37,8 @@ export interface RuntimeSignInCheck {
37
37
  checkedAt: string;
38
38
  /** Why the check could not tell, for the log and the JSON output. */
39
39
  detail?: string;
40
+ /** Set when the status command could not be started at all (for example, the tool is not installed). */
41
+ couldNotStart?: true;
40
42
  }
41
43
  /** How long a passed check stands in for another before a turn. */
42
44
  export declare const SIGN_IN_CHECK_FRESH_MS = 30000;
@@ -131,6 +131,8 @@ const DEBUG_CONTEXT_HOOK_EVENTS = new Set([
131
131
  "TeammateIdle",
132
132
  ]);
133
133
  const SAFE_SLOW_PHASES = new Set([
134
+ "native_stop_checks",
135
+ "native_dispatch",
134
136
  "startup",
135
137
  "source",
136
138
  "config_load",
@@ -20,6 +20,14 @@
20
20
  * it gains no access it did not have; the check keeps a link, a hardlink, a
21
21
  * file of another user or a writable file from being run by mistake.
22
22
  *
23
+ * On Windows (only `hq doctor --only machine-checks` runs there; the daemon
24
+ * schedule skips Windows) each script is run with the trusted Git Bash that
25
+ * src/utils/windows-bash.ts resolves, never System32\bash.exe (WSL) or a
26
+ * WindowsApps alias. With no trusted Git Bash every check is `unknown` and
27
+ * nothing is run. The store read rules there are safe-store's Windows rules:
28
+ * a real folder (not a symlink or junction) and a regular single-link file
29
+ * that is not a symlink; Windows has no POSIX owner or mode bits to check.
30
+ *
23
31
  * Results can name local paths, so they are written only to the daemon's
24
32
  * private folder (machine-checks.json, mode 0600) and the state file, and are
25
33
  * never logged or sent.
@@ -58,7 +66,20 @@ export interface RunMachineChecksOptions {
58
66
  checks?: readonly MachineCheckSpec[];
59
67
  killGraceMs?: number;
60
68
  drainMs?: number;
69
+ /** Platform whose rules apply. Default process.platform. */
70
+ platform?: NodeJS.Platform;
71
+ /** Windows only: the trusted Git Bash, or undefined when none. Default resolveWindowsBash. */
72
+ resolveBash?: (env: NodeJS.ProcessEnv) => string | undefined;
61
73
  }
74
+ /** The summary of every check on Windows when no trusted Git Bash is found. */
75
+ export declare const MACHINE_CHECK_NO_GIT_BASH = "not run: Git Bash was not found (set CLAUDE_CODE_GIT_BASH_PATH or install Git for Windows)";
76
+ /**
77
+ * The shell that runs every script: /bin/bash off Windows; on Windows the
78
+ * trusted Git Bash, or undefined when none is found. A resolver answer that
79
+ * windows-bash.ts excludes (System32\bash.exe, a WindowsApps alias) or that
80
+ * is not an absolute path counts as none.
81
+ */
82
+ export declare function machineCheckShell(platform: NodeJS.Platform, env: NodeJS.ProcessEnv, resolveBash?: (env: NodeJS.ProcessEnv) => string | undefined): string | undefined;
62
83
  /** The finding text a script's stdout carries: empty means nothing to report. */
63
84
  export declare function findingText(stdout: string): string;
64
85
  /** First non-empty line with `<tag>` and `</tag>` markers removed, at most 240 characters. */
@@ -75,7 +96,7 @@ type ScriptCheck = {
75
96
  summary: string;
76
97
  };
77
98
  /** The script's absolute path when it may be run; else why not. */
78
- export declare function checkMachineCheckScript(hqRoot: string, relative: string): ScriptCheck;
99
+ export declare function checkMachineCheckScript(hqRoot: string, relative: string, platform?: NodeJS.Platform): ScriptCheck;
79
100
  /**
80
101
  * Run every machine check once, one at a time. A call while a batch is
81
102
  * running returns that batch. Inside a machine check