@indigoai-us/hq-cli 5.345.207 → 5.345.210
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 +105 -0
- package/assets/scaffold/core/scripts/derive-trigger-facts.sh +22 -3
- package/dist/command-catalog.generated.d.ts +33 -8
- package/dist/command-catalog.generated.js +40 -8
- package/dist/command-registration-plan.d.ts +2 -2
- package/dist/command-registration-plan.js +1 -1
- package/dist/commands/access.js +11 -5
- package/dist/commands/agents.d.ts +8 -0
- package/dist/commands/agents.js +5 -0
- package/dist/commands/bot.d.ts +8 -0
- package/dist/commands/bot.js +67 -7
- package/dist/commands/channels.js +4 -0
- package/dist/commands/cloud.d.ts +83 -2
- package/dist/commands/cloud.js +161 -31
- package/dist/commands/company.d.ts +9 -0
- package/dist/commands/company.js +44 -14
- package/dist/commands/core-checkpoint-native.js +21 -0
- package/dist/commands/core-derive-trigger-facts-native.js +14 -3
- package/dist/commands/core-generate-workers-registry-fast.d.ts +1 -1
- package/dist/commands/core-generate-workers-registry-fast.js +7 -1
- package/dist/commands/core-job-run-native.d.ts +8 -0
- package/dist/commands/core-job-run-native.js +11 -3
- package/dist/commands/core-jobs-native.js +1 -1
- package/dist/commands/core-register-project-native.js +31 -1
- package/dist/commands/core-scan-packages-fast.d.ts +1 -1
- package/dist/commands/core-scan-packages-fast.js +8 -1
- package/dist/commands/core.js +12 -3
- package/dist/commands/dm-attach.d.ts +10 -0
- package/dist/commands/dm-attach.js +33 -5
- package/dist/commands/integrations-connect.js +47 -2
- package/dist/commands/lanes-session-start.d.ts +17 -0
- package/dist/commands/lanes-session-start.js +281 -13
- package/dist/commands/lanes-watch.js +11 -3
- package/dist/commands/lanes.d.ts +4 -0
- package/dist/commands/lanes.js +95 -22
- package/dist/commands/library.d.ts +10 -0
- package/dist/commands/library.js +30 -3
- package/dist/commands/meetings.d.ts +42 -0
- package/dist/commands/meetings.js +157 -12
- package/dist/commands/mesh.js +3 -0
- package/dist/commands/monitor.d.ts +6 -0
- package/dist/commands/monitor.js +29 -19
- package/dist/commands/onboard.js +8 -1
- package/dist/commands/sources.js +7 -3
- package/dist/commands/storage-offload.d.ts +3 -2
- package/dist/commands/storage-offload.js +30 -16
- package/dist/commands/storage.js +2 -1
- package/dist/index.js +9 -0
- package/dist/lanes-monitor-check-argv.d.ts +1 -1
- package/dist/lanes-monitor-check-argv.js +2 -2
- package/dist/lanes-session-start-argv.d.ts +4 -1
- package/dist/lanes-session-start-argv.js +5 -2
- package/dist/lib/bot/fleet-daemon.d.ts +101 -0
- package/dist/lib/bot/fleet-daemon.js +227 -0
- package/dist/lib/bot/fleet-local.d.ts +26 -0
- package/dist/lib/bot/fleet-local.js +51 -2
- package/dist/lib/bot/index.d.ts +1 -0
- package/dist/lib/bot/index.js +1 -0
- package/dist/lib/bot/jobs/hot-signal-sync.d.ts +4 -0
- package/dist/lib/bot/jobs/hot-signal-sync.js +8 -1
- package/dist/lib/bot/log.js +3 -1
- package/dist/lib/bot/probe.js +2 -0
- package/dist/lib/bot/run.js +28 -3
- package/dist/lib/bot/runtime-failure.d.ts +4 -2
- package/dist/lib/bot/runtime-failure.js +9 -1
- package/dist/lib/bot/status.d.ts +17 -0
- package/dist/lib/bot/status.js +53 -2
- package/dist/lib/capacity/collectors/claude-oauth.d.ts +5 -5
- package/dist/lib/capacity/collectors/claude-oauth.js +6 -6
- package/dist/lib/core-utils/native-scaffold-help.d.ts +16 -0
- package/dist/lib/core-utils/native-scaffold-help.js +26 -0
- package/dist/lib/core-utils/session-company.d.ts +25 -8
- package/dist/lib/core-utils/session-company.js +59 -17
- package/dist/lib/daemon/catalog.d.ts +25 -1
- package/dist/lib/daemon/catalog.js +29 -2
- package/dist/lib/daemon/run.d.ts +0 -1
- package/dist/lib/daemon/run.js +3 -11
- package/dist/lib/daemon/server.js +26 -7
- package/dist/lib/daemon/supervisor.js +1 -1
- package/dist/lib/daemon/tools.js +17 -1
- package/dist/lib/db/sqlite-binding.js +2 -1
- package/dist/lib/doctor/checks/bots.d.ts +2 -0
- package/dist/lib/doctor/checks/bots.js +11 -0
- package/dist/lib/doctor/checks/runtime-health.js +3 -2
- package/dist/lib/doctor/checks/work-context.js +5 -2
- package/dist/lib/hook-engine/resolve.d.ts +1 -1
- package/dist/lib/hook-engine/resolve.js +4 -1
- package/dist/lib/hot-channels/adapters/meeting-providers.d.ts +2 -0
- package/dist/lib/hot-channels/adapters/meeting-providers.js +13 -2
- package/dist/lib/lanes/index.d.ts +1 -1
- package/dist/lib/lanes/index.js +1 -1
- package/dist/lib/lanes/monitor.d.ts +14 -0
- package/dist/lib/lanes/monitor.js +51 -10
- package/dist/lib/lanes/outpost-dispatch.d.ts +3 -0
- package/dist/lib/lanes/outpost-dispatch.js +1 -0
- package/dist/lib/lanes/store.d.ts +1 -1
- package/dist/lib/lanes/store.js +2 -1
- package/dist/lib/mesh/client.js +7 -1
- package/dist/lib/mesh/live/backfill-held.d.ts +3 -0
- package/dist/lib/mesh/live/backfill-held.js +167 -7
- package/dist/lib/mesh/live/flush.d.ts +7 -0
- package/dist/lib/mesh/live/flush.js +10 -1
- package/dist/lib/monitor.d.ts +9 -0
- package/dist/lib/monitor.js +33 -7
- package/dist/lib/onboarding/orchestrator.js +269 -132
- package/dist/lib/onboarding/types.d.ts +2 -0
- package/dist/lib/scaffold-cli-floor.js +2 -1
- package/dist/lib/signals/failure-alert.js +3 -1
- package/dist/lib/work-context/organize.d.ts +6 -0
- package/dist/lib/work-context/organize.js +28 -0
- package/dist/lib/work-context/paths.d.ts +9 -0
- package/dist/lib/work-context/paths.js +15 -0
- package/dist/lib/work-context/prd-sync.js +2 -1
- package/dist/runners-alias.d.ts +54 -0
- package/dist/runners-alias.js +86 -0
- package/dist/utils/install-tree-torn.js +5 -3
- package/dist/utils/npm-install-flags.d.ts +27 -0
- package/dist/utils/npm-install-flags.js +68 -0
- package/dist/utils/package-use-lease.js +1 -1
- package/dist/utils/qmd-native-binding-error.js +2 -1
- package/dist/utils/self-update.js +2 -1
- package/dist/utils/staged-install.js +2 -1
- package/dist/utils/staged-npm-install.js +2 -1
- package/dist/utils/upload-author.d.ts +2 -1
- package/dist/utils/upload-author.js +9 -5
- package/dist/utils/version-check.js +2 -1
- package/dist/utils/version-gate.js +7 -6
- package/package.json +7 -7
- package/scripts/install-hook-engine.mjs +7 -3
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* for files over the sync limit approved 2026-10-15.
|
|
6
6
|
*
|
|
7
7
|
* Two kinds of big file:
|
|
8
|
-
* -
|
|
8
|
+
* - Personal-only history copies (old versions inside HQ root git history).
|
|
9
|
+
* Blobs with any company path are excluded, including shared blobs. The CLI
|
|
9
10
|
* uploads each blob to the caller's PERSONAL vault, verifies size + sha256
|
|
10
11
|
* + git blob id, then hands only verified blobs to core `hq-storage.sh
|
|
11
12
|
* strip-large`, which rewrites history to the pointer text. Working-tree
|
|
@@ -520,7 +521,7 @@ export function s3VaultObjectStore(bucket, s3, opts = {}) {
|
|
|
520
521
|
*/
|
|
521
522
|
export function resolveOffloadTarget(rel) {
|
|
522
523
|
const posix = toPosix(rel);
|
|
523
|
-
const m = /^companies\/([^/]+)\/(.+)
|
|
524
|
+
const m = /^companies\/([^/]+)\/(.+)$/i.exec(posix);
|
|
524
525
|
if (m)
|
|
525
526
|
return { vault: "company", slug: m[1], key: m[2] };
|
|
526
527
|
return { vault: "personal", key: posix };
|
|
@@ -592,11 +593,14 @@ export function worktreeHoldsAllCopy(held) {
|
|
|
592
593
|
}
|
|
593
594
|
/**
|
|
594
595
|
* History blobs eligible for offload: at least `minBytes`, and not part of the
|
|
595
|
-
* current checkout. Blobs in HEAD are current files; stripping them would
|
|
596
|
+
* current checkout, with no company path. Blobs in HEAD are current files; stripping them would
|
|
596
597
|
* leave the working tree out of step with HEAD.
|
|
597
598
|
*/
|
|
598
599
|
export function selectHistoryBlobs(blobs, minBytes) {
|
|
599
|
-
|
|
600
|
+
// A blob may have both personal and company names. Never send any such
|
|
601
|
+
// content to the personal store; historical paths need no longer exist.
|
|
602
|
+
return blobs.filter((b) => !b.in_head && b.bytes >= minBytes && b.paths.length > 0 &&
|
|
603
|
+
b.paths.every((p) => !/^companies(?:\/|$)/i.test(toPosix(path.posix.normalize(toPosix(p))))));
|
|
600
604
|
}
|
|
601
605
|
// ── Upload + verify ─────────────────────────────────────────────────────────
|
|
602
606
|
export function matchesDigest(obj, digest) {
|
|
@@ -672,11 +676,12 @@ export const durablePlaceholderFs = {
|
|
|
672
676
|
export async function offloadCurrentFile(rel, store, deps, fsOps = durablePlaceholderFs) {
|
|
673
677
|
if (store.vault !== "personal")
|
|
674
678
|
throw new Error("Offload only writes to your personal vault.");
|
|
679
|
+
const abs = containedPath(deps.hqRoot, rel);
|
|
680
|
+
rel = toPosix(path.relative(fs.realpathSync.native(deps.hqRoot), abs));
|
|
675
681
|
if (resolveOffloadTarget(rel).vault === "company") {
|
|
676
682
|
throw new Error(`'${rel}' is a company file. Company files are never uploaded to your personal vault.`);
|
|
677
683
|
}
|
|
678
684
|
assertRestorable(rel);
|
|
679
|
-
const abs = containedPath(deps.hqRoot, rel);
|
|
680
685
|
const before = await fs.promises.stat(abs);
|
|
681
686
|
if (!before.isFile())
|
|
682
687
|
throw new Error(`'${rel}' is not a regular file.`);
|
|
@@ -1016,7 +1021,7 @@ function skippedByName(rel) {
|
|
|
1016
1021
|
* Symlinks are not followed, and a path outside HQ throws.
|
|
1017
1022
|
*/
|
|
1018
1023
|
function walkCurrentPaths(hqRoot, args) {
|
|
1019
|
-
const realRoot = fs.realpathSync(path.resolve(hqRoot));
|
|
1024
|
+
const realRoot = fs.realpathSync.native(path.resolve(hqRoot));
|
|
1020
1025
|
const out = [];
|
|
1021
1026
|
const seen = new Set();
|
|
1022
1027
|
const visit = (abs) => {
|
|
@@ -1055,10 +1060,12 @@ async function planCurrentFiles(rels, opts, deps, openVault) {
|
|
|
1055
1060
|
let active;
|
|
1056
1061
|
const planned = [];
|
|
1057
1062
|
const now = deps.now().getTime();
|
|
1058
|
-
for (const
|
|
1063
|
+
for (const candidate of rels) {
|
|
1064
|
+
const abs = containedPath(deps.hqRoot, candidate);
|
|
1065
|
+
// Canonicalise discovery output too, not just explicit path arguments.
|
|
1066
|
+
const rel = toPosix(path.relative(fs.realpathSync.native(deps.hqRoot), abs));
|
|
1059
1067
|
if (skippedByName(rel))
|
|
1060
1068
|
continue;
|
|
1061
|
-
const abs = containedPath(deps.hqRoot, rel);
|
|
1062
1069
|
let st;
|
|
1063
1070
|
try {
|
|
1064
1071
|
st = fs.lstatSync(abs);
|
|
@@ -1093,6 +1100,15 @@ async function planCurrentFiles(rels, opts, deps, openVault) {
|
|
|
1093
1100
|
};
|
|
1094
1101
|
if (target.vault === "company") {
|
|
1095
1102
|
plan.company = target.slug;
|
|
1103
|
+
// Decide this before any journal or vault access. A synced or
|
|
1104
|
+
// library-matching file would otherwise be replaced by a placeholder, and
|
|
1105
|
+
// a vault that cannot open would abort every other file in the run.
|
|
1106
|
+
if (deps.serverOwned?.(rel.toLowerCase())) {
|
|
1107
|
+
plan.excluded_by = "server-owned";
|
|
1108
|
+
plan.reason = exclusionReason({ excluded: true, layer: "server-owned" });
|
|
1109
|
+
planned.push({ plan, target });
|
|
1110
|
+
continue;
|
|
1111
|
+
}
|
|
1096
1112
|
active ??= deps.activeCompanySlugs ? await deps.activeCompanySlugs() : [];
|
|
1097
1113
|
if (!active.includes(target.slug)) {
|
|
1098
1114
|
plan.reason = `You are not an active member of '${target.slug}'.`;
|
|
@@ -1143,9 +1159,7 @@ async function planCurrentFiles(rels, opts, deps, openVault) {
|
|
|
1143
1159
|
plan.placeholder = "written";
|
|
1144
1160
|
}
|
|
1145
1161
|
else if (target.vault === "company") {
|
|
1146
|
-
const ex = deps.
|
|
1147
|
-
? { excluded: true, layer: "server-owned" }
|
|
1148
|
-
: deps.syncExclusion?.(rel);
|
|
1162
|
+
const ex = deps.syncExclusion?.(rel);
|
|
1149
1163
|
if (ex?.excluded) {
|
|
1150
1164
|
plan.excluded_by = ex.layer ?? "ignore rules";
|
|
1151
1165
|
plan.reason = exclusionReason(ex);
|
|
@@ -1473,14 +1487,14 @@ export function containedPath(hqRoot, rel) {
|
|
|
1473
1487
|
if (abs !== root && !abs.startsWith(root + path.sep)) {
|
|
1474
1488
|
throw new Error(`Path '${rel}' is outside HQ.`);
|
|
1475
1489
|
}
|
|
1476
|
-
const realRoot = fs.realpathSync(root);
|
|
1490
|
+
const realRoot = fs.realpathSync.native(root);
|
|
1477
1491
|
let existing = abs;
|
|
1478
1492
|
const rest = [];
|
|
1479
1493
|
while (!fs.existsSync(existing)) {
|
|
1480
1494
|
rest.unshift(path.basename(existing));
|
|
1481
1495
|
existing = path.dirname(existing);
|
|
1482
1496
|
}
|
|
1483
|
-
const real = path.join(fs.realpathSync(existing), ...rest);
|
|
1497
|
+
const real = path.join(fs.realpathSync.native(existing), ...rest);
|
|
1484
1498
|
if (real !== realRoot && !real.startsWith(realRoot + path.sep)) {
|
|
1485
1499
|
throw new Error(`Path '${rel}' is outside HQ.`);
|
|
1486
1500
|
}
|
|
@@ -1561,10 +1575,10 @@ async function fetchOrphan(pointer, opts, deps) {
|
|
|
1561
1575
|
throw new Error(`${ORPHANED_MESSAGE} You have no personal copy of it to restore.`);
|
|
1562
1576
|
}
|
|
1563
1577
|
const dest = path.resolve(opts.out);
|
|
1564
|
-
const realRoot = fs.realpathSync(path.resolve(deps.hqRoot));
|
|
1578
|
+
const realRoot = fs.realpathSync.native(path.resolve(deps.hqRoot));
|
|
1565
1579
|
let realParent;
|
|
1566
1580
|
try {
|
|
1567
|
-
realParent = fs.realpathSync(path.dirname(dest));
|
|
1581
|
+
realParent = fs.realpathSync.native(path.dirname(dest));
|
|
1568
1582
|
}
|
|
1569
1583
|
catch {
|
|
1570
1584
|
throw new Error(`The folder for '${opts.out}' does not exist.`);
|
|
@@ -1591,7 +1605,7 @@ async function fetchPlaceholder(arg, deps, opts) {
|
|
|
1591
1605
|
if (opts.forceOrphan)
|
|
1592
1606
|
throw new Error("--force-orphan is only for files a teammate deleted.");
|
|
1593
1607
|
const target = containedPath(deps.hqRoot, pointer.path);
|
|
1594
|
-
const realRoot = fs.realpathSync(path.resolve(deps.hqRoot));
|
|
1608
|
+
const realRoot = fs.realpathSync.native(path.resolve(deps.hqRoot));
|
|
1595
1609
|
const placeholderRel = toPosix(path.relative(realRoot, placeholder));
|
|
1596
1610
|
if (`${toPosix(path.relative(realRoot, target))}${PLACEHOLDER_SUFFIX}` !== placeholderRel) {
|
|
1597
1611
|
throw new Error(`Placeholder '${placeholderRel}' names '${pointer.path}', which is not its own location. Nothing was changed.`);
|
package/dist/commands/storage.js
CHANGED
|
@@ -845,7 +845,8 @@ const CURRENT_ACTION_LABEL = {
|
|
|
845
845
|
/** One `--current` plan line: path, size, owning vault, sync state, action. */
|
|
846
846
|
function formatCurrentFile(f) {
|
|
847
847
|
const vault = f.vault === "company" ? `company ${f.company ?? "?"}` : "personal vault";
|
|
848
|
-
const
|
|
848
|
+
const syncState = f.excluded_by === "server-owned" ? "sync not checked" : f.synced ? "synced" : "not synced";
|
|
849
|
+
const parts = [f.path, formatBytes(f.bytes), vault, syncState, CURRENT_ACTION_LABEL[f.action]];
|
|
849
850
|
if (f.action === "upload+offload") {
|
|
850
851
|
parts.push(`(${f.bytes} bytes to the company ${f.company ?? "?"} vault at ${f.vault_key ?? f.path})`);
|
|
851
852
|
}
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ import { installWindowsHideDefault } from "./utils/windows-hide-default.js";
|
|
|
17
17
|
import { fileURLToPath } from "node:url";
|
|
18
18
|
import { parseMonitorCheckFastRequest } from "./lanes-monitor-check-argv.js";
|
|
19
19
|
import { isLaneSessionStartFastRequest } from "./lanes-session-start-argv.js";
|
|
20
|
+
import { writeLanesAliasDeprecationForArgv } from "./runners-alias.js";
|
|
20
21
|
import { createRequire } from "node:module";
|
|
21
22
|
import { hookEnginePathArgs, runHookEnginePath } from "./hook-engine-path.js";
|
|
22
23
|
function cygpathMixedPath(value) {
|
|
@@ -225,6 +226,14 @@ function dispatchCliRoutes() {
|
|
|
225
226
|
process.argv = normalizeCorePathOperands(process.argv, "win32", cygpathMixedPath);
|
|
226
227
|
}
|
|
227
228
|
const versionRequest = isVersionRequest(process.argv);
|
|
229
|
+
// `hq lanes` is the deprecated alias of `hq runners`. Every route below
|
|
230
|
+
// (catalog help, the session-start and monitor-check fast routes, and the
|
|
231
|
+
// full command graph) shares this one stderr line; stdout is untouched. It
|
|
232
|
+
// prints only for a person at a terminal, never for hook-run subcommands,
|
|
233
|
+
// `--json`, or output that is not a terminal: HQ core's hooks fail on any
|
|
234
|
+
// stderr.
|
|
235
|
+
if (!versionRequest)
|
|
236
|
+
writeLanesAliasDeprecationForArgv(process.argv);
|
|
228
237
|
const helpRequest = !versionRequest && isCommandHelpRequest(process.argv);
|
|
229
238
|
const parsedFastCore = versionRequest || helpRequest ? null : parseFastCore(process.argv);
|
|
230
239
|
const monitorRequest = versionRequest || helpRequest ? null : parseMonitorCheckFastRequest(process.argv);
|
|
@@ -7,6 +7,6 @@ export interface MonitorCheckFastRequest {
|
|
|
7
7
|
engine?: string;
|
|
8
8
|
json: boolean;
|
|
9
9
|
}
|
|
10
|
-
/** Exactly `hq lanes monitor-check --session <id> [--engine <e>] [--json]`. */
|
|
10
|
+
/** Exactly `hq runners|lanes monitor-check --session <id> [--engine <e>] [--json]`. */
|
|
11
11
|
export declare function parseMonitorCheckFastRequest(argv: readonly string[]): MonitorCheckFastRequest | null;
|
|
12
12
|
//# sourceMappingURL=lanes-monitor-check-argv.d.ts.map
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* Imported statically by src/index.ts, so it must not import anything.
|
|
4
4
|
*/
|
|
5
5
|
const SAFE_SESSION_ID = /^[A-Za-z0-9._:-]{1,200}$/u;
|
|
6
|
-
/** Exactly `hq lanes monitor-check --session <id> [--engine <e>] [--json]`. */
|
|
6
|
+
/** Exactly `hq runners|lanes monitor-check --session <id> [--engine <e>] [--json]`. */
|
|
7
7
|
export function parseMonitorCheckFastRequest(argv) {
|
|
8
|
-
if (argv[2] !== "lanes" || argv[3] !== "monitor-check")
|
|
8
|
+
if ((argv[2] !== "runners" && argv[2] !== "lanes") || argv[3] !== "monitor-check")
|
|
9
9
|
return null;
|
|
10
10
|
let sessionId;
|
|
11
11
|
let engine;
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
* Dependency-free argv matcher for the `hq lanes session-start` fast route.
|
|
3
3
|
* Imported statically by src/index.ts, so it must not import anything.
|
|
4
4
|
*/
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Exactly `hq runners session-start` or the deprecated `hq lanes session-start`
|
|
7
|
+
* alias, with no options (the SessionStart hook form).
|
|
8
|
+
*/
|
|
6
9
|
export declare function isLaneSessionStartFastRequest(argv: readonly string[]): boolean;
|
|
7
10
|
//# sourceMappingURL=lanes-session-start-argv.d.ts.map
|
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
* Dependency-free argv matcher for the `hq lanes session-start` fast route.
|
|
3
3
|
* Imported statically by src/index.ts, so it must not import anything.
|
|
4
4
|
*/
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Exactly `hq runners session-start` or the deprecated `hq lanes session-start`
|
|
7
|
+
* alias, with no options (the SessionStart hook form).
|
|
8
|
+
*/
|
|
6
9
|
export function isLaneSessionStartFastRequest(argv) {
|
|
7
|
-
return argv.length === 4 && argv[2] === "lanes" && argv[3] === "session-start";
|
|
10
|
+
return argv.length === 4 && (argv[2] === "runners" || argv[2] === "lanes") && argv[3] === "session-start";
|
|
8
11
|
}
|
|
9
12
|
//# sourceMappingURL=lanes-session-start-argv.js.map
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HQ Fleet bots under `hq daemon` on macOS.
|
|
3
|
+
*
|
|
4
|
+
* The HQ Fleet Runtime registers each bot's gateway as its own LaunchAgent
|
|
5
|
+
* whose program is the runtime's `python`. macOS reports every such login
|
|
6
|
+
* item as a new background item from an unknown developer. On a Mac that runs
|
|
7
|
+
* `hq daemon` (one login item, registered through the HQ app), the daemon runs
|
|
8
|
+
* the gateways itself as `fleet-bots:<name>` units instead, and any LaunchAgent
|
|
9
|
+
* the runtime left behind is unloaded and deleted.
|
|
10
|
+
*
|
|
11
|
+
* Other platforms, and a Mac without `hq daemon`, keep the runtime's own
|
|
12
|
+
* service path.
|
|
13
|
+
*/
|
|
14
|
+
import { type BotConfig } from "./config.js";
|
|
15
|
+
import { type FleetLocalControlDeps, type FleetLocalServiceAction } from "./fleet-local.js";
|
|
16
|
+
import type { FleetBotPlan } from "../daemon/catalog.js";
|
|
17
|
+
import { type DaemonPaths } from "../daemon/paths.js";
|
|
18
|
+
export declare const FLEET_BOT_UNIT_PREFIX = "fleet-bots:";
|
|
19
|
+
export declare function fleetBotUnitId(name: string): string;
|
|
20
|
+
export interface FleetDaemonHost {
|
|
21
|
+
platform?: NodeJS.Platform;
|
|
22
|
+
home?: string;
|
|
23
|
+
paths?: DaemonPaths;
|
|
24
|
+
env?: NodeJS.ProcessEnv;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* `hq daemon` runs this Mac's HQ Fleet bots: it is installed here, or the
|
|
28
|
+
* desktop app hosts it. `HQ_FLEET_BOTS_SERVICE=runtime` keeps the runtime's
|
|
29
|
+
* own LaunchAgents instead.
|
|
30
|
+
*/
|
|
31
|
+
export declare function fleetBotsManagedByDaemon(host?: FleetDaemonHost): boolean;
|
|
32
|
+
export type LaunchctlRun = (args: string[]) => {
|
|
33
|
+
status: number | null;
|
|
34
|
+
};
|
|
35
|
+
export interface RemoveLaunchAgentDeps {
|
|
36
|
+
home?: string;
|
|
37
|
+
uid?: number;
|
|
38
|
+
launchctl?: LaunchctlRun;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Unload and delete the LaunchAgent the runtime registered for this bot, so the
|
|
42
|
+
* daemon's copy is the only one. True when a plist was there and is gone now;
|
|
43
|
+
* a plist that cannot be deleted stays, and the caller sees it still there.
|
|
44
|
+
*/
|
|
45
|
+
export declare function removeFleetBotLaunchAgent(agentUid: string, deps?: RemoveLaunchAgentDeps): boolean;
|
|
46
|
+
export interface FleetBot {
|
|
47
|
+
name: string;
|
|
48
|
+
dir: string;
|
|
49
|
+
config: BotConfig;
|
|
50
|
+
}
|
|
51
|
+
export declare function listFleetBots(root?: string): FleetBot[];
|
|
52
|
+
export declare function findFleetBotByAgent(agentUid: string, root?: string): FleetBot | null;
|
|
53
|
+
export interface PlanFleetBotsDeps extends RemoveLaunchAgentDeps {
|
|
54
|
+
platform?: NodeJS.Platform;
|
|
55
|
+
root?: string;
|
|
56
|
+
fleetHome?: string;
|
|
57
|
+
env?: NodeJS.ProcessEnv;
|
|
58
|
+
log?: (message: string) => void;
|
|
59
|
+
/** The daemon's own pid: a gateway under it is left alone. */
|
|
60
|
+
daemonPid?: number;
|
|
61
|
+
/** `ps -o ppid=,command= -p <pid>` (tests). */
|
|
62
|
+
ps?: (pid: number) => {
|
|
63
|
+
ppid: number;
|
|
64
|
+
command: string;
|
|
65
|
+
} | null;
|
|
66
|
+
kill?: (pid: number, signal: NodeJS.Signals) => void;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The pid of this bot's gateway when it runs outside the daemon (the runtime's
|
|
70
|
+
* LaunchAgent, a detached fallback, or a manual `gateway run`); null when there
|
|
71
|
+
* is none, or when the running one descends from the daemon.
|
|
72
|
+
*/
|
|
73
|
+
export declare function gatewayOutsideDaemon(agentUid: string, deps: {
|
|
74
|
+
fleetHome?: string;
|
|
75
|
+
daemonPid: number;
|
|
76
|
+
ps?: (pid: number) => {
|
|
77
|
+
ppid: number;
|
|
78
|
+
command: string;
|
|
79
|
+
} | null;
|
|
80
|
+
}): number | null;
|
|
81
|
+
/**
|
|
82
|
+
* The daemon's view of every HQ Fleet bot on this machine. On macOS this also
|
|
83
|
+
* retires each bot's own LaunchAgent, so the daemon can start the gateway
|
|
84
|
+
* without a second copy racing it; a plist that survives the attempt keeps the
|
|
85
|
+
* unit waiting.
|
|
86
|
+
*/
|
|
87
|
+
export declare function planFleetBots(deps?: PlanFleetBotsDeps): FleetBotPlan[];
|
|
88
|
+
export interface ControlFleetBotDeps extends FleetLocalControlDeps, FleetDaemonHost {
|
|
89
|
+
root?: string;
|
|
90
|
+
uid?: number;
|
|
91
|
+
launchctl?: LaunchctlRun;
|
|
92
|
+
alive?: (pid: number) => boolean;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* `controlFleetLocalBot` for a bot the daemon runs: the runtime's service
|
|
96
|
+
* commands become daemon requests, and `install`/`start` also retire the
|
|
97
|
+
* bot's own LaunchAgent. Elsewhere the runtime's own service path runs as
|
|
98
|
+
* before.
|
|
99
|
+
*/
|
|
100
|
+
export declare function controlFleetBot(agentUid: string, action: FleetLocalServiceAction, deps?: ControlFleetBotDeps): Record<string, unknown>;
|
|
101
|
+
//# sourceMappingURL=fleet-daemon.d.ts.map
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HQ Fleet bots under `hq daemon` on macOS.
|
|
3
|
+
*
|
|
4
|
+
* The HQ Fleet Runtime registers each bot's gateway as its own LaunchAgent
|
|
5
|
+
* whose program is the runtime's `python`. macOS reports every such login
|
|
6
|
+
* item as a new background item from an unknown developer. On a Mac that runs
|
|
7
|
+
* `hq daemon` (one login item, registered through the HQ app), the daemon runs
|
|
8
|
+
* the gateways itself as `fleet-bots:<name>` units instead, and any LaunchAgent
|
|
9
|
+
* the runtime left behind is unloaded and deleted.
|
|
10
|
+
*
|
|
11
|
+
* Other platforms, and a Mac without `hq daemon`, keep the runtime's own
|
|
12
|
+
* service path.
|
|
13
|
+
*/
|
|
14
|
+
import { spawnSync } from "node:child_process";
|
|
15
|
+
import * as fs from "node:fs";
|
|
16
|
+
import * as os from "node:os";
|
|
17
|
+
import * as path from "node:path";
|
|
18
|
+
import { HQ_FLEET_RUNTIME_ENGINE_ID, patchBotConfig, readBotConfig } from "./config.js";
|
|
19
|
+
import { defaultPathEntries } from "./daemon.js";
|
|
20
|
+
import { controlFleetLocalBot, fleetLocalGatewayPid, fleetLocalGatewayProcess, fleetLocalLaunchAgentLabel, fleetLocalLaunchAgentPlist, removeFleetLocalEmbeddedRuntime, } from "./fleet-local.js";
|
|
21
|
+
import { botsRoot } from "./paths.js";
|
|
22
|
+
import { isPidAlive } from "./status.js";
|
|
23
|
+
import { askDaemonToStart, askDaemonToStop, daemonUnitInstalled, hostedDaemonRunning } from "../daemon/handoff.js";
|
|
24
|
+
import { daemonPaths } from "../daemon/paths.js";
|
|
25
|
+
import { isDaemonProcess } from "../daemon/lock.js";
|
|
26
|
+
export const FLEET_BOT_UNIT_PREFIX = "fleet-bots:";
|
|
27
|
+
export function fleetBotUnitId(name) {
|
|
28
|
+
return `${FLEET_BOT_UNIT_PREFIX}${name}`;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* `hq daemon` runs this Mac's HQ Fleet bots: it is installed here, or the
|
|
32
|
+
* desktop app hosts it. `HQ_FLEET_BOTS_SERVICE=runtime` keeps the runtime's
|
|
33
|
+
* own LaunchAgents instead.
|
|
34
|
+
*/
|
|
35
|
+
export function fleetBotsManagedByDaemon(host = {}) {
|
|
36
|
+
const platform = host.platform ?? process.platform;
|
|
37
|
+
if (platform !== "darwin")
|
|
38
|
+
return false;
|
|
39
|
+
if ((host.env ?? process.env).HQ_FLEET_BOTS_SERVICE?.trim() === "runtime")
|
|
40
|
+
return false;
|
|
41
|
+
const home = host.home ?? os.homedir();
|
|
42
|
+
const paths = host.paths ?? daemonPaths(home);
|
|
43
|
+
return daemonUnitInstalled({ platform, home, windowsTaskName: "", windowsTaskExists: () => false }) || hostedDaemonRunning(paths);
|
|
44
|
+
}
|
|
45
|
+
function defaultLaunchctl(args) {
|
|
46
|
+
return spawnSync("launchctl", args, { encoding: "utf8", windowsHide: true, timeout: 15_000 });
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Unload and delete the LaunchAgent the runtime registered for this bot, so the
|
|
50
|
+
* daemon's copy is the only one. True when a plist was there and is gone now;
|
|
51
|
+
* a plist that cannot be deleted stays, and the caller sees it still there.
|
|
52
|
+
*/
|
|
53
|
+
export function removeFleetBotLaunchAgent(agentUid, deps = {}) {
|
|
54
|
+
const home = deps.home ?? os.homedir();
|
|
55
|
+
const plist = fleetLocalLaunchAgentPlist(agentUid, home);
|
|
56
|
+
if (!fs.existsSync(plist))
|
|
57
|
+
return false;
|
|
58
|
+
const uid = deps.uid ?? process.getuid?.() ?? 0;
|
|
59
|
+
(deps.launchctl ?? defaultLaunchctl)(["bootout", `gui/${uid}/${fleetLocalLaunchAgentLabel(agentUid)}`]);
|
|
60
|
+
try {
|
|
61
|
+
fs.rmSync(plist, { force: true });
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
export function listFleetBots(root = botsRoot()) {
|
|
69
|
+
if (!fs.existsSync(root))
|
|
70
|
+
return [];
|
|
71
|
+
return fs
|
|
72
|
+
.readdirSync(root, { withFileTypes: true })
|
|
73
|
+
.filter((d) => d.isDirectory())
|
|
74
|
+
.map((d) => ({ name: d.name, dir: path.join(root, d.name), config: readBotConfig(path.join(root, d.name)) }))
|
|
75
|
+
.filter((b) => b.config !== null && b.config.engine?.id === HQ_FLEET_RUNTIME_ENGINE_ID)
|
|
76
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
77
|
+
}
|
|
78
|
+
export function findFleetBotByAgent(agentUid, root = botsRoot()) {
|
|
79
|
+
return listFleetBots(root).find((b) => b.config.agentUid === agentUid) ?? null;
|
|
80
|
+
}
|
|
81
|
+
function defaultPs(pid) {
|
|
82
|
+
const result = spawnSync("ps", ["-o", "ppid=,command=", "-p", String(pid)], { encoding: "utf8", timeout: 5_000 });
|
|
83
|
+
const line = result.stdout?.trim();
|
|
84
|
+
if (result.status !== 0 || !line)
|
|
85
|
+
return null;
|
|
86
|
+
const match = /^(\d+)\s+(.*)$/.exec(line);
|
|
87
|
+
return match ? { ppid: Number(match[1]), command: match[2] } : null;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The pid of this bot's gateway when it runs outside the daemon (the runtime's
|
|
91
|
+
* LaunchAgent, a detached fallback, or a manual `gateway run`); null when there
|
|
92
|
+
* is none, or when the running one descends from the daemon.
|
|
93
|
+
*/
|
|
94
|
+
export function gatewayOutsideDaemon(agentUid, deps) {
|
|
95
|
+
const pid = fleetLocalGatewayPid(agentUid, deps);
|
|
96
|
+
if (pid === null || !isPidAlive(pid))
|
|
97
|
+
return null;
|
|
98
|
+
const ps = deps.ps ?? defaultPs;
|
|
99
|
+
const own = ps(pid);
|
|
100
|
+
// The pid file may name a pid the OS reused for something else.
|
|
101
|
+
if (!own || !/hq_fleet_cli|hq-fleet/.test(own.command))
|
|
102
|
+
return null;
|
|
103
|
+
let current = own.ppid;
|
|
104
|
+
for (let hops = 0; hops < 6 && current > 1; hops += 1) {
|
|
105
|
+
if (current === deps.daemonPid)
|
|
106
|
+
return null;
|
|
107
|
+
current = ps(current)?.ppid ?? 0;
|
|
108
|
+
}
|
|
109
|
+
return pid;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The daemon's view of every HQ Fleet bot on this machine. On macOS this also
|
|
113
|
+
* retires each bot's own LaunchAgent, so the daemon can start the gateway
|
|
114
|
+
* without a second copy racing it; a plist that survives the attempt keeps the
|
|
115
|
+
* unit waiting.
|
|
116
|
+
*/
|
|
117
|
+
export function planFleetBots(deps = {}) {
|
|
118
|
+
const platform = deps.platform ?? process.platform;
|
|
119
|
+
const home = deps.home ?? os.homedir();
|
|
120
|
+
const env = deps.env ?? process.env;
|
|
121
|
+
return listFleetBots(deps.root ?? botsRoot(home, env)).map(({ name, config }) => {
|
|
122
|
+
let legacyAgent;
|
|
123
|
+
let outsideGateway;
|
|
124
|
+
if (platform === "darwin") {
|
|
125
|
+
if (removeFleetBotLaunchAgent(config.agentUid, { home, uid: deps.uid, launchctl: deps.launchctl })) {
|
|
126
|
+
deps.log?.(`retired the HQ Fleet LaunchAgent for ${name}; hq daemon runs its gateway now`);
|
|
127
|
+
}
|
|
128
|
+
if (fs.existsSync(fleetLocalLaunchAgentPlist(config.agentUid, home)))
|
|
129
|
+
legacyAgent = fleetLocalLaunchAgentLabel(config.agentUid);
|
|
130
|
+
// A gateway the LaunchAgent (or a detached fallback) left running holds
|
|
131
|
+
// the profile, and the runtime refuses to start a second one. Ask it to
|
|
132
|
+
// exit; the unit waits until it has.
|
|
133
|
+
const outside = gatewayOutsideDaemon(config.agentUid, { fleetHome: deps.fleetHome, daemonPid: deps.daemonPid ?? process.pid, ps: deps.ps });
|
|
134
|
+
if (outside !== null) {
|
|
135
|
+
outsideGateway = outside;
|
|
136
|
+
try {
|
|
137
|
+
(deps.kill ?? ((pid, signal) => process.kill(pid, signal)))(outside, "SIGTERM");
|
|
138
|
+
deps.log?.(`asked the gateway for ${name} started outside hq daemon (pid ${outside}) to exit`);
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
/* already gone */
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const gateway = fleetLocalGatewayProcess(config.agentUid, {
|
|
146
|
+
fleetHome: deps.fleetHome,
|
|
147
|
+
platform,
|
|
148
|
+
pathEntries: defaultPathEntries(home),
|
|
149
|
+
basePath: env.PATH ?? "",
|
|
150
|
+
});
|
|
151
|
+
return {
|
|
152
|
+
name,
|
|
153
|
+
gateway,
|
|
154
|
+
authPending: config.fleetAuthPending === true,
|
|
155
|
+
installPending: config.fleetServiceInstallPending === true,
|
|
156
|
+
...(legacyAgent ? { legacyAgent } : {}),
|
|
157
|
+
...(outsideGateway !== undefined ? { outsideGateway } : {}),
|
|
158
|
+
};
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function unitState(paths, unitId, alive) {
|
|
162
|
+
try {
|
|
163
|
+
const state = JSON.parse(fs.readFileSync(paths.statePath, "utf8"));
|
|
164
|
+
if (!alive(state.pid))
|
|
165
|
+
return null;
|
|
166
|
+
const unit = state.units.find((u) => u.id === unitId);
|
|
167
|
+
return unit ? { status: unit.status, ...(unit.reason ? { reason: unit.reason } : {}), ...(unit.pid !== undefined ? { pid: unit.pid } : {}) } : null;
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* `controlFleetLocalBot` for a bot the daemon runs: the runtime's service
|
|
175
|
+
* commands become daemon requests, and `install`/`start` also retire the
|
|
176
|
+
* bot's own LaunchAgent. Elsewhere the runtime's own service path runs as
|
|
177
|
+
* before.
|
|
178
|
+
*/
|
|
179
|
+
export function controlFleetBot(agentUid, action, deps = {}) {
|
|
180
|
+
const platform = deps.platform ?? process.platform;
|
|
181
|
+
const home = deps.home ?? os.homedir();
|
|
182
|
+
const paths = deps.paths ?? daemonPaths(home);
|
|
183
|
+
const bot = fleetBotsManagedByDaemon({ platform, home, paths, env: deps.env }) ? findFleetBotByAgent(agentUid, deps.root) : null;
|
|
184
|
+
if (!bot)
|
|
185
|
+
return controlFleetLocalBot(agentUid, action, deps);
|
|
186
|
+
const unit = fleetBotUnitId(bot.name);
|
|
187
|
+
const agent = { home, uid: deps.uid, launchctl: deps.launchctl };
|
|
188
|
+
switch (action) {
|
|
189
|
+
case "install":
|
|
190
|
+
case "start": {
|
|
191
|
+
removeFleetBotLaunchAgent(agentUid, agent);
|
|
192
|
+
if (action === "install")
|
|
193
|
+
removeFleetLocalEmbeddedRuntime(agentUid, deps);
|
|
194
|
+
patchBotConfig(bot.dir, { fleetServiceInstallPending: false, enabled: true });
|
|
195
|
+
askDaemonToStart(paths, unit);
|
|
196
|
+
return { ok: true, unit, summary: `${action === "install" ? "installed under" : "started by"} hq daemon (${unit})` };
|
|
197
|
+
}
|
|
198
|
+
case "restart":
|
|
199
|
+
removeFleetBotLaunchAgent(agentUid, agent);
|
|
200
|
+
askDaemonToStart(paths, unit);
|
|
201
|
+
return { ok: true, unit, summary: `restarted by hq daemon (${unit})` };
|
|
202
|
+
case "stop":
|
|
203
|
+
removeFleetBotLaunchAgent(agentUid, agent);
|
|
204
|
+
askDaemonToStop(paths, unit);
|
|
205
|
+
return { ok: true, unit, summary: `stopped by hq daemon (${unit})` };
|
|
206
|
+
case "status": {
|
|
207
|
+
const alive = deps.alive ?? ((pid) => isDaemonProcess(pid));
|
|
208
|
+
const state = unitState(paths, unit, alive);
|
|
209
|
+
const pid = fleetLocalGatewayPid(agentUid, deps);
|
|
210
|
+
const running = pid !== null && isPidAlive(pid);
|
|
211
|
+
return {
|
|
212
|
+
ok: true,
|
|
213
|
+
unit,
|
|
214
|
+
running,
|
|
215
|
+
pid: running ? pid : null,
|
|
216
|
+
state: state?.status ?? "unknown",
|
|
217
|
+
...(state?.reason ? { reason: state.reason } : {}),
|
|
218
|
+
summary: running ? `running under hq daemon (pid ${pid})` : `not running (${state?.reason ?? state?.status ?? "hq daemon is not running"})`,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
case "remove":
|
|
222
|
+
removeFleetBotLaunchAgent(agentUid, agent);
|
|
223
|
+
askDaemonToStop(paths, unit);
|
|
224
|
+
return controlFleetLocalBot(agentUid, action, deps);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=fleet-daemon.js.map
|
|
@@ -302,6 +302,32 @@ export declare function fleetLocalServiceInstalled(agentUid: string, deps?: {
|
|
|
302
302
|
platform?: NodeJS.Platform;
|
|
303
303
|
home?: string;
|
|
304
304
|
}): boolean | null;
|
|
305
|
+
/** The launchd label the HQ Fleet Runtime registers a bot's own gateway under. */
|
|
306
|
+
export declare function fleetLocalLaunchAgentLabel(agentUid: string): string;
|
|
307
|
+
export declare function fleetLocalLaunchAgentPlist(agentUid: string, home?: string): string;
|
|
308
|
+
export interface FleetLocalGatewayProcess {
|
|
309
|
+
file: string;
|
|
310
|
+
args: string[];
|
|
311
|
+
env: Record<string, string>;
|
|
312
|
+
cwd: string;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* The bot's gateway as a process for an outside supervisor: the command,
|
|
316
|
+
* environment and working directory the runtime writes into its own
|
|
317
|
+
* LaunchAgent, with `--external-supervisor` so the runtime hands restarts back
|
|
318
|
+
* to the supervisor instead of relaunching itself. The gateway is the direct
|
|
319
|
+
* child (the LaunchAgent's stderr-timestamp wrapper is left out), so the
|
|
320
|
+
* supervisor's signals reach it and a forced stop cannot orphan it. Null when
|
|
321
|
+
* the profile or its runtime is not fully installed.
|
|
322
|
+
*/
|
|
323
|
+
export declare function fleetLocalGatewayProcess(agentUid: string, deps?: {
|
|
324
|
+
fleetHome?: string;
|
|
325
|
+
platform?: NodeJS.Platform;
|
|
326
|
+
pathEntries?: readonly string[];
|
|
327
|
+
basePath?: string;
|
|
328
|
+
}): FleetLocalGatewayProcess | null;
|
|
329
|
+
/** After a service install: drop the profile's own copy of the runtime once the shared one runs it. */
|
|
330
|
+
export declare function removeFleetLocalEmbeddedRuntime(agentUid: string, deps?: Pick<FleetLocalControlDeps, "fleetHome" | "platform">): void;
|
|
305
331
|
export declare function fleetLocalProfileNeedsAdoption(agentUid: string, deps?: Pick<FleetLocalControlDeps, "fleetHome" | "platform"> & {
|
|
306
332
|
release?: FleetLocalReleasePin;
|
|
307
333
|
}): boolean;
|
|
@@ -12,6 +12,7 @@ import semver from "semver";
|
|
|
12
12
|
import { CLI_VERSION } from "../../cli-version.js";
|
|
13
13
|
import { ensureCognitoToken } from "../../utils/cognito-session.js";
|
|
14
14
|
import { vaultApiFetch } from "../../utils/vault-api.js";
|
|
15
|
+
import { HQ_CLI_NPM_UPDATE_COMMAND } from "../../utils/npm-install-flags.js";
|
|
15
16
|
/** The model the HQ Fleet Runtime asks for when a Claude bot names none. */
|
|
16
17
|
export const FLEET_CLAUDE_DEFAULT_MODEL = "claude-opus-5-5";
|
|
17
18
|
/**
|
|
@@ -367,7 +368,7 @@ export function fleetLocalCliCompatibilityWarning(manifest, release = HQ_FLEET_L
|
|
|
367
368
|
if (!required || !current || semver.gte(current, required))
|
|
368
369
|
return null;
|
|
369
370
|
return `HQ Fleet Local ${release.version} asks for hq CLI ${minimum} or newer; this is ${cliVersion}. ` +
|
|
370
|
-
|
|
371
|
+
`Update with \`${HQ_CLI_NPM_UPDATE_COMMAND}\` if the bot misbehaves.`;
|
|
371
372
|
}
|
|
372
373
|
/** `gh auth token` fallback for the release download token. */
|
|
373
374
|
export const FLEET_RELEASE_TOKEN_TIMEOUT_MS = 15_000;
|
|
@@ -1049,7 +1050,55 @@ export function fleetLocalServiceInstalled(agentUid, deps = {}) {
|
|
|
1049
1050
|
if (platform !== "darwin")
|
|
1050
1051
|
return null;
|
|
1051
1052
|
const home = deps.home ?? os.homedir();
|
|
1052
|
-
return fs.existsSync(
|
|
1053
|
+
return fs.existsSync(fleetLocalLaunchAgentPlist(agentUid, home));
|
|
1054
|
+
}
|
|
1055
|
+
/** The launchd label the HQ Fleet Runtime registers a bot's own gateway under. */
|
|
1056
|
+
export function fleetLocalLaunchAgentLabel(agentUid) {
|
|
1057
|
+
return `ai.hq-fleet.gateway-${profileName(agentUid)}`;
|
|
1058
|
+
}
|
|
1059
|
+
export function fleetLocalLaunchAgentPlist(agentUid, home = os.homedir()) {
|
|
1060
|
+
return path.join(home, "Library", "LaunchAgents", `${fleetLocalLaunchAgentLabel(agentUid)}.plist`);
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
* The bot's gateway as a process for an outside supervisor: the command,
|
|
1064
|
+
* environment and working directory the runtime writes into its own
|
|
1065
|
+
* LaunchAgent, with `--external-supervisor` so the runtime hands restarts back
|
|
1066
|
+
* to the supervisor instead of relaunching itself. The gateway is the direct
|
|
1067
|
+
* child (the LaunchAgent's stderr-timestamp wrapper is left out), so the
|
|
1068
|
+
* supervisor's signals reach it and a forced stop cannot orphan it. Null when
|
|
1069
|
+
* the profile or its runtime is not fully installed.
|
|
1070
|
+
*/
|
|
1071
|
+
export function fleetLocalGatewayProcess(agentUid, deps = {}) {
|
|
1072
|
+
if (!/^agt_[A-Za-z0-9_-]+$/.test(agentUid))
|
|
1073
|
+
return null;
|
|
1074
|
+
const root = deps.fleetHome ?? fleetHome();
|
|
1075
|
+
const platform = deps.platform ?? process.platform;
|
|
1076
|
+
const profileDir = profileRoot(agentUid, root);
|
|
1077
|
+
const shared = sharedRuntimeFromMarker(profileDir, root, platform);
|
|
1078
|
+
const runtimeDir = shared?.runtimeDir ?? path.join(profileDir, "runtime");
|
|
1079
|
+
const python = venvExecutable(runtimeDir, "python", platform);
|
|
1080
|
+
if (![python, path.join(profileDir, "profile.json")].every((item) => fs.existsSync(item)))
|
|
1081
|
+
return null;
|
|
1082
|
+
const bin = path.dirname(python);
|
|
1083
|
+
const pathParts = [bin, ...(deps.pathEntries ?? []), ...(deps.basePath ?? "").split(path.delimiter)].filter(Boolean);
|
|
1084
|
+
return {
|
|
1085
|
+
file: python,
|
|
1086
|
+
args: ["-m", "hq_fleet_cli.main", "--profile", profileName(agentUid), "gateway", "run", "--external-supervisor"],
|
|
1087
|
+
env: {
|
|
1088
|
+
PATH: [...new Set(pathParts)].join(path.delimiter),
|
|
1089
|
+
VIRTUAL_ENV: runtimeDir,
|
|
1090
|
+
HQ_FLEET_HOME: profileDir,
|
|
1091
|
+
HQ_FLEET_SUPERVISED_CHILD: "1",
|
|
1092
|
+
},
|
|
1093
|
+
cwd: profileDir,
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
/** After a service install: drop the profile's own copy of the runtime once the shared one runs it. */
|
|
1097
|
+
export function removeFleetLocalEmbeddedRuntime(agentUid, deps = {}) {
|
|
1098
|
+
if (!/^agt_[A-Za-z0-9_-]+$/.test(agentUid))
|
|
1099
|
+
return;
|
|
1100
|
+
const platform = deps.platform ?? process.platform;
|
|
1101
|
+
removeEmbeddedRuntime(profileRoot(agentUid, deps.fleetHome ?? fleetHome()), platform);
|
|
1053
1102
|
}
|
|
1054
1103
|
export function fleetLocalProfileNeedsAdoption(agentUid, deps = {}) {
|
|
1055
1104
|
if (!/^agt_[A-Za-z0-9_-]+$/.test(agentUid))
|