@indigoai-us/hq-cli 5.345.212 → 5.345.215-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 +49 -0
- package/dist/bin/hq-auth-refresh.js +2 -1
- package/dist/command-catalog.generated.d.ts +442 -50
- package/dist/command-catalog.generated.js +541 -50
- package/dist/commands/agent-inbox.d.ts +11 -1
- package/dist/commands/agent-inbox.js +128 -38
- package/dist/commands/agent-kit.js +2 -2
- package/dist/commands/agents.d.ts +51 -1
- package/dist/commands/agents.js +154 -2
- package/dist/commands/bot-jobs.d.ts +2 -15
- package/dist/commands/bot-jobs.js +2 -94
- package/dist/commands/bot-runtime.d.ts +46 -5
- package/dist/commands/bot-runtime.js +228 -18
- package/dist/commands/bot.d.ts +16 -9
- package/dist/commands/bot.js +169 -51
- package/dist/commands/cloud.d.ts +66 -13
- package/dist/commands/cloud.js +120 -39
- package/dist/commands/company-restore.d.ts +23 -0
- package/dist/commands/company-restore.js +128 -0
- package/dist/commands/company.js +2 -0
- package/dist/commands/core-handoff.js +1 -0
- package/dist/commands/core-hq-session-native.js +2 -2
- package/dist/commands/core-pin-native.js +1 -1
- package/dist/commands/core-policy.js +1 -1
- package/dist/commands/core-resolve-company-native.js +1 -1
- package/dist/commands/core-sentry-report-fast.d.ts +2 -0
- package/dist/commands/core-sentry-report-fast.js +3 -1
- package/dist/commands/daemon.js +11 -1
- package/dist/commands/integrations-connect.d.ts +17 -4
- package/dist/commands/integrations-connect.js +224 -26
- package/dist/commands/lanes-link.js +10 -5
- package/dist/commands/lanes.js +26 -9
- package/dist/commands/rescue.js +13 -0
- package/dist/commands/secrets.d.ts +11 -0
- package/dist/commands/secrets.js +41 -7
- package/dist/commands/sources.js +6 -0
- package/dist/commands/storage-offload.d.ts +12 -0
- package/dist/commands/storage-offload.js +41 -3
- package/dist/commands/sync-mode.js +5 -0
- package/dist/commands/whoami.js +4 -0
- package/dist/index.js +2 -0
- package/dist/lazy-commands.js +2 -0
- package/dist/lib/agent-kit/inbox-fetch.d.ts +122 -1
- package/dist/lib/agent-kit/inbox-fetch.js +215 -3
- package/dist/lib/agent-kit/inbox-redact.js +1 -1
- package/dist/lib/agent-kit/inbox-state.d.ts +98 -1
- package/dist/lib/agent-kit/inbox-state.js +261 -4
- package/dist/lib/agent-kit/mcp/tools.d.ts +3 -3
- package/dist/lib/agent-kit/mcp/tools.js +68 -25
- package/dist/lib/agent-kit/run/inbox.js +4 -2
- package/dist/lib/agent-kit/skills.js +4 -1
- package/dist/lib/agent-kit/wake.d.ts +9 -1
- package/dist/lib/agent-kit/wake.js +10 -3
- package/dist/lib/bot/config.d.ts +1 -0
- package/dist/lib/bot/config.js +10 -0
- package/dist/lib/bot/eventbridge-cron.d.ts +22 -0
- package/dist/lib/bot/eventbridge-cron.js +104 -0
- package/dist/lib/bot/fleet-cron.js +193 -14
- package/dist/lib/bot/fleet-download.d.ts +2 -0
- package/dist/lib/bot/fleet-download.js +23 -0
- package/dist/lib/bot/fleet-local.d.ts +34 -1
- package/dist/lib/bot/fleet-local.js +254 -37
- package/dist/lib/bot/fleet-python.d.ts +3 -0
- package/dist/lib/bot/fleet-python.js +34 -4
- package/dist/lib/bot/fleet-runtime-sources.d.ts +15 -0
- package/dist/lib/bot/fleet-runtime-sources.js +30 -0
- package/dist/lib/bot/legacy-provider-login.d.ts +8 -0
- package/dist/lib/bot/legacy-provider-login.js +19 -2
- package/dist/lib/bot/prompt.js +1 -1
- package/dist/lib/bot/readiness.d.ts +8 -0
- package/dist/lib/bot/readiness.js +17 -3
- package/dist/lib/bot/runtime-auth.d.ts +30 -0
- package/dist/lib/bot/runtime-auth.js +94 -3
- package/dist/lib/bot/status.d.ts +2 -0
- package/dist/lib/capacity/collectors/grok-refresh.d.ts +80 -0
- package/dist/lib/capacity/collectors/grok-refresh.js +189 -0
- package/dist/lib/capacity/collectors/grok.d.ts +5 -0
- package/dist/lib/capacity/collectors/grok.js +56 -5
- package/dist/lib/core-utils/session-id.d.ts +1 -1
- package/dist/lib/core-utils/session-id.js +4 -0
- package/dist/lib/daemon/catalog.js +11 -1
- package/dist/lib/daemon/run.js +9 -1
- package/dist/lib/daemon/updater.d.ts +34 -2
- package/dist/lib/daemon/updater.js +51 -2
- package/dist/lib/db/sqlite-binding.d.ts +1 -0
- package/dist/lib/db/sqlite-binding.js +1 -1
- package/dist/lib/delivery/artifacts.d.ts +99 -0
- package/dist/lib/delivery/artifacts.js +548 -0
- package/dist/lib/delivery/backup.d.ts +78 -0
- package/dist/lib/delivery/backup.js +343 -0
- package/dist/lib/delivery/cache.d.ts +29 -0
- package/dist/lib/delivery/cache.js +33 -0
- package/dist/lib/delivery/contracts.d.ts +142 -0
- package/dist/lib/delivery/contracts.js +289 -0
- package/dist/lib/delivery/credentials.d.ts +54 -0
- package/dist/lib/delivery/credentials.js +119 -0
- package/dist/lib/delivery/enrollment.d.ts +142 -0
- package/dist/lib/delivery/enrollment.js +382 -0
- package/dist/lib/delivery/identity.d.ts +25 -0
- package/dist/lib/delivery/identity.js +82 -0
- package/dist/lib/delivery/inbox.d.ts +116 -0
- package/dist/lib/delivery/inbox.js +260 -0
- package/dist/lib/delivery/migrations.d.ts +139 -0
- package/dist/lib/delivery/migrations.js +623 -0
- package/dist/lib/delivery/mqtt-adapter.d.ts +50 -0
- package/dist/lib/delivery/mqtt-adapter.js +242 -0
- package/dist/lib/delivery/mqtt.d.ts +61 -0
- package/dist/lib/delivery/mqtt.js +112 -0
- package/dist/lib/delivery/outbox.d.ts +95 -0
- package/dist/lib/delivery/outbox.js +187 -0
- package/dist/lib/delivery/provenance.d.ts +129 -0
- package/dist/lib/delivery/provenance.js +93 -0
- package/dist/lib/delivery/reconciler.d.ts +151 -0
- package/dist/lib/delivery/reconciler.js +492 -0
- package/dist/lib/delivery/restore.d.ts +35 -0
- package/dist/lib/delivery/restore.js +134 -0
- package/dist/lib/delivery/store.d.ts +161 -0
- package/dist/lib/delivery/store.js +940 -0
- package/dist/lib/delivery/workers/macos-job-helper.d.ts +103 -0
- package/dist/lib/delivery/workers/macos-job-helper.js +927 -0
- package/dist/lib/delivery/workers/macos.d.ts +176 -0
- package/dist/lib/delivery/workers/macos.js +901 -0
- package/dist/lib/delivery/workers/windows-boundary.d.ts +453 -0
- package/dist/lib/delivery/workers/windows-boundary.js +693 -0
- package/dist/lib/delivery/workers/windows-job-helper.d.ts +35 -0
- package/dist/lib/delivery/workers/windows-job-helper.js +264 -0
- package/dist/lib/delivery/workers/windows.d.ts +241 -0
- package/dist/lib/delivery/workers/windows.js +608 -0
- package/dist/lib/doctor/checks/release-links.d.ts +50 -8
- package/dist/lib/doctor/checks/release-links.js +260 -24
- package/dist/lib/doctor/fix/apply.js +24 -8
- package/dist/lib/doctor/fix/remediation.js +15 -5
- package/dist/lib/install/provider-wrappers.d.ts +2 -0
- package/dist/lib/install/provider-wrappers.js +68 -3
- package/dist/lib/lanes/autopilot-registry.d.ts +14 -0
- package/dist/lib/lanes/autopilot-registry.js +59 -7
- package/dist/lib/lanes/links.d.ts +14 -0
- package/dist/lib/lanes/links.js +320 -25
- package/dist/lib/lanes/outpost-pruner-install.d.ts +10 -0
- package/dist/lib/lanes/outpost-pruner-install.js +4 -3
- package/dist/main.js +3 -1
- package/dist/sentry-init.d.ts +2 -0
- package/dist/sentry-init.js +13 -2
- package/dist/sentry.d.ts +2 -0
- package/dist/sentry.js +5 -1
- package/dist/utils/cli-network-lifecycle.d.ts +9 -0
- package/dist/utils/cli-network-lifecycle.js +52 -0
- package/dist/utils/cognito-callback-port.d.ts +14 -0
- package/dist/utils/cognito-callback-port.js +24 -0
- package/dist/utils/cognito-session.js +3 -3
- package/dist/utils/deleted-company-notice.d.ts +59 -0
- package/dist/utils/deleted-company-notice.js +156 -0
- package/dist/utils/login-browser.d.ts +1 -1
- package/dist/utils/login-browser.js +7 -5
- package/dist/utils/resident-package-preload.js +30 -15
- package/dist/utils/safe-link.d.ts +63 -0
- package/dist/utils/safe-link.js +246 -0
- package/dist/utils/sentry-keepalive-transport.d.ts +28 -0
- package/dist/utils/sentry-keepalive-transport.js +70 -0
- package/dist/utils/vault-api.js +7 -0
- package/package.json +7 -7
|
@@ -23,6 +23,8 @@ import { fleetCronOps, fleetOwnerOrigin, fleetScheduleFromLegacy } from "../lib/
|
|
|
23
23
|
import { isQuietJobContext, JOB_RUN_OPTIONS_CONTEXT_KEY } from "../lib/bot/job-run.js";
|
|
24
24
|
import { BOT_JOB_QUIET_OPTION_FLAG, botJobQuietOptionEnabled } from "../lib/bot/job-quiet-flag.js";
|
|
25
25
|
import { runScheduleParse } from "./core-jobs-schedule.js";
|
|
26
|
+
import { BotJobsError, toEventBridgeCron } from "../lib/bot/eventbridge-cron.js";
|
|
27
|
+
export { BotJobsError, toEventBridgeCron };
|
|
26
28
|
// ─── Schedule translation ────────────────────────────────────────────────────
|
|
27
29
|
/** Mirrors hq-pro-agents `MIN_RECURRING_INTERVAL_SECONDS`. */
|
|
28
30
|
export const MIN_RECURRING_INTERVAL_SECONDS = 5 * 60;
|
|
@@ -30,9 +32,6 @@ export const MIN_RECURRING_INTERVAL_SECONDS = 5 * 60;
|
|
|
30
32
|
export const MAX_ACTIVE_JOBS_PER_AGENT = 25;
|
|
31
33
|
/** Mirrors hq-pro-agents `MAX_PROMPT_BYTES`. */
|
|
32
34
|
export const MAX_PROMPT_BYTES = 16 * 1024;
|
|
33
|
-
export class BotJobsError extends Error {
|
|
34
|
-
expected = true;
|
|
35
|
-
}
|
|
36
35
|
function refuse(message) {
|
|
37
36
|
throw new BotJobsError(message);
|
|
38
37
|
}
|
|
@@ -45,97 +44,6 @@ export function machineTimezone() {
|
|
|
45
44
|
return "UTC";
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Standard 5-field cron → the six-field `cron(...)` string a job is stored as.
|
|
50
|
-
*
|
|
51
|
-
* The stored form (the six-field cron syntax hosted agent jobs also use, so
|
|
52
|
-
* local and hosted jobs share one format; the function keeps its historical
|
|
53
|
-
* name) has SIX fields (a trailing year), numbers its days of week
|
|
54
|
-
* 1–7 with SUNDAY = 1 (standard cron uses 0–6 with SUNDAY = 0), and refuses
|
|
55
|
-
* `*` in BOTH the day-of-month and day-of-week fields — exactly one must be
|
|
56
|
-
* `?`. An expression that is already `cron(...)` or `rate(...)` is passed
|
|
57
|
-
* through untouched.
|
|
58
|
-
*/
|
|
59
|
-
export function toEventBridgeCron(expr) {
|
|
60
|
-
const trimmed = expr.trim();
|
|
61
|
-
// An explicit cron(...) / rate(...) is the caller saying "this is already the
|
|
62
|
-
// stored syntax" — passed through untranslated, on purpose.
|
|
63
|
-
if (/^(cron|rate)\s*\(/i.test(trimmed))
|
|
64
|
-
return trimmed;
|
|
65
|
-
const fields = trimmed.split(/\s+/).filter(Boolean);
|
|
66
|
-
if (fields.length === 6) {
|
|
67
|
-
// Six BARE fields are ambiguous: the stored form's sixth field is a
|
|
68
|
-
// trailing year, Quartz's first is leading seconds. Guessing wrong
|
|
69
|
-
// silently moves every run. Make the caller say which they mean.
|
|
70
|
-
refuse(`"${trimmed}" has six fields, and I can't tell whether the last one is a year ` +
|
|
71
|
-
`(minute hour day-of-month month day-of-week year, the form bot jobs are stored in) or the ` +
|
|
72
|
-
`first one is seconds (a Quartz expression) — reading it the wrong way would schedule the job ` +
|
|
73
|
-
`at the wrong time. Pass five fields ("0 9 * * 1-5"), or wrap it yourself as cron(...) if it ` +
|
|
74
|
-
`already ends with a year field.`);
|
|
75
|
-
}
|
|
76
|
-
if (fields.length !== 5) {
|
|
77
|
-
refuse(`"${trimmed}" is not a cron expression. A cron expression has five fields: ` +
|
|
78
|
-
`minute hour day-of-month month day-of-week (for example "0 9 * * 1-5").`);
|
|
79
|
-
}
|
|
80
|
-
const [minute, hour, month] = [fields[0], fields[1], fields[3]];
|
|
81
|
-
let dayOfMonth = fields[2];
|
|
82
|
-
let dayOfWeek = fields[4];
|
|
83
|
-
if (dayOfWeek === "*" || dayOfWeek === "?") {
|
|
84
|
-
dayOfWeek = "?";
|
|
85
|
-
if (dayOfMonth === "?")
|
|
86
|
-
dayOfMonth = "*";
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
dayOfWeek = shiftDayOfWeek(dayOfWeek);
|
|
90
|
-
if (dayOfMonth === "*")
|
|
91
|
-
dayOfMonth = "?";
|
|
92
|
-
}
|
|
93
|
-
return `cron(${minute} ${hour} ${dayOfMonth} ${month} ${dayOfWeek} *)`;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Standard 0–6 (SUN=0, and 7 also SUN) → the stored form's 1–7 (SUN=1).
|
|
97
|
-
*
|
|
98
|
-
* Mapped per TERM, not per digit. Shifting digits individually turned a range
|
|
99
|
-
* that wraps past Sunday — "6-0" (Sat–Sun), "5-1" (Fri–Mon) — into "7-1" /
|
|
100
|
-
* "6-2": reversed or plain wrong, and silently so. Such a range is refused with
|
|
101
|
-
* the list form that does work.
|
|
102
|
-
*/
|
|
103
|
-
function shiftDayOfWeek(field) {
|
|
104
|
-
return field
|
|
105
|
-
.split(",")
|
|
106
|
-
.map((term) => shiftDayOfWeekTerm(term.trim()))
|
|
107
|
-
.join(",");
|
|
108
|
-
}
|
|
109
|
-
function shiftDay(n) {
|
|
110
|
-
return (n % 7) + 1;
|
|
111
|
-
}
|
|
112
|
-
function shiftDayOfWeekTerm(term) {
|
|
113
|
-
const step = term.match(/^(.+)\/(\d+)$/);
|
|
114
|
-
if (step)
|
|
115
|
-
return `${shiftDayOfWeekTerm(step[1])}/${step[2]}`;
|
|
116
|
-
const range = term.match(/^(\d+)-(\d+)$/);
|
|
117
|
-
if (range) {
|
|
118
|
-
const from = shiftDay(Number(range[1]));
|
|
119
|
-
const to = shiftDay(Number(range[2]));
|
|
120
|
-
if (from > to) {
|
|
121
|
-
const days = [];
|
|
122
|
-
for (let d = Number(range[1]);; d = (d + 1) % 7) {
|
|
123
|
-
days.push(d);
|
|
124
|
-
if (d === Number(range[2]) % 7)
|
|
125
|
-
break;
|
|
126
|
-
if (days.length > 7)
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
refuse(`"${term}" is a day-of-week range that wraps past Sunday, which the schedule cannot express. ` +
|
|
130
|
-
`List the days instead, for example "${days.join(",")}".`);
|
|
131
|
-
}
|
|
132
|
-
return `${from}-${to}`;
|
|
133
|
-
}
|
|
134
|
-
if (/^\d+$/.test(term))
|
|
135
|
-
return String(shiftDay(Number(term)));
|
|
136
|
-
// Day NAMES (MON, MON-FRI) mean the same thing in both syntaxes.
|
|
137
|
-
return term;
|
|
138
|
-
}
|
|
139
47
|
/**
|
|
140
48
|
* The smallest gap a recurring expression can produce, in seconds, or null
|
|
141
49
|
* when it is not a recognised rate()/cron() form. Mirrors hq-pro-agents
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { type ClaudeLoginCheck } from "../lib/bot/claude-login.js";
|
|
1
2
|
import { fleetRuntimeReady, type FleetInstallProgress, type FleetInstallProgressListener, type FleetLocalTargetRelease } from "../lib/bot/fleet-local.js";
|
|
2
3
|
import { installedFleetPython } from "../lib/bot/fleet-python.js";
|
|
3
4
|
import { type FleetSignInHereDeps, type FleetSignInProvider } from "../lib/bot/legacy-provider-login.js";
|
|
5
|
+
import type { LegacyProviderLogin } from "../lib/bot/legacy-convert.js";
|
|
4
6
|
export type FleetProgressMode = "text" | "json" | "silent";
|
|
5
7
|
interface ProgressOutput {
|
|
6
8
|
write(text: string): void;
|
|
7
9
|
isTTY: boolean;
|
|
8
10
|
}
|
|
9
|
-
/** The sentence for a phase, for people. */
|
|
10
11
|
export declare function describeFleetInstallPhase(event: FleetInstallProgress): string;
|
|
11
12
|
/**
|
|
12
13
|
* Progress for a terminal (stderr, one line that rewrites itself on a TTY and
|
|
@@ -41,14 +42,54 @@ export declare function runBotRuntimeInstall(opts: {
|
|
|
41
42
|
export declare function runBotRuntimeStatus(opts: {
|
|
42
43
|
json?: boolean;
|
|
43
44
|
}): Promise<void>;
|
|
45
|
+
export type BrainProvider = "claude" | FleetSignInProvider;
|
|
46
|
+
export type BrainLoginSource = "claude-code" | "codex-cli" | "grok-cli" | "fleet-bot";
|
|
47
|
+
export interface BrainSignInStatus {
|
|
48
|
+
provider: BrainProvider;
|
|
49
|
+
signedIn: boolean;
|
|
50
|
+
source: BrainLoginSource | null;
|
|
51
|
+
}
|
|
52
|
+
export interface BrainSignInDeps extends FleetSignInHereDeps {
|
|
53
|
+
target?: () => Promise<FleetLocalTargetRelease>;
|
|
54
|
+
claudeLogin?: () => ClaudeLoginCheck;
|
|
55
|
+
grokSiblings?: () => Promise<LegacyProviderLogin>;
|
|
56
|
+
}
|
|
57
|
+
export declare function parseBrainProvider(value: string): BrainProvider;
|
|
44
58
|
export declare function parseFleetSignInProvider(value: string): FleetSignInProvider;
|
|
59
|
+
export declare function brainSignInStatus(provider: BrainProvider, deps?: BrainSignInDeps): Promise<BrainSignInStatus>;
|
|
45
60
|
export declare function runBotAuthStatus(opts: {
|
|
46
61
|
provider: string;
|
|
47
62
|
json?: boolean;
|
|
48
|
-
}, deps?:
|
|
49
|
-
|
|
50
|
-
})
|
|
51
|
-
|
|
63
|
+
}, deps?: BrainSignInDeps): Promise<(BrainSignInStatus & {
|
|
64
|
+
ok: true;
|
|
65
|
+
}) | {
|
|
66
|
+
ok: false;
|
|
67
|
+
provider: string;
|
|
68
|
+
reason: "unknown-provider";
|
|
69
|
+
}>;
|
|
70
|
+
export interface BrainSignInRun {
|
|
71
|
+
stdout: NodeJS.ReadableStream | null;
|
|
72
|
+
stderr: NodeJS.ReadableStream | null;
|
|
73
|
+
exit: Promise<number | null>;
|
|
74
|
+
kill(signal?: NodeJS.Signals): void;
|
|
75
|
+
}
|
|
76
|
+
export interface BotSignInDeps extends BrainSignInDeps {
|
|
77
|
+
findCli?: (name: string) => string | null;
|
|
78
|
+
run?: (cli: string, args: string[]) => BrainSignInRun;
|
|
79
|
+
emit?: (line: string) => void;
|
|
80
|
+
write?: (text: string) => void;
|
|
81
|
+
onCancel?: (cancel: () => void) => () => void;
|
|
82
|
+
}
|
|
83
|
+
export declare const BRAIN_SIGN_IN_KILL_AFTER_MS = 1500;
|
|
84
|
+
export declare function findCliOnPath(name: string, env?: NodeJS.ProcessEnv): string | null;
|
|
85
|
+
export declare function deviceCodeTracker(emit: (event: Record<string, unknown>) => void): (line: string) => void;
|
|
86
|
+
export declare function runBotSignIn(opts: {
|
|
87
|
+
provider: string;
|
|
88
|
+
json?: boolean;
|
|
89
|
+
browser?: boolean;
|
|
90
|
+
}, deps?: BotSignInDeps): Promise<BrainSignInStatus & {
|
|
91
|
+
ok: boolean;
|
|
92
|
+
reason?: string;
|
|
52
93
|
}>;
|
|
53
94
|
export {};
|
|
54
95
|
//# sourceMappingURL=bot-runtime.d.ts.map
|
|
@@ -1,19 +1,33 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as os from "node:os";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import { stripVTControlCharacters } from "node:util";
|
|
1
6
|
import chalk from "chalk";
|
|
2
|
-
import {
|
|
7
|
+
import { checkClaudeCodeLogin } from "../lib/bot/claude-login.js";
|
|
8
|
+
import { botRuntimeFromBrainName } from "../lib/bot/config.js";
|
|
9
|
+
import { installFleetRuntimeSources } from "../lib/bot/fleet-runtime-sources.js";
|
|
10
|
+
import { cachedFleetLocalTargetRelease, ensureFleetRuntimeInstalled, fleetLocalDistributionInstalled, fleetReleaseImportsGrokCli, fleetRuntimeReady, installTargetFleetLocalDistribution, resolveFleetLocalTargetRelease, } from "../lib/bot/fleet-local.js";
|
|
3
11
|
import { installedFleetPython } from "../lib/bot/fleet-python.js";
|
|
4
12
|
import { createInstallProgressTracker } from "../lib/bot/install-progress.js";
|
|
5
13
|
import { botCreateEstimate } from "../lib/bot/readiness.js";
|
|
6
|
-
import { fleetSignInReusableHere } from "../lib/bot/legacy-provider-login.js";
|
|
14
|
+
import { fleetSignInReusableHere, grokCliLoginReadable, grokLoginReadableHereAsync, } from "../lib/bot/legacy-provider-login.js";
|
|
7
15
|
function megabytes(bytes) {
|
|
8
16
|
return `${(bytes / 1_048_576).toFixed(1)} MB`;
|
|
9
17
|
}
|
|
10
18
|
/** The sentence for a phase, for people. */
|
|
19
|
+
const FLEET_WHEELHOUSE_PREFIX = "hq-fleet-local-wheels-";
|
|
20
|
+
function shownInTerminal(file) {
|
|
21
|
+
return file.startsWith("hq-fleet-runtime-") || file.startsWith(FLEET_WHEELHOUSE_PREFIX);
|
|
22
|
+
}
|
|
11
23
|
export function describeFleetInstallPhase(event) {
|
|
12
24
|
switch (event.phase) {
|
|
13
25
|
case "download-start":
|
|
14
26
|
return "Downloading the HQ Fleet Runtime";
|
|
15
27
|
case "download": {
|
|
16
|
-
const name = event.file.startsWith("hq-fleet-runtime-")
|
|
28
|
+
const name = event.file.startsWith("hq-fleet-runtime-")
|
|
29
|
+
? "the HQ Fleet Runtime"
|
|
30
|
+
: event.file.startsWith(FLEET_WHEELHOUSE_PREFIX) ? "the HQ Fleet Runtime's packages" : "the HQ Fleet Runtime's release files";
|
|
17
31
|
if (event.total === null)
|
|
18
32
|
return `Downloading ${name}: ${megabytes(event.received)}`;
|
|
19
33
|
const percent = Math.min(100, Math.floor((event.received / Math.max(event.total, 1)) * 100));
|
|
@@ -57,11 +71,20 @@ export function fleetInstallProgressReporter(mode, output = { write: (text) => {
|
|
|
57
71
|
}
|
|
58
72
|
let lastTenth = -1;
|
|
59
73
|
let lineOpen = false;
|
|
60
|
-
|
|
61
|
-
|
|
74
|
+
const shown = new Map();
|
|
75
|
+
return (incoming) => {
|
|
76
|
+
if (incoming.phase === "download-start")
|
|
62
77
|
return;
|
|
63
|
-
if (
|
|
78
|
+
if (incoming.phase === "download" && !shownInTerminal(incoming.file))
|
|
64
79
|
return;
|
|
80
|
+
let event = incoming;
|
|
81
|
+
if (incoming.phase === "download") {
|
|
82
|
+
shown.set(incoming.file, { received: incoming.received, total: incoming.total });
|
|
83
|
+
const files = [...shown.values()];
|
|
84
|
+
const received = files.reduce((sum, file) => sum + file.received, 0);
|
|
85
|
+
const total = files.every((file) => file.total !== null) ? files.reduce((sum, file) => sum + (file.total ?? 0), 0) : null;
|
|
86
|
+
event = { phase: "download", file: "hq-fleet-runtime-", received, total };
|
|
87
|
+
}
|
|
65
88
|
const text = describeFleetInstallPhase(event);
|
|
66
89
|
if (event.phase === "download" && event.total !== null) {
|
|
67
90
|
const tenth = Math.floor((event.received / Math.max(event.total, 1)) * 10);
|
|
@@ -100,8 +123,8 @@ export async function fleetRuntimeStatus(deps = {}) {
|
|
|
100
123
|
export async function runBotRuntimeInstall(opts) {
|
|
101
124
|
const report = fleetInstallProgressReporter(opts.json ? "json" : "text");
|
|
102
125
|
const target = await resolveFleetLocalTargetRelease();
|
|
103
|
-
const installation = await installTargetFleetLocalDistribution({ target, onProgress: report });
|
|
104
|
-
const result = await ensureFleetRuntimeInstalled(installation, { onProgress: report });
|
|
126
|
+
const { installation, python } = await installFleetRuntimeSources(() => installTargetFleetLocalDistribution({ target, onProgress: report }), { onProgress: report });
|
|
127
|
+
const result = await ensureFleetRuntimeInstalled(installation, { python, onProgress: report });
|
|
105
128
|
if (opts.json) {
|
|
106
129
|
console.log(JSON.stringify({
|
|
107
130
|
ok: true,
|
|
@@ -129,32 +152,219 @@ export async function runBotRuntimeStatus(opts) {
|
|
|
129
152
|
if (!current.ready)
|
|
130
153
|
console.log(chalk.dim(" Run `hq bot runtime install` to get it ready before creating a bot."));
|
|
131
154
|
}
|
|
155
|
+
export function parseBrainProvider(value) {
|
|
156
|
+
const runtime = botRuntimeFromBrainName(value);
|
|
157
|
+
if (runtime === "claude" || runtime === "grok")
|
|
158
|
+
return runtime;
|
|
159
|
+
if (runtime === "codex")
|
|
160
|
+
return "chatgpt";
|
|
161
|
+
throw Object.assign(new Error(`--provider must be claude, codex (or chatgpt) or grok, not ${value}.`), { expected: true });
|
|
162
|
+
}
|
|
132
163
|
export function parseFleetSignInProvider(value) {
|
|
133
164
|
const provider = value.trim().toLowerCase();
|
|
134
165
|
if (provider === "chatgpt" || provider === "grok")
|
|
135
166
|
return provider;
|
|
136
167
|
throw Object.assign(new Error(`--provider must be chatgpt or grok, not ${value}.`), { expected: true });
|
|
137
168
|
}
|
|
138
|
-
export async function
|
|
139
|
-
|
|
169
|
+
export async function brainSignInStatus(provider, deps = {}) {
|
|
170
|
+
if (provider === "claude") {
|
|
171
|
+
const signedIn = (deps.claudeLogin ?? (() => checkClaudeCodeLogin()))().signedIn;
|
|
172
|
+
return { provider, signedIn, source: signedIn ? "claude-code" : null };
|
|
173
|
+
}
|
|
140
174
|
let grokCliImport = deps.grokCliImport;
|
|
141
175
|
if (provider === "grok" && grokCliImport === undefined) {
|
|
142
176
|
try {
|
|
143
|
-
grokCliImport = fleetReleaseImportsGrokCli((await (deps.target ?? (() =>
|
|
177
|
+
grokCliImport = fleetReleaseImportsGrokCli((await (deps.target ?? (async () => cachedFleetLocalTargetRelease()))()).release.version);
|
|
144
178
|
}
|
|
145
179
|
catch {
|
|
146
180
|
grokCliImport = false;
|
|
147
181
|
}
|
|
148
182
|
}
|
|
149
|
-
|
|
183
|
+
let grok = deps.grok;
|
|
184
|
+
if (provider === "grok" && !grok) {
|
|
185
|
+
const cli = (deps.grokCli ?? (() => grokCliLoginReadable(deps.homedir ?? os.homedir(), deps.env ?? process.env)))();
|
|
186
|
+
if (!(grokCliImport && cli.readable)) {
|
|
187
|
+
const siblings = await (deps.grokSiblings ?? (() => grokLoginReadableHereAsync("")))();
|
|
188
|
+
grok = () => siblings;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const { target: _target, claudeLogin: _claudeLogin, grokSiblings: _grokSiblings, ...hereDeps } = deps;
|
|
192
|
+
const login = fleetSignInReusableHere(provider, { ...hereDeps, ...(grok ? { grok } : {}), ...(grokCliImport !== undefined ? { grokCliImport } : {}) });
|
|
193
|
+
if (!login.readable)
|
|
194
|
+
return { provider, signedIn: false, source: null };
|
|
195
|
+
const source = provider === "chatgpt" ? "codex-cli" : login.detail.startsWith("Grok CLI login") ? "grok-cli" : "fleet-bot";
|
|
196
|
+
return { provider, signedIn: true, source };
|
|
197
|
+
}
|
|
198
|
+
const BRAIN_NAMES = { claude: "Claude", chatgpt: "ChatGPT", grok: "Grok" };
|
|
199
|
+
export async function runBotAuthStatus(opts, deps = {}) {
|
|
200
|
+
let provider;
|
|
201
|
+
try {
|
|
202
|
+
provider = parseBrainProvider(opts.provider);
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
if (!opts.json)
|
|
206
|
+
throw error;
|
|
207
|
+
const failure = { ok: false, provider: opts.provider, reason: "unknown-provider" };
|
|
208
|
+
console.log(JSON.stringify(failure));
|
|
209
|
+
process.exitCode = 1;
|
|
210
|
+
return failure;
|
|
211
|
+
}
|
|
212
|
+
const status = { ...(await brainSignInStatus(provider, deps)), ok: true };
|
|
150
213
|
if (opts.json) {
|
|
151
|
-
console.log(JSON.stringify(
|
|
152
|
-
return
|
|
214
|
+
console.log(JSON.stringify(status));
|
|
215
|
+
return status;
|
|
153
216
|
}
|
|
154
|
-
const name = provider
|
|
155
|
-
console.log(signedIn
|
|
217
|
+
const name = BRAIN_NAMES[status.provider];
|
|
218
|
+
console.log(status.signedIn
|
|
156
219
|
? `A new ${name} bot signs in with the ${name} login already on this computer.`
|
|
157
|
-
: `A new ${name} bot needs
|
|
158
|
-
return
|
|
220
|
+
: `A new ${name} bot needs a ${name} sign-in first (hq bot sign-in --provider ${status.provider}).`);
|
|
221
|
+
return status;
|
|
222
|
+
}
|
|
223
|
+
function onTerminate(cancel) {
|
|
224
|
+
process.once("SIGTERM", cancel);
|
|
225
|
+
process.once("SIGINT", cancel);
|
|
226
|
+
return () => {
|
|
227
|
+
process.off("SIGTERM", cancel);
|
|
228
|
+
process.off("SIGINT", cancel);
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
const BRAIN_SIGN_IN_CLI = {
|
|
232
|
+
chatgpt: { cli: "codex", browser: ["login"], device: ["login", "--device-auth"] },
|
|
233
|
+
grok: { cli: "grok", browser: ["login", "--oauth"], device: ["login", "--device-auth"] },
|
|
234
|
+
};
|
|
235
|
+
export const BRAIN_SIGN_IN_KILL_AFTER_MS = 1_500;
|
|
236
|
+
export function findCliOnPath(name, env = process.env) {
|
|
237
|
+
for (const dir of (env.PATH ?? "").split(path.delimiter).filter(Boolean)) {
|
|
238
|
+
const file = path.join(dir, name);
|
|
239
|
+
try {
|
|
240
|
+
if (fs.statSync(file).isFile()) {
|
|
241
|
+
fs.accessSync(file, fs.constants.X_OK);
|
|
242
|
+
return file;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
function runCli(cli, args) {
|
|
252
|
+
const child = spawn(cli, args, { stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
|
|
253
|
+
return {
|
|
254
|
+
stdout: child.stdout,
|
|
255
|
+
stderr: child.stderr,
|
|
256
|
+
exit: new Promise((resolve) => {
|
|
257
|
+
child.once("error", () => resolve(null));
|
|
258
|
+
child.once("close", (code) => resolve(code));
|
|
259
|
+
}),
|
|
260
|
+
kill: (signal = "SIGTERM") => {
|
|
261
|
+
child.kill(signal);
|
|
262
|
+
},
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
const DEVICE_URL_RE = /https:\/\/[^\s"'<>)]+/;
|
|
266
|
+
const DEVICE_CODE_RE = /\b[A-Z0-9]{4,5}-[A-Z0-9]{4,5}\b/;
|
|
267
|
+
export function deviceCodeTracker(emit) {
|
|
268
|
+
let verificationUri = null;
|
|
269
|
+
let userCode = null;
|
|
270
|
+
let sent = false;
|
|
271
|
+
return (raw) => {
|
|
272
|
+
const line = stripVTControlCharacters(raw).trim();
|
|
273
|
+
if (!line)
|
|
274
|
+
return;
|
|
275
|
+
verificationUri ??= DEVICE_URL_RE.exec(line)?.[0] ?? null;
|
|
276
|
+
userCode ??= DEVICE_CODE_RE.exec(line)?.[0] ?? null;
|
|
277
|
+
if (!sent && verificationUri && userCode) {
|
|
278
|
+
sent = true;
|
|
279
|
+
emit({ event: "auth", phase: "device-code", verificationUri, userCode });
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
emit({ event: "auth", phase: "message", text: line });
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
function forEachLine(stream, onLine) {
|
|
286
|
+
if (!stream)
|
|
287
|
+
return Promise.resolve();
|
|
288
|
+
return new Promise((resolve) => {
|
|
289
|
+
let buffered = "";
|
|
290
|
+
stream.on("data", (chunk) => {
|
|
291
|
+
buffered += chunk.toString();
|
|
292
|
+
const lines = buffered.split(/\r?\n/);
|
|
293
|
+
buffered = lines.pop() ?? "";
|
|
294
|
+
for (const line of lines)
|
|
295
|
+
onLine(line);
|
|
296
|
+
});
|
|
297
|
+
stream.on("end", () => {
|
|
298
|
+
if (buffered)
|
|
299
|
+
onLine(buffered);
|
|
300
|
+
resolve();
|
|
301
|
+
});
|
|
302
|
+
stream.on("error", () => resolve());
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
export async function runBotSignIn(opts, deps = {}) {
|
|
306
|
+
const brain = parseBrainProvider(opts.provider);
|
|
307
|
+
const emit = deps.emit ?? ((line) => { process.stdout.write(`${line}\n`); });
|
|
308
|
+
const write = deps.write ?? ((text) => { process.stderr.write(text); });
|
|
309
|
+
const finish = (result) => {
|
|
310
|
+
if (opts.json)
|
|
311
|
+
emit(JSON.stringify(result));
|
|
312
|
+
else
|
|
313
|
+
write(result.ok
|
|
314
|
+
? `${BRAIN_NAMES[result.provider]} is signed in on this computer; new ${BRAIN_NAMES[result.provider]} bots use this login.\n`
|
|
315
|
+
: `${BRAIN_NAMES[result.provider]} is not signed in on this computer${result.reason ? ` (${result.reason})` : ""}.\n`);
|
|
316
|
+
return result;
|
|
317
|
+
};
|
|
318
|
+
if (brain === "claude") {
|
|
319
|
+
throw Object.assign(new Error("hq bot sign-in covers codex (or chatgpt) and grok; sign in to Claude with claude /login."), { expected: true });
|
|
320
|
+
}
|
|
321
|
+
const before = await brainSignInStatus(brain, deps);
|
|
322
|
+
if (before.signedIn)
|
|
323
|
+
return finish({ ...before, ok: true });
|
|
324
|
+
const { cli, browser, device } = BRAIN_SIGN_IN_CLI[brain];
|
|
325
|
+
const args = opts.browser === false ? device : browser;
|
|
326
|
+
const executable = (deps.findCli ?? ((name) => findCliOnPath(name)))(cli);
|
|
327
|
+
if (!executable) {
|
|
328
|
+
process.exitCode = 1;
|
|
329
|
+
return finish({ ...before, ok: false, reason: "cli-missing" });
|
|
330
|
+
}
|
|
331
|
+
const track = deviceCodeTracker((event) => {
|
|
332
|
+
if (opts.json)
|
|
333
|
+
emit(JSON.stringify(event));
|
|
334
|
+
else
|
|
335
|
+
write(`${event.phase === "device-code" ? `Open ${String(event.verificationUri)} and enter ${String(event.userCode)}` : String(event.text)}\n`);
|
|
336
|
+
});
|
|
337
|
+
const child = (deps.run ?? runCli)(executable, args);
|
|
338
|
+
let cancelled = false;
|
|
339
|
+
let forceKill = null;
|
|
340
|
+
const cancel = () => {
|
|
341
|
+
if (cancelled)
|
|
342
|
+
return;
|
|
343
|
+
cancelled = true;
|
|
344
|
+
child.kill("SIGTERM");
|
|
345
|
+
forceKill = setTimeout(() => child.kill("SIGKILL"), BRAIN_SIGN_IN_KILL_AFTER_MS);
|
|
346
|
+
forceKill.unref?.();
|
|
347
|
+
};
|
|
348
|
+
const release = (deps.onCancel ?? onTerminate)(cancel);
|
|
349
|
+
const reading = Promise.all([forEachLine(child.stdout, track), forEachLine(child.stderr, track)]);
|
|
350
|
+
try {
|
|
351
|
+
const code = await child.exit;
|
|
352
|
+
if (!cancelled)
|
|
353
|
+
await reading;
|
|
354
|
+
if (cancelled) {
|
|
355
|
+
process.exitCode = 1;
|
|
356
|
+
return finish({ ...before, ok: false, reason: "cancelled" });
|
|
357
|
+
}
|
|
358
|
+
const after = await brainSignInStatus(brain, deps);
|
|
359
|
+
if (code === 0 && after.signedIn)
|
|
360
|
+
return finish({ ...after, ok: true });
|
|
361
|
+
process.exitCode = 1;
|
|
362
|
+
return finish({ ...after, ok: false, reason: code === 0 ? "login-not-reusable" : "sign-in-failed" });
|
|
363
|
+
}
|
|
364
|
+
finally {
|
|
365
|
+
if (forceKill)
|
|
366
|
+
clearTimeout(forceKill);
|
|
367
|
+
release();
|
|
368
|
+
}
|
|
159
369
|
}
|
|
160
370
|
//# sourceMappingURL=bot-runtime.js.map
|
package/dist/commands/bot.d.ts
CHANGED
|
@@ -6,9 +6,9 @@ import { type RuntimeSignInCheck, type RuntimeSignInIssue } from "../lib/bot/run
|
|
|
6
6
|
import { type ClaudeLoginCheck } from "../lib/bot/claude-login.js";
|
|
7
7
|
import type { BotStatusFile } from "../lib/bot/status.js";
|
|
8
8
|
import { probeBotRuntime, type RuntimeProbeResult } from "../lib/bot/probe.js";
|
|
9
|
-
import { type SpawnInteractive } from "../lib/bot/runtime-auth.js";
|
|
9
|
+
import { type BotLoginRuntime, type SpawnInteractive } from "../lib/bot/runtime-auth.js";
|
|
10
10
|
import { type BotLocalConfig, type MyLocalBot, type BotKind, type BotMemoryMode, type BotNotRunnableReason, type RuntimeCrash, type BotConfig, type BotRuntimeId, type LaunchctlExec, HQ_FLEET_RUNTIME_ENGINE_ID, type BotRole } from "../lib/bot/index.js";
|
|
11
|
-
import { fleetRuntimeStatus } from "./bot-runtime.js";
|
|
11
|
+
import { brainSignInStatus, fleetRuntimeStatus } from "./bot-runtime.js";
|
|
12
12
|
import { ensureFleetRuntimeInstalled } from "../lib/bot/fleet-local.js";
|
|
13
13
|
/** Real launchctl; every failure is a non-ok result, never a throw. */
|
|
14
14
|
export declare const defaultLaunchctl: LaunchctlExec;
|
|
@@ -202,19 +202,16 @@ export declare const legacyConvertSeams: {
|
|
|
202
202
|
/** Whether the provider sign-in a Codex or Grok legacy bot needs is readable here, as HQ Fleet Local imports it. */
|
|
203
203
|
providerLogin: (dir: string, config: BotConfig) => LegacyProviderLoginProbe;
|
|
204
204
|
};
|
|
205
|
-
|
|
206
|
-
* `output`: "json" | "text" print a result; "silent" prints nothing — used
|
|
207
|
-
* when stop is a step inside rm/restart, whose own JSON must be the only
|
|
208
|
-
* document on stdout (the desktop app parses it; a second object made it
|
|
209
|
-
* "unreadable output: trailing characters").
|
|
210
|
-
*/
|
|
211
|
-
/** Seams for the self-stop path, replaced in tests. */
|
|
205
|
+
export declare const FLEET_SIGN_IN_PICKUP_WAIT_MS = 20000;
|
|
212
206
|
export declare const botCreateSeams: {
|
|
213
207
|
/** The Claude Code login read the way the HQ Fleet Runtime reads it. */
|
|
214
208
|
claudeLogin: () => ClaudeLoginCheck;
|
|
209
|
+
brainSignIn: typeof brainSignInStatus;
|
|
210
|
+
importBrainLogin: (agentUid: string, runtime: "codex" | "grok") => void;
|
|
215
211
|
runtimeStatus: typeof fleetRuntimeStatus;
|
|
216
212
|
installRuntime: typeof ensureFleetRuntimeInstalled;
|
|
217
213
|
waitForReady: typeof waitForGatewayReady;
|
|
214
|
+
greetingSentAt: (agentUid: string) => string | null;
|
|
218
215
|
};
|
|
219
216
|
export declare const botStopSeams: {
|
|
220
217
|
/** True when this process runs inside the bot process `botPid` (one of its turns). */
|
|
@@ -318,6 +315,10 @@ export interface BotSetOptions {
|
|
|
318
315
|
}
|
|
319
316
|
export interface BotSetDeps {
|
|
320
317
|
probe?: typeof probeBotRuntime;
|
|
318
|
+
/** Test seam: the bot's own browser sign-in that `switch-account --sign-in` runs. */
|
|
319
|
+
botSignIn?: (dir: string, runtime: BotLoginRuntime) => unknown;
|
|
320
|
+
/** Test seam: every vendor login/logout command `switch-account --sign-in` spawns. */
|
|
321
|
+
authSpawn?: SpawnInteractive;
|
|
321
322
|
/** Test seam: the Fleet sign-in (`hq bot auth`) switch-account runs for a Fleet bot. */
|
|
322
323
|
fleetAuth?: (name: string, opts: {
|
|
323
324
|
provider: string;
|
|
@@ -336,6 +337,12 @@ export declare function runBotSet(nameArg: string, opts: BotSetOptions, deps?: B
|
|
|
336
337
|
/** switch-account's test turn: short, so probe, stop, start and a rollback fit the desktop's 5-minute budget. */
|
|
337
338
|
export declare const SWITCH_ACCOUNT_PROBE_TIMEOUT_MS = 60000;
|
|
338
339
|
export interface BotSwitchAccountOptions {
|
|
340
|
+
/**
|
|
341
|
+
* Sign the bot in with a login of its own for `runtime` first (claude, codex):
|
|
342
|
+
* a browser sign-in into ~/.hq/bots/<name>/auth/<runtime>. Without it the
|
|
343
|
+
* bot moves onto the owner's own sign-in.
|
|
344
|
+
*/
|
|
345
|
+
signIn?: boolean;
|
|
339
346
|
/** The runtime the owner just signed in to (the Create-bot account switcher's runtime). */
|
|
340
347
|
runtime: string;
|
|
341
348
|
json?: boolean;
|