@downcity/agent 1.1.15 → 1.1.17

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 (666) hide show
  1. package/README.md +126 -635
  2. package/bin/{project → config/project}/AgentInitializer.d.ts +2 -2
  3. package/bin/config/project/AgentInitializer.d.ts.map +1 -0
  4. package/bin/{project → config/project}/AgentInitializer.js +7 -7
  5. package/bin/config/project/AgentInitializer.js.map +1 -0
  6. package/bin/{project → config/project}/types/AgentProject.d.ts +2 -2
  7. package/bin/config/project/types/AgentProject.d.ts.map +1 -0
  8. package/bin/config/project/types/AgentProject.js.map +1 -0
  9. package/bin/core/AgentContextTypes.d.ts +9 -71
  10. package/bin/core/AgentContextTypes.d.ts.map +1 -1
  11. package/bin/core/AgentCore.d.ts.map +1 -1
  12. package/bin/core/AgentCore.js +5 -2
  13. package/bin/core/AgentCore.js.map +1 -1
  14. package/bin/core/AgentCoreTypes.d.ts +1 -6
  15. package/bin/core/AgentCoreTypes.d.ts.map +1 -1
  16. package/bin/index.d.ts +22 -22
  17. package/bin/index.d.ts.map +1 -1
  18. package/bin/index.js +9 -10
  19. package/bin/index.js.map +1 -1
  20. package/bin/plugin/builtins/asr/Config.d.ts +1 -1
  21. package/bin/plugin/builtins/asr/Config.d.ts.map +1 -1
  22. package/bin/plugin/builtins/auth/runtime/AuthorizationPolicy.d.ts +1 -1
  23. package/bin/plugin/builtins/auth/runtime/AuthorizationPolicy.d.ts.map +1 -1
  24. package/bin/plugin/builtins/voice/Config.d.ts +1 -1
  25. package/bin/plugin/builtins/voice/Config.d.ts.map +1 -1
  26. package/bin/plugin/builtins/workboard/runtime/Collector.js +1 -1
  27. package/bin/plugin/builtins/workboard/runtime/Collector.js.map +1 -1
  28. package/bin/plugin/builtins/workboard/runtime/Normalizer.d.ts +1 -1
  29. package/bin/plugin/builtins/workboard/runtime/Normalizer.d.ts.map +1 -1
  30. package/bin/plugin/core/HttpRoutes.d.ts +1 -1
  31. package/bin/plugin/core/HttpRoutes.d.ts.map +1 -1
  32. package/bin/plugin/core/LocalExecution.js +1 -1
  33. package/bin/plugin/core/PluginManager.js +1 -1
  34. package/bin/plugin/types/Plugin.d.ts +2 -2
  35. package/bin/plugin/types/Plugin.d.ts.map +1 -1
  36. package/bin/{host/runtime → runtime/host}/AgentHostRuntime.d.ts +1 -1
  37. package/bin/{host/runtime → runtime/host}/AgentHostRuntime.d.ts.map +1 -1
  38. package/bin/{host/runtime → runtime/host}/AgentHostRuntime.js.map +1 -1
  39. package/bin/{host/runtime → runtime/host}/PluginRuntime.d.ts.map +1 -1
  40. package/bin/{host/runtime → runtime/host}/PluginRuntime.js.map +1 -1
  41. package/bin/{host → runtime/host}/daemon/Api.d.ts +1 -1
  42. package/bin/runtime/host/daemon/Api.d.ts.map +1 -0
  43. package/bin/runtime/host/daemon/Api.js.map +1 -0
  44. package/bin/runtime/host/daemon/Client.d.ts.map +1 -0
  45. package/bin/{host → runtime/host}/daemon/Client.js +2 -2
  46. package/bin/runtime/host/daemon/Client.js.map +1 -0
  47. package/bin/runtime/host/daemon/Paths.d.ts.map +1 -0
  48. package/bin/{host → runtime/host}/daemon/Paths.js +2 -2
  49. package/bin/runtime/host/daemon/Paths.js.map +1 -0
  50. package/bin/{host → runtime/host}/daemon/ProjectSetup.d.ts +1 -1
  51. package/bin/runtime/host/daemon/ProjectSetup.d.ts.map +1 -0
  52. package/bin/{host → runtime/host}/daemon/ProjectSetup.js +3 -3
  53. package/bin/runtime/host/daemon/ProjectSetup.js.map +1 -0
  54. package/bin/{sandbox → runtime/sandbox}/MacOsSeatbeltSandbox.d.ts +1 -1
  55. package/bin/runtime/sandbox/MacOsSeatbeltSandbox.d.ts.map +1 -0
  56. package/bin/runtime/sandbox/MacOsSeatbeltSandbox.js.map +1 -0
  57. package/bin/{sandbox → runtime/sandbox}/SandboxConfigResolver.d.ts +2 -2
  58. package/bin/runtime/sandbox/SandboxConfigResolver.d.ts.map +1 -0
  59. package/bin/runtime/sandbox/SandboxConfigResolver.js.map +1 -0
  60. package/bin/{sandbox → runtime/sandbox}/SandboxRunner.d.ts +2 -2
  61. package/bin/runtime/sandbox/SandboxRunner.d.ts.map +1 -0
  62. package/bin/{sandbox → runtime/sandbox}/SandboxRunner.js +2 -2
  63. package/bin/runtime/sandbox/SandboxRunner.js.map +1 -0
  64. package/bin/runtime/sandbox/types/Sandbox.d.ts.map +1 -0
  65. package/bin/runtime/sandbox/types/Sandbox.js.map +1 -0
  66. package/bin/{sandbox → runtime/sandbox}/types/SandboxRuntime.d.ts +2 -2
  67. package/bin/runtime/sandbox/types/SandboxRuntime.d.ts.map +1 -0
  68. package/bin/runtime/sandbox/types/SandboxRuntime.js.map +1 -0
  69. package/bin/{server → runtime/server}/http/Server.d.ts +3 -3
  70. package/bin/runtime/server/http/Server.d.ts.map +1 -0
  71. package/bin/{server → runtime/server}/http/Server.js +8 -8
  72. package/bin/runtime/server/http/Server.js.map +1 -0
  73. package/bin/runtime/server/http/auth/AuthEnv.d.ts.map +1 -0
  74. package/bin/runtime/server/http/auth/AuthEnv.js.map +1 -0
  75. package/bin/runtime/server/http/auth/AuthError.d.ts.map +1 -0
  76. package/bin/runtime/server/http/auth/AuthError.js.map +1 -0
  77. package/bin/runtime/server/http/auth/CliAuthStateStore.d.ts.map +1 -0
  78. package/bin/runtime/server/http/auth/CliAuthStateStore.js.map +1 -0
  79. package/bin/runtime/server/http/auth/PasswordHasher.d.ts.map +1 -0
  80. package/bin/runtime/server/http/auth/PasswordHasher.js.map +1 -0
  81. package/bin/runtime/server/http/auth/TokenService.d.ts.map +1 -0
  82. package/bin/runtime/server/http/auth/TokenService.js.map +1 -0
  83. package/bin/{server → runtime/server}/http/control/AuthControlService.d.ts +3 -3
  84. package/bin/runtime/server/http/control/AuthControlService.d.ts.map +1 -0
  85. package/bin/{server → runtime/server}/http/control/AuthControlService.js +1 -1
  86. package/bin/runtime/server/http/control/AuthControlService.js.map +1 -0
  87. package/bin/runtime/server/http/control/CommonHelpers.d.ts.map +1 -0
  88. package/bin/runtime/server/http/control/CommonHelpers.js.map +1 -0
  89. package/bin/{server → runtime/server}/http/control/ControlApiRoutes.d.ts +1 -1
  90. package/bin/runtime/server/http/control/ControlApiRoutes.d.ts.map +1 -0
  91. package/bin/{server → runtime/server}/http/control/ControlApiRoutes.js +5 -5
  92. package/bin/runtime/server/http/control/ControlApiRoutes.js.map +1 -0
  93. package/bin/{server → runtime/server}/http/control/ControlAuthorizationRoutes.d.ts +1 -1
  94. package/bin/runtime/server/http/control/ControlAuthorizationRoutes.d.ts.map +1 -0
  95. package/bin/{server → runtime/server}/http/control/ControlAuthorizationRoutes.js +3 -3
  96. package/bin/runtime/server/http/control/ControlAuthorizationRoutes.js.map +1 -0
  97. package/bin/{server → runtime/server}/http/control/ControlRouter.d.ts +2 -2
  98. package/bin/runtime/server/http/control/ControlRouter.d.ts.map +1 -0
  99. package/bin/{server → runtime/server}/http/control/ControlRouter.js +1 -1
  100. package/bin/runtime/server/http/control/ControlRouter.js.map +1 -0
  101. package/bin/{server → runtime/server}/http/control/ExecuteBySession.d.ts +4 -4
  102. package/bin/runtime/server/http/control/ExecuteBySession.d.ts.map +1 -0
  103. package/bin/{server → runtime/server}/http/control/ExecuteBySession.js +6 -6
  104. package/bin/runtime/server/http/control/ExecuteBySession.js.map +1 -0
  105. package/bin/{server → runtime/server}/http/control/ExecuteInput.d.ts +1 -1
  106. package/bin/runtime/server/http/control/ExecuteInput.d.ts.map +1 -0
  107. package/bin/{server → runtime/server}/http/control/ExecuteInput.js +2 -2
  108. package/bin/runtime/server/http/control/ExecuteInput.js.map +1 -0
  109. package/bin/runtime/server/http/control/Helpers.d.ts.map +1 -0
  110. package/bin/runtime/server/http/control/Helpers.js.map +1 -0
  111. package/bin/{server → runtime/server}/http/control/MessageTimeline.d.ts +2 -2
  112. package/bin/runtime/server/http/control/MessageTimeline.d.ts.map +1 -0
  113. package/bin/{server → runtime/server}/http/control/MessageTimeline.js +2 -2
  114. package/bin/runtime/server/http/control/MessageTimeline.js.map +1 -0
  115. package/bin/{server → runtime/server}/http/control/ModelRoutes.d.ts +1 -1
  116. package/bin/runtime/server/http/control/ModelRoutes.d.ts.map +1 -0
  117. package/bin/{server → runtime/server}/http/control/ModelRoutes.js +2 -2
  118. package/bin/runtime/server/http/control/ModelRoutes.js.map +1 -0
  119. package/bin/{server → runtime/server}/http/control/OverviewRoutes.d.ts +1 -1
  120. package/bin/runtime/server/http/control/OverviewRoutes.d.ts.map +1 -0
  121. package/bin/{server → runtime/server}/http/control/OverviewRoutes.js +2 -2
  122. package/bin/runtime/server/http/control/OverviewRoutes.js.map +1 -0
  123. package/bin/{server → runtime/server}/http/control/SessionRoutes.d.ts +1 -1
  124. package/bin/runtime/server/http/control/SessionRoutes.d.ts.map +1 -0
  125. package/bin/{server → runtime/server}/http/control/SessionRoutes.js +2 -2
  126. package/bin/runtime/server/http/control/SessionRoutes.js.map +1 -0
  127. package/bin/{server → runtime/server}/http/control/SessionSummaryStore.d.ts +2 -2
  128. package/bin/runtime/server/http/control/SessionSummaryStore.d.ts.map +1 -0
  129. package/bin/{server → runtime/server}/http/control/SessionSummaryStore.js +2 -2
  130. package/bin/runtime/server/http/control/SessionSummaryStore.js.map +1 -0
  131. package/bin/{server → runtime/server}/http/control/TaskRoutes.d.ts +1 -1
  132. package/bin/runtime/server/http/control/TaskRoutes.d.ts.map +1 -0
  133. package/bin/{server → runtime/server}/http/control/TaskRoutes.js +4 -4
  134. package/bin/runtime/server/http/control/TaskRoutes.js.map +1 -0
  135. package/bin/{server → runtime/server}/http/control/TaskStore.d.ts +1 -1
  136. package/bin/runtime/server/http/control/TaskStore.d.ts.map +1 -0
  137. package/bin/{server → runtime/server}/http/control/TaskStore.js +2 -2
  138. package/bin/runtime/server/http/control/TaskStore.js.map +1 -0
  139. package/bin/{server → runtime/server}/http/control/types/AuthControl.d.ts +1 -1
  140. package/bin/runtime/server/http/control/types/AuthControl.d.ts.map +1 -0
  141. package/bin/runtime/server/http/control/types/AuthControl.js.map +1 -0
  142. package/bin/{server → runtime/server}/http/control/types/ControlRoutes.d.ts +2 -2
  143. package/bin/runtime/server/http/control/types/ControlRoutes.d.ts.map +1 -0
  144. package/bin/runtime/server/http/control/types/ControlRoutes.js.map +1 -0
  145. package/bin/runtime/server/http/control/types/ControlSessionExecute.d.ts.map +1 -0
  146. package/bin/runtime/server/http/control/types/ControlSessionExecute.js.map +1 -0
  147. package/bin/{server → runtime/server}/http/control/types/ControlViewData.d.ts +1 -1
  148. package/bin/runtime/server/http/control/types/ControlViewData.d.ts.map +1 -0
  149. package/bin/runtime/server/http/control/types/ControlViewData.js.map +1 -0
  150. package/bin/{server → runtime/server}/http/execute/execute.d.ts +1 -1
  151. package/bin/runtime/server/http/execute/execute.d.ts.map +1 -0
  152. package/bin/{server → runtime/server}/http/execute/execute.js +2 -2
  153. package/bin/runtime/server/http/execute/execute.js.map +1 -0
  154. package/bin/runtime/server/http/health/health.d.ts.map +1 -0
  155. package/bin/runtime/server/http/health/health.js.map +1 -0
  156. package/bin/{server → runtime/server}/http/plugins/plugins.d.ts +1 -1
  157. package/bin/runtime/server/http/plugins/plugins.d.ts.map +1 -0
  158. package/bin/runtime/server/http/plugins/plugins.js.map +1 -0
  159. package/bin/{server → runtime/server}/http/services/services.d.ts +1 -1
  160. package/bin/runtime/server/http/services/services.d.ts.map +1 -0
  161. package/bin/{server → runtime/server}/http/services/services.js +2 -2
  162. package/bin/runtime/server/http/services/services.js.map +1 -0
  163. package/bin/{server → runtime/server}/http/static/static.d.ts +1 -1
  164. package/bin/runtime/server/http/static/static.d.ts.map +1 -0
  165. package/bin/{server → runtime/server}/http/static/static.js +1 -1
  166. package/bin/runtime/server/http/static/static.js.map +1 -0
  167. package/bin/{server → runtime/server}/rpc/Server.d.ts +4 -4
  168. package/bin/runtime/server/rpc/Server.d.ts.map +1 -0
  169. package/bin/{server → runtime/server}/rpc/Server.js +5 -5
  170. package/bin/runtime/server/rpc/Server.js.map +1 -0
  171. package/bin/{transport → runtime/transport}/rpc/Client.d.ts +1 -1
  172. package/bin/runtime/transport/rpc/Client.d.ts.map +1 -0
  173. package/bin/runtime/transport/rpc/Client.js.map +1 -0
  174. package/bin/runtime/transport/rpc/Paths.d.ts.map +1 -0
  175. package/bin/runtime/transport/rpc/Paths.js.map +1 -0
  176. package/bin/{transport → runtime/transport}/rpc/Transport.d.ts +1 -1
  177. package/bin/runtime/transport/rpc/Transport.d.ts.map +1 -0
  178. package/bin/{transport → runtime/transport}/rpc/Transport.js +1 -1
  179. package/bin/runtime/transport/rpc/Transport.js.map +1 -0
  180. package/bin/sdk/Agent.js +2 -2
  181. package/bin/sdk/Agent.js.map +1 -1
  182. package/bin/sdk/AgentSdkTypes.d.ts +3 -3
  183. package/bin/sdk/AgentSdkTypes.d.ts.map +1 -1
  184. package/bin/sdk/Session.d.ts +2 -1
  185. package/bin/sdk/Session.d.ts.map +1 -1
  186. package/bin/sdk/Session.js +13 -7
  187. package/bin/sdk/Session.js.map +1 -1
  188. package/bin/sdk/SessionSystemBuilder.d.ts +2 -2
  189. package/bin/sdk/SessionSystemBuilder.d.ts.map +1 -1
  190. package/bin/sdk/SessionSystemBuilder.js +1 -3
  191. package/bin/sdk/SessionSystemBuilder.js.map +1 -1
  192. package/bin/sdk/session/ServicePort.d.ts +3 -2
  193. package/bin/sdk/session/ServicePort.d.ts.map +1 -1
  194. package/bin/sdk/session/ServicePort.js +1 -1
  195. package/bin/sdk/session/ServicePort.js.map +1 -1
  196. package/bin/service/builtins/chat/ChatService.d.ts +1 -1
  197. package/bin/service/builtins/chat/ChatService.d.ts.map +1 -1
  198. package/bin/service/builtins/chat/ChatServiceTypes.d.ts +1 -1
  199. package/bin/service/builtins/chat/ChatServiceTypes.d.ts.map +1 -1
  200. package/bin/service/builtins/chat/accounts/ChannelAccountService.d.ts +1 -1
  201. package/bin/service/builtins/chat/accounts/ChannelAccountService.d.ts.map +1 -1
  202. package/bin/service/builtins/chat/runtime/ChatChannelConfig.d.ts +1 -1
  203. package/bin/service/builtins/chat/runtime/ChatChannelConfig.d.ts.map +1 -1
  204. package/bin/service/builtins/chat/runtime/ChatChannelCore.d.ts +1 -1
  205. package/bin/service/builtins/chat/runtime/ChatChannelCore.d.ts.map +1 -1
  206. package/bin/service/builtins/chat/runtime/ChatSession.d.ts +10 -5
  207. package/bin/service/builtins/chat/runtime/ChatSession.d.ts.map +1 -1
  208. package/bin/service/builtins/chat/runtime/ChatSession.js +6 -5
  209. package/bin/service/builtins/chat/runtime/ChatSession.js.map +1 -1
  210. package/bin/service/builtins/chat/runtime/{ChatSessionExecutionComposer.d.ts → ChatSessionContextComposer.d.ts} +7 -7
  211. package/bin/service/builtins/chat/runtime/ChatSessionContextComposer.d.ts.map +1 -0
  212. package/bin/service/builtins/chat/runtime/{ChatSessionExecutionComposer.js → ChatSessionContextComposer.js} +5 -5
  213. package/bin/service/builtins/chat/runtime/ChatSessionContextComposer.js.map +1 -0
  214. package/bin/service/builtins/chat/types/ChannelAccount.d.ts +1 -1
  215. package/bin/service/builtins/chat/types/ChannelAccount.d.ts.map +1 -1
  216. package/bin/service/builtins/memory/runtime/Flush.js +3 -3
  217. package/bin/service/builtins/memory/runtime/Flush.js.map +1 -1
  218. package/bin/service/builtins/shell/runtime/ShellActionRuntime.js +1 -1
  219. package/bin/service/builtins/shell/runtime/ShellActionRuntime.js.map +1 -1
  220. package/bin/service/builtins/shell/runtime/ShellRuntimeEnvironment.js +1 -1
  221. package/bin/service/builtins/shell/runtime/ShellRuntimeEnvironment.js.map +1 -1
  222. package/bin/service/builtins/task/runtime/Runner.d.ts.map +1 -1
  223. package/bin/service/builtins/task/runtime/Runner.js +5 -0
  224. package/bin/service/builtins/task/runtime/Runner.js.map +1 -1
  225. package/bin/service/builtins/task/runtime/TaskRunnerRound.js +2 -2
  226. package/bin/service/builtins/task/runtime/TaskRunnerRound.js.map +1 -1
  227. package/bin/service/builtins/task/runtime/TaskRunnerSession.d.ts +7 -4
  228. package/bin/service/builtins/task/runtime/TaskRunnerSession.d.ts.map +1 -1
  229. package/bin/service/builtins/task/runtime/TaskRunnerSession.js +39 -24
  230. package/bin/service/builtins/task/runtime/TaskRunnerSession.js.map +1 -1
  231. package/bin/service/builtins/task/runtime/TaskRunnerTypes.d.ts +4 -4
  232. package/bin/service/builtins/task/runtime/TaskRunnerTypes.d.ts.map +1 -1
  233. package/bin/session/Executor.d.ts +50 -17
  234. package/bin/session/Executor.d.ts.map +1 -1
  235. package/bin/session/Executor.js +366 -44
  236. package/bin/session/Executor.js.map +1 -1
  237. package/bin/session/composer/compaction/SessionCompactionComposer.d.ts +11 -12
  238. package/bin/session/composer/compaction/SessionCompactionComposer.d.ts.map +1 -1
  239. package/bin/session/composer/compaction/SessionCompactionComposer.js +2 -7
  240. package/bin/session/composer/compaction/SessionCompactionComposer.js.map +1 -1
  241. package/bin/session/composer/compaction/jsonl/JsonlSessionCompactionComposer.d.ts +3 -4
  242. package/bin/session/composer/compaction/jsonl/JsonlSessionCompactionComposer.d.ts.map +1 -1
  243. package/bin/session/composer/compaction/jsonl/JsonlSessionCompactionComposer.js +3 -5
  244. package/bin/session/composer/compaction/jsonl/JsonlSessionCompactionComposer.js.map +1 -1
  245. package/bin/session/composer/{execution/LocalSessionExecutionComposer.d.ts → context/LocalSessionContextComposer.d.ts} +10 -11
  246. package/bin/session/composer/context/LocalSessionContextComposer.d.ts.map +1 -0
  247. package/bin/session/composer/{execution/LocalSessionExecutionComposer.js → context/LocalSessionContextComposer.js} +8 -10
  248. package/bin/session/composer/context/LocalSessionContextComposer.js.map +1 -0
  249. package/bin/session/composer/{execution/SessionExecutionComposer.d.ts → context/SessionContextComposer.d.ts} +14 -15
  250. package/bin/session/composer/context/SessionContextComposer.d.ts.map +1 -0
  251. package/bin/session/composer/context/SessionContextComposer.js +9 -0
  252. package/bin/session/composer/context/SessionContextComposer.js.map +1 -0
  253. package/bin/session/composer/history/SessionHistoryComposer.d.ts +9 -111
  254. package/bin/session/composer/history/SessionHistoryComposer.d.ts.map +1 -1
  255. package/bin/session/composer/history/SessionHistoryComposer.js +3 -7
  256. package/bin/session/composer/history/SessionHistoryComposer.js.map +1 -1
  257. package/bin/session/composer/history/SessionHistoryWriter.d.ts +5 -5
  258. package/bin/session/composer/history/SessionHistoryWriter.d.ts.map +1 -1
  259. package/bin/session/composer/history/SessionHistoryWriter.js +10 -10
  260. package/bin/session/composer/history/SessionHistoryWriter.js.map +1 -1
  261. package/bin/session/composer/history/jsonl/JsonlSessionHistoryComposer.d.ts +21 -54
  262. package/bin/session/composer/history/jsonl/JsonlSessionHistoryComposer.d.ts.map +1 -1
  263. package/bin/session/composer/history/jsonl/JsonlSessionHistoryComposer.js +16 -367
  264. package/bin/session/composer/history/jsonl/JsonlSessionHistoryComposer.js.map +1 -1
  265. package/bin/session/composer/system/SessionSystemComposer.d.ts +5 -6
  266. package/bin/session/composer/system/SessionSystemComposer.d.ts.map +1 -1
  267. package/bin/session/composer/system/SessionSystemComposer.js +2 -7
  268. package/bin/session/composer/system/SessionSystemComposer.js.map +1 -1
  269. package/bin/session/composer/system/default/DefaultSessionSystemComposer.d.ts +2 -2
  270. package/bin/session/composer/system/default/DefaultSessionSystemComposer.d.ts.map +1 -1
  271. package/bin/session/composer/system/default/DefaultSessionSystemComposer.js +1 -3
  272. package/bin/session/composer/system/default/DefaultSessionSystemComposer.js.map +1 -1
  273. package/bin/session/{executors/local/SessionExecutionError.d.ts → core-engine/CoreEngineError.d.ts} +5 -5
  274. package/bin/session/core-engine/CoreEngineError.d.ts.map +1 -0
  275. package/bin/session/{executors/local/SessionExecutionError.js → core-engine/CoreEngineError.js} +4 -4
  276. package/bin/session/core-engine/CoreEngineError.js.map +1 -0
  277. package/bin/session/{executors/local/SessionLoopDecision.d.ts → core-engine/CoreEngineLoopDecision.d.ts} +6 -6
  278. package/bin/session/core-engine/CoreEngineLoopDecision.d.ts.map +1 -0
  279. package/bin/session/{executors/local/SessionLoopDecision.js → core-engine/CoreEngineLoopDecision.js} +5 -5
  280. package/bin/session/core-engine/CoreEngineLoopDecision.js.map +1 -0
  281. package/bin/session/{executors/local/SessionModelMessageState.d.ts → core-engine/CoreEngineMessageState.d.ts} +7 -7
  282. package/bin/session/core-engine/CoreEngineMessageState.d.ts.map +1 -0
  283. package/bin/session/{executors/local/SessionModelMessageState.js → core-engine/CoreEngineMessageState.js} +7 -7
  284. package/bin/session/core-engine/CoreEngineMessageState.js.map +1 -0
  285. package/bin/session/{executors/local/SessionSignals.d.ts → core-engine/CoreEngineSignals.d.ts} +6 -6
  286. package/bin/session/core-engine/CoreEngineSignals.d.ts.map +1 -0
  287. package/bin/session/{executors/local/SessionSignals.js → core-engine/CoreEngineSignals.js} +4 -4
  288. package/bin/session/core-engine/CoreEngineSignals.js.map +1 -0
  289. package/bin/session/{executors/local/SessionUiStreamCollector.d.ts → core-engine/CoreEngineUiStreamCollector.d.ts} +3 -3
  290. package/bin/session/core-engine/CoreEngineUiStreamCollector.d.ts.map +1 -0
  291. package/bin/session/{executors/local/SessionUiStreamCollector.js → core-engine/CoreEngineUiStreamCollector.js} +3 -3
  292. package/bin/session/core-engine/CoreEngineUiStreamCollector.js.map +1 -0
  293. package/bin/session/store/history/SessionHistoryStore.d.ts +119 -0
  294. package/bin/session/store/history/SessionHistoryStore.d.ts.map +1 -0
  295. package/bin/session/store/history/SessionHistoryStore.js +10 -0
  296. package/bin/session/store/history/SessionHistoryStore.js.map +1 -0
  297. package/bin/session/store/history/jsonl/JsonlSessionHistoryStore.d.ts +76 -0
  298. package/bin/session/store/history/jsonl/JsonlSessionHistoryStore.d.ts.map +1 -0
  299. package/bin/session/store/history/jsonl/JsonlSessionHistoryStore.js +374 -0
  300. package/bin/session/store/history/jsonl/JsonlSessionHistoryStore.js.map +1 -0
  301. package/bin/session/tools/shell/ShellToolFormatting.js +1 -1
  302. package/bin/session/tools/shell/ShellToolFormatting.js.map +1 -1
  303. package/bin/session/types/SessionHistoryPaths.d.ts +2 -2
  304. package/bin/session/types/SessionLoop.d.ts +1 -1
  305. package/bin/session/types/SessionLoop.js +1 -1
  306. package/bin/session/types/SessionMessages.d.ts +1 -1
  307. package/bin/session/types/SessionMessages.js +1 -1
  308. package/bin/session/types/SessionRun.d.ts +2 -2
  309. package/bin/session/types/SessionRun.js +1 -1
  310. package/bin/types/config/DowncityConfig.d.ts +4 -3
  311. package/bin/types/config/DowncityConfig.d.ts.map +1 -1
  312. package/bin/types/runtime/auth/AuthPermission.d.ts.map +1 -0
  313. package/bin/types/runtime/auth/AuthPermission.js.map +1 -0
  314. package/bin/types/runtime/auth/AuthRoute.d.ts.map +1 -0
  315. package/bin/types/runtime/auth/AuthRoute.js.map +1 -0
  316. package/bin/types/runtime/auth/AuthToken.d.ts.map +1 -0
  317. package/bin/types/runtime/auth/AuthToken.js.map +1 -0
  318. package/bin/types/runtime/auth/AuthTypes.d.ts.map +1 -0
  319. package/bin/types/runtime/auth/AuthTypes.js.map +1 -0
  320. package/bin/types/runtime/daemon/Daemon.d.ts.map +1 -0
  321. package/bin/types/runtime/daemon/Daemon.js.map +1 -0
  322. package/bin/types/{host → runtime/host}/AgentHost.d.ts +7 -7
  323. package/bin/types/runtime/host/AgentHost.d.ts.map +1 -0
  324. package/bin/types/runtime/host/AgentHost.js.map +1 -0
  325. package/bin/types/{host → runtime/host}/Store.d.ts +1 -1
  326. package/bin/types/runtime/host/Store.d.ts.map +1 -0
  327. package/bin/types/runtime/host/Store.js.map +1 -0
  328. package/bin/types/runtime/http/InlineInstant.d.ts.map +1 -0
  329. package/bin/types/runtime/http/InlineInstant.js.map +1 -0
  330. package/bin/types/runtime/platform/Platform.d.ts.map +1 -0
  331. package/bin/types/runtime/platform/Platform.js.map +1 -0
  332. package/bin/types/runtime/platform/PlatformGateway.d.ts.map +1 -0
  333. package/bin/types/runtime/platform/PlatformGateway.js.map +1 -0
  334. package/bin/types/{rpc → runtime/rpc}/LocalRpc.d.ts +2 -2
  335. package/bin/types/runtime/rpc/LocalRpc.d.ts.map +1 -0
  336. package/bin/types/runtime/rpc/LocalRpc.js.map +1 -0
  337. package/bin/utils/logger/FormatRequest.js +1 -1
  338. package/bin/utils/logger/FormatRequest.js.map +1 -1
  339. package/package.json +1 -1
  340. package/src/{project → config/project}/AgentInitializer.ts +2 -2
  341. package/src/core/AgentContextTypes.ts +9 -74
  342. package/src/core/AgentCore.ts +6 -3
  343. package/src/core/AgentCoreTypes.ts +1 -6
  344. package/src/index.ts +26 -23
  345. package/src/plugin/builtins/asr/Config.ts +1 -1
  346. package/src/plugin/builtins/auth/runtime/AuthorizationPolicy.ts +1 -1
  347. package/src/plugin/builtins/voice/Config.ts +1 -1
  348. package/src/plugin/builtins/workboard/runtime/Collector.ts +1 -1
  349. package/src/plugin/builtins/workboard/runtime/Normalizer.ts +1 -1
  350. package/src/plugin/core/HttpRoutes.ts +1 -1
  351. package/src/plugin/core/LocalExecution.ts +2 -2
  352. package/src/plugin/core/PluginManager.ts +1 -1
  353. package/src/plugin/types/Plugin.ts +2 -2
  354. package/src/{host/runtime → runtime/host}/AgentHostRuntime.ts +1 -1
  355. package/src/{host → runtime/host}/daemon/Client.ts +2 -2
  356. package/src/{host → runtime/host}/daemon/Paths.ts +1 -1
  357. package/src/{host → runtime/host}/daemon/ProjectSetup.ts +1 -1
  358. package/src/{sandbox → runtime/sandbox}/MacOsSeatbeltSandbox.ts +1 -1
  359. package/src/{sandbox → runtime/sandbox}/SandboxConfigResolver.ts +1 -1
  360. package/src/{sandbox → runtime/sandbox}/SandboxRunner.ts +3 -3
  361. package/src/{sandbox → runtime/sandbox}/types/SandboxRuntime.ts +2 -2
  362. package/src/{server → runtime/server}/http/Server.ts +6 -6
  363. package/src/{server → runtime/server}/http/control/AuthControlService.ts +1 -1
  364. package/src/{server → runtime/server}/http/control/ControlApiRoutes.ts +6 -6
  365. package/src/{server → runtime/server}/http/control/ControlAuthorizationRoutes.ts +2 -2
  366. package/src/{server → runtime/server}/http/control/ControlRouter.ts +1 -1
  367. package/src/{server → runtime/server}/http/control/ExecuteBySession.ts +1 -1
  368. package/src/{server → runtime/server}/http/control/ExecuteInput.ts +1 -1
  369. package/src/{server → runtime/server}/http/control/MessageTimeline.ts +1 -1
  370. package/src/{server → runtime/server}/http/control/ModelRoutes.ts +2 -2
  371. package/src/{server → runtime/server}/http/control/OverviewRoutes.ts +1 -1
  372. package/src/{server → runtime/server}/http/control/SessionRoutes.ts +2 -2
  373. package/src/{server → runtime/server}/http/control/SessionSummaryStore.ts +1 -1
  374. package/src/{server → runtime/server}/http/control/TaskRoutes.ts +1 -1
  375. package/src/{server → runtime/server}/http/control/TaskStore.ts +1 -1
  376. package/src/{server → runtime/server}/rpc/Server.ts +4 -4
  377. package/src/{transport → runtime/transport}/rpc/Client.ts +2 -2
  378. package/src/{transport → runtime/transport}/rpc/Transport.ts +2 -2
  379. package/src/sdk/Agent.ts +2 -2
  380. package/src/sdk/AgentSdkTypes.ts +3 -3
  381. package/src/sdk/Session.ts +13 -7
  382. package/src/sdk/SessionSystemBuilder.ts +2 -3
  383. package/src/sdk/session/ServicePort.ts +4 -3
  384. package/src/service/builtins/chat/ChatService.ts +1 -1
  385. package/src/service/builtins/chat/ChatServiceTypes.ts +1 -1
  386. package/src/service/builtins/chat/accounts/ChannelAccountService.ts +2 -2
  387. package/src/service/builtins/chat/runtime/ChatChannelConfig.ts +1 -1
  388. package/src/service/builtins/chat/runtime/ChatChannelCore.ts +1 -1
  389. package/src/service/builtins/chat/runtime/ChatSession.ts +15 -8
  390. package/src/service/builtins/chat/runtime/{ChatSessionExecutionComposer.ts → ChatSessionContextComposer.ts} +7 -7
  391. package/src/service/builtins/chat/types/ChannelAccount.ts +1 -1
  392. package/src/service/builtins/memory/runtime/Flush.ts +3 -3
  393. package/src/service/builtins/shell/runtime/ShellActionRuntime.ts +1 -1
  394. package/src/service/builtins/shell/runtime/ShellRuntimeEnvironment.ts +1 -1
  395. package/src/service/builtins/task/runtime/Runner.ts +7 -0
  396. package/src/service/builtins/task/runtime/TaskRunnerRound.ts +2 -2
  397. package/src/service/builtins/task/runtime/TaskRunnerSession.ts +48 -25
  398. package/src/service/builtins/task/runtime/TaskRunnerTypes.ts +4 -4
  399. package/src/session/Executor.ts +473 -52
  400. package/src/session/README.md +107 -0
  401. package/src/session/composer/compaction/SessionCompactionComposer.ts +11 -17
  402. package/src/session/composer/compaction/jsonl/JsonlSessionCompactionComposer.ts +7 -6
  403. package/src/session/composer/{execution/LocalSessionExecutionComposer.ts → context/LocalSessionContextComposer.ts} +14 -15
  404. package/src/session/composer/{execution/SessionExecutionComposer.ts → context/SessionContextComposer.ts} +13 -14
  405. package/src/session/composer/history/SessionHistoryComposer.ts +9 -141
  406. package/src/session/composer/history/SessionHistoryWriter.ts +14 -14
  407. package/src/session/composer/history/jsonl/JsonlSessionHistoryComposer.ts +28 -443
  408. package/src/session/composer/system/SessionSystemComposer.ts +5 -6
  409. package/src/session/composer/system/default/DefaultSessionSystemComposer.ts +2 -3
  410. package/src/session/{executors/local/SessionExecutionError.ts → core-engine/CoreEngineError.ts} +3 -3
  411. package/src/session/{executors/local/SessionLoopDecision.ts → core-engine/CoreEngineLoopDecision.ts} +4 -4
  412. package/src/session/{executors/local/SessionModelMessageState.ts → core-engine/CoreEngineMessageState.ts} +6 -6
  413. package/src/session/{executors/local/SessionSignals.ts → core-engine/CoreEngineSignals.ts} +3 -3
  414. package/src/session/{executors/local/SessionUiStreamCollector.ts → core-engine/CoreEngineUiStreamCollector.ts} +1 -1
  415. package/src/session/store/history/SessionHistoryStore.ts +145 -0
  416. package/src/session/store/history/jsonl/JsonlSessionHistoryStore.ts +465 -0
  417. package/src/session/tools/shell/ShellToolFormatting.ts +1 -1
  418. package/src/session/types/SessionHistoryPaths.ts +2 -2
  419. package/src/session/types/SessionLoop.ts +1 -1
  420. package/src/session/types/SessionMessages.ts +1 -1
  421. package/src/session/types/SessionRun.ts +2 -2
  422. package/src/types/config/DowncityConfig.ts +4 -3
  423. package/src/types/{host → runtime/host}/AgentHost.ts +3 -3
  424. package/src/types/{rpc → runtime/rpc}/LocalRpc.ts +1 -1
  425. package/src/utils/logger/FormatRequest.ts +1 -1
  426. package/tsconfig.tsbuildinfo +1 -1
  427. package/bin/host/daemon/Api.d.ts.map +0 -1
  428. package/bin/host/daemon/Api.js.map +0 -1
  429. package/bin/host/daemon/Client.d.ts.map +0 -1
  430. package/bin/host/daemon/Client.js.map +0 -1
  431. package/bin/host/daemon/Paths.d.ts.map +0 -1
  432. package/bin/host/daemon/Paths.js.map +0 -1
  433. package/bin/host/daemon/ProjectSetup.d.ts.map +0 -1
  434. package/bin/host/daemon/ProjectSetup.js.map +0 -1
  435. package/bin/model/CreateModel.d.ts +0 -30
  436. package/bin/model/CreateModel.d.ts.map +0 -1
  437. package/bin/model/CreateModel.js +0 -311
  438. package/bin/model/CreateModel.js.map +0 -1
  439. package/bin/model/ModelManager.d.ts +0 -71
  440. package/bin/model/ModelManager.d.ts.map +0 -1
  441. package/bin/model/ModelManager.js +0 -187
  442. package/bin/model/ModelManager.js.map +0 -1
  443. package/bin/project/AgentInitializer.d.ts.map +0 -1
  444. package/bin/project/AgentInitializer.js.map +0 -1
  445. package/bin/project/types/AgentProject.d.ts.map +0 -1
  446. package/bin/project/types/AgentProject.js.map +0 -1
  447. package/bin/sandbox/MacOsSeatbeltSandbox.d.ts.map +0 -1
  448. package/bin/sandbox/MacOsSeatbeltSandbox.js.map +0 -1
  449. package/bin/sandbox/SandboxConfigResolver.d.ts.map +0 -1
  450. package/bin/sandbox/SandboxConfigResolver.js.map +0 -1
  451. package/bin/sandbox/SandboxRunner.d.ts.map +0 -1
  452. package/bin/sandbox/SandboxRunner.js.map +0 -1
  453. package/bin/sandbox/types/Sandbox.d.ts.map +0 -1
  454. package/bin/sandbox/types/Sandbox.js.map +0 -1
  455. package/bin/sandbox/types/SandboxRuntime.d.ts.map +0 -1
  456. package/bin/sandbox/types/SandboxRuntime.js.map +0 -1
  457. package/bin/server/http/Server.d.ts.map +0 -1
  458. package/bin/server/http/Server.js.map +0 -1
  459. package/bin/server/http/auth/AuthEnv.d.ts.map +0 -1
  460. package/bin/server/http/auth/AuthEnv.js.map +0 -1
  461. package/bin/server/http/auth/AuthError.d.ts.map +0 -1
  462. package/bin/server/http/auth/AuthError.js.map +0 -1
  463. package/bin/server/http/auth/CliAuthStateStore.d.ts.map +0 -1
  464. package/bin/server/http/auth/CliAuthStateStore.js.map +0 -1
  465. package/bin/server/http/auth/PasswordHasher.d.ts.map +0 -1
  466. package/bin/server/http/auth/PasswordHasher.js.map +0 -1
  467. package/bin/server/http/auth/TokenService.d.ts.map +0 -1
  468. package/bin/server/http/auth/TokenService.js.map +0 -1
  469. package/bin/server/http/control/AuthControlService.d.ts.map +0 -1
  470. package/bin/server/http/control/AuthControlService.js.map +0 -1
  471. package/bin/server/http/control/CommonHelpers.d.ts.map +0 -1
  472. package/bin/server/http/control/CommonHelpers.js.map +0 -1
  473. package/bin/server/http/control/ControlApiRoutes.d.ts.map +0 -1
  474. package/bin/server/http/control/ControlApiRoutes.js.map +0 -1
  475. package/bin/server/http/control/ControlAuthorizationRoutes.d.ts.map +0 -1
  476. package/bin/server/http/control/ControlAuthorizationRoutes.js.map +0 -1
  477. package/bin/server/http/control/ControlRouter.d.ts.map +0 -1
  478. package/bin/server/http/control/ControlRouter.js.map +0 -1
  479. package/bin/server/http/control/ExecuteBySession.d.ts.map +0 -1
  480. package/bin/server/http/control/ExecuteBySession.js.map +0 -1
  481. package/bin/server/http/control/ExecuteInput.d.ts.map +0 -1
  482. package/bin/server/http/control/ExecuteInput.js.map +0 -1
  483. package/bin/server/http/control/Helpers.d.ts.map +0 -1
  484. package/bin/server/http/control/Helpers.js.map +0 -1
  485. package/bin/server/http/control/MessageTimeline.d.ts.map +0 -1
  486. package/bin/server/http/control/MessageTimeline.js.map +0 -1
  487. package/bin/server/http/control/ModelRoutes.d.ts.map +0 -1
  488. package/bin/server/http/control/ModelRoutes.js.map +0 -1
  489. package/bin/server/http/control/OverviewRoutes.d.ts.map +0 -1
  490. package/bin/server/http/control/OverviewRoutes.js.map +0 -1
  491. package/bin/server/http/control/SessionRoutes.d.ts.map +0 -1
  492. package/bin/server/http/control/SessionRoutes.js.map +0 -1
  493. package/bin/server/http/control/SessionSummaryStore.d.ts.map +0 -1
  494. package/bin/server/http/control/SessionSummaryStore.js.map +0 -1
  495. package/bin/server/http/control/TaskRoutes.d.ts.map +0 -1
  496. package/bin/server/http/control/TaskRoutes.js.map +0 -1
  497. package/bin/server/http/control/TaskStore.d.ts.map +0 -1
  498. package/bin/server/http/control/TaskStore.js.map +0 -1
  499. package/bin/server/http/control/types/AuthControl.d.ts.map +0 -1
  500. package/bin/server/http/control/types/AuthControl.js.map +0 -1
  501. package/bin/server/http/control/types/ControlRoutes.d.ts.map +0 -1
  502. package/bin/server/http/control/types/ControlRoutes.js.map +0 -1
  503. package/bin/server/http/control/types/ControlSessionExecute.d.ts.map +0 -1
  504. package/bin/server/http/control/types/ControlSessionExecute.js.map +0 -1
  505. package/bin/server/http/control/types/ControlViewData.d.ts.map +0 -1
  506. package/bin/server/http/control/types/ControlViewData.js.map +0 -1
  507. package/bin/server/http/execute/execute.d.ts.map +0 -1
  508. package/bin/server/http/execute/execute.js.map +0 -1
  509. package/bin/server/http/health/health.d.ts.map +0 -1
  510. package/bin/server/http/health/health.js.map +0 -1
  511. package/bin/server/http/plugins/plugins.d.ts.map +0 -1
  512. package/bin/server/http/plugins/plugins.js.map +0 -1
  513. package/bin/server/http/services/services.d.ts.map +0 -1
  514. package/bin/server/http/services/services.js.map +0 -1
  515. package/bin/server/http/static/static.d.ts.map +0 -1
  516. package/bin/server/http/static/static.js.map +0 -1
  517. package/bin/server/rpc/Server.d.ts.map +0 -1
  518. package/bin/server/rpc/Server.js.map +0 -1
  519. package/bin/service/builtins/chat/runtime/ChatSessionExecutionComposer.d.ts.map +0 -1
  520. package/bin/service/builtins/chat/runtime/ChatSessionExecutionComposer.js.map +0 -1
  521. package/bin/session/composer/SessionComposer.d.ts +0 -29
  522. package/bin/session/composer/SessionComposer.d.ts.map +0 -1
  523. package/bin/session/composer/SessionComposer.js +0 -29
  524. package/bin/session/composer/SessionComposer.js.map +0 -1
  525. package/bin/session/composer/execution/LocalSessionExecutionComposer.d.ts.map +0 -1
  526. package/bin/session/composer/execution/LocalSessionExecutionComposer.js.map +0 -1
  527. package/bin/session/composer/execution/SessionExecutionComposer.d.ts.map +0 -1
  528. package/bin/session/composer/execution/SessionExecutionComposer.js +0 -14
  529. package/bin/session/composer/execution/SessionExecutionComposer.js.map +0 -1
  530. package/bin/session/executors/local/Runner.d.ts +0 -108
  531. package/bin/session/executors/local/Runner.d.ts.map +0 -1
  532. package/bin/session/executors/local/Runner.js +0 -219
  533. package/bin/session/executors/local/Runner.js.map +0 -1
  534. package/bin/session/executors/local/SessionExecutionError.d.ts.map +0 -1
  535. package/bin/session/executors/local/SessionExecutionError.js.map +0 -1
  536. package/bin/session/executors/local/SessionLoopDecision.d.ts.map +0 -1
  537. package/bin/session/executors/local/SessionLoopDecision.js.map +0 -1
  538. package/bin/session/executors/local/SessionModelMessageState.d.ts.map +0 -1
  539. package/bin/session/executors/local/SessionModelMessageState.js.map +0 -1
  540. package/bin/session/executors/local/SessionSignals.d.ts.map +0 -1
  541. package/bin/session/executors/local/SessionSignals.js.map +0 -1
  542. package/bin/session/executors/local/SessionToolLoopRunner.d.ts +0 -44
  543. package/bin/session/executors/local/SessionToolLoopRunner.d.ts.map +0 -1
  544. package/bin/session/executors/local/SessionToolLoopRunner.js +0 -261
  545. package/bin/session/executors/local/SessionToolLoopRunner.js.map +0 -1
  546. package/bin/session/executors/local/SessionUiStreamCollector.d.ts.map +0 -1
  547. package/bin/session/executors/local/SessionUiStreamCollector.js.map +0 -1
  548. package/bin/transport/rpc/Client.d.ts.map +0 -1
  549. package/bin/transport/rpc/Client.js.map +0 -1
  550. package/bin/transport/rpc/Paths.d.ts.map +0 -1
  551. package/bin/transport/rpc/Paths.js.map +0 -1
  552. package/bin/transport/rpc/Transport.d.ts.map +0 -1
  553. package/bin/transport/rpc/Transport.js.map +0 -1
  554. package/bin/types/auth/AuthPermission.d.ts.map +0 -1
  555. package/bin/types/auth/AuthPermission.js.map +0 -1
  556. package/bin/types/auth/AuthRoute.d.ts.map +0 -1
  557. package/bin/types/auth/AuthRoute.js.map +0 -1
  558. package/bin/types/auth/AuthToken.d.ts.map +0 -1
  559. package/bin/types/auth/AuthToken.js.map +0 -1
  560. package/bin/types/auth/AuthTypes.d.ts.map +0 -1
  561. package/bin/types/auth/AuthTypes.js.map +0 -1
  562. package/bin/types/daemon/Daemon.d.ts.map +0 -1
  563. package/bin/types/daemon/Daemon.js.map +0 -1
  564. package/bin/types/host/AgentHost.d.ts.map +0 -1
  565. package/bin/types/host/AgentHost.js.map +0 -1
  566. package/bin/types/host/Store.d.ts.map +0 -1
  567. package/bin/types/host/Store.js.map +0 -1
  568. package/bin/types/http/InlineInstant.d.ts.map +0 -1
  569. package/bin/types/http/InlineInstant.js.map +0 -1
  570. package/bin/types/platform/Platform.d.ts.map +0 -1
  571. package/bin/types/platform/Platform.js.map +0 -1
  572. package/bin/types/platform/PlatformGateway.d.ts.map +0 -1
  573. package/bin/types/platform/PlatformGateway.js.map +0 -1
  574. package/bin/types/rpc/LocalRpc.d.ts.map +0 -1
  575. package/bin/types/rpc/LocalRpc.js.map +0 -1
  576. package/src/model/CreateModel.ts +0 -350
  577. package/src/model/ModelManager.ts +0 -242
  578. package/src/session/composer/SessionComposer.ts +0 -34
  579. package/src/session/executors/local/Runner.ts +0 -297
  580. package/src/session/executors/local/SessionToolLoopRunner.ts +0 -350
  581. /package/bin/{project → config/project}/types/AgentProject.js +0 -0
  582. /package/bin/{host/runtime → runtime/host}/AgentHostRuntime.js +0 -0
  583. /package/bin/{host/runtime → runtime/host}/PluginRuntime.d.ts +0 -0
  584. /package/bin/{host/runtime → runtime/host}/PluginRuntime.js +0 -0
  585. /package/bin/{host → runtime/host}/daemon/Api.js +0 -0
  586. /package/bin/{host → runtime/host}/daemon/Client.d.ts +0 -0
  587. /package/bin/{host → runtime/host}/daemon/Paths.d.ts +0 -0
  588. /package/bin/{sandbox → runtime/sandbox}/MacOsSeatbeltSandbox.js +0 -0
  589. /package/bin/{sandbox → runtime/sandbox}/SandboxConfigResolver.js +0 -0
  590. /package/bin/{sandbox → runtime/sandbox}/types/Sandbox.d.ts +0 -0
  591. /package/bin/{sandbox → runtime/sandbox}/types/Sandbox.js +0 -0
  592. /package/bin/{sandbox → runtime/sandbox}/types/SandboxRuntime.js +0 -0
  593. /package/bin/{server → runtime/server}/http/auth/AuthEnv.d.ts +0 -0
  594. /package/bin/{server → runtime/server}/http/auth/AuthEnv.js +0 -0
  595. /package/bin/{server → runtime/server}/http/auth/AuthError.d.ts +0 -0
  596. /package/bin/{server → runtime/server}/http/auth/AuthError.js +0 -0
  597. /package/bin/{server → runtime/server}/http/auth/CliAuthStateStore.d.ts +0 -0
  598. /package/bin/{server → runtime/server}/http/auth/CliAuthStateStore.js +0 -0
  599. /package/bin/{server → runtime/server}/http/auth/PasswordHasher.d.ts +0 -0
  600. /package/bin/{server → runtime/server}/http/auth/PasswordHasher.js +0 -0
  601. /package/bin/{server → runtime/server}/http/auth/TokenService.d.ts +0 -0
  602. /package/bin/{server → runtime/server}/http/auth/TokenService.js +0 -0
  603. /package/bin/{server → runtime/server}/http/control/CommonHelpers.d.ts +0 -0
  604. /package/bin/{server → runtime/server}/http/control/CommonHelpers.js +0 -0
  605. /package/bin/{server → runtime/server}/http/control/Helpers.d.ts +0 -0
  606. /package/bin/{server → runtime/server}/http/control/Helpers.js +0 -0
  607. /package/bin/{server → runtime/server}/http/control/types/AuthControl.js +0 -0
  608. /package/bin/{server → runtime/server}/http/control/types/ControlRoutes.js +0 -0
  609. /package/bin/{server → runtime/server}/http/control/types/ControlSessionExecute.d.ts +0 -0
  610. /package/bin/{server → runtime/server}/http/control/types/ControlSessionExecute.js +0 -0
  611. /package/bin/{server → runtime/server}/http/control/types/ControlViewData.js +0 -0
  612. /package/bin/{server → runtime/server}/http/health/health.d.ts +0 -0
  613. /package/bin/{server → runtime/server}/http/health/health.js +0 -0
  614. /package/bin/{server → runtime/server}/http/plugins/plugins.js +0 -0
  615. /package/bin/{transport → runtime/transport}/rpc/Client.js +0 -0
  616. /package/bin/{transport → runtime/transport}/rpc/Paths.d.ts +0 -0
  617. /package/bin/{transport → runtime/transport}/rpc/Paths.js +0 -0
  618. /package/bin/types/{auth → runtime/auth}/AuthPermission.d.ts +0 -0
  619. /package/bin/types/{auth → runtime/auth}/AuthPermission.js +0 -0
  620. /package/bin/types/{auth → runtime/auth}/AuthRoute.d.ts +0 -0
  621. /package/bin/types/{auth → runtime/auth}/AuthRoute.js +0 -0
  622. /package/bin/types/{auth → runtime/auth}/AuthToken.d.ts +0 -0
  623. /package/bin/types/{auth → runtime/auth}/AuthToken.js +0 -0
  624. /package/bin/types/{auth → runtime/auth}/AuthTypes.d.ts +0 -0
  625. /package/bin/types/{auth → runtime/auth}/AuthTypes.js +0 -0
  626. /package/bin/types/{daemon → runtime/daemon}/Daemon.d.ts +0 -0
  627. /package/bin/types/{daemon → runtime/daemon}/Daemon.js +0 -0
  628. /package/bin/types/{host → runtime/host}/AgentHost.js +0 -0
  629. /package/bin/types/{host → runtime/host}/Store.js +0 -0
  630. /package/bin/types/{http → runtime/http}/InlineInstant.d.ts +0 -0
  631. /package/bin/types/{http → runtime/http}/InlineInstant.js +0 -0
  632. /package/bin/types/{platform → runtime/platform}/Platform.d.ts +0 -0
  633. /package/bin/types/{platform → runtime/platform}/Platform.js +0 -0
  634. /package/bin/types/{platform → runtime/platform}/PlatformGateway.d.ts +0 -0
  635. /package/bin/types/{platform → runtime/platform}/PlatformGateway.js +0 -0
  636. /package/bin/types/{rpc → runtime/rpc}/LocalRpc.js +0 -0
  637. /package/src/{project → config/project}/types/AgentProject.ts +0 -0
  638. /package/src/{host/runtime → runtime/host}/PluginRuntime.ts +0 -0
  639. /package/src/{host → runtime/host}/daemon/Api.ts +0 -0
  640. /package/src/{sandbox → runtime/sandbox}/types/Sandbox.ts +0 -0
  641. /package/src/{server → runtime/server}/http/auth/AuthEnv.ts +0 -0
  642. /package/src/{server → runtime/server}/http/auth/AuthError.ts +0 -0
  643. /package/src/{server → runtime/server}/http/auth/CliAuthStateStore.ts +0 -0
  644. /package/src/{server → runtime/server}/http/auth/PasswordHasher.ts +0 -0
  645. /package/src/{server → runtime/server}/http/auth/TokenService.ts +0 -0
  646. /package/src/{server → runtime/server}/http/control/CommonHelpers.ts +0 -0
  647. /package/src/{server → runtime/server}/http/control/Helpers.ts +0 -0
  648. /package/src/{server → runtime/server}/http/control/types/AuthControl.ts +0 -0
  649. /package/src/{server → runtime/server}/http/control/types/ControlRoutes.ts +0 -0
  650. /package/src/{server → runtime/server}/http/control/types/ControlSessionExecute.ts +0 -0
  651. /package/src/{server → runtime/server}/http/control/types/ControlViewData.ts +0 -0
  652. /package/src/{server → runtime/server}/http/execute/execute.ts +0 -0
  653. /package/src/{server → runtime/server}/http/health/health.ts +0 -0
  654. /package/src/{server → runtime/server}/http/plugins/plugins.ts +0 -0
  655. /package/src/{server → runtime/server}/http/services/services.ts +0 -0
  656. /package/src/{server → runtime/server}/http/static/static.ts +0 -0
  657. /package/src/{transport → runtime/transport}/rpc/Paths.ts +0 -0
  658. /package/src/types/{auth → runtime/auth}/AuthPermission.ts +0 -0
  659. /package/src/types/{auth → runtime/auth}/AuthRoute.ts +0 -0
  660. /package/src/types/{auth → runtime/auth}/AuthToken.ts +0 -0
  661. /package/src/types/{auth → runtime/auth}/AuthTypes.ts +0 -0
  662. /package/src/types/{daemon → runtime/daemon}/Daemon.ts +0 -0
  663. /package/src/types/{host → runtime/host}/Store.ts +0 -0
  664. /package/src/types/{http → runtime/http}/InlineInstant.ts +0 -0
  665. /package/src/types/{platform → runtime/platform}/Platform.ts +0 -0
  666. /package/src/types/{platform → runtime/platform}/PlatformGateway.ts +0 -0
@@ -0,0 +1,145 @@
1
+ /**
2
+ * SessionHistoryStore:会话历史事实源接口。
3
+ *
4
+ * 关键点(中文)
5
+ * - Store 负责消息、meta、archive、lock 等持久化能力。
6
+ * - Composer 只负责把 Store 中的历史组装成本轮模型输入。
7
+ * - 这个接口刻意独立于 Composer,避免把“落盘事实源”误当成“组装策略”。
8
+ */
9
+
10
+ import type { LanguageModel } from "ai";
11
+ import type {
12
+ SessionMessageV1,
13
+ SessionMetadataV1,
14
+ } from "@/session/types/SessionMessages.js";
15
+ import type { SessionSystemMessage } from "@/session/types/SessionPrompts.js";
16
+
17
+ /**
18
+ * compact 输入参数。
19
+ */
20
+ export type SessionHistoryCompactInput = {
21
+ /**
22
+ * 当前模型实例。
23
+ */
24
+ model: LanguageModel;
25
+
26
+ /**
27
+ * 当前轮 system messages。
28
+ */
29
+ system: SessionSystemMessage[];
30
+
31
+ /**
32
+ * 保留最近消息条数。
33
+ */
34
+ keepLastMessages: number;
35
+
36
+ /**
37
+ * 输入 token 近似上限。
38
+ */
39
+ maxInputTokensApprox: number;
40
+
41
+ /**
42
+ * compact 时是否归档旧消息。
43
+ */
44
+ archiveOnCompact: boolean;
45
+
46
+ /**
47
+ * 前段压缩比例(0-1)。
48
+ */
49
+ compactRatio: number;
50
+ };
51
+
52
+ /**
53
+ * 会话历史事实源。
54
+ */
55
+ export interface SessionHistoryStore {
56
+ /**
57
+ * 当前会话 ID。
58
+ */
59
+ readonly sessionId: string;
60
+
61
+ /**
62
+ * 追加一条消息到历史。
63
+ */
64
+ append(message: SessionMessageV1): Promise<void>;
65
+
66
+ /**
67
+ * 读取完整消息历史。
68
+ */
69
+ list(): Promise<SessionMessageV1[]>;
70
+
71
+ /**
72
+ * 读取消息区间 [start, end)。
73
+ */
74
+ slice(start: number, end: number): Promise<SessionMessageV1[]>;
75
+
76
+ /**
77
+ * 读取消息总条数。
78
+ */
79
+ size(): Promise<number>;
80
+
81
+ /**
82
+ * 读取元信息。
83
+ */
84
+ meta(): Promise<Record<string, unknown>>;
85
+
86
+ /**
87
+ * 执行一次 compact(best-effort)。
88
+ */
89
+ compact(input: SessionHistoryCompactInput): Promise<{
90
+ compacted: boolean;
91
+ reason?: string;
92
+ }>;
93
+
94
+ /**
95
+ * 构造 user 文本消息。
96
+ */
97
+ userText(input: {
98
+ /**
99
+ * 用户文本内容。
100
+ */
101
+ text: string;
102
+
103
+ /**
104
+ * 消息元信息(除 schema 字段)。
105
+ */
106
+ metadata: Omit<SessionMetadataV1, "v" | "ts"> &
107
+ Partial<Pick<SessionMetadataV1, "ts">>;
108
+
109
+ /**
110
+ * 可选消息 ID(默认自动生成)。
111
+ */
112
+ id?: string;
113
+ }): SessionMessageV1;
114
+
115
+ /**
116
+ * 构造 assistant 文本消息。
117
+ */
118
+ assistantText(input: {
119
+ /**
120
+ * 助手文本内容。
121
+ */
122
+ text: string;
123
+
124
+ /**
125
+ * 消息元信息(除 schema 字段)。
126
+ */
127
+ metadata: Omit<SessionMetadataV1, "v" | "ts"> &
128
+ Partial<Pick<SessionMetadataV1, "ts">>;
129
+
130
+ /**
131
+ * 可选消息 ID(默认自动生成)。
132
+ */
133
+ id?: string;
134
+
135
+ /**
136
+ * 消息种类(普通/摘要)。
137
+ */
138
+ kind?: "normal" | "summary";
139
+
140
+ /**
141
+ * 消息来源(egress/compact)。
142
+ */
143
+ source?: "egress" | "compact";
144
+ }): SessionMessageV1;
145
+ }
@@ -0,0 +1,465 @@
1
+ /**
2
+ * JsonlSessionHistoryStore:基于 JSONL 的 session history 事实源。
3
+ *
4
+ * 关键点(中文)
5
+ * - 负责 `.downcity/.../messages/messages.jsonl`、`meta.json`、archive 与文件锁。
6
+ * - append 与 compact 共用同一把文件锁,避免并发覆盖。
7
+ * - 不负责为模型组装 messages;组装逻辑放在 `JsonlSessionHistoryComposer`。
8
+ */
9
+
10
+ import fs from "fs-extra";
11
+ import {
12
+ open as openFile,
13
+ readFile as readFileNative,
14
+ stat as statNative,
15
+ } from "node:fs/promises";
16
+ import path from "node:path";
17
+ import { generateId } from "@/utils/Id.js";
18
+ import { getLogger } from "@/utils/logger/Logger.js";
19
+ import { compactSessionMessagesIfNeeded } from "@session/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js";
20
+ import type {
21
+ SessionMessageV1,
22
+ SessionMetadataV1,
23
+ } from "@/session/types/SessionMessages.js";
24
+ import type { SessionSystemMessage } from "@/session/types/SessionPrompts.js";
25
+ import type { SessionHistoryMetaV1 } from "@/session/types/SessionHistoryMeta.js";
26
+ import type { SessionHistoryPathOverrides } from "@/session/types/SessionHistoryPaths.js";
27
+ import type {
28
+ SessionHistoryCompactInput,
29
+ SessionHistoryStore,
30
+ } from "@/session/store/history/SessionHistoryStore.js";
31
+
32
+ /**
33
+ * JSONL history store 构造参数。
34
+ */
35
+ export type JsonlSessionHistoryStoreOptions = {
36
+ /**
37
+ * 当前项目根目录。
38
+ */
39
+ rootPath: string;
40
+ /**
41
+ * 当前 sessionId。
42
+ */
43
+ sessionId?: string;
44
+ /**
45
+ * 可选路径覆盖,供 SDK session / task run 复用同一 JSONL store。
46
+ */
47
+ paths?: SessionHistoryPathOverrides;
48
+ };
49
+
50
+ function getDowncityDirPath(rootPath: string): string {
51
+ return path.join(rootPath, ".downcity");
52
+ }
53
+
54
+ function getDowncitySessionRootDirPath(rootPath: string): string {
55
+ return path.join(getDowncityDirPath(rootPath), "session");
56
+ }
57
+
58
+ function getDowncitySessionDirPath(rootPath: string, sessionId: string): string {
59
+ return path.join(
60
+ getDowncitySessionRootDirPath(rootPath),
61
+ encodeURIComponent(sessionId),
62
+ );
63
+ }
64
+
65
+ function getDowncitySessionMessagesDirPath(
66
+ rootPath: string,
67
+ sessionId: string,
68
+ ): string {
69
+ return path.join(getDowncitySessionDirPath(rootPath, sessionId), "messages");
70
+ }
71
+
72
+ /**
73
+ * JSONL Session history store。
74
+ */
75
+ export class JsonlSessionHistoryStore implements SessionHistoryStore {
76
+ readonly sessionId: string;
77
+
78
+ private readonly rootPath: string;
79
+ private readonly overrideSessionDirPath?: string;
80
+ private readonly overrideMessagesDirPath?: string;
81
+ private readonly overrideMessagesFilePath?: string;
82
+ private readonly overrideMetaFilePath?: string;
83
+ private readonly overrideArchiveDirPath?: string;
84
+
85
+ constructor(options: JsonlSessionHistoryStoreOptions) {
86
+ const rootPath = String(options.rootPath || "").trim();
87
+ if (!rootPath) {
88
+ throw new Error("JsonlSessionHistoryStore requires a non-empty rootPath");
89
+ }
90
+ const sessionId = String(options.sessionId || "").trim();
91
+ if (!sessionId) {
92
+ throw new Error("JsonlSessionHistoryStore requires a non-empty sessionId");
93
+ }
94
+
95
+ this.rootPath = rootPath;
96
+ this.sessionId = sessionId;
97
+ this.overrideSessionDirPath = this.readOptionalPath(
98
+ options.paths?.sessionDirPath,
99
+ );
100
+ this.overrideMessagesDirPath = this.readOptionalPath(
101
+ options.paths?.messagesDirPath,
102
+ );
103
+ this.overrideMessagesFilePath = this.readOptionalPath(
104
+ options.paths?.messagesFilePath,
105
+ );
106
+ this.overrideMetaFilePath = this.readOptionalPath(
107
+ options.paths?.metaFilePath,
108
+ );
109
+ this.overrideArchiveDirPath = this.readOptionalPath(
110
+ options.paths?.archiveDirPath,
111
+ );
112
+ }
113
+
114
+ private readOptionalPath(value: string | undefined): string | undefined {
115
+ const out = String(value || "").trim();
116
+ return out || undefined;
117
+ }
118
+
119
+ private getMessagesDirPath(): string {
120
+ if (this.overrideMessagesDirPath) return this.overrideMessagesDirPath;
121
+ if (this.overrideSessionDirPath) {
122
+ return path.join(this.overrideSessionDirPath, "messages");
123
+ }
124
+ return getDowncitySessionMessagesDirPath(this.rootPath, this.sessionId);
125
+ }
126
+
127
+ private getMessagesFilePath(): string {
128
+ if (this.overrideMessagesFilePath) return this.overrideMessagesFilePath;
129
+ if (this.overrideMessagesDirPath) {
130
+ return path.join(this.overrideMessagesDirPath, "messages.jsonl");
131
+ }
132
+ return path.join(this.getMessagesDirPath(), "messages.jsonl");
133
+ }
134
+
135
+ private getMetaFilePath(): string {
136
+ if (this.overrideMetaFilePath) return this.overrideMetaFilePath;
137
+ if (this.overrideMessagesDirPath) {
138
+ return path.join(this.overrideMessagesDirPath, "meta.json");
139
+ }
140
+ return path.join(this.getMessagesDirPath(), "meta.json");
141
+ }
142
+
143
+ private getArchiveDirPath(): string {
144
+ if (this.overrideArchiveDirPath) return this.overrideArchiveDirPath;
145
+ if (this.overrideMessagesDirPath) {
146
+ return path.join(this.overrideMessagesDirPath, "archive");
147
+ }
148
+ return path.join(this.getMessagesDirPath(), "archive");
149
+ }
150
+
151
+ private getLockFilePath(): string {
152
+ return path.join(this.getMessagesDirPath(), ".session.lock");
153
+ }
154
+
155
+ private async ensureLayout(): Promise<void> {
156
+ // 关键点(中文):以 messages 目录为最小落盘单元,统一保证 messages/meta/archive 可写。
157
+ await fs.ensureDir(this.getMessagesDirPath());
158
+ await fs.ensureDir(this.getArchiveDirPath());
159
+ await fs.ensureFile(this.getMessagesFilePath());
160
+ }
161
+
162
+ private normalizePinnedSkillIds(input: string[] | undefined): string[] {
163
+ if (!Array.isArray(input)) return [];
164
+ const out: string[] = [];
165
+ for (const raw of input) {
166
+ const id = typeof raw === "string" ? raw.trim() : "";
167
+ if (!id) continue;
168
+ out.push(id);
169
+ }
170
+ return Array.from(new Set(out)).slice(0, 2000);
171
+ }
172
+
173
+ private normalizeSdkConfig(
174
+ input: SessionHistoryMetaV1["sdkConfig"],
175
+ ): SessionHistoryMetaV1["sdkConfig"] {
176
+ if (!input || typeof input !== "object" || Array.isArray(input)) {
177
+ return undefined;
178
+ }
179
+ const modelLabel =
180
+ typeof input.modelLabel === "string" ? input.modelLabel.trim() : "";
181
+ if (!modelLabel) return undefined;
182
+ return {
183
+ modelLabel,
184
+ };
185
+ }
186
+
187
+ private async readMetaUnsafe(): Promise<SessionHistoryMetaV1> {
188
+ const file = this.getMetaFilePath();
189
+ try {
190
+ const raw = (await fs.readJson(
191
+ file,
192
+ )) as Partial<SessionHistoryMetaV1> | null;
193
+ if (!raw || typeof raw !== "object") throw new Error("invalid_meta");
194
+ return {
195
+ v: 1,
196
+ sessionId: this.sessionId,
197
+ ...(typeof raw.agentId === "string" && raw.agentId.trim()
198
+ ? { agentId: raw.agentId.trim() }
199
+ : {}),
200
+ ...(typeof raw.createdAt === "number" && Number.isFinite(raw.createdAt)
201
+ ? { createdAt: raw.createdAt }
202
+ : {}),
203
+ updatedAt: typeof raw.updatedAt === "number" ? raw.updatedAt : 0,
204
+ pinnedSkillIds: this.normalizePinnedSkillIds(raw.pinnedSkillIds),
205
+ ...(typeof raw.lastArchiveId === "string" && raw.lastArchiveId.trim()
206
+ ? { lastArchiveId: raw.lastArchiveId.trim() }
207
+ : {}),
208
+ ...(typeof raw.keepLastMessages === "number" &&
209
+ Number.isFinite(raw.keepLastMessages)
210
+ ? { keepLastMessages: raw.keepLastMessages }
211
+ : {}),
212
+ ...(typeof raw.maxInputTokensApprox === "number" &&
213
+ Number.isFinite(raw.maxInputTokensApprox)
214
+ ? { maxInputTokensApprox: raw.maxInputTokensApprox }
215
+ : {}),
216
+ ...(typeof raw.compactRatio === "number" && Number.isFinite(raw.compactRatio)
217
+ ? { compactRatio: raw.compactRatio }
218
+ : {}),
219
+ ...(this.normalizeSdkConfig(raw.sdkConfig)
220
+ ? { sdkConfig: this.normalizeSdkConfig(raw.sdkConfig) }
221
+ : {}),
222
+ };
223
+ } catch {
224
+ return {
225
+ v: 1,
226
+ sessionId: this.sessionId,
227
+ createdAt: Date.now(),
228
+ updatedAt: 0,
229
+ pinnedSkillIds: [],
230
+ };
231
+ }
232
+ }
233
+
234
+ private async writeMetaUnsafe(next: SessionHistoryMetaV1): Promise<void> {
235
+ const normalized: SessionHistoryMetaV1 = {
236
+ v: 1,
237
+ sessionId: this.sessionId,
238
+ ...(typeof next.agentId === "string" && next.agentId.trim()
239
+ ? { agentId: next.agentId.trim() }
240
+ : {}),
241
+ ...(typeof next.createdAt === "number" && Number.isFinite(next.createdAt)
242
+ ? { createdAt: next.createdAt }
243
+ : {}),
244
+ updatedAt:
245
+ typeof next.updatedAt === "number" ? next.updatedAt : Date.now(),
246
+ pinnedSkillIds: this.normalizePinnedSkillIds(next.pinnedSkillIds),
247
+ ...(typeof next.lastArchiveId === "string" && next.lastArchiveId.trim()
248
+ ? { lastArchiveId: next.lastArchiveId.trim() }
249
+ : {}),
250
+ ...(typeof next.keepLastMessages === "number" &&
251
+ Number.isFinite(next.keepLastMessages)
252
+ ? { keepLastMessages: next.keepLastMessages }
253
+ : {}),
254
+ ...(typeof next.maxInputTokensApprox === "number" &&
255
+ Number.isFinite(next.maxInputTokensApprox)
256
+ ? { maxInputTokensApprox: next.maxInputTokensApprox }
257
+ : {}),
258
+ ...(typeof next.compactRatio === "number" &&
259
+ Number.isFinite(next.compactRatio)
260
+ ? { compactRatio: next.compactRatio }
261
+ : {}),
262
+ ...(this.normalizeSdkConfig(next.sdkConfig)
263
+ ? { sdkConfig: this.normalizeSdkConfig(next.sdkConfig) }
264
+ : {}),
265
+ };
266
+ await fs.writeJson(this.getMetaFilePath(), normalized, { spaces: 2 });
267
+ }
268
+
269
+ private async withWriteLock<T>(fn: () => Promise<T>): Promise<T> {
270
+ await this.ensureLayout();
271
+ const lockPath = this.getLockFilePath();
272
+ const token = `${process.pid}:${Date.now()}:${generateId()}`;
273
+ const logger = getLogger(this.rootPath, "info");
274
+
275
+ // 关键点(中文):append 与 compact 共用同一把文件锁,防止 rewrite 覆盖 append。
276
+ const staleMs = 30_000;
277
+ const start = Date.now();
278
+ while (true) {
279
+ try {
280
+ const fh = await openFile(lockPath, "wx");
281
+ await fh.writeFile(token, "utf8");
282
+ await fh.close();
283
+ break;
284
+ } catch (error) {
285
+ const err = error as NodeJS.ErrnoException;
286
+ if (err.code !== "EEXIST") throw err;
287
+ try {
288
+ const stat = await statNative(lockPath);
289
+ const age = Date.now() - stat.mtimeMs;
290
+ if (age > staleMs) {
291
+ await fs.remove(lockPath);
292
+ await logger.log("warn", "Removed stale session lock", {
293
+ sessionId: this.sessionId,
294
+ lockPath,
295
+ ageMs: age,
296
+ });
297
+ continue;
298
+ }
299
+ } catch {
300
+ // ignore
301
+ }
302
+ if (Date.now() - start > staleMs * 2) {
303
+ throw new Error(`Context lock timeout: ${lockPath}`);
304
+ }
305
+ await new Promise((resolve) => setTimeout(resolve, 60));
306
+ }
307
+ }
308
+
309
+ try {
310
+ return await fn();
311
+ } finally {
312
+ try {
313
+ const current = await readFileNative(lockPath, "utf8");
314
+ if (String(current || "").trim() === token) {
315
+ await fs.remove(lockPath);
316
+ }
317
+ } catch {
318
+ // ignore
319
+ }
320
+ }
321
+ }
322
+
323
+ private normalizeSystem(system: SessionSystemMessage[]): SessionSystemMessage[] {
324
+ if (!Array.isArray(system)) return [];
325
+ return system.filter((item) => item && typeof item === "object");
326
+ }
327
+
328
+ async compact(input: SessionHistoryCompactInput): Promise<{
329
+ compacted: boolean;
330
+ reason?: string;
331
+ }> {
332
+ return await compactSessionMessagesIfNeeded(
333
+ {
334
+ rootPath: this.rootPath,
335
+ sessionId: this.sessionId,
336
+ withWriteLock: (fn) => this.withWriteLock(fn),
337
+ loadAll: () => this.list(),
338
+ createSummaryMessage: ({ text, sourceRange }) => ({
339
+ id: `a:${this.sessionId}:${generateId()}`,
340
+ role: "assistant",
341
+ metadata: {
342
+ v: 1,
343
+ ts: Date.now(),
344
+ sessionId: this.sessionId,
345
+ source: "compact",
346
+ kind: "summary",
347
+ ...(sourceRange ? { sourceRange } : {}),
348
+ },
349
+ parts: [{ type: "text", text: String(text ?? "") }],
350
+ }),
351
+ getArchiveDirPath: () => this.getArchiveDirPath(),
352
+ getMessagesFilePath: () => this.getMessagesFilePath(),
353
+ readMetaUnsafe: () => this.readMetaUnsafe(),
354
+ writeMetaUnsafe: (next) => this.writeMetaUnsafe(next),
355
+ },
356
+ {
357
+ model: input.model,
358
+ system: this.normalizeSystem(input.system),
359
+ keepLastMessages: input.keepLastMessages,
360
+ maxInputTokensApprox: input.maxInputTokensApprox,
361
+ archiveOnCompact: input.archiveOnCompact,
362
+ compactRatio: input.compactRatio,
363
+ },
364
+ );
365
+ }
366
+
367
+ async append(message: SessionMessageV1): Promise<void> {
368
+ await this.withWriteLock(async () => {
369
+ await fs.appendFile(
370
+ this.getMessagesFilePath(),
371
+ JSON.stringify(message) + "\n",
372
+ "utf8",
373
+ );
374
+ });
375
+ }
376
+
377
+ async list(): Promise<SessionMessageV1[]> {
378
+ await this.ensureLayout();
379
+ const file = this.getMessagesFilePath();
380
+ const raw = await fs.readFile(file, "utf8");
381
+ const lines = raw.split("\n").filter(Boolean);
382
+ const out: SessionMessageV1[] = [];
383
+ for (const line of lines) {
384
+ try {
385
+ const obj = JSON.parse(line) as Partial<SessionMessageV1>;
386
+ if (!obj || typeof obj !== "object") continue;
387
+ const role = String(obj.role || "");
388
+ if (role !== "user" && role !== "assistant") continue;
389
+ if (!Array.isArray(obj.parts)) continue;
390
+ out.push(obj as SessionMessageV1);
391
+ } catch {
392
+ // ignore invalid lines
393
+ }
394
+ }
395
+ return out;
396
+ }
397
+
398
+ async slice(start: number, end: number): Promise<SessionMessageV1[]> {
399
+ const msgs = await this.list();
400
+ const startIndex = Math.max(0, Math.floor(start));
401
+ const endIndex = Math.max(startIndex, Math.floor(end));
402
+ return msgs.slice(startIndex, endIndex);
403
+ }
404
+
405
+ async size(): Promise<number> {
406
+ const msgs = await this.list();
407
+ return msgs.length;
408
+ }
409
+
410
+ async meta(): Promise<Record<string, unknown>> {
411
+ await this.ensureLayout();
412
+ const metadata = await this.readMetaUnsafe();
413
+ return (
414
+ metadata && typeof metadata === "object" ? { ...metadata } : {}
415
+ ) as Record<string, unknown>;
416
+ }
417
+
418
+ userText(input: {
419
+ text: string;
420
+ metadata: Omit<SessionMetadataV1, "v" | "ts"> &
421
+ Partial<Pick<SessionMetadataV1, "ts">>;
422
+ id?: string;
423
+ }): SessionMessageV1 {
424
+ const { ts, ...metadata } = input.metadata;
425
+ const md: SessionMetadataV1 = {
426
+ v: 1,
427
+ ts: typeof ts === "number" ? ts : Date.now(),
428
+ ...metadata,
429
+ source: "ingress",
430
+ kind: "normal",
431
+ };
432
+ const id = input.id || `u:${this.sessionId}:${generateId()}`;
433
+ return {
434
+ id,
435
+ role: "user",
436
+ metadata: md,
437
+ parts: [{ type: "text", text: String(input.text ?? "") }],
438
+ };
439
+ }
440
+
441
+ assistantText(input: {
442
+ text: string;
443
+ metadata: Omit<SessionMetadataV1, "v" | "ts"> &
444
+ Partial<Pick<SessionMetadataV1, "ts">>;
445
+ id?: string;
446
+ kind?: "normal" | "summary";
447
+ source?: "egress" | "compact";
448
+ }): SessionMessageV1 {
449
+ const { ts, ...metadata } = input.metadata;
450
+ const md: SessionMetadataV1 = {
451
+ v: 1,
452
+ ts: typeof ts === "number" ? ts : Date.now(),
453
+ ...metadata,
454
+ source: input.source || "egress",
455
+ kind: input.kind || "normal",
456
+ };
457
+ const id = input.id || `a:${this.sessionId}:${generateId()}`;
458
+ return {
459
+ id,
460
+ role: "assistant",
461
+ metadata: md,
462
+ parts: [{ type: "text", text: String(input.text ?? "") }],
463
+ };
464
+ }
465
+ }
@@ -6,7 +6,7 @@
6
6
  * - 这里仅保留当前仍被 tool 与测试复用的最小能力:命令安全校验与 env 注入。
7
7
  */
8
8
 
9
- import { stripInvocationAuthEnv } from "@/server/http/auth/AuthEnv.js";
9
+ import { stripInvocationAuthEnv } from "@/runtime/server/http/auth/AuthEnv.js";
10
10
  import { getSessionRunScope } from "@session/SessionRunScope.js";
11
11
 
12
12
  function setEnvString(
@@ -1,8 +1,8 @@
1
1
  /**
2
- * JsonlSessionHistoryComposer 路径覆盖类型。
2
+ * JsonlSessionHistoryStore 路径覆盖类型。
3
3
  *
4
4
  * 关键点(中文)
5
- * - 用于把 history Composer 落盘路径定向到自定义目录(例如 task run 目录)。
5
+ * - 用于把 history Store 落盘路径定向到自定义目录(例如 task run 目录)。
6
6
  * - 每个字段都为可选,未提供时回退到默认 `.downcity/session/<encodedSessionId>/messages/*`。
7
7
  */
8
8
  export type SessionHistoryPathOverrides = {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Runner tool-loop 决策相关类型。
2
+ * Session tool-loop 决策相关类型。
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - 这里只描述“是否继续下一轮”的纯决策输入/输出。
@@ -4,7 +4,7 @@
4
4
  * 关键点(中文)
5
5
  * - 这里统一描述 session 消息落盘格式与元信息结构。
6
6
  * - session 的唯一事实源是 `UIMessage[]`,不会再维护第二套平行消息结构。
7
- * - 这些类型会被 history Composer、compact、control UI、task runtime 共同复用。
7
+ * - 这些类型会被 history Store、history Composer、compact、control UI、task runtime 共同复用。
8
8
  */
9
9
 
10
10
  import type { UIMessage } from "ai";
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - `SessionRunInput` 表示上层会话入口输入(例如 context query)。
6
- * - `SessionExecuteInput` 表示 Runner 通过 Composer 装配后的中间运行态。
6
+ * - `SessionExecuteInput` 表示 Executor 通过 Composer 装配后的中间运行态。
7
7
  * - 输出仅暴露 assistantMessage(UIMessage)。
8
8
  */
9
9
 
@@ -107,7 +107,7 @@ export interface SessionRunInput {
107
107
  }
108
108
 
109
109
  /**
110
- * Runner 通过 Composer 装配后的中间运行态。
110
+ * Executor 通过 Composer 装配后的中间运行态。
111
111
  */
112
112
  export interface SessionExecuteInput {
113
113
  /**
@@ -8,7 +8,7 @@
8
8
  import type { LlmConfig } from "@/types/config/LlmConfig.js";
9
9
  import type { ExecutionBindingConfig } from "@/types/config/ExecutionBinding.js";
10
10
  import type { JsonObject } from "@/types/common/Json.js";
11
- import type { SandboxProjectConfig } from "@/sandbox/types/Sandbox.js";
11
+ import type { SandboxProjectConfig } from "@/runtime/sandbox/types/Sandbox.js";
12
12
 
13
13
  export interface DowncityConfig {
14
14
  $schema?: string;
@@ -143,8 +143,9 @@ export interface DowncityConfig {
143
143
  * LLM 全量配置(通常来自平台全局层合并结果)。
144
144
  *
145
145
  * 关键点(中文)
146
- * - 运行时会读取该字段创建真实模型实例。
147
- * - 对于项目内 `downcity.json`,通常不需要显式写该字段。
146
+ * - `@downcity/agent` 本地 SDK 不直接消费该字段。
147
+ * - 宿主侧(例如 `@downcity/city`)可读取该字段控制模型工厂行为,例如 `llm.logMessages`。
148
+ * - 对于项目内 `downcity.json`,通常不需要显式写 provider/model 明细。
148
149
  */
149
150
  llm?: LlmConfig;
150
151
  /**