@indigoai-us/hq-cli 5.345.211 → 5.345.212

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.
Files changed (90) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/command-catalog.generated.d.ts +28 -0
  3. package/dist/command-catalog.generated.js +34 -0
  4. package/dist/command-registration-plan.d.ts +15 -0
  5. package/dist/command-registration-plan.js +20 -1
  6. package/dist/commands/agents.js +6 -1
  7. package/dist/commands/billing.js +17 -4
  8. package/dist/commands/bot-runtime.d.ts +21 -2
  9. package/dist/commands/bot-runtime.js +54 -9
  10. package/dist/commands/bot.d.ts +13 -0
  11. package/dist/commands/bot.js +142 -12
  12. package/dist/commands/daemon.js +60 -5
  13. package/dist/commands/files.js +2 -2
  14. package/dist/commands/integrations-api.d.ts +11 -0
  15. package/dist/commands/integrations-connect.d.ts +2 -0
  16. package/dist/commands/integrations-connect.js +17 -5
  17. package/dist/commands/integrations-core.d.ts +1 -1
  18. package/dist/commands/integrations-core.js +18 -10
  19. package/dist/commands/integrations.js +1 -1
  20. package/dist/commands/lanes.js +34 -16
  21. package/dist/commands/whoami.js +7 -6
  22. package/dist/lazy-commands.js +4 -1
  23. package/dist/lib/billing/usage-only.d.ts +4 -1
  24. package/dist/lib/billing/usage-only.js +7 -2
  25. package/dist/lib/bot/api.d.ts +1 -1
  26. package/dist/lib/bot/config.js +2 -1
  27. package/dist/lib/bot/fleet-daemon.d.ts +4 -0
  28. package/dist/lib/bot/fleet-daemon.js +12 -1
  29. package/dist/lib/bot/fleet-download.d.ts +6 -0
  30. package/dist/lib/bot/fleet-download.js +128 -3
  31. package/dist/lib/bot/fleet-local.d.ts +38 -1
  32. package/dist/lib/bot/fleet-local.js +239 -26
  33. package/dist/lib/bot/install-progress.d.ts +28 -0
  34. package/dist/lib/bot/install-progress.js +185 -0
  35. package/dist/lib/bot/legacy-provider-login.d.ts +22 -1
  36. package/dist/lib/bot/legacy-provider-login.js +67 -9
  37. package/dist/lib/bot/prompt.d.ts +1 -0
  38. package/dist/lib/bot/prompt.js +3 -2
  39. package/dist/lib/bot/readiness.d.ts +68 -0
  40. package/dist/lib/bot/readiness.js +145 -0
  41. package/dist/lib/bot/run.d.ts +2 -0
  42. package/dist/lib/bot/run.js +6 -3
  43. package/dist/lib/bot/scaffold.d.ts +6 -3
  44. package/dist/lib/bot/scaffold.js +18 -12
  45. package/dist/lib/capacity/ledger.d.ts +7 -0
  46. package/dist/lib/capacity/ledger.js +31 -1
  47. package/dist/lib/capacity/project.d.ts +1 -1
  48. package/dist/lib/capacity/project.js +13 -4
  49. package/dist/lib/capacity/route.d.ts +10 -0
  50. package/dist/lib/capacity/route.js +16 -0
  51. package/dist/lib/daemon/install.d.ts +15 -0
  52. package/dist/lib/daemon/install.js +31 -0
  53. package/dist/lib/daemon/migrate.js +29 -4
  54. package/dist/lib/daemon/run.d.ts +1 -0
  55. package/dist/lib/daemon/run.js +6 -1
  56. package/dist/lib/daemon/supervisor.d.ts +1 -0
  57. package/dist/lib/daemon/supervisor.js +5 -3
  58. package/dist/lib/doctor/__testing__/run-doctor.js +4 -0
  59. package/dist/lib/doctor/checks/jq.d.ts +27 -0
  60. package/dist/lib/doctor/checks/jq.js +82 -0
  61. package/dist/lib/doctor/registry.js +4 -0
  62. package/dist/lib/flag-snapshot-file.js +36 -8
  63. package/dist/lib/install/codex-targets.d.ts +52 -1
  64. package/dist/lib/install/codex-targets.js +77 -2
  65. package/dist/lib/lanes/monitor.d.ts +4 -1
  66. package/dist/lib/lanes/monitor.js +47 -10
  67. package/dist/lib/lanes/spawn.js +8 -1
  68. package/dist/lib/lanes/watch.js +31 -0
  69. package/dist/lib/onboarding/checkpoint.d.ts +6 -0
  70. package/dist/lib/onboarding/checkpoint.js +6 -0
  71. package/dist/lib/onboarding/orchestrator.d.ts +3 -1
  72. package/dist/lib/onboarding/orchestrator.js +62 -9
  73. package/dist/lib/onboarding/types.d.ts +8 -0
  74. package/dist/lib/work-context/organize.d.ts +23 -1
  75. package/dist/lib/work-context/organize.js +25 -3
  76. package/dist/lib/work-context/reconcile.js +3 -2
  77. package/dist/secrets-env-action.js +7 -5
  78. package/dist/startup-registration.js +7 -2
  79. package/dist/utils/billing-gate.d.ts +12 -16
  80. package/dist/utils/billing-gate.js +17 -18
  81. package/dist/utils/install-tree-torn.d.ts +22 -4
  82. package/dist/utils/install-tree-torn.js +24 -0
  83. package/dist/utils/registration-plan-error.d.ts +22 -0
  84. package/dist/utils/registration-plan-error.js +27 -0
  85. package/dist/utils/sentry-fingerprint.js +3 -0
  86. package/dist/utils/unauthorized-error.d.ts +36 -0
  87. package/dist/utils/unauthorized-error.js +105 -0
  88. package/dist/utils/vault-api.js +7 -5
  89. package/package.json +7 -7
  90. package/scripts/install-hook-engine.mjs +17 -0
@@ -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 runtime only copies another Fleet bot's Grok login (its own
10
- * device-code sign-in needs a browser), so the probe asks the helper of
11
- * every other Fleet bot on this computer whether it holds one.
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 reads, prints or copies a credential value: the Codex check
14
- * decodes only the token's expiry claim, and the Grok check asks the helper
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
- /** The live probe for a bot: Codex from its login home, Grok from the other Fleet bots here. */
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 grokLoginReadableHere(config.agentUid);
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
@@ -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
@@ -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 ${botName} — 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"}.`
456
- : `Hi, I'm ${botName} — your HQ bot. I run locally on this computer using your ${runtimeLabel} login, so I can work inside your HQ with your permissions.`;
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
@@ -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`. */
@@ -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 renderWorkerYaml(name: string, agentUid: string, runtime: string, memoryDir?: string): string;
23
- export declare function renderPersonaMd(name: string): string;
24
- export declare function renderMemoryReadme(name: string): string;
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;
@@ -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 renderWorkerYaml(name, agentUid, runtime, memoryDir) {
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: "${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
- return `# ${name}
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 ${name}, a personal assistant bot that lives in this HQ.
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
- return `# ${name} memory
53
+ export function renderMemoryReadme(name, displayName) {
54
+ const spoken = botSpokenName(name, displayName);
55
+ return `# ${spoken} memory
50
56
 
51
- Short markdown notes ${name} keeps between conversations: preferences, recurring
52
- context, and things the owner asked it to remember. ${name} may edit these files;
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
@@ -170,6 +170,11 @@ export interface NowAccount {
170
170
  * been able to refresh them since.
171
171
  */
172
172
  usageStale?: boolean;
173
+ /**
174
+ * Newest failure for this account that is not a sign-in problem (parse
175
+ * drift, HTTP error), absent once a later reading from the account lands.
176
+ */
177
+ lastError?: string;
173
178
  limits: NowLimit[];
174
179
  }
175
180
  export interface NowProvider {
@@ -402,4 +407,6 @@ export declare function readLedgerEvents(options?: LedgerOptions): LedgerEvent[]
402
407
  export declare function readCollectorMark(options?: LedgerOptions): CollectorMark | null;
403
408
  export declare function setCollectorEnabled(enabled: boolean, options?: LedgerOptions): CollectorMark;
404
409
  export declare function rebuildNow(options?: LedgerOptions): NowView;
410
+ /** Newest uncleared parse or HTTP error among these accounts. */
411
+ export declare function newestAccountError(accounts: readonly NowAccount[]): string | null;
405
412
  //# sourceMappingURL=ledger.d.ts.map
@@ -881,7 +881,10 @@ function materialize(events, ctx) {
881
881
  }
882
882
  if (failed)
883
883
  state = "unknown";
884
- if (limits.length === 0 && failed)
884
+ // No mapped limit is never "ok". A labelled account's parse drift or HTTP
885
+ // error is account-scoped, so `failed` misses it; without this the
886
+ // provider read "ok" with an empty table (feedback_601a961f).
887
+ if (limits.length === 0)
885
888
  state = "unknown";
886
889
  const unknownLimit = limits.find((limit) => limit.state === "unknown" && limit.lastError);
887
890
  const lastError = failed
@@ -894,6 +897,10 @@ function materialize(events, ctx) {
894
897
  }
895
898
  const unscopedFailure = bucket.failure !== null && bucket.failure.at >= bucket.latestReadingAt;
896
899
  attachAccounts(entry, events, unscopedFailure);
900
+ // With no limits, show the newest account error (parse drift, HTTP error)
901
+ // that no later reading from that account has cleared.
902
+ if (limits.length === 0 && entry.lastError === null)
903
+ entry.lastError = newestAccountError(entry.accounts ?? []);
897
904
  if (provider === "codex" && !failed && entry.accounts?.length) {
898
905
  for (const account of entry.accounts) {
899
906
  if (account.authState === "ok" && account.state === "exhausted"
@@ -972,6 +979,7 @@ function clusterAccounts(provider, events) {
972
979
  organization: cleanOrganization(event.organization),
973
980
  at,
974
981
  problem: problemFor(event.error),
982
+ failure: problemFor(event.error) ? null : event.error,
975
983
  });
976
984
  continue;
977
985
  }
@@ -985,6 +993,7 @@ function clusterAccounts(provider, events) {
985
993
  organization: cleanOrganization(reading.organization),
986
994
  at,
987
995
  problem: null,
996
+ failure: null,
988
997
  });
989
998
  }
990
999
  if (seeds.length === 0)
@@ -1035,6 +1044,8 @@ function clusterAccounts(provider, events) {
1035
1044
  let problem = null;
1036
1045
  let latestReadingAt = Number.NEGATIVE_INFINITY;
1037
1046
  let latestAt = Number.NEGATIVE_INFINITY;
1047
+ let latestDataAt = Number.NEGATIVE_INFINITY;
1048
+ let failure = null;
1038
1049
  for (const seed of members) {
1039
1050
  for (const label of seed.labels) {
1040
1051
  if (!labels.includes(label))
@@ -1051,7 +1062,13 @@ function clusterAccounts(provider, events) {
1051
1062
  latestReadingAt = seed.at;
1052
1063
  if (seed.at > latestAt)
1053
1064
  latestAt = seed.at;
1065
+ if (seed.failure !== null && (!failure || seed.at >= failure.at))
1066
+ failure = { error: seed.failure, at: seed.at };
1067
+ if (seed.problem === null && seed.failure === null && seed.at > latestDataAt)
1068
+ latestDataAt = seed.at;
1054
1069
  }
1070
+ // The account's newest parse or HTTP error, until a later reading clears it.
1071
+ const accountError = failure && failure.at >= latestDataAt ? failure.error : null;
1055
1072
  const ordered = orderLabels(labels);
1056
1073
  const primary = ordered.find((label) => label !== "default") ?? ordered[0] ?? "default";
1057
1074
  const limitedIds = ids.filter((id) => provider.limits.some((limit) => limit.accountId === id));
@@ -1099,12 +1116,25 @@ function clusterAccounts(provider, events) {
1099
1116
  : capacityLoginCommand(provider.provider, primary))
1100
1117
  : null,
1101
1118
  usageStale: usageStale ? true : undefined,
1119
+ lastError: accountError ?? undefined,
1102
1120
  limits,
1103
1121
  });
1104
1122
  }
1105
1123
  accounts.sort((a, b) => (a.labels[0] ?? "").localeCompare(b.labels[0] ?? ""));
1106
1124
  return accounts;
1107
1125
  }
1126
+ /** Newest uncleared parse or HTTP error among these accounts. */
1127
+ export function newestAccountError(accounts) {
1128
+ let best = null;
1129
+ for (const account of accounts) {
1130
+ if (!account.lastError)
1131
+ continue;
1132
+ const at = account.observedAt ?? "";
1133
+ if (!best || at > best.at)
1134
+ best = { error: account.lastError, at };
1135
+ }
1136
+ return best?.error ?? null;
1137
+ }
1108
1138
  function problemFor(error) {
1109
1139
  if (isExpiredReason(error))
1110
1140
  return { kind: "expired", reason: EXPIRED_REASON };
@@ -1,5 +1,5 @@
1
1
  import type { CapacityAccount } from "./accounts.js";
2
- import type { NowView } from "./ledger.js";
2
+ import { type NowView } from "./ledger.js";
3
3
  export interface ProjectCapacityOptions {
4
4
  accounts: readonly CapacityAccount[];
5
5
  /**