@indigoai-us/hq-cli 5.345.211 → 5.345.212-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 +20 -0
- package/dist/command-catalog.generated.d.ts +28 -0
- package/dist/command-catalog.generated.js +34 -0
- package/dist/commands/bot-runtime.d.ts +21 -2
- package/dist/commands/bot-runtime.js +54 -9
- package/dist/commands/bot.d.ts +13 -0
- package/dist/commands/bot.js +142 -12
- package/dist/commands/daemon.js +3 -0
- package/dist/commands/whoami.js +7 -6
- package/dist/lib/bot/api.d.ts +1 -1
- package/dist/lib/bot/config.js +2 -1
- package/dist/lib/bot/fleet-daemon.d.ts +4 -0
- package/dist/lib/bot/fleet-daemon.js +12 -1
- package/dist/lib/bot/fleet-download.d.ts +6 -0
- package/dist/lib/bot/fleet-download.js +128 -3
- package/dist/lib/bot/fleet-local.d.ts +38 -1
- package/dist/lib/bot/fleet-local.js +239 -26
- package/dist/lib/bot/install-progress.d.ts +28 -0
- package/dist/lib/bot/install-progress.js +185 -0
- package/dist/lib/bot/legacy-provider-login.d.ts +22 -1
- package/dist/lib/bot/legacy-provider-login.js +67 -9
- package/dist/lib/bot/prompt.d.ts +1 -0
- package/dist/lib/bot/prompt.js +3 -2
- package/dist/lib/bot/readiness.d.ts +68 -0
- package/dist/lib/bot/readiness.js +145 -0
- package/dist/lib/bot/run.d.ts +2 -0
- package/dist/lib/bot/run.js +6 -3
- package/dist/lib/bot/scaffold.d.ts +6 -3
- package/dist/lib/bot/scaffold.js +18 -12
- package/dist/lib/daemon/run.d.ts +1 -0
- package/dist/lib/daemon/run.js +6 -1
- package/dist/lib/daemon/supervisor.d.ts +1 -0
- package/dist/lib/daemon/supervisor.js +5 -3
- package/package.json +7 -7
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
export const INSTALL_PROGRESS_INTERVAL_MS = 250;
|
|
2
|
+
const PHASE_ORDER = ["download", "verify", "prepare", "unpack", "environment", "done"];
|
|
3
|
+
export const INSTALL_PHASE_SPANS = {
|
|
4
|
+
download: [0, 0.3],
|
|
5
|
+
verify: [0.3, 0.31],
|
|
6
|
+
prepare: [0.31, 0.5],
|
|
7
|
+
unpack: [0.5, 0.52],
|
|
8
|
+
environment: [0.52, 0.99],
|
|
9
|
+
};
|
|
10
|
+
const ENVIRONMENT_SETUP_SHARE = 0.05;
|
|
11
|
+
export const PREPARE_EXPECTED_MS = 15_000;
|
|
12
|
+
export const PACKAGES_EXPECTED_MS = 30_000;
|
|
13
|
+
const MESSAGES = {
|
|
14
|
+
download: "Downloading the runtime",
|
|
15
|
+
verify: "Checking the download",
|
|
16
|
+
prepare: "Preparing the runtime's core components",
|
|
17
|
+
unpack: "Unpacking the runtime",
|
|
18
|
+
environment: "Setting up the runtime",
|
|
19
|
+
done: "The runtime is ready",
|
|
20
|
+
};
|
|
21
|
+
export function createInstallProgressTracker(emit, deps = {}) {
|
|
22
|
+
const now = deps.now ?? Date.now;
|
|
23
|
+
const setTimer = deps.setTimer ?? ((fn, ms) => setTimeout(fn, ms));
|
|
24
|
+
const clearTimer = deps.clearTimer ?? ((timer) => clearTimeout(timer));
|
|
25
|
+
const files = new Map();
|
|
26
|
+
let expectedFiles = null;
|
|
27
|
+
let phase = null;
|
|
28
|
+
let fraction = 0;
|
|
29
|
+
let lastEmitAt = Number.NEGATIVE_INFINITY;
|
|
30
|
+
let pending = null;
|
|
31
|
+
let flushTimer = null;
|
|
32
|
+
let creepTimer = null;
|
|
33
|
+
let creeping = null;
|
|
34
|
+
let installedSomething = false;
|
|
35
|
+
let finished = false;
|
|
36
|
+
const start = (fn, ms) => {
|
|
37
|
+
const timer = setTimer(fn, ms);
|
|
38
|
+
timer?.unref?.();
|
|
39
|
+
return timer;
|
|
40
|
+
};
|
|
41
|
+
const cancel = (timer) => {
|
|
42
|
+
if (timer !== null)
|
|
43
|
+
clearTimer(timer);
|
|
44
|
+
return null;
|
|
45
|
+
};
|
|
46
|
+
const send = (line) => {
|
|
47
|
+
pending = null;
|
|
48
|
+
flushTimer = cancel(flushTimer);
|
|
49
|
+
lastEmitAt = now();
|
|
50
|
+
emit(line);
|
|
51
|
+
};
|
|
52
|
+
const schedule = (line) => {
|
|
53
|
+
const wait = lastEmitAt + INSTALL_PROGRESS_INTERVAL_MS - now();
|
|
54
|
+
if (wait <= 0) {
|
|
55
|
+
send(line);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
pending = line;
|
|
59
|
+
if (flushTimer === null) {
|
|
60
|
+
flushTimer = start(() => {
|
|
61
|
+
flushTimer = null;
|
|
62
|
+
if (pending)
|
|
63
|
+
send(pending);
|
|
64
|
+
}, wait);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const downloadBytes = () => {
|
|
68
|
+
let done = 0;
|
|
69
|
+
let total = 0;
|
|
70
|
+
let known = 0;
|
|
71
|
+
for (const file of files.values()) {
|
|
72
|
+
done += file.received;
|
|
73
|
+
if (file.total !== null) {
|
|
74
|
+
total += file.total;
|
|
75
|
+
known += 1;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const allKnown = expectedFiles !== null && known >= expectedFiles;
|
|
79
|
+
return { done: allKnown ? Math.min(done, total) : done, total: allKnown ? total : null };
|
|
80
|
+
};
|
|
81
|
+
const line = (next, target, extra = {}) => {
|
|
82
|
+
fraction = Math.min(1, Math.max(fraction, target));
|
|
83
|
+
const bytes = next === "download" ? downloadBytes() : null;
|
|
84
|
+
return {
|
|
85
|
+
event: "install",
|
|
86
|
+
phase: next,
|
|
87
|
+
bytesDone: bytes ? bytes.done : null,
|
|
88
|
+
bytesTotal: bytes ? bytes.total : null,
|
|
89
|
+
fraction: Math.floor(fraction * 1000) / 1000,
|
|
90
|
+
message: MESSAGES[next],
|
|
91
|
+
...extra,
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
const enter = (next, within) => {
|
|
95
|
+
if (finished)
|
|
96
|
+
return;
|
|
97
|
+
const index = PHASE_ORDER.indexOf(next);
|
|
98
|
+
const current = phase === null ? -1 : PHASE_ORDER.indexOf(phase);
|
|
99
|
+
if (index < current)
|
|
100
|
+
return;
|
|
101
|
+
const [from, to] = INSTALL_PHASE_SPANS[next];
|
|
102
|
+
const target = from + (to - from) * Math.min(1, Math.max(0, within));
|
|
103
|
+
if (index > current) {
|
|
104
|
+
if (pending)
|
|
105
|
+
send(pending);
|
|
106
|
+
phase = next;
|
|
107
|
+
send(line(next, target));
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
schedule(line(next, target));
|
|
111
|
+
};
|
|
112
|
+
const creep = () => {
|
|
113
|
+
creepTimer = null;
|
|
114
|
+
if (finished || creeping === null || phase !== creeping.phase)
|
|
115
|
+
return;
|
|
116
|
+
const elapsed = now() - creeping.since;
|
|
117
|
+
const share = creeping.base + (1 - creeping.base) * (1 - Math.exp(-elapsed / creeping.expectedMs));
|
|
118
|
+
enter(creeping.phase, Math.min(share, 0.98));
|
|
119
|
+
creepTimer = start(creep, INSTALL_PROGRESS_INTERVAL_MS);
|
|
120
|
+
};
|
|
121
|
+
const startCreep = (next, base, expectedMs) => {
|
|
122
|
+
creeping = { phase: next, since: now(), base, expectedMs };
|
|
123
|
+
creepTimer = cancel(creepTimer);
|
|
124
|
+
creepTimer = start(creep, INSTALL_PROGRESS_INTERVAL_MS);
|
|
125
|
+
};
|
|
126
|
+
const tracker = ((event) => {
|
|
127
|
+
if (finished)
|
|
128
|
+
return;
|
|
129
|
+
switch (event.phase) {
|
|
130
|
+
case "download-start":
|
|
131
|
+
expectedFiles = event.files;
|
|
132
|
+
installedSomething = true;
|
|
133
|
+
enter("download", 0);
|
|
134
|
+
return;
|
|
135
|
+
case "download": {
|
|
136
|
+
installedSomething = true;
|
|
137
|
+
files.set(event.file, { received: event.received, total: event.total });
|
|
138
|
+
const bytes = downloadBytes();
|
|
139
|
+
enter("download", bytes.total ? bytes.done / Math.max(bytes.total, 1) : 0);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
case "verify":
|
|
143
|
+
enter("verify", 0);
|
|
144
|
+
return;
|
|
145
|
+
case "python":
|
|
146
|
+
enter("prepare", 0);
|
|
147
|
+
startCreep("prepare", 0, PREPARE_EXPECTED_MS);
|
|
148
|
+
return;
|
|
149
|
+
case "extract":
|
|
150
|
+
installedSomething = true;
|
|
151
|
+
enter("unpack", 0);
|
|
152
|
+
return;
|
|
153
|
+
case "environment":
|
|
154
|
+
installedSomething = true;
|
|
155
|
+
enter("environment", 0);
|
|
156
|
+
return;
|
|
157
|
+
case "packages":
|
|
158
|
+
installedSomething = true;
|
|
159
|
+
enter("environment", ENVIRONMENT_SETUP_SHARE);
|
|
160
|
+
startCreep("environment", ENVIRONMENT_SETUP_SHARE, PACKAGES_EXPECTED_MS);
|
|
161
|
+
return;
|
|
162
|
+
case "ready":
|
|
163
|
+
if (event.step === "download") {
|
|
164
|
+
if (!event.cached)
|
|
165
|
+
enter("verify", 1);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
finished = true;
|
|
169
|
+
creepTimer = cancel(creepTimer);
|
|
170
|
+
if (pending)
|
|
171
|
+
send(pending);
|
|
172
|
+
phase = "done";
|
|
173
|
+
send(line("done", 1, installedSomething ? {} : { cached: true, message: "The runtime is already on this computer" }));
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
tracker.stop = () => {
|
|
178
|
+
finished = true;
|
|
179
|
+
creepTimer = cancel(creepTimer);
|
|
180
|
+
flushTimer = cancel(flushTimer);
|
|
181
|
+
pending = null;
|
|
182
|
+
};
|
|
183
|
+
return tracker;
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=install-progress.js.map
|
|
@@ -29,6 +29,27 @@ export declare const GROK_HOLDER_SCAN_TTL_MS = 30000;
|
|
|
29
29
|
export declare function resetGrokHolderScan(): void;
|
|
30
30
|
/** Mirrors the helper's `_existing_machine_oauth`: another Fleet bot here holds a Grok OAuth login. */
|
|
31
31
|
export declare function grokLoginReadableHere(exclude: string, deps?: GrokLoginProbeDeps, now?: number): LegacyProviderLogin;
|
|
32
|
-
|
|
32
|
+
export declare const GROK_CLI_AUTH_ISSUER = "https://auth.x.ai";
|
|
33
|
+
export declare const FLEET_XAI_OAUTH_CLIENT_ID = "b1a00492-073a-47ea-816f-4c329264a828";
|
|
34
|
+
export declare function grokCliAuthPath(homedir?: string, env?: NodeJS.ProcessEnv): string;
|
|
35
|
+
export declare function grokCliLoginReadable(homedir?: string, env?: NodeJS.ProcessEnv): LegacyProviderLogin;
|
|
36
|
+
export declare function fleetHelperSharesGrokCliLogin(): boolean;
|
|
37
|
+
export interface GrokSignInDeps {
|
|
38
|
+
sibling?: () => LegacyProviderLogin;
|
|
39
|
+
cli?: () => LegacyProviderLogin;
|
|
40
|
+
cliImport?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export declare function grokSignInReusableHere(exclude: string, deps?: GrokSignInDeps): LegacyProviderLogin;
|
|
43
|
+
/** The live probe for a bot: Codex from its login home, Grok from the Grok CLI or the other Fleet bots here. */
|
|
33
44
|
export declare function legacyProviderLoginProbe(dir: string, config: Pick<BotConfig, "name" | "agentUid" | "runtime" | "runtimeAuth" | "hqRoot">): LegacyProviderLoginProbe;
|
|
45
|
+
export type FleetSignInProvider = "chatgpt" | "grok";
|
|
46
|
+
export interface FleetSignInHereDeps {
|
|
47
|
+
env?: NodeJS.ProcessEnv;
|
|
48
|
+
homedir?: string;
|
|
49
|
+
grok?: () => LegacyProviderLogin;
|
|
50
|
+
grokCli?: () => LegacyProviderLogin;
|
|
51
|
+
grokCliImport?: boolean;
|
|
52
|
+
now?: number;
|
|
53
|
+
}
|
|
54
|
+
export declare function fleetSignInReusableHere(provider: FleetSignInProvider, deps?: FleetSignInHereDeps): LegacyProviderLogin;
|
|
34
55
|
//# sourceMappingURL=legacy-provider-login.d.ts.map
|
|
@@ -6,18 +6,20 @@
|
|
|
6
6
|
* ~/.codex/auth.json) with a refreshable, unexpired token. A bot with its
|
|
7
7
|
* own Codex login (hq bot login) or a capacity account imports from that
|
|
8
8
|
* home instead, so the account it answered with comes along.
|
|
9
|
-
* - Grok: the
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* - Grok: the helper copies another Fleet bot's Grok login, and from release
|
|
10
|
+
* 0.4.31 (local builds from 0.4.31-local.13) also shares the Grok CLI login
|
|
11
|
+
* in <GROK_HOME>/auth.json, else ~/.grok/auth.json (a record for the
|
|
12
|
+
* runtime's xAI client with a refresh token). Its own
|
|
13
|
+
* device-code sign-in needs a browser.
|
|
12
14
|
*
|
|
13
|
-
* Nothing here
|
|
14
|
-
*
|
|
15
|
-
* for a yes or no.
|
|
15
|
+
* Nothing here prints or copies a credential value: the Codex check decodes
|
|
16
|
+
* only the token's expiry claim, the Grok CLI check looks only at which
|
|
17
|
+
* fields are present, and the Fleet bot check asks the helper for a yes or no.
|
|
16
18
|
*/
|
|
17
19
|
import * as fs from "node:fs";
|
|
18
20
|
import * as os from "node:os";
|
|
19
21
|
import * as path from "node:path";
|
|
20
|
-
import { fleetLocalProviderAuthStatus, listFleetLocalProfiles } from "./fleet-local.js";
|
|
22
|
+
import { cachedFleetLocalTargetRelease, fleetLocalProviderAuthStatus, fleetReleaseImportsGrokCli, listFleetLocalProfiles } from "./fleet-local.js";
|
|
21
23
|
import { botOwnAuthHome, botRuntimeAuth, capacityAccountHome } from "./runtime-auth.js";
|
|
22
24
|
export function codexCliAuthPath(home) {
|
|
23
25
|
return path.join(home, "auth.json");
|
|
@@ -126,13 +128,57 @@ export function grokLoginReadableHere(exclude, deps = {}, now = Date.now()) {
|
|
|
126
128
|
detail: others.length ? `none of the ${others.length} other HQ Fleet bot(s) on this computer is signed in to Grok` : "no other HQ Fleet bot on this computer is signed in to Grok",
|
|
127
129
|
};
|
|
128
130
|
}
|
|
129
|
-
|
|
131
|
+
export const GROK_CLI_AUTH_ISSUER = "https://auth.x.ai";
|
|
132
|
+
export const FLEET_XAI_OAUTH_CLIENT_ID = "b1a00492-073a-47ea-816f-4c329264a828";
|
|
133
|
+
export function grokCliAuthPath(homedir = os.homedir(), env = process.env) {
|
|
134
|
+
const configured = env.GROK_HOME?.trim();
|
|
135
|
+
return path.join(configured ? path.resolve(configured.replace(/^~(?=$|[\\/])/, homedir)) : path.join(homedir, ".grok"), "auth.json");
|
|
136
|
+
}
|
|
137
|
+
export function grokCliLoginReadable(homedir = os.homedir(), env = process.env) {
|
|
138
|
+
const file = grokCliAuthPath(homedir, env);
|
|
139
|
+
if (!fs.existsSync(file))
|
|
140
|
+
return { readable: false, detail: `no Grok CLI login at ${file}` };
|
|
141
|
+
let record;
|
|
142
|
+
try {
|
|
143
|
+
const parsed = JSON.parse(fs.readFileSync(file, "utf8").replace(/^\uFEFF/, ""));
|
|
144
|
+
record = parsed && typeof parsed === "object" && !Array.isArray(parsed)
|
|
145
|
+
? parsed[`${GROK_CLI_AUTH_ISSUER}::${FLEET_XAI_OAUTH_CLIENT_ID}`]
|
|
146
|
+
: undefined;
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
return { readable: false, detail: `${file} could not be read` };
|
|
150
|
+
}
|
|
151
|
+
const fields = record && typeof record === "object" && !Array.isArray(record) ? record : null;
|
|
152
|
+
const present = (name) => typeof fields?.[name] === "string" && fields[name].trim() !== "";
|
|
153
|
+
const clientId = fields?.oidc_client_id;
|
|
154
|
+
const clientMatches = clientId === undefined || clientId === null || (typeof clientId === "string" && ["", FLEET_XAI_OAUTH_CLIENT_ID].includes(clientId.trim()));
|
|
155
|
+
if (!present("key") || !present("refresh_token") || !clientMatches)
|
|
156
|
+
return { readable: false, detail: `${file} holds no refreshable Grok CLI login for HQ Fleet` };
|
|
157
|
+
return { readable: true, detail: `Grok CLI login at ${file}` };
|
|
158
|
+
}
|
|
159
|
+
export function fleetHelperSharesGrokCliLogin() {
|
|
160
|
+
try {
|
|
161
|
+
return fleetReleaseImportsGrokCli(cachedFleetLocalTargetRelease().release.version);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
export function grokSignInReusableHere(exclude, deps = {}) {
|
|
168
|
+
if (deps.cliImport ?? fleetHelperSharesGrokCliLogin()) {
|
|
169
|
+
const cli = (deps.cli ?? (() => grokCliLoginReadable()))();
|
|
170
|
+
if (cli.readable)
|
|
171
|
+
return cli;
|
|
172
|
+
}
|
|
173
|
+
return (deps.sibling ?? (() => grokLoginReadableHere(exclude)))();
|
|
174
|
+
}
|
|
175
|
+
/** The live probe for a bot: Codex from its login home, Grok from the Grok CLI or the other Fleet bots here. */
|
|
130
176
|
export function legacyProviderLoginProbe(dir, config) {
|
|
131
177
|
return (runtime) => {
|
|
132
178
|
if (runtime === "grok") {
|
|
133
179
|
if (config.runtimeAuth?.grok !== undefined)
|
|
134
180
|
return { readable: false, detail: "it uses its own Grok login, which HQ Fleet Local cannot import" };
|
|
135
|
-
return
|
|
181
|
+
return grokSignInReusableHere(config.agentUid);
|
|
136
182
|
}
|
|
137
183
|
const home = legacyCodexHome(dir, config);
|
|
138
184
|
if ("error" in home)
|
|
@@ -141,4 +187,16 @@ export function legacyProviderLoginProbe(dir, config) {
|
|
|
141
187
|
return home.env && login.readable ? { ...login, env: home.env } : login;
|
|
142
188
|
};
|
|
143
189
|
}
|
|
190
|
+
export function fleetSignInReusableHere(provider, deps = {}) {
|
|
191
|
+
if (provider === "grok") {
|
|
192
|
+
return grokSignInReusableHere("", {
|
|
193
|
+
...(deps.grok ? { sibling: deps.grok } : {}),
|
|
194
|
+
cli: deps.grokCli ?? (() => grokCliLoginReadable(deps.homedir ?? os.homedir(), deps.env ?? process.env)),
|
|
195
|
+
...(deps.grokCliImport !== undefined ? { cliImport: deps.grokCliImport } : {}),
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
const env = deps.env ?? process.env;
|
|
199
|
+
const home = env.CODEX_HOME?.trim() || path.join(deps.homedir ?? os.homedir(), ".codex");
|
|
200
|
+
return codexCliLoginReadable(home, deps.now ?? Date.now());
|
|
201
|
+
}
|
|
144
202
|
//# sourceMappingURL=legacy-provider-login.js.map
|
package/dist/lib/bot/prompt.d.ts
CHANGED
|
@@ -146,5 +146,6 @@ export declare function scheduledJobsParagraph(botName: string): string;
|
|
|
146
146
|
export declare function introDmText(botName: string, runtime: string, intro?: string, identity?: {
|
|
147
147
|
kind?: BotKind;
|
|
148
148
|
companies?: string[];
|
|
149
|
+
displayName?: string;
|
|
149
150
|
}): string;
|
|
150
151
|
//# sourceMappingURL=prompt.d.ts.map
|
package/dist/lib/bot/prompt.js
CHANGED
|
@@ -449,11 +449,12 @@ export function scheduledJobsParagraph(botName) {
|
|
|
449
449
|
export function introDmText(botName, runtime, intro, identity = {}) {
|
|
450
450
|
if (intro?.trim())
|
|
451
451
|
return intro.trim();
|
|
452
|
+
const spokenName = identity.displayName?.trim() || botName;
|
|
452
453
|
const runtimeLabel = runtime === "claude" ? "Claude Code" : runtime === "codex" ? "Codex" : runtime === "grok" ? "Grok" : runtime;
|
|
453
454
|
const companies = (identity.companies ?? []).filter((c) => c.trim());
|
|
454
455
|
const opening = (identity.kind ?? "personal") === "company"
|
|
455
|
-
? `Hi, I'm ${
|
|
456
|
-
: `Hi, I'm ${
|
|
456
|
+
? `Hi, I'm ${spokenName} — your HQ company bot. I run locally on this computer with my own identity, as a member of ${companies.length > 0 ? companies.join(", ") : "my companies"}, so I can only work inside ${companies.length === 1 ? "that company" : "those companies"}.`
|
|
457
|
+
: `Hi, I'm ${spokenName} — your HQ bot. I run locally on this computer using your ${runtimeLabel} login, so I can work inside your HQ with your permissions.`;
|
|
457
458
|
return (`${opening}\n\n` +
|
|
458
459
|
`You can message me here from the desktop app or your phone whenever this computer is on, and I'll reply in this thread. ` +
|
|
459
460
|
`You can also open me in Claude Code or Codex from your HQ folder.\n\n` +
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type FleetLocalGatewayState } from "./fleet-local.js";
|
|
2
|
+
export type BotReadiness = "creating" | "installing" | "starting" | "ready" | "offline";
|
|
3
|
+
export declare const BOT_READINESS_VALUES: readonly BotReadiness[];
|
|
4
|
+
export type BotSetupStep = "identity" | "install" | "starting" | "ready";
|
|
5
|
+
export declare const BOT_SETUP_STEPS: ReadonlyArray<{
|
|
6
|
+
step: BotSetupStep;
|
|
7
|
+
label: string;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const BOT_SETUP_MARKER_FILE = "setup-step.json";
|
|
10
|
+
export declare const DEFAULT_BOT_READY_TIMEOUT_SECONDS = 300;
|
|
11
|
+
export declare const GATEWAY_READY_POLL_MS = 250;
|
|
12
|
+
export declare const RUNTIME_ESTIMATE_NOT_INSTALLED = "about 5 minutes";
|
|
13
|
+
export declare const RUNTIME_ESTIMATE_INSTALLED = "about a minute";
|
|
14
|
+
export declare function botCreateEstimate(runtimeInstalled: boolean): string;
|
|
15
|
+
export declare function setupStepLabel(step: BotSetupStep): string;
|
|
16
|
+
export declare function writeBotSetupStep(dir: string, step: BotSetupStep, pid?: number, now?: Date): void;
|
|
17
|
+
export declare function clearBotSetupStep(dir: string, pid?: number): void;
|
|
18
|
+
export declare function readBotSetupStep(dir: string, alive?: (pid: number) => boolean): BotSetupStep | null;
|
|
19
|
+
export interface ReadinessFacts {
|
|
20
|
+
setupStep: BotSetupStep | null;
|
|
21
|
+
fleet: boolean;
|
|
22
|
+
processAlive: boolean;
|
|
23
|
+
livePid?: number | null;
|
|
24
|
+
gateway: Pick<FleetLocalGatewayState, "gatewayState" | "ready" | "pid"> | null;
|
|
25
|
+
}
|
|
26
|
+
export declare function deriveBotReadiness(facts: ReadinessFacts): BotReadiness;
|
|
27
|
+
export interface BotReadinessReport {
|
|
28
|
+
readiness: BotReadiness;
|
|
29
|
+
ready: boolean;
|
|
30
|
+
readyAt: string | null;
|
|
31
|
+
}
|
|
32
|
+
export declare function botReadinessReport(facts: ReadinessFacts & {
|
|
33
|
+
gateway: FleetLocalGatewayState | null;
|
|
34
|
+
}): BotReadinessReport;
|
|
35
|
+
export interface HeartbeatReadyComponents {
|
|
36
|
+
ready: boolean;
|
|
37
|
+
readyAt: string | null;
|
|
38
|
+
}
|
|
39
|
+
export declare function heartbeatReadyComponents(runnerStartedAt: string): HeartbeatReadyComponents;
|
|
40
|
+
export interface ReadyWaitResult {
|
|
41
|
+
ready: boolean;
|
|
42
|
+
readyAt: string | null;
|
|
43
|
+
timedOut: boolean;
|
|
44
|
+
failed: string | null;
|
|
45
|
+
waitedMs: number;
|
|
46
|
+
}
|
|
47
|
+
export declare function waitForGatewayReady(agentUid: string, opts: {
|
|
48
|
+
timeoutMs: number;
|
|
49
|
+
pollMs?: number;
|
|
50
|
+
fleetHome?: string;
|
|
51
|
+
now?: () => number;
|
|
52
|
+
sleep?: (ms: number) => Promise<void>;
|
|
53
|
+
alive?: (pid: number) => boolean;
|
|
54
|
+
}): Promise<ReadyWaitResult>;
|
|
55
|
+
export type SetupStepStatus = "pending" | "active" | "done" | "skipped" | "timeout" | "failed";
|
|
56
|
+
export interface SetupStepRecord {
|
|
57
|
+
step: BotSetupStep;
|
|
58
|
+
label: string;
|
|
59
|
+
status: SetupStepStatus;
|
|
60
|
+
}
|
|
61
|
+
export interface SetupStepReporter {
|
|
62
|
+
begin(step: BotSetupStep): void;
|
|
63
|
+
finish(step: BotSetupStep, status: Exclude<SetupStepStatus, "pending" | "active">): void;
|
|
64
|
+
identify(agentUid: string): void;
|
|
65
|
+
steps(): SetupStepRecord[];
|
|
66
|
+
}
|
|
67
|
+
export declare function createSetupStepReporter(mode: "text" | "json" | "silent", write?: (line: string) => void): SetupStepReporter;
|
|
68
|
+
//# sourceMappingURL=readiness.d.ts.map
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { readFleetLocalGatewayState } from "./fleet-local.js";
|
|
4
|
+
import { isPidAlive } from "./status.js";
|
|
5
|
+
export const BOT_READINESS_VALUES = ["creating", "installing", "starting", "ready", "offline"];
|
|
6
|
+
export const BOT_SETUP_STEPS = [
|
|
7
|
+
{ step: "install", label: "Installing on this Mac" },
|
|
8
|
+
{ step: "identity", label: "Creating identity" },
|
|
9
|
+
{ step: "starting", label: "Starting" },
|
|
10
|
+
{ step: "ready", label: "Ready to chat" },
|
|
11
|
+
];
|
|
12
|
+
export const BOT_SETUP_MARKER_FILE = "setup-step.json";
|
|
13
|
+
export const DEFAULT_BOT_READY_TIMEOUT_SECONDS = 300;
|
|
14
|
+
export const GATEWAY_READY_POLL_MS = 250;
|
|
15
|
+
export const RUNTIME_ESTIMATE_NOT_INSTALLED = "about 5 minutes";
|
|
16
|
+
export const RUNTIME_ESTIMATE_INSTALLED = "about a minute";
|
|
17
|
+
export function botCreateEstimate(runtimeInstalled) {
|
|
18
|
+
return runtimeInstalled ? RUNTIME_ESTIMATE_INSTALLED : RUNTIME_ESTIMATE_NOT_INSTALLED;
|
|
19
|
+
}
|
|
20
|
+
export function setupStepLabel(step) {
|
|
21
|
+
return BOT_SETUP_STEPS.find((entry) => entry.step === step).label;
|
|
22
|
+
}
|
|
23
|
+
export function writeBotSetupStep(dir, step, pid = process.pid, now = new Date()) {
|
|
24
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
25
|
+
const file = path.join(dir, BOT_SETUP_MARKER_FILE);
|
|
26
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
27
|
+
fs.writeFileSync(temporary, `${JSON.stringify({ step, pid, at: now.toISOString() })}\n`, { mode: 0o600 });
|
|
28
|
+
fs.renameSync(temporary, file);
|
|
29
|
+
}
|
|
30
|
+
export function clearBotSetupStep(dir, pid = process.pid) {
|
|
31
|
+
const file = path.join(dir, BOT_SETUP_MARKER_FILE);
|
|
32
|
+
try {
|
|
33
|
+
const marker = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
34
|
+
if (marker && marker.pid !== pid)
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
if (!fs.existsSync(file))
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
fs.rmSync(file, { force: true });
|
|
42
|
+
}
|
|
43
|
+
export function readBotSetupStep(dir, alive = isPidAlive) {
|
|
44
|
+
let marker;
|
|
45
|
+
try {
|
|
46
|
+
marker = JSON.parse(fs.readFileSync(path.join(dir, BOT_SETUP_MARKER_FILE), "utf8"));
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
if (!marker || typeof marker.pid !== "number" || !alive(marker.pid))
|
|
52
|
+
return null;
|
|
53
|
+
return BOT_SETUP_STEPS.some((entry) => entry.step === marker.step) ? marker.step : null;
|
|
54
|
+
}
|
|
55
|
+
export function deriveBotReadiness(facts) {
|
|
56
|
+
if (facts.setupStep === "identity")
|
|
57
|
+
return "creating";
|
|
58
|
+
if (facts.setupStep === "install")
|
|
59
|
+
return "installing";
|
|
60
|
+
if (!facts.processAlive)
|
|
61
|
+
return facts.setupStep === "starting" ? "starting" : "offline";
|
|
62
|
+
if (!facts.fleet)
|
|
63
|
+
return "ready";
|
|
64
|
+
const current = facts.livePid === undefined || facts.livePid === null || facts.gateway?.pid === facts.livePid;
|
|
65
|
+
if (current && facts.gateway?.gatewayState === "running" && facts.gateway.ready)
|
|
66
|
+
return "ready";
|
|
67
|
+
return "starting";
|
|
68
|
+
}
|
|
69
|
+
export function botReadinessReport(facts) {
|
|
70
|
+
const readiness = deriveBotReadiness(facts);
|
|
71
|
+
const ready = readiness === "ready";
|
|
72
|
+
return { readiness, ready, readyAt: ready && facts.fleet ? (facts.gateway?.readyAt ?? null) : null };
|
|
73
|
+
}
|
|
74
|
+
export function heartbeatReadyComponents(runnerStartedAt) {
|
|
75
|
+
return { ready: true, readyAt: runnerStartedAt };
|
|
76
|
+
}
|
|
77
|
+
export async function waitForGatewayReady(agentUid, opts) {
|
|
78
|
+
const now = opts.now ?? Date.now;
|
|
79
|
+
const sleep = opts.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
80
|
+
const alive = opts.alive ?? isPidAlive;
|
|
81
|
+
const pollMs = opts.pollMs ?? GATEWAY_READY_POLL_MS;
|
|
82
|
+
const started = now();
|
|
83
|
+
let seenPid = null;
|
|
84
|
+
for (;;) {
|
|
85
|
+
const gateway = readFleetLocalGatewayState(agentUid, opts.fleetHome ? { fleetHome: opts.fleetHome } : {});
|
|
86
|
+
const running = gateway !== null && gateway.pid !== null && alive(gateway.pid);
|
|
87
|
+
if (running)
|
|
88
|
+
seenPid = gateway.pid;
|
|
89
|
+
if (running && gateway.gatewayState === "running" && gateway.ready) {
|
|
90
|
+
return { ready: true, readyAt: gateway.readyAt, timedOut: false, failed: null, waitedMs: now() - started };
|
|
91
|
+
}
|
|
92
|
+
if (running && gateway.gatewayState === "startup_failed") {
|
|
93
|
+
return { ready: false, readyAt: null, timedOut: false, failed: "the gateway failed to start", waitedMs: now() - started };
|
|
94
|
+
}
|
|
95
|
+
if (!running && seenPid !== null) {
|
|
96
|
+
return { ready: false, readyAt: null, timedOut: false, failed: "the gateway stopped while it was starting", waitedMs: now() - started };
|
|
97
|
+
}
|
|
98
|
+
if (now() - started >= opts.timeoutMs) {
|
|
99
|
+
return { ready: false, readyAt: null, timedOut: true, failed: null, waitedMs: now() - started };
|
|
100
|
+
}
|
|
101
|
+
await sleep(pollMs);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export function createSetupStepReporter(mode, write = (line) => { process.stdout.write(`${line}\n`); }) {
|
|
105
|
+
const records = BOT_SETUP_STEPS.map((entry) => ({ ...entry, status: "pending" }));
|
|
106
|
+
const record = (step) => records.find((entry) => entry.step === step);
|
|
107
|
+
let agentUid = null;
|
|
108
|
+
const emit = (entry) => {
|
|
109
|
+
if (mode === "json") {
|
|
110
|
+
write(JSON.stringify({ event: "step", step: entry.step, label: entry.label, status: entry.status, ...(agentUid ? { agentUid } : {}) }));
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (mode !== "text")
|
|
114
|
+
return;
|
|
115
|
+
const position = `${records.indexOf(entry) + 1}/${records.length}`;
|
|
116
|
+
if (entry.status === "active")
|
|
117
|
+
write(`[${position}] ${entry.label}…`);
|
|
118
|
+
else if (entry.status === "skipped")
|
|
119
|
+
write(`[${position}] ${entry.label}: skipped`);
|
|
120
|
+
else if (entry.status === "timeout")
|
|
121
|
+
write(`[${position}] ${entry.label}: not yet`);
|
|
122
|
+
else if (entry.status === "failed")
|
|
123
|
+
write(`[${position}] ${entry.label}: failed`);
|
|
124
|
+
};
|
|
125
|
+
return {
|
|
126
|
+
begin(step) {
|
|
127
|
+
const entry = record(step);
|
|
128
|
+
entry.status = "active";
|
|
129
|
+
emit(entry);
|
|
130
|
+
},
|
|
131
|
+
finish(step, status) {
|
|
132
|
+
const entry = record(step);
|
|
133
|
+
entry.status = status;
|
|
134
|
+
emit(entry);
|
|
135
|
+
},
|
|
136
|
+
identify(uid) {
|
|
137
|
+
agentUid = uid;
|
|
138
|
+
const active = records.find((entry) => entry.status === "active");
|
|
139
|
+
if (active)
|
|
140
|
+
emit(active);
|
|
141
|
+
},
|
|
142
|
+
steps: () => records.map((entry) => ({ ...entry })),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=readiness.js.map
|
package/dist/lib/bot/run.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { type HeartbeatAgentUidSource, type HeartbeatCredsSource, type Heartbeat
|
|
|
14
14
|
import { type BotState, type BotStatusFile } from "./status.js";
|
|
15
15
|
import { type CliUpdate, type CliUpdateWatch } from "./cli-update.js";
|
|
16
16
|
import { createInboxWakeWatcher } from "./inbox-wake.js";
|
|
17
|
+
import { type HeartbeatReadyComponents } from "./readiness.js";
|
|
17
18
|
export declare const INBOX_POLL_INTERVAL_MS = 2000;
|
|
18
19
|
export declare const INBOX_MQTT_WAKE_FALLBACK_MS = 60000;
|
|
19
20
|
export declare const HEARTBEAT_INTERVAL_MS = 30000;
|
|
@@ -125,6 +126,7 @@ export interface BotRunDeps {
|
|
|
125
126
|
ownerAlerted?: boolean;
|
|
126
127
|
}>;
|
|
127
128
|
heartbeatIntervalMs?: number;
|
|
129
|
+
readyComponents?: () => HeartbeatReadyComponents;
|
|
128
130
|
/** Override the rendered system prompt (tests). */
|
|
129
131
|
systemPromptOverride?: string;
|
|
130
132
|
/** Signal source; defaults to `process`. */
|
package/dist/lib/bot/run.js
CHANGED
|
@@ -107,6 +107,7 @@ import { CLI_UPDATE_RESTART_EXIT_CODE, describeCliUpdate } from "./cli-update.js
|
|
|
107
107
|
import { createInboxMqttWakeFlagReader, createInboxPollBackoffFlagReader, safeErrorClass } from "./inbox-poll-backoff-flag.js";
|
|
108
108
|
import { createInboxWakeWatcher } from "./inbox-wake.js";
|
|
109
109
|
import { workMeshRoot } from "../mesh/live/paths.js";
|
|
110
|
+
import { heartbeatReadyComponents } from "./readiness.js";
|
|
110
111
|
export const INBOX_POLL_INTERVAL_MS = 2_000;
|
|
111
112
|
export const INBOX_MQTT_WAKE_FALLBACK_MS = 60_000;
|
|
112
113
|
export const HEARTBEAT_INTERVAL_MS = 30_000;
|
|
@@ -467,6 +468,8 @@ export async function runBot(deps) {
|
|
|
467
468
|
};
|
|
468
469
|
const jobQuietOptionEnabled = deps.jobQuietOptionEnabled ?? botJobQuietOptionEnabled;
|
|
469
470
|
const heartbeatIntervalMs = deps.heartbeatIntervalMs ?? HEARTBEAT_INTERVAL_MS;
|
|
471
|
+
const runStartedAt = now().toISOString();
|
|
472
|
+
const readyComponents = deps.readyComponents ?? (() => heartbeatReadyComponents(runStartedAt));
|
|
470
473
|
const exit = deps.exit ?? ((code) => process.exit(code));
|
|
471
474
|
const fallback = () => defaultBotStatus(pid, config.runtime, now);
|
|
472
475
|
// status.json is a report: a failed write (a full disk) is logged once and
|
|
@@ -845,7 +848,7 @@ export async function runBot(deps) {
|
|
|
845
848
|
return await stoppedDuringStartup();
|
|
846
849
|
if (!offered)
|
|
847
850
|
try {
|
|
848
|
-
const sent = await api.sendDm({ toPersonUid: config.ownerUid, body: introDmText(config.name, config.runtime, config.intro, { kind: effectiveBotKind(config), companies: effectiveBotCompanies(config) }) });
|
|
851
|
+
const sent = await api.sendDm({ toPersonUid: config.ownerUid, body: introDmText(config.name, config.runtime, config.intro, { kind: effectiveBotKind(config), companies: effectiveBotCompanies(config), ...(config.displayName ? { displayName: config.displayName } : {}) }) });
|
|
849
852
|
patchBotConfig(dir, { introSentAt: now().toISOString() });
|
|
850
853
|
log("info", "intro DM sent to owner");
|
|
851
854
|
try {
|
|
@@ -853,7 +856,7 @@ export async function runBot(deps) {
|
|
|
853
856
|
role: "assistant",
|
|
854
857
|
from: config.name,
|
|
855
858
|
fromPersonUid: config.agentUid,
|
|
856
|
-
body: introDmText(config.name, config.runtime, config.intro, { kind: effectiveBotKind(config), companies: effectiveBotCompanies(config) }),
|
|
859
|
+
body: introDmText(config.name, config.runtime, config.intro, { kind: effectiveBotKind(config), companies: effectiveBotCompanies(config), ...(config.displayName ? { displayName: config.displayName } : {}) }),
|
|
857
860
|
at: now().toISOString(),
|
|
858
861
|
...(sent?.eventId ? { eventId: sent.eventId } : {}),
|
|
859
862
|
});
|
|
@@ -1036,7 +1039,7 @@ export async function runBot(deps) {
|
|
|
1036
1039
|
try {
|
|
1037
1040
|
// The server's component vocabulary is the fleet one (sync/model/task…);
|
|
1038
1041
|
// runtime → model, inbox → task, sync → sync.
|
|
1039
|
-
await api.heartbeat(config.agentUid, { model: modelHealth, task: "ok", sync: "ok" });
|
|
1042
|
+
await api.heartbeat(config.agentUid, { model: modelHealth, task: "ok", sync: "ok", ...readyComponents() });
|
|
1040
1043
|
heartbeatFails = 0;
|
|
1041
1044
|
setStatus({
|
|
1042
1045
|
lastHeartbeatAt: now().toISOString(),
|
|
@@ -12,6 +12,8 @@ export interface ScaffoldResult {
|
|
|
12
12
|
kept: string[];
|
|
13
13
|
}
|
|
14
14
|
export interface ScaffoldOptions {
|
|
15
|
+
/** The name people call the bot ("Sky Pilot"); the handle when unset. */
|
|
16
|
+
displayName?: string;
|
|
15
17
|
/**
|
|
16
18
|
* Memory folder override: hqRoot-relative or absolute (`--memory local`
|
|
17
19
|
* keeps it under ~/.hq/bots/<name>/memory, outside the synced tree).
|
|
@@ -19,9 +21,10 @@ export interface ScaffoldOptions {
|
|
|
19
21
|
*/
|
|
20
22
|
memoryDir?: string;
|
|
21
23
|
}
|
|
22
|
-
export declare function
|
|
23
|
-
export declare function
|
|
24
|
-
export declare function
|
|
24
|
+
export declare function botSpokenName(name: string, displayName?: string): string;
|
|
25
|
+
export declare function renderWorkerYaml(name: string, agentUid: string, runtime: string, memoryDir?: string, displayName?: string): string;
|
|
26
|
+
export declare function renderPersonaMd(name: string, displayName?: string): string;
|
|
27
|
+
export declare function renderMemoryReadme(name: string, displayName?: string): string;
|
|
25
28
|
type ScaffoldFs = Pick<typeof fs, "existsSync" | "mkdirSync" | "writeFileSync">;
|
|
26
29
|
/** Absolute memory folder for a scaffold: the override (relative to hqRoot unless absolute) or the default. */
|
|
27
30
|
export declare function resolveScaffoldMemoryDir(hqRoot: string, name: string, memoryDir?: string): string;
|