@songsid/agend 2.4.0-beta.20 → 2.4.0-beta.22

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 (256) hide show
  1. package/dist/agent-cli-instructions.md +1 -1
  2. package/dist/backend/claude-carry.d.ts +11 -0
  3. package/dist/backend/claude-carry.js +88 -6
  4. package/dist/backend/claude-carry.js.map +1 -1
  5. package/dist/backend/claude-code.js +3 -0
  6. package/dist/backend/claude-code.js.map +1 -1
  7. package/dist/build-provenance.json +1 -1
  8. package/dist/cache-ledger.d.ts +23 -21
  9. package/dist/cache-ledger.js +70 -6
  10. package/dist/cache-ledger.js.map +1 -1
  11. package/dist/cache-prices.d.ts +8 -6
  12. package/dist/cache-prices.js +12 -5
  13. package/dist/cache-prices.js.map +1 -1
  14. package/dist/cache-service.d.ts +9 -5
  15. package/dist/cache-service.js +202 -50
  16. package/dist/cache-service.js.map +1 -1
  17. package/dist/channel/mcp-tools.js +6 -4
  18. package/dist/channel/mcp-tools.js.map +1 -1
  19. package/dist/cli-audited.js +2 -1
  20. package/dist/cli-audited.js.map +1 -1
  21. package/dist/cli.js +4 -1
  22. package/dist/cli.js.map +1 -1
  23. package/dist/contact-auth-policy.js +1 -1
  24. package/dist/contact-auth-policy.js.map +1 -1
  25. package/dist/contact-auth-service.js +8 -2
  26. package/dist/contact-auth-service.js.map +1 -1
  27. package/dist/contact-auth-store.d.ts +3 -0
  28. package/dist/contact-auth-store.js +34 -8
  29. package/dist/contact-auth-store.js.map +1 -1
  30. package/dist/contact-auth-types.d.ts +3 -2
  31. package/dist/contact-auth-types.js.map +1 -1
  32. package/dist/contact-change-proposals.d.ts +47 -0
  33. package/dist/contact-change-proposals.js +132 -0
  34. package/dist/contact-change-proposals.js.map +1 -0
  35. package/dist/daemon.d.ts +31 -0
  36. package/dist/daemon.js +149 -2
  37. package/dist/daemon.js.map +1 -1
  38. package/dist/delivery-outbox.d.ts +10 -0
  39. package/dist/delivery-outbox.js +21 -0
  40. package/dist/delivery-outbox.js.map +1 -1
  41. package/dist/fleet-manager.d.ts +65 -1
  42. package/dist/fleet-manager.js +338 -20
  43. package/dist/fleet-manager.js.map +1 -1
  44. package/dist/general-knowledge/skills/concepts/SKILL.md +2 -1
  45. package/dist/general-knowledge/skills/hub/SKILL.md +45 -5
  46. package/dist/general-knowledge/skills/task-board/SKILL.md +4 -0
  47. package/dist/general-knowledge/skills/web-appearance/SKILL.md +1 -1
  48. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +16 -6
  49. package/dist/hub/agent-pictures-model.d.ts +275 -0
  50. package/dist/hub/agent-pictures-model.js +103 -0
  51. package/dist/hub/agent-pictures-model.js.map +1 -0
  52. package/dist/hub/agent-pictures.d.ts +64 -0
  53. package/dist/hub/agent-pictures.js +255 -0
  54. package/dist/hub/agent-pictures.js.map +1 -0
  55. package/dist/hub/client.d.ts +4 -0
  56. package/dist/hub/client.js +23 -2
  57. package/dist/hub/client.js.map +1 -1
  58. package/dist/hub/compose/member.d.ts +14 -3
  59. package/dist/hub/compose/member.js +46 -10
  60. package/dist/hub/compose/member.js.map +1 -1
  61. package/dist/hub/compose/server.d.ts +6 -5
  62. package/dist/hub/compose/server.js +7 -3
  63. package/dist/hub/compose/server.js.map +1 -1
  64. package/dist/hub/direct-posts-model.d.ts +1 -0
  65. package/dist/hub/direct-posts-model.js +2 -0
  66. package/dist/hub/direct-posts-model.js.map +1 -0
  67. package/dist/hub/direct-posts.d.ts +36 -0
  68. package/dist/hub/direct-posts.js +145 -0
  69. package/dist/hub/direct-posts.js.map +1 -0
  70. package/dist/hub/http/compose.d.ts +5 -0
  71. package/dist/hub/http/compose.js +158 -20
  72. package/dist/hub/http/compose.js.map +1 -1
  73. package/dist/hub/http/core.d.ts +9 -1
  74. package/dist/hub/http/core.js +21 -1
  75. package/dist/hub/http/core.js.map +1 -1
  76. package/dist/hub/http/deps.d.ts +1 -0
  77. package/dist/hub/http/schema.js +7 -0
  78. package/dist/hub/http/schema.js.map +1 -1
  79. package/dist/hub/init/text.js +1 -1
  80. package/dist/hub/join/service.d.ts +2 -0
  81. package/dist/hub/join/service.js +7 -3
  82. package/dist/hub/join/service.js.map +1 -1
  83. package/dist/hub/member/agent-pictures.d.ts +76 -0
  84. package/dist/hub/member/agent-pictures.js +196 -0
  85. package/dist/hub/member/agent-pictures.js.map +1 -0
  86. package/dist/hub/member/direct-rooms.d.ts +9 -0
  87. package/dist/hub/member/direct-rooms.js +14 -0
  88. package/dist/hub/member/direct-rooms.js.map +1 -0
  89. package/dist/hub/member/room-ask.d.ts +22 -1
  90. package/dist/hub/member/room-ask.js +99 -5
  91. package/dist/hub/member/room-ask.js.map +1 -1
  92. package/dist/hub/member/room-asker-store.d.ts +48 -0
  93. package/dist/hub/member/room-asker-store.js +181 -0
  94. package/dist/hub/member/room-asker-store.js.map +1 -0
  95. package/dist/hub/member/room-post.d.ts +11 -10
  96. package/dist/hub/member/room-post.js +51 -7
  97. package/dist/hub/member/room-post.js.map +1 -1
  98. package/dist/hub/policy.d.ts +11 -2
  99. package/dist/hub/policy.js +60 -7
  100. package/dist/hub/policy.js.map +1 -1
  101. package/dist/hub/protocol.d.ts +254 -1
  102. package/dist/hub/protocol.js +20 -8
  103. package/dist/hub/protocol.js.map +1 -1
  104. package/dist/hub/representative.d.ts +38 -0
  105. package/dist/hub/representative.js +140 -12
  106. package/dist/hub/representative.js.map +1 -1
  107. package/dist/hub/room-asker-identity-model.d.ts +53 -0
  108. package/dist/hub/room-asker-identity-model.js +14 -0
  109. package/dist/hub/room-asker-identity-model.js.map +1 -0
  110. package/dist/hub/room-asker-identity.d.ts +22 -0
  111. package/dist/hub/room-asker-identity.js +43 -0
  112. package/dist/hub/room-asker-identity.js.map +1 -0
  113. package/dist/hub/rooms/agents.d.ts +2 -0
  114. package/dist/hub/rooms/agents.js +30 -3
  115. package/dist/hub/rooms/agents.js.map +1 -1
  116. package/dist/hub/rooms/asker-identity.d.ts +21 -0
  117. package/dist/hub/rooms/asker-identity.js +86 -0
  118. package/dist/hub/rooms/asker-identity.js.map +1 -0
  119. package/dist/hub/rooms/direct-view.d.ts +3 -2
  120. package/dist/hub/rooms/direct-view.js +23 -8
  121. package/dist/hub/rooms/direct-view.js.map +1 -1
  122. package/dist/hub/rooms/office.d.ts +27 -0
  123. package/dist/hub/rooms/office.js +12 -2
  124. package/dist/hub/rooms/office.js.map +1 -1
  125. package/dist/hub/rooms/service.d.ts +38 -1
  126. package/dist/hub/rooms/service.js +56 -3
  127. package/dist/hub/rooms/service.js.map +1 -1
  128. package/dist/hub/rooms/types.d.ts +5 -2
  129. package/dist/hub/rooms.d.ts +9 -0
  130. package/dist/hub/rooms.js +97 -26
  131. package/dist/hub/rooms.js.map +1 -1
  132. package/dist/hub/runtime.d.ts +1 -1
  133. package/dist/hub/server.js +24 -2
  134. package/dist/hub/server.js.map +1 -1
  135. package/dist/hub/session-directory-transition.d.ts +1 -0
  136. package/dist/hub/session-directory-transition.js +15 -9
  137. package/dist/hub/session-directory-transition.js.map +1 -1
  138. package/dist/hub/session-limits.d.ts +58 -0
  139. package/dist/hub/session-limits.js +121 -0
  140. package/dist/hub/session-limits.js.map +1 -0
  141. package/dist/hub/sessions.d.ts +1 -1
  142. package/dist/hub/sessions.js +13 -7
  143. package/dist/hub/sessions.js.map +1 -1
  144. package/dist/hub/settings-directory-decision.js +1 -1
  145. package/dist/hub/settings-directory-decision.js.map +1 -1
  146. package/dist/hub/types.d.ts +9 -2
  147. package/dist/hub-character-plan.d.ts +47 -0
  148. package/dist/hub-character-plan.js +70 -0
  149. package/dist/hub-character-plan.js.map +1 -0
  150. package/dist/hub-contact-windows.d.ts +13 -1
  151. package/dist/hub-contact-windows.js +35 -2
  152. package/dist/hub-contact-windows.js.map +1 -1
  153. package/dist/hub-picture-reduce.d.ts +34 -0
  154. package/dist/hub-picture-reduce.js +101 -0
  155. package/dist/hub-picture-reduce.js.map +1 -0
  156. package/dist/hub-picture-worker.d.ts +1 -0
  157. package/dist/hub-picture-worker.js +19 -0
  158. package/dist/hub-picture-worker.js.map +1 -0
  159. package/dist/hub-report-target.d.ts +6 -0
  160. package/dist/hub-report-target.js +6 -0
  161. package/dist/hub-report-target.js.map +1 -1
  162. package/dist/locale.js +357 -265
  163. package/dist/locale.js.map +1 -1
  164. package/dist/ls-rows.d.ts +2 -0
  165. package/dist/ls-rows.js.map +1 -1
  166. package/dist/needs-you.d.ts +6 -0
  167. package/dist/needs-you.js +3 -1
  168. package/dist/needs-you.js.map +1 -1
  169. package/dist/outbound-handlers.d.ts +8 -0
  170. package/dist/outbound-handlers.js +53 -6
  171. package/dist/outbound-handlers.js.map +1 -1
  172. package/dist/outbound-schemas.d.ts +2 -0
  173. package/dist/outbound-schemas.js +6 -4
  174. package/dist/outbound-schemas.js.map +1 -1
  175. package/dist/runtime-cli-install.js +4 -4
  176. package/dist/runtime-cli-install.js.map +1 -1
  177. package/dist/task-board-tool.d.ts +17 -0
  178. package/dist/task-board-tool.js +58 -6
  179. package/dist/task-board-tool.js.map +1 -1
  180. package/dist/tips.js +3 -3
  181. package/dist/tool-permissions.js +2 -2
  182. package/dist/tool-permissions.js.map +1 -1
  183. package/dist/ui/agent-export-strings.js +1 -1
  184. package/dist/ui/agent-page-strings.js +5 -5
  185. package/dist/ui/contact-auth-client.js +2 -2
  186. package/dist/ui/contact-tool-groups.js +1 -1
  187. package/dist/ui/fleet-cache.js +5 -5
  188. package/dist/ui/fleet-canvas.js +3 -2
  189. package/dist/ui/fleet-office-card.js +46 -7
  190. package/dist/ui/fleet-office-dialogue.d.ts +6 -3
  191. package/dist/ui/fleet-office-dialogue.js +13 -3
  192. package/dist/ui/fleet-office-layout.js +15 -15
  193. package/dist/ui/fleet-office-model.js +3 -2
  194. package/dist/ui/fleet-office-overview.js +1 -1
  195. package/dist/ui/fleet-office-pack.d.ts +17 -7
  196. package/dist/ui/fleet-office-pack.js +106 -38
  197. package/dist/ui/fleet-office-play.js +11 -4
  198. package/dist/ui/fleet-office-skin.js +41 -11
  199. package/dist/ui/fleet-office-store.js +10 -1
  200. package/dist/ui/fleet-office-talk.js +423 -0
  201. package/dist/ui/fleet-office-view.js +58 -17
  202. package/dist/ui/fleet-office-zones.js +20 -12
  203. package/dist/ui/fleet-office.js +250 -65
  204. package/dist/ui/fleet-org.js +3 -3
  205. package/dist/ui/fleet-task-common.js +3 -3
  206. package/dist/ui/fleet-task-sort.js +88 -0
  207. package/dist/ui/fleet-task-view.js +38 -9
  208. package/dist/ui/fleet-tasks.js +47 -15
  209. package/dist/ui/fleet-usage.js +6 -6
  210. package/dist/ui/hub-admin-overview.js +1 -1
  211. package/dist/ui/hub-chat-store.js +4 -3
  212. package/dist/ui/hub-chat-strings.js +3 -1
  213. package/dist/ui/hub-client.js +3 -0
  214. package/dist/ui/hub-my-agents-strings.js +2 -2
  215. package/dist/ui/hub-my-agents.js +3 -0
  216. package/dist/ui/hub-room-composer.js +24 -4
  217. package/dist/ui/hub-room-members.js +7 -3
  218. package/dist/ui/hub-room-office.js +71 -2
  219. package/dist/ui/hub-room-presence.js +14 -0
  220. package/dist/ui/hub-room-strings.js +18 -2
  221. package/dist/ui/hub-room-thread.js +82 -13
  222. package/dist/ui/hub-room-working.js +37 -0
  223. package/dist/ui/hub-session-limits.js +79 -0
  224. package/dist/ui/panel-fleet.js +5 -5
  225. package/dist/ui/panel-hub.js +41 -6
  226. package/dist/ui/panel-log.js +3 -3
  227. package/dist/ui/panel-needs.js +28 -2
  228. package/dist/ui/panel-runtimes.js +2 -2
  229. package/dist/ui/runtime-cli-install.js +1 -1
  230. package/dist/ui/runtime-update-status.js +1 -1
  231. package/dist/ui/settings-access-strings.js +1 -1
  232. package/dist/ui/settings-hub-setup-strings.js +1 -1
  233. package/dist/ui/settings-layout.js +2 -2
  234. package/dist/ui/settings-named-test.js +16 -16
  235. package/dist/ui/settings-public-session-strings.js +2 -2
  236. package/dist/ui/settings-revoke-strings.js +1 -1
  237. package/dist/ui/settings-shared-strings.js +2 -2
  238. package/dist/ui/settings-strings.js +40 -40
  239. package/dist/ui/shared/app-shell.js +1 -1
  240. package/dist/ui/shared/app.css +106 -6
  241. package/dist/ui/shared/chat-strings.js +9 -9
  242. package/dist/ui/shared/hub-owner.css +5 -0
  243. package/dist/ui/shared/hub-rooms-u2.css +3 -0
  244. package/dist/ui/shared/instance-nav.js +36 -2
  245. package/dist/ui/shared/office-dialogue.css +110 -0
  246. package/dist/ui/shared/task-board.css +103 -7
  247. package/dist/ui/shared/view-strings.js +27 -9
  248. package/dist/web-api.d.ts +5 -0
  249. package/dist/web-api.js +29 -0
  250. package/dist/web-api.js.map +1 -1
  251. package/dist/web-office-skins.d.ts +8 -2
  252. package/dist/web-office-skins.js +33 -14
  253. package/dist/web-office-skins.js.map +1 -1
  254. package/dist/web-office-store.js +5 -3
  255. package/dist/web-office-store.js.map +1 -1
  256. package/package.json +1 -1
package/dist/daemon.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { managedClaudeBinding } from "./claude-credential-launch.js";
2
2
  import { HUB_REPORT_TARGET } from "./hub-report-target.js";
3
+ import { atomicWriteFileSync } from "./atomic-write.js";
3
4
  import { RoomConversationGeneration, roomContextInputMarker } from "./hub-room-conversation.js";
4
5
  import { checkpointGrokDelivery } from "./grok-delivery-proof.js";
5
6
  import { nativePaneToolRefusal } from "./native-pane-tools.js";
@@ -1141,6 +1142,33 @@ const FLEET_RESPONSE_TYPES = new Set([
1141
1142
  "fleet_schedule_response", "fleet_outbound_response", "fleet_decision_response", "fleet_task_response",
1142
1143
  "fleet_display_name_response", "fleet_description_response", "fleet_persona_emoji_response", "fleet_web_theme_response",
1143
1144
  ]);
1145
+ /** null: no record (no turn). "unknown": a record that cannot be read or makes no sense — a turn may be running. */
1146
+ function readHubAnswerTurn(file) {
1147
+ let text;
1148
+ try {
1149
+ text = readFileSync(file, "utf8");
1150
+ }
1151
+ catch (err) {
1152
+ return err.code === "ENOENT" ? null : "unknown";
1153
+ }
1154
+ try {
1155
+ const r = JSON.parse(text);
1156
+ if (!r || typeof r.correlationId !== "string" || !/^hub-[A-Za-z0-9-]+$/.test(r.correlationId))
1157
+ return "unknown";
1158
+ return { correlationId: r.correlationId, contactLimit: r.contactLimit !== false, sawWorking: true, restored: true };
1159
+ }
1160
+ catch {
1161
+ return "unknown";
1162
+ }
1163
+ }
1164
+ /**
1165
+ * M-3660: a question from the Hub (a representative or room ask) that the agent answers with report_result to agend-hub.
1166
+ * It trusts the meta: only the fleet writes fleet_inbound, and from_instance "agend-hub" is its reserved sender — an
1167
+ * agent's send_to_instance is stamped with the agent's own name.
1168
+ */
1169
+ export function isHubQuestionMeta(meta) {
1170
+ return meta.from_instance === HUB_REPORT_TARGET && meta.request_kind === "query" && /^hub-[A-Za-z0-9-]+$/.test(meta.correlation_id ?? "");
1171
+ }
1144
1172
  export class Daemon extends EventEmitter {
1145
1173
  name;
1146
1174
  config;
@@ -3278,6 +3306,7 @@ export class Daemon extends EventEmitter {
3278
3306
  }
3279
3307
  // Batch response for prune path
3280
3308
  this.ipcServer?.send(socket, { type: "query_sessions_response", sessions });
3309
+ this.ipcServer?.send(socket, this.hubAnswerTurnStateMessage()); // M-3660: a fresh connection learns the current turn
3281
3310
  }
3282
3311
  else
3283
3312
  this.handleFleetMessage(msg, reply => { this.ipcServer?.send(socket, reply); });
@@ -3386,6 +3415,7 @@ export class Daemon extends EventEmitter {
3386
3415
  if (nativeDisposition)
3387
3416
  this.isNewSession = nativeDisposition === "fresh";
3388
3417
  this.resetRoomConversation(nativeDisposition === "reattached");
3418
+ this.settleHubAnswerTurnAtLaunch(nativeDisposition === "reattached");
3389
3419
  // #1209: conditional continuation for the turn interrupted by the last
3390
3420
  // restart, if the gates allow. Detached; the gate
3391
3421
  // consumes its one-shot marker first and never throws into boot.
@@ -6323,6 +6353,7 @@ export class Daemon extends EventEmitter {
6323
6353
  }
6324
6354
  if (msg.type === "query_sessions") {
6325
6355
  send({ type: "query_sessions_response", sessions: [] });
6356
+ send(this.hubAnswerTurnStateMessage()); // M-3660
6326
6357
  }
6327
6358
  else if (msg.type === "fleet_inbound") {
6328
6359
  const meta = msg.meta;
@@ -7310,6 +7341,99 @@ export class Daemon extends EventEmitter {
7310
7341
  hubRoomTurnBoot = randomUUID();
7311
7342
  hubRoomTurnSequence = 0;
7312
7343
  turnEndTimer = null;
7344
+ /**
7345
+ * M-3660: the Hub question this pane is answering as a turn of its own — from just before its write until the idle edge
7346
+ * after that turn's work (or the next write into the idle pane). The fleet keeps the agent's contact window for exactly
7347
+ * this turn: hub_question_input opens it, hub_question_turn_ended closes it.
7348
+ */
7349
+ // It is kept on disk too (hub-answer-turn.json): a daemon restarted mid-turn takes it up again, so deliveries keep
7350
+ // waiting behind it and its end is still announced; the fleet is told the current state again on every (re)connect.
7351
+ hubAnswerTurnState;
7352
+ /** Prism #4420 P2-2: the turn record exists but cannot be read — a turn may be running; fail closed until an idle edge. */
7353
+ hubAnswerTurnUnknown = false;
7354
+ get hubAnswerTurn() {
7355
+ if (this.hubAnswerTurnState === undefined) {
7356
+ const file = this.hubAnswerTurnFile(), read = file ? readHubAnswerTurn(file) : null;
7357
+ this.hubAnswerTurnUnknown = read === "unknown";
7358
+ this.hubAnswerTurnState = read === "unknown" ? null : read;
7359
+ }
7360
+ return this.hubAnswerTurnState;
7361
+ }
7362
+ /** M-3660: a turn is running, or may be (an unreadable record): nothing is handed into it. */
7363
+ hubAnswerTurnMayRun() { return this.hubAnswerTurn !== null || this.hubAnswerTurnUnknown; }
7364
+ /** The unknown is resolved (an idle edge, a write into the idle pane): no turn runs; the fleet is told "none". */
7365
+ resolveUnknownHubAnswerTurn() {
7366
+ if (!this.hubAnswerTurnUnknown)
7367
+ return;
7368
+ this.hubAnswerTurnUnknown = false;
7369
+ const file = this.hubAnswerTurnFile();
7370
+ try {
7371
+ if (file)
7372
+ rmSync(file, { force: true });
7373
+ }
7374
+ catch (err) {
7375
+ this.logger.warn({ err }, "Unreadable Hub answer turn record could not be removed");
7376
+ }
7377
+ this.broadcastFleetMessage({ type: "hub_question_turn_state", correlationId: null });
7378
+ }
7379
+ hubAnswerTurnFile() { return typeof this.instanceDir === "string" ? join(this.instanceDir, "hub-answer-turn.json") : null; }
7380
+ /** A turn's end is always kept in memory; a record that cannot be removed is read as a restored turn later (fail closed). */
7381
+ setHubAnswerTurn(turn) {
7382
+ this.hubAnswerTurnState = turn;
7383
+ const file = this.hubAnswerTurnFile();
7384
+ if (!file)
7385
+ return;
7386
+ try {
7387
+ if (turn)
7388
+ atomicWriteFileSync(file, JSON.stringify({ correlationId: turn.correlationId, contactLimit: turn.contactLimit }), { mode: 0o600 });
7389
+ else
7390
+ rmSync(file, { force: true });
7391
+ }
7392
+ catch (err) {
7393
+ // Prism #4420 P2-2: a turn that cannot be recorded is not begun — its question is not written (the caller throws).
7394
+ if (turn) {
7395
+ this.hubAnswerTurnState = null;
7396
+ throw err;
7397
+ }
7398
+ this.logger.warn({ err }, "Hub answer turn end could not be saved; a restart reads it as a turn that ends at its first idle edge");
7399
+ }
7400
+ }
7401
+ hubAnswerTurnBegins(correlationId, contactLimit = true) {
7402
+ if (correlationId !== undefined && this.hubAnswerTurn?.correlationId === correlationId)
7403
+ return; // a retried write
7404
+ this.resolveUnknownHubAnswerTurn(); // written into the idle pane: whatever might have run is over
7405
+ this.endHubAnswerTurn();
7406
+ if (correlationId === undefined)
7407
+ return;
7408
+ // Throws when the turn cannot be recorded: the question is then not written, and its delivery fails (reported).
7409
+ this.setHubAnswerTurn({ correlationId, contactLimit, sawWorking: false, restored: false });
7410
+ this.broadcastFleetMessage({ type: "hub_question_input", correlationId, contactLimit });
7411
+ }
7412
+ endHubAnswerTurn() {
7413
+ const turn = this.hubAnswerTurn;
7414
+ if (!turn)
7415
+ return;
7416
+ this.setHubAnswerTurn(null);
7417
+ this.broadcastFleetMessage({ type: "hub_question_turn_ended", correlationId: turn.correlationId });
7418
+ }
7419
+ /**
7420
+ * Lumen #4420 R2-A: a turn taken up from the record outlives nothing but the pane it ran in. A launch that starts a new
7421
+ * CLI (every launch but a native reattach) ends it, and an unreadable record resolves to "none", at once.
7422
+ */
7423
+ settleHubAnswerTurnAtLaunch(reattached) {
7424
+ if (reattached)
7425
+ return;
7426
+ if (this.hubAnswerTurn?.restored)
7427
+ this.endHubAnswerTurn();
7428
+ this.resolveUnknownHubAnswerTurn();
7429
+ }
7430
+ /** M-3660: the current Hub answer turn, told to a fleet connection when it (re)connects (a signal may have been lost). */
7431
+ hubAnswerTurnStateMessage() {
7432
+ const turn = this.hubAnswerTurn;
7433
+ if (!turn && this.hubAnswerTurnUnknown)
7434
+ return { type: "hub_question_turn_state", correlationId: null, unknown: true };
7435
+ return { type: "hub_question_turn_state", correlationId: turn?.correlationId ?? null, ...(turn ? { contactLimit: turn.contactLimit } : {}) };
7436
+ }
7313
7437
  /** M-3239: Claude's and Codex's transcripts tell each tool call and answer; their pane's spinner alone is not a turn. */
7314
7438
  turnEvidence() {
7315
7439
  const bin = this.backend?.binaryName;
@@ -7336,9 +7460,17 @@ export class Daemon extends EventEmitter {
7336
7460
  if (state === "working") {
7337
7461
  this.turnWatch.begin(Date.now());
7338
7462
  this.hubRoomTurnActivityStart ??= this.hubRoomTranscriptActivity;
7463
+ {
7464
+ const hubTurn = this.hubAnswerTurn;
7465
+ if (hubTurn)
7466
+ hubTurn.sawWorking = true;
7467
+ }
7339
7468
  }
7340
7469
  return;
7341
7470
  }
7471
+ // Lumen #4420 R2-A: a turn taken up from the record ends on the first idle state, at once (no settle wait, no work proof).
7472
+ if (this.hubAnswerTurn?.restored)
7473
+ this.endHubAnswerTurn();
7342
7474
  if (this.turnEndTimer)
7343
7475
  return;
7344
7476
  const roomGeneration = this.roomConversationState ? this.roomConversationGeneration() : null, roomInputEpoch = this.hubRoomInputEpoch;
@@ -7349,6 +7481,14 @@ export class Daemon extends EventEmitter {
7349
7481
  const bin = this.backend?.binaryName, needsTranscript = bin === "claude" || bin === "codex";
7350
7482
  const realWork = !needsTranscript || this.hubRoomTurnActivityStart !== null && this.hubRoomTranscriptActivity > this.hubRoomTurnActivityStart;
7351
7483
  this.hubRoomTurnActivityStart = null;
7484
+ // M-3660: the Hub answer turn ends only on real work (a compaction spinner is not its end: realWork needs a fresh
7485
+ // working edge AND transcript activity since it, so a flicker leaves the turn running until real work then idle) —
7486
+ // or, taken up again after a daemon restart, on the first idle edge.
7487
+ const hubTurn = this.hubAnswerTurn;
7488
+ if (hubTurn?.sawWorking && (realWork || hubTurn.restored))
7489
+ this.endHubAnswerTurn();
7490
+ else if (!hubTurn)
7491
+ this.resolveUnknownHubAnswerTurn(); // an unreadable record: the pane is idle now, nothing runs
7352
7492
  if (turn && realWork && roomGeneration && roomGeneration === this.roomConversationGeneration() && roomInputEpoch === this.hubRoomInputEpoch)
7353
7493
  this.broadcastFleetMessage({ type: "hub_room_turn_ended", generation: roomGeneration, turn: `${this.hubRoomTurnBoot}:${++this.hubRoomTurnSequence}` });
7354
7494
  if (!turn || turn.messaged || !turn.text.trim() || !this.turnEvidence())
@@ -9033,6 +9173,7 @@ export class Daemon extends EventEmitter {
9033
9173
  sent = await this.deliverMessage(pasted, status, {
9034
9174
  deliveryEpoch,
9035
9175
  submissionId: meta.message_id,
9176
+ ...(isHubQuestionMeta(meta) ? { hubQuestion: meta.correlation_id, hubContactLimit: meta.hub_contact_limit !== "off" } : {}),
9036
9177
  ...(meta.hub_room_context_generation ? { roomContextGeneration: meta.hub_room_context_generation } : {}),
9037
9178
  ...(meta.verification_id ? { humanVerificationId: meta.verification_id, humanMeta: meta } : {}),
9038
9179
  verdict,
@@ -9166,7 +9307,10 @@ export class Daemon extends EventEmitter {
9166
9307
  // normal Enter input has steering/interrupt semantics in several other CLIs.
9167
9308
  let readiness = "ready";
9168
9309
  const gateWindowId = windowId;
9169
- const handOffEligible = !!(supportsQueuedInput || opts?.steer || composerQueue);
9310
+ // M-3660: a Hub question is never handed into a running turn (Claude would merge it into that turn's work), and while
9311
+ // a Hub answer turn runs, nothing else is handed into it: each waits for the idle pane and becomes a turn of its own.
9312
+ const exclusiveTurn = opts?.hubQuestion !== undefined || this.hubAnswerTurnMayRun();
9313
+ const handOffEligible = !exclusiveTurn && !!(supportsQueuedInput || opts?.steer || composerQueue);
9170
9314
  const handOffAdmissible = async () => (await this.probeBlockingDialog()).state === "clear"
9171
9315
  && await this.hasPositiveDeliveryInput(true)
9172
9316
  && ((!opts?.steer && !composerQueue) || (this.launchTakesSteer() && await this.steerComposerAdmits(false, opts?.steer === true)));
@@ -9347,7 +9491,10 @@ export class Daemon extends EventEmitter {
9347
9491
  return stale();
9348
9492
  if (residue !== "clear")
9349
9493
  return this.failDelivery(verdict, status, "input-residue", residue);
9350
- const written = await this.writeMessageToPane(formatted, windowId, handingOffToNativeQueue, status, opts?.submissionId, verdict, opts?.durableAttempt, opts?.steer === true, writeCurrent, opts?.humanVerificationId, opts?.beforePaneWrite, opts?.lookBeforePaneWrite, opts?.humanMeta);
9494
+ const written = await this.writeMessageToPane(formatted, windowId, handingOffToNativeQueue, status, opts?.submissionId, verdict, opts?.durableAttempt, opts?.steer === true, writeCurrent, opts?.humanVerificationId,
9495
+ // M-3660: written into an idle pane, so whatever Hub answer turn ran is over; a Hub question begins its own.
9496
+ () => { if (!handingOffToNativeQueue)
9497
+ this.hubAnswerTurnBegins(opts?.hubQuestion, opts?.hubContactLimit !== false); opts?.beforePaneWrite?.(); }, opts?.lookBeforePaneWrite, opts?.humanMeta);
9351
9498
  // #1690: still under the lock — whatever waits on it next must already see what this write started.
9352
9499
  if (verdict.paneWriteStarted)
9353
9500
  opts?.onPaneWritten?.();