@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
@@ -1,19 +1,19 @@
1
1
  import { r as ExecutionTarget } from "./schemas-D4zaFE2p.mjs";
2
- import { d as Turn$1 } from "./index-gAFwNiJT.mjs";
3
- import { a as PipelineStep, o as SessionEditorAction, t as ActionCategory } from "./types-BMS6yfLS.mjs";
2
+ import { d as Turn$1 } from "./index-BvTd61i5.mjs";
3
+ import { a as PipelineStep, o as SessionEditorAction, t as ActionCategory } from "./types-BNW5n6qm.mjs";
4
4
  import { z } from "zod";
5
5
  import * as _$_makaio_core0 from "@makaio/framework/core";
6
6
  import { ExtractSubjectPayload, SubjectDefinition } from "@makaio/framework/core";
7
7
  import { IMakaioBus } from "@makaio/framework/bus";
8
8
  import * as _$_makaio_contracts0 from "@makaio/framework/contracts";
9
- import { AIReasoningLevel, AdapterRuntimeOptions, BranchKind, ContextWindowState, ForkOptions, ForkTransforms, IMakaioSession, JsonValue, MakaioSessionAgent, MakaioSessionEvent, Message, MessageBlock, MessageInput, ReasoningLevelMap, SessionContext, SessionExtensionContext, SessionLineage, SessionLineageKind, SessionMessage, SessionMessageBlock, TurnInitiator } from "@makaio/framework/contracts";
9
+ import { AIReasoningLevel, AdapterRuntimeOptions, BranchKind, ContextWindowState, ForkOptions, ForkTransforms, ICapabilityProvider, IMakaioSession, JsonValue, MakaioSessionAgent, MakaioSessionEvent, Message, MessageBlock, MessageInput, NativeLocalityVerdict, ReasoningLevelMap, SessionContext, SessionEventType, SessionExtensionContext, SessionLineage, SessionLineageKind, SessionMessage, SessionMessageBlock, SessionMessageOrigin, SessionSubjects, TurnIngestionMarker, TurnInitiator, TurnUsage } from "@makaio/framework/contracts";
10
10
  import { BaseService } from "@makaio/framework/service-base";
11
- import * as _$_makaio_storage_core0 from "@makaio/framework/storage";
12
11
  import * as _$drizzle_orm_sqlite_core0 from "drizzle-orm/sqlite-core";
13
12
  import * as _$drizzle_orm_pg_core0 from "drizzle-orm/pg-core";
14
13
  import * as _$_makaio_storage_drizzle0 from "@makaio/framework/storage/drizzle";
15
14
  import { MakaioDatabase } from "@makaio/framework/storage/drizzle";
16
15
  import * as _$drizzle_orm0 from "drizzle-orm";
16
+ import * as _$_makaio_storage_core0 from "@makaio/framework/storage";
17
17
 
18
18
  //#region services/core/src/session/session-service.d.ts
19
19
  /**
@@ -32,10 +32,11 @@ import * as _$drizzle_orm0 from "drizzle-orm";
32
32
  * `SessionStorageSubjects.*` subjects. Register appropriate storage handlers
33
33
  * (memory or drizzle) before creating this service.
34
34
  *
35
- * `SessionLogger` is intentionally NOT a dependency here: it persists session
36
- * lifecycle events consumed only by recovery context assembly, fork, merge,
37
- * compress, and purge all host features. Host services declare
38
- * `SessionLogger` in their own dependency chain.
35
+ * Session lifecycle rows in `session_events` (agent.added, branch.created)
36
+ * are written by the subscription writers registered during init
37
+ * (see `registerSessionLifecycleEventWriters`); turn lifecycle rows are
38
+ * persisted inline at their emit sites. No separate logger component needs
39
+ * to be wired by hosts.
39
40
  * @example
40
41
  * ```typescript
41
42
  * import { MakaioBus } from '@makaio/framework/bus';
@@ -109,7 +110,7 @@ interface CoreSessionServiceHandlerDeps {
109
110
  * Registers the framework-core session service handlers:
110
111
  * `session.create`, `session.get`, `session.list`, `session.turn.await`,
111
112
  * `session.close`, `session.restartAgents`, `session.update`,
112
- * `session.archive`, `session.purge`, `session.registerExternal`,
113
+ * `session.archive`, `session.purge`,
113
114
  * `session.agent.added`, and `session.agent.removed`.
114
115
  *
115
116
  * These handlers cover the minimal, load-bearing session contract for the
@@ -155,8 +156,8 @@ interface ISessionOrchestrator {
155
156
  * 4. Verify agent liveness and build recovery context for dead agents
156
157
  * (requestOptional `AdapterSubjects.getAgent` + `buildRecoveryContext`)
157
158
  * 5. Get or create turn (via `SessionTurnManager`)
158
- * 6. Generate message ID and store user message + routing records
159
- * (requestOptional, fire-and-forget)
159
+ * 6. Generate message ID and store user message (awaited, persist-before-route)
160
+ * + routing records (fire-and-forget)
160
161
  * 7. Emit `session.turn.started` + `session.user_message.sent`
161
162
  * 8. Route to agents (via `routeToAgentsCore`, single shared context)
162
163
  * 9. Return result with `messageId`, `turnId`, `sessionId`
@@ -181,13 +182,16 @@ declare class SessionOrchestrator implements ISessionOrchestrator {
181
182
  private readonly bus;
182
183
  private readonly turnManager;
183
184
  private readonly adapterRegistry;
185
+ private readonly machineId;
184
186
  /** Cleanup functions for bus subscriptions. */
185
187
  private readonly cleanups;
186
188
  /**
187
189
  * @param bus - Event bus used for handler registration and message routing
188
- * @param _machineId - Machine identifier (reserved for future routing use)
190
+ * @param machineId - Stable machine identity forwarded to the attach handler
191
+ * to drive native-locality decisions (resume locality evaluation, adapter
192
+ * instance resolution).
189
193
  */
190
- constructor(bus: IMakaioBus | undefined, _machineId: string);
194
+ constructor(bus: IMakaioBus | undefined, machineId: string);
191
195
  /**
192
196
  * Register the `session.sendMessage` RPC handler.
193
197
  *
@@ -198,7 +202,7 @@ declare class SessionOrchestrator implements ISessionOrchestrator {
198
202
  * 3. Resolve target agents
199
203
  * 4. Verify agent liveness and build recovery context for dead agents
200
204
  * 5. Get or create turn (via SessionTurnManager)
201
- * 6. Generate message ID and store user message + routing records (fire-and-forget)
205
+ * 6. Generate message ID and store user message (awaited) + routing records (fire-and-forget)
202
206
  * 7. Emit turn.started + user_message.sent
203
207
  * 8. Route to agents (routeToAgentsCore, single shared context)
204
208
  * 9. Return result with messageId, turnId, sessionId
@@ -356,9 +360,10 @@ declare function normalizeToBlocks(message: MessageInput): SessionMessageBlock[]
356
360
  * @param providedSessionId - Session ID to look up
357
361
  * @param _sessionContext - Optional session context (scope fields removed in W1-A)
358
362
  * @param originWindowId - Window ID that initiated the session creation
363
+ * @param machineId - Machine identity to stamp on the session at creation time
359
364
  * @returns Session ID and session object
360
365
  */
361
- declare function getOrCreateSession(bus: IMakaioBus, providedSessionId: string, _sessionContext?: SessionContext, originWindowId?: string): Promise<{
366
+ declare function getOrCreateSession(bus: IMakaioBus, providedSessionId: string, _sessionContext?: SessionContext, originWindowId?: string, machineId?: string): Promise<{
362
367
  sessionId: string;
363
368
  session: IMakaioSession;
364
369
  }>;
@@ -435,6 +440,15 @@ interface RecoveryConfig {
435
440
  cwd?: string;
436
441
  /** Model identifier (e.g., 'claude-sonnet-4-20250514', 'gpt-4o') */
437
442
  model?: string;
443
+ /**
444
+ * Provider-native session ID to resume.
445
+ *
446
+ * When set, the adapter creates the connector in native-resume mode so the
447
+ * provider session continues from where it left off. The caller is responsible
448
+ * for evaluating locality (machine identity, adapter capability, CWD match)
449
+ * before setting this field.
450
+ */
451
+ resumeAdapterSessionId?: string;
438
452
  }
439
453
  /**
440
454
  * Ensure agent cwd matches desired cwd, swapping connector if needed.
@@ -796,15 +810,24 @@ type FallbackRuntimeOptions = Pick<AdapterRuntimeOptions, 'cwd' | 'systemPrompt'
796
810
  declare function pickFallbackRuntimeOptions(payload: Partial<Pick<AdapterRuntimeOptions, 'cwd' | 'systemPrompt' | 'allowedTools' | 'disallowedTools'>>): FallbackRuntimeOptions;
797
811
  //#endregion
798
812
  //#region services/core/src/session/context/assemble-fork-context.d.ts
813
+ /** Adapter capability signals required before emitting a native fork directive. */
814
+ interface AssembleForkContextCapabilities {
815
+ /** Adapter declares provider-native fork support for the selected target. */
816
+ readonly adapterSupportsNativeFork: boolean;
817
+ /** Adapter declares support for provider-native mid-history/checkpoint fork. */
818
+ readonly midHistoryForkSupported: boolean;
819
+ }
799
820
  /**
800
821
  * Assemble fork context for a session's first turn.
801
822
  *
802
823
  * For fork sessions on their first turn, this:
803
824
  * 1. Detects if this is a fork session (has parentSessionId)
804
825
  * 2. Checks if this is the first turn (via isNewTurn flag + storage query)
805
- * 3. Calls getFullConversation() to get projected context with transforms
806
- * 4. Converts SessionMessage[] to Message[] format
807
- * 5. Returns enriched SessionContext with messageHistory
826
+ * 3. Evaluates native locality for the source (parent) session
827
+ * 4a. If native: returns a fork directive without message history injection
828
+ * 4b. Otherwise: calls getFullConversation() to get projected context with transforms,
829
+ * converts SessionMessage[] to Message[] format, and attaches the locality verdict
830
+ * 5. Returns enriched SessionContext
808
831
  *
809
832
  * If not a fork first turn, returns the original sessionContext unchanged.
810
833
  * @param bus - Bus instance for RPC calls
@@ -812,9 +835,24 @@ declare function pickFallbackRuntimeOptions(payload: Partial<Pick<AdapterRuntime
812
835
  * @param sessionId - Session ID
813
836
  * @param originalContext - Original sessionContext from payload
814
837
  * @param isNewTurn - Whether this is a new turn (avoids race with just-created turn record)
838
+ * @param localMachineId - Stable machine identity of the current host process
839
+ * @param capabilities - Adapter capability signals resolved by the caller
840
+ * @param targetCwd - Effective working directory for the new agent, overriding
841
+ * `session.targetWorkingDirectory` in the locality check. Callers that resolve
842
+ * a per-request cwd override (e.g. a send payload `cwd` field) must pass the
843
+ * resolved value here so the native-fork evaluation and the eventual
844
+ * `startAgent` call operate on the same cwd — preventing a mismatch where
845
+ * locality is approved against the stored session cwd but the agent starts in
846
+ * a different directory.
847
+ * @param targetAdapterName - Stable adapter type name of the target adapter.
848
+ * Compared against the source session's adapterName to prevent cross-adapter
849
+ * fork — sending a provider session ID to a different adapter type would
850
+ * corrupt the conversation. Undefined when the caller cannot determine the
851
+ * target adapter (e.g. route-to-agents with mixed adapters); in that case the
852
+ * adapter-mismatch check is skipped.
815
853
  * @returns Enriched or original SessionContext
816
854
  */
817
- declare function assembleForkContext(bus: IMakaioBus, session: IMakaioSession, sessionId: string, originalContext?: SessionContext, isNewTurn?: boolean): Promise<SessionContext | undefined>;
855
+ declare function assembleForkContext(bus: IMakaioBus, session: IMakaioSession, sessionId: string, originalContext?: SessionContext, isNewTurn?: boolean, localMachineId?: string, capabilities?: AssembleForkContextCapabilities, targetCwd?: string, targetAdapterName?: string): Promise<SessionContext | undefined>;
818
856
  //#endregion
819
857
  //#region services/core/src/session/session-bridge.d.ts
820
858
  declare class SessionBridge {
@@ -1158,6 +1196,7 @@ declare const AgentStorageNamespace: _$_makaio_storage_core0.StorageNamespaceDef
1158
1196
  request: z.ZodObject<{
1159
1197
  agentId: z.ZodString;
1160
1198
  adapterId: z.ZodOptional<z.ZodString>;
1199
+ adapterSessionId: z.ZodOptional<z.ZodString>;
1161
1200
  cwd: z.ZodOptional<z.ZodString>;
1162
1201
  model: z.ZodOptional<z.ZodString>;
1163
1202
  allowedDirectories: z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -1767,6 +1806,7 @@ declare const AgentStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_core0.
1767
1806
  request: z.ZodObject<{
1768
1807
  agentId: z.ZodString;
1769
1808
  adapterId: z.ZodOptional<z.ZodString>;
1809
+ adapterSessionId: z.ZodOptional<z.ZodString>;
1770
1810
  cwd: z.ZodOptional<z.ZodString>;
1771
1811
  model: z.ZodOptional<z.ZodString>;
1772
1812
  allowedDirectories: z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -1905,7 +1945,7 @@ declare const sessionStorageSchema: _$_makaio_storage_drizzle0.DialectSchema<{
1905
1945
  tableName: "sessions";
1906
1946
  dataType: "string";
1907
1947
  columnType: "SQLiteText";
1908
- data: "discovered" | "closed" | "active" | "archived";
1948
+ data: "closed" | "discovered" | "active" | "archived";
1909
1949
  driverParam: string;
1910
1950
  notNull: true;
1911
1951
  hasDefault: false;
@@ -2443,6 +2483,42 @@ declare const sessionStorageSchema: _$_makaio_storage_drizzle0.DialectSchema<{
2443
2483
  }, {}, {
2444
2484
  length: number | undefined;
2445
2485
  }>;
2486
+ isSidechain: _$drizzle_orm_sqlite_core0.SQLiteColumn<{
2487
+ name: string;
2488
+ tableName: "sessions";
2489
+ dataType: "boolean";
2490
+ columnType: "SQLiteBoolean";
2491
+ data: boolean;
2492
+ driverParam: number;
2493
+ notNull: false;
2494
+ hasDefault: false;
2495
+ isPrimaryKey: false;
2496
+ isAutoincrement: false;
2497
+ hasRuntimeDefault: false;
2498
+ enumValues: undefined;
2499
+ baseColumn: never;
2500
+ identity: undefined;
2501
+ generated: undefined;
2502
+ }, {}, {}>;
2503
+ machineId: _$drizzle_orm_sqlite_core0.SQLiteColumn<{
2504
+ name: "machine_id";
2505
+ tableName: "sessions";
2506
+ dataType: "string";
2507
+ columnType: "SQLiteText";
2508
+ data: string;
2509
+ driverParam: string;
2510
+ notNull: false;
2511
+ hasDefault: false;
2512
+ isPrimaryKey: false;
2513
+ isAutoincrement: false;
2514
+ hasRuntimeDefault: false;
2515
+ enumValues: [string, ...string[]];
2516
+ baseColumn: never;
2517
+ identity: undefined;
2518
+ generated: undefined;
2519
+ }, {}, {
2520
+ length: number | undefined;
2521
+ }>;
2446
2522
  };
2447
2523
  dialect: "sqlite";
2448
2524
  }>;
@@ -2862,6 +2938,7 @@ type SearchSessionRow = {
2862
2938
  fork_transforms: string | null;
2863
2939
  target_working_directory: string | null;
2864
2940
  metadata: Record<string, JsonValue> | string | null;
2941
+ machine_id: string | null;
2865
2942
  };
2866
2943
  /**
2867
2944
  * Filter parameters accepted by FTS search queries.
@@ -2982,7 +3059,8 @@ declare function getSessionAncestorChain(db: MakaioDatabase, sessionId: string):
2982
3059
  * Session events table schema.
2983
3060
  *
2984
3061
  * Stores immutable, append-only session events for unified history reconstruction.
2985
- * Events are persisted by SessionLogger via storage service.
3062
+ * Lifecycle rows are persisted at their emit sites via the session lifecycle
3063
+ * event helpers (see session-lifecycle-events.ts).
2986
3064
  *
2987
3065
  * **Event Types:**
2988
3066
  * - Message references (type='message' with messageId FK to messages table)
@@ -3370,7 +3448,7 @@ declare function registerMemorySessionEventStorage(bus: IMakaioBus): () => void;
3370
3448
  */
3371
3449
  declare function registerDrizzleSessionEventStorage(bus: IMakaioBus, db: MakaioDatabase): () => void;
3372
3450
  //#endregion
3373
- //#region services/core/src/session/session-logger.d.ts
3451
+ //#region services/core/src/session/session-lifecycle-events.d.ts
3374
3452
  /**
3375
3453
  * Transform function for event payloads before storage emission.
3376
3454
  * Use for redaction, PII filtering, or payload normalization.
@@ -3384,90 +3462,326 @@ declare function registerDrizzleSessionEventStorage(bus: IMakaioBus, db: MakaioD
3384
3462
  */
3385
3463
  type EventTransform = (event: MakaioSessionEvent) => MakaioSessionEvent | null;
3386
3464
  /**
3387
- * Options for SessionLogger.
3465
+ * Arguments for {@link appendSessionLifecycleEvent}.
3388
3466
  */
3389
- interface SessionLoggerOptions {
3467
+ interface SessionLifecycleEventArgs {
3468
+ /** Event type for classification (e.g. 'turn.started'). */
3469
+ type: SessionEventType;
3470
+ /** Session the event belongs to. */
3471
+ sessionId: string;
3472
+ /** Event payload to persist. */
3473
+ payload: unknown;
3390
3474
  /**
3391
- * Transform function applied before storage emission.
3392
- * Return null to skip storage entirely.
3393
- * Note: Does not affect individual session.* subjects (see EventTransform docs).
3394
- * Default: identity (no transformation)
3475
+ * Stable event identifier. Provide one when the caller needs idempotent
3476
+ * retries; defaults to a fresh UUID per call.
3395
3477
  */
3396
- transform?: EventTransform;
3478
+ eventId?: string;
3479
+ /** Event timestamp (Unix ms). Defaults to `Date.now()`. */
3480
+ timestamp?: number;
3397
3481
  }
3398
3482
  /**
3399
- * Bridges session lifecycle events to storage layer for persistence.
3400
- *
3401
- * **Architecture (Normalized Message Model):**
3402
- * - Messages: Stored in `messages` table via MessageStorageSubjects (by SessionOrchestrator/SessionBridge)
3403
- * - SessionLogger: Stores LIFECYCLE events only — agent.added, turn.started, turn.completed
3404
- *
3405
- * **NO longer subscribes to user_message.* events** user messages are now
3406
- * first-class entities in the `messages` table, not embedded in event payloads.
3407
- *
3408
- * The correlation link is `session.agent.added` which maps:
3409
- * `sessionId agentId adapterSessionId`
3410
- *
3411
- * Subscribes to:
3412
- * - session.agent.added correlation link for multi-agent reconstruction
3413
- * - session.turn.started, session.turn.completed turn lifecycle
3414
- * - session.branch.created branch creation audit trail
3415
- *
3416
- * Does NOT subscribe to session.branch.merged or session.squash — those
3417
- * handlers (merge-handler, compress-handler) own their persistence directly
3418
- * using a stable eventId so retries are idempotent.
3483
+ * Append a session lifecycle row to `session_events`.
3484
+ *
3485
+ * Builds the {@link MakaioSessionEvent} envelope, applies the optional
3486
+ * transform (null result skips persistence), then requests
3487
+ * `storage:sessionEvent.append` via `requestOptional` so ephemeral mode
3488
+ * (no session-event storage registered) degrades gracefully. A handled
3489
+ * append failure propagates to the caller so emit sites can preserve the
3490
+ * persist-before-emit contract.
3491
+ *
3492
+ * This is the single write path for lifecycle rows in `session_events`.
3493
+ * It MUST NOT be used for `branch.merged` / `squash` those handlers
3494
+ * (merge-handler, compress-handler) own their own idempotent persistence
3495
+ * with stable eventIds; double-writing here would duplicate rows.
3496
+ * @param bus - Bus used to reach session-event storage
3497
+ * @param args - Event envelope fields (type, sessionId, payload, optional eventId/timestamp)
3498
+ * @param transform - Optional transform applied before persistence (return null to skip)
3499
+ */
3500
+ declare function appendSessionLifecycleEvent(bus: IMakaioBus, args: SessionLifecycleEventArgs, transform?: EventTransform): Promise<void>;
3501
+ /**
3502
+ * Payload of the canonical `session.turn.started` event.
3503
+ */
3504
+ type SessionTurnStartedPayload = ExtractSubjectPayload<typeof SessionSubjects.turn.started>;
3505
+ /**
3506
+ * Persist the `turn.started` lifecycle row, then emit `session.turn.started`.
3507
+ *
3508
+ * This is the only sanctioned emit path for live-path `session.turn.started`
3509
+ * emissions (single-emitter discipline): the orchestration emit sites
3510
+ * (SessionOrchestrator, attach handler, MakaioSession entity) all route
3511
+ * through this helper so the `session_events` row is durable before any
3512
+ * consumer observes the event (persist-before-emit). The turn ingestion seam
3513
+ * (`ingestCompletedTurn`) is the one other sanctioned emitter — it batches
3514
+ * both lifecycle rows before emitting and must not be rerouted through this
3515
+ * helper (doing so would reorder its persist-before-emit batch).
3516
+ * @param bus - Bus used for lifecycle persistence and event emission
3517
+ * @param payload - The exact `session.turn.started` payload to persist and emit
3518
+ */
3519
+ declare function emitSessionTurnStarted(bus: IMakaioBus, payload: SessionTurnStartedPayload): Promise<void>;
3520
+ /**
3521
+ * Register subscription-based `session_events` writers for the lifecycle
3522
+ * subjects that have no single emit site: `session.agent.added` (persisted as
3523
+ * type `agent.added`, the sessionId ↔ agentId ↔ adapterSessionId correlation
3524
+ * link) and `session.branch.created` (branch creation audit trail).
3525
+ *
3526
+ * `turn.started` / `turn.completed` rows are NOT written here — their emit
3527
+ * sites persist inline ({@link emitSessionTurnStarted}, SessionTurnManager's
3528
+ * completion barrier, the turn ingestion seam) so the row lands before the
3529
+ * event fires.
3530
+ *
3531
+ * Deliberately does NOT subscribe to `session.branch.merged` or
3532
+ * `session.squash`: the merge and compress handlers own their persistence
3533
+ * directly and call `storage:sessionEvent.append` with a stable eventId so
3534
+ * retries are idempotent. Subscribing here would duplicate those rows.
3535
+ *
3536
+ * Wired by `MakaioSessionService` during init, so the writers run in every
3537
+ * host that composes the session package.
3538
+ * @param bus - Bus to subscribe on and persist through
3539
+ * @param transform - Optional transform applied before persistence (return null to skip)
3540
+ * @returns Cleanup function cancelling both subscriptions
3541
+ */
3542
+ declare function registerSessionLifecycleEventWriters(bus: IMakaioBus, transform?: EventTransform): () => void;
3543
+ //#endregion
3544
+ //#region services/core/src/session/turn-ingest.d.ts
3545
+ /**
3546
+ * A message belonging to an ingested turn.
3419
3547
  *
3420
- * Emits transformed events to `storage:sessionEvent.append` for persistence.
3421
- * @example
3422
- * ```typescript
3423
- * // Basic usage - lifecycle events are emitted to storage:sessionEvent.append
3424
- * const sessionLogger = new SessionLogger(MakaioBus);
3425
- *
3426
- * // With redaction transform (mainly for turn error messages)
3427
- * const sessionLogger = new SessionLogger(MakaioBus, {
3428
- * transform: (event) => {
3429
- * // Redact sensitive info if needed
3430
- * return event;
3431
- * },
3432
- * });
3433
- * ```
3548
+ * Mirrors the `storage:message.upsertByAdapterMessageId` request minus
3549
+ * `sessionId` / `turnId`, which the seam supplies from the ingested turn.
3434
3550
  */
3435
- declare class SessionLogger {
3436
- private readonly bus;
3437
- private readonly options;
3438
- private readonly cleanups;
3439
- private readonly transform;
3440
- constructor(bus?: IMakaioBus, options?: SessionLoggerOptions);
3441
- /**
3442
- * Emit a session event to storage layer.
3443
- *
3444
- * Creates event envelope, applies transform, and emits to storage subject.
3445
- * If transform returns null, event is skipped.
3446
- * @param eventType - Event type for classification
3447
- * @param sessionId - Session identifier
3448
- * @param payload - Event payload to persist
3449
- */
3450
- private emitStorageEvent;
3451
- /**
3452
- * Register a handler for a session event subject.
3453
- * @param subject - Subject definition to subscribe to
3454
- * @param eventType - Event type for persistence
3455
- */
3456
- private registerHandler;
3551
+ interface IngestTurnMessage {
3552
+ /** Adapter's message ID (external record uuid) — the idempotency key. */
3553
+ adapterMessageId: string;
3554
+ /** Message role. */
3555
+ role: 'user' | 'assistant';
3556
+ /** Plain text content for FTS indexing. */
3557
+ contentText: string;
3558
+ /** Structured content blocks. */
3559
+ blocks: SessionMessageBlock[];
3560
+ /** Agent ID (for assistant messages). */
3561
+ agentId?: string;
3562
+ /** Adapter's session ID. */
3563
+ adapterSessionId?: string;
3564
+ /** Message timestamp (Unix ms). */
3565
+ timestamp: number;
3566
+ /** Origin of the message (e.g. voice/text). */
3567
+ origin?: SessionMessageOrigin;
3568
+ }
3569
+ /**
3570
+ * Parameters for {@link ingestCompletedTurn}.
3571
+ */
3572
+ interface IngestCompletedTurnParams {
3573
+ /** Makaio session the turn belongs to. */
3574
+ sessionId: string;
3457
3575
  /**
3458
- * Register all session lifecycle event handlers.
3459
- *
3460
- * **Normalized Message Model:**
3461
- * - User messages are stored in `messages` table by SessionOrchestrator
3462
- * - Assistant messages are stored by SessionBridge on agent.complete
3463
- * - SessionLogger only stores LIFECYCLE events for audit/correlation
3576
+ * Content-derived idempotency anchor the adapterMessageId of the
3577
+ * turn-start user message. Re-ingesting the same anchor is a no-op.
3464
3578
  */
3465
- private registerHandlers;
3579
+ turnAnchorId: string;
3580
+ /** Turn start timestamp (Unix ms). */
3581
+ startedAt: number;
3582
+ /** Turn completion timestamp (Unix ms). */
3583
+ completedAt: number;
3584
+ /** Final turn status. */
3585
+ status: 'completed' | 'error';
3586
+ /** Error message when status is 'error'. */
3587
+ error?: string;
3588
+ /** Aggregated token usage for the turn. */
3589
+ usage?: TurnUsage;
3590
+ /** Actor provenance of whoever started the turn. */
3591
+ initiator?: TurnInitiator;
3592
+ /** Whether this emission is live ingestion or historical backfill. */
3593
+ ingestionMarker: TurnIngestionMarker;
3594
+ /** Messages of the turn, in transcript order. */
3595
+ messages: IngestTurnMessage[];
3596
+ }
3597
+ /**
3598
+ * Result of {@link ingestCompletedTurn}.
3599
+ */
3600
+ interface IngestCompletedTurnResult {
3601
+ /** Makaio turn ID (stable across re-ingestion of the same anchor). */
3602
+ turnId: string;
3603
+ /** Monotonic per-session ordinal (stable across re-ingestion). */
3604
+ turnNumber: number;
3605
+ /** True on first ingestion; false when the anchor already existed. */
3606
+ created: boolean;
3607
+ }
3608
+ /**
3609
+ * Ingest an externally-completed turn: persist the turn row and its messages,
3610
+ * then emit the canonical `session.turn.*` events exactly once.
3611
+ *
3612
+ * Steps (persist-before-emit by construction):
3613
+ * 1. Upsert the turn row via `storage:turn.ingestCompleted` (anchor-keyed).
3614
+ * Uses `bus.request`, not `requestOptional`: import paths always run with
3615
+ * turn storage registered — a missing handler is a caller error and must
3616
+ * surface, not silently drop the turn.
3617
+ * 2. Upsert every message via `storage:message.upsertByAdapterMessageId`
3618
+ * with the real `turnId`. NEVER `storage:message.append` — append mints
3619
+ * fresh messageIds and would break re-import idempotency.
3620
+ * 3. When the turn's `session.turn.*` side effects have not completed yet:
3621
+ * persist `turn.started` / `turn.completed` lifecycle rows into
3622
+ * `session_events` (deterministic eventIds, idempotent appends), then emit
3623
+ * `session.turn.started` followed by `session.turn.completed`.
3624
+ * 4. Return the stable `(turnId, turnNumber)` identity plus `created`.
3625
+ *
3626
+ * Both events are emitted AFTER all persistence resolves. This deliberately
3627
+ * differs from the managed orchestration path, which emits `turn.started`
3628
+ * before routing to agents: here the turn is already finished, so there is
3629
+ * no in-progress phase to signal — and emitting only after persistence is
3630
+ * what guarantees the four-point consumer contract (session row, completed
3631
+ * turn row, `getByTurn`-queryable messages, complete event payload) holds
3632
+ * at emission time.
3633
+ *
3634
+ * Invariants:
3635
+ * - (a) Never touches SessionTurnManager in-memory state
3636
+ * (`activeTurns` / `completingSessions`) — the turn is already complete
3637
+ * and never passes through the live turn lifecycle.
3638
+ * - (b) Re-ingestion of the same anchor is a storage no-op and re-emits
3639
+ * nothing once the `turn.completed` lifecycle row is durable. Emission is
3640
+ * NOT gated on the anchor claim alone: a prior ingestion that claimed the
3641
+ * anchor but failed before its side effects completed (partial message
3642
+ * upsert, lifecycle append failure) leaves that row absent, and the next
3643
+ * ingestion of the same anchor resumes the emission instead of suppressing
3644
+ * it forever. Executions are serialized per anchor so concurrent hook- and
3645
+ * watcher-triggered ingestion stays exactly-once. Residual window: a
3646
+ * process crash between the lifecycle append and the bus emit loses that
3647
+ * emission (the durable row already claims it) — an accepted at-most-once
3648
+ * bound absent a transactional outbox. Without session-event storage
3649
+ * registered, resume detection is impossible and emission falls back to
3650
+ * first-ingestion-only.
3651
+ * - (c) The four-point consumer contract holds when `session.turn.*` fires.
3652
+ *
3653
+ * Guard: when `params.messages` is empty, event emission is skipped
3654
+ * (contract point 3 — `getByTurn` — would be unfulfillable) and a warning is
3655
+ * logged; the turn row still persists, and a later re-ingestion that carries
3656
+ * messages emits via the resume path.
3657
+ * @param bus - Bus used for storage requests and event emission
3658
+ * @param params - Turn identity, completion state, marker, and messages
3659
+ * @returns Stable turn identity and whether this call created the turn
3660
+ */
3661
+ declare function ingestCompletedTurn(bus: IMakaioBus, params: IngestCompletedTurnParams): Promise<IngestCompletedTurnResult>;
3662
+ //#endregion
3663
+ //#region services/core/src/session/observed-session-ingestion.d.ts
3664
+ /**
3665
+ * Minimal local mirror of the log-import bus subjects this component calls.
3666
+ *
3667
+ * The log-import service package depends on this package, so importing its
3668
+ * subject definitions here would create a package cycle. Bus subjects are
3669
+ * matched by fully-qualified name and payloads are validated against the
3670
+ * schemas registered by the owning service at boot — these mirrored
3671
+ * definitions are type carriers for the fields this component reads and
3672
+ * writes, not a second source of truth. Canonical schemas live with the
3673
+ * log-import service.
3674
+ *
3675
+ * Exported for tests that stub the log-import seam; not part of the public
3676
+ * session API surface.
3677
+ * @internal
3678
+ */
3679
+ declare const LogImportTriggerSubjects: _$_makaio_core0.BusSubjects<_$_makaio_core0.FlatSubjectDefinitions<"log-import", {
3680
+ /** Mirror of `log-import.listImporters` (adapterName/clientId subset). */listImporters: {
3681
+ request: z.ZodObject<{}, z.core.$strip>;
3682
+ response: z.ZodObject<{
3683
+ importers: z.ZodArray<z.ZodObject<{
3684
+ adapterName: z.ZodString;
3685
+ clientId: z.ZodOptional<z.ZodString>;
3686
+ }, z.core.$strip>>;
3687
+ }, z.core.$strip>;
3688
+ }; /** Mirror of `log-import.importFile` (path-addressable import trigger). */
3689
+ importFile: {
3690
+ request: z.ZodObject<{
3691
+ filePath: z.ZodString;
3692
+ adapterName: z.ZodString;
3693
+ ingestionMarker: z.ZodOptional<z.ZodEnum<{
3694
+ live: "live";
3695
+ backfill: "backfill";
3696
+ }>>;
3697
+ }, z.core.$strip>;
3698
+ response: z.ZodDiscriminatedUnion<[z.ZodObject<{
3699
+ status: z.ZodLiteral<"imported">;
3700
+ sessionId: z.ZodString;
3701
+ messageCount: z.ZodNumber;
3702
+ turnCount: z.ZodNumber;
3703
+ }, z.core.$strip>, z.ZodObject<{
3704
+ status: z.ZodLiteral<"skipped">;
3705
+ reason: z.ZodEnum<{
3706
+ "no-importer": "no-importer";
3707
+ "file-missing": "file-missing";
3708
+ }>;
3709
+ }, z.core.$strip>], "status">;
3710
+ }; /** Mirror of `log-import.importSession` (discovery-stub-based trigger). */
3711
+ importSession: {
3712
+ request: z.ZodObject<{
3713
+ adapterSessionId: z.ZodString;
3714
+ adapterName: z.ZodString;
3715
+ ingestionMarker: z.ZodOptional<z.ZodEnum<{
3716
+ live: "live";
3717
+ backfill: "backfill";
3718
+ }>>;
3719
+ }, z.core.$strip>;
3720
+ response: z.ZodObject<{
3721
+ sessionId: z.ZodString;
3722
+ messageCount: z.ZodNumber;
3723
+ }, z.core.$strip>;
3724
+ };
3725
+ }>, "log-import">;
3726
+ /**
3727
+ * Check whether a stored session represents a metadata-only observed session.
3728
+ *
3729
+ * Plain discovery scans also use `importStatus: 'discovered'`; the client id
3730
+ * distinguishes hook-observed metadata-only registrations from scan-discovered
3731
+ * sessions that are still eligible for explicit lazy import.
3732
+ * @param session - Stored session row
3733
+ * @returns True when content import must be suppressed
3734
+ */
3735
+ declare function isPolicyDiscoveredObservedSession(session: Pick<IMakaioSession, 'clientId' | 'importStatus'>): boolean;
3736
+ //#endregion
3737
+ //#region services/core/src/session/observed-session-ingestion-policy.d.ts
3738
+ /** Capability id used for observed-session ingestion policy providers. */
3739
+ declare const OBSERVED_SESSION_INGESTION_POLICY_CAPABILITY_ID = "observed-session-ingestion-policy";
3740
+ /** Import lifecycle status a policy can choose for an observed session. */
3741
+ type ObservedSessionIngestionPolicyImportStatus = 'tracking' | 'discovered';
3742
+ /** Decision returned by an observed-session ingestion policy provider. */
3743
+ interface ObservedSessionIngestionPolicyDecision {
3744
+ /** `tracking` imports transcript content; `discovered` registers metadata only. */
3745
+ readonly importStatus: ObservedSessionIngestionPolicyImportStatus;
3746
+ }
3747
+ /** Inputs available when deciding how an observed session should be ingested. */
3748
+ interface ObservedSessionIngestionPolicyInput {
3749
+ /** Stable client id that emitted the observation. */
3750
+ readonly clientId: string;
3751
+ /** Observation source, such as `native-hook` or `adapter-derived`. */
3752
+ readonly source: string;
3753
+ /** External session id reported by the client runtime. */
3754
+ readonly adapterSessionId: string;
3755
+ /** Canonical importer adapter name that would own content import. */
3756
+ readonly adapterName: string;
3757
+ /** Working directory observed at session start, when available. */
3758
+ readonly cwd?: string;
3759
+ /** Transcript path observed from the client runtime, when available. */
3760
+ readonly transcriptPath?: string;
3761
+ }
3762
+ /** Capability provider that decides observed-session content ingestion policy. */
3763
+ interface IObservedSessionIngestionPolicyProvider extends ICapabilityProvider {
3466
3764
  /**
3467
- * Stop the logger and clean up subscriptions.
3765
+ * Decide whether an observed session should content-import or metadata-register only.
3766
+ * @param input - Observed session identity and importer context
3767
+ * @returns Ingestion policy decision
3468
3768
  */
3469
- destroy(): void;
3769
+ decideObservedSessionIngestion(input: ObservedSessionIngestionPolicyInput): ObservedSessionIngestionPolicyDecision | Promise<ObservedSessionIngestionPolicyDecision>;
3470
3770
  }
3771
+ /**
3772
+ * Register an observed-session ingestion policy provider.
3773
+ * @param bus - Makaio bus instance
3774
+ * @param provider - Policy provider to register
3775
+ * @returns Promise that resolves after registration handlers have completed
3776
+ */
3777
+ declare function registerObservedSessionIngestionPolicyProvider(bus: IMakaioBus, provider: IObservedSessionIngestionPolicyProvider): Promise<void>;
3778
+ /**
3779
+ * Unregister an observed-session ingestion policy provider.
3780
+ * @param bus - Makaio bus instance
3781
+ * @param providerId - Policy provider id to remove
3782
+ * @returns Promise that resolves after unregistration handlers have completed
3783
+ */
3784
+ declare function unregisterObservedSessionIngestionPolicyProvider(bus: IMakaioBus, providerId: string): Promise<void>;
3471
3785
  //#endregion
3472
3786
  //#region services/core/src/session/import-cursors/schema.d.ts
3473
3787
  /**
@@ -3836,6 +4150,17 @@ declare const turnsDual: _$_makaio_storage_drizzle0.DualTable<"turns", {
3836
4150
  * Stored as hand-stringified JSON because turn.create uses a raw SQL CTE.
3837
4151
  */
3838
4152
  initiator: _$_makaio_storage_drizzle0.DualBuilder<_$drizzle_orm_sqlite_core0.SQLiteTextBuilderInitial<"initiator", [string, ...string[]], number | undefined>, _$drizzle_orm_pg_core0.PgTextBuilderInitial<"initiator", [string, ...string[]]>>;
4153
+ /**
4154
+ * Content-derived idempotency anchor for turns ingested from external
4155
+ * transcripts — the adapterMessageId (external record uuid) of the
4156
+ * turn-start user message. NULL for turns created by the managed
4157
+ * orchestration path (storage:turn.create).
4158
+ *
4159
+ * Backs the ON CONFLICT target of storage:turn.ingestCompleted so
4160
+ * re-parsing the same transcript (including compaction re-reads from
4161
+ * byte 0) resolves to the existing turn row and never renumbers.
4162
+ */
4163
+ turnAnchorId: _$_makaio_storage_drizzle0.DualBuilder<_$drizzle_orm_sqlite_core0.SQLiteTextBuilderInitial<"turn_anchor_id", [string, ...string[]], number | undefined>, _$drizzle_orm_pg_core0.PgTextBuilderInitial<"turn_anchor_id", [string, ...string[]]>>;
3839
4164
  }>;
3840
4165
  /** SQLite face of the `turns` table (canonical schema). */
3841
4166
  declare const turns: _$drizzle_orm_sqlite_core0.SQLiteTableWithColumns<{
@@ -4007,6 +4332,25 @@ declare const turns: _$drizzle_orm_sqlite_core0.SQLiteTableWithColumns<{
4007
4332
  }, {}, {
4008
4333
  length: number | undefined;
4009
4334
  }>;
4335
+ turnAnchorId: _$drizzle_orm_sqlite_core0.SQLiteColumn<{
4336
+ name: "turn_anchor_id";
4337
+ tableName: "turns";
4338
+ dataType: "string";
4339
+ columnType: "SQLiteText";
4340
+ data: string;
4341
+ driverParam: string;
4342
+ notNull: false;
4343
+ hasDefault: false;
4344
+ isPrimaryKey: false;
4345
+ isAutoincrement: false;
4346
+ hasRuntimeDefault: false;
4347
+ enumValues: [string, ...string[]];
4348
+ baseColumn: never;
4349
+ identity: undefined;
4350
+ generated: undefined;
4351
+ }, {}, {
4352
+ length: number | undefined;
4353
+ }>;
4010
4354
  };
4011
4355
  dialect: "sqlite";
4012
4356
  }>;
@@ -4271,7 +4615,7 @@ declare const messages: _$drizzle_orm_sqlite_core0.SQLiteTableWithColumns<{
4271
4615
  tableName: "messages";
4272
4616
  dataType: "string";
4273
4617
  columnType: "SQLiteText";
4274
- data: "text" | "voice" | "compact";
4618
+ data: "text" | "compact" | "voice";
4275
4619
  driverParam: string;
4276
4620
  notNull: false;
4277
4621
  hasDefault: false;
@@ -4998,4 +5342,78 @@ declare function buildSessionContext(bus: IMakaioBus, options: BuildContextOptio
4998
5342
  */
4999
5343
  declare function getFullConversation(bus: IMakaioBus, sessionId: string): Promise<ContextAssemblyResult>;
5000
5344
  //#endregion
5001
- export { fetchMessageCountsBySession as $, registerMemoryTurnStorage as A, RecoveryConfig as At, registerMemorySessionEventStorage as B, findTurnByAgent as Bt, messages as C, registerGetStatusCountsHandler as Ct, SelectTurn as D, ContextWindowTrackerConfig as Dt, InsertTurn as E, AgentContextState as Et, importCursorsDual as F, verifyAndRecoverAgents as Ft, getSessionAncestorChain as G, TurnContextEnricher as Gt, SelectSessionEvent as H, resolveTargetAgents as Ht, EventTransform as I, buildRecoveryContext as It, mapAgentsBySession as J, SessionOrchestrator as Jt, SessionPreviewMaps as K, AdapterRegistry as Kt, SessionLogger as L, resolveAdapterId as Lt, EmbeddingIndexManager as M, ensureAgentCwd as Mt, registerDrizzleImportCursorStorage as N, ensureAgentModel as Nt, turns as O, SessionContextWindowState as Ot, importCursors as P, recoverAgent as Pt, fetchAgentsBySession as Q, SessionLoggerOptions as R, resolveExecutionTarget as Rt, SelectMessage as S, actionRegistry as St, registerDrizzleMessageStorage as T, ContextWindowTracker as Tt, sessionEvents as U, extractTextContent as Ut, InsertSessionEvent as V, getOrCreateSession as Vt, sessionEventsDual as W, normalizeToBlocks as Wt, SearchFilters as X, MakaioSessionService as Xt, mapToSession as Y, registerCoreSessionServiceHandlers as Yt, SearchSessionRow as Z, messageRoutingDual as _, normalizeSelectionString as _t, kindToBranchKind as a, registerMemoryAgentStorage as at, MessageRoutingSubjects as b, registerBuiltInActions as bt, registerSpawningToolCallResolver as c, AgentStorageNamespace as ct, MakaioSession as d, createSessionExtensionContext as dt, fetchPreviewBySession as et, MakaioSessionConfig as f, SessionBridge as ft, messageRouting as g, CONNECTOR_SWAP_DEFAULT_PIPELINE as gt, SelectMessageRouting as h, pickFallbackRuntimeOptions as ht, ContextAssemblyResult as i, registerDrizzleAgentStorage as it, registerDrizzleTurnStorage as j, buildRecoveryContextWithPipeline as jt, turnsDual as k, buildTurnInitiator as kt, registerCompressLineageResolver as l, AgentStorageSubjects as lt, InsertMessageRouting as m, FallbackRuntimeOptions as mt, buildSessionContext as n, parseForkTransforms as nt, toSessionLineage as o, registerDrizzleSessionStorage as ot, StartTurnOptions as p, assembleForkContext as pt, fetchSessionPreviewMaps as q, ISessionOrchestrator as qt, BuildContextOptions as r, registerFtsSearchHandler as rt, registerSessionDiscoveredHandler as s, registerMemorySessionStorage as st, getFullConversation as t, mapRowToSession as tt, registerParentResolver as u, SessionExtensionContextImpl as ut, registerDrizzleMessageRoutingStorage as v, resolveAdapterNameById as vt, registerMemoryMessageStorage as w, registerResumeHandler as wt, InsertMessage as x, resetBuiltInActionsRegistration as xt, MessageRoutingNamespace as y, registerListActionsHandler as yt, registerDrizzleSessionEventStorage as z, resolveModelCapabilities as zt };
5345
+ //#region services/core/src/session/native-locality.d.ts
5346
+ /**
5347
+ * Describes whether the session resume/fork intent is a native continuation
5348
+ * or a new fork branching from an existing session.
5349
+ */
5350
+ type NativeLocalityIntent = 'resume' | 'fork';
5351
+ /**
5352
+ * All inputs required for the native locality evaluator.
5353
+ */
5354
+ interface NativeLocalityInput {
5355
+ /** Whether this is a resume or fork operation. */
5356
+ readonly intent: NativeLocalityIntent;
5357
+ /** The session being resumed or forked. */
5358
+ readonly session: IMakaioSession;
5359
+ /**
5360
+ * The stable machine identity of the current host process.
5361
+ * Undefined when the framework host has not yet resolved machine identity.
5362
+ */
5363
+ readonly localMachineId: string | undefined;
5364
+ /**
5365
+ * Whether the adapter for this session declares native resume/fork capability.
5366
+ * Adapters that cannot natively replay/branch must always inject history.
5367
+ */
5368
+ readonly adapterSupportsNative: boolean;
5369
+ /**
5370
+ * Stable adapter type name of the target adapter (e.g. 'claude-code', 'codex-mcp').
5371
+ *
5372
+ * Compared against `session.adapterName` to prevent cross-adapter resume/fork:
5373
+ * sending a Claude provider session ID to a Codex adapter (or vice versa) would
5374
+ * corrupt the provider conversation. When the session has no stored adapterName
5375
+ * (legacy records, sessions created before adapter identity tracking), the check
5376
+ * is skipped — the downstream adapter will reject an incompatible session ID.
5377
+ */
5378
+ readonly targetAdapterName: string;
5379
+ /**
5380
+ * Working directory of the current adapter instance.
5381
+ * Only relevant when `targetCwd` is also supplied.
5382
+ */
5383
+ readonly currentCwd?: string;
5384
+ /**
5385
+ * Requested working directory for the resumed or forked session.
5386
+ * When it differs from `currentCwd`, native operation cannot reuse the
5387
+ * existing connector.
5388
+ */
5389
+ readonly targetCwd?: string;
5390
+ /**
5391
+ * Turn-scoped context signals produced by the session orchestrator.
5392
+ * Used to detect compression, connector swaps, and pending transforms.
5393
+ */
5394
+ readonly sessionContext?: SessionContext;
5395
+ /**
5396
+ * Whether the underlying adapter supports forking at a mid-history message.
5397
+ * Required when `session.forkPointMessageId` is set and `intent === 'fork'`.
5398
+ */
5399
+ readonly midHistoryForkSupported?: boolean;
5400
+ }
5401
+ /**
5402
+ * Evaluates whether a session can use native resume or fork, or must fall back
5403
+ * to history injection.
5404
+ *
5405
+ * Checks are ordered from cheapest/most common disqualifier to most specific so
5406
+ * that callers pay no cost for conditions that are almost never hit:
5407
+ *
5408
+ * 1. Adapter capability declaration
5409
+ * 2. Provider-native session ID presence
5410
+ * 3. Machine identity availability and ownership
5411
+ * 4. Structural constraints (imports + orchestration, compression, transforms,
5412
+ * connector swap, CWD mismatch)
5413
+ * 5. Mid-history fork support
5414
+ * @param input - All signals needed to determine locality
5415
+ * @returns A {@link NativeLocalityVerdict} describing the outcome
5416
+ */
5417
+ declare function evaluateNativeLocality(input: NativeLocalityInput): NativeLocalityVerdict;
5418
+ //#endregion
5419
+ export { SessionLifecycleEventArgs as $, recoverAgent as $t, SelectTurn as A, createSessionExtensionContext as At, OBSERVED_SESSION_INGESTION_POLICY_CAPABILITY_ID as B, resetBuiltInActionsRegistration as Bt, MessageRoutingSubjects as C, registerDrizzleAgentStorage as Ct, registerMemoryMessageStorage as D, AgentStorageNamespace as Dt, messages as E, registerMemorySessionStorage as Et, EmbeddingIndexManager as F, CONNECTOR_SWAP_DEFAULT_PIPELINE as Ft, unregisterObservedSessionIngestionPolicyProvider as G, AgentContextState as Gt, ObservedSessionIngestionPolicyImportStatus as H, registerGetStatusCountsHandler as Ht, registerDrizzleImportCursorStorage as I, normalizeSelectionString as It, IngestCompletedTurnParams as J, buildTurnInitiator as Jt, LogImportTriggerSubjects as K, ContextWindowTrackerConfig as Kt, importCursors as L, resolveAdapterNameById as Lt, turnsDual as M, assembleForkContext as Mt, registerMemoryTurnStorage as N, FallbackRuntimeOptions as Nt, registerDrizzleMessageStorage as O, AgentStorageSubjects as Ot, registerDrizzleTurnStorage as P, pickFallbackRuntimeOptions as Pt, EventTransform as Q, ensureAgentModel as Qt, importCursorsDual as R, registerListActionsHandler as Rt, MessageRoutingNamespace as S, registerFtsSearchHandler as St, SelectMessage as T, registerDrizzleSessionStorage as Tt, ObservedSessionIngestionPolicyInput as U, registerResumeHandler as Ut, ObservedSessionIngestionPolicyDecision as V, actionRegistry as Vt, registerObservedSessionIngestionPolicyProvider as W, ContextWindowTracker as Wt, IngestTurnMessage as X, buildRecoveryContextWithPipeline as Xt, IngestCompletedTurnResult as Y, RecoveryConfig as Yt, ingestCompletedTurn as Z, ensureAgentCwd as Zt, InsertMessageRouting as _, fetchAgentsBySession as _t, buildSessionContext as a, findTurnByAgent as an, registerMemorySessionEventStorage as at, messageRoutingDual as b, mapRowToSession as bt, kindToBranchKind as c, extractTextContent as cn, sessionEvents as ct, registerSpawningToolCallResolver as d, AdapterRegistry as dn, SessionPreviewMaps as dt, verifyAndRecoverAgents as en, SessionTurnStartedPayload as et, registerCompressLineageResolver as f, ISessionOrchestrator as fn, fetchSessionPreviewMaps as ft, StartTurnOptions as g, SearchSessionRow as gt, MakaioSessionConfig as h, MakaioSessionService as hn, SearchFilters as ht, getFullConversation as i, resolveModelCapabilities as in, registerDrizzleSessionEventStorage as it, turns as j, SessionBridge as jt, InsertTurn as k, SessionExtensionContextImpl as kt, toSessionLineage as l, normalizeToBlocks as ln, sessionEventsDual as lt, MakaioSession as m, registerCoreSessionServiceHandlers as mn, mapToSession as mt, NativeLocalityIntent as n, resolveAdapterId as nn, emitSessionTurnStarted as nt, BuildContextOptions as o, getOrCreateSession as on, InsertSessionEvent as ot, registerParentResolver as p, SessionOrchestrator as pn, mapAgentsBySession as pt, isPolicyDiscoveredObservedSession as q, SessionContextWindowState as qt, evaluateNativeLocality as r, resolveExecutionTarget as rn, registerSessionLifecycleEventWriters as rt, ContextAssemblyResult as s, resolveTargetAgents as sn, SelectSessionEvent as st, NativeLocalityInput as t, buildRecoveryContext as tn, appendSessionLifecycleEvent as tt, registerSessionDiscoveredHandler as u, TurnContextEnricher as un, getSessionAncestorChain as ut, SelectMessageRouting as v, fetchMessageCountsBySession as vt, InsertMessage as w, registerMemoryAgentStorage as wt, registerDrizzleMessageRoutingStorage as x, parseForkTransforms as xt, messageRouting as y, fetchPreviewBySession as yt, IObservedSessionIngestionPolicyProvider as z, registerBuiltInActions as zt };