@indigoai-us/hq-cli 5.345.203 → 5.345.205
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 +34 -0
- package/dist/command-catalog.generated.d.ts +51 -1
- package/dist/command-catalog.generated.js +63 -1
- package/dist/commands/bot.d.ts +67 -0
- package/dist/commands/bot.js +308 -41
- package/dist/commands/cloud-off-gate.d.ts +9 -2
- package/dist/commands/cloud-off-gate.js +49 -13
- package/dist/commands/cloud.d.ts +14 -2
- package/dist/commands/cloud.js +25 -16
- package/dist/commands/feedback.d.ts +26 -0
- package/dist/commands/feedback.js +91 -5
- package/dist/commands/install-global.d.ts +3 -1
- package/dist/commands/install-global.js +15 -4
- package/dist/commands/lanes.d.ts +2 -0
- package/dist/commands/lanes.js +9 -3
- package/dist/commands/mcp-serve.d.ts +5 -2
- package/dist/commands/mcp-serve.js +45 -3
- package/dist/commands/mcp-status.d.ts +3 -1
- package/dist/commands/mcp-status.js +24 -14
- package/dist/commands/secrets.js +11 -1
- package/dist/commands/sources.js +10 -15
- package/dist/commands/sync-core.js +2 -0
- package/dist/index.js +7 -2
- package/dist/lib/bot/claude-login.d.ts +7 -1
- package/dist/lib/bot/claude-login.js +56 -16
- package/dist/lib/bot/executive-settings.d.ts +13 -0
- package/dist/lib/bot/executive-settings.js +20 -17
- package/dist/lib/bot/executive-sync.d.ts +12 -0
- package/dist/lib/bot/executive-sync.js +36 -0
- package/dist/lib/bot/executive.d.ts +51 -0
- package/dist/lib/bot/executive.js +144 -0
- package/dist/lib/bot/fleet-cron.d.ts +7 -0
- package/dist/lib/bot/fleet-cron.js +2 -1
- package/dist/lib/bot/jobs/executive-handover.d.ts +6 -0
- package/dist/lib/bot/jobs/executive-handover.js +33 -0
- package/dist/lib/bot/jobs/hot-signal-sync.d.ts +22 -0
- package/dist/lib/bot/jobs/hot-signal-sync.js +47 -0
- package/dist/lib/bot/listed-running.d.ts +16 -0
- package/dist/lib/bot/listed-running.js +16 -0
- package/dist/lib/bot/pending-switch.d.ts +51 -0
- package/dist/lib/bot/pending-switch.js +103 -0
- package/dist/lib/bot/run.js +27 -3
- package/dist/lib/bot/runtime-failure.js +19 -3
- package/dist/lib/bot/status.d.ts +20 -0
- package/dist/lib/capacity/collectors/claude-oauth.d.ts +53 -5
- package/dist/lib/capacity/collectors/claude-oauth.js +251 -71
- package/dist/lib/company-skill-wrapper.js +29 -0
- package/dist/lib/daemon/catalog.js +2 -2
- package/dist/lib/daemon/hq-child-bootstrap.mjs +197 -2
- package/dist/lib/daemon/resolver.d.ts +14 -0
- package/dist/lib/daemon/resolver.js +96 -0
- package/dist/lib/daemon/run.d.ts +11 -0
- package/dist/lib/daemon/run.js +60 -8
- package/dist/lib/daemon/server.d.ts +2 -9
- package/dist/lib/daemon/server.js +3 -89
- package/dist/lib/doctor/checks/claude-wiring.js +41 -0
- package/dist/lib/doctor/checks/sync-health.d.ts +8 -0
- package/dist/lib/doctor/checks/sync-health.js +34 -2
- package/dist/lib/doctor/duplicate-hook-registrations.d.ts +34 -0
- package/dist/lib/doctor/duplicate-hook-registrations.js +130 -0
- package/dist/lib/doctor/fix/apply.js +79 -3
- package/dist/lib/doctor/fix/remediation.d.ts +1 -1
- package/dist/lib/doctor/fix/remediation.js +15 -0
- package/dist/lib/doctor/types.d.ts +1 -1
- package/dist/lib/doctor/types.js +1 -0
- package/dist/lib/lanes/config.js +13 -0
- package/dist/lib/lanes/throttle.d.ts +12 -1
- package/dist/lib/lanes/throttle.js +27 -8
- package/dist/lib/lanes/types.d.ts +5 -0
- package/dist/lib/mcp/local-native-tools.d.ts +40 -0
- package/dist/lib/mcp/local-native-tools.js +111 -0
- package/dist/lib/mcp/tools.d.ts +2 -0
- package/dist/lib/mcp/tools.js +2 -0
- package/dist/lib/signals/steps/extract.d.ts +111 -5
- package/dist/lib/signals/steps/extract.js +524 -55
- package/dist/lib/sync-core/engine-home.d.ts +2 -1
- package/dist/lib/sync-core/engine-home.js +25 -8
- package/dist/lib/sync-core/reconcile.d.ts +3 -1
- package/dist/lib/sync-core/reconcile.js +21 -8
- package/dist/lib/sync-core/release.d.ts +14 -5
- package/dist/lib/sync-core/release.js +58 -14
- package/dist/sentry-init.js +6 -0
- package/dist/utils/cli-network-lifecycle.d.ts +11 -1
- package/dist/utils/cli-network-lifecycle.js +36 -2
- package/dist/utils/daemon-helper-lifetime.d.ts +39 -0
- package/dist/utils/daemon-helper-lifetime.js +209 -0
- package/dist/utils/daemon-helper-markers.d.ts +24 -0
- package/dist/utils/daemon-helper-markers.js +53 -0
- package/dist/utils/mcp-launcher.d.ts +28 -0
- package/dist/utils/mcp-launcher.js +117 -0
- package/dist/utils/package-use-lease.d.ts +10 -0
- package/dist/utils/package-use-lease.js +31 -0
- package/dist/utils/resident-package-preload.js +4 -1
- package/docs/anywhere-runtime.md +7 -0
- package/package.json +7 -7
package/dist/commands/bot.js
CHANGED
|
@@ -25,6 +25,7 @@ import { hasPromotionHold, promotionHoldSummary } from "../lib/bot/promotion-hol
|
|
|
25
25
|
* hq bot restore [--all] [--dry-run] (every bot you own that is missing here)
|
|
26
26
|
* hq bot start|stop|restart <name>
|
|
27
27
|
* hq bot status <name> [--json]
|
|
28
|
+
* hq bot eb [name] [--json] (show or choose the Executive bot)
|
|
28
29
|
* hq bot logs <name> [--follow] [-n N]
|
|
29
30
|
* hq bot run <name> (the resident process; launchd runs this)
|
|
30
31
|
* hq bot daemon install|uninstall|status <name>
|
|
@@ -48,6 +49,9 @@ import { registerBotContinuityCommand } from "./bot-continuity.js";
|
|
|
48
49
|
import { registerBotJobsCommand } from "./bot-jobs.js";
|
|
49
50
|
import { registerBotEventsCommand } from "./bot-events.js";
|
|
50
51
|
import { executiveStatus } from "../lib/bot/executive-settings.js";
|
|
52
|
+
import { describeExecutiveBotSource, resolveExecutiveBot, setExecutiveBot } from "../lib/bot/executive.js";
|
|
53
|
+
import { executiveHotSignalSyncCompanies } from "../lib/bot/executive-sync.js";
|
|
54
|
+
import { readBotListedProcess } from "../lib/bot/listed-running.js";
|
|
51
55
|
import { ensureFleetHotSignalSync, fleetCronOps, migrateLegacyJobsToFleet } from "../lib/bot/fleet-cron.js";
|
|
52
56
|
import { resolvePackSetupPrompt } from "../lib/bot/pack-setup.js";
|
|
53
57
|
import { detectCodingToolActivity } from "../lib/bot/coding-tool-activity.js";
|
|
@@ -70,10 +74,11 @@ import { isAncestorProcess } from "../lib/bot/self-process.js";
|
|
|
70
74
|
import { runtimeDisplayName, signInCommand } from "../lib/bot/runtime-sign-in.js";
|
|
71
75
|
import { checkClaudeCodeLogin, claudeLoginFix, describeClaudeLoginSources } from "../lib/bot/claude-login.js";
|
|
72
76
|
import { unresolvedLastFailure } from "../lib/doctor/checks/bots.js";
|
|
73
|
-
import {
|
|
77
|
+
import { clearPendingSwitch, recoverPendingSwitchSafely, writePendingSwitch } from "../lib/bot/pending-switch.js";
|
|
78
|
+
import { classifyRuntimeFailure, isRuntimeUsageLimit, runtimeFailureReason, usageLimitResetsAt } from "../lib/bot/runtime-failure.js";
|
|
74
79
|
import { PROBE_DEFAULT_TIMEOUT_MS, probeBotRuntime } from "../lib/bot/probe.js";
|
|
75
80
|
import { BOT_LOGIN_RUNTIMES, botAuthEnv, botRuntimeAuth, capacityAccountHome, describeBotAuth, formatBotAuth, isBotLoginRuntime, restoreBotSessions, setAsideBotSessions, signInBotRuntime, signOutBotRuntime, withRuntimeAuth, } from "../lib/bot/runtime-auth.js";
|
|
76
|
-
import { BotApi, BotApiError, BOT_RESTORE_DEFAULTS, buildBotLocalConfig, describeBotLocalConfig, orphanBotRunMessage, parseBotLocalConfig, removeOrphanBotDaemon, botDaemonStatus, botDir, botCredsPath, botLogPath, botsRoot, botTokenStateDir, botWorkerRelDir, buildBotDaemonPaths, createBotLogger, deleteBotCreds, installBotDaemon, repairBotDaemonIfStale, healBotDaemonNodeFromJob, introDmText, isBotMemoryMode, botLocalMemoryDir, botMemoryMode, resolveBotMemoryDir, validateBotIntro, validateBotDisplayName, validateBotKickoff, validateBotEffort, validateBotModel, effectiveBotEffort, BOT_EFFORT_LEVELS, DEFAULT_BOT_EFFORT, BOT_MEMORY_MODES, BOT_KINDS, isBotKind, effectiveBotKind, effectiveBotCompanies, normalizeBotCompanies, SETUP_BOT_WORKER_ID, isBotRuntimeId, localNameForRemoteBot, remoteBotRunnability, isPidAlive, listBotWorkerOptions, patchBotConfig, readBotConfig, readBotCredsIdentity, readBotStatus, runtimeCrashSinceStart, resolveBotWorker, runBot, runtimeFor, scaffoldBotMemory, scaffoldBotWorker, startBotDaemon, stopBotDaemon, uninstallBotDaemon, validateBotName, writeBotConfig, writeBotCreds, BOT_RUNTIMES, BOT_INTRO_MAX_CHARS, BOT_DISPLAY_NAME_MAX_CHARS, BOT_KICKOFF_MAX_CHARS, detectBotPlatform, withBotLock, localBotRole, remoteBotRole, remoteBotDisplayName, personFacingName, writeCloudDisplayName, setupSlugFor, ASSISTANT_ROLE, HQ_FLEET_RUNTIME_ENGINE_ID, HQ_FLEET_LOCAL_RELEASE, authenticateFleetLocalBot, bootstrapFleetLocalBot, buildSystemPrompt, controlFleetLocalBot, ensureFleetPython, fleetLocalGatewayPid, fleetLocalProfileNeedsAdoption, fleetLocalServiceInstalled, fleetProviderForRuntime, importFleetLocalMachineCredential, importFleetLocalProviderLogin, fleetProviderNeedsSignIn, fleetOwnerCompanies, refreshFleetLocalInstructions, fleetLocalPromotionRuntime, installPinnedFleetLocalDistribution, installTargetFleetLocalDistribution, resolveFleetLocalPointerTarget, resolveFleetLocalTargetRelease, fleetLocalProfileDir, fleetProfileOwnerCompanies, fleetLocalChannels, readFleetLocalGatewayState, readPromptSources, removeFleetLocalBot, } from "../lib/bot/index.js";
|
|
81
|
+
import { BotApi, BotApiError, BOT_RESTORE_DEFAULTS, buildBotLocalConfig, describeBotLocalConfig, orphanBotRunMessage, parseBotLocalConfig, removeOrphanBotDaemon, botDaemonStatus, botDir, botCredsPath, botLogPath, botsRoot, botTokenStateDir, botWorkerRelDir, buildBotDaemonPaths, createBotLogger, deleteBotCreds, installBotDaemon, repairBotDaemonIfStale, healBotDaemonNodeFromJob, introDmText, isBotMemoryMode, botLocalMemoryDir, botMemoryMode, resolveBotMemoryDir, validateBotIntro, validateBotDisplayName, validateBotKickoff, validateBotEffort, validateBotModel, effectiveBotEffort, BOT_EFFORT_LEVELS, DEFAULT_BOT_EFFORT, BOT_MEMORY_MODES, BOT_KINDS, isBotKind, effectiveBotKind, effectiveBotCompanies, normalizeBotCompanies, SETUP_BOT_WORKER_ID, isBotRuntimeId, localNameForRemoteBot, remoteBotRunnability, isPidAlive, listBotWorkerOptions, patchBotConfig, readBotConfig, readBotCredsIdentity, readBotStatus, patchBotStatus, runtimeCrashSinceStart, resolveBotWorker, runBot, runtimeFor, scaffoldBotMemory, scaffoldBotWorker, startBotDaemon, stopBotDaemon, uninstallBotDaemon, validateBotName, writeBotConfig, writeBotCreds, BOT_RUNTIMES, BOT_INTRO_MAX_CHARS, BOT_DISPLAY_NAME_MAX_CHARS, BOT_KICKOFF_MAX_CHARS, detectBotPlatform, withBotLock, localBotRole, remoteBotRole, remoteBotDisplayName, personFacingName, writeCloudDisplayName, setupSlugFor, ASSISTANT_ROLE, HQ_FLEET_RUNTIME_ENGINE_ID, HQ_FLEET_LOCAL_RELEASE, authenticateFleetLocalBot, bootstrapFleetLocalBot, buildSystemPrompt, controlFleetLocalBot, ensureFleetPython, fleetLocalGatewayPid, fleetLocalProfileNeedsAdoption, fleetLocalServiceInstalled, fleetProviderForRuntime, importFleetLocalMachineCredential, importFleetLocalProviderLogin, fleetProviderNeedsSignIn, fleetOwnerCompanies, refreshFleetLocalInstructions, fleetLocalPromotionRuntime, installPinnedFleetLocalDistribution, installTargetFleetLocalDistribution, resolveFleetLocalPointerTarget, resolveFleetLocalTargetRelease, fleetLocalProfileDir, fleetProfileOwnerCompanies, fleetLocalChannels, readFleetLocalGatewayState, readPromptSources, removeFleetLocalBot, } from "../lib/bot/index.js";
|
|
77
82
|
import { gatedInteractiveLogin } from "../utils/interactive-caller.js";
|
|
78
83
|
import { fleetInstallProgressReporter, runBotRuntimeInstall, runBotRuntimeStatus } from "./bot-runtime.js";
|
|
79
84
|
function collectRepeated(value, previous) {
|
|
@@ -128,6 +133,7 @@ export function listBotNames(root) {
|
|
|
128
133
|
function requireBot(name) {
|
|
129
134
|
const valid = validateBotName(name);
|
|
130
135
|
const dir = botDir(valid);
|
|
136
|
+
recoverPendingSwitchSafely(dir);
|
|
131
137
|
const config = readBotConfig(dir);
|
|
132
138
|
if (!config) {
|
|
133
139
|
// Never point at `create` alone: after a wiped ~/.hq the cloud still has
|
|
@@ -252,13 +258,18 @@ function syncFleetRuntimeJobs(name, dir, config) {
|
|
|
252
258
|
log("warn", `could not move ${name}'s scheduled jobs into the HQ Fleet Runtime: ${err instanceof Error ? err.message : String(err)}`);
|
|
253
259
|
}
|
|
254
260
|
try {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
261
|
+
// The Executive bot is preferred for daily hot-signal-sync jobs.
|
|
262
|
+
// The Executive bot registers them on its start regardless of what other
|
|
263
|
+
// bots hold (so a new Executive bot does not wait for the old one); a bot
|
|
264
|
+
// that is no longer the Executive bot removes only jobs covered by it.
|
|
265
|
+
//
|
|
266
|
+
// This follows the Executive identity only (resolveExecutiveBot), never
|
|
267
|
+
// the executive.enabled opt-in: the hot-channel sync runs for every user.
|
|
268
|
+
// With no personal bot here there is no Executive bot, so every bot keeps
|
|
269
|
+
// the earlier behaviour (each syncs its company, one bot per company).
|
|
270
|
+
const executiveBot = resolveExecutiveBot();
|
|
271
|
+
const role = hotSignalSyncRole(name, config, executiveBot);
|
|
272
|
+
const executive = role.executive;
|
|
262
273
|
const result = ensureFleetHotSignalSync({
|
|
263
274
|
dir,
|
|
264
275
|
config,
|
|
@@ -266,13 +277,20 @@ function syncFleetRuntimeJobs(name, dir, config) {
|
|
|
266
277
|
profileDir: fleetLocalProfileDir(config.agentUid),
|
|
267
278
|
activeCompany: readActiveCompanySlug(config.hqRoot) ?? null,
|
|
268
279
|
ownerCompanies: fleetProfileOwnerCompanies(config.agentUid),
|
|
269
|
-
otherBotDirs,
|
|
280
|
+
otherBotDirs: role.otherBotDirs,
|
|
270
281
|
nodeBinary: resolveNodeBinary(),
|
|
271
282
|
hqBinary: resolveHqBinary(),
|
|
272
283
|
signalsJobEnabled: fleetSignalsJobEnabled(),
|
|
284
|
+
executive,
|
|
285
|
+
executiveCompanies: role.executiveCompanies,
|
|
273
286
|
});
|
|
274
|
-
|
|
275
|
-
log("info", `removed the hot-signal-sync
|
|
287
|
+
if (executive === false && result.removed.length > 0) {
|
|
288
|
+
log("info", `removed the daily hot-signal-sync from this bot (${result.removed.length} job${result.removed.length === 1 ? "" : "s"}): ${executiveBot ? `${executiveBot.name} is the Executive bot now and runs it` : "only the Executive bot runs it"}`);
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
for (const id of result.removed)
|
|
292
|
+
log("info", `removed the hot-signal-sync job ${id}: this bot no longer syncs that company`);
|
|
293
|
+
}
|
|
276
294
|
for (const entry of result.companies) {
|
|
277
295
|
if (entry.created)
|
|
278
296
|
log("info", `registered the daily hot-signal-sync job for ${entry.company} at 06:30 in the HQ Fleet Runtime`);
|
|
@@ -284,6 +302,47 @@ function syncFleetRuntimeJobs(name, dir, config) {
|
|
|
284
302
|
log("warn", `could not set up ${name}'s hot-signal-sync job: ${err instanceof Error ? err.message : String(err)}`);
|
|
285
303
|
}
|
|
286
304
|
}
|
|
305
|
+
/**
|
|
306
|
+
* How a bot takes part in the daily hot-channel sync. Identity only (never
|
|
307
|
+
* the executive.enabled opt-in):
|
|
308
|
+
* - a company bot, or any bot when there is no personal bot here: the earlier
|
|
309
|
+
* behaviour, each bot syncs its company and one bot per company;
|
|
310
|
+
* - the Executive bot: registers its companies, leaving a company to a company
|
|
311
|
+
* bot that already runs it (other personal bots do not hold it back);
|
|
312
|
+
* - any other personal bot: hands over only companies the Executive already holds.
|
|
313
|
+
*/
|
|
314
|
+
export function hotSignalSyncRole(name, config, executiveBot) {
|
|
315
|
+
if (!executiveBot || effectiveBotKind(config) !== "personal")
|
|
316
|
+
return { otherBotDirs: allBotDirs() };
|
|
317
|
+
if (executiveBot.name !== name)
|
|
318
|
+
return {
|
|
319
|
+
executive: false,
|
|
320
|
+
executiveCompanies: executiveHotSignalSyncCompanies(executiveBot),
|
|
321
|
+
otherBotDirs: allBotDirs().filter((dir) => path.resolve(dir) !== path.resolve(executiveBot.dir)),
|
|
322
|
+
};
|
|
323
|
+
return { executive: true, otherBotDirs: companyBotDirs() };
|
|
324
|
+
}
|
|
325
|
+
/** Every local company bot folder; empty when they cannot be listed. */
|
|
326
|
+
function companyBotDirs() {
|
|
327
|
+
return allBotDirs().filter((dir) => {
|
|
328
|
+
try {
|
|
329
|
+
const other = readBotConfig(dir);
|
|
330
|
+
return other !== null && effectiveBotKind(other) !== "personal";
|
|
331
|
+
}
|
|
332
|
+
catch {
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
/** Every local bot folder; empty when they cannot be listed. */
|
|
338
|
+
function allBotDirs() {
|
|
339
|
+
try {
|
|
340
|
+
return listBotNames(botsRoot()).map((n) => botDir(n));
|
|
341
|
+
}
|
|
342
|
+
catch {
|
|
343
|
+
return [];
|
|
344
|
+
}
|
|
345
|
+
}
|
|
287
346
|
function refuseHeldFleetBot(dir) {
|
|
288
347
|
if (hasPromotionHold(dir))
|
|
289
348
|
throw new Error("This bot is held for cloud promotion. Continue its promotion before changing local settings or lifecycle.");
|
|
@@ -372,10 +431,38 @@ export function runtimeSignedIn(status, processAlive) {
|
|
|
372
431
|
return status.runtimeSignInCheck?.signedIn ?? null;
|
|
373
432
|
}
|
|
374
433
|
/**
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
434
|
+
* `brainUsage` for a row. A model-CLI bot records it itself (status.brainUsage);
|
|
435
|
+
* a Fleet bot's last failure carries the runtime's `brain_usage`, and an older
|
|
436
|
+
* runtime's usage-limit cause is read from its text.
|
|
378
437
|
*/
|
|
438
|
+
/** The bot runtime a Fleet provider name belongs to ("anthropic" is claude), or null. */
|
|
439
|
+
function runtimeIdForFleetProvider(provider) {
|
|
440
|
+
const p = (provider ?? "").trim().toLowerCase();
|
|
441
|
+
if (!p)
|
|
442
|
+
return null;
|
|
443
|
+
if (p === "claude" || p.includes("anthropic"))
|
|
444
|
+
return "claude";
|
|
445
|
+
if (p === "codex" || p === "chatgpt" || p.includes("openai"))
|
|
446
|
+
return "codex";
|
|
447
|
+
if (p === "grok" || p.includes("xai") || p === "x.ai")
|
|
448
|
+
return "grok";
|
|
449
|
+
return null;
|
|
450
|
+
}
|
|
451
|
+
export function brainUsageFor(config, status) {
|
|
452
|
+
const provider = config.runtime;
|
|
453
|
+
const own = status?.brainUsage;
|
|
454
|
+
if (own?.state === "exhausted")
|
|
455
|
+
return { state: "exhausted", provider: own.runtime ?? provider, resetsAt: own.resetsAt ?? null, since: own.since ?? null };
|
|
456
|
+
const failure = unresolvedLastFailure(status);
|
|
457
|
+
if (failure) {
|
|
458
|
+
const reported = failure.brainUsage?.state === "exhausted";
|
|
459
|
+
if (reported || isRuntimeUsageLimit(failure.cause)) {
|
|
460
|
+
const resetsAt = (reported ? failure.brainUsage?.resetsAt : null) ?? usageLimitResetsAt(failure.cause) ?? null;
|
|
461
|
+
return { state: "exhausted", provider: runtimeIdForFleetProvider(failure.provider) ?? provider, resetsAt, since: failure.at ?? null };
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return { state: "ok", provider, resetsAt: null, since: null };
|
|
465
|
+
}
|
|
379
466
|
export function brainSignInFor(name, config, status, legacy) {
|
|
380
467
|
const provider = config.runtime;
|
|
381
468
|
const command = fleetAuthCommand(name, config);
|
|
@@ -400,12 +487,15 @@ function signedOutReason(name, issue) {
|
|
|
400
487
|
}
|
|
401
488
|
function rowFor(name, opts = {}) {
|
|
402
489
|
const dir = botDir(name);
|
|
490
|
+
recoverPendingSwitchSafely(dir);
|
|
403
491
|
const config = readBotConfig(dir);
|
|
404
|
-
const
|
|
405
|
-
const
|
|
492
|
+
const executiveBot = opts.executiveBot === undefined ? resolveExecutiveBot() : opts.executiveBot;
|
|
493
|
+
const listed = readBotListedProcess(dir, config);
|
|
494
|
+
const fleet = listed.fleet;
|
|
495
|
+
const status = listed.status;
|
|
406
496
|
const legacy = fleet ? null : opts.legacy ?? legacyMoveState(dir, config, legacyConvertSeams.providerLogin(dir, config));
|
|
407
|
-
const pid =
|
|
408
|
-
const processAlive =
|
|
497
|
+
const pid = listed.pid;
|
|
498
|
+
const processAlive = listed.running;
|
|
409
499
|
// Turns this bot has taken and not finished: what "thinking" means.
|
|
410
500
|
const inflightTurns = readInflightTurns(dir);
|
|
411
501
|
let daemonInstalled = false;
|
|
@@ -451,6 +541,7 @@ function rowFor(name, opts = {}) {
|
|
|
451
541
|
...(fleet && config.fleetServiceInstallPending === true ? { needsSignIn: false, serviceInstallPending: true } : {}),
|
|
452
542
|
signInCommand: fleet ? fleetAuthCommand(name, config) : signInCommand(config.runtime),
|
|
453
543
|
brainSignIn: brainSignInFor(name, config, status, legacy),
|
|
544
|
+
brainUsage: brainUsageFor(config, status),
|
|
454
545
|
...(legacy ? { legacy: legacyStatusJson(legacy) } : {}),
|
|
455
546
|
runtimeCrash: processAlive ? runtimeCrashSinceStart(status) : null,
|
|
456
547
|
daemonInstalled,
|
|
@@ -460,6 +551,7 @@ function rowFor(name, opts = {}) {
|
|
|
460
551
|
introSentAt: config.introSentAt,
|
|
461
552
|
kind: effectiveBotKind(config),
|
|
462
553
|
companies: effectiveBotCompanies(config),
|
|
554
|
+
executive: executiveBot?.name === name,
|
|
463
555
|
workerSource: config.workerSource ?? "scaffold",
|
|
464
556
|
workerDir: config.workerDir,
|
|
465
557
|
...(config.workerId ? { workerId: config.workerId } : {}),
|
|
@@ -935,7 +1027,11 @@ function requireClaudeCodeLoginForCreate(name) {
|
|
|
935
1027
|
const check = botCreateSeams.claudeLogin();
|
|
936
1028
|
if (check.signedIn)
|
|
937
1029
|
return;
|
|
938
|
-
|
|
1030
|
+
const reason = `Claude Code is not signed in on this computer, so ${name} could not answer.`;
|
|
1031
|
+
// The same `brainSignIn` shape list, status and start report, so the
|
|
1032
|
+
// desktop app offers its own sign-in instead of showing a terminal command.
|
|
1033
|
+
const brainSignIn = { provider: "claude", needed: true, reason, command: "claude /login" };
|
|
1034
|
+
throw Object.assign(new Error(`${reason} ${describeClaudeLoginSources(check)} ${claudeLoginFix()}`.replace(/\s+/g, " ").trim()), { expected: true, brainSignIn });
|
|
939
1035
|
}
|
|
940
1036
|
export const botStopSeams = {
|
|
941
1037
|
/** True when this process runs inside the bot process `botPid` (one of its turns). */
|
|
@@ -1099,7 +1195,8 @@ export async function runBotCreate(nameArg, opts) {
|
|
|
1099
1195
|
// there too, not only a line on stderr.
|
|
1100
1196
|
if (opts.json && !err?.jsonReported) {
|
|
1101
1197
|
const message = err instanceof Error ? err.message : String(err);
|
|
1102
|
-
|
|
1198
|
+
const brainSignIn = err?.brainSignIn ?? null;
|
|
1199
|
+
console.log(JSON.stringify({ ok: false, name: nameArg, reason: "create-failed", message, ...(brainSignIn ? { brainSignIn } : {}) }, null, 2));
|
|
1103
1200
|
}
|
|
1104
1201
|
throw err;
|
|
1105
1202
|
}
|
|
@@ -1734,18 +1831,17 @@ async function runBotResident(nameArg) {
|
|
|
1734
1831
|
// A new pass per run: the login preflight and the 20-document cap are per run.
|
|
1735
1832
|
signalsPass: createClaudeSignalsPass({ hqRoot: config.hqRoot, company: input.company }),
|
|
1736
1833
|
}));
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
// No other bots could be listed; this bot is the only one checked.
|
|
1743
|
-
}
|
|
1834
|
+
// Prefer the Executive bot for daily hot-channel sync. Other personal bots
|
|
1835
|
+
// keep their company covered until the Executive has a replacement job.
|
|
1836
|
+
// Identity only (never the executive.enabled opt-in); with no personal bot
|
|
1837
|
+
// here every bot keeps the earlier one-bot-per-company behaviour.
|
|
1838
|
+
const executiveBot = resolveExecutiveBot();
|
|
1744
1839
|
registerHotSignalSyncOnStart({
|
|
1745
1840
|
dir,
|
|
1746
1841
|
config,
|
|
1747
1842
|
activeCompany: readActiveCompanySlug(config.hqRoot) ?? null,
|
|
1748
|
-
|
|
1843
|
+
...hotSignalSyncRole(name, config, executiveBot),
|
|
1844
|
+
executiveName: executiveBot?.name ?? null,
|
|
1749
1845
|
timezone: machineTimeZone(),
|
|
1750
1846
|
runFirst: (company) => runHotSignalSync({ company, catchUp: false, firstRun: true, now: () => new Date() }),
|
|
1751
1847
|
log: (level, message) => (level === "warn" ? console.error(message) : console.log(message)),
|
|
@@ -1808,10 +1904,14 @@ async function runBotList(opts) {
|
|
|
1808
1904
|
await runBotListRemote(opts);
|
|
1809
1905
|
return;
|
|
1810
1906
|
}
|
|
1811
|
-
const
|
|
1907
|
+
const executiveBot = resolveExecutiveBot();
|
|
1908
|
+
const rows = listBotNames(botsRoot()).map((n) => rowFor(n, { executiveBot }));
|
|
1812
1909
|
await decorateOnline(rows);
|
|
1813
1910
|
if (opts.json) {
|
|
1814
|
-
console.log(JSON.stringify({
|
|
1911
|
+
console.log(JSON.stringify({
|
|
1912
|
+
bots: rows,
|
|
1913
|
+
executiveBot: executiveBot ? { name: executiveBot.name, source: executiveBot.source } : null,
|
|
1914
|
+
}, null, 2));
|
|
1815
1915
|
return;
|
|
1816
1916
|
}
|
|
1817
1917
|
if (rows.length === 0) {
|
|
@@ -1819,9 +1919,37 @@ async function runBotList(opts) {
|
|
|
1819
1919
|
return;
|
|
1820
1920
|
}
|
|
1821
1921
|
for (const r of rows) {
|
|
1822
|
-
console.log(`${chalk.bold(r.name.padEnd(16))} ${r.agentUid} ${r.runtime.padEnd(6)} ${humanOnline(r).padEnd(8)} ${r.processAlive ? chalk.green(`pid ${r.pid}`) : chalk.gray(r.state)}${chalk.dim(` ${r.kind === "company" ? `company bot: ${r.companies.join(", ") || "no company"}` : "personal"}`)}${r.daemonInstalled ? chalk.dim(" launchd") : ""}${r.daemonNodeMissing ? chalk.red(` node missing (hq bot start ${r.name})`) : ""}${r.workerId ? chalk.dim(` worker ${r.workerId}${r.companySlug ? ` (${r.companySlug})` : ""}`) : ""}`);
|
|
1922
|
+
console.log(`${chalk.bold(r.name.padEnd(16))} ${r.agentUid} ${r.runtime.padEnd(6)} ${humanOnline(r).padEnd(8)} ${r.processAlive ? chalk.green(`pid ${r.pid}`) : chalk.gray(r.state)}${chalk.dim(` ${r.kind === "company" ? `company bot: ${r.companies.join(", ") || "no company"}` : "personal"}`)}${r.executive ? chalk.cyan(" (executive)") : ""}${r.daemonInstalled ? chalk.dim(" launchd") : ""}${r.daemonNodeMissing ? chalk.red(` node missing (hq bot start ${r.name})`) : ""}${r.workerId ? chalk.dim(` worker ${r.workerId}${r.companySlug ? ` (${r.companySlug})` : ""}`) : ""}`);
|
|
1823
1923
|
}
|
|
1824
1924
|
}
|
|
1925
|
+
/**
|
|
1926
|
+
* `hq bot eb [name]`: show or set the Executive bot (lib/bot/executive.ts).
|
|
1927
|
+
* Setting writes ~/.hq/executive.json; the bots pick the change up on their
|
|
1928
|
+
* next start (the new Executive bot registers the daily jobs, the old one
|
|
1929
|
+
* removes its copies).
|
|
1930
|
+
*/
|
|
1931
|
+
async function runBotEb(nameArg, opts) {
|
|
1932
|
+
if (nameArg === undefined) {
|
|
1933
|
+
const current = resolveExecutiveBot();
|
|
1934
|
+
if (opts.json) {
|
|
1935
|
+
console.log(JSON.stringify(current ? { name: current.name, source: current.source, runtime: current.config.runtime } : null, null, 2));
|
|
1936
|
+
return;
|
|
1937
|
+
}
|
|
1938
|
+
console.log(describeExecutiveBotSource(current));
|
|
1939
|
+
return;
|
|
1940
|
+
}
|
|
1941
|
+
const result = setExecutiveBot(nameArg);
|
|
1942
|
+
if (opts.json) {
|
|
1943
|
+
console.log(JSON.stringify(result, null, 2));
|
|
1944
|
+
return;
|
|
1945
|
+
}
|
|
1946
|
+
if (!result.changed) {
|
|
1947
|
+
console.log(`${result.name} is already the Executive bot; it is now the chosen one (hq bot eb ${result.name}).`);
|
|
1948
|
+
return;
|
|
1949
|
+
}
|
|
1950
|
+
console.log(`${result.name} is the Executive bot now: it builds your Daily Brief, extracts signals, runs the daily hot-channel sync and asks your decisions.`);
|
|
1951
|
+
console.log(chalk.dim(`Running bots pick this up on their next start: restart them with hq bot restart <name>.`));
|
|
1952
|
+
}
|
|
1825
1953
|
async function runBotStatus(nameArg, opts) {
|
|
1826
1954
|
const { name, dir, config } = requireBot(nameArg);
|
|
1827
1955
|
const fleet = isFleetRuntimeBot(config);
|
|
@@ -1848,6 +1976,8 @@ async function runBotStatus(nameArg, opts) {
|
|
|
1848
1976
|
else
|
|
1849
1977
|
console.log(` engine: ${chalk.yellow(`legacy ${runtimeDisplayName(config.runtime)} runner (not on the HQ Fleet Runtime)`)}`);
|
|
1850
1978
|
console.log(` kind: ${describeKind(row.kind, row.companies)}`);
|
|
1979
|
+
if (row.executive)
|
|
1980
|
+
console.log(` executive: yes (the Executive bot on this computer; change it with hq bot eb <name>)`);
|
|
1851
1981
|
const login = describeBotAuth(dir, config);
|
|
1852
1982
|
console.log(` runtime: ${row.runtime} model ${row.model ?? "default"} thinking ${row.effort}${row.effortIsDefault ? " (default)" : ""}`);
|
|
1853
1983
|
console.log(` login: ${login.login === "own" && !login.present ? chalk.red(formatBotAuth(login, name)) : formatBotAuth(login, name)}`);
|
|
@@ -1857,6 +1987,9 @@ async function runBotStatus(nameArg, opts) {
|
|
|
1857
1987
|
console.log(` process: ${row.processAlive ? chalk.green(`running (pid ${row.pid})`) : chalk.gray(row.state)}`);
|
|
1858
1988
|
if (row.needsSignIn)
|
|
1859
1989
|
console.log(` sign-in: required (${row.authCommand})`);
|
|
1990
|
+
if (row.brainUsage.state === "exhausted") {
|
|
1991
|
+
console.log(` usage: ${chalk.yellow(`out of usage${row.brainUsage.resetsAt ? `, resets ${row.brainUsage.resetsAt}` : ""}`)} — switch account: hq bot switch-account ${name} --runtime <claude|codex|grok>`);
|
|
1992
|
+
}
|
|
1860
1993
|
console.log(` HQ online: ${humanOnline(row)}${row.lastHeartbeatAt ? chalk.dim(` last heartbeat ${row.lastHeartbeatAt}`) : ""}${row.lastHeartbeatOk === false && status?.lastHeartbeatError ? chalk.dim(` (${status.lastHeartbeatError})`) : ""}`);
|
|
1861
1994
|
if (status?.lastInboxPollOk === false) {
|
|
1862
1995
|
console.log(` inbox: ${chalk.red("cannot receive")}${status.lastInboxError ? chalk.dim(` ${status.lastInboxError}`) : ""}`);
|
|
@@ -2385,6 +2518,7 @@ async function switchRuntimeOrAccount(input) {
|
|
|
2385
2518
|
runtime: targetRuntime,
|
|
2386
2519
|
...(candidate.model ? { model: candidate.model } : {}),
|
|
2387
2520
|
...(candidate.effort ? { effort: candidate.effort } : {}),
|
|
2521
|
+
...(input.probeTimeoutMs ? { timeoutMs: input.probeTimeoutMs } : {}),
|
|
2388
2522
|
env: probeEnv,
|
|
2389
2523
|
});
|
|
2390
2524
|
if (!probe.ok) {
|
|
@@ -2395,25 +2529,66 @@ async function switchRuntimeOrAccount(input) {
|
|
|
2395
2529
|
throw Object.assign(new Error(`${name} cannot change its runtime or login from inside one of its own turns. Run this from outside the bot. Nothing was changed.`), { expected: true });
|
|
2396
2530
|
}
|
|
2397
2531
|
const wasRunning = life.isRunning(dir);
|
|
2532
|
+
const shouldStart = wasRunning || input.startAlways === true;
|
|
2533
|
+
// Written before anything changes: a switch killed part-way (the desktop's
|
|
2534
|
+
// time budget, a closed terminal) is rolled back, or finished when the bot
|
|
2535
|
+
// was already up on the new account, by the next start, status or list.
|
|
2536
|
+
const journal = input.journal
|
|
2537
|
+
? {
|
|
2538
|
+
v: 1,
|
|
2539
|
+
pid: process.pid,
|
|
2540
|
+
startedAt: new Date().toISOString(),
|
|
2541
|
+
phase: "changing",
|
|
2542
|
+
wasRunning,
|
|
2543
|
+
from: { runtime: config.runtime, runtimeAuth: config.runtimeAuth ?? null, model: config.model ?? null, effort: config.effort ?? null },
|
|
2544
|
+
to: targetRuntime,
|
|
2545
|
+
aside: null,
|
|
2546
|
+
brainState: null,
|
|
2547
|
+
}
|
|
2548
|
+
: null;
|
|
2549
|
+
const saveJournal = (patch = {}) => {
|
|
2550
|
+
if (journal)
|
|
2551
|
+
writePendingSwitch(dir, Object.assign(journal, patch));
|
|
2552
|
+
};
|
|
2553
|
+
saveJournal();
|
|
2398
2554
|
if (wasRunning && !(await life.stop(name, dir, config))) {
|
|
2555
|
+
clearPendingSwitch(dir);
|
|
2399
2556
|
throw Object.assign(new Error(`${name} did not stop, so nothing was changed. Try again, or run hq bot stop ${name} first.`), { expected: true });
|
|
2400
2557
|
}
|
|
2401
2558
|
let aside = null;
|
|
2559
|
+
// The old account's sign-in and usage state, as it was before a clear, so a
|
|
2560
|
+
// rollback puts it back: the bot is on that account again, and HQ must keep
|
|
2561
|
+
// saying it is out of usage or signed out.
|
|
2562
|
+
let clearedBrainState = null;
|
|
2402
2563
|
// Only the settings this command changed go back, onto a fresh bot.json.
|
|
2403
2564
|
const rollBack = () => {
|
|
2404
2565
|
if (aside)
|
|
2405
2566
|
restoreBotSessions(dir, aside);
|
|
2567
|
+
if (clearedBrainState && readBotStatus(dir))
|
|
2568
|
+
patchBotStatus(dir, clearedBrainState, () => readBotStatus(dir));
|
|
2406
2569
|
return patchBotConfig(dir, { runtime: config.runtime, runtimeAuth: config.runtimeAuth, model: config.model, effort: config.effort });
|
|
2407
2570
|
};
|
|
2408
2571
|
let next;
|
|
2409
2572
|
let running = false;
|
|
2410
2573
|
let rolledBack = false;
|
|
2411
2574
|
try {
|
|
2412
|
-
if (switching)
|
|
2575
|
+
if (switching) {
|
|
2413
2576
|
aside = setAsideBotSessions(dir, config.runtime);
|
|
2577
|
+
saveJournal({ aside: { archiveDir: aside.archiveDir, moved: aside.moved } });
|
|
2578
|
+
}
|
|
2579
|
+
const before = input.clearBrainState ? readBotStatus(dir) : null;
|
|
2580
|
+
if (before) {
|
|
2581
|
+
clearedBrainState = { brainUsage: before.brainUsage ?? null, runtimeSignIn: before.runtimeSignIn ?? null, modelHold: before.modelHold ?? null };
|
|
2582
|
+
saveJournal({ brainState: clearedBrainState });
|
|
2583
|
+
}
|
|
2414
2584
|
next = patchBotConfig(dir, patch);
|
|
2415
|
-
if (
|
|
2585
|
+
if (before)
|
|
2586
|
+
patchBotStatus(dir, { brainUsage: null, runtimeSignIn: null, modelHold: null }, () => readBotStatus(dir));
|
|
2587
|
+
if (shouldStart)
|
|
2416
2588
|
running = await life.start(name, dir, next);
|
|
2589
|
+
// Up on the new account: a kill from here on finishes the switch instead of undoing it.
|
|
2590
|
+
if (running)
|
|
2591
|
+
saveJournal({ phase: "started" });
|
|
2417
2592
|
}
|
|
2418
2593
|
catch (err) {
|
|
2419
2594
|
// Any failure part-way puts the old settings and sessions back, and the bot back up.
|
|
@@ -2422,19 +2597,22 @@ async function switchRuntimeOrAccount(input) {
|
|
|
2422
2597
|
}
|
|
2423
2598
|
catch { /* best effort */ }
|
|
2424
2599
|
const old = rollBack();
|
|
2600
|
+
clearPendingSwitch(dir);
|
|
2425
2601
|
if (wasRunning)
|
|
2426
2602
|
await life.start(name, dir, old);
|
|
2427
2603
|
throw err;
|
|
2428
2604
|
}
|
|
2429
2605
|
const login = describeBotAuth(dir, next);
|
|
2430
2606
|
createBotLogger(dir)("info", `settings: runtime=${next.runtime} login=${login.login}${login.account ? ` account=${login.account}` : ""} model=${next.model ?? "default"} effort=${effectiveBotEffort(next)}${aside ? ` (sessions set aside in ${aside.archiveDir})` : ""}`);
|
|
2431
|
-
if (
|
|
2607
|
+
if (shouldStart && !running) {
|
|
2432
2608
|
await life.stop(name, dir, next);
|
|
2433
2609
|
const old = rollBack();
|
|
2434
2610
|
rolledBack = true;
|
|
2435
|
-
|
|
2611
|
+
clearPendingSwitch(dir);
|
|
2612
|
+
running = wasRunning ? await life.start(name, dir, old) : false;
|
|
2436
2613
|
createBotLogger(dir)("warn", `settings rolled back: ${name} did not start on ${next.runtime}`);
|
|
2437
2614
|
}
|
|
2615
|
+
clearPendingSwitch(dir);
|
|
2438
2616
|
const result = {
|
|
2439
2617
|
ok: !rolledBack,
|
|
2440
2618
|
name,
|
|
@@ -2446,7 +2624,7 @@ async function switchRuntimeOrAccount(input) {
|
|
|
2446
2624
|
sessionsSetAside: aside && !rolledBack ? { dir: aside.archiveDir, files: aside.moved.length } : null,
|
|
2447
2625
|
backup: aside ? path.join(aside.archiveDir, "bot.json") : null,
|
|
2448
2626
|
running,
|
|
2449
|
-
restarted:
|
|
2627
|
+
restarted: shouldStart,
|
|
2450
2628
|
rolledBack,
|
|
2451
2629
|
};
|
|
2452
2630
|
if (rolledBack)
|
|
@@ -2466,9 +2644,86 @@ async function switchRuntimeOrAccount(input) {
|
|
|
2466
2644
|
else {
|
|
2467
2645
|
console.log(chalk.green(`${name} now uses ${formatBotAuth(login, name)} for ${next.runtime}.`));
|
|
2468
2646
|
}
|
|
2469
|
-
if (
|
|
2647
|
+
if (shouldStart)
|
|
2470
2648
|
console.log(chalk.dim(running ? " restarted" : ` did not report running; check: hq bot logs ${name}`));
|
|
2471
2649
|
}
|
|
2650
|
+
/** switch-account's test turn: short, so probe, stop, start and a rollback fit the desktop's 5-minute budget. */
|
|
2651
|
+
export const SWITCH_ACCOUNT_PROBE_TIMEOUT_MS = 60_000;
|
|
2652
|
+
/** The Fleet provider `hq bot auth` takes for a bot runtime. */
|
|
2653
|
+
function fleetProviderForRuntimeId(runtime) {
|
|
2654
|
+
return runtime === "grok" ? "grok" : runtime === "codex" ? "chatgpt" : "claude";
|
|
2655
|
+
}
|
|
2656
|
+
/**
|
|
2657
|
+
* switch-account for a bot on the HQ Fleet Runtime: the Fleet sign-in path
|
|
2658
|
+
* (`hq bot auth`). Claude reads the owner's Claude Code sign-in, which the
|
|
2659
|
+
* desktop signs in to the new account first. ChatGPT and Grok run the Fleet
|
|
2660
|
+
* runtime's own browser sign-in for this bot. The bot keeps its identity,
|
|
2661
|
+
* profile, memory and jobs and is restarted on the new login. On success the
|
|
2662
|
+
* old account's out-of-usage report is cleared from status.json.
|
|
2663
|
+
*/
|
|
2664
|
+
async function switchFleetBotAccount(name, dir, runtime, opts, deps) {
|
|
2665
|
+
const auth = deps.fleetAuth ?? runBotAuth;
|
|
2666
|
+
const signedIn = await auth(name, { provider: fleetProviderForRuntimeId(runtime), ...(opts.json ? { json: true } : {}) });
|
|
2667
|
+
// A sign-in whose gateway did not come up is not a working new account yet:
|
|
2668
|
+
// keep the old report so HQ still says why the bot is not answering.
|
|
2669
|
+
if (signedIn && signedIn.running === false) {
|
|
2670
|
+
process.exitCode = 1;
|
|
2671
|
+
return;
|
|
2672
|
+
}
|
|
2673
|
+
const status = readBotStatus(dir);
|
|
2674
|
+
if (status && (status.lastFailure || status.brainUsage || status.runtimeSignIn)) {
|
|
2675
|
+
patchBotStatus(dir, { lastFailure: undefined, brainUsage: null, runtimeSignIn: null }, () => readBotStatus(dir));
|
|
2676
|
+
}
|
|
2677
|
+
createBotLogger(dir)("info", `switch-account: ${name} signed in to ${fleetProviderForRuntimeId(runtime)} through the HQ Fleet sign-in`);
|
|
2678
|
+
}
|
|
2679
|
+
/**
|
|
2680
|
+
* `hq bot switch-account <name> --runtime <runtime>`: move an existing local
|
|
2681
|
+
* bot onto the account the owner's own sign-in for `runtime` now uses (the
|
|
2682
|
+
* desktop app's Switch account signs that in first, with the same switcher as
|
|
2683
|
+
* New bot). Same provider or a different one. The bot keeps its HQ identity,
|
|
2684
|
+
* worker folder, memory, DM history and jobs: only its runtime and login
|
|
2685
|
+
* settings change, the new setup is probed first (nothing changes when it
|
|
2686
|
+
* cannot answer), the old sign-in and usage state are cleared, and the bot is
|
|
2687
|
+
* started again even when it was stopped because it was signed out or out of
|
|
2688
|
+
* usage. A bot that does not come back is rolled back.
|
|
2689
|
+
*/
|
|
2690
|
+
export async function runBotSwitchAccount(nameArg, opts, deps = {}) {
|
|
2691
|
+
const name = validateBotName(nameArg);
|
|
2692
|
+
await withBotLock(name, async () => {
|
|
2693
|
+
const { dir, config } = requireBot(name);
|
|
2694
|
+
if (hasPromotionHold(dir))
|
|
2695
|
+
throw new Error("This bot is held for cloud promotion. Continue its promotion before changing local settings or lifecycle.");
|
|
2696
|
+
if (!isBotRuntimeId(opts.runtime)) {
|
|
2697
|
+
throw Object.assign(new Error(`--runtime must be one of ${BOT_RUNTIMES.join(", ")}`), { expected: true });
|
|
2698
|
+
}
|
|
2699
|
+
if (isFleetRuntimeBot(config)) {
|
|
2700
|
+
if (opts.runtime === "grok") {
|
|
2701
|
+
// The Fleet Grok sign-in reuses another bot's xAI login on this
|
|
2702
|
+
// computer, so it cannot reach a different account.
|
|
2703
|
+
throw Object.assign(new Error(`Grok accounts cannot be switched for HQ Fleet bots yet: the Fleet Grok sign-in reuses the xAI login already on this computer. Nothing was changed.`), { expected: true });
|
|
2704
|
+
}
|
|
2705
|
+
return switchFleetBotAccount(name, dir, opts.runtime, opts, deps);
|
|
2706
|
+
}
|
|
2707
|
+
const targetRuntime = opts.runtime;
|
|
2708
|
+
const switching = targetRuntime !== config.runtime;
|
|
2709
|
+
// The owner's own sign-in for the target runtime: the account just picked.
|
|
2710
|
+
const runtimeAuth = withRuntimeAuth(config.runtimeAuth, targetRuntime, null);
|
|
2711
|
+
return switchRuntimeOrAccount({
|
|
2712
|
+
name,
|
|
2713
|
+
dir,
|
|
2714
|
+
config,
|
|
2715
|
+
targetRuntime,
|
|
2716
|
+
switching,
|
|
2717
|
+
runtimeAuth,
|
|
2718
|
+
opts: { ...(opts.json ? { json: true } : {}) },
|
|
2719
|
+
deps,
|
|
2720
|
+
startAlways: true,
|
|
2721
|
+
clearBrainState: true,
|
|
2722
|
+
probeTimeoutMs: SWITCH_ACCOUNT_PROBE_TIMEOUT_MS,
|
|
2723
|
+
journal: true,
|
|
2724
|
+
});
|
|
2725
|
+
}, { command: "hq bot switch-account" });
|
|
2726
|
+
}
|
|
2472
2727
|
/** `hq bot login <name>`: sign the bot in with a login of its own. */
|
|
2473
2728
|
export async function runBotLogin(nameArg, opts, deps = {}) {
|
|
2474
2729
|
const name = validateBotName(nameArg);
|
|
@@ -2614,7 +2869,7 @@ export async function runBotRestart(nameArg, opts = {}) {
|
|
|
2614
2869
|
await stopBot(b.name, b.dir, b.config, "silent");
|
|
2615
2870
|
await startBot(b.name, b.dir, b.config, opts.output ?? (opts.json ? "json" : "text"));
|
|
2616
2871
|
}
|
|
2617
|
-
async function runBotAuth(nameArg, opts) {
|
|
2872
|
+
export async function runBotAuth(nameArg, opts) {
|
|
2618
2873
|
const b = requireBot(nameArg);
|
|
2619
2874
|
const apiKey = opts.apiKey ? fs.readFileSync(0, "utf8").trim() : undefined;
|
|
2620
2875
|
if (opts.apiKey && !apiKey) {
|
|
@@ -2698,11 +2953,12 @@ async function runBotAuth(nameArg, opts) {
|
|
|
2698
2953
|
const running = await fleetGatewayComesUp(b.config.agentUid, result.restarted ? fleetStartWaitMs() : 0);
|
|
2699
2954
|
if (opts.json) {
|
|
2700
2955
|
console.log(JSON.stringify({ ok: true, name: b.name, runtime: HQ_FLEET_RUNTIME_ENGINE_ID, ...result, needsSignIn: false, running, serviceInstallPending: pending && !result.restarted, ...(legacy ? { movedToFleet: true } : {}) }, null, 2));
|
|
2701
|
-
return;
|
|
2956
|
+
return { running };
|
|
2702
2957
|
}
|
|
2703
2958
|
console.log(running
|
|
2704
2959
|
? chalk.green(`${b.name} is signed in to ${result.provider} and running ${result.model}.`)
|
|
2705
2960
|
: chalk.yellow(`${b.name} is signed in to ${result.provider}, but did not start. Run hq bot start ${b.name}.`));
|
|
2961
|
+
return { running };
|
|
2706
2962
|
}
|
|
2707
2963
|
// ── adopt / restore (bring a bot you own back to this computer) ──────────────
|
|
2708
2964
|
/**
|
|
@@ -3410,7 +3666,7 @@ export function registerBotCommand(program) {
|
|
|
3410
3666
|
.option("--transport <transport>", "Provider transport: chat_completions, anthropic_messages, or codex_responses")
|
|
3411
3667
|
.option("--no-browser", "Do not open a browser during device authorization")
|
|
3412
3668
|
.option("--json", "Print machine-readable JSON")
|
|
3413
|
-
.action((name, opts) => wrap(() => runBotAuth(name, opts))());
|
|
3669
|
+
.action((name, opts) => wrap(async () => { await runBotAuth(name, opts); })());
|
|
3414
3670
|
bot
|
|
3415
3671
|
.command("logs <name>")
|
|
3416
3672
|
.description("Show the bot's log")
|
|
@@ -3438,6 +3694,17 @@ export function registerBotCommand(program) {
|
|
|
3438
3694
|
.option("--effort <level>", `Thinking level (claude ${BOT_EFFORT_LEVELS.claude.join("|")}; codex ${BOT_EFFORT_LEVELS.codex.join("|")}; grok ${BOT_EFFORT_LEVELS.grok.join("|")}), or default (${DEFAULT_BOT_EFFORT})`)
|
|
3439
3695
|
.option("--json", "Print machine-readable JSON")
|
|
3440
3696
|
.action((name, opts) => wrap(() => runBotSet(name, opts))());
|
|
3697
|
+
bot
|
|
3698
|
+
.command("switch-account <name>")
|
|
3699
|
+
.description("Move the bot onto another account (same provider or another), keeping its identity, worker, memory and jobs, then start it again. A model-CLI bot uses your own sign-in for --runtime, checked with one test turn first; a cut-off switch is rolled back by the next start or status. A Fleet Runtime bot uses the HQ Fleet sign-in (hq bot auth)")
|
|
3700
|
+
.requiredOption("--runtime <runtime>", `${BOT_RUNTIMES.join("|")}`)
|
|
3701
|
+
.option("--json", "Print machine-readable JSON")
|
|
3702
|
+
.action((name, opts) => wrap(() => runBotSwitchAccount(name, opts))());
|
|
3703
|
+
bot
|
|
3704
|
+
.command("eb [name]")
|
|
3705
|
+
.description("Executive bot (EB): the main personal bot that builds your Daily Brief, extracts signals, runs the daily hot-channel sync and asks your decisions. With no name, show which bot it is and how that was decided; with a name, make that personal bot the Executive bot (its jobs move on the bots' next start)")
|
|
3706
|
+
.option("--json", "Print machine-readable JSON")
|
|
3707
|
+
.action((name, opts) => wrap(() => runBotEb(name, opts))());
|
|
3441
3708
|
bot
|
|
3442
3709
|
.command("login <name>")
|
|
3443
3710
|
.description("Give the bot a model login of its own, so it does not use yours: runs the runtime's own sign-in into ~/.hq/bots/<name>/auth/<runtime>")
|
|
@@ -37,6 +37,13 @@ export type GatedSyncCommand = "push" | "pull" | "now";
|
|
|
37
37
|
export declare function isCloudOff(home?: string): boolean;
|
|
38
38
|
/** True when `company` (a slug) is a company vault whose switch is off. */
|
|
39
39
|
export declare function isCompanyVaultOff(switches: VaultSyncSwitches, company: string): boolean;
|
|
40
|
+
export interface EngineOwnedVaults {
|
|
41
|
+
personal: boolean;
|
|
42
|
+
companies: ReadonlySet<string>;
|
|
43
|
+
uidSlugs: ReadonlyMap<string, string>;
|
|
44
|
+
}
|
|
45
|
+
export declare const NO_ENGINE_VAULTS: EngineOwnedVaults;
|
|
46
|
+
export declare function readEngineOwnedVaults(home?: string): EngineOwnedVaults;
|
|
40
47
|
/**
|
|
41
48
|
* The refusal text when every vault is off. The first line keeps the phrase
|
|
42
49
|
* "refused immediately": `handoff-sync-prefetch` (shell and native) reports
|
|
@@ -93,7 +100,7 @@ export declare function resolveVaultRef(ref: string, hqRoot: string | undefined)
|
|
|
93
100
|
* With `--creds-from-stdin` and no `--company`, the target is unknown until
|
|
94
101
|
* stdin is parsed; {@link refusalForEntity} checks it then.
|
|
95
102
|
*/
|
|
96
|
-
export declare function refusalFor(command: GatedSyncCommand, selection: SyncSelection, switches: VaultSyncSwitches): VaultRefusal | null;
|
|
103
|
+
export declare function refusalFor(command: GatedSyncCommand, selection: SyncSelection, switches: VaultSyncSwitches, engine?: EngineOwnedVaults): VaultRefusal | null;
|
|
97
104
|
/**
|
|
98
105
|
* The refusal for a pre-vended EntityContext read from stdin. A `prs_*` uid
|
|
99
106
|
* is the personal vault; otherwise the slug (or the uid, through the
|
|
@@ -102,7 +109,7 @@ export declare function refusalFor(command: GatedSyncCommand, selection: SyncSel
|
|
|
102
109
|
export declare function refusalForEntity(command: GatedSyncCommand, entity: {
|
|
103
110
|
uid?: unknown;
|
|
104
111
|
slug?: unknown;
|
|
105
|
-
}, hqRoot: string | undefined, switches: VaultSyncSwitches): VaultRefusal | null;
|
|
112
|
+
}, hqRoot: string | undefined, switches: VaultSyncSwitches, engine?: EngineOwnedVaults): VaultRefusal | null;
|
|
106
113
|
/** The vaults an `--all` run leaves out. */
|
|
107
114
|
export declare function vaultSkips(selection: SyncSelection, switches: VaultSyncSwitches): VaultSkips;
|
|
108
115
|
/** Thrown after stdin is parsed when its target vault is off. */
|