@leuduan/lagent 0.1.2 → 44.0.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 (353) hide show
  1. package/README.md +28 -15
  2. package/dist/chunks/{UC3FVVJ2.js → 2GCIWSOA.js} +2 -2
  3. package/dist/chunks/2P47AHNK.js +7 -0
  4. package/dist/chunks/3UMZMPWW.js +1 -0
  5. package/dist/chunks/5IRF47YB.js +1 -0
  6. package/dist/chunks/6DRCKZ2C.js +1 -0
  7. package/dist/chunks/6FRNHMCV.js +1 -0
  8. package/dist/chunks/7LI64H5X.js +17 -0
  9. package/dist/chunks/{SL2YLB2F.js → 7VAPNE3L.js} +1 -1
  10. package/dist/chunks/{BM3S37EZ.js → ASSQZH3F.js} +1 -1
  11. package/dist/chunks/B4FXK5ER.js +77 -0
  12. package/dist/chunks/{37YOGDGY.js → BBCW2FZK.js} +1 -1
  13. package/dist/chunks/BPRCULZH.js +1 -0
  14. package/dist/chunks/CANPZYTH.js +24 -0
  15. package/dist/chunks/CQEVREBT.js +1 -0
  16. package/dist/chunks/CUK7CGC7.js +1 -0
  17. package/dist/chunks/D4PQP5MA.js +3 -0
  18. package/dist/chunks/{CDQG7RKA.js → DDZ7YF26.js} +1 -1
  19. package/dist/chunks/EMRB4KCN.js +6 -0
  20. package/dist/chunks/EPYQ5M3B.js +3 -0
  21. package/dist/chunks/G44LG6VL.js +1 -0
  22. package/dist/chunks/GGSVIIWJ.js +2 -0
  23. package/dist/chunks/IAAEP6VL.js +30 -0
  24. package/dist/chunks/{AP6Q4EPT.js → JCTBX33H.js} +1 -1
  25. package/dist/chunks/JFX2MXBA.js +4 -0
  26. package/dist/chunks/JFZZXVWD.js +15 -0
  27. package/dist/chunks/KUZCL2SH.js +1 -0
  28. package/dist/chunks/MHC6VPB4.js +7 -0
  29. package/dist/chunks/MMNNZCBO.js +5 -0
  30. package/dist/chunks/{C5LYCXJG.js → MNJ4SRF7.js} +1 -1
  31. package/dist/chunks/N6IXG2VL.js +1 -0
  32. package/dist/chunks/OCBPT7KE.js +1 -0
  33. package/dist/chunks/OL5A6ITQ.js +1 -0
  34. package/dist/chunks/Q75FUN7D.js +2 -0
  35. package/dist/chunks/Q7S5LFGN.js +1 -0
  36. package/dist/chunks/RCIHV3KG.js +1 -0
  37. package/dist/chunks/S34ZA2R6.js +1 -0
  38. package/dist/chunks/SS3B5W34.js +12 -0
  39. package/dist/chunks/VYMT4TXD.js +1 -0
  40. package/dist/chunks/W57RW55W.js +1 -0
  41. package/dist/compositions/base.d.ts +11 -0
  42. package/dist/{presets → compositions}/codex.d.ts +12 -6
  43. package/dist/{presets/prompts.d.ts → compositions/codexPrompts.d.ts} +1 -1
  44. package/dist/context.d.ts +18 -10
  45. package/dist/index.d.ts +31 -23
  46. package/dist/index.js +1 -77
  47. package/dist/journal/catalog.d.ts +1 -1
  48. package/dist/journal/journal.d.ts +3 -3
  49. package/dist/journal/projection.d.ts +1 -1
  50. package/dist/journal/store.d.ts +3 -3
  51. package/dist/llm/index.d.ts +19 -13
  52. package/dist/llm/index.js +1 -0
  53. package/dist/llm/provider.d.ts +11 -0
  54. package/dist/loop/agent.d.ts +16 -132
  55. package/dist/loop/authorization.d.ts +41 -0
  56. package/dist/loop/auxiliary.d.ts +7 -3
  57. package/dist/loop/chunks.d.ts +3 -3
  58. package/dist/loop/completion.d.ts +17 -0
  59. package/dist/loop/errors.d.ts +6 -29
  60. package/dist/loop/hooks.d.ts +39 -6
  61. package/dist/loop/index.d.ts +7 -28
  62. package/dist/loop/runner.d.ts +134 -0
  63. package/dist/loop/runtime.d.ts +7 -16
  64. package/dist/loop/strategy.d.ts +12 -3
  65. package/dist/loop/{prepare.d.ts → surfacePrepare.d.ts} +2 -2
  66. package/dist/loop/tool.d.ts +11 -6
  67. package/dist/loop/toolCalls.d.ts +3 -10
  68. package/dist/plugin.d.ts +31 -34
  69. package/dist/plugin.js +1 -1
  70. package/dist/plugins/agentsMd.d.ts +24 -20
  71. package/dist/plugins/agentsMd.js +1 -1
  72. package/dist/plugins/ask/index.d.ts +2 -2
  73. package/dist/plugins/ask/index.js +1 -1
  74. package/dist/plugins/ask/service.d.ts +2 -2
  75. package/dist/plugins/commands/index.d.ts +5 -2
  76. package/dist/plugins/commands/index.js +1 -1
  77. package/dist/plugins/commands/output.d.ts +1 -1
  78. package/dist/plugins/commands/record.d.ts +31 -22
  79. package/dist/plugins/commands/service.d.ts +18 -11
  80. package/dist/plugins/commands/{background.d.ts → tools.d.ts} +2 -0
  81. package/dist/plugins/compaction/checkpoint.d.ts +4 -1
  82. package/dist/plugins/compaction/config.d.ts +3 -3
  83. package/dist/plugins/compaction/estimate.d.ts +9 -1
  84. package/dist/plugins/compaction/index.d.ts +87 -2
  85. package/dist/plugins/compaction/index.js +5 -5
  86. package/dist/plugins/compaction/{records.d.ts → record.d.ts} +36 -36
  87. package/dist/plugins/compaction/{log.d.ts → state.d.ts} +8 -1
  88. package/dist/plugins/dateAndBranch.js +1 -1
  89. package/dist/plugins/delegations/answers.d.ts +1 -1
  90. package/dist/plugins/delegations/assignmentKey.d.ts +1 -1
  91. package/dist/plugins/delegations/cleanup.d.ts +1 -1
  92. package/dist/plugins/delegations/index.js +1 -1
  93. package/dist/plugins/delegations/notices.d.ts +8 -8
  94. package/dist/plugins/delegations/obligations.d.ts +13 -13
  95. package/dist/plugins/delegations/record.d.ts +11 -10
  96. package/dist/plugins/delegations/request.d.ts +8 -5
  97. package/dist/plugins/delegations/role.d.ts +1 -1
  98. package/dist/plugins/delegations/service.d.ts +9 -8
  99. package/dist/plugins/delegations/{waitBook.d.ts → waitResolver.d.ts} +9 -9
  100. package/dist/plugins/diagnostics/digest.d.ts +1 -1
  101. package/dist/plugins/diagnostics/index.d.ts +1 -1
  102. package/dist/plugins/diagnostics/index.js +1 -1
  103. package/dist/plugins/fileTools/config.d.ts +10 -0
  104. package/dist/plugins/{tools → fileTools}/editFiles.d.ts +16 -27
  105. package/dist/plugins/fileTools/gitDiscovery.d.ts +9 -0
  106. package/dist/plugins/fileTools/index.d.ts +18 -0
  107. package/dist/plugins/fileTools/index.js +1 -0
  108. package/dist/plugins/fileTools/tools.d.ts +6 -0
  109. package/dist/plugins/historyRecall/history.d.ts +1 -1
  110. package/dist/plugins/historyRecall/index.js +1 -1
  111. package/dist/plugins/historyRecall/render.d.ts +1 -1
  112. package/dist/plugins/mcp/catalog.d.ts +1 -1
  113. package/dist/plugins/mcp/index.d.ts +2 -2
  114. package/dist/plugins/mcp/index.js +1 -1
  115. package/dist/plugins/mcp/mount.d.ts +2 -2
  116. package/dist/plugins/mcp/render.d.ts +1 -1
  117. package/dist/plugins/mcp/{tool.d.ts → tools.d.ts} +1 -1
  118. package/dist/plugins/{routeContext.d.ts → routeNotice.d.ts} +2 -2
  119. package/dist/plugins/routeNotice.js +1 -0
  120. package/dist/{sandbox → plugins/sandbox}/absent.d.ts +11 -10
  121. package/dist/{sandbox → plugins/sandbox}/index.d.ts +5 -2
  122. package/dist/plugins/sandbox/index.js +4 -0
  123. package/dist/{sandbox → plugins/sandbox}/mode.d.ts +5 -5
  124. package/dist/plugins/sandbox/policy.d.ts +163 -0
  125. package/dist/{sandbox → plugins/sandbox}/service.d.ts +23 -13
  126. package/dist/plugins/schedules/index.js +3 -3
  127. package/dist/plugins/schedules/record.d.ts +18 -18
  128. package/dist/plugins/schedules/service.d.ts +2 -2
  129. package/dist/plugins/skills/discovery.d.ts +38 -9
  130. package/dist/plugins/skills/index.d.ts +1 -1
  131. package/dist/plugins/skills/index.js +1 -1
  132. package/dist/plugins/subAgents/index.js +1 -1
  133. package/dist/plugins/subAgents/{fork.d.ts → tools.d.ts} +36 -1
  134. package/dist/plugins/threadDirs.d.ts +36 -0
  135. package/dist/plugins/threadDirs.js +1 -0
  136. package/dist/plugins/toolPolicy/index.d.ts +2 -2
  137. package/dist/plugins/toolPolicy/index.js +1 -1
  138. package/dist/plugins/truncateToolOutput.d.ts +14 -10
  139. package/dist/plugins/truncateToolOutput.js +6 -1
  140. package/dist/plugins/usage/index.d.ts +4 -2
  141. package/dist/plugins/usage/index.js +1 -1
  142. package/dist/plugins/usage/tracker.d.ts +1 -1
  143. package/dist/plugins/verify/index.d.ts +7 -55
  144. package/dist/plugins/verify/index.js +6 -1
  145. package/dist/plugins/verify/judgement.d.ts +16 -0
  146. package/dist/plugins/verify/record.d.ts +382 -0
  147. package/dist/plugins/verify/service.d.ts +7 -4
  148. package/dist/plugins/verify/state.d.ts +58 -0
  149. package/dist/plugins/webTools/index.d.ts +34 -0
  150. package/dist/plugins/webTools/index.js +1 -0
  151. package/dist/plugins/workflows/assignment.d.ts +6 -2
  152. package/dist/plugins/workflows/cleanup.d.ts +1 -1
  153. package/dist/plugins/workflows/definition.d.ts +2 -2
  154. package/dist/plugins/workflows/{bindings.d.ts → entryPlan.d.ts} +2 -2
  155. package/dist/plugins/workflows/{providers.d.ts → hostBindings.d.ts} +2 -2
  156. package/dist/plugins/workflows/index.d.ts +4 -4
  157. package/dist/plugins/workflows/index.js +10 -5
  158. package/dist/plugins/workflows/observations.d.ts +3 -3
  159. package/dist/plugins/workflows/participantModels.d.ts +28 -0
  160. package/dist/plugins/workflows/participants.d.ts +2 -2
  161. package/dist/plugins/workflows/policy.d.ts +2 -2
  162. package/dist/plugins/workflows/record.d.ts +51 -65
  163. package/dist/plugins/workflows/routing.d.ts +2 -2
  164. package/dist/plugins/workflows/service.d.ts +24 -24
  165. package/dist/plugins/workflows/{fold.d.ts → state.d.ts} +2 -2
  166. package/dist/plugins/workflows/stopCheck.d.ts +13 -0
  167. package/dist/plugins/workflows/tools.d.ts +13 -0
  168. package/dist/plugins/workflows/view.d.ts +2 -2
  169. package/dist/plugins/{workspaceContext.d.ts → workspaceNotice.d.ts} +5 -7
  170. package/dist/plugins/workspaceNotice.js +1 -0
  171. package/dist/{plugins/providers → providers}/anthropic.d.ts +6 -3
  172. package/dist/{plugins/providers → providers}/anthropicMessages.d.ts +2 -1
  173. package/dist/{plugins/providers → providers}/codex.d.ts +14 -3
  174. package/dist/{plugins/providers → providers}/deepseek.d.ts +6 -2
  175. package/dist/{plugins/providers → providers}/failure.d.ts +1 -1
  176. package/dist/{plugins/providers → providers}/gateway.d.ts +2 -1
  177. package/dist/providers/index.d.ts +18 -0
  178. package/dist/providers/index.js +6 -0
  179. package/dist/{plugins/providers → providers}/openaiChat.d.ts +13 -2
  180. package/dist/{plugins/providers → providers}/openaiResponses.d.ts +12 -3
  181. package/dist/{plugins/providers → providers}/opencodeCopilot.d.ts +2 -2
  182. package/dist/{plugins/providers → providers}/opencodeGo.d.ts +18 -7
  183. package/dist/{plugins/providers → providers}/shared.d.ts +9 -1
  184. package/dist/{plugins/providers → providers}/stream.d.ts +4 -2
  185. package/dist/{models/door.d.ts → records/index.d.ts} +8 -7
  186. package/dist/records/index.js +1 -0
  187. package/dist/{models/wire → records}/journal.d.ts +210 -14
  188. package/dist/{models/wire/primitives.d.ts → records/toolResult.d.ts} +1 -1
  189. package/dist/services/agents.d.ts +26 -1
  190. package/dist/services/confinement/files.d.ts +118 -0
  191. package/dist/services/confinement/service.d.ts +219 -0
  192. package/dist/services/core.d.ts +2 -8
  193. package/dist/{kit/extension.d.ts → services/extensionEvents.d.ts} +5 -4
  194. package/dist/services/journal.d.ts +1 -1
  195. package/dist/services/llm.d.ts +4 -2
  196. package/dist/{kit → services}/modes.d.ts +1 -1
  197. package/dist/services/plugins.d.ts +34 -0
  198. package/dist/services/{preset.d.ts → presets/definition.d.ts} +4 -4
  199. package/dist/services/{presets.d.ts → presets/installations.d.ts} +3 -3
  200. package/dist/services/prompts.d.ts +23 -5
  201. package/dist/services/{threadActivation.d.ts → threads/activation.d.ts} +3 -3
  202. package/dist/services/{admission.d.ts → threads/admission.d.ts} +3 -3
  203. package/dist/services/{birth.d.ts → threads/birth.d.ts} +9 -10
  204. package/dist/services/threads/index.d.ts +14 -0
  205. package/dist/services/{runEvents.d.ts → threads/runEvents.d.ts} +2 -2
  206. package/dist/services/{owner.d.ts → threads/runOwner.d.ts} +5 -4
  207. package/dist/services/{threads.d.ts → threads/service.d.ts} +9 -8
  208. package/dist/services/{thread.d.ts → threads/thread.d.ts} +8 -7
  209. package/dist/services/{threadView.d.ts → threads/view.d.ts} +7 -6
  210. package/dist/services/tools.d.ts +79 -2
  211. package/dist/{loop/opening.d.ts → state/birth.d.ts} +22 -2
  212. package/dist/{loop → state}/chain.d.ts +3 -3
  213. package/dist/state/confirmations.d.ts +64 -0
  214. package/dist/{loop → state}/continuation.d.ts +3 -2
  215. package/dist/{loop → state}/decide.d.ts +10 -2
  216. package/dist/state/dispatches.d.ts +54 -0
  217. package/dist/state/errors.d.ts +26 -0
  218. package/dist/{loop → state}/forks.d.ts +1 -1
  219. package/dist/{loop → state}/holds.d.ts +1 -1
  220. package/dist/{loop → state}/inbox.d.ts +2 -2
  221. package/dist/state/index.d.ts +31 -0
  222. package/dist/state/inputs.d.ts +58 -0
  223. package/dist/state/installations.d.ts +28 -0
  224. package/dist/state/prompt.d.ts +13 -0
  225. package/dist/state/recovery.d.ts +7 -0
  226. package/dist/{loop → state}/replace.d.ts +2 -2
  227. package/dist/{loop → state}/requests.d.ts +3 -3
  228. package/dist/{loop → state}/route.d.ts +10 -2
  229. package/dist/state/summary.d.ts +16 -0
  230. package/dist/{loop → state}/surface.d.ts +3 -3
  231. package/dist/state/surfaceRead.d.ts +20 -0
  232. package/dist/{loop/threadState.d.ts → state/thread.d.ts} +12 -11
  233. package/dist/state/turns.d.ts +87 -0
  234. package/dist/state/waits.d.ts +38 -0
  235. package/dist/{loop → state}/wake.d.ts +1 -1
  236. package/dist/stores/durableObject.js +1 -0
  237. package/dist/{plugins/store → stores}/memory.d.ts +2 -2
  238. package/dist/{plugins/store → stores}/sql.d.ts +2 -2
  239. package/dist/stores/sqlite.js +1 -0
  240. package/dist/sys/environment.d.ts +0 -5
  241. package/dist/sys/git.d.ts +0 -13
  242. package/dist/sys/paths.d.ts +0 -47
  243. package/dist/sys/spawn.d.ts +16 -6
  244. package/dist/testing/clock.d.ts +1 -1
  245. package/dist/testing/fakeLlm.d.ts +4 -2
  246. package/dist/testing/fedLlm.d.ts +3 -1
  247. package/dist/testing/helpers.d.ts +31 -13
  248. package/dist/testing/index.js +1 -1
  249. package/dist/testing/settlement.d.ts +1 -1
  250. package/package.json +36 -28
  251. package/dist/chunks/2O7ZGEIT.js +0 -1
  252. package/dist/chunks/2OSESBIL.js +0 -1
  253. package/dist/chunks/3LQHQRIU.js +0 -6
  254. package/dist/chunks/3QCW4WDJ.js +0 -1
  255. package/dist/chunks/4XVRUSCQ.js +0 -1
  256. package/dist/chunks/6ECI2GGV.js +0 -1
  257. package/dist/chunks/74HKUGRR.js +0 -1
  258. package/dist/chunks/ADHERZLW.js +0 -2
  259. package/dist/chunks/D7E6EWIE.js +0 -3
  260. package/dist/chunks/DRYAN665.js +0 -1
  261. package/dist/chunks/DXFXAYDN.js +0 -17
  262. package/dist/chunks/EGZI4XQX.js +0 -24
  263. package/dist/chunks/ENWFSU27.js +0 -41
  264. package/dist/chunks/G6RXC3AL.js +0 -1
  265. package/dist/chunks/G74AGRAJ.js +0 -15
  266. package/dist/chunks/GQGNVSKB.js +0 -1
  267. package/dist/chunks/IJ2WNMD5.js +0 -7
  268. package/dist/chunks/JPZFKSWT.js +0 -1
  269. package/dist/chunks/KESCTXGO.js +0 -5
  270. package/dist/chunks/L3N4FIEN.js +0 -1
  271. package/dist/chunks/NAOUTU7A.js +0 -4
  272. package/dist/chunks/NDIM7MEW.js +0 -1
  273. package/dist/chunks/O4PPOM5Z.js +0 -2
  274. package/dist/chunks/OVZFGILJ.js +0 -1
  275. package/dist/chunks/P5ZHHOOM.js +0 -6
  276. package/dist/chunks/QMMLQJBS.js +0 -1
  277. package/dist/chunks/RK3VP2Q4.js +0 -3
  278. package/dist/chunks/SGGMBSBA.js +0 -1
  279. package/dist/chunks/TOOIB6J2.js +0 -1
  280. package/dist/chunks/TYTQRLTX.js +0 -1
  281. package/dist/chunks/UCTEU62F.js +0 -1
  282. package/dist/chunks/UD3VJER6.js +0 -1
  283. package/dist/chunks/WUUKTSRT.js +0 -7
  284. package/dist/chunks/X65X4KP5.js +0 -7
  285. package/dist/chunks/YIR5MYGU.js +0 -1
  286. package/dist/chunks/YLNJXQ3Z.js +0 -1
  287. package/dist/kit/claim.d.ts +0 -13
  288. package/dist/kit/drain.d.ts +0 -10
  289. package/dist/kit/grants.d.ts +0 -9
  290. package/dist/kit/scope.d.ts +0 -32
  291. package/dist/kit/service.d.ts +0 -7
  292. package/dist/kit/strategy.d.ts +0 -10
  293. package/dist/kit/tool.d.ts +0 -72
  294. package/dist/llm/door.d.ts +0 -21
  295. package/dist/llm/door.js +0 -1
  296. package/dist/loop/projections.d.ts +0 -307
  297. package/dist/loop/state.d.ts +0 -70
  298. package/dist/loop/summary.d.ts +0 -3
  299. package/dist/models/config/agent.d.ts +0 -18
  300. package/dist/models/config/prompt.d.ts +0 -18
  301. package/dist/models/door.js +0 -1
  302. package/dist/models/index.d.ts +0 -7
  303. package/dist/plugins/commands/foreground.d.ts +0 -4
  304. package/dist/plugins/compaction/preset.d.ts +0 -86
  305. package/dist/plugins/compaction/shared.d.ts +0 -14
  306. package/dist/plugins/delegations/testing.d.ts +0 -16
  307. package/dist/plugins/providers/door.d.ts +0 -61
  308. package/dist/plugins/providers/door.js +0 -1
  309. package/dist/plugins/providers/index.d.ts +0 -6
  310. package/dist/plugins/routeContext.js +0 -1
  311. package/dist/plugins/store/durableObject.js +0 -1
  312. package/dist/plugins/store/sqlite.js +0 -1
  313. package/dist/plugins/subAgents/tool.d.ts +0 -38
  314. package/dist/plugins/tools/index.d.ts +0 -59
  315. package/dist/plugins/tools/index.js +0 -1
  316. package/dist/plugins/verify/facts.d.ts +0 -356
  317. package/dist/plugins/workflows/submit.d.ts +0 -8
  318. package/dist/plugins/workspaceContext.js +0 -1
  319. package/dist/presets/agents.d.ts +0 -7
  320. package/dist/presets/base.d.ts +0 -10
  321. package/dist/presets/index.d.ts +0 -4
  322. package/dist/sandbox/index.js +0 -4
  323. package/dist/sandbox/policy.d.ts +0 -86
  324. package/dist/services/launches.d.ts +0 -104
  325. package/dist/services/threadDirs.d.ts +0 -38
  326. package/dist/testing/sandbox.d.ts +0 -71
  327. /package/dist/chunks/{UKXMCHHT.js → FJLU4UH3.js} +0 -0
  328. /package/dist/chunks/{J5S4URAW.js → HK6ZSONF.js} +0 -0
  329. /package/dist/plugins/ask/{askQuestion.d.ts → tools.d.ts} +0 -0
  330. /package/dist/plugins/delegations/{waits.d.ts → waitContracts.d.ts} +0 -0
  331. /package/dist/plugins/{tools → fileTools}/fsRead.d.ts +0 -0
  332. /package/dist/plugins/{tools → fileTools}/ripgrep.d.ts +0 -0
  333. /package/dist/plugins/{tools → fileTools}/textEdit.d.ts +0 -0
  334. /package/dist/{util → plugins/mcp}/version.d.ts +0 -0
  335. /package/dist/{sandbox → plugins/sandbox}/client.d.ts +0 -0
  336. /package/dist/{sandbox → plugins/sandbox}/files.d.ts +0 -0
  337. /package/dist/{sandbox → plugins/sandbox}/protocol.d.ts +0 -0
  338. /package/dist/{sandbox → plugins/sandbox}/worker.d.ts +0 -0
  339. /package/dist/{sandbox → plugins/sandbox}/worker.js +0 -0
  340. /package/dist/plugins/skills/{tool.d.ts → tools.d.ts} +0 -0
  341. /package/dist/plugins/{tools → webTools}/html.d.ts +0 -0
  342. /package/dist/plugins/{tools → webTools}/network.d.ts +0 -0
  343. /package/dist/plugins/{tools → webTools}/web.d.ts +0 -0
  344. /package/dist/plugins/workflows/{work.d.ts → workStatus.d.ts} +0 -0
  345. /package/dist/{plugins/providers → providers}/codexAuth.d.ts +0 -0
  346. /package/dist/services/{contributions.d.ts → catalogContributions.d.ts} +0 -0
  347. /package/dist/{loop → state}/limits.d.ts +0 -0
  348. /package/dist/{plugins/store → stores}/durableObject.d.ts +0 -0
  349. /package/dist/{plugins/store → stores}/durableObjectConnection.d.ts +0 -0
  350. /package/dist/{plugins/store → stores}/sqlite.d.ts +0 -0
  351. /package/dist/{models → util}/jsonSchema.d.ts +0 -0
  352. /package/dist/{kit → util}/retries.d.ts +0 -0
  353. /package/dist/{kit → util}/timers.d.ts +0 -0
@@ -1,6 +1,11 @@
1
1
  import { Context, Service, type ScopeKey } from '@leuduan/cordis';
2
- import { type AgentSelector } from '../kit/scope.js';
3
- import type { Tool, ToolEntry } from '../loop/index.js';
2
+ import { z } from 'zod';
3
+ import { type AgentSelector } from './agents.js';
4
+ import { type Tool, type ToolEntry, type InvocationContext, type ToolExecutionMode, type WaitRequest } from '../loop/index.js';
5
+ import { type InterruptionPolicy } from '../records/journal.js';
6
+ import { type ParsedToolCall, type ToolCall } from '../llm/primitives.js';
7
+ import { type ToolResult, type ToolResultPayloadInput } from '../records/toolResult.js';
8
+ import type { JsonValue } from '../util/json.js';
4
9
  /**
5
10
  * The tools this process can offer, and who may call them. Live: a tool or a grant lasts
6
11
  * exactly as long as the plugin that registered it, and an agent's reachable set is resolved when a
@@ -39,3 +44,75 @@ export declare class ToolsService extends Service {
39
44
  toolFor(scope: ScopeKey | undefined, agentName: string, toolName: string): ToolEntry | undefined;
40
45
  mayCall(scope: ScopeKey | undefined, agentName: string, toolName: string): boolean;
41
46
  }
47
+ /**
48
+ * Parameters described elsewhere, as JSON schema: advertised as given and handed to `execute`
49
+ * unvalidated, for a tool whose real validator is someone else's, such as an MCP server.
50
+ */
51
+ export type JsonSchemaParameters = {
52
+ readonly jsonSchema: Record<string, JsonValue>;
53
+ };
54
+ type ParametersOf<P> = P extends z.ZodType ? z.output<P> : Record<string, unknown>;
55
+ /** What `execute` returns: a result with `is_error`, `notes` and `metadata` optional, or a wait (`waitFor`). */
56
+ export type ToolReply = ToolResultPayloadInput | WaitRequest;
57
+ /** One tool, as {@link defineTool} takes it. */
58
+ export type ToolDefinition<P extends z.ZodType | JsonSchemaParameters> = {
59
+ /** The name it is registered under, and advertised to the model by. */
60
+ readonly name: string;
61
+ /** One paragraph advertised to the model. */
62
+ readonly description: string;
63
+ /** A zod schema the arguments are validated against and advertised from, or JSON schema. */
64
+ readonly parameters: P;
65
+ /**
66
+ * What a re-dispatch may do with a call that may have begun when its turn was interrupted; see
67
+ * `Tool.onInterrupted`. Every tool says which; there is no default.
68
+ */
69
+ readonly onInterrupted: InterruptionPolicy;
70
+ /** Whether a call may overlap its batch's others; see `Tool.executionMode`. No default either. */
71
+ readonly executionMode: ToolExecutionMode;
72
+ /** Runs one call. A throw becomes an `is_error` result: a tool never fails a turn. */
73
+ execute(parameters: ParametersOf<P>, context: InvocationContext, call: ParsedToolCall): Promise<ToolReply>;
74
+ };
75
+ /**
76
+ * Defines a tool: the one way to write one. Arguments are validated against `parameters` when it is
77
+ * a zod schema, and a validation failure or a throw from `execute` becomes an `is_error` result, so
78
+ * a tool can never crash a turn; the result is timed. A tool that needs configuration closes over it.
79
+ *
80
+ * ```ts
81
+ * const echo = defineTool({
82
+ * name: 'echo',
83
+ * description: 'Repeat the text.',
84
+ * parameters: z.strictObject({ text: z.string() }),
85
+ * onInterrupted: 'rerun',
86
+ * executionMode: 'parallel',
87
+ * execute: async ({ text }) => ({ output: text }),
88
+ * })
89
+ * ```
90
+ */
91
+ export declare function defineTool<P extends z.ZodType | JsonSchemaParameters>(definition: ToolDefinition<P>): Tool;
92
+ /**
93
+ * Offers `tool` in the calling plugin's scope for the life of its fiber, and grants it to the agents
94
+ * `agents` selects when given; without them it is registered for a grant elsewhere, a preset's say.
95
+ * Returns the disposer.
96
+ */
97
+ export declare function registerTool(ctx: Context, tool: Tool, options?: {
98
+ readonly agents?: AgentSelector;
99
+ }): () => void | Promise<void>;
100
+ /**
101
+ * {@link registerTool} for each of `tools`, then a prompt instruction under `tag` for every agent that
102
+ * is granted one of them: the `guidance` of each granted tool, in tool order, and nothing when none
103
+ * is granted or none has any.
104
+ */
105
+ export declare function registerTools(ctx: Context, tools: readonly Tool[], options: {
106
+ readonly tag: string;
107
+ readonly guidance: ReadonlyMap<string, string>;
108
+ }): void;
109
+ /** A tool's result for `call`, its defaults applied and its duration recorded. */
110
+ export declare function toToolResult(call: ToolCall, reply: ToolResultPayloadInput, startedAt: number): ToolResult;
111
+ export { errorResult } from '../loop/index.js';
112
+ /**
113
+ * Grants `toolName` to the agents `agents` selects, for the life of the calling plugin's fiber, or
114
+ * until the returned disposer runs. The selector is stored as given: registries are live, so
115
+ * a grant to `'global'` or `'all'` is matched against each agent when it asks, agents registered
116
+ * later included.
117
+ */
118
+ export declare function grantTool(ctx: Context, toolName: string, agents: AgentSelector): () => void | Promise<void>;
@@ -1,7 +1,8 @@
1
- import type { ModelRoute } from '../llm/index.js';
2
- import type { InitialInstallation, ThreadEnvironment, ThreadOrigin } from '../models/index.js';
1
+ import type { ModelRoute } from '../llm/provider.js';
2
+ import type { InitialInstallation, JournalEvent, Seq, ThreadEnvironment, ThreadFork, ThreadOrigin } from '../records/journal.js';
3
3
  import type { DeepReadonly } from '../util/json.js';
4
4
  import type { RowRef } from './surface.js';
5
+ import type { Reducer } from './thread.js';
5
6
  /**
6
7
  * What a fresh thread is born with, as its spawn row records it: the one value `create` resolves a
7
8
  * birth to, whichever source it came from, and the one a reused thread is compared on. `installations`
@@ -40,3 +41,22 @@ export type ForkOpening = {
40
41
  installations: InitialInstallation[];
41
42
  };
42
43
  };
44
+ export type ThreadRecord = {
45
+ thread_id: string;
46
+ agent_name: string;
47
+ metadata: JournalEvent<'thread/spawned'>['data']['metadata'];
48
+ /** The source thread and row this thread was forked at; `null` unless it is a fork. */
49
+ fork: ThreadFork | null;
50
+ origin: ThreadOrigin | null;
51
+ environment: ThreadEnvironment;
52
+ /** The constraint owners the thread's runs are under. */
53
+ requires: readonly string[];
54
+ /** The `thread/spawned` row. */
55
+ seq: Seq;
56
+ };
57
+ /**
58
+ * A thread's identity, lineage and environment, from its spawn row. A fork's lineage replays its
59
+ * source's spawn row first and its own after it, so the fork's record is its own. The set of all
60
+ * threads is the journal's catalog, not a fold.
61
+ */
62
+ export declare const threadRecord: Reducer<ThreadRecord | null>;
@@ -1,5 +1,5 @@
1
- import type { RunChain, Seq } from '../models/index.js';
2
- import type { Reducer } from './threadState.js';
1
+ import type { RunChain, Seq } from '../records/journal.js';
2
+ import type { Reducer } from './thread.js';
3
3
  /** An inputless cause not yet consumed: the run whose next turn it classifies, `null` once carried. */
4
4
  type InputlessCause = {
5
5
  readonly seq: Seq;
@@ -11,7 +11,7 @@ type InputlessCause = {
11
11
  * {@link ChainState} concern of `threadState`, which a fork starts over.
12
12
  *
13
13
  * The rules, a turn's class and the count of reactive turns in a row, are in
14
- * `docs/lifecycle.md#the-chain`. What only this fold fixes: a later weaker claim never lowers a
14
+ * `docs/guides/threads.md#the-chain`. What only this fold fixes: a later weaker claim never lowers a
15
15
  * class, a request extended while it runs is not a claim, and the count is provisional while a
16
16
  * `reactive` turn is open and final at its `turn/end`, by the class it ended with.
17
17
  */
@@ -0,0 +1,64 @@
1
+ import type { JournalEvent, Seq } from '../records/journal.js';
2
+ import type { ReadonlyState } from '../util/foldState.js';
3
+ import type { ParsedToolCall } from '../llm/primitives.js';
4
+ import type { Reducer, ThreadState } from './thread.js';
5
+ import { type WaitEntry } from './waits.js';
6
+ export type ConfirmationState = {
7
+ request_id: string;
8
+ thread_id: string;
9
+ /** The exact model `tool/call` or runtime `execution/requested` row being approved. */
10
+ target: JournalEvent<'confirm/requested'>['data']['target'];
11
+ tool_call: ParsedToolCall;
12
+ reason: string;
13
+ resolution: {
14
+ approved: boolean;
15
+ rejection_message: string | null;
16
+ } | null;
17
+ };
18
+ /**
19
+ * A thread's confirmation requests and their answers, keyed by request id. Thread-scoped: an answer
20
+ * is written on the thread that asked, so a thread's confirmations are a function of its own rows.
21
+ * A fork starts with none: a fork is never cut with a request still open, and an inherited answer
22
+ * belongs to a call the source already finished.
23
+ */
24
+ export declare const confirmations: Reducer<Map<string, ConfirmationState>>;
25
+ /** One runtime-owned operation and its authorization/result, reconstructed without redispatch. */
26
+ export type RuntimeExecution = {
27
+ seq: Seq;
28
+ request: JournalEvent<'execution/requested'>['data'];
29
+ authorization: {
30
+ seq: Seq;
31
+ data: JournalEvent<'execution/authorization'>['data'];
32
+ } | null;
33
+ result: {
34
+ seq: Seq;
35
+ value: JournalEvent<'execution/result'>['data']['result'];
36
+ } | null;
37
+ };
38
+ export declare const executions: Reducer<Map<Seq, RuntimeExecution>>;
39
+ /** Requests still waiting on the user on one thread. */
40
+ export declare const outstandingConfirmations: (state: ReadonlyMap<string, ReadonlyState<ConfirmationState>>, threadId: string) => ReadonlyState<ConfirmationState>[];
41
+ /**
42
+ * Model dispatches held by a pending confirmation or unresolved wait, by durable sequence.
43
+ * These holds survive turns: dispatching again before the answer or value would only raise a
44
+ * second request, or declare the wait twice.
45
+ */
46
+ export declare const parkedCallSeqs: (confirmationState: ReadonlyMap<string, ReadonlyState<ConfirmationState>>, waitState: ReadonlyMap<Seq, WaitEntry>, threadId: string) => Set<Seq>;
47
+ /**
48
+ * The confirmation of one durable dispatch, pending or answered. Model and runtime dispatch share
49
+ * this lookup; a provider's call ID, request ID or source citation never grants approval authority.
50
+ */
51
+ export declare const confirmationFor: (state: ReadonlyMap<string, ReadonlyState<ConfirmationState>>, dispatch: {
52
+ threadId: string;
53
+ target: ConfirmationState["target"];
54
+ }) => ReadonlyState<ConfirmationState> | undefined;
55
+ /** The thread's latest `confirm/resolved` row, or `null`: what tells a parked caller an answer landed under it. */
56
+ export declare const lastAnswer: Reducer<Seq | null>;
57
+ /**
58
+ * Confirmations on `threadId` whose call has no result yet and was not rejected: still waiting on the
59
+ * user, or approved. An approval lasts until the call's result: the call runs at the next turn, and
60
+ * one that waits or is cut off runs again on the same approval, against whatever tool answers to its
61
+ * name by then. Runtime approval belongs to its pending candidate; once that candidate is rejected
62
+ * or superseded it no longer blocks configuration. Unknown command cleanup is accounted separately.
63
+ */
64
+ export declare function unfinishedConfirmations(state: ReadonlyState<Pick<ThreadState, 'confirmations' | 'executions' | 'answerCheck' | 'dispatchedCalls'>>, threadId: string): ReadonlyState<ConfirmationState>[];
@@ -1,8 +1,9 @@
1
- import type { CancelIntent, InterruptionCause, JsonValue, RunOutcomeKind, RunSettledReason, Seq, TurnEndReason } from '../models/index.js';
1
+ import type { CancelIntent, InterruptionCause, RunOutcomeKind, RunSettledReason, Seq, TurnEndReason } from '../records/journal.js';
2
+ import type { JsonValue } from '../util/json.js';
2
3
  import { type DeepReadonly } from '../util/json.js';
3
4
  import type { DerivedHold, Hold } from './holds.js';
4
5
  import type { PendingRun } from './requests.js';
5
- import type { ThreadState } from './threadState.js';
6
+ import type { ThreadState } from './thread.js';
6
7
  /**
7
8
  * What a registered constraint says of a thread's pending request: `allow`; `hold` with why (`reason`,
8
9
  * in words) and, optionally, a machine-readable `code` and `data`, until the feature calls `changed`;
@@ -1,6 +1,7 @@
1
- import type { QueuedInput, Seq, TurnEndReason } from '../models/index.js';
2
- import type { ToolCall } from '../llm/index.js';
1
+ import { type QueuedInput, type Seq, type TurnEndReason, type InboxTarget } from '../records/journal.js';
2
+ import type { ToolCall } from '../llm/primitives.js';
3
3
  import type { TurnLimits } from './limits.js';
4
+ import type { Journal } from '../journal/index.js';
4
5
  /**
5
6
  * What one thread looks like at a decision point. Not the public `ThreadView` read.
6
7
  *
@@ -62,3 +63,10 @@ export type Action =
62
63
  export declare function nextAction(view: DecisionView, limits: TurnLimits): Action;
63
64
  /** Whether there is anything to do at all — the same decision, asked as a question. */
64
65
  export declare const hasWork: (view: DecisionView, limits: TurnLimits) => boolean;
66
+ /**
67
+ * A journal view, usable without constructing an execution runtime or activating plugins.
68
+ * `sentBack` says a stop check sent back the answer of a turn that opened by answering calls, so
69
+ * input waiting for a turn joins it batch by batch (`Inbox.peek`).
70
+ */
71
+ export declare function decisionView(journal: Journal, threadId: string, target: InboxTarget, step: number, turn: number, sentBack?: boolean): DecisionView;
72
+ export declare function hasThreadWork(journal: Journal, threadId: string, limits: TurnLimits): boolean;
@@ -0,0 +1,54 @@
1
+ import type { InterruptionPolicy, JournalEvent, Seq } from '../records/journal.js';
2
+ import type { DeepReadonly } from '../util/json.js';
3
+ import type { ConversationMessage, ToolCall } from '../llm/primitives.js';
4
+ import type { Reducer } from './thread.js';
5
+ import { type WaitEntry } from './waits.js';
6
+ /**
7
+ * Calls dispatched and not yet answered, and the row that recorded the dispatch.
8
+ *
9
+ * Bookkeeping, not truth: what a turn still owes answers for is {@link unansweredToolCalls}, read
10
+ * off the conversation. This exists so a re-dispatched call can cite its original `tool/call` rather
11
+ * than recording a second one.
12
+ */
13
+ export declare const dispatchedCalls: Reducer<Map<string, Seq>>;
14
+ /** One dispatch attempt of a call: its `tool/authorization` row, and what became of it. */
15
+ export type DispatchAttempt = {
16
+ /** The `tool/authorization` row: the attempt itself. */
17
+ seq: Seq;
18
+ /** The `tool/call` row the attempt dispatched. */
19
+ call_seq: Seq;
20
+ turn: number;
21
+ decision: JournalEvent<'tool/authorization'>['data']['decision'];
22
+ /** What the tool declared, at this attempt, a re-dispatch may do if the attempt is interrupted. */
23
+ policy: InterruptionPolicy;
24
+ };
25
+ /**
26
+ * The latest dispatch attempt of every call that has no result yet, by call id.
27
+ *
28
+ * An attempt is written immediately before the tool is invoked, so an allowed attempt with no
29
+ * result, from a turn that has since closed, of a call that did not suspend, is a call the process
30
+ * was cut off in: the tool may have begun. {@link abandonedAttempt} reads that; the policy recorded with the attempt
31
+ * decides what a re-dispatch may do. A new `tool/call` under a reused provider id starts a new call
32
+ * with no attempt; a result clears the call's attempt.
33
+ */
34
+ export declare const dispatchAttempts: Reducer<Map<string, DispatchAttempt>>;
35
+ /**
36
+ * The attempt of `callId` that was abandoned, if any: allowed, so the tool may have begun;
37
+ * unanswered; of the `tool/call` row being dispatched now, not of an earlier call that reused the
38
+ * provider's id; of a call that is not suspended (`waits`), since a waiting call returned on purpose
39
+ * and one whose wait resolved is dispatched again from its recorded value, however often a crash
40
+ * cuts that dispatch off; and from a turn before `currentTurn`, so the process that made it is gone —
41
+ * every earlier turn is closed before a new one opens. Read before a new attempt is recorded, so the
42
+ * judgment is about the attempt that was cut off.
43
+ */
44
+ export declare function abandonedAttempt(state: ReadonlyMap<string, DispatchAttempt>, waits: ReadonlyMap<Seq, WaitEntry>, callId: string, callSeq: Seq, currentTurn: number): DispatchAttempt | undefined;
45
+ /**
46
+ * Tool calls on the last assistant message that have no result yet.
47
+ *
48
+ * Derived from the conversation, not from `tool/call` rows, because the conversation is what a
49
+ * provider validates: a message holding calls must be followed by a result for each one. Calls are
50
+ * recorded one row at a time, so a hard kill part-way through that burst leaves a thread with fewer
51
+ * `tool/call` rows than the model asked for — nothing "pending", and a conversation nothing could
52
+ * answer. Reading the assistant message instead makes the two agree by construction.
53
+ */
54
+ export declare function unansweredToolCalls(messages: readonly DeepReadonly<ConversationMessage>[]): DeepReadonly<ToolCall>[];
@@ -0,0 +1,26 @@
1
+ import type { ReplacementRule } from './surface.js';
2
+ /** No thread has this id. */
3
+ export declare class UnknownThreadError extends ReferenceError {
4
+ readonly threadId: string;
5
+ constructor(threadId: string);
6
+ }
7
+ /** A fork was asked for at a row it cannot be cut at; nothing was appended. */
8
+ export declare class ForkCutError extends Error {
9
+ readonly threadId: string;
10
+ readonly seq: number;
11
+ constructor(threadId: string, seq: number, reason: string);
12
+ }
13
+ /**
14
+ * A replacement `replaceSurface` refused: it breaks a rule of the surface it would land on (see
15
+ * `judgeReplacement`). Nothing of its group was recorded. Distinct from any other failure, so a
16
+ * strategy can tell a plan the surface refused from a journal that could not write.
17
+ */
18
+ export declare class ReplacementRefusedError extends Error {
19
+ readonly index: number;
20
+ readonly rule: ReplacementRule;
21
+ constructor(message: string,
22
+ /** The refused replacement's position in the group it was offered with. */
23
+ index: number,
24
+ /** The surface rule it breaks. */
25
+ rule: ReplacementRule);
26
+ }
@@ -1,5 +1,5 @@
1
1
  import type { Journal } from '../journal/index.js';
2
- import type { Seq, TurnEndReason } from '../models/index.js';
2
+ import type { Seq, TurnEndReason } from '../records/journal.js';
3
3
  import type { RowRef } from './surface.js';
4
4
  /**
5
5
  * Where forks may be cut, and the lookups that find such a row from a turn or a reply. Journal
@@ -1,4 +1,4 @@
1
- import type { Seq } from '../models/index.js';
1
+ import type { Seq } from '../records/journal.js';
2
2
  import type { ReadonlyState } from '../util/foldState.js';
3
3
  import { type ReadonlyJsonValue } from '../util/json.js';
4
4
  import type { RequestsState } from './requests.js';
@@ -1,8 +1,8 @@
1
- import type { ExtensionRecord, InboxTarget, QueuedInput, Seq, ThreadInput } from '../models/index.js';
1
+ import type { ExtensionRecord, InboxTarget, QueuedInput, Seq, ThreadInput } from '../records/journal.js';
2
2
  import type { AppendEntry, Journal } from '../journal/index.js';
3
3
  import type { DeepReadonly, ReadonlyJsonValue } from '../util/json.js';
4
4
  import type { RouteAuthority } from './route.js';
5
- import type { FreshOpening, ForkOpening } from './opening.js';
5
+ import type { FreshOpening, ForkOpening } from './birth.js';
6
6
  import { type Wake } from './wake.js';
7
7
  /**
8
8
  * Why a write-time callback refused its write, as data a host or plugin can act on without parsing
@@ -0,0 +1,31 @@
1
+ /**
2
+ * What the rest of the package may use of recorded state: the folds of a thread's rows, the queries
3
+ * over them, and the writes that need no activation (the inbox, closing an interrupted turn, the
4
+ * surface replacement writer). Nothing here runs a turn or imports Cordis; the loop executes against
5
+ * these and the services read them. The journal substrate itself is `journal/`, imported directly.
6
+ */
7
+ export * from './thread.js';
8
+ export * from './turns.js';
9
+ export * from './dispatches.js';
10
+ export * from './waits.js';
11
+ export * from './confirmations.js';
12
+ export * from './prompt.js';
13
+ export * from './inputs.js';
14
+ export * from './installations.js';
15
+ export * from './surface.js';
16
+ export * from './requests.js';
17
+ export * from './holds.js';
18
+ export * from './chain.js';
19
+ export * from './route.js';
20
+ export * from './errors.js';
21
+ export * from './limits.js';
22
+ export * from './birth.js';
23
+ export * from './continuation.js';
24
+ export * from './decide.js';
25
+ export * from './forks.js';
26
+ export * from './inbox.js';
27
+ export * from './recovery.js';
28
+ export * from './replace.js';
29
+ export * from './surfaceRead.js';
30
+ export * from './summary.js';
31
+ export * from './wake.js';
@@ -0,0 +1,58 @@
1
+ import type { InboxTarget, QueuedInput, Seq } from '../records/journal.js';
2
+ import type { ReadonlyState } from '../util/foldState.js';
3
+ import type { Reducer, ThreadState } from './thread.js';
4
+ export type InboxState = Record<InboxTarget, QueuedInput[]>;
5
+ /**
6
+ * Input waiting for a turn or a step boundary. Durable, so a crash does not lose a queued message.
7
+ * A fork starts with nothing queued: its source's queued input is not the fork's.
8
+ */
9
+ export declare const inbox: Reducer<InboxState>;
10
+ /** Where one input id's life is recorded: the row that queued it, and the step's row that claimed it. */
11
+ export type InputRows = {
12
+ readonly queuedAt: Seq;
13
+ readonly claimedAt: Seq | null;
14
+ };
15
+ /**
16
+ * Every input id this thread was ever handed: the row that queued it and, once a step took it, the
17
+ * `input/message` that claimed it. Never forgets: this is what makes `send` with an explicit id
18
+ * idempotent across a re-dispatch or a restart, and why a withdrawn or cancelled id stays
19
+ * spent. A fork starts over: the ids its source was handed are the source's.
20
+ */
21
+ export declare const inputs: Reducer<Map<string, InputRows>>;
22
+ /**
23
+ * What became of the input id a thread was handed: `unknown` when it never was; `queued` while it
24
+ * waits, for `target`; `claimed` once a step took it; `discarded` when it left the queue unclaimed,
25
+ * withdrawn or cleared by a cancel. Each names the row that queued it, and a claim the
26
+ * `input/message` that took it. A discarded or claimed id stays spent: it is never queued again.
27
+ */
28
+ export type InputFate = {
29
+ readonly state: 'unknown';
30
+ } | {
31
+ readonly state: 'queued';
32
+ readonly queuedAt: Seq;
33
+ readonly target: InboxTarget;
34
+ } | {
35
+ readonly state: 'claimed';
36
+ readonly queuedAt: Seq;
37
+ readonly claimedAt: Seq;
38
+ } | {
39
+ readonly state: 'discarded';
40
+ readonly queuedAt: Seq;
41
+ };
42
+ /**
43
+ * The fate of input `id` from a thread's state: the one answer to "what became of input X", read
44
+ * inside a write or a contributor from the state the journal folds, or through `ThreadView.input`.
45
+ * A fork's own ids only: its source's are the source's.
46
+ */
47
+ export declare function inputFate(state: ReadonlyState<Pick<ThreadState, 'inputs' | 'inbox'>>, id: string): InputFate;
48
+ /**
49
+ * Whether a fork has yet to claim the task it was created with. A fork cut at a request inherits a
50
+ * conversation that ends on input its source is answering. Created to regenerate that answer, the
51
+ * fork owes it; created with a task, it owes only the task. So a task discarded before it was
52
+ * claimed — by `cancel()` — leaves the fork with nothing to do, rather than answering its source's
53
+ * request. Any input the fork records settles it.
54
+ */
55
+ export declare const forkTask: Reducer<{
56
+ spawnSeq: Seq | null;
57
+ unclaimed: boolean;
58
+ }>;
@@ -0,0 +1,28 @@
1
+ import type { InstallationLifetime } from '../records/journal.js';
2
+ import type { JsonValue } from '../util/json.js';
3
+ import type { Reducer } from './thread.js';
4
+ /** One installation a thread holds, as its folds read it. */
5
+ export type InstallationRecord = {
6
+ readonly installationId: string;
7
+ readonly presetId: string;
8
+ /** The validated configuration, defaults included: exactly what `setup` receives. */
9
+ readonly config: JsonValue;
10
+ /**
11
+ * `defining` for one recorded as such in its thread's spawn row, on this thread or on the one a
12
+ * fork inherited it from, which cannot be removed; `configurable` for any other, one applied
13
+ * later included.
14
+ */
15
+ readonly lifetime: InstallationLifetime;
16
+ };
17
+ /** A thread's installations: the current ones in application order, and every id it ever used. */
18
+ export type InstallationsState = {
19
+ readonly current: Map<string, InstallationRecord>;
20
+ readonly used: Set<string>;
21
+ };
22
+ /**
23
+ * The preset installations that define a thread's plugins. A fork inherits its source's
24
+ * installations and reserved ids at the cut: its own spawn row carries none, and the source's spawn
25
+ * row, which it folds through lineage, keeps a defining installation defining on every fork.
26
+ * Installations never move, so application order is also the order they are restored in.
27
+ */
28
+ export declare const installations: Reducer<InstallationsState>;
@@ -0,0 +1,13 @@
1
+ import type { ToolSpec } from '../llm/primitives.js';
2
+ import type { PromptBlock } from '../llm/prompt.js';
3
+ import type { Reducer } from './thread.js';
4
+ /**
5
+ * The system prompt a thread sends: the latest `thread/prompt` row, or none yet. A fork inherits
6
+ * it and never renders its own, so it sends its source's exact prompt.
7
+ */
8
+ export declare const threadPrompt: Reducer<PromptBlock[] | null>;
9
+ /**
10
+ * The tool specifications a thread's requests send: the latest `thread/tools` row, or none before
11
+ * its first request. Read at a request's seq, what that request sent. A fork inherits it.
12
+ */
13
+ export declare const threadTools: Reducer<readonly ToolSpec[] | null>;
@@ -0,0 +1,7 @@
1
+ import type { Journal } from '../journal/index.js';
2
+ import type { TurnLimits } from './limits.js';
3
+ /**
4
+ * Close a process-interrupted turn from journal state, including when no new execution is needed.
5
+ * Decided inside the write, so a turn something else closed meanwhile is not closed twice.
6
+ */
7
+ export declare function closeInterruptedTurn(journal: Journal, threadId: string, limits: TurnLimits): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  import type { Journal } from '../journal/index.js';
2
- import type { JournalEventInput, ReplacementTrigger, Seq } from '../models/index.js';
3
- import type { RowRef } from './surface.js';
2
+ import { type JournalEventInput, type ReplacementTrigger, type Seq } from '../records/journal.js';
3
+ import { type RowRef } from './surface.js';
4
4
  type ReplacedData = JournalEventInput['surface/replaced'];
5
5
  type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
6
6
  /**
@@ -1,6 +1,6 @@
1
- import type { CancelIntent, RunChain, RunOutcomeKind, RunSettledReason, Seq } from '../models/index.js';
2
- import type { InputFate } from './state.js';
3
- import type { Reducer } from './threadState.js';
1
+ import type { CancelIntent, RunChain, RunOutcomeKind, RunSettledReason, Seq } from '../records/journal.js';
2
+ import type { InputFate } from './inputs.js';
3
+ import type { Reducer } from './thread.js';
4
4
  /** One `run/cause` row as the request fold keeps it. */
5
5
  export type RunCause = {
6
6
  readonly seq: Seq;
@@ -1,5 +1,6 @@
1
- import type { ModelRoute } from '../llm/index.js';
2
- import type { ModelSelection } from './runtime.js';
1
+ import type { ModelRoute } from '../llm/provider.js';
2
+ import type { ModelSelection } from '../llm/provider.js';
3
+ import type { Reducer } from './thread.js';
3
4
  /**
4
5
  * What a wake says about the route it runs on, checked by core inside the write that records it:
5
6
  * `expect`, the route the caller was shown and did not change; `select`, the route to run on,
@@ -51,3 +52,10 @@ export declare const sameRoute: (a: ModelRoute, b: ModelRoute) => boolean;
51
52
  * which refuses the whole write.
52
53
  */
53
54
  export declare function statedRoute(threadId: string, statement: RouteStatement, routes: RouteAuthority): ModelRoute | null;
55
+ /**
56
+ * The thread's route: the one its spawn row was born with, replaced by each cause that changed it.
57
+ * A lineage fold: a fork, born with none of its own, goes on with the route its inherited rows fold
58
+ * to at the cut, which keeps it on the model whose cache holds its history. Nothing else changes it:
59
+ * not turns, settlements, cancels or compaction. `null` only before a spawn row, which no thread lacks.
60
+ */
61
+ export declare const threadRoute: Reducer<ModelRoute | null>;
@@ -0,0 +1,16 @@
1
+ import type { Journal, ThreadSummaryCore } from '../journal/index.js';
2
+ import type { TurnLimits } from './limits.js';
3
+ /**
4
+ * A thread's catalog summary, from its folds as they stand: the spawn row's identity, how its last
5
+ * turn ended, the thread's route, whether a turn is open, whether a run would find
6
+ * work, and where its run requests stand — the pending one the run owner picks its candidates by at
7
+ * `threads.start`, from the catalog, so only those are loaded and run; the latest settlement and person's cancel the holds
8
+ * derive from; and the latest answer, which tells a parked caller an answer landed under it. The confirmations it waits on and the calls it
9
+ * suspended are listed as descriptors, enough to find them without the thread's rows; the full
10
+ * requests and dependencies come from the thread once it is loaded.
11
+ *
12
+ * Registered with the journal by the journal plugin, which is how `journal/` never learns what a
13
+ * turn is. Everything here is a thread-scoped fold, so the summary is a function of the thread's
14
+ * own lineage and nothing else.
15
+ */
16
+ export declare function summarizeThread(journal: Journal, threadId: string, limits: TurnLimits): ThreadSummaryCore;
@@ -1,7 +1,7 @@
1
1
  import type { Journal } from '../journal/index.js';
2
- import type { Reducer } from './threadState.js';
3
- import type { ConversationMessage } from '../llm/index.js';
4
- import type { JournalEvent, ReplacementKind, Seq, SurfaceEventType } from '../models/index.js';
2
+ import type { Reducer } from './thread.js';
3
+ import type { ConversationMessage } from '../llm/primitives.js';
4
+ import type { JournalEvent, ReplacementKind, Seq, SurfaceEventType } from '../records/journal.js';
5
5
  import type { ReadonlyState } from '../util/foldState.js';
6
6
  /** A journal row, named by the thread that owns it. Inherited rows belong to a fork's source lineage. */
7
7
  export type RowRef = {
@@ -0,0 +1,20 @@
1
+ import type { Journal, PluginJournal } from '../journal/index.js';
2
+ import type { ConversationMessage } from '../llm/primitives.js';
3
+ import type { ReadonlyState } from '../util/foldState.js';
4
+ import { type ReplacementRefusal, type RowRef } from './surface.js';
5
+ /**
6
+ * The first replacement `threadId`'s surface refused, or `null`: a thread that has one carries
7
+ * history no execution may continue from, which every entry that executes checks.
8
+ */
9
+ export declare function refusedReplacement(journal: Pick<Journal, 'state'>, threadId: string): {
10
+ readonly row: RowRef;
11
+ readonly refusal: ReplacementRefusal;
12
+ } | null;
13
+ /**
14
+ * The last thing the model said on a thread, if anything: the message of the last
15
+ * `assistant/message` row on its lineage that the stream did not cut off. Found through the rows
16
+ * behind the surface, not by role, so an assistant-role stand-in is never reported as the model's
17
+ * last word; a reply a replacement took off the surface is still found, through the rows its
18
+ * stand-in replaced.
19
+ */
20
+ export declare function lastAssistantMessage(journal: Pick<PluginJournal, 'eventAt' | 'state'>, threadId: string): ReadonlyState<ConversationMessage> | null;