@indigoai-us/hq-cli 5.345.237 → 5.345.238

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 CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [5.345.238] — 2026-11-19
6
+ - Publish the warm CLI test fixture atomically before executing it on Unix.
7
+ - Internal: The hq-hook PR test shards run under cargo-nextest, one process per test across all cores.
8
+ - Record native UserPromptSubmit master coverage on Unix for Claude, Codex and Grok.
9
+ - Preserve pending inbox acknowledgements when their state file cannot be read or parsed.
10
+ - A local bot held for a move to the cloud now frees itself when HQ shows that move was cancelled (or has no move for it and its owner is signed in). `hq daemon` checks each held bot at most every 15 minutes and starts it again: a bot the daemon runs if it was running before the move, and an HQ Fleet bot on macOS. On Linux an HQ Fleet bot is freed but needs `hq bot start`. `hq bot run` checks within the same 15-minute limit, and `hq bot start` checks once before refusing. A bot that moved to the cloud, or whose move is still in progress, stays held.
11
+ - Host canaries can snapshot the working HQ scaffold and bind results to the installed policy gate.
12
+
5
13
  ## [5.345.237] — 2026-11-19
6
14
  - Declare the tests for the Unicode credential and released secrets guard replay differences.
7
15
  - Declare the existing tests for five dispatcher replay differences.
@@ -662,6 +662,8 @@ export declare const botPromoteSeams: {
662
662
  running: boolean;
663
663
  how: string;
664
664
  }>;
665
+ /** `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
+ reconcileHold: (name: string, dir: string, config: BotConfig, command: "hq bot start" | "hq bot run") => Promise<import("../lib/bot/promote.js").PromotionHoldReconcile>;
665
667
  };
666
668
  export declare function registerBotCommand(program: Command): void;
667
669
  /**
@@ -18,6 +18,7 @@ import { OwnerContextCache, lookupOwnerContext } from "../lib/bot/owner-context.
18
18
  import { hasActivePromotion, localPromotionState } from "../lib/bot/promotion-receipt.js";
19
19
  import { botBusyState, readInflightTurns } from "../lib/bot/inflight.js";
20
20
  import { hasPromotionHold, promotionHoldSummary } from "../lib/bot/promotion-hold.js";
21
+ import { heldBotThrottleDir, reconcileHeldBot } from "../lib/bot/promotion-hold-reconcile.js";
21
22
  /**
22
23
  * `hq bot` — personal local bots (local-bots US-003/US-004/US-005).
23
24
  *
@@ -2254,6 +2255,7 @@ async function runBotResident(nameArg) {
2254
2255
  console.log(orphanBotRunMessage(name, outcome));
2255
2256
  return;
2256
2257
  }
2258
+ await releaseCancelledMove(name, dir, config, "text", "hq bot run");
2257
2259
  if ((await convertLegacyBotToFleet(name, dir, config, "run")).fleet)
2258
2260
  return;
2259
2261
  if (healNodePathFromJob(name, dir, config))
@@ -4230,7 +4232,27 @@ async function runBotListRemote(opts) {
4230
4232
  /** The bot's lifecycle seams for `hq bot promote`; tests replace them. */
4231
4233
  export const botPromoteSeams = {
4232
4234
  start: (name, dir, config) => startBot(name, dir, config, "silent"),
4235
+ /** `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
+ reconcileHold: (name, dir, config, command) => reconcileHeldBot(name, dir, config, command === "hq bot run"
4237
+ ? { command, lockWaitMs: 0, throttle: { dir: heldBotThrottleDir(daemonPaths().root) } }
4238
+ : { command, lockWaitMs: 15_000, onWait: () => console.error(chalk.dim(`${name}: waiting for another hq command working on this bot...`)) }),
4233
4239
  };
4240
+ /** Before a start refuses a held bot: free it when HQ shows its move cancelled. */
4241
+ async function releaseCancelledMove(name, dir, config, output, command) {
4242
+ try {
4243
+ if (!hasPromotionHold(dir))
4244
+ return;
4245
+ }
4246
+ catch {
4247
+ return;
4248
+ }
4249
+ const result = await botPromoteSeams.reconcileHold(name, dir, config, command);
4250
+ if (result.outcome !== "released" || output !== "text")
4251
+ return;
4252
+ console.log(result.reason === "cancelled"
4253
+ ? `${name}: its move to the cloud was cancelled in HQ, so it is no longer held on this computer. Starting it.`
4254
+ : `${name}: HQ has no move to the cloud for it, so it is no longer held on this computer. Starting it.`);
4255
+ }
4234
4256
  /** `hq bot promote <name> --company <uid> --cancel`. */
4235
4257
  async function runBotPromoteCancel(name, dir, config, api, opts) {
4236
4258
  const result = await cancelLocalBotPromotion({
@@ -4422,6 +4444,7 @@ export function registerBotCommand(program) {
4422
4444
  .option("--json", "Print machine-readable JSON")
4423
4445
  .action((name, opts) => wrap(async () => {
4424
4446
  const b = requireBot(name);
4447
+ await releaseCancelledMove(b.name, b.dir, b.config, opts.json ? "json" : "text", "hq bot start");
4425
4448
  if (isFleetRuntimeBot(b.config)) {
4426
4449
  refuseHeldFleetBot(b.dir);
4427
4450
  const adopted = await adoptFleetRuntimeProfile(b.name, b.dir, b.config, { progress: fleetInstallProgressReporter(opts.json ? "silent" : "text") });
@@ -43,7 +43,8 @@ export declare function readDoneIds(paths: Pick<AgentKitPaths, "inboxDir">): Set
43
43
  export declare function markInboxDone(paths: Pick<AgentKitPaths, "inboxDir">, ids: string[]): string[];
44
44
  /**
45
45
  * Ids marked handled by the bot whose server ack is not confirmed yet, oldest
46
- * first. A missing or unreadable file is an empty list.
46
+ * first. Listing reads treat a missing or unreadable file as an empty list;
47
+ * addAckPending and confirmInboxAck use the strict reader below.
47
48
  */
48
49
  export declare function readAckPending(paths: Pick<AgentKitPaths, "inboxDir">): string[];
49
50
  /** Record ids as awaiting a server ack. Call before the ack is sent. */
@@ -92,7 +92,8 @@ function markInboxDoneUnlocked(paths, ids) {
92
92
  }
93
93
  /**
94
94
  * Ids marked handled by the bot whose server ack is not confirmed yet, oldest
95
- * first. A missing or unreadable file is an empty list.
95
+ * first. Listing reads treat a missing or unreadable file as an empty list;
96
+ * addAckPending and confirmInboxAck use the strict reader below.
96
97
  */
97
98
  export function readAckPending(paths) {
98
99
  try {
@@ -103,13 +104,36 @@ export function readAckPending(paths) {
103
104
  return [];
104
105
  }
105
106
  }
107
+ /** A failed read must not turn an existing pending list into an empty write. */
108
+ function readAckPendingStrict(paths) {
109
+ let text;
110
+ try {
111
+ text = fs.readFileSync(path.join(paths.inboxDir, ACK_PENDING_NAME), "utf8");
112
+ }
113
+ catch (err) {
114
+ if (err.code === "ENOENT")
115
+ return [];
116
+ throw new Error("Pending inbox acknowledgements could not be read; existing state was not changed.", { cause: err });
117
+ }
118
+ let raw;
119
+ try {
120
+ raw = JSON.parse(text);
121
+ }
122
+ catch {
123
+ throw new Error("Pending inbox acknowledgements are not valid JSON; existing state was not changed.");
124
+ }
125
+ if (!Array.isArray(raw) || raw.some((id) => typeof id !== "string")) {
126
+ throw new Error("Pending inbox acknowledgements must be an array of IDs; existing state was not changed.");
127
+ }
128
+ return [...new Set(raw)];
129
+ }
106
130
  function writeAckPending(paths, ids) {
107
131
  writePrivateFile(path.join(paths.inboxDir, ACK_PENDING_NAME), JSON.stringify(ids.slice(-MAX_ACK_PENDING_IDS)), 0o600);
108
132
  }
109
133
  /** Record ids as awaiting a server ack. Call before the ack is sent. */
110
134
  export function addAckPending(paths, ids) {
111
135
  withStateLock(paths, () => {
112
- const current = readAckPending(paths);
136
+ const current = readAckPendingStrict(paths);
113
137
  const have = new Set(current);
114
138
  const next = [...current];
115
139
  for (const id of ids) {
@@ -129,8 +153,8 @@ export function addAckPending(paths, ids) {
129
153
  */
130
154
  export function confirmInboxAck(paths, id) {
131
155
  return withStateLock(paths, () => {
156
+ const current = readAckPendingStrict(paths);
132
157
  const added = markInboxDoneUnlocked(paths, [id]).length > 0;
133
- const current = readAckPending(paths);
134
158
  if (current.includes(id))
135
159
  writeAckPending(paths, current.filter((x) => x !== id));
136
160
  return added;
@@ -71,6 +71,29 @@ export declare function promoteLocalBot(input: {
71
71
  pending: boolean;
72
72
  fleetState?: FleetStateManifest | null;
73
73
  }>;
74
+ export type PromotionHoldReconcile = {
75
+ outcome: "none";
76
+ } | {
77
+ outcome: "kept";
78
+ reason: string;
79
+ } | {
80
+ outcome: "released";
81
+ reason: "cancelled" | "not-found";
82
+ companyUid: string;
83
+ wasRunning: boolean | null;
84
+ };
85
+ /** A held bot whose move HQ has since dropped frees itself, by the proof rules
86
+ * of cancelLocalBotPromotion: HQ shows this hold's own operation cancelled, or
87
+ * HQ has no move for the bot and its owner is the one signed in. A bot with an
88
+ * active-promotion receipt, a damaged hold, an in-flight or different move, or
89
+ * any failed read stays held. Never cancels anything on the server.
90
+ */
91
+ export declare function reconcilePromotionHold(input: {
92
+ dir: string;
93
+ config: BotConfig;
94
+ api: BotApi;
95
+ signedInPerson?: SignedInPerson;
96
+ }): Promise<PromotionHoldReconcile>;
74
97
  export type PromotionCancelOutcome = "canceled" | "pending" | "active" | "not-found";
75
98
  export interface PromotionCancelResult {
76
99
  outcome: PromotionCancelOutcome;
@@ -463,6 +463,79 @@ async function serverMayKnow(api, config, companyUid, operationId) {
463
463
  return true;
464
464
  }
465
465
  }
466
+ function hasReceiptFile(dir) {
467
+ try {
468
+ fs.lstatSync(path.join(dir, "promotion-active.json"));
469
+ return true;
470
+ }
471
+ catch {
472
+ return false;
473
+ }
474
+ }
475
+ /** A held bot whose move HQ has since dropped frees itself, by the proof rules
476
+ * of cancelLocalBotPromotion: HQ shows this hold's own operation cancelled, or
477
+ * HQ has no move for the bot and its owner is the one signed in. A bot with an
478
+ * active-promotion receipt, a damaged hold, an in-flight or different move, or
479
+ * any failed read stays held. Never cancels anything on the server.
480
+ */
481
+ export async function reconcilePromotionHold(input) {
482
+ const { dir, config, api } = input;
483
+ if (!hasPromotionHold(dir))
484
+ return { outcome: "none" };
485
+ if (hasReceiptFile(dir))
486
+ return { outcome: "kept", reason: "the bot moved to the cloud" };
487
+ const read = readLocalHold(dir, config);
488
+ if (!read.hold)
489
+ return { outcome: "kept", reason: `the hold cannot be used: ${read.unreadable ?? "it is missing"}` };
490
+ const companyUid = read.hold.companyUid;
491
+ const operationId = read.hold.operationId;
492
+ let state;
493
+ try {
494
+ state = await readPromotionStatusRaw(api, config, companyUid);
495
+ }
496
+ catch (error) {
497
+ if (error instanceof BotApiError)
498
+ logRaw(dir, error);
499
+ else
500
+ appendBotLog(dir, botLogLine("warn", `promotion: status check failed: ${sentence(error)}`));
501
+ if (!(error instanceof BotApiError && error.status === 404 && error.code === "PROMOTION_NOT_FOUND"))
502
+ return { outcome: "kept", reason: "HQ did not show the move" };
503
+ state = null;
504
+ }
505
+ let why;
506
+ if (state === null) {
507
+ if (!await signedInAsOwner(input))
508
+ return { outcome: "kept", reason: "only the bot's owner can confirm HQ has no move" };
509
+ why = "not-found";
510
+ }
511
+ else if (state.operationId !== operationId) {
512
+ return { outcome: "kept", reason: "HQ shows a different move" };
513
+ }
514
+ else if (state.phase === "active") {
515
+ // The bot is live in the cloud; record it so nothing asks HQ about this hold again.
516
+ try {
517
+ recordActivePromotion(dir, { agentUid: config.agentUid, ownerUid: config.ownerUid, companyUid, operationId }, state);
518
+ }
519
+ catch (error) {
520
+ appendBotLog(dir, botLogLine("warn", `promotion: could not record the cloud move: ${sentence(error)}`));
521
+ }
522
+ return { outcome: "kept", reason: "the bot moved to the cloud" };
523
+ }
524
+ else if (state.phase !== "cancelled") {
525
+ return { outcome: "kept", reason: `the move is ${state.phase}` };
526
+ }
527
+ else
528
+ why = "cancelled";
529
+ const again = readLocalHold(dir, config);
530
+ if (again.hold?.operationId !== operationId || again.hold.companyUid !== companyUid || hasReceiptFile(dir))
531
+ return { outcome: "kept", reason: "the hold changed" };
532
+ const wasRunning = readPromotionHoldOrigin(dir, operationId);
533
+ releaseLocalPromotion(dir);
534
+ appendBotLog(dir, botLogLine("info", why === "cancelled"
535
+ ? `promotion: HQ shows the move ${operationId} to company ${companyUid} cancelled; released the hold on this computer`
536
+ : `promotion: HQ has no move to company ${companyUid} for this bot; released the hold on this computer`));
537
+ return { outcome: "released", reason: why, companyUid, wasRunning };
538
+ }
466
539
  export const PROMOTION_CANCEL_POLL_MS = 5_000;
467
540
  /** Below the bot lock's stale age, so no other command can take the lock mid-cancel. */
468
541
  export const PROMOTION_CANCEL_TIMEOUT_MS = 8 * 60_000;
@@ -0,0 +1,56 @@
1
+ import { BotApi } from "./api.js";
2
+ import { type BotConfig } from "./config.js";
3
+ import { type PromotionHoldReconcile, type SignedInPerson } from "./promote.js";
4
+ export interface PromotionAccess {
5
+ api: BotApi;
6
+ signedInPerson: SignedInPerson;
7
+ }
8
+ /** The signed-in owner's HQ access, without ever opening a browser sign-in. */
9
+ export declare function ownerPromotionAccess(command: string): PromotionAccess;
10
+ /** How often the daemon and `hq bot run` ask HQ about one held bot. */
11
+ export declare const HELD_BOT_RECONCILE_INTERVAL_MS: number;
12
+ /** Per-bot record of the last HQ check, shared by every process on this
13
+ * computer (a restarting daemon, each `hq bot run`). Written before the check
14
+ * starts, so a check in flight counts as a recent one.
15
+ */
16
+ /** Where the per-bot check records live, under the daemon's own folder. */
17
+ export declare const heldBotThrottleDir: (daemonRoot: string) => string;
18
+ export interface ReconcileThrottle {
19
+ dir: string;
20
+ intervalMs?: number;
21
+ now?: () => number;
22
+ }
23
+ /** Claims this bot's next HQ check: false while a check is in flight or ran within the interval. */
24
+ export declare function claimHeldBotCheck(throttle: ReconcileThrottle, name: string): boolean;
25
+ /** reconcilePromotionHold under the bot's lock. A busy lock, a signed-out owner
26
+ * or any other failure keeps the hold. With a throttle, a bot checked recently
27
+ * (or being checked now) is skipped without asking HQ.
28
+ */
29
+ export declare function reconcileHeldBot(name: string, dir: string, config: BotConfig, opts: {
30
+ command: string;
31
+ access?: PromotionAccess;
32
+ lockWaitMs?: number;
33
+ root?: string;
34
+ throttle?: ReconcileThrottle;
35
+ onWait?: () => void;
36
+ }): Promise<PromotionHoldReconcile>;
37
+ export interface HeldBot {
38
+ name: string;
39
+ dir: string;
40
+ config: BotConfig;
41
+ }
42
+ /** The daemon's self-heal for held bots: one pass at a time, and at most one
43
+ * HQ check per bot per interval across daemon restarts. A released bot's
44
+ * daemon unit is asked to start.
45
+ */
46
+ export declare function createHeldBotReconciler(deps: {
47
+ root?: string;
48
+ platform?: NodeJS.Platform;
49
+ throttle: ReconcileThrottle;
50
+ reconcile?: (bot: HeldBot) => Promise<PromotionHoldReconcile>;
51
+ requestStart: (unitId: string) => void;
52
+ log: (level: "info" | "warn", message: string) => void;
53
+ }): {
54
+ kick(): Promise<void>;
55
+ };
56
+ //# sourceMappingURL=promotion-hold-reconcile.d.ts.map
@@ -0,0 +1,155 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ import { randomUUID } from "node:crypto";
4
+ import { ensureOwnerToken } from "../../utils/owner-session.js";
5
+ import { resolveCallerPersonUid } from "../../utils/vault-api.js";
6
+ import { BotApi } from "./api.js";
7
+ import { HQ_FLEET_RUNTIME_ENGINE_ID, readBotConfig } from "./config.js";
8
+ import { withBotLock } from "./lock.js";
9
+ import { botsRoot } from "./paths.js";
10
+ import { reconcilePromotionHold } from "./promote.js";
11
+ import { hasPromotionHold } from "./promotion-hold.js";
12
+ /** The signed-in owner's HQ access, without ever opening a browser sign-in. */
13
+ export function ownerPromotionAccess(command) {
14
+ const token = () => ensureOwnerToken({ interactive: false });
15
+ return { api: new BotApi({ token }), signedInPerson: async () => resolveCallerPersonUid(await token(), undefined, { command }) };
16
+ }
17
+ /** How often the daemon and `hq bot run` ask HQ about one held bot. */
18
+ export const HELD_BOT_RECONCILE_INTERVAL_MS = 15 * 60_000;
19
+ /** Per-bot record of the last HQ check, shared by every process on this
20
+ * computer (a restarting daemon, each `hq bot run`). Written before the check
21
+ * starts, so a check in flight counts as a recent one.
22
+ */
23
+ /** Where the per-bot check records live, under the daemon's own folder. */
24
+ export const heldBotThrottleDir = (daemonRoot) => path.join(daemonRoot, "promotion-reconcile");
25
+ const throttleFile = (throttle, name) => path.join(throttle.dir, `${name}.json`);
26
+ /** Claims this bot's next HQ check: false while a check is in flight or ran within the interval. */
27
+ export function claimHeldBotCheck(throttle, name) {
28
+ const now = (throttle.now ?? Date.now)();
29
+ const file = throttleFile(throttle, name);
30
+ try {
31
+ const last = JSON.parse(fs.readFileSync(file, "utf8"));
32
+ if (typeof last.startedAt === "number" && last.startedAt <= now && now - last.startedAt < (throttle.intervalMs ?? HELD_BOT_RECONCILE_INTERVAL_MS))
33
+ return false;
34
+ }
35
+ catch { /* none yet, or unreadable: check now */ }
36
+ writeThrottle(file, { startedAt: now, inFlight: true, pid: process.pid });
37
+ return true;
38
+ }
39
+ function finishHeldBotCheck(throttle, name, result) {
40
+ const file = throttleFile(throttle, name);
41
+ if (result.outcome === "released" || result.outcome === "none") {
42
+ fs.rmSync(file, { force: true });
43
+ return;
44
+ }
45
+ try {
46
+ const last = JSON.parse(fs.readFileSync(file, "utf8"));
47
+ writeThrottle(file, { ...last, inFlight: false, finishedAt: (throttle.now ?? Date.now)() });
48
+ }
49
+ catch { /* the claim stays as written */ }
50
+ }
51
+ function writeThrottle(file, value) {
52
+ fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
53
+ const temp = `${file}.${randomUUID()}.tmp`;
54
+ fs.writeFileSync(temp, JSON.stringify(value), { mode: 0o600 });
55
+ fs.renameSync(temp, file);
56
+ }
57
+ /** reconcilePromotionHold under the bot's lock. A busy lock, a signed-out owner
58
+ * or any other failure keeps the hold. With a throttle, a bot checked recently
59
+ * (or being checked now) is skipped without asking HQ.
60
+ */
61
+ export async function reconcileHeldBot(name, dir, config, opts) {
62
+ let claimed = false;
63
+ let result;
64
+ try {
65
+ if (!hasPromotionHold(dir))
66
+ return { outcome: "none" };
67
+ if (opts.throttle) {
68
+ if (!claimHeldBotCheck(opts.throttle, name))
69
+ return { outcome: "kept", reason: "HQ was asked recently" };
70
+ claimed = true;
71
+ }
72
+ const access = opts.access ?? ownerPromotionAccess(opts.command);
73
+ result = await withBotLock(name, () => reconcilePromotionHold({ dir, config, ...access }), {
74
+ command: opts.command,
75
+ ...(opts.lockWaitMs !== undefined ? { waitMs: opts.lockWaitMs } : {}),
76
+ ...(opts.root ? { root: opts.root } : {}),
77
+ ...(opts.onWait ? { onWait: opts.onWait } : {}),
78
+ });
79
+ }
80
+ catch (error) {
81
+ result = { outcome: "kept", reason: error instanceof Error ? error.message : String(error) };
82
+ }
83
+ if (claimed) {
84
+ try {
85
+ finishHeldBotCheck(opts.throttle, name, result);
86
+ }
87
+ catch { /* the claim stays as written */ }
88
+ }
89
+ return result;
90
+ }
91
+ /** The daemon's self-heal for held bots: one pass at a time, and at most one
92
+ * HQ check per bot per interval across daemon restarts. A released bot's
93
+ * daemon unit is asked to start.
94
+ */
95
+ export function createHeldBotReconciler(deps) {
96
+ const root = deps.root ?? botsRoot();
97
+ const platform = deps.platform ?? process.platform;
98
+ const reconcile = deps.reconcile ?? ((bot) => reconcileHeldBot(bot.name, bot.dir, bot.config, { command: "hq daemon", lockWaitMs: 0, root }));
99
+ let running = null;
100
+ const held = () => {
101
+ let names;
102
+ try {
103
+ names = fs.readdirSync(root, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name).sort();
104
+ }
105
+ catch {
106
+ return [];
107
+ }
108
+ const bots = [];
109
+ for (const name of names) {
110
+ const dir = path.join(root, name);
111
+ try {
112
+ if (!hasPromotionHold(dir) || fs.existsSync(path.join(dir, "promotion-active.json")))
113
+ continue;
114
+ const config = readBotConfig(dir);
115
+ if (config)
116
+ bots.push({ name, dir, config });
117
+ }
118
+ catch { /* unreadable: stays held */ }
119
+ }
120
+ return bots;
121
+ };
122
+ const pass = async () => {
123
+ for (const bot of held()) {
124
+ if (!claimHeldBotCheck(deps.throttle, bot.name))
125
+ continue;
126
+ const result = await reconcile(bot).catch((error) => ({ outcome: "kept", reason: error instanceof Error ? error.message : String(error) }));
127
+ try {
128
+ finishHeldBotCheck(deps.throttle, bot.name, result);
129
+ }
130
+ catch { /* the claim stays as written */ }
131
+ if (result.outcome !== "released")
132
+ continue;
133
+ const fleet = bot.config.engine?.id === HQ_FLEET_RUNTIME_ENGINE_ID;
134
+ const unit = fleet ? (platform === "darwin" ? `fleet-bots:${bot.name}` : null) : `bots:${bot.name}`;
135
+ const start = unit !== null && (fleet || result.wasRunning !== false);
136
+ const why = result.reason === "cancelled" ? "HQ shows its move to the cloud was cancelled" : "HQ has no move to the cloud for it";
137
+ deps.log("info", `${bot.name}: ${why}; released its hold${start ? " and starting it" : `; start it with: hq bot start ${bot.name}`}`);
138
+ if (start) {
139
+ try {
140
+ deps.requestStart(unit);
141
+ }
142
+ catch (error) {
143
+ deps.log("warn", `${bot.name}: could not ask the daemon to start it: ${error instanceof Error ? error.message : String(error)}`);
144
+ }
145
+ }
146
+ }
147
+ };
148
+ return {
149
+ kick() {
150
+ running ??= pass().catch(() => undefined).finally(() => { running = null; });
151
+ return running;
152
+ },
153
+ };
154
+ }
155
+ //# sourceMappingURL=promotion-hold-reconcile.js.map
@@ -6,7 +6,8 @@
6
6
  * signing in takes effect without restarting the daemon.
7
7
  */
8
8
  import { acquirePackageUseLease } from "../../utils/package-use-lease.js";
9
- import { type LegacySyncHolder, type PlanContext, type ServiceName, type UnitPlan } from "./catalog.js";
9
+ import { type PlanFleetBotsDeps } from "../bot/fleet-daemon.js";
10
+ import { type FleetBotPlan, type LegacySyncHolder, type PlanContext, type ServiceName, type UnitPlan } from "./catalog.js";
10
11
  import { type LegacyHandover } from "./legacy-handover.js";
11
12
  import { type SyncCoreVaultPlan } from "../sync-core/engine-home.js";
12
13
  import { type DaemonFlagRegistryRead, type DaemonFlagSnapshotSource } from "./flag.js";
@@ -143,6 +144,21 @@ export declare function daemonInstantSyncEnabled(env: NodeJS.ProcessEnv, configu
143
144
  * background service, so it is not one of them.
144
145
  */
145
146
  export declare function listLocalBots(root?: string): string[];
147
+ /** The plan's bots. A signed-in pass also lets held bots whose move HQ cancelled
148
+ * free themselves, in the background and rate-limited per bot.
149
+ */
150
+ export declare function daemonBotPlans(input: {
151
+ heldBots: {
152
+ kick(): Promise<void>;
153
+ };
154
+ signedIn: boolean;
155
+ services: readonly ServiceName[];
156
+ fleet: PlanFleetBotsDeps;
157
+ root?: string;
158
+ }): {
159
+ bots: string[];
160
+ fleetBots: FleetBotPlan[];
161
+ };
146
162
  /** Whose task `taskName` is: only the current user's own task may be taken over. */
147
163
  export declare function windowsTaskOwner(taskName: string): WindowsTaskOwner;
148
164
  export declare function probeLegacyUnits(platform: NodeJS.Platform, home: string): LegacyUnit[];
@@ -23,6 +23,7 @@ import { isLocalDependencyInstall, resolveRunningInstall } from "../../utils/ver
23
23
  import { agentKitPaths } from "../agent-kit/paths.js";
24
24
  import { HQ_FLEET_RUNTIME_ENGINE_ID, readBotConfig } from "../bot/config.js";
25
25
  import { clearStaleReadyBeforeGatewayStart, planFleetBots } from "../bot/fleet-daemon.js";
26
+ import { createHeldBotReconciler, heldBotThrottleDir } from "../bot/promotion-hold-reconcile.js";
26
27
  import { botsRoot } from "../bot/paths.js";
27
28
  import { CLAUDE_RUNNER_SCRIPT, CODEX_RUNNER_SCRIPT, enabledServices, planUnits, SEARCH_INDEX_WORKER_UNAVAILABLE, isLegacyRestartWait } from "./catalog.js";
28
29
  import { createLegacyHandover, LEGACY_HANDOVER_STUCK_FILE, writeLegacyHandoverStuck } from "./legacy-handover.js";
@@ -70,7 +71,7 @@ import { createHqdRuntimeEvents, observeHqdRuntimeFlag, startHqdRuntimeListener
70
71
  import { heartbeatFile, startHeartbeat } from "./heartbeat.js";
71
72
  import { daemonStartEnv } from "./hook-env.js";
72
73
  import { createProtocolTail, ensureProtocolFifo, openProtocolWriter } from "./protocol-tail.js";
73
- import { takeControlRequests } from "./requests.js";
74
+ import { takeControlRequests, writeControlRequest } from "./requests.js";
74
75
  import { currentHqCloud, currentHqCloudAfterLeaseRelease, hqCloudRunners, hqCloudVersionOlder } from "./hq-cloud.js";
75
76
  import { stageSyncRunnerBundle } from "./sync-runner-bundle.js";
76
77
  import { stageHqChildBootstrap } from "./hq-child-bootstrap-stage.js";
@@ -553,6 +554,14 @@ export function listLocalBots(root = botsRoot()) {
553
554
  .map((d) => d.name)
554
555
  .sort();
555
556
  }
557
+ /** The plan's bots. A signed-in pass also lets held bots whose move HQ cancelled
558
+ * free themselves, in the background and rate-limited per bot.
559
+ */
560
+ export function daemonBotPlans(input) {
561
+ if (input.signedIn && input.services.includes("bots"))
562
+ void input.heldBots.kick();
563
+ return { bots: listLocalBots(input.root), fleetBots: planFleetBots(input.fleet) };
564
+ }
556
565
  /** Whose task `taskName` is: only the current user's own task may be taken over. */
557
566
  export function windowsTaskOwner(taskName) {
558
567
  const run = (cmd, args) => {
@@ -863,6 +872,13 @@ export async function runDaemon(opts) {
863
872
  const paths = daemonPaths(home, env);
864
873
  ensurePrivateDir(paths.syncPassRequestsDir);
865
874
  const log = makeLogger(paths, opts.foreground === true);
875
+ const heldBots = createHeldBotReconciler({
876
+ root: botsRoot(home, env),
877
+ platform,
878
+ throttle: { dir: heldBotThrottleDir(paths.root) },
879
+ requestStart: (unit) => { writeControlRequest(paths.requestsDir, { action: "restart", unit }); },
880
+ log,
881
+ });
866
882
  const syncRunnerBundleDirectory = opts.syncRunnerBundleDirectory ?? path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../hq-cloud-sync-runner");
867
883
  const cliPackageRoot = opts.cliPackageRoot === undefined ? resolveRunningInstall().packageRoot : opts.cliPackageRoot;
868
884
  const cliPackagePrefix = opts.cliPackagePrefix === undefined
@@ -1616,8 +1632,12 @@ export async function runDaemon(opts) {
1616
1632
  syncOwner === "daemon" && services.includes("sync") && !config.syncPaused &&
1617
1633
  !appManagesSync && Boolean(hqRoot && isSignedIn && runners.syncRunner),
1618
1634
  syncHeartbeatTimeoutMs: syncHeartbeatTimeoutMs(env),
1619
- bots: listLocalBots(),
1620
- fleetBots: planFleetBots({ platform, home, env, log: (message) => log("info", message) }),
1635
+ ...daemonBotPlans({
1636
+ heldBots,
1637
+ signedIn: isSignedIn,
1638
+ services,
1639
+ fleet: { platform, home, env, log: (message) => log("info", message) },
1640
+ }),
1621
1641
  legacyOwner: legacyOwnerLookup(legacy),
1622
1642
  cliSelfUpdatable: updatable,
1623
1643
  claudePath: findUserBinary("claude", env, home),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigoai-us/hq-cli",
3
- "version": "5.345.237",
3
+ "version": "5.345.238",
4
4
  "description": "HQ by Indigo management CLI — modules and cloud sync",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -126,11 +126,11 @@
126
126
  "*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
127
127
  },
128
128
  "optionalDependencies": {
129
- "@indigoai-us/hq-hook-win32-x64": "5.345.237",
130
- "@indigoai-us/hq-hook-win32-arm64": "5.345.237",
131
- "@indigoai-us/hq-hook-darwin-x64": "5.345.237",
132
- "@indigoai-us/hq-hook-darwin-arm64": "5.345.237",
133
- "@indigoai-us/hq-hook-linux-x64": "5.345.237",
134
- "@indigoai-us/hq-hook-linux-arm64": "5.345.237"
129
+ "@indigoai-us/hq-hook-win32-x64": "5.345.238",
130
+ "@indigoai-us/hq-hook-win32-arm64": "5.345.238",
131
+ "@indigoai-us/hq-hook-darwin-x64": "5.345.238",
132
+ "@indigoai-us/hq-hook-darwin-arm64": "5.345.238",
133
+ "@indigoai-us/hq-hook-linux-x64": "5.345.238",
134
+ "@indigoai-us/hq-hook-linux-arm64": "5.345.238"
135
135
  }
136
136
  }