@indigoai-us/hq-cli 5.345.199 → 5.345.201
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 +40 -0
- package/assets/scaffold/core/scripts/lib/session-scope-capability.sh +6 -4
- package/dist/command-catalog.generated.d.ts +44 -0
- package/dist/command-catalog.generated.js +52 -0
- package/dist/commands/bot-runtime.d.ts +35 -0
- package/dist/commands/bot-runtime.js +115 -0
- package/dist/commands/bot.d.ts +53 -0
- package/dist/commands/bot.js +239 -30
- package/dist/commands/cloud.d.ts +39 -0
- package/dist/commands/cloud.js +173 -82
- package/dist/commands/creators.js +2 -1
- package/dist/commands/deploy-domains.js +8 -4
- package/dist/commands/library-remove.js +2 -1
- package/dist/commands/library.js +5 -4
- package/dist/commands/mesh.d.ts +0 -7
- package/dist/commands/mesh.js +5 -1
- package/dist/commands/sync-held.js +2 -2
- package/dist/lib/bot/api.d.ts +8 -0
- package/dist/lib/bot/api.js +9 -0
- package/dist/lib/bot/fleet-download.d.ts +27 -0
- package/dist/lib/bot/fleet-download.js +162 -0
- package/dist/lib/bot/fleet-local.d.ts +79 -2
- package/dist/lib/bot/fleet-local.js +246 -74
- package/dist/lib/bot/fleet-python.d.ts +2 -0
- package/dist/lib/bot/fleet-python.js +29 -0
- package/dist/lib/bot/jobs/source-report.d.ts +31 -0
- package/dist/lib/bot/jobs/source-report.js +276 -0
- package/dist/lib/bot/legacy-convert.d.ts +107 -4
- package/dist/lib/bot/legacy-convert.js +159 -13
- package/dist/lib/bot/legacy-provider-login.d.ts +34 -0
- package/dist/lib/bot/legacy-provider-login.js +144 -0
- package/dist/lib/bot/run.js +20 -1
- package/dist/lib/doctor/checks/bots.d.ts +4 -0
- package/dist/lib/doctor/checks/bots.js +33 -0
- package/dist/lib/lanes/mesh-events.js +3 -1
- package/dist/lib/lanes/store.js +7 -0
- package/dist/lib/lanes/types.d.ts +2 -0
- package/dist/lib/lanes/types.js +1 -0
- package/dist/lib/lanes/watcher.d.ts +0 -33
- package/dist/lib/lanes/watcher.js +7 -0
- package/dist/lib/mesh/api.js +2 -1
- package/dist/lib/mesh/live/daemon/run.d.ts +0 -10
- package/dist/lib/mesh/live/daemon/run.js +3 -0
- package/dist/lib/mesh/live/emit.d.ts +2 -11
- package/dist/lib/mesh/live/emit.js +20 -2
- package/dist/lib/mesh/live/flush.d.ts +2 -0
- package/dist/lib/mesh/live/flush.js +34 -3
- package/dist/lib/mesh/live/reporting-privacy.d.ts +7 -0
- package/dist/lib/mesh/live/reporting-privacy.js +47 -0
- package/dist/lib/work-context/company.d.ts +2 -3
- package/dist/lib/work-context/company.js +4 -22
- package/dist/secrets-env-action.js +5 -2
- package/dist/utils/cognito-callback-port.d.ts +2 -0
- package/dist/utils/cognito-callback-port.js +10 -5
- package/dist/utils/cognito-config.js +6 -1
- package/dist/utils/cognito-session.js +6 -1
- package/dist/utils/interactive-caller.d.ts +8 -0
- package/dist/utils/interactive-caller.js +10 -0
- package/dist/utils/login-browser.js +2 -1
- package/dist/utils/resident-package-preload.js +57 -4
- package/package.json +7 -7
|
@@ -6,6 +6,7 @@ import * as path from "node:path";
|
|
|
6
6
|
import * as zlib from "node:zlib";
|
|
7
7
|
import { HQ_FLEET_RUNTIME_ENGINE_ID, } from "./config.js";
|
|
8
8
|
import { withBotLock } from "./lock.js";
|
|
9
|
+
import { downloadFleetFile, fileSha256 } from "./fleet-download.js";
|
|
9
10
|
import { ensureFleetPython, fleetUvEnv } from "./fleet-python.js";
|
|
10
11
|
import semver from "semver";
|
|
11
12
|
import { CLI_VERSION } from "../../cli-version.js";
|
|
@@ -79,14 +80,14 @@ export function sharedRuntimeLayout(root, id, platform) {
|
|
|
79
80
|
}
|
|
80
81
|
export const HQ_FLEET_LOCAL_RELEASE = {
|
|
81
82
|
repository: "indigoai-us/hq-fleet-local",
|
|
82
|
-
tag: "v0.4.
|
|
83
|
-
version: "0.4.
|
|
84
|
-
artifact: "hq-fleet-local-0.4.
|
|
85
|
-
artifactSha256: "
|
|
86
|
-
runtimeArtifact: "hq-fleet-runtime-d257fdd1171f.tar",
|
|
87
|
-
runtimeArtifactSha256: "
|
|
88
|
-
manifestSha256: "
|
|
89
|
-
signatureSha256: "
|
|
83
|
+
tag: "v0.4.26",
|
|
84
|
+
version: "0.4.26",
|
|
85
|
+
artifact: "hq-fleet-local-0.4.26.zip",
|
|
86
|
+
artifactSha256: "a738704bf3ea7109ecc133c091b97a2d602d54d83df74a44a25fed508ed8ce27",
|
|
87
|
+
runtimeArtifact: "hq-fleet-runtime-d257fdd1171f.tar.gz",
|
|
88
|
+
runtimeArtifactSha256: "4d26d250eb100efff280bcd254e06e3a2993875c1fff4eec1733eaf99e52cd70",
|
|
89
|
+
manifestSha256: "07d4ee6e34dc63c5f42df009fa9c70d3ef6a93527143956373a9d3cef6f5c3cc",
|
|
90
|
+
signatureSha256: "34793d91b60acdcc7e508d4ddb98311ef0d34b8a60c57930cef08e649288297a",
|
|
90
91
|
runtimeCommit: "d257fdd1171f1edd5e381b3bad7baacab0cb00d3",
|
|
91
92
|
};
|
|
92
93
|
/** hq-fleet-local trust/release-public.pem (rotated 2026-10-30; signed v0.4.17). */
|
|
@@ -470,7 +471,8 @@ export function parseFleetLocalReleasePin(value) {
|
|
|
470
471
|
return null;
|
|
471
472
|
if (!COMMIT_RE.test(pin.runtimeCommit))
|
|
472
473
|
return null;
|
|
473
|
-
|
|
474
|
+
const runtimeStem = `hq-fleet-runtime-${pin.runtimeCommit.slice(0, 12)}`;
|
|
475
|
+
if (pin.runtimeArtifact !== `${runtimeStem}.tar` && pin.runtimeArtifact !== `${runtimeStem}.tar.gz`)
|
|
474
476
|
return null;
|
|
475
477
|
if (![pin.artifactSha256, pin.runtimeArtifactSha256, pin.manifestSha256, pin.signatureSha256].every((hash) => SHA256_RE.test(hash))) {
|
|
476
478
|
return null;
|
|
@@ -637,38 +639,67 @@ function trustedReleaseLink(url) {
|
|
|
637
639
|
return false;
|
|
638
640
|
}
|
|
639
641
|
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
+
export const FLEET_LOCAL_METADATA_DOWNLOAD_TIMEOUT_MS = 30_000;
|
|
643
|
+
/** One machine-wide lock: concurrent creates and adopts share one download instead of repeating it. */
|
|
644
|
+
export const FLEET_LOCAL_DISTRIBUTION_LOCK_NAME = "hq-fleet-local-distribution";
|
|
645
|
+
export const FLEET_LOCAL_DISTRIBUTION_LOCK_WAIT_MS = 30 * 60_000;
|
|
646
|
+
export const FLEET_LOCAL_DISTRIBUTION_LOCK_STALE_MS = 60 * 60_000;
|
|
647
|
+
const RELEASE_FILE_NAMES = (release) => [
|
|
648
|
+
release.artifact,
|
|
649
|
+
release.runtimeArtifact,
|
|
650
|
+
"release-manifest.json",
|
|
651
|
+
"release-manifest.sig",
|
|
652
|
+
];
|
|
653
|
+
function downloadsDir(root, release) {
|
|
654
|
+
return path.join(root, "distributions", "hq-fleet-local", ".downloads", release.version);
|
|
655
|
+
}
|
|
656
|
+
function discardDownloads(target) {
|
|
657
|
+
fs.rmSync(target, { recursive: true, force: true });
|
|
658
|
+
try {
|
|
659
|
+
fs.rmdirSync(path.dirname(target));
|
|
660
|
+
}
|
|
661
|
+
catch {
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
async function downloadReleaseFiles(release, fetcher, resolve, cachedRuntime, target, onProgress, stallMs) {
|
|
666
|
+
fs.mkdirSync(target, { recursive: true, mode: 0o700 });
|
|
667
|
+
const downloaded = new Map();
|
|
668
|
+
for (const name of RELEASE_FILE_NAMES(release)) {
|
|
669
|
+
if (name === release.runtimeArtifact && cachedRuntime) {
|
|
670
|
+
downloaded.set(name, cachedRuntime);
|
|
671
|
+
continue;
|
|
672
|
+
}
|
|
673
|
+
const { url, headers } = resolve(name);
|
|
674
|
+
const file = await downloadFleetFile(url, path.join(target, name), {
|
|
675
|
+
fetch: fetcher,
|
|
676
|
+
...(headers ? { headers } : {}),
|
|
677
|
+
...(stallMs !== undefined ? { stallMs } : {}),
|
|
678
|
+
onProgress: (progress) => onProgress?.({ phase: "download", file: name, received: progress.received, total: progress.total }),
|
|
679
|
+
});
|
|
680
|
+
downloaded.set(name, file);
|
|
681
|
+
}
|
|
682
|
+
return {
|
|
683
|
+
archive: fs.readFileSync(downloaded.get(release.artifact)),
|
|
684
|
+
runtimeArchive: fs.readFileSync(downloaded.get(release.runtimeArtifact)),
|
|
685
|
+
manifest: fs.readFileSync(downloaded.get("release-manifest.json")),
|
|
686
|
+
signature: fs.readFileSync(downloaded.get("release-manifest.sig")),
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
async function downloadFleetLocalReleaseFromHq(release, fetcher, links, cachedRuntime, target, onProgress, stallMs) {
|
|
690
|
+
for (const name of RELEASE_FILE_NAMES(release)) {
|
|
691
|
+
if (name === release.runtimeArtifact && cachedRuntime)
|
|
692
|
+
continue;
|
|
642
693
|
const url = links.get(name);
|
|
643
694
|
if (!url)
|
|
644
695
|
throw expectedError(`HQ Fleet Local ${release.tag} is missing release asset ${name}.`);
|
|
645
696
|
if (!trustedReleaseLink(url)) {
|
|
646
697
|
throw expectedError(`HQ Fleet Local ${release.tag} returned an untrusted download link for ${name}.`);
|
|
647
698
|
}
|
|
648
|
-
const response = await fetcher(url, { signal: AbortSignal.timeout(timeoutMs) });
|
|
649
|
-
if (!response.ok) {
|
|
650
|
-
throw expectedError(`Could not download ${name}: HQ storage returned HTTP ${response.status}.`);
|
|
651
|
-
}
|
|
652
|
-
return Buffer.from(await response.arrayBuffer());
|
|
653
|
-
};
|
|
654
|
-
const [archive, runtimeArchive, manifest, signature] = await Promise.all([
|
|
655
|
-
get(release.artifact, FLEET_LOCAL_ARCHIVE_DOWNLOAD_TIMEOUT_MS),
|
|
656
|
-
cachedRuntime ?? get(release.runtimeArtifact, FLEET_LOCAL_RUNTIME_DOWNLOAD_TIMEOUT_MS),
|
|
657
|
-
get("release-manifest.json", FLEET_LOCAL_METADATA_DOWNLOAD_TIMEOUT_MS),
|
|
658
|
-
get("release-manifest.sig", FLEET_LOCAL_METADATA_DOWNLOAD_TIMEOUT_MS),
|
|
659
|
-
]);
|
|
660
|
-
return { archive, runtimeArchive, manifest, signature };
|
|
661
|
-
}
|
|
662
|
-
async function responseBytes(response, label) {
|
|
663
|
-
if (!response.ok) {
|
|
664
|
-
throw expectedError(`Could not download ${label}: GitHub returned HTTP ${response.status}.`);
|
|
665
699
|
}
|
|
666
|
-
return
|
|
700
|
+
return downloadReleaseFiles(release, fetcher, (name) => ({ url: links.get(name) }), cachedRuntime, target, onProgress, stallMs);
|
|
667
701
|
}
|
|
668
|
-
|
|
669
|
-
export const FLEET_LOCAL_ARCHIVE_DOWNLOAD_TIMEOUT_MS = 5 * 60_000;
|
|
670
|
-
export const FLEET_LOCAL_RUNTIME_DOWNLOAD_TIMEOUT_MS = 20 * 60_000;
|
|
671
|
-
async function downloadFleetLocalRelease(release, fetcher, token, cachedRuntime) {
|
|
702
|
+
async function downloadFleetLocalRelease(release, fetcher, token, cachedRuntime, target, onProgress, stallMs) {
|
|
672
703
|
const headers = {
|
|
673
704
|
Accept: "application/vnd.github+json",
|
|
674
705
|
Authorization: `Bearer ${token}`,
|
|
@@ -676,7 +707,7 @@ async function downloadFleetLocalRelease(release, fetcher, token, cachedRuntime)
|
|
|
676
707
|
"X-GitHub-Api-Version": "2022-11-28",
|
|
677
708
|
};
|
|
678
709
|
const releaseUrl = `https://api.github.com/repos/${release.repository}/releases/tags/${release.tag}`;
|
|
679
|
-
const response = await fetcher(releaseUrl, { headers, signal: AbortSignal.timeout(
|
|
710
|
+
const response = await fetcher(releaseUrl, { headers, signal: AbortSignal.timeout(FLEET_LOCAL_METADATA_DOWNLOAD_TIMEOUT_MS) });
|
|
680
711
|
if (!response.ok) {
|
|
681
712
|
throw expectedError(`Could not read HQ Fleet Local ${release.tag}: GitHub returned HTTP ${response.status}.`);
|
|
682
713
|
}
|
|
@@ -684,25 +715,17 @@ async function downloadFleetLocalRelease(release, fetcher, token, cachedRuntime)
|
|
|
684
715
|
const assets = new Map((body.assets ?? [])
|
|
685
716
|
.filter((asset) => !!asset.name && !!asset.url)
|
|
686
717
|
.map((asset) => [asset.name, asset.url]));
|
|
687
|
-
const
|
|
718
|
+
for (const name of RELEASE_FILE_NAMES(release)) {
|
|
719
|
+
if (name === release.runtimeArtifact && cachedRuntime)
|
|
720
|
+
continue;
|
|
688
721
|
const url = assets.get(name);
|
|
689
722
|
if (!url)
|
|
690
723
|
throw expectedError(`HQ Fleet Local ${release.tag} is missing release asset ${name}.`);
|
|
691
724
|
if (new URL(url).origin !== "https://api.github.com") {
|
|
692
725
|
throw expectedError(`HQ Fleet Local ${release.tag} returned an untrusted asset URL for ${name}.`);
|
|
693
726
|
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
signal: AbortSignal.timeout(timeoutMs),
|
|
697
|
-
}), name);
|
|
698
|
-
};
|
|
699
|
-
const [archive, runtimeArchive, manifest, signature] = await Promise.all([
|
|
700
|
-
get(release.artifact, FLEET_LOCAL_ARCHIVE_DOWNLOAD_TIMEOUT_MS),
|
|
701
|
-
cachedRuntime ?? get(release.runtimeArtifact, FLEET_LOCAL_RUNTIME_DOWNLOAD_TIMEOUT_MS),
|
|
702
|
-
get("release-manifest.json", FLEET_LOCAL_METADATA_DOWNLOAD_TIMEOUT_MS),
|
|
703
|
-
get("release-manifest.sig", FLEET_LOCAL_METADATA_DOWNLOAD_TIMEOUT_MS),
|
|
704
|
-
]);
|
|
705
|
-
return { archive, runtimeArchive, manifest, signature };
|
|
727
|
+
}
|
|
728
|
+
return downloadReleaseFiles(release, fetcher, (name) => ({ url: assets.get(name), headers: { ...headers, Accept: "application/octet-stream" } }), cachedRuntime, target, onProgress, stallMs);
|
|
706
729
|
}
|
|
707
730
|
function installedFiles(dir, release) {
|
|
708
731
|
const archive = path.join(dir, release.artifact);
|
|
@@ -749,49 +772,83 @@ function installFiles(target, files, release, publicKey) {
|
|
|
749
772
|
fs.rmSync(staging, { recursive: true, force: true });
|
|
750
773
|
}
|
|
751
774
|
}
|
|
775
|
+
/** A runtime archive already on this machine whose bytes match the pin: any installed release, or a finished download. */
|
|
752
776
|
function cachedRuntimeArchive(root, release) {
|
|
753
777
|
const distributions = path.join(root, "distributions", "hq-fleet-local");
|
|
754
778
|
if (!fs.existsSync(distributions))
|
|
755
779
|
return null;
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
continue;
|
|
759
|
-
const directory = path.join(distributions, entry.name);
|
|
780
|
+
const candidates = [];
|
|
781
|
+
const visit = (directory) => {
|
|
760
782
|
for (const file of fs.readdirSync(directory, { withFileTypes: true })) {
|
|
761
|
-
|
|
783
|
+
const full = path.join(directory, file.name);
|
|
784
|
+
if (file.isDirectory()) {
|
|
785
|
+
if (file.name === ".downloads" || !file.name.startsWith("."))
|
|
786
|
+
visit(full);
|
|
787
|
+
continue;
|
|
788
|
+
}
|
|
789
|
+
if (!file.isFile() || !file.name.startsWith("hq-fleet-runtime-"))
|
|
762
790
|
continue;
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
791
|
+
if (!file.name.endsWith(".tar") && !file.name.endsWith(".tar.gz"))
|
|
792
|
+
continue;
|
|
793
|
+
candidates.push(full);
|
|
766
794
|
}
|
|
795
|
+
};
|
|
796
|
+
visit(distributions);
|
|
797
|
+
for (const candidate of candidates) {
|
|
798
|
+
if (fileSha256(candidate) === release.runtimeArtifactSha256)
|
|
799
|
+
return candidate;
|
|
767
800
|
}
|
|
768
801
|
return null;
|
|
769
802
|
}
|
|
803
|
+
/** Whether the pinned release is installed on this machine (no download needed). */
|
|
804
|
+
export function fleetLocalDistributionInstalled(release = HQ_FLEET_LOCAL_RELEASE, root = fleetHome()) {
|
|
805
|
+
return installedFiles(path.join(root, "distributions", "hq-fleet-local", release.version), release) !== null;
|
|
806
|
+
}
|
|
770
807
|
export async function installPinnedFleetLocalDistribution(deps = {}) {
|
|
771
808
|
const release = deps.release ?? HQ_FLEET_LOCAL_RELEASE;
|
|
772
809
|
const publicKey = deps.publicKey ?? HQ_FLEET_LOCAL_PUBLIC_KEYS;
|
|
773
810
|
const root = deps.fleetHome ?? fleetHome();
|
|
774
811
|
const dir = path.join(root, "distributions", "hq-fleet-local", release.version);
|
|
775
|
-
const
|
|
812
|
+
const onProgress = deps.onProgress;
|
|
776
813
|
const warnCompatibility = (manifest) => {
|
|
777
814
|
const warning = fleetLocalCliCompatibilityWarning(manifest, release);
|
|
778
815
|
if (warning)
|
|
779
816
|
process.stderr.write(`Warning: ${warning}\n`);
|
|
780
817
|
};
|
|
818
|
+
const installation = () => ({
|
|
819
|
+
release,
|
|
820
|
+
dir,
|
|
821
|
+
archive: path.join(dir, release.artifact),
|
|
822
|
+
runtimeArchive: path.join(dir, release.runtimeArtifact),
|
|
823
|
+
manifest: path.join(dir, "release-manifest.json"),
|
|
824
|
+
signature: path.join(dir, "release-manifest.sig"),
|
|
825
|
+
engine: engineMetadata(release),
|
|
826
|
+
});
|
|
827
|
+
const current = installedFiles(dir, release);
|
|
781
828
|
if (current) {
|
|
782
829
|
verifyFleetLocalRelease(current, release, publicKey);
|
|
783
830
|
warnCompatibility(current.manifest);
|
|
784
|
-
|
|
785
|
-
|
|
831
|
+
onProgress?.({ phase: "ready", step: "download", cached: true });
|
|
832
|
+
return installation();
|
|
833
|
+
}
|
|
834
|
+
return withBotLock(FLEET_LOCAL_DISTRIBUTION_LOCK_NAME, async () => {
|
|
835
|
+
const again = installedFiles(dir, release);
|
|
836
|
+
if (again) {
|
|
837
|
+
verifyFleetLocalRelease(again, release, publicKey);
|
|
838
|
+
warnCompatibility(again.manifest);
|
|
839
|
+
onProgress?.({ phase: "ready", step: "download", cached: true });
|
|
840
|
+
return installation();
|
|
841
|
+
}
|
|
786
842
|
const fetcher = deps.fetch ?? fetch;
|
|
787
843
|
const lookup = deps.hqReleaseLinks
|
|
788
844
|
? { links: await deps.hqReleaseLinks(release), reason: null }
|
|
789
845
|
: await (deps.hqReleaseLookup ?? lookupHqFleetReleaseLinks)(release);
|
|
790
846
|
const links = lookup.links;
|
|
791
847
|
const cachedRuntime = cachedRuntimeArchive(root, release);
|
|
848
|
+
const target = downloadsDir(root, release);
|
|
792
849
|
let files;
|
|
793
850
|
if (links) {
|
|
794
|
-
files = await downloadFleetLocalReleaseFromHq(release, fetcher, links, cachedRuntime);
|
|
851
|
+
files = await downloadFleetLocalReleaseFromHq(release, fetcher, links, cachedRuntime, target, onProgress, deps.downloadStallMs);
|
|
795
852
|
}
|
|
796
853
|
else {
|
|
797
854
|
let githubToken;
|
|
@@ -799,24 +856,29 @@ export async function installPinnedFleetLocalDistribution(deps = {}) {
|
|
|
799
856
|
githubToken = (deps.token ?? resolveFleetReleaseToken)();
|
|
800
857
|
}
|
|
801
858
|
catch (error) {
|
|
802
|
-
// A customer has no GitHub token; say why HQ had no download instead of asking them to sign in again.
|
|
803
859
|
throw noReleaseSourceError(release, lookup.reason) ?? error;
|
|
804
860
|
}
|
|
805
|
-
files = await downloadFleetLocalRelease(release, fetcher, githubToken, cachedRuntime);
|
|
861
|
+
files = await downloadFleetLocalRelease(release, fetcher, githubToken, cachedRuntime, target, onProgress, deps.downloadStallMs);
|
|
862
|
+
}
|
|
863
|
+
onProgress?.({ phase: "verify" });
|
|
864
|
+
try {
|
|
865
|
+
verifyFleetLocalRelease(files, release, publicKey);
|
|
866
|
+
}
|
|
867
|
+
catch (error) {
|
|
868
|
+
discardDownloads(target);
|
|
869
|
+
throw error;
|
|
806
870
|
}
|
|
807
|
-
verifyFleetLocalRelease(files, release, publicKey);
|
|
808
871
|
warnCompatibility(files.manifest);
|
|
809
872
|
installFiles(dir, files, release, publicKey);
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
};
|
|
873
|
+
discardDownloads(target);
|
|
874
|
+
onProgress?.({ phase: "ready", step: "download", cached: false });
|
|
875
|
+
return installation();
|
|
876
|
+
}, {
|
|
877
|
+
root: path.join(root, "distributions"),
|
|
878
|
+
command: "HQ Fleet Runtime download",
|
|
879
|
+
waitMs: FLEET_LOCAL_DISTRIBUTION_LOCK_WAIT_MS,
|
|
880
|
+
staleMs: FLEET_LOCAL_DISTRIBUTION_LOCK_STALE_MS,
|
|
881
|
+
});
|
|
820
882
|
}
|
|
821
883
|
function profileName(agentUid) {
|
|
822
884
|
return agentUid.toLowerCase();
|
|
@@ -1633,7 +1695,76 @@ export function importFleetLocalMachineCredential(agentUid, machineCredentials,
|
|
|
1633
1695
|
if (!opts.keepSource)
|
|
1634
1696
|
fs.rmSync(machineCredentials, { force: true });
|
|
1635
1697
|
}
|
|
1636
|
-
|
|
1698
|
+
/** The bots with an HQ Fleet profile on this computer, by the id their profile.json names. */
|
|
1699
|
+
export function listFleetLocalProfiles(deps = {}) {
|
|
1700
|
+
const profiles = path.join(deps.fleetHome ?? fleetHome(), "profiles");
|
|
1701
|
+
let entries;
|
|
1702
|
+
try {
|
|
1703
|
+
entries = fs.readdirSync(profiles, { withFileTypes: true });
|
|
1704
|
+
}
|
|
1705
|
+
catch {
|
|
1706
|
+
return [];
|
|
1707
|
+
}
|
|
1708
|
+
const found = [];
|
|
1709
|
+
for (const entry of entries) {
|
|
1710
|
+
if (!entry.isDirectory())
|
|
1711
|
+
continue;
|
|
1712
|
+
const profileDir = path.join(profiles, entry.name);
|
|
1713
|
+
try {
|
|
1714
|
+
const metadata = JSON.parse(fs.readFileSync(path.join(profileDir, "profile.json"), "utf8"));
|
|
1715
|
+
if (typeof metadata.botId === "string" && /^agt_[A-Za-z0-9_-]+$/.test(metadata.botId))
|
|
1716
|
+
found.push({ agentUid: metadata.botId, profileDir });
|
|
1717
|
+
}
|
|
1718
|
+
catch {
|
|
1719
|
+
/* not a bot profile */
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
return found.sort((a, b) => a.profileDir.localeCompare(b.profileDir));
|
|
1723
|
+
}
|
|
1724
|
+
/**
|
|
1725
|
+
* The helper's word on a provider credential a bot holds here (never the
|
|
1726
|
+
* credential itself). Null when the helper cannot be asked: the profile is
|
|
1727
|
+
* not installed, or the helper failed.
|
|
1728
|
+
*/
|
|
1729
|
+
export function fleetLocalProviderAuthStatus(agentUid, provider, deps = {}) {
|
|
1730
|
+
let files;
|
|
1731
|
+
try {
|
|
1732
|
+
files = fleetLocalExecutables(agentUid, deps);
|
|
1733
|
+
}
|
|
1734
|
+
catch {
|
|
1735
|
+
return null;
|
|
1736
|
+
}
|
|
1737
|
+
const run = deps.run ?? execFileSync;
|
|
1738
|
+
try {
|
|
1739
|
+
const status = runJson(run, files.helper, ["auth", "status", "--profile", files.profileDir, "--bot-id", agentUid, "--provider", provider], { stdio: ["ignore", "pipe", "pipe"], timeout: 15_000 }, `${provider} sign-in status`);
|
|
1740
|
+
return { authenticated: status.authenticated === true, ...(typeof status.authType === "string" ? { authType: status.authType } : {}) };
|
|
1741
|
+
}
|
|
1742
|
+
catch {
|
|
1743
|
+
return null;
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
/** The helper waits this long for a sign-in import before the move counts as failed. */
|
|
1747
|
+
const FLEET_PROVIDER_IMPORT_TIMEOUT_MS = 60_000;
|
|
1748
|
+
/**
|
|
1749
|
+
* Sign a bot in from a login already on this computer, without a browser:
|
|
1750
|
+
* the helper imports the Codex CLI login (CODEX_HOME, else ~/.codex) or
|
|
1751
|
+
* copies another Fleet bot's Grok login. `env` is added to the helper's
|
|
1752
|
+
* environment (a bot's own Codex home). The profile's provider is already
|
|
1753
|
+
* the runtime's preset from the bootstrap; this re-renders and checks it.
|
|
1754
|
+
*/
|
|
1755
|
+
export function importFleetLocalProviderLogin(agentUid, runtime, deps = {}, opts = {}) {
|
|
1756
|
+
const provider = runtime === "grok" ? "xai-oauth" : "openai-codex";
|
|
1757
|
+
const run = deps.run ?? execFileSync;
|
|
1758
|
+
const files = fleetLocalExecutables(agentUid, deps);
|
|
1759
|
+
const env = opts.env ? { ...process.env, ...opts.env } : undefined;
|
|
1760
|
+
const auth = runJson(run, files.helper, ["auth", "login", "--profile", files.profileDir, "--bot-id", agentUid, "--provider", provider, "--no-browser"], { stdio: ["ignore", "pipe", "pipe"], timeout: FLEET_PROVIDER_IMPORT_TIMEOUT_MS, ...(env ? { env } : {}) }, `${provider} sign-in import`);
|
|
1761
|
+
if (auth.authenticated !== true)
|
|
1762
|
+
throw expectedError(`HQ Fleet Local could not import a ${provider} sign-in from this computer.`);
|
|
1763
|
+
runJson(run, files.helper, ["render-profile", "--spec", files.profile, "--mode", "update"], { stdio: ["ignore", "pipe", "pipe"] }, "profile update");
|
|
1764
|
+
runJson(run, files.helper, ["doctor-profile", "--profile", files.profileDir, "--runtime", files.runtime], { stdio: ["ignore", "pipe", "pipe"] }, "profile validation");
|
|
1765
|
+
return { runtimeProvider: provider };
|
|
1766
|
+
}
|
|
1767
|
+
async function installSharedFleetRuntime(installation, root, python, platform, run, spawn, onProgress) {
|
|
1637
1768
|
const identity = digest(Buffer.from(JSON.stringify({
|
|
1638
1769
|
version: installation.release.version,
|
|
1639
1770
|
distribution: installation.release.artifactSha256,
|
|
@@ -1672,9 +1803,11 @@ async function installSharedFleetRuntime(installation, root, python, platform, r
|
|
|
1672
1803
|
if (!executables.every((name) => fs.existsSync(venvExecutable(runtimeDir, name, platform)))) {
|
|
1673
1804
|
throw expectedError("The shared HQ Fleet Runtime is incomplete. Reinstall it before creating another bot.");
|
|
1674
1805
|
}
|
|
1806
|
+
onProgress?.({ phase: "ready", step: "runtime", cached: true });
|
|
1675
1807
|
return layout;
|
|
1676
1808
|
}
|
|
1677
1809
|
fs.rmSync(shared, { recursive: true, force: true });
|
|
1810
|
+
onProgress?.({ phase: "extract" });
|
|
1678
1811
|
fs.mkdirSync(distributionSource, { recursive: true, mode: 0o700 });
|
|
1679
1812
|
fs.mkdirSync(runtimeSource, { recursive: true, mode: 0o700 });
|
|
1680
1813
|
const uvEnv = fleetUvEnv(python.pythonDir);
|
|
@@ -1689,6 +1822,7 @@ async function installSharedFleetRuntime(installation, root, python, platform, r
|
|
|
1689
1822
|
installation.runtimeArchive,
|
|
1690
1823
|
runtimeSource,
|
|
1691
1824
|
], { stdio: "ignore" }, "runtime extraction");
|
|
1825
|
+
onProgress?.({ phase: "environment" });
|
|
1692
1826
|
checkedRun(run, python.uv, [
|
|
1693
1827
|
"venv",
|
|
1694
1828
|
"--no-config",
|
|
@@ -1697,6 +1831,7 @@ async function installSharedFleetRuntime(installation, root, python, platform, r
|
|
|
1697
1831
|
runtimeDir,
|
|
1698
1832
|
], { stdio: "ignore", env: uvEnv }, "environment creation");
|
|
1699
1833
|
const runtimePython = venvExecutable(runtimeDir, "python", platform);
|
|
1834
|
+
onProgress?.({ phase: "packages" });
|
|
1700
1835
|
checkedRun(run, python.uv, [
|
|
1701
1836
|
"pip",
|
|
1702
1837
|
"install",
|
|
@@ -1711,6 +1846,7 @@ async function installSharedFleetRuntime(installation, root, python, platform, r
|
|
|
1711
1846
|
throw expectedError("HQ Fleet Local installed without its runtime executables.");
|
|
1712
1847
|
}
|
|
1713
1848
|
fs.writeFileSync(marker, `${JSON.stringify({ schemaVersion: 1, runtimeId: identity, engine: installation.engine })}\n`, { mode: 0o600 });
|
|
1849
|
+
onProgress?.({ phase: "ready", step: "runtime", cached: false });
|
|
1714
1850
|
return layout;
|
|
1715
1851
|
}, { root: path.join(root, "runtimes"), command: "HQ Fleet Runtime installation", waitMs: 20 * 60_000, staleMs: 2 * 60 * 60_000 });
|
|
1716
1852
|
}
|
|
@@ -1725,6 +1861,42 @@ function removeEmbeddedRuntime(profileDir, platform = process.platform) {
|
|
|
1725
1861
|
if (hasEmbeddedRuntime(profileDir, platform))
|
|
1726
1862
|
fs.rmSync(path.join(profileDir, "runtime"), { recursive: true, force: true });
|
|
1727
1863
|
}
|
|
1864
|
+
/**
|
|
1865
|
+
* Everything a bot needs that is shared by every bot on this machine: the
|
|
1866
|
+
* pinned distribution and runtime archive, the private Python, and the built
|
|
1867
|
+
* runtime environment. Safe to run any number of times; a complete install
|
|
1868
|
+
* returns at once.
|
|
1869
|
+
*/
|
|
1870
|
+
export async function ensureFleetRuntimeInstalled(installation, deps = {}) {
|
|
1871
|
+
const run = deps.run ?? execFileSync;
|
|
1872
|
+
const platform = deps.platform ?? process.platform;
|
|
1873
|
+
const root = deps.fleetHome ?? fleetHome();
|
|
1874
|
+
deps.onProgress?.({ phase: "python" });
|
|
1875
|
+
const python = deps.python ?? await ensureFleetPython({ fleetHome: root, platform, run });
|
|
1876
|
+
const spawn = deps.spawn ?? (deps.run ? spawnFromRun(deps.run) : spawnSync);
|
|
1877
|
+
const shared = await installSharedFleetRuntime(installation, root, python, platform, run, spawn, deps.onProgress);
|
|
1878
|
+
return { release: installation.release, distributionDir: installation.dir, runtimeDir: shared.runtimeDir, runtimeId: shared.id };
|
|
1879
|
+
}
|
|
1880
|
+
/** Whether the shared runtime for this release is already built on this machine. */
|
|
1881
|
+
export function fleetRuntimeReady(installation, deps = {}) {
|
|
1882
|
+
const root = deps.fleetHome ?? fleetHome();
|
|
1883
|
+
const platform = deps.platform ?? process.platform;
|
|
1884
|
+
const python = deps.python;
|
|
1885
|
+
if (!python)
|
|
1886
|
+
return false;
|
|
1887
|
+
const identity = digest(Buffer.from(JSON.stringify({
|
|
1888
|
+
version: installation.release.version,
|
|
1889
|
+
distribution: installation.release.artifactSha256,
|
|
1890
|
+
runtime: installation.release.runtimeArtifactSha256,
|
|
1891
|
+
python: python.python,
|
|
1892
|
+
platform,
|
|
1893
|
+
extras: ["mcp", "anthropic"],
|
|
1894
|
+
})));
|
|
1895
|
+
const layout = sharedRuntimeLayout(root, identity, platform);
|
|
1896
|
+
if (!fs.existsSync(path.join(layout.root, "ready.json")))
|
|
1897
|
+
return false;
|
|
1898
|
+
return ["python", "hq-fleet", "hq-fleet-local"].every((name) => fs.existsSync(venvExecutable(layout.runtimeDir, name, platform)));
|
|
1899
|
+
}
|
|
1728
1900
|
export async function bootstrapFleetLocalBot(input, deps = {}) {
|
|
1729
1901
|
const run = deps.run ?? execFileSync;
|
|
1730
1902
|
const platform = deps.platform ?? process.platform;
|
|
@@ -1733,7 +1905,7 @@ export async function bootstrapFleetLocalBot(input, deps = {}) {
|
|
|
1733
1905
|
const profileDir = adoptLegacyProfileDirectory(input.agentUid, root);
|
|
1734
1906
|
fs.mkdirSync(profileDir, { recursive: true, mode: 0o700 });
|
|
1735
1907
|
const spawn = deps.spawn ?? (deps.run ? spawnFromRun(deps.run) : spawnSync);
|
|
1736
|
-
const shared = await installSharedFleetRuntime(input.installation, root, python, platform, run, spawn);
|
|
1908
|
+
const shared = await installSharedFleetRuntime(input.installation, root, python, platform, run, spawn, deps.onProgress);
|
|
1737
1909
|
writeNativeProfileMarker(profileDir, shared, input.installation.engine);
|
|
1738
1910
|
const { systemPrompt, machineCredentials, ...profileInput } = input;
|
|
1739
1911
|
if (systemPrompt !== undefined)
|
|
@@ -43,6 +43,8 @@ export declare function fleetUvEnv(pythonDir: string, base?: NodeJS.ProcessEnv):
|
|
|
43
43
|
/** The operating system's own tar when it is where it always is, so a `tar` on PATH or in the current folder is never run. */
|
|
44
44
|
export declare function tarExecutable(platform: NodeJS.Platform, env?: NodeJS.ProcessEnv): string;
|
|
45
45
|
export declare function fleetPythonToolPath(deps?: FleetPythonDeps): string;
|
|
46
|
+
/** The installer and private Python already on this machine, or null; never downloads anything. */
|
|
47
|
+
export declare function installedFleetPython(deps?: FleetPythonDeps): FleetPython | null;
|
|
46
48
|
/**
|
|
47
49
|
* The pinned installer and private Python, installed once per machine under
|
|
48
50
|
* the fleet folder and reused by every bot. Concurrent creates wait for each
|
|
@@ -222,6 +222,35 @@ async function ensureFleetPythonLocked(root, deps) {
|
|
|
222
222
|
}
|
|
223
223
|
return { uv, python, pythonDir };
|
|
224
224
|
}
|
|
225
|
+
/** The installer and private Python already on this machine, or null; never downloads anything. */
|
|
226
|
+
export function installedFleetPython(deps = {}) {
|
|
227
|
+
const root = deps.fleetHome ?? fleetHome();
|
|
228
|
+
const platform = deps.platform ?? process.platform;
|
|
229
|
+
const run = deps.run ?? execFileSync;
|
|
230
|
+
const version = deps.pythonVersion ?? HQ_FLEET_PYTHON_VERSION;
|
|
231
|
+
const uv = fleetPythonToolPath(deps);
|
|
232
|
+
const pythonDir = path.join(root, "python");
|
|
233
|
+
if (!installedTool(uv) || !fs.existsSync(pythonDir))
|
|
234
|
+
return null;
|
|
235
|
+
try {
|
|
236
|
+
const output = run(uv, ["python", "find", version, "--managed-python", "--no-config"], {
|
|
237
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
238
|
+
env: fleetUvEnv(pythonDir, deps.env ?? process.env),
|
|
239
|
+
encoding: "utf8",
|
|
240
|
+
windowsHide: true,
|
|
241
|
+
timeout: FLEET_PYTHON_FIND_TIMEOUT_MS,
|
|
242
|
+
killSignal: "SIGKILL",
|
|
243
|
+
});
|
|
244
|
+
const found = (Buffer.isBuffer(output) ? output.toString("utf8") : output).trim();
|
|
245
|
+
const python = path.resolve(found);
|
|
246
|
+
if (!found || !fs.existsSync(python) || !isInside(pythonDir, python, platform))
|
|
247
|
+
return null;
|
|
248
|
+
return { uv, python, pythonDir };
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
225
254
|
/**
|
|
226
255
|
* The pinned installer and private Python, installed once per machine under
|
|
227
256
|
* the fleet folder and reused by every bot. Concurrent creates wait for each
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { BotApi, JobRunCompletion } from "../api.js";
|
|
2
|
+
import { type BotConfig } from "../config.js";
|
|
3
|
+
import { type LocalJob } from "../local-jobs.js";
|
|
4
|
+
import { type LaneRecord } from "../../lanes/types.js";
|
|
5
|
+
export declare const SOURCE_REPORT_JOB_KIND = "source-report";
|
|
6
|
+
export declare const REPORT_COOLDOWN_MS: number;
|
|
7
|
+
export declare const sourceLaneTerminal: (lane: LaneRecord) => boolean;
|
|
8
|
+
export declare function ensureSourceReportJobs(dir: string, config: BotConfig, companies?: string[], home?: string): LocalJob[];
|
|
9
|
+
/** Local append only; duplicate watcher observations are harmless. */
|
|
10
|
+
export declare function emitExecutiveLaneFinished(hqRoot: string, lane: LaneRecord, root?: string, home?: string): boolean;
|
|
11
|
+
/** Replay terminal commits whose watcher never durably published its event. */
|
|
12
|
+
export declare function flushExecutiveLaneFinished(hqRoot: string, root?: string, home?: string): void;
|
|
13
|
+
export declare function sourceReportReceiptPath(hqRoot: string, company: string, sourceRef: string): string;
|
|
14
|
+
export interface SourceReporterDeps {
|
|
15
|
+
config: BotConfig;
|
|
16
|
+
api: Pick<BotApi, "sendDm">;
|
|
17
|
+
home?: string;
|
|
18
|
+
botsDir?: string;
|
|
19
|
+
companies?: () => string[];
|
|
20
|
+
now?: () => Date;
|
|
21
|
+
lanes?: (company: string, sourceRef: string) => LaneRecord[];
|
|
22
|
+
/** Fault injection at the two durable boundaries, without changing delivery. */
|
|
23
|
+
afterIntent?: () => void;
|
|
24
|
+
afterSend?: () => void;
|
|
25
|
+
}
|
|
26
|
+
export declare function createSourceReporter(deps: SourceReporterDeps): {
|
|
27
|
+
handle(event: unknown, payload: unknown, company: unknown): Promise<JobRunCompletion>;
|
|
28
|
+
/** Poll from the resident bot loop, so a last lane inside cooldown is not lost. */
|
|
29
|
+
recover(): Promise<void>;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=source-report.d.ts.map
|