@downcity/agent 1.1.430 → 1.1.437

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
@@ -1,8 +0,0 @@
1
- /**
2
- * Session Message 物理分段类型。
3
- *
4
- * Segment 保存一段连续的原始 Message,并在文件末尾保存覆盖到该段末尾的累计 Summary。
5
- * Summary 只服务模型上下文,不占用 Session Message sequence。
6
- */
7
- export {};
8
- //# sourceMappingURL=SessionSegment.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SessionSegment.js","sourceRoot":"","sources":["../../../src/types/session/SessionSegment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -1,88 +0,0 @@
1
- /**
2
- * 单个 Session 数据存储类型。
3
- *
4
- * 关键点(中文)
5
- * - Session 领域只依赖这些持久化能力,不感知 JSONL、目录或文件名。
6
- * - Message、Metadata 与 Instruction 共享同一个 Session 生命周期边界。
7
- */
8
- import type { SessionHistoryMeta } from "../../executor/types/SessionHistoryMeta.js";
9
- import type { SessionAssistantMessage, SessionMessage } from "@downcity/type";
10
- import type { SessionMessageStorageStats, SessionSegmentRange, SessionSegmentSnapshot, SessionSegmentSummary } from "../../types/session/SessionSegment.js";
11
- import type { SessionAttachmentStore } from "../../types/store/SessionAttachmentStore.js";
12
- import type { SessionOrigin } from "@downcity/type";
13
- /** 在 Message Store 写事务中创建新消息所需的稳定状态。 */
14
- export interface SessionMessageCommitState {
15
- /** 下一条真实 Message 应使用的全局线性顺序。 */
16
- message_sequence: number;
17
- /** 当前 Active 与 Assistant 草稿组成的运行态 Message。 */
18
- messages: SessionMessage[];
19
- }
20
- /** Active Message 压缩提交参数。 */
21
- export interface CompactActiveMessagesInput {
22
- /** 移入新 Segment 的最后一条真实 Message sequence。 */
23
- through_sequence: number;
24
- /** 写入新 Segment 末尾的累计上下文摘要。 */
25
- summary: SessionSegmentSummary;
26
- }
27
- /** Active Message 压缩提交结果。 */
28
- export interface CompactActiveMessagesResult {
29
- /** 本次创建的不可变历史分段。 */
30
- segment: SessionSegmentSnapshot;
31
- /** 压缩后继续保留在 Active 区域的 Message。 */
32
- active_messages: SessionMessage[];
33
- }
34
- /** Session Message 持久化能力。 */
35
- export interface SessionMessageStore {
36
- /** 初始化消息存储,并修复可恢复的中断状态。 */
37
- initialize(): Promise<void>;
38
- /** 读取当前 Active Message 与运行中的 Assistant 草稿。 */
39
- list_messages(): Promise<SessionMessage[]>;
40
- /** 读取指定 sequence 之前最近的完整历史分段。 */
41
- read_segment_before(before_sequence: number): Promise<SessionSegmentSnapshot | null>;
42
- /** 读取最新历史分段的累计摘要。 */
43
- read_latest_summary(): Promise<SessionSegmentSummary | null>;
44
- /** 读取当前 Session 的全部真实历史消息。 */
45
- list_history_messages(): Promise<SessionMessage[]>;
46
- /** 读取消息数量、存储大小与最新消息统计。 */
47
- stats(): Promise<SessionMessageStorageStats>;
48
- /** 判断指定 sequence 之前是否存在历史分段。 */
49
- has_segment_before(before_sequence: number): Promise<boolean>;
50
- /** 计算当前 Active Message 之前的读取边界。 */
51
- active_before_sequence(messages: SessionMessage[]): Promise<number | undefined>;
52
- /** 读取当前运行中的 Assistant 草稿。 */
53
- read_assistant_message(): Promise<SessionAssistantMessage | null>;
54
- /** 原子覆盖当前运行中的 Assistant 草稿。 */
55
- write_assistant_message(message: SessionAssistantMessage): Promise<void>;
56
- /** 在存储事务中创建唯一 Assistant 草稿。 */
57
- create_assistant_message(build_message: (state: SessionMessageCommitState) => SessionAssistantMessage): Promise<SessionAssistantMessage>;
58
- /** 在存储事务中追加一条 Message。 */
59
- append_message(build_message: (state: SessionMessageCommitState) => SessionMessage): Promise<SessionMessage>;
60
- /** 提交最终 Assistant Message 并删除运行中草稿。 */
61
- finalize_assistant_message(message: SessionAssistantMessage): Promise<void>;
62
- /** 将 Active 前缀压缩为不可变历史分段。 */
63
- compact_active(input: CompactActiveMessagesInput): Promise<CompactActiveMessagesResult>;
64
- /** 读取全部历史分段的 sequence 索引。 */
65
- list_segment_ranges(): Promise<SessionSegmentRange[]>;
66
- }
67
- /** 单个 Session 的领域持久化视图。 */
68
- export interface SessionDataStore {
69
- /** 当前 Session 的稳定标识。 */
70
- readonly session_id: string;
71
- /** 当前 Session 的创建来源与物理存储分区。 */
72
- readonly origin: SessionOrigin;
73
- /** 当前 Session 的 Message 持久化能力。 */
74
- readonly messages: SessionMessageStore;
75
- /** 当前 Session 的附件持久化能力。 */
76
- readonly attachments: SessionAttachmentStore;
77
- /** 读取 Session Metadata;不存在时返回规范化的初始值。 */
78
- read_metadata(): Promise<SessionHistoryMeta>;
79
- /** 原子写入完整 Session Metadata。 */
80
- write_metadata(metadata: SessionHistoryMeta): Promise<void>;
81
- /** 判断 Session 是否存在显式固化的完整 system。 */
82
- has_instruction(): Promise<boolean>;
83
- /** 读取显式固化的完整 system;不存在时返回 null。 */
84
- read_instruction(): Promise<string | null>;
85
- /** 原子写入显式固化的完整 system。 */
86
- write_instruction(instruction: string): Promise<void>;
87
- }
88
- //# sourceMappingURL=SessionDataStore.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SessionDataStore.d.ts","sourceRoot":"","sources":["../../../src/types/store/SessionDataStore.ts"],"names":[],"mappings":"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"}
@@ -1,9 +0,0 @@
1
- /**
2
- * 单个 Session 数据存储类型。
3
- *
4
- * 关键点(中文)
5
- * - Session 领域只依赖这些持久化能力,不感知 JSONL、目录或文件名。
6
- * - Message、Metadata 与 Instruction 共享同一个 Session 生命周期边界。
7
- */
8
- export {};
9
- //# sourceMappingURL=SessionDataStore.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SessionDataStore.js","sourceRoot":"","sources":["../../../src/types/store/SessionDataStore.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -1,17 +0,0 @@
1
- /**
2
- * 字符串模板渲染工具。
3
- *
4
- * 职责说明(中文)
5
- * - 提供统一的 `{{variable}}` 占位符替换能力。
6
- * - 供 init 模板与 runtime system prompt 渲染复用,避免重复实现。
7
- */
8
- import type { TemplateVariableMap } from "../types/common/Template.js";
9
- /**
10
- * 渲染模板中的 `{{variable}}` 占位符。
11
- *
12
- * 关键点(中文)
13
- * - 变量名支持字母、数字、下划线,且允许写成 `{{ key }}`。
14
- * - 未提供值的变量保持原样,便于排查模板与变量映射不一致问题。
15
- */
16
- export declare function render_template_variables(template: string, variables: TemplateVariableMap): string;
17
- //# sourceMappingURL=Template.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Template.d.ts","sourceRoot":"","sources":["../../src/utils/Template.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,mBAAmB,GAC7B,MAAM,CAOR"}
@@ -1,24 +0,0 @@
1
- /**
2
- * 字符串模板渲染工具。
3
- *
4
- * 职责说明(中文)
5
- * - 提供统一的 `{{variable}}` 占位符替换能力。
6
- * - 供 init 模板与 runtime system prompt 渲染复用,避免重复实现。
7
- */
8
- /**
9
- * 渲染模板中的 `{{variable}}` 占位符。
10
- *
11
- * 关键点(中文)
12
- * - 变量名支持字母、数字、下划线,且允许写成 `{{ key }}`。
13
- * - 未提供值的变量保持原样,便于排查模板与变量映射不一致问题。
14
- */
15
- export function render_template_variables(template, variables) {
16
- if (!template)
17
- return template;
18
- return template.replace(/\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/g, (match, key) => {
19
- return Object.prototype.hasOwnProperty.call(variables, key)
20
- ? String(variables[key])
21
- : match;
22
- });
23
- }
24
- //# sourceMappingURL=Template.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Template.js","sourceRoot":"","sources":["../../src/utils/Template.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CACvC,QAAgB,EAChB,SAA8B;IAE9B,IAAI,CAAC,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAC/B,OAAO,QAAQ,CAAC,OAAO,CAAC,gCAAgC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACvE,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,CAAC;YACzD,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACxB,CAAC,CAAC,KAAK,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,49 +0,0 @@
1
- /**
2
- * @file 验证 Session compact prompt 的结构化摘要格式。
3
- *
4
- * 关键点(中文)
5
- * - compact prompt 必须保持结构化摘要格式稳定。
6
- * - 迭代更新 prompt 需要携带 previous-summary 标签。
7
- */
8
-
9
- import test from "node:test";
10
- import assert from "node:assert/strict";
11
-
12
- import {
13
- SESSION_COMPACTION_SYSTEM_PROMPT,
14
- build_initial_session_compaction_prompt,
15
- build_turn_prefix_session_compaction_prompt,
16
- build_update_session_compaction_prompt,
17
- } from "../bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.js";
18
-
19
- test("session compaction prompts preserve structured formats", () => {
20
- assert.match(
21
- SESSION_COMPACTION_SYSTEM_PROMPT,
22
- /Do NOT continue the conversation/,
23
- );
24
-
25
- const initial_prompt = build_initial_session_compaction_prompt({
26
- conversation_text: "user: 请修改 packages/agent/src/foo.ts",
27
- });
28
- assert.match(initial_prompt, /## Goal/);
29
- assert.match(initial_prompt, /## Constraints & Preferences/);
30
- assert.match(initial_prompt, /## Critical Context/);
31
- assert.match(
32
- initial_prompt,
33
- /Keep each section concise\. Preserve exact file paths/,
34
- );
35
-
36
- const update_prompt = build_update_session_compaction_prompt({
37
- previous_summary: "## Goal\n旧目标",
38
- new_conversation_text: "assistant: 已完成一部分",
39
- });
40
- assert.match(update_prompt, /<previous-summary>\n## Goal\n旧目标\n<\/previous-summary>/);
41
- assert.match(update_prompt, /PRESERVE all existing information/);
42
- assert.match(update_prompt, /## Next Steps/);
43
-
44
- const prefix_prompt = build_turn_prefix_session_compaction_prompt({
45
- prefix_text: "user: 这个 turn 太长",
46
- });
47
- assert.match(prefix_prompt, /## Original Request/);
48
- assert.match(prefix_prompt, /## Context for Suffix/);
49
- });
@@ -1,162 +0,0 @@
1
- /**
2
- * JsonlSessionCompactionPrompts:上下文压缩提示词模块。
3
- *
4
- * 关键点(中文)
5
- * - 统一维护 session compact 使用的 system prompt 与 user prompt。
6
- * - 支持初始压缩、迭代更新压缩、turn prefix 压缩三类场景。
7
- * - prompt 文本保持结构化格式稳定,便于后续 LLM 继续接力。
8
- */
9
-
10
- /**
11
- * 上下文压缩 system prompt。
12
- */
13
- export const SESSION_COMPACTION_SYSTEM_PROMPT = [
14
- "You are a context summarization assistant. Your task is to read a conversation between a user and an AI assistant, then produce a structured summary following the exact format specified.",
15
- "",
16
- "Do NOT continue the conversation. Do NOT respond to any questions in the conversation. ONLY output the structured summary.",
17
- ].join("\n");
18
-
19
- /**
20
- * 构建初始上下文压缩 prompt。
21
- */
22
- export function build_initial_session_compaction_prompt(params: {
23
- /** 待压缩的历史对话文本。 */
24
- conversation_text: string;
25
- }): string {
26
- return [
27
- String(params.conversation_text || "").trim(),
28
- "",
29
- "The messages above are a conversation to summarize. Create a structured context checkpoint summary that another LLM will use to continue the work.",
30
- "",
31
- "Use this EXACT format:",
32
- "",
33
- "## Goal",
34
- "[What is the user trying to accomplish? Can be multiple items if the session covers different tasks.]",
35
- "",
36
- "## Constraints & Preferences",
37
- "- [Any constraints, preferences, or requirements mentioned by user]",
38
- '- [Or "(none)" if none were mentioned]',
39
- "",
40
- "## Progress",
41
- "### Done",
42
- "- [x] [Completed tasks/changes]",
43
- "",
44
- "### In Progress",
45
- "- [ ] [Current work]",
46
- "",
47
- "### Blocked",
48
- "[Issues preventing progress, if any]",
49
- "",
50
- "## Key Decisions",
51
- "- **[Decision]**: [Brief rationale]",
52
- "",
53
- "## Next Steps",
54
- "1. [Ordered list of what should happen next]",
55
- "",
56
- "## Critical Context",
57
- "- [Any data, examples, or references needed to continue]",
58
- '- [Or "(none)" if not applicable]',
59
- "",
60
- "Keep each section concise. Preserve exact file paths, function names, and error messages.",
61
- ].join("\n");
62
- }
63
-
64
- /**
65
- * 构建迭代更新上下文压缩 prompt。
66
- */
67
- export function build_update_session_compaction_prompt(params: {
68
- /** 已存在的旧摘要。 */
69
- previous_summary: string;
70
- /** 本次需要合入旧摘要的新对话文本。 */
71
- new_conversation_text: string;
72
- }): string {
73
- return [
74
- "<previous-summary>",
75
- String(params.previous_summary || "").trim(),
76
- "</previous-summary>",
77
- "",
78
- String(params.new_conversation_text || "").trim(),
79
- "",
80
- "The messages above are NEW conversation messages to incorporate into the existing summary provided in <previous-summary> tags.",
81
- "",
82
- "Update the existing structured summary with new information. RULES:",
83
- "- PRESERVE all existing information from the previous summary",
84
- "- ADD new progress, decisions, and context from the new messages",
85
- '- UPDATE the Progress section: move items from "In Progress" to "Done" when completed',
86
- '- UPDATE "Next Steps" based on what was accomplished',
87
- "- PRESERVE exact file paths, function names, and error messages",
88
- "- If something is no longer relevant, you may remove it",
89
- "",
90
- "Use this EXACT format:",
91
- "",
92
- "## Goal",
93
- "[Preserve existing goals, add new ones if the task expanded]",
94
- "",
95
- "## Constraints & Preferences",
96
- "- [Preserve existing, add new ones discovered]",
97
- "",
98
- "## Progress",
99
- "### Done",
100
- "- [x] [Include previously done items AND newly completed items]",
101
- "",
102
- "### In Progress",
103
- "- [ ] [Current work - update based on progress]",
104
- "",
105
- "### Blocked",
106
- "[Current blockers - remove if resolved]",
107
- "",
108
- "## Key Decisions",
109
- "- **[Decision]**: [Brief rationale] (preserve all previous, add new)",
110
- "",
111
- "## Next Steps",
112
- "1. [Update based on current state]",
113
- "",
114
- "## Critical Context",
115
- "- [Preserve important context, add new if needed]",
116
- "",
117
- "Keep each section concise. Preserve exact file paths, function names, and error messages.",
118
- ].join("\n");
119
- }
120
-
121
- /**
122
- * 构建 turn prefix 压缩 prompt。
123
- */
124
- export function build_turn_prefix_session_compaction_prompt(params: {
125
- /** 被切下来的 turn prefix 文本。 */
126
- prefix_text: string;
127
- }): string {
128
- return [
129
- String(params.prefix_text || "").trim(),
130
- "",
131
- "This is the PREFIX of a turn that was too large to keep. The SUFFIX (recent work) is retained.",
132
- "",
133
- "Summarize the prefix to provide context for the retained suffix:",
134
- "",
135
- "## Original Request",
136
- "[What did the user ask for in this turn?]",
137
- "",
138
- "## Early Progress",
139
- "- [Key decisions and work done in the prefix]",
140
- "",
141
- "## Context for Suffix",
142
- "- [Information needed to understand the retained recent work]",
143
- "",
144
- "Be concise. Focus on what's needed to understand the kept suffix.",
145
- ].join("\n");
146
- }
147
-
148
- /**
149
- * 给摘要追加文件操作 XML。
150
- */
151
- export function append_session_compaction_file_operations(params: {
152
- /** LLM 生成的结构化摘要。 */
153
- summary: string;
154
- /** 文件操作 XML,空字符串时不追加。 */
155
- file_operations_xml?: string;
156
- }): string {
157
- const summary = String(params.summary || "").trim();
158
- const file_operations_xml = String(params.file_operations_xml || "").trim();
159
- if (!file_operations_xml) return summary;
160
- if (!summary) return file_operations_xml;
161
- return `${summary}\n\n${file_operations_xml}`;
162
- }
@@ -1,25 +0,0 @@
1
- /**
2
- * SessionSystemComposer:Session system messages Composer 抽象。
3
- *
4
- * 关键点(中文)
5
- * - 专职负责“会话上下文 -> system messages”解析。
6
- * - 与 tools / step 编排解耦,避免 Executor 过载。
7
- */
8
-
9
- import type { SessionSystemMessage } from "@/executor/types/SessionPrompts.js";
10
- import type { SessionComposeInput } from "@/types/session/SessionComposer.js";
11
-
12
- /**
13
- * Session system Composer 协议。
14
- */
15
- export interface SessionSystemComposer {
16
- /**
17
- * 解析器名称(由具体实现声明)。
18
- */
19
- readonly name: string;
20
-
21
- /**
22
- * 解析本轮 system messages。
23
- */
24
- resolve(input: SessionComposeInput): Promise<SessionSystemMessage[]>;
25
- }
@@ -1,76 +0,0 @@
1
- /**
2
- * DefaultSessionSystemComposer:默认 system Composer。
3
- *
4
- * 关键点(中文)
5
- * - 该实现归属默认 system Composer,统一负责 Session system 解析入口。
6
- * - 具体“解析 / 加载 / 组装”下沉到 SystemDomain,保持类本身轻量。
7
- */
8
-
9
- import type {
10
- SessionSystemComposer,
11
- } from "@executor/composer/system/SessionSystemComposer.js";
12
- import type { SessionHookRuntime } from "@downcity/type";
13
- import type { SessionComposeInput } from "@/types/session/SessionComposer.js";
14
- import {
15
- resolve_session_system_messages,
16
- type SystemProfile,
17
- } from "@executor/composer/system/default/SystemDomain.js";
18
-
19
- type DefaultSessionSystemComposerOptions = {
20
- /**
21
- * 项目根目录,用于渲染运行时 system 模板。
22
- */
23
- project_root: string;
24
-
25
- /**
26
- * 读取当前生效的静态 system 文本集合。
27
- */
28
- get_static_system_prompts: () => string[];
29
-
30
- /**
31
- * 读取当前执行上下文(用于加载 Plugin system 文本)。
32
- */
33
- get_hooks: () => SessionHookRuntime;
34
-
35
- /**
36
- * system 档位(默认 chat)。
37
- */
38
- profile?: SystemProfile;
39
- };
40
-
41
- /**
42
- * SessionSystemComposer 默认实现。
43
- */
44
- export class DefaultSessionSystemComposer implements SessionSystemComposer {
45
- readonly name = "prompt_system";
46
-
47
- private readonly project_root: string;
48
- private readonly get_static_system_prompts: DefaultSessionSystemComposerOptions["get_static_system_prompts"];
49
- private readonly get_hooks: DefaultSessionSystemComposerOptions["get_hooks"];
50
- private readonly profile: SystemProfile;
51
-
52
- constructor(options: DefaultSessionSystemComposerOptions) {
53
- const project_root = String(options.project_root || "").trim();
54
- if (!project_root) {
55
- throw new Error("DefaultSessionSystemComposer requires a non-empty project_root");
56
- }
57
- this.project_root = project_root;
58
- this.get_static_system_prompts = options.get_static_system_prompts;
59
- this.get_hooks = options.get_hooks;
60
- this.profile = options.profile === "task" ? "task" : "chat";
61
- }
62
-
63
- async resolve(input: SessionComposeInput) {
64
- const session_id = input.session.session_id;
65
- if (!session_id) {
66
- throw new Error("DefaultSessionSystemComposer.resolve requires a non-empty session_id");
67
- }
68
- return await resolve_session_system_messages({
69
- project_root: this.project_root,
70
- session_id,
71
- profile: this.profile,
72
- static_system_prompts: this.get_static_system_prompts(),
73
- hooks: this.get_hooks(),
74
- });
75
- }
76
- }
@@ -1,52 +0,0 @@
1
- /**
2
- * PromptRenderer:system prompt 消息渲染器。
3
- *
4
- * 关键点(中文)
5
- * - 负责文本 prompt -> system message 的转换能力。
6
- * - 变量替换下沉到 `session/composer/system/default/variables/VariableReplacer`。
7
- * - 不关注具体 prompt 来源(静态/服务/运行时)。
8
- */
9
-
10
- import type { SessionSystemMessage } from "@/executor/types/SessionPrompts.js";
11
- import {
12
- replace_variables_in_prompts,
13
- type PromptVariableMode,
14
- } from "@executor/composer/system/default/variables/VariableReplacer.js";
15
-
16
- /**
17
- * 将纯文本 prompts 转为 `system` messages。
18
- *
19
- * 关键点(中文)
20
- * - 自动过滤空串并执行变量替换。
21
- */
22
- export async function transform_prompts_into_system_messages(
23
- prompts: string[],
24
- options?: {
25
- /**
26
- * 项目路径(用于模板变量)。
27
- */
28
- projectPath?: string;
29
-
30
- /**
31
- * 会话 ID(用于模板变量)。
32
- */
33
- session_id?: string;
34
-
35
- /**
36
- * 变量替换模式。
37
- *
38
- * 关键点(中文)
39
- * - `full`:替换全部变量(含时间/位置)。
40
- * - `stable`:仅保留稳定变量,易变变量替换为稳定占位文本。
41
- */
42
- variableMode?: PromptVariableMode;
43
- },
44
- ): Promise<SessionSystemMessage[]> {
45
- const nonEmptyPrompts = prompts.filter((item) => item.length > 0);
46
- return Promise.all(
47
- nonEmptyPrompts.map(async (item) => ({
48
- role: "system" as const,
49
- content: await replace_variables_in_prompts(item, options),
50
- })),
51
- );
52
- }