@indigoai-us/hq-cli 5.345.212 → 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.
- package/CHANGELOG.md +49 -0
- package/dist/bin/hq-auth-refresh.js +2 -1
- package/dist/command-catalog.generated.d.ts +442 -50
- package/dist/command-catalog.generated.js +541 -50
- package/dist/commands/agent-inbox.d.ts +11 -1
- package/dist/commands/agent-inbox.js +128 -38
- package/dist/commands/agent-kit.js +2 -2
- package/dist/commands/agents.d.ts +51 -1
- package/dist/commands/agents.js +154 -2
- package/dist/commands/bot-jobs.d.ts +2 -15
- package/dist/commands/bot-jobs.js +2 -94
- package/dist/commands/bot-runtime.d.ts +46 -5
- package/dist/commands/bot-runtime.js +228 -18
- package/dist/commands/bot.d.ts +16 -9
- package/dist/commands/bot.js +169 -51
- package/dist/commands/cloud.d.ts +66 -13
- package/dist/commands/cloud.js +120 -39
- package/dist/commands/company-restore.d.ts +23 -0
- package/dist/commands/company-restore.js +128 -0
- package/dist/commands/company.js +2 -0
- package/dist/commands/core-handoff.js +1 -0
- package/dist/commands/core-hq-session-native.js +2 -2
- package/dist/commands/core-pin-native.js +1 -1
- package/dist/commands/core-policy.js +1 -1
- package/dist/commands/core-resolve-company-native.js +1 -1
- package/dist/commands/core-sentry-report-fast.d.ts +2 -0
- package/dist/commands/core-sentry-report-fast.js +3 -1
- package/dist/commands/daemon.js +11 -1
- package/dist/commands/integrations-connect.d.ts +17 -4
- package/dist/commands/integrations-connect.js +224 -26
- package/dist/commands/lanes-link.js +10 -5
- package/dist/commands/lanes.js +26 -9
- package/dist/commands/rescue.js +13 -0
- package/dist/commands/secrets.d.ts +11 -0
- package/dist/commands/secrets.js +41 -7
- package/dist/commands/sources.js +6 -0
- package/dist/commands/storage-offload.d.ts +12 -0
- package/dist/commands/storage-offload.js +41 -3
- package/dist/commands/sync-mode.js +5 -0
- package/dist/commands/whoami.js +4 -0
- package/dist/index.js +2 -0
- package/dist/lazy-commands.js +2 -0
- package/dist/lib/agent-kit/inbox-fetch.d.ts +122 -1
- package/dist/lib/agent-kit/inbox-fetch.js +215 -3
- package/dist/lib/agent-kit/inbox-redact.js +1 -1
- package/dist/lib/agent-kit/inbox-state.d.ts +98 -1
- package/dist/lib/agent-kit/inbox-state.js +261 -4
- package/dist/lib/agent-kit/mcp/tools.d.ts +3 -3
- package/dist/lib/agent-kit/mcp/tools.js +68 -25
- package/dist/lib/agent-kit/run/inbox.js +4 -2
- package/dist/lib/agent-kit/skills.js +4 -1
- package/dist/lib/agent-kit/wake.d.ts +9 -1
- package/dist/lib/agent-kit/wake.js +10 -3
- package/dist/lib/bot/config.d.ts +1 -0
- package/dist/lib/bot/config.js +10 -0
- package/dist/lib/bot/eventbridge-cron.d.ts +22 -0
- package/dist/lib/bot/eventbridge-cron.js +104 -0
- package/dist/lib/bot/fleet-cron.js +193 -14
- package/dist/lib/bot/fleet-download.d.ts +2 -0
- package/dist/lib/bot/fleet-download.js +23 -0
- package/dist/lib/bot/fleet-local.d.ts +34 -1
- package/dist/lib/bot/fleet-local.js +254 -37
- package/dist/lib/bot/fleet-python.d.ts +3 -0
- package/dist/lib/bot/fleet-python.js +34 -4
- package/dist/lib/bot/fleet-runtime-sources.d.ts +15 -0
- package/dist/lib/bot/fleet-runtime-sources.js +30 -0
- package/dist/lib/bot/legacy-provider-login.d.ts +8 -0
- package/dist/lib/bot/legacy-provider-login.js +19 -2
- package/dist/lib/bot/prompt.js +1 -1
- package/dist/lib/bot/readiness.d.ts +8 -0
- package/dist/lib/bot/readiness.js +17 -3
- package/dist/lib/bot/runtime-auth.d.ts +30 -0
- package/dist/lib/bot/runtime-auth.js +94 -3
- package/dist/lib/bot/status.d.ts +2 -0
- package/dist/lib/capacity/collectors/grok-refresh.d.ts +80 -0
- package/dist/lib/capacity/collectors/grok-refresh.js +189 -0
- package/dist/lib/capacity/collectors/grok.d.ts +5 -0
- package/dist/lib/capacity/collectors/grok.js +56 -5
- package/dist/lib/core-utils/session-id.d.ts +1 -1
- package/dist/lib/core-utils/session-id.js +4 -0
- package/dist/lib/daemon/catalog.js +11 -1
- package/dist/lib/daemon/run.js +9 -1
- package/dist/lib/daemon/updater.d.ts +34 -2
- package/dist/lib/daemon/updater.js +51 -2
- package/dist/lib/db/sqlite-binding.d.ts +1 -0
- package/dist/lib/db/sqlite-binding.js +1 -1
- package/dist/lib/delivery/artifacts.d.ts +99 -0
- package/dist/lib/delivery/artifacts.js +548 -0
- package/dist/lib/delivery/backup.d.ts +78 -0
- package/dist/lib/delivery/backup.js +343 -0
- package/dist/lib/delivery/cache.d.ts +29 -0
- package/dist/lib/delivery/cache.js +33 -0
- package/dist/lib/delivery/contracts.d.ts +142 -0
- package/dist/lib/delivery/contracts.js +289 -0
- package/dist/lib/delivery/credentials.d.ts +54 -0
- package/dist/lib/delivery/credentials.js +119 -0
- package/dist/lib/delivery/enrollment.d.ts +142 -0
- package/dist/lib/delivery/enrollment.js +382 -0
- package/dist/lib/delivery/identity.d.ts +25 -0
- package/dist/lib/delivery/identity.js +82 -0
- package/dist/lib/delivery/inbox.d.ts +116 -0
- package/dist/lib/delivery/inbox.js +260 -0
- package/dist/lib/delivery/migrations.d.ts +139 -0
- package/dist/lib/delivery/migrations.js +623 -0
- package/dist/lib/delivery/mqtt-adapter.d.ts +50 -0
- package/dist/lib/delivery/mqtt-adapter.js +242 -0
- package/dist/lib/delivery/mqtt.d.ts +61 -0
- package/dist/lib/delivery/mqtt.js +112 -0
- package/dist/lib/delivery/outbox.d.ts +95 -0
- package/dist/lib/delivery/outbox.js +187 -0
- package/dist/lib/delivery/provenance.d.ts +129 -0
- package/dist/lib/delivery/provenance.js +93 -0
- package/dist/lib/delivery/reconciler.d.ts +151 -0
- package/dist/lib/delivery/reconciler.js +492 -0
- package/dist/lib/delivery/restore.d.ts +35 -0
- package/dist/lib/delivery/restore.js +134 -0
- package/dist/lib/delivery/store.d.ts +161 -0
- package/dist/lib/delivery/store.js +940 -0
- package/dist/lib/delivery/workers/macos-job-helper.d.ts +103 -0
- package/dist/lib/delivery/workers/macos-job-helper.js +927 -0
- package/dist/lib/delivery/workers/macos.d.ts +176 -0
- package/dist/lib/delivery/workers/macos.js +901 -0
- package/dist/lib/delivery/workers/windows-boundary.d.ts +453 -0
- package/dist/lib/delivery/workers/windows-boundary.js +693 -0
- package/dist/lib/delivery/workers/windows-job-helper.d.ts +35 -0
- package/dist/lib/delivery/workers/windows-job-helper.js +264 -0
- package/dist/lib/delivery/workers/windows.d.ts +241 -0
- package/dist/lib/delivery/workers/windows.js +608 -0
- package/dist/lib/doctor/checks/release-links.d.ts +50 -8
- package/dist/lib/doctor/checks/release-links.js +260 -24
- package/dist/lib/doctor/fix/apply.js +24 -8
- package/dist/lib/doctor/fix/remediation.js +15 -5
- package/dist/lib/install/provider-wrappers.d.ts +2 -0
- package/dist/lib/install/provider-wrappers.js +68 -3
- package/dist/lib/lanes/autopilot-registry.d.ts +14 -0
- package/dist/lib/lanes/autopilot-registry.js +59 -7
- package/dist/lib/lanes/links.d.ts +14 -0
- package/dist/lib/lanes/links.js +320 -25
- package/dist/lib/lanes/outpost-pruner-install.d.ts +10 -0
- package/dist/lib/lanes/outpost-pruner-install.js +4 -3
- package/dist/main.js +3 -1
- package/dist/sentry-init.d.ts +2 -0
- package/dist/sentry-init.js +13 -2
- package/dist/sentry.d.ts +2 -0
- package/dist/sentry.js +5 -1
- package/dist/utils/cli-network-lifecycle.d.ts +9 -0
- package/dist/utils/cli-network-lifecycle.js +52 -0
- package/dist/utils/cognito-callback-port.d.ts +14 -0
- package/dist/utils/cognito-callback-port.js +24 -0
- package/dist/utils/cognito-session.js +3 -3
- package/dist/utils/deleted-company-notice.d.ts +59 -0
- package/dist/utils/deleted-company-notice.js +156 -0
- package/dist/utils/login-browser.d.ts +1 -1
- package/dist/utils/login-browser.js +7 -5
- package/dist/utils/resident-package-preload.js +30 -15
- package/dist/utils/safe-link.d.ts +63 -0
- package/dist/utils/safe-link.js +246 -0
- package/dist/utils/sentry-keepalive-transport.d.ts +28 -0
- package/dist/utils/sentry-keepalive-transport.js +70 -0
- package/dist/utils/vault-api.js +7 -0
- 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";
|
|
@@ -7,7 +7,7 @@ import * as zlib from "node:zlib";
|
|
|
7
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
|
-
import {
|
|
10
|
+
import { downloadFleetFileFromSources, fileSha256 } from "./fleet-download.js";
|
|
11
11
|
import { ensureFleetPython, fleetUvEnv } from "./fleet-python.js";
|
|
12
12
|
import semver from "semver";
|
|
13
13
|
import { CLI_VERSION } from "../../cli-version.js";
|
|
@@ -421,8 +421,11 @@ export async function lookupHqFleetReleaseLinks(release, deps = {}) {
|
|
|
421
421
|
const body = (await response.json());
|
|
422
422
|
const links = new Map();
|
|
423
423
|
for (const asset of body.assets ?? []) {
|
|
424
|
-
if (typeof asset.name === "string" && typeof asset.url === "string")
|
|
424
|
+
if (typeof asset.name === "string" && typeof asset.url === "string") {
|
|
425
425
|
links.set(asset.name, asset.url);
|
|
426
|
+
if (typeof asset.cdnUrl === "string")
|
|
427
|
+
links.set(fleetReleaseCdnLinkName(asset.name), asset.cdnUrl);
|
|
428
|
+
}
|
|
426
429
|
}
|
|
427
430
|
return links.size > 0 ? { links, reason: null } : { links: null, reason: "not_published" };
|
|
428
431
|
}
|
|
@@ -534,7 +537,51 @@ export function parseFleetLocalReleasePin(value) {
|
|
|
534
537
|
if (![pin.artifactSha256, pin.runtimeArtifactSha256, pin.manifestSha256, pin.signatureSha256].every((hash) => SHA256_RE.test(hash))) {
|
|
535
538
|
return null;
|
|
536
539
|
}
|
|
537
|
-
|
|
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
|
+
}
|
|
538
585
|
}
|
|
539
586
|
export function parseFleetLocalReleasePointer(body, now = Date.now()) {
|
|
540
587
|
if (!body || typeof body !== "object" || Array.isArray(body))
|
|
@@ -551,8 +598,11 @@ export function parseFleetLocalReleasePointer(body, now = Date.now()) {
|
|
|
551
598
|
const links = new Map();
|
|
552
599
|
for (const asset of Array.isArray(record.assets) ? record.assets : []) {
|
|
553
600
|
const entry = asset;
|
|
554
|
-
if (typeof entry?.name === "string" && typeof entry.url === "string")
|
|
601
|
+
if (typeof entry?.name === "string" && typeof entry.url === "string") {
|
|
555
602
|
links.set(entry.name, entry.url);
|
|
603
|
+
if (typeof entry.cdnUrl === "string")
|
|
604
|
+
links.set(fleetReleaseCdnLinkName(entry.name), entry.cdnUrl);
|
|
605
|
+
}
|
|
556
606
|
}
|
|
557
607
|
const expires = typeof record.expiresInSeconds === "number" && record.expiresInSeconds > 0 ? record.expiresInSeconds : 0;
|
|
558
608
|
return {
|
|
@@ -712,6 +762,21 @@ function trustedReleaseLink(url) {
|
|
|
712
762
|
return false;
|
|
713
763
|
}
|
|
714
764
|
}
|
|
765
|
+
export function fleetReleaseCdnLinkName(name) {
|
|
766
|
+
return `cdn:${name}`;
|
|
767
|
+
}
|
|
768
|
+
function trustedReleaseCdnLink(url) {
|
|
769
|
+
try {
|
|
770
|
+
const parsed = new URL(url);
|
|
771
|
+
return parsed.protocol === "https:" && parsed.hostname.endsWith(".cloudfront.net");
|
|
772
|
+
}
|
|
773
|
+
catch {
|
|
774
|
+
return false;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
function releaseCdnDisabled(env = process.env) {
|
|
778
|
+
return env.HQ_FLEET_RELEASE_CDN?.trim().toLowerCase() === "off";
|
|
779
|
+
}
|
|
715
780
|
export const FLEET_LOCAL_METADATA_DOWNLOAD_TIMEOUT_MS = 30_000;
|
|
716
781
|
/** One machine-wide lock: concurrent creates and adopts share one download instead of repeating it. */
|
|
717
782
|
export const FLEET_LOCAL_DISTRIBUTION_LOCK_NAME = "hq-fleet-local-distribution";
|
|
@@ -735,10 +800,17 @@ function discardDownloads(target) {
|
|
|
735
800
|
return;
|
|
736
801
|
}
|
|
737
802
|
}
|
|
738
|
-
async function downloadReleaseFiles(release, fetcher, resolve, cachedRuntime, target, onProgress, stallMs) {
|
|
803
|
+
async function downloadReleaseFiles(release, fetcher, resolve, cachedRuntime, target, onProgress, stallMs, wheelhouse = null) {
|
|
739
804
|
fs.mkdirSync(target, { recursive: true, mode: 0o700 });
|
|
805
|
+
const pinned = new Map([
|
|
806
|
+
[release.artifact, release.artifactSha256],
|
|
807
|
+
[release.runtimeArtifact, release.runtimeArtifactSha256],
|
|
808
|
+
["release-manifest.json", release.manifestSha256],
|
|
809
|
+
["release-manifest.sig", release.signatureSha256],
|
|
810
|
+
...(wheelhouse ? [[wheelhouse.name, wheelhouse.sha256]] : []),
|
|
811
|
+
]);
|
|
740
812
|
const downloaded = new Map();
|
|
741
|
-
const wanted = RELEASE_FILE_NAMES(release).filter((name) => {
|
|
813
|
+
const wanted = [...RELEASE_FILE_NAMES(release), ...(wheelhouse ? [wheelhouse.name] : [])].filter((name) => {
|
|
742
814
|
if (name === release.runtimeArtifact && cachedRuntime) {
|
|
743
815
|
downloaded.set(name, cachedRuntime);
|
|
744
816
|
return false;
|
|
@@ -747,7 +819,8 @@ async function downloadReleaseFiles(release, fetcher, resolve, cachedRuntime, ta
|
|
|
747
819
|
});
|
|
748
820
|
const sources = wanted.map((name) => ({ name, ...resolve(name) }));
|
|
749
821
|
onProgress?.({ phase: "download-start", files: wanted.length });
|
|
750
|
-
await Promise.all(sources.map(async ({ name,
|
|
822
|
+
await Promise.all(sources.map(async ({ name, urls, headers }) => {
|
|
823
|
+
const url = urls.at(-1);
|
|
751
824
|
if (url.startsWith("file:")) {
|
|
752
825
|
const destination = path.join(target, name);
|
|
753
826
|
fs.copyFileSync(fileURLToPath(url), destination);
|
|
@@ -756,12 +829,12 @@ async function downloadReleaseFiles(release, fetcher, resolve, cachedRuntime, ta
|
|
|
756
829
|
downloaded.set(name, destination);
|
|
757
830
|
return;
|
|
758
831
|
}
|
|
759
|
-
const file = await
|
|
832
|
+
const file = await downloadFleetFileFromSources(urls, path.join(target, name), {
|
|
760
833
|
fetch: fetcher,
|
|
761
834
|
...(headers ? { headers } : {}),
|
|
762
835
|
...(stallMs !== undefined ? { stallMs } : {}),
|
|
763
836
|
onProgress: (progress) => onProgress?.({ phase: "download", file: name, received: progress.received, total: progress.total }),
|
|
764
|
-
});
|
|
837
|
+
}, (candidate) => fileSha256(candidate) === pinned.get(name));
|
|
765
838
|
downloaded.set(name, file);
|
|
766
839
|
}));
|
|
767
840
|
return {
|
|
@@ -769,10 +842,12 @@ async function downloadReleaseFiles(release, fetcher, resolve, cachedRuntime, ta
|
|
|
769
842
|
runtimeArchive: fs.readFileSync(downloaded.get(release.runtimeArtifact)),
|
|
770
843
|
manifest: fs.readFileSync(downloaded.get("release-manifest.json")),
|
|
771
844
|
signature: fs.readFileSync(downloaded.get("release-manifest.sig")),
|
|
845
|
+
...(wheelhouse ? { wheelhouse: downloaded.get(wheelhouse.name) } : {}),
|
|
772
846
|
};
|
|
773
847
|
}
|
|
774
|
-
async function downloadFleetLocalReleaseFromHq(release, fetcher, links, cachedRuntime, target, onProgress, stallMs, allowFileLinks = false) {
|
|
775
|
-
|
|
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] : [])]) {
|
|
776
851
|
if (name === release.runtimeArtifact && cachedRuntime)
|
|
777
852
|
continue;
|
|
778
853
|
const url = links.get(name);
|
|
@@ -782,9 +857,14 @@ async function downloadFleetLocalReleaseFromHq(release, fetcher, links, cachedRu
|
|
|
782
857
|
throw expectedError(`HQ Fleet Local ${release.tag} returned an untrusted download link for ${name}.`);
|
|
783
858
|
}
|
|
784
859
|
}
|
|
785
|
-
|
|
860
|
+
const cdnUsable = !releaseCdnDisabled();
|
|
861
|
+
return downloadReleaseFiles(release, fetcher, (name) => {
|
|
862
|
+
const cdn = cdnUsable ? links.get(fleetReleaseCdnLinkName(name)) : undefined;
|
|
863
|
+
const candidates = cdn && trustedReleaseCdnLink(cdn) ? [cdn] : [];
|
|
864
|
+
return { urls: [...candidates, links.get(name)] };
|
|
865
|
+
}, cachedRuntime, target, onProgress, stallMs, bundle);
|
|
786
866
|
}
|
|
787
|
-
async function downloadFleetLocalRelease(release, fetcher, token, cachedRuntime, target, onProgress, stallMs) {
|
|
867
|
+
async function downloadFleetLocalRelease(release, fetcher, token, cachedRuntime, target, onProgress, stallMs, wheelhouse = null) {
|
|
788
868
|
const headers = {
|
|
789
869
|
Accept: "application/vnd.github+json",
|
|
790
870
|
Authorization: `Bearer ${token}`,
|
|
@@ -800,7 +880,8 @@ async function downloadFleetLocalRelease(release, fetcher, token, cachedRuntime,
|
|
|
800
880
|
const assets = new Map((body.assets ?? [])
|
|
801
881
|
.filter((asset) => !!asset.name && !!asset.url)
|
|
802
882
|
.map((asset) => [asset.name, asset.url]));
|
|
803
|
-
|
|
883
|
+
const bundle = wheelhouse && assets.has(wheelhouse.name) ? wheelhouse : null;
|
|
884
|
+
for (const name of [...RELEASE_FILE_NAMES(release), ...(bundle ? [bundle.name] : [])]) {
|
|
804
885
|
if (name === release.runtimeArtifact && cachedRuntime)
|
|
805
886
|
continue;
|
|
806
887
|
const url = assets.get(name);
|
|
@@ -810,7 +891,7 @@ async function downloadFleetLocalRelease(release, fetcher, token, cachedRuntime,
|
|
|
810
891
|
throw expectedError(`HQ Fleet Local ${release.tag} returned an untrusted asset URL for ${name}.`);
|
|
811
892
|
}
|
|
812
893
|
}
|
|
813
|
-
return downloadReleaseFiles(release, fetcher, (name) => ({
|
|
894
|
+
return downloadReleaseFiles(release, fetcher, (name) => ({ urls: [assets.get(name)], headers: { ...headers, Accept: "application/octet-stream" } }), cachedRuntime, target, onProgress, stallMs, bundle);
|
|
814
895
|
}
|
|
815
896
|
function installedFiles(dir, release) {
|
|
816
897
|
const archive = path.join(dir, release.artifact);
|
|
@@ -837,6 +918,8 @@ function installFiles(target, files, release, publicKey) {
|
|
|
837
918
|
fs.writeFileSync(path.join(staging, release.runtimeArtifact), files.runtimeArchive, { mode: 0o644 });
|
|
838
919
|
fs.writeFileSync(path.join(staging, "release-manifest.json"), files.manifest, { mode: 0o644 });
|
|
839
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)));
|
|
840
923
|
fs.writeFileSync(path.join(staging, "release-public.pem"), publicKeyList(publicKey).join(""), { mode: 0o644 });
|
|
841
924
|
fs.writeFileSync(path.join(staging, "install.json"), `${JSON.stringify({ schemaVersion: 1, release, engine: engineMetadata(release) }, null, 2)}\n`, { mode: 0o644 });
|
|
842
925
|
if (fs.existsSync(target))
|
|
@@ -904,20 +987,32 @@ export async function installPinnedFleetLocalDistribution(deps = {}) {
|
|
|
904
987
|
const root = deps.fleetHome ?? fleetHome();
|
|
905
988
|
const dir = path.join(root, "distributions", "hq-fleet-local", release.version);
|
|
906
989
|
const onProgress = deps.onProgress;
|
|
990
|
+
const environmentPlatform = fleetEnvironmentPlatform(deps.platform ?? process.platform, deps.arch ?? process.arch);
|
|
991
|
+
const wheelhouse = releaseWheelhouse(release, environmentPlatform);
|
|
907
992
|
const warnCompatibility = (manifest) => {
|
|
908
993
|
const warning = fleetLocalCliCompatibilityWarning(manifest, release);
|
|
909
994
|
if (warning)
|
|
910
995
|
process.stderr.write(`Warning: ${warning}\n`);
|
|
911
996
|
};
|
|
912
|
-
const
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
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
|
+
};
|
|
921
1016
|
const current = filesMatchPin(installedFiles(dir, release), release);
|
|
922
1017
|
if (current) {
|
|
923
1018
|
verifyFleetLocalRelease(current, release, publicKey);
|
|
@@ -942,7 +1037,7 @@ export async function installPinnedFleetLocalDistribution(deps = {}) {
|
|
|
942
1037
|
const target = downloadsDir(root, release);
|
|
943
1038
|
let files;
|
|
944
1039
|
if (links) {
|
|
945
|
-
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);
|
|
946
1041
|
}
|
|
947
1042
|
else {
|
|
948
1043
|
let githubToken;
|
|
@@ -952,11 +1047,13 @@ export async function installPinnedFleetLocalDistribution(deps = {}) {
|
|
|
952
1047
|
catch (error) {
|
|
953
1048
|
throw noReleaseSourceError(release, lookup.reason) ?? error;
|
|
954
1049
|
}
|
|
955
|
-
files = await downloadFleetLocalRelease(release, fetcher, githubToken, cachedRuntime, target, onProgress, deps.downloadStallMs);
|
|
1050
|
+
files = await downloadFleetLocalRelease(release, fetcher, githubToken, cachedRuntime, target, onProgress, deps.downloadStallMs, wheelhouse);
|
|
956
1051
|
}
|
|
957
1052
|
onProgress?.({ phase: "verify" });
|
|
958
1053
|
try {
|
|
959
1054
|
verifyFleetLocalRelease(files, release, publicKey);
|
|
1055
|
+
if (files.wheelhouse && wheelhouse)
|
|
1056
|
+
verifyFleetLocalWheelhouse(files.wheelhouse, wheelhouse, files.manifest, environmentPlatform, release);
|
|
960
1057
|
}
|
|
961
1058
|
catch (error) {
|
|
962
1059
|
discardDownloads(target);
|
|
@@ -1615,6 +1712,42 @@ export function writeFleetLocalFirstStart(profileDir, firstStart) {
|
|
|
1615
1712
|
fs.renameSync(temporary, destination);
|
|
1616
1713
|
return destination;
|
|
1617
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
|
+
}
|
|
1618
1751
|
export function writeFleetLocalSoul(agentUid, systemPrompt, deps = {}) {
|
|
1619
1752
|
if (!/^agt_[A-Za-z0-9_-]+$/.test(agentUid)) {
|
|
1620
1753
|
throw expectedError(`Cannot use an HQ Fleet profile for invalid bot id ${agentUid}.`);
|
|
@@ -1852,6 +1985,47 @@ function checkedRun(run, executable, args, options, label, spawn) {
|
|
|
1852
1985
|
throw expectedError(`HQ Fleet Local ${label} failed.${tail ? `\n${tail}` : ""}`);
|
|
1853
1986
|
}
|
|
1854
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
|
+
}
|
|
1855
2029
|
/** A FleetLocalSpawn backed by an execFileSync-shaped runner (stderr is only known on failure). */
|
|
1856
2030
|
export function spawnFromRun(run) {
|
|
1857
2031
|
return (executable, args, options) => {
|
|
@@ -2005,6 +2179,35 @@ export function fleetLocalProviderAuthStatus(agentUid, provider, deps = {}) {
|
|
|
2005
2179
|
return null;
|
|
2006
2180
|
}
|
|
2007
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
|
+
}
|
|
2008
2211
|
/** The helper waits this long for a sign-in import before the move counts as failed. */
|
|
2009
2212
|
const FLEET_PROVIDER_IMPORT_TIMEOUT_MS = 60_000;
|
|
2010
2213
|
/**
|
|
@@ -2094,16 +2297,30 @@ async function installSharedFleetRuntime(installation, root, python, platform, r
|
|
|
2094
2297
|
], { stdio: "ignore", env: uvEnv }, "environment creation");
|
|
2095
2298
|
const runtimePython = venvExecutable(runtimeDir, "python", platform);
|
|
2096
2299
|
onProgress?.({ phase: "packages" });
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
"
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
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);
|
|
2107
2324
|
if (!executables.every((name) => fs.existsSync(venvExecutable(runtimeDir, name, platform)))) {
|
|
2108
2325
|
throw expectedError("HQ Fleet Local installed without its runtime executables.");
|
|
2109
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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)
|
package/dist/lib/bot/prompt.js
CHANGED
|
@@ -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,
|
|
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. ` +
|