@indigoai-us/hq-cli 5.345.214 → 5.345.215-beta.0

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 (103) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/command-catalog.generated.d.ts +134 -7
  3. package/dist/command-catalog.generated.js +168 -7
  4. package/dist/commands/agents.d.ts +51 -1
  5. package/dist/commands/agents.js +154 -2
  6. package/dist/commands/bot-jobs.d.ts +2 -15
  7. package/dist/commands/bot-jobs.js +2 -94
  8. package/dist/commands/bot-runtime.d.ts +46 -5
  9. package/dist/commands/bot-runtime.js +228 -18
  10. package/dist/commands/bot.d.ts +16 -9
  11. package/dist/commands/bot.js +169 -51
  12. package/dist/commands/cloud.d.ts +66 -13
  13. package/dist/commands/cloud.js +120 -39
  14. package/dist/commands/company-restore.d.ts +23 -0
  15. package/dist/commands/company-restore.js +128 -0
  16. package/dist/commands/company.js +2 -0
  17. package/dist/commands/integrations-connect.d.ts +10 -3
  18. package/dist/commands/integrations-connect.js +87 -13
  19. package/dist/commands/lanes.js +26 -9
  20. package/dist/commands/sources.js +6 -0
  21. package/dist/commands/storage-offload.d.ts +12 -0
  22. package/dist/commands/storage-offload.js +41 -3
  23. package/dist/commands/sync-mode.js +5 -0
  24. package/dist/commands/whoami.js +4 -0
  25. package/dist/lib/bot/config.d.ts +1 -0
  26. package/dist/lib/bot/config.js +10 -0
  27. package/dist/lib/bot/eventbridge-cron.d.ts +22 -0
  28. package/dist/lib/bot/eventbridge-cron.js +104 -0
  29. package/dist/lib/bot/fleet-local.d.ts +33 -1
  30. package/dist/lib/bot/fleet-local.js +215 -31
  31. package/dist/lib/bot/fleet-python.d.ts +3 -0
  32. package/dist/lib/bot/fleet-python.js +34 -4
  33. package/dist/lib/bot/fleet-runtime-sources.d.ts +15 -0
  34. package/dist/lib/bot/fleet-runtime-sources.js +30 -0
  35. package/dist/lib/bot/legacy-provider-login.d.ts +8 -0
  36. package/dist/lib/bot/legacy-provider-login.js +19 -2
  37. package/dist/lib/bot/prompt.js +1 -1
  38. package/dist/lib/bot/readiness.d.ts +8 -0
  39. package/dist/lib/bot/readiness.js +17 -3
  40. package/dist/lib/bot/runtime-auth.d.ts +30 -0
  41. package/dist/lib/bot/runtime-auth.js +94 -3
  42. package/dist/lib/bot/status.d.ts +2 -0
  43. package/dist/lib/capacity/collectors/grok-refresh.d.ts +80 -0
  44. package/dist/lib/capacity/collectors/grok-refresh.js +189 -0
  45. package/dist/lib/capacity/collectors/grok.d.ts +5 -0
  46. package/dist/lib/capacity/collectors/grok.js +56 -5
  47. package/dist/lib/daemon/catalog.js +11 -1
  48. package/dist/lib/db/sqlite-binding.d.ts +1 -0
  49. package/dist/lib/db/sqlite-binding.js +1 -1
  50. package/dist/lib/delivery/artifacts.d.ts +99 -0
  51. package/dist/lib/delivery/artifacts.js +548 -0
  52. package/dist/lib/delivery/backup.d.ts +78 -0
  53. package/dist/lib/delivery/backup.js +343 -0
  54. package/dist/lib/delivery/cache.d.ts +29 -0
  55. package/dist/lib/delivery/cache.js +33 -0
  56. package/dist/lib/delivery/contracts.d.ts +142 -0
  57. package/dist/lib/delivery/contracts.js +289 -0
  58. package/dist/lib/delivery/credentials.d.ts +54 -0
  59. package/dist/lib/delivery/credentials.js +119 -0
  60. package/dist/lib/delivery/enrollment.d.ts +142 -0
  61. package/dist/lib/delivery/enrollment.js +382 -0
  62. package/dist/lib/delivery/identity.d.ts +25 -0
  63. package/dist/lib/delivery/identity.js +82 -0
  64. package/dist/lib/delivery/inbox.d.ts +116 -0
  65. package/dist/lib/delivery/inbox.js +260 -0
  66. package/dist/lib/delivery/migrations.d.ts +139 -0
  67. package/dist/lib/delivery/migrations.js +623 -0
  68. package/dist/lib/delivery/mqtt-adapter.d.ts +50 -0
  69. package/dist/lib/delivery/mqtt-adapter.js +242 -0
  70. package/dist/lib/delivery/mqtt.d.ts +61 -0
  71. package/dist/lib/delivery/mqtt.js +112 -0
  72. package/dist/lib/delivery/outbox.d.ts +95 -0
  73. package/dist/lib/delivery/outbox.js +187 -0
  74. package/dist/lib/delivery/provenance.d.ts +129 -0
  75. package/dist/lib/delivery/provenance.js +93 -0
  76. package/dist/lib/delivery/reconciler.d.ts +151 -0
  77. package/dist/lib/delivery/reconciler.js +492 -0
  78. package/dist/lib/delivery/restore.d.ts +35 -0
  79. package/dist/lib/delivery/restore.js +134 -0
  80. package/dist/lib/delivery/store.d.ts +161 -0
  81. package/dist/lib/delivery/store.js +940 -0
  82. package/dist/lib/delivery/workers/macos-job-helper.d.ts +103 -0
  83. package/dist/lib/delivery/workers/macos-job-helper.js +927 -0
  84. package/dist/lib/delivery/workers/macos.d.ts +176 -0
  85. package/dist/lib/delivery/workers/macos.js +901 -0
  86. package/dist/lib/delivery/workers/windows-boundary.d.ts +453 -0
  87. package/dist/lib/delivery/workers/windows-boundary.js +693 -0
  88. package/dist/lib/delivery/workers/windows-job-helper.d.ts +35 -0
  89. package/dist/lib/delivery/workers/windows-job-helper.js +264 -0
  90. package/dist/lib/delivery/workers/windows.d.ts +241 -0
  91. package/dist/lib/delivery/workers/windows.js +608 -0
  92. package/dist/lib/install/provider-wrappers.d.ts +2 -0
  93. package/dist/lib/install/provider-wrappers.js +68 -3
  94. package/dist/utils/cognito-callback-port.d.ts +14 -0
  95. package/dist/utils/cognito-callback-port.js +24 -0
  96. package/dist/utils/cognito-session.js +3 -3
  97. package/dist/utils/deleted-company-notice.d.ts +59 -0
  98. package/dist/utils/deleted-company-notice.js +156 -0
  99. package/dist/utils/login-browser.d.ts +1 -1
  100. package/dist/utils/login-browser.js +7 -5
  101. package/dist/utils/resident-package-preload.js +30 -15
  102. package/dist/utils/vault-api.js +7 -0
  103. package/package.json +7 -7
@@ -1,4 +1,4 @@
1
- import { execFileSync, spawn, spawnSync } from "node:child_process";
1
+ import { execFile, execFileSync, spawn, spawnSync } from "node:child_process";
2
2
  import * as crypto from "node:crypto";
3
3
  import * as fs from "node:fs";
4
4
  import * as os from "node:os";
@@ -537,7 +537,51 @@ export function parseFleetLocalReleasePin(value) {
537
537
  if (![pin.artifactSha256, pin.runtimeArtifactSha256, pin.manifestSha256, pin.signatureSha256].every((hash) => SHA256_RE.test(hash))) {
538
538
  return null;
539
539
  }
540
- return pin;
540
+ if (record.environmentArtifacts === undefined)
541
+ return pin;
542
+ const environmentArtifacts = parseEnvironmentArtifacts(record.environmentArtifacts, pin.version);
543
+ return environmentArtifacts ? { ...pin, environmentArtifacts } : null;
544
+ }
545
+ const ENVIRONMENT_PLATFORM_RE = /^[a-z0-9]+-[a-z0-9_]+$/;
546
+ function parseEnvironmentArtifacts(value, version) {
547
+ if (!value || typeof value !== "object" || Array.isArray(value))
548
+ return null;
549
+ const artifacts = {};
550
+ for (const [platform, entry] of Object.entries(value)) {
551
+ if (!ENVIRONMENT_PLATFORM_RE.test(platform) || !entry || typeof entry !== "object" || Array.isArray(entry))
552
+ return null;
553
+ const { name, sha256, size } = entry;
554
+ if (name !== `hq-fleet-local-wheels-${version}-${platform}.tar`)
555
+ return null;
556
+ if (typeof sha256 !== "string" || !SHA256_RE.test(sha256))
557
+ return null;
558
+ if (typeof size !== "number" || !Number.isSafeInteger(size) || size <= 0)
559
+ return null;
560
+ artifacts[platform] = { name, sha256, size };
561
+ }
562
+ return artifacts;
563
+ }
564
+ export function fleetEnvironmentPlatform(platform = process.platform, arch = process.arch) {
565
+ return `${platform}-${arch}`;
566
+ }
567
+ export function releaseWheelhouse(release, platform) {
568
+ return release.environmentArtifacts?.[platform] ?? null;
569
+ }
570
+ export function verifyFleetLocalWheelhouse(file, artifact, manifest, platform, release) {
571
+ let signed;
572
+ try {
573
+ const parsed = JSON.parse(manifest.toString("utf8"));
574
+ signed = parsed.environment?.wheelhouses?.[platform];
575
+ }
576
+ catch {
577
+ signed = undefined;
578
+ }
579
+ if (!signed || signed.asset !== artifact.name || signed.sha256 !== artifact.sha256 || signed.size !== artifact.size) {
580
+ throw expectedError(`HQ Fleet Local ${release.version} bundled packages for ${platform} do not match the signed manifest.`);
581
+ }
582
+ if (fs.statSync(file).size !== artifact.size || fileSha256(file) !== artifact.sha256) {
583
+ throw expectedError(`HQ Fleet Local ${release.version} bundled packages for ${platform} failed their hash check. The download was discarded; retry, and report it with \`hq bug\` if it happens again.`);
584
+ }
541
585
  }
542
586
  export function parseFleetLocalReleasePointer(body, now = Date.now()) {
543
587
  if (!body || typeof body !== "object" || Array.isArray(body))
@@ -756,16 +800,17 @@ function discardDownloads(target) {
756
800
  return;
757
801
  }
758
802
  }
759
- async function downloadReleaseFiles(release, fetcher, resolve, cachedRuntime, target, onProgress, stallMs) {
803
+ async function downloadReleaseFiles(release, fetcher, resolve, cachedRuntime, target, onProgress, stallMs, wheelhouse = null) {
760
804
  fs.mkdirSync(target, { recursive: true, mode: 0o700 });
761
805
  const pinned = new Map([
762
806
  [release.artifact, release.artifactSha256],
763
807
  [release.runtimeArtifact, release.runtimeArtifactSha256],
764
808
  ["release-manifest.json", release.manifestSha256],
765
809
  ["release-manifest.sig", release.signatureSha256],
810
+ ...(wheelhouse ? [[wheelhouse.name, wheelhouse.sha256]] : []),
766
811
  ]);
767
812
  const downloaded = new Map();
768
- const wanted = RELEASE_FILE_NAMES(release).filter((name) => {
813
+ const wanted = [...RELEASE_FILE_NAMES(release), ...(wheelhouse ? [wheelhouse.name] : [])].filter((name) => {
769
814
  if (name === release.runtimeArtifact && cachedRuntime) {
770
815
  downloaded.set(name, cachedRuntime);
771
816
  return false;
@@ -797,10 +842,12 @@ async function downloadReleaseFiles(release, fetcher, resolve, cachedRuntime, ta
797
842
  runtimeArchive: fs.readFileSync(downloaded.get(release.runtimeArtifact)),
798
843
  manifest: fs.readFileSync(downloaded.get("release-manifest.json")),
799
844
  signature: fs.readFileSync(downloaded.get("release-manifest.sig")),
845
+ ...(wheelhouse ? { wheelhouse: downloaded.get(wheelhouse.name) } : {}),
800
846
  };
801
847
  }
802
- async function downloadFleetLocalReleaseFromHq(release, fetcher, links, cachedRuntime, target, onProgress, stallMs, allowFileLinks = false) {
803
- for (const name of RELEASE_FILE_NAMES(release)) {
848
+ async function downloadFleetLocalReleaseFromHq(release, fetcher, links, cachedRuntime, target, onProgress, stallMs, allowFileLinks = false, wheelhouse = null) {
849
+ const bundle = wheelhouse && links.has(wheelhouse.name) ? wheelhouse : null;
850
+ for (const name of [...RELEASE_FILE_NAMES(release), ...(bundle ? [bundle.name] : [])]) {
804
851
  if (name === release.runtimeArtifact && cachedRuntime)
805
852
  continue;
806
853
  const url = links.get(name);
@@ -815,9 +862,9 @@ async function downloadFleetLocalReleaseFromHq(release, fetcher, links, cachedRu
815
862
  const cdn = cdnUsable ? links.get(fleetReleaseCdnLinkName(name)) : undefined;
816
863
  const candidates = cdn && trustedReleaseCdnLink(cdn) ? [cdn] : [];
817
864
  return { urls: [...candidates, links.get(name)] };
818
- }, cachedRuntime, target, onProgress, stallMs);
865
+ }, cachedRuntime, target, onProgress, stallMs, bundle);
819
866
  }
820
- async function downloadFleetLocalRelease(release, fetcher, token, cachedRuntime, target, onProgress, stallMs) {
867
+ async function downloadFleetLocalRelease(release, fetcher, token, cachedRuntime, target, onProgress, stallMs, wheelhouse = null) {
821
868
  const headers = {
822
869
  Accept: "application/vnd.github+json",
823
870
  Authorization: `Bearer ${token}`,
@@ -833,7 +880,8 @@ async function downloadFleetLocalRelease(release, fetcher, token, cachedRuntime,
833
880
  const assets = new Map((body.assets ?? [])
834
881
  .filter((asset) => !!asset.name && !!asset.url)
835
882
  .map((asset) => [asset.name, asset.url]));
836
- for (const name of RELEASE_FILE_NAMES(release)) {
883
+ const bundle = wheelhouse && assets.has(wheelhouse.name) ? wheelhouse : null;
884
+ for (const name of [...RELEASE_FILE_NAMES(release), ...(bundle ? [bundle.name] : [])]) {
837
885
  if (name === release.runtimeArtifact && cachedRuntime)
838
886
  continue;
839
887
  const url = assets.get(name);
@@ -843,7 +891,7 @@ async function downloadFleetLocalRelease(release, fetcher, token, cachedRuntime,
843
891
  throw expectedError(`HQ Fleet Local ${release.tag} returned an untrusted asset URL for ${name}.`);
844
892
  }
845
893
  }
846
- return downloadReleaseFiles(release, fetcher, (name) => ({ urls: [assets.get(name)], headers: { ...headers, Accept: "application/octet-stream" } }), cachedRuntime, target, onProgress, stallMs);
894
+ return downloadReleaseFiles(release, fetcher, (name) => ({ urls: [assets.get(name)], headers: { ...headers, Accept: "application/octet-stream" } }), cachedRuntime, target, onProgress, stallMs, bundle);
847
895
  }
848
896
  function installedFiles(dir, release) {
849
897
  const archive = path.join(dir, release.artifact);
@@ -870,6 +918,8 @@ function installFiles(target, files, release, publicKey) {
870
918
  fs.writeFileSync(path.join(staging, release.runtimeArtifact), files.runtimeArchive, { mode: 0o644 });
871
919
  fs.writeFileSync(path.join(staging, "release-manifest.json"), files.manifest, { mode: 0o644 });
872
920
  fs.writeFileSync(path.join(staging, "release-manifest.sig"), files.signature, { mode: 0o644 });
921
+ if (files.wheelhouse)
922
+ fs.renameSync(files.wheelhouse, path.join(staging, path.basename(files.wheelhouse)));
873
923
  fs.writeFileSync(path.join(staging, "release-public.pem"), publicKeyList(publicKey).join(""), { mode: 0o644 });
874
924
  fs.writeFileSync(path.join(staging, "install.json"), `${JSON.stringify({ schemaVersion: 1, release, engine: engineMetadata(release) }, null, 2)}\n`, { mode: 0o644 });
875
925
  if (fs.existsSync(target))
@@ -937,20 +987,32 @@ export async function installPinnedFleetLocalDistribution(deps = {}) {
937
987
  const root = deps.fleetHome ?? fleetHome();
938
988
  const dir = path.join(root, "distributions", "hq-fleet-local", release.version);
939
989
  const onProgress = deps.onProgress;
990
+ const environmentPlatform = fleetEnvironmentPlatform(deps.platform ?? process.platform, deps.arch ?? process.arch);
991
+ const wheelhouse = releaseWheelhouse(release, environmentPlatform);
940
992
  const warnCompatibility = (manifest) => {
941
993
  const warning = fleetLocalCliCompatibilityWarning(manifest, release);
942
994
  if (warning)
943
995
  process.stderr.write(`Warning: ${warning}\n`);
944
996
  };
945
- const installation = () => ({
946
- release,
947
- dir,
948
- archive: path.join(dir, release.artifact),
949
- runtimeArchive: path.join(dir, release.runtimeArtifact),
950
- manifest: path.join(dir, "release-manifest.json"),
951
- signature: path.join(dir, "release-manifest.sig"),
952
- engine: engineMetadata(release),
953
- });
997
+ const installedWheelhouse = () => {
998
+ if (!wheelhouse)
999
+ return null;
1000
+ const file = path.join(dir, wheelhouse.name);
1001
+ return fs.existsSync(file) ? file : null;
1002
+ };
1003
+ const installation = () => {
1004
+ const bundle = installedWheelhouse();
1005
+ return {
1006
+ release,
1007
+ dir,
1008
+ archive: path.join(dir, release.artifact),
1009
+ runtimeArchive: path.join(dir, release.runtimeArtifact),
1010
+ manifest: path.join(dir, "release-manifest.json"),
1011
+ signature: path.join(dir, "release-manifest.sig"),
1012
+ engine: engineMetadata(release),
1013
+ ...(bundle ? { wheelhouse: bundle, environmentPlatform } : {}),
1014
+ };
1015
+ };
954
1016
  const current = filesMatchPin(installedFiles(dir, release), release);
955
1017
  if (current) {
956
1018
  verifyFleetLocalRelease(current, release, publicKey);
@@ -975,7 +1037,7 @@ export async function installPinnedFleetLocalDistribution(deps = {}) {
975
1037
  const target = downloadsDir(root, release);
976
1038
  let files;
977
1039
  if (links) {
978
- files = await downloadFleetLocalReleaseFromHq(release, fetcher, links, cachedRuntime, target, onProgress, deps.downloadStallMs, deps.allowFileLinks === true);
1040
+ files = await downloadFleetLocalReleaseFromHq(release, fetcher, links, cachedRuntime, target, onProgress, deps.downloadStallMs, deps.allowFileLinks === true, wheelhouse);
979
1041
  }
980
1042
  else {
981
1043
  let githubToken;
@@ -985,11 +1047,13 @@ export async function installPinnedFleetLocalDistribution(deps = {}) {
985
1047
  catch (error) {
986
1048
  throw noReleaseSourceError(release, lookup.reason) ?? error;
987
1049
  }
988
- files = await downloadFleetLocalRelease(release, fetcher, githubToken, cachedRuntime, target, onProgress, deps.downloadStallMs);
1050
+ files = await downloadFleetLocalRelease(release, fetcher, githubToken, cachedRuntime, target, onProgress, deps.downloadStallMs, wheelhouse);
989
1051
  }
990
1052
  onProgress?.({ phase: "verify" });
991
1053
  try {
992
1054
  verifyFleetLocalRelease(files, release, publicKey);
1055
+ if (files.wheelhouse && wheelhouse)
1056
+ verifyFleetLocalWheelhouse(files.wheelhouse, wheelhouse, files.manifest, environmentPlatform, release);
993
1057
  }
994
1058
  catch (error) {
995
1059
  discardDownloads(target);
@@ -1648,6 +1712,42 @@ export function writeFleetLocalFirstStart(profileDir, firstStart) {
1648
1712
  fs.renameSync(temporary, destination);
1649
1713
  return destination;
1650
1714
  }
1715
+ const SIGN_IN_PROVIDER_RUNTIME = { anthropic: "claude", "openai-codex": "codex", "xai-oauth": "grok" };
1716
+ const SIGN_IN_LOGINS = new Set(["claude-code", "codex-cli", "grok-cli", "bot"]);
1717
+ export function fleetLocalSignInNeededPath(agentUid, deps = {}) {
1718
+ return path.join(profileRoot(agentUid, deps.fleetHome ?? fleetHome()), "state", "sign-in-needed.json");
1719
+ }
1720
+ export function readFleetLocalSignInNeeded(agentUid, deps = {}) {
1721
+ if (!/^agt_[A-Za-z0-9_-]+$/.test(agentUid))
1722
+ return null;
1723
+ let record;
1724
+ try {
1725
+ record = JSON.parse(fs.readFileSync(fleetLocalSignInNeededPath(agentUid, deps), "utf8"));
1726
+ }
1727
+ catch {
1728
+ return null;
1729
+ }
1730
+ if (!record || typeof record !== "object" || Array.isArray(record))
1731
+ return null;
1732
+ const runtime = typeof record.provider === "string" ? SIGN_IN_PROVIDER_RUNTIME[record.provider] : undefined;
1733
+ if (!runtime)
1734
+ return null;
1735
+ const login = typeof record.personSignIn === "string" && SIGN_IN_LOGINS.has(record.personSignIn) ? record.personSignIn : null;
1736
+ const since = typeof record.since === "string" && Number.isFinite(Date.parse(record.since)) ? record.since : null;
1737
+ return { runtime, login, since };
1738
+ }
1739
+ export function readFleetLocalIntroSentAt(agentUid, deps = {}) {
1740
+ if (!/^agt_[A-Za-z0-9_-]+$/.test(agentUid))
1741
+ return null;
1742
+ try {
1743
+ const record = JSON.parse(fs.readFileSync(path.join(profileRoot(agentUid, deps.fleetHome ?? fleetHome()), "first-start.json"), "utf8"));
1744
+ const at = record?.introSentAt;
1745
+ return typeof at === "string" && Number.isFinite(Date.parse(at)) ? at : null;
1746
+ }
1747
+ catch {
1748
+ return null;
1749
+ }
1750
+ }
1651
1751
  export function writeFleetLocalSoul(agentUid, systemPrompt, deps = {}) {
1652
1752
  if (!/^agt_[A-Za-z0-9_-]+$/.test(agentUid)) {
1653
1753
  throw expectedError(`Cannot use an HQ Fleet profile for invalid bot id ${agentUid}.`);
@@ -1885,6 +1985,47 @@ function checkedRun(run, executable, args, options, label, spawn) {
1885
1985
  throw expectedError(`HQ Fleet Local ${label} failed.${tail ? `\n${tail}` : ""}`);
1886
1986
  }
1887
1987
  }
1988
+ export const FLEET_WHEELHOUSE_EXIT = { installed: 0, verificationFailed: 2, unavailable: 3, installFailed: 4 };
1989
+ function installFromWheelhouse(installation, python, runtimePython, runtimeSource, distributionSource, env, spawn) {
1990
+ const platform = installation.environmentPlatform;
1991
+ const artifact = releaseWheelhouse(installation.release, platform);
1992
+ const wheelhouse = installation.wheelhouse;
1993
+ if (!artifact || !fs.existsSync(wheelhouse))
1994
+ return "fallback";
1995
+ verifyFleetLocalWheelhouse(wheelhouse, artifact, fs.readFileSync(installation.manifest), platform, installation.release);
1996
+ const installer = path.join(distributionSource, "src", "hq_fleet_local", "environment.py");
1997
+ if (!fs.existsSync(installer))
1998
+ return "fallback";
1999
+ const { stdio } = pipeInheritedStdio(["ignore", 2, 2]);
2000
+ const result = spawn(python.python, [
2001
+ "-I",
2002
+ installer,
2003
+ "install",
2004
+ "--uv",
2005
+ python.uv,
2006
+ "--python",
2007
+ runtimePython,
2008
+ "--platform",
2009
+ platform,
2010
+ "--manifest",
2011
+ installation.manifest,
2012
+ "--wheelhouse",
2013
+ wheelhouse,
2014
+ "--runtime-source",
2015
+ runtimeSource,
2016
+ "--distribution-source",
2017
+ distributionSource,
2018
+ ], { maxBuffer: 16 * 1024 * 1024, stdio, env, windowsHide: true });
2019
+ copyChildOutput(result.stdout);
2020
+ copyChildOutput(result.stderr);
2021
+ if (!result.error && result.status === FLEET_WHEELHOUSE_EXIT.installed)
2022
+ return "installed";
2023
+ if (!result.error && result.status === FLEET_WHEELHOUSE_EXIT.verificationFailed) {
2024
+ throw expectedError(`HQ Fleet Local ${installation.release.version} bundled packages failed verification, so nothing was installed from them. ` +
2025
+ "Retry; if it happens again, report it with `hq bug`.");
2026
+ }
2027
+ return "fallback";
2028
+ }
1888
2029
  /** A FleetLocalSpawn backed by an execFileSync-shaped runner (stderr is only known on failure). */
1889
2030
  export function spawnFromRun(run) {
1890
2031
  return (executable, args, options) => {
@@ -2038,6 +2179,35 @@ export function fleetLocalProviderAuthStatus(agentUid, provider, deps = {}) {
2038
2179
  return null;
2039
2180
  }
2040
2181
  }
2182
+ function execFileText(executable, args, options) {
2183
+ return new Promise((resolve, reject) => {
2184
+ execFile(executable, args, { ...options, encoding: "utf8", windowsHide: true }, (error, stdout) => {
2185
+ if (error)
2186
+ reject(error);
2187
+ else
2188
+ resolve(String(stdout));
2189
+ });
2190
+ });
2191
+ }
2192
+ export async function fleetLocalProviderAuthStatusAsync(agentUid, provider, deps = {}) {
2193
+ let files;
2194
+ try {
2195
+ files = fleetLocalExecutables(agentUid, deps);
2196
+ }
2197
+ catch {
2198
+ return null;
2199
+ }
2200
+ try {
2201
+ const output = await (deps.runAsync ?? execFileText)(files.helper, ["auth", "status", "--profile", files.profileDir, "--bot-id", agentUid, "--provider", provider], { timeout: 15_000 });
2202
+ const status = JSON.parse(output);
2203
+ if (!status || typeof status !== "object" || Array.isArray(status))
2204
+ return null;
2205
+ return { authenticated: status.authenticated === true, ...(typeof status.authType === "string" ? { authType: status.authType } : {}) };
2206
+ }
2207
+ catch {
2208
+ return null;
2209
+ }
2210
+ }
2041
2211
  /** The helper waits this long for a sign-in import before the move counts as failed. */
2042
2212
  const FLEET_PROVIDER_IMPORT_TIMEOUT_MS = 60_000;
2043
2213
  /**
@@ -2127,16 +2297,30 @@ async function installSharedFleetRuntime(installation, root, python, platform, r
2127
2297
  ], { stdio: "ignore", env: uvEnv }, "environment creation");
2128
2298
  const runtimePython = venvExecutable(runtimeDir, "python", platform);
2129
2299
  onProgress?.({ phase: "packages" });
2130
- checkedRun(run, python.uv, [
2131
- "pip",
2132
- "install",
2133
- "--no-config",
2134
- "--python",
2135
- runtimePython,
2136
- "--editable",
2137
- `${runtimeSource}[mcp,anthropic]`,
2138
- distributionSource,
2139
- ], { stdio: ["ignore", 2, 2], env: uvEnv }, "package installation", spawn);
2300
+ const bundled = installation.wheelhouse && installation.environmentPlatform
2301
+ ? installFromWheelhouse(installation, python, runtimePython, runtimeSource, distributionSource, uvEnv, spawn)
2302
+ : "unavailable";
2303
+ if (bundled === "fallback") {
2304
+ fs.rmSync(runtimeDir, { recursive: true, force: true });
2305
+ checkedRun(run, python.uv, [
2306
+ "venv",
2307
+ "--no-config",
2308
+ "--python",
2309
+ python.python,
2310
+ runtimeDir,
2311
+ ], { stdio: "ignore", env: uvEnv }, "environment creation");
2312
+ }
2313
+ if (bundled !== "installed")
2314
+ checkedRun(run, python.uv, [
2315
+ "pip",
2316
+ "install",
2317
+ "--no-config",
2318
+ "--python",
2319
+ runtimePython,
2320
+ "--editable",
2321
+ `${runtimeSource}[mcp,anthropic]`,
2322
+ distributionSource,
2323
+ ], { stdio: ["ignore", 2, 2], env: uvEnv }, "package installation", spawn);
2140
2324
  if (!executables.every((name) => fs.existsSync(venvExecutable(runtimeDir, name, platform)))) {
2141
2325
  throw expectedError("HQ Fleet Local installed without its runtime executables.");
2142
2326
  }
@@ -1,4 +1,5 @@
1
1
  type Exec = (executable: string, args: string[], options: Record<string, unknown>) => Buffer | string;
2
+ type AsyncExec = (executable: string, args: string[], options: Record<string, unknown>) => Promise<void>;
2
3
  export interface FleetPythonToolAsset {
3
4
  name: string;
4
5
  sha256: string;
@@ -14,6 +15,8 @@ export interface FleetPythonDeps {
14
15
  arch?: NodeJS.Architecture;
15
16
  fetch?: typeof fetch;
16
17
  run?: Exec;
18
+ runAsync?: AsyncExec;
19
+ signal?: AbortSignal;
17
20
  tool?: FleetPythonToolPin;
18
21
  pythonVersion?: string;
19
22
  env?: NodeJS.ProcessEnv;
@@ -1,9 +1,10 @@
1
- import { execFileSync } from "node:child_process";
1
+ import { execFile, execFileSync } from "node:child_process";
2
2
  import * as crypto from "node:crypto";
3
3
  import * as fs from "node:fs";
4
4
  import * as path from "node:path";
5
5
  import { fleetHome } from "./fleet-local.js";
6
6
  import { withBotLock } from "./lock.js";
7
+ import { anySignal } from "../../utils/vault-api.js";
7
8
  export const HQ_FLEET_PYTHON_VERSION = "3.13.17";
8
9
  export const HQ_FLEET_PYTHON_TOOL = {
9
10
  repository: "astral-sh/uv",
@@ -37,7 +38,7 @@ function causeOf(error, timeoutMs) {
37
38
  if (error && typeof error === "object") {
38
39
  const failure = error;
39
40
  // A child killed by execFileSync's timeout: say so instead of a bare signal.
40
- if (failure.code === "ETIMEDOUT") {
41
+ if (failure.code === "ETIMEDOUT" || (failure.killed === true && failure.code !== "ABORT_ERR" && timeoutMs !== undefined)) {
41
42
  return timeoutMs !== undefined ? `timed out after ${Math.round(timeoutMs / 1000)}s` : "timed out";
42
43
  }
43
44
  const stderr = failure.stderr === undefined ? "" : (Buffer.isBuffer(failure.stderr) ? failure.stderr.toString("utf8") : String(failure.stderr));
@@ -46,6 +47,8 @@ function causeOf(error, timeoutMs) {
46
47
  return tail;
47
48
  if (typeof failure.status === "number")
48
49
  return `exit code ${failure.status}`;
50
+ if (typeof failure.code === "number")
51
+ return `exit code ${failure.code}`;
49
52
  if (failure.message)
50
53
  return failure.message;
51
54
  }
@@ -121,7 +124,14 @@ async function installTool(deps) {
121
124
  const url = `https://github.com/${tool.repository}/releases/download/${tool.version}/${asset.name}`;
122
125
  let response;
123
126
  try {
124
- response = await fetcher(url, { signal: AbortSignal.timeout(FLEET_PYTHON_TOOL_DOWNLOAD_TIMEOUT_MS) });
127
+ const timeout = AbortSignal.timeout(FLEET_PYTHON_TOOL_DOWNLOAD_TIMEOUT_MS);
128
+ const combined = deps.signal ? anySignal([timeout, deps.signal]) : null;
129
+ try {
130
+ response = await fetcher(url, { signal: combined ? combined.signal : timeout });
131
+ }
132
+ finally {
133
+ combined?.dispose();
134
+ }
125
135
  }
126
136
  catch {
127
137
  throw expectedError("Could not download the HQ Fleet Local runtime installer. Check your internet connection and retry.");
@@ -181,6 +191,25 @@ function isInside(parent, child, platform) {
181
191
  const relative = path.relative(fold(realpathOrSelf(parent)), fold(realpathOrSelf(child)));
182
192
  return relative !== "" && !relative.startsWith("..") && !path.isAbsolute(relative);
183
193
  }
194
+ function runAsync(deps) {
195
+ if (deps.runAsync)
196
+ return deps.runAsync;
197
+ if (deps.run) {
198
+ const run = deps.run;
199
+ return async (executable, args, options) => {
200
+ run(executable, args, options);
201
+ };
202
+ }
203
+ return (executable, args, options) => new Promise((resolve, reject) => {
204
+ const { stdio: _stdio, ...rest } = options;
205
+ execFile(executable, args, { ...rest, encoding: "buffer", maxBuffer: 16 * 1024 * 1024 }, (error) => {
206
+ if (error)
207
+ reject(error);
208
+ else
209
+ resolve();
210
+ });
211
+ });
212
+ }
184
213
  async function ensureFleetPythonLocked(root, deps) {
185
214
  const platform = deps.platform ?? process.platform;
186
215
  const run = deps.run ?? execFileSync;
@@ -190,12 +219,13 @@ async function ensureFleetPythonLocked(root, deps) {
190
219
  const env = fleetUvEnv(pythonDir, deps.env ?? process.env);
191
220
  fs.mkdirSync(pythonDir, { recursive: true, mode: 0o700 });
192
221
  try {
193
- run(uv, ["python", "install", version, "--no-config", "--no-bin", "--no-registry", "--install-dir", pythonDir], {
222
+ await runAsync(deps)(uv, ["python", "install", version, "--no-config", "--no-bin", "--no-registry", "--install-dir", pythonDir], {
194
223
  stdio: ["ignore", "ignore", "pipe"],
195
224
  env,
196
225
  windowsHide: true,
197
226
  timeout: FLEET_PYTHON_INSTALL_TIMEOUT_MS,
198
227
  killSignal: "SIGKILL",
228
+ ...(deps.signal ? { signal: deps.signal } : {}),
199
229
  });
200
230
  }
201
231
  catch (error) {
@@ -0,0 +1,15 @@
1
+ import { type FleetPython } from "./fleet-python.js";
2
+ import type { FleetInstallProgressListener } from "./fleet-local.js";
3
+ export interface FleetRuntimeSources<T> {
4
+ installation: T;
5
+ python: FleetPython;
6
+ }
7
+ export interface FleetRuntimeSourcesDeps {
8
+ onProgress?: FleetInstallProgressListener;
9
+ ensurePython?: (deps: {
10
+ signal: AbortSignal;
11
+ }) => Promise<FleetPython>;
12
+ }
13
+ export declare function installFleetRuntimeSources<T>(distribution: () => Promise<T>, deps?: FleetRuntimeSourcesDeps): Promise<FleetRuntimeSources<T>>;
14
+ export declare function installOptionalFleetRuntimeSources<T>(distribution: () => Promise<T | null>, deps?: FleetRuntimeSourcesDeps): Promise<FleetRuntimeSources<T> | null>;
15
+ //# sourceMappingURL=fleet-runtime-sources.d.ts.map
@@ -0,0 +1,30 @@
1
+ import { ensureFleetPython } from "./fleet-python.js";
2
+ async function withPythonAlongside(distribution, deps) {
3
+ const controller = new AbortController();
4
+ const python = (deps.ensurePython ?? ((options) => ensureFleetPython(options)))({ signal: controller.signal });
5
+ python.catch(() => undefined);
6
+ let installation;
7
+ try {
8
+ installation = await distribution();
9
+ }
10
+ catch (error) {
11
+ controller.abort();
12
+ throw error;
13
+ }
14
+ if (installation === null) {
15
+ controller.abort();
16
+ return null;
17
+ }
18
+ deps.onProgress?.({ phase: "python" });
19
+ return { installation, python: await python };
20
+ }
21
+ export async function installFleetRuntimeSources(distribution, deps = {}) {
22
+ const sources = await withPythonAlongside(distribution, deps);
23
+ if (!sources)
24
+ throw new Error("HQ Fleet Local installed no distribution.");
25
+ return sources;
26
+ }
27
+ export async function installOptionalFleetRuntimeSources(distribution, deps = {}) {
28
+ return withPythonAlongside(distribution, deps);
29
+ }
30
+ //# sourceMappingURL=fleet-runtime-sources.js.map
@@ -27,6 +27,14 @@ export interface GrokLoginProbeDeps {
27
27
  /** The helper asks the keychain per profile, so one list of bots shares a scan this long. */
28
28
  export declare const GROK_HOLDER_SCAN_TTL_MS = 30000;
29
29
  export declare function resetGrokHolderScan(): void;
30
+ export interface GrokLoginProbeAsyncDeps {
31
+ profiles?: () => Array<{
32
+ agentUid: string;
33
+ profileDir: string;
34
+ }>;
35
+ status?: (agentUid: string) => Promise<FleetLocalProviderAuthStatus | null>;
36
+ }
37
+ export declare function grokLoginReadableHereAsync(exclude: string, deps?: GrokLoginProbeAsyncDeps): Promise<LegacyProviderLogin>;
30
38
  /** Mirrors the helper's `_existing_machine_oauth`: another Fleet bot here holds a Grok OAuth login. */
31
39
  export declare function grokLoginReadableHere(exclude: string, deps?: GrokLoginProbeDeps, now?: number): LegacyProviderLogin;
32
40
  export declare const GROK_CLI_AUTH_ISSUER = "https://auth.x.ai";
@@ -19,7 +19,7 @@
19
19
  import * as fs from "node:fs";
20
20
  import * as os from "node:os";
21
21
  import * as path from "node:path";
22
- import { cachedFleetLocalTargetRelease, fleetLocalProviderAuthStatus, fleetReleaseImportsGrokCli, listFleetLocalProfiles } from "./fleet-local.js";
22
+ import { cachedFleetLocalTargetRelease, fleetLocalProviderAuthStatus, fleetLocalProviderAuthStatusAsync, fleetReleaseImportsGrokCli, listFleetLocalProfiles } from "./fleet-local.js";
23
23
  import { botOwnAuthHome, botRuntimeAuth, capacityAccountHome } from "./runtime-auth.js";
24
24
  export function codexCliAuthPath(home) {
25
25
  return path.join(home, "auth.json");
@@ -111,9 +111,26 @@ function grokHolders(deps, now) {
111
111
  grokHolderScan = scan;
112
112
  return scan;
113
113
  }
114
+ export async function grokLoginReadableHereAsync(exclude, deps = {}) {
115
+ const profiles = (deps.profiles ?? listFleetLocalProfiles)();
116
+ const status = deps.status ?? ((agentUid) => fleetLocalProviderAuthStatusAsync(agentUid, "xai-oauth"));
117
+ const answers = await Promise.all(profiles.map((profile) => status(profile.agentUid)));
118
+ const holders = [];
119
+ const unanswered = [];
120
+ answers.forEach((found, index) => {
121
+ const agentUid = profiles[index].agentUid;
122
+ if (found === null)
123
+ unanswered.push(agentUid);
124
+ else if (found.authenticated && found.authType === "oauth")
125
+ holders.push(agentUid);
126
+ });
127
+ return grokLoginFromScan({ holders, uids: profiles.map((profile) => profile.agentUid), unanswered }, exclude);
128
+ }
114
129
  /** Mirrors the helper's `_existing_machine_oauth`: another Fleet bot here holds a Grok OAuth login. */
115
130
  export function grokLoginReadableHere(exclude, deps = {}, now = Date.now()) {
116
- const scan = grokHolders(deps, now);
131
+ return grokLoginFromScan(grokHolders(deps, now), exclude);
132
+ }
133
+ function grokLoginFromScan(scan, exclude) {
117
134
  const other = (agentUid) => agentUid.toLowerCase() !== exclude.toLowerCase();
118
135
  const holder = scan.holders.find(other);
119
136
  if (holder)
@@ -294,7 +294,7 @@ export function botKindParagraph(input) {
294
294
  }
295
295
  const ownerContext = input.fleetRuntime
296
296
  ? `The runtime labels every message with the sender's HQ identity: messages from ${input.ownerUid} are your owner's, and only those carry your owner's authority. ` +
297
- `When you need to know which companies your owner belongs to, run \`hq whoami\` yourself; never guess. ` +
297
+ `When you need to know which companies your owner belongs to, call the hq_companies_list tool yourself; \`hq whoami\` does not list companies. Never guess. ` +
298
298
  `Other people read your answers in rooms: in a room, never state which companies your owner belongs to, and never repeat anything from their files or your DMs.`
299
299
  : `Direct messages from your owner start with an "Owner context" block checked with your owner's own sign-in; that is the only source for your owner's companies. ` +
300
300
  `If it says the check failed, say you could not check; never say your owner has no company unless that block says so. ` +
@@ -1,4 +1,5 @@
1
1
  import { type FleetLocalGatewayState } from "./fleet-local.js";
2
+ import { type BotStatusFile } from "./status.js";
2
3
  export type BotReadiness = "creating" | "installing" | "starting" | "ready" | "offline";
3
4
  export declare const BOT_READINESS_VALUES: readonly BotReadiness[];
4
5
  export type BotSetupStep = "identity" | "install" | "starting" | "ready";
@@ -22,7 +23,12 @@ export interface ReadinessFacts {
22
23
  processAlive: boolean;
23
24
  livePid?: number | null;
24
25
  gateway: Pick<FleetLocalGatewayState, "gatewayState" | "ready" | "pid"> | null;
26
+ status?: Pick<BotStatusFile, "pid" | "ready"> | null;
27
+ statusCarriesReady?: boolean;
25
28
  }
29
+ export declare const FLEET_STATUS_READY_MIN_VERSION = "0.4.30";
30
+ export declare function fleetStatusCarriesReady(engineVersion: string | null | undefined): boolean;
31
+ export declare function fleetGatewayReadyForChat(gateway: Pick<FleetLocalGatewayState, "gatewayState" | "ready" | "pid"> | null, status: Pick<BotStatusFile, "pid" | "ready"> | null | undefined, statusCarriesReady: boolean): boolean;
26
32
  export declare function deriveBotReadiness(facts: ReadinessFacts): BotReadiness;
27
33
  export interface BotReadinessReport {
28
34
  readiness: BotReadiness;
@@ -51,6 +57,8 @@ export declare function waitForGatewayReady(agentUid: string, opts: {
51
57
  now?: () => number;
52
58
  sleep?: (ms: number) => Promise<void>;
53
59
  alive?: (pid: number) => boolean;
60
+ botDir?: string;
61
+ statusCarriesReady?: boolean;
54
62
  }): Promise<ReadyWaitResult>;
55
63
  export type SetupStepStatus = "pending" | "active" | "done" | "skipped" | "timeout" | "failed";
56
64
  export interface SetupStepRecord {
@@ -1,7 +1,8 @@
1
1
  import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
3
  import { readFleetLocalGatewayState } from "./fleet-local.js";
4
- import { isPidAlive } from "./status.js";
4
+ import semver from "semver";
5
+ import { isPidAlive, readBotStatus } from "./status.js";
5
6
  export const BOT_READINESS_VALUES = ["creating", "installing", "starting", "ready", "offline"];
6
7
  export const BOT_SETUP_STEPS = [
7
8
  { step: "install", label: "Installing on this Mac" },
@@ -52,6 +53,18 @@ export function readBotSetupStep(dir, alive = isPidAlive) {
52
53
  return null;
53
54
  return BOT_SETUP_STEPS.some((entry) => entry.step === marker.step) ? marker.step : null;
54
55
  }
56
+ export const FLEET_STATUS_READY_MIN_VERSION = "0.4.30";
57
+ export function fleetStatusCarriesReady(engineVersion) {
58
+ const version = semver.coerce(engineVersion ?? "");
59
+ return version !== null && semver.gte(version, FLEET_STATUS_READY_MIN_VERSION);
60
+ }
61
+ export function fleetGatewayReadyForChat(gateway, status, statusCarriesReady) {
62
+ if (!gateway || gateway.gatewayState !== "running" || !gateway.ready)
63
+ return false;
64
+ if (!statusCarriesReady)
65
+ return true;
66
+ return status !== null && status !== undefined && status.pid === gateway.pid && status.ready === true;
67
+ }
55
68
  export function deriveBotReadiness(facts) {
56
69
  if (facts.setupStep === "identity")
57
70
  return "creating";
@@ -62,7 +75,7 @@ export function deriveBotReadiness(facts) {
62
75
  if (!facts.fleet)
63
76
  return "ready";
64
77
  const current = facts.livePid === undefined || facts.livePid === null || facts.gateway?.pid === facts.livePid;
65
- if (current && facts.gateway?.gatewayState === "running" && facts.gateway.ready)
78
+ if (current && fleetGatewayReadyForChat(facts.gateway, facts.status, facts.statusCarriesReady === true))
66
79
  return "ready";
67
80
  return "starting";
68
81
  }
@@ -86,7 +99,8 @@ export async function waitForGatewayReady(agentUid, opts) {
86
99
  const running = gateway !== null && gateway.pid !== null && alive(gateway.pid);
87
100
  if (running)
88
101
  seenPid = gateway.pid;
89
- if (running && gateway.gatewayState === "running" && gateway.ready) {
102
+ const status = opts.botDir ? readBotStatus(opts.botDir) : null;
103
+ if (running && fleetGatewayReadyForChat(gateway, status, opts.statusCarriesReady === true)) {
90
104
  return { ready: true, readyAt: gateway.readyAt, timedOut: false, failed: null, waitedMs: now() - started };
91
105
  }
92
106
  if (running && gateway.gatewayState === "startup_failed") {