@indigoai-us/hq-cli 5.345.210 → 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 +28 -0
- package/assets/scaffold/core/scripts/lib/trigger-fact-text.awk +152 -41
- 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/core-derive-trigger-facts-native.d.ts +1 -0
- package/dist/commands/core-derive-trigger-facts-native.js +61 -11
- package/dist/commands/core-work-mesh-bind-trusted-native.d.ts +14 -2
- package/dist/commands/core-work-mesh-bind-trusted-native.js +62 -8
- package/dist/commands/daemon.js +3 -0
- package/dist/commands/integrations-connect.d.ts +16 -0
- package/dist/commands/integrations-connect.js +23 -4
- 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/catalog.d.ts +9 -0
- package/dist/lib/daemon/catalog.js +13 -1
- package/dist/lib/daemon/run.d.ts +6 -3
- package/dist/lib/daemon/run.js +43 -6
- package/dist/lib/daemon/supervisor.d.ts +3 -0
- package/dist/lib/daemon/supervisor.js +64 -3
- package/dist/lib/sync-core/reconcile.js +15 -11
- package/package.json +7 -7
|
@@ -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;
|
package/dist/lib/bot/scaffold.js
CHANGED
|
@@ -5,11 +5,14 @@
|
|
|
5
5
|
import * as fs from "node:fs";
|
|
6
6
|
import * as path from "node:path";
|
|
7
7
|
import { botWorkerRelDir } from "./paths.js";
|
|
8
|
-
export function
|
|
8
|
+
export function botSpokenName(name, displayName) {
|
|
9
|
+
return displayName?.trim() || name;
|
|
10
|
+
}
|
|
11
|
+
export function renderWorkerYaml(name, agentUid, runtime, memoryDir, displayName) {
|
|
9
12
|
const memory = (memoryDir?.trim() || `personal/workers/${name}/memory`).replace(/\/+$/, "");
|
|
10
13
|
return `worker:
|
|
11
14
|
id: ${name}
|
|
12
|
-
name:
|
|
15
|
+
name: ${JSON.stringify(botSpokenName(name, displayName))}
|
|
13
16
|
description: "Personal local HQ bot (${runtime}) — runs on this computer with the owner's permissions"
|
|
14
17
|
type: PersonalBot
|
|
15
18
|
version: "1.0"
|
|
@@ -27,10 +30,12 @@ context:
|
|
|
27
30
|
- ${memory}/
|
|
28
31
|
`;
|
|
29
32
|
}
|
|
30
|
-
export function renderPersonaMd(name) {
|
|
31
|
-
|
|
33
|
+
export function renderPersonaMd(name, displayName) {
|
|
34
|
+
const spoken = botSpokenName(name, displayName);
|
|
35
|
+
const handle = spoken === name ? "" : ` Your hq bot handle is \`${name}\`; use it only in \`hq bot\` commands.`;
|
|
36
|
+
return `# ${spoken}
|
|
32
37
|
|
|
33
|
-
You are ${
|
|
38
|
+
You are ${spoken}, a personal assistant bot that lives in this HQ.${handle}
|
|
34
39
|
|
|
35
40
|
## Voice
|
|
36
41
|
|
|
@@ -45,11 +50,12 @@ You are ${name}, a personal assistant bot that lives in this HQ.
|
|
|
45
50
|
- Keep durable facts about your owner in \`memory/\` (short markdown notes).
|
|
46
51
|
`;
|
|
47
52
|
}
|
|
48
|
-
export function renderMemoryReadme(name) {
|
|
49
|
-
|
|
53
|
+
export function renderMemoryReadme(name, displayName) {
|
|
54
|
+
const spoken = botSpokenName(name, displayName);
|
|
55
|
+
return `# ${spoken} memory
|
|
50
56
|
|
|
51
|
-
Short markdown notes ${
|
|
52
|
-
context, and things the owner asked it to remember. ${
|
|
57
|
+
Short markdown notes ${spoken} keeps between conversations: preferences, recurring
|
|
58
|
+
context, and things the owner asked it to remember. ${spoken} may edit these files;
|
|
53
59
|
you can too. Never store secrets here.
|
|
54
60
|
`;
|
|
55
61
|
}
|
|
@@ -80,15 +86,15 @@ export function scaffoldBotMemory(hqRoot, name, io = fs, opts = {}) {
|
|
|
80
86
|
const memoryDir = resolveScaffoldMemoryDir(hqRoot, name, opts.memoryDir);
|
|
81
87
|
const result = { dir, memoryDir, created: [], kept: [] };
|
|
82
88
|
io.mkdirSync(memoryDir, { recursive: true });
|
|
83
|
-
writeIfMissing(io, path.join(memoryDir, "README.md"), renderMemoryReadme(name), result);
|
|
89
|
+
writeIfMissing(io, path.join(memoryDir, "README.md"), renderMemoryReadme(name, opts.displayName), result);
|
|
84
90
|
return result;
|
|
85
91
|
}
|
|
86
92
|
export function scaffoldBotWorker(hqRoot, name, agentUid, runtime, io = fs, opts = {}) {
|
|
87
93
|
const result = scaffoldBotMemory(hqRoot, name, io, opts);
|
|
88
94
|
const { dir } = result;
|
|
89
95
|
io.mkdirSync(dir, { recursive: true });
|
|
90
|
-
writeIfMissing(io, path.join(dir, "worker.yaml"), renderWorkerYaml(name, agentUid, runtime, opts.memoryDir), result);
|
|
91
|
-
writeIfMissing(io, path.join(dir, "persona.md"), renderPersonaMd(name), result);
|
|
96
|
+
writeIfMissing(io, path.join(dir, "worker.yaml"), renderWorkerYaml(name, agentUid, runtime, opts.memoryDir, opts.displayName), result);
|
|
97
|
+
writeIfMissing(io, path.join(dir, "persona.md"), renderPersonaMd(name, opts.displayName), result);
|
|
92
98
|
return result;
|
|
93
99
|
}
|
|
94
100
|
//# sourceMappingURL=scaffold.js.map
|
|
@@ -127,6 +127,14 @@ export declare const SYNC_CORE_SELFCHECK_UNIT = "sync-core-selfcheck";
|
|
|
127
127
|
export declare const SYNC_CORE_SELFCHECK_INTERVAL_SEC = 3600;
|
|
128
128
|
export declare const SYNC_CORE_MANIFEST_INTERVAL_SEC: number;
|
|
129
129
|
export declare const SYNC_CORE_LEGACY_SETTLE_MS: number;
|
|
130
|
+
export type LegacySyncHolder = {
|
|
131
|
+
status: "started";
|
|
132
|
+
startedAt: number;
|
|
133
|
+
} | {
|
|
134
|
+
status: "missing";
|
|
135
|
+
} | {
|
|
136
|
+
status: "unreadable";
|
|
137
|
+
};
|
|
130
138
|
export interface PlanContext {
|
|
131
139
|
machineType: MachineType;
|
|
132
140
|
platform: NodeJS.Platform;
|
|
@@ -157,6 +165,7 @@ export interface PlanContext {
|
|
|
157
165
|
syncCoreVaults?: readonly SyncCoreVaultPlan[];
|
|
158
166
|
syncCoreRunning?: SyncCoreRunning;
|
|
159
167
|
legacySyncReadyForCore?: boolean;
|
|
168
|
+
legacySyncHolder?: LegacySyncHolder;
|
|
160
169
|
now?: number;
|
|
161
170
|
/** A legacy desktop app or sync unit is still managing sync. */
|
|
162
171
|
desktopAppManagesSync: boolean;
|
|
@@ -241,9 +241,20 @@ function planService(service, ctx) {
|
|
|
241
241
|
: ctx.vaultSync?.offCompanies.has(vault.slug ?? "") === true;
|
|
242
242
|
const offSince = vault.legacyOffSince ? Date.parse(vault.legacyOffSince) : Number.NaN;
|
|
243
243
|
const settled = Number.isFinite(offSince) && now - offSince >= SYNC_CORE_LEGACY_SETTLE_MS;
|
|
244
|
-
const settleNeeded = ctx.
|
|
244
|
+
const settleNeeded = ctx.legacySyncHolder !== undefined
|
|
245
|
+
|| (ctx.desktopAppManagesSync && !daemonAloneRunsLegacySync(ctx));
|
|
245
246
|
const legacyReady = ctx.legacySyncReadyForCore === true && (!settleNeeded || settled);
|
|
246
247
|
const what = vault.kind === "personal" ? "the personal vault" : `the ${vault.slug} vault`;
|
|
248
|
+
const holder = ctx.legacySyncHolder;
|
|
249
|
+
const holderBlock = holder === undefined
|
|
250
|
+
? undefined
|
|
251
|
+
: holder.status === "missing"
|
|
252
|
+
? "waiting for the current sync to take the sync lock again (the runner that held it has exited)"
|
|
253
|
+
: holder.status === "unreadable"
|
|
254
|
+
? "waiting to learn when the sync that holds the sync lock started (its owner status could not be read)"
|
|
255
|
+
: !Number.isFinite(offSince) || holder.startedAt < offSince
|
|
256
|
+
? `waiting for the running sync (started before the switch was turned off for ${what}) to restart`
|
|
257
|
+
: undefined;
|
|
247
258
|
return base(service, {
|
|
248
259
|
id: syncCoreUnitId(vault.uid),
|
|
249
260
|
description: full
|
|
@@ -266,6 +277,7 @@ function planService(service, ctx) {
|
|
|
266
277
|
[!ctx.signedIn, NOT_SIGNED_IN],
|
|
267
278
|
[!!vault.blockedReason, vault.blockedReason ?? ""],
|
|
268
279
|
[full && !legacyOff, `waiting for the current sync to be turned off for ${what}`],
|
|
280
|
+
[full && !!holderBlock, holderBlock ?? ""],
|
|
269
281
|
[full && !legacyReady, ctx.legacySyncReadyForCore !== true
|
|
270
282
|
? "waiting for the current sync to run its plan without this vault"
|
|
271
283
|
: "waiting for the desktop app's sync to pick up the off-switch"],
|
package/dist/lib/daemon/run.d.ts
CHANGED
|
@@ -5,18 +5,20 @@
|
|
|
5
5
|
* legacy units, the desktop app), so enabling a service, creating a bot, or
|
|
6
6
|
* signing in takes effect without restarting the daemon.
|
|
7
7
|
*/
|
|
8
|
-
import { type PlanContext, type ServiceName, type UnitPlan } from "./catalog.js";
|
|
8
|
+
import { type LegacySyncHolder, type PlanContext, type ServiceName, type UnitPlan } from "./catalog.js";
|
|
9
9
|
import { type SyncCoreVaultPlan } from "../sync-core/engine-home.js";
|
|
10
10
|
import { type LegacyUnit, type WindowsTaskOwner } from "./legacy.js";
|
|
11
11
|
import { type DaemonLockResult } from "./lock.js";
|
|
12
12
|
import { type MachineType } from "./machine-type.js";
|
|
13
13
|
import { type PickedHqCloud } from "./hq-cloud.js";
|
|
14
|
-
import { type
|
|
14
|
+
import { type WatchRunnerOwnerStatus } from "./sync-runner.js";
|
|
15
|
+
import { type DaemonState, type HostApp, type Supervisor } from "./supervisor.js";
|
|
15
16
|
export declare const LOG_ROTATE_BYTES: number;
|
|
16
17
|
/** Exit code for "restart me": non-zero so every service manager relaunches (Windows tasks only restart on failure). */
|
|
17
18
|
export declare const RESTART_EXIT_CODE = 75;
|
|
18
19
|
export declare function syncCoreVaultPlans(home: string, hqRoot: string | undefined, platform: NodeJS.Platform): SyncCoreVaultPlan[];
|
|
19
|
-
export declare function planUnitsWithSyncCoreInterlock(services: readonly ServiceName[], context: PlanContext, supervisor: Pick<Supervisor, "runningPlanKey" | "state"> | null | undefined): UnitPlan[];
|
|
20
|
+
export declare function planUnitsWithSyncCoreInterlock(services: readonly ServiceName[], context: PlanContext, supervisor: Pick<Supervisor, "runningPlanKey" | "state"> | null | undefined, readOwnerStatus: () => WatchRunnerOwnerStatus | null): UnitPlan[];
|
|
21
|
+
export declare function legacySyncHeldByOtherOwner(units: DaemonState["units"], readOwnerStatus: () => WatchRunnerOwnerStatus | null): LegacySyncHolder | undefined;
|
|
20
22
|
/** A bounded shutdown deadline that can account for sync push persistence. */
|
|
21
23
|
export declare function createShutdownCap(): {
|
|
22
24
|
promise: Promise<"timeout">;
|
|
@@ -133,6 +135,7 @@ export declare function desktopAppManagesSync(opts: {
|
|
|
133
135
|
}): boolean;
|
|
134
136
|
/** Copy-and-truncate, so children appending with O_APPEND keep writing to the live file. */
|
|
135
137
|
export declare function rotateLogs(logsDir: string, maxBytes?: number): number;
|
|
138
|
+
export declare function prepareUnitStart(unit: Pick<UnitPlan, "id" | "env">, log: (level: "info" | "warn" | "error", msg: string) => void, alive?: (pid: number) => boolean): void;
|
|
136
139
|
/**
|
|
137
140
|
* Environment for one service process. The CLI's own update check is off:
|
|
138
141
|
* a child that updates itself exits 0 and asks to be rerun, which would leave
|