@downcity/agent 1.1.437 → 1.1.445

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 (702) hide show
  1. package/README.md +25 -18
  2. package/bin/agent/Agent.d.ts +44 -20
  3. package/bin/agent/Agent.d.ts.map +1 -1
  4. package/bin/agent/Agent.js +114 -69
  5. package/bin/agent/Agent.js.map +1 -1
  6. package/bin/agent/AgentInstructions.d.ts +18 -4
  7. package/bin/agent/AgentInstructions.d.ts.map +1 -1
  8. package/bin/agent/AgentInstructions.js +33 -14
  9. package/bin/agent/AgentInstructions.js.map +1 -1
  10. package/bin/agent/AgentMemoryStorage.d.ts +1 -1
  11. package/bin/agent/AgentMemoryStorage.d.ts.map +1 -1
  12. package/bin/agent/AgentMemoryStorage.js.map +1 -1
  13. package/bin/agent/AgentSessions.d.ts +29 -16
  14. package/bin/agent/AgentSessions.d.ts.map +1 -1
  15. package/bin/agent/AgentSessions.js +42 -22
  16. package/bin/agent/AgentSessions.js.map +1 -1
  17. package/bin/group/Group.d.ts +13 -12
  18. package/bin/group/Group.d.ts.map +1 -1
  19. package/bin/group/Group.js +24 -23
  20. package/bin/group/Group.js.map +1 -1
  21. package/bin/group/GroupSession.d.ts.map +1 -1
  22. package/bin/group/GroupSession.js +13 -9
  23. package/bin/group/GroupSession.js.map +1 -1
  24. package/bin/group/GroupSessions.d.ts +27 -2
  25. package/bin/group/GroupSessions.d.ts.map +1 -1
  26. package/bin/group/GroupSessions.js +68 -21
  27. package/bin/group/GroupSessions.js.map +1 -1
  28. package/bin/group/storage/LocalGroupSessionDataStore.d.ts +8 -0
  29. package/bin/group/storage/LocalGroupSessionDataStore.d.ts.map +1 -1
  30. package/bin/group/storage/LocalGroupSessionDataStore.js +1 -1
  31. package/bin/group/storage/LocalGroupSessionDataStore.js.map +1 -1
  32. package/bin/group/storage/LocalGroupSessionStore.d.ts +64 -5
  33. package/bin/group/storage/LocalGroupSessionStore.d.ts.map +1 -1
  34. package/bin/group/storage/LocalGroupSessionStore.js +114 -23
  35. package/bin/group/storage/LocalGroupSessionStore.js.map +1 -1
  36. package/bin/index.d.ts +25 -30
  37. package/bin/index.d.ts.map +1 -1
  38. package/bin/index.js +14 -14
  39. package/bin/index.js.map +1 -1
  40. package/bin/{executor/model → model}/ModelGenerate.d.ts +1 -1
  41. package/bin/model/ModelGenerate.d.ts.map +1 -0
  42. package/bin/model/ModelGenerate.js.map +1 -0
  43. package/bin/{executor/model → model}/ModelRequestRunner.d.ts +1 -1
  44. package/bin/model/ModelRequestRunner.d.ts.map +1 -0
  45. package/bin/model/ModelRequestRunner.js.map +1 -0
  46. package/bin/{executor/model → model}/ModelStepRunner.d.ts +6 -7
  47. package/bin/model/ModelStepRunner.d.ts.map +1 -0
  48. package/bin/{executor/model → model}/ModelStepRunner.js +16 -10
  49. package/bin/model/ModelStepRunner.js.map +1 -0
  50. package/bin/model/ModelStreamConsumer.d.ts.map +1 -0
  51. package/bin/model/ModelStreamConsumer.js.map +1 -0
  52. package/bin/model/ModelStreamFailure.d.ts.map +1 -0
  53. package/bin/model/ModelStreamFailure.js.map +1 -0
  54. package/bin/model/ToolInputValidation.d.ts +28 -0
  55. package/bin/model/ToolInputValidation.d.ts.map +1 -0
  56. package/bin/model/ToolInputValidation.js +37 -0
  57. package/bin/model/ToolInputValidation.js.map +1 -0
  58. package/bin/model/messages/ChatMessageMarkup.d.ts.map +1 -0
  59. package/bin/model/messages/ChatMessageMarkup.js.map +1 -0
  60. package/bin/{executor → model}/messages/ChatMessageMarkupTypes.d.ts +1 -1
  61. package/bin/model/messages/ChatMessageMarkupTypes.d.ts.map +1 -0
  62. package/bin/{executor → model}/messages/ChatMessageMarkupTypes.js +1 -1
  63. package/bin/model/messages/ChatMessageMarkupTypes.js.map +1 -0
  64. package/bin/model/messages/SessionAttachmentMapper.d.ts.map +1 -0
  65. package/bin/model/messages/SessionAttachmentMapper.js.map +1 -0
  66. package/bin/model/messages/SessionMessageLog.d.ts.map +1 -0
  67. package/bin/model/messages/SessionMessageLog.js.map +1 -0
  68. package/bin/model/messages/SessionModelMessages.d.ts.map +1 -0
  69. package/bin/{executor → model}/messages/SessionModelMessages.js +0 -1
  70. package/bin/model/messages/SessionModelMessages.js.map +1 -0
  71. package/bin/model/prompts/SystemPromptAssets.d.ts.map +1 -0
  72. package/bin/{executor/composer/system/default → model/prompts}/SystemPromptAssets.js +1 -1
  73. package/bin/model/prompts/SystemPromptAssets.js.map +1 -0
  74. package/bin/model/prompts/assets/core.prompt.d.ts +7 -0
  75. package/bin/model/prompts/assets/core.prompt.d.ts.map +1 -0
  76. package/bin/model/prompts/assets/core.prompt.js +8 -0
  77. package/bin/model/prompts/assets/core.prompt.js.map +1 -0
  78. package/bin/session/Session.d.ts +29 -17
  79. package/bin/session/Session.d.ts.map +1 -1
  80. package/bin/session/Session.js +161 -134
  81. package/bin/session/Session.js.map +1 -1
  82. package/bin/session/input/SessionHookRunner.d.ts +52 -0
  83. package/bin/session/input/SessionHookRunner.d.ts.map +1 -0
  84. package/bin/session/input/SessionHookRunner.js +51 -0
  85. package/bin/session/input/SessionHookRunner.js.map +1 -0
  86. package/bin/session/input/SessionSystem.d.ts +26 -0
  87. package/bin/session/input/SessionSystem.d.ts.map +1 -0
  88. package/bin/session/{SessionSystem.js → input/SessionSystem.js} +27 -23
  89. package/bin/session/input/SessionSystem.js.map +1 -0
  90. package/bin/session/input/StepInput.d.ts +77 -0
  91. package/bin/session/input/StepInput.d.ts.map +1 -0
  92. package/bin/session/input/StepInput.js +429 -0
  93. package/bin/session/input/StepInput.js.map +1 -0
  94. package/bin/session/input/composer/AdaptiveContextCheckpoint.d.ts +33 -0
  95. package/bin/session/input/composer/AdaptiveContextCheckpoint.d.ts.map +1 -0
  96. package/bin/session/input/composer/AdaptiveContextCheckpoint.js +83 -0
  97. package/bin/session/input/composer/AdaptiveContextCheckpoint.js.map +1 -0
  98. package/bin/session/input/composer/AdaptiveContextParts.d.ts +26 -0
  99. package/bin/session/input/composer/AdaptiveContextParts.d.ts.map +1 -0
  100. package/bin/session/input/composer/AdaptiveContextParts.js +124 -0
  101. package/bin/session/input/composer/AdaptiveContextParts.js.map +1 -0
  102. package/bin/session/input/composer/ComposerAssembly.d.ts +21 -0
  103. package/bin/session/input/composer/ComposerAssembly.d.ts.map +1 -0
  104. package/bin/session/input/composer/ComposerAssembly.js +64 -0
  105. package/bin/session/input/composer/ComposerAssembly.js.map +1 -0
  106. package/bin/session/{composer/policies/SessionSummaryPrompts.d.ts → input/composer/ContextSummaryPrompts.d.ts} +5 -3
  107. package/bin/session/input/composer/ContextSummaryPrompts.d.ts.map +1 -0
  108. package/bin/session/{composer/policies/SessionSummaryPrompts.js → input/composer/ContextSummaryPrompts.js} +5 -3
  109. package/bin/session/input/composer/ContextSummaryPrompts.js.map +1 -0
  110. package/bin/session/input/composer/DefaultSessionComposer.d.ts +24 -0
  111. package/bin/session/input/composer/DefaultSessionComposer.d.ts.map +1 -0
  112. package/bin/session/input/composer/DefaultSessionComposer.js +108 -0
  113. package/bin/session/input/composer/DefaultSessionComposer.js.map +1 -0
  114. package/bin/session/input/composer/FullHistorySessionComposer.d.ts +19 -0
  115. package/bin/session/input/composer/FullHistorySessionComposer.d.ts.map +1 -0
  116. package/bin/session/input/composer/FullHistorySessionComposer.js +36 -0
  117. package/bin/session/input/composer/FullHistorySessionComposer.js.map +1 -0
  118. package/bin/session/{SessionLoop.d.ts → loop/SessionLoop.d.ts} +34 -7
  119. package/bin/session/loop/SessionLoop.d.ts.map +1 -0
  120. package/bin/session/{SessionLoop.js → loop/SessionLoop.js} +79 -16
  121. package/bin/session/loop/SessionLoop.js.map +1 -0
  122. package/bin/session/{SessionQueue.d.ts → loop/SessionQueue.d.ts} +9 -1
  123. package/bin/session/loop/SessionQueue.d.ts.map +1 -0
  124. package/bin/session/{SessionQueue.js → loop/SessionQueue.js} +19 -0
  125. package/bin/session/loop/SessionQueue.js.map +1 -0
  126. package/bin/session/{SessionState.d.ts → loop/SessionState.d.ts} +4 -5
  127. package/bin/session/loop/SessionState.d.ts.map +1 -0
  128. package/bin/session/{SessionState.js → loop/SessionState.js} +6 -25
  129. package/bin/session/loop/SessionState.js.map +1 -0
  130. package/bin/session/{SessionTitle.d.ts → loop/SessionTitle.d.ts} +4 -4
  131. package/bin/session/loop/SessionTitle.d.ts.map +1 -0
  132. package/bin/session/{SessionTitle.js → loop/SessionTitle.js} +3 -3
  133. package/bin/session/loop/SessionTitle.js.map +1 -0
  134. package/bin/session/loop/SessionTitleTask.d.ts.map +1 -0
  135. package/bin/session/loop/SessionTitleTask.js.map +1 -0
  136. package/bin/session/{runtime → loop}/SessionTurnCompletion.d.ts +7 -0
  137. package/bin/session/loop/SessionTurnCompletion.d.ts.map +1 -0
  138. package/bin/session/{runtime → loop}/SessionTurnCompletion.js +25 -6
  139. package/bin/session/loop/SessionTurnCompletion.js.map +1 -0
  140. package/bin/session/loop/SessionTurnContext.d.ts +12 -0
  141. package/bin/session/loop/SessionTurnContext.d.ts.map +1 -0
  142. package/bin/session/{runtime → loop}/SessionTurnContext.js +14 -67
  143. package/bin/session/loop/SessionTurnContext.js.map +1 -0
  144. package/bin/session/loop/SessionTurnFileDiff.d.ts.map +1 -0
  145. package/bin/session/{runtime → loop}/SessionTurnFileDiff.js +1 -1
  146. package/bin/session/loop/SessionTurnFileDiff.js.map +1 -0
  147. package/bin/session/{messages → loop}/SessionTurnFileDiffBuilder.d.ts +3 -3
  148. package/bin/session/loop/SessionTurnFileDiffBuilder.d.ts.map +1 -0
  149. package/bin/session/loop/SessionTurnFileDiffBuilder.js.map +1 -0
  150. package/bin/session/messages/ApprovalInteraction.d.ts +30 -0
  151. package/bin/session/messages/ApprovalInteraction.d.ts.map +1 -0
  152. package/bin/session/messages/ApprovalInteraction.js +61 -0
  153. package/bin/session/messages/ApprovalInteraction.js.map +1 -0
  154. package/bin/session/messages/SessionAgentMessageState.d.ts +47 -18
  155. package/bin/session/messages/SessionAgentMessageState.d.ts.map +1 -1
  156. package/bin/session/messages/SessionAgentMessageState.js +224 -86
  157. package/bin/session/messages/SessionAgentMessageState.js.map +1 -1
  158. package/bin/session/messages/SessionAgentMessageWriter.d.ts +15 -4
  159. package/bin/session/messages/SessionAgentMessageWriter.d.ts.map +1 -1
  160. package/bin/session/messages/SessionAgentMessageWriter.js +57 -37
  161. package/bin/session/messages/SessionAgentMessageWriter.js.map +1 -1
  162. package/bin/session/messages/SessionAgentParts.d.ts +14 -0
  163. package/bin/session/messages/SessionAgentParts.d.ts.map +1 -0
  164. package/bin/session/messages/SessionAgentParts.js +20 -0
  165. package/bin/session/messages/SessionAgentParts.js.map +1 -0
  166. package/bin/session/{execution → messages}/SessionAssistantOutputAdapter.d.ts +2 -2
  167. package/bin/session/messages/SessionAssistantOutputAdapter.d.ts.map +1 -0
  168. package/bin/session/messages/SessionAssistantOutputAdapter.js.map +1 -0
  169. package/bin/session/messages/SessionEventHub.d.ts.map +1 -0
  170. package/bin/session/messages/SessionEventHub.js.map +1 -0
  171. package/bin/session/messages/SessionInteractions.d.ts +57 -0
  172. package/bin/session/messages/SessionInteractions.d.ts.map +1 -0
  173. package/bin/session/messages/SessionInteractions.js +178 -0
  174. package/bin/session/messages/SessionInteractions.js.map +1 -0
  175. package/bin/session/messages/SessionJsonValue.d.ts +1 -3
  176. package/bin/session/messages/SessionJsonValue.d.ts.map +1 -1
  177. package/bin/session/messages/SessionJsonValue.js +0 -19
  178. package/bin/session/messages/SessionJsonValue.js.map +1 -1
  179. package/bin/session/messages/SessionMessageCache.d.ts +55 -0
  180. package/bin/session/messages/SessionMessageCache.d.ts.map +1 -0
  181. package/bin/session/messages/SessionMessageCache.js +133 -0
  182. package/bin/session/messages/SessionMessageCache.js.map +1 -0
  183. package/bin/session/messages/SessionMessageState.d.ts +17 -0
  184. package/bin/session/messages/SessionMessageState.d.ts.map +1 -0
  185. package/bin/session/messages/SessionMessageState.js +34 -0
  186. package/bin/session/messages/SessionMessageState.js.map +1 -0
  187. package/bin/session/messages/SessionMessageTimeline.d.ts.map +1 -0
  188. package/bin/session/{browse → messages}/SessionMessageTimeline.js +0 -1
  189. package/bin/session/messages/SessionMessageTimeline.js.map +1 -0
  190. package/bin/session/{SessionMessages.d.ts → messages/SessionMessages.d.ts} +35 -43
  191. package/bin/session/messages/SessionMessages.d.ts.map +1 -0
  192. package/bin/session/{SessionMessages.js → messages/SessionMessages.js} +178 -196
  193. package/bin/session/messages/SessionMessages.js.map +1 -0
  194. package/bin/session/messages/SessionModelRequestWarning.d.ts.map +1 -0
  195. package/bin/session/messages/SessionModelRequestWarning.js.map +1 -0
  196. package/bin/session/messages/SessionMutationFactory.d.ts +26 -0
  197. package/bin/session/messages/SessionMutationFactory.d.ts.map +1 -0
  198. package/bin/session/messages/SessionMutationFactory.js +38 -0
  199. package/bin/session/messages/SessionMutationFactory.js.map +1 -0
  200. package/bin/session/messages/SessionUserMessage.d.ts +5 -7
  201. package/bin/session/messages/SessionUserMessage.d.ts.map +1 -1
  202. package/bin/session/messages/SessionUserMessage.js +5 -28
  203. package/bin/session/messages/SessionUserMessage.js.map +1 -1
  204. package/bin/{executor/core-engine/CoreEngineSignals.d.ts → session/runner/AssistantParts.d.ts} +4 -9
  205. package/bin/session/runner/AssistantParts.d.ts.map +1 -0
  206. package/bin/{executor/core-engine/CoreEngineSignals.js → session/runner/AssistantParts.js} +4 -17
  207. package/bin/session/runner/AssistantParts.js.map +1 -0
  208. package/bin/session/runner/ContextPressure.d.ts +15 -0
  209. package/bin/session/runner/ContextPressure.d.ts.map +1 -0
  210. package/bin/{executor/core-engine/CoreEngineContextCompaction.js → session/runner/ContextPressure.js} +11 -11
  211. package/bin/session/runner/ContextPressure.js.map +1 -0
  212. package/bin/session/runner/ContextRetry.d.ts +39 -0
  213. package/bin/session/runner/ContextRetry.d.ts.map +1 -0
  214. package/bin/{executor/services/ExecutorRecoveryPolicy.js → session/runner/ContextRetry.js} +19 -19
  215. package/bin/session/runner/ContextRetry.js.map +1 -0
  216. package/bin/{executor/core-engine/CoreEngineError.d.ts → session/runner/ModelFailure.d.ts} +4 -4
  217. package/bin/session/runner/ModelFailure.d.ts.map +1 -0
  218. package/bin/{executor/core-engine/CoreEngineError.js → session/runner/ModelFailure.js} +4 -4
  219. package/bin/session/runner/ModelFailure.js.map +1 -0
  220. package/bin/session/runner/SessionExecutor.d.ts +108 -0
  221. package/bin/session/runner/SessionExecutor.d.ts.map +1 -0
  222. package/bin/session/runner/SessionExecutor.js +430 -0
  223. package/bin/session/runner/SessionExecutor.js.map +1 -0
  224. package/bin/session/runner/ToolLoopDecision.d.ts +60 -0
  225. package/bin/session/runner/ToolLoopDecision.d.ts.map +1 -0
  226. package/bin/{executor/core-engine/CoreEngineLoopDecision.js → session/runner/ToolLoopDecision.js} +5 -5
  227. package/bin/session/runner/ToolLoopDecision.js.map +1 -0
  228. package/bin/session/runner/ToolLoopLimits.d.ts +30 -0
  229. package/bin/session/runner/ToolLoopLimits.d.ts.map +1 -0
  230. package/bin/session/runner/ToolLoopLimits.js +46 -0
  231. package/bin/session/runner/ToolLoopLimits.js.map +1 -0
  232. package/bin/session/{browse → storage}/Browse.d.ts +1 -1
  233. package/bin/session/storage/Browse.d.ts.map +1 -0
  234. package/bin/session/{browse → storage}/Browse.js +1 -1
  235. package/bin/session/storage/Browse.js.map +1 -0
  236. package/bin/session/storage/LocalSessionStore.js +1 -1
  237. package/bin/session/storage/LocalSessionStore.js.map +1 -1
  238. package/bin/session/storage/LocalStorePaths.d.ts +0 -2
  239. package/bin/session/storage/LocalStorePaths.d.ts.map +1 -1
  240. package/bin/session/storage/LocalStorePaths.js +1 -1
  241. package/bin/session/storage/LocalStorePaths.js.map +1 -1
  242. package/bin/session/storage/Metadata.d.ts +1 -23
  243. package/bin/session/storage/Metadata.d.ts.map +1 -1
  244. package/bin/session/storage/Metadata.js +0 -18
  245. package/bin/session/storage/Metadata.js.map +1 -1
  246. package/bin/session/storage/RuntimeSessionPort.d.ts +0 -4
  247. package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
  248. package/bin/session/storage/RuntimeSessionPort.js +0 -1
  249. package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
  250. package/bin/session/{preview → storage}/SessionMessagePreview.d.ts.map +1 -1
  251. package/bin/session/{preview → storage}/SessionMessagePreview.js +0 -1
  252. package/bin/session/{preview → storage}/SessionMessagePreview.js.map +1 -1
  253. package/bin/session/storage/SessionStorageCodec.d.ts.map +1 -1
  254. package/bin/session/storage/SessionStorageCodec.js +36 -18
  255. package/bin/session/storage/SessionStorageCodec.js.map +1 -1
  256. package/bin/session/storage/SessionStorageSchema.d.ts +1 -1
  257. package/bin/session/storage/SessionStorageSchema.js +1 -1
  258. package/bin/session/storage/SqliteSessionStorage.d.ts +6 -4
  259. package/bin/session/storage/SqliteSessionStorage.d.ts.map +1 -1
  260. package/bin/session/storage/SqliteSessionStorage.js +21 -18
  261. package/bin/session/storage/SqliteSessionStorage.js.map +1 -1
  262. package/bin/tools/ask/AskQuestionAnswers.d.ts +20 -0
  263. package/bin/tools/ask/AskQuestionAnswers.d.ts.map +1 -0
  264. package/bin/tools/ask/AskQuestionAnswers.js +99 -0
  265. package/bin/tools/ask/AskQuestionAnswers.js.map +1 -0
  266. package/bin/tools/ask/AskQuestionsTool.d.ts +5 -2
  267. package/bin/tools/ask/AskQuestionsTool.d.ts.map +1 -1
  268. package/bin/tools/ask/AskQuestionsTool.js +23 -31
  269. package/bin/tools/ask/AskQuestionsTool.js.map +1 -1
  270. package/bin/tools/ask/AskQuestionsToolSchemas.d.ts +1 -1
  271. package/bin/types/agent/AgentOptions.d.ts +16 -8
  272. package/bin/types/agent/AgentOptions.d.ts.map +1 -1
  273. package/bin/types/agent/AgentSessionCollection.d.ts +8 -0
  274. package/bin/types/agent/AgentSessionCollection.d.ts.map +1 -1
  275. package/bin/types/agent/SessionActor.d.ts +3 -3
  276. package/bin/types/agent/SessionActor.d.ts.map +1 -1
  277. package/bin/types/group/DispatchStrategy.js +1 -1
  278. package/bin/types/group/DispatchStrategy.js.map +1 -1
  279. package/bin/types/group/GroupSession.d.ts +41 -1
  280. package/bin/types/group/GroupSession.d.ts.map +1 -1
  281. package/bin/types/group/GroupSessionStore.d.ts +30 -3
  282. package/bin/types/group/GroupSessionStore.d.ts.map +1 -1
  283. package/bin/types/model/ModelRequest.d.ts.map +1 -0
  284. package/bin/types/model/ModelRequest.js.map +1 -0
  285. package/bin/types/sdk/AgentSessionAction.d.ts +1 -9
  286. package/bin/types/sdk/AgentSessionAction.d.ts.map +1 -1
  287. package/bin/types/session/{AdaptivePartContextPolicy.d.ts → ContextCheckpoint.d.ts} +10 -9
  288. package/bin/types/session/ContextCheckpoint.d.ts.map +1 -0
  289. package/bin/types/session/ContextCheckpoint.js +8 -0
  290. package/bin/types/session/ContextCheckpoint.js.map +1 -0
  291. package/bin/types/session/SessionAgentMessageState.d.ts +6 -10
  292. package/bin/types/session/SessionAgentMessageState.d.ts.map +1 -1
  293. package/bin/types/session/SessionAgentMessageState.js +3 -2
  294. package/bin/types/session/SessionAgentMessageState.js.map +1 -1
  295. package/bin/types/session/SessionComposer.d.ts +65 -36
  296. package/bin/types/session/SessionComposer.d.ts.map +1 -1
  297. package/bin/types/session/SessionComposer.js +7 -2
  298. package/bin/types/session/SessionComposer.js.map +1 -1
  299. package/bin/types/session/SessionExecution.d.ts +15 -11
  300. package/bin/types/session/SessionExecution.d.ts.map +1 -1
  301. package/bin/types/session/SessionExecution.js +1 -1
  302. package/bin/types/session/SessionInteractions.d.ts +0 -2
  303. package/bin/types/session/SessionInteractions.d.ts.map +1 -1
  304. package/bin/types/session/SessionLocalState.d.ts +0 -4
  305. package/bin/types/session/SessionLocalState.d.ts.map +1 -1
  306. package/bin/types/session/SessionLoop.d.ts +33 -12
  307. package/bin/types/session/SessionLoop.d.ts.map +1 -1
  308. package/bin/types/session/SessionMessages.d.ts +3 -29
  309. package/bin/types/session/SessionMessages.d.ts.map +1 -1
  310. package/bin/types/session/SessionOptions.d.ts +16 -13
  311. package/bin/types/session/SessionOptions.d.ts.map +1 -1
  312. package/bin/types/session/SessionPort.d.ts +0 -3
  313. package/bin/types/session/SessionPort.d.ts.map +1 -1
  314. package/bin/types/session/SessionState.d.ts +0 -1
  315. package/bin/types/session/SessionState.d.ts.map +1 -1
  316. package/bin/types/session/SessionSystem.d.ts +10 -12
  317. package/bin/types/session/SessionSystem.d.ts.map +1 -1
  318. package/bin/types/session/SessionTool.d.ts +2 -2
  319. package/bin/types/session/SessionTool.d.ts.map +1 -1
  320. package/bin/types/session/SessionTurnCompletion.d.ts +12 -2
  321. package/bin/types/session/SessionTurnCompletion.d.ts.map +1 -1
  322. package/bin/types/session/SessionTurnFileDiff.d.ts +4 -4
  323. package/bin/types/session/SessionTurnFileDiff.d.ts.map +1 -1
  324. package/bin/types/session/{SessionComposition.d.ts → StepInput.d.ts} +17 -15
  325. package/bin/types/session/StepInput.d.ts.map +1 -0
  326. package/bin/types/session/StepInput.js +8 -0
  327. package/bin/types/session/StepInput.js.map +1 -0
  328. package/bin/types/store/SessionHistoryMeta.d.ts.map +1 -0
  329. package/bin/types/store/SessionHistoryMeta.js.map +1 -0
  330. package/bin/types/store/SessionStorage.d.ts +17 -12
  331. package/bin/types/store/SessionStorage.d.ts.map +1 -1
  332. package/bin/types/tool/BoundAgentTool.d.ts +36 -0
  333. package/bin/types/tool/BoundAgentTool.d.ts.map +1 -0
  334. package/bin/types/tool/BoundAgentTool.js +13 -0
  335. package/bin/types/tool/BoundAgentTool.js.map +1 -0
  336. package/bin/types/tools/ask/AskQuestionsTool.d.ts +9 -13
  337. package/bin/types/tools/ask/AskQuestionsTool.d.ts.map +1 -1
  338. package/bin/types/tools/ask/AskQuestionsTool.js +3 -2
  339. package/bin/types/tools/ask/AskQuestionsTool.js.map +1 -1
  340. package/bin/types/turn/SessionAssistantOutput.d.ts.map +1 -0
  341. package/bin/types/turn/SessionAssistantOutput.js.map +1 -0
  342. package/bin/types/{executor → turn}/SessionTurnContext.d.ts +10 -28
  343. package/bin/types/turn/SessionTurnContext.d.ts.map +1 -0
  344. package/bin/types/turn/SessionTurnContext.js.map +1 -0
  345. package/bin/{executor/ids/resolveSessionId.d.ts → utils/ResolveSessionId.d.ts} +1 -1
  346. package/bin/utils/ResolveSessionId.d.ts.map +1 -0
  347. package/bin/{executor/ids/resolveSessionId.js → utils/ResolveSessionId.js} +1 -1
  348. package/bin/utils/ResolveSessionId.js.map +1 -0
  349. package/bin/utils/Time.d.ts +5 -8
  350. package/bin/utils/Time.d.ts.map +1 -1
  351. package/bin/utils/Time.js +5 -54
  352. package/bin/utils/Time.js.map +1 -1
  353. package/package.json +2 -2
  354. package/scripts/ask-question-answers.test.mjs +132 -0
  355. package/scripts/group-session-archive.test.mjs +193 -0
  356. package/scripts/{core-engine-model-stream.test.mjs → model-step-runner.test.mjs} +97 -4
  357. package/scripts/rewrite-build-aliases.mjs +3 -4
  358. package/scripts/session-action-part.test.mjs +172 -0
  359. package/scripts/session-agent-message-part-order.test.mjs +13 -7
  360. package/scripts/{core-engine-context-compaction.test.mjs → session-executor-context-pressure.test.mjs} +40 -32
  361. package/scripts/{executor-failure-result.test.mjs → session-executor-failure-result.test.mjs} +17 -14
  362. package/scripts/session-executor-max-steps.test.mjs +143 -0
  363. package/scripts/session-initialization.test.mjs +3 -4
  364. package/scripts/session-interaction-migration.test.mjs +145 -0
  365. package/scripts/session-interaction-mutation.test.mjs +202 -0
  366. package/scripts/session-messages-error-part.test.mjs +1 -1
  367. package/scripts/session-messages-error.test.mjs +1 -1
  368. package/scripts/session-prompt-idempotency.test.mjs +4 -2
  369. package/scripts/session-queue.test.mjs +21 -1
  370. package/scripts/session-storage-sqlite.test.mjs +3 -3
  371. package/scripts/session-system-blocks.test.mjs +61 -39
  372. package/scripts/session-turn-context.test.mjs +37 -40
  373. package/scripts/verify-build-aliases.mjs +1 -1
  374. package/src/agent/Agent.ts +137 -80
  375. package/src/agent/AgentInstructions.ts +48 -15
  376. package/src/agent/AgentMemoryStorage.ts +1 -1
  377. package/src/agent/AgentSessions.ts +60 -38
  378. package/src/group/Group.ts +27 -24
  379. package/src/group/GroupSession.ts +12 -8
  380. package/src/group/GroupSessions.ts +79 -20
  381. package/src/group/storage/LocalGroupSessionDataStore.ts +9 -1
  382. package/src/group/storage/LocalGroupSessionStore.ts +138 -28
  383. package/src/index.ts +35 -52
  384. package/src/{executor/model → model}/ModelGenerate.ts +3 -3
  385. package/src/{executor/model → model}/ModelRequestRunner.ts +2 -2
  386. package/src/{executor/model → model}/ModelStepRunner.ts +22 -19
  387. package/src/{executor/model → model}/ModelStreamConsumer.ts +1 -1
  388. package/src/model/README.md +117 -0
  389. package/src/model/ToolInputValidation.ts +58 -0
  390. package/src/{executor → model}/messages/ChatMessageMarkupTypes.ts +1 -1
  391. package/src/{executor → model}/messages/SessionModelMessages.ts +0 -1
  392. package/src/{executor/composer/system/default → model/prompts}/SystemPromptAssets.ts +1 -1
  393. package/src/model/prompts/assets/core.prompt.ts +9 -0
  394. package/src/{executor/composer/system/default → model/prompts}/assets/core.prompt.ts.txt +26 -25
  395. package/src/session/Session.ts +185 -151
  396. package/src/session/input/SessionHookRunner.ts +100 -0
  397. package/src/session/{SessionSystem.ts → input/SessionSystem.ts} +31 -29
  398. package/src/session/input/StepInput.ts +507 -0
  399. package/src/session/input/composer/AdaptiveContextCheckpoint.ts +115 -0
  400. package/src/session/input/composer/AdaptiveContextParts.ts +166 -0
  401. package/src/session/input/composer/ComposerAssembly.ts +81 -0
  402. package/src/session/{composer/policies/SessionSummaryPrompts.ts → input/composer/ContextSummaryPrompts.ts} +5 -2
  403. package/src/session/input/composer/DefaultSessionComposer.ts +147 -0
  404. package/src/session/input/composer/FullHistorySessionComposer.ts +55 -0
  405. package/src/session/loop/README.md +28 -0
  406. package/src/session/{SessionLoop.ts → loop/SessionLoop.ts} +100 -24
  407. package/src/session/{SessionQueue.ts → loop/SessionQueue.ts} +18 -0
  408. package/src/session/{SessionState.ts → loop/SessionState.ts} +4 -21
  409. package/src/session/{SessionTitle.ts → loop/SessionTitle.ts} +3 -3
  410. package/src/session/{runtime → loop}/SessionTurnCompletion.ts +27 -8
  411. package/src/session/{runtime → loop}/SessionTurnContext.ts +19 -93
  412. package/src/session/{runtime → loop}/SessionTurnFileDiff.ts +1 -1
  413. package/src/session/{messages → loop}/SessionTurnFileDiffBuilder.ts +4 -4
  414. package/src/session/messages/ApprovalInteraction.ts +77 -0
  415. package/src/session/messages/README.md +27 -0
  416. package/src/session/messages/SessionAgentMessageState.ts +324 -113
  417. package/src/session/messages/SessionAgentMessageWriter.ts +82 -45
  418. package/src/session/messages/SessionAgentParts.ts +39 -0
  419. package/src/session/{execution → messages}/SessionAssistantOutputAdapter.ts +2 -2
  420. package/src/session/messages/SessionInteractions.ts +227 -0
  421. package/src/session/messages/SessionJsonValue.ts +1 -18
  422. package/src/session/messages/SessionMessageCache.ts +171 -0
  423. package/src/session/messages/SessionMessageState.ts +42 -0
  424. package/src/session/{browse → messages}/SessionMessageTimeline.ts +0 -1
  425. package/src/session/{SessionMessages.ts → messages/SessionMessages.ts} +225 -284
  426. package/src/session/messages/SessionMutationFactory.ts +58 -0
  427. package/src/session/messages/SessionUserMessage.ts +7 -32
  428. package/src/{executor/core-engine/CoreEngineSignals.ts → session/runner/AssistantParts.ts} +3 -21
  429. package/src/{executor/core-engine/CoreEngineContextCompaction.ts → session/runner/ContextPressure.ts} +10 -10
  430. package/src/{executor/services/ExecutorRecoveryPolicy.ts → session/runner/ContextRetry.ts} +25 -25
  431. package/src/{executor/core-engine/CoreEngineError.ts → session/runner/ModelFailure.ts} +3 -3
  432. package/src/session/runner/SessionExecutor.ts +633 -0
  433. package/src/session/runner/ToolLoopDecision.ts +98 -0
  434. package/src/session/runner/ToolLoopLimits.ts +53 -0
  435. package/src/session/{browse → storage}/Browse.ts +2 -2
  436. package/src/session/storage/LocalSessionStore.ts +1 -1
  437. package/src/session/storage/LocalStorePaths.ts +1 -1
  438. package/src/session/storage/Metadata.ts +1 -44
  439. package/src/session/storage/RuntimeSessionPort.ts +0 -5
  440. package/src/session/{preview → storage}/SessionMessagePreview.ts +0 -1
  441. package/src/session/storage/SessionStorageCodec.ts +54 -28
  442. package/src/session/storage/SessionStorageSchema.ts +1 -1
  443. package/src/session/storage/SqliteSessionStorage.ts +29 -22
  444. package/src/tools/ask/AskQuestionAnswers.ts +125 -0
  445. package/src/tools/ask/AskQuestionsTool.ts +32 -37
  446. package/src/types/agent/AgentOptions.ts +17 -8
  447. package/src/types/agent/AgentSessionCollection.ts +9 -0
  448. package/src/types/agent/SessionActor.ts +3 -4
  449. package/src/types/group/DispatchStrategy.ts +1 -1
  450. package/src/types/group/GroupSession.ts +44 -1
  451. package/src/types/group/GroupSessionStore.ts +30 -3
  452. package/src/types/sdk/AgentSessionAction.ts +1 -14
  453. package/src/types/session/{AdaptivePartContextPolicy.ts → ContextCheckpoint.ts} +9 -8
  454. package/src/types/session/SessionAgentMessageState.ts +6 -16
  455. package/src/types/session/SessionComposer.ts +67 -39
  456. package/src/types/session/SessionExecution.ts +15 -13
  457. package/src/types/session/SessionInteractions.ts +0 -2
  458. package/src/types/session/SessionLocalState.ts +0 -5
  459. package/src/types/session/SessionLoop.ts +37 -12
  460. package/src/types/session/SessionMessages.ts +3 -34
  461. package/src/types/session/SessionOptions.ts +18 -13
  462. package/src/types/session/SessionPort.ts +0 -4
  463. package/src/types/session/SessionState.ts +0 -1
  464. package/src/types/session/SessionSystem.ts +10 -16
  465. package/src/types/session/SessionTool.ts +2 -2
  466. package/src/types/session/SessionTurnCompletion.ts +12 -2
  467. package/src/types/session/SessionTurnFileDiff.ts +4 -4
  468. package/src/types/session/{SessionComposition.ts → StepInput.ts} +22 -14
  469. package/src/types/store/SessionStorage.ts +17 -12
  470. package/src/types/tool/BoundAgentTool.ts +38 -0
  471. package/src/types/tools/ask/AskQuestionsTool.ts +11 -13
  472. package/src/types/{executor → turn}/SessionTurnContext.ts +8 -34
  473. package/src/utils/Time.ts +12 -64
  474. package/tsconfig.json +1 -2
  475. package/tsconfig.tsbuildinfo +1 -1
  476. package/bin/executor/Executor.d.ts +0 -92
  477. package/bin/executor/Executor.d.ts.map +0 -1
  478. package/bin/executor/Executor.js +0 -232
  479. package/bin/executor/Executor.js.map +0 -1
  480. package/bin/executor/composer/system/default/SystemPromptAssets.d.ts.map +0 -1
  481. package/bin/executor/composer/system/default/SystemPromptAssets.js.map +0 -1
  482. package/bin/executor/composer/system/default/assets/core.prompt.d.ts +0 -7
  483. package/bin/executor/composer/system/default/assets/core.prompt.d.ts.map +0 -1
  484. package/bin/executor/composer/system/default/assets/core.prompt.js +0 -8
  485. package/bin/executor/composer/system/default/assets/core.prompt.js.map +0 -1
  486. package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts +0 -15
  487. package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts.map +0 -1
  488. package/bin/executor/core-engine/CoreEngineContextCompaction.js.map +0 -1
  489. package/bin/executor/core-engine/CoreEngineError.d.ts.map +0 -1
  490. package/bin/executor/core-engine/CoreEngineError.js.map +0 -1
  491. package/bin/executor/core-engine/CoreEngineLoopDecision.d.ts +0 -26
  492. package/bin/executor/core-engine/CoreEngineLoopDecision.d.ts.map +0 -1
  493. package/bin/executor/core-engine/CoreEngineLoopDecision.js.map +0 -1
  494. package/bin/executor/core-engine/CoreEngineRunner.d.ts +0 -48
  495. package/bin/executor/core-engine/CoreEngineRunner.d.ts.map +0 -1
  496. package/bin/executor/core-engine/CoreEngineRunner.js +0 -343
  497. package/bin/executor/core-engine/CoreEngineRunner.js.map +0 -1
  498. package/bin/executor/core-engine/CoreEngineSignals.d.ts.map +0 -1
  499. package/bin/executor/core-engine/CoreEngineSignals.js.map +0 -1
  500. package/bin/executor/ids/resolveSessionId.d.ts.map +0 -1
  501. package/bin/executor/ids/resolveSessionId.js.map +0 -1
  502. package/bin/executor/messages/ChatMessageMarkup.d.ts.map +0 -1
  503. package/bin/executor/messages/ChatMessageMarkup.js.map +0 -1
  504. package/bin/executor/messages/ChatMessageMarkupTypes.d.ts.map +0 -1
  505. package/bin/executor/messages/ChatMessageMarkupTypes.js.map +0 -1
  506. package/bin/executor/messages/SessionAttachmentMapper.d.ts.map +0 -1
  507. package/bin/executor/messages/SessionAttachmentMapper.js.map +0 -1
  508. package/bin/executor/messages/SessionMessageLog.d.ts.map +0 -1
  509. package/bin/executor/messages/SessionMessageLog.js.map +0 -1
  510. package/bin/executor/messages/SessionModelMessages.d.ts.map +0 -1
  511. package/bin/executor/messages/SessionModelMessages.js.map +0 -1
  512. package/bin/executor/model/ModelGenerate.d.ts.map +0 -1
  513. package/bin/executor/model/ModelGenerate.js.map +0 -1
  514. package/bin/executor/model/ModelRequestRunner.d.ts.map +0 -1
  515. package/bin/executor/model/ModelRequestRunner.js.map +0 -1
  516. package/bin/executor/model/ModelStepRunner.d.ts.map +0 -1
  517. package/bin/executor/model/ModelStepRunner.js.map +0 -1
  518. package/bin/executor/model/ModelStreamConsumer.d.ts.map +0 -1
  519. package/bin/executor/model/ModelStreamConsumer.js.map +0 -1
  520. package/bin/executor/model/ModelStreamFailure.d.ts.map +0 -1
  521. package/bin/executor/model/ModelStreamFailure.js.map +0 -1
  522. package/bin/executor/services/ExecutorRecoveryPolicy.d.ts +0 -39
  523. package/bin/executor/services/ExecutorRecoveryPolicy.d.ts.map +0 -1
  524. package/bin/executor/services/ExecutorRecoveryPolicy.js.map +0 -1
  525. package/bin/executor/types/SessionHistoryMeta.d.ts.map +0 -1
  526. package/bin/executor/types/SessionHistoryMeta.js.map +0 -1
  527. package/bin/executor/types/SessionLoop.d.ts +0 -59
  528. package/bin/executor/types/SessionLoop.d.ts.map +0 -1
  529. package/bin/executor/types/SessionLoop.js +0 -9
  530. package/bin/executor/types/SessionLoop.js.map +0 -1
  531. package/bin/executor/types/SessionPrompts.d.ts +0 -14
  532. package/bin/executor/types/SessionPrompts.d.ts.map +0 -1
  533. package/bin/executor/types/SessionPrompts.js +0 -8
  534. package/bin/executor/types/SessionPrompts.js.map +0 -1
  535. package/bin/session/DefaultSessionComposer.d.ts +0 -24
  536. package/bin/session/DefaultSessionComposer.d.ts.map +0 -1
  537. package/bin/session/DefaultSessionComposer.js +0 -99
  538. package/bin/session/DefaultSessionComposer.js.map +0 -1
  539. package/bin/session/SessionComposition.d.ts +0 -49
  540. package/bin/session/SessionComposition.d.ts.map +0 -1
  541. package/bin/session/SessionComposition.js +0 -309
  542. package/bin/session/SessionComposition.js.map +0 -1
  543. package/bin/session/SessionHookPoints.d.ts +0 -15
  544. package/bin/session/SessionHookPoints.d.ts.map +0 -1
  545. package/bin/session/SessionHookPoints.js +0 -15
  546. package/bin/session/SessionHookPoints.js.map +0 -1
  547. package/bin/session/SessionHooks.d.ts +0 -38
  548. package/bin/session/SessionHooks.d.ts.map +0 -1
  549. package/bin/session/SessionHooks.js +0 -71
  550. package/bin/session/SessionHooks.js.map +0 -1
  551. package/bin/session/SessionLoop.d.ts.map +0 -1
  552. package/bin/session/SessionLoop.js.map +0 -1
  553. package/bin/session/SessionMessages.d.ts.map +0 -1
  554. package/bin/session/SessionMessages.js.map +0 -1
  555. package/bin/session/SessionQueue.d.ts.map +0 -1
  556. package/bin/session/SessionQueue.js.map +0 -1
  557. package/bin/session/SessionState.d.ts.map +0 -1
  558. package/bin/session/SessionState.js.map +0 -1
  559. package/bin/session/SessionSystem.d.ts +0 -19
  560. package/bin/session/SessionSystem.d.ts.map +0 -1
  561. package/bin/session/SessionSystem.js.map +0 -1
  562. package/bin/session/SessionTitle.d.ts.map +0 -1
  563. package/bin/session/SessionTitle.js.map +0 -1
  564. package/bin/session/browse/Browse.d.ts.map +0 -1
  565. package/bin/session/browse/Browse.js.map +0 -1
  566. package/bin/session/browse/SessionMessageTimeline.d.ts.map +0 -1
  567. package/bin/session/browse/SessionMessageTimeline.js.map +0 -1
  568. package/bin/session/composer/policies/AdaptivePartContextPolicy.d.ts +0 -35
  569. package/bin/session/composer/policies/AdaptivePartContextPolicy.d.ts.map +0 -1
  570. package/bin/session/composer/policies/AdaptivePartContextPolicy.js +0 -256
  571. package/bin/session/composer/policies/AdaptivePartContextPolicy.js.map +0 -1
  572. package/bin/session/composer/policies/FullHistoryContextPolicy.d.ts +0 -24
  573. package/bin/session/composer/policies/FullHistoryContextPolicy.d.ts.map +0 -1
  574. package/bin/session/composer/policies/FullHistoryContextPolicy.js +0 -31
  575. package/bin/session/composer/policies/FullHistoryContextPolicy.js.map +0 -1
  576. package/bin/session/composer/policies/SessionSummaryPrompts.d.ts.map +0 -1
  577. package/bin/session/composer/policies/SessionSummaryPrompts.js.map +0 -1
  578. package/bin/session/control/SessionInteractions.d.ts +0 -39
  579. package/bin/session/control/SessionInteractions.d.ts.map +0 -1
  580. package/bin/session/control/SessionInteractions.js +0 -255
  581. package/bin/session/control/SessionInteractions.js.map +0 -1
  582. package/bin/session/execution/SessionAssistantOutputAdapter.d.ts.map +0 -1
  583. package/bin/session/execution/SessionAssistantOutputAdapter.js.map +0 -1
  584. package/bin/session/execution/tools/SessionShellApprovalAdapter.d.ts +0 -28
  585. package/bin/session/execution/tools/SessionShellApprovalAdapter.d.ts.map +0 -1
  586. package/bin/session/execution/tools/SessionShellApprovalAdapter.js +0 -87
  587. package/bin/session/execution/tools/SessionShellApprovalAdapter.js.map +0 -1
  588. package/bin/session/messages/SessionAgentActionPartWriter.d.ts +0 -22
  589. package/bin/session/messages/SessionAgentActionPartWriter.d.ts.map +0 -1
  590. package/bin/session/messages/SessionAgentActionPartWriter.js +0 -36
  591. package/bin/session/messages/SessionAgentActionPartWriter.js.map +0 -1
  592. package/bin/session/messages/SessionMessageInteractionWriter.d.ts +0 -46
  593. package/bin/session/messages/SessionMessageInteractionWriter.d.ts.map +0 -1
  594. package/bin/session/messages/SessionMessageInteractionWriter.js +0 -183
  595. package/bin/session/messages/SessionMessageInteractionWriter.js.map +0 -1
  596. package/bin/session/messages/SessionTurnFileDiffBuilder.d.ts.map +0 -1
  597. package/bin/session/messages/SessionTurnFileDiffBuilder.js.map +0 -1
  598. package/bin/session/runtime/SessionEventHub.d.ts.map +0 -1
  599. package/bin/session/runtime/SessionEventHub.js.map +0 -1
  600. package/bin/session/runtime/SessionModelRequestWarning.d.ts.map +0 -1
  601. package/bin/session/runtime/SessionModelRequestWarning.js.map +0 -1
  602. package/bin/session/runtime/SessionTitleTask.d.ts.map +0 -1
  603. package/bin/session/runtime/SessionTitleTask.js.map +0 -1
  604. package/bin/session/runtime/SessionTurnCompletion.d.ts.map +0 -1
  605. package/bin/session/runtime/SessionTurnCompletion.js.map +0 -1
  606. package/bin/session/runtime/SessionTurnContext.d.ts +0 -29
  607. package/bin/session/runtime/SessionTurnContext.d.ts.map +0 -1
  608. package/bin/session/runtime/SessionTurnContext.js.map +0 -1
  609. package/bin/session/runtime/SessionTurnFileDiff.d.ts.map +0 -1
  610. package/bin/session/runtime/SessionTurnFileDiff.js.map +0 -1
  611. package/bin/types/action/ActionResult.d.ts +0 -35
  612. package/bin/types/action/ActionResult.d.ts.map +0 -1
  613. package/bin/types/action/ActionResult.js +0 -18
  614. package/bin/types/action/ActionResult.js.map +0 -1
  615. package/bin/types/executor/ModelRequest.d.ts.map +0 -1
  616. package/bin/types/executor/ModelRequest.js.map +0 -1
  617. package/bin/types/executor/SessionAssistantOutput.d.ts.map +0 -1
  618. package/bin/types/executor/SessionAssistantOutput.js.map +0 -1
  619. package/bin/types/executor/SessionToolExecutionContext.d.ts +0 -23
  620. package/bin/types/executor/SessionToolExecutionContext.d.ts.map +0 -1
  621. package/bin/types/executor/SessionToolExecutionContext.js +0 -10
  622. package/bin/types/executor/SessionToolExecutionContext.js.map +0 -1
  623. package/bin/types/executor/SessionTurnContext.d.ts.map +0 -1
  624. package/bin/types/executor/SessionTurnContext.js.map +0 -1
  625. package/bin/types/session/AdaptivePartContextPolicy.d.ts.map +0 -1
  626. package/bin/types/session/AdaptivePartContextPolicy.js +0 -7
  627. package/bin/types/session/AdaptivePartContextPolicy.js.map +0 -1
  628. package/bin/types/session/SessionComposition.d.ts.map +0 -1
  629. package/bin/types/session/SessionComposition.js +0 -8
  630. package/bin/types/session/SessionComposition.js.map +0 -1
  631. package/bin/types/session/SessionContextPolicy.d.ts +0 -70
  632. package/bin/types/session/SessionContextPolicy.d.ts.map +0 -1
  633. package/bin/types/session/SessionContextPolicy.js +0 -8
  634. package/bin/types/session/SessionContextPolicy.js.map +0 -1
  635. package/bin/types/tools/ToolActionExecutionContext.d.ts +0 -30
  636. package/bin/types/tools/ToolActionExecutionContext.d.ts.map +0 -1
  637. package/bin/types/tools/ToolActionExecutionContext.js +0 -8
  638. package/bin/types/tools/ToolActionExecutionContext.js.map +0 -1
  639. package/src/executor/Executor.ts +0 -319
  640. package/src/executor/README.md +0 -92
  641. package/src/executor/composer/system/default/assets/core.prompt.ts +0 -9
  642. package/src/executor/core-engine/CoreEngineLoopDecision.ts +0 -63
  643. package/src/executor/core-engine/CoreEngineRunner.ts +0 -458
  644. package/src/executor/types/SessionLoop.ts +0 -69
  645. package/src/executor/types/SessionPrompts.ts +0 -14
  646. package/src/session/DefaultSessionComposer.ts +0 -123
  647. package/src/session/SessionComposition.ts +0 -370
  648. package/src/session/SessionHookPoints.ts +0 -17
  649. package/src/session/SessionHooks.ts +0 -85
  650. package/src/session/composer/policies/AdaptivePartContextPolicy.ts +0 -307
  651. package/src/session/composer/policies/FullHistoryContextPolicy.ts +0 -36
  652. package/src/session/control/SessionInteractions.ts +0 -311
  653. package/src/session/execution/tools/SessionShellApprovalAdapter.ts +0 -105
  654. package/src/session/messages/SessionAgentActionPartWriter.ts +0 -54
  655. package/src/session/messages/SessionMessageInteractionWriter.ts +0 -279
  656. package/src/types/action/ActionResult.ts +0 -50
  657. package/src/types/executor/SessionToolExecutionContext.ts +0 -26
  658. package/src/types/session/SessionContextPolicy.ts +0 -77
  659. package/src/types/tools/ToolActionExecutionContext.ts +0 -32
  660. /package/bin/{executor/model → model}/ModelGenerate.js +0 -0
  661. /package/bin/{executor/model → model}/ModelRequestRunner.js +0 -0
  662. /package/bin/{executor/model → model}/ModelStreamConsumer.d.ts +0 -0
  663. /package/bin/{executor/model → model}/ModelStreamConsumer.js +0 -0
  664. /package/bin/{executor/model → model}/ModelStreamFailure.d.ts +0 -0
  665. /package/bin/{executor/model → model}/ModelStreamFailure.js +0 -0
  666. /package/bin/{executor → model}/messages/ChatMessageMarkup.d.ts +0 -0
  667. /package/bin/{executor → model}/messages/ChatMessageMarkup.js +0 -0
  668. /package/bin/{executor → model}/messages/SessionAttachmentMapper.d.ts +0 -0
  669. /package/bin/{executor → model}/messages/SessionAttachmentMapper.js +0 -0
  670. /package/bin/{executor → model}/messages/SessionMessageLog.d.ts +0 -0
  671. /package/bin/{executor → model}/messages/SessionMessageLog.js +0 -0
  672. /package/bin/{executor → model}/messages/SessionModelMessages.d.ts +0 -0
  673. /package/bin/{executor/composer/system/default → model/prompts}/SystemPromptAssets.d.ts +0 -0
  674. /package/bin/session/{runtime → loop}/SessionTitleTask.d.ts +0 -0
  675. /package/bin/session/{runtime → loop}/SessionTitleTask.js +0 -0
  676. /package/bin/session/{runtime → loop}/SessionTurnFileDiff.d.ts +0 -0
  677. /package/bin/session/{messages → loop}/SessionTurnFileDiffBuilder.js +0 -0
  678. /package/bin/session/{execution → messages}/SessionAssistantOutputAdapter.js +0 -0
  679. /package/bin/session/{runtime → messages}/SessionEventHub.d.ts +0 -0
  680. /package/bin/session/{runtime → messages}/SessionEventHub.js +0 -0
  681. /package/bin/session/{browse → messages}/SessionMessageTimeline.d.ts +0 -0
  682. /package/bin/session/{runtime → messages}/SessionModelRequestWarning.d.ts +0 -0
  683. /package/bin/session/{runtime → messages}/SessionModelRequestWarning.js +0 -0
  684. /package/bin/session/{preview → storage}/SessionMessagePreview.d.ts +0 -0
  685. /package/bin/types/{executor → model}/ModelRequest.d.ts +0 -0
  686. /package/bin/types/{executor → model}/ModelRequest.js +0 -0
  687. /package/bin/{executor/types → types/store}/SessionHistoryMeta.d.ts +0 -0
  688. /package/bin/{executor/types → types/store}/SessionHistoryMeta.js +0 -0
  689. /package/bin/types/{executor → turn}/SessionAssistantOutput.d.ts +0 -0
  690. /package/bin/types/{executor → turn}/SessionAssistantOutput.js +0 -0
  691. /package/bin/types/{executor → turn}/SessionTurnContext.js +0 -0
  692. /package/src/{executor/model → model}/ModelStreamFailure.ts +0 -0
  693. /package/src/{executor → model}/messages/ChatMessageMarkup.ts +0 -0
  694. /package/src/{executor → model}/messages/SessionAttachmentMapper.ts +0 -0
  695. /package/src/{executor → model}/messages/SessionMessageLog.ts +0 -0
  696. /package/src/session/{runtime → loop}/SessionTitleTask.ts +0 -0
  697. /package/src/session/{runtime → messages}/SessionEventHub.ts +0 -0
  698. /package/src/session/{runtime → messages}/SessionModelRequestWarning.ts +0 -0
  699. /package/src/types/{executor → model}/ModelRequest.ts +0 -0
  700. /package/src/{executor/types → types/store}/SessionHistoryMeta.ts +0 -0
  701. /package/src/types/{executor → turn}/SessionAssistantOutput.ts +0 -0
  702. /package/src/{executor/ids/resolveSessionId.ts → utils/ResolveSessionId.ts} +0 -0
@@ -8,8 +8,30 @@ import type {
8
8
  GroupSessionStore,
9
9
  GroupSessionStoreOptions,
10
10
  } from "@/types/group/GroupSessionStore.js";
11
+ import type { GroupSessionArchiveResult, GroupSessionCleanArchiveResult } from "@/types/group/GroupSession.js";
11
12
  import { LocalGroupSessionDataStore } from "@/group/storage/LocalGroupSessionDataStore.js";
12
13
 
14
+ /**
15
+ * GroupSession 的两个存储区。
16
+ *
17
+ * ```text
18
+ * <group-root>/sessions/<session_id>/ 活动
19
+ * <group-root>/archived-sessions/<session_id>/ 归档
20
+ * ```
21
+ *
22
+ * 归档是**目录搬迁**而不是打标记:活动列表因此天然只含活动项,
23
+ * `list_session_metadata()` 不需要加过滤条件,`metadata.v` 也不用升版本。
24
+ * 这与 Agent Session 的做法一致(`LocalSessionStore.archive_session`),
25
+ * 两处同类能力不该有两套语义。
26
+ */
27
+ type SessionArea = "active" | "archived";
28
+
29
+ /** 各存储区的目录名。 */
30
+ const area_directory_name: Record<SessionArea, string> = {
31
+ active: "sessions",
32
+ archived: "archived-sessions",
33
+ };
34
+
13
35
  /** GroupSession 的底层文件 Store。 */
14
36
  export class LocalGroupSessionStore implements GroupSessionStore {
15
37
  private readonly files: FileSystem;
@@ -23,48 +45,106 @@ export class LocalGroupSessionStore implements GroupSessionStore {
23
45
  this.group_id = options.group_id;
24
46
  }
25
47
 
26
- /** 返回指定 GroupSession 的持久化视图。 */
27
- session(session_id: string): GroupSessionDataStore {
48
+ /**
49
+ * 返回指定 GroupSession 的持久化视图。
50
+ *
51
+ * 缓存键带存储区:同一个 session_id 在活动区与归档区各有一份视图,
52
+ * 不分区的话归档后会拿到活动区的旧视图(路径指向已经不存在的目录)。
53
+ */
54
+ session(session_id: string, area: SessionArea = "active"): GroupSessionDataStore {
28
55
  const resolved_session_id = String(session_id || "").trim();
29
56
  if (!resolved_session_id) throw new Error("GroupSessionStore.session requires a non-empty session_id");
30
- const cached = this.sessions_by_id.get(resolved_session_id);
57
+ const cache_key = `${area}:${resolved_session_id}`;
58
+ const cached = this.sessions_by_id.get(cache_key);
31
59
  if (cached) return cached;
32
60
  const created = new LocalGroupSessionDataStore({
33
61
  files: this.files,
34
62
  storage_root_path: this.storage_root_path,
35
63
  session_id: resolved_session_id,
36
64
  group_id: this.group_id,
65
+ area,
37
66
  });
38
- this.sessions_by_id.set(resolved_session_id, created);
67
+ this.sessions_by_id.set(cache_key, created);
39
68
  return created;
40
69
  }
41
70
 
42
- /** 判断指定 GroupSession 是否存在。 */
71
+ /** 判断指定 GroupSession 是否存在(活动区)。 */
43
72
  async has_session(session_id: string): Promise<boolean> {
44
- return await this.files.path_exists(this.session_path(session_id));
73
+ return await this.files.path_exists(this.session_path(session_id, "active"));
45
74
  }
46
75
 
47
- /** 列出当前 Group 的全部 Session metadata。 */
76
+ /** 列出当前 Group 活动区的全部 Session metadata(不含已归档)。 */
48
77
  async list_session_metadata(): Promise<GroupSessionHistoryMeta[]> {
49
- const sessions_path = path.join(path.resolve(this.storage_root_path), "sessions");
50
- if (!(await this.files.path_exists(sessions_path))) return [];
51
- const entries = await this.files.read_directory(sessions_path);
52
- const metadata: GroupSessionHistoryMeta[] = [];
53
- for (const entry of entries.filter((item) => item.is_directory)) {
54
- const session_id = decode_session_id(entry.name);
55
- metadata.push(await this.session(session_id).read_metadata());
56
- }
57
- return metadata.sort((left, right) => right.updated_at - left.updated_at);
78
+ return await this.list_area_metadata("active");
79
+ }
80
+
81
+ /** 列出归档区的 Session metadata。 */
82
+ async list_archived_session_metadata(): Promise<GroupSessionHistoryMeta[]> {
83
+ return await this.list_area_metadata("archived");
58
84
  }
59
85
 
60
- /** 删除指定 GroupSession 的全部数据。 */
86
+ /** 删除指定 GroupSession 的全部数据(活动区)。 */
61
87
  async remove_session(session_id: string): Promise<boolean> {
88
+ return await this.remove_area_session(session_id, "active");
89
+ }
90
+
91
+ /** 删除归档区中的指定 Session。 */
92
+ async remove_archived_session(session_id: string): Promise<boolean> {
93
+ return await this.remove_area_session(session_id, "archived");
94
+ }
95
+
96
+ /**
97
+ * 把一个活动 GroupSession 迁入归档区。
98
+ *
99
+ * 用 `move_path` 而不是「复制再删除」:它是原子的,且**不覆盖已有目标**——
100
+ * 后者正是这里要的语义(覆盖会丢掉一份真实数据)。两个方向的失败都必须报错,
101
+ * 不能静默成功。
102
+ *
103
+ * **先查归档区再查活动区**,顺序不能反:重复归档时活动区已经空了,
104
+ * 先查活动区会报「not found」——而用户明明看得到那条群聊(在归档区),
105
+ * 那句话只会让他以为数据丢了。报「已归档」才是他需要知道的事。
106
+ */
107
+ async archive_session(session_id: string): Promise<GroupSessionArchiveResult> {
62
108
  const resolved_session_id = String(session_id || "").trim();
63
- const session_path = this.session_path(resolved_session_id);
64
- const existed = await this.files.path_exists(session_path);
65
- if (existed) await this.files.remove_path(session_path);
66
- this.sessions_by_id.delete(resolved_session_id);
67
- return existed;
109
+ if (!resolved_session_id) throw new Error("GroupSessionStore.archive_session requires a non-empty session_id");
110
+ const target_path = this.session_path(resolved_session_id, "archived");
111
+ if (await this.files.path_exists(target_path)) {
112
+ throw new Error(`Archived GroupSession "${resolved_session_id}" already exists`);
113
+ }
114
+ const source_path = this.session_path(resolved_session_id, "active");
115
+ if (!(await this.files.path_exists(source_path))) {
116
+ throw new Error(`GroupSession "${resolved_session_id}" not found`);
117
+ }
118
+ await this.files.ensure_directory(this.area_path("archived"));
119
+ await this.files.move_path(source_path, target_path);
120
+ // 运行时缓存指向的是活动区路径;搬迁后必须丢掉它,否则下次 `session()` 会拿到旧视图。
121
+ this.sessions_by_id.delete(`active:${resolved_session_id}`);
122
+ return { session_id: resolved_session_id, archived_at: Date.now() };
123
+ }
124
+
125
+ /** 永久清空归档区。 */
126
+ async clean_archive(): Promise<GroupSessionCleanArchiveResult> {
127
+ const archived_path = this.area_path("archived");
128
+ if (!(await this.files.path_exists(archived_path))) return { removed_session_ids: [] };
129
+ const entries = await this.files.read_directory(archived_path);
130
+ const removed_session_ids = entries
131
+ .filter((entry) => entry.is_directory)
132
+ .map((entry) => decode_session_id(entry.name));
133
+ await this.files.remove_path(archived_path);
134
+ return { removed_session_ids };
135
+ }
136
+
137
+ /**
138
+ * 永久删除当前 Group 的全部 GroupSession 数据。
139
+ *
140
+ * 两个区都删:Group 被删时它的活动会话与归档一样无处可访问,留着只是磁盘泄漏。
141
+ * 只删两个区目录而不是整个作用域根:作用域可能还装着 Group 的其它私有数据,
142
+ * 那些不归这个 Store 管。
143
+ */
144
+ async purge(): Promise<void> {
145
+ await this.files.remove_path(this.area_path("active"));
146
+ await this.files.remove_path(this.area_path("archived"));
147
+ this.sessions_by_id.clear();
68
148
  }
69
149
 
70
150
  /** 释放当前 Store 的运行时缓存。 */
@@ -72,12 +152,42 @@ export class LocalGroupSessionStore implements GroupSessionStore {
72
152
  this.sessions_by_id.clear();
73
153
  }
74
154
 
75
- private session_path(session_id: string): string {
76
- return path.join(
77
- path.resolve(this.storage_root_path),
78
- "sessions",
79
- encodeURIComponent(String(session_id || "").trim()),
80
- );
155
+ /** 一个存储区的根目录。 */
156
+ private area_path(area: SessionArea): string {
157
+ return path.join(path.resolve(this.storage_root_path), area_directory_name[area]);
158
+ }
159
+
160
+ /**
161
+ * 某个区里单个 Session 的目录。
162
+ *
163
+ * 两个区共用同一段拼接:各写一遍必然分叉,而这类路径一旦分叉,
164
+ * 表现是「归档后找不到了」——极难归因。
165
+ */
166
+ private session_path(session_id: string, area: SessionArea): string {
167
+ return path.join(this.area_path(area), encodeURIComponent(String(session_id || "").trim()));
168
+ }
169
+
170
+ /** 列出某个区的全部 Session metadata,按最近更新倒序。 */
171
+ private async list_area_metadata(area: SessionArea): Promise<GroupSessionHistoryMeta[]> {
172
+ const area_path = this.area_path(area);
173
+ if (!(await this.files.path_exists(area_path))) return [];
174
+ const entries = await this.files.read_directory(area_path);
175
+ const metadata: GroupSessionHistoryMeta[] = [];
176
+ for (const entry of entries.filter((item) => item.is_directory)) {
177
+ metadata.push(await this.session(decode_session_id(entry.name), area).read_metadata());
178
+ }
179
+ return metadata.sort((left, right) => right.updated_at - left.updated_at);
180
+ }
181
+
182
+ /** 删除某个区里的一个 Session。 */
183
+ private async remove_area_session(session_id: string, area: SessionArea): Promise<boolean> {
184
+ const resolved_session_id = String(session_id || "").trim();
185
+ const session_path = this.session_path(resolved_session_id, area);
186
+ const existed = await this.files.path_exists(session_path);
187
+ if (existed) await this.files.remove_path(session_path);
188
+ // 只清这个区的缓存:同一个 id 在另一个区可能仍有视图。
189
+ this.sessions_by_id.delete(`${area}:${resolved_session_id}`);
190
+ return existed;
81
191
  }
82
192
  }
83
193
 
package/src/index.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * 关键点(中文)
5
5
  * - 这是 agent 包核心运行时的稳定公开入口;可选 Tool 通过 `@downcity/agent/tools` 导出。
6
6
  * - 只导出 Agent SDK 与必要的 Session 协议类型。
7
- * - HTTP、RPC、Plugin、Workspace 与 Sandbox 实现不从根入口暴露。
7
+ * - HTTP、RPC、Power、Workspace 与 Sandbox 实现不从根入口暴露。
8
8
  */
9
9
 
10
10
  // Agent 入口
@@ -50,19 +50,19 @@ export type {
50
50
  } from "./group/index.js";
51
51
  export { AiDispatchStrategy } from "./group/index.js";
52
52
  export type { SessionStore } from "./types/store/SessionStore.js";
53
+ export type {
54
+ SessionDerivedStore,
55
+ SessionDerivedStoreTransaction,
56
+ } from "./types/store/SessionStorage.js";
53
57
  export type { SessionAttachmentStore } from "./types/store/SessionAttachmentStore.js";
54
58
  export type { AgentStorage } from "./types/agent/AgentStorage.js";
55
59
  export { Session } from "./session/Session.js";
56
- export { SessionHooks, SessionHookScope } from "./session/SessionHooks.js";
57
- export type { SessionOptions } from "./types/session/SessionOptions.js";
58
60
  export type { SessionOrigin } from "@downcity/type";
59
- export { SESSION_HOOK_POINTS } from "./session/SessionHookPoints.js";
61
+ export { SESSION_HOOK_POINTS } from "@downcity/type";
60
62
  export type {
61
63
  SessionCommittedTurnStatus,
62
64
  SessionHookContextBlock,
63
65
  SessionHookUserMessage,
64
- SessionHookContext,
65
- SessionHookHandlers,
66
66
  SessionSystemContextHookValue,
67
67
  SessionTurnCommittedHookValue,
68
68
  SessionTurnContextHookValue,
@@ -97,7 +97,7 @@ export type {
97
97
  SessionAgentActionPart,
98
98
  SessionAgentDataPart,
99
99
  SessionAgentFilePart,
100
- SessionAgentInteractionPart,
100
+ SessionAgentInteraction,
101
101
  SessionAgentMessage,
102
102
  SessionAgentMessagePart,
103
103
  SessionAgentReasoningPart,
@@ -124,8 +124,8 @@ export {
124
124
  read_session_turn_file_diff_data,
125
125
  SESSION_TURN_FILE_DIFF_DATA_TYPE,
126
126
  } from "./session/messages/SessionTurnFileDiffData.js";
127
- export { to_session_message_timeline_events } from "./session/browse/SessionMessageTimeline.js";
128
- export { SessionAssistantOutputAdapter } from "./session/execution/SessionAssistantOutputAdapter.js";
127
+ export { to_session_message_timeline_events } from "./session/messages/SessionMessageTimeline.js";
128
+ export { SessionAssistantOutputAdapter } from "./session/messages/SessionAssistantOutputAdapter.js";
129
129
  export {
130
130
  is_session_mutation,
131
131
  } from "@downcity/type";
@@ -148,24 +148,27 @@ export type {
148
148
  } from "@downcity/type";
149
149
  export type {
150
150
  RespondSessionInteractionInput,
151
+ SessionApprovalDecision,
151
152
  SessionApprovalMode,
153
+ SessionApprovalPort,
154
+ SessionApprovalRequestInput,
152
155
  SessionCancelledInteractionResult,
153
- SessionExpiredInteractionResult,
154
156
  SessionInteractionAnswer,
155
157
  SessionInteractionHandle,
156
158
  SessionInteractionLifecycle,
157
159
  SessionInteractionOption,
158
160
  SessionInteractionPort,
159
161
  SessionInteractionQuestion,
160
- SessionInteractionQuestionResponseType,
162
+ SessionInteractionQuestionType,
161
163
  SessionInteractionRequest,
164
+ SessionInteractionRequestInput,
162
165
  SessionInteractionResponse,
163
166
  SessionInteractionResult,
164
167
  SessionInteractionSource,
165
168
  SessionInteractionStatus,
166
- SessionPendingInteraction,
167
169
  SessionResolvedInteractionResult,
168
170
  } from "@downcity/type";
171
+ export { SESSION_APPROVAL_RESPONSE_SCHEMA } from "@downcity/type";
169
172
  export type {
170
173
  AgentOptions,
171
174
  AgentSessionConstructor,
@@ -184,8 +187,6 @@ export type { AgentManagedSession } from "./types/session/SessionOptions.js";
184
187
  export type {
185
188
  AgentSessionActionCallback,
186
189
  AgentSessionActionEvent,
187
- AgentSessionActionRecord,
188
- AgentSessionActionState,
189
190
  } from "./types/sdk/AgentSessionAction.js";
190
191
  export type {
191
192
  AgentSessionPromptContent,
@@ -207,25 +208,24 @@ export type {
207
208
  AgentSessionTurnResult,
208
209
  } from "./types/sdk/AgentSessionTurn.js";
209
210
  export type { SessionPort } from "./types/session/SessionPort.js";
210
- export type {
211
- ActionResult,
212
- ActionResultMessage,
213
- } from "./types/action/ActionResult.js";
211
+ export {
212
+ is_action_result,
213
+ type ActionResult,
214
+ type ActionResultMessage,
215
+ type SessionSystemMessage,
216
+ } from "@downcity/type";
214
217
 
215
218
  // Session 与即时执行集成
216
- export { Executor } from "./executor/Executor.js";
217
- export { DefaultSessionComposer } from "./session/DefaultSessionComposer.js";
218
- export { FullHistoryContextPolicy } from "./session/composer/policies/FullHistoryContextPolicy.js";
219
- export { AdaptivePartContextPolicy } from "./session/composer/policies/AdaptivePartContextPolicy.js";
220
- export { SessionMessages } from "./session/SessionMessages.js";
219
+ export { SessionExecutor } from "./session/runner/SessionExecutor.js";
220
+ export { DefaultSessionComposer } from "./session/input/composer/DefaultSessionComposer.js";
221
+ export { FullHistorySessionComposer } from "./session/input/composer/FullHistorySessionComposer.js";
222
+ export { SessionMessages } from "./session/messages/SessionMessages.js";
221
223
  export type {
222
- AppendCompletedAgentMessageInput,
223
224
  AppendExternalSessionAgentMessageInput,
224
225
  AppendExternalSessionUserMessageInput,
225
226
  AppendSessionAgentErrorPartInput,
226
227
  AppendSessionPromptMessageInput,
227
228
  AppendSessionUserMessageInput,
228
- OpenSessionAgentActionPartInput,
229
229
  OpenSessionAgentMessageInput,
230
230
  SessionMessagesOptions,
231
231
  } from "./types/session/SessionMessages.js";
@@ -236,38 +236,20 @@ export type {
236
236
  SessionComposeState,
237
237
  SessionComposeTurn,
238
238
  SessionComposerInitializeInput,
239
- SessionContextRecoveryInput,
239
+ SessionContextAdvanceInput,
240
+ SessionContextAdvanceTrigger,
241
+ SessionContextDiagnostics,
240
242
  SessionStepInput,
241
243
  } from "./types/session/SessionComposer.js";
242
244
  export type {
243
- SessionContextPolicy,
244
- SessionContextPolicyInitializeInput,
245
- SessionContextPolicyInput,
246
- SessionContextPolicyRecoveryInput,
247
- SessionContextRecoveryReason,
248
- SessionResolvedContext,
249
- SessionResolvedContextDiagnostics,
250
- } from "./types/session/SessionContextPolicy.js";
251
- export type {
252
- SessionExecutor,
253
245
  SessionTurnExecutionResult,
254
246
  } from "./types/session/SessionExecution.js";
255
- export { create_session_turn_context } from "./session/runtime/SessionTurnContext.js";
247
+ export { create_session_turn_context } from "./session/loop/SessionTurnContext.js";
256
248
  export type {
257
249
  SessionTurnContext,
258
250
  SessionTurnContextInit,
259
- } from "./types/executor/SessionTurnContext.js";
260
- export type { SessionToolExecutionContext } from "./types/executor/SessionToolExecutionContext.js";
261
- export type {
262
- ToolActionExecutionContext,
263
- ToolSessionExecutionScope,
264
- } from "./types/tools/ToolActionExecutionContext.js";
265
- export type {
266
- SessionActionEvent,
267
- SessionActionEventInput,
268
- SessionActionStatus,
269
- } from "@downcity/type";
270
- export type { SessionSystemMessage } from "./executor/types/SessionPrompts.js";
251
+ } from "./types/turn/SessionTurnContext.js";
252
+ export type { SessionActionEvent, SessionActionStatus } from "@downcity/type";
271
253
  export {
272
254
  extract_session_message_text,
273
255
  extract_session_tool_calls,
@@ -278,18 +260,19 @@ export {
278
260
  build_chat_message_text,
279
261
  parse_chat_message_markup,
280
262
  render_chat_message_file_tag,
281
- } from "./executor/messages/ChatMessageMarkup.js";
263
+ } from "./model/messages/ChatMessageMarkup.js";
282
264
  export type {
283
265
  ChatMessageFileTag,
284
266
  ChatMessageFileType,
285
267
  ChatMessageSegment,
286
268
  ChatMessageSendOptions,
287
- } from "./executor/messages/ChatMessageMarkupTypes.js";
269
+ } from "./model/messages/ChatMessageMarkupTypes.js";
288
270
 
289
271
  // 日志
290
272
  export { get_logger, type Logger } from "./utils/logger/Logger.js";
291
273
  export { generate_id } from "./utils/Id.js";
292
274
  export {
275
+ format_date_in_timezone,
293
276
  format_date_time_in_timezone,
294
277
  resolve_runtime_timezone,
295
278
  } from "./utils/Time.js";
@@ -297,4 +280,4 @@ export {
297
280
  // JSON 基础类型
298
281
  export type { JsonObject, JsonPrimitive, JsonValue } from "@downcity/type";
299
282
 
300
- export { resolve_session_id } from "./executor/ids/resolveSessionId.js";
283
+ export { resolve_session_id } from "./utils/ResolveSessionId.js";
@@ -13,11 +13,11 @@ import type {
13
13
  ModelToolCallContent,
14
14
  ModelUsage,
15
15
  } from "@downcity/type";
16
- import { execute_model_request } from "@executor/model/ModelRequestRunner.js";
17
- import { consume_model_stream } from "@executor/model/ModelStreamConsumer.js";
16
+ import { execute_model_request } from "@/model/ModelRequestRunner.js";
17
+ import { consume_model_stream } from "@/model/ModelStreamConsumer.js";
18
18
  import type {
19
19
  ModelRequestFailureReporter,
20
- } from "@/types/executor/ModelRequest.js";
20
+ } from "@/types/model/ModelRequest.js";
21
21
 
22
22
  /** 单次非交互模型生成结果。 */
23
23
  export interface ModelGenerateResult {
@@ -5,11 +5,11 @@
5
5
  */
6
6
 
7
7
  import type { ModelRequestKind } from "@downcity/type";
8
- import type { ModelRequestFailureReporter } from "@/types/executor/ModelRequest.js";
8
+ import type { ModelRequestFailureReporter } from "@/types/model/ModelRequest.js";
9
9
  import {
10
10
  ModelStreamFailure,
11
11
  is_retryable_empty_model_stream_failure,
12
- } from "@executor/model/ModelStreamFailure.js";
12
+ } from "@/model/ModelStreamFailure.js";
13
13
 
14
14
  /** 首次模型调用失败后的最大自动重试次数。 */
15
15
  export const MAX_MODEL_REQUEST_RETRIES = 5;
@@ -14,17 +14,17 @@ import {
14
14
  type ModelStreamEvent,
15
15
  type ModelTool,
16
16
  type ModelUsage,
17
- type RuntimeTool as Tool,
18
- type RuntimeToolExecutionOptions as ToolExecutionOptions,
19
17
  } from "@downcity/type";
18
+ import type { BoundAgentTool, ToolCallSite } from "@/types/tool/BoundAgentTool.js";
20
19
  import { z } from "zod";
21
- import type { SessionSystemMessage } from "@/executor/types/SessionPrompts.js";
22
- import type { SessionAssistantOutput } from "@/types/executor/SessionAssistantOutput.js";
20
+ import type { SessionSystemMessage } from "@downcity/type";
21
+ import type { SessionAssistantOutput } from "@/types/turn/SessionAssistantOutput.js";
23
22
  import type {
24
23
  SessionAgentMessagePart,
25
24
  SessionAgentToolPart,
26
25
  } from "@downcity/type";
27
- import { consume_model_stream } from "@/executor/model/ModelStreamConsumer.js";
26
+ import { consume_model_stream } from "@/model/ModelStreamConsumer.js";
27
+ import { validate_tool_input } from "@/model/ToolInputValidation.js";
28
28
 
29
29
  /** 单个工具调用的执行事实。 */
30
30
  export interface ModelStepToolCall {
@@ -70,14 +70,12 @@ export interface RunModelStepInput {
70
70
  system: SessionSystemMessage[];
71
71
  /** 当前模型上下文。 */
72
72
  messages: ModelMessage[];
73
- /** 当前可用工具运行时。 */
74
- tools: Record<string, Tool>;
73
+ /** 当前可用工具运行时;上下文已在包装层绑定。 */
74
+ tools: Record<string, BoundAgentTool>;
75
75
  /** 当前取消信号。 */
76
76
  abort_signal: AbortSignal;
77
77
  /** canonical Assistant 输出端口。 */
78
78
  assistant_output?: SessionAssistantOutput;
79
- /** 工具执行前的审批回调。 */
80
- approve_tool?: (call: ModelStepToolCall, tool: Tool) => Promise<boolean>;
81
79
  }
82
80
 
83
81
  /** 执行一个 Downcity 模型 Step 并收敛工具结果。 */
@@ -261,26 +259,31 @@ async function execute_tools(
261
259
  });
262
260
  continue;
263
261
  }
264
- const approved = input.approve_tool
265
- ? await input.approve_tool(call, tool)
266
- : true;
267
- if (!approved) {
262
+ // 关键点(中文):模型输入先按工具自己的 schema 校验,非法输入在执行之前
263
+ // 就形成结构化失败,不会带着错误类型进入工具实现。
264
+ const validated = validate_tool_input({
265
+ tool,
266
+ tool_name: call.tool_name,
267
+ input: call.input,
268
+ });
269
+ if ("error" in validated) {
268
270
  results.push({
269
271
  ...call,
270
272
  success: false,
271
- output: { error: "Tool execution denied" },
273
+ output: { error: validated.error },
272
274
  });
273
275
  continue;
274
276
  }
275
277
  try {
276
- const options: ToolExecutionOptions = {
278
+ const site: ToolCallSite = {
277
279
  tool_call_id: call.tool_call_id,
278
280
  messages,
279
- abort_signal: input.abort_signal,
281
+ ...(input.abort_signal ? { abort_signal: input.abort_signal } : {}),
280
282
  };
281
- const output = await tool.execute(call.input, options);
283
+ const output = await tool.execute(validated.input, site);
282
284
  results.push({
283
285
  ...call,
286
+ input: validated.input,
284
287
  success: !is_structured_tool_failure(output),
285
288
  output,
286
289
  });
@@ -314,8 +317,8 @@ function convert_system_messages(messages: SessionSystemMessage[]): ModelMessage
314
317
  }));
315
318
  }
316
319
 
317
- /** 把 Agent 工具定义转换为只含 JSON Schema 的模型协议。 */
318
- function convert_tools(tools: Record<string, Tool>): ModelTool[] {
320
+ /** 把已绑定工具定义转换为只含 JSON Schema 的模型协议。 */
321
+ function convert_tools(tools: Record<string, BoundAgentTool>): ModelTool[] {
319
322
  return Object.entries(tools).map(([name, tool]) => ({
320
323
  name,
321
324
  description: tool.description ?? "",
@@ -17,7 +17,7 @@ import {
17
17
  ModelStreamFailure,
18
18
  normalize_model_invocation_failure,
19
19
  normalize_model_protocol_failure,
20
- } from "@executor/model/ModelStreamFailure.js";
20
+ } from "@/model/ModelStreamFailure.js";
21
21
 
22
22
  /** 消费并校验一次完整模型事件流。 */
23
23
  export async function consume_model_stream(
@@ -0,0 +1,117 @@
1
+ # Execution Module
2
+
3
+ `model/` 是模型请求与 Tool Loop 的低层内核;Session 级编排在 `session/runner/`。普通 SDK 用户只通过 `Session` 调用它。
4
+
5
+ 完整 Session Runtime 设计见 [`docs/session-runtime-architecture.md`](../../../../docs/session-runtime-architecture.md)。
6
+
7
+ ## 边界
8
+
9
+ - `Session` 拥有输入队列并创建 Command;`SessionLoop` 负责消费、Turn Handle 与 Assistant Message 收口。
10
+ - `SessionTurnContext` 从 Turn 创建起唯一拥有取消信号、Step 快照和执行期资源。
11
+ - `SessionComposer` 根据只读 Session 快照组装 system、messages 和 tools。
12
+ - `StepInput` 是 SessionLoop 的「输入环境」:刷新 Hook、请求 Composer 组装、冻结并套用 system、绑定工具执行上下文。
13
+ - `SessionExecutor` 负责模型请求、Tool Loop、续写恢复、上下文超限重试与真实 usage 观测;它只对外提供 `execute()`,Step 输入由回调提供。
14
+ - `ModelRequestRunner` 唯一拥有普通模型请求的五次重试、退避和逐次失败通知。
15
+ - `SessionMessages` 是 Message 唯一事实源;执行层不写文件、不持有 Store。
16
+
17
+ ## 执行关系
18
+
19
+ ```mermaid
20
+ flowchart LR
21
+ Loop["SessionLoop"] --> Context["SessionTurnContext"]
22
+ Loop --> Assembly["StepInput"]
23
+ Assembly --> Composer["SessionComposer"]
24
+ Composer --> Input["system + messages + tools"]
25
+ Context --> Executor["SessionExecutor"]
26
+ Input --> Executor
27
+ Executor --> Request["ModelRequestRunner"]
28
+ Request --> Step["ModelStepRunner"]
29
+ Step --> Model["ModelClient"]
30
+ Executor --> Tools["Tools / Plugins"]
31
+ Model -->|"ModelStreamEvent"| Step
32
+ Step --> Request
33
+ Step -->|"ModelStreamEvent / Tool Result"| Context
34
+ Context --> Messages["SessionMessages"]
35
+ ```
36
+
37
+ 每个模型 Step 前,`SessionLoop` 先消费排队的 Steer 和状态 Command。`StepInput` 随后捕获最新 effective state,并调用 Composer 生成完整 Step 输入。
38
+
39
+ ```text
40
+ Session.prompt()
41
+ -> SessionLoop 持久化 canonical User Message
42
+ -> StepInput 捕获只读 Session 快照
43
+ -> SessionComposer.compose()
44
+ -> SessionModelMessages: SessionMessage -> ModelMessage
45
+ -> SessionExecutor.execute()
46
+ -> Federation / Provider 返回 ModelStreamEvent
47
+ -> SessionAssistantOutput 直接更新 canonical Assistant Message
48
+ -> SessionMessages 持久化并发布 Mutation
49
+ ```
50
+
51
+ ## 旧 Composer 去向
52
+
53
+ 过去的四个独立 Composer 不再构成执行管线:
54
+
55
+ | 旧能力 | 当前归属 |
56
+ | --- | --- |
57
+ | `SystemComposer` | `DefaultSessionComposer.compose()` + `SessionSystem` |
58
+ | `HistoryComposer` | `SessionComposer.compose()` + `SessionModelMessages` |
59
+ | `ContextComposer` 的 tools | `Session` 装配 + `SessionComposer.compose()` |
60
+ | `ContextComposer` 的 Step Callback | `SessionLoop` + `StepInput` |
61
+ | `ContextComposer` 的 fallback Assistant | `SessionExecutor` + `ContextAdvanceRetry` |
62
+ | `CompactionComposer` | `SessionComposer.advance_context()` + `session/input/composer/` 内的算法与派生表 |
63
+
64
+ 统一 Composer 只回答一个策略问题:
65
+
66
+ 1. 当前 Step 的 system、messages 和 tools 是什么?上下文超限时能否推进派生上下文?
67
+
68
+ Queue 消费、Turn 控制、Message 写入和 Mutation 发布都不是 Composer 职责。
69
+
70
+ ## Context advance
71
+
72
+ ```text
73
+ SessionLoop / ContextAdvanceRetry
74
+ -> Session.advance_context(trigger)
75
+ -> SessionComposer.advance_context()
76
+ -> 默认实现在自己的 checkpoint 派生表推进边界
77
+ -> 下一次 compose() 读取最新派生上下文
78
+ ```
79
+
80
+ Composer 只接收调用方读好的 canonical history 快照与命名空间派生存储;它可以调用模型生成摘要,
81
+ 但不能修改 canonical Message、Metadata 或发布事件。持久化提交始终由 `SessionStorage` 事务完成。
82
+
83
+ ## 目录
84
+
85
+ ```text
86
+ model/
87
+ ModelGenerate.ts 共享的一次性模型生成入口
88
+ ModelRequestRunner.ts 单次模型请求的重试与失败通知
89
+ ModelStepRunner.ts 单个 Tool Loop Step 的模型调用
90
+ ModelStreamConsumer.ts 模型流消费
91
+ ModelStreamFailure.ts 模型流错误分类
92
+ messages/ Session 与 Model Protocol 消息转换
93
+ prompts/ 默认 core system prompt 资产
94
+
95
+ types/model/
96
+ ModelRequest.ts 模型请求失败上报契约
97
+
98
+ types/turn/
99
+ SessionTurnContext.ts 一个 Turn 的执行上下文
100
+ SessionAssistantOutput.ts Turn 的 Assistant 输出端口
101
+
102
+ session/input/
103
+ StepInput.ts 每步模型输入与冻结 system
104
+ SessionSystem.ts 默认 system block 组装
105
+ SessionHooks.ts Hook 运行类
106
+ SessionHookPoints.ts Hook 检查点目录
107
+ composer/ Composer 实现与压缩算法
108
+
109
+ session/runner/
110
+ SessionExecutor.ts 模型请求、Tool Loop 与上下文推进重试
111
+ ToolLoopLimits.ts Step 上限与边界提示
112
+ ToolLoopDecision.ts 是否继续下一轮的纯决策
113
+ AssistantParts.ts Assistant 产出读取与诊断
114
+ ModelFailure.ts 模型调用错误归一化
115
+ ContextPressure.ts usage 压力阈值判断
116
+ ContextRetry.ts 推进上下文后重试整轮
117
+ ```