@indigoai-us/hq-cli 5.345.210 → 5.345.212-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/assets/scaffold/core/scripts/lib/trigger-fact-text.awk +152 -41
  3. package/dist/command-catalog.generated.d.ts +28 -0
  4. package/dist/command-catalog.generated.js +34 -0
  5. package/dist/commands/bot-runtime.d.ts +21 -2
  6. package/dist/commands/bot-runtime.js +54 -9
  7. package/dist/commands/bot.d.ts +13 -0
  8. package/dist/commands/bot.js +142 -12
  9. package/dist/commands/core-derive-trigger-facts-native.d.ts +1 -0
  10. package/dist/commands/core-derive-trigger-facts-native.js +61 -11
  11. package/dist/commands/core-work-mesh-bind-trusted-native.d.ts +14 -2
  12. package/dist/commands/core-work-mesh-bind-trusted-native.js +62 -8
  13. package/dist/commands/daemon.js +3 -0
  14. package/dist/commands/integrations-connect.d.ts +16 -0
  15. package/dist/commands/integrations-connect.js +23 -4
  16. package/dist/commands/whoami.js +7 -6
  17. package/dist/lib/bot/api.d.ts +1 -1
  18. package/dist/lib/bot/config.js +2 -1
  19. package/dist/lib/bot/fleet-daemon.d.ts +4 -0
  20. package/dist/lib/bot/fleet-daemon.js +12 -1
  21. package/dist/lib/bot/fleet-download.d.ts +6 -0
  22. package/dist/lib/bot/fleet-download.js +128 -3
  23. package/dist/lib/bot/fleet-local.d.ts +38 -1
  24. package/dist/lib/bot/fleet-local.js +239 -26
  25. package/dist/lib/bot/install-progress.d.ts +28 -0
  26. package/dist/lib/bot/install-progress.js +185 -0
  27. package/dist/lib/bot/legacy-provider-login.d.ts +22 -1
  28. package/dist/lib/bot/legacy-provider-login.js +67 -9
  29. package/dist/lib/bot/prompt.d.ts +1 -0
  30. package/dist/lib/bot/prompt.js +3 -2
  31. package/dist/lib/bot/readiness.d.ts +68 -0
  32. package/dist/lib/bot/readiness.js +145 -0
  33. package/dist/lib/bot/run.d.ts +2 -0
  34. package/dist/lib/bot/run.js +6 -3
  35. package/dist/lib/bot/scaffold.d.ts +6 -3
  36. package/dist/lib/bot/scaffold.js +18 -12
  37. package/dist/lib/daemon/catalog.d.ts +9 -0
  38. package/dist/lib/daemon/catalog.js +13 -1
  39. package/dist/lib/daemon/run.d.ts +6 -3
  40. package/dist/lib/daemon/run.js +43 -6
  41. package/dist/lib/daemon/supervisor.d.ts +3 -0
  42. package/dist/lib/daemon/supervisor.js +64 -3
  43. package/dist/lib/sync-core/reconcile.js +15 -11
  44. package/package.json +7 -7
@@ -19,7 +19,7 @@ import { currentPackageUseLeaseInstall, currentPackageUseUpdateRequested } from
19
19
  import { isLocalDependencyInstall, resolveRunningInstall } from "../../utils/version-gate.js";
20
20
  import { agentKitPaths } from "../agent-kit/paths.js";
21
21
  import { HQ_FLEET_RUNTIME_ENGINE_ID, readBotConfig } from "../bot/config.js";
22
- import { planFleetBots } from "../bot/fleet-daemon.js";
22
+ import { clearStaleReadyBeforeGatewayStart, planFleetBots } from "../bot/fleet-daemon.js";
23
23
  import { botsRoot } from "../bot/paths.js";
24
24
  import { CLAUDE_RUNNER_SCRIPT, CODEX_RUNNER_SCRIPT, enabledServices, planUnits } from "./catalog.js";
25
25
  import { effectiveSyncOwner, readDaemonConfig } from "./config.js";
@@ -58,7 +58,7 @@ import { stageSyncRunnerBundle } from "./sync-runner-bundle.js";
58
58
  import { stageHqChildBootstrap } from "./hq-child-bootstrap-stage.js";
59
59
  import { runnerSessionName } from "./remote-control.js";
60
60
  import { adoptChild, createChildTracker, finishSuccession, handoffEligible, readProcStart, stopOrphans, successionPaths, systemdKillMode, takeSuccession, writeHandoff, } from "./succession.js";
61
- import { listSyncRunnerProcesses, readWatchRunnerOwnerStatus, syncHeartbeatTimeoutMs, syncRunnerNodeOptions, watchRunnerOwnerStatusPath, } from "./sync-runner.js";
61
+ import { listSyncRunnerProcesses, readWatchRunnerOwnerStatus, SYNC_RUNNER_LEASE_CONFLICT_EXIT, syncHeartbeatTimeoutMs, syncRunnerNodeOptions, watchRunnerOwnerStatusPath, } from "./sync-runner.js";
62
62
  import { STOP_ESCALATION_MS, SYNC_RUNNER_PERSIST_GRACE_MS, createSupervisor, planKey, } from "./supervisor.js";
63
63
  import { userToolDirs } from "./tools.js";
64
64
  import { logOffset, readLogSince, readUnitHolds, writeUnitHolds } from "./unit-holds.js";
@@ -88,7 +88,7 @@ export function syncCoreVaultPlans(home, hqRoot, platform) {
88
88
  });
89
89
  }
90
90
  const rememberedSyncCoreVaults = new Map();
91
- export function planUnitsWithSyncCoreInterlock(services, context, supervisor) {
91
+ export function planUnitsWithSyncCoreInterlock(services, context, supervisor, readOwnerStatus) {
92
92
  const companies = new Set();
93
93
  const runningVaults = new Set();
94
94
  let personal = false;
@@ -155,9 +155,39 @@ export function planUnitsWithSyncCoreInterlock(services, context, supervisor) {
155
155
  waiting = planUnits(services, transitionContext);
156
156
  legacy = waiting.find((unit) => unit.id === "sync");
157
157
  }
158
+ const holder = context.syncCoreVaults?.some((vault) => vault.phase === "full")
159
+ ? legacySyncHeldByOtherOwner(supervisor?.state().units ?? [], readOwnerStatus)
160
+ : undefined;
158
161
  const legacySyncReadyForCore = legacy !== undefined
159
- && (legacy.blocked !== undefined || supervisor?.runningPlanKey("sync") === planKey(legacy, CLI_VERSION));
160
- return planUnits(services, { ...transitionContext, legacySyncReadyForCore });
162
+ && (legacy.blocked !== undefined
163
+ || holder !== undefined
164
+ || supervisor?.runningPlanKey("sync") === planKey(legacy, CLI_VERSION));
165
+ return planUnits(services, {
166
+ ...transitionContext,
167
+ legacySyncReadyForCore,
168
+ ...(holder !== undefined ? { legacySyncHolder: holder } : {}),
169
+ });
170
+ }
171
+ export function legacySyncHeldByOtherOwner(units, readOwnerStatus) {
172
+ const sync = units.find((unit) => unit.id === "sync");
173
+ if (sync?.lastExit?.code !== SYNC_RUNNER_LEASE_CONFLICT_EXIT)
174
+ return undefined;
175
+ const retrying = sync.status === "running" && sync.startedAt !== undefined && sync.startedAt >= sync.lastExit.at;
176
+ if (sync.status !== "waiting" && !retrying)
177
+ return undefined;
178
+ let owner;
179
+ try {
180
+ owner = readOwnerStatus();
181
+ }
182
+ catch {
183
+ return { status: "unreadable" };
184
+ }
185
+ if (!owner)
186
+ return { status: "missing" };
187
+ if (retrying && sync.pid !== undefined && owner.pid === sync.pid)
188
+ return undefined;
189
+ const startedAt = Date.parse(owner.startedAt);
190
+ return Number.isFinite(startedAt) ? { status: "started", startedAt } : { status: "unreadable" };
161
191
  }
162
192
  /** A bounded shutdown deadline that can account for sync push persistence. */
163
193
  export function createShutdownCap() {
@@ -535,6 +565,10 @@ const DAEMON_CHILD_ONE_SHOT_KEYS = [
535
565
  "HQ_DAEMON_OWNER_CONTROL_FD",
536
566
  "HQ_DAEMON_HANDOFF_PATH",
537
567
  ];
568
+ export function prepareUnitStart(unit, log, alive) {
569
+ if (clearStaleReadyBeforeGatewayStart(unit, alive))
570
+ log("info", `${unit.id}: cleared the ready signal its previous gateway left before starting a new one`);
571
+ }
538
572
  /**
539
573
  * Environment for one service process. The CLI's own update check is off:
540
574
  * a child that updates itself exits 0 and asks to be rerun, which would leave
@@ -1163,7 +1197,9 @@ export async function runDaemon(opts) {
1163
1197
  availablePoolFrontends,
1164
1198
  unverifiablePoolFrontends,
1165
1199
  };
1166
- const plans = planUnitsWithSyncCoreInterlock(services, context, supervisor);
1200
+ const plans = planUnitsWithSyncCoreInterlock(services, context, supervisor, () => hqRoot
1201
+ ? readWatchRunnerOwnerStatus(watchRunnerOwnerStatusPath(hqRoot, home, env))
1202
+ : null);
1167
1203
  if (startupPlanOpen) {
1168
1204
  const replaceablePackageRoots = cliPackageRoot ? [cliPackageRoot] : [];
1169
1205
  if (hqCloud?.source === "bundled")
@@ -1181,6 +1217,7 @@ export async function runDaemon(opts) {
1181
1217
  const command = unit.command;
1182
1218
  if (!command || command.type === "internal")
1183
1219
  throw new Error(`${unit.id} has no process to start`);
1220
+ prepareUnitStart(unit, log);
1184
1221
  unitLogOffsets.set(unit.id, logOffset(paths.unitLogPath(unit.id)));
1185
1222
  let [file, args] = command.type === "hq"
1186
1223
  ? daemonHqChildCommand(opts.nodeBinary, opts.hqBinary, command.args, stagedHqChildBootstrap?.bootstrapPath ?? null, cliPackagePrefix, childBootstrapHandoffWatchFlag.status().enabled)
@@ -57,6 +57,8 @@ export declare const SYNC_CORE_LOCK_HELD_EXIT = 17;
57
57
  export declare const SYNC_CORE_PROGRESS_EXEMPT_MAX = 6;
58
58
  /** How often a unit held for exit 17 checks whether the lock holder is still alive. */
59
59
  export declare const LOCK_HOLDER_POLL_MS = 5000;
60
+ export declare const WAKE_TICK_MS = 5000;
61
+ export declare const WAKE_GAP_MS = 30000;
60
62
  /**
61
63
  * The pid hq-syncd names when it exits 17: "local sync engine is already
62
64
  * running (pid N)" or "HQ operation lock for ... is held by "cmd" (pid N)".
@@ -223,6 +225,7 @@ export interface Supervisor {
223
225
  * `keepAcrossCliUpdates` running.
224
226
  */
225
227
  export declare function planKey(plan: UnitPlan, cliVersion?: string): string;
228
+ export declare const DAEMON_REQUEST_POLL_MS = 250;
226
229
  export declare function createSupervisor(deps: SupervisorDeps): Supervisor;
227
230
  export {};
228
231
  //# sourceMappingURL=supervisor.d.ts.map
@@ -62,6 +62,8 @@ export const SYNC_CORE_LOCK_HELD_EXIT = 17;
62
62
  export const SYNC_CORE_PROGRESS_EXEMPT_MAX = 6;
63
63
  /** How often a unit held for exit 17 checks whether the lock holder is still alive. */
64
64
  export const LOCK_HOLDER_POLL_MS = 5_000;
65
+ export const WAKE_TICK_MS = 5_000;
66
+ export const WAKE_GAP_MS = 30_000;
65
67
  /**
66
68
  * The pid hq-syncd names when it exits 17: "local sync engine is already
67
69
  * running (pid N)" or "HQ operation lock for ... is held by "cmd" (pid N)".
@@ -168,12 +170,13 @@ function lastProtocolHint(slot) {
168
170
  return ` (last protocol line: ${slot.lastProtocolLine})`;
169
171
  return "";
170
172
  }
173
+ export const DAEMON_REQUEST_POLL_MS = 250;
171
174
  export function createSupervisor(deps) {
172
175
  const now = deps.now ?? Date.now;
173
176
  const setT = deps.setTimeout ?? ((fn, ms) => setTimeout(fn, ms));
174
177
  const clearT = deps.clearTimeout ?? ((h) => clearTimeout(h));
175
178
  const reconcileMs = deps.reconcileMs ?? 15_000;
176
- const requestPollMs = deps.requestPollMs ?? 1_000;
179
+ const requestPollMs = deps.requestPollMs ?? DAEMON_REQUEST_POLL_MS;
177
180
  const startedAt = now();
178
181
  let persistedHolds = {};
179
182
  /** Holds dropped at plan time (a changed command) that holds.json still lists. */
@@ -238,6 +241,55 @@ export function createSupervisor(deps) {
238
241
  clearT(slot.heartbeatTimer);
239
242
  slot.heartbeatTimer = undefined;
240
243
  };
244
+ let wakeTickTimer;
245
+ let lastWakeTickAt;
246
+ let resumedAt;
247
+ const noteWakeGap = () => {
248
+ if (lastWakeTickAt === undefined)
249
+ return;
250
+ const at = now();
251
+ if (at - lastWakeTickAt > WAKE_GAP_MS)
252
+ resumedAt = at;
253
+ lastWakeTickAt = at;
254
+ };
255
+ const stopWakeTicker = () => {
256
+ if (wakeTickTimer !== undefined)
257
+ clearT(wakeTickTimer);
258
+ wakeTickTimer = undefined;
259
+ lastWakeTickAt = undefined;
260
+ };
261
+ const scheduleWakeTick = () => {
262
+ const handle = setT(() => {
263
+ wakeTickTimer = undefined;
264
+ noteWakeGap();
265
+ if (stopped || ![...slots.values()].some((s) => s.heartbeatTimer !== undefined)) {
266
+ lastWakeTickAt = undefined;
267
+ return;
268
+ }
269
+ scheduleWakeTick();
270
+ }, WAKE_TICK_MS);
271
+ if (typeof handle === "object" && handle !== null && "unref" in handle && typeof handle.unref === "function") {
272
+ handle.unref();
273
+ }
274
+ wakeTickTimer = handle;
275
+ };
276
+ const ensureWakeTicker = () => {
277
+ if (wakeTickTimer !== undefined)
278
+ return;
279
+ lastWakeTickAt = now();
280
+ scheduleWakeTick();
281
+ };
282
+ const resumedWithin = (windowMs) => {
283
+ noteWakeGap();
284
+ if (resumedAt === undefined)
285
+ return false;
286
+ const sinceResume = now() - resumedAt;
287
+ if (sinceResume < 0) {
288
+ resumedAt = undefined;
289
+ return false;
290
+ }
291
+ return sinceResume < windowMs;
292
+ };
241
293
  const clearDeferredCliRestart = () => {
242
294
  deferredCliRestart = false;
243
295
  if (deferredCliRestartTimer !== undefined)
@@ -587,10 +639,16 @@ export function createSupervisor(deps) {
587
639
  if (!timeoutMs)
588
640
  return;
589
641
  clearHeartbeatTimer(slot);
642
+ ensureWakeTicker();
590
643
  slot.heartbeatTimer = setT(() => {
591
644
  slot.heartbeatTimer = undefined;
592
645
  if (stopped || slot.child !== child || slot.expectingExit)
593
646
  return;
647
+ if (resumedWithin(timeoutMs)) {
648
+ deps.log("info", `${slot.plan.id} emitted no sync protocol heartbeat for ${timeoutMs}ms, but this machine resumed from sleep ${now() - (resumedAt ?? now())}ms ago; waiting another ${timeoutMs}ms before restarting it`);
649
+ armHeartbeatWatchdog();
650
+ return;
651
+ }
594
652
  // An engine that reported bytes moving during this run is slow, not
595
653
  // hung: restart it, but do not count it toward the exhausted hold.
596
654
  // Bounded per episode: past SYNC_CORE_PROGRESS_EXEMPT_MAX these count again.
@@ -1342,10 +1400,11 @@ export function createSupervisor(deps) {
1342
1400
  // A bot created since the last plan read is asked for before the timer
1343
1401
  // would pick it up; read the plan now rather than dropping the request.
1344
1402
  const unplanned = req.unit !== undefined && !slots.has(req.unit);
1345
- if (unplanned)
1403
+ const heldInPlan = req.unit !== undefined && req.action === "restart" && Boolean(slots.get(req.unit)?.plan.blocked);
1404
+ if (unplanned || heldInPlan)
1346
1405
  reconcile();
1347
1406
  // The re-read already started a new long-running unit; restarting it would only bounce it.
1348
- if (unplanned && req.action === "restart" && slots.get(req.unit)?.child) {
1407
+ if ((unplanned || heldInPlan) && req.action === "restart" && slots.get(req.unit)?.child) {
1349
1408
  emit();
1350
1409
  return;
1351
1410
  }
@@ -1451,6 +1510,7 @@ export function createSupervisor(deps) {
1451
1510
  clearT(handoffTimer);
1452
1511
  clearDeferredCliRestart();
1453
1512
  clearPendingSyncCommandRestart();
1513
+ stopWakeTicker();
1454
1514
  const childOwners = new Map(liveOwners);
1455
1515
  for (const slot of slots.values()) {
1456
1516
  clearTimer(slot);
@@ -1546,6 +1606,7 @@ export function createSupervisor(deps) {
1546
1606
  if (handoffTimer !== undefined)
1547
1607
  clearT(handoffTimer);
1548
1608
  clearDeferredCliRestart();
1609
+ stopWakeTicker();
1549
1610
  for (const slot of slots.values()) {
1550
1611
  clearTimer(slot);
1551
1612
  if (slot.killTimer !== undefined)
@@ -107,19 +107,23 @@ export async function reconcileSyncCore(deps) {
107
107
  if (personUid)
108
108
  desired.push({ uid: personUid, kind: "personal" });
109
109
  }
110
- const skipped = [];
110
+ let skips;
111
111
  try {
112
- const skips = readSyncCoreSkips(deps.home);
113
- for (let i = desired.length - 1; i >= 0; i -= 1) {
114
- const skip = skips.find((entry) => entry.uid === desired[i]?.uid);
115
- if (!skip)
116
- continue;
117
- skipped.unshift(skip);
118
- desired.splice(i, 1);
119
- }
112
+ skips = readSyncCoreSkips(deps.home);
120
113
  }
121
114
  catch (error) {
122
- warnings.push(message(error));
115
+ skips = previous?.skipped ?? [];
116
+ warnings.push(`${message(error)}; ${skips.length > 0
117
+ ? `keeping last run's skips (${skips.map((skip) => skip.uid).join(", ")})`
118
+ : "no vault was skipped last run, so none is skipped now"}`);
119
+ }
120
+ const skipped = [];
121
+ for (let i = desired.length - 1; i >= 0; i -= 1) {
122
+ const skip = skips.find((entry) => entry.uid === desired[i]?.uid);
123
+ if (!skip)
124
+ continue;
125
+ skipped.unshift(skip);
126
+ desired.splice(i, 1);
123
127
  }
124
128
  let binaryPath = syncCoreBinaryPath(deps.home, platform);
125
129
  let installedRelease = installedSyncCoreRelease(deps.home, platform);
@@ -181,7 +185,7 @@ export async function reconcileSyncCore(deps) {
181
185
  ? switchesBefore.personalOff
182
186
  : switchesBefore.offCompanies.has(vault.slug ?? "");
183
187
  const legacyAlreadyOff = wasFull ? before.legacyAlreadyOff === true : alreadyOff;
184
- const legacyOffSince = (wasFull ? before.legacyOffSince : undefined) ?? at;
188
+ const legacyOffSince = (wasFull && alreadyOff ? before.legacyOffSince : undefined) ?? at;
185
189
  const recorded = wasFull ? before.firstCycle : undefined;
186
190
  const firstCycle = recorded && recorded.planned > 0
187
191
  ? recorded
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigoai-us/hq-cli",
3
- "version": "5.345.210",
3
+ "version": "5.345.212-beta.0",
4
4
  "description": "HQ by Indigo management CLI — modules and cloud sync",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -117,11 +117,11 @@
117
117
  "*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
118
118
  },
119
119
  "optionalDependencies": {
120
- "@indigoai-us/hq-hook-win32-x64": "5.345.210",
121
- "@indigoai-us/hq-hook-win32-arm64": "5.345.210",
122
- "@indigoai-us/hq-hook-darwin-x64": "5.345.210",
123
- "@indigoai-us/hq-hook-darwin-arm64": "5.345.210",
124
- "@indigoai-us/hq-hook-linux-x64": "5.345.210",
125
- "@indigoai-us/hq-hook-linux-arm64": "5.345.210"
120
+ "@indigoai-us/hq-hook-win32-x64": "5.345.212-beta.0",
121
+ "@indigoai-us/hq-hook-win32-arm64": "5.345.212-beta.0",
122
+ "@indigoai-us/hq-hook-darwin-x64": "5.345.212-beta.0",
123
+ "@indigoai-us/hq-hook-darwin-arm64": "5.345.212-beta.0",
124
+ "@indigoai-us/hq-hook-linux-x64": "5.345.212-beta.0",
125
+ "@indigoai-us/hq-hook-linux-arm64": "5.345.212-beta.0"
126
126
  }
127
127
  }