@theokit/sdk 5.13.0 → 5.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/dist/{agent-DSMuwADp.d.ts → agent-B6C9i_qu.d.ts} +31 -213
  3. package/dist/{agent-iW5kPpfT.d.cts → agent-B6FQad6P.d.cts} +31 -213
  4. package/dist/{agent-5DSDDH7K.js → agent-DRDGUU6T.js} +21 -20
  5. package/dist/{agent-5DSDDH7K.js.map → agent-DRDGUU6T.js.map} +1 -1
  6. package/dist/{agent-WOMRT3KX.cjs → agent-VI2HITPT.cjs} +22 -21
  7. package/dist/{agent-WOMRT3KX.cjs.map → agent-VI2HITPT.cjs.map} +1 -1
  8. package/dist/agent.d.ts +2 -3
  9. package/dist/auth/index.cjs +17 -16
  10. package/dist/auth/index.cjs.map +1 -1
  11. package/dist/auth/index.js +5 -4
  12. package/dist/auth/index.js.map +1 -1
  13. package/dist/{batch-EP3FCL6D.js → batch-N2XDYZED.js} +4 -4
  14. package/dist/{batch-EP3FCL6D.js.map → batch-N2XDYZED.js.map} +1 -1
  15. package/dist/{batch-IZ5EDKJ5.cjs → batch-VFR2MAUE.cjs} +7 -7
  16. package/dist/{batch-IZ5EDKJ5.cjs.map → batch-VFR2MAUE.cjs.map} +1 -1
  17. package/dist/{chunk-XOYNB3YN.js → chunk-23SS4ID4.js} +3 -3
  18. package/dist/{chunk-XOYNB3YN.js.map → chunk-23SS4ID4.js.map} +1 -1
  19. package/dist/{chunk-NHOEXFZT.js → chunk-2HXTNVLM.js} +5 -2
  20. package/dist/chunk-2HXTNVLM.js.map +1 -0
  21. package/dist/{chunk-2C24NSNV.js → chunk-3BBTHFGJ.js} +3 -3
  22. package/dist/{chunk-2C24NSNV.js.map → chunk-3BBTHFGJ.js.map} +1 -1
  23. package/dist/{chunk-NP362THY.cjs → chunk-3F53FLQ7.cjs} +5 -7
  24. package/dist/chunk-3F53FLQ7.cjs.map +1 -0
  25. package/dist/{chunk-3FSBE4PS.js → chunk-3GTN4HOO.js} +10 -6
  26. package/dist/chunk-3GTN4HOO.js.map +1 -0
  27. package/dist/{chunk-7WARNHWW.cjs → chunk-3UMPP553.cjs} +5 -2
  28. package/dist/chunk-3UMPP553.cjs.map +1 -0
  29. package/dist/{chunk-SXH37C7X.cjs → chunk-55LLQFHW.cjs} +6 -6
  30. package/dist/{chunk-SXH37C7X.cjs.map → chunk-55LLQFHW.cjs.map} +1 -1
  31. package/dist/{chunk-QISSETTG.cjs → chunk-5645PMVU.cjs} +6 -4
  32. package/dist/chunk-5645PMVU.cjs.map +1 -0
  33. package/dist/{chunk-JX4LB6XO.js → chunk-5M5GQYBM.js} +617 -250
  34. package/dist/chunk-5M5GQYBM.js.map +1 -0
  35. package/dist/{chunk-KL7ZUMK3.cjs → chunk-64ECM3XM.cjs} +704 -337
  36. package/dist/chunk-64ECM3XM.cjs.map +1 -0
  37. package/dist/{chunk-ZJAYFSVI.js → chunk-7ACS6P5Z.js} +5 -7
  38. package/dist/chunk-7ACS6P5Z.js.map +1 -0
  39. package/dist/{chunk-5A4UFBHW.cjs → chunk-A77UMVMD.cjs} +15 -11
  40. package/dist/chunk-A77UMVMD.cjs.map +1 -0
  41. package/dist/{chunk-ZTP6ZACR.js → chunk-ARC2V7NY.js} +3 -3
  42. package/dist/{chunk-ZTP6ZACR.js.map → chunk-ARC2V7NY.js.map} +1 -1
  43. package/dist/{chunk-WDVG5R2Q.cjs → chunk-AUH2EVWY.cjs} +4 -3
  44. package/dist/chunk-AUH2EVWY.cjs.map +1 -0
  45. package/dist/chunk-BNEUB52I.cjs +55 -0
  46. package/dist/chunk-BNEUB52I.cjs.map +1 -0
  47. package/dist/chunk-BPL5CVZ5.js +53 -0
  48. package/dist/chunk-BPL5CVZ5.js.map +1 -0
  49. package/dist/{chunk-2SFLLOMN.js → chunk-CBBT42VX.js} +3 -3
  50. package/dist/{chunk-2SFLLOMN.js.map → chunk-CBBT42VX.js.map} +1 -1
  51. package/dist/chunk-CHKV2L2Y.cjs +416 -0
  52. package/dist/chunk-CHKV2L2Y.cjs.map +1 -0
  53. package/dist/{chunk-4UYHP6NF.cjs → chunk-DJKGDLYZ.cjs} +93 -63
  54. package/dist/chunk-DJKGDLYZ.cjs.map +1 -0
  55. package/dist/{chunk-354F3OF5.js → chunk-FGGVSHDW.js} +3 -3
  56. package/dist/{chunk-354F3OF5.js.map → chunk-FGGVSHDW.js.map} +1 -1
  57. package/dist/{chunk-6OCJWGVD.cjs → chunk-FTXY4D44.cjs} +4 -4
  58. package/dist/{chunk-6OCJWGVD.cjs.map → chunk-FTXY4D44.cjs.map} +1 -1
  59. package/dist/chunk-INVEGVGO.js +405 -0
  60. package/dist/chunk-INVEGVGO.js.map +1 -0
  61. package/dist/{chunk-2PRGRYEQ.js → chunk-IOBHFP2E.js} +50 -20
  62. package/dist/chunk-IOBHFP2E.js.map +1 -0
  63. package/dist/{chunk-47EACDOC.cjs → chunk-KMFBNKCT.cjs} +4 -4
  64. package/dist/{chunk-47EACDOC.cjs.map → chunk-KMFBNKCT.cjs.map} +1 -1
  65. package/dist/{chunk-DF77RBF4.js → chunk-LCCT5ZXJ.js} +6 -6
  66. package/dist/{chunk-DF77RBF4.js.map → chunk-LCCT5ZXJ.js.map} +1 -1
  67. package/dist/{chunk-G7XBVM3T.cjs → chunk-MHUOVS5I.cjs} +5 -5
  68. package/dist/{chunk-G7XBVM3T.cjs.map → chunk-MHUOVS5I.cjs.map} +1 -1
  69. package/dist/{chunk-CWQPQTUZ.cjs → chunk-NEH3BPFD.cjs} +15 -15
  70. package/dist/{chunk-CWQPQTUZ.cjs.map → chunk-NEH3BPFD.cjs.map} +1 -1
  71. package/dist/{chunk-5AR6O7GW.js → chunk-NK5EOTDY.js} +3 -3
  72. package/dist/{chunk-5AR6O7GW.js.map → chunk-NK5EOTDY.js.map} +1 -1
  73. package/dist/{chunk-S46WJTDL.cjs → chunk-P7QYG4RZ.cjs} +27 -19
  74. package/dist/chunk-P7QYG4RZ.cjs.map +1 -0
  75. package/dist/chunk-PPU2D4FZ.js +19 -0
  76. package/dist/chunk-PPU2D4FZ.js.map +1 -0
  77. package/dist/{chunk-MS3TQSXU.js → chunk-QD6B6W6I.js} +6 -4
  78. package/dist/chunk-QD6B6W6I.js.map +1 -0
  79. package/dist/{chunk-AB4OPJLD.js → chunk-RGVMJU57.js} +3 -3
  80. package/dist/{chunk-AB4OPJLD.js.map → chunk-RGVMJU57.js.map} +1 -1
  81. package/dist/{chunk-NWWTYBD3.cjs → chunk-RTDVSHJR.cjs} +5 -5
  82. package/dist/{chunk-NWWTYBD3.cjs.map → chunk-RTDVSHJR.cjs.map} +1 -1
  83. package/dist/{chunk-5HSMH2ZZ.js → chunk-RZL2W4C3.js} +25 -17
  84. package/dist/chunk-RZL2W4C3.js.map +1 -0
  85. package/dist/chunk-SPEN7RJU.cjs +18 -0
  86. package/dist/{chunk-LO6LIUZ6.cjs.map → chunk-SPEN7RJU.cjs.map} +1 -1
  87. package/dist/{chunk-ZF2LDKQQ.cjs → chunk-U3DW3WDE.cjs} +9 -8
  88. package/dist/chunk-U3DW3WDE.cjs.map +1 -0
  89. package/dist/{chunk-DVP3YMDA.cjs → chunk-U7PRI3XM.cjs} +3 -3
  90. package/dist/{chunk-DVP3YMDA.cjs.map → chunk-U7PRI3XM.cjs.map} +1 -1
  91. package/dist/{chunk-H7G65PNI.js → chunk-VCQ37TC5.js} +3 -3
  92. package/dist/{chunk-H7G65PNI.js.map → chunk-VCQ37TC5.js.map} +1 -1
  93. package/dist/{chunk-SDZ4XDWS.cjs → chunk-VWYFGE27.cjs} +9 -9
  94. package/dist/{chunk-SDZ4XDWS.cjs.map → chunk-VWYFGE27.cjs.map} +1 -1
  95. package/dist/{chunk-RN3XDZGS.js → chunk-WM646HEN.js} +4 -3
  96. package/dist/chunk-WM646HEN.js.map +1 -0
  97. package/dist/chunk-X7CE7Y5W.js +305 -0
  98. package/dist/chunk-X7CE7Y5W.js.map +1 -0
  99. package/dist/{chunk-CGH4BCIY.cjs → chunk-XE3CAY6Z.cjs} +5 -5
  100. package/dist/{chunk-CGH4BCIY.cjs.map → chunk-XE3CAY6Z.cjs.map} +1 -1
  101. package/dist/chunk-XOU3CL7S.cjs +312 -0
  102. package/dist/chunk-XOU3CL7S.cjs.map +1 -0
  103. package/dist/{chunk-NKQVLWDF.js → chunk-YKNBTHMD.js} +3 -3
  104. package/dist/{chunk-NKQVLWDF.js.map → chunk-YKNBTHMD.js.map} +1 -1
  105. package/dist/{compact-session-B7P6EU3Z.cjs → compact-session-NX7HUNTB.cjs} +18 -18
  106. package/dist/{compact-session-B7P6EU3Z.cjs.map → compact-session-NX7HUNTB.cjs.map} +1 -1
  107. package/dist/{compact-session-5HMX6KYT.js → compact-session-Q5IGNFPW.js} +9 -9
  108. package/dist/{compact-session-5HMX6KYT.js.map → compact-session-Q5IGNFPW.js.map} +1 -1
  109. package/dist/{cron-BvxrLW5J.d.cts → cron-Bh3aWgQ2.d.cts} +2 -2
  110. package/dist/{cron-DdKzwJqK.d.ts → cron-CCDxeeFZ.d.ts} +2 -2
  111. package/dist/cron.cjs +21 -20
  112. package/dist/cron.d.cts +4 -3
  113. package/dist/cron.d.ts +4 -3
  114. package/dist/cron.js +20 -19
  115. package/dist/eval.cjs +20 -19
  116. package/dist/eval.cjs.map +1 -1
  117. package/dist/eval.js +19 -18
  118. package/dist/eval.js.map +1 -1
  119. package/dist/fs-session-store-CYNTEPJZ.cjs +20 -0
  120. package/dist/{fs-session-store-S2AXVJIX.cjs.map → fs-session-store-CYNTEPJZ.cjs.map} +1 -1
  121. package/dist/fs-session-store-MYQEVUFL.js +11 -0
  122. package/dist/{fs-session-store-6ZCCJX3K.js.map → fs-session-store-MYQEVUFL.js.map} +1 -1
  123. package/dist/{index-manager-HO456AVW.cjs → index-manager-2KH75BRW.cjs} +7 -7
  124. package/dist/{index-manager-HO456AVW.cjs.map → index-manager-2KH75BRW.cjs.map} +1 -1
  125. package/dist/{index-manager-QDH56FER.js → index-manager-NF2WRLOU.js} +6 -6
  126. package/dist/{index-manager-QDH56FER.js.map → index-manager-NF2WRLOU.js.map} +1 -1
  127. package/dist/index.cjs +93 -273
  128. package/dist/index.cjs.map +1 -1
  129. package/dist/index.d.cts +13 -46
  130. package/dist/index.d.ts +13 -46
  131. package/dist/index.js +52 -236
  132. package/dist/index.js.map +1 -1
  133. package/dist/{inject-session-75L3NCNL.js → inject-session-4ROYLZHY.js} +3 -3
  134. package/dist/{inject-session-75L3NCNL.js.map → inject-session-4ROYLZHY.js.map} +1 -1
  135. package/dist/{inject-session-WOH7TPDX.cjs → inject-session-AWKDCGHV.cjs} +4 -4
  136. package/dist/{inject-session-WOH7TPDX.cjs.map → inject-session-AWKDCGHV.cjs.map} +1 -1
  137. package/dist/internal/agent-loop/doom-loop-tracker.d.ts +3 -0
  138. package/dist/internal/agent-loop/prune-tool-results.d.ts +37 -0
  139. package/dist/internal/agent-loop/types.d.ts +6 -0
  140. package/dist/internal/auth/credential-store.d.ts +1 -1
  141. package/dist/internal/auth/types.d.ts +4 -0
  142. package/dist/internal/error-mappers/anthropic.d.ts +3 -0
  143. package/dist/internal/error-mappers/openai-compatible.d.ts +2 -3
  144. package/dist/internal/local-agent/local-agent-dispatch.d.ts +3 -1
  145. package/dist/internal/local-agent/send-queue.d.ts +31 -0
  146. package/dist/internal/mcp/client.d.ts +2 -0
  147. package/dist/internal/mcp/oauth-bearer.d.ts +2 -0
  148. package/dist/internal/memory/adapters/index.cjs +3 -3
  149. package/dist/internal/memory/adapters/index.js +2 -2
  150. package/dist/internal/memory/dreaming/phases.d.ts +15 -0
  151. package/dist/internal/memory/dreaming/run.d.ts +29 -0
  152. package/dist/internal/memory/sdk-memory-peer-loader.d.ts +2 -0
  153. package/dist/internal/memory/storage/index.cjs +51 -35
  154. package/dist/internal/memory/storage/index.d.cts +2 -0
  155. package/dist/internal/memory/storage/index.d.ts +2 -0
  156. package/dist/internal/memory/storage/index.js +4 -4
  157. package/dist/internal/persistence/cwd-mutex.d.cts +4 -2
  158. package/dist/internal/persistence/cwd-mutex.d.ts +4 -2
  159. package/dist/internal/persistence/index.cjs +4 -4
  160. package/dist/internal/persistence/index.js +2 -2
  161. package/dist/internal/persistence/sqlite-session-store.d.cts +25 -0
  162. package/dist/internal/persistence/sqlite-session-store.d.ts +25 -0
  163. package/dist/internal/providers/registry.d.ts +5 -1
  164. package/dist/internal/runtime/skills/binary-on-path.d.ts +1 -0
  165. package/dist/internal/runtime/skills/discover-skills.d.ts +2 -0
  166. package/dist/mcp-auth.cjs +25 -307
  167. package/dist/mcp-auth.cjs.map +1 -1
  168. package/dist/mcp-auth.js +5 -305
  169. package/dist/mcp-auth.js.map +1 -1
  170. package/dist/models.cjs +11 -11
  171. package/dist/models.js +4 -4
  172. package/dist/persistence.cjs +9 -4
  173. package/dist/persistence.cjs.map +1 -1
  174. package/dist/persistence.d.cts +744 -40
  175. package/dist/persistence.d.ts +744 -40
  176. package/dist/persistence.js +3 -2
  177. package/dist/persistence.js.map +1 -1
  178. package/dist/providers.cjs +6 -6
  179. package/dist/providers.js +4 -4
  180. package/dist/sandbox/docker-sandbox.d.cts +58 -0
  181. package/dist/sandbox/docker-sandbox.d.ts +58 -0
  182. package/dist/sandbox/index.cjs +129 -1
  183. package/dist/sandbox/index.cjs.map +1 -1
  184. package/dist/sandbox/index.d.cts +1 -0
  185. package/dist/sandbox/index.d.ts +1 -0
  186. package/dist/sandbox/index.js +132 -5
  187. package/dist/sandbox/index.js.map +1 -1
  188. package/dist/{sdk-agent-4-dXI2GS.d.cts → sdk-agent-BA_6_wtc.d.cts} +57 -4
  189. package/dist/{sdk-agent-CTOJlWA_.d.ts → sdk-agent-CnwPODYH.d.ts} +57 -4
  190. package/dist/session-store-Dh07jr9N.d.cts +209 -0
  191. package/dist/session-store-Dh07jr9N.d.ts +209 -0
  192. package/dist/skills.cjs +4 -4
  193. package/dist/skills.js +1 -1
  194. package/dist/sqlite-session-store-BbcpKY1L.d.ts +64 -0
  195. package/dist/sqlite-session-store-TKXtT4ON.d.cts +64 -0
  196. package/dist/subagents-loader-KLWF4QPD.cjs +16 -0
  197. package/dist/{subagents-loader-TXOA5EJJ.cjs.map → subagents-loader-KLWF4QPD.cjs.map} +1 -1
  198. package/dist/subagents-loader-SXETS2F2.js +7 -0
  199. package/dist/{subagents-loader-Z744TAKD.js.map → subagents-loader-SXETS2F2.js.map} +1 -1
  200. package/dist/subagents-loader.cjs +2 -2
  201. package/dist/subagents-loader.d.cts +3 -2
  202. package/dist/subagents-loader.d.ts +3 -2
  203. package/dist/subagents-loader.js +1 -1
  204. package/dist/types/agent.d.ts +20 -1
  205. package/dist/types/budget-tracker.d.ts +6 -2
  206. package/dist/types/mcp.d.ts +14 -0
  207. package/dist/types/run.d.ts +42 -3
  208. package/dist/workflow.d.cts +1 -1
  209. package/dist/workflow.d.ts +1 -1
  210. package/docs/adr/mutation-testing-scope.md +66 -0
  211. package/docs/error-codes.md +48 -45
  212. package/docs/harness-capability-map.md +60 -6
  213. package/package.json +1 -1
  214. package/dist/chunk-2PRGRYEQ.js.map +0 -1
  215. package/dist/chunk-3FSBE4PS.js.map +0 -1
  216. package/dist/chunk-4UYHP6NF.cjs.map +0 -1
  217. package/dist/chunk-5A4UFBHW.cjs.map +0 -1
  218. package/dist/chunk-5HSMH2ZZ.js.map +0 -1
  219. package/dist/chunk-6CXRYPG7.cjs +0 -211
  220. package/dist/chunk-6CXRYPG7.cjs.map +0 -1
  221. package/dist/chunk-7WARNHWW.cjs.map +0 -1
  222. package/dist/chunk-JX4LB6XO.js.map +0 -1
  223. package/dist/chunk-KL7ZUMK3.cjs.map +0 -1
  224. package/dist/chunk-LO6LIUZ6.cjs +0 -18
  225. package/dist/chunk-MS3TQSXU.js.map +0 -1
  226. package/dist/chunk-MSEL5E5P.js +0 -204
  227. package/dist/chunk-MSEL5E5P.js.map +0 -1
  228. package/dist/chunk-NHOEXFZT.js.map +0 -1
  229. package/dist/chunk-NP362THY.cjs.map +0 -1
  230. package/dist/chunk-Q5EWJPRY.js +0 -18
  231. package/dist/chunk-Q5EWJPRY.js.map +0 -1
  232. package/dist/chunk-QISSETTG.cjs.map +0 -1
  233. package/dist/chunk-RN3XDZGS.js.map +0 -1
  234. package/dist/chunk-S46WJTDL.cjs.map +0 -1
  235. package/dist/chunk-WDVG5R2Q.cjs.map +0 -1
  236. package/dist/chunk-ZF2LDKQQ.cjs.map +0 -1
  237. package/dist/chunk-ZJAYFSVI.js.map +0 -1
  238. package/dist/fs-session-store-6ZCCJX3K.js +0 -11
  239. package/dist/fs-session-store-S2AXVJIX.cjs +0 -20
  240. package/dist/subagents-loader-TXOA5EJJ.cjs +0 -16
  241. package/dist/subagents-loader-Z744TAKD.js +0 -7
@@ -431,6 +431,13 @@ type McpStdioServerConfig = {
431
431
  * policy and always wins. Pass `"all"` to restore full inheritance.
432
432
  */
433
433
  envPolicy?: EnvPolicy;
434
+ /**
435
+ * Run the calls a model makes to this server's tools in ONE step one at a time, in the order the
436
+ * model listed them, instead of at once. Set it for a stateful server whose tools act on shared
437
+ * state, such as a browser MCP server where a snapshot must wait for the navigation before it.
438
+ * Calls to other servers or non-MCP tools in the same step are not held behind it. Default `false`.
439
+ */
440
+ sequential?: boolean;
434
441
  };
435
442
  /**
436
443
  * OAuth-style auth bundle for HTTP/SSE MCP servers.
@@ -482,6 +489,13 @@ type McpHttpServerConfig = {
482
489
  * `NetworkError` (`code: "mcp_timeout"`). Default 30_000.
483
490
  */
484
491
  requestTimeoutMs?: number;
492
+ /**
493
+ * Run the calls a model makes to this server's tools in ONE step one at a time, in the order the
494
+ * model listed them, instead of at once. Set it for a stateful server whose tools act on shared
495
+ * state, such as a browser MCP server where a snapshot must wait for the navigation before it.
496
+ * Calls to other servers or non-MCP tools in the same step are not held behind it. Default `false`.
497
+ */
498
+ sequential?: boolean;
485
499
  };
486
500
  /**
487
501
  * Union of MCP server configs.
@@ -1577,6 +1591,17 @@ interface ToolResultGuardOptions {
1577
1591
  /** Redact common PII patterns (email, phone) in tool-result content. */
1578
1592
  redactPii?: boolean;
1579
1593
  }
1594
+ /**
1595
+ * B-564 — how old a tool result may get, in tool rounds, before its content is pruned from the
1596
+ * next LLM request (`SendOptions.pruneToolResults`). Contract type owned by `types/`; the
1597
+ * implementation lives in `internal/agent-loop/prune-tool-results.ts`, which re-exports this.
1598
+ *
1599
+ * @public
1600
+ */
1601
+ interface PruneToolResultsOptions {
1602
+ /** Keep the newest `olderThanRounds` tool rounds whole; an integer of at least 1. */
1603
+ olderThanRounds: number;
1604
+ }
1580
1605
  /**
1581
1606
  * Lifecycle status of a {@link Run}.
1582
1607
  *
@@ -1853,6 +1878,8 @@ type SDKImage = {
1853
1878
  mimeType: string;
1854
1879
  dimension?: SDKImageDimension;
1855
1880
  };
1881
+ /** How a message sent during a running turn is queued. See {@link SendOptions.queueMode}. @public */
1882
+ type QueueMode = "followup" | "steer" | "collect";
1856
1883
  /**
1857
1884
  * Structured form of `agent.send()`'s message argument. Use it to send images
1858
1885
  * alongside text.
@@ -1868,7 +1895,7 @@ interface SDKUserMessage {
1868
1895
  *
1869
1896
  * ## Which options do I need?
1870
1897
  *
1871
- * Twenty-one optional fields with genuinely different audiences, so most callers read all of them to
1898
+ * Twenty-two optional fields with genuinely different audiences, so most callers read all of them to
1872
1899
  * find their two. This table is the fix that was chosen; the alternative — nesting the groups under
1873
1900
  * `observe?` and `toolPolicy?` and carrying the flat keys as deprecated aliases for one major — would
1874
1901
  * have added surface to remove surface, and the harm here is the READING cost, not a representable
@@ -1878,9 +1905,9 @@ interface SDKUserMessage {
1878
1905
  * | If you are… | you want |
1879
1906
  * |---|---|
1880
1907
  * | rendering a live UI | `onDelta`, `onStep`, `onRunEvent` |
1881
- * | applying a policy | `permissionMode`, `activeTools`, `toolChoice`, `toolResultGuard`, `perToolTimeoutMs` |
1908
+ * | applying a policy | `permissionMode`, `activeTools`, `toolChoice`, `toolResultGuard`, `pruneToolResults`, `perToolTimeoutMs` |
1882
1909
  * | running an eval or a harness | `maxIterations`, `completionCheck`, `doomLoop`, `signal` |
1883
- * | orchestrating agents | `origin`, `task`, `context` |
1910
+ * | orchestrating agents | `origin`, `task`, `context`, `queueMode` |
1884
1911
  * | overriding this one send | `model`, `systemPrompt`, `tools`, `mcpServers`, `contextPaths`, `local` |
1885
1912
  *
1886
1913
  * Every field appears in exactly one row, and
@@ -1891,6 +1918,18 @@ interface SDKUserMessage {
1891
1918
  * @public
1892
1919
  */
1893
1920
  interface SendOptions {
1921
+ /**
1922
+ * What to do with this message when the agent is ALREADY running a turn (local runtime only; a
1923
+ * cloud agent always queues as `"followup"`). With no turn running, every mode just starts one.
1924
+ *
1925
+ * - `"followup"` (default) — wait for the running turn, then run as its own turn.
1926
+ * - `"steer"` — inject the text into the RUNNING turn as a user message, picked up before the
1927
+ * model's next call (after the current tool round). Resolves to the running turn's `Run`. If
1928
+ * the turn ends before it can pick the message up, it runs as a followup turn instead.
1929
+ * - `"collect"` — batch every `"collect"` message sent while a turn runs into ONE followup turn
1930
+ * (texts joined by a blank line). Every collecting caller resolves to that same batched `Run`.
1931
+ */
1932
+ queueMode?: QueueMode;
1894
1933
  /**
1895
1934
  * Per-send model override. SE8 — accepts a bare-string id shorthand
1896
1935
  * (`"openai/gpt-4o-mini"`, normalized to `{ id }`) OR a {@link ModelSelection}
@@ -2023,6 +2062,20 @@ interface SendOptions {
2023
2062
  * @public
2024
2063
  */
2025
2064
  toolResultGuard?: ToolResultGuardOptions;
2065
+ /**
2066
+ * B-564 — opt-in pruning of aged tool results. With `{ olderThanRounds: n }`, the content of
2067
+ * every tool result older than `n` tool rounds is replaced by a short stub in each request the
2068
+ * run's agent loop sends (its `toolUseId` and `isError` kept; session compaction is not pruned); the transcript the run keeps, persists and resumes
2069
+ * from stays whole. `olderThanRounds` must be an integer of at least 1, else the send fails
2070
+ * with `ConfigurationError` code `invalid_prune_tool_results` before any provider call.
2071
+ * Undefined = no pruning (the request is unchanged). Pruning trades request size against
2072
+ * prefix-cache reuse: each new round turns one more previously sent result into a stub, so the
2073
+ * request prefix changes from that message onward on providers that cache message prefixes.
2074
+ * The cache-hit cost was not measured.
2075
+ *
2076
+ * @public
2077
+ */
2078
+ pruneToolResults?: PruneToolResultsOptions;
2026
2079
  /**
2027
2080
  * Opt-in task wrapping (ADRs D363, D374). When truthy, the entire
2028
2081
  * run is registered as a `Task` in the SDK's observable registry —
@@ -2557,4 +2610,4 @@ interface InvalidateCacheOptions {
2557
2610
  applyNow?: boolean;
2558
2611
  }
2559
2612
 
2560
- export type { OutputProcessorContext as $, AgentConversationTurn as A, GenerateRunResult as B, ContextSettings as C, DoomLoopThresholds as D, EnvPolicy as E, ForkOptions as F, GoalOptions as G, InteractionUpdate as H, InputProcessorContext as I, JudgeResult as J, InvalidateCacheOptions as K, McpAuthConfig as L, McpServerConfig as M, McpHttpServerConfig as N, McpOAuthConfig as O, ProviderRoutingSettings as P, McpStdioServerConfig as Q, RunResult as R, SDKAgent as S, MemoryAdapter as T, MemoryAdapterCapabilities as U, MemoryContext as V, MemoryFact as W, MemoryRevision as X, MemoryToolSchema as Y, MemoryTurnMessage as Z, MessageOrigin as _, PluginsSettings as a, ToolCall as a$, PartialToolCallUpdate as a0, PersonalityPreset as a1, ProcessorControls as a2, ProcessorTripwire as a3, ProcessorViolation as a4, ProviderCapability as a5, ProviderRoute as a6, ResolvedProviderRoute as a7, RunCompactBoundaryEvent as a8, RunCompletionCheckEvent as a9, SDKProvidersManager as aA, SDKRequestMessage as aB, SDKStatusMessage as aC, SDKSystemMessage as aD, SDKTaskMessage as aE, SDKThinkingMessage as aF, SDKToolUseMessage as aG, SDKUserMessage as aH, SDKUserMessageEvent as aI, SendOptions as aJ, ShellCommand as aK, ShellConversationTurn as aL, ShellOutput as aM, ShellOutputDeltaUpdate as aN, StepCompletedUpdate as aO, StepStartedUpdate as aP, StreamToCompletionResult as aQ, SummaryCompletedUpdate as aR, SummaryStartedUpdate as aS, SummaryUpdate as aT, SystemPromptSkillRef as aU, TextDeltaUpdate as aV, ThinkingCompletedUpdate as aW, ThinkingDeltaUpdate as aX, ThinkingMessage as aY, TokenDeltaUpdate as aZ, TokenUsage as a_, RunErrorDetail as aa, RunEvent as ab, RunGitInfo as ac, RunMemoryDegradedEvent as ad, RunPermissionDeniedEvent as ae, RunRateLimitEvent as af, RunStatus as ag, RunTaskCompletedEvent as ah, RunTaskStartedEvent as ai, RunTaskUpdatedEvent as aj, RunTimelineEvent as ak, RunToCompletionOptions as al, RunToCompletionResult as am, RunToolProgressEvent as an, RunTripwireEvent as ao, RunUntilIterator as ap, SDKAgentPlugins as aq, SDKAgentSkillDetail as ar, SDKAgentSkills as as, SDKArtifact as at, SDKAssistantMessage as au, SDKContextManager as av, SDKImage as aw, SDKImageDimension as ax, SDKObjectDelta as ay, SDKPluginMetadata as az, Run as b, ToolCallCompletedUpdate as b0, ToolCallStartedUpdate as b1, ToolResult as b2, ToolResultGuardOptions as b3, ToolUseBlock as b4, TurnEndedUpdate as b5, UserMessage as b6, UserMessageAppendedUpdate as b7, Verdict as b8, Processor as c, GoalEvent as d, GoalResult as e, MemoryId as f, RunEventSink as g, SDKProvider as h, SDKMessage as i, AgentMemory as j, AgentOperation as k, AssistantMessage as l, CompletionCheck as m, CompletionCheckResult as n, ContextBudget as o, ContextManagerKind as p, ContextSnapshot as q, ContextSource as r, ContextSourceStatus as s, ConversationStep as t, ConversationTurn as u, CostBreakdown as v, CostSource as w, CostStatus as x, ForkResult as y, GenerateOptions as z };
2613
+ export type { OutputProcessorContext as $, AgentConversationTurn as A, GenerateRunResult as B, ContextSettings as C, DoomLoopThresholds as D, EnvPolicy as E, ForkOptions as F, GoalOptions as G, InteractionUpdate as H, InputProcessorContext as I, JudgeResult as J, InvalidateCacheOptions as K, McpAuthConfig as L, McpServerConfig as M, McpHttpServerConfig as N, McpOAuthConfig as O, ProviderRoutingSettings as P, McpStdioServerConfig as Q, RunResult as R, SDKAgent as S, MemoryAdapter as T, MemoryAdapterCapabilities as U, MemoryContext as V, MemoryFact as W, MemoryRevision as X, MemoryToolSchema as Y, MemoryTurnMessage as Z, MessageOrigin as _, PluginsSettings as a, TokenDeltaUpdate as a$, PartialToolCallUpdate as a0, PersonalityPreset as a1, ProcessorControls as a2, ProcessorTripwire as a3, ProcessorViolation as a4, ProviderCapability as a5, ProviderRoute as a6, PruneToolResultsOptions as a7, QueueMode as a8, ResolvedProviderRoute as a9, SDKObjectDelta as aA, SDKPluginMetadata as aB, SDKProvidersManager as aC, SDKRequestMessage as aD, SDKStatusMessage as aE, SDKSystemMessage as aF, SDKTaskMessage as aG, SDKThinkingMessage as aH, SDKToolUseMessage as aI, SDKUserMessage as aJ, SDKUserMessageEvent as aK, SendOptions as aL, ShellCommand as aM, ShellConversationTurn as aN, ShellOutput as aO, ShellOutputDeltaUpdate as aP, StepCompletedUpdate as aQ, StepStartedUpdate as aR, StreamToCompletionResult as aS, SummaryCompletedUpdate as aT, SummaryStartedUpdate as aU, SummaryUpdate as aV, SystemPromptSkillRef as aW, TextDeltaUpdate as aX, ThinkingCompletedUpdate as aY, ThinkingDeltaUpdate as aZ, ThinkingMessage as a_, RunCompactBoundaryEvent as aa, RunCompletionCheckEvent as ab, RunErrorDetail as ac, RunEvent as ad, RunGitInfo as ae, RunMemoryDegradedEvent as af, RunPermissionDeniedEvent as ag, RunRateLimitEvent as ah, RunStatus as ai, RunTaskCompletedEvent as aj, RunTaskStartedEvent as ak, RunTaskUpdatedEvent as al, RunTimelineEvent as am, RunToCompletionOptions as an, RunToCompletionResult as ao, RunToolProgressEvent as ap, RunTripwireEvent as aq, RunUntilIterator as ar, SDKAgentPlugins as as, SDKAgentSkillDetail as at, SDKAgentSkills as au, SDKArtifact as av, SDKAssistantMessage as aw, SDKContextManager as ax, SDKImage as ay, SDKImageDimension as az, Run as b, TokenUsage as b0, ToolCall as b1, ToolCallCompletedUpdate as b2, ToolCallStartedUpdate as b3, ToolResult as b4, ToolResultGuardOptions as b5, ToolUseBlock as b6, TurnEndedUpdate as b7, UserMessage as b8, UserMessageAppendedUpdate as b9, Verdict as ba, Processor as c, GoalEvent as d, GoalResult as e, MemoryId as f, RunEventSink as g, SDKProvider as h, SDKMessage as i, AgentMemory as j, AgentOperation as k, AssistantMessage as l, CompletionCheck as m, CompletionCheckResult as n, ContextBudget as o, ContextManagerKind as p, ContextSnapshot as q, ContextSource as r, ContextSourceStatus as s, ConversationStep as t, ConversationTurn as u, CostBreakdown as v, CostSource as w, CostStatus as x, ForkResult as y, GenerateOptions as z };
@@ -0,0 +1,209 @@
1
+ /**
2
+ * Owner: `src/` (1 of 2 importers). Derived from the import graph, not
3
+ * declared — `tests/lint/types-name-their-owner.test.ts` re-derives it.
4
+ *
5
+ * `SessionRecord` — the native on-disk transcript record shape (SE40).
6
+ *
7
+ * The theokit session format IS the Claude Code record shape: a
8
+ * `uuid`/`parentUuid` DAG of records with structured
9
+ * `text`/`tool_use`/`tool_result`/`thinking` blocks. This is the contract the
10
+ * pluggable {@link SessionStore} seam operates over.
11
+ *
12
+ * DIP-correct home (SE46): the contract lives in the domain `types/` layer;
13
+ * the application-layer DAG core (`internal/persistence/session-transcript.ts`)
14
+ * re-exports it for back-compat while owning the record builders + reader.
15
+ *
16
+ * @public
17
+ */
18
+ /** A content block inside {@link TranscriptMessage}. */
19
+ type TranscriptBlock = {
20
+ type: "text";
21
+ text: string;
22
+ } | {
23
+ type: "thinking";
24
+ thinking?: string;
25
+ signature?: string;
26
+ } | {
27
+ type: "tool_use";
28
+ id: string;
29
+ name: string;
30
+ input: unknown;
31
+ } | {
32
+ type: "tool_result";
33
+ tool_use_id: string;
34
+ content: unknown;
35
+ is_error?: boolean;
36
+ };
37
+ /**
38
+ * The message body of a {@link SessionRecord}.
39
+ *
40
+ * **It is NOT called `SessionMessage`** — that name already exists in
41
+ * `internal/session/session-types.ts` with the shape `{role, text}`, incompatible with this one.
42
+ * Reusing an exported name for a new shape is
43
+ * precisely the silent break M91 cost two patches to undo.
44
+ *
45
+ * Parsing from disk stays **tolerant** (`readTranscript` skips a malformed line): what changes here
46
+ * is the **type**, not leniency — records written by earlier versions stay readable.
47
+ *
48
+ * @public
49
+ */
50
+ interface TranscriptMessage {
51
+ role: "user" | "assistant";
52
+ content: TranscriptBlock[];
53
+ /**
54
+ * The three fields below appear **only** on the assistant record, and come from the writer
55
+ * (`SessionTranscript.appendAssistant`). Declared optional because the user record does not carry
56
+ * them — measured in the writer itself, not assumed.
57
+ */
58
+ id?: string;
59
+ type?: "message";
60
+ model?: string;
61
+ }
62
+ /**
63
+ * One transcript record — a single line of the session JSONL file, and the unit the pluggable
64
+ * `SessionStore` seam reads and writes.
65
+ *
66
+ * Records form a `uuid`/`parentUuid` DAG, not a flat list: `parentUuid` names the preceding record
67
+ * and is `null` at the root. Thread a session by following those links; a reader that assumes file
68
+ * order is linear will mis-thread one that branched.
69
+ *
70
+ * `message` is absent on `system` records — a compaction boundary carries `compactMetadata` instead —
71
+ * so it is optional even on records you would expect to be conversational, and `type` is what tells
72
+ * you which you are holding.
73
+ *
74
+ * Reading is deliberately tolerant: a malformed line is skipped rather than failing the whole read.
75
+ * Every record you receive is well-formed, but the file may have contained more than you got back,
76
+ * so this is not the type to use for an exact-count audit of what was written.
77
+ *
78
+ * @public
79
+ */
80
+ interface SessionRecord {
81
+ type: "user" | "assistant" | "system";
82
+ uuid: string;
83
+ parentUuid: string | null;
84
+ sessionId: string;
85
+ timestamp: string;
86
+ isSidechain?: boolean;
87
+ userType?: string;
88
+ cwd?: string;
89
+ version?: string;
90
+ subtype?: string;
91
+ compactMetadata?: {
92
+ preTokens: number;
93
+ trigger: string;
94
+ };
95
+ /**
96
+ * The message body, in the shape the transcript writer actually writes.
97
+ *
98
+ * M94 — it was `Record<string, unknown>`, and the consumer recovered the type with a cast on every read.
99
+ * The shape **has always been fixed** (`SessionTranscript.appendToolResults` / `#push` produce
100
+ * it); it simply was not declared. It stays optional because system records carry no message.
101
+ */
102
+ message?: TranscriptMessage;
103
+ }
104
+
105
+ /**
106
+ * Owner: `internal/session/` (4 of 8 importers). Derived from the import graph, not declared —
107
+ * `tests/lint/types-name-their-owner.test.ts` re-derives it.
108
+ *
109
+ * SE41 — the pluggable `SessionStore` seam over the NATIVE session transcript.
110
+ *
111
+ * A minimal, two-method port so an external store (Postgres / Redis / KV /
112
+ * durable object) can be the **primary store AND resume source** — the
113
+ * serverless (ephemeral FS) and multi-host / multi-pod use case that SE40
114
+ * dropped when it removed the `ConversationStorageAdapter`. This is deliberately
115
+ * NOT that removed ~10-method adapter: the seam is JUST record read/append over
116
+ * the native {@link SessionRecord} shape (no getMessages / getSessionMeta /
117
+ * delete / objective methods).
118
+ *
119
+ * The SDK ships a real default implementation, `FsSessionStore`, that reads and
120
+ * append-writes the native Claude-shaped `.jsonl` transcript — omitting
121
+ * `local.sessionStore` yields byte-identical current behavior (back-compat, zero
122
+ * consumer change). Injected via `local.sessionStore` for external stores.
123
+ *
124
+ * THIS SEAM DOES NOT HIDE THE STORAGE, AND IS NOT MEANT TO. A Repository
125
+ * abstracts a persistence model away; this one is defined in terms of the
126
+ * native one — the port speaks {@link SessionRecord}, "the exact SessionRecord
127
+ * the SDK writes", and the on-disk layout's path helpers (`encodeProjectDir`,
128
+ * `transcriptPath`, `transcriptRoot`) are published on purpose at
129
+ * `@theokit/sdk/persistence` so a consumer can locate a transcript file.
130
+ *
131
+ * That is the whole design and the reason the seam is two methods rather than
132
+ * ten: the format is the contract, and a store implements read/append over it.
133
+ * A consumer supplying `local.sessionStore` is NOT bound by those paths — they
134
+ * describe where the DEFAULT `FsSessionStore` puts files, not where an external
135
+ * store must.
136
+ *
137
+ * Consistency contract: `appendRecords` is append-only and ordering-preserving.
138
+ * The FS default serializes appends per agent with a cross-process file lock;
139
+ * external implementations own (and MUST document) their own concurrency
140
+ * guarantees for two hosts appending to the same `agentId`.
141
+ *
142
+ * @public
143
+ */
144
+
145
+ /**
146
+ * The pluggable session-store seam. Exactly two methods over the native
147
+ * {@link SessionRecord} shape.
148
+ *
149
+ * @public
150
+ */
151
+ interface SessionStore {
152
+ /**
153
+ * Return every persisted record for `agentId`, in append order. A session
154
+ * that was never written MUST resolve to `[]` (not throw) — a fresh agent has
155
+ * no history. The SDK reconstructs the resumable `LlmMessage[]` from these
156
+ * records via the native DAG reader, so the shape MUST be the exact
157
+ * {@link SessionRecord} the SDK writes.
158
+ *
159
+ * A store that cannot READ (e.g. the backing DB is unreachable on resume)
160
+ * MUST throw a typed error rather than silently returning `[]` — a silent
161
+ * empty read would masquerade as "no history" and drop the conversation.
162
+ */
163
+ readRecords(agentId: string): Promise<SessionRecord[]>;
164
+ /**
165
+ * Append `records` (the new-turn delta) to `agentId`'s session, append-only.
166
+ * MUST preserve order and MUST NOT drop or rewrite prior records — the native
167
+ * format is an append-only `parentUuid` DAG (compaction is a new-root
168
+ * `compact_boundary` record, still an append).
169
+ *
170
+ * Note on the write path: per-turn persistence is fire-and-forget so `send()`
171
+ * is never blocked by store I/O — an `appendRecords` rejection is logged to
172
+ * stderr, NOT thrown to the caller (best-effort write). An external store that
173
+ * must guarantee durability should make `appendRecords` resilient (retry /
174
+ * durable write) internally. This differs from {@link SessionStore.readRecords},
175
+ * which MUST throw on failure (a resume cannot proceed on a silent partial history).
176
+ */
177
+ appendRecords(agentId: string, records: readonly SessionRecord[]): Promise<void>;
178
+ /**
179
+ * Claim the single-writer lease for `agentId`, if this store has one. OPTIONAL.
180
+ *
181
+ * The SDK calls it when an agent starts and skips it when absent, so a two-method store keeps
182
+ * working unchanged — declaring it here does not require it, which is the whole reason it is
183
+ * optional. What declaring it DOES is make the capability discoverable: the SDK probed for this
184
+ * method through an `as unknown` cast against an interface that never mentioned it, so a
185
+ * third-party store author — the serverless / multi-pod case this port exists to serve — read a
186
+ * two-method interface, implemented two methods, and never learned the hook was there.
187
+ *
188
+ * CONTRACT, and the half that matters: a rejection whose `name` is `"SessionBusyError"` PROPAGATES
189
+ * to the caller, because another process holding the session is a decision the caller has to make
190
+ * (`exec` forks to a new id). Any other rejection is treated as "no lease available here" —
191
+ * logged, and the turn proceeds without single-writer protection, since the write is best-effort
192
+ * by contract anyway.
193
+ */
194
+ acquire?(agentId: string): Promise<void>;
195
+ /**
196
+ * Release the lease `acquire` claimed, if this store has one. OPTIONAL.
197
+ *
198
+ * Called on agent disposal. A rejection is not handled specially.
199
+ */
200
+ release?(agentId: string): Promise<void>;
201
+ /**
202
+ * Release store-level resources — a connection pool, a file handle. OPTIONAL.
203
+ *
204
+ * Called once, on agent disposal, after {@link SessionStore.release}.
205
+ */
206
+ dispose?(): Promise<void>;
207
+ }
208
+
209
+ export type { SessionRecord as S, TranscriptBlock as T, SessionStore as a, TranscriptMessage as b };
@@ -0,0 +1,209 @@
1
+ /**
2
+ * Owner: `src/` (1 of 2 importers). Derived from the import graph, not
3
+ * declared — `tests/lint/types-name-their-owner.test.ts` re-derives it.
4
+ *
5
+ * `SessionRecord` — the native on-disk transcript record shape (SE40).
6
+ *
7
+ * The theokit session format IS the Claude Code record shape: a
8
+ * `uuid`/`parentUuid` DAG of records with structured
9
+ * `text`/`tool_use`/`tool_result`/`thinking` blocks. This is the contract the
10
+ * pluggable {@link SessionStore} seam operates over.
11
+ *
12
+ * DIP-correct home (SE46): the contract lives in the domain `types/` layer;
13
+ * the application-layer DAG core (`internal/persistence/session-transcript.ts`)
14
+ * re-exports it for back-compat while owning the record builders + reader.
15
+ *
16
+ * @public
17
+ */
18
+ /** A content block inside {@link TranscriptMessage}. */
19
+ type TranscriptBlock = {
20
+ type: "text";
21
+ text: string;
22
+ } | {
23
+ type: "thinking";
24
+ thinking?: string;
25
+ signature?: string;
26
+ } | {
27
+ type: "tool_use";
28
+ id: string;
29
+ name: string;
30
+ input: unknown;
31
+ } | {
32
+ type: "tool_result";
33
+ tool_use_id: string;
34
+ content: unknown;
35
+ is_error?: boolean;
36
+ };
37
+ /**
38
+ * The message body of a {@link SessionRecord}.
39
+ *
40
+ * **It is NOT called `SessionMessage`** — that name already exists in
41
+ * `internal/session/session-types.ts` with the shape `{role, text}`, incompatible with this one.
42
+ * Reusing an exported name for a new shape is
43
+ * precisely the silent break M91 cost two patches to undo.
44
+ *
45
+ * Parsing from disk stays **tolerant** (`readTranscript` skips a malformed line): what changes here
46
+ * is the **type**, not leniency — records written by earlier versions stay readable.
47
+ *
48
+ * @public
49
+ */
50
+ interface TranscriptMessage {
51
+ role: "user" | "assistant";
52
+ content: TranscriptBlock[];
53
+ /**
54
+ * The three fields below appear **only** on the assistant record, and come from the writer
55
+ * (`SessionTranscript.appendAssistant`). Declared optional because the user record does not carry
56
+ * them — measured in the writer itself, not assumed.
57
+ */
58
+ id?: string;
59
+ type?: "message";
60
+ model?: string;
61
+ }
62
+ /**
63
+ * One transcript record — a single line of the session JSONL file, and the unit the pluggable
64
+ * `SessionStore` seam reads and writes.
65
+ *
66
+ * Records form a `uuid`/`parentUuid` DAG, not a flat list: `parentUuid` names the preceding record
67
+ * and is `null` at the root. Thread a session by following those links; a reader that assumes file
68
+ * order is linear will mis-thread one that branched.
69
+ *
70
+ * `message` is absent on `system` records — a compaction boundary carries `compactMetadata` instead —
71
+ * so it is optional even on records you would expect to be conversational, and `type` is what tells
72
+ * you which you are holding.
73
+ *
74
+ * Reading is deliberately tolerant: a malformed line is skipped rather than failing the whole read.
75
+ * Every record you receive is well-formed, but the file may have contained more than you got back,
76
+ * so this is not the type to use for an exact-count audit of what was written.
77
+ *
78
+ * @public
79
+ */
80
+ interface SessionRecord {
81
+ type: "user" | "assistant" | "system";
82
+ uuid: string;
83
+ parentUuid: string | null;
84
+ sessionId: string;
85
+ timestamp: string;
86
+ isSidechain?: boolean;
87
+ userType?: string;
88
+ cwd?: string;
89
+ version?: string;
90
+ subtype?: string;
91
+ compactMetadata?: {
92
+ preTokens: number;
93
+ trigger: string;
94
+ };
95
+ /**
96
+ * The message body, in the shape the transcript writer actually writes.
97
+ *
98
+ * M94 — it was `Record<string, unknown>`, and the consumer recovered the type with a cast on every read.
99
+ * The shape **has always been fixed** (`SessionTranscript.appendToolResults` / `#push` produce
100
+ * it); it simply was not declared. It stays optional because system records carry no message.
101
+ */
102
+ message?: TranscriptMessage;
103
+ }
104
+
105
+ /**
106
+ * Owner: `internal/session/` (4 of 8 importers). Derived from the import graph, not declared —
107
+ * `tests/lint/types-name-their-owner.test.ts` re-derives it.
108
+ *
109
+ * SE41 — the pluggable `SessionStore` seam over the NATIVE session transcript.
110
+ *
111
+ * A minimal, two-method port so an external store (Postgres / Redis / KV /
112
+ * durable object) can be the **primary store AND resume source** — the
113
+ * serverless (ephemeral FS) and multi-host / multi-pod use case that SE40
114
+ * dropped when it removed the `ConversationStorageAdapter`. This is deliberately
115
+ * NOT that removed ~10-method adapter: the seam is JUST record read/append over
116
+ * the native {@link SessionRecord} shape (no getMessages / getSessionMeta /
117
+ * delete / objective methods).
118
+ *
119
+ * The SDK ships a real default implementation, `FsSessionStore`, that reads and
120
+ * append-writes the native Claude-shaped `.jsonl` transcript — omitting
121
+ * `local.sessionStore` yields byte-identical current behavior (back-compat, zero
122
+ * consumer change). Injected via `local.sessionStore` for external stores.
123
+ *
124
+ * THIS SEAM DOES NOT HIDE THE STORAGE, AND IS NOT MEANT TO. A Repository
125
+ * abstracts a persistence model away; this one is defined in terms of the
126
+ * native one — the port speaks {@link SessionRecord}, "the exact SessionRecord
127
+ * the SDK writes", and the on-disk layout's path helpers (`encodeProjectDir`,
128
+ * `transcriptPath`, `transcriptRoot`) are published on purpose at
129
+ * `@theokit/sdk/persistence` so a consumer can locate a transcript file.
130
+ *
131
+ * That is the whole design and the reason the seam is two methods rather than
132
+ * ten: the format is the contract, and a store implements read/append over it.
133
+ * A consumer supplying `local.sessionStore` is NOT bound by those paths — they
134
+ * describe where the DEFAULT `FsSessionStore` puts files, not where an external
135
+ * store must.
136
+ *
137
+ * Consistency contract: `appendRecords` is append-only and ordering-preserving.
138
+ * The FS default serializes appends per agent with a cross-process file lock;
139
+ * external implementations own (and MUST document) their own concurrency
140
+ * guarantees for two hosts appending to the same `agentId`.
141
+ *
142
+ * @public
143
+ */
144
+
145
+ /**
146
+ * The pluggable session-store seam. Exactly two methods over the native
147
+ * {@link SessionRecord} shape.
148
+ *
149
+ * @public
150
+ */
151
+ interface SessionStore {
152
+ /**
153
+ * Return every persisted record for `agentId`, in append order. A session
154
+ * that was never written MUST resolve to `[]` (not throw) — a fresh agent has
155
+ * no history. The SDK reconstructs the resumable `LlmMessage[]` from these
156
+ * records via the native DAG reader, so the shape MUST be the exact
157
+ * {@link SessionRecord} the SDK writes.
158
+ *
159
+ * A store that cannot READ (e.g. the backing DB is unreachable on resume)
160
+ * MUST throw a typed error rather than silently returning `[]` — a silent
161
+ * empty read would masquerade as "no history" and drop the conversation.
162
+ */
163
+ readRecords(agentId: string): Promise<SessionRecord[]>;
164
+ /**
165
+ * Append `records` (the new-turn delta) to `agentId`'s session, append-only.
166
+ * MUST preserve order and MUST NOT drop or rewrite prior records — the native
167
+ * format is an append-only `parentUuid` DAG (compaction is a new-root
168
+ * `compact_boundary` record, still an append).
169
+ *
170
+ * Note on the write path: per-turn persistence is fire-and-forget so `send()`
171
+ * is never blocked by store I/O — an `appendRecords` rejection is logged to
172
+ * stderr, NOT thrown to the caller (best-effort write). An external store that
173
+ * must guarantee durability should make `appendRecords` resilient (retry /
174
+ * durable write) internally. This differs from {@link SessionStore.readRecords},
175
+ * which MUST throw on failure (a resume cannot proceed on a silent partial history).
176
+ */
177
+ appendRecords(agentId: string, records: readonly SessionRecord[]): Promise<void>;
178
+ /**
179
+ * Claim the single-writer lease for `agentId`, if this store has one. OPTIONAL.
180
+ *
181
+ * The SDK calls it when an agent starts and skips it when absent, so a two-method store keeps
182
+ * working unchanged — declaring it here does not require it, which is the whole reason it is
183
+ * optional. What declaring it DOES is make the capability discoverable: the SDK probed for this
184
+ * method through an `as unknown` cast against an interface that never mentioned it, so a
185
+ * third-party store author — the serverless / multi-pod case this port exists to serve — read a
186
+ * two-method interface, implemented two methods, and never learned the hook was there.
187
+ *
188
+ * CONTRACT, and the half that matters: a rejection whose `name` is `"SessionBusyError"` PROPAGATES
189
+ * to the caller, because another process holding the session is a decision the caller has to make
190
+ * (`exec` forks to a new id). Any other rejection is treated as "no lease available here" —
191
+ * logged, and the turn proceeds without single-writer protection, since the write is best-effort
192
+ * by contract anyway.
193
+ */
194
+ acquire?(agentId: string): Promise<void>;
195
+ /**
196
+ * Release the lease `acquire` claimed, if this store has one. OPTIONAL.
197
+ *
198
+ * Called on agent disposal. A rejection is not handled specially.
199
+ */
200
+ release?(agentId: string): Promise<void>;
201
+ /**
202
+ * Release store-level resources — a connection pool, a file handle. OPTIONAL.
203
+ *
204
+ * Called once, on agent disposal, after {@link SessionStore.release}.
205
+ */
206
+ dispose?(): Promise<void>;
207
+ }
208
+
209
+ export type { SessionRecord as S, TranscriptBlock as T, SessionStore as a, TranscriptMessage as b };
package/dist/skills.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunk7WARNHWW_cjs = require('./chunk-7WARNHWW.cjs');
3
+ var chunk3UMPP553_cjs = require('./chunk-3UMPP553.cjs');
4
4
  require('./chunk-3KIUY67P.cjs');
5
5
  require('./chunk-SA6K24NB.cjs');
6
6
  require('./chunk-6XQLTQB6.cjs');
@@ -11,15 +11,15 @@ require('./chunk-RNXXYF22.cjs');
11
11
 
12
12
  Object.defineProperty(exports, "buildSkillsBlock", {
13
13
  enumerable: true,
14
- get: function () { return chunk7WARNHWW_cjs.buildSkillsBlock; }
14
+ get: function () { return chunk3UMPP553_cjs.buildSkillsBlock; }
15
15
  });
16
16
  Object.defineProperty(exports, "discoverSkills", {
17
17
  enumerable: true,
18
- get: function () { return chunk7WARNHWW_cjs.discoverSkills; }
18
+ get: function () { return chunk3UMPP553_cjs.discoverSkills; }
19
19
  });
20
20
  Object.defineProperty(exports, "loadSkillInstructions", {
21
21
  enumerable: true,
22
- get: function () { return chunk7WARNHWW_cjs.loadSkillInstructions; }
22
+ get: function () { return chunk3UMPP553_cjs.loadSkillInstructions; }
23
23
  });
24
24
  //# sourceMappingURL=skills.cjs.map
25
25
  //# sourceMappingURL=skills.cjs.map
package/dist/skills.js CHANGED
@@ -1,4 +1,4 @@
1
- export { buildSkillsBlock, discoverSkills, loadSkillInstructions } from './chunk-NHOEXFZT.js';
1
+ export { buildSkillsBlock, discoverSkills, loadSkillInstructions } from './chunk-2HXTNVLM.js';
2
2
  import './chunk-PKRPV3R7.js';
3
3
  import './chunk-UKMBRMGT.js';
4
4
  import './chunk-Q7UG242V.js';
@@ -0,0 +1,64 @@
1
+ import { a as SessionStore, S as SessionRecord } from './session-store-Dh07jr9N.js';
2
+
3
+ /**
4
+ * Run `fn` after every earlier `withCwdMutex` call for the same `key` has settled, and return
5
+ * what `fn` returns.
6
+ *
7
+ * Calls with the same key run strictly in the order they were made — FIFO, never concurrent.
8
+ * Calls with different keys never wait on each other. The key is an opaque string: two callers
9
+ * serialize against each other exactly when they pass equal keys, so a shared key IS the
10
+ * contract, and a mismatched one silently buys no protection at all.
11
+ *
12
+ * A rejection does not poison the queue. The next waiter runs whether the previous `fn` fulfilled
13
+ * or rejected, and the rejection is delivered only to the caller whose `fn` threw. This function
14
+ * neither retries nor swallows: the returned promise rejects with whatever `fn` rejected with.
15
+ *
16
+ * There is no timeout and no cancellation. An `fn` that never settles blocks that key for the
17
+ * lifetime of the process.
18
+ *
19
+ * **Scope — this is an in-process lock only.** State is a module-scoped Map, so it serializes
20
+ * callers that share one module instance and nothing else. Two processes, two worker threads, or
21
+ * two copies of the SDK resolved into the same tree do not see each other's queue. When the
22
+ * resource is a file that other processes can also write, use `withFileLock` from
23
+ * `./file-lock.ts` instead — it takes an OS-level lock and layers this mutex underneath, so it
24
+ * gives both guarantees. Reach for `withCwdMutex` directly when the shared state is in memory, or
25
+ * when the file is one only this process touches.
26
+ *
27
+ * Extracted packages (`@theokit/sdk-budget`, `@theokit/sdk-memory`) import this from
28
+ * `@theokit/sdk` rather than reimplementing it, precisely so the Map is the same one: a per-package
29
+ * copy would give each package its own queue and let their writes race.
30
+ *
31
+ * The Map is module-scoped, so nothing survives a process restart or a fresh module instance.
32
+ * An entry is dropped as soon as its key has no call pending.
33
+ * Signature and semantics will not change before sdk-core v3.0.
34
+ *
35
+ * @public
36
+ */
37
+ declare function withCwdMutex<T>(key: string, fn: () => Promise<T>): Promise<T>;
38
+
39
+ /** Options for {@link SqliteSessionStore}. */
40
+ interface SqliteSessionStoreOptions {
41
+ /** Absolute path of the SQLite file. Parent directories are created. */
42
+ filePath: string;
43
+ }
44
+ /**
45
+ * A {@link SessionStore} that keeps the native session records in one SQLite file instead of
46
+ * per-agent JSONL transcripts. Pass it as `local.sessionStore`.
47
+ *
48
+ * Uses `better-sqlite3` when installed, else the built-in `node:sqlite` (Node 22.5+).
49
+ * Appends are one transaction, so a batch lands whole or not at all; order is the
50
+ * autoincrement `seq`. Corruption is NOT silently rebuilt: opening a corrupt file throws.
51
+ *
52
+ * @public
53
+ */
54
+ declare class SqliteSessionStore implements SessionStore {
55
+ private readonly filePath;
56
+ private dbPromise;
57
+ constructor(options: SqliteSessionStoreOptions);
58
+ private db;
59
+ readRecords(agentId: string): Promise<SessionRecord[]>;
60
+ appendRecords(agentId: string, records: readonly SessionRecord[]): Promise<void>;
61
+ dispose(): Promise<void>;
62
+ }
63
+
64
+ export { SqliteSessionStore as S, type SqliteSessionStoreOptions as a, withCwdMutex as w };