@downcity/agent 1.1.430 → 1.1.438

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 (488) hide show
  1. package/README.md +13 -11
  2. package/bin/agent/Agent.d.ts +3 -3
  3. package/bin/agent/Agent.d.ts.map +1 -1
  4. package/bin/agent/Agent.js +38 -8
  5. package/bin/agent/Agent.js.map +1 -1
  6. package/bin/agent/AgentInstructions.js +2 -2
  7. package/bin/agent/AgentInstructions.js.map +1 -1
  8. package/bin/agent/AgentMemoryStorage.d.ts.map +1 -1
  9. package/bin/agent/AgentMemoryStorage.js +1 -0
  10. package/bin/agent/AgentMemoryStorage.js.map +1 -1
  11. package/bin/agent/AgentSessions.d.ts +5 -1
  12. package/bin/agent/AgentSessions.d.ts.map +1 -1
  13. package/bin/agent/AgentSessions.js +17 -9
  14. package/bin/agent/AgentSessions.js.map +1 -1
  15. package/bin/executor/Executor.d.ts +9 -27
  16. package/bin/executor/Executor.d.ts.map +1 -1
  17. package/bin/executor/Executor.js +32 -127
  18. package/bin/executor/Executor.js.map +1 -1
  19. package/bin/executor/composer/system/default/SystemPromptAssets.d.ts +0 -4
  20. package/bin/executor/composer/system/default/SystemPromptAssets.d.ts.map +1 -1
  21. package/bin/executor/composer/system/default/SystemPromptAssets.js +0 -5
  22. package/bin/executor/composer/system/default/SystemPromptAssets.js.map +1 -1
  23. package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts +3 -9
  24. package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts.map +1 -1
  25. package/bin/executor/core-engine/CoreEngineContextCompaction.js +4 -130
  26. package/bin/executor/core-engine/CoreEngineContextCompaction.js.map +1 -1
  27. package/bin/executor/core-engine/CoreEngineRunner.d.ts +3 -30
  28. package/bin/executor/core-engine/CoreEngineRunner.d.ts.map +1 -1
  29. package/bin/executor/core-engine/CoreEngineRunner.js +38 -194
  30. package/bin/executor/core-engine/CoreEngineRunner.js.map +1 -1
  31. package/bin/executor/core-engine/CoreEngineSignals.d.ts +6 -6
  32. package/bin/executor/core-engine/CoreEngineSignals.d.ts.map +1 -1
  33. package/bin/executor/core-engine/CoreEngineSignals.js +1 -1
  34. package/bin/executor/core-engine/CoreEngineSignals.js.map +1 -1
  35. package/bin/executor/messages/SessionAttachmentMapper.d.ts +2 -2
  36. package/bin/executor/messages/SessionAttachmentMapper.d.ts.map +1 -1
  37. package/bin/executor/messages/SessionAttachmentMapper.js.map +1 -1
  38. package/bin/executor/messages/SessionMessageLog.d.ts +3 -3
  39. package/bin/executor/messages/SessionMessageLog.d.ts.map +1 -1
  40. package/bin/executor/messages/SessionMessageLog.js.map +1 -1
  41. package/bin/executor/messages/SessionModelMessages.d.ts +0 -3
  42. package/bin/executor/messages/SessionModelMessages.d.ts.map +1 -1
  43. package/bin/executor/messages/SessionModelMessages.js +80 -97
  44. package/bin/executor/messages/SessionModelMessages.js.map +1 -1
  45. package/bin/executor/model/ModelStepRunner.d.ts +2 -6
  46. package/bin/executor/model/ModelStepRunner.d.ts.map +1 -1
  47. package/bin/executor/model/ModelStepRunner.js +0 -28
  48. package/bin/executor/model/ModelStepRunner.js.map +1 -1
  49. package/bin/executor/services/ExecutorRecoveryPolicy.d.ts +7 -64
  50. package/bin/executor/services/ExecutorRecoveryPolicy.d.ts.map +1 -1
  51. package/bin/executor/services/ExecutorRecoveryPolicy.js +29 -45
  52. package/bin/executor/services/ExecutorRecoveryPolicy.js.map +1 -1
  53. package/bin/executor/types/SessionHistoryMeta.d.ts +1 -3
  54. package/bin/executor/types/SessionHistoryMeta.d.ts.map +1 -1
  55. package/bin/executor/types/SessionHistoryMeta.js +1 -1
  56. package/bin/index.d.ts +9 -13
  57. package/bin/index.d.ts.map +1 -1
  58. package/bin/index.js +2 -4
  59. package/bin/index.js.map +1 -1
  60. package/bin/session/DefaultSessionComposer.d.ts +13 -7
  61. package/bin/session/DefaultSessionComposer.d.ts.map +1 -1
  62. package/bin/session/DefaultSessionComposer.js +26 -21
  63. package/bin/session/DefaultSessionComposer.js.map +1 -1
  64. package/bin/session/Session.d.ts +12 -19
  65. package/bin/session/Session.d.ts.map +1 -1
  66. package/bin/session/Session.js +70 -202
  67. package/bin/session/Session.js.map +1 -1
  68. package/bin/session/SessionComposition.d.ts +0 -2
  69. package/bin/session/SessionComposition.d.ts.map +1 -1
  70. package/bin/session/SessionComposition.js +30 -54
  71. package/bin/session/SessionComposition.js.map +1 -1
  72. package/bin/session/SessionLoop.d.ts +17 -16
  73. package/bin/session/SessionLoop.d.ts.map +1 -1
  74. package/bin/session/SessionLoop.js +217 -320
  75. package/bin/session/SessionLoop.js.map +1 -1
  76. package/bin/session/SessionMessages.d.ts +52 -44
  77. package/bin/session/SessionMessages.d.ts.map +1 -1
  78. package/bin/session/SessionMessages.js +285 -187
  79. package/bin/session/SessionMessages.js.map +1 -1
  80. package/bin/session/SessionQueue.d.ts +1 -1
  81. package/bin/session/SessionQueue.d.ts.map +1 -1
  82. package/bin/session/SessionQueue.js +2 -1
  83. package/bin/session/SessionQueue.js.map +1 -1
  84. package/bin/session/SessionState.d.ts +3 -7
  85. package/bin/session/SessionState.d.ts.map +1 -1
  86. package/bin/session/SessionState.js +50 -89
  87. package/bin/session/SessionState.js.map +1 -1
  88. package/bin/session/SessionSystem.d.ts +5 -1
  89. package/bin/session/SessionSystem.d.ts.map +1 -1
  90. package/bin/session/SessionSystem.js +40 -0
  91. package/bin/session/SessionSystem.js.map +1 -1
  92. package/bin/session/SessionTitle.d.ts +3 -3
  93. package/bin/session/SessionTitle.d.ts.map +1 -1
  94. package/bin/session/SessionTitle.js +2 -2
  95. package/bin/session/browse/Browse.d.ts +32 -46
  96. package/bin/session/browse/Browse.d.ts.map +1 -1
  97. package/bin/session/browse/Browse.js +104 -360
  98. package/bin/session/browse/Browse.js.map +1 -1
  99. package/bin/session/browse/SessionMessageTimeline.d.ts.map +1 -1
  100. package/bin/session/browse/SessionMessageTimeline.js +61 -37
  101. package/bin/session/browse/SessionMessageTimeline.js.map +1 -1
  102. package/bin/session/composer/policies/AdaptivePartContextPolicy.d.ts +35 -0
  103. package/bin/session/composer/policies/AdaptivePartContextPolicy.d.ts.map +1 -0
  104. package/bin/session/composer/policies/AdaptivePartContextPolicy.js +256 -0
  105. package/bin/session/composer/policies/AdaptivePartContextPolicy.js.map +1 -0
  106. package/bin/session/composer/policies/FullHistoryContextPolicy.d.ts +24 -0
  107. package/bin/session/composer/policies/FullHistoryContextPolicy.d.ts.map +1 -0
  108. package/bin/session/composer/policies/FullHistoryContextPolicy.js +31 -0
  109. package/bin/session/composer/policies/FullHistoryContextPolicy.js.map +1 -0
  110. package/bin/session/composer/policies/SessionSummaryPrompts.d.ts +16 -0
  111. package/bin/session/composer/policies/SessionSummaryPrompts.d.ts.map +1 -0
  112. package/bin/session/composer/policies/SessionSummaryPrompts.js +32 -0
  113. package/bin/session/composer/policies/SessionSummaryPrompts.js.map +1 -0
  114. package/bin/session/execution/SessionAssistantOutputAdapter.d.ts +15 -4
  115. package/bin/session/execution/SessionAssistantOutputAdapter.d.ts.map +1 -1
  116. package/bin/session/execution/SessionAssistantOutputAdapter.js +7 -3
  117. package/bin/session/execution/SessionAssistantOutputAdapter.js.map +1 -1
  118. package/bin/session/messages/{SessionActionMessageWriter.d.ts → SessionAgentActionPartWriter.d.ts} +7 -7
  119. package/bin/session/messages/SessionAgentActionPartWriter.d.ts.map +1 -0
  120. package/bin/session/messages/{SessionActionMessageWriter.js → SessionAgentActionPartWriter.js} +7 -7
  121. package/bin/session/messages/SessionAgentActionPartWriter.js.map +1 -0
  122. package/bin/session/messages/SessionAgentContent.d.ts +10 -0
  123. package/bin/session/messages/SessionAgentContent.d.ts.map +1 -0
  124. package/bin/session/messages/SessionAgentContent.js +44 -0
  125. package/bin/session/messages/SessionAgentContent.js.map +1 -0
  126. package/bin/session/messages/SessionAgentMessageState.d.ts +50 -0
  127. package/bin/session/messages/SessionAgentMessageState.d.ts.map +1 -0
  128. package/bin/session/messages/SessionAgentMessageState.js +283 -0
  129. package/bin/session/messages/SessionAgentMessageState.js.map +1 -0
  130. package/bin/session/messages/{SessionAssistantMessageWriter.d.ts → SessionAgentMessageWriter.d.ts} +22 -8
  131. package/bin/session/messages/SessionAgentMessageWriter.d.ts.map +1 -0
  132. package/bin/session/messages/{SessionAssistantMessageWriter.js → SessionAgentMessageWriter.js} +54 -42
  133. package/bin/session/messages/SessionAgentMessageWriter.js.map +1 -0
  134. package/bin/session/messages/SessionForkMessageFiles.d.ts +11 -0
  135. package/bin/session/messages/SessionForkMessageFiles.d.ts.map +1 -1
  136. package/bin/session/messages/SessionForkMessageFiles.js +8 -2
  137. package/bin/session/messages/SessionForkMessageFiles.js.map +1 -1
  138. package/bin/session/messages/SessionMessageInteractionWriter.d.ts +6 -6
  139. package/bin/session/messages/SessionMessageInteractionWriter.d.ts.map +1 -1
  140. package/bin/session/messages/SessionMessageInteractionWriter.js +4 -4
  141. package/bin/session/messages/SessionMessageInteractionWriter.js.map +1 -1
  142. package/bin/session/messages/SessionMessageText.d.ts +3 -3
  143. package/bin/session/messages/SessionMessageText.d.ts.map +1 -1
  144. package/bin/session/messages/SessionMessageText.js +0 -2
  145. package/bin/session/messages/SessionMessageText.js.map +1 -1
  146. package/bin/session/messages/SessionTurnFileDiffData.d.ts +3 -3
  147. package/bin/session/messages/SessionTurnFileDiffData.d.ts.map +1 -1
  148. package/bin/session/messages/SessionTurnFileDiffData.js.map +1 -1
  149. package/bin/session/messages/SessionUserMessage.d.ts +3 -3
  150. package/bin/session/messages/SessionUserMessage.d.ts.map +1 -1
  151. package/bin/session/messages/SessionUserMessage.js +6 -3
  152. package/bin/session/messages/SessionUserMessage.js.map +1 -1
  153. package/bin/session/preview/SessionMessagePreview.d.ts.map +1 -1
  154. package/bin/session/preview/SessionMessagePreview.js +25 -9
  155. package/bin/session/preview/SessionMessagePreview.js.map +1 -1
  156. package/bin/session/runtime/SessionTurnCompletion.d.ts +15 -0
  157. package/bin/session/runtime/SessionTurnCompletion.d.ts.map +1 -0
  158. package/bin/session/runtime/SessionTurnCompletion.js +126 -0
  159. package/bin/session/runtime/SessionTurnCompletion.js.map +1 -0
  160. package/bin/session/runtime/SessionTurnContext.d.ts.map +1 -1
  161. package/bin/session/runtime/SessionTurnContext.js +14 -19
  162. package/bin/session/runtime/SessionTurnContext.js.map +1 -1
  163. package/bin/session/runtime/SessionTurnFileDiff.d.ts +12 -0
  164. package/bin/session/runtime/SessionTurnFileDiff.d.ts.map +1 -0
  165. package/bin/session/runtime/SessionTurnFileDiff.js +71 -0
  166. package/bin/session/runtime/SessionTurnFileDiff.js.map +1 -0
  167. package/bin/session/storage/LocalSessionDataStore.d.ts +6 -41
  168. package/bin/session/storage/LocalSessionDataStore.d.ts.map +1 -1
  169. package/bin/session/storage/LocalSessionDataStore.js +19 -101
  170. package/bin/session/storage/LocalSessionDataStore.js.map +1 -1
  171. package/bin/session/storage/LocalSessionStore.d.ts +13 -5
  172. package/bin/session/storage/LocalSessionStore.d.ts.map +1 -1
  173. package/bin/session/storage/LocalSessionStore.js +153 -30
  174. package/bin/session/storage/LocalSessionStore.js.map +1 -1
  175. package/bin/session/storage/LocalStorePaths.d.ts +4 -16
  176. package/bin/session/storage/LocalStorePaths.d.ts.map +1 -1
  177. package/bin/session/storage/LocalStorePaths.js +7 -31
  178. package/bin/session/storage/LocalStorePaths.js.map +1 -1
  179. package/bin/session/storage/Metadata.d.ts +4 -4
  180. package/bin/session/storage/Metadata.d.ts.map +1 -1
  181. package/bin/session/storage/Metadata.js +3 -11
  182. package/bin/session/storage/Metadata.js.map +1 -1
  183. package/bin/session/storage/RuntimeSessionPort.d.ts +4 -4
  184. package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
  185. package/bin/session/storage/RuntimeSessionPort.js +3 -3
  186. package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
  187. package/bin/session/storage/SessionStorageCodec.d.ts +59 -0
  188. package/bin/session/storage/SessionStorageCodec.d.ts.map +1 -0
  189. package/bin/session/storage/SessionStorageCodec.js +331 -0
  190. package/bin/session/storage/SessionStorageCodec.js.map +1 -0
  191. package/bin/session/storage/SessionStorageSchema.d.ts +11 -0
  192. package/bin/session/storage/SessionStorageSchema.d.ts.map +1 -0
  193. package/bin/session/storage/SessionStorageSchema.js +131 -0
  194. package/bin/session/storage/SessionStorageSchema.js.map +1 -0
  195. package/bin/session/storage/SqliteSessionStorage.d.ts +120 -0
  196. package/bin/session/storage/SqliteSessionStorage.d.ts.map +1 -0
  197. package/bin/session/storage/SqliteSessionStorage.js +581 -0
  198. package/bin/session/storage/SqliteSessionStorage.js.map +1 -0
  199. package/bin/tools/ask/AskQuestionsTool.d.ts.map +1 -1
  200. package/bin/tools/ask/AskQuestionsTool.js +3 -1
  201. package/bin/tools/ask/AskQuestionsTool.js.map +1 -1
  202. package/bin/types/action/ActionResult.d.ts +9 -9
  203. package/bin/types/action/ActionResult.d.ts.map +1 -1
  204. package/bin/types/action/ActionResult.js +1 -1
  205. package/bin/types/agent/AgentOptions.d.ts +10 -0
  206. package/bin/types/agent/AgentOptions.d.ts.map +1 -1
  207. package/bin/types/agent/AgentStorage.d.ts +3 -1
  208. package/bin/types/agent/AgentStorage.d.ts.map +1 -1
  209. package/bin/types/agent/SessionActor.d.ts +0 -9
  210. package/bin/types/agent/SessionActor.d.ts.map +1 -1
  211. package/bin/types/agent/SessionTypes.d.ts +5 -5
  212. package/bin/types/agent/SessionTypes.d.ts.map +1 -1
  213. package/bin/types/executor/SessionAssistantOutput.d.ts +15 -4
  214. package/bin/types/executor/SessionAssistantOutput.d.ts.map +1 -1
  215. package/bin/types/executor/SessionTurnContext.d.ts +17 -19
  216. package/bin/types/executor/SessionTurnContext.d.ts.map +1 -1
  217. package/bin/types/sdk/AgentSessionAction.d.ts +1 -1
  218. package/bin/types/sdk/AgentSessionAction.js +1 -1
  219. package/bin/types/sdk/AgentSessionPrompt.d.ts +14 -5
  220. package/bin/types/sdk/AgentSessionPrompt.d.ts.map +1 -1
  221. package/bin/types/sdk/AgentSessionPrompt.js +1 -1
  222. package/bin/types/sdk/AgentSessionPrompt.js.map +1 -1
  223. package/bin/types/session/AdaptivePartContextPolicy.d.ts +31 -0
  224. package/bin/types/session/AdaptivePartContextPolicy.d.ts.map +1 -0
  225. package/bin/types/session/AdaptivePartContextPolicy.js +7 -0
  226. package/bin/types/session/AdaptivePartContextPolicy.js.map +1 -0
  227. package/bin/types/session/{SessionAssistantMessageState.d.ts → SessionAgentMessageState.d.ts} +7 -7
  228. package/bin/types/session/SessionAgentMessageState.d.ts.map +1 -0
  229. package/bin/types/session/{SessionAssistantMessageState.js → SessionAgentMessageState.js} +1 -1
  230. package/bin/types/session/SessionAgentMessageState.js.map +1 -0
  231. package/bin/types/session/SessionCommand.d.ts +19 -7
  232. package/bin/types/session/SessionCommand.d.ts.map +1 -1
  233. package/bin/types/session/SessionComposer.d.ts +43 -43
  234. package/bin/types/session/SessionComposer.d.ts.map +1 -1
  235. package/bin/types/session/SessionComposer.js +2 -2
  236. package/bin/types/session/SessionComposition.d.ts +2 -5
  237. package/bin/types/session/SessionComposition.d.ts.map +1 -1
  238. package/bin/types/session/SessionContextPolicy.d.ts +70 -0
  239. package/bin/types/session/SessionContextPolicy.d.ts.map +1 -0
  240. package/bin/types/session/SessionContextPolicy.js +8 -0
  241. package/bin/types/session/SessionContextPolicy.js.map +1 -0
  242. package/bin/types/session/SessionExecution.d.ts +5 -32
  243. package/bin/types/session/SessionExecution.d.ts.map +1 -1
  244. package/bin/types/session/SessionLoop.d.ts +3 -5
  245. package/bin/types/session/SessionLoop.d.ts.map +1 -1
  246. package/bin/types/session/SessionMessages.d.ts +18 -28
  247. package/bin/types/session/SessionMessages.d.ts.map +1 -1
  248. package/bin/types/session/SessionOptions.d.ts +5 -5
  249. package/bin/types/session/SessionOptions.d.ts.map +1 -1
  250. package/bin/types/session/SessionPort.d.ts +8 -9
  251. package/bin/types/session/SessionPort.d.ts.map +1 -1
  252. package/bin/types/session/SessionState.d.ts +2 -5
  253. package/bin/types/session/SessionState.d.ts.map +1 -1
  254. package/bin/types/session/SessionSystem.d.ts +14 -0
  255. package/bin/types/session/SessionSystem.d.ts.map +1 -1
  256. package/bin/types/session/SessionTool.d.ts +2 -2
  257. package/bin/types/session/SessionTool.d.ts.map +1 -1
  258. package/bin/types/session/SessionTurnCompletion.d.ts +23 -0
  259. package/bin/types/session/SessionTurnCompletion.d.ts.map +1 -0
  260. package/bin/types/session/SessionTurnCompletion.js +8 -0
  261. package/bin/types/session/SessionTurnCompletion.js.map +1 -0
  262. package/bin/types/session/SessionTurnFileDiff.d.ts +42 -0
  263. package/bin/types/session/SessionTurnFileDiff.d.ts.map +1 -0
  264. package/bin/types/session/SessionTurnFileDiff.js +8 -0
  265. package/bin/types/session/SessionTurnFileDiff.js.map +1 -0
  266. package/bin/types/store/LocalStore.d.ts +6 -13
  267. package/bin/types/store/LocalStore.d.ts.map +1 -1
  268. package/bin/types/store/LocalStore.js +1 -1
  269. package/bin/types/store/SessionStorage.d.ts +103 -0
  270. package/bin/types/store/SessionStorage.d.ts.map +1 -0
  271. package/bin/types/store/SessionStorage.js +8 -0
  272. package/bin/types/store/SessionStorage.js.map +1 -0
  273. package/bin/types/store/SessionStore.d.ts +5 -3
  274. package/bin/types/store/SessionStore.d.ts.map +1 -1
  275. package/package.json +2 -2
  276. package/scripts/core-engine-context-compaction.test.mjs +96 -219
  277. package/scripts/core-engine-model-stream.test.mjs +2 -4
  278. package/scripts/executor-failure-result.test.mjs +14 -17
  279. package/scripts/session-agent-message-part-order.test.mjs +63 -0
  280. package/scripts/session-initialization.test.mjs +141 -0
  281. package/scripts/session-message-timeline.test.mjs +5 -6
  282. package/scripts/session-messages-error-part.test.mjs +175 -0
  283. package/scripts/session-messages-error.test.mjs +47 -6
  284. package/scripts/session-prompt-idempotency.test.mjs +91 -0
  285. package/scripts/session-queue.test.mjs +13 -12
  286. package/scripts/session-storage-sqlite.test.mjs +209 -0
  287. package/scripts/session-turn-context.test.mjs +21 -33
  288. package/src/agent/Agent.ts +48 -12
  289. package/src/agent/AgentInstructions.ts +2 -2
  290. package/src/agent/AgentMemoryStorage.ts +1 -0
  291. package/src/agent/AgentSessions.ts +31 -12
  292. package/src/executor/Executor.ts +47 -184
  293. package/src/executor/README.md +12 -13
  294. package/src/executor/composer/system/default/SystemPromptAssets.ts +0 -6
  295. package/src/executor/core-engine/CoreEngineContextCompaction.ts +3 -135
  296. package/src/executor/core-engine/CoreEngineRunner.ts +51 -273
  297. package/src/executor/core-engine/CoreEngineSignals.ts +9 -9
  298. package/src/executor/messages/SessionAttachmentMapper.ts +4 -4
  299. package/src/executor/messages/SessionMessageLog.ts +3 -3
  300. package/src/executor/messages/SessionModelMessages.ts +85 -103
  301. package/src/executor/model/ModelStepRunner.ts +9 -41
  302. package/src/executor/services/ExecutorRecoveryPolicy.ts +34 -127
  303. package/src/executor/types/SessionHistoryMeta.ts +1 -3
  304. package/src/index.ts +39 -47
  305. package/src/session/DefaultSessionComposer.ts +33 -30
  306. package/src/session/Session.ts +96 -227
  307. package/src/session/SessionComposition.ts +28 -65
  308. package/src/session/SessionLoop.ts +267 -370
  309. package/src/session/SessionMessages.ts +363 -242
  310. package/src/session/SessionQueue.ts +3 -2
  311. package/src/session/SessionState.ts +55 -101
  312. package/src/session/SessionSystem.ts +51 -1
  313. package/src/session/SessionTitle.ts +4 -4
  314. package/src/session/browse/Browse.ts +182 -468
  315. package/src/session/browse/SessionMessageTimeline.ts +63 -38
  316. package/src/session/composer/policies/AdaptivePartContextPolicy.ts +307 -0
  317. package/src/session/composer/policies/FullHistoryContextPolicy.ts +36 -0
  318. package/src/session/composer/policies/SessionSummaryPrompts.ts +42 -0
  319. package/src/session/execution/SessionAssistantOutputAdapter.ts +25 -11
  320. package/src/session/messages/{SessionActionMessageWriter.ts → SessionAgentActionPartWriter.ts} +8 -8
  321. package/src/session/messages/SessionAgentContent.ts +56 -0
  322. package/src/session/messages/SessionAgentMessageState.ts +378 -0
  323. package/src/session/messages/{SessionAssistantMessageWriter.ts → SessionAgentMessageWriter.ts} +89 -60
  324. package/src/session/messages/SessionForkMessageFiles.ts +25 -1
  325. package/src/session/messages/SessionMessageInteractionWriter.ts +19 -19
  326. package/src/session/messages/SessionMessageText.ts +3 -4
  327. package/src/session/messages/SessionTurnFileDiffData.ts +3 -3
  328. package/src/session/messages/SessionUserMessage.ts +10 -7
  329. package/src/session/preview/SessionMessagePreview.ts +26 -9
  330. package/src/session/runtime/SessionTurnCompletion.ts +159 -0
  331. package/src/session/runtime/SessionTurnContext.ts +20 -21
  332. package/src/session/runtime/SessionTurnFileDiff.ts +105 -0
  333. package/src/session/storage/LocalSessionDataStore.ts +27 -176
  334. package/src/session/storage/LocalSessionStore.ts +170 -38
  335. package/src/session/storage/LocalStorePaths.ts +14 -86
  336. package/src/session/storage/Metadata.ts +4 -13
  337. package/src/session/storage/RuntimeSessionPort.ts +7 -7
  338. package/src/session/storage/SessionStorageCodec.ts +465 -0
  339. package/src/session/storage/SessionStorageSchema.ts +132 -0
  340. package/src/session/storage/SqliteSessionStorage.ts +776 -0
  341. package/src/tools/ask/AskQuestionsTool.ts +3 -1
  342. package/src/types/action/ActionResult.ts +10 -10
  343. package/src/types/agent/AgentOptions.ts +11 -0
  344. package/src/types/agent/AgentStorage.ts +3 -1
  345. package/src/types/agent/SessionActor.ts +0 -10
  346. package/src/types/agent/SessionTypes.ts +5 -5
  347. package/src/types/executor/SessionAssistantOutput.ts +15 -4
  348. package/src/types/executor/SessionTurnContext.ts +25 -22
  349. package/src/types/sdk/AgentSessionAction.ts +1 -1
  350. package/src/types/sdk/AgentSessionPrompt.ts +15 -5
  351. package/src/types/session/AdaptivePartContextPolicy.ts +37 -0
  352. package/src/types/session/{SessionAssistantMessageState.ts → SessionAgentMessageState.ts} +6 -6
  353. package/src/types/session/SessionCommand.ts +21 -7
  354. package/src/types/session/SessionComposer.ts +48 -48
  355. package/src/types/session/SessionComposition.ts +2 -5
  356. package/src/types/session/SessionContextPolicy.ts +77 -0
  357. package/src/types/session/SessionExecution.ts +11 -36
  358. package/src/types/session/SessionLoop.ts +3 -8
  359. package/src/types/session/SessionMessages.ts +19 -29
  360. package/src/types/session/SessionOptions.ts +5 -5
  361. package/src/types/session/SessionPort.ts +10 -10
  362. package/src/types/session/SessionState.ts +2 -5
  363. package/src/types/session/SessionSystem.ts +19 -0
  364. package/src/types/session/SessionTool.ts +2 -2
  365. package/src/types/session/SessionTurnCompletion.ts +24 -0
  366. package/src/types/session/SessionTurnFileDiff.ts +44 -0
  367. package/src/types/store/LocalStore.ts +6 -14
  368. package/src/types/store/SessionStorage.ts +121 -0
  369. package/src/types/store/SessionStore.ts +6 -3
  370. package/tsconfig.tsbuildinfo +1 -1
  371. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.d.ts +0 -45
  372. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.d.ts.map +0 -1
  373. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.js +0 -144
  374. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.js.map +0 -1
  375. package/bin/executor/composer/system/SessionSystemComposer.d.ts +0 -23
  376. package/bin/executor/composer/system/SessionSystemComposer.d.ts.map +0 -1
  377. package/bin/executor/composer/system/SessionSystemComposer.js +0 -9
  378. package/bin/executor/composer/system/SessionSystemComposer.js.map +0 -1
  379. package/bin/executor/composer/system/default/DefaultSessionSystemComposer.d.ts +0 -43
  380. package/bin/executor/composer/system/default/DefaultSessionSystemComposer.d.ts.map +0 -1
  381. package/bin/executor/composer/system/default/DefaultSessionSystemComposer.js +0 -42
  382. package/bin/executor/composer/system/default/DefaultSessionSystemComposer.js.map +0 -1
  383. package/bin/executor/composer/system/default/PromptRenderer.d.ts +0 -35
  384. package/bin/executor/composer/system/default/PromptRenderer.d.ts.map +0 -1
  385. package/bin/executor/composer/system/default/PromptRenderer.js +0 -23
  386. package/bin/executor/composer/system/default/PromptRenderer.js.map +0 -1
  387. package/bin/executor/composer/system/default/SystemDomain.d.ts +0 -151
  388. package/bin/executor/composer/system/default/SystemDomain.d.ts.map +0 -1
  389. package/bin/executor/composer/system/default/SystemDomain.js +0 -162
  390. package/bin/executor/composer/system/default/SystemDomain.js.map +0 -1
  391. package/bin/executor/composer/system/default/assets/task.prompt.d.ts +0 -7
  392. package/bin/executor/composer/system/default/assets/task.prompt.d.ts.map +0 -1
  393. package/bin/executor/composer/system/default/assets/task.prompt.js +0 -8
  394. package/bin/executor/composer/system/default/assets/task.prompt.js.map +0 -1
  395. package/bin/executor/composer/system/default/variables/GeoContext.d.ts +0 -14
  396. package/bin/executor/composer/system/default/variables/GeoContext.d.ts.map +0 -1
  397. package/bin/executor/composer/system/default/variables/GeoContext.js +0 -150
  398. package/bin/executor/composer/system/default/variables/GeoContext.js.map +0 -1
  399. package/bin/executor/composer/system/default/variables/PromptTypes.d.ts +0 -36
  400. package/bin/executor/composer/system/default/variables/PromptTypes.d.ts.map +0 -1
  401. package/bin/executor/composer/system/default/variables/PromptTypes.js +0 -9
  402. package/bin/executor/composer/system/default/variables/PromptTypes.js.map +0 -1
  403. package/bin/executor/composer/system/default/variables/VariableReplacer.d.ts +0 -61
  404. package/bin/executor/composer/system/default/variables/VariableReplacer.d.ts.map +0 -1
  405. package/bin/executor/composer/system/default/variables/VariableReplacer.js +0 -93
  406. package/bin/executor/composer/system/default/variables/VariableReplacer.js.map +0 -1
  407. package/bin/executor/core-engine/CoreEngineMessageState.d.ts +0 -63
  408. package/bin/executor/core-engine/CoreEngineMessageState.d.ts.map +0 -1
  409. package/bin/executor/core-engine/CoreEngineMessageState.js +0 -81
  410. package/bin/executor/core-engine/CoreEngineMessageState.js.map +0 -1
  411. package/bin/session/SessionCommand.d.ts +0 -24
  412. package/bin/session/SessionCommand.d.ts.map +0 -1
  413. package/bin/session/SessionCommand.js +0 -35
  414. package/bin/session/SessionCommand.js.map +0 -1
  415. package/bin/session/messages/SessionActionMessageWriter.d.ts.map +0 -1
  416. package/bin/session/messages/SessionActionMessageWriter.js.map +0 -1
  417. package/bin/session/messages/SessionAssistantMessageState.d.ts +0 -49
  418. package/bin/session/messages/SessionAssistantMessageState.d.ts.map +0 -1
  419. package/bin/session/messages/SessionAssistantMessageState.js +0 -296
  420. package/bin/session/messages/SessionAssistantMessageState.js.map +0 -1
  421. package/bin/session/messages/SessionAssistantMessageWriter.d.ts.map +0 -1
  422. package/bin/session/messages/SessionAssistantMessageWriter.js.map +0 -1
  423. package/bin/session/messages/SessionMessageCompaction.d.ts +0 -29
  424. package/bin/session/messages/SessionMessageCompaction.d.ts.map +0 -1
  425. package/bin/session/messages/SessionMessageCompaction.js +0 -128
  426. package/bin/session/messages/SessionMessageCompaction.js.map +0 -1
  427. package/bin/session/runtime/SessionCompactOperation.d.ts +0 -29
  428. package/bin/session/runtime/SessionCompactOperation.d.ts.map +0 -1
  429. package/bin/session/runtime/SessionCompactOperation.js +0 -66
  430. package/bin/session/runtime/SessionCompactOperation.js.map +0 -1
  431. package/bin/session/runtime/SessionHistoryCompaction.d.ts +0 -22
  432. package/bin/session/runtime/SessionHistoryCompaction.d.ts.map +0 -1
  433. package/bin/session/runtime/SessionHistoryCompaction.js +0 -31
  434. package/bin/session/runtime/SessionHistoryCompaction.js.map +0 -1
  435. package/bin/session/storage/JsonlSessionMessageStore.d.ts +0 -77
  436. package/bin/session/storage/JsonlSessionMessageStore.d.ts.map +0 -1
  437. package/bin/session/storage/JsonlSessionMessageStore.js +0 -419
  438. package/bin/session/storage/JsonlSessionMessageStore.js.map +0 -1
  439. package/bin/session/storage/SessionMessageStoreFactory.d.ts +0 -12
  440. package/bin/session/storage/SessionMessageStoreFactory.d.ts.map +0 -1
  441. package/bin/session/storage/SessionMessageStoreFactory.js +0 -13
  442. package/bin/session/storage/SessionMessageStoreFactory.js.map +0 -1
  443. package/bin/types/common/Template.d.ts +0 -9
  444. package/bin/types/common/Template.d.ts.map +0 -1
  445. package/bin/types/common/Template.js +0 -9
  446. package/bin/types/common/Template.js.map +0 -1
  447. package/bin/types/sdk/AgentSessionCompact.d.ts +0 -30
  448. package/bin/types/sdk/AgentSessionCompact.d.ts.map +0 -1
  449. package/bin/types/sdk/AgentSessionCompact.js +0 -8
  450. package/bin/types/sdk/AgentSessionCompact.js.map +0 -1
  451. package/bin/types/session/SessionAssistantMessageState.d.ts.map +0 -1
  452. package/bin/types/session/SessionAssistantMessageState.js.map +0 -1
  453. package/bin/types/session/SessionSegment.d.ts +0 -57
  454. package/bin/types/session/SessionSegment.d.ts.map +0 -1
  455. package/bin/types/session/SessionSegment.js +0 -8
  456. package/bin/types/session/SessionSegment.js.map +0 -1
  457. package/bin/types/store/SessionDataStore.d.ts +0 -88
  458. package/bin/types/store/SessionDataStore.d.ts.map +0 -1
  459. package/bin/types/store/SessionDataStore.js +0 -9
  460. package/bin/types/store/SessionDataStore.js.map +0 -1
  461. package/bin/utils/Template.d.ts +0 -17
  462. package/bin/utils/Template.d.ts.map +0 -1
  463. package/bin/utils/Template.js +0 -24
  464. package/bin/utils/Template.js.map +0 -1
  465. package/scripts/session-compaction-prompts.test.mjs +0 -49
  466. package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.ts +0 -162
  467. package/src/executor/composer/system/SessionSystemComposer.ts +0 -25
  468. package/src/executor/composer/system/default/DefaultSessionSystemComposer.ts +0 -76
  469. package/src/executor/composer/system/default/PromptRenderer.ts +0 -52
  470. package/src/executor/composer/system/default/SystemDomain.ts +0 -301
  471. package/src/executor/composer/system/default/assets/task.prompt.ts +0 -9
  472. package/src/executor/composer/system/default/assets/task.prompt.ts.txt +0 -33
  473. package/src/executor/composer/system/default/variables/GeoContext.ts +0 -180
  474. package/src/executor/composer/system/default/variables/PromptTypes.ts +0 -37
  475. package/src/executor/composer/system/default/variables/VariableReplacer.ts +0 -154
  476. package/src/executor/core-engine/CoreEngineMessageState.ts +0 -117
  477. package/src/session/SessionCommand.ts +0 -42
  478. package/src/session/messages/SessionAssistantMessageState.ts +0 -392
  479. package/src/session/messages/SessionMessageCompaction.ts +0 -160
  480. package/src/session/runtime/SessionCompactOperation.ts +0 -93
  481. package/src/session/runtime/SessionHistoryCompaction.ts +0 -45
  482. package/src/session/storage/JsonlSessionMessageStore.ts +0 -513
  483. package/src/session/storage/SessionMessageStoreFactory.ts +0 -18
  484. package/src/types/common/Template.ts +0 -9
  485. package/src/types/sdk/AgentSessionCompact.ts +0 -32
  486. package/src/types/session/SessionSegment.ts +0 -62
  487. package/src/types/store/SessionDataStore.ts +0 -113
  488. package/src/utils/Template.ts +0 -28
@@ -8,8 +8,7 @@
8
8
  import type { ModelClient, RuntimeTool as Tool } from "@downcity/type";
9
9
  import type { AgentSessionSystemBlock } from "@/types/agent/SessionTypes.js";
10
10
  import type { SessionOrigin } from "@downcity/type";
11
- import type { SessionDataStore } from "@/types/store/SessionDataStore.js";
12
- import type { SessionMessages } from "@/session/SessionMessages.js";
11
+ import type { SessionStorage } from "@/types/store/SessionStorage.js";
13
12
  import type { SessionHookRuntime } from "@downcity/type";
14
13
  import type { SessionComposer } from "@/types/session/SessionComposer.js";
15
14
  import type { Logger } from "@/utils/logger/Logger.js";
@@ -25,9 +24,7 @@ export interface SessionCompositionOptions {
25
24
  /** 当前 Session 使用的 Workspace 绝对根目录。 */
26
25
  workspace_path: string;
27
26
  /** 当前 Session 的领域持久化视图。 */
28
- store: SessionDataStore;
29
- /** canonical Message 唯一事实源。 */
30
- messages: SessionMessages;
27
+ store: SessionStorage;
31
28
  /** 当前 Session 使用的统一 Composer。 */
32
29
  composer: SessionComposer;
33
30
  /** 在每个 Step 检查点读取当前可用 Tool 集合。 */
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Session Composer 的上下文策略协议。
3
+ *
4
+ * Policy 只读取 canonical Message,并在自己的命名空间维护可删除、可重建的派生数据;
5
+ * 它不修改 Session Message、State 或 Turn 生命周期。
6
+ */
7
+
8
+ import type { ModelClient, ModelMessage, SessionSystemBlock } from "@downcity/type";
9
+ import type { ModelRequestFailureReporter } from "@/types/executor/ModelRequest.js";
10
+ import type { SessionComposerStorage } from "@/types/store/SessionStorage.js";
11
+
12
+ /** Composer 可以处理的上下文恢复原因。 */
13
+ export type SessionContextRecoveryReason =
14
+ /** Provider 明确拒绝超出上下文窗口的请求。 */
15
+ | "provider_context_limit"
16
+ /** Provider usage 已达到主动压缩阈值。 */
17
+ | "usage_pressure";
18
+
19
+ /** Policy 初始化输入。 */
20
+ export interface SessionContextPolicyInitializeInput {
21
+ /** 当前 Policy 已限定命名空间的派生存储。 */
22
+ storage: SessionComposerStorage;
23
+ }
24
+
25
+ /** Policy 正常解析上下文的输入。 */
26
+ export interface SessionContextPolicyInput {
27
+ /** 当前 Policy 已限定命名空间的派生存储。 */
28
+ storage: SessionComposerStorage;
29
+ /** 解析文件 Part 时使用的 Workspace 根目录。 */
30
+ project_root: string;
31
+ }
32
+
33
+ /** 上下文恢复输入。 */
34
+ export interface SessionContextPolicyRecoveryInput extends SessionContextPolicyInput {
35
+ /** 触发当前恢复的稳定领域原因。 */
36
+ reason: SessionContextRecoveryReason;
37
+ /** 用于生成派生摘要的当前模型。 */
38
+ model?: ModelClient;
39
+ /** 模型请求逐次失败的可选观测入口。 */
40
+ on_model_request_failure?: ModelRequestFailureReporter;
41
+ }
42
+
43
+ /** Policy 对本次模型上下文的只读诊断。 */
44
+ export interface SessionResolvedContextDiagnostics {
45
+ /** 生成当前上下文的 Policy 名称。 */
46
+ policy_name: string;
47
+ /** 当前上下文覆盖到的最新 canonical Message sequence。 */
48
+ through_sequence?: number;
49
+ /** 当前派生边界在 Message 内覆盖到的 Part sequence。 */
50
+ through_part_sequence?: number;
51
+ /** 当前上下文是否使用了派生摘要或检索结果。 */
52
+ derived: boolean;
53
+ /** 当前使用的可选派生记录标识。 */
54
+ derivation_id?: string;
55
+ }
56
+
57
+ /** Policy 已确定顺序的最终模型历史。 */
58
+ export interface SessionResolvedContext {
59
+ /** 送入模型的标准历史消息。 */
60
+ messages: ModelMessage[];
61
+ /** 由 Policy 生成、且不伪装成普通历史消息的显式 system 上下文。 */
62
+ system_blocks?: SessionSystemBlock[];
63
+ /** 不进入 canonical history 的策略诊断。 */
64
+ diagnostics: SessionResolvedContextDiagnostics;
65
+ }
66
+
67
+ /** Session Composer 内部可替换的上下文策略。 */
68
+ export interface SessionContextPolicy {
69
+ /** Policy 稳定名称,同时作为派生表命名空间。 */
70
+ readonly name: string;
71
+ /** 初始化当前 Policy 的派生 schema。 */
72
+ initialize(input: SessionContextPolicyInitializeInput): Promise<void>;
73
+ /** 从 canonical history 与派生数据生成模型历史。 */
74
+ resolve(input: SessionContextPolicyInput): Promise<SessionResolvedContext>;
75
+ /** 模型上下文失败后尝试推进派生状态;发生有效变化时返回 true。 */
76
+ recover(input: SessionContextPolicyRecoveryInput): Promise<boolean>;
77
+ }
@@ -7,8 +7,11 @@
7
7
  * - 输出只返回执行结果;Assistant Message 通过显式输出端口写入唯一事实源。
8
8
  */
9
9
 
10
- import type { ModelMessage, RuntimeTool as Tool } from "@downcity/type";
11
- import type { SessionUserMessage } from "@downcity/type";
10
+ import type {
11
+ ModelClient,
12
+ ModelMessage,
13
+ RuntimeTool as Tool,
14
+ } from "@downcity/type";
12
15
  import type { SessionSystemMessage } from "@/executor/types/SessionPrompts.js";
13
16
  import type { SessionTurnContext } from "@/types/executor/SessionTurnContext.js";
14
17
 
@@ -29,15 +32,6 @@ export interface SessionTurnExecutionResult {
29
32
  */
30
33
  error?: string;
31
34
 
32
- /**
33
- * 本轮执行结束后待写入长期历史的 user 消息。
34
- *
35
- * 关键点(中文)
36
- * - 这些消息通常由 tool 运行时在执行过程中动态注入。
37
- * - 为保证消息顺序稳定,统一在 assistant 结果落盘后再由外层 Session 持久化。
38
- */
39
- deferred_persisted_user_messages?: SessionUserMessage[];
40
-
41
35
  /**
42
36
  * 本轮结束后是否需要把已完成的 canonical 历史持久化压缩。
43
37
  *
@@ -52,11 +46,6 @@ export interface SessionTurnExecutionResult {
52
46
  * Session Turn 执行入口输入。
53
47
  */
54
48
  export interface SessionTurnExecutionInput {
55
- /**
56
- * 本轮用户输入查询文本。
57
- */
58
- query: string;
59
-
60
49
  /**
61
50
  * 本轮唯一的显式 Turn 上下文。
62
51
  *
@@ -71,10 +60,8 @@ export interface SessionTurnExecutionInput {
71
60
  * Executor 通过 Composer 装配后的中间运行态。
72
61
  */
73
62
  export interface SessionStepExecutionInput {
74
- /**
75
- * 当前轮用户查询文本。
76
- */
77
- query: string;
63
+ /** 当前 Step 使用的模型实例。 */
64
+ model: ModelClient;
78
65
 
79
66
  /**
80
67
  * 当前轮 system messages。
@@ -84,13 +71,14 @@ export interface SessionStepExecutionInput {
84
71
  /** 当前轮标准模型消息历史。 */
85
72
  messages: ModelMessage[];
86
73
 
87
- /** 当前模型历史所包含的最新持久化 Summary 标识。 */
88
- history_summary_id?: string;
89
-
90
74
  /**
91
75
  * 当前轮可用工具集合。
92
76
  */
93
77
  tools: Record<string, Tool>;
78
+
79
+ /** 当前模型支持的上下文窗口长度。 */
80
+ context_window?: number;
81
+
94
82
  }
95
83
 
96
84
  /** 单个 Session 的统一 Turn 执行协议。 */
@@ -100,16 +88,3 @@ export interface SessionExecutor {
100
88
  input: SessionTurnExecutionInput,
101
89
  ): Promise<SessionTurnExecutionResult>;
102
90
  }
103
-
104
- /** Session 领域执行一次持久化历史压缩的统一回调。 */
105
- export type SessionCompactHistory = (input: {
106
- /** 触发压缩的 Turn 标识;非 Turn 维护操作允许为空。 */
107
- turn_id?: string;
108
- }) => Promise<{
109
- /** 是否生成并成功提交了压缩计划。 */
110
- compacted: boolean;
111
- /** 没有压缩时的稳定原因。 */
112
- reason?: string;
113
- /** 压缩失败时的具体错误文本。 */
114
- error?: string;
115
- }>;
@@ -13,10 +13,7 @@ import type {
13
13
  SessionInteractionLifecycle,
14
14
  SessionInteractionPort,
15
15
  } from "@downcity/type";
16
- import type {
17
- SessionCompactHistory,
18
- SessionExecutor,
19
- } from "@/types/session/SessionExecution.js";
16
+ import type { SessionExecutor } from "@/types/session/SessionExecution.js";
20
17
  import type { SessionQueue } from "@/session/SessionQueue.js";
21
18
  import type { Logger } from "@/utils/logger/Logger.js";
22
19
  import type { SessionTurnContext } from "@/types/executor/SessionTurnContext.js";
@@ -40,8 +37,6 @@ export interface ActiveSessionTurnState {
40
37
  deferred_finished: SessionDeferred<AgentSessionTurnResult>;
41
38
  /** 当前 Turn 进入执行阶段后拥有的唯一上下文。 */
42
39
  turn_context: SessionTurnContext | null;
43
- /** 下一 Step 是否需要重新读取 canonical history。 */
44
- history_reload_requested: boolean;
45
40
  /** 当前 Turn 是否已经接收并持久化首条 Prompt。 */
46
41
  prompt_started: boolean;
47
42
  }
@@ -56,8 +51,8 @@ export interface SessionLoopOptions {
56
51
  workspace_path: string;
57
52
  /** 当前 Session 的模型执行器。 */
58
53
  executor: SessionExecutor;
59
- /** Session 领域提供的 canonical 历史压缩入口。 */
60
- compact_history: SessionCompactHistory;
54
+ /** Turn 结束后按需维护 Composer 派生上下文。 */
55
+ maintain_context: () => Promise<void>;
61
56
  /** 当前 Session 的配置与 Metadata 状态。 */
62
57
  state: SessionState;
63
58
  /** 当前 Session 的 canonical Message 入口。 */
@@ -5,15 +5,15 @@
5
5
  */
6
6
 
7
7
  import type { JsonObject } from "@downcity/type";
8
- import type { SessionMessageStore } from "@/types/store/SessionDataStore.js";
8
+ import type { SessionStorage } from "@/types/store/SessionStorage.js";
9
9
  import type { SessionAttachmentStore } from "@/types/store/SessionAttachmentStore.js";
10
10
  import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
11
11
  import type {
12
- SessionAssistantResultPart,
13
- SessionPromptPart,
12
+ SessionAgentContent,
13
+ SessionUserContent,
14
14
  } from "@downcity/type";
15
15
  import type {
16
- SessionAssistantMessagePart,
16
+ SessionAgentMessagePart,
17
17
  SessionUserMessagePart,
18
18
  } from "@downcity/type";
19
19
  import type { SessionMutation } from "@downcity/type";
@@ -23,7 +23,7 @@ export interface SessionMessagesOptions {
23
23
  /** 当前 Session 标识。 */
24
24
  session_id: string;
25
25
  /** Message 快照持久化 Store。 */
26
- store: SessionMessageStore;
26
+ store: SessionStorage;
27
27
  /** 当前 Session 的附件持久化能力。 */
28
28
  attachment_store: SessionAttachmentStore;
29
29
  /** 持久化成功后的实时 Mutation 发布函数。 */
@@ -34,8 +34,6 @@ export interface SessionMessagesOptions {
34
34
  export interface AppendSessionUserMessageInput {
35
35
  /** 当前输入所属 Turn。 */
36
36
  turn_id: string;
37
- /** 当前输入是普通 Prompt 还是 Steering 输入。 */
38
- input_type: "prompt" | "steer";
39
37
  /** User 结构化 Part。 */
40
38
  parts: SessionUserMessagePart[];
41
39
  /** 可选的稳定 Message 标识。 */
@@ -45,35 +43,27 @@ export interface AppendSessionUserMessageInput {
45
43
  }
46
44
 
47
45
  /** Assistant Message 创建参数。 */
48
- export interface OpenSessionAssistantMessageInput {
46
+ export interface OpenSessionAgentMessageInput {
49
47
  /** 当前 Assistant 所属 Turn。 */
50
48
  turn_id: string;
51
- /** 当前 Assistant 是普通回复还是压缩 Summary。 */
52
- kind?: "normal" | "summary";
53
49
  /** 当前 Message 的默认展示范围。 */
54
50
  visibility?: "visible" | "internal";
55
51
  /** 可选的稳定 Message 标识。 */
56
52
  message_id?: string;
57
- /** Summary 已覆盖到的来源 Message 标识。 */
58
- summary_through_message_id?: string;
59
53
  }
60
54
 
61
55
  /** 已完成 Assistant Message 的直接写入参数。 */
62
- export interface AppendCompletedAssistantMessageInput {
56
+ export interface AppendCompletedAgentMessageInput {
63
57
  /** 当前 Assistant 所属 Turn。 */
64
58
  turn_id?: string;
65
59
  /** Assistant 完整结构化 Part。 */
66
- parts: SessionAssistantMessagePart[];
67
- /** 当前 Assistant 是普通回复还是压缩 Summary。 */
68
- kind?: "normal" | "summary";
60
+ parts: SessionAgentMessagePart[];
69
61
  /** 当前 Message 的默认展示范围。 */
70
62
  visibility?: "visible" | "internal";
71
- /** Summary 已覆盖到的来源 Message 标识。 */
72
- summary_through_message_id?: string;
73
63
  }
74
64
 
75
- /** Action Message 创建参数。 */
76
- export interface OpenSessionActionMessageInput {
65
+ /** Action Part 及其所属 Agent Message 的创建参数。 */
66
+ export interface OpenSessionAgentActionPartInput {
77
67
  /** 可选的稳定 Message 标识,用于更新同一个 Action 生命周期。 */
78
68
  message_id?: string;
79
69
  /** 当前 Action 所属 Turn。 */
@@ -90,8 +80,8 @@ export interface OpenSessionActionMessageInput {
90
80
  publish_mutation?: boolean;
91
81
  }
92
82
 
93
- /** 完成 Action Message 时允许覆盖的内容。 */
94
- export interface CompleteSessionActionMessageInput {
83
+ /** 完成 Action Part 时允许覆盖的内容。 */
84
+ export interface CompleteSessionAgentActionPartInput {
95
85
  /** 完成时覆盖的可选标题。 */
96
86
  title?: string;
97
87
  /** 完成时覆盖的可选描述。 */
@@ -100,8 +90,8 @@ export interface CompleteSessionActionMessageInput {
100
90
  data?: JsonObject;
101
91
  }
102
92
 
103
- /** Error Message 创建参数。 */
104
- export interface AppendSessionErrorMessageInput {
93
+ /** Error Part 归入所属 Turn Agent Message 的参数。 */
94
+ export interface AppendSessionAgentErrorPartInput {
105
95
  /** 当前错误影响 Session 还是单个 Turn。 */
106
96
  scope: "session" | "turn";
107
97
  /** 当前错误所属 Turn。 */
@@ -117,15 +107,15 @@ export interface AppendSessionErrorMessageInput {
117
107
  /** 公开 Session API 追加 User Message 的输入。 */
118
108
  export interface AppendExternalSessionUserMessageInput {
119
109
  /** 可选的结构化 User 内容。 */
120
- parts?: SessionPromptPart[];
110
+ parts?: SessionUserContent[];
121
111
  /** 未提供结构化内容时使用的纯文本。 */
122
112
  text?: string;
123
113
  }
124
114
 
125
115
  /** 公开 Session API 追加 Assistant Message 的输入。 */
126
- export interface AppendExternalSessionAssistantMessageInput {
116
+ export interface AppendExternalSessionAgentMessageInput {
127
117
  /** 可选的结构化 Assistant 内容。 */
128
- parts?: SessionAssistantResultPart[];
118
+ parts?: SessionAgentContent[];
129
119
  /** 未提供结构化内容时使用的纯文本。 */
130
120
  text?: string;
131
121
  }
@@ -138,6 +128,6 @@ export interface AppendSessionPromptMessageInput {
138
128
  prompt: AgentSessionPromptInput;
139
129
  /** 当前输入所属 Turn。 */
140
130
  turn_id: string;
141
- /** 当前输入是普通 Prompt 还是 Steering 输入。 */
142
- input_type: "prompt" | "steer";
131
+ /** 幂等 Prompt 使用的稳定 User Message ID。 */
132
+ message_id?: string;
143
133
  }
@@ -14,7 +14,7 @@ import type { AgentSessionSystemBlock } from "@/types/agent/SessionTypes.js";
14
14
  import type { SessionHookRuntime } from "@downcity/type";
15
15
  import type { SessionComposer } from "@/types/session/SessionComposer.js";
16
16
  import type { Logger } from "@/utils/logger/Logger.js";
17
- import type { SessionDataStore } from "@/types/store/SessionDataStore.js";
17
+ import type { SessionStorage } from "@/types/store/SessionStorage.js";
18
18
  import type { SessionOrigin } from "@downcity/type";
19
19
 
20
20
  /**
@@ -60,10 +60,10 @@ export interface SessionOptions {
60
60
  origin: SessionOrigin;
61
61
 
62
62
  /** 当前 Session 独享的领域持久化视图。 */
63
- store: SessionDataStore;
63
+ store: SessionStorage;
64
64
 
65
65
  /** 为 fork 创建另一个 Session 的领域持久化视图。 */
66
- get_session_store: (session_id: string) => SessionDataStore;
66
+ create_session_store: (session_id: string) => SessionStorage;
67
67
 
68
68
  /**
69
69
  * 将 fork 创建的子 Session 交回 AgentSessions 登记。
@@ -127,6 +127,6 @@ export interface SessionOptions {
127
127
  /** 读取 Agent 当前持有的运行时模型实例。 */
128
128
  get_agent_model: () => ModelClient | undefined;
129
129
 
130
- /** 当前 Session 使用的统一执行策略;省略时使用默认 Composer */
131
- composer?: SessionComposer;
130
+ /** 为当前 Session 及其 fork 子 Session 创建独立 Composer 的工厂。 */
131
+ create_composer?: () => SessionComposer;
132
132
  }
@@ -8,8 +8,9 @@
8
8
 
9
9
  import type { ModelClient } from "@downcity/type";
10
10
  import type {
11
- SessionAssistantResultPart,
12
- SessionPromptPart,
11
+ SessionAgentContent,
12
+ SessionUserContent,
13
+ SessionMessage,
13
14
  } from "@downcity/type";
14
15
  import type { SessionExecutor } from "@/types/session/SessionExecution.js";
15
16
  import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
@@ -19,7 +20,6 @@ import type {
19
20
  SessionMutationSubscriber,
20
21
  SessionMutationUnsubscribe,
21
22
  } from "@downcity/type";
22
- import type { SessionContextSnapshot } from "@/types/session/SessionSegment.js";
23
23
 
24
24
  /**
25
25
  * 单个 Session 实例端口。
@@ -34,8 +34,8 @@ export interface SessionPort {
34
34
  /** 获取当前 Session 的执行端口。 */
35
35
  get_executor(): SessionExecutor;
36
36
 
37
- /** 读取当前 Session 的累计 Summary 与 Active Message 快照。 */
38
- context(): Promise<SessionContextSnapshot>;
37
+ /** 读取全部 canonical Session Message */
38
+ messages(): Promise<SessionMessage[]>;
39
39
 
40
40
  /** 向当前 Session actor 追加一条新的 prompt。 */
41
41
  prompt(input: AgentSessionPromptInput): Promise<AgentSessionTurnHandle>;
@@ -51,17 +51,17 @@ export interface SessionPort {
51
51
  */
52
52
  append_user_message(params: {
53
53
  /** 已构造好的 User 内容。 */
54
- parts?: SessionPromptPart[];
54
+ parts?: SessionUserContent[];
55
55
  /** 未传入结构化内容时使用的文本。 */
56
56
  text?: string;
57
57
  }): Promise<void>;
58
58
 
59
59
  /**
60
- * 追加一条 assistant 消息。
60
+ * 追加一条 Agent 消息。
61
61
  */
62
- append_assistant_message(params: {
63
- /** 已构造好的 Assistant 内容。 */
64
- parts?: SessionAssistantResultPart[];
62
+ append_agent_message(params: {
63
+ /** 已构造好的 Agent 内容。 */
64
+ parts?: SessionAgentContent[];
65
65
  /** 未传入结构化内容时使用的文本。 */
66
66
  text?: string;
67
67
  }): Promise<void>;
@@ -5,11 +5,10 @@
5
5
  */
6
6
 
7
7
  import type { ModelClient } from "@downcity/type";
8
- import type { SessionMessages } from "@/session/SessionMessages.js";
9
8
  import type { SessionLocalState } from "@/types/session/SessionLocalState.js";
10
9
  import type { SessionMutation } from "@downcity/type";
11
10
  import type { Logger } from "@/utils/logger/Logger.js";
12
- import type { SessionDataStore } from "@/types/store/SessionDataStore.js";
11
+ import type { SessionStorage } from "@/types/store/SessionStorage.js";
13
12
  import type { SessionOrigin } from "@downcity/type";
14
13
 
15
14
  /** SessionState 构造参数。 */
@@ -21,9 +20,7 @@ export interface SessionStateOptions {
21
20
  /** 当前 Session 的创建来源。 */
22
21
  origin: SessionOrigin;
23
22
  /** 当前 Session 独享的领域持久化视图。 */
24
- store: SessionDataStore;
25
- /** 当前 Session 的 canonical Message 入口。 */
26
- messages: SessionMessages;
23
+ store: SessionStorage;
27
24
  /** 当前 Session 的可变内存状态。 */
28
25
  state: SessionLocalState;
29
26
  /** 当前 Session 的运行日志器。 */
@@ -5,6 +5,11 @@
5
5
  */
6
6
 
7
7
  import type { AgentSessionSystemBlock } from "@/types/agent/SessionTypes.js";
8
+ import type {
9
+ SessionHookContext,
10
+ SessionHookRuntime,
11
+ SessionHookScopeRuntime,
12
+ } from "@downcity/type";
8
13
 
9
14
  /** 默认 Session System Block 的组装参数。 */
10
15
  export interface BuildSessionSystemBlocksInput {
@@ -25,3 +30,17 @@ export interface BuildSessionSystemBlocksInput {
25
30
  /** 读取当前 Session Plugin 的 System Block。 */
26
31
  get_plugin_system_blocks: () => Promise<AgentSessionSystemBlock[]>;
27
32
  }
33
+
34
+ /** 解析 Plugin system blocks 所需的稳定执行输入。 */
35
+ export interface ResolveSessionPluginSystemBlocksInput {
36
+ /** 当前 Session 的稳定标识。 */
37
+ session_id: string;
38
+ /** 当前 Turn 的稳定标识;控制面预览等非 Turn 调用允许为空。 */
39
+ turn_id?: string;
40
+ /** 当前调用捕获的 Hook runtime 或 Step scope。 */
41
+ hooks: SessionHookRuntime | SessionHookScopeRuntime;
42
+ /** 向 Plugin 暴露的只读 Session 上下文。 */
43
+ context: SessionHookContext;
44
+ /** Plugin system 解析失败后的可选降级观测入口。 */
45
+ on_error?: (error: unknown) => void | Promise<void>;
46
+ }
@@ -4,14 +4,14 @@
4
4
  * 这些类型描述 Tool 生命周期协调器与 Recorder 之间的稳定边界。
5
5
  */
6
6
 
7
- import type { SessionAssistantToolPart } from "@downcity/type";
7
+ import type { SessionAgentToolPart } from "@downcity/type";
8
8
 
9
9
  /** 当前流式 Assistant 中的 Tool Part 定位结果。 */
10
10
  export interface SessionStreamingToolLocation {
11
11
  /** Tool Part 所属 Assistant Message。 */
12
12
  message_id: string;
13
13
  /** 当前 Tool Part 完整快照。 */
14
- part: SessionAssistantToolPart;
14
+ part: SessionAgentToolPart;
15
15
  }
16
16
 
17
17
  /** Executor 在调用 Tool 实现前提交的完整输入。 */
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Session Turn 收口领域函数的依赖类型。
3
+ *
4
+ * 这些依赖只覆盖 canonical Message、Mutation、Hook 与资源释放,不包含 Queue 或
5
+ * Executor,避免 Turn 结果提交反向理解调度过程。
6
+ */
7
+
8
+ import type { SessionEventHub } from "@/session/runtime/SessionEventHub.js";
9
+ import type { SessionMessages } from "@/session/SessionMessages.js";
10
+ import type { Logger } from "@/utils/logger/Logger.js";
11
+
12
+ /** Turn 收口函数的稳定依赖。 */
13
+ export interface SessionTurnCompletionOptions {
14
+ /** 当前 Session 的稳定标识。 */
15
+ session_id: string;
16
+ /** 当前 Session 的 canonical Message 入口。 */
17
+ messages: SessionMessages;
18
+ /** 当前 Session 的 Mutation 发布入口。 */
19
+ events: SessionEventHub;
20
+ /** 当前 Session 的统一日志器。 */
21
+ logger: Logger;
22
+ /** Turn 停止时对外使用的稳定错误文本。 */
23
+ stopped_message: string;
24
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Session Turn 文件修改观测函数的依赖类型。
3
+ *
4
+ * 文件 Diff 是辅助观测结果,不参与模型或 Tool 的成功判定;这些类型显式限制它只能
5
+ * 读取 Turn effects、写入 Assistant 输出并发布摘要 Mutation。
6
+ */
7
+
8
+ import type { RuntimeToolEffect } from "@downcity/type";
9
+ import type { SessionAssistantOutput } from "@/types/executor/SessionAssistantOutput.js";
10
+ import type { SessionTurnContext } from "@/types/executor/SessionTurnContext.js";
11
+ import type { SessionMutation } from "@downcity/type";
12
+ import type { Logger } from "@/utils/logger/Logger.js";
13
+
14
+ /** 持久化 Turn 最终文件 Diff 的输入。 */
15
+ export interface AppendSessionTurnFileDiffInput {
16
+ /** 当前 Session 的稳定标识。 */
17
+ session_id: string;
18
+ /** 当前 Turn 的稳定标识。 */
19
+ turn_id: string;
20
+ /** 当前 Workspace 的绝对根路径。 */
21
+ workspace_path: string;
22
+ /** 当前 Turn 持有的 effects 与生命周期上下文。 */
23
+ turn_context: SessionTurnContext;
24
+ /** 当前 Turn 的 canonical Assistant 输出端口。 */
25
+ assistant_output: SessionAssistantOutput;
26
+ /** 当前 Session 的统一日志器。 */
27
+ logger: Logger;
28
+ }
29
+
30
+ /** 发布 Turn 实时文件 Diff 摘要的输入。 */
31
+ export interface PublishSessionTurnFileDiffInput {
32
+ /** 当前 Session 的稳定标识。 */
33
+ session_id: string;
34
+ /** 当前 Turn 的稳定标识。 */
35
+ turn_id: string;
36
+ /** 当前 Workspace 的绝对根路径。 */
37
+ workspace_path: string;
38
+ /** 当前检查点已经发生的 Tool effects。 */
39
+ effects: readonly RuntimeToolEffect[];
40
+ /** 发布公开 Session Mutation 的函数。 */
41
+ publish: (mutation: SessionMutation) => void;
42
+ /** 当前 Session 的统一日志器。 */
43
+ logger: Logger;
44
+ }
@@ -3,10 +3,10 @@
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - 本地 Store 接收 AgentStorage 创建的私有 FileSystem 与存储根目录。
6
- * - SessionStore 与 SessionDataStore 不复用项目 WorkspaceTools 的 FileSystem。
6
+ * - SessionStore 与 SessionStorage 不复用项目 WorkspaceTools 的 FileSystem。
7
7
  */
8
8
 
9
- import type { FileSystem } from "@downcity/type";
9
+ import type { FileSystem, StorageDatabaseLocation } from "@downcity/type";
10
10
  import type { SessionOrigin } from "@downcity/type";
11
11
 
12
12
  /** LocalSessionStore 构造参数。 */
@@ -17,6 +17,8 @@ export interface LocalSessionStoreOptions {
17
17
  storage_root_path: string;
18
18
  /** 当前 Session 查询视图所属 Agent 的稳定标识。 */
19
19
  agent_id: string;
20
+ /** Session 数据库使用本地文件还是进程内存。 */
21
+ database_location: StorageDatabaseLocation;
20
22
  /** 当前 Workspace 的稳定标识。 */
21
23
  workspace_id?: string;
22
24
  }
@@ -29,6 +31,8 @@ export interface LocalSessionDataStoreOptions {
29
31
  storage_root_path: string;
30
32
  /** 当前 Session 所属 Agent 的稳定标识。 */
31
33
  agent_id: string;
34
+ /** 当前 Session 数据库使用本地文件还是进程内存。 */
35
+ database_location: StorageDatabaseLocation;
32
36
  /** 当前 Session 所属 Workspace 的稳定标识。 */
33
37
  workspace_id?: string;
34
38
  /** 当前 Session 的稳定标识。 */
@@ -36,15 +40,3 @@ export interface LocalSessionDataStoreOptions {
36
40
  /** 当前 Session 的创建来源与物理存储分区。 */
37
41
  origin: SessionOrigin;
38
42
  }
39
-
40
- /** JsonlSessionMessageStore 构造参数。 */
41
- export interface JsonlSessionMessageStoreOptions {
42
- /** 当前 Message Store 使用的 Agent 私有文件能力。 */
43
- files: FileSystem;
44
- /** 当前 Session 的稳定标识。 */
45
- session_id: string;
46
- /** Active JSONL 文件的绝对路径。 */
47
- file_path: string;
48
- /** Assistant 运行中快照的可选绝对路径。 */
49
- assistant_message_file_path?: string;
50
- }