@xenosystem/agent-interface-host 0.1.3

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 (482) hide show
  1. package/LICENSE +67 -0
  2. package/dist/acp/AcpAgentRegistryService.d.ts +77 -0
  3. package/dist/acp/AcpAgentRegistryService.d.ts.map +1 -0
  4. package/dist/acp/AcpAgentRegistryService.js +754 -0
  5. package/dist/acp/AcpAgentRegistryService.js.map +1 -0
  6. package/dist/acp/AcpAgentTurnExecutionAdapter.d.ts +56 -0
  7. package/dist/acp/AcpAgentTurnExecutionAdapter.d.ts.map +1 -0
  8. package/dist/acp/AcpAgentTurnExecutionAdapter.js +323 -0
  9. package/dist/acp/AcpAgentTurnExecutionAdapter.js.map +1 -0
  10. package/dist/acp/AcpApprovalPortAdapter.d.ts +41 -0
  11. package/dist/acp/AcpApprovalPortAdapter.d.ts.map +1 -0
  12. package/dist/acp/AcpApprovalPortAdapter.js +82 -0
  13. package/dist/acp/AcpApprovalPortAdapter.js.map +1 -0
  14. package/dist/acp/AcpCoordinationBridge.d.ts +13 -0
  15. package/dist/acp/AcpCoordinationBridge.d.ts.map +1 -0
  16. package/dist/acp/AcpCoordinationBridge.js +13 -0
  17. package/dist/acp/AcpCoordinationBridge.js.map +1 -0
  18. package/dist/acp/AcpDiagnosticsService.d.ts +61 -0
  19. package/dist/acp/AcpDiagnosticsService.d.ts.map +1 -0
  20. package/dist/acp/AcpDiagnosticsService.js +203 -0
  21. package/dist/acp/AcpDiagnosticsService.js.map +1 -0
  22. package/dist/acp/AcpExternalCertificationHarness.d.ts +47 -0
  23. package/dist/acp/AcpExternalCertificationHarness.d.ts.map +1 -0
  24. package/dist/acp/AcpExternalCertificationHarness.js +176 -0
  25. package/dist/acp/AcpExternalCertificationHarness.js.map +1 -0
  26. package/dist/acp/AcpHostBridge.d.ts +81 -0
  27. package/dist/acp/AcpHostBridge.d.ts.map +1 -0
  28. package/dist/acp/AcpHostBridge.js +101 -0
  29. package/dist/acp/AcpHostBridge.js.map +1 -0
  30. package/dist/acp/AcpInteractivePermissionBridge.d.ts +77 -0
  31. package/dist/acp/AcpInteractivePermissionBridge.d.ts.map +1 -0
  32. package/dist/acp/AcpInteractivePermissionBridge.js +127 -0
  33. package/dist/acp/AcpInteractivePermissionBridge.js.map +1 -0
  34. package/dist/acp/AcpPermissionBridge.d.ts +19 -0
  35. package/dist/acp/AcpPermissionBridge.d.ts.map +1 -0
  36. package/dist/acp/AcpPermissionBridge.js +110 -0
  37. package/dist/acp/AcpPermissionBridge.js.map +1 -0
  38. package/dist/acp/AcpPermissionPolicy.d.ts +111 -0
  39. package/dist/acp/AcpPermissionPolicy.d.ts.map +1 -0
  40. package/dist/acp/AcpPermissionPolicy.js +167 -0
  41. package/dist/acp/AcpPermissionPolicy.js.map +1 -0
  42. package/dist/acp/AcpProcessSupervisor.d.ts +134 -0
  43. package/dist/acp/AcpProcessSupervisor.d.ts.map +1 -0
  44. package/dist/acp/AcpProcessSupervisor.js +674 -0
  45. package/dist/acp/AcpProcessSupervisor.js.map +1 -0
  46. package/dist/acp/AcpProviderApprovalService.d.ts +27 -0
  47. package/dist/acp/AcpProviderApprovalService.d.ts.map +1 -0
  48. package/dist/acp/AcpProviderApprovalService.js +128 -0
  49. package/dist/acp/AcpProviderApprovalService.js.map +1 -0
  50. package/dist/acp/AcpProviderCatalogService.d.ts +69 -0
  51. package/dist/acp/AcpProviderCatalogService.d.ts.map +1 -0
  52. package/dist/acp/AcpProviderCatalogService.js +707 -0
  53. package/dist/acp/AcpProviderCatalogService.js.map +1 -0
  54. package/dist/acp/AcpProviderModelService.d.ts +6 -0
  55. package/dist/acp/AcpProviderModelService.d.ts.map +1 -0
  56. package/dist/acp/AcpProviderModelService.js +274 -0
  57. package/dist/acp/AcpProviderModelService.js.map +1 -0
  58. package/dist/acp/AcpProviderVersionReadiness.d.ts +6 -0
  59. package/dist/acp/AcpProviderVersionReadiness.d.ts.map +1 -0
  60. package/dist/acp/AcpProviderVersionReadiness.js +100 -0
  61. package/dist/acp/AcpProviderVersionReadiness.js.map +1 -0
  62. package/dist/acp/AcpRuntimeEventMapper.d.ts +16 -0
  63. package/dist/acp/AcpRuntimeEventMapper.d.ts.map +1 -0
  64. package/dist/acp/AcpRuntimeEventMapper.js +326 -0
  65. package/dist/acp/AcpRuntimeEventMapper.js.map +1 -0
  66. package/dist/acp/AcpSessionService.d.ts +65 -0
  67. package/dist/acp/AcpSessionService.d.ts.map +1 -0
  68. package/dist/acp/AcpSessionService.js +931 -0
  69. package/dist/acp/AcpSessionService.js.map +1 -0
  70. package/dist/acp/DurableAcpPermissionPolicyStore.d.ts +25 -0
  71. package/dist/acp/DurableAcpPermissionPolicyStore.d.ts.map +1 -0
  72. package/dist/acp/DurableAcpPermissionPolicyStore.js +100 -0
  73. package/dist/acp/DurableAcpPermissionPolicyStore.js.map +1 -0
  74. package/dist/acp/acpCommandSafety.d.ts +63 -0
  75. package/dist/acp/acpCommandSafety.d.ts.map +1 -0
  76. package/dist/acp/acpCommandSafety.js +90 -0
  77. package/dist/acp/acpCommandSafety.js.map +1 -0
  78. package/dist/acp/acpErrors.d.ts +47 -0
  79. package/dist/acp/acpErrors.d.ts.map +1 -0
  80. package/dist/acp/acpErrors.js +93 -0
  81. package/dist/acp/acpErrors.js.map +1 -0
  82. package/dist/acp/acpRedaction.d.ts +9 -0
  83. package/dist/acp/acpRedaction.d.ts.map +1 -0
  84. package/dist/acp/acpRedaction.js +69 -0
  85. package/dist/acp/acpRedaction.js.map +1 -0
  86. package/dist/acp/acpSessionResume.d.ts +8 -0
  87. package/dist/acp/acpSessionResume.d.ts.map +1 -0
  88. package/dist/acp/acpSessionResume.js +31 -0
  89. package/dist/acp/acpSessionResume.js.map +1 -0
  90. package/dist/acp/acpTypes.d.ts +467 -0
  91. package/dist/acp/acpTypes.d.ts.map +1 -0
  92. package/dist/acp/acpTypes.js +2 -0
  93. package/dist/acp/acpTypes.js.map +1 -0
  94. package/dist/agent/chooseDirectoryBridge.d.ts +29 -0
  95. package/dist/agent/chooseDirectoryBridge.d.ts.map +1 -0
  96. package/dist/agent/chooseDirectoryBridge.js +116 -0
  97. package/dist/agent/chooseDirectoryBridge.js.map +1 -0
  98. package/dist/agent/permissionProfiles.d.ts +29 -0
  99. package/dist/agent/permissionProfiles.d.ts.map +1 -0
  100. package/dist/agent/permissionProfiles.js +107 -0
  101. package/dist/agent/permissionProfiles.js.map +1 -0
  102. package/dist/agent/runtimeAuthorityPrompt.d.ts +13 -0
  103. package/dist/agent/runtimeAuthorityPrompt.d.ts.map +1 -0
  104. package/dist/agent/runtimeAuthorityPrompt.js +45 -0
  105. package/dist/agent/runtimeAuthorityPrompt.js.map +1 -0
  106. package/dist/agent/runtimeModeOutputGuard.d.ts +6 -0
  107. package/dist/agent/runtimeModeOutputGuard.d.ts.map +1 -0
  108. package/dist/agent/runtimeModeOutputGuard.js +40 -0
  109. package/dist/agent/runtimeModeOutputGuard.js.map +1 -0
  110. package/dist/agent/workspacePlacementBridge.d.ts +29 -0
  111. package/dist/agent/workspacePlacementBridge.d.ts.map +1 -0
  112. package/dist/agent/workspacePlacementBridge.js +143 -0
  113. package/dist/agent/workspacePlacementBridge.js.map +1 -0
  114. package/dist/agentSearch/AgentSearchService.d.ts +81 -0
  115. package/dist/agentSearch/AgentSearchService.d.ts.map +1 -0
  116. package/dist/agentSearch/AgentSearchService.js +1038 -0
  117. package/dist/agentSearch/AgentSearchService.js.map +1 -0
  118. package/dist/agentSearch/JsonInvertedIndexAdapter.d.ts +44 -0
  119. package/dist/agentSearch/JsonInvertedIndexAdapter.d.ts.map +1 -0
  120. package/dist/agentSearch/JsonInvertedIndexAdapter.js +307 -0
  121. package/dist/agentSearch/JsonInvertedIndexAdapter.js.map +1 -0
  122. package/dist/agentSearch/SearchIndexAdapter.d.ts +33 -0
  123. package/dist/agentSearch/SearchIndexAdapter.d.ts.map +1 -0
  124. package/dist/agentSearch/SearchIndexAdapter.js +2 -0
  125. package/dist/agentSearch/SearchIndexAdapter.js.map +1 -0
  126. package/dist/agentSearch/SearchSourceWatcher.d.ts +29 -0
  127. package/dist/agentSearch/SearchSourceWatcher.d.ts.map +1 -0
  128. package/dist/agentSearch/SearchSourceWatcher.js +150 -0
  129. package/dist/agentSearch/SearchSourceWatcher.js.map +1 -0
  130. package/dist/agentSearch/SqliteFtsIndexAdapter.d.ts +58 -0
  131. package/dist/agentSearch/SqliteFtsIndexAdapter.d.ts.map +1 -0
  132. package/dist/agentSearch/SqliteFtsIndexAdapter.js +420 -0
  133. package/dist/agentSearch/SqliteFtsIndexAdapter.js.map +1 -0
  134. package/dist/agentSearch/conversationIndexer.d.ts +69 -0
  135. package/dist/agentSearch/conversationIndexer.d.ts.map +1 -0
  136. package/dist/agentSearch/conversationIndexer.js +313 -0
  137. package/dist/agentSearch/conversationIndexer.js.map +1 -0
  138. package/dist/agentSearch/searchTypes.d.ts +264 -0
  139. package/dist/agentSearch/searchTypes.d.ts.map +1 -0
  140. package/dist/agentSearch/searchTypes.js +2 -0
  141. package/dist/agentSearch/searchTypes.js.map +1 -0
  142. package/dist/agentSearch/searchUtils.d.ts +12 -0
  143. package/dist/agentSearch/searchUtils.d.ts.map +1 -0
  144. package/dist/agentSearch/searchUtils.js +125 -0
  145. package/dist/agentSearch/searchUtils.js.map +1 -0
  146. package/dist/agentSearch/workspaceMetadataIndexer.d.ts +3 -0
  147. package/dist/agentSearch/workspaceMetadataIndexer.d.ts.map +1 -0
  148. package/dist/agentSearch/workspaceMetadataIndexer.js +125 -0
  149. package/dist/agentSearch/workspaceMetadataIndexer.js.map +1 -0
  150. package/dist/cli/CliControlPlaneService.d.ts +269 -0
  151. package/dist/cli/CliControlPlaneService.d.ts.map +1 -0
  152. package/dist/cli/CliControlPlaneService.js +1874 -0
  153. package/dist/cli/CliControlPlaneService.js.map +1 -0
  154. package/dist/cloud/XenoCloudAgentTurnExecutionAdapter.d.ts +91 -0
  155. package/dist/cloud/XenoCloudAgentTurnExecutionAdapter.d.ts.map +1 -0
  156. package/dist/cloud/XenoCloudAgentTurnExecutionAdapter.js +379 -0
  157. package/dist/cloud/XenoCloudAgentTurnExecutionAdapter.js.map +1 -0
  158. package/dist/codebase/CodebaseIntelligenceService.d.ts +68 -0
  159. package/dist/codebase/CodebaseIntelligenceService.d.ts.map +1 -0
  160. package/dist/codebase/CodebaseIntelligenceService.js +1717 -0
  161. package/dist/codebase/CodebaseIntelligenceService.js.map +1 -0
  162. package/dist/codebase/LanguageServerProcessManager.d.ts +85 -0
  163. package/dist/codebase/LanguageServerProcessManager.d.ts.map +1 -0
  164. package/dist/codebase/LanguageServerProcessManager.js +607 -0
  165. package/dist/codebase/LanguageServerProcessManager.js.map +1 -0
  166. package/dist/codebase/codeTypes.d.ts +485 -0
  167. package/dist/codebase/codeTypes.d.ts.map +1 -0
  168. package/dist/codebase/codeTypes.js +2 -0
  169. package/dist/codebase/codeTypes.js.map +1 -0
  170. package/dist/codebase/codeUtils.d.ts +24 -0
  171. package/dist/codebase/codeUtils.d.ts.map +1 -0
  172. package/dist/codebase/codeUtils.js +177 -0
  173. package/dist/codebase/codeUtils.js.map +1 -0
  174. package/dist/codebase/contextPacks.d.ts +18 -0
  175. package/dist/codebase/contextPacks.d.ts.map +1 -0
  176. package/dist/codebase/contextPacks.js +180 -0
  177. package/dist/codebase/contextPacks.js.map +1 -0
  178. package/dist/codebase/dependencyGraph.d.ts +3 -0
  179. package/dist/codebase/dependencyGraph.d.ts.map +1 -0
  180. package/dist/codebase/dependencyGraph.js +209 -0
  181. package/dist/codebase/dependencyGraph.js.map +1 -0
  182. package/dist/codebase/fileIndexer.d.ts +27 -0
  183. package/dist/codebase/fileIndexer.d.ts.map +1 -0
  184. package/dist/codebase/fileIndexer.js +167 -0
  185. package/dist/codebase/fileIndexer.js.map +1 -0
  186. package/dist/codebase/symbolIndexer.d.ts +3 -0
  187. package/dist/codebase/symbolIndexer.d.ts.map +1 -0
  188. package/dist/codebase/symbolIndexer.js +184 -0
  189. package/dist/codebase/symbolIndexer.js.map +1 -0
  190. package/dist/codebase/whatChanged.d.ts +4 -0
  191. package/dist/codebase/whatChanged.d.ts.map +1 -0
  192. package/dist/codebase/whatChanged.js +138 -0
  193. package/dist/codebase/whatChanged.js.map +1 -0
  194. package/dist/coordination/CoordinationService.d.ts +166 -0
  195. package/dist/coordination/CoordinationService.d.ts.map +1 -0
  196. package/dist/coordination/CoordinationService.js +247 -0
  197. package/dist/coordination/CoordinationService.js.map +1 -0
  198. package/dist/coordination/claims.d.ts +122 -0
  199. package/dist/coordination/claims.d.ts.map +1 -0
  200. package/dist/coordination/claims.js +196 -0
  201. package/dist/coordination/claims.js.map +1 -0
  202. package/dist/coordination/coordinationTools.d.ts +40 -0
  203. package/dist/coordination/coordinationTools.d.ts.map +1 -0
  204. package/dist/coordination/coordinationTools.js +92 -0
  205. package/dist/coordination/coordinationTools.js.map +1 -0
  206. package/dist/coordination/laneBridge.d.ts +84 -0
  207. package/dist/coordination/laneBridge.d.ts.map +1 -0
  208. package/dist/coordination/laneBridge.js +86 -0
  209. package/dist/coordination/laneBridge.js.map +1 -0
  210. package/dist/coordination/messages.d.ts +225 -0
  211. package/dist/coordination/messages.d.ts.map +1 -0
  212. package/dist/coordination/messages.js +335 -0
  213. package/dist/coordination/messages.js.map +1 -0
  214. package/dist/coordination/permissionWaitRegistry.d.ts +32 -0
  215. package/dist/coordination/permissionWaitRegistry.d.ts.map +1 -0
  216. package/dist/coordination/permissionWaitRegistry.js +59 -0
  217. package/dist/coordination/permissionWaitRegistry.js.map +1 -0
  218. package/dist/coordination/query.d.ts +187 -0
  219. package/dist/coordination/query.d.ts.map +1 -0
  220. package/dist/coordination/query.js +138 -0
  221. package/dist/coordination/query.js.map +1 -0
  222. package/dist/coordination/renderInbox.d.ts +15 -0
  223. package/dist/coordination/renderInbox.d.ts.map +1 -0
  224. package/dist/coordination/renderInbox.js +19 -0
  225. package/dist/coordination/renderInbox.js.map +1 -0
  226. package/dist/coordination/runtimeEvents.d.ts +53 -0
  227. package/dist/coordination/runtimeEvents.d.ts.map +1 -0
  228. package/dist/coordination/runtimeEvents.js +112 -0
  229. package/dist/coordination/runtimeEvents.js.map +1 -0
  230. package/dist/detachedHostService.d.ts +77 -0
  231. package/dist/detachedHostService.d.ts.map +1 -0
  232. package/dist/detachedHostService.js +66 -0
  233. package/dist/detachedHostService.js.map +1 -0
  234. package/dist/detachedHostSupervisor.d.ts +102 -0
  235. package/dist/detachedHostSupervisor.d.ts.map +1 -0
  236. package/dist/detachedHostSupervisor.js +168 -0
  237. package/dist/detachedHostSupervisor.js.map +1 -0
  238. package/dist/durableRuntimeEventStore.d.ts +49 -0
  239. package/dist/durableRuntimeEventStore.d.ts.map +1 -0
  240. package/dist/durableRuntimeEventStore.js +364 -0
  241. package/dist/durableRuntimeEventStore.js.map +1 -0
  242. package/dist/engineering/EngineeringWorkbenchService.d.ts +142 -0
  243. package/dist/engineering/EngineeringWorkbenchService.d.ts.map +1 -0
  244. package/dist/engineering/EngineeringWorkbenchService.js +2301 -0
  245. package/dist/engineering/EngineeringWorkbenchService.js.map +1 -0
  246. package/dist/engineering/LandingService.d.ts +112 -0
  247. package/dist/engineering/LandingService.d.ts.map +1 -0
  248. package/dist/engineering/LandingService.js +239 -0
  249. package/dist/engineering/LandingService.js.map +1 -0
  250. package/dist/engineering/engineeringTypes.d.ts +2 -0
  251. package/dist/engineering/engineeringTypes.d.ts.map +1 -0
  252. package/dist/engineering/engineeringTypes.js +2 -0
  253. package/dist/engineering/engineeringTypes.js.map +1 -0
  254. package/dist/engineering/patchReview.d.ts +11 -0
  255. package/dist/engineering/patchReview.d.ts.map +1 -0
  256. package/dist/engineering/patchReview.js +174 -0
  257. package/dist/engineering/patchReview.js.map +1 -0
  258. package/dist/index.d.ts +834 -0
  259. package/dist/index.d.ts.map +1 -0
  260. package/dist/index.js +3242 -0
  261. package/dist/index.js.map +1 -0
  262. package/dist/intake/IntakeService.d.ts +84 -0
  263. package/dist/intake/IntakeService.d.ts.map +1 -0
  264. package/dist/intake/IntakeService.js +117 -0
  265. package/dist/intake/IntakeService.js.map +1 -0
  266. package/dist/intake/RepositoryTodoIntakeSource.d.ts +72 -0
  267. package/dist/intake/RepositoryTodoIntakeSource.d.ts.map +1 -0
  268. package/dist/intake/RepositoryTodoIntakeSource.js +168 -0
  269. package/dist/intake/RepositoryTodoIntakeSource.js.map +1 -0
  270. package/dist/intake/WorkspaceTodoIntakeSource.d.ts +53 -0
  271. package/dist/intake/WorkspaceTodoIntakeSource.d.ts.map +1 -0
  272. package/dist/intake/WorkspaceTodoIntakeSource.js +81 -0
  273. package/dist/intake/WorkspaceTodoIntakeSource.js.map +1 -0
  274. package/dist/isolation/CommandExecution.d.ts +132 -0
  275. package/dist/isolation/CommandExecution.d.ts.map +1 -0
  276. package/dist/isolation/CommandExecution.js +48 -0
  277. package/dist/isolation/CommandExecution.js.map +1 -0
  278. package/dist/isolation/LocalCommandExecutor.d.ts +27 -0
  279. package/dist/isolation/LocalCommandExecutor.d.ts.map +1 -0
  280. package/dist/isolation/LocalCommandExecutor.js +97 -0
  281. package/dist/isolation/LocalCommandExecutor.js.map +1 -0
  282. package/dist/isolation/RunExecutionEnvironment.d.ts +135 -0
  283. package/dist/isolation/RunExecutionEnvironment.d.ts.map +1 -0
  284. package/dist/isolation/RunExecutionEnvironment.js +206 -0
  285. package/dist/isolation/RunExecutionEnvironment.js.map +1 -0
  286. package/dist/isolation/RunIsolationService.d.ts +90 -0
  287. package/dist/isolation/RunIsolationService.d.ts.map +1 -0
  288. package/dist/isolation/RunIsolationService.js +86 -0
  289. package/dist/isolation/RunIsolationService.js.map +1 -0
  290. package/dist/isolation/SandboxCommandExecutor.d.ts +93 -0
  291. package/dist/isolation/SandboxCommandExecutor.d.ts.map +1 -0
  292. package/dist/isolation/SandboxCommandExecutor.js +189 -0
  293. package/dist/isolation/SandboxCommandExecutor.js.map +1 -0
  294. package/dist/knowledge/WorkspaceKnowledgeService.d.ts +71 -0
  295. package/dist/knowledge/WorkspaceKnowledgeService.d.ts.map +1 -0
  296. package/dist/knowledge/WorkspaceKnowledgeService.js +103 -0
  297. package/dist/knowledge/WorkspaceKnowledgeService.js.map +1 -0
  298. package/dist/localHostAuthority.d.ts +24 -0
  299. package/dist/localHostAuthority.d.ts.map +1 -0
  300. package/dist/localHostAuthority.js +87 -0
  301. package/dist/localHostAuthority.js.map +1 -0
  302. package/dist/localHostLease.d.ts +51 -0
  303. package/dist/localHostLease.d.ts.map +1 -0
  304. package/dist/localHostLease.js +167 -0
  305. package/dist/localHostLease.js.map +1 -0
  306. package/dist/localHostPaths.d.ts +30 -0
  307. package/dist/localHostPaths.d.ts.map +1 -0
  308. package/dist/localHostPaths.js +60 -0
  309. package/dist/localHostPaths.js.map +1 -0
  310. package/dist/localRpcTransport.d.ts +21 -0
  311. package/dist/localRpcTransport.d.ts.map +1 -0
  312. package/dist/localRpcTransport.js +423 -0
  313. package/dist/localRpcTransport.js.map +1 -0
  314. package/dist/node.d.ts +104 -0
  315. package/dist/node.d.ts.map +1 -0
  316. package/dist/node.js +103 -0
  317. package/dist/node.js.map +1 -0
  318. package/dist/observation/DirectoryBaselineScanner.d.ts +44 -0
  319. package/dist/observation/DirectoryBaselineScanner.d.ts.map +1 -0
  320. package/dist/observation/DirectoryBaselineScanner.js +112 -0
  321. package/dist/observation/DirectoryBaselineScanner.js.map +1 -0
  322. package/dist/observation/MountContentReader.d.ts +63 -0
  323. package/dist/observation/MountContentReader.d.ts.map +1 -0
  324. package/dist/observation/MountContentReader.js +158 -0
  325. package/dist/observation/MountContentReader.js.map +1 -0
  326. package/dist/observation/RunObservationService.d.ts +229 -0
  327. package/dist/observation/RunObservationService.d.ts.map +1 -0
  328. package/dist/observation/RunObservationService.js +248 -0
  329. package/dist/observation/RunObservationService.js.map +1 -0
  330. package/dist/observation/XenoUseObservationSource.d.ts +42 -0
  331. package/dist/observation/XenoUseObservationSource.d.ts.map +1 -0
  332. package/dist/observation/XenoUseObservationSource.js +104 -0
  333. package/dist/observation/XenoUseObservationSource.js.map +1 -0
  334. package/dist/observation/XenoUseRunObserver.d.ts +140 -0
  335. package/dist/observation/XenoUseRunObserver.d.ts.map +1 -0
  336. package/dist/observation/XenoUseRunObserver.js +256 -0
  337. package/dist/observation/XenoUseRunObserver.js.map +1 -0
  338. package/dist/pluginMcp/PluginMcpManagerService.d.ts +141 -0
  339. package/dist/pluginMcp/PluginMcpManagerService.d.ts.map +1 -0
  340. package/dist/pluginMcp/PluginMcpManagerService.js +1821 -0
  341. package/dist/pluginMcp/PluginMcpManagerService.js.map +1 -0
  342. package/dist/pluginMcp/pluginMcpTypes.d.ts +349 -0
  343. package/dist/pluginMcp/pluginMcpTypes.d.ts.map +1 -0
  344. package/dist/pluginMcp/pluginMcpTypes.js +2 -0
  345. package/dist/pluginMcp/pluginMcpTypes.js.map +1 -0
  346. package/dist/policy/WorkspacePolicyService.d.ts +83 -0
  347. package/dist/policy/WorkspacePolicyService.d.ts.map +1 -0
  348. package/dist/policy/WorkspacePolicyService.js +809 -0
  349. package/dist/policy/WorkspacePolicyService.js.map +1 -0
  350. package/dist/policy/policyGuard.d.ts +27 -0
  351. package/dist/policy/policyGuard.d.ts.map +1 -0
  352. package/dist/policy/policyGuard.js +143 -0
  353. package/dist/policy/policyGuard.js.map +1 -0
  354. package/dist/policy/policyTypes.d.ts +190 -0
  355. package/dist/policy/policyTypes.d.ts.map +1 -0
  356. package/dist/policy/policyTypes.js +2 -0
  357. package/dist/policy/policyTypes.js.map +1 -0
  358. package/dist/runtime/RuntimeEventStore.d.ts +42 -0
  359. package/dist/runtime/RuntimeEventStore.d.ts.map +1 -0
  360. package/dist/runtime/RuntimeEventStore.js +412 -0
  361. package/dist/runtime/RuntimeEventStore.js.map +1 -0
  362. package/dist/runtime/RuntimeEventStoreRepositoryAdapter.d.ts +21 -0
  363. package/dist/runtime/RuntimeEventStoreRepositoryAdapter.d.ts.map +1 -0
  364. package/dist/runtime/RuntimeEventStoreRepositoryAdapter.js +41 -0
  365. package/dist/runtime/RuntimeEventStoreRepositoryAdapter.js.map +1 -0
  366. package/dist/runtime/RuntimeTimelineProjection.d.ts +5 -0
  367. package/dist/runtime/RuntimeTimelineProjection.d.ts.map +1 -0
  368. package/dist/runtime/RuntimeTimelineProjection.js +705 -0
  369. package/dist/runtime/RuntimeTimelineProjection.js.map +1 -0
  370. package/dist/runtime/runtimeEventTypes.d.ts +73 -0
  371. package/dist/runtime/runtimeEventTypes.d.ts.map +1 -0
  372. package/dist/runtime/runtimeEventTypes.js +2 -0
  373. package/dist/runtime/runtimeEventTypes.js.map +1 -0
  374. package/dist/sdk/SdkNativeAgentTurnExecutionAdapter.d.ts +117 -0
  375. package/dist/sdk/SdkNativeAgentTurnExecutionAdapter.d.ts.map +1 -0
  376. package/dist/sdk/SdkNativeAgentTurnExecutionAdapter.js +214 -0
  377. package/dist/sdk/SdkNativeAgentTurnExecutionAdapter.js.map +1 -0
  378. package/dist/session/AgentSessionService.d.ts +285 -0
  379. package/dist/session/AgentSessionService.d.ts.map +1 -0
  380. package/dist/session/AgentSessionService.js +444 -0
  381. package/dist/session/AgentSessionService.js.map +1 -0
  382. package/dist/session/bufferedSessionPty.d.ts +27 -0
  383. package/dist/session/bufferedSessionPty.d.ts.map +1 -0
  384. package/dist/session/bufferedSessionPty.js +49 -0
  385. package/dist/session/bufferedSessionPty.js.map +1 -0
  386. package/dist/session/renderSupport.d.ts +53 -0
  387. package/dist/session/renderSupport.d.ts.map +1 -0
  388. package/dist/session/renderSupport.js +41 -0
  389. package/dist/session/renderSupport.js.map +1 -0
  390. package/dist/session/runtimeEventChannel.d.ts +56 -0
  391. package/dist/session/runtimeEventChannel.d.ts.map +1 -0
  392. package/dist/session/runtimeEventChannel.js +53 -0
  393. package/dist/session/runtimeEventChannel.js.map +1 -0
  394. package/dist/state/JsonAgentStateRepository.d.ts +29 -0
  395. package/dist/state/JsonAgentStateRepository.d.ts.map +1 -0
  396. package/dist/state/JsonAgentStateRepository.js +165 -0
  397. package/dist/state/JsonAgentStateRepository.js.map +1 -0
  398. package/dist/state/SqliteAgentStateRepository.d.ts +58 -0
  399. package/dist/state/SqliteAgentStateRepository.d.ts.map +1 -0
  400. package/dist/state/SqliteAgentStateRepository.js +777 -0
  401. package/dist/state/SqliteAgentStateRepository.js.map +1 -0
  402. package/dist/state/createAgentStateRepository.d.ts +4 -0
  403. package/dist/state/createAgentStateRepository.d.ts.map +1 -0
  404. package/dist/state/createAgentStateRepository.js +12 -0
  405. package/dist/state/createAgentStateRepository.js.map +1 -0
  406. package/dist/state/stateSanitizers.d.ts +7 -0
  407. package/dist/state/stateSanitizers.d.ts.map +1 -0
  408. package/dist/state/stateSanitizers.js +87 -0
  409. package/dist/state/stateSanitizers.js.map +1 -0
  410. package/dist/subagents/AcpSubagentExecutionAdapter.d.ts +12 -0
  411. package/dist/subagents/AcpSubagentExecutionAdapter.d.ts.map +1 -0
  412. package/dist/subagents/AcpSubagentExecutionAdapter.js +119 -0
  413. package/dist/subagents/AcpSubagentExecutionAdapter.js.map +1 -0
  414. package/dist/subagents/CliSubagentExecutionAdapter.d.ts +13 -0
  415. package/dist/subagents/CliSubagentExecutionAdapter.d.ts.map +1 -0
  416. package/dist/subagents/CliSubagentExecutionAdapter.js +217 -0
  417. package/dist/subagents/CliSubagentExecutionAdapter.js.map +1 -0
  418. package/dist/subagents/HostTurnSubagentExecutionAdapter.d.ts +78 -0
  419. package/dist/subagents/HostTurnSubagentExecutionAdapter.d.ts.map +1 -0
  420. package/dist/subagents/HostTurnSubagentExecutionAdapter.js +160 -0
  421. package/dist/subagents/HostTurnSubagentExecutionAdapter.js.map +1 -0
  422. package/dist/subagents/SubagentRunService.d.ts +103 -0
  423. package/dist/subagents/SubagentRunService.d.ts.map +1 -0
  424. package/dist/subagents/SubagentRunService.js +1183 -0
  425. package/dist/subagents/SubagentRunService.js.map +1 -0
  426. package/dist/subagents/SubagentScheduler.d.ts +167 -0
  427. package/dist/subagents/SubagentScheduler.d.ts.map +1 -0
  428. package/dist/subagents/SubagentScheduler.js +530 -0
  429. package/dist/subagents/SubagentScheduler.js.map +1 -0
  430. package/dist/subagents/TeamAgentRouter.d.ts +104 -0
  431. package/dist/subagents/TeamAgentRouter.d.ts.map +1 -0
  432. package/dist/subagents/TeamAgentRouter.js +435 -0
  433. package/dist/subagents/TeamAgentRouter.js.map +1 -0
  434. package/dist/subagents/capabilityMatcher.d.ts +3 -0
  435. package/dist/subagents/capabilityMatcher.d.ts.map +1 -0
  436. package/dist/subagents/capabilityMatcher.js +127 -0
  437. package/dist/subagents/capabilityMatcher.js.map +1 -0
  438. package/dist/subagents/subagentRunPort.d.ts +43 -0
  439. package/dist/subagents/subagentRunPort.d.ts.map +1 -0
  440. package/dist/subagents/subagentRunPort.js +24 -0
  441. package/dist/subagents/subagentRunPort.js.map +1 -0
  442. package/dist/subagents/subagentTypes.d.ts +330 -0
  443. package/dist/subagents/subagentTypes.d.ts.map +1 -0
  444. package/dist/subagents/subagentTypes.js +2 -0
  445. package/dist/subagents/subagentTypes.js.map +1 -0
  446. package/dist/subagents/subagentWorkspaceAuthority.d.ts +29 -0
  447. package/dist/subagents/subagentWorkspaceAuthority.d.ts.map +1 -0
  448. package/dist/subagents/subagentWorkspaceAuthority.js +173 -0
  449. package/dist/subagents/subagentWorkspaceAuthority.js.map +1 -0
  450. package/dist/support/SupportDiagnosticsService.d.ts +87 -0
  451. package/dist/support/SupportDiagnosticsService.d.ts.map +1 -0
  452. package/dist/support/SupportDiagnosticsService.js +1199 -0
  453. package/dist/support/SupportDiagnosticsService.js.map +1 -0
  454. package/dist/turns/DurableInterruptedTurnStore.d.ts +14 -0
  455. package/dist/turns/DurableInterruptedTurnStore.d.ts.map +1 -0
  456. package/dist/turns/DurableInterruptedTurnStore.js +63 -0
  457. package/dist/turns/DurableInterruptedTurnStore.js.map +1 -0
  458. package/dist/turns/interruptedTurns.d.ts +50 -0
  459. package/dist/turns/interruptedTurns.d.ts.map +1 -0
  460. package/dist/turns/interruptedTurns.js +54 -0
  461. package/dist/turns/interruptedTurns.js.map +1 -0
  462. package/dist/turns/turnAdmission.d.ts +113 -0
  463. package/dist/turns/turnAdmission.d.ts.map +1 -0
  464. package/dist/turns/turnAdmission.js +136 -0
  465. package/dist/turns/turnAdmission.js.map +1 -0
  466. package/dist/workspace/WorkspaceHostService.d.ts +126 -0
  467. package/dist/workspace/WorkspaceHostService.d.ts.map +1 -0
  468. package/dist/workspace/WorkspaceHostService.js +841 -0
  469. package/dist/workspace/WorkspaceHostService.js.map +1 -0
  470. package/dist/workspace/WorkspaceShellService.d.ts +71 -0
  471. package/dist/workspace/WorkspaceShellService.d.ts.map +1 -0
  472. package/dist/workspace/WorkspaceShellService.js +273 -0
  473. package/dist/workspace/WorkspaceShellService.js.map +1 -0
  474. package/dist/workspace/fileAssociations.d.ts +12 -0
  475. package/dist/workspace/fileAssociations.d.ts.map +1 -0
  476. package/dist/workspace/fileAssociations.js +202 -0
  477. package/dist/workspace/fileAssociations.js.map +1 -0
  478. package/dist/workspace/scrollbackBuffer.d.ts +48 -0
  479. package/dist/workspace/scrollbackBuffer.d.ts.map +1 -0
  480. package/dist/workspace/scrollbackBuffer.js +94 -0
  481. package/dist/workspace/scrollbackBuffer.js.map +1 -0
  482. package/package.json +42 -0
@@ -0,0 +1,931 @@
1
+ import { createHash, randomUUID } from 'crypto';
2
+ import { mkdirSync } from 'fs';
3
+ import { join } from 'path';
4
+ import { RuntimeEventStore } from '../runtime/RuntimeEventStore.js';
5
+ import { defaultRunIdOf } from '@xenosystem/agent-interface-contract';
6
+ import { HostCoordinationLaneBridge } from '../coordination/laneBridge.js';
7
+ import { AcpProcessSupervisor, XENO_ACP_CONTEXT_META_KEY } from './AcpProcessSupervisor.js';
8
+ import { FailClosedAcpPermissionBridge } from './AcpPermissionBridge.js';
9
+ import { FailClosedAcpHostBridge, } from './AcpHostBridge.js';
10
+ import { acpErrorCode, acpSafeErrorMessage } from './acpErrors.js';
11
+ import { redactAcpText } from './acpRedaction.js';
12
+ import { XENO_ACP_SESSION_RESUME_META_KEY } from './acpSessionResume.js';
13
+ import { mapAcpAgentExitedToRuntimeEvent, mapAcpAgentFailedToRuntimeEvent, mapAcpAgentReadyToRuntimeEvent, mapAcpAgentStartedToRuntimeEvent, mapAcpAgentStderrToRuntimeEvent, mapAcpChooseDirectoryResultToRuntimeEvent, mapAcpChooseWorkspacePlacementResultToRuntimeEvent, mapAcpPermissionDecidedToRuntimeEvent, mapAcpPermissionRequestedToRuntimeEvent, mapAcpPromptResultToRuntimeEvent, mapAcpSessionFailedToRuntimeEvent, mapAcpSessionStartedToRuntimeEvent, mapAcpSessionUpdateToRuntimeEvent, } from './AcpRuntimeEventMapper.js';
14
+ /**
15
+ * How long a cancelled prompt waits for its transport to finish dying before concluding it did
16
+ * not die.
17
+ *
18
+ * Generous enough that a process which exits on cancel — the normal case, and the one the
19
+ * lifecycle event exists to report — is reliably observed. Short enough to be invisible on a path
20
+ * a human just triggered, and it is only ever paid when the agent survives the cancel, since the
21
+ * wait returns the moment the exit lands.
22
+ */
23
+ const CANCELLED_TRANSPORT_SETTLE_MS = 500;
24
+ export class AcpSessionService {
25
+ rootDir;
26
+ runtimeStore;
27
+ onRuntimeEvent;
28
+ permissionBridge;
29
+ hostBridge;
30
+ coordinationPort;
31
+ onRunActivity;
32
+ requestTimeoutMs;
33
+ conversationSessions = new Map();
34
+ conversationPromptTails = new Map();
35
+ constructor(options = {}) {
36
+ this.rootDir = options.rootDir;
37
+ this.runtimeStore = options.runtimeStore || new RuntimeEventStore(options.rootDir ? join(options.rootDir, 'runtime-events') : undefined);
38
+ this.onRuntimeEvent = options.onRuntimeEvent;
39
+ this.permissionBridge = options.permissionBridge || new FailClosedAcpPermissionBridge();
40
+ this.hostBridge = options.hostBridge || new FailClosedAcpHostBridge();
41
+ this.coordinationPort = options.coordinationPort;
42
+ this.onRunActivity = options.onRunActivity;
43
+ this.requestTimeoutMs = options.requestTimeoutMs || 30_000;
44
+ }
45
+ async runPrompt(request) {
46
+ const [result] = await this.runPromptBatch({
47
+ config: request.config,
48
+ prompts: [{
49
+ conversationId: request.conversationId,
50
+ requestId: request.requestId,
51
+ subagentRunId: request.subagentRunId,
52
+ prompt: request.prompt,
53
+ history: request.history,
54
+ systemPrompt: request.systemPrompt,
55
+ cwd: request.cwd,
56
+ additionalDirectories: request.additionalDirectories,
57
+ execution: request.execution,
58
+ providerModel: request.providerModel,
59
+ resumeSessionId: request.resumeSessionId,
60
+ resumeState: request.resumeState,
61
+ resumeAgentConfigId: request.resumeAgentConfigId,
62
+ resumeAgentConfigFingerprint: request.resumeAgentConfigFingerprint,
63
+ resumeWorkspaceFingerprint: request.resumeWorkspaceFingerprint,
64
+ timeoutMs: request.timeoutMs,
65
+ cancelAfterMs: request.cancelAfterMs,
66
+ abortSignal: request.abortSignal,
67
+ }],
68
+ });
69
+ if (!result)
70
+ throw new Error('ACP prompt batch returned no result for its requested prompt.');
71
+ return result;
72
+ }
73
+ async runConversationPrompt(request) {
74
+ const key = `${request.config.id}:${request.conversationId}`;
75
+ const previous = this.conversationPromptTails.get(key) || Promise.resolve();
76
+ let releaseCurrent;
77
+ const current = new Promise((resolve) => {
78
+ releaseCurrent = resolve;
79
+ });
80
+ const tail = previous.catch(() => undefined).then(() => current);
81
+ this.conversationPromptTails.set(key, tail);
82
+ await previous.catch(() => undefined);
83
+ try {
84
+ return await this.runConversationPromptExclusive(request, key);
85
+ }
86
+ finally {
87
+ releaseCurrent();
88
+ if (this.conversationPromptTails.get(key) === tail) {
89
+ this.conversationPromptTails.delete(key);
90
+ }
91
+ }
92
+ }
93
+ async runConversationPromptExclusive(request, key) {
94
+ if (!request.config.enabled) {
95
+ return {
96
+ success: false,
97
+ status: 'failed',
98
+ conversationId: request.conversationId,
99
+ requestId: request.requestId,
100
+ acpProcessId: `acp-process-${Date.now()}-${randomUUID().slice(0, 8)}`,
101
+ acpAgentConfigId: request.config.id,
102
+ eventCount: 0,
103
+ error: 'ACP agent config must be enabled before launch.',
104
+ };
105
+ }
106
+ const cwd = this.resolveConversationCwd(request);
107
+ const additionalDirectories = request.additionalDirectories || [];
108
+ const workspaceKey = this.workspaceKeyFor(cwd, additionalDirectories, request.execution);
109
+ const workspaceFingerprint = this.workspaceFingerprintFor(workspaceKey);
110
+ const configFingerprint = this.agentConfigFingerprintFor(request.config);
111
+ let replayHistoryOnFreshSession = false;
112
+ let active = this.conversationSessions.get(key);
113
+ if (active && (active.supervisor.getStatus() !== 'ready' || active.workspaceKey !== workspaceKey)) {
114
+ await this.closeConversationSession(active).catch(() => undefined);
115
+ active = undefined;
116
+ }
117
+ if (!active) {
118
+ const acpProcessId = `acp-process-${Date.now()}-${randomUUID().slice(0, 8)}`;
119
+ const recorder = new RuntimeRecordingAcpPermissionBridge(this.permissionBridge, (mapping, context) => {
120
+ this.appendRuntimeEvent(context, mapping);
121
+ }, this.onRunActivity);
122
+ const hostRecorder = new RuntimeRecordingAcpHostBridge(this.hostBridge, (mapping, context) => {
123
+ this.appendRuntimeEvent(context, mapping);
124
+ });
125
+ const supervisor = new AcpProcessSupervisor(request.config, {
126
+ permissionBridge: recorder,
127
+ hostBridge: hostRecorder,
128
+ /**
129
+ * \u{1F534} The caller's run id is bound HERE, from the host's own request —
130
+ * never read from a parameter the agent supplies. An agent that could
131
+ * name its own `fromRunId` could message as another run, read a peer's
132
+ * summary through someone else's visibility, and claim a file in a
133
+ * third run's name. Coordination is host-mediated exactly so a
134
+ * participant cannot assert who it is.
135
+ *
136
+ * `defaultRunIdOf` rather than `conversationId`, because a subagent run
137
+ * is its own run and coordinates under its own identity.
138
+ */
139
+ ...(this.coordinationPort
140
+ ? {
141
+ coordinationBridge: new HostCoordinationLaneBridge({
142
+ callerRunId: defaultRunIdOf({
143
+ conversationId: request.conversationId,
144
+ ...(request.subagentRunId === undefined ? {} : { subagentRunId: request.subagentRunId }),
145
+ }),
146
+ port: this.coordinationPort,
147
+ }),
148
+ }
149
+ : {}),
150
+ requestTimeoutMs: this.requestTimeoutMs,
151
+ });
152
+ const context = {
153
+ conversationId: request.conversationId,
154
+ requestId: request.requestId,
155
+ subagentRunId: request.subagentRunId,
156
+ acpProcessId,
157
+ acpAgentConfigId: request.config.id,
158
+ providerKind: 'acp-provider',
159
+ providerId: request.config.id,
160
+ providerModel: request.providerModel,
161
+ schemaVersion: 1,
162
+ redactionState: 'redacted',
163
+ };
164
+ this.appendRuntimeEvent(context, mapAcpAgentStartedToRuntimeEvent(context, supervisor.diagnostics()));
165
+ try {
166
+ await supervisor.initialize();
167
+ this.appendRuntimeEvent(context, mapAcpAgentReadyToRuntimeEvent(context, supervisor.diagnostics()));
168
+ let session;
169
+ let resumeSkipReason;
170
+ if (request.resumeSessionId) {
171
+ if (request.resumeAgentConfigId !== request.config.id) {
172
+ resumeSkipReason = 'provider_mismatch';
173
+ }
174
+ else if (!request.resumeAgentConfigFingerprint
175
+ || request.resumeAgentConfigFingerprint !== configFingerprint) {
176
+ resumeSkipReason = 'provider_config_changed';
177
+ }
178
+ else if (!request.resumeWorkspaceFingerprint
179
+ || request.resumeWorkspaceFingerprint !== workspaceFingerprint) {
180
+ resumeSkipReason = 'workspace_mismatch';
181
+ }
182
+ else if (!request.resumeState) {
183
+ resumeSkipReason = 'missing_resume_state';
184
+ }
185
+ else if (!supervisor.supportsResumeSession()
186
+ && !supervisor.supportsSessionNewResumeState()) {
187
+ resumeSkipReason = 'unsupported';
188
+ }
189
+ else {
190
+ try {
191
+ const transport = supervisor.supportsResumeSession()
192
+ ? 'session_resume'
193
+ : 'session_new_meta';
194
+ session = transport === 'session_resume'
195
+ ? await supervisor.resumeSession(request.resumeSessionId, {
196
+ cwd,
197
+ additionalDirectories,
198
+ mcpServers: [],
199
+ ...this.sessionExecutionMeta(request, true),
200
+ })
201
+ : await supervisor.createSession({
202
+ cwd,
203
+ additionalDirectories,
204
+ mcpServers: [],
205
+ ...this.sessionExecutionMeta(request, true),
206
+ });
207
+ context.acpSessionId = session.sessionId;
208
+ this.appendLifecycleEvent(context, 'acp.session.resumed', {
209
+ status: 'ready',
210
+ transport,
211
+ configFingerprint,
212
+ workspaceFingerprint,
213
+ });
214
+ }
215
+ catch (error) {
216
+ resumeSkipReason = 'resume_failed';
217
+ this.appendLifecycleEvent(context, 'acp.session.resume_failed', {
218
+ status: 'failed',
219
+ configFingerprint,
220
+ workspaceFingerprint,
221
+ error: redactAcpText(acpSafeErrorMessage(error)),
222
+ });
223
+ }
224
+ }
225
+ if (resumeSkipReason && resumeSkipReason !== 'resume_failed') {
226
+ this.appendLifecycleEvent(context, 'acp.session.resume_skipped', {
227
+ status: 'skipped',
228
+ reason: resumeSkipReason,
229
+ configFingerprint,
230
+ workspaceFingerprint,
231
+ });
232
+ }
233
+ }
234
+ if (!session) {
235
+ session = await supervisor.createSession({
236
+ cwd,
237
+ additionalDirectories,
238
+ mcpServers: [],
239
+ ...this.sessionExecutionMeta(request),
240
+ });
241
+ replayHistoryOnFreshSession = (request.history?.length || 0) > 0;
242
+ }
243
+ context.acpSessionId = session.sessionId;
244
+ const started = mapAcpSessionStartedToRuntimeEvent(context, session.sessionId);
245
+ started.event.configFingerprint = configFingerprint;
246
+ started.event.workspaceFingerprint = workspaceFingerprint;
247
+ this.appendRuntimeEvent(context, started);
248
+ active = {
249
+ key,
250
+ conversationId: request.conversationId,
251
+ configId: request.config.id,
252
+ configFingerprint,
253
+ workspaceKey,
254
+ workspaceFingerprint,
255
+ acpProcessId,
256
+ acpSessionId: session.sessionId,
257
+ supervisor,
258
+ recorder,
259
+ hostRecorder,
260
+ };
261
+ this.conversationSessions.set(key, active);
262
+ }
263
+ catch (error) {
264
+ const diagnostics = supervisor.diagnostics();
265
+ this.appendRuntimeEvent(context, mapAcpAgentFailedToRuntimeEvent(context, redactAcpText(acpSafeErrorMessage(error)), diagnostics));
266
+ this.emitStderrIfPresent(context, diagnostics);
267
+ this.appendRuntimeEvent(context, mapAcpAgentExitedToRuntimeEvent(context, diagnostics));
268
+ await supervisor.stop().catch(() => undefined);
269
+ return {
270
+ success: false,
271
+ status: statusForError(error),
272
+ conversationId: request.conversationId,
273
+ requestId: request.requestId,
274
+ acpProcessId,
275
+ acpAgentConfigId: request.config.id,
276
+ eventCount: 0,
277
+ error: redactAcpText(acpSafeErrorMessage(error)),
278
+ diagnostics,
279
+ };
280
+ }
281
+ }
282
+ const promptRequest = replayHistoryOnFreshSession
283
+ ? {
284
+ ...request,
285
+ prompt: buildAcpConversationReplayPrompt(request.history || [], request.prompt),
286
+ }
287
+ : request;
288
+ if (replayHistoryOnFreshSession) {
289
+ this.appendLifecycleEvent({
290
+ conversationId: request.conversationId,
291
+ requestId: request.requestId,
292
+ subagentRunId: request.subagentRunId,
293
+ acpProcessId: active.acpProcessId,
294
+ acpAgentConfigId: request.config.id,
295
+ acpSessionId: active.acpSessionId,
296
+ providerKind: 'acp-provider',
297
+ providerId: request.config.id,
298
+ providerModel: request.providerModel,
299
+ schemaVersion: 1,
300
+ redactionState: 'redacted',
301
+ }, 'acp.session.context_replayed', {
302
+ status: 'ready',
303
+ messageCount: request.history?.length || 0,
304
+ characterCount: (request.history || []).reduce((sum, message) => sum + message.content.length, 0),
305
+ configFingerprint: active.configFingerprint,
306
+ workspaceFingerprint: active.workspaceFingerprint,
307
+ });
308
+ }
309
+ const result = await this.runExistingSessionPrompt(active.supervisor, {
310
+ ...promptRequest,
311
+ timeoutMs: request.timeoutMs || this.requestTimeoutMs,
312
+ }, active.acpProcessId, active.acpSessionId, active.recorder, active.hostRecorder);
313
+ if (!result.success) {
314
+ if (result.status === 'timed_out') {
315
+ await this.closeConversationSession(active).catch(() => undefined);
316
+ }
317
+ else if (result.status === 'process_exited') {
318
+ this.conversationSessions.delete(active.key);
319
+ await active.supervisor.stop().catch(() => undefined);
320
+ }
321
+ else if (result.status === 'cancelled' && active.supervisor.getStatus() !== 'ready') {
322
+ // Deliberately still a plain read, and it is now sufficient: the exit was already
323
+ // established above (with a bounded wait) before this result was returned, so by the time
324
+ // control reaches here a transport that died has had its chance to say so. A second
325
+ // independent wait would double the cancel latency to re-answer a settled question.
326
+ this.conversationSessions.delete(active.key);
327
+ await active.supervisor.stop().catch(() => undefined);
328
+ }
329
+ }
330
+ return result;
331
+ }
332
+ async closeConversationSessions() {
333
+ const sessions = [...this.conversationSessions.values()];
334
+ await Promise.all(sessions.map((session) => this.closeConversationSession(session).catch(() => undefined)));
335
+ }
336
+ async closeConversation(conversationId, configId) {
337
+ const sessions = [...this.conversationSessions.values()]
338
+ .filter((session) => (session.conversationId === conversationId
339
+ && (!configId || session.configId === configId)));
340
+ await Promise.all(sessions.map((session) => this.closeConversationSession(session).catch(() => undefined)));
341
+ return sessions.length;
342
+ }
343
+ async runPromptBatch(request) {
344
+ const acpProcessId = `acp-process-${Date.now()}-${randomUUID().slice(0, 8)}`;
345
+ if (!request.config.enabled) {
346
+ return request.prompts.map((prompt) => ({
347
+ success: false,
348
+ status: 'failed',
349
+ conversationId: prompt.conversationId,
350
+ requestId: prompt.requestId,
351
+ acpProcessId,
352
+ acpAgentConfigId: request.config.id,
353
+ eventCount: 0,
354
+ error: 'ACP agent config must be enabled before launch.',
355
+ }));
356
+ }
357
+ const recorder = new RuntimeRecordingAcpPermissionBridge(this.permissionBridge, (mapping, context) => {
358
+ this.appendRuntimeEvent(context, mapping);
359
+ }, this.onRunActivity);
360
+ const hostRecorder = new RuntimeRecordingAcpHostBridge(this.hostBridge, (mapping, context) => {
361
+ this.appendRuntimeEvent(context, mapping);
362
+ });
363
+ const supervisor = new AcpProcessSupervisor(request.config, {
364
+ permissionBridge: recorder,
365
+ hostBridge: hostRecorder,
366
+ requestTimeoutMs: this.requestTimeoutMs,
367
+ });
368
+ const results = [];
369
+ const firstPrompt = request.prompts[0];
370
+ const baseContext = {
371
+ conversationId: firstPrompt?.conversationId || 'acp-conversation-unknown',
372
+ requestId: firstPrompt?.requestId || 'acp-request-unknown',
373
+ subagentRunId: firstPrompt?.subagentRunId,
374
+ acpProcessId,
375
+ acpAgentConfigId: request.config.id,
376
+ providerKind: 'acp-provider',
377
+ providerId: request.config.id,
378
+ providerModel: firstPrompt?.providerModel,
379
+ schemaVersion: 1,
380
+ redactionState: 'redacted',
381
+ };
382
+ this.appendRuntimeEvent(baseContext, mapAcpAgentStartedToRuntimeEvent(baseContext, supervisor.diagnostics()));
383
+ try {
384
+ await supervisor.initialize();
385
+ this.appendRuntimeEvent(baseContext, mapAcpAgentReadyToRuntimeEvent(baseContext, supervisor.diagnostics()));
386
+ for (const prompt of request.prompts) {
387
+ results.push(await this.runSinglePrompt(supervisor, {
388
+ ...prompt,
389
+ config: request.config,
390
+ timeoutMs: prompt.timeoutMs || request.timeoutMs || this.requestTimeoutMs,
391
+ }, acpProcessId, recorder, hostRecorder));
392
+ }
393
+ return results;
394
+ }
395
+ catch (error) {
396
+ const diagnostics = supervisor.diagnostics();
397
+ this.appendRuntimeEvent(baseContext, mapAcpAgentFailedToRuntimeEvent(baseContext, redactAcpText(acpSafeErrorMessage(error)), diagnostics));
398
+ const fallback = {
399
+ success: false,
400
+ status: statusForError(error),
401
+ conversationId: baseContext.conversationId,
402
+ requestId: baseContext.requestId,
403
+ acpProcessId,
404
+ acpAgentConfigId: request.config.id,
405
+ eventCount: 0,
406
+ error: redactAcpText(acpSafeErrorMessage(error)),
407
+ diagnostics,
408
+ };
409
+ return results.length ? results : [fallback];
410
+ }
411
+ finally {
412
+ const diagnosticsBeforeStop = supervisor.diagnostics();
413
+ this.emitStderrIfPresent(baseContext, diagnosticsBeforeStop);
414
+ this.appendRuntimeEvent(baseContext, mapAcpAgentExitedToRuntimeEvent(baseContext, diagnosticsBeforeStop));
415
+ await supervisor.stop().catch(() => undefined);
416
+ }
417
+ }
418
+ async runSinglePrompt(supervisor, request, acpProcessId, recorder, hostRecorder) {
419
+ let acpSessionId;
420
+ const context = {
421
+ conversationId: request.conversationId,
422
+ requestId: request.requestId,
423
+ subagentRunId: request.subagentRunId,
424
+ acpProcessId,
425
+ acpAgentConfigId: request.config.id,
426
+ providerKind: 'acp-provider',
427
+ providerId: request.config.id,
428
+ providerModel: request.providerModel,
429
+ schemaVersion: 1,
430
+ redactionState: 'redacted',
431
+ };
432
+ let status = 'starting';
433
+ const eventCountBefore = this.listEventCount(request.conversationId);
434
+ try {
435
+ const session = await supervisor.createSession({
436
+ cwd: request.cwd || request.config.cwd,
437
+ additionalDirectories: request.additionalDirectories,
438
+ mcpServers: [],
439
+ ...this.sessionExecutionMeta(request),
440
+ });
441
+ acpSessionId = session.sessionId;
442
+ context.acpSessionId = acpSessionId;
443
+ this.appendRuntimeEvent(context, mapAcpSessionStartedToRuntimeEvent(context, acpSessionId));
444
+ return await this.runExistingSessionPrompt(supervisor, request, acpProcessId, acpSessionId, recorder, hostRecorder, eventCountBefore);
445
+ }
446
+ catch (error) {
447
+ status = statusForError(error);
448
+ const diagnostics = supervisor.diagnostics();
449
+ diagnostics.runtimeEventCount = this.listEventCount(request.conversationId) - eventCountBefore;
450
+ this.appendRuntimeEvent(context, mapAcpSessionFailedToRuntimeEvent(context, status, redactAcpText(acpSafeErrorMessage(error)), diagnostics));
451
+ if (status === 'process_exited') {
452
+ this.appendRuntimeEvent(context, mapAcpAgentExitedToRuntimeEvent(context, diagnostics));
453
+ }
454
+ return {
455
+ success: false,
456
+ status,
457
+ conversationId: request.conversationId,
458
+ requestId: request.requestId,
459
+ acpProcessId,
460
+ acpAgentConfigId: request.config.id,
461
+ acpSessionId,
462
+ eventCount: diagnostics.runtimeEventCount || 0,
463
+ error: redactAcpText(acpSafeErrorMessage(error)),
464
+ diagnostics,
465
+ };
466
+ }
467
+ finally {
468
+ recorder.setActiveContext(undefined);
469
+ hostRecorder.setActiveContext(undefined);
470
+ }
471
+ }
472
+ async runExistingSessionPrompt(supervisor, request, acpProcessId, acpSessionId, recorder, hostRecorder, eventCountBefore = this.listEventCount(request.conversationId)) {
473
+ const context = {
474
+ conversationId: request.conversationId,
475
+ requestId: request.requestId,
476
+ subagentRunId: request.subagentRunId,
477
+ acpProcessId,
478
+ acpAgentConfigId: request.config.id,
479
+ acpSessionId,
480
+ providerKind: 'acp-provider',
481
+ providerId: request.config.id,
482
+ providerModel: request.providerModel,
483
+ schemaVersion: 1,
484
+ redactionState: 'redacted',
485
+ };
486
+ recorder.setActiveContext(context);
487
+ hostRecorder.setActiveContext(context);
488
+ let cancelTimer;
489
+ let cancellationRequested = request.abortSignal?.aborted === true;
490
+ const cancelActiveSession = () => {
491
+ cancellationRequested = true;
492
+ void supervisor.cancelSession(acpSessionId).catch(() => undefined);
493
+ };
494
+ if (request.cancelAfterMs !== undefined) {
495
+ cancelTimer = setTimeout(cancelActiveSession, Math.max(0, request.cancelAfterMs));
496
+ }
497
+ try {
498
+ const promptResult = await supervisor.prompt(acpSessionId, request.prompt, {
499
+ timeoutMs: request.timeoutMs,
500
+ signal: request.abortSignal,
501
+ model: request.providerModel,
502
+ systemPrompt: request.systemPrompt,
503
+ execution: request.execution,
504
+ onUpdate: (update) => {
505
+ this.appendRuntimeEvent(context, mapAcpSessionUpdateToRuntimeEvent(update, context));
506
+ },
507
+ });
508
+ this.appendRuntimeEvent(context, mapAcpPromptResultToRuntimeEvent(acpSessionId, context, promptResult.result));
509
+ const status = promptResult.result.stopReason === 'cancelled' ? 'cancelled' : 'completed';
510
+ const diagnostics = supervisor.diagnostics();
511
+ diagnostics.lastStopReason = promptResult.result.stopReason;
512
+ diagnostics.runtimeEventCount = this.listEventCount(request.conversationId) - eventCountBefore;
513
+ return {
514
+ success: status === 'completed',
515
+ status,
516
+ conversationId: request.conversationId,
517
+ requestId: request.requestId,
518
+ acpProcessId,
519
+ acpAgentConfigId: request.config.id,
520
+ acpSessionId,
521
+ eventCount: diagnostics.runtimeEventCount,
522
+ stopReason: promptResult.result.stopReason,
523
+ diagnostics,
524
+ };
525
+ }
526
+ catch (error) {
527
+ const status = cancellationRequested || request.abortSignal?.aborted === true
528
+ ? 'cancelled'
529
+ : statusForError(error);
530
+ const diagnostics = supervisor.diagnostics();
531
+ if (status === 'cancelled')
532
+ diagnostics.lastStopReason = 'cancelled';
533
+ diagnostics.runtimeEventCount = this.listEventCount(request.conversationId) - eventCountBefore;
534
+ if (status === 'cancelled') {
535
+ this.appendRuntimeEvent(context, mapAcpPromptResultToRuntimeEvent(acpSessionId, context, { stopReason: 'cancelled' }));
536
+ }
537
+ else {
538
+ this.appendRuntimeEvent(context, mapAcpSessionFailedToRuntimeEvent(context, status, redactAcpText(acpSafeErrorMessage(error)), diagnostics));
539
+ }
540
+ /**
541
+ * ESTABLISH the exit; do not sample it.
542
+ *
543
+ * This read `supervisor.getStatus() === 'exited'` at the instant the prompt rejected —
544
+ * which, for a cancellation, is the one moment the connection state is guaranteed to still
545
+ * be settling, because cancelling is what aborted it.
546
+ *
547
+ * ⚠️ Stated carefully, because a stronger version of this comment was written first and the
548
+ * evidence did not support it. Losing that race does NOT lose the event:
549
+ * `closeConversationSession` emits `acp.agent.exited` later under the synthetic request id
550
+ * `acp-session-close`. What raced was ATTRIBUTION — whether the exit is reported against
551
+ * the request that caused it, or deferred and attributed to a close — plus the matching
552
+ * decision about discarding the session.
553
+ *
554
+ * ⚠️ And it is a race removed BY CONSTRUCTION, not a diagnosed cause. An intermittent
555
+ * failure was observed in the cancel-recovery test under full parallel load; reading the
556
+ * code showed three separate decisions sampling this one settling value. But no
557
+ * deterministic reproduction of the sampled answer being WRONG was achieved — with the
558
+ * fixtures available the exit is always already visible by the time the prompt settles. So
559
+ * this is "a class of race made unrepresentable", which is worth having, and it is not
560
+ * evidence that it was the cause of that failure.
561
+ *
562
+ * `process_exited` needs no wait — that status IS the observation, and `prompt()` has
563
+ * already transitioned the supervisor to `exited` on `AcpProcessExitedError`.
564
+ */
565
+ const transportGone = status === 'process_exited'
566
+ || (status === 'cancelled' && await supervisor.waitForExit(CANCELLED_TRANSPORT_SETTLE_MS));
567
+ if (transportGone) {
568
+ this.appendRuntimeEvent(context, mapAcpAgentExitedToRuntimeEvent(context, diagnostics));
569
+ }
570
+ return {
571
+ success: false,
572
+ status,
573
+ conversationId: request.conversationId,
574
+ requestId: request.requestId,
575
+ acpProcessId,
576
+ acpAgentConfigId: request.config.id,
577
+ acpSessionId,
578
+ eventCount: diagnostics.runtimeEventCount || 0,
579
+ ...(status === 'cancelled'
580
+ ? { stopReason: 'cancelled' }
581
+ : { error: redactAcpText(acpSafeErrorMessage(error)) }),
582
+ diagnostics,
583
+ };
584
+ }
585
+ finally {
586
+ if (cancelTimer)
587
+ clearTimeout(cancelTimer);
588
+ recorder.setActiveContext(undefined);
589
+ hostRecorder.setActiveContext(undefined);
590
+ }
591
+ }
592
+ async closeConversationSession(active) {
593
+ this.conversationSessions.delete(active.key);
594
+ const context = {
595
+ conversationId: active.conversationId,
596
+ requestId: 'acp-session-close',
597
+ acpProcessId: active.acpProcessId,
598
+ acpAgentConfigId: active.configId,
599
+ acpSessionId: active.acpSessionId,
600
+ providerKind: 'acp-provider',
601
+ providerId: active.configId,
602
+ schemaVersion: 1,
603
+ redactionState: 'redacted',
604
+ };
605
+ const diagnostics = active.supervisor.diagnostics();
606
+ this.emitStderrIfPresent(context, diagnostics);
607
+ this.appendRuntimeEvent(context, mapAcpAgentExitedToRuntimeEvent(context, diagnostics));
608
+ await active.supervisor.stop().catch(() => undefined);
609
+ }
610
+ appendRuntimeEvent(context, mapping) {
611
+ const result = this.runtimeStore.append({
612
+ conversationId: context.conversationId,
613
+ requestId: context.requestId,
614
+ subagentRunId: context.subagentRunId,
615
+ source: 'acp',
616
+ event: {
617
+ ...mapping.event,
618
+ conversationId: context.conversationId,
619
+ requestId: context.requestId,
620
+ source: 'acp',
621
+ },
622
+ });
623
+ if (result.event && !result.duplicate)
624
+ this.onRuntimeEvent?.(result.event);
625
+ }
626
+ appendLifecycleEvent(context, type, payload) {
627
+ this.appendRuntimeEvent(context, {
628
+ type,
629
+ event: {
630
+ type,
631
+ timestamp: new Date().toISOString(),
632
+ ...context,
633
+ ...payload,
634
+ },
635
+ });
636
+ }
637
+ emitStderrIfPresent(context, diagnostics) {
638
+ if (diagnostics.stderrTail.length === 0)
639
+ return;
640
+ this.appendRuntimeEvent(context, mapAcpAgentStderrToRuntimeEvent(context, diagnostics.stderrTail));
641
+ }
642
+ listEventCount(conversationId) {
643
+ return this.runtimeStore.list({ conversationId, limit: 5000 }).events.length;
644
+ }
645
+ workspaceKeyFor(cwd, additionalDirectories, execution) {
646
+ return JSON.stringify({
647
+ cwd: normalizeWorkspacePath(cwd || ''),
648
+ additionalDirectories: additionalDirectories.map(normalizeWorkspacePath).sort(),
649
+ execution: execution || {
650
+ schemaVersion: 1,
651
+ permissionProfile: 'unspecified',
652
+ filesystem: 'read-only',
653
+ },
654
+ });
655
+ }
656
+ sessionExecutionMeta(request, includeResumeState = false) {
657
+ const meta = {};
658
+ if (request.execution) {
659
+ meta[XENO_ACP_CONTEXT_META_KEY] = {
660
+ execution: request.execution,
661
+ };
662
+ }
663
+ if (includeResumeState && request.resumeState) {
664
+ meta[XENO_ACP_SESSION_RESUME_META_KEY] = request.resumeState;
665
+ }
666
+ return Object.keys(meta).length > 0 ? { _meta: meta } : {};
667
+ }
668
+ workspaceFingerprintFor(workspaceKey) {
669
+ return createHash('sha256').update(workspaceKey).digest('hex');
670
+ }
671
+ agentConfigFingerprintFor(config) {
672
+ return createHash('sha256').update(JSON.stringify({
673
+ id: config.id,
674
+ command: config.command,
675
+ args: config.args,
676
+ cwd: config.cwd || '',
677
+ envKeys: Object.keys(config.env || {}).sort(),
678
+ trustLevel: config.trustLevel,
679
+ updatedAt: config.updatedAt,
680
+ })).digest('hex');
681
+ }
682
+ resolveConversationCwd(request) {
683
+ if (request.cwd)
684
+ return request.cwd;
685
+ if (!this.rootDir)
686
+ return undefined;
687
+ const safeConversationId = request.conversationId
688
+ .replace(/[^A-Za-z0-9._-]/g, '_')
689
+ .slice(0, 120) || 'conversation';
690
+ const cwd = join(this.rootDir, 'acp-chat-workspaces', safeConversationId);
691
+ mkdirSync(cwd, { recursive: true });
692
+ return cwd;
693
+ }
694
+ }
695
+ function normalizeWorkspacePath(path) {
696
+ const normalized = path.trim().replace(/\//g, '\\').replace(/\\+$/, '');
697
+ return process.platform === 'win32' ? normalized.toLowerCase() : normalized;
698
+ }
699
+ class RuntimeRecordingAcpPermissionBridge {
700
+ delegate;
701
+ append;
702
+ onRunActivity;
703
+ activeContext;
704
+ constructor(delegate, append,
705
+ /**
706
+ * 🔴 This layer is the ONLY one that knows both facts at once: that a
707
+ * human is being waited on, and which run is waiting. The delegate knows
708
+ * the prompt and not the run; the host knows the run and not that the
709
+ * prompt is outstanding.
710
+ */
711
+ onRunActivity) {
712
+ this.delegate = delegate;
713
+ this.append = append;
714
+ this.onRunActivity = onRunActivity;
715
+ }
716
+ setActiveContext(context) {
717
+ this.activeContext = context;
718
+ }
719
+ async requestPermission(request) {
720
+ const context = {
721
+ ...this.activeContext,
722
+ conversationId: this.activeContext?.conversationId || 'acp-conversation-unknown',
723
+ requestId: this.activeContext?.requestId || 'acp-request-unknown',
724
+ acpProcessId: this.activeContext?.acpProcessId || 'acp-process-unknown',
725
+ acpAgentConfigId: this.activeContext?.acpAgentConfigId || 'acp-agent-unknown',
726
+ providerKind: this.activeContext?.providerKind || 'acp-provider',
727
+ providerId: this.activeContext?.providerId || this.activeContext?.acpAgentConfigId || 'acp-agent-unknown',
728
+ subagentRunId: this.activeContext?.subagentRunId,
729
+ acpSessionId: request.sessionId || this.activeContext?.acpSessionId,
730
+ schemaVersion: 1,
731
+ redactionState: 'redacted',
732
+ };
733
+ const permissionId = `acp-permission-${Date.now()}-${randomUUID().slice(0, 8)}`;
734
+ this.append(mapAcpPermissionRequestedToRuntimeEvent(context, permissionId, request), context);
735
+ // The delegate may need to raise this to a surface, and a surface routes a
736
+ // prompt onto a conversation by the HOST request id. Only this layer knows
737
+ // it, so it is attached here rather than plumbed through every bridge.
738
+ const runId = defaultRunIdOf({
739
+ conversationId: context.conversationId,
740
+ ...(context.subagentRunId === undefined ? {} : { subagentRunId: context.subagentRunId }),
741
+ });
742
+ this.onRunActivity?.({ runId, state: 'awaiting-approval' });
743
+ try {
744
+ const outcome = await this.delegate.requestPermission({
745
+ ...request,
746
+ hostRequestId: context.requestId,
747
+ hostConversationId: context.conversationId,
748
+ // The SAME id the journal event above carries, so a prompt rendered from
749
+ // either source is answerable by the same key.
750
+ hostPermissionId: permissionId,
751
+ });
752
+ this.append(mapAcpPermissionDecidedToRuntimeEvent(context, permissionId, outcome, request.sessionId), context);
753
+ this.onRunActivity?.({
754
+ runId,
755
+ state: 'running',
756
+ // §7's "last decision", in the run's own terms. The OUTCOME, not the
757
+ // prompt: a peer needs to know what this run was allowed to do, and the
758
+ // prompt text is the request rather than the answer.
759
+ lastDecision: describePermissionOutcome(outcome),
760
+ });
761
+ return outcome;
762
+ }
763
+ catch (error) {
764
+ // A failed prompt still ENDS the wait. Left in `awaiting-approval` the run
765
+ // would look blocked on a human forever, and a peer would keep deferring
766
+ // to something that is not going to answer.
767
+ this.onRunActivity?.({ runId, state: 'running' });
768
+ throw error;
769
+ }
770
+ }
771
+ cancelOutstanding(reason) {
772
+ this.delegate.cancelOutstanding?.(reason);
773
+ }
774
+ }
775
+ /**
776
+ * One line a peer can act on, from a permission outcome.
777
+ *
778
+ * Deliberately terse and structural rather than the prompt text: §9 is explicit
779
+ * that a summary is never a transcript, and a permission prompt can quote a
780
+ * command, a path or a diff. What another run needs is what this one was
781
+ * allowed to do, not what it was asked.
782
+ */
783
+ function describePermissionOutcome(outcome) {
784
+ return outcome.outcome === 'selected'
785
+ ? `permission selected (${outcome.selectedOptionId})`
786
+ : 'permission cancelled';
787
+ }
788
+ class RuntimeRecordingAcpHostBridge {
789
+ delegate;
790
+ append;
791
+ activeContext;
792
+ constructor(delegate, append) {
793
+ this.delegate = delegate;
794
+ this.append = append;
795
+ }
796
+ setActiveContext(context) {
797
+ this.activeContext = context;
798
+ }
799
+ async chooseDirectory(request) {
800
+ const context = {
801
+ ...this.activeContext,
802
+ conversationId: this.activeContext?.conversationId || 'acp-conversation-unknown',
803
+ requestId: this.activeContext?.requestId || request.requestId || 'acp-request-unknown',
804
+ acpProcessId: this.activeContext?.acpProcessId || 'acp-process-unknown',
805
+ acpAgentConfigId: this.activeContext?.acpAgentConfigId || 'acp-agent-unknown',
806
+ providerKind: this.activeContext?.providerKind || 'acp-provider',
807
+ providerId: this.activeContext?.providerId || this.activeContext?.acpAgentConfigId || 'acp-agent-unknown',
808
+ subagentRunId: this.activeContext?.subagentRunId,
809
+ acpSessionId: request.sessionId || this.activeContext?.acpSessionId,
810
+ schemaVersion: 1,
811
+ redactionState: 'redacted',
812
+ };
813
+ let chooseDirectoryId;
814
+ const delegatedRequest = {
815
+ ...request,
816
+ requestId: context.requestId,
817
+ sessionId: context.acpSessionId,
818
+ emitRuntimeEvent: (event) => {
819
+ const type = typeof event.type === 'string' && event.type.trim()
820
+ ? event.type.trim()
821
+ : 'choose_directory.requested';
822
+ if (typeof event.chooseDirectoryId === 'string' && event.chooseDirectoryId.trim()) {
823
+ chooseDirectoryId = event.chooseDirectoryId.trim();
824
+ }
825
+ this.append({
826
+ type,
827
+ event: {
828
+ ...event,
829
+ type,
830
+ source: 'acp',
831
+ ...context,
832
+ toolCallId: request.toolCallId,
833
+ toolName: 'ChooseDirectory',
834
+ },
835
+ }, context);
836
+ },
837
+ };
838
+ let result;
839
+ try {
840
+ result = await this.delegate.chooseDirectory(delegatedRequest);
841
+ }
842
+ catch (error) {
843
+ result = { error: acpSafeErrorMessage(error) };
844
+ }
845
+ this.append(mapAcpChooseDirectoryResultToRuntimeEvent(context, delegatedRequest, result, chooseDirectoryId), context);
846
+ return result;
847
+ }
848
+ async chooseWorkspacePlacement(request) {
849
+ const context = {
850
+ ...this.activeContext,
851
+ conversationId: this.activeContext?.conversationId || 'acp-conversation-unknown',
852
+ requestId: this.activeContext?.requestId || request.requestId || 'acp-request-unknown',
853
+ acpProcessId: this.activeContext?.acpProcessId || 'acp-process-unknown',
854
+ acpAgentConfigId: this.activeContext?.acpAgentConfigId || 'acp-agent-unknown',
855
+ providerKind: this.activeContext?.providerKind || 'acp-provider',
856
+ providerId: this.activeContext?.providerId || this.activeContext?.acpAgentConfigId || 'acp-agent-unknown',
857
+ subagentRunId: this.activeContext?.subagentRunId,
858
+ acpSessionId: request.sessionId || this.activeContext?.acpSessionId,
859
+ schemaVersion: 1,
860
+ redactionState: 'redacted',
861
+ };
862
+ let workspacePlacementId;
863
+ const delegatedRequest = {
864
+ ...request,
865
+ requestId: context.requestId,
866
+ sessionId: context.acpSessionId,
867
+ emitRuntimeEvent: (event) => {
868
+ const type = typeof event.type === 'string' && event.type.trim()
869
+ ? event.type.trim()
870
+ : 'workspace_placement.requested';
871
+ if (typeof event.workspacePlacementId === 'string' && event.workspacePlacementId.trim()) {
872
+ workspacePlacementId = event.workspacePlacementId.trim();
873
+ }
874
+ this.append({
875
+ type,
876
+ event: {
877
+ ...event,
878
+ type,
879
+ source: 'acp',
880
+ ...context,
881
+ toolCallId: request.toolCallId,
882
+ toolName: 'ChooseWorkspacePlacement',
883
+ },
884
+ }, context);
885
+ },
886
+ };
887
+ let result;
888
+ try {
889
+ result = await this.delegate.chooseWorkspacePlacement(delegatedRequest);
890
+ }
891
+ catch (error) {
892
+ result = { error: acpSafeErrorMessage(error) };
893
+ }
894
+ this.append(mapAcpChooseWorkspacePlacementResultToRuntimeEvent(context, delegatedRequest, result, workspacePlacementId), context);
895
+ return result;
896
+ }
897
+ cancelOutstanding(reason) {
898
+ this.delegate.cancelOutstanding?.(reason);
899
+ }
900
+ }
901
+ export function buildAcpConversationReplayPrompt(history, currentPrompt) {
902
+ const priorMessages = history.map((message) => ({ ...message }));
903
+ const last = priorMessages.at(-1);
904
+ if (last?.role === 'user' && last.content.trim() === currentPrompt.trim()) {
905
+ priorMessages.pop();
906
+ }
907
+ if (priorMessages.length === 0)
908
+ return currentPrompt;
909
+ return [
910
+ 'XENO Agent restored this conversation into a fresh ACP session.',
911
+ 'Use the JSON transcript as prior conversational context. Do not repeat or answer prior turns again.',
912
+ 'Answer only the current user message that follows the transcript.',
913
+ JSON.stringify({
914
+ schema: 'xeno.agent.acp-conversation-replay.v1',
915
+ messages: priorMessages,
916
+ }),
917
+ 'Current user message:',
918
+ currentPrompt,
919
+ ].join('\n\n');
920
+ }
921
+ function statusForError(error) {
922
+ const code = acpErrorCode(error);
923
+ if (code === 'ACP_TIMEOUT')
924
+ return 'timed_out';
925
+ if (code === 'ACP_CANCELLED')
926
+ return 'cancelled';
927
+ if (code === 'ACP_PROCESS_EXITED')
928
+ return 'process_exited';
929
+ return 'failed';
930
+ }
931
+ //# sourceMappingURL=AcpSessionService.js.map