@indigoai-us/hq-cli 5.345.215-beta.0 → 5.345.217

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 (241) hide show
  1. package/CHANGELOG.md +206 -1
  2. package/README.md +45 -0
  3. package/assets/scaffold/core/scripts/hq-delegate-verify.sh +5 -2
  4. package/assets/scaffold/core/scripts/lib/epochrealtime.sh +30 -0
  5. package/assets/scaffold/core/scripts/lib/work-mesh-enqueue.sh +12 -5
  6. package/dist/command-catalog.generated.d.ts +105 -10
  7. package/dist/command-catalog.generated.js +127 -10
  8. package/dist/command-help.js +3 -1
  9. package/dist/command-registration-plan.d.ts +6 -0
  10. package/dist/command-registration-plan.js +1 -0
  11. package/dist/commands/auth.d.ts +1 -1
  12. package/dist/commands/auth.js +11 -52
  13. package/dist/commands/bot.js +75 -10
  14. package/dist/commands/capacity.d.ts +4 -1
  15. package/dist/commands/capacity.js +46 -10
  16. package/dist/commands/cloud-demote.d.ts +19 -4
  17. package/dist/commands/cloud-demote.js +85 -12
  18. package/dist/commands/cloud-provision.d.ts +5 -1
  19. package/dist/commands/cloud-provision.js +6 -2
  20. package/dist/commands/cloud.d.ts +36 -0
  21. package/dist/commands/cloud.js +110 -27
  22. package/dist/commands/core-delegate-w1b.js +15 -1
  23. package/dist/commands/core-policy.js +67 -8
  24. package/dist/commands/core.js +1 -0
  25. package/dist/commands/daemon.js +9 -1
  26. package/dist/commands/dm.js +7 -0
  27. package/dist/commands/doctor-usage.d.ts +8 -0
  28. package/dist/commands/doctor-usage.js +20 -0
  29. package/dist/commands/doctor.js +7 -1
  30. package/dist/commands/env.d.ts +18 -0
  31. package/dist/commands/env.js +82 -0
  32. package/dist/commands/files-browse.d.ts +11 -4
  33. package/dist/commands/files-browse.js +21 -4
  34. package/dist/commands/files.d.ts +1 -1
  35. package/dist/commands/files.js +25 -11
  36. package/dist/commands/install-global.js +2 -2
  37. package/dist/commands/integrations-auth-rules.d.ts +27 -0
  38. package/dist/commands/integrations-auth-rules.js +79 -0
  39. package/dist/commands/integrations-import.js +124 -12
  40. package/dist/commands/lanes.js +102 -26
  41. package/dist/commands/logout.d.ts +7 -0
  42. package/dist/commands/logout.js +41 -34
  43. package/dist/commands/mesh.d.ts +2 -0
  44. package/dist/commands/mesh.js +60 -35
  45. package/dist/commands/sources.d.ts +8 -2
  46. package/dist/commands/sources.js +65 -9
  47. package/dist/commands/sync-held.js +5 -2
  48. package/dist/commands/whoami.js +26 -1
  49. package/dist/data/command-states.json +15 -0
  50. package/dist/index.js +52 -4
  51. package/dist/lazy-commands.js +5 -6
  52. package/dist/lib/anywhere-person-setting.d.ts +2 -0
  53. package/dist/lib/anywhere-person-setting.js +6 -3
  54. package/dist/lib/billing/usage-card.d.ts +25 -4
  55. package/dist/lib/billing/usage-card.js +76 -9
  56. package/dist/lib/billing/usage-cost.d.ts +3 -3
  57. package/dist/lib/billing/usage-cost.js +35 -13
  58. package/dist/lib/billing/usage-only.js +4 -2
  59. package/dist/lib/billing/usage-rate-card.d.ts +2 -2
  60. package/dist/lib/billing/usage-rate-card.js +3 -0
  61. package/dist/lib/bot/fleet-cron.d.ts +8 -0
  62. package/dist/lib/bot/fleet-cron.js +126 -7
  63. package/dist/lib/bot/fleet-daemon.d.ts +46 -0
  64. package/dist/lib/bot/fleet-daemon.js +99 -1
  65. package/dist/lib/bot/inflight.d.ts +9 -0
  66. package/dist/lib/bot/inflight.js +10 -0
  67. package/dist/lib/bot/jobs/hot-signal-sync.js +12 -1
  68. package/dist/lib/bot/probe.js +7 -1
  69. package/dist/lib/bot/run.js +20 -1
  70. package/dist/lib/bot/runtime/codex.js +1 -1
  71. package/dist/lib/bot/runtime/grok-acp.d.ts +6 -1
  72. package/dist/lib/bot/runtime/grok-acp.js +32 -14
  73. package/dist/lib/bot/runtime/grok.js +1 -1
  74. package/dist/lib/bot/runtime/index.js +19 -9
  75. package/dist/lib/bot/runtime/messages-stream.js +2 -2
  76. package/dist/lib/bot/runtime/types.d.ts +15 -0
  77. package/dist/lib/bot/runtime/types.js +9 -0
  78. package/dist/lib/bot/runtime-failure.d.ts +23 -0
  79. package/dist/lib/bot/runtime-failure.js +43 -1
  80. package/dist/lib/capacity/accounts.d.ts +8 -0
  81. package/dist/lib/capacity/accounts.js +19 -0
  82. package/dist/lib/capacity/available.d.ts +154 -0
  83. package/dist/lib/capacity/available.js +905 -0
  84. package/dist/lib/capacity/codex-availability.d.ts +14 -1
  85. package/dist/lib/capacity/codex-availability.js +26 -1
  86. package/dist/lib/capacity/collectors/claude-oauth.d.ts +29 -2
  87. package/dist/lib/capacity/collectors/claude-oauth.js +104 -7
  88. package/dist/lib/capacity/collectors/codex.js +10 -7
  89. package/dist/lib/capacity/ledger.d.ts +37 -1
  90. package/dist/lib/capacity/ledger.js +207 -30
  91. package/dist/lib/capacity/project.d.ts +26 -0
  92. package/dist/lib/capacity/project.js +137 -8
  93. package/dist/lib/capacity/refusal-rows.d.ts +31 -0
  94. package/dist/lib/capacity/refusal-rows.js +61 -0
  95. package/dist/lib/capacity/refusal.d.ts +53 -2
  96. package/dist/lib/capacity/refusal.js +284 -65
  97. package/dist/lib/capacity/route.js +46 -11
  98. package/dist/lib/capacity/widget.d.ts +12 -1
  99. package/dist/lib/capacity/widget.js +91 -3
  100. package/dist/lib/daemon/flag-monitor.d.ts +8 -0
  101. package/dist/lib/daemon/flag-monitor.js +17 -6
  102. package/dist/lib/daemon/flag.d.ts +65 -1
  103. package/dist/lib/daemon/flag.js +190 -40
  104. package/dist/lib/daemon/ops/policy.js +62 -5
  105. package/dist/lib/daemon/paths.d.ts +72 -2
  106. package/dist/lib/daemon/paths.js +154 -3
  107. package/dist/lib/daemon/resolver.d.ts +2 -0
  108. package/dist/lib/daemon/resolver.js +3 -0
  109. package/dist/lib/daemon/run.d.ts +9 -0
  110. package/dist/lib/daemon/run.js +79 -21
  111. package/dist/lib/daemon/selfcheck.d.ts +22 -0
  112. package/dist/lib/daemon/selfcheck.js +40 -1
  113. package/dist/lib/daemon/server.d.ts +5 -1
  114. package/dist/lib/daemon/server.js +17 -23
  115. package/dist/lib/daemon/state-file-switch.d.ts +57 -0
  116. package/dist/lib/daemon/state-file-switch.js +88 -0
  117. package/dist/lib/daemon/state-file.d.ts +198 -0
  118. package/dist/lib/daemon/state-file.js +419 -0
  119. package/dist/lib/daemon/tcc-eperm.d.ts +153 -0
  120. package/dist/lib/daemon/tcc-eperm.js +310 -0
  121. package/dist/lib/daemon/timed-flag-monitors.d.ts +47 -0
  122. package/dist/lib/daemon/timed-flag-monitors.js +75 -0
  123. package/dist/lib/delivery/admission.d.ts +86 -0
  124. package/dist/lib/delivery/admission.js +148 -0
  125. package/dist/lib/delivery/artifacts.d.ts +7 -1
  126. package/dist/lib/delivery/artifacts.js +29 -10
  127. package/dist/lib/delivery/attempt-id.d.ts +13 -0
  128. package/dist/lib/delivery/attempt-id.js +16 -0
  129. package/dist/lib/delivery/disposable-target.d.ts +42 -0
  130. package/dist/lib/delivery/disposable-target.js +111 -0
  131. package/dist/lib/delivery/effects.d.ts +136 -0
  132. package/dist/lib/delivery/effects.js +541 -0
  133. package/dist/lib/delivery/enrollment.d.ts +21 -17
  134. package/dist/lib/delivery/enrollment.js +83 -5
  135. package/dist/lib/delivery/escalations.d.ts +51 -0
  136. package/dist/lib/delivery/escalations.js +60 -0
  137. package/dist/lib/delivery/lease.d.ts +80 -0
  138. package/dist/lib/delivery/lease.js +134 -0
  139. package/dist/lib/delivery/migrations.d.ts +120 -4
  140. package/dist/lib/delivery/migrations.js +215 -15
  141. package/dist/lib/delivery/mqtt.d.ts +2 -0
  142. package/dist/lib/delivery/mqtt.js +7 -0
  143. package/dist/lib/delivery/reconciler.d.ts +65 -1
  144. package/dist/lib/delivery/reconciler.js +224 -13
  145. package/dist/lib/delivery/rpc/client.d.ts +22 -0
  146. package/dist/lib/delivery/rpc/client.js +159 -0
  147. package/dist/lib/delivery/rpc/port.d.ts +40 -0
  148. package/dist/lib/delivery/rpc/port.js +16 -0
  149. package/dist/lib/delivery/rpc/server.d.ts +30 -0
  150. package/dist/lib/delivery/rpc/server.js +205 -0
  151. package/dist/lib/delivery/rpc/wire.d.ts +85 -0
  152. package/dist/lib/delivery/rpc/wire.js +143 -0
  153. package/dist/lib/delivery/store.d.ts +2 -0
  154. package/dist/lib/delivery/store.js +4 -0
  155. package/dist/lib/delivery/windows-service-install.d.ts +262 -0
  156. package/dist/lib/delivery/windows-service-install.js +892 -0
  157. package/dist/lib/delivery/workers/macos.d.ts +16 -1
  158. package/dist/lib/delivery/workers/macos.js +54 -12
  159. package/dist/lib/delivery/workers/windows-service-live.d.ts +121 -0
  160. package/dist/lib/delivery/workers/windows-service-live.js +711 -0
  161. package/dist/lib/delivery/workers/windows-service-runner.d.ts +33 -0
  162. package/dist/lib/delivery/workers/windows-service-runner.js +82 -0
  163. package/dist/lib/delivery/workers/windows-service.d.ts +140 -0
  164. package/dist/lib/delivery/workers/windows-service.js +584 -0
  165. package/dist/lib/delivery/workers/windows.d.ts +32 -22
  166. package/dist/lib/delivery/workers/windows.js +50 -64
  167. package/dist/lib/doctor/checks/host-core.d.ts +50 -0
  168. package/dist/lib/doctor/checks/host-core.js +269 -0
  169. package/dist/lib/doctor/checks/replay-recorder.d.ts +39 -0
  170. package/dist/lib/doctor/checks/replay-recorder.js +261 -0
  171. package/dist/lib/doctor/registry.js +4 -0
  172. package/dist/lib/environment/profile.d.ts +239 -0
  173. package/dist/lib/environment/profile.js +251 -0
  174. package/dist/lib/hook-engine/reconcile.js +39 -13
  175. package/dist/lib/hook-engine/registration.d.ts +9 -0
  176. package/dist/lib/hook-engine/registration.js +19 -0
  177. package/dist/lib/hot-channels/adapters/meetings.d.ts +15 -0
  178. package/dist/lib/hot-channels/adapters/meetings.js +36 -3
  179. package/dist/lib/hot-channels/adapters/slack.d.ts +21 -5
  180. package/dist/lib/hot-channels/adapters/slack.js +64 -21
  181. package/dist/lib/hot-channels/alert.d.ts +2 -0
  182. package/dist/lib/hot-channels/alert.js +8 -1
  183. package/dist/lib/hot-channels/contract.d.ts +12 -0
  184. package/dist/lib/hot-channels/contract.js +7 -0
  185. package/dist/lib/hot-channels/loop.js +1 -0
  186. package/dist/lib/hot-channels/run.d.ts +6 -0
  187. package/dist/lib/hot-channels/run.js +4 -0
  188. package/dist/lib/hot-channels/signals-pass.d.ts +74 -1
  189. package/dist/lib/hot-channels/signals-pass.js +82 -41
  190. package/dist/lib/hot-channels/signals-redo.js +10 -2
  191. package/dist/lib/install/claude-targets.d.ts +12 -1
  192. package/dist/lib/install/claude-targets.js +57 -5
  193. package/dist/lib/install/codex-targets.d.ts +2 -2
  194. package/dist/lib/install/codex-targets.js +36 -6
  195. package/dist/lib/install/hook-target.d.ts +3 -0
  196. package/dist/lib/install/hook-target.js +11 -0
  197. package/dist/lib/lanes/canonical-host.d.ts +35 -0
  198. package/dist/lib/lanes/canonical-host.js +65 -0
  199. package/dist/lib/lanes/host-capacity.d.ts +30 -0
  200. package/dist/lib/lanes/host-capacity.js +29 -3
  201. package/dist/lib/lanes/watcher.js +35 -0
  202. package/dist/lib/mesh/live/daemon/run.d.ts +2 -0
  203. package/dist/lib/mesh/live/daemon/run.js +5 -2
  204. package/dist/lib/mesh/live/flush.d.ts +5 -1
  205. package/dist/lib/mesh/live/flush.js +12 -6
  206. package/dist/lib/mesh/live/reporting-privacy.d.ts +32 -0
  207. package/dist/lib/mesh/live/reporting-privacy.js +56 -1
  208. package/dist/lib/mesh/live/spool.d.ts +7 -0
  209. package/dist/lib/mesh/live/spool.js +25 -0
  210. package/dist/lib/person-setting-cache.d.ts +38 -0
  211. package/dist/lib/person-setting-cache.js +98 -0
  212. package/dist/lib/safe-store.d.ts +245 -0
  213. package/dist/lib/safe-store.js +777 -0
  214. package/dist/lib/signals/engine.d.ts +29 -2
  215. package/dist/lib/signals/engine.js +103 -4
  216. package/dist/lib/signals/reply.js +73 -18
  217. package/dist/lib/signals/steps/adapters.js +7 -2
  218. package/dist/lib/signals/steps/extract.d.ts +13 -0
  219. package/dist/lib/signals/steps/extract.js +122 -6
  220. package/dist/main.js +46 -3
  221. package/dist/schemas/hq-available-ai.v1.schema.json +76 -0
  222. package/dist/schemas/hq-environment-profile.v1.schema.json +438 -0
  223. package/dist/utils/auth-expiry.d.ts +8 -0
  224. package/dist/utils/auth-expiry.js +53 -0
  225. package/dist/utils/catalog-runtime-paths.d.ts +34 -0
  226. package/dist/utils/catalog-runtime-paths.js +53 -0
  227. package/dist/utils/cli-telemetry.d.ts +21 -0
  228. package/dist/utils/cli-telemetry.js +34 -0
  229. package/dist/utils/command-usage.d.ts +275 -0
  230. package/dist/utils/command-usage.js +797 -0
  231. package/dist/utils/files-browse-acl.js +1 -1
  232. package/dist/utils/hook-trust.d.ts +7 -0
  233. package/dist/utils/hook-trust.js +31 -4
  234. package/dist/utils/host-registration.d.ts +126 -0
  235. package/dist/utils/host-registration.js +378 -0
  236. package/dist/utils/resident-package-preload.js +2 -0
  237. package/package.json +10 -8
  238. package/scripts/bench-core.mjs +1096 -0
  239. package/scripts/check-function-manifest.mjs +702 -0
  240. package/dist/lib/delivery/workers/windows-boundary.d.ts +0 -453
  241. package/dist/lib/delivery/workers/windows-boundary.js +0 -693
@@ -66,7 +66,8 @@ import { OUTPOST_DIR, OUTPOST_ID_PATH, readOutpostIdentity, resolveAdmissionHost
66
66
  export { OUTPOST_DIR, OUTPOST_ID_PATH, readOutpostIdentity } from "../lib/lanes/admission-host.js";
67
67
  import { buildOutpostCapacityCommand, buildOutpostIdentityBackfillCommand, buildOutpostLaneCommand, buildOutpostQuestionListCommand, buildOutpostPickupCommand, createOutpostsClient, dispatchErrorMessage, dispatchOutpostPickup, buildOutpostLaneListCommand, buildOutpostLegacyLaneUlidListCommand, REMOTE_LANE_READ_ENV, outpostRejectedEffortOption, parseOutpostPickupPayload, PICKUP_WAIT_MS, stageOutpostPayload, } from "../lib/lanes/outpost-dispatch.js";
68
68
  import { outpostHireSummaryCacheKey, OUTPOST_HIRE_SUMMARY_CACHE_TTL_MS, readOutpostHireSummaryCache, readOutpostHireSummaryCacheIncludingStale, writeOutpostHireSummaryCache, } from "../lib/lanes/outpost-hire-cache.js";
69
- import { buildHostCapacitySnapshot, chooseHostForLane, parseHostCapacitySnapshot, } from "../lib/lanes/host-capacity.js";
69
+ import { buildHostCapacitySnapshot, chooseHostForLane, hostCapacitySnapshotToWire, parseHostCapacitySnapshot, } from "../lib/lanes/host-capacity.js";
70
+ import { resolveCanonicalHost } from "../lib/lanes/canonical-host.js";
70
71
  import { BALANCE_MOVABLE_STATES, selectClaudeAccount, } from "../lib/lanes/claude-balance.js";
71
72
  import { parseUserYaml } from "../utils/user-yaml-error.js";
72
73
  import { backfillOutpostIdentityMarker as backfillOutpostIdentityMarkerImpl, createOutpostIdentityMarkerIfMissing, validateOutpostIdentityId, } from "../lib/lanes/outpost-identity.js";
@@ -94,7 +95,7 @@ import { writeQuestionBody } from "../lib/lanes/questions.js";
94
95
  import { compactionAfterUsage, } from "../lib/lanes/compaction.js";
95
96
  import { parseCliEffort, resolveLaneEffort, } from "../lib/lanes/effort.js";
96
97
  import { LanesError } from "../lib/lanes/errors.js";
97
- import { LedgerCorrupt, LedgerMissing, capacityOptionsFromEnv, readCollectorMark, readNow, rebuildNow, } from "../lib/capacity/ledger.js";
98
+ import { LedgerCorrupt, LedgerMissing, capacityOptionsFromEnv, readCollectorMark, readCurrentNow, rebuildNow, } from "../lib/capacity/ledger.js";
98
99
  import { pickAccount, refusalHasNoReadings, refusalHasStaleReading, staleReadingTargets, UNKNOWN_USAGE_SCORE, } from "../lib/capacity/route.js";
99
100
  import { capacityViewAge } from "../lib/capacity/freshness.js";
100
101
  import { applyTerminalToLane, classifyLaneExit, readLatestEnvelopeRecord } from "../lib/lanes/watcher.js";
@@ -3142,18 +3143,38 @@ function askDeliveryFailedPath(hqRoot, laneId) {
3142
3143
  async function emitLaneMeshEvent(ctx, company, threadId, event, payload) {
3143
3144
  if (!company)
3144
3145
  return;
3145
- let targetThreadId = threadId;
3146
- let eventPayload = payload;
3147
- const laneId = typeof payload.lane_id === "string" ? payload.lane_id.trim() : "";
3148
- if (laneId && ctx.mesh.ensureLaneThread) {
3149
- const lane = readLane(ctx.hqRoot(), laneId);
3150
- const ready = await ensureLaneThreadRecord(ctx, lane, lane.project_id, lane.story_id, "running");
3151
- targetThreadId = ready.thread_id;
3152
- eventPayload = { ...laneMeshEventIdentity(ready), ...payload };
3153
- }
3154
- if (!targetThreadId)
3155
- return;
3156
- await ctx.mesh.appendThreadEvent(company, targetThreadId, event, eventPayload);
3146
+ // lane_started races the just-spawned worker, which bumps the lane record.
3147
+ // The server rejects a stale lane.laneVersion on the append, so re-read the
3148
+ // lane and retry that one event once. Only this event is retried, so other
3149
+ // stories' lane_started events are never duplicated.
3150
+ const attempts = event === "lane_started" ? 2 : 1;
3151
+ for (let attempt = 1;; attempt++) {
3152
+ let targetThreadId = threadId;
3153
+ let eventPayload = payload;
3154
+ const laneId = typeof payload.lane_id === "string" ? payload.lane_id.trim() : "";
3155
+ if (laneId && ctx.mesh.ensureLaneThread) {
3156
+ const lane = readLane(ctx.hqRoot(), laneId);
3157
+ const ready = await ensureLaneThreadRecord(ctx, lane, lane.project_id, lane.story_id, "running");
3158
+ targetThreadId = ready.thread_id;
3159
+ eventPayload = {
3160
+ ...laneMeshEventIdentity(ready),
3161
+ ...payload,
3162
+ // A caller-supplied identity snapshot may predate a worker bump; the
3163
+ // fresh read wins for the version the server compares.
3164
+ ...("lane_version" in payload ? { lane_version: ready.version } : {}),
3165
+ };
3166
+ }
3167
+ if (!targetThreadId)
3168
+ return;
3169
+ try {
3170
+ await ctx.mesh.appendThreadEvent(company, targetThreadId, event, eventPayload);
3171
+ return;
3172
+ }
3173
+ catch (err) {
3174
+ if (attempt >= attempts || !isStaleLaneVersionError(err))
3175
+ throw err;
3176
+ }
3177
+ }
3157
3178
  }
3158
3179
  async function emitLaneTerminalStateSoft(ctx, lane) {
3159
3180
  if (lane.state !== "failed" && lane.state !== "interrupted" &&
@@ -3166,7 +3187,37 @@ async function emitLaneTerminalStateSoft(ctx, lane) {
3166
3187
  process.stderr.write(`hq lanes: terminal mesh update failed for ${lane.lane_id}: ${err instanceof Error ? err.message : String(err)}\n`);
3167
3188
  }
3168
3189
  }
3190
+ /**
3191
+ * The Work Mesh rejects a lane event whose lane.laneVersion is older than the
3192
+ * thread's copy. hq-pro work-mesh/thread-store.ts (appendThreadEvent lane
3193
+ * checks) throws WorkThreadPayloadValidationError("lane.laneVersion is stale"),
3194
+ * a 400-class error (work-mesh/events.ts). The CLI client (meshJson in
3195
+ * lib/mesh/api.ts) rethrows it with `status = 400` and a message of
3196
+ * `400 WorkThread payload validation failed [kind=lane_started]: lane.laneVersion is stale`.
3197
+ */
3198
+ function isStaleLaneVersionError(err) {
3199
+ if (!(err instanceof Error))
3200
+ return false;
3201
+ const status = err.status;
3202
+ return status === 400 && /lane\.laneVersion is stale/i.test(err.message);
3203
+ }
3204
+ /**
3205
+ * Post-spawn Work Mesh update for a started lane. The worker is already
3206
+ * running, so nothing here may fail the create: a non-zero exit would invite a
3207
+ * conductor to retry and spawn a second worker. Existing convention for mesh
3208
+ * trouble after the lane is live (story_not_on_board, emitLaneTerminalStateSoft)
3209
+ * is to keep going and report. Every failure is therefore returned as a
3210
+ * warning naming what did not sync and the manual fix, and also written to
3211
+ * stderr. Nothing claims the mesh will reconcile: no reconcile path was found.
3212
+ */
3169
3213
  async function emitLaneStartedForStories(ctx, company, lane, threadId, knownAbsentStories = new Set()) {
3214
+ const prefix = `Lane ${lane.lane_id} is RUNNING (do not re-run create).`;
3215
+ const warnings = [];
3216
+ const fail = (text) => {
3217
+ process.stderr.write(`hq lanes: ${prefix} ${text}\n`);
3218
+ warnings.push(`${prefix} ${text}`);
3219
+ };
3220
+ const storyFix = (story) => `hq mesh story --company ${company.slug} --project ${story.project_id} --story ${story.story_id} --status in_progress`;
3170
3221
  let ready = lane;
3171
3222
  if (ctx.mesh.ensureLaneThread) {
3172
3223
  try {
@@ -3176,14 +3227,13 @@ async function emitLaneStartedForStories(ctx, company, lane, threadId, knownAbse
3176
3227
  const warning = storyNotOnBoardWarning(err);
3177
3228
  if (warning !== undefined)
3178
3229
  return [warning];
3179
- throw err;
3230
+ fail(`Work Mesh lane registration failed (${err instanceof Error ? err.message : String(err)}), so the lane is not registered on the mesh and its stories were not moved to in_progress. Fix the mesh error and set story status by hand with the hq mesh story command.`);
3231
+ return warnings;
3180
3232
  }
3181
3233
  }
3182
3234
  const stableThreadId = ready.thread_id ?? threadId;
3183
3235
  if (!stableThreadId)
3184
3236
  return [];
3185
- const failures = [];
3186
- const warnings = [];
3187
3237
  for (const story of laneStories(ready)) {
3188
3238
  try {
3189
3239
  await emitLaneMeshEvent(ctx, company, stableThreadId, "lane_started", {
@@ -3199,7 +3249,10 @@ async function emitLaneStartedForStories(ctx, company, lane, threadId, knownAbse
3199
3249
  warnings.push(warning);
3200
3250
  continue;
3201
3251
  }
3202
- failures.push(err);
3252
+ const message = err instanceof Error ? err.message : String(err);
3253
+ fail(isStaleLaneVersionError(err)
3254
+ ? `The Work Mesh still rejected the lane_started event for story ${story.story_id} as stale after a re-read and retry (${message}). Set story status by hand: ${storyFix(story)}`
3255
+ : `The Work Mesh lane_started event for story ${story.story_id} failed (${message}). Set story status by hand: ${storyFix(story)}`);
3203
3256
  continue;
3204
3257
  }
3205
3258
  if (!story.project_id?.trim() || !story.story_id?.trim())
@@ -3213,12 +3266,11 @@ async function emitLaneStartedForStories(ctx, company, lane, threadId, knownAbse
3213
3266
  const warning = storyNotOnBoardWarning(err);
3214
3267
  if (warning !== undefined)
3215
3268
  warnings.push(warning);
3216
- else
3217
- failures.push(err);
3269
+ else {
3270
+ fail(`Story ${story.story_id} status was not set to in_progress (${err instanceof Error ? err.message : String(err)}). Set it by hand: ${storyFix(story)}`);
3271
+ }
3218
3272
  }
3219
3273
  }
3220
- if (failures.length > 0)
3221
- throw failures[0];
3222
3274
  return warnings;
3223
3275
  }
3224
3276
  async function assertStoriesOnBoard(ctx, company, projectId, storyIds) {
@@ -3626,7 +3678,7 @@ async function runCreate(ctx, opts) {
3626
3678
  };
3627
3679
  let view = null;
3628
3680
  try {
3629
- view = readNow(ledgerOptions);
3681
+ view = readCurrentNow(ledgerOptions);
3630
3682
  }
3631
3683
  catch (err) {
3632
3684
  if (err instanceof LedgerCorrupt) {
@@ -4699,6 +4751,9 @@ async function runCreate(ctx, opts) {
4699
4751
  locateTranscript: ctx.locateTranscript,
4700
4752
  });
4701
4753
  if (meshCompany) {
4754
+ // The worker is already running, so this never fails the create (see
4755
+ // emitLaneStartedForStories). The lane_started append re-reads the lane
4756
+ // and retries once on a stale laneVersion (emitLaneMeshEvent).
4702
4757
  createStoryWarnings.push(...await emitLaneStartedForStories(ctx, meshCompany, started, started.thread_id, knownAbsentStories));
4703
4758
  }
4704
4759
  }
@@ -6288,6 +6343,7 @@ async function runList(ctx, opts) {
6288
6343
  const placementEnabled = !remoteRead && await readLanePlacementEnabled(ctx, placementCompany);
6289
6344
  const host_capacity = placementEnabled
6290
6345
  ? (await loadHostCapacitySnapshots(ctx, hqRoot, undefined, allLanes)).entries
6346
+ .map((entry) => "schema_version" in entry ? hostCapacitySnapshotToWire(entry) : entry)
6291
6347
  : undefined;
6292
6348
  const result = {
6293
6349
  ok: true,
@@ -6419,20 +6475,40 @@ async function runCapacity(ctx) {
6419
6475
  const host = laneHostFromCtx(ctx);
6420
6476
  const admissionHost = reconcileHostFromCtx(ctx);
6421
6477
  const lanes = loadAllLanes(hqRoot);
6478
+ const now = ctx.now();
6479
+ const hostname = ctx.hostname();
6480
+ // Read only: this command also runs as the remote capacity probe.
6481
+ const localIdentity = observeLocalHostIdentity({ homedir: ctx.homedir(), hostname: hostname.trim() });
6482
+ const canonical = resolveCanonicalHost({
6483
+ host,
6484
+ hostname,
6485
+ ...(localIdentity
6486
+ ? { identityAliases: localIdentity.aliases, localIdentityId: localIdentity.id }
6487
+ : {}),
6488
+ lanes,
6489
+ now,
6490
+ });
6422
6491
  const snapshot = buildHostCapacitySnapshot({
6423
6492
  host,
6493
+ aliases: canonical.aliases,
6494
+ // Count what lane admission and `queued_lanes` below accept, no wider.
6495
+ localMatch: {
6496
+ hostname: admissionHost.hostname,
6497
+ ...(admissionHost.machineId !== undefined ? { machineId: admissionHost.machineId } : {}),
6498
+ ...(admissionHost.aliases !== undefined ? { aliases: admissionHost.aliases } : {}),
6499
+ },
6424
6500
  lanes,
6425
6501
  config: loadLanesConfig(hqRoot),
6426
6502
  existsSync: ctx.existsSync,
6427
6503
  probe: ctx.probeProvider,
6428
6504
  readClaudeCredential: ctx.readClaudeCredential,
6429
6505
  env: ctx.env,
6430
- hostname: ctx.hostname(),
6431
- now: ctx.now(),
6506
+ hostname,
6507
+ now,
6432
6508
  quotaState: loadQuotaState(hqRoot),
6433
6509
  });
6434
6510
  printJson({
6435
- ...snapshot,
6511
+ ...hostCapacitySnapshotToWire(snapshot),
6436
6512
  queued_lanes: lanes
6437
6513
  .filter((lane) => lane.state === "queued" && laneRunsHere(lane, admissionHost))
6438
6514
  .map((lane) => ({
@@ -4,8 +4,15 @@
4
4
  *
5
5
  * The refresh token is revoked first so a copied token file stops working.
6
6
  * Local tokens are always deleted, even when the server can't be reached.
7
+ *
8
+ * `hq auth logout` is a second name for this command and runs the
9
+ * same {@link runLogout}, so both names revoke the person session's refresh
10
+ * token. Machine sessions are out of scope: they carry no refresh token, and
11
+ * the machine token cache in the daemon state folder is not cleared here.
7
12
  */
8
13
  import { Command } from 'commander';
9
14
  export declare const REVOKE_FAILED_MESSAGE = "Signed out on this device. Couldn't reach HQ to end the session everywhere; it will expire on its own.";
15
+ /** Sign out: revoke the refresh token on the server, then delete local tokens. */
16
+ export declare function runLogout(): Promise<void>;
10
17
  export declare function registerLogoutCommand(program: Command): void;
11
18
  //# sourceMappingURL=logout.d.ts.map
@@ -4,6 +4,11 @@
4
4
  *
5
5
  * The refresh token is revoked first so a copied token file stops working.
6
6
  * Local tokens are always deleted, even when the server can't be reached.
7
+ *
8
+ * `hq auth logout` is a second name for this command and runs the
9
+ * same {@link runLogout}, so both names revoke the person session's refresh
10
+ * token. Machine sessions are out of scope: they carry no refresh token, and
11
+ * the machine token cache in the daemon state folder is not cleared here.
7
12
  */
8
13
  import chalk from 'chalk';
9
14
  import { clearCachedTokens, loadCachedTokens } from '@indigoai-us/hq-cloud';
@@ -12,43 +17,45 @@ import { workContextRoot } from '../lib/work-context/paths.js';
12
17
  import { DEFAULT_COGNITO } from '../utils/cognito-config.js';
13
18
  import { revokeRefreshToken } from '../utils/cognito-revoke.js';
14
19
  export const REVOKE_FAILED_MESSAGE = "Signed out on this device. Couldn't reach HQ to end the session everywhere; it will expire on its own.";
15
- export function registerLogoutCommand(program) {
16
- program
17
- .command('logout')
18
- .description('Log out and clear cached credentials')
19
- .action(async () => {
20
+ /** Sign out: revoke the refresh token on the server, then delete local tokens. */
21
+ export async function runLogout() {
22
+ try {
23
+ const { clearMcpOAuthCaches } = await import('../lib/daemon/mcp-oauth.js');
24
+ clearMcpOAuthCaches();
25
+ // Signing out withdraws the opt-in to count no-company usage toward the
26
+ // default company; the next account must opt in for itself.
20
27
  try {
21
- const { clearMcpOAuthCaches } = await import('../lib/daemon/mcp-oauth.js');
22
- clearMcpOAuthCaches();
23
- // Signing out withdraws the opt-in to count no-company usage toward the
24
- // default company; the next account must opt in for itself.
25
- try {
26
- retainUsageAttributionForPerson(null, { root: workContextRoot() });
27
- }
28
- catch (error) {
29
- console.error(chalk.yellow('Could not withdraw the usage opt-in:'), error instanceof Error ? error.message : 'Unknown error');
30
- }
31
- const existing = loadCachedTokens();
32
- if (!existing) {
33
- console.log(chalk.yellow('No cached HQ session'));
34
- return;
35
- }
36
- // Machine-minted sessions carry no refresh token; nothing to revoke.
37
- const revoked = existing.refreshToken
38
- ? (await revokeRefreshToken(existing.refreshToken, DEFAULT_COGNITO)).ok
39
- : true;
40
- clearCachedTokens();
41
- if (revoked) {
42
- console.log(chalk.green('Logged out successfully'));
43
- }
44
- else {
45
- console.log(chalk.yellow(REVOKE_FAILED_MESSAGE));
46
- }
28
+ retainUsageAttributionForPerson(null, { root: workContextRoot() });
47
29
  }
48
30
  catch (error) {
49
- console.error(chalk.red('Logout failed:'), error instanceof Error ? error.message : 'Unknown error');
50
- process.exit(1);
31
+ console.error(chalk.yellow('Could not withdraw the usage opt-in:'), error instanceof Error ? error.message : 'Unknown error');
32
+ }
33
+ const existing = loadCachedTokens();
34
+ if (!existing) {
35
+ console.log(chalk.yellow('No cached HQ session'));
36
+ return;
37
+ }
38
+ // Machine-minted sessions carry no refresh token; nothing to revoke.
39
+ const revoked = existing.refreshToken
40
+ ? (await revokeRefreshToken(existing.refreshToken, DEFAULT_COGNITO)).ok
41
+ : true;
42
+ clearCachedTokens();
43
+ if (revoked) {
44
+ console.log(chalk.green('Logged out successfully'));
51
45
  }
52
- });
46
+ else {
47
+ console.log(chalk.yellow(REVOKE_FAILED_MESSAGE));
48
+ }
49
+ }
50
+ catch (error) {
51
+ console.error(chalk.red('Logout failed:'), error instanceof Error ? error.message : 'Unknown error');
52
+ process.exit(1);
53
+ }
54
+ }
55
+ export function registerLogoutCommand(program) {
56
+ program
57
+ .command('logout')
58
+ .description('Log out and clear cached credentials')
59
+ .action(runLogout);
53
60
  }
54
61
  //# sourceMappingURL=logout.js.map
@@ -13,6 +13,8 @@ export declare function localPrdWithStory(company: {
13
13
  prdPath: string;
14
14
  source: ProjectPlanSource;
15
15
  } | null;
16
+ /** 404 PROJECT_VIEW_NOT_FOUND: the project has no Board at all yet. */
17
+ export declare function isMissingBoardProject(error: unknown): boolean;
16
18
  type ProjectPlanSource = {
17
19
  name?: string;
18
20
  description?: string;
@@ -211,6 +211,52 @@ function unknownStoryHint(error, company, projectId, storyId, prdPath) {
211
211
  code: error?.code,
212
212
  });
213
213
  }
214
+ /** 404 PROJECT_VIEW_NOT_FOUND: the project has no Board at all yet. */
215
+ export function isMissingBoardProject(error) {
216
+ if (!error || typeof error !== "object" || httpStatus(error) !== 404)
217
+ return false;
218
+ const candidate = error;
219
+ return (candidate.code === "PROJECT_VIEW_NOT_FOUND" ||
220
+ (typeof candidate.message === "string" && candidate.message.includes("PROJECT_VIEW_NOT_FOUND")));
221
+ }
222
+ /**
223
+ * PATCH a story. When the story (or its whole project) is not on the Board but
224
+ * the local prd.json lists it, register the PRD (the same merge `hq mesh
225
+ * project ensure` does) and retry once. `ensure: false` only prints the command.
226
+ */
227
+ async function patchStoryRegisteringLocalPrd(token, company, projectId, storyId, patch, opts) {
228
+ try {
229
+ return { patched: await patchStory(token, company.companyUid, projectId, storyId, patch) };
230
+ }
231
+ catch (err) {
232
+ if (!isUnknownBoardStory(err) && !isMissingBoardProject(err))
233
+ throw err;
234
+ const recovery = localPrdWithStory(company, projectId, storyId);
235
+ if (!recovery)
236
+ throw unknownStoryHint(err, company, projectId, storyId);
237
+ if (opts.ensure === false) {
238
+ throw unknownStoryHint(err, company, projectId, storyId, recovery.prdPath);
239
+ }
240
+ await ensureProjectFromSource({
241
+ token,
242
+ company,
243
+ projectId,
244
+ source: recovery.source,
245
+ current: await getProjectView(token, company.companyUid, projectId).catch((viewErr) => {
246
+ if (httpStatus(viewErr) === 404)
247
+ return undefined;
248
+ throw viewErr;
249
+ }),
250
+ });
251
+ if (!opts.json) {
252
+ console.error(`Work mesh: ${storyId} was not on the ${projectId} Board; registered the project from ${recovery.prdPath}.`);
253
+ }
254
+ return {
255
+ patched: await patchStory(token, company.companyUid, projectId, storyId, patch),
256
+ registeredFrom: recovery.prdPath,
257
+ };
258
+ }
259
+ }
214
260
  async function runStory(opts) {
215
261
  const storyId = opts.story?.trim();
216
262
  const status = opts.status?.trim();
@@ -249,37 +295,7 @@ async function runStory(opts) {
249
295
  let patched;
250
296
  let registeredFrom;
251
297
  try {
252
- try {
253
- patched = await patchStory(token, company.companyUid, projectId, storyId, patch);
254
- }
255
- catch (err) {
256
- if (!isUnknownBoardStory(err))
257
- throw err;
258
- // The story is in the local PRD but not on the Board yet: register the
259
- // PRD (the same merge `hq mesh project ensure` does), then retry once.
260
- const recovery = localPrdWithStory(company, projectId, storyId);
261
- if (!recovery)
262
- throw unknownStoryHint(err, company, projectId, storyId);
263
- if (opts.ensure === false) {
264
- throw unknownStoryHint(err, company, projectId, storyId, recovery.prdPath);
265
- }
266
- await ensureProjectFromSource({
267
- token,
268
- company,
269
- projectId,
270
- source: recovery.source,
271
- current: await getProjectView(token, company.companyUid, projectId).catch((viewErr) => {
272
- if (httpStatus(viewErr) === 404)
273
- return undefined;
274
- throw viewErr;
275
- }),
276
- });
277
- registeredFrom = recovery.prdPath;
278
- if (!opts.json) {
279
- console.error(`Work mesh: ${storyId} was not on the ${projectId} Board; registered the project from ${recovery.prdPath}.`);
280
- }
281
- patched = await patchStory(token, company.companyUid, projectId, storyId, patch);
282
- }
298
+ ({ patched, registeredFrom } = await patchStoryRegisteringLocalPrd(token, company, projectId, storyId, patch, opts));
283
299
  }
284
300
  catch (err) {
285
301
  const conflict = storyConflictFromError(err);
@@ -315,12 +331,13 @@ async function runClaim(opts) {
315
331
  const { token, company } = await withCompany(opts);
316
332
  const me = await requireAssignableSelf(token, "hq mesh claim");
317
333
  let patched;
334
+ let registeredFrom;
318
335
  try {
319
- patched = await patchStory(token, company.companyUid, projectId, storyId, {
336
+ ({ patched, registeredFrom } = await patchStoryRegisteringLocalPrd(token, company, projectId, storyId, {
320
337
  status: "in_progress",
321
338
  assigneeUid: me,
322
339
  ...(opts.force ? { force: true } : {}),
323
- });
340
+ }, opts));
324
341
  }
325
342
  catch (err) {
326
343
  const conflict = storyConflictFromError(err);
@@ -329,7 +346,14 @@ async function runClaim(opts) {
329
346
  throw err;
330
347
  }
331
348
  if (opts.json) {
332
- console.log(JSON.stringify({ ok: true, action: "claim", company, ...patched, storyId }, null, 2));
349
+ console.log(JSON.stringify({
350
+ ok: true,
351
+ action: "claim",
352
+ company,
353
+ ...patched,
354
+ storyId,
355
+ ...(registeredFrom ? { registeredFrom } : {}),
356
+ }, null, 2));
333
357
  return;
334
358
  }
335
359
  console.log(`Work mesh: claimed ${storyId} (in_progress, assignee ${patched.assigneeUid ?? me}) (v${patched.version ?? "?"})`);
@@ -2750,7 +2774,8 @@ export function registerMeshCommand(program, deps = {}) {
2750
2774
  .command("claim")
2751
2775
  .description("Assign a story to yourself and move it to in_progress")
2752
2776
  .requiredOption("--story <id>", "Story id, e.g. US-001")
2753
- .option("--force", "Take the story even when someone else holds it")).action((opts) => wrap(() => runClaim(opts))());
2777
+ .option("--force", "Take the story even when someone else holds it")
2778
+ .option("--no-ensure", "Do not register the project from its local prd.json when the story is not on the Board")).action((opts) => wrap(() => runClaim(opts))());
2754
2779
  mesh
2755
2780
  .command("overlap")
2756
2781
  .description("List other sessions working on the same story, branch, or files")
@@ -56,6 +56,8 @@ export interface SyncOptions {
56
56
  company?: string;
57
57
  hqRoot: string;
58
58
  json?: boolean;
59
+ /** What the ledger lines record: `scheduled` for the bot's daily job, `on-demand` by default. */
60
+ trigger?: RunTrigger;
59
61
  }
60
62
  export interface SyncOverrides {
61
63
  /** Adapters to run. This build registers none, so the default is empty. */
@@ -124,8 +126,8 @@ export interface SignalsAlertSenders {
124
126
  export declare function runCompanyHotChannelSync(input: CompanyHotChannelSyncInput): Promise<OnDemandSyncReport>;
125
127
  /**
126
128
  * Run every hot channel for the signed-in person now: each adapter once per
127
- * usable connection. Writes cursors, landed sources and an `on-demand` ledger
128
- * line under `companies/{company}/sources/`, and nothing else.
129
+ * usable connection. Writes cursors, landed sources and a ledger line (trigger
130
+ * `on-demand` unless `--trigger` says `scheduled`) under `companies/{company}/sources/`, and nothing else.
129
131
  */
130
132
  export declare function runSync(options: SyncOptions, overrides?: SyncOverrides): Promise<OnDemandSyncReport>;
131
133
  export interface SignalsRedoOptions {
@@ -160,7 +162,10 @@ export interface SignalsRedoReport {
160
162
  /** Keys still waiting in each channel's pending file after the run. */
161
163
  pendingLeft: Record<string, number>;
162
164
  notices: string[];
165
+ /** The message of an error that stopped the run, else the first failed channel's pass error code. */
163
166
  error: string | null;
167
+ /** Pass error code per channel whose pass failed; the other channels still ran. */
168
+ failedChannels: Record<string, string>;
164
169
  exitCode: number;
165
170
  }
166
171
  /**
@@ -201,6 +206,7 @@ export declare class NoHotSignalSyncJobError extends Error {
201
206
  * first. Exits non-zero when `--at` is given and no job exists.
202
207
  */
203
208
  export declare function runSchedule(options: ScheduleOptions, overrides?: ScheduleOverrides): Promise<ScheduleReport>;
209
+ export declare function describeThrownError(err: unknown): string;
204
210
  export declare function registerSourcesCommand(program: Command): void;
205
211
  export {};
206
212
  //# sourceMappingURL=sources.d.ts.map