@indigoai-us/hq-cli 5.345.208 → 5.345.211

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 (133) hide show
  1. package/CHANGELOG.md +106 -0
  2. package/assets/scaffold/core/scripts/derive-trigger-facts.sh +22 -3
  3. package/assets/scaffold/core/scripts/lib/trigger-fact-text.awk +152 -41
  4. package/dist/command-catalog.generated.d.ts +33 -8
  5. package/dist/command-catalog.generated.js +40 -8
  6. package/dist/command-registration-plan.d.ts +2 -2
  7. package/dist/command-registration-plan.js +1 -1
  8. package/dist/commands/access.js +11 -5
  9. package/dist/commands/agents.d.ts +8 -0
  10. package/dist/commands/agents.js +5 -0
  11. package/dist/commands/bot.d.ts +8 -0
  12. package/dist/commands/bot.js +67 -7
  13. package/dist/commands/channels.js +4 -0
  14. package/dist/commands/cloud.d.ts +83 -2
  15. package/dist/commands/cloud.js +161 -31
  16. package/dist/commands/company.d.ts +9 -0
  17. package/dist/commands/company.js +44 -14
  18. package/dist/commands/core-checkpoint-native.js +21 -0
  19. package/dist/commands/core-derive-trigger-facts-native.d.ts +1 -0
  20. package/dist/commands/core-derive-trigger-facts-native.js +75 -14
  21. package/dist/commands/core-generate-workers-registry-fast.d.ts +1 -1
  22. package/dist/commands/core-generate-workers-registry-fast.js +7 -1
  23. package/dist/commands/core-job-run-native.d.ts +8 -0
  24. package/dist/commands/core-job-run-native.js +11 -3
  25. package/dist/commands/core-jobs-native.js +1 -1
  26. package/dist/commands/core-register-project-native.js +31 -1
  27. package/dist/commands/core-scan-packages-fast.d.ts +1 -1
  28. package/dist/commands/core-scan-packages-fast.js +8 -1
  29. package/dist/commands/core-work-mesh-bind-trusted-native.d.ts +14 -2
  30. package/dist/commands/core-work-mesh-bind-trusted-native.js +62 -8
  31. package/dist/commands/core.js +12 -3
  32. package/dist/commands/dm-attach.d.ts +10 -0
  33. package/dist/commands/dm-attach.js +33 -5
  34. package/dist/commands/integrations-connect.d.ts +16 -0
  35. package/dist/commands/integrations-connect.js +70 -6
  36. package/dist/commands/lanes-session-start.d.ts +17 -0
  37. package/dist/commands/lanes-session-start.js +281 -13
  38. package/dist/commands/lanes-watch.js +11 -3
  39. package/dist/commands/lanes.d.ts +4 -0
  40. package/dist/commands/lanes.js +95 -22
  41. package/dist/commands/library.d.ts +10 -0
  42. package/dist/commands/library.js +30 -3
  43. package/dist/commands/meetings.d.ts +42 -0
  44. package/dist/commands/meetings.js +157 -12
  45. package/dist/commands/mesh.js +3 -0
  46. package/dist/commands/monitor.d.ts +6 -0
  47. package/dist/commands/monitor.js +29 -19
  48. package/dist/commands/onboard.js +8 -1
  49. package/dist/commands/sources.js +7 -3
  50. package/dist/index.js +9 -0
  51. package/dist/lanes-monitor-check-argv.d.ts +1 -1
  52. package/dist/lanes-monitor-check-argv.js +2 -2
  53. package/dist/lanes-session-start-argv.d.ts +4 -1
  54. package/dist/lanes-session-start-argv.js +5 -2
  55. package/dist/lib/bot/fleet-daemon.d.ts +101 -0
  56. package/dist/lib/bot/fleet-daemon.js +227 -0
  57. package/dist/lib/bot/fleet-local.d.ts +26 -0
  58. package/dist/lib/bot/fleet-local.js +51 -2
  59. package/dist/lib/bot/index.d.ts +1 -0
  60. package/dist/lib/bot/index.js +1 -0
  61. package/dist/lib/bot/jobs/hot-signal-sync.d.ts +4 -0
  62. package/dist/lib/bot/jobs/hot-signal-sync.js +8 -1
  63. package/dist/lib/bot/log.js +3 -1
  64. package/dist/lib/bot/probe.js +2 -0
  65. package/dist/lib/bot/run.js +28 -3
  66. package/dist/lib/bot/runtime-failure.d.ts +4 -2
  67. package/dist/lib/bot/runtime-failure.js +9 -1
  68. package/dist/lib/bot/status.d.ts +17 -0
  69. package/dist/lib/bot/status.js +53 -2
  70. package/dist/lib/capacity/collectors/claude-oauth.d.ts +5 -5
  71. package/dist/lib/capacity/collectors/claude-oauth.js +6 -6
  72. package/dist/lib/core-utils/native-scaffold-help.d.ts +16 -0
  73. package/dist/lib/core-utils/native-scaffold-help.js +26 -0
  74. package/dist/lib/core-utils/session-company.d.ts +25 -8
  75. package/dist/lib/core-utils/session-company.js +59 -17
  76. package/dist/lib/daemon/catalog.d.ts +34 -1
  77. package/dist/lib/daemon/catalog.js +42 -3
  78. package/dist/lib/daemon/run.d.ts +5 -4
  79. package/dist/lib/daemon/run.js +40 -16
  80. package/dist/lib/daemon/server.js +26 -7
  81. package/dist/lib/daemon/supervisor.d.ts +2 -0
  82. package/dist/lib/daemon/supervisor.js +60 -1
  83. package/dist/lib/daemon/tools.js +17 -1
  84. package/dist/lib/db/sqlite-binding.js +2 -1
  85. package/dist/lib/doctor/checks/bots.d.ts +2 -0
  86. package/dist/lib/doctor/checks/bots.js +11 -0
  87. package/dist/lib/doctor/checks/runtime-health.js +3 -2
  88. package/dist/lib/doctor/checks/work-context.js +5 -2
  89. package/dist/lib/hook-engine/resolve.d.ts +1 -1
  90. package/dist/lib/hook-engine/resolve.js +4 -1
  91. package/dist/lib/hot-channels/adapters/meeting-providers.d.ts +2 -0
  92. package/dist/lib/hot-channels/adapters/meeting-providers.js +13 -2
  93. package/dist/lib/lanes/index.d.ts +1 -1
  94. package/dist/lib/lanes/index.js +1 -1
  95. package/dist/lib/lanes/monitor.d.ts +14 -0
  96. package/dist/lib/lanes/monitor.js +51 -10
  97. package/dist/lib/lanes/outpost-dispatch.d.ts +3 -0
  98. package/dist/lib/lanes/outpost-dispatch.js +1 -0
  99. package/dist/lib/lanes/store.d.ts +1 -1
  100. package/dist/lib/lanes/store.js +2 -1
  101. package/dist/lib/mesh/client.js +7 -1
  102. package/dist/lib/mesh/live/backfill-held.d.ts +3 -0
  103. package/dist/lib/mesh/live/backfill-held.js +167 -7
  104. package/dist/lib/mesh/live/flush.d.ts +7 -0
  105. package/dist/lib/mesh/live/flush.js +10 -1
  106. package/dist/lib/monitor.d.ts +9 -0
  107. package/dist/lib/monitor.js +33 -7
  108. package/dist/lib/onboarding/orchestrator.js +269 -132
  109. package/dist/lib/onboarding/types.d.ts +2 -0
  110. package/dist/lib/scaffold-cli-floor.js +2 -1
  111. package/dist/lib/signals/failure-alert.js +3 -1
  112. package/dist/lib/sync-core/reconcile.js +15 -11
  113. package/dist/lib/work-context/organize.d.ts +6 -0
  114. package/dist/lib/work-context/organize.js +28 -0
  115. package/dist/lib/work-context/paths.d.ts +9 -0
  116. package/dist/lib/work-context/paths.js +15 -0
  117. package/dist/lib/work-context/prd-sync.js +2 -1
  118. package/dist/runners-alias.d.ts +54 -0
  119. package/dist/runners-alias.js +86 -0
  120. package/dist/utils/install-tree-torn.js +5 -3
  121. package/dist/utils/npm-install-flags.d.ts +27 -0
  122. package/dist/utils/npm-install-flags.js +68 -0
  123. package/dist/utils/package-use-lease.js +1 -1
  124. package/dist/utils/qmd-native-binding-error.js +2 -1
  125. package/dist/utils/self-update.js +2 -1
  126. package/dist/utils/staged-install.js +2 -1
  127. package/dist/utils/staged-npm-install.js +2 -1
  128. package/dist/utils/upload-author.d.ts +2 -1
  129. package/dist/utils/upload-author.js +9 -5
  130. package/dist/utils/version-check.js +2 -1
  131. package/dist/utils/version-gate.js +7 -6
  132. package/package.json +7 -7
  133. package/scripts/install-hook-engine.mjs +7 -3
@@ -2104,10 +2104,12 @@ async function runContextOrganize(opts) {
2104
2104
  return;
2105
2105
  }
2106
2106
  let postOrganize;
2107
+ let submitFetchCandidates;
2107
2108
  if (!opts.untracked && !opts.offline) {
2108
2109
  try {
2109
2110
  const token = await requireToken();
2110
2111
  postOrganize = createOrganizePoster({ token });
2112
+ submitFetchCandidates = createCandidatesFetcher({ token });
2111
2113
  }
2112
2114
  catch {
2113
2115
  fail("Cognito session required to submit organize (server receipt only)");
@@ -2122,6 +2124,7 @@ async function runContextOrganize(opts) {
2122
2124
  createTaskTitle: opts.createTask,
2123
2125
  untracked: opts.untracked,
2124
2126
  postOrganize,
2127
+ fetchCandidates: submitFetchCandidates,
2125
2128
  });
2126
2129
  if (!submitted.ok) {
2127
2130
  console.error(chalk.red(`${submitted.errorCode ?? "ORGANIZE_FAILED"}: ${submitted.message ?? "organize failed"}`));
@@ -31,6 +31,12 @@ export declare function invokeLaneMonitorMessage(hqRoot: string, meta: MonitorMe
31
31
  outcome: string;
32
32
  }>;
33
33
  export declare function deliverNormalEvent(hqRoot: string, meta: MonitorMetadata, state: MonitorState, rawText: string, inProcess?: MonitorLaneMessageApi): Promise<MonitorState>;
34
+ /**
35
+ * One supervisor tick's check-in. Listing every monitor is only worth doing when
36
+ * this monitor's own check-in may be due; every tick still refreshes `state` from
37
+ * disk, because a check-in sent by a sibling's supervisor can advance it.
38
+ */
39
+ export declare function monitorCheckin(hqRoot: string, meta: MonitorMetadata, state: MonitorState, inProcess?: MonitorLaneMessageApi): Promise<MonitorState>;
34
40
  export interface RunSupervisorDeps {
35
41
  resolveRoot?: () => string;
36
42
  monitorEnabled?: typeof monitorEnabled;
@@ -8,7 +8,7 @@ import { LanesError } from "../lib/lanes/errors.js";
8
8
  import { readToolActivity, tryReadLane } from "../lib/lanes/index.js";
9
9
  import { appendDropboxMessageAtPath, drainDropboxAtPath, formatDropboxMessages } from "../lib/lanes/dropbox.js";
10
10
  import { dispatchLaneDelivery } from "../lib/lanes/delivery-core.js";
11
- import { MONITOR_FLAG, MONITOR_FLAG_DEFAULT, MONITOR_DEFAULT_CHECKIN_MS, MONITOR_DEFAULT_TIMEOUT_MS, MONITOR_POLL_INTERVAL_MS, MONITOR_BATCH_WINDOW_MS, MONITOR_MAX_EVENTS_PER_WINDOW, MONITOR_MAX_FLOOD_WINDOWS, MONITOR_RATE_WINDOW_MS, MONITOR_SCHEMA_VERSION, monitorDir, monitorSessionDir, monitorSessionHasActiveMarkerForOwner, monitorSessionHasActiveMarkers, monitorSessionHasWork, monitorSessionInboxHasEvents, monitorTargetKey, assertMonitorTimeoutCompatibility, parseMonitorDuration, parseMonitorTarget, detectMonitorTarget, findNearestMonitorRuntime, makeMonitorId, recordMonitorTargetDelivery, recordMonitorTargetActivity, recordMonitorTargetDeliveryAtPath, runMonitorCheckinTick, readMonitorPidLiveness, recordHookSessionMapping, resolveMappedSessionId, parseHookSessionId, withMonitorTargetLock, nextMonitorEventSequence, recordMonitorEventState, requestMonitorStop, nextMonitorTimeoutDelay } from "../lib/monitor.js";
11
+ import { MONITOR_FLAG, MONITOR_FLAG_DEFAULT, MONITOR_DEFAULT_CHECKIN_MS, MONITOR_DEFAULT_TIMEOUT_MS, MONITOR_POLL_INTERVAL_MS, MONITOR_BATCH_WINDOW_MS, MONITOR_MAX_EVENTS_PER_WINDOW, MONITOR_MAX_FLOOD_WINDOWS, MONITOR_RATE_WINDOW_MS, MONITOR_SCHEMA_VERSION, monitorDir, monitorSessionDir, monitorSessionHasActiveMarkerForOwner, monitorSessionHasActiveMarkers, monitorSessionHasWork, monitorSessionInboxHasEvents, monitorTargetKey, assertMonitorTimeoutCompatibility, parseMonitorDuration, parseMonitorTarget, detectMonitorTarget, findNearestMonitorRuntime, makeMonitorId, recordMonitorTargetDelivery, recordMonitorTargetActivity, recordMonitorTargetDeliveryAtPath, monitorCheckinMayBeDue, runMonitorCheckinTick, readMonitorPidLiveness, recordHookSessionMapping, resolveMappedSessionId, parseHookSessionId, withMonitorTargetLock, nextMonitorEventSequence, recordMonitorEventState, requestMonitorStop, nextMonitorTimeoutDelay } from "../lib/monitor.js";
12
12
  import { readProcStarttime } from "../lib/lanes/spawn.js";
13
13
  import { createMonitorLaneMessageApi } from "./lanes.js";
14
14
  import { releaseCurrentPackageUseLease, releasePackageUseLeaseAfterResidentPreload } from "../utils/package-use-lease.js";
@@ -533,28 +533,38 @@ function targetEnded(hqRoot, meta) {
533
533
  const lane = tryReadLane(hqRoot, meta.target.laneId);
534
534
  return !lane || ["killed", "cancelled", "failed"].includes(lane.state);
535
535
  }
536
- async function monitorCheckin(hqRoot, meta, state, inProcess) {
536
+ function targetCanWake(hqRoot, target) {
537
+ if (target.kind === "session")
538
+ return target.provider === "claude";
539
+ const lane = tryReadLane(hqRoot, target.laneId);
540
+ return lane !== null && (lane.state === "running" ||
541
+ ((lane.state === "done" || lane.state === "blocked") && Boolean(lane.provider_session_id)));
542
+ }
543
+ function laneToolActivityAt(hqRoot, target) {
544
+ if (target.kind !== "lane")
545
+ return null;
546
+ const activityAt = readToolActivity(hqRoot, target.laneId)?.at;
547
+ if (!activityAt)
548
+ return null;
549
+ const parsed = Date.parse(activityAt);
550
+ return Number.isFinite(parsed) ? parsed : null;
551
+ }
552
+ /**
553
+ * One supervisor tick's check-in. Listing every monitor is only worth doing when
554
+ * this monitor's own check-in may be due; every tick still refreshes `state` from
555
+ * disk, because a check-in sent by a sibling's supervisor can advance it.
556
+ */
557
+ export async function monitorCheckin(hqRoot, meta, state, inProcess) {
558
+ const mayBeDue = monitorCheckinMayBeDue(hqRoot, meta.target_key, meta.checkin_ms, Date.now(), laneToolActivityAt(hqRoot, meta.target));
559
+ if (!mayBeDue || !targetCanWake(hqRoot, meta.target))
560
+ return readJson(statePath(hqRoot, meta.monitor_id)) ?? state;
537
561
  await runMonitorCheckinTick(hqRoot, meta.target_key, {
538
562
  now: () => new Date(),
539
563
  isWakeable: async (targetKey) => {
540
564
  const monitor = activeTargetMeta(hqRoot, targetKey)[0];
541
- if (!monitor)
542
- return false;
543
- if (monitor.target.kind === "session")
544
- return monitor.target.provider === "claude";
545
- const lane = tryReadLane(hqRoot, monitor.target.laneId);
546
- return lane !== null && (lane.state === "running" ||
547
- ((lane.state === "done" || lane.state === "blocked") && Boolean(lane.provider_session_id)));
548
- },
549
- readTargetActivityAt: (targetKey) => {
550
- if (meta.target.kind !== "lane" || targetKey !== meta.target_key)
551
- return null;
552
- const activityAt = readToolActivity(hqRoot, meta.target.laneId)?.at;
553
- if (!activityAt)
554
- return null;
555
- const parsed = Date.parse(activityAt);
556
- return Number.isFinite(parsed) ? parsed : null;
565
+ return monitor !== undefined && targetCanWake(hqRoot, monitor.target);
557
566
  },
567
+ readTargetActivityAt: (targetKey) => (targetKey === meta.target_key ? laneToolActivityAt(hqRoot, meta.target) : null),
558
568
  deliver: async (text) => {
559
569
  const monitor = activeTargetMeta(hqRoot, meta.target_key)[0];
560
570
  if (!monitor)
@@ -933,7 +943,7 @@ export function registerMonitorCommand(parent) {
933
943
  .description("Start a detached monitor script")
934
944
  .requiredOption("--description <text>", "Why this monitor exists")
935
945
  .option("--command <sh>", "Run one shell command under bash -c")
936
- .option("--timeout <duration>", "Deadline; bare numbers are milliseconds")
946
+ .option("--timeout <duration>", "Deadline; default 30m; bare numbers are milliseconds")
937
947
  .option("--persistent", "Run until the script exits, the target ends, or stopped")
938
948
  .option("--target <target>", "lane:<id> or session:<provider>:<session-id>")
939
949
  .option("--checkin <duration|off>", "Per-target check-in interval; defaults to 55m")
@@ -168,7 +168,14 @@ export function registerOnboardCommand(program) {
168
168
  checkpoint,
169
169
  ownedPersonUids,
170
170
  });
171
- if (check.kind === "mismatch") {
171
+ if (check.kind === "mismatch" && ownedPersonUids.length > 0) {
172
+ // feedback_a169f6dc: the orchestrator now re-links the run to the
173
+ // person record this sign-in owns, so resume can finish instead
174
+ // of stopping at the membership step.
175
+ console.warn(chalk.yellow(` The saved onboarding checkpoint names person ${check.personUid}, which belongs to another sign-in. ` +
176
+ `Continuing with your current sign-in's person record; the company and membership steps run again under it.`));
177
+ }
178
+ else if (check.kind === "mismatch") {
172
179
  console.error(chalk.red(`\n✗ Resume blocked:\n\n${check.message}`));
173
180
  process.exit(1);
174
181
  }
@@ -451,9 +451,11 @@ async function meetingIdentities(input, session, email) {
451
451
  */
452
452
  export async function runCompanyHotChannelSync(input) {
453
453
  assertSafeSegment(input.company, "company");
454
+ // A sub-only upload author (machine token with no email) has no person key
455
+ // for the hot-channel audience, so it is treated as not signed in.
454
456
  const author = resolveUploadAuthor();
455
- const session = author ? await signedInSession(input.company) : null;
456
- if (!author || !session)
457
+ const session = author?.email ? await signedInSession(input.company) : null;
458
+ if (!author?.email || !session)
457
459
  return signInReport();
458
460
  const vaultRoot = path.join(input.hqRoot, "companies", input.company);
459
461
  const personKey = audienceKey([author.email]);
@@ -694,7 +696,9 @@ export async function runSignalsRedo(options, overrides = {}) {
694
696
  const channels = [...new Set([...selection.pending.keys(), ...selection.worklist.keys()])];
695
697
  if (!report.dryRun && channels.length > 0) {
696
698
  const author = overrides.author !== undefined ? overrides.author : resolveUploadAuthor();
697
- if (!author)
699
+ // A sub-only author (machine token with no email) has no person key for
700
+ // the hot-channel lock, so it is treated as not signed in.
701
+ if (!author?.email)
698
702
  return fail(`${SIGN_IN_PROMPT} (the run takes your hot-channel sync lock)`, 1);
699
703
  const lock = await acquireSyncLock(vaultRoot, audienceKey([author.email]), overrides.now ? { now: overrides.now } : {});
700
704
  if (!lock)
package/dist/index.js CHANGED
@@ -17,6 +17,7 @@ import { installWindowsHideDefault } from "./utils/windows-hide-default.js";
17
17
  import { fileURLToPath } from "node:url";
18
18
  import { parseMonitorCheckFastRequest } from "./lanes-monitor-check-argv.js";
19
19
  import { isLaneSessionStartFastRequest } from "./lanes-session-start-argv.js";
20
+ import { writeLanesAliasDeprecationForArgv } from "./runners-alias.js";
20
21
  import { createRequire } from "node:module";
21
22
  import { hookEnginePathArgs, runHookEnginePath } from "./hook-engine-path.js";
22
23
  function cygpathMixedPath(value) {
@@ -225,6 +226,14 @@ function dispatchCliRoutes() {
225
226
  process.argv = normalizeCorePathOperands(process.argv, "win32", cygpathMixedPath);
226
227
  }
227
228
  const versionRequest = isVersionRequest(process.argv);
229
+ // `hq lanes` is the deprecated alias of `hq runners`. Every route below
230
+ // (catalog help, the session-start and monitor-check fast routes, and the
231
+ // full command graph) shares this one stderr line; stdout is untouched. It
232
+ // prints only for a person at a terminal, never for hook-run subcommands,
233
+ // `--json`, or output that is not a terminal: HQ core's hooks fail on any
234
+ // stderr.
235
+ if (!versionRequest)
236
+ writeLanesAliasDeprecationForArgv(process.argv);
228
237
  const helpRequest = !versionRequest && isCommandHelpRequest(process.argv);
229
238
  const parsedFastCore = versionRequest || helpRequest ? null : parseFastCore(process.argv);
230
239
  const monitorRequest = versionRequest || helpRequest ? null : parseMonitorCheckFastRequest(process.argv);
@@ -7,6 +7,6 @@ export interface MonitorCheckFastRequest {
7
7
  engine?: string;
8
8
  json: boolean;
9
9
  }
10
- /** Exactly `hq lanes monitor-check --session <id> [--engine <e>] [--json]`. */
10
+ /** Exactly `hq runners|lanes monitor-check --session <id> [--engine <e>] [--json]`. */
11
11
  export declare function parseMonitorCheckFastRequest(argv: readonly string[]): MonitorCheckFastRequest | null;
12
12
  //# sourceMappingURL=lanes-monitor-check-argv.d.ts.map
@@ -3,9 +3,9 @@
3
3
  * Imported statically by src/index.ts, so it must not import anything.
4
4
  */
5
5
  const SAFE_SESSION_ID = /^[A-Za-z0-9._:-]{1,200}$/u;
6
- /** Exactly `hq lanes monitor-check --session <id> [--engine <e>] [--json]`. */
6
+ /** Exactly `hq runners|lanes monitor-check --session <id> [--engine <e>] [--json]`. */
7
7
  export function parseMonitorCheckFastRequest(argv) {
8
- if (argv[2] !== "lanes" || argv[3] !== "monitor-check")
8
+ if ((argv[2] !== "runners" && argv[2] !== "lanes") || argv[3] !== "monitor-check")
9
9
  return null;
10
10
  let sessionId;
11
11
  let engine;
@@ -2,6 +2,9 @@
2
2
  * Dependency-free argv matcher for the `hq lanes session-start` fast route.
3
3
  * Imported statically by src/index.ts, so it must not import anything.
4
4
  */
5
- /** Exactly `hq lanes session-start` with no options (the SessionStart hook form). */
5
+ /**
6
+ * Exactly `hq runners session-start` or the deprecated `hq lanes session-start`
7
+ * alias, with no options (the SessionStart hook form).
8
+ */
6
9
  export declare function isLaneSessionStartFastRequest(argv: readonly string[]): boolean;
7
10
  //# sourceMappingURL=lanes-session-start-argv.d.ts.map
@@ -2,8 +2,11 @@
2
2
  * Dependency-free argv matcher for the `hq lanes session-start` fast route.
3
3
  * Imported statically by src/index.ts, so it must not import anything.
4
4
  */
5
- /** Exactly `hq lanes session-start` with no options (the SessionStart hook form). */
5
+ /**
6
+ * Exactly `hq runners session-start` or the deprecated `hq lanes session-start`
7
+ * alias, with no options (the SessionStart hook form).
8
+ */
6
9
  export function isLaneSessionStartFastRequest(argv) {
7
- return argv.length === 4 && argv[2] === "lanes" && argv[3] === "session-start";
10
+ return argv.length === 4 && (argv[2] === "runners" || argv[2] === "lanes") && argv[3] === "session-start";
8
11
  }
9
12
  //# sourceMappingURL=lanes-session-start-argv.js.map
@@ -0,0 +1,101 @@
1
+ /**
2
+ * HQ Fleet bots under `hq daemon` on macOS.
3
+ *
4
+ * The HQ Fleet Runtime registers each bot's gateway as its own LaunchAgent
5
+ * whose program is the runtime's `python`. macOS reports every such login
6
+ * item as a new background item from an unknown developer. On a Mac that runs
7
+ * `hq daemon` (one login item, registered through the HQ app), the daemon runs
8
+ * the gateways itself as `fleet-bots:<name>` units instead, and any LaunchAgent
9
+ * the runtime left behind is unloaded and deleted.
10
+ *
11
+ * Other platforms, and a Mac without `hq daemon`, keep the runtime's own
12
+ * service path.
13
+ */
14
+ import { type BotConfig } from "./config.js";
15
+ import { type FleetLocalControlDeps, type FleetLocalServiceAction } from "./fleet-local.js";
16
+ import type { FleetBotPlan } from "../daemon/catalog.js";
17
+ import { type DaemonPaths } from "../daemon/paths.js";
18
+ export declare const FLEET_BOT_UNIT_PREFIX = "fleet-bots:";
19
+ export declare function fleetBotUnitId(name: string): string;
20
+ export interface FleetDaemonHost {
21
+ platform?: NodeJS.Platform;
22
+ home?: string;
23
+ paths?: DaemonPaths;
24
+ env?: NodeJS.ProcessEnv;
25
+ }
26
+ /**
27
+ * `hq daemon` runs this Mac's HQ Fleet bots: it is installed here, or the
28
+ * desktop app hosts it. `HQ_FLEET_BOTS_SERVICE=runtime` keeps the runtime's
29
+ * own LaunchAgents instead.
30
+ */
31
+ export declare function fleetBotsManagedByDaemon(host?: FleetDaemonHost): boolean;
32
+ export type LaunchctlRun = (args: string[]) => {
33
+ status: number | null;
34
+ };
35
+ export interface RemoveLaunchAgentDeps {
36
+ home?: string;
37
+ uid?: number;
38
+ launchctl?: LaunchctlRun;
39
+ }
40
+ /**
41
+ * Unload and delete the LaunchAgent the runtime registered for this bot, so the
42
+ * daemon's copy is the only one. True when a plist was there and is gone now;
43
+ * a plist that cannot be deleted stays, and the caller sees it still there.
44
+ */
45
+ export declare function removeFleetBotLaunchAgent(agentUid: string, deps?: RemoveLaunchAgentDeps): boolean;
46
+ export interface FleetBot {
47
+ name: string;
48
+ dir: string;
49
+ config: BotConfig;
50
+ }
51
+ export declare function listFleetBots(root?: string): FleetBot[];
52
+ export declare function findFleetBotByAgent(agentUid: string, root?: string): FleetBot | null;
53
+ export interface PlanFleetBotsDeps extends RemoveLaunchAgentDeps {
54
+ platform?: NodeJS.Platform;
55
+ root?: string;
56
+ fleetHome?: string;
57
+ env?: NodeJS.ProcessEnv;
58
+ log?: (message: string) => void;
59
+ /** The daemon's own pid: a gateway under it is left alone. */
60
+ daemonPid?: number;
61
+ /** `ps -o ppid=,command= -p <pid>` (tests). */
62
+ ps?: (pid: number) => {
63
+ ppid: number;
64
+ command: string;
65
+ } | null;
66
+ kill?: (pid: number, signal: NodeJS.Signals) => void;
67
+ }
68
+ /**
69
+ * The pid of this bot's gateway when it runs outside the daemon (the runtime's
70
+ * LaunchAgent, a detached fallback, or a manual `gateway run`); null when there
71
+ * is none, or when the running one descends from the daemon.
72
+ */
73
+ export declare function gatewayOutsideDaemon(agentUid: string, deps: {
74
+ fleetHome?: string;
75
+ daemonPid: number;
76
+ ps?: (pid: number) => {
77
+ ppid: number;
78
+ command: string;
79
+ } | null;
80
+ }): number | null;
81
+ /**
82
+ * The daemon's view of every HQ Fleet bot on this machine. On macOS this also
83
+ * retires each bot's own LaunchAgent, so the daemon can start the gateway
84
+ * without a second copy racing it; a plist that survives the attempt keeps the
85
+ * unit waiting.
86
+ */
87
+ export declare function planFleetBots(deps?: PlanFleetBotsDeps): FleetBotPlan[];
88
+ export interface ControlFleetBotDeps extends FleetLocalControlDeps, FleetDaemonHost {
89
+ root?: string;
90
+ uid?: number;
91
+ launchctl?: LaunchctlRun;
92
+ alive?: (pid: number) => boolean;
93
+ }
94
+ /**
95
+ * `controlFleetLocalBot` for a bot the daemon runs: the runtime's service
96
+ * commands become daemon requests, and `install`/`start` also retire the
97
+ * bot's own LaunchAgent. Elsewhere the runtime's own service path runs as
98
+ * before.
99
+ */
100
+ export declare function controlFleetBot(agentUid: string, action: FleetLocalServiceAction, deps?: ControlFleetBotDeps): Record<string, unknown>;
101
+ //# sourceMappingURL=fleet-daemon.d.ts.map
@@ -0,0 +1,227 @@
1
+ /**
2
+ * HQ Fleet bots under `hq daemon` on macOS.
3
+ *
4
+ * The HQ Fleet Runtime registers each bot's gateway as its own LaunchAgent
5
+ * whose program is the runtime's `python`. macOS reports every such login
6
+ * item as a new background item from an unknown developer. On a Mac that runs
7
+ * `hq daemon` (one login item, registered through the HQ app), the daemon runs
8
+ * the gateways itself as `fleet-bots:<name>` units instead, and any LaunchAgent
9
+ * the runtime left behind is unloaded and deleted.
10
+ *
11
+ * Other platforms, and a Mac without `hq daemon`, keep the runtime's own
12
+ * service path.
13
+ */
14
+ import { spawnSync } from "node:child_process";
15
+ import * as fs from "node:fs";
16
+ import * as os from "node:os";
17
+ import * as path from "node:path";
18
+ import { HQ_FLEET_RUNTIME_ENGINE_ID, patchBotConfig, readBotConfig } from "./config.js";
19
+ import { defaultPathEntries } from "./daemon.js";
20
+ import { controlFleetLocalBot, fleetLocalGatewayPid, fleetLocalGatewayProcess, fleetLocalLaunchAgentLabel, fleetLocalLaunchAgentPlist, removeFleetLocalEmbeddedRuntime, } from "./fleet-local.js";
21
+ import { botsRoot } from "./paths.js";
22
+ import { isPidAlive } from "./status.js";
23
+ import { askDaemonToStart, askDaemonToStop, daemonUnitInstalled, hostedDaemonRunning } from "../daemon/handoff.js";
24
+ import { daemonPaths } from "../daemon/paths.js";
25
+ import { isDaemonProcess } from "../daemon/lock.js";
26
+ export const FLEET_BOT_UNIT_PREFIX = "fleet-bots:";
27
+ export function fleetBotUnitId(name) {
28
+ return `${FLEET_BOT_UNIT_PREFIX}${name}`;
29
+ }
30
+ /**
31
+ * `hq daemon` runs this Mac's HQ Fleet bots: it is installed here, or the
32
+ * desktop app hosts it. `HQ_FLEET_BOTS_SERVICE=runtime` keeps the runtime's
33
+ * own LaunchAgents instead.
34
+ */
35
+ export function fleetBotsManagedByDaemon(host = {}) {
36
+ const platform = host.platform ?? process.platform;
37
+ if (platform !== "darwin")
38
+ return false;
39
+ if ((host.env ?? process.env).HQ_FLEET_BOTS_SERVICE?.trim() === "runtime")
40
+ return false;
41
+ const home = host.home ?? os.homedir();
42
+ const paths = host.paths ?? daemonPaths(home);
43
+ return daemonUnitInstalled({ platform, home, windowsTaskName: "", windowsTaskExists: () => false }) || hostedDaemonRunning(paths);
44
+ }
45
+ function defaultLaunchctl(args) {
46
+ return spawnSync("launchctl", args, { encoding: "utf8", windowsHide: true, timeout: 15_000 });
47
+ }
48
+ /**
49
+ * Unload and delete the LaunchAgent the runtime registered for this bot, so the
50
+ * daemon's copy is the only one. True when a plist was there and is gone now;
51
+ * a plist that cannot be deleted stays, and the caller sees it still there.
52
+ */
53
+ export function removeFleetBotLaunchAgent(agentUid, deps = {}) {
54
+ const home = deps.home ?? os.homedir();
55
+ const plist = fleetLocalLaunchAgentPlist(agentUid, home);
56
+ if (!fs.existsSync(plist))
57
+ return false;
58
+ const uid = deps.uid ?? process.getuid?.() ?? 0;
59
+ (deps.launchctl ?? defaultLaunchctl)(["bootout", `gui/${uid}/${fleetLocalLaunchAgentLabel(agentUid)}`]);
60
+ try {
61
+ fs.rmSync(plist, { force: true });
62
+ }
63
+ catch {
64
+ return false;
65
+ }
66
+ return true;
67
+ }
68
+ export function listFleetBots(root = botsRoot()) {
69
+ if (!fs.existsSync(root))
70
+ return [];
71
+ return fs
72
+ .readdirSync(root, { withFileTypes: true })
73
+ .filter((d) => d.isDirectory())
74
+ .map((d) => ({ name: d.name, dir: path.join(root, d.name), config: readBotConfig(path.join(root, d.name)) }))
75
+ .filter((b) => b.config !== null && b.config.engine?.id === HQ_FLEET_RUNTIME_ENGINE_ID)
76
+ .sort((a, b) => a.name.localeCompare(b.name));
77
+ }
78
+ export function findFleetBotByAgent(agentUid, root = botsRoot()) {
79
+ return listFleetBots(root).find((b) => b.config.agentUid === agentUid) ?? null;
80
+ }
81
+ function defaultPs(pid) {
82
+ const result = spawnSync("ps", ["-o", "ppid=,command=", "-p", String(pid)], { encoding: "utf8", timeout: 5_000 });
83
+ const line = result.stdout?.trim();
84
+ if (result.status !== 0 || !line)
85
+ return null;
86
+ const match = /^(\d+)\s+(.*)$/.exec(line);
87
+ return match ? { ppid: Number(match[1]), command: match[2] } : null;
88
+ }
89
+ /**
90
+ * The pid of this bot's gateway when it runs outside the daemon (the runtime's
91
+ * LaunchAgent, a detached fallback, or a manual `gateway run`); null when there
92
+ * is none, or when the running one descends from the daemon.
93
+ */
94
+ export function gatewayOutsideDaemon(agentUid, deps) {
95
+ const pid = fleetLocalGatewayPid(agentUid, deps);
96
+ if (pid === null || !isPidAlive(pid))
97
+ return null;
98
+ const ps = deps.ps ?? defaultPs;
99
+ const own = ps(pid);
100
+ // The pid file may name a pid the OS reused for something else.
101
+ if (!own || !/hq_fleet_cli|hq-fleet/.test(own.command))
102
+ return null;
103
+ let current = own.ppid;
104
+ for (let hops = 0; hops < 6 && current > 1; hops += 1) {
105
+ if (current === deps.daemonPid)
106
+ return null;
107
+ current = ps(current)?.ppid ?? 0;
108
+ }
109
+ return pid;
110
+ }
111
+ /**
112
+ * The daemon's view of every HQ Fleet bot on this machine. On macOS this also
113
+ * retires each bot's own LaunchAgent, so the daemon can start the gateway
114
+ * without a second copy racing it; a plist that survives the attempt keeps the
115
+ * unit waiting.
116
+ */
117
+ export function planFleetBots(deps = {}) {
118
+ const platform = deps.platform ?? process.platform;
119
+ const home = deps.home ?? os.homedir();
120
+ const env = deps.env ?? process.env;
121
+ return listFleetBots(deps.root ?? botsRoot(home, env)).map(({ name, config }) => {
122
+ let legacyAgent;
123
+ let outsideGateway;
124
+ if (platform === "darwin") {
125
+ if (removeFleetBotLaunchAgent(config.agentUid, { home, uid: deps.uid, launchctl: deps.launchctl })) {
126
+ deps.log?.(`retired the HQ Fleet LaunchAgent for ${name}; hq daemon runs its gateway now`);
127
+ }
128
+ if (fs.existsSync(fleetLocalLaunchAgentPlist(config.agentUid, home)))
129
+ legacyAgent = fleetLocalLaunchAgentLabel(config.agentUid);
130
+ // A gateway the LaunchAgent (or a detached fallback) left running holds
131
+ // the profile, and the runtime refuses to start a second one. Ask it to
132
+ // exit; the unit waits until it has.
133
+ const outside = gatewayOutsideDaemon(config.agentUid, { fleetHome: deps.fleetHome, daemonPid: deps.daemonPid ?? process.pid, ps: deps.ps });
134
+ if (outside !== null) {
135
+ outsideGateway = outside;
136
+ try {
137
+ (deps.kill ?? ((pid, signal) => process.kill(pid, signal)))(outside, "SIGTERM");
138
+ deps.log?.(`asked the gateway for ${name} started outside hq daemon (pid ${outside}) to exit`);
139
+ }
140
+ catch {
141
+ /* already gone */
142
+ }
143
+ }
144
+ }
145
+ const gateway = fleetLocalGatewayProcess(config.agentUid, {
146
+ fleetHome: deps.fleetHome,
147
+ platform,
148
+ pathEntries: defaultPathEntries(home),
149
+ basePath: env.PATH ?? "",
150
+ });
151
+ return {
152
+ name,
153
+ gateway,
154
+ authPending: config.fleetAuthPending === true,
155
+ installPending: config.fleetServiceInstallPending === true,
156
+ ...(legacyAgent ? { legacyAgent } : {}),
157
+ ...(outsideGateway !== undefined ? { outsideGateway } : {}),
158
+ };
159
+ });
160
+ }
161
+ function unitState(paths, unitId, alive) {
162
+ try {
163
+ const state = JSON.parse(fs.readFileSync(paths.statePath, "utf8"));
164
+ if (!alive(state.pid))
165
+ return null;
166
+ const unit = state.units.find((u) => u.id === unitId);
167
+ return unit ? { status: unit.status, ...(unit.reason ? { reason: unit.reason } : {}), ...(unit.pid !== undefined ? { pid: unit.pid } : {}) } : null;
168
+ }
169
+ catch {
170
+ return null;
171
+ }
172
+ }
173
+ /**
174
+ * `controlFleetLocalBot` for a bot the daemon runs: the runtime's service
175
+ * commands become daemon requests, and `install`/`start` also retire the
176
+ * bot's own LaunchAgent. Elsewhere the runtime's own service path runs as
177
+ * before.
178
+ */
179
+ export function controlFleetBot(agentUid, action, deps = {}) {
180
+ const platform = deps.platform ?? process.platform;
181
+ const home = deps.home ?? os.homedir();
182
+ const paths = deps.paths ?? daemonPaths(home);
183
+ const bot = fleetBotsManagedByDaemon({ platform, home, paths, env: deps.env }) ? findFleetBotByAgent(agentUid, deps.root) : null;
184
+ if (!bot)
185
+ return controlFleetLocalBot(agentUid, action, deps);
186
+ const unit = fleetBotUnitId(bot.name);
187
+ const agent = { home, uid: deps.uid, launchctl: deps.launchctl };
188
+ switch (action) {
189
+ case "install":
190
+ case "start": {
191
+ removeFleetBotLaunchAgent(agentUid, agent);
192
+ if (action === "install")
193
+ removeFleetLocalEmbeddedRuntime(agentUid, deps);
194
+ patchBotConfig(bot.dir, { fleetServiceInstallPending: false, enabled: true });
195
+ askDaemonToStart(paths, unit);
196
+ return { ok: true, unit, summary: `${action === "install" ? "installed under" : "started by"} hq daemon (${unit})` };
197
+ }
198
+ case "restart":
199
+ removeFleetBotLaunchAgent(agentUid, agent);
200
+ askDaemonToStart(paths, unit);
201
+ return { ok: true, unit, summary: `restarted by hq daemon (${unit})` };
202
+ case "stop":
203
+ removeFleetBotLaunchAgent(agentUid, agent);
204
+ askDaemonToStop(paths, unit);
205
+ return { ok: true, unit, summary: `stopped by hq daemon (${unit})` };
206
+ case "status": {
207
+ const alive = deps.alive ?? ((pid) => isDaemonProcess(pid));
208
+ const state = unitState(paths, unit, alive);
209
+ const pid = fleetLocalGatewayPid(agentUid, deps);
210
+ const running = pid !== null && isPidAlive(pid);
211
+ return {
212
+ ok: true,
213
+ unit,
214
+ running,
215
+ pid: running ? pid : null,
216
+ state: state?.status ?? "unknown",
217
+ ...(state?.reason ? { reason: state.reason } : {}),
218
+ summary: running ? `running under hq daemon (pid ${pid})` : `not running (${state?.reason ?? state?.status ?? "hq daemon is not running"})`,
219
+ };
220
+ }
221
+ case "remove":
222
+ removeFleetBotLaunchAgent(agentUid, agent);
223
+ askDaemonToStop(paths, unit);
224
+ return controlFleetLocalBot(agentUid, action, deps);
225
+ }
226
+ }
227
+ //# sourceMappingURL=fleet-daemon.js.map
@@ -302,6 +302,32 @@ export declare function fleetLocalServiceInstalled(agentUid: string, deps?: {
302
302
  platform?: NodeJS.Platform;
303
303
  home?: string;
304
304
  }): boolean | null;
305
+ /** The launchd label the HQ Fleet Runtime registers a bot's own gateway under. */
306
+ export declare function fleetLocalLaunchAgentLabel(agentUid: string): string;
307
+ export declare function fleetLocalLaunchAgentPlist(agentUid: string, home?: string): string;
308
+ export interface FleetLocalGatewayProcess {
309
+ file: string;
310
+ args: string[];
311
+ env: Record<string, string>;
312
+ cwd: string;
313
+ }
314
+ /**
315
+ * The bot's gateway as a process for an outside supervisor: the command,
316
+ * environment and working directory the runtime writes into its own
317
+ * LaunchAgent, with `--external-supervisor` so the runtime hands restarts back
318
+ * to the supervisor instead of relaunching itself. The gateway is the direct
319
+ * child (the LaunchAgent's stderr-timestamp wrapper is left out), so the
320
+ * supervisor's signals reach it and a forced stop cannot orphan it. Null when
321
+ * the profile or its runtime is not fully installed.
322
+ */
323
+ export declare function fleetLocalGatewayProcess(agentUid: string, deps?: {
324
+ fleetHome?: string;
325
+ platform?: NodeJS.Platform;
326
+ pathEntries?: readonly string[];
327
+ basePath?: string;
328
+ }): FleetLocalGatewayProcess | null;
329
+ /** After a service install: drop the profile's own copy of the runtime once the shared one runs it. */
330
+ export declare function removeFleetLocalEmbeddedRuntime(agentUid: string, deps?: Pick<FleetLocalControlDeps, "fleetHome" | "platform">): void;
305
331
  export declare function fleetLocalProfileNeedsAdoption(agentUid: string, deps?: Pick<FleetLocalControlDeps, "fleetHome" | "platform"> & {
306
332
  release?: FleetLocalReleasePin;
307
333
  }): boolean;