@makaio/framework 1.0.0-dev-1783282710723 → 1.0.0-dev-1783439621927

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 (194) hide show
  1. package/dist/.makaio-build.json +2 -2
  2. package/dist/adapter-Lx6K7yQS.mjs +1 -0
  3. package/dist/adapter-subsystem/index.mjs +1 -1
  4. package/dist/adapters/config/index.d.mts +1 -1
  5. package/dist/adapters/index.d.mts +229 -41
  6. package/dist/adapters/index.mjs +6 -6
  7. package/dist/adapters/node.d.mts +1 -1
  8. package/dist/adapters/node.mjs +1 -1
  9. package/dist/{base-orchestrator-Cw0vpNgB.d.mts → base-orchestrator-ODRyDBzu.d.mts} +79 -3
  10. package/dist/bus/index.mjs +1 -1
  11. package/dist/client-n0OJiTt1.mjs +1 -0
  12. package/dist/contracts/adapter/index.d.mts +2 -2
  13. package/dist/contracts/adapter/index.mjs +1 -1
  14. package/dist/contracts/adapter/schemas/session-lineage.d.mts +1 -1
  15. package/dist/contracts/adapter/schemas/session-lineage.mjs +1 -1
  16. package/dist/contracts/artifact/index.d.mts +1 -1
  17. package/dist/contracts/client/index.d.mts +2 -2
  18. package/dist/contracts/client/index.mjs +1 -1
  19. package/dist/contracts/config/index.d.mts +6 -6
  20. package/dist/contracts/extension/index.d.mts +2 -2
  21. package/dist/contracts/facet/index.d.mts +1 -1
  22. package/dist/contracts/harness/index.d.mts +1 -1
  23. package/dist/contracts/index.d.mts +375 -197
  24. package/dist/contracts/index.mjs +1 -1
  25. package/dist/contracts/materialization/index.d.mts +3 -3
  26. package/dist/contracts/provider/index.d.mts +1 -1
  27. package/dist/contracts/session/index.d.mts +3 -3
  28. package/dist/contracts/session/index.mjs +1 -1
  29. package/dist/contracts/variant/index.d.mts +1 -1
  30. package/dist/contracts/workflow/index.d.mts +2 -2
  31. package/dist/contracts/workflow/index.mjs +1 -1
  32. package/dist/{definition-DFcxkf2i.d.mts → definition-DpkfJi8v.d.mts} +1 -1
  33. package/dist/drizzle/0021_m_mr8e1j84.sql +3 -0
  34. package/dist/drizzle/0022_m_mr8i4ky3.sql +43 -0
  35. package/dist/drizzle/0023_m_mr9gc37m.sql +1 -0
  36. package/dist/drizzle/meta/_journal.json +21 -0
  37. package/dist/{handler-2bPhRn0u.mjs → handler-BFNvtv5t.mjs} +1 -1
  38. package/dist/handlers-B74FvKlA.mjs +57 -0
  39. package/dist/hooks/index.d.mts +27 -2
  40. package/dist/hooks/index.mjs +1 -1
  41. package/dist/{identity-BarL3JYI.mjs → identity-DC3Pk0ps.mjs} +1 -1
  42. package/dist/{index-4eP9DRL_.d.mts → index-B3fjN5HX.d.mts} +7 -7
  43. package/dist/{index-Bh6lHiW4.d.mts → index-B5Uczo3R.d.mts} +40 -40
  44. package/dist/{index-CL2T6LVv.d.mts → index-BIZeIA5k.d.mts} +8 -8
  45. package/dist/{index-gAFwNiJT.d.mts → index-BvTd61i5.d.mts} +212 -26
  46. package/dist/{index-Y2r0Zvcm.d.mts → index-BvjLe_w9.d.mts} +12 -12
  47. package/dist/{index-2fK9iSHI.d.mts → index-BwGfdbI0.d.mts} +9 -9
  48. package/dist/{index-CaOWqztb.d.mts → index-C8k2f_E0.d.mts} +1 -1
  49. package/dist/{index-DEzdNQum.d.mts → index-CYHWOXUm.d.mts} +1 -1
  50. package/dist/{index-9b2_jXxq.d.mts → index-CwHP8Jxs.d.mts} +514 -96
  51. package/dist/{index-D6aAzr32.d.mts → index-Cyi7y_aG.d.mts} +20 -20
  52. package/dist/{index-DdBRlm7m.d.mts → index-D7Fu3375.d.mts} +401 -21
  53. package/dist/{index-CfIW5biI.d.mts → index-D7rWAEY0.d.mts} +1 -0
  54. package/dist/{index-CTEsbp9H.d.mts → index-DFK3tpEY.d.mts} +83 -5
  55. package/dist/{index-Dg-y1mrq.d.mts → index-DS6kxiFl.d.mts} +28 -28
  56. package/dist/{index-BMbmoarE.d.mts → index-DTBQOCar.d.mts} +16 -16
  57. package/dist/{index-GD-i3DW7.d.mts → index-DmJ-OpTD.d.mts} +1275 -224
  58. package/dist/{index-DLy-tc0L.d.mts → index-Dtb2cVJz.d.mts} +260 -47
  59. package/dist/{index-D9-vOJvZ.d.mts → index-h5go5Dtd.d.mts} +1 -1
  60. package/dist/kernel/extension/index.d.mts +1 -1
  61. package/dist/kernel/index.d.mts +2 -2
  62. package/dist/kernel/observability/index.d.mts +1 -1
  63. package/dist/{lib-Ba55od_d.mjs → lib-BOmKyjWD.mjs} +1 -1
  64. package/dist/{lib-CM_BUxN8.mjs → lib-DLZYp5z3.mjs} +1 -1
  65. package/dist/{loop-gate-handlers-BLoGCWMQ.mjs → loop-gate-handlers-Bjmat-K3.mjs} +1 -1
  66. package/dist/{namespace-D8P8Sxce2.d.mts → namespace-6sIu5nBI2.d.mts} +2 -2
  67. package/dist/{namespace-CfvtDD_U.d.mts → namespace-BLER-Qom.d.mts} +2 -2
  68. package/dist/{namespace-B3ol3pc-.d.mts → namespace-BigVYQyx.d.mts} +12 -0
  69. package/dist/{namespace-j7vFsmYL.d.mts → namespace-C74bbsdZ.d.mts} +2 -2
  70. package/dist/{namespace-B4cV_pk3.d.mts → namespace-CGxFYDlK.d.mts} +32 -32
  71. package/dist/{namespace-LUNf8zo5.d.mts → namespace-D1_9WVCo.d.mts} +157 -0
  72. package/dist/{namespace-KMxsPJwm.d.mts → namespace-D4Uf5Mw_.d.mts} +432 -18
  73. package/dist/{namespace-BsYKEMd8.d.mts → namespace-DAj_riOn.d.mts} +138 -0
  74. package/dist/{namespace-DXW-voCe.d.mts → namespace-DRXQyBe0.d.mts} +204 -24
  75. package/dist/{namespace-DGAWYjbO.d.mts → namespace-JFzrlNs4.d.mts} +27 -27
  76. package/dist/namespace-dFBD2ZmS.mjs +1 -0
  77. package/dist/node/transports/index.mjs +1 -1
  78. package/dist/orchestrator-shared-ChygCvR1.mjs +1 -0
  79. package/dist/{orchestrator-shared-ChOdIgh6.d.mts → orchestrator-shared-DFLb1otg.d.mts} +9 -3
  80. package/dist/{package-MmQvNJ3u.d.mts → package-B6mEMD8r.d.mts} +5 -0
  81. package/dist/package-BQn_RTo7.mjs +1 -0
  82. package/dist/package.json +1 -1
  83. package/dist/runtime-node/index.mjs +1 -1
  84. package/dist/schema-7aKBGB7S.mjs +1 -0
  85. package/dist/{schema-D1HrnvT7.d.mts → schema-B9goOieO.d.mts} +50 -1
  86. package/dist/{schema-DHlTAy0N.mjs → schema-CHp6I33k.mjs} +1 -1
  87. package/dist/{schemas-D-9zNyAM2.d.mts → schemas-9S9Y9PHT2.d.mts} +7 -7
  88. package/dist/{schemas-CoFCV42v.d.mts → schemas-B_t6oOK-.d.mts} +2 -2
  89. package/dist/{schemas-lnE9YoG7.d.mts → schemas-CW6YsPT4.d.mts} +3 -3
  90. package/dist/schemas-CkOigLAT.mjs +1 -0
  91. package/dist/{schemas-BemsLc_V.d.mts → schemas-CurUbHy4.d.mts} +4 -4
  92. package/dist/{schemas-DMCGXlKa.d.mts → schemas-DXeGCbJ9.d.mts} +4 -4
  93. package/dist/schemas-DZGnr9Tl.mjs +1 -0
  94. package/dist/{schemas-DWfo0wp4.d.mts → schemas-DnmbwE_V.d.mts} +7 -7
  95. package/dist/{schemas-DmGRSeIq.d.mts → schemas-t6h9oSct.d.mts} +28 -1
  96. package/dist/services/adapter-runtime/index.d.mts +4 -4
  97. package/dist/services/adapter-runtime/index.mjs +1 -1
  98. package/dist/services/adapter-runtime/namespace.d.mts +1 -1
  99. package/dist/services/adapter-runtime/schemas.d.mts +2 -2
  100. package/dist/services/adapter-runtime/schemas.mjs +1 -1
  101. package/dist/services/adapter-subsystem/index.d.mts +2 -2
  102. package/dist/services/adapter-subsystem/namespace.d.mts +1 -1
  103. package/dist/services/agent-runtime/index.d.mts +2 -2
  104. package/dist/services/agent-runtime/namespace.d.mts +1 -1
  105. package/dist/services/agent-runtime/schemas.d.mts +1 -1
  106. package/dist/services/context-rules/index.d.mts +3 -3
  107. package/dist/services/filesystem/namespace.d.mts +6 -6
  108. package/dist/services/filesystem/schemas.d.mts +3 -3
  109. package/dist/services/git/namespace.d.mts +2 -2
  110. package/dist/services/git/schemas.d.mts +2 -2
  111. package/dist/services/harness/index.d.mts +4 -4
  112. package/dist/services/harness/index.mjs +1 -1
  113. package/dist/services/index.d.mts +129 -53
  114. package/dist/services/index.mjs +1 -1
  115. package/dist/services/log-import/browser.d.mts +2 -2
  116. package/dist/services/log-import/index.d.mts +86 -6
  117. package/dist/services/log-import/index.mjs +2 -2
  118. package/dist/services/log-import/log-import.d.mts +1 -1
  119. package/dist/services/log-import/log-import.mjs +1 -1
  120. package/dist/services/log-import/namespace.d.mts +54 -0
  121. package/dist/services/log-import/namespace.mjs +1 -1
  122. package/dist/services/log-import/schemas.d.mts +44 -0
  123. package/dist/services/log-import/schemas.mjs +1 -1
  124. package/dist/services/preferences/index.d.mts +2 -2
  125. package/dist/services/preferences/schemas.d.mts +1 -1
  126. package/dist/services/preferences/storage-namespace.d.mts +2 -2
  127. package/dist/services/session/handlers/index.d.mts +1 -1
  128. package/dist/services/session/handlers/index.mjs +1 -1
  129. package/dist/services/session/index.d.mts +9 -9
  130. package/dist/services/session/index.mjs +1 -1
  131. package/dist/services/session/messages/namespace.d.mts +1 -1
  132. package/dist/services/session/messages/namespace.mjs +1 -1
  133. package/dist/services/session/orchestrator-testing/index.d.mts +1 -1
  134. package/dist/services/session/orchestrator-testing/index.mjs +1 -1
  135. package/dist/services/session/session-events/namespace.d.mts +1 -1
  136. package/dist/services/session/session-events/namespace.mjs +1 -1
  137. package/dist/services/session/storage/namespace.d.mts +1 -1
  138. package/dist/services/session/storage/schema.d.mts +1 -1
  139. package/dist/services/session/storage/schema.mjs +1 -1
  140. package/dist/services/session/testing/index.mjs +10 -4
  141. package/dist/services/session/testing/orchestrator-shared.d.mts +1 -1
  142. package/dist/services/session/testing/orchestrator-shared.mjs +1 -1
  143. package/dist/services/session/turns/namespace.d.mts +1 -1
  144. package/dist/services/session/turns/namespace.mjs +1 -1
  145. package/dist/services/session-editor/index.d.mts +1 -1
  146. package/dist/services/settings/namespace.d.mts +7 -7
  147. package/dist/services/subagent-template/index.d.mts +2 -2
  148. package/dist/services/subagent-template/namespace.d.mts +1 -1
  149. package/dist/services/subagent-template/schemas.d.mts +1 -1
  150. package/dist/services/tool-approval/index.mjs +1 -1
  151. package/dist/services/tools/index.mjs +1 -1
  152. package/dist/services/tray-menu/index.d.mts +2 -2
  153. package/dist/services/tray-menu/namespace.d.mts +1 -1
  154. package/dist/services/tray-menu/schemas.d.mts +1 -1
  155. package/dist/services/turn/index.d.mts +1 -1
  156. package/dist/services/turn/namespace.d.mts +1 -1
  157. package/dist/services/turn/schemas.d.mts +89 -0
  158. package/dist/services/turn/schemas.mjs +1 -1
  159. package/dist/session-CZUrp7gC.mjs +69 -0
  160. package/dist/session-Dp7z5N1d.mjs +1 -0
  161. package/dist/{session-lineage-DR-9DU-U.d.mts → session-lineage-C1M7-O3C.d.mts} +3 -3
  162. package/dist/storage/drizzle/index.d.mts +1 -1
  163. package/dist/storage/drizzle/index.mjs +1 -1
  164. package/dist/{storage-namespace-Di1A3DMm.d.mts → storage-namespace-BvRF22by.d.mts} +10 -10
  165. package/dist/{tool-approval-service-DEQiipxj.mjs → tool-approval-service-BIbUSuqg.mjs} +1 -1
  166. package/dist/tools-Yz8XyiwA.mjs +1 -0
  167. package/dist/{transition-DnXibkhX.d.mts → transition-DYorNHZu.d.mts} +1 -1
  168. package/dist/{types-Dur8EtpR.d.mts → types-9XCB1aPK.d.mts} +562 -107
  169. package/dist/{types-BMS6yfLS.d.mts → types-BNW5n6qm.d.mts} +1 -1
  170. package/dist/{types-BslClRkH.d.mts → types-BWduCvRU.d.mts} +22 -1
  171. package/dist/{types-Cse8s_cD.d.mts → types-N_BOtTqt.d.mts} +29 -18
  172. package/dist/ui-components/index.mjs +1 -1
  173. package/dist/ui-kernel/index.d.mts +4 -4
  174. package/dist/ui-kernel/pages/namespace.d.mts +4 -4
  175. package/dist/ui-kernel/pages/schemas.d.mts +1 -1
  176. package/dist/{workflow-BqH6ar-D.mjs → workflow-C1z7I5CI.mjs} +1 -1
  177. package/dist/workflow-engine/index.d.mts +45 -45
  178. package/dist/workflow-engine/index.mjs +1 -1
  179. package/dist/workflow-engine/package.d.mts +1 -1
  180. package/dist/workflow-engine/package.mjs +1 -1
  181. package/dist/workflow-engine/workflow-orchestrator.mjs +1 -1
  182. package/package.json +1 -1
  183. package/dist/adapter-DaQqmKOJ.mjs +0 -1
  184. package/dist/client-BcfR-LJC.mjs +0 -1
  185. package/dist/handlers-BAycjV02.mjs +0 -41
  186. package/dist/namespace-C-piH3w4.mjs +0 -1
  187. package/dist/orchestrator-shared-Cxk3x8Vs.mjs +0 -1
  188. package/dist/package-B1AXe-oz.mjs +0 -1
  189. package/dist/schema-D6WAI8OL.mjs +0 -1
  190. package/dist/schemas-ArqQTC0Q.mjs +0 -1
  191. package/dist/schemas-uID59wR8.mjs +0 -1
  192. package/dist/session-0nWT4st6.mjs +0 -39
  193. package/dist/session-DH-ja8Ka.mjs +0 -1
  194. package/dist/tools-DFOsOboy.mjs +0 -1
@@ -87,6 +87,8 @@ declare class Turn$1 {
87
87
  private readonly _agentIds;
88
88
  /** Messages sent during this turn */
89
89
  private readonly _messageIds;
90
+ /** Message IDs currently claiming this turn while their storage append is in-flight. */
91
+ private readonly _pendingMessageAppends;
90
92
  /** Agents that have completed successfully */
91
93
  private readonly _completedAgents;
92
94
  /** Agents that errored (agentId → error message) */
@@ -108,6 +110,11 @@ declare class Turn$1 {
108
110
  * @returns Immutable array of message IDs
109
111
  */
110
112
  get messageIds(): readonly string[];
113
+ /**
114
+ * Whether a user message has claimed this turn before its storage append completes.
115
+ * @returns True when at least one message append is in-flight
116
+ */
117
+ get hasPendingMessageAppends(): boolean;
111
118
  /**
112
119
  * Agents that have completed successfully.
113
120
  * @returns Read-only set of completed agent IDs
@@ -123,6 +130,16 @@ declare class Turn$1 {
123
130
  * @param messageId - The message ID to add
124
131
  */
125
132
  addMessage(messageId: string): void;
133
+ /**
134
+ * Claim this turn for a message whose durable append has started.
135
+ * @param messageId - Message ID whose append is in-flight
136
+ */
137
+ claimMessageAppend(messageId: string): void;
138
+ /**
139
+ * Release a failed message append claim without adding the message.
140
+ * @param messageId - Message ID whose append failed
141
+ */
142
+ releaseMessageAppend(messageId: string): void;
126
143
  /**
127
144
  * Mark an agent as completed successfully.
128
145
  * @param agentId - The agent that completed
@@ -165,6 +182,12 @@ declare class Turn$1 {
165
182
  * @returns Turn context with turnId and the specified messageId
166
183
  */
167
184
  getContextForMessage(messageId: string): TurnContext;
185
+ /**
186
+ * Return the recorded terminal outcome for an agent, if any.
187
+ * @param agentId - Agent ID to inspect.
188
+ * @returns Terminal outcome already recorded for the agent.
189
+ */
190
+ private getAgentTerminalOutcome;
168
191
  /**
169
192
  * Check if turn should complete and return appropriate state change.
170
193
  * @returns State change indicating completion status and result if complete
@@ -201,15 +224,29 @@ type TurnCompleteCallback = (turn: Turn$1, result: TurnCompletionResult) => Prom
201
224
  * `TurnStorageSubjects.create` is unhandled, synthetic IDs are generated
202
225
  * locally. When `TurnStorageSubjects.complete` is unhandled, the turn is
203
226
  * still cleared from memory and `session.turn.completed` is emitted.
227
+ *
228
+ * **Persist-before-emit barrier:** `session.turn.completed` promises the
229
+ * four-point consumer contract, including messages being queryable via
230
+ * `storage:message.getByTurn`. Message persistence (SessionBridge) and turn
231
+ * completion both react to `agent.complete`, and the bus runs event handlers
232
+ * in parallel — so before emitting, `completeTurn` awaits
233
+ * `storage:message.stored` confirmations for the turn's assistant messages
234
+ * (bus-mediated: the manager holds no reference to SessionBridge). The wait
235
+ * is bounded by {@link TURN_COMPLETION_PERSISTENCE_TIMEOUT_MS} and skipped
236
+ * entirely in ephemeral mode.
204
237
  */
205
238
  declare class SessionTurnManager {
206
239
  private readonly bus;
207
240
  /** Active turns keyed by sessionId (one turn per session). */
208
241
  private readonly activeTurns;
209
- /** Per-session usage accumulators, parallel to activeTurns. */
242
+ /** Per-turn usage accumulators, keyed by turnId. */
210
243
  private readonly usageAccumulators;
211
- /** Sessions currently persisting turn completion (prevents concurrent writes). */
212
- private readonly completingSessions;
244
+ /** Turns currently persisting completion (prevents concurrent writes). */
245
+ private readonly completingTurnIds;
246
+ /** Completing turns retained for usage correlation after active routing is cleared. */
247
+ private readonly completingTurns;
248
+ /** Pending terminal completions keyed by turnId; value records whether turn storage handled the transition. */
249
+ private readonly pendingTerminalCompletions;
213
250
  /** Usage events received while completion persistence is in-flight. */
214
251
  private readonly bufferedUsageDuringCompletion;
215
252
  /**
@@ -221,6 +258,18 @@ declare class SessionTurnManager {
221
258
  * the counter and cause duplicate turn numbers if the session continues.
222
259
  */
223
260
  private readonly syntheticTurnCounters;
261
+ /**
262
+ * Stored assistant messages per turnId, counted from `storage:message.stored`.
263
+ *
264
+ * Populated continuously (from construction) so messages persisted before
265
+ * `completeTurn` runs are counted. FIFO-capped at
266
+ * {@link ASSISTANT_PERSISTENCE_COUNTER_CAP}; a turn's entry is deleted when
267
+ * its completion emits, so late `stored` events for an already-emitted turn
268
+ * merely recreate a short-lived entry that the cap eventually evicts.
269
+ */
270
+ private readonly assistantStoredCounts;
271
+ /** Pending persist-before-emit barrier waiters, keyed by turnId. */
272
+ private readonly assistantPersistenceWaiters;
224
273
  /** Bus subscription cleanup functions. */
225
274
  private readonly cleanups;
226
275
  /**
@@ -240,6 +289,28 @@ declare class SessionTurnManager {
240
289
  * @returns The newly created and activated Turn entity
241
290
  */
242
291
  createTurn(sessionId: string, agentIds: string[], initiator?: TurnInitiator, turnId?: string): Promise<Turn$1>;
292
+ /**
293
+ * Discard active in-memory state for a turn that failed before routing began.
294
+ *
295
+ * Use when no durable turn row needs a terminal status transition.
296
+ * @param turn - Newly created active turn to discard
297
+ */
298
+ discardActiveTurn(turn: Turn$1): void;
299
+ /**
300
+ * Mark an unclaimed newly created turn as failed and discard its active in-memory state.
301
+ *
302
+ * This preserves the durable turn lifecycle invariant when setup fails after
303
+ * `storage:turn.create` has already assigned a turn number.
304
+ * @param turn - Newly created active turn whose setup failed before any message claimed it
305
+ * @param error - Durable error code to store on the terminal turn
306
+ */
307
+ failActiveTurnSetup(turn: Turn$1, error: string): Promise<void>;
308
+ /**
309
+ * Remove a turn from the active routing index when it is no longer routable.
310
+ * @param turn - Turn to remove when it still owns the session slot
311
+ * @returns Whether the turn owned and cleared the active routing slot
312
+ */
313
+ private clearActiveRoutingTurn;
243
314
  /**
244
315
  * Register bus listeners for `agent.usage` and `agent.complete` events.
245
316
  *
@@ -260,10 +331,22 @@ declare class SessionTurnManager {
260
331
  * `TurnStorageSubjects.complete` call. State is cleared only after durable
261
332
  * persistence succeeds; if persistence fails, the state remains intact so
262
333
  * completion can be retried.
334
+ *
335
+ * Before the event fires, the persist-before-emit barrier waits for the
336
+ * turn's assistant messages to be stored (see class docs), then a
337
+ * `turn.completed` lifecycle row is appended to `session_events` — so both
338
+ * message rows and the lifecycle row are durable before consumers observe
339
+ * `session.turn.completed`.
263
340
  * @param turn - The turn to complete
264
341
  * @param result - Turn result (success status and error messages)
265
342
  */
266
343
  completeTurn(turn: Turn$1, result: TurnCompletionResult): Promise<void>;
344
+ /**
345
+ * Clear in-memory state retained only while a turn completion is in progress.
346
+ * @param turn - Turn whose completion state should be removed
347
+ * @param usageAccumulator - Optional accumulator retained for late usage merges
348
+ */
349
+ private clearCompletionState;
267
350
  /**
268
351
  * Get the active turn for a session, if any.
269
352
  * @param sessionId - Session identifier
@@ -303,14 +386,85 @@ declare class SessionTurnManager {
303
386
  * @param success - Whether the agent completed successfully
304
387
  * @param error - Error message if the agent failed
305
388
  * @param onTurnComplete - Callback to invoke when the turn is complete
389
+ * @param completionTurnId - Turn identifier supplied by the adapter completion event
306
390
  */
307
391
  private handleAgentCompletion;
308
392
  /**
309
393
  * Buffer a usage event that arrived while turn completion persistence is in-flight.
310
- * @param sessionId - Session whose turn is currently completing
394
+ * @param turnId - Turn whose completion is currently being persisted
311
395
  * @param usageEvent - Usage event to defer until after persistence
312
396
  */
313
397
  private bufferUsageDuringCompletion;
398
+ /**
399
+ * Find a turn that may still accept usage by turnId.
400
+ * @param turnId - Turn identifier from an agent usage event
401
+ * @returns Active or completing turn, if usage can still be recorded
402
+ */
403
+ private findTurnForUsage;
404
+ /**
405
+ * Find a turn that may still accept agent completion by turnId.
406
+ * @param turnId - Turn identifier from an agent completion event
407
+ * @returns Active or completing turn, if completion can still be correlated
408
+ */
409
+ private findTurnForCompletion;
410
+ /**
411
+ * Find the active turn for a legacy completion event without turnId.
412
+ * @param agentId - Agent ID from the completion event.
413
+ * @returns Active turn to mutate, or undefined when the event is ambiguous.
414
+ */
415
+ private findTurnForUncorrelatedCompletion;
416
+ /**
417
+ * Check whether a terminal outcome has already been recorded for an agent.
418
+ * @param turn - Turn being completed.
419
+ * @param agentId - Agent ID from the terminal event.
420
+ * @returns Whether the agent already has a terminal outcome on the turn.
421
+ */
422
+ private hasTerminalOutcome;
423
+ /**
424
+ * Persist a turn's terminal status and optional usage snapshot.
425
+ * @param turn - Turn being completed
426
+ * @param result - Completion result to persist
427
+ * @param usage - Usage snapshot to include, when available
428
+ * @param expectedStatus - Optional status guard for the first terminal transition
429
+ * @returns Whether turn storage handled the request and terminalized the turn
430
+ */
431
+ private persistTurnCompletion;
432
+ /**
433
+ * Merge buffered usage and persist the updated snapshot.
434
+ * @param turn - Turn whose buffered usage should be merged
435
+ * @param result - Completion result for the turn
436
+ * @param usageAccumulator - Usage accumulator captured by the completing turn
437
+ * @param currentUsage - Current completed usage snapshot
438
+ * @returns Updated usage snapshot
439
+ */
440
+ private flushBufferedUsageDuringCompletion;
441
+ /**
442
+ * Subscribe to `storage:message.stored` and count stored assistant messages
443
+ * per turnId, resolving any pending barrier waiter on each increment.
444
+ *
445
+ * Registered from the constructor (not `registerCompletionHandlers`) so the
446
+ * barrier also works for callers that drive `completeTurn` directly without
447
+ * wiring the agent-event handlers.
448
+ */
449
+ private registerAssistantPersistenceCounter;
450
+ /**
451
+ * Persist-before-emit barrier: wait until the turn's assistant messages are
452
+ * durably stored (one per agent) or the bounded timeout elapses.
453
+ *
454
+ * Resolution paths, in order:
455
+ * 1. The continuous `storage:message.stored` counter already reached the
456
+ * expected count (messages stored before `completeTurn` ran).
457
+ * 2. `storage:message.getByTurn` is unhandled — no message storage exists,
458
+ * nothing can be waited for (skip).
459
+ * 3. A queryable-state probe already shows the expected assistant messages
460
+ * (covers messages persisted before this manager was constructed).
461
+ * 4. A waiter resolved by the counter reaching the expected count, bounded
462
+ * by {@link TURN_COMPLETION_PERSISTENCE_TIMEOUT_MS} — the timeout is
463
+ * mandatory because SessionBridge persists nothing for agents with zero
464
+ * blocks and no error, and swallows write errors.
465
+ * @param turn - The completing turn (expected count = its agent count)
466
+ */
467
+ private awaitAssistantPersistence;
314
468
  }
315
469
  //#endregion
316
470
  //#region services/core/src/session/handlers/abandon-handler.d.ts
@@ -359,9 +513,10 @@ declare function registerCompressHandler(bus: IMakaioBus): () => void;
359
513
  * Creates a new session with parent reference. The forked session starts
360
514
  * empty - its full conversation is assembled by traversing the parent chain.
361
515
  * @param bus - Bus instance for communication
516
+ * @param machineId - Stable runtime machine identity to stamp on child sessions
362
517
  * @returns Cleanup function to unsubscribe
363
518
  */
364
- declare function registerForkHandler(bus: IMakaioBus): () => void;
519
+ declare function registerForkHandler(bus: IMakaioBus, machineId?: string): () => void;
365
520
  //#endregion
366
521
  //#region services/core/src/session/handlers/merge-handler.d.ts
367
522
  /**
@@ -385,6 +540,50 @@ interface CwdSwapMeta {
385
540
  previousCwd: string;
386
541
  newCwd: string;
387
542
  }
543
+ /**
544
+ * Options for routing a message to target agents.
545
+ */
546
+ interface RouteToAgentsOptions {
547
+ /** Bus instance for communication. */
548
+ readonly bus: IMakaioBus;
549
+ /** Session metadata (for fork detection). */
550
+ readonly session: IMakaioSession;
551
+ /** Target agents to route to. */
552
+ readonly agents: MakaioSessionAgent[];
553
+ /** Message content to send. */
554
+ readonly message: MessageInput;
555
+ /** Message identifier. */
556
+ readonly messageId: string;
557
+ /** Turn tracking object. */
558
+ readonly turn: Turn$1;
559
+ /** How to deliver the message. */
560
+ readonly deliveryMode: 'enqueue' | 'immediate' | undefined;
561
+ /** Callback when turn completes (all agents done). */
562
+ readonly onTurnComplete: (turn: Turn$1, result: {
563
+ success: boolean;
564
+ errors: string[];
565
+ }) => Promise<void>;
566
+ /** Session context with curated messageHistory and decision signals. */
567
+ readonly sessionContext?: SessionContext;
568
+ /** Optional enricher for immediate message context. */
569
+ readonly turnContextEnricher?: ITurnContextEnricher;
570
+ /** Whether this is the first message in a new turn. */
571
+ readonly isNewTurn?: boolean;
572
+ /** Context enriched with messageHistory for agents that were just recovered. */
573
+ readonly recoveryContext?: SessionContext;
574
+ /** Set of agent IDs that were recovered in this handler invocation. */
575
+ readonly recoveredAgentIds?: ReadonlySet<string>;
576
+ /** Set of agent IDs that swapped connector due to cwd mismatch. */
577
+ readonly swappedAgentIds?: ReadonlySet<string>;
578
+ /** Previous/new cwd metadata keyed by agent ID. */
579
+ readonly swappedAgentCwd?: ReadonlyMap<string, CwdSwapMeta>;
580
+ /** Curated history for agents forced into fresh mode. */
581
+ readonly freshMessageHistory?: Message[];
582
+ /** Optional structured output descriptor for the turn. */
583
+ readonly responseSchema?: ResponseSchemaDescriptor;
584
+ /** Stable machine identity of the current host process for locality evaluation. */
585
+ readonly localMachineId?: string;
586
+ }
388
587
  /**
389
588
  * Route a message to target agents via agent.sendMessage.
390
589
  *
@@ -392,28 +591,9 @@ interface CwdSwapMeta {
392
591
  * and checks for turn completion.
393
592
  *
394
593
  * For fork sessions on their first turn, assembles projected context from parent chain.
395
- * @param bus - Bus instance for communication
396
- * @param session - Session metadata (for fork detection)
397
- * @param agents - Target agents to route to
398
- * @param message - Message content to send
399
- * @param messageId - Message identifier
400
- * @param turn - Turn tracking object
401
- * @param deliveryMode - How to deliver the message
402
- * @param onTurnComplete - Callback when turn completes (all agents done)
403
- * @param sessionContext - Session context with curated messageHistory and decision signals
404
- * @param turnContextEnricher - Optional enricher for immediate message context
405
- * @param isNewTurn - Whether this is the first message in a new turn
406
- * @param recoveryContext - Context enriched with messageHistory for agents that were just recovered
407
- * @param recoveredAgentIds - Set of agent IDs that were recovered in this handler invocation
408
- * @param swappedAgentIds - Set of agent IDs that swapped connector due to cwd mismatch
409
- * @param swappedAgentCwd - Previous/new cwd metadata keyed by agent ID
410
- * @param freshMessageHistory - Curated history for agents forced into fresh mode
411
- * @param responseSchema - Optional structured output descriptor for the turn
594
+ * @param options - Routing options including bus, session, agents, message, and lifecycle dependencies
412
595
  */
413
- declare function routeToAgents(bus: IMakaioBus, session: IMakaioSession, agents: MakaioSessionAgent[], message: MessageInput, messageId: string, turn: Turn$1, deliveryMode: 'enqueue' | 'immediate' | undefined, onTurnComplete: (turn: Turn$1, result: {
414
- success: boolean;
415
- errors: string[];
416
- }) => Promise<void>, sessionContext?: SessionContext, turnContextEnricher?: ITurnContextEnricher, isNewTurn?: boolean, recoveryContext?: SessionContext, recoveredAgentIds?: ReadonlySet<string>, swappedAgentIds?: ReadonlySet<string>, swappedAgentCwd?: ReadonlyMap<string, CwdSwapMeta>, freshMessageHistory?: Message[], responseSchema?: ResponseSchemaDescriptor): Promise<void>;
596
+ declare function routeToAgents(options: RouteToAgentsOptions): Promise<void>;
417
597
  //#endregion
418
598
  //#region services/core/src/session/handlers/route-to-agents-core.d.ts
419
599
  /**
@@ -422,6 +602,12 @@ declare function routeToAgents(bus: IMakaioBus, session: IMakaioSession, agents:
422
602
  * Fans out to all agents in parallel. On routing failure, marks the agent
423
603
  * as errored and checks for turn completion. On `HookAbortError`, marks
424
604
  * the agent as completed with `cancelled` outcome.
605
+ *
606
+ * Contract: `sessionContext` must not carry a `nativeFork` directive. This
607
+ * function dispatches exclusively via `agent.sendMessage`, which never
608
+ * consumes the directive — fork directives are consumed only on the
609
+ * `startAgent` path. Callers assembling fork contexts must degrade them to
610
+ * fresh-with-history first (see `routeToAgents`).
425
611
  * @param bus - Bus instance for communication
426
612
  * @param session - Session metadata (for session ID)
427
613
  * @param agents - Target agents to route to
@@ -140,17 +140,16 @@ declare const HarnessDefinitionCreateSchema: z.ZodObject<{
140
140
  cwd: z.ZodOptional<z.ZodString>;
141
141
  env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
142
142
  name: z.ZodString;
143
- adapterName: z.ZodOptional<z.ZodString>;
144
143
  nativeTools: z.ZodObject<{
145
144
  enabled: z.ZodArray<z.ZodString>;
146
145
  disabled: z.ZodArray<z.ZodString>;
147
146
  }, z.core.$strip>;
148
- clientId: z.ZodOptional<z.ZodString>;
149
- credentials: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
150
147
  registryTools: z.ZodObject<{
151
148
  enabled: z.ZodArray<z.ZodString>;
152
149
  disabled: z.ZodArray<z.ZodString>;
153
150
  }, z.core.$strip>;
151
+ adapterName: z.ZodOptional<z.ZodString>;
152
+ clientId: z.ZodOptional<z.ZodString>;
154
153
  skills: z.ZodOptional<z.ZodObject<{
155
154
  enabled: z.ZodArray<z.ZodString>;
156
155
  disabled: z.ZodArray<z.ZodString>;
@@ -176,6 +175,7 @@ declare const HarnessDefinitionCreateSchema: z.ZodObject<{
176
175
  "always-ask": "always-ask";
177
176
  "full-access": "full-access";
178
177
  }>>>;
178
+ credentials: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
179
179
  approvalPolicy: z.ZodOptional<z.ZodEnum<{
180
180
  reject: "reject";
181
181
  "always-ask": "always-ask";
@@ -316,17 +316,16 @@ declare const HarnessSchemas: {
316
316
  cwd: z.ZodOptional<z.ZodString>;
317
317
  env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
318
318
  name: z.ZodString;
319
- adapterName: z.ZodOptional<z.ZodString>;
320
319
  nativeTools: z.ZodObject<{
321
320
  enabled: z.ZodArray<z.ZodString>;
322
321
  disabled: z.ZodArray<z.ZodString>;
323
322
  }, z.core.$strip>;
324
- clientId: z.ZodOptional<z.ZodString>;
325
- credentials: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
326
323
  registryTools: z.ZodObject<{
327
324
  enabled: z.ZodArray<z.ZodString>;
328
325
  disabled: z.ZodArray<z.ZodString>;
329
326
  }, z.core.$strip>;
327
+ adapterName: z.ZodOptional<z.ZodString>;
328
+ clientId: z.ZodOptional<z.ZodString>;
330
329
  skills: z.ZodOptional<z.ZodObject<{
331
330
  enabled: z.ZodArray<z.ZodString>;
332
331
  disabled: z.ZodArray<z.ZodString>;
@@ -352,6 +351,7 @@ declare const HarnessSchemas: {
352
351
  "always-ask": "always-ask";
353
352
  "full-access": "full-access";
354
353
  }>>>;
354
+ credentials: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
355
355
  approvalPolicy: z.ZodOptional<z.ZodEnum<{
356
356
  reject: "reject";
357
357
  "always-ask": "always-ask";
@@ -759,17 +759,16 @@ declare const HarnessNamespace: _$_makaio_core0.BusNamespaceDefinition<"harness"
759
759
  cwd: z.ZodOptional<z.ZodString>;
760
760
  env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
761
761
  name: z.ZodString;
762
- adapterName: z.ZodOptional<z.ZodString>;
763
762
  nativeTools: z.ZodObject<{
764
763
  enabled: z.ZodArray<z.ZodString>;
765
764
  disabled: z.ZodArray<z.ZodString>;
766
765
  }, z.core.$strip>;
767
- clientId: z.ZodOptional<z.ZodString>;
768
- credentials: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
769
766
  registryTools: z.ZodObject<{
770
767
  enabled: z.ZodArray<z.ZodString>;
771
768
  disabled: z.ZodArray<z.ZodString>;
772
769
  }, z.core.$strip>;
770
+ adapterName: z.ZodOptional<z.ZodString>;
771
+ clientId: z.ZodOptional<z.ZodString>;
773
772
  skills: z.ZodOptional<z.ZodObject<{
774
773
  enabled: z.ZodArray<z.ZodString>;
775
774
  disabled: z.ZodArray<z.ZodString>;
@@ -795,6 +794,7 @@ declare const HarnessNamespace: _$_makaio_core0.BusNamespaceDefinition<"harness"
795
794
  "always-ask": "always-ask";
796
795
  "full-access": "full-access";
797
796
  }>>>;
797
+ credentials: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
798
798
  approvalPolicy: z.ZodOptional<z.ZodEnum<{
799
799
  reject: "reject";
800
800
  "always-ask": "always-ask";
@@ -1202,17 +1202,16 @@ declare const HarnessSubjects: _$_makaio_core0.BusSubjects<_$_makaio_core0.FlatS
1202
1202
  cwd: z.ZodOptional<z.ZodString>;
1203
1203
  env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
1204
1204
  name: z.ZodString;
1205
- adapterName: z.ZodOptional<z.ZodString>;
1206
1205
  nativeTools: z.ZodObject<{
1207
1206
  enabled: z.ZodArray<z.ZodString>;
1208
1207
  disabled: z.ZodArray<z.ZodString>;
1209
1208
  }, z.core.$strip>;
1210
- clientId: z.ZodOptional<z.ZodString>;
1211
- credentials: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
1212
1209
  registryTools: z.ZodObject<{
1213
1210
  enabled: z.ZodArray<z.ZodString>;
1214
1211
  disabled: z.ZodArray<z.ZodString>;
1215
1212
  }, z.core.$strip>;
1213
+ adapterName: z.ZodOptional<z.ZodString>;
1214
+ clientId: z.ZodOptional<z.ZodString>;
1216
1215
  skills: z.ZodOptional<z.ZodObject<{
1217
1216
  enabled: z.ZodArray<z.ZodString>;
1218
1217
  disabled: z.ZodArray<z.ZodString>;
@@ -1238,6 +1237,7 @@ declare const HarnessSubjects: _$_makaio_core0.BusSubjects<_$_makaio_core0.FlatS
1238
1237
  "always-ask": "always-ask";
1239
1238
  "full-access": "full-access";
1240
1239
  }>>>;
1240
+ credentials: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
1241
1241
  approvalPolicy: z.ZodOptional<z.ZodEnum<{
1242
1242
  reject: "reject";
1243
1243
  "always-ask": "always-ask";
@@ -48,8 +48,8 @@ declare const MaterializationSchemas: {
48
48
  template: z.ZodString;
49
49
  }, z.core.$strip>], "kind">;
50
50
  appliesTo: z.ZodArray<z.ZodEnum<{
51
- artifact: "artifact";
52
51
  workpiece: "workpiece";
52
+ artifact: "artifact";
53
53
  surface: "surface";
54
54
  }>>;
55
55
  valueMapping: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
@@ -88,8 +88,8 @@ declare const MaterializationSchemas: {
88
88
  template: z.ZodString;
89
89
  }, z.core.$strip>], "kind">;
90
90
  appliesTo: z.ZodArray<z.ZodEnum<{
91
- artifact: "artifact";
92
91
  workpiece: "workpiece";
92
+ artifact: "artifact";
93
93
  surface: "surface";
94
94
  }>>;
95
95
  valueMapping: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
@@ -106,8 +106,8 @@ declare const MaterializationSchemas: {
106
106
  provider: z.ZodString;
107
107
  externalId: z.ZodString;
108
108
  operation: z.ZodEnum<{
109
- deleted: "deleted";
110
109
  upserted: "upserted";
110
+ deleted: "deleted";
111
111
  }>;
112
112
  }, z.core.$strip>; /** Emitted when a provider surface capability set has been resolved. */
113
113
  'capability.resolved': z.ZodObject<{
@@ -153,8 +153,8 @@ declare const MaterializationNamespace: _$_makaio_core0.BusNamespaceDefinition<"
153
153
  template: z.ZodString;
154
154
  }, z.core.$strip>], "kind">;
155
155
  appliesTo: z.ZodArray<z.ZodEnum<{
156
- artifact: "artifact";
157
156
  workpiece: "workpiece";
157
+ artifact: "artifact";
158
158
  surface: "surface";
159
159
  }>>;
160
160
  valueMapping: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
@@ -193,8 +193,8 @@ declare const MaterializationNamespace: _$_makaio_core0.BusNamespaceDefinition<"
193
193
  template: z.ZodString;
194
194
  }, z.core.$strip>], "kind">;
195
195
  appliesTo: z.ZodArray<z.ZodEnum<{
196
- artifact: "artifact";
197
196
  workpiece: "workpiece";
197
+ artifact: "artifact";
198
198
  surface: "surface";
199
199
  }>>;
200
200
  valueMapping: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
@@ -211,8 +211,8 @@ declare const MaterializationNamespace: _$_makaio_core0.BusNamespaceDefinition<"
211
211
  provider: z.ZodString;
212
212
  externalId: z.ZodString;
213
213
  operation: z.ZodEnum<{
214
- deleted: "deleted";
215
214
  upserted: "upserted";
215
+ deleted: "deleted";
216
216
  }>;
217
217
  }, z.core.$strip>; /** Emitted when a provider surface capability set has been resolved. */
218
218
  'capability.resolved': z.ZodObject<{
@@ -268,8 +268,8 @@ declare const MaterializationSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
268
268
  template: z.ZodString;
269
269
  }, z.core.$strip>], "kind">;
270
270
  appliesTo: z.ZodArray<z.ZodEnum<{
271
- artifact: "artifact";
272
271
  workpiece: "workpiece";
272
+ artifact: "artifact";
273
273
  surface: "surface";
274
274
  }>>;
275
275
  valueMapping: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
@@ -308,8 +308,8 @@ declare const MaterializationSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
308
308
  template: z.ZodString;
309
309
  }, z.core.$strip>], "kind">;
310
310
  appliesTo: z.ZodArray<z.ZodEnum<{
311
- artifact: "artifact";
312
311
  workpiece: "workpiece";
312
+ artifact: "artifact";
313
313
  surface: "surface";
314
314
  }>>;
315
315
  valueMapping: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
@@ -326,8 +326,8 @@ declare const MaterializationSubjects: _$_makaio_core0.BusSubjects<_$_makaio_cor
326
326
  provider: z.ZodString;
327
327
  externalId: z.ZodString;
328
328
  operation: z.ZodEnum<{
329
- deleted: "deleted";
330
329
  upserted: "upserted";
330
+ deleted: "deleted";
331
331
  }>;
332
332
  }, z.core.$strip>; /** Emitted when a provider surface capability set has been resolved. */
333
333
  'capability.resolved': z.ZodObject<{
@@ -1,5 +1,5 @@
1
1
  import { i as CliContribution } from "./types-DCvp_swt.mjs";
2
- import { c as ExtensionInfo } from "./index-Bh6lHiW4.mjs";
2
+ import { c as ExtensionInfo } from "./index-B5Uczo3R.mjs";
3
3
  import { r as WindowRegistry } from "./window-registry-ofIUQnfo.mjs";
4
4
  import { IMakaioBus } from "@makaio/framework/bus";
5
5
  import { ExtensionContributionProcessor, ExtensionService, ExtensionToken, MakaioExtension, NodeExtensionContext, StorageDialect, TrayManifest, VersionLiteral } from "@makaio/framework/contracts";
@@ -9,8 +9,8 @@ import { z } from "zod";
9
9
  * - `visible` — Model is usable and shown in the AgentPicker UI.
10
10
  */
11
11
  declare const ModelVisibilitySchema: z.ZodEnum<{
12
- disabled: "disabled";
13
12
  enabled: "enabled";
13
+ disabled: "disabled";
14
14
  visible: "visible";
15
15
  }>;
16
16
  type ModelVisibility = z.infer<typeof ModelVisibilitySchema>;