@downcity/agent 1.1.73 → 1.1.79

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 (390) hide show
  1. package/README.md +26 -28
  2. package/bin/agent/{Agent.d.ts → local/Agent.d.ts} +8 -36
  3. package/bin/agent/local/Agent.d.ts.map +1 -0
  4. package/bin/agent/{Agent.js → local/Agent.js} +45 -200
  5. package/bin/agent/local/Agent.js.map +1 -0
  6. package/bin/agent/local/AgentInstructions.d.ts +22 -0
  7. package/bin/agent/local/AgentInstructions.d.ts.map +1 -0
  8. package/bin/agent/local/AgentInstructions.js +57 -0
  9. package/bin/agent/local/AgentInstructions.js.map +1 -0
  10. package/bin/agent/local/AgentPluginFactory.d.ts +29 -0
  11. package/bin/agent/local/AgentPluginFactory.d.ts.map +1 -0
  12. package/bin/agent/local/AgentPluginFactory.js +53 -0
  13. package/bin/agent/local/AgentPluginFactory.js.map +1 -0
  14. package/bin/{runtime/host/AgentHostRuntime.d.ts → agent/local/AgentRuntimeAssembly.d.ts} +2 -2
  15. package/bin/agent/local/AgentRuntimeAssembly.d.ts.map +1 -0
  16. package/bin/{runtime/host/AgentHostRuntime.js → agent/local/AgentRuntimeAssembly.js} +2 -2
  17. package/bin/agent/local/AgentRuntimeAssembly.js.map +1 -0
  18. package/bin/agent/local/AgentRuntimeFactory.d.ts +72 -0
  19. package/bin/agent/local/AgentRuntimeFactory.d.ts.map +1 -0
  20. package/bin/agent/local/AgentRuntimeFactory.js +94 -0
  21. package/bin/agent/local/AgentRuntimeFactory.js.map +1 -0
  22. package/bin/{runtime/host → agent/local}/ProjectSetup.d.ts +1 -1
  23. package/bin/agent/local/ProjectSetup.d.ts.map +1 -0
  24. package/bin/{runtime/host → agent/local}/ProjectSetup.js +1 -1
  25. package/bin/agent/local/ProjectSetup.js.map +1 -0
  26. package/bin/agent/{RemoteAgent.d.ts → remote/RemoteAgent.d.ts} +3 -3
  27. package/bin/agent/remote/RemoteAgent.d.ts.map +1 -0
  28. package/bin/agent/remote/RemoteAgent.js +58 -0
  29. package/bin/agent/remote/RemoteAgent.js.map +1 -0
  30. package/bin/agent/remote/RemoteSession.d.ts +62 -0
  31. package/bin/agent/remote/RemoteSession.d.ts.map +1 -0
  32. package/bin/agent/remote/RemoteSession.js +225 -0
  33. package/bin/agent/remote/RemoteSession.js.map +1 -0
  34. package/bin/agent/remote/RemoteTransport.d.ts +52 -0
  35. package/bin/agent/remote/RemoteTransport.d.ts.map +1 -0
  36. package/bin/agent/remote/RemoteTransport.js +9 -0
  37. package/bin/agent/remote/RemoteTransport.js.map +1 -0
  38. package/bin/agent/remote/TransportFactory.d.ts +13 -0
  39. package/bin/agent/remote/TransportFactory.d.ts.map +1 -0
  40. package/bin/agent/remote/TransportFactory.js +22 -0
  41. package/bin/agent/remote/TransportFactory.js.map +1 -0
  42. package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts +35 -0
  43. package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts.map +1 -0
  44. package/bin/agent/remote/transports/HttpRemoteAgentTransport.js +259 -0
  45. package/bin/agent/remote/transports/HttpRemoteAgentTransport.js.map +1 -0
  46. package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts +34 -0
  47. package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts.map +1 -0
  48. package/bin/agent/remote/transports/RpcRemoteAgentTransport.js +66 -0
  49. package/bin/agent/remote/transports/RpcRemoteAgentTransport.js.map +1 -0
  50. package/bin/config/AgentInitializer.d.ts +1 -1
  51. package/bin/config/AgentInitializer.js +1 -1
  52. package/bin/executor/Executor.d.ts +4 -0
  53. package/bin/executor/Executor.d.ts.map +1 -1
  54. package/bin/executor/Executor.js +52 -35
  55. package/bin/executor/Executor.js.map +1 -1
  56. package/bin/executor/composer/history/SessionHistoryWriter.js +2 -2
  57. package/bin/executor/composer/history/SessionHistoryWriter.js.map +1 -1
  58. package/bin/executor/composer/system/default/assets/core.prompt.d.ts +1 -1
  59. package/bin/executor/composer/system/default/assets/core.prompt.d.ts.map +1 -1
  60. package/bin/executor/composer/system/default/assets/core.prompt.js +1 -1
  61. package/bin/executor/composer/system/default/assets/core.prompt.js.map +1 -1
  62. package/bin/executor/messages/AssistantResultPersistence.d.ts +3 -3
  63. package/bin/executor/messages/AssistantResultPersistence.d.ts.map +1 -1
  64. package/bin/executor/messages/AssistantResultPersistence.js +2 -6
  65. package/bin/executor/messages/AssistantResultPersistence.js.map +1 -1
  66. package/bin/executor/messages/SessionStepEventMapper.d.ts +7 -8
  67. package/bin/executor/messages/SessionStepEventMapper.d.ts.map +1 -1
  68. package/bin/executor/messages/SessionStepEventMapper.js +55 -86
  69. package/bin/executor/messages/SessionStepEventMapper.js.map +1 -1
  70. package/bin/executor/messages/UserVisibleText.d.ts +2 -10
  71. package/bin/executor/messages/UserVisibleText.d.ts.map +1 -1
  72. package/bin/executor/messages/UserVisibleText.js +3 -16
  73. package/bin/executor/messages/UserVisibleText.js.map +1 -1
  74. package/bin/executor/store/history/SessionHistoryStore.d.ts +12 -0
  75. package/bin/executor/store/history/SessionHistoryStore.d.ts.map +1 -1
  76. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts +12 -0
  77. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts.map +1 -1
  78. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +145 -8
  79. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js.map +1 -1
  80. package/bin/executor/tools/shell/ShellToolFormatting.d.ts +1 -10
  81. package/bin/executor/tools/shell/ShellToolFormatting.d.ts.map +1 -1
  82. package/bin/executor/tools/shell/ShellToolFormatting.js +1 -39
  83. package/bin/executor/tools/shell/ShellToolFormatting.js.map +1 -1
  84. package/bin/executor/types/SessionHistoryPaths.d.ts +4 -0
  85. package/bin/executor/types/SessionHistoryPaths.d.ts.map +1 -1
  86. package/bin/index.d.ts +5 -5
  87. package/bin/index.d.ts.map +1 -1
  88. package/bin/index.js +3 -3
  89. package/bin/index.js.map +1 -1
  90. package/bin/plugin/core/PluginCommandRequest.d.ts +1 -1
  91. package/bin/plugin/core/PluginCommandRequest.js +1 -1
  92. package/bin/plugin/core/PluginLocalExecution.js +1 -1
  93. package/bin/plugin/core/PluginLocalExecution.js.map +1 -1
  94. package/bin/plugin/core/ProjectConfigStore.d.ts +3 -2
  95. package/bin/plugin/core/ProjectConfigStore.d.ts.map +1 -1
  96. package/bin/plugin/core/ProjectConfigStore.js +3 -4
  97. package/bin/plugin/core/ProjectConfigStore.js.map +1 -1
  98. package/bin/plugin/types/Plugin.d.ts +10 -842
  99. package/bin/plugin/types/Plugin.d.ts.map +1 -1
  100. package/bin/plugin/types/Plugin.js +3 -4
  101. package/bin/plugin/types/Plugin.js.map +1 -1
  102. package/bin/plugin/types/PluginApi.d.ts +1 -1
  103. package/bin/plugin/types/PluginApi.js +1 -1
  104. package/bin/plugin/types/PluginState.d.ts +1 -1
  105. package/bin/plugin/types/PluginState.d.ts.map +1 -1
  106. package/bin/rpc/Client.d.ts +2 -99
  107. package/bin/rpc/Client.d.ts.map +1 -1
  108. package/bin/rpc/Client.js +0 -46
  109. package/bin/rpc/Client.js.map +1 -1
  110. package/bin/rpc/Server.d.ts +5 -21
  111. package/bin/rpc/Server.d.ts.map +1 -1
  112. package/bin/rpc/Server.js +30 -315
  113. package/bin/rpc/Server.js.map +1 -1
  114. package/bin/rpc/server/InternalHandlers.d.ts +21 -0
  115. package/bin/rpc/server/InternalHandlers.d.ts.map +1 -0
  116. package/bin/rpc/server/InternalHandlers.js +190 -0
  117. package/bin/rpc/server/InternalHandlers.js.map +1 -0
  118. package/bin/rpc/server/RequestDispatcher.d.ts +27 -0
  119. package/bin/rpc/server/RequestDispatcher.d.ts.map +1 -0
  120. package/bin/rpc/server/RequestDispatcher.js +38 -0
  121. package/bin/rpc/server/RequestDispatcher.js.map +1 -0
  122. package/bin/rpc/server/SdkSessionHandlers.d.ts +25 -0
  123. package/bin/rpc/server/SdkSessionHandlers.d.ts.map +1 -0
  124. package/bin/rpc/server/SdkSessionHandlers.js +86 -0
  125. package/bin/rpc/server/SdkSessionHandlers.js.map +1 -0
  126. package/bin/rpc/server/ServerTypes.d.ts +59 -0
  127. package/bin/rpc/server/ServerTypes.d.ts.map +1 -0
  128. package/bin/rpc/server/ServerTypes.js +9 -0
  129. package/bin/rpc/server/ServerTypes.js.map +1 -0
  130. package/bin/{runtime/sandbox → sandbox}/MacOsSeatbeltSandbox.d.ts +1 -1
  131. package/bin/sandbox/MacOsSeatbeltSandbox.d.ts.map +1 -0
  132. package/bin/sandbox/MacOsSeatbeltSandbox.js.map +1 -0
  133. package/bin/{runtime/sandbox → sandbox}/SandboxConfigResolver.d.ts +2 -2
  134. package/bin/sandbox/SandboxConfigResolver.d.ts.map +1 -0
  135. package/bin/sandbox/SandboxConfigResolver.js.map +1 -0
  136. package/bin/{runtime/sandbox → sandbox}/SandboxRunner.d.ts +2 -2
  137. package/bin/sandbox/SandboxRunner.d.ts.map +1 -0
  138. package/bin/{runtime/sandbox → sandbox}/SandboxRunner.js +2 -2
  139. package/bin/sandbox/SandboxRunner.js.map +1 -0
  140. package/bin/sandbox/types/Sandbox.d.ts.map +1 -0
  141. package/bin/sandbox/types/Sandbox.js.map +1 -0
  142. package/bin/{runtime/sandbox → sandbox}/types/SandboxRuntime.d.ts +2 -2
  143. package/bin/sandbox/types/SandboxRuntime.d.ts.map +1 -0
  144. package/bin/sandbox/types/SandboxRuntime.js.map +1 -0
  145. package/bin/session/Session.d.ts.map +1 -1
  146. package/bin/session/Session.js +2 -1
  147. package/bin/session/Session.js.map +1 -1
  148. package/bin/session/browse/Browse.d.ts +1 -1
  149. package/bin/session/browse/Browse.d.ts.map +1 -1
  150. package/bin/session/browse/Browse.js +28 -13
  151. package/bin/session/browse/Browse.js.map +1 -1
  152. package/bin/session/index.d.ts +1 -1
  153. package/bin/session/index.d.ts.map +1 -1
  154. package/bin/session/index.js +1 -1
  155. package/bin/session/index.js.map +1 -1
  156. package/bin/session/storage/Paths.d.ts +9 -0
  157. package/bin/session/storage/Paths.d.ts.map +1 -1
  158. package/bin/session/storage/Paths.js +11 -0
  159. package/bin/session/storage/Paths.js.map +1 -1
  160. package/bin/types/agent/AgentOptions.d.ts +134 -0
  161. package/bin/types/agent/AgentOptions.d.ts.map +1 -0
  162. package/bin/types/agent/AgentOptions.js +9 -0
  163. package/bin/types/agent/AgentOptions.js.map +1 -0
  164. package/bin/types/{runtime/host/AgentHost.d.ts → agent/AgentRuntimeAssembly.d.ts} +4 -4
  165. package/bin/types/agent/AgentRuntimeAssembly.d.ts.map +1 -0
  166. package/bin/types/{runtime/host/AgentHost.js → agent/AgentRuntimeAssembly.js} +3 -3
  167. package/bin/types/agent/AgentRuntimeAssembly.js.map +1 -0
  168. package/bin/types/agent/AgentTypes.d.ts +8 -613
  169. package/bin/types/agent/AgentTypes.d.ts.map +1 -1
  170. package/bin/types/agent/AgentTypes.js +4 -4
  171. package/bin/types/agent/RemoteAgentOptions.d.ts +28 -0
  172. package/bin/types/agent/RemoteAgentOptions.d.ts.map +1 -0
  173. package/bin/types/agent/RemoteAgentOptions.js +9 -0
  174. package/bin/types/agent/RemoteAgentOptions.js.map +1 -0
  175. package/bin/types/agent/SessionActor.d.ts +60 -0
  176. package/bin/types/agent/SessionActor.d.ts.map +1 -0
  177. package/bin/types/agent/SessionActor.js +9 -0
  178. package/bin/types/agent/SessionActor.js.map +1 -0
  179. package/bin/types/agent/SessionTypes.d.ts +312 -0
  180. package/bin/types/agent/SessionTypes.d.ts.map +1 -0
  181. package/bin/types/agent/SessionTypes.js +9 -0
  182. package/bin/types/agent/SessionTypes.js.map +1 -0
  183. package/bin/types/config/DowncityConfig.d.ts +1 -1
  184. package/bin/types/config/DowncityConfig.d.ts.map +1 -1
  185. package/bin/types/{runtime/host → platform}/Store.d.ts +1 -1
  186. package/bin/types/platform/Store.d.ts.map +1 -0
  187. package/bin/types/{runtime/host → platform}/Store.js +1 -1
  188. package/bin/types/platform/Store.js.map +1 -0
  189. package/bin/types/plugin/PluginAction.d.ts +119 -0
  190. package/bin/types/plugin/PluginAction.d.ts.map +1 -0
  191. package/bin/types/plugin/PluginAction.js +9 -0
  192. package/bin/types/plugin/PluginAction.js.map +1 -0
  193. package/bin/types/plugin/PluginCommand.d.ts +80 -0
  194. package/bin/types/plugin/PluginCommand.d.ts.map +1 -0
  195. package/bin/types/plugin/PluginCommand.js +9 -0
  196. package/bin/types/plugin/PluginCommand.js.map +1 -0
  197. package/bin/types/plugin/PluginDefinition.d.ts +57 -0
  198. package/bin/types/plugin/PluginDefinition.d.ts.map +1 -0
  199. package/bin/types/plugin/PluginDefinition.js +9 -0
  200. package/bin/types/plugin/PluginDefinition.js.map +1 -0
  201. package/bin/types/plugin/PluginHttp.d.ts +34 -0
  202. package/bin/types/plugin/PluginHttp.d.ts.map +1 -0
  203. package/bin/types/plugin/PluginHttp.js +9 -0
  204. package/bin/types/plugin/PluginHttp.js.map +1 -0
  205. package/bin/types/plugin/PluginRuntime.d.ts +148 -0
  206. package/bin/types/plugin/PluginRuntime.d.ts.map +1 -0
  207. package/bin/types/plugin/PluginRuntime.js +9 -0
  208. package/bin/types/plugin/PluginRuntime.js.map +1 -0
  209. package/bin/types/plugin/PluginSetup.d.ts +133 -0
  210. package/bin/types/plugin/PluginSetup.d.ts.map +1 -0
  211. package/bin/types/plugin/PluginSetup.js +9 -0
  212. package/bin/types/plugin/PluginSetup.js.map +1 -0
  213. package/bin/types/plugin/PluginState.d.ts +69 -0
  214. package/bin/types/plugin/PluginState.d.ts.map +1 -0
  215. package/bin/types/plugin/PluginState.js +9 -0
  216. package/bin/types/plugin/PluginState.js.map +1 -0
  217. package/bin/types/rpc/RpcProtocol.d.ts +323 -0
  218. package/bin/types/rpc/RpcProtocol.d.ts.map +1 -0
  219. package/bin/types/rpc/RpcProtocol.js +10 -0
  220. package/bin/types/rpc/RpcProtocol.js.map +1 -0
  221. package/bin/types/runtime/agent/AgentContext.d.ts +1 -1
  222. package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
  223. package/bin/types/runtime/agent/AgentRuntime.d.ts +1 -1
  224. package/bin/types/runtime/agent/AgentRuntime.d.ts.map +1 -1
  225. package/bin/types/runtime/platform/Platform.d.ts +7 -7
  226. package/bin/types/runtime/platform/PlatformGateway.d.ts +1 -1
  227. package/bin/types/runtime/platform/PlatformGateway.js +1 -1
  228. package/package.json +2 -2
  229. package/scripts/session-history-inflight.test.mjs +146 -0
  230. package/src/agent/{Agent.ts → local/Agent.ts} +50 -228
  231. package/src/agent/local/AgentInstructions.ts +68 -0
  232. package/src/agent/local/AgentPluginFactory.ts +83 -0
  233. package/src/{runtime/host/AgentHostRuntime.ts → agent/local/AgentRuntimeAssembly.ts} +2 -2
  234. package/src/agent/local/AgentRuntimeFactory.ts +173 -0
  235. package/src/{runtime/host → agent/local}/ProjectSetup.ts +1 -1
  236. package/src/agent/remote/RemoteAgent.ts +76 -0
  237. package/src/agent/remote/RemoteSession.ts +287 -0
  238. package/src/agent/remote/RemoteTransport.ts +71 -0
  239. package/src/agent/remote/TransportFactory.ts +29 -0
  240. package/src/agent/remote/transports/HttpRemoteAgentTransport.ts +347 -0
  241. package/src/agent/remote/transports/RpcRemoteAgentTransport.ts +107 -0
  242. package/src/config/AgentInitializer.ts +1 -1
  243. package/src/executor/Executor.ts +56 -37
  244. package/src/executor/composer/history/SessionHistoryWriter.ts +2 -2
  245. package/src/executor/composer/system/default/assets/core.prompt.ts +1 -1
  246. package/src/executor/composer/system/default/assets/core.prompt.ts.txt +1 -1
  247. package/src/executor/messages/AssistantResultPersistence.ts +4 -12
  248. package/src/executor/messages/SessionStepEventMapper.ts +59 -101
  249. package/src/executor/messages/UserVisibleText.ts +3 -18
  250. package/src/executor/store/history/SessionHistoryStore.ts +15 -0
  251. package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +164 -11
  252. package/src/executor/tools/shell/ShellToolFormatting.ts +1 -50
  253. package/src/executor/types/SessionHistoryPaths.ts +5 -0
  254. package/src/index.ts +5 -5
  255. package/src/plugin/core/PluginCommandRequest.ts +1 -1
  256. package/src/plugin/core/PluginLocalExecution.ts +1 -1
  257. package/src/plugin/core/ProjectConfigStore.ts +4 -4
  258. package/src/plugin/types/Plugin.ts +54 -913
  259. package/src/plugin/types/PluginApi.ts +1 -1
  260. package/src/plugin/types/PluginState.ts +1 -1
  261. package/src/rpc/Client.ts +16 -322
  262. package/src/rpc/Server.ts +39 -565
  263. package/src/rpc/server/InternalHandlers.ts +230 -0
  264. package/src/rpc/server/RequestDispatcher.ts +67 -0
  265. package/src/rpc/server/SdkSessionHandlers.ts +106 -0
  266. package/src/rpc/server/ServerTypes.ts +65 -0
  267. package/src/{runtime/sandbox → sandbox}/MacOsSeatbeltSandbox.ts +1 -1
  268. package/src/{runtime/sandbox → sandbox}/SandboxConfigResolver.ts +1 -1
  269. package/src/{runtime/sandbox → sandbox}/SandboxRunner.ts +3 -3
  270. package/src/{runtime/sandbox → sandbox}/types/SandboxRuntime.ts +2 -2
  271. package/src/session/Session.ts +6 -0
  272. package/src/session/browse/Browse.ts +29 -10
  273. package/src/session/index.ts +1 -0
  274. package/src/session/storage/Paths.ts +19 -0
  275. package/src/types/agent/AgentOptions.ts +147 -0
  276. package/src/types/{runtime/host/AgentHost.ts → agent/AgentRuntimeAssembly.ts} +2 -2
  277. package/src/types/agent/AgentTypes.ts +37 -709
  278. package/src/types/agent/RemoteAgentOptions.ts +29 -0
  279. package/src/types/agent/SessionActor.ts +88 -0
  280. package/src/types/agent/SessionTypes.ts +334 -0
  281. package/src/types/config/DowncityConfig.ts +1 -1
  282. package/src/types/{runtime/host → platform}/Store.ts +1 -1
  283. package/src/types/plugin/PluginAction.ts +133 -0
  284. package/src/types/plugin/PluginCommand.ts +89 -0
  285. package/src/types/plugin/PluginDefinition.ts +74 -0
  286. package/src/types/plugin/PluginHttp.ts +36 -0
  287. package/src/types/plugin/PluginRuntime.ts +169 -0
  288. package/src/types/plugin/PluginSetup.ts +138 -0
  289. package/src/types/plugin/PluginState.ts +82 -0
  290. package/src/types/rpc/RpcProtocol.ts +361 -0
  291. package/src/types/runtime/agent/AgentContext.ts +1 -1
  292. package/src/types/runtime/agent/AgentRuntime.ts +1 -1
  293. package/src/types/runtime/platform/Platform.ts +7 -7
  294. package/src/types/runtime/platform/PlatformGateway.ts +1 -1
  295. package/tsconfig.tsbuildinfo +1 -1
  296. package/bin/agent/Agent.d.ts.map +0 -1
  297. package/bin/agent/Agent.js.map +0 -1
  298. package/bin/agent/RemoteAgent.d.ts.map +0 -1
  299. package/bin/agent/RemoteAgent.js +0 -585
  300. package/bin/agent/RemoteAgent.js.map +0 -1
  301. package/bin/runtime/auth/AuthEnv.d.ts +0 -36
  302. package/bin/runtime/auth/AuthEnv.d.ts.map +0 -1
  303. package/bin/runtime/auth/AuthEnv.js +0 -54
  304. package/bin/runtime/auth/AuthEnv.js.map +0 -1
  305. package/bin/runtime/auth/CliAuthStateStore.d.ts +0 -29
  306. package/bin/runtime/auth/CliAuthStateStore.d.ts.map +0 -1
  307. package/bin/runtime/auth/CliAuthStateStore.js +0 -26
  308. package/bin/runtime/auth/CliAuthStateStore.js.map +0 -1
  309. package/bin/runtime/control/AuthControlService.d.ts +0 -34
  310. package/bin/runtime/control/AuthControlService.d.ts.map +0 -1
  311. package/bin/runtime/control/AuthControlService.js +0 -129
  312. package/bin/runtime/control/AuthControlService.js.map +0 -1
  313. package/bin/runtime/control/CommonHelpers.d.ts +0 -36
  314. package/bin/runtime/control/CommonHelpers.d.ts.map +0 -1
  315. package/bin/runtime/control/CommonHelpers.js +0 -63
  316. package/bin/runtime/control/CommonHelpers.js.map +0 -1
  317. package/bin/runtime/control/ExecuteBySession.d.ts +0 -30
  318. package/bin/runtime/control/ExecuteBySession.d.ts.map +0 -1
  319. package/bin/runtime/control/ExecuteBySession.js +0 -41
  320. package/bin/runtime/control/ExecuteBySession.js.map +0 -1
  321. package/bin/runtime/control/ExecuteInput.d.ts +0 -18
  322. package/bin/runtime/control/ExecuteInput.d.ts.map +0 -1
  323. package/bin/runtime/control/ExecuteInput.js +0 -201
  324. package/bin/runtime/control/ExecuteInput.js.map +0 -1
  325. package/bin/runtime/control/Helpers.d.ts +0 -13
  326. package/bin/runtime/control/Helpers.d.ts.map +0 -1
  327. package/bin/runtime/control/Helpers.js +0 -13
  328. package/bin/runtime/control/Helpers.js.map +0 -1
  329. package/bin/runtime/control/MessageTimeline.d.ts +0 -22
  330. package/bin/runtime/control/MessageTimeline.d.ts.map +0 -1
  331. package/bin/runtime/control/MessageTimeline.js +0 -226
  332. package/bin/runtime/control/MessageTimeline.js.map +0 -1
  333. package/bin/runtime/control/SessionSummaryStore.d.ts +0 -20
  334. package/bin/runtime/control/SessionSummaryStore.d.ts.map +0 -1
  335. package/bin/runtime/control/SessionSummaryStore.js +0 -50
  336. package/bin/runtime/control/SessionSummaryStore.js.map +0 -1
  337. package/bin/runtime/control/TaskStore.d.ts +0 -33
  338. package/bin/runtime/control/TaskStore.d.ts.map +0 -1
  339. package/bin/runtime/control/TaskStore.js +0 -175
  340. package/bin/runtime/control/TaskStore.js.map +0 -1
  341. package/bin/runtime/control/types/AuthControl.d.ts +0 -30
  342. package/bin/runtime/control/types/AuthControl.d.ts.map +0 -1
  343. package/bin/runtime/control/types/AuthControl.js +0 -9
  344. package/bin/runtime/control/types/AuthControl.js.map +0 -1
  345. package/bin/runtime/control/types/ControlSessionExecute.d.ts +0 -85
  346. package/bin/runtime/control/types/ControlSessionExecute.d.ts.map +0 -1
  347. package/bin/runtime/control/types/ControlSessionExecute.js +0 -9
  348. package/bin/runtime/control/types/ControlSessionExecute.js.map +0 -1
  349. package/bin/runtime/control/types/ControlViewData.d.ts +0 -320
  350. package/bin/runtime/control/types/ControlViewData.d.ts.map +0 -1
  351. package/bin/runtime/control/types/ControlViewData.js +0 -9
  352. package/bin/runtime/control/types/ControlViewData.js.map +0 -1
  353. package/bin/runtime/host/AgentHostRuntime.d.ts.map +0 -1
  354. package/bin/runtime/host/AgentHostRuntime.js.map +0 -1
  355. package/bin/runtime/host/ProjectSetup.d.ts.map +0 -1
  356. package/bin/runtime/host/ProjectSetup.js.map +0 -1
  357. package/bin/runtime/sandbox/MacOsSeatbeltSandbox.d.ts.map +0 -1
  358. package/bin/runtime/sandbox/MacOsSeatbeltSandbox.js.map +0 -1
  359. package/bin/runtime/sandbox/SandboxConfigResolver.d.ts.map +0 -1
  360. package/bin/runtime/sandbox/SandboxConfigResolver.js.map +0 -1
  361. package/bin/runtime/sandbox/SandboxRunner.d.ts.map +0 -1
  362. package/bin/runtime/sandbox/SandboxRunner.js.map +0 -1
  363. package/bin/runtime/sandbox/types/Sandbox.d.ts.map +0 -1
  364. package/bin/runtime/sandbox/types/Sandbox.js.map +0 -1
  365. package/bin/runtime/sandbox/types/SandboxRuntime.d.ts.map +0 -1
  366. package/bin/runtime/sandbox/types/SandboxRuntime.js.map +0 -1
  367. package/bin/types/runtime/host/AgentHost.d.ts.map +0 -1
  368. package/bin/types/runtime/host/AgentHost.js.map +0 -1
  369. package/bin/types/runtime/host/Store.d.ts.map +0 -1
  370. package/bin/types/runtime/host/Store.js.map +0 -1
  371. package/src/agent/RemoteAgent.ts +0 -834
  372. package/src/runtime/auth/AuthEnv.ts +0 -62
  373. package/src/runtime/auth/CliAuthStateStore.ts +0 -46
  374. package/src/runtime/control/AuthControlService.ts +0 -169
  375. package/src/runtime/control/CommonHelpers.ts +0 -69
  376. package/src/runtime/control/ExecuteBySession.ts +0 -52
  377. package/src/runtime/control/ExecuteInput.ts +0 -236
  378. package/src/runtime/control/Helpers.ts +0 -22
  379. package/src/runtime/control/MessageTimeline.ts +0 -269
  380. package/src/runtime/control/SessionSummaryStore.ts +0 -72
  381. package/src/runtime/control/TaskStore.ts +0 -242
  382. package/src/runtime/control/types/AuthControl.ts +0 -34
  383. package/src/runtime/control/types/ControlSessionExecute.ts +0 -99
  384. package/src/runtime/control/types/ControlViewData.ts +0 -392
  385. /package/bin/{runtime/sandbox → sandbox}/MacOsSeatbeltSandbox.js +0 -0
  386. /package/bin/{runtime/sandbox → sandbox}/SandboxConfigResolver.js +0 -0
  387. /package/bin/{runtime/sandbox → sandbox}/types/Sandbox.d.ts +0 -0
  388. /package/bin/{runtime/sandbox → sandbox}/types/Sandbox.js +0 -0
  389. /package/bin/{runtime/sandbox → sandbox}/types/SandboxRuntime.js +0 -0
  390. /package/src/{runtime/sandbox → sandbox}/types/Sandbox.ts +0 -0
@@ -4,14 +4,11 @@
4
4
  * 关键点(中文)
5
5
  * - 负责收敛“写完整 assistant message / 写 fallback 文本 / 完全跳过”三种分支。
6
6
  * - 避免 SDK、HTTP execute、control execute、chat queue 各自复制一套判断。
7
- * - 一旦 step 消息已经单独持久化,最终 merged assistant 必须跳过,不能再补一条 fallback。
7
+ * - 运行中 step/tool 的持久化由 inflight 快照承担;run 结束时只关心最终 assistant 如何收口。
8
8
  */
9
9
 
10
10
  import type { SessionMessageV1 } from "@/executor/types/SessionMessages.js";
11
- import {
12
- hasPersistedAssistantSteps,
13
- resolveAssistantMessageForPersistence,
14
- } from "@/executor/messages/UserVisibleText.js";
11
+ import { resolveAssistantMessageForPersistence } from "@/executor/messages/UserVisibleText.js";
15
12
 
16
13
  /**
17
14
  * assistant 写入端口。
@@ -48,8 +45,8 @@ export interface PersistAssistantResultParams {
48
45
  * 可选兜底文本。
49
46
  *
50
47
  * 关键点(中文)
51
- * - 仅在没有完整 assistant message 且未发生 step 持久化时才允许写入。
52
- * - step 已单独落盘,这里必须被忽略,避免重复 assistant。
48
+ * - 仅在没有完整 assistant message 时才允许写入。
49
+ * - inflight 快照的正式收口由 history store 负责,这里不再处理旧的 step 独立落盘分支。
53
50
  */
54
51
  fallbackText?: string;
55
52
  }
@@ -83,11 +80,6 @@ export function buildAssistantResultPersistencePayload(
83
80
  };
84
81
  }
85
82
 
86
- // 关键点(中文):step 已经单独落盘时,最终 merged assistant 必须完全跳过。
87
- if (hasPersistedAssistantSteps(params.assistantMessage)) {
88
- return null;
89
- }
90
-
91
83
  const fallbackText = normalizeFallbackText(params.fallbackText);
92
84
  if (!fallbackText) return null;
93
85
  return {
@@ -1,14 +1,12 @@
1
1
  /**
2
- * SessionStepEventMapper:把单个 step 结果转成按顺序可持久化的 session 消息。
2
+ * SessionStepEventMapper:把单个 step 结果转成 assistant parts。
3
3
  *
4
4
  * 关键点(中文)
5
- * - 工具结果使用 AI SDK v6 UI tool part 格式,避免历史重放时丢失 tool result
6
- * - 只做 best-effort 提取,不依赖 provider 私有结构。
7
- * - 输出仍然是标准 SessionMessageV1,供 SessionHistoryWriter 直接落盘。
5
+ * - 运行过程仍然要持久化,但收口到同一条 assistant UIMessage
6
+ * - 工具结果使用 AI SDK v6 UI tool part 格式,和官方 UIMessage 语义保持一致。
7
+ * - 每个 step 前插入 `step-start`,便于在 UI 中保留多 step 边界。
8
8
  */
9
9
 
10
- import { generateId } from "@/utils/Id.js";
11
- import type { JsonObject } from "@/types/common/Json.js";
12
10
  import type { SessionMessageV1 } from "@/executor/types/SessionMessages.js";
13
11
 
14
12
  type UnknownRecord = Record<string, unknown>;
@@ -64,6 +62,21 @@ function resolveToolResultPayload(value: unknown): unknown {
64
62
  return undefined;
65
63
  }
66
64
 
65
+ function resolveToolResultErrorText(value: unknown): string | undefined {
66
+ const record = toRecord(value);
67
+ if (!record) return undefined;
68
+ if (typeof record.errorText === "string" && record.errorText.trim()) {
69
+ return record.errorText.trim();
70
+ }
71
+ if (typeof record.error === "string" && record.error.trim()) {
72
+ return record.error.trim();
73
+ }
74
+ if (record.error instanceof Error && record.error.message.trim()) {
75
+ return record.error.message.trim();
76
+ }
77
+ return undefined;
78
+ }
79
+
67
80
  function mapToolResultsByCallId(toolResults: unknown[]): Map<string, unknown> {
68
81
  const out = new Map<string, unknown>();
69
82
  for (const toolResult of toolResults) {
@@ -91,53 +104,16 @@ function toDataPartType(type: string): string {
91
104
  return `data-acp-${type.replace(/_/g, "-")}`;
92
105
  }
93
106
 
94
- function buildMetadata(params: {
95
- sessionId: string;
96
- ts: number;
97
- extra?: JsonObject;
98
- }): SessionMessageV1["metadata"] {
99
- return {
100
- v: 1,
101
- ts: params.ts,
102
- sessionId: params.sessionId,
103
- source: "egress",
104
- kind: "normal",
105
- ...(params.extra ? { extra: params.extra } : {}),
106
- };
107
- }
108
-
109
- function buildAssistantStepMessage(params: {
110
- sessionId: string;
111
- ts: number;
112
- part: Record<string, unknown>;
113
- extra: JsonObject;
114
- }): SessionMessageV1 {
115
- return {
116
- id: `a:${params.sessionId}:${generateId()}`,
117
- role: "assistant",
118
- metadata: buildMetadata({
119
- sessionId: params.sessionId,
120
- ts: params.ts,
121
- extra: params.extra,
122
- }),
123
- parts: [params.part as SessionMessageV1["parts"][number]],
124
- };
125
- }
126
-
127
107
  /**
128
- * 从 stepResult 提取按顺序落盘的 session assistant 消息。
108
+ * 从 stepResult 提取按顺序写入同一条 assistant message 的 parts。
129
109
  */
130
- export function buildSessionStepEventMessages(params: {
131
- sessionId: string;
110
+ export function buildSessionStepParts(params: {
132
111
  stepIndex: number;
133
112
  stepResult?: unknown;
134
113
  text: string;
135
114
  visibility?: "visible" | "internal";
136
- }): SessionMessageV1[] {
137
- const sessionId = String(params.sessionId || "").trim();
138
- if (!sessionId) return [];
139
-
140
- const out: SessionMessageV1[] = [];
115
+ }): SessionMessageV1["parts"] {
116
+ const out: SessionMessageV1["parts"] = [];
141
117
  const stepRecord = toRecord(params.stepResult) || {};
142
118
  const toolCalls = Array.isArray(stepRecord.toolCalls) ? stepRecord.toolCalls : [];
143
119
  const toolResults = Array.isArray(stepRecord.toolResults)
@@ -147,34 +123,29 @@ export function buildSessionStepEventMessages(params: {
147
123
  const acpEvents = Array.isArray(stepRecord.acpEvents)
148
124
  ? stepRecord.acpEvents
149
125
  : [];
150
- const baseTs = Date.now();
151
- let sequence = 0;
152
126
 
153
127
  const text = String(params.text || "").trim();
128
+ const has_structured_output =
129
+ Boolean(text) || toolCalls.length > 0 || acpEvents.length > 0;
130
+ if (!has_structured_output) return [];
131
+
132
+ out.push({ type: "step-start" });
133
+
154
134
  if (text) {
155
135
  const isInternal = params.visibility === "internal";
156
136
  out.push(
157
- buildAssistantStepMessage({
158
- sessionId,
159
- ts: baseTs + sequence,
160
- part: isInternal
161
- ? {
162
- type: "reasoning",
163
- text,
164
- state: "done",
165
- }
166
- : {
167
- type: "text",
168
- text,
169
- },
170
- extra: {
171
- internal: isInternal ? "assistant_step_reasoning" : "assistant_step_text",
172
- stepIndex: params.stepIndex,
173
- persistedBy: "session_store_run",
174
- },
175
- }),
137
+ isInternal
138
+ ? {
139
+ type: "reasoning",
140
+ text,
141
+ state: "done",
142
+ }
143
+ : {
144
+ type: "text",
145
+ text,
146
+ state: "done",
147
+ },
176
148
  );
177
- sequence += 1;
178
149
  }
179
150
 
180
151
  for (let index = 0; index < toolCalls.length; index += 1) {
@@ -185,25 +156,23 @@ export function buildSessionStepEventMessages(params: {
185
156
  const toolResult = toolCallId ? toolResultsByCallId.get(toolCallId) : undefined;
186
157
  if (!toolResult) continue;
187
158
  const output = resolveToolResultPayload(toolResult);
159
+ const errorText = resolveToolResultErrorText(toolResult);
188
160
  out.push(
189
- buildAssistantStepMessage({
190
- sessionId,
191
- ts: baseTs + sequence,
192
- part: {
193
- type: `tool-${toolName}`,
194
- ...(toolCallId ? { toolCallId } : {}),
195
- ...(input !== undefined ? { input } : {}),
196
- state: "output-available",
197
- output,
198
- },
199
- extra: {
200
- internal: "assistant_step_tool_result",
201
- stepIndex: params.stepIndex,
202
- toolIndex: index + 1,
203
- },
204
- }),
161
+ {
162
+ type: `tool-${toolName}`,
163
+ ...(toolCallId ? { toolCallId } : {}),
164
+ ...(input !== undefined ? { input } : {}),
165
+ ...(errorText
166
+ ? {
167
+ state: "output-error",
168
+ errorText,
169
+ }
170
+ : {
171
+ state: "output-available",
172
+ output,
173
+ }),
174
+ } as SessionMessageV1["parts"][number],
205
175
  );
206
- sequence += 1;
207
176
  }
208
177
 
209
178
  for (let index = 0; index < acpEvents.length; index += 1) {
@@ -211,22 +180,11 @@ export function buildSessionStepEventMessages(params: {
211
180
  const type = resolveAcpEventType(acpEvent);
212
181
  if (!type) continue;
213
182
  out.push(
214
- buildAssistantStepMessage({
215
- sessionId,
216
- ts: baseTs + sequence,
217
- part: {
218
- type: toDataPartType(type),
219
- data: resolveAcpEventData(acpEvent),
220
- },
221
- extra: {
222
- internal: "assistant_step_acp_event",
223
- stepIndex: params.stepIndex,
224
- acpEventType: type,
225
- eventIndex: index + 1,
226
- },
227
- }),
183
+ {
184
+ type: toDataPartType(type),
185
+ data: resolveAcpEventData(acpEvent),
186
+ } as SessionMessageV1["parts"][number],
228
187
  );
229
- sequence += 1;
230
188
  }
231
189
 
232
190
  return out;
@@ -17,29 +17,14 @@ import {
17
17
  * 生成真正应该落盘到 session 的 assistant message。
18
18
  *
19
19
  * 关键点(中文)
20
- * - 没有 step 持久化时,直接保留完整 assistant message
21
- * - 一旦 step 已单独落盘,最终 merged assistant 不再重复写入。
20
+ * - session 正式历史应尽量保留 AI SDK 最终 assistant UIMessage
21
+ * - 运行中 step/tool 的中断恢复由 inflight 快照承担,不再通过跳过最终 message 收口。
22
22
  */
23
23
  export function resolveAssistantMessageForPersistence(
24
24
  message: SessionMessageV1 | null | undefined,
25
25
  ): SessionMessageV1 | null {
26
26
  if (!message || typeof message !== "object") return null;
27
- return hasPersistedAssistantSteps(message) ? null : message;
28
- }
29
-
30
- /**
31
- * 判断 assistant message 是否声明“本轮 step 消息已单独持久化”。
32
- *
33
- * 关键点(中文)
34
- * - 该标记只用于避免在 run 结束时把最终 merged assistant 再重复写入 context。
35
- * - 不影响 channel 发送;只影响 context messages 的最终 append 策略。
36
- */
37
- export function hasPersistedAssistantSteps(
38
- message: SessionMessageV1 | null | undefined,
39
- ): boolean {
40
- const extra = message?.metadata?.extra;
41
- if (!extra || typeof extra !== "object" || Array.isArray(extra)) return false;
42
- return extra.assistantStepMessagesPersisted === true;
27
+ return message;
43
28
  }
44
29
 
45
30
  /**
@@ -63,6 +63,21 @@ export interface SessionHistoryStore {
63
63
  */
64
64
  append(message: SessionMessageV1): Promise<void>;
65
65
 
66
+ /**
67
+ * 读取当前运行中的 assistant 快照。
68
+ */
69
+ readInflight(): Promise<SessionMessageV1 | null>;
70
+
71
+ /**
72
+ * 写入当前运行中的 assistant 快照。
73
+ */
74
+ writeInflight(message: SessionMessageV1): Promise<void>;
75
+
76
+ /**
77
+ * 用最终 assistant 收口 inflight 快照。
78
+ */
79
+ finalizeInflight(message?: SessionMessageV1 | null): Promise<void>;
80
+
66
81
  /**
67
82
  * 读取完整消息历史。
68
83
  */
@@ -106,6 +106,7 @@ export class JsonlSessionHistoryStore implements SessionHistoryStore {
106
106
  private readonly overrideMessagesFilePath?: string;
107
107
  private readonly overrideMetaFilePath?: string;
108
108
  private readonly overrideArchiveDirPath?: string;
109
+ private readonly overrideInflightFilePath?: string;
109
110
 
110
111
  constructor(options: JsonlSessionHistoryStoreOptions) {
111
112
  const rootPath = String(options.rootPath || "").trim();
@@ -135,6 +136,9 @@ export class JsonlSessionHistoryStore implements SessionHistoryStore {
135
136
  this.overrideArchiveDirPath = this.readOptionalPath(
136
137
  options.paths?.archiveDirPath,
137
138
  );
139
+ this.overrideInflightFilePath = this.readOptionalPath(
140
+ options.paths?.inflightFilePath,
141
+ );
138
142
  }
139
143
 
140
144
  private readOptionalPath(value: string | undefined): string | undefined {
@@ -183,6 +187,14 @@ export class JsonlSessionHistoryStore implements SessionHistoryStore {
183
187
  return path.join(this.getMessagesDirPath(), "archive");
184
188
  }
185
189
 
190
+ private getInflightFilePath(): string {
191
+ if (this.overrideInflightFilePath) return this.overrideInflightFilePath;
192
+ if (this.overrideMessagesDirPath) {
193
+ return path.join(this.overrideMessagesDirPath, "inflight.json");
194
+ }
195
+ return path.join(this.getMessagesDirPath(), "inflight.json");
196
+ }
197
+
186
198
  private getLockFilePath(): string {
187
199
  return path.join(this.getMessagesDirPath(), ".session.lock");
188
200
  }
@@ -199,6 +211,75 @@ export class JsonlSessionHistoryStore implements SessionHistoryStore {
199
211
  return value || undefined;
200
212
  }
201
213
 
214
+ private normalizePersistedMessage(
215
+ input: unknown,
216
+ ): SessionMessageV1 | null {
217
+ if (!input || typeof input !== "object") return null;
218
+ const candidate = input as Partial<SessionMessageV1>;
219
+ const role = String(candidate.role || "");
220
+ if (role !== "user" && role !== "assistant") return null;
221
+ if (!Array.isArray(candidate.parts)) return null;
222
+ return candidate as SessionMessageV1;
223
+ }
224
+
225
+ private hasStructuredAssistantParts(message: SessionMessageV1 | null): boolean {
226
+ if (!message || message.role !== "assistant" || !Array.isArray(message.parts)) {
227
+ return false;
228
+ }
229
+ return message.parts.some((part) => {
230
+ if (!part || typeof part !== "object") return false;
231
+ const type = typeof part.type === "string" ? part.type.trim() : "";
232
+ return Boolean(type) && type !== "text";
233
+ });
234
+ }
235
+
236
+ private mergeInflightWithFinal(
237
+ inflight: SessionMessageV1,
238
+ finalMessage: SessionMessageV1,
239
+ ): SessionMessageV1 {
240
+ const final_parts = Array.isArray(finalMessage.parts)
241
+ ? finalMessage.parts.filter((part) => part && typeof part === "object")
242
+ : [];
243
+ if (this.hasStructuredAssistantParts(finalMessage)) {
244
+ return finalMessage;
245
+ }
246
+ if (final_parts.length === 0) return inflight;
247
+
248
+ const inflight_parts = Array.isArray(inflight.parts)
249
+ ? inflight.parts
250
+ : [];
251
+ const last_inflight_part =
252
+ inflight_parts.length > 0 ? inflight_parts[inflight_parts.length - 1] : undefined;
253
+ const last_inflight_text =
254
+ last_inflight_part &&
255
+ typeof last_inflight_part === "object" &&
256
+ last_inflight_part.type === "text" &&
257
+ typeof last_inflight_part.text === "string"
258
+ ? last_inflight_part.text.trim()
259
+ : "";
260
+ const append_parts = final_parts.filter((part, index) => {
261
+ if (index > 0) return true;
262
+ if (!part || typeof part !== "object" || part.type !== "text") return true;
263
+ const next_text = typeof part.text === "string" ? part.text.trim() : "";
264
+ if (!next_text) return false;
265
+ return next_text !== last_inflight_text;
266
+ });
267
+
268
+ return {
269
+ ...inflight,
270
+ id: finalMessage.id,
271
+ metadata: {
272
+ ...(inflight.metadata || {
273
+ v: 1 as const,
274
+ ts: Date.now(),
275
+ sessionId: this.sessionId,
276
+ }),
277
+ ...(finalMessage.metadata || {}),
278
+ },
279
+ parts: [...inflight_parts, ...append_parts],
280
+ };
281
+ }
282
+
202
283
  private async readMetaUnsafe(): Promise<SessionHistoryMetaV1> {
203
284
  const file = this.getMetaFilePath();
204
285
  try {
@@ -261,6 +342,40 @@ export class JsonlSessionHistoryStore implements SessionHistoryStore {
261
342
  await fs.writeJson(this.getMetaFilePath(), normalized, { spaces: 2 });
262
343
  }
263
344
 
345
+ private async readInflightUnsafe(): Promise<SessionMessageV1 | null> {
346
+ const file = this.getInflightFilePath();
347
+ try {
348
+ const raw = await fs.readJson(file);
349
+ return this.normalizePersistedMessage(raw);
350
+ } catch {
351
+ return null;
352
+ }
353
+ }
354
+
355
+ private async writeInflightUnsafe(message: SessionMessageV1): Promise<void> {
356
+ const normalized = this.normalizePersistedMessage(message);
357
+ if (!normalized || normalized.role !== "assistant") {
358
+ throw new Error("inflight assistant must be an assistant UIMessage");
359
+ }
360
+ const file = this.getInflightFilePath();
361
+ const temp = `${file}.${process.pid}.${Date.now()}.tmp`;
362
+ await fs.ensureDir(path.dirname(file));
363
+ await fs.writeJson(temp, normalized, { spaces: 2 });
364
+ await fs.move(temp, file, { overwrite: true });
365
+ }
366
+
367
+ private async removeInflightUnsafe(): Promise<void> {
368
+ await fs.remove(this.getInflightFilePath());
369
+ }
370
+
371
+ private async appendMessageUnsafe(message: SessionMessageV1): Promise<void> {
372
+ await fs.appendFile(
373
+ this.getMessagesFilePath(),
374
+ JSON.stringify(message) + "\n",
375
+ "utf8",
376
+ );
377
+ }
378
+
264
379
  private async withWriteLock<T>(fn: () => Promise<T>): Promise<T> {
265
380
  await this.ensureLayout();
266
381
  const lockPath = this.getLockFilePath();
@@ -361,11 +476,48 @@ export class JsonlSessionHistoryStore implements SessionHistoryStore {
361
476
 
362
477
  async append(message: SessionMessageV1): Promise<void> {
363
478
  await this.withWriteLock(async () => {
364
- await fs.appendFile(
365
- this.getMessagesFilePath(),
366
- JSON.stringify(message) + "\n",
367
- "utf8",
368
- );
479
+ const normalized = this.normalizePersistedMessage(message);
480
+ if (!normalized) return;
481
+
482
+ // 关键点(中文):若上一次 assistant 在运行中中断,新的 user 到来前先把残留快照收口到正式历史,
483
+ // 避免 `list()` 时旧 inflight 跑到新 user 后面,打乱时序。
484
+ if (normalized.role === "user") {
485
+ const current_inflight = await this.readInflightUnsafe();
486
+ if (current_inflight) {
487
+ await this.appendMessageUnsafe(current_inflight);
488
+ await this.removeInflightUnsafe();
489
+ }
490
+ }
491
+
492
+ await this.appendMessageUnsafe(normalized);
493
+ });
494
+ }
495
+
496
+ async readInflight(): Promise<SessionMessageV1 | null> {
497
+ await this.ensureLayout();
498
+ return this.readInflightUnsafe();
499
+ }
500
+
501
+ async writeInflight(message: SessionMessageV1): Promise<void> {
502
+ await this.withWriteLock(async () => {
503
+ await this.writeInflightUnsafe(message);
504
+ });
505
+ }
506
+
507
+ async finalizeInflight(message?: SessionMessageV1 | null): Promise<void> {
508
+ await this.withWriteLock(async () => {
509
+ const current_inflight = await this.readInflightUnsafe();
510
+ const normalized_message = this.normalizePersistedMessage(message);
511
+ const final_message =
512
+ current_inflight && normalized_message
513
+ ? this.mergeInflightWithFinal(current_inflight, normalized_message)
514
+ : normalized_message || current_inflight;
515
+ if (final_message) {
516
+ await this.appendMessageUnsafe(final_message);
517
+ }
518
+ if (current_inflight) {
519
+ await this.removeInflightUnsafe();
520
+ }
369
521
  });
370
522
  }
371
523
 
@@ -377,16 +529,17 @@ export class JsonlSessionHistoryStore implements SessionHistoryStore {
377
529
  const out: SessionMessageV1[] = [];
378
530
  for (const line of lines) {
379
531
  try {
380
- const obj = JSON.parse(line) as Partial<SessionMessageV1>;
381
- if (!obj || typeof obj !== "object") continue;
382
- const role = String(obj.role || "");
383
- if (role !== "user" && role !== "assistant") continue;
384
- if (!Array.isArray(obj.parts)) continue;
385
- out.push(obj as SessionMessageV1);
532
+ const obj = this.normalizePersistedMessage(JSON.parse(line));
533
+ if (!obj) continue;
534
+ out.push(obj);
386
535
  } catch {
387
536
  // ignore invalid lines
388
537
  }
389
538
  }
539
+ const current_inflight = await this.readInflightUnsafe();
540
+ if (current_inflight) {
541
+ out.push(current_inflight);
542
+ }
390
543
  return out;
391
544
  }
392
545
 
@@ -3,35 +3,9 @@
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - shell 会话生命周期已经统一收敛到 shell plugin runtime。
6
- * - 这里仅保留当前仍被 tool 与测试复用的最小能力:命令安全校验与 env 注入。
6
+ * - 这里仅保留当前仍被 tool 与测试复用的最小能力:命令安全校验。
7
7
  */
8
8
 
9
- import { stripInvocationAuthEnv } from "@/runtime/auth/AuthEnv.js";
10
- import { getSessionRunScope } from "@executor/SessionRunScope.js";
11
-
12
- function setEnvString(
13
- env: NodeJS.ProcessEnv,
14
- key: string,
15
- value: string | undefined,
16
- ): void {
17
- if (typeof value !== "string") return;
18
- const trimmed = value.trim();
19
- if (!trimmed) return;
20
- env[key] = trimmed;
21
- }
22
-
23
- function applyEnvMap(
24
- env: NodeJS.ProcessEnv,
25
- entries?: Record<string, string>,
26
- ): void {
27
- if (!entries) return;
28
- for (const [rawKey, rawValue] of Object.entries(entries)) {
29
- const key = String(rawKey || "").trim();
30
- if (!key) continue;
31
- setEnvString(env, key, rawValue);
32
- }
33
- }
34
-
35
9
  /**
36
10
  * 对 `town chat send` 命令做前置安全校验。
37
11
  *
@@ -58,26 +32,3 @@ export function validateChatSendCommand(cmd: string): string | null {
58
32
  "If your message is multi-line, use `town chat send --stdin` (with heredoc/pipe), `--text-file`, or explicit `--text`.",
59
33
  ].join(" ");
60
34
  }
61
-
62
- /**
63
- * 构建 shell 子进程环境变量。
64
- *
65
- * 关键点(中文)
66
- * - 当前仍用于 shell tool / shell runtime 与相关测试。
67
- * - 优先级:显式注入 > 当前请求上下文变量 > 宿主进程环境。
68
- * - 默认剥离 Bearer Token,避免通用 shell 隐式走本地 HTTP。
69
- */
70
- export function buildShellContextEnv(
71
- injected?: Record<string, string>,
72
- ): NodeJS.ProcessEnv {
73
- const env: NodeJS.ProcessEnv = { ...process.env };
74
- const contextCtx = getSessionRunScope();
75
-
76
- applyEnvMap(env, injected);
77
- setEnvString(env, "DC_SESSION_ID", contextCtx?.sessionId);
78
- setEnvString(env, "DC_CITY_HOST", process.env.DC_CITY_HOST);
79
- setEnvString(env, "DC_CITY_PORT", process.env.DC_CITY_PORT);
80
- stripInvocationAuthEnv(env);
81
-
82
- return env;
83
- }
@@ -30,4 +30,9 @@ export type SessionHistoryPathOverrides = {
30
30
  * 历史归档目录(通常是 `.../messages/archive`)。
31
31
  */
32
32
  archiveDirPath?: string;
33
+
34
+ /**
35
+ * 运行中 assistant 快照路径(通常是 `.../messages/inflight.json`)。
36
+ */
37
+ inflightFilePath?: string;
33
38
  };
package/src/index.ts CHANGED
@@ -8,8 +8,8 @@
8
8
  */
9
9
 
10
10
  // Agent 入口
11
- export { Agent } from "./agent/Agent.js";
12
- export { RemoteAgent } from "./agent/RemoteAgent.js";
11
+ export { Agent } from "./agent/local/Agent.js";
12
+ export { RemoteAgent } from "./agent/remote/RemoteAgent.js";
13
13
  export {
14
14
  inferAgentModelLabel,
15
15
  normalizeAgentModel,
@@ -134,7 +134,7 @@ export {
134
134
  export { loadDowncityConfig } from "./config/Config.js";
135
135
  export {
136
136
  ensureRuntimeProjectReady,
137
- } from "./runtime/host/ProjectSetup.js";
137
+ } from "./agent/local/ProjectSetup.js";
138
138
  export { assertProjectExecutionTarget } from "./config/ExecutionBinding.js";
139
139
 
140
140
  // 日志
@@ -144,7 +144,7 @@ export { getLogger, logger, type Logger } from "./utils/logger/Logger.js";
144
144
  export type {
145
145
  AgentPathRuntime,
146
146
  AgentPluginConfigRuntime,
147
- } from "./types/runtime/host/AgentHost.js";
147
+ } from "./types/agent/AgentRuntimeAssembly.js";
148
148
 
149
149
  // 项目协议类型
150
150
  export type {
@@ -273,7 +273,7 @@ export type {
273
273
  UpsertChannelAccountInput,
274
274
  UpsertEnvEntryInput,
275
275
  UpsertGlobalEnvEntryInput,
276
- } from "./types/runtime/host/Store.js";
276
+ } from "./types/platform/Store.js";
277
277
 
278
278
  // HTTP auth 协议类型
279
279
  export {
@@ -2,7 +2,7 @@
2
2
  * PluginCommandRequest:统一 plugin runtime command 请求解析模块。
3
3
  *
4
4
  * 关键点(中文)
5
- * - 统一收口当前 HTTP 入口的请求体解析。
5
+ * - 统一收口 Town gateway command 入口的请求体解析。
6
6
  * - plugin runtime 远程调用统一走 runtime command 协议,不再让 action 自带 HTTP route。
7
7
  * - ActionSchedule 参数(`schedule` / `delay` / `time`)也在这里一次性归一化。
8
8
  */
@@ -15,7 +15,7 @@ import { findPluginByName } from "@/plugin/core/PluginCatalog.js";
15
15
  import {
16
16
  createAgentPathRuntime,
17
17
  createAgentPluginConfigRuntime,
18
- } from "@/runtime/host/AgentHostRuntime.js";
18
+ } from "@/agent/local/AgentRuntimeAssembly.js";
19
19
  import type { JsonValue } from "@/types/common/Json.js";
20
20
  import type {
21
21
  Plugin,