@indigoai-us/hq-cli 5.345.243 → 5.345.244
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 +8 -0
- package/dist/command-catalog.generated.d.ts +3 -3
- package/dist/command-catalog.generated.js +3 -3
- package/dist/commands/bot.d.ts +12 -0
- package/dist/commands/bot.js +126 -44
- package/dist/hq-cloud-sync-runner/bin/sync-runner.js +285 -225
- package/dist/hq-cloud-sync-runner/package.json +1 -1
- package/dist/lib/bot/config.d.ts +10 -0
- package/dist/lib/bot/config.js +15 -0
- package/dist/lib/bot/continuity.js +2 -2
- package/dist/lib/bot/promote-sign-in.d.ts +78 -0
- package/dist/lib/bot/promote-sign-in.js +152 -0
- package/dist/lib/bot/promote.d.ts +19 -1
- package/dist/lib/bot/promote.js +25 -5
- package/dist/lib/bot/scaffold.d.ts +20 -3
- package/dist/lib/bot/scaffold.js +18 -8
- package/dist/lib/daemon/hook-requests-fleet-session-start.d.ts +10 -0
- package/dist/lib/daemon/hook-requests-fleet-session-start.js +86 -42
- package/dist/lib/daemon/hook-requests.d.ts +2 -2
- package/dist/lib/daemon/hook-requests.js +13 -3
- package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
- package/dist/lib/flag-registry-worker-source.generated.js +1 -1
- package/dist/lib/lanes/liveness.js +46 -16
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [5.345.244] — 2026-11-20
|
|
6
|
+
- Fixed: `hq bot create --kind company --company <slug>` now files the bot as a company bot. Its `personal/workers/<name>/worker.yaml` says `type: CompanyBot`, `company: <slug>` and a company description, and its `persona.md` says it is a company bot that acts as itself, with its own permissions, only in its company's context. Before, both files described the owner's personal bot. `hq bot adopt` and `hq bot restore` label a rebuilt company bot the same way. `hq bot create --json` and `hq bot list --json` report a one-company bot's company in `companySlug` instead of `null`, the HQ Fleet Runtime instructions bind its turns to that company, and its promotion snapshot carries the company, so the cloud import refuses to load it into another company. Bots that already exist keep their files.
|
|
7
|
+
- Fixed: `hq bot promote` now says what a pending move waits for. While HQ sets up the cloud copy it says a Codex sign-in comes next; once HQ has a device code it prints the page (https://auth.openai.com/codex/device), the code and when the code expires. `--json` carries the same as a new `signIn` field (`type: "codex-device-sign-in"`, `status`, `url`, `code`, `capturedAt`, `expiresAt`, `instruction`), and no longer passes on an expired code as `pairing`. In a terminal the command keeps waiting: it checks every 30 seconds, shows the new code when one expires, rides out a few failed checks, and stops when the move finishes, when HQ reports a failure, when the move is cancelled (it never starts a new one), or after an hour. Ctrl-C stops waiting and leaves the move running. `--company` now takes the company's slug (e.g. `--company indigo`) as well as its uid; a company bot's slug must be one of its own companies. The help says so.
|
|
8
|
+
- Fixed: `hq bot promote` now always sends the bot's thinking level, as `hq bot status` shows it, including the default (`medium`). Before, a bot on the default sent no level, HQ filled in its cloud default (`high`), and the cloud bot came up on a higher level than the local one. A level the bot's model runtime does not have is sent as the default. For a new move, the moved-and-stayed summary (`fleetState.settings.effort`) shows the level that was sent instead of `null`.
|
|
9
|
+
- Updates the bundled HQ Cloud to 6.18.119. A sync runner signed in as a machine (an agent box, an Outpost or a company Outpost) now pulls as soon as the new sync engine writes a file to a vault it syncs, instead of waiting up to 6 hours for the next full check: it reads the caller identity for those change notices from the machine's own token. Usage telemetry now caps upload requests per runtime, so a Codex backlog no longer stops Claude usage from reaching the server. Sync with `--on-conflict abort` now merges a log file that two writers only appended to instead of aborting the whole push.
|
|
10
|
+
- Fixed: `hq lanes list` builds its liveness index from the work-mesh spool by splitting raw bytes on newlines, so a multi-byte character cut by a 64 KiB read boundary no longer corrupts that event, and a spool line over 1 MiB is skipped whole with one warning instead of its tail being parsed as a separate malformed line.
|
|
11
|
+
- Internal: on local bots (`fleet-local`), `hq-hook` now hands the `.claude/settings.json` UserPromptSubmit commands to the HQ daemon on a new `fleet-local-prompt` request note and answers the prompt at once, without waiting for them. The daemon runs `hq-hook fleet-settings UserPromptSubmit` and leaves the commands' context in the session's deferred folder, which the next prompt picks up, so that context arrives one prompt late (owner decision, 2026-11-20). The company-scope line and earlier deferred notes are still added in the hook. `fleet-local-adapter:UserPromptSubmit` stays unclaimed, because the adapter's per-sender company scope is not ported, so bots keep the shell adapter for this event. Hosted agents (`agents-v2`) are unchanged.
|
|
12
|
+
|
|
5
13
|
## [5.345.243] — 2026-11-20
|
|
6
14
|
- Added (`hq doctor`): a `claude-imports` check that warns when `~/.claude/CLAUDE.md` or one of the HQ tree's CLAUDE.md files has an `@import` path written with backslashes (for example `@C:\Users\me\hq\.claude\CLAUDE.md`). Claude Code never loads such an import, so on Windows the HQ charter or another file silently never reached the session. An escaped space (`\ `) is left alone, and imports inside code or HTML comments are ignored. `hq doctor --fix` rewrites those import paths with forward slashes and changes nothing else in the file. The check also warns when the `hq install --global` import in `~/.claude/CLAUDE.md` names a path Claude Code cannot find, such as one cut short by an unescaped space; when the full path exists, `--fix` rewrites that one line with escaped spaces.
|
|
7
15
|
- On hosted agents-v2 and fleet-local bots, the new hook engine now refuses an edit under `core/` (and the other protected scaffold paths) in the bot's HQ folder when the runtime runs the hook from a folder outside that HQ folder, as the released bot adapters do. It also accepts a registered `--hq-root` that has `core/` and `.claude/hooks/hook-gate.sh` but no `companies/` folder, so a plain command such as `date -u` is no longer refused with "the HQ root is unknown". A root that is not an HQ folder is still refused. The replay harness now runs fleet events from outside the HQ folder, as the runtimes do.
|
|
@@ -20547,8 +20547,8 @@ export declare const COMMAND_CATALOG: readonly [{
|
|
|
20547
20547
|
readonly description: "";
|
|
20548
20548
|
}];
|
|
20549
20549
|
readonly options: readonly [{
|
|
20550
|
-
readonly flags: "--company <
|
|
20551
|
-
readonly description: "
|
|
20550
|
+
readonly flags: "--company <company>";
|
|
20551
|
+
readonly description: "The company the bot moves into: its slug (e.g. indigo) or uid (cmp_...)";
|
|
20552
20552
|
readonly hidden: false;
|
|
20553
20553
|
}, {
|
|
20554
20554
|
readonly flags: "--cancel";
|
|
@@ -20556,7 +20556,7 @@ export declare const COMMAND_CATALOG: readonly [{
|
|
|
20556
20556
|
readonly hidden: false;
|
|
20557
20557
|
}, {
|
|
20558
20558
|
readonly flags: "--json";
|
|
20559
|
-
readonly description: "Print promotion progress as JSON";
|
|
20559
|
+
readonly description: "Print promotion progress as JSON, including the Codex sign-in the move waits for (signIn)";
|
|
20560
20560
|
readonly hidden: false;
|
|
20561
20561
|
}];
|
|
20562
20562
|
readonly subcommands: readonly [];
|
|
@@ -25061,8 +25061,8 @@ export const COMMAND_CATALOG = [
|
|
|
25061
25061
|
],
|
|
25062
25062
|
"options": [
|
|
25063
25063
|
{
|
|
25064
|
-
"flags": "--company <
|
|
25065
|
-
"description": "
|
|
25064
|
+
"flags": "--company <company>",
|
|
25065
|
+
"description": "The company the bot moves into: its slug (e.g. indigo) or uid (cmp_...)",
|
|
25066
25066
|
"hidden": false
|
|
25067
25067
|
},
|
|
25068
25068
|
{
|
|
@@ -25072,7 +25072,7 @@ export const COMMAND_CATALOG = [
|
|
|
25072
25072
|
},
|
|
25073
25073
|
{
|
|
25074
25074
|
"flags": "--json",
|
|
25075
|
-
"description": "Print promotion progress as JSON",
|
|
25075
|
+
"description": "Print promotion progress as JSON, including the Codex sign-in the move waits for (signIn)",
|
|
25076
25076
|
"hidden": false
|
|
25077
25077
|
}
|
|
25078
25078
|
],
|
package/dist/commands/bot.d.ts
CHANGED
|
@@ -662,9 +662,21 @@ export declare const botPromoteSeams: {
|
|
|
662
662
|
running: boolean;
|
|
663
663
|
how: string;
|
|
664
664
|
}>;
|
|
665
|
+
/** A person is watching: the command keeps waiting for the move instead of returning at once. */
|
|
666
|
+
attached: () => boolean;
|
|
667
|
+
sleep: (ms: number) => Promise<void>;
|
|
668
|
+
now: () => number;
|
|
665
669
|
/** `hq bot start` asks HQ every time; `hq bot run` shares the daemon's per-bot interval, so a restart loop does not hammer HQ. */
|
|
666
670
|
reconcileHold: (name: string, dir: string, config: BotConfig, command: "hq bot start" | "hq bot run") => Promise<import("../lib/bot/promote.js").PromotionHoldReconcile>;
|
|
667
671
|
};
|
|
672
|
+
/**
|
|
673
|
+
* `hq bot promote --company` takes the company's slug or uid. A uid is used as
|
|
674
|
+
* given (HQ refuses any company but the bot's own). A company bot's slug must
|
|
675
|
+
* be one of the bot's companies, so a typo or another company's slug is
|
|
676
|
+
* refused here, before any lookup; it is then resolved with the same lookup
|
|
677
|
+
* every other `--company <slug>` uses, which prefers the caller's own company.
|
|
678
|
+
*/
|
|
679
|
+
export declare function resolvePromoteCompany(token: string, ref: string, config: Pick<BotConfig, "name" | "kind" | "companies" | "workerId">): Promise<string>;
|
|
668
680
|
export declare function registerBotCommand(program: Command): void;
|
|
669
681
|
/**
|
|
670
682
|
* The company a bot's hot-signal-sync job syncs: the bot's own company, else
|
package/dist/commands/bot.js
CHANGED
|
@@ -44,6 +44,7 @@ import { heldBotThrottleDir, reconcileHeldBot } from "../lib/bot/promotion-hold-
|
|
|
44
44
|
*/
|
|
45
45
|
import { assertPromotedBotRemovable, cancelLocalBotPromotion, promoteLocalBot, promotionDetailsError, promotionFailureText, PROMOTION_CANCEL_TIMEOUT_MS } from "../lib/bot/promote.js";
|
|
46
46
|
import { describeFleetState } from "../lib/bot/fleet-state.js";
|
|
47
|
+
import { describePromotionSignIn, promotionSignIn, waitForPromotion } from "../lib/bot/promote-sign-in.js";
|
|
47
48
|
import { DecisionsClient } from "../lib/decisions/client.js";
|
|
48
49
|
import { releaseCurrentPackageUseLease, releasePackageUseLeaseAfterResidentPreload } from "../utils/package-use-lease.js";
|
|
49
50
|
import { preloadResidentPackageModules, reportResidentPackagePreloadFailure, runResidentCommandWithPackageLease, } from "../utils/resident-package-preload.js";
|
|
@@ -76,7 +77,7 @@ import { ensureOwnerToken } from "../utils/owner-session.js";
|
|
|
76
77
|
import { OutpostsClient } from "@indigoai-us/hq-cloud/outposts";
|
|
77
78
|
import { runBotCreateOnOutpost } from "../lib/bot/cloud-create.js";
|
|
78
79
|
import { peekHqApiKey } from "../utils/resolve-vault-credential.js";
|
|
79
|
-
import { getCompanyUid, resolveCallerPersonUid, vaultApiFetch } from "../utils/vault-api.js";
|
|
80
|
+
import { getCompanyUid, looksLikeCompanyUid, resolveCallerPersonUid, vaultApiFetch } from "../utils/vault-api.js";
|
|
80
81
|
import { askDaemonToStart, askDaemonToStop, daemonOwnsProcess, daemonHoldReason, daemonSupervises, daemonWillSupervise, handOffInstallHere, } from "../lib/daemon/handoff.js";
|
|
81
82
|
import { daemonPaths } from "../lib/daemon/paths.js";
|
|
82
83
|
import { launchdLabel } from "../lib/bot/paths.js";
|
|
@@ -88,7 +89,7 @@ import { clearPendingSwitch, recoverPendingSwitchSafely, writePendingSwitch } fr
|
|
|
88
89
|
import { classifyRuntimeFailure, isRuntimeUsageLimit, runtimeFailureReason, usageLimitResetsAt } from "../lib/bot/runtime-failure.js";
|
|
89
90
|
import { PROBE_DEFAULT_TIMEOUT_MS, probeBotRuntime } from "../lib/bot/probe.js";
|
|
90
91
|
import { BOT_LOGIN_RUNTIMES, botAuthEnv, botRuntimeAuth, capacityAccountHome, defaultSpawnBrowserSignIn, describeBotAuth, formatBotAuth, isBotLoginRuntime, restoreBotSessions, setAsideBotSessions, discardHeldBotLogin, holdPreviousBotLogin, restoreHeldBotLogin, signInBotRuntime, signOutBotRuntime, withRuntimeAuth, } from "../lib/bot/runtime-auth.js";
|
|
91
|
-
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, botRuntimeFromBrainName, 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, controlFleetBot as controlFleetLocalBot, ensureFleetBotDaemon, FleetDaemonStoppedError, fleetBotUnitId, fleetBotsManagedByDaemon, fleetLocalGatewayPid, fleetLocalProfileNeedsAdoption, fleetLocalServiceInstalled, fleetProviderForRuntime, importFleetLocalMachineCredential, importFleetLocalProviderLogin, fleetAuthUsesXaiOauthLogin, xaiOauthLoginHeldBack, xaiOauthLoginRefusal, fleetProviderNeedsSignIn, fleetOwnerCompanies, refreshFleetLocalInstructions, fleetLocalPromotionRuntime, installPinnedFleetLocalDistribution, installTargetFleetLocalDistribution, resolveFleetLocalPointerTarget, resolveFleetLocalTargetRelease, fleetLocalProfileDir, fleetProfileOwnerCompanies, fleetLocalChannels, readFleetLocalGatewayState, readFleetLocalIntroSentAt, readFleetLocalSignInNeeded, readPromptSources, removeFleetLocalBot, } from "../lib/bot/index.js";
|
|
92
|
+
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, botCompanySlug, normalizeBotCompanies, SETUP_BOT_WORKER_ID, isBotRuntimeId, botRuntimeFromBrainName, 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, controlFleetBot as controlFleetLocalBot, ensureFleetBotDaemon, FleetDaemonStoppedError, fleetBotUnitId, fleetBotsManagedByDaemon, fleetLocalGatewayPid, fleetLocalProfileNeedsAdoption, fleetLocalServiceInstalled, fleetProviderForRuntime, importFleetLocalMachineCredential, importFleetLocalProviderLogin, fleetAuthUsesXaiOauthLogin, xaiOauthLoginHeldBack, xaiOauthLoginRefusal, fleetProviderNeedsSignIn, fleetOwnerCompanies, refreshFleetLocalInstructions, fleetLocalPromotionRuntime, installPinnedFleetLocalDistribution, installTargetFleetLocalDistribution, resolveFleetLocalPointerTarget, resolveFleetLocalTargetRelease, fleetLocalProfileDir, fleetProfileOwnerCompanies, fleetLocalChannels, readFleetLocalGatewayState, readFleetLocalIntroSentAt, readFleetLocalSignInNeeded, readPromptSources, removeFleetLocalBot, } from "../lib/bot/index.js";
|
|
92
93
|
import { gatedInteractiveLogin } from "../utils/interactive-caller.js";
|
|
93
94
|
import { brainSignInStatus, fleetInstallProgressReporter, fleetRuntimeStatus, runBotAuthStatus, runBotRuntimeInstall, runBotRuntimeStatus, runBotSignIn } from "./bot-runtime.js";
|
|
94
95
|
import { ensureFleetRuntimeInstalled } from "../lib/bot/fleet-local.js";
|
|
@@ -174,6 +175,13 @@ function fleetBotSystemPrompt(name, config, overrides = {}) {
|
|
|
174
175
|
catch {
|
|
175
176
|
packSetup = null;
|
|
176
177
|
}
|
|
178
|
+
// A company bot made with --company has no companySlug in bot.json; its one
|
|
179
|
+
// membership is its company, the same bind its turns run under.
|
|
180
|
+
const companySlug = botCompanySlug({
|
|
181
|
+
...config,
|
|
182
|
+
...(overrides.kind ? { kind: overrides.kind } : {}),
|
|
183
|
+
...(overrides.companies ? { companies: overrides.companies } : {}),
|
|
184
|
+
});
|
|
177
185
|
const prompt = buildSystemPrompt({
|
|
178
186
|
packSetup,
|
|
179
187
|
botName: name,
|
|
@@ -184,7 +192,7 @@ function fleetBotSystemPrompt(name, config, overrides = {}) {
|
|
|
184
192
|
workerDir: config.workerDir,
|
|
185
193
|
workerSource: config.workerSource,
|
|
186
194
|
workerId: config.workerId,
|
|
187
|
-
companySlug
|
|
195
|
+
companySlug,
|
|
188
196
|
kind: overrides.kind ?? effectiveBotKind(config),
|
|
189
197
|
companies: overrides.companies ?? effectiveBotCompanies(config),
|
|
190
198
|
memoryDir: config.memoryDir,
|
|
@@ -192,7 +200,7 @@ function fleetBotSystemPrompt(name, config, overrides = {}) {
|
|
|
192
200
|
sources: readPromptSources(config.hqRoot, config.workerDir, undefined, {
|
|
193
201
|
memoryDir: config.memoryDir,
|
|
194
202
|
workerSource: config.workerSource,
|
|
195
|
-
companySlug
|
|
203
|
+
companySlug,
|
|
196
204
|
}),
|
|
197
205
|
});
|
|
198
206
|
const offer = pendingFleetSetupToolOffer(name, config);
|
|
@@ -797,7 +805,7 @@ function rowFor(name, opts = {}) {
|
|
|
797
805
|
workerSource: config.workerSource ?? "scaffold",
|
|
798
806
|
workerDir: config.workerDir,
|
|
799
807
|
...(config.workerId ? { workerId: config.workerId } : {}),
|
|
800
|
-
...(config
|
|
808
|
+
...(botCompanySlug(config) ? { companySlug: botCompanySlug(config) } : {}),
|
|
801
809
|
memory: botMemoryMode(config),
|
|
802
810
|
memoryDir: resolveBotMemoryDir(config),
|
|
803
811
|
...(config.displayName ? { displayName: config.displayName } : {}),
|
|
@@ -1982,8 +1990,15 @@ async function runBotCreateLocked(name, opts) {
|
|
|
1982
1990
|
}
|
|
1983
1991
|
}
|
|
1984
1992
|
// A worker-sourced bot never writes into the company tree: only its own
|
|
1985
|
-
// memory folder is scaffolded.
|
|
1986
|
-
|
|
1993
|
+
// memory folder is scaffolded. A company bot's own folder says it is a
|
|
1994
|
+
// company bot (of its one company), not its owner's personal bot.
|
|
1995
|
+
const scaffoldCompany = kind === "company" ? botCompanySlug(config) : undefined;
|
|
1996
|
+
const scaffoldOpts = {
|
|
1997
|
+
memoryDir: config.memoryDir,
|
|
1998
|
+
...(config.displayName ? { displayName: config.displayName } : {}),
|
|
1999
|
+
kind,
|
|
2000
|
+
...(scaffoldCompany ? { company: scaffoldCompany } : {}),
|
|
2001
|
+
};
|
|
1987
2002
|
const scaffold = worker
|
|
1988
2003
|
? scaffoldBotMemory(hqRoot, name, undefined, scaffoldOpts)
|
|
1989
2004
|
: scaffoldBotWorker(hqRoot, name, agentUid, HQ_FLEET_RUNTIME_ENGINE_ID, undefined, scaffoldOpts);
|
|
@@ -2081,7 +2096,7 @@ async function runBotCreateLocked(name, opts) {
|
|
|
2081
2096
|
dir,
|
|
2082
2097
|
worker: worker ? path.join(hqRoot, worker.path) : scaffold.dir,
|
|
2083
2098
|
workerId: worker?.id ?? null,
|
|
2084
|
-
companySlug:
|
|
2099
|
+
companySlug: botCompanySlug(config) ?? null,
|
|
2085
2100
|
memory: memoryMode,
|
|
2086
2101
|
memoryDir: scaffold.memoryDir,
|
|
2087
2102
|
displayName: displayName ?? null,
|
|
@@ -3919,7 +3934,14 @@ async function adoptRemoteBotLocked(input) {
|
|
|
3919
3934
|
if (fleetInstallation)
|
|
3920
3935
|
config.engine = fleetInstallation.engine;
|
|
3921
3936
|
writeBotConfig(dir, config);
|
|
3922
|
-
const
|
|
3937
|
+
const adoptedKind = effectiveBotKind(config);
|
|
3938
|
+
const adoptedCompany = adoptedKind === "company" ? botCompanySlug(config) : undefined;
|
|
3939
|
+
const scaffoldOpts = {
|
|
3940
|
+
memoryDir: config.memoryDir,
|
|
3941
|
+
...(config.displayName ? { displayName: config.displayName } : {}),
|
|
3942
|
+
kind: adoptedKind,
|
|
3943
|
+
...(adoptedCompany ? { company: adoptedCompany } : {}),
|
|
3944
|
+
};
|
|
3923
3945
|
const scaffold = config.workerSource === "worker"
|
|
3924
3946
|
? scaffoldBotMemory(input.hqRoot, name, undefined, scaffoldOpts)
|
|
3925
3947
|
: scaffoldBotWorker(input.hqRoot, name, bot.agentUid, config.runtime, undefined, scaffoldOpts);
|
|
@@ -4232,6 +4254,10 @@ async function runBotListRemote(opts) {
|
|
|
4232
4254
|
/** The bot's lifecycle seams for `hq bot promote`; tests replace them. */
|
|
4233
4255
|
export const botPromoteSeams = {
|
|
4234
4256
|
start: (name, dir, config) => startBot(name, dir, config, "silent"),
|
|
4257
|
+
/** A person is watching: the command keeps waiting for the move instead of returning at once. */
|
|
4258
|
+
attached: () => Boolean(process.stdout.isTTY && process.stdin.isTTY),
|
|
4259
|
+
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
4260
|
+
now: () => Date.now(),
|
|
4235
4261
|
/** `hq bot start` asks HQ every time; `hq bot run` shares the daemon's per-bot interval, so a restart loop does not hammer HQ. */
|
|
4236
4262
|
reconcileHold: (name, dir, config, command) => reconcileHeldBot(name, dir, config, command === "hq bot run"
|
|
4237
4263
|
? { command, lockWaitMs: 0, throttle: { dir: heldBotThrottleDir(daemonPaths().root) } }
|
|
@@ -4253,7 +4279,33 @@ async function releaseCancelledMove(name, dir, config, output, command) {
|
|
|
4253
4279
|
? `${name}: its move to the cloud was cancelled in HQ, so it is no longer held on this computer. Starting it.`
|
|
4254
4280
|
: `${name}: HQ has no move to the cloud for it, so it is no longer held on this computer. Starting it.`);
|
|
4255
4281
|
}
|
|
4256
|
-
/**
|
|
4282
|
+
/**
|
|
4283
|
+
* `hq bot promote --company` takes the company's slug or uid. A uid is used as
|
|
4284
|
+
* given (HQ refuses any company but the bot's own). A company bot's slug must
|
|
4285
|
+
* be one of the bot's companies, so a typo or another company's slug is
|
|
4286
|
+
* refused here, before any lookup; it is then resolved with the same lookup
|
|
4287
|
+
* every other `--company <slug>` uses, which prefers the caller's own company.
|
|
4288
|
+
*/
|
|
4289
|
+
export async function resolvePromoteCompany(token, ref, config) {
|
|
4290
|
+
const value = ref.trim();
|
|
4291
|
+
if (!value)
|
|
4292
|
+
throw Object.assign(new Error("--company needs the company's slug (e.g. indigo) or uid (cmp_...)."), { expected: true });
|
|
4293
|
+
if (looksLikeCompanyUid(value))
|
|
4294
|
+
return value;
|
|
4295
|
+
const own = effectiveBotCompanies(config);
|
|
4296
|
+
if (effectiveBotKind(config) === "company" && !own.includes(value)) {
|
|
4297
|
+
throw Object.assign(new Error(`${config.name} is a company bot of ${own.join(", ") || "no company"}, so it can only move into ${own.length === 1 ? "that company" : "one of them"}, not "${value}". Nothing was changed.`), { expected: true });
|
|
4298
|
+
}
|
|
4299
|
+
try {
|
|
4300
|
+
return await getCompanyUid(token, value);
|
|
4301
|
+
}
|
|
4302
|
+
catch (err) {
|
|
4303
|
+
if (err instanceof Error && err.name === "AuthError")
|
|
4304
|
+
throw err;
|
|
4305
|
+
throw Object.assign(new Error(`Cannot find company "${value}": ${err instanceof Error ? err.message : String(err)}. Pass the slug of a company you belong to, or its uid (cmp_...).`), { expected: true, cause: err });
|
|
4306
|
+
}
|
|
4307
|
+
}
|
|
4308
|
+
/** `hq bot promote <name> --company <slug|uid> --cancel`. */
|
|
4257
4309
|
async function runBotPromoteCancel(name, dir, config, api, opts) {
|
|
4258
4310
|
const result = await cancelLocalBotPromotion({
|
|
4259
4311
|
dir,
|
|
@@ -4331,53 +4383,83 @@ export function registerBotCommand(program) {
|
|
|
4331
4383
|
registerBotEventsCommand(bot, { requireBot });
|
|
4332
4384
|
bot.command("promote <name>")
|
|
4333
4385
|
.description("Move this local bot to cloud compute, preserving its identity and private context")
|
|
4334
|
-
.requiredOption("--company <
|
|
4386
|
+
.requiredOption("--company <company>", "The company the bot moves into: its slug (e.g. indigo) or uid (cmp_...)")
|
|
4335
4387
|
.option("--cancel", "Cancel the move: shut down the cloud copy and run the bot on this computer again")
|
|
4336
|
-
.option("--json", "Print promotion progress as JSON")
|
|
4388
|
+
.option("--json", "Print promotion progress as JSON, including the Codex sign-in the move waits for (signIn)")
|
|
4337
4389
|
.action((name, opts) => wrap(async () => {
|
|
4338
4390
|
const { dir, config } = requireBot(name);
|
|
4339
4391
|
const token = await ownerToken(false);
|
|
4340
|
-
const
|
|
4392
|
+
const companyUid = await resolvePromoteCompany(token, opts.company, config);
|
|
4393
|
+
const api = new BotApi({ token: () => ownerToken(false) }); // fresh on every call: an attached promote waits up to an hour
|
|
4341
4394
|
if (opts.cancel) {
|
|
4342
4395
|
const signedInPerson = () => resolveCallerPersonUid(token, undefined, { command: "hq bot promote --cancel" });
|
|
4343
|
-
await withBotLock(name, () => runBotPromoteCancel(name, dir, config, api, { company:
|
|
4396
|
+
await withBotLock(name, () => runBotPromoteCancel(name, dir, config, api, { company: companyUid, json: opts.json, signedInPerson }), { command: "hq bot promote --cancel" });
|
|
4344
4397
|
return;
|
|
4345
4398
|
}
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4399
|
+
let firstCheck = true;
|
|
4400
|
+
// One check on the move: resume it under the bot's lock, then read what it
|
|
4401
|
+
// waits for. A follow-up check only continues the first check's operation:
|
|
4402
|
+
// a move cancelled meanwhile is never started again unasked.
|
|
4403
|
+
const check = async (continueOperation) => {
|
|
4404
|
+
const showSnapshot = firstCheck && !opts.json;
|
|
4405
|
+
firstCheck = false;
|
|
4406
|
+
const result = await withBotLock(name, () => promoteLocalBot({
|
|
4407
|
+
dir,
|
|
4408
|
+
config,
|
|
4409
|
+
companyUid,
|
|
4410
|
+
api,
|
|
4411
|
+
...(continueOperation ? { continueOperation } : {}),
|
|
4412
|
+
isRunning: () => readBotListedProcess(dir, config).running,
|
|
4413
|
+
restart: () => botPromoteSeams.start(name, dir, config),
|
|
4414
|
+
...(isFleetRuntimeBot(config) ? { runtime: fleetLocalPromotionRuntime(config.agentUid) } : {}),
|
|
4415
|
+
onSnapshot: (fleetState) => {
|
|
4416
|
+
if (fleetState && showSnapshot)
|
|
4417
|
+
for (const line of describeFleetState(fleetState))
|
|
4418
|
+
console.log(line);
|
|
4419
|
+
},
|
|
4420
|
+
}), { command: "hq bot promote" });
|
|
4421
|
+
let details = null;
|
|
4422
|
+
let detailsError = null;
|
|
4423
|
+
if (result.pending) {
|
|
4424
|
+
try {
|
|
4425
|
+
details = await api.promotionDetails(config.agentUid, companyUid);
|
|
4426
|
+
}
|
|
4427
|
+
catch (err) {
|
|
4428
|
+
detailsError = `${promotionDetailsError(dir, err)}, so the details of the move could not be read`;
|
|
4429
|
+
}
|
|
4368
4430
|
}
|
|
4431
|
+
const failure = details?.failure ? promotionFailureText(dir, config, companyUid, details.failure, details.failureCode) : null;
|
|
4432
|
+
return { result, pairing: details?.pairing ?? null, failure, detailsError };
|
|
4433
|
+
};
|
|
4434
|
+
const first = await check();
|
|
4435
|
+
const { result, pairing, failure, detailsError } = first;
|
|
4436
|
+
const signIn = failure || detailsError ? null : promotionSignIn(result, pairing, botPromoteSeams.now());
|
|
4437
|
+
if (opts.json) {
|
|
4438
|
+
// An expired code is not passed on as `pairing` either.
|
|
4439
|
+
const livePairing = signIn && signIn.status !== "code-ready" ? null : pairing;
|
|
4440
|
+
console.log(JSON.stringify({ ...result, pairing: livePairing, signIn, ...(failure ? { failure } : {}), ...(detailsError ? { detailsError } : {}) }));
|
|
4441
|
+
return;
|
|
4369
4442
|
}
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
else if (failure)
|
|
4443
|
+
// Attached to a terminal, the command waits for the move (and its sign-in) to finish.
|
|
4444
|
+
const attached = botPromoteSeams.attached() && result.pending && !failure;
|
|
4445
|
+
if (failure)
|
|
4374
4446
|
console.log(`${name}: ${failure}`);
|
|
4375
4447
|
else if (detailsError)
|
|
4376
|
-
console.log(`${name}: ${result.promotion.phase}. ${detailsError}. Run the same command to continue promotion
|
|
4377
|
-
else if (
|
|
4378
|
-
|
|
4448
|
+
console.log(`${name}: ${result.promotion.phase}. ${detailsError}. ${attached ? "Checking again." : "Run the same command to continue promotion."}`);
|
|
4449
|
+
else if (signIn)
|
|
4450
|
+
for (const line of describePromotionSignIn(name, signIn, botPromoteSeams.now(), attached))
|
|
4451
|
+
console.log(line);
|
|
4379
4452
|
else
|
|
4380
|
-
console.log(`${name}: ${result.promotion.phase}.${result.pending ? " Run the same command to continue promotion." : ""}`);
|
|
4453
|
+
console.log(`${name}: ${result.promotion.phase}.${result.pending ? (attached ? " Waiting for the move to finish." : " Run the same command to continue promotion.") : ""}`);
|
|
4454
|
+
if (!attached)
|
|
4455
|
+
return;
|
|
4456
|
+
const operationId = result.promotion.operationId;
|
|
4457
|
+
await waitForPromotion(name, first, {
|
|
4458
|
+
check: () => check(operationId),
|
|
4459
|
+
sleep: botPromoteSeams.sleep,
|
|
4460
|
+
now: botPromoteSeams.now,
|
|
4461
|
+
print: (line) => console.log(line),
|
|
4462
|
+
});
|
|
4381
4463
|
})());
|
|
4382
4464
|
bot
|
|
4383
4465
|
.command("create <name>")
|