@indigoai-us/hq-cli 5.345.214 → 5.345.215

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 (200) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/assets/scaffold/core/scripts/hq-delegate-verify.sh +5 -2
  3. package/dist/command-catalog.generated.d.ts +180 -13
  4. package/dist/command-catalog.generated.js +221 -13
  5. package/dist/commands/agents.d.ts +51 -1
  6. package/dist/commands/agents.js +154 -2
  7. package/dist/commands/bot-jobs.d.ts +2 -15
  8. package/dist/commands/bot-jobs.js +2 -94
  9. package/dist/commands/bot-runtime.d.ts +46 -5
  10. package/dist/commands/bot-runtime.js +228 -18
  11. package/dist/commands/bot.d.ts +16 -9
  12. package/dist/commands/bot.js +231 -55
  13. package/dist/commands/capacity.d.ts +4 -1
  14. package/dist/commands/capacity.js +46 -10
  15. package/dist/commands/cloud.d.ts +66 -13
  16. package/dist/commands/cloud.js +121 -40
  17. package/dist/commands/company-restore.d.ts +23 -0
  18. package/dist/commands/company-restore.js +128 -0
  19. package/dist/commands/company.js +2 -0
  20. package/dist/commands/core-delegate-w1b.js +15 -1
  21. package/dist/commands/core-policy.js +67 -8
  22. package/dist/commands/daemon.js +5 -0
  23. package/dist/commands/files-browse.d.ts +11 -4
  24. package/dist/commands/files-browse.js +21 -4
  25. package/dist/commands/files.d.ts +1 -1
  26. package/dist/commands/files.js +25 -11
  27. package/dist/commands/integrations-auth-rules.d.ts +27 -0
  28. package/dist/commands/integrations-auth-rules.js +79 -0
  29. package/dist/commands/integrations-connect.d.ts +10 -3
  30. package/dist/commands/integrations-connect.js +87 -13
  31. package/dist/commands/integrations-import.js +124 -12
  32. package/dist/commands/lanes.js +28 -11
  33. package/dist/commands/mesh.d.ts +2 -0
  34. package/dist/commands/mesh.js +60 -35
  35. package/dist/commands/sources.js +6 -0
  36. package/dist/commands/storage-offload.d.ts +12 -0
  37. package/dist/commands/storage-offload.js +41 -3
  38. package/dist/commands/sync-held.js +5 -2
  39. package/dist/commands/sync-mode.js +5 -0
  40. package/dist/commands/whoami.js +4 -0
  41. package/dist/lazy-commands.js +3 -5
  42. package/dist/lib/bot/config.d.ts +1 -0
  43. package/dist/lib/bot/config.js +10 -0
  44. package/dist/lib/bot/eventbridge-cron.d.ts +22 -0
  45. package/dist/lib/bot/eventbridge-cron.js +104 -0
  46. package/dist/lib/bot/fleet-cron.d.ts +8 -0
  47. package/dist/lib/bot/fleet-cron.js +35 -3
  48. package/dist/lib/bot/fleet-daemon.d.ts +46 -0
  49. package/dist/lib/bot/fleet-daemon.js +99 -1
  50. package/dist/lib/bot/fleet-local.d.ts +33 -1
  51. package/dist/lib/bot/fleet-local.js +215 -31
  52. package/dist/lib/bot/fleet-python.d.ts +3 -0
  53. package/dist/lib/bot/fleet-python.js +34 -4
  54. package/dist/lib/bot/fleet-runtime-sources.d.ts +15 -0
  55. package/dist/lib/bot/fleet-runtime-sources.js +30 -0
  56. package/dist/lib/bot/legacy-provider-login.d.ts +8 -0
  57. package/dist/lib/bot/legacy-provider-login.js +19 -2
  58. package/dist/lib/bot/probe.js +7 -1
  59. package/dist/lib/bot/prompt.js +1 -1
  60. package/dist/lib/bot/readiness.d.ts +8 -0
  61. package/dist/lib/bot/readiness.js +17 -3
  62. package/dist/lib/bot/run.js +20 -1
  63. package/dist/lib/bot/runtime/codex.js +1 -1
  64. package/dist/lib/bot/runtime/grok-acp.d.ts +5 -1
  65. package/dist/lib/bot/runtime/grok-acp.js +6 -3
  66. package/dist/lib/bot/runtime/index.js +19 -9
  67. package/dist/lib/bot/runtime/messages-stream.js +2 -2
  68. package/dist/lib/bot/runtime/types.d.ts +15 -0
  69. package/dist/lib/bot/runtime/types.js +9 -0
  70. package/dist/lib/bot/runtime-auth.d.ts +30 -0
  71. package/dist/lib/bot/runtime-auth.js +94 -3
  72. package/dist/lib/bot/runtime-failure.d.ts +23 -0
  73. package/dist/lib/bot/runtime-failure.js +43 -1
  74. package/dist/lib/bot/status.d.ts +2 -0
  75. package/dist/lib/capacity/accounts.d.ts +8 -0
  76. package/dist/lib/capacity/accounts.js +19 -0
  77. package/dist/lib/capacity/available.d.ts +154 -0
  78. package/dist/lib/capacity/available.js +905 -0
  79. package/dist/lib/capacity/codex-availability.d.ts +14 -1
  80. package/dist/lib/capacity/codex-availability.js +26 -1
  81. package/dist/lib/capacity/collectors/claude-oauth.d.ts +29 -2
  82. package/dist/lib/capacity/collectors/claude-oauth.js +104 -7
  83. package/dist/lib/capacity/collectors/codex.js +10 -7
  84. package/dist/lib/capacity/collectors/grok-refresh.d.ts +80 -0
  85. package/dist/lib/capacity/collectors/grok-refresh.js +189 -0
  86. package/dist/lib/capacity/collectors/grok.d.ts +5 -0
  87. package/dist/lib/capacity/collectors/grok.js +56 -5
  88. package/dist/lib/capacity/ledger.d.ts +37 -1
  89. package/dist/lib/capacity/ledger.js +207 -30
  90. package/dist/lib/capacity/project.d.ts +26 -0
  91. package/dist/lib/capacity/project.js +137 -8
  92. package/dist/lib/capacity/refusal-rows.d.ts +31 -0
  93. package/dist/lib/capacity/refusal-rows.js +61 -0
  94. package/dist/lib/capacity/refusal.d.ts +53 -2
  95. package/dist/lib/capacity/refusal.js +284 -65
  96. package/dist/lib/capacity/route.js +46 -11
  97. package/dist/lib/capacity/widget.d.ts +12 -1
  98. package/dist/lib/capacity/widget.js +91 -3
  99. package/dist/lib/daemon/catalog.js +11 -1
  100. package/dist/lib/daemon/resolver.d.ts +2 -0
  101. package/dist/lib/daemon/resolver.js +3 -0
  102. package/dist/lib/daemon/run.d.ts +9 -0
  103. package/dist/lib/daemon/run.js +54 -1
  104. package/dist/lib/daemon/server.d.ts +2 -0
  105. package/dist/lib/daemon/server.js +10 -1
  106. package/dist/lib/daemon/tcc-eperm.d.ts +153 -0
  107. package/dist/lib/daemon/tcc-eperm.js +310 -0
  108. package/dist/lib/db/sqlite-binding.d.ts +1 -0
  109. package/dist/lib/db/sqlite-binding.js +1 -1
  110. package/dist/lib/delivery/admission.d.ts +86 -0
  111. package/dist/lib/delivery/admission.js +148 -0
  112. package/dist/lib/delivery/artifacts.d.ts +105 -0
  113. package/dist/lib/delivery/artifacts.js +567 -0
  114. package/dist/lib/delivery/attempt-id.d.ts +13 -0
  115. package/dist/lib/delivery/attempt-id.js +16 -0
  116. package/dist/lib/delivery/backup.d.ts +78 -0
  117. package/dist/lib/delivery/backup.js +343 -0
  118. package/dist/lib/delivery/cache.d.ts +29 -0
  119. package/dist/lib/delivery/cache.js +33 -0
  120. package/dist/lib/delivery/contracts.d.ts +142 -0
  121. package/dist/lib/delivery/contracts.js +289 -0
  122. package/dist/lib/delivery/credentials.d.ts +54 -0
  123. package/dist/lib/delivery/credentials.js +119 -0
  124. package/dist/lib/delivery/disposable-target.d.ts +42 -0
  125. package/dist/lib/delivery/disposable-target.js +111 -0
  126. package/dist/lib/delivery/effects.d.ts +136 -0
  127. package/dist/lib/delivery/effects.js +541 -0
  128. package/dist/lib/delivery/enrollment.d.ts +146 -0
  129. package/dist/lib/delivery/enrollment.js +460 -0
  130. package/dist/lib/delivery/escalations.d.ts +51 -0
  131. package/dist/lib/delivery/escalations.js +60 -0
  132. package/dist/lib/delivery/identity.d.ts +25 -0
  133. package/dist/lib/delivery/identity.js +82 -0
  134. package/dist/lib/delivery/inbox.d.ts +116 -0
  135. package/dist/lib/delivery/inbox.js +260 -0
  136. package/dist/lib/delivery/lease.d.ts +80 -0
  137. package/dist/lib/delivery/lease.js +134 -0
  138. package/dist/lib/delivery/migrations.d.ts +255 -0
  139. package/dist/lib/delivery/migrations.js +823 -0
  140. package/dist/lib/delivery/mqtt-adapter.d.ts +50 -0
  141. package/dist/lib/delivery/mqtt-adapter.js +242 -0
  142. package/dist/lib/delivery/mqtt.d.ts +63 -0
  143. package/dist/lib/delivery/mqtt.js +119 -0
  144. package/dist/lib/delivery/outbox.d.ts +95 -0
  145. package/dist/lib/delivery/outbox.js +187 -0
  146. package/dist/lib/delivery/provenance.d.ts +129 -0
  147. package/dist/lib/delivery/provenance.js +93 -0
  148. package/dist/lib/delivery/reconciler.d.ts +215 -0
  149. package/dist/lib/delivery/reconciler.js +703 -0
  150. package/dist/lib/delivery/restore.d.ts +35 -0
  151. package/dist/lib/delivery/restore.js +134 -0
  152. package/dist/lib/delivery/rpc/client.d.ts +22 -0
  153. package/dist/lib/delivery/rpc/client.js +159 -0
  154. package/dist/lib/delivery/rpc/port.d.ts +40 -0
  155. package/dist/lib/delivery/rpc/port.js +16 -0
  156. package/dist/lib/delivery/rpc/server.d.ts +30 -0
  157. package/dist/lib/delivery/rpc/server.js +205 -0
  158. package/dist/lib/delivery/rpc/wire.d.ts +85 -0
  159. package/dist/lib/delivery/rpc/wire.js +143 -0
  160. package/dist/lib/delivery/store.d.ts +163 -0
  161. package/dist/lib/delivery/store.js +944 -0
  162. package/dist/lib/delivery/windows-service-install.d.ts +262 -0
  163. package/dist/lib/delivery/windows-service-install.js +892 -0
  164. package/dist/lib/delivery/workers/macos-job-helper.d.ts +103 -0
  165. package/dist/lib/delivery/workers/macos-job-helper.js +927 -0
  166. package/dist/lib/delivery/workers/macos.d.ts +191 -0
  167. package/dist/lib/delivery/workers/macos.js +943 -0
  168. package/dist/lib/delivery/workers/windows-job-helper.d.ts +35 -0
  169. package/dist/lib/delivery/workers/windows-job-helper.js +264 -0
  170. package/dist/lib/delivery/workers/windows-service-live.d.ts +121 -0
  171. package/dist/lib/delivery/workers/windows-service-live.js +711 -0
  172. package/dist/lib/delivery/workers/windows-service-runner.d.ts +33 -0
  173. package/dist/lib/delivery/workers/windows-service-runner.js +82 -0
  174. package/dist/lib/delivery/workers/windows-service.d.ts +140 -0
  175. package/dist/lib/delivery/workers/windows-service.js +584 -0
  176. package/dist/lib/delivery/workers/windows.d.ts +251 -0
  177. package/dist/lib/delivery/workers/windows.js +594 -0
  178. package/dist/lib/hot-channels/adapters/meetings.d.ts +15 -0
  179. package/dist/lib/hot-channels/adapters/meetings.js +36 -3
  180. package/dist/lib/hot-channels/signals-pass.d.ts +10 -0
  181. package/dist/lib/hot-channels/signals-pass.js +71 -2
  182. package/dist/lib/hot-channels/signals-redo.js +10 -2
  183. package/dist/lib/install/provider-wrappers.d.ts +2 -0
  184. package/dist/lib/install/provider-wrappers.js +68 -3
  185. package/dist/lib/lanes/watcher.js +35 -0
  186. package/dist/lib/signals/steps/extract.js +40 -4
  187. package/dist/schemas/hq-available-ai.v1.schema.json +76 -0
  188. package/dist/utils/catalog-runtime-paths.d.ts +34 -0
  189. package/dist/utils/catalog-runtime-paths.js +53 -0
  190. package/dist/utils/cognito-callback-port.d.ts +14 -0
  191. package/dist/utils/cognito-callback-port.js +24 -0
  192. package/dist/utils/cognito-session.js +3 -3
  193. package/dist/utils/deleted-company-notice.d.ts +59 -0
  194. package/dist/utils/deleted-company-notice.js +156 -0
  195. package/dist/utils/files-browse-acl.js +1 -1
  196. package/dist/utils/login-browser.d.ts +1 -1
  197. package/dist/utils/login-browser.js +7 -5
  198. package/dist/utils/resident-package-preload.js +30 -15
  199. package/dist/utils/vault-api.js +7 -0
  200. package/package.json +7 -7
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Standard five-field cron to the stored six-field `cron(...)` form shared by
3
+ * local bot jobs and hosted agent jobs. Pure and dependency-free so commands on
4
+ * resident paths (`hq agents jobs update`) can use it without loading the bot
5
+ * jobs command graph.
6
+ */
7
+ export declare class BotJobsError extends Error {
8
+ readonly expected: true;
9
+ }
10
+ /**
11
+ * Standard 5-field cron → the six-field `cron(...)` string a job is stored as.
12
+ *
13
+ * The stored form (the six-field cron syntax hosted agent jobs also use, so
14
+ * local and hosted jobs share one format; the function keeps its historical
15
+ * name) has SIX fields (a trailing year), numbers its days of week
16
+ * 1–7 with SUNDAY = 1 (standard cron uses 0–6 with SUNDAY = 0), and refuses
17
+ * `*` in BOTH the day-of-month and day-of-week fields — exactly one must be
18
+ * `?`. An expression that is already `cron(...)` or `rate(...)` is passed
19
+ * through untouched.
20
+ */
21
+ export declare function toEventBridgeCron(expr: string): string;
22
+ //# sourceMappingURL=eventbridge-cron.d.ts.map
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Standard five-field cron to the stored six-field `cron(...)` form shared by
3
+ * local bot jobs and hosted agent jobs. Pure and dependency-free so commands on
4
+ * resident paths (`hq agents jobs update`) can use it without loading the bot
5
+ * jobs command graph.
6
+ */
7
+ export class BotJobsError extends Error {
8
+ expected = true;
9
+ }
10
+ function refuse(message) {
11
+ throw new BotJobsError(message);
12
+ }
13
+ /**
14
+ * Standard 5-field cron → the six-field `cron(...)` string a job is stored as.
15
+ *
16
+ * The stored form (the six-field cron syntax hosted agent jobs also use, so
17
+ * local and hosted jobs share one format; the function keeps its historical
18
+ * name) has SIX fields (a trailing year), numbers its days of week
19
+ * 1–7 with SUNDAY = 1 (standard cron uses 0–6 with SUNDAY = 0), and refuses
20
+ * `*` in BOTH the day-of-month and day-of-week fields — exactly one must be
21
+ * `?`. An expression that is already `cron(...)` or `rate(...)` is passed
22
+ * through untouched.
23
+ */
24
+ export function toEventBridgeCron(expr) {
25
+ const trimmed = expr.trim();
26
+ // An explicit cron(...) / rate(...) is the caller saying "this is already the
27
+ // stored syntax" — passed through untranslated, on purpose.
28
+ if (/^(cron|rate)\s*\(/i.test(trimmed))
29
+ return trimmed;
30
+ const fields = trimmed.split(/\s+/).filter(Boolean);
31
+ if (fields.length === 6) {
32
+ // Six BARE fields are ambiguous: the stored form's sixth field is a
33
+ // trailing year, Quartz's first is leading seconds. Guessing wrong
34
+ // silently moves every run. Make the caller say which they mean.
35
+ refuse(`"${trimmed}" has six fields, and I can't tell whether the last one is a year ` +
36
+ `(minute hour day-of-month month day-of-week year, the form bot jobs are stored in) or the ` +
37
+ `first one is seconds (a Quartz expression) — reading it the wrong way would schedule the job ` +
38
+ `at the wrong time. Pass five fields ("0 9 * * 1-5"), or wrap it yourself as cron(...) if it ` +
39
+ `already ends with a year field.`);
40
+ }
41
+ if (fields.length !== 5) {
42
+ refuse(`"${trimmed}" is not a cron expression. A cron expression has five fields: ` +
43
+ `minute hour day-of-month month day-of-week (for example "0 9 * * 1-5").`);
44
+ }
45
+ const [minute, hour, month] = [fields[0], fields[1], fields[3]];
46
+ let dayOfMonth = fields[2];
47
+ let dayOfWeek = fields[4];
48
+ if (dayOfWeek === "*" || dayOfWeek === "?") {
49
+ dayOfWeek = "?";
50
+ if (dayOfMonth === "?")
51
+ dayOfMonth = "*";
52
+ }
53
+ else {
54
+ dayOfWeek = shiftDayOfWeek(dayOfWeek);
55
+ if (dayOfMonth === "*")
56
+ dayOfMonth = "?";
57
+ }
58
+ return `cron(${minute} ${hour} ${dayOfMonth} ${month} ${dayOfWeek} *)`;
59
+ }
60
+ /**
61
+ * Standard 0–6 (SUN=0, and 7 also SUN) → the stored form's 1–7 (SUN=1).
62
+ *
63
+ * Mapped per TERM, not per digit. Shifting digits individually turned a range
64
+ * that wraps past Sunday — "6-0" (Sat–Sun), "5-1" (Fri–Mon) — into "7-1" /
65
+ * "6-2": reversed or plain wrong, and silently so. Such a range is refused with
66
+ * the list form that does work.
67
+ */
68
+ function shiftDayOfWeek(field) {
69
+ return field
70
+ .split(",")
71
+ .map((term) => shiftDayOfWeekTerm(term.trim()))
72
+ .join(",");
73
+ }
74
+ function shiftDay(n) {
75
+ return (n % 7) + 1;
76
+ }
77
+ function shiftDayOfWeekTerm(term) {
78
+ const step = term.match(/^(.+)\/(\d+)$/);
79
+ if (step)
80
+ return `${shiftDayOfWeekTerm(step[1])}/${step[2]}`;
81
+ const range = term.match(/^(\d+)-(\d+)$/);
82
+ if (range) {
83
+ const from = shiftDay(Number(range[1]));
84
+ const to = shiftDay(Number(range[2]));
85
+ if (from > to) {
86
+ const days = [];
87
+ for (let d = Number(range[1]);; d = (d + 1) % 7) {
88
+ days.push(d);
89
+ if (d === Number(range[2]) % 7)
90
+ break;
91
+ if (days.length > 7)
92
+ break;
93
+ }
94
+ refuse(`"${term}" is a day-of-week range that wraps past Sunday, which the schedule cannot express. ` +
95
+ `List the days instead, for example "${days.join(",")}".`);
96
+ }
97
+ return `${from}-${to}`;
98
+ }
99
+ if (/^\d+$/.test(term))
100
+ return String(shiftDay(Number(term)));
101
+ // Day NAMES (MON, MON-FRI) mean the same thing in both syntaxes.
102
+ return term;
103
+ }
104
+ //# sourceMappingURL=eventbridge-cron.js.map
@@ -73,6 +73,12 @@ export declare const FLEET_HOT_SIGNAL_SYNC_NAME = "hot-signal-sync";
73
73
  export declare const FLEET_HOT_SIGNAL_SYNC_SCHEDULE = "30 6 * * *";
74
74
  export declare function fleetHotSignalSyncScript(company: string): string;
75
75
  export declare function companyOfHotSignalSyncJob(job: FleetCronJob): string | null;
76
+ /**
77
+ * pnpm global installs land the CLI under `.../pnpm/global/vN/<hash>/...`.
78
+ * That hash folder is removed on the next CLI update. The stable launcher is
79
+ * `.../pnpm/bin/hq`. Empty when `hqBinary` is not a pnpm package entry.
80
+ */
81
+ export declare function fleetPnpmHqLauncher(hqBinary: string): string;
76
82
  export declare function renderFleetHotSignalSyncScript(input: {
77
83
  nodeBinary: string;
78
84
  hqBinary: string;
@@ -85,6 +91,8 @@ export declare function renderFleetHotSignalSyncScript(input: {
85
91
  * the job these bots ran before the engine.
86
92
  */
87
93
  signalsEngine?: boolean;
94
+ /** Override the baked pnpm `bin/hq` fallback. Tests pass this. */
95
+ hqLauncher?: string;
88
96
  }): string;
89
97
  export interface EnsureFleetHotSignalSyncInput {
90
98
  dir: string;
@@ -361,6 +361,31 @@ def classify(out, err, code):
361
361
  const HOT_SIGNAL_SYNC_RUN_END = String.raw `def run_end(code):
362
362
  return 'signal %d' % -code if code < 0 else 'exit %d' % code
363
363
  `;
364
+ /**
365
+ * pnpm global installs land the CLI under `.../pnpm/global/vN/<hash>/...`.
366
+ * That hash folder is removed on the next CLI update. The stable launcher is
367
+ * `.../pnpm/bin/hq`. Empty when `hqBinary` is not a pnpm package entry.
368
+ */
369
+ export function fleetPnpmHqLauncher(hqBinary) {
370
+ const normalized = hqBinary.replace(/\\/g, "/");
371
+ const match = /^(.*)\/pnpm\/global\/v\d+\/[^/]+\/node_modules\/@indigoai-us\/hq-cli\/dist\/index\.js$/i.exec(normalized);
372
+ return match ? `${match[1]}/pnpm/bin/hq` : "";
373
+ }
374
+ const HOT_SIGNAL_SYNC_HQ_ARGV = String.raw `def hq_argv():
375
+ if os.path.isfile(HQ):
376
+ return [NODE, HQ]
377
+ if LAUNCHER and os.path.isfile(LAUNCHER):
378
+ return [LAUNCHER]
379
+ found = shutil.which('hq')
380
+ if found:
381
+ return [found]
382
+ home = os.path.expanduser('~')
383
+ for rel in ('Library/pnpm/bin/hq', '.local/share/pnpm/hq'):
384
+ p = os.path.join(home, rel)
385
+ if os.path.isfile(p):
386
+ return [p]
387
+ raise FileNotFoundError(HQ)
388
+ `;
364
389
  export function renderFleetHotSignalSyncScript(input) {
365
390
  const plainSync = input.signalsEngine === false;
366
391
  const args = plainSync
@@ -390,9 +415,14 @@ export function renderFleetHotSignalSyncScript(input) {
390
415
  // plain script exits non-zero after a failed run (128 + N after signal N, as
391
416
  // a shell does), so the job's status is not `ok`: Fleet records a no-agent
392
417
  // job from its exit code.
418
+ const launcher = input.hqLauncher ?? fleetPnpmHqLauncher(input.hqBinary);
419
+ // HQ is often the pnpm hash folder's dist/index.js. That path dies on the
420
+ // next CLI update (feedback_614121bf). Prefer it while it exists so tests
421
+ // and `node <entry>` callers stay unchanged; otherwise run the stable
422
+ // launcher without node (it is a shell/cmd shim, not JS).
393
423
  const run = plainSync
394
424
  ? [
395
- " result = subprocess.run([NODE, HQ, *ARGS], stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8', errors='replace')",
425
+ " result = subprocess.run(hq_argv() + ARGS, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8', errors='replace')",
396
426
  " with open(LOG, 'a', encoding='utf-8') as log:",
397
427
  header,
398
428
  " log.write(result.stderr)",
@@ -409,18 +439,20 @@ export function renderFleetHotSignalSyncScript(input) {
409
439
  " with open(LOG, 'a', encoding='utf-8') as log:",
410
440
  header,
411
441
  " log.flush()",
412
- " result = subprocess.run([NODE, HQ, *ARGS], stdout=subprocess.PIPE, stderr=log, encoding='utf-8', errors='replace')",
442
+ " result = subprocess.run(hq_argv() + ARGS, stdout=subprocess.PIPE, stderr=log, encoding='utf-8', errors='replace')",
413
443
  footer,
414
444
  " sys.stdout.write(result.stdout)",
415
445
  ];
416
446
  return [
417
- plainSync ? "import json, os, re, signal, subprocess, sys, time, urllib.parse" : "import subprocess, sys, time",
447
+ plainSync ? "import json, os, re, shutil, signal, subprocess, sys, time, urllib.parse" : "import os, shutil, subprocess, sys, time",
418
448
  `NODE = ${JSON.stringify(input.nodeBinary)}`,
419
449
  `HQ = ${JSON.stringify(input.hqBinary)}`,
450
+ `LAUNCHER = ${JSON.stringify(launcher)}`,
420
451
  `ARGS = ${JSON.stringify(args)}`,
421
452
  `LOG = ${JSON.stringify(input.logFile)}`,
422
453
  "STARTED = time.localtime()",
423
454
  HOT_SIGNAL_SYNC_RUN_END,
455
+ HOT_SIGNAL_SYNC_HQ_ARGV,
424
456
  ...(plainSync ? [`FIXES = ${JSON.stringify(fixes)}`, HOT_SIGNAL_SYNC_ALERT_HELPERS] : []),
425
457
  "try:",
426
458
  ...run,
@@ -29,6 +29,52 @@ export interface FleetDaemonHost {
29
29
  * own LaunchAgents instead.
30
30
  */
31
31
  export declare function fleetBotsManagedByDaemon(host?: FleetDaemonHost): boolean;
32
+ /**
33
+ * Whether a bot handed to hq daemon now would be picked up:
34
+ * - `not-used`: the daemon does not run this Mac's bots; the runtime's own service does.
35
+ * - `running`: a live daemon holds the lock (a hosted daemon included).
36
+ * - `stopped`: the daemon's login item is installed, so bots are handed to it,
37
+ * but no daemon is running to read the request.
38
+ */
39
+ export type FleetBotDaemonState = "not-used" | "running" | "stopped";
40
+ export declare function fleetBotDaemonState(host?: FleetDaemonHost & {
41
+ alive?: (pid: number) => boolean;
42
+ }): FleetBotDaemonState;
43
+ /** The one sentence a person sees when hq daemon is off and could not be started. */
44
+ export declare function fleetDaemonStoppedMessage(name: string): string;
45
+ /** hq daemon is installed here but not running, and starting it did not bring it up. */
46
+ export declare class FleetDaemonStoppedError extends Error {
47
+ readonly expected: true;
48
+ readonly reason: "daemon-stopped";
49
+ constructor(name: string);
50
+ }
51
+ /** `hq daemon start` waits up to 15 s for the daemon itself; this bounds the whole command. */
52
+ export declare const FLEET_DAEMON_START_TIMEOUT_MS = 45000;
53
+ /** How long to look for a live daemon after `hq daemon start` returned. */
54
+ export declare const FLEET_DAEMON_LIVE_WAIT_MS = 20000;
55
+ /** Side effects of {@link ensureFleetBotDaemon}; tests replace them. */
56
+ export declare const fleetDaemonSeams: {
57
+ startDaemon: (timeoutMs: number) => {
58
+ ok: boolean;
59
+ detail: string;
60
+ };
61
+ sleep: (ms: number) => void;
62
+ startTimeoutMs: number;
63
+ liveWaitMs: number;
64
+ pollMs: number;
65
+ };
66
+ export interface EnsureFleetDaemonDeps extends FleetDaemonHost {
67
+ alive?: (pid: number) => boolean;
68
+ log?: (message: string) => void;
69
+ }
70
+ /**
71
+ * Before a bot is handed to hq daemon: make sure a daemon is running to pick
72
+ * it up. When the daemon's login item is installed but no daemon is live
73
+ * (unloaded after a failed update, for one), run `hq daemon start` and wait,
74
+ * bounded, for a live daemon. Throws {@link FleetDaemonStoppedError} when it
75
+ * still is not up, so the caller never reports a hand-off nobody will read.
76
+ */
77
+ export declare function ensureFleetBotDaemon(name: string, deps?: EnsureFleetDaemonDeps): "untouched" | "started";
32
78
  export type LaunchctlRun = (args: string[]) => {
33
79
  status: number | null;
34
80
  };
@@ -22,7 +22,9 @@ import { botsRoot } from "./paths.js";
22
22
  import { isPidAlive } from "./status.js";
23
23
  import { askDaemonToStart, askDaemonToStop, daemonUnitInstalled, hostedDaemonRunning } from "../daemon/handoff.js";
24
24
  import { daemonPaths } from "../daemon/paths.js";
25
- import { isDaemonProcess } from "../daemon/lock.js";
25
+ import { isDaemonProcess, runningDaemonPid } from "../daemon/lock.js";
26
+ import { resolveHqBinary } from "../mesh/live/daemon/install.js";
27
+ import { blockingSleep } from "../service-manager/launchd.js";
26
28
  export const FLEET_BOT_UNIT_PREFIX = "fleet-bots:";
27
29
  export function fleetBotUnitId(name) {
28
30
  return `${FLEET_BOT_UNIT_PREFIX}${name}`;
@@ -42,6 +44,97 @@ export function fleetBotsManagedByDaemon(host = {}) {
42
44
  const paths = host.paths ?? daemonPaths(home);
43
45
  return daemonUnitInstalled({ platform, home, windowsTaskName: "", windowsTaskExists: () => false }) || hostedDaemonRunning(paths);
44
46
  }
47
+ export function fleetBotDaemonState(host = {}) {
48
+ const platform = host.platform ?? process.platform;
49
+ if (platform !== "darwin")
50
+ return "not-used";
51
+ if ((host.env ?? process.env).HQ_FLEET_BOTS_SERVICE?.trim() === "runtime")
52
+ return "not-used";
53
+ const home = host.home ?? os.homedir();
54
+ const paths = host.paths ?? daemonPaths(home);
55
+ if (runningDaemonPid(paths.lockPath, host.alive ?? ((pid) => isDaemonProcess(pid))) !== null)
56
+ return "running";
57
+ return daemonUnitInstalled({ platform, home, windowsTaskName: "", windowsTaskExists: () => false }) ? "stopped" : "not-used";
58
+ }
59
+ /** The one sentence a person sees when hq daemon is off and could not be started. */
60
+ export function fleetDaemonStoppedMessage(name) {
61
+ const who = name.trim() || "the bot";
62
+ return (`HQ's background service (hq daemon) is off on this Mac and could not be turned on, so ${who} can't start. ` +
63
+ "Try again, or run `hq daemon start` and check `hq daemon logs`; restart your Mac if it keeps happening.");
64
+ }
65
+ /** hq daemon is installed here but not running, and starting it did not bring it up. */
66
+ export class FleetDaemonStoppedError extends Error {
67
+ expected = true;
68
+ reason = "daemon-stopped";
69
+ constructor(name) {
70
+ super(fleetDaemonStoppedMessage(name));
71
+ this.name = "FleetDaemonStoppedError";
72
+ }
73
+ }
74
+ /** `hq daemon start` waits up to 15 s for the daemon itself; this bounds the whole command. */
75
+ export const FLEET_DAEMON_START_TIMEOUT_MS = 45_000;
76
+ /** How long to look for a live daemon after `hq daemon start` returned. */
77
+ export const FLEET_DAEMON_LIVE_WAIT_MS = 20_000;
78
+ const FLEET_DAEMON_LIVE_POLL_MS = 500;
79
+ /** Run `hq daemon start` with this CLI, bounded. Never throws. */
80
+ function defaultStartDaemon(timeoutMs) {
81
+ let entry;
82
+ try {
83
+ entry = resolveHqBinary();
84
+ }
85
+ catch (err) {
86
+ return { ok: false, detail: err.message };
87
+ }
88
+ const r = spawnSync(process.execPath, [entry, "daemon", "start"], {
89
+ encoding: "utf8",
90
+ windowsHide: true,
91
+ timeout: timeoutMs,
92
+ stdio: ["ignore", "pipe", "pipe"],
93
+ env: { ...process.env, HQ_NO_UPDATE_CHECK: "1", HQ_NO_ENSURE_HQ_DESKTOP: "1" },
94
+ });
95
+ if (r.error)
96
+ return { ok: false, detail: r.error.message };
97
+ const detail = (r.stderr || r.stdout || "").trim().replace(/\s+/g, " ").slice(0, 400);
98
+ return { ok: r.status === 0, detail: r.status === 0 ? detail : `exit ${r.status ?? r.signal}: ${detail}` };
99
+ }
100
+ /** Side effects of {@link ensureFleetBotDaemon}; tests replace them. */
101
+ export const fleetDaemonSeams = {
102
+ startDaemon: defaultStartDaemon,
103
+ sleep: blockingSleep,
104
+ startTimeoutMs: FLEET_DAEMON_START_TIMEOUT_MS,
105
+ liveWaitMs: FLEET_DAEMON_LIVE_WAIT_MS,
106
+ pollMs: FLEET_DAEMON_LIVE_POLL_MS,
107
+ };
108
+ /**
109
+ * Before a bot is handed to hq daemon: make sure a daemon is running to pick
110
+ * it up. When the daemon's login item is installed but no daemon is live
111
+ * (unloaded after a failed update, for one), run `hq daemon start` and wait,
112
+ * bounded, for a live daemon. Throws {@link FleetDaemonStoppedError} when it
113
+ * still is not up, so the caller never reports a hand-off nobody will read.
114
+ */
115
+ export function ensureFleetBotDaemon(name, deps = {}) {
116
+ const home = deps.home ?? os.homedir();
117
+ const paths = deps.paths ?? daemonPaths(home);
118
+ const alive = deps.alive ?? ((pid) => isDaemonProcess(pid));
119
+ const host = { platform: deps.platform, home, paths, env: deps.env, alive };
120
+ if (fleetBotDaemonState(host) !== "stopped")
121
+ return "untouched";
122
+ deps.log?.("hq daemon runs this Mac's bots but is not running; starting it (hq daemon start)");
123
+ const started = fleetDaemonSeams.startDaemon(fleetDaemonSeams.startTimeoutMs);
124
+ if (!started.ok)
125
+ deps.log?.(`hq daemon start failed: ${started.detail}`);
126
+ for (let waited = 0;; waited += fleetDaemonSeams.pollMs) {
127
+ if (runningDaemonPid(paths.lockPath, alive) !== null) {
128
+ deps.log?.("hq daemon is running again");
129
+ return "started";
130
+ }
131
+ if (waited >= fleetDaemonSeams.liveWaitMs)
132
+ break;
133
+ fleetDaemonSeams.sleep(fleetDaemonSeams.pollMs);
134
+ }
135
+ deps.log?.(`hq daemon did not come up within ${Math.round(fleetDaemonSeams.liveWaitMs / 1000)}s; not handing ${name || "the bot"} to it`);
136
+ throw new FleetDaemonStoppedError(name);
137
+ }
45
138
  function defaultLaunchctl(args) {
46
139
  return spawnSync("launchctl", args, { encoding: "utf8", windowsHide: true, timeout: 15_000 });
47
140
  }
@@ -196,6 +289,11 @@ export function controlFleetBot(agentUid, action, deps = {}) {
196
289
  return controlFleetLocalBot(agentUid, action, deps);
197
290
  const unit = fleetBotUnitId(bot.name);
198
291
  const agent = { home, uid: deps.uid, launchctl: deps.launchctl };
292
+ // A start request a stopped daemon never reads leaves the bot offline while
293
+ // this reports success. Bring the daemon up first, or fail before changing anything.
294
+ if (action === "install" || action === "start" || action === "restart") {
295
+ ensureFleetBotDaemon(bot.name, { platform, home, paths, env: deps.env, ...(deps.alive ? { alive: deps.alive } : {}) });
296
+ }
199
297
  switch (action) {
200
298
  case "install":
201
299
  case "start": {
@@ -1,8 +1,13 @@
1
- import { type BotEngineMetadata } from "./config.js";
1
+ import { type BotEngineMetadata, type BotRuntimeId } from "./config.js";
2
2
  import type { BotMachineCreds } from "./creds.js";
3
3
  import { type FleetPython } from "./fleet-python.js";
4
4
  import { vaultApiFetch } from "../../utils/vault-api.js";
5
5
  import type { LocalBotPromotionRuntime } from "./promote.js";
6
+ export interface FleetLocalEnvironmentArtifact {
7
+ name: string;
8
+ sha256: string;
9
+ size: number;
10
+ }
6
11
  export interface FleetLocalReleasePin {
7
12
  repository: string;
8
13
  tag: string;
@@ -14,12 +19,14 @@ export interface FleetLocalReleasePin {
14
19
  manifestSha256: string;
15
20
  signatureSha256: string;
16
21
  runtimeCommit: string;
22
+ environmentArtifacts?: Record<string, FleetLocalEnvironmentArtifact>;
17
23
  }
18
24
  export interface FleetLocalReleaseFiles {
19
25
  archive: Buffer;
20
26
  runtimeArchive: Buffer;
21
27
  manifest: Buffer;
22
28
  signature: Buffer;
29
+ wheelhouse?: string;
23
30
  }
24
31
  export interface FleetLocalInstallation {
25
32
  release: FleetLocalReleasePin;
@@ -29,6 +36,8 @@ export interface FleetLocalInstallation {
29
36
  manifest: string;
30
37
  signature: string;
31
38
  engine: BotEngineMetadata;
39
+ wheelhouse?: string;
40
+ environmentPlatform?: string;
32
41
  }
33
42
  export interface FleetLocalProfile {
34
43
  schemaVersion: 1;
@@ -69,6 +78,8 @@ export interface FleetLocalInstallDeps {
69
78
  /** How long a download may go without bytes before it is resumed (tests). */
70
79
  downloadStallMs?: number;
71
80
  allowFileLinks?: boolean;
81
+ platform?: NodeJS.Platform;
82
+ arch?: string;
72
83
  }
73
84
  export interface FleetLocalProfileInput {
74
85
  agentUid: string;
@@ -244,6 +255,9 @@ export declare const FLEET_RELEASE_POINTER_FILE_ENV = "HQ_FLEET_RELEASE_POINTER_
244
255
  export declare function fleetReleasePointerFileOverride(env?: NodeJS.ProcessEnv): string | null;
245
256
  export declare function readLocalFleetReleasePointer(file: string, now?: number): FleetLocalReleasePointer;
246
257
  export declare function parseFleetLocalReleasePin(value: unknown): FleetLocalReleasePin | null;
258
+ export declare function fleetEnvironmentPlatform(platform?: NodeJS.Platform, arch?: string): string;
259
+ export declare function releaseWheelhouse(release: FleetLocalReleasePin, platform: string): FleetLocalEnvironmentArtifact | null;
260
+ export declare function verifyFleetLocalWheelhouse(file: string, artifact: FleetLocalEnvironmentArtifact, manifest: Buffer, platform: string, release: FleetLocalReleasePin): void;
247
261
  export declare function parseFleetLocalReleasePointer(body: unknown, now?: number): FleetLocalReleasePointer | null;
248
262
  export declare function chooseFleetLocalTargetRelease(pointer: FleetLocalReleasePointer | null, compiled?: FleetLocalReleasePin, cliVersion?: string): FleetLocalTargetRelease;
249
263
  export declare function fetchFleetLocalReleasePointer(deps?: {
@@ -373,6 +387,14 @@ export declare function writeFleetLocalFirstStart(profileDir: string, firstStart
373
387
  intro?: string;
374
388
  kickoff?: string;
375
389
  }): string;
390
+ export interface FleetLocalSignInNeeded {
391
+ runtime: BotRuntimeId;
392
+ login: "claude-code" | "codex-cli" | "grok-cli" | "bot" | null;
393
+ since: string | null;
394
+ }
395
+ export declare function fleetLocalSignInNeededPath(agentUid: string, deps?: Pick<FleetLocalControlDeps, "fleetHome">): string;
396
+ export declare function readFleetLocalSignInNeeded(agentUid: string, deps?: Pick<FleetLocalControlDeps, "fleetHome">): FleetLocalSignInNeeded | null;
397
+ export declare function readFleetLocalIntroSentAt(agentUid: string, deps?: Pick<FleetLocalControlDeps, "fleetHome">): string | null;
376
398
  export declare function writeFleetLocalSoul(agentUid: string, systemPrompt: string, deps?: Pick<FleetLocalControlDeps, "fleetHome">): string;
377
399
  /**
378
400
  * The pinned runtime refuses a persona file that trips its context-file
@@ -412,6 +434,12 @@ export declare function fleetLocalBusyReason(agentUid: string, deps?: Pick<Fleet
412
434
  export declare function refreshFleetLocalInstructions(agentUid: string, systemPrompt: string, deps?: FleetLocalControlDeps): string;
413
435
  /** Last few non-empty stderr lines of a failed child process, trimmed for an error message. */
414
436
  export declare function stderrTail(error: unknown): string;
437
+ export declare const FLEET_WHEELHOUSE_EXIT: {
438
+ readonly installed: 0;
439
+ readonly verificationFailed: 2;
440
+ readonly unavailable: 3;
441
+ readonly installFailed: 4;
442
+ };
415
443
  /** A FleetLocalSpawn backed by an execFileSync-shaped runner (stderr is only known on failure). */
416
444
  export declare function spawnFromRun(run: FleetLocalExec): FleetLocalSpawn;
417
445
  /**
@@ -449,6 +477,10 @@ export interface FleetLocalProviderAuthStatus {
449
477
  * not installed, or the helper failed.
450
478
  */
451
479
  export declare function fleetLocalProviderAuthStatus(agentUid: string, provider: string, deps?: FleetLocalControlDeps): FleetLocalProviderAuthStatus | null;
480
+ export type FleetLocalAsyncRun = (executable: string, args: string[], options: Record<string, unknown>) => Promise<string>;
481
+ export declare function fleetLocalProviderAuthStatusAsync(agentUid: string, provider: string, deps?: FleetLocalControlDeps & {
482
+ runAsync?: FleetLocalAsyncRun;
483
+ }): Promise<FleetLocalProviderAuthStatus | null>;
452
484
  /**
453
485
  * Sign a bot in from a login already on this computer, without a browser:
454
486
  * the helper imports the Codex CLI login (CODEX_HOME, else ~/.codex) or