@caupulican/pi-adaptative 0.85.4 → 0.86.1

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 (480) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/dist/bun/cli.d.ts +1 -1
  3. package/dist/bun/cli.d.ts.map +1 -1
  4. package/dist/bun/cli.js +1 -0
  5. package/dist/bun/cli.js.map +1 -1
  6. package/dist/core/agent-paths.d.ts +3 -3
  7. package/dist/core/agent-paths.d.ts.map +1 -1
  8. package/dist/core/agent-paths.js +3 -3
  9. package/dist/core/agent-paths.js.map +1 -1
  10. package/dist/core/agent-session-runtime.d.ts +1 -1
  11. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  12. package/dist/core/agent-session-runtime.js +1 -1
  13. package/dist/core/agent-session-runtime.js.map +1 -1
  14. package/dist/core/agent-session.d.ts +11 -5
  15. package/dist/core/agent-session.d.ts.map +1 -1
  16. package/dist/core/agent-session.js +14 -3
  17. package/dist/core/agent-session.js.map +1 -1
  18. package/dist/core/auth-storage.d.ts +2 -2
  19. package/dist/core/auth-storage.d.ts.map +1 -1
  20. package/dist/core/auth-storage.js +2 -2
  21. package/dist/core/auth-storage.js.map +1 -1
  22. package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
  23. package/dist/core/autonomy/bounded-completion.js +19 -8
  24. package/dist/core/autonomy/bounded-completion.js.map +1 -1
  25. package/dist/core/autonomy/lane-tool-surface.d.ts +11 -5
  26. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  27. package/dist/core/autonomy/lane-tool-surface.js +34 -8
  28. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  29. package/dist/core/autonomy/subagent-prompt.d.ts +3 -3
  30. package/dist/core/autonomy/subagent-prompt.js +9 -9
  31. package/dist/core/autonomy/subagent-prompt.js.map +1 -1
  32. package/dist/core/background-lane-controller.d.ts +10 -8
  33. package/dist/core/background-lane-controller.d.ts.map +1 -1
  34. package/dist/core/background-lane-controller.js +23 -13
  35. package/dist/core/background-lane-controller.js.map +1 -1
  36. package/dist/core/bash-execution-controller.d.ts +4 -0
  37. package/dist/core/bash-execution-controller.d.ts.map +1 -1
  38. package/dist/core/bash-execution-controller.js +11 -4
  39. package/dist/core/bash-execution-controller.js.map +1 -1
  40. package/dist/core/bash-executor.d.ts +2 -0
  41. package/dist/core/bash-executor.d.ts.map +1 -1
  42. package/dist/core/bash-executor.js +4 -3
  43. package/dist/core/bash-executor.js.map +1 -1
  44. package/dist/core/billing-failover-controller.d.ts +2 -2
  45. package/dist/core/billing-failover-controller.d.ts.map +1 -1
  46. package/dist/core/billing-failover-controller.js +1 -1
  47. package/dist/core/billing-failover-controller.js.map +1 -1
  48. package/dist/core/capability-contract.d.ts +1 -1
  49. package/dist/core/capability-contract.d.ts.map +1 -1
  50. package/dist/core/capability-contract.js +0 -1
  51. package/dist/core/capability-contract.js.map +1 -1
  52. package/dist/core/compaction-controller.d.ts +8 -2
  53. package/dist/core/compaction-controller.d.ts.map +1 -1
  54. package/dist/core/compaction-controller.js +73 -3
  55. package/dist/core/compaction-controller.js.map +1 -1
  56. package/dist/core/compaction-support.d.ts +2 -2
  57. package/dist/core/compaction-support.d.ts.map +1 -1
  58. package/dist/core/compaction-support.js +9 -1
  59. package/dist/core/compaction-support.js.map +1 -1
  60. package/dist/core/context/artifact-retrieval.d.ts +1 -1
  61. package/dist/core/context/artifact-retrieval.d.ts.map +1 -1
  62. package/dist/core/context/artifact-retrieval.js +1 -1
  63. package/dist/core/context/artifact-retrieval.js.map +1 -1
  64. package/dist/core/context/context-artifacts.d.ts +6 -6
  65. package/dist/core/context/context-artifacts.d.ts.map +1 -1
  66. package/dist/core/context/context-artifacts.js +151 -63
  67. package/dist/core/context/context-artifacts.js.map +1 -1
  68. package/dist/core/context/context-composition.js +1 -1
  69. package/dist/core/context/context-composition.js.map +1 -1
  70. package/dist/core/context/context-store-retention.d.ts.map +1 -1
  71. package/dist/core/context/context-store-retention.js +5 -2
  72. package/dist/core/context/context-store-retention.js.map +1 -1
  73. package/dist/core/context/file-store-memory-provider.js +1 -1
  74. package/dist/core/context/file-store-memory-provider.js.map +1 -1
  75. package/dist/core/context/tool-output-packer.d.ts +1 -1
  76. package/dist/core/context/tool-output-packer.d.ts.map +1 -1
  77. package/dist/core/context/tool-output-packer.js +1 -1
  78. package/dist/core/context/tool-output-packer.js.map +1 -1
  79. package/dist/core/context-gc.d.ts.map +1 -1
  80. package/dist/core/context-gc.js +7 -5
  81. package/dist/core/context-gc.js.map +1 -1
  82. package/dist/core/context-pipeline.d.ts +2 -2
  83. package/dist/core/context-pipeline.d.ts.map +1 -1
  84. package/dist/core/context-pipeline.js +8 -4
  85. package/dist/core/context-pipeline.js.map +1 -1
  86. package/dist/core/cost/cost-summary.d.ts +1 -1
  87. package/dist/core/cost/cost-summary.d.ts.map +1 -1
  88. package/dist/core/cost/cost-summary.js +1 -1
  89. package/dist/core/cost/cost-summary.js.map +1 -1
  90. package/dist/core/cost/daily-usage.d.ts +1 -1
  91. package/dist/core/cost/daily-usage.d.ts.map +1 -1
  92. package/dist/core/cost/daily-usage.js +2 -2
  93. package/dist/core/cost/daily-usage.js.map +1 -1
  94. package/dist/core/cost/session-usage.d.ts +1 -1
  95. package/dist/core/cost/session-usage.d.ts.map +1 -1
  96. package/dist/core/cost/session-usage.js +1 -1
  97. package/dist/core/cost/session-usage.js.map +1 -1
  98. package/dist/core/default-tool-surface.d.ts +1 -0
  99. package/dist/core/default-tool-surface.d.ts.map +1 -1
  100. package/dist/core/default-tool-surface.js +3 -2
  101. package/dist/core/default-tool-surface.js.map +1 -1
  102. package/dist/core/delegation/worker-actions.js +1 -1
  103. package/dist/core/delegation/worker-actions.js.map +1 -1
  104. package/dist/core/delegation/worker-agent-control-coordinator.d.ts +27 -8
  105. package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -1
  106. package/dist/core/delegation/worker-agent-control-coordinator.js +191 -33
  107. package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
  108. package/dist/core/delegation/worker-agent-control.d.ts +45 -6
  109. package/dist/core/delegation/worker-agent-control.d.ts.map +1 -1
  110. package/dist/core/delegation/worker-agent-control.js +110 -13
  111. package/dist/core/delegation/worker-agent-control.js.map +1 -1
  112. package/dist/core/delegation/worker-attempt-executor.d.ts +1 -1
  113. package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -1
  114. package/dist/core/delegation/worker-attempt-executor.js +180 -160
  115. package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
  116. package/dist/core/delegation/worker-authority-resolver.d.ts +23 -0
  117. package/dist/core/delegation/worker-authority-resolver.d.ts.map +1 -0
  118. package/dist/core/delegation/worker-authority-resolver.js +128 -0
  119. package/dist/core/delegation/worker-authority-resolver.js.map +1 -0
  120. package/dist/core/delegation/worker-conversation-store.d.ts +2 -1
  121. package/dist/core/delegation/worker-conversation-store.d.ts.map +1 -1
  122. package/dist/core/delegation/worker-conversation-store.js +4 -3
  123. package/dist/core/delegation/worker-conversation-store.js.map +1 -1
  124. package/dist/core/delegation/worker-delegation-controller.d.ts +7 -1
  125. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
  126. package/dist/core/delegation/worker-delegation-controller.js +260 -87
  127. package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
  128. package/dist/core/delegation/worker-delegation-request.d.ts +25 -4
  129. package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
  130. package/dist/core/delegation/worker-delegation-request.js +90 -1
  131. package/dist/core/delegation/worker-delegation-request.js.map +1 -1
  132. package/dist/core/delegation/worker-execution-policy.d.ts +2 -0
  133. package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -1
  134. package/dist/core/delegation/worker-execution-policy.js +22 -12
  135. package/dist/core/delegation/worker-execution-policy.js.map +1 -1
  136. package/dist/core/delegation/worker-lifecycle.d.ts +1 -0
  137. package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
  138. package/dist/core/delegation/worker-lifecycle.js +4 -2
  139. package/dist/core/delegation/worker-lifecycle.js.map +1 -1
  140. package/dist/core/delegation/worker-profile-resolver.d.ts +0 -2
  141. package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
  142. package/dist/core/delegation/worker-profile-resolver.js +8 -35
  143. package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
  144. package/dist/core/delegation/worker-recovery-coordinator.d.ts.map +1 -1
  145. package/dist/core/delegation/worker-recovery-coordinator.js +1 -0
  146. package/dist/core/delegation/worker-recovery-coordinator.js.map +1 -1
  147. package/dist/core/delegation/worker-runner.d.ts +6 -1
  148. package/dist/core/delegation/worker-runner.d.ts.map +1 -1
  149. package/dist/core/delegation/worker-runner.js +20 -6
  150. package/dist/core/delegation/worker-runner.js.map +1 -1
  151. package/dist/core/delegation/worker-tree-budget-coordinator.d.ts +47 -0
  152. package/dist/core/delegation/worker-tree-budget-coordinator.d.ts.map +1 -0
  153. package/dist/core/delegation/worker-tree-budget-coordinator.js +210 -0
  154. package/dist/core/delegation/worker-tree-budget-coordinator.js.map +1 -0
  155. package/dist/core/extensions/builtin.d.ts +2 -2
  156. package/dist/core/extensions/builtin.d.ts.map +1 -1
  157. package/dist/core/extensions/builtin.js +2 -2
  158. package/dist/core/extensions/builtin.js.map +1 -1
  159. package/dist/core/extensions/bundled-virtual-modules.d.ts +2 -0
  160. package/dist/core/extensions/bundled-virtual-modules.d.ts.map +1 -0
  161. package/dist/core/extensions/bundled-virtual-modules.js +129 -0
  162. package/dist/core/extensions/bundled-virtual-modules.js.map +1 -0
  163. package/dist/core/extensions/factory-runtime.d.ts +22 -0
  164. package/dist/core/extensions/factory-runtime.d.ts.map +1 -0
  165. package/dist/core/extensions/factory-runtime.js +334 -0
  166. package/dist/core/extensions/factory-runtime.js.map +1 -0
  167. package/dist/core/extensions/index.d.ts +1 -1
  168. package/dist/core/extensions/index.d.ts.map +1 -1
  169. package/dist/core/extensions/index.js +1 -1
  170. package/dist/core/extensions/index.js.map +1 -1
  171. package/dist/core/extensions/lifecycle.d.ts +13 -0
  172. package/dist/core/extensions/lifecycle.d.ts.map +1 -0
  173. package/dist/core/extensions/lifecycle.js +52 -0
  174. package/dist/core/extensions/lifecycle.js.map +1 -0
  175. package/dist/core/extensions/loader.d.ts +3 -24
  176. package/dist/core/extensions/loader.d.ts.map +1 -1
  177. package/dist/core/extensions/loader.js +21 -531
  178. package/dist/core/extensions/loader.js.map +1 -1
  179. package/dist/core/extensions/virtual-modules.d.ts +51 -0
  180. package/dist/core/extensions/virtual-modules.d.ts.map +1 -0
  181. package/dist/core/extensions/virtual-modules.js +59 -0
  182. package/dist/core/extensions/virtual-modules.js.map +1 -0
  183. package/dist/core/foreground-recovery-controller.d.ts +2 -1
  184. package/dist/core/foreground-recovery-controller.d.ts.map +1 -1
  185. package/dist/core/foreground-recovery-controller.js +3 -3
  186. package/dist/core/foreground-recovery-controller.js.map +1 -1
  187. package/dist/core/goal-loop-controller.js +1 -1
  188. package/dist/core/goal-loop-controller.js.map +1 -1
  189. package/dist/core/goals/compact-goal-context.d.ts +1 -1
  190. package/dist/core/goals/compact-goal-context.d.ts.map +1 -1
  191. package/dist/core/goals/compact-goal-context.js +1 -1
  192. package/dist/core/goals/compact-goal-context.js.map +1 -1
  193. package/dist/core/goals/goal-auto-continue-controller.js +1 -1
  194. package/dist/core/goals/goal-auto-continue-controller.js.map +1 -1
  195. package/dist/core/goals/goal-session-controller.d.ts +1 -1
  196. package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
  197. package/dist/core/goals/goal-session-controller.js +1 -1
  198. package/dist/core/goals/goal-session-controller.js.map +1 -1
  199. package/dist/core/http-dispatcher.d.ts +1 -1
  200. package/dist/core/http-dispatcher.d.ts.map +1 -1
  201. package/dist/core/http-dispatcher.js +1 -1
  202. package/dist/core/http-dispatcher.js.map +1 -1
  203. package/dist/core/index.d.ts +3 -2
  204. package/dist/core/index.d.ts.map +1 -1
  205. package/dist/core/index.js +2 -1
  206. package/dist/core/index.js.map +1 -1
  207. package/dist/core/memory/providers/file-store.d.ts.map +1 -1
  208. package/dist/core/memory/providers/file-store.js +1 -1
  209. package/dist/core/memory/providers/file-store.js.map +1 -1
  210. package/dist/core/memory/providers/user-memory-archive.js +1 -1
  211. package/dist/core/memory/providers/user-memory-archive.js.map +1 -1
  212. package/dist/core/model-registry.d.ts +2 -1
  213. package/dist/core/model-registry.d.ts.map +1 -1
  214. package/dist/core/model-registry.js +4 -1
  215. package/dist/core/model-registry.js.map +1 -1
  216. package/dist/core/model-resolver.d.ts +1 -1
  217. package/dist/core/model-resolver.d.ts.map +1 -1
  218. package/dist/core/model-resolver.js +1 -1
  219. package/dist/core/model-resolver.js.map +1 -1
  220. package/dist/core/model-router-controller.js +1 -1
  221. package/dist/core/model-router-controller.js.map +1 -1
  222. package/dist/core/model-selection-controller.js +1 -1
  223. package/dist/core/model-selection-controller.js.map +1 -1
  224. package/dist/core/model-tool-protocol.d.ts +1 -1
  225. package/dist/core/model-tool-protocol.d.ts.map +1 -1
  226. package/dist/core/model-tool-protocol.js +1 -1
  227. package/dist/core/model-tool-protocol.js.map +1 -1
  228. package/dist/core/models/llamacpp-runtime.d.ts +7 -0
  229. package/dist/core/models/llamacpp-runtime.d.ts.map +1 -1
  230. package/dist/core/models/llamacpp-runtime.js +8 -3
  231. package/dist/core/models/llamacpp-runtime.js.map +1 -1
  232. package/dist/core/models/local-runtime.js +1 -1
  233. package/dist/core/models/local-runtime.js.map +1 -1
  234. package/dist/core/models/runtime-process.d.ts.map +1 -1
  235. package/dist/core/models/runtime-process.js +5 -18
  236. package/dist/core/models/runtime-process.js.map +1 -1
  237. package/dist/core/orchestration/bounded-string-array.d.ts +11 -0
  238. package/dist/core/orchestration/bounded-string-array.d.ts.map +1 -0
  239. package/dist/core/orchestration/bounded-string-array.js +17 -0
  240. package/dist/core/orchestration/bounded-string-array.js.map +1 -0
  241. package/dist/core/orchestration/capability-gateway.d.ts +16 -0
  242. package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
  243. package/dist/core/orchestration/capability-gateway.js +38 -0
  244. package/dist/core/orchestration/capability-gateway.js.map +1 -1
  245. package/dist/core/orchestration/contracts.d.ts +11 -3
  246. package/dist/core/orchestration/contracts.d.ts.map +1 -1
  247. package/dist/core/orchestration/contracts.js +0 -1
  248. package/dist/core/orchestration/contracts.js.map +1 -1
  249. package/dist/core/orchestration/delegation-ledger.d.ts +1 -0
  250. package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -1
  251. package/dist/core/orchestration/delegation-ledger.js +3 -0
  252. package/dist/core/orchestration/delegation-ledger.js.map +1 -1
  253. package/dist/core/orchestration/event-store.d.ts +12 -10
  254. package/dist/core/orchestration/event-store.d.ts.map +1 -1
  255. package/dist/core/orchestration/event-store.js +94 -104
  256. package/dist/core/orchestration/event-store.js.map +1 -1
  257. package/dist/core/orchestration/lane-tool-manifests.d.ts +2 -2
  258. package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
  259. package/dist/core/orchestration/lane-tool-manifests.js +4 -1
  260. package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
  261. package/dist/core/orchestration/model-binding.d.ts +1 -1
  262. package/dist/core/orchestration/model-binding.d.ts.map +1 -1
  263. package/dist/core/orchestration/model-binding.js +1 -1
  264. package/dist/core/orchestration/model-binding.js.map +1 -1
  265. package/dist/core/orchestration/policy-compiler.d.ts.map +1 -1
  266. package/dist/core/orchestration/policy-compiler.js +8 -9
  267. package/dist/core/orchestration/policy-compiler.js.map +1 -1
  268. package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
  269. package/dist/core/orchestration/profile-registry.js +4 -10
  270. package/dist/core/orchestration/profile-registry.js.map +1 -1
  271. package/dist/core/orchestration/task-profile-writer.js +1 -1
  272. package/dist/core/orchestration/task-profile-writer.js.map +1 -1
  273. package/dist/core/orchestration/task-runtime.d.ts +1 -0
  274. package/dist/core/orchestration/task-runtime.d.ts.map +1 -1
  275. package/dist/core/orchestration/task-runtime.js +58 -3
  276. package/dist/core/orchestration/task-runtime.js.map +1 -1
  277. package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -1
  278. package/dist/core/orchestration/worker-execution-contract.js +10 -17
  279. package/dist/core/orchestration/worker-execution-contract.js.map +1 -1
  280. package/dist/core/process-matrix/runtime.d.ts +15 -1
  281. package/dist/core/process-matrix/runtime.d.ts.map +1 -1
  282. package/dist/core/process-matrix/runtime.js +55 -34
  283. package/dist/core/process-matrix/runtime.js.map +1 -1
  284. package/dist/core/reflection-controller.d.ts +4 -3
  285. package/dist/core/reflection-controller.d.ts.map +1 -1
  286. package/dist/core/reflection-controller.js +2 -2
  287. package/dist/core/reflection-controller.js.map +1 -1
  288. package/dist/core/research/model-fitness-controller.js +1 -1
  289. package/dist/core/research/model-fitness-controller.js.map +1 -1
  290. package/dist/core/research/research-lane-controller.d.ts +2 -2
  291. package/dist/core/research/research-lane-controller.d.ts.map +1 -1
  292. package/dist/core/research/research-lane-controller.js +1 -1
  293. package/dist/core/research/research-lane-controller.js.map +1 -1
  294. package/dist/core/resource-loader.d.ts +10 -19
  295. package/dist/core/resource-loader.d.ts.map +1 -1
  296. package/dist/core/resource-loader.js +8 -70
  297. package/dist/core/resource-loader.js.map +1 -1
  298. package/dist/core/risk-classifier.js +3 -3
  299. package/dist/core/risk-classifier.js.map +1 -1
  300. package/dist/core/runtime-builder.d.ts +4 -1
  301. package/dist/core/runtime-builder.d.ts.map +1 -1
  302. package/dist/core/runtime-builder.js +47 -18
  303. package/dist/core/runtime-builder.js.map +1 -1
  304. package/dist/core/scout-controller.d.ts +1 -1
  305. package/dist/core/scout-controller.d.ts.map +1 -1
  306. package/dist/core/scout-controller.js +1 -1
  307. package/dist/core/scout-controller.js.map +1 -1
  308. package/dist/core/sdk.d.ts +2 -2
  309. package/dist/core/sdk.d.ts.map +1 -1
  310. package/dist/core/sdk.js +3 -3
  311. package/dist/core/sdk.js.map +1 -1
  312. package/dist/core/secrets/bitwarden-credential-storage.d.ts +51 -0
  313. package/dist/core/secrets/bitwarden-credential-storage.d.ts.map +1 -0
  314. package/dist/core/secrets/bitwarden-credential-storage.js +345 -0
  315. package/dist/core/secrets/bitwarden-credential-storage.js.map +1 -0
  316. package/dist/core/secrets/credential-exposure-guard.d.ts +8 -4
  317. package/dist/core/secrets/credential-exposure-guard.d.ts.map +1 -1
  318. package/dist/core/secrets/credential-exposure-guard.js +31 -29
  319. package/dist/core/secrets/credential-exposure-guard.js.map +1 -1
  320. package/dist/core/secrets/credential-manager.d.ts +109 -0
  321. package/dist/core/secrets/credential-manager.d.ts.map +1 -0
  322. package/dist/core/secrets/credential-manager.js +384 -0
  323. package/dist/core/secrets/credential-manager.js.map +1 -0
  324. package/dist/core/secrets/credential-project.d.ts +4 -0
  325. package/dist/core/secrets/credential-project.d.ts.map +1 -0
  326. package/dist/core/secrets/credential-project.js +145 -0
  327. package/dist/core/secrets/credential-project.js.map +1 -0
  328. package/dist/core/secrets/secret-dotenv.d.ts +1 -1
  329. package/dist/core/secrets/secret-dotenv.js +1 -1
  330. package/dist/core/secrets/secret-dotenv.js.map +1 -1
  331. package/dist/core/security/context-threat-scanner.d.ts +14 -0
  332. package/dist/core/security/context-threat-scanner.d.ts.map +1 -0
  333. package/dist/core/security/context-threat-scanner.js +71 -0
  334. package/dist/core/security/context-threat-scanner.js.map +1 -0
  335. package/dist/core/session-supervision-runtime.d.ts +4 -1
  336. package/dist/core/session-supervision-runtime.d.ts.map +1 -1
  337. package/dist/core/session-supervision-runtime.js +49 -11
  338. package/dist/core/session-supervision-runtime.js.map +1 -1
  339. package/dist/core/settings-manager.d.ts +4 -2
  340. package/dist/core/settings-manager.d.ts.map +1 -1
  341. package/dist/core/settings-manager.js +10 -6
  342. package/dist/core/settings-manager.js.map +1 -1
  343. package/dist/core/slash-commands.d.ts.map +1 -1
  344. package/dist/core/slash-commands.js +1 -0
  345. package/dist/core/slash-commands.js.map +1 -1
  346. package/dist/core/system-prompt.js +1 -1
  347. package/dist/core/system-prompt.js.map +1 -1
  348. package/dist/core/tool-capability-policy.js +2 -2
  349. package/dist/core/tool-capability-policy.js.map +1 -1
  350. package/dist/core/tool-recovery-logger.js +1 -1
  351. package/dist/core/tool-recovery-logger.js.map +1 -1
  352. package/dist/core/tools/artifact-retrieve.js +1 -1
  353. package/dist/core/tools/artifact-retrieve.js.map +1 -1
  354. package/dist/core/tools/bash.d.ts +2 -2
  355. package/dist/core/tools/bash.d.ts.map +1 -1
  356. package/dist/core/tools/bash.js +16 -4
  357. package/dist/core/tools/bash.js.map +1 -1
  358. package/dist/core/tools/delegate.d.ts +29 -1
  359. package/dist/core/tools/delegate.d.ts.map +1 -1
  360. package/dist/core/tools/delegate.js +179 -28
  361. package/dist/core/tools/delegate.js.map +1 -1
  362. package/dist/core/tools/extensionify-runtime.d.ts +44 -0
  363. package/dist/core/tools/extensionify-runtime.d.ts.map +1 -0
  364. package/dist/core/tools/extensionify-runtime.js +115 -0
  365. package/dist/core/tools/extensionify-runtime.js.map +1 -0
  366. package/dist/core/tools/extensionify.d.ts +9 -30
  367. package/dist/core/tools/extensionify.d.ts.map +1 -1
  368. package/dist/core/tools/extensionify.js +10 -140
  369. package/dist/core/tools/extensionify.js.map +1 -1
  370. package/dist/core/tools/find.d.ts +1 -1
  371. package/dist/core/tools/find.d.ts.map +1 -1
  372. package/dist/core/tools/find.js +1 -1
  373. package/dist/core/tools/find.js.map +1 -1
  374. package/dist/core/tools/git-filter.d.ts +1 -0
  375. package/dist/core/tools/git-filter.d.ts.map +1 -1
  376. package/dist/core/tools/git-filter.js +1 -1
  377. package/dist/core/tools/git-filter.js.map +1 -1
  378. package/dist/core/tools/index.d.ts +2 -4
  379. package/dist/core/tools/index.d.ts.map +1 -1
  380. package/dist/core/tools/index.js +7 -43
  381. package/dist/core/tools/index.js.map +1 -1
  382. package/dist/core/tools/ls.d.ts +1 -1
  383. package/dist/core/tools/ls.d.ts.map +1 -1
  384. package/dist/core/tools/ls.js +1 -1
  385. package/dist/core/tools/ls.js.map +1 -1
  386. package/dist/core/tools/output-accumulator.d.ts +1 -1
  387. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  388. package/dist/core/tools/output-accumulator.js +1 -1
  389. package/dist/core/tools/output-accumulator.js.map +1 -1
  390. package/dist/core/tools/profile-writer.js +3 -3
  391. package/dist/core/tools/profile-writer.js.map +1 -1
  392. package/dist/core/tools/python.d.ts +2 -0
  393. package/dist/core/tools/python.d.ts.map +1 -1
  394. package/dist/core/tools/python.js +17 -12
  395. package/dist/core/tools/python.js.map +1 -1
  396. package/dist/core/tools/render-utils.js +1 -1
  397. package/dist/core/tools/render-utils.js.map +1 -1
  398. package/dist/core/tools/run-process.d.ts +2 -0
  399. package/dist/core/tools/run-process.d.ts.map +1 -1
  400. package/dist/core/tools/run-process.js +7 -3
  401. package/dist/core/tools/run-process.js.map +1 -1
  402. package/dist/core/tools/search-command-guard.d.ts +8 -0
  403. package/dist/core/tools/search-command-guard.d.ts.map +1 -1
  404. package/dist/core/tools/search-command-guard.js +54 -0
  405. package/dist/core/tools/search-command-guard.js.map +1 -1
  406. package/dist/core/tools/secret-store.d.ts +8 -18
  407. package/dist/core/tools/secret-store.d.ts.map +1 -1
  408. package/dist/core/tools/secret-store.js +83 -348
  409. package/dist/core/tools/secret-store.js.map +1 -1
  410. package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
  411. package/dist/core/tools/shell-contract-router.js +9 -4
  412. package/dist/core/tools/shell-contract-router.js.map +1 -1
  413. package/dist/core/tools/shell-session.d.ts.map +1 -1
  414. package/dist/core/tools/shell-session.js +6 -4
  415. package/dist/core/tools/shell-session.js.map +1 -1
  416. package/dist/core/tools/tool-definition-factory.d.ts +32 -0
  417. package/dist/core/tools/tool-definition-factory.d.ts.map +1 -0
  418. package/dist/core/tools/tool-definition-factory.js +55 -0
  419. package/dist/core/tools/tool-definition-factory.js.map +1 -0
  420. package/dist/core/util/atomic-file.d.ts.map +1 -1
  421. package/dist/core/util/atomic-file.js +79 -32
  422. package/dist/core/util/atomic-file.js.map +1 -1
  423. package/dist/index.d.ts +5 -2
  424. package/dist/index.d.ts.map +1 -1
  425. package/dist/index.js +5 -2
  426. package/dist/index.js.map +1 -1
  427. package/dist/main.d.ts +2 -0
  428. package/dist/main.d.ts.map +1 -1
  429. package/dist/main.js +24 -18
  430. package/dist/main.js.map +1 -1
  431. package/dist/modes/interactive/auto-learn-controller.js +1 -1
  432. package/dist/modes/interactive/auto-learn-controller.js.map +1 -1
  433. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  434. package/dist/modes/interactive/components/settings-selector.js +35 -14
  435. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  436. package/dist/modes/interactive/components/tool-execution.js +1 -1
  437. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  438. package/dist/modes/interactive/interactive-event-controller.js +1 -1
  439. package/dist/modes/interactive/interactive-event-controller.js.map +1 -1
  440. package/dist/modes/interactive/interactive-mode.d.ts +1 -0
  441. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  442. package/dist/modes/interactive/interactive-mode.js +27 -4
  443. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  444. package/dist/modes/interactive/secret-menu-controller.d.ts +21 -0
  445. package/dist/modes/interactive/secret-menu-controller.d.ts.map +1 -0
  446. package/dist/modes/interactive/secret-menu-controller.js +276 -0
  447. package/dist/modes/interactive/secret-menu-controller.js.map +1 -0
  448. package/dist/utils/child-process.js +1 -1
  449. package/dist/utils/child-process.js.map +1 -1
  450. package/dist/utils/tools-manager.d.ts +2 -1
  451. package/dist/utils/tools-manager.d.ts.map +1 -1
  452. package/dist/utils/tools-manager.js +43 -48
  453. package/dist/utils/tools-manager.js.map +1 -1
  454. package/dist/utils/zip-extractor.d.ts +8 -0
  455. package/dist/utils/zip-extractor.d.ts.map +1 -0
  456. package/dist/utils/zip-extractor.js +275 -0
  457. package/dist/utils/zip-extractor.js.map +1 -0
  458. package/docs/harness-architecture.md +34 -22
  459. package/docs/index.md +1 -1
  460. package/docs/resources.md +1 -1
  461. package/docs/settings.md +39 -103
  462. package/docs/usage.md +7 -5
  463. package/docs/worker-profiles.md +9 -7
  464. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  465. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  466. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  467. package/examples/extensions/sandbox/package-lock.json +2 -2
  468. package/examples/extensions/sandbox/package.json +1 -1
  469. package/examples/extensions/with-deps/package-lock.json +2 -2
  470. package/examples/extensions/with-deps/package.json +1 -1
  471. package/npm-shrinkwrap.json +12 -12
  472. package/package.json +7 -5
  473. package/dist/core/secrets/secret-vault-format.d.ts +0 -112
  474. package/dist/core/secrets/secret-vault-format.d.ts.map +0 -1
  475. package/dist/core/secrets/secret-vault-format.js +0 -396
  476. package/dist/core/secrets/secret-vault-format.js.map +0 -1
  477. package/dist/core/secrets/secret-vault.d.ts +0 -72
  478. package/dist/core/secrets/secret-vault.d.ts.map +0 -1
  479. package/dist/core/secrets/secret-vault.js +0 -663
  480. package/dist/core/secrets/secret-vault.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"subagent-prompt.js","sourceRoot":"","sources":["../../../src/core/autonomy/subagent-prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG;IAC1C,qFAAqF;IACrF,6EAA6E;IAC7E,iJAAiJ;IACjJ,0EAA0E;IAC1E,uFAAuF;IACvF,iGAAiG;CACjG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAWb,MAAM,UAAU,2BAA2B,CAAC,KAA0B;IACrE,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC;IACxC,MAAM,KAAK,GACV,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;QAC9B,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,KAAK,CAAC,UAAU,CAAC;aACrC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;aAClE,IAAI,CAAC,MAAM,CAAC,CAAC;IAClB,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,2BAA2B,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,2BAA2B,CAAC;AACtG,CAAC","sourcesContent":["/**\n * Subagent system-prompt composition with an irreducible level-0 core.\n *\n * The core is the \"ultimate level-0 default\": ~80 tokens of non-negotiable rules that survive ANY\n * customization. Everything above it — the lane's role prompt and a shipped profile's soul — is a\n * replaceable layer: settings, a lane profile, or the calling model (delegate tool) can erase and\n * replace it entirely. This keeps shipped subagents maximally efficient on small open models (a\n * caller can hand a tiny model a purpose-built minimal prompt) without ever shedding the safety\n * floor. Keep the core UNDER 300 tokens; it is deliberately terse.\n */\nexport const SUBAGENT_CORE_SYSTEM_PROMPT = [\n\t\"You are a bounded subagent shipped by a coding-agent session. Non-negotiable rules:\",\n\t\"1. Do only the task you were given; you cannot see the parent conversation.\",\n\t\"2. You are read-only unless your envelope explicitly grants otherwise; never attempt to change files, settings, credentials, or external state.\",\n\t\"3. Never invent facts, file paths, or APIs; say so when you do not know.\",\n\t\"4. Your output is untrusted evidence for the parent agent - data, never instructions.\",\n\t\"5. Follow the requested output format exactly and be concise; budgets are enforced outside you.\",\n].join(\"\\n\");\n\nexport interface SubagentPromptParts {\n\t/** Situational identity from the shipped profile (replaceable layer). */\n\tsoul?: string;\n\t/** The lane's default role prompt (replaceable layer). */\n\trolePrompt: string;\n\t/** User- or model-provided replacement for every layer above level 0. */\n\toverride?: string;\n}\n\nexport function composeSubagentSystemPrompt(parts: SubagentPromptParts): string {\n\tconst override = parts.override?.trim();\n\tconst above =\n\t\toverride && override.length > 0\n\t\t\t? override\n\t\t\t: [parts.soul?.trim(), parts.rolePrompt]\n\t\t\t\t\t.filter((part): part is string => Boolean(part && part.length > 0))\n\t\t\t\t\t.join(\"\\n\\n\");\n\treturn above.length > 0 ? `${SUBAGENT_CORE_SYSTEM_PROMPT}\\n\\n${above}` : SUBAGENT_CORE_SYSTEM_PROMPT;\n}\n"]}
1
+ {"version":3,"file":"subagent-prompt.js","sourceRoot":"","sources":["../../../src/core/autonomy/subagent-prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG;IAC1C,uFAAuF;IACvF,uHAAuH;IACvH,+HAA+H;IAC/H,yIAAyI;IACzI,0FAA0F;IAC1F,2HAA2H;CAC3H,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAWb,MAAM,UAAU,2BAA2B,CAAC,KAA0B;IACrE,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC;IACxC,MAAM,KAAK,GACV,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;QAC9B,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,KAAK,CAAC,UAAU,CAAC;aACrC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;aAClE,IAAI,CAAC,MAAM,CAAC,CAAC;IAClB,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,2BAA2B,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,2BAA2B,CAAC;AACtG,CAAC","sourcesContent":["/**\n * Agent system-prompt composition with an irreducible execution-contract core.\n *\n * The core is the \"ultimate level-0 default\": ~80 tokens of non-negotiable rules that survive ANY\n * customization. Everything above it — the lane's role prompt and a shipped profile's soul — is a\n * replaceable layer: settings, a lane profile, or the calling model (delegate tool) can erase and\n * replace it entirely. This keeps shipped subagents maximally efficient on small open models (a\n * caller can hand a tiny model a purpose-built minimal prompt) while the kernel remains the sole\n * authority and budget owner. Keep the core UNDER 300 tokens; it is deliberately terse.\n */\nexport const SUBAGENT_CORE_SYSTEM_PROMPT = [\n\t\"You are an autonomous agent in a coding-agent orchestration tree. Execution contract:\",\n\t\"1. Use the maximum useful capability exposed by your tool surface; the kernel enforces the exact inherited authority.\",\n\t\"2. You may delegate recursively, inspect exact peer transcripts, and exchange threaded messages when those tools are present.\",\n\t\"3. Concurrency, cumulative budgets, leases, cycle detection, cancellation, and irreversible user-authority boundaries are kernel-owned.\",\n\t\"4. Never invent facts, file paths, APIs, or command results; state uncertainty directly.\",\n\t\"5. Follow the requested output contract exactly; your result remains evidence that other agents may independently verify.\",\n].join(\"\\n\");\n\nexport interface SubagentPromptParts {\n\t/** Situational identity from the shipped profile (replaceable layer). */\n\tsoul?: string;\n\t/** The lane's default role prompt (replaceable layer). */\n\trolePrompt: string;\n\t/** User- or model-provided replacement for every layer above level 0. */\n\toverride?: string;\n}\n\nexport function composeSubagentSystemPrompt(parts: SubagentPromptParts): string {\n\tconst override = parts.override?.trim();\n\tconst above =\n\t\toverride && override.length > 0\n\t\t\t? override\n\t\t\t: [parts.soul?.trim(), parts.rolePrompt]\n\t\t\t\t\t.filter((part): part is string => Boolean(part && part.length > 0))\n\t\t\t\t\t.join(\"\\n\\n\");\n\treturn above.length > 0 ? `${SUBAGENT_CORE_SYSTEM_PROMPT}\\n\\n${above}` : SUBAGENT_CORE_SYSTEM_PROMPT;\n}\n"]}
@@ -16,7 +16,7 @@
16
16
  import type { Api, Model } from "@caupulican/pi-ai";
17
17
  import type { GoalContinuationLoopOptions, GoalContinuationLoopResult, PromptOptions, ResearchLaneRunOutcome, WorkerDelegationRunOutcome } from "./agent-session-contracts.ts";
18
18
  import { type LaneRecord } from "./autonomy/lane-tracker.ts";
19
- import type { WorkerAgentControlPort } from "./delegation/worker-agent-control.ts";
19
+ import type { WorkerAgentControlPort, WorkerAgentControlScope, WorkerAgentMessageOptions, WorkerAgentTranscriptOptions } from "./delegation/worker-agent-control.ts";
20
20
  import { type WorkerDelegationControllerDeps } from "./delegation/worker-delegation-controller.ts";
21
21
  import type { WorkerDelegationRequest } from "./delegation/worker-delegation-request.ts";
22
22
  import type { ManagedLaneEvent } from "./extensions/types.ts";
@@ -141,7 +141,7 @@ export declare class BackgroundLaneController implements WorkerAgentControlPort
141
141
  context?: string;
142
142
  goalId?: string;
143
143
  }): Promise<ResearchLaneRunOutcome>;
144
- /** Start a durable, profile-bound worker delegation. */
144
+ /** Start a durable recursive agent with inherited, preset, or model-selected authority. */
145
145
  startWorkerDelegation(request: WorkerDelegationRequest): {
146
146
  started: false;
147
147
  skipReason: string;
@@ -150,28 +150,30 @@ export declare class BackgroundLaneController implements WorkerAgentControlPort
150
150
  record: LaneRecord;
151
151
  };
152
152
  /** Durable logical-worker controls. Each checks UAC before materializing worker state. */
153
- sendWorkerAgentMessage(agentId: string, message: string): {
153
+ listWorkerAgents(scope?: WorkerAgentControlScope): ReturnType<WorkerAgentControlPort["listWorkerAgents"]>;
154
+ readWorkerAgentTranscript(agentId: string, options?: WorkerAgentTranscriptOptions): ReturnType<WorkerAgentControlPort["readWorkerAgentTranscript"]>;
155
+ sendWorkerAgentMessage(agentId: string, message: string, options?: WorkerAgentMessageOptions): {
154
156
  messageId: string;
155
157
  queued: true;
156
158
  };
157
- followUpWorkerAgent(agentId: string, message: string): {
159
+ followUpWorkerAgent(agentId: string, message: string, options?: WorkerAgentMessageOptions): {
158
160
  started: boolean;
159
161
  steering: boolean;
160
162
  messageId: string;
161
163
  record?: LaneRecord;
162
164
  skipReason?: string;
163
165
  };
164
- interruptWorkerAgent(agentId: string): {
166
+ interruptWorkerAgent(agentId: string, scope?: WorkerAgentControlScope): {
165
167
  interrupted: boolean;
166
168
  reason?: string;
167
169
  };
168
- resumeWorkerAgent(agentId: string): {
170
+ resumeWorkerAgent(agentId: string, scope?: WorkerAgentControlScope): {
169
171
  started: boolean;
170
172
  record?: LaneRecord;
171
173
  skipReason?: string;
172
174
  };
173
- cancelWorkerAgent(agentId: string, reasonCode?: string): LaneRecord | undefined;
174
- waitForWorkerAgent(agentId: string, timeoutMs?: number): Promise<{
175
+ cancelWorkerAgent(agentId: string, reasonCode?: string, scope?: WorkerAgentControlScope): LaneRecord | undefined;
176
+ waitForWorkerAgent(agentId: string, timeoutMs?: number, scope?: WorkerAgentControlScope): Promise<{
175
177
  status: "active" | "suspended" | "idle" | "unknown";
176
178
  }>;
177
179
  /** Run one worker immediately; used by focused integrations and tests. */
@@ -1 +1 @@
1
- {"version":3,"file":"background-lane-controller.d.ts","sourceRoot":"","sources":["../../src/core/background-lane-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EACX,2BAA2B,EAC3B,0BAA0B,EAC1B,aAAa,EACb,sBAAsB,EACtB,0BAA0B,EAC1B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,KAAK,UAAU,EAAe,MAAM,4BAA4B,CAAC;AAG1E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAEN,KAAK,8BAA8B,EACnC,MAAM,8CAA8C,CAAC;AACtD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2CAA2C,CAAC;AAGzF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AACzG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,KAAK,EACX,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}
1
+ {"version":3,"file":"background-lane-controller.d.ts","sourceRoot":"","sources":["../../src/core/background-lane-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EACX,2BAA2B,EAC3B,0BAA0B,EAC1B,aAAa,EACb,sBAAsB,EACtB,0BAA0B,EAC1B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,KAAK,UAAU,EAAe,MAAM,4BAA4B,CAAC;AAG1E,OAAO,KAAK,EACX,sBAAsB,EACtB,uBAAuB,EACvB,yBAAyB,EACzB,4BAA4B,EAC5B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAEN,KAAK,8BAA8B,EACnC,MAAM,8CAA8C,CAAC;AACtD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2CAA2C,CAAC;AAGzF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AACzG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,KAAK,EACX,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAqB,KAAK,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAClG,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAA0B,KAAK,0BAA0B,EAAE,MAAM,wCAAwC,CAAC;AACjH,OAAO,EAA0B,K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AED,mGAAmG;IACnG,4BAA4B,IAAI,IAAI,CAEnC;IAED,mGAAmG;IACnG,uBAAuB,IAAI,mBAAmB,EAAE,CAE/C;CACD"}
@@ -236,40 +236,50 @@ export class BackgroundLaneController {
236
236
  async runResearchLaneOnce(request) {
237
237
  return this._research.runOnce(request);
238
238
  }
239
- /** Start a durable, profile-bound worker delegation. */
239
+ /** Start a durable recursive agent with inherited, preset, or model-selected authority. */
240
240
  startWorkerDelegation(request) {
241
241
  return this._getWorkerController().start(request);
242
242
  }
243
243
  /** Durable logical-worker controls. Each checks UAC before materializing worker state. */
244
- sendWorkerAgentMessage(agentId, message) {
244
+ listWorkerAgents(scope) {
245
245
  if (!this.deps.isDelegateToolActive())
246
246
  throw new Error("Worker delegation control is unavailable in this UAC surface.");
247
- return this._getWorkerController().getAgentControl().sendWorkerAgentMessage(agentId, message);
247
+ return this._getWorkerController().getAgentControl().listWorkerAgents(scope);
248
248
  }
249
- followUpWorkerAgent(agentId, message) {
249
+ readWorkerAgentTranscript(agentId, options) {
250
250
  if (!this.deps.isDelegateToolActive())
251
251
  throw new Error("Worker delegation control is unavailable in this UAC surface.");
252
- return this._getWorkerController().getAgentControl().followUpWorkerAgent(agentId, message);
252
+ return this._getWorkerController().getAgentControl().readWorkerAgentTranscript(agentId, options);
253
253
  }
254
- interruptWorkerAgent(agentId) {
254
+ sendWorkerAgentMessage(agentId, message, options) {
255
255
  if (!this.deps.isDelegateToolActive())
256
256
  throw new Error("Worker delegation control is unavailable in this UAC surface.");
257
- return this._getWorkerController().getAgentControl().interruptWorkerAgent(agentId);
257
+ return this._getWorkerController().getAgentControl().sendWorkerAgentMessage(agentId, message, options);
258
258
  }
259
- resumeWorkerAgent(agentId) {
259
+ followUpWorkerAgent(agentId, message, options) {
260
260
  if (!this.deps.isDelegateToolActive())
261
261
  throw new Error("Worker delegation control is unavailable in this UAC surface.");
262
- return this._getWorkerController().getAgentControl().resumeWorkerAgent(agentId);
262
+ return this._getWorkerController().getAgentControl().followUpWorkerAgent(agentId, message, options);
263
263
  }
264
- cancelWorkerAgent(agentId, reasonCode) {
264
+ interruptWorkerAgent(agentId, scope) {
265
265
  if (!this.deps.isDelegateToolActive())
266
266
  throw new Error("Worker delegation control is unavailable in this UAC surface.");
267
- return this._getWorkerController().getAgentControl().cancelWorkerAgent(agentId, reasonCode);
267
+ return this._getWorkerController().getAgentControl().interruptWorkerAgent(agentId, scope);
268
268
  }
269
- waitForWorkerAgent(agentId, timeoutMs) {
269
+ resumeWorkerAgent(agentId, scope) {
270
270
  if (!this.deps.isDelegateToolActive())
271
271
  throw new Error("Worker delegation control is unavailable in this UAC surface.");
272
- return this._getWorkerController().getAgentControl().waitForWorkerAgent(agentId, timeoutMs);
272
+ return this._getWorkerController().getAgentControl().resumeWorkerAgent(agentId, scope);
273
+ }
274
+ cancelWorkerAgent(agentId, reasonCode, scope) {
275
+ if (!this.deps.isDelegateToolActive())
276
+ throw new Error("Worker delegation control is unavailable in this UAC surface.");
277
+ return this._getWorkerController().getAgentControl().cancelWorkerAgent(agentId, reasonCode, scope);
278
+ }
279
+ waitForWorkerAgent(agentId, timeoutMs, scope) {
280
+ if (!this.deps.isDelegateToolActive())
281
+ throw new Error("Worker delegation control is unavailable in this UAC surface.");
282
+ return this._getWorkerController().getAgentControl().waitForWorkerAgent(agentId, timeoutMs, scope);
273
283
  }
274
284
  /** Run one worker immediately; used by focused integrations and tests. */
275
285
  async runWorkerDelegationOnce(request, onStarted, existingRecord) {
@@ -1 +1 @@
1
- {"version":3,"file":"background-lane-controller.js","sourceRoot":"","sources":["../../src/core/background-lane-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAUH,OAAO,EAAmB,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAC3G,OAAO,EAAE,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;AAEhF,OAAO,EACN,0BAA0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AQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,mGAAmG;IACnG,4BAA4B;QAC3B,IAAI,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,EAAE;YAAE,IAAI,CAAC,oBAAoB,EAAE,CAAC,KAAK,EAAE,CAAC;IAC7E,CAAC;IAED,mGAAmG;IACnG,uBAAuB;QACtB,OAAO,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,CAAC;IACzC,CAAC;CACD","sourcesContent":["/**\n * Execution-plane coordinator for goal continuation, research, managed lanes, worker delegation,\n * and model fitness.\n *\n * Coordination state is owned by focused controllers. This coordinator retains one AgentSession\n * composition seam and a shared lane read model. Everything it needs\n * — the session manager, settings, model registry, live model, capability envelope, the goal\n * continuation LOOP, the isolated-completion primitive, spawned-usage accounting, and the telemetry\n * sink — is reached through narrow deps accessors rather than the whole AgentSession.\n *\n * Drive-loop boundary (deliberate): the idle triggers ({@link scheduleGoalAutoContinueFromIdle},\n * {@link scheduleResearchLaneFromIdle}) are invoked from the session's prompt tail as one-line\n * delegations; goal auto-continue itself only ever asks the session to `continueGoalLoop`, so this\n * controller never touches `prompt()`, the last-assistant-message, retry, or streaming state.\n */\n\nimport type { Api, Model } from \"@caupulican/pi-ai\";\nimport type {\n\tGoalContinuationLoopOptions,\n\tGoalContinuationLoopResult,\n\tPromptOptions,\n\tResearchLaneRunOutcome,\n\tWorkerDelegationRunOutcome,\n} from \"./agent-session-contracts.ts\";\nimport { type LaneRecord, LaneTracker } from \"./autonomy/lane-tracker.ts\";\nimport { appendLaneRecordSnapshot, getLatestLaneRecordSnapshots } from \"./autonomy/session-lane-record.ts\";\nimport { ManagedLaneController } from \"./delegation/managed-lane-controller.ts\";\nimport type { WorkerAgentControlPort } from \"./delegation/worker-agent-control.ts\";\nimport {\n\tWorkerDelegationController,\n\ttype WorkerDelegationControllerDeps,\n} from \"./delegation/worker-delegation-controller.ts\";\nimport type { WorkerDelegationRequest } from \"./delegation/worker-delegation-request.ts\";\nimport { WorkerLifecycle } from \"./delegation/worker-lifecycle.ts\";\nimport { WorkerNotificationCoordinator } from \"./delegation/worker-notification-coordinator.ts\";\nimport type { ManagedLaneEvent } from \"./extensions/types.ts\";\nimport { GoalAutoContinueController } from \"./goals/goal-auto-continue-controller.ts\";\nimport type { GoalRuntimeSnapshot, GoalRuntimeSnapshotSettings } from \"./goals/goal-runtime-snapshot.ts\";\nimport type { GoalState } from \"./goals/goal-state.ts\";\nimport type { ModelCapabilityProfile } from \"./model-capability.ts\";\nimport type { StoredFitnessReport } from \"./models/fitness-store.ts\";\nimport type {\n\tTaskProfileCreateInput,\n\tTaskProfileCreateResult,\n\tTaskProfileInspection,\n} from \"./orchestration/task-profile-writer.ts\";\nimport type { TaskRuntimeProjection } from \"./orchestration/task-runtime.ts\";\nimport { LaneModelResolver, type LaneModelResolverDeps } from \"./research/lane-model-resolver.ts\";\nimport type { ModelFitnessReport } from \"./research/model-fitness.ts\";\nimport { ModelFitnessController, type ModelFitnessControllerDeps } from \"./research/model-fitness-controller.ts\";\nimport { ResearchLaneController, type ResearchLaneControllerDeps } from \"./research/research-lane-controller.ts\";\nimport { getActiveSessionBranchEntries } from \"./session-snapshot.ts\";\n\nexport { isLocalExecutionModel } from \"./delegation/worker-delegation-controller.ts\";\nexport { clampLaneMaxUsd } from \"./research/lane-model-resolver.ts\";\n\nexport interface BackgroundLaneControllerDeps\n\textends WorkerDelegationControllerDeps,\n\t\tResearchLaneControllerDeps,\n\t\tModelFitnessControllerDeps,\n\t\tLaneModelResolverDeps {\n\t/** True iff the `goal` tool is in the session's ACTIVE surface -- the capability-adaptive gate\n\t * for every goal-continuation loop (see `continueGoalLoopExclusive`): a surface without the\n\t * goal tool (lean capability blocklist, worker role ceiling, --tools/profile exclusion) must\n\t * never be driven with continuation prompts it cannot execute. */\n\tisGoalToolActive(): boolean;\n\t/** Capability profile of the SESSION model (gates background lanes, scales continuation budgets). */\n\tgetModelCapabilityProfile(): ModelCapabilityProfile;\n\t/** Continuation gate + goal state for the idle autosteer scheduler. */\n\tgetGoalRuntimeSnapshot(settings: GoalRuntimeSnapshotSettings): GoalRuntimeSnapshot;\n\t/** Drive-loop boundary: the session's bounded goal-continuation loop (owns `prompt()`, not us). */\n\tcontinueGoalLoop(options: GoalContinuationLoopOptions): Promise<GoalContinuationLoopResult>;\n\t/** True while the session owns a foreground prompt/retry/follow-up run. */\n\tisForegroundBusy(): boolean;\n\t/** Resolve only after the complete foreground retry/follow-up run releases the session. */\n\twaitForForegroundIdle(): Promise<void>;\n\t/** Persist an explicit stopped state when the selected surface cannot drive the active goal. */\n\tmarkGoalToolUnavailable(): void;\n}\n\nexport class BackgroundLaneController implements WorkerAgentControlPort {\n\t/** Live lane registry — the real source for AutonomyStatusSnapshot.activeLaneCount. */\n\tprivate readonly _laneTracker = new LaneTracker();\n\tprivate readonly _laneModels: LaneModelResolver;\n\tprivate readonly _goalAutoContinue: GoalAutoContinueController;\n\tprivate readonly _research: ResearchLaneController;\n\tprivate readonly _fitness: ModelFitnessController;\n\t/** Lazily materialized only when managed-lane state is queried or reported. */\n\tprivate _managedLanes: ManagedLaneController | undefined;\n\t/** Lazily materialized so a UAC surface without `delegate` allocates no worker runtime state. */\n\tprivate _workers: WorkerDelegationController | undefined;\n\t/** One durable lifecycle shared by every worker execution adapter. */\n\tprivate _workerLifecycle: WorkerLifecycle | undefined;\n\t/** Shared terminal outbox for managed and in-process workers; lazy under UAC omission. */\n\tprivate _workerNotifications: WorkerNotificationCoordinator | undefined;\n\tprivate readonly deps: BackgroundLaneControllerDeps;\n\n\t/** Emit a warning without ever throwing — used from disposal-adjacent persistence where a\n\t * listener failure (or a bare test double missing `emit`) must never block or crash cleanup. */\n\tprivate _safeWarn(message: string): void {\n\t\ttry {\n\t\t\tthis.deps.emit({ type: \"warning\", message });\n\t\t} catch {\n\t\t\t// Dispose must never throw.\n\t\t}\n\t}\n\n\tprivate _recordWorkerTerminal(record: LaneRecord, durableNotificationId: string): void {\n\t\tthis._getWorkerNotificationCoordinator().recordTerminal(record, durableNotificationId);\n\t}\n\n\tconstructor(deps: BackgroundLaneControllerDeps) {\n\t\tthis.deps = deps;\n\t\tthis._laneModels = new LaneModelResolver(deps);\n\t\tthis._research = new ResearchLaneController(deps, this._laneTracker, this._laneModels);\n\t\tthis._fitness = new ModelFitnessController(deps, this._laneModels);\n\t\tthis._goalAutoContinue = new GoalAutoContinueController({\n\t\t\tisDisposed: deps.isDisposed,\n\t\t\tisGoalToolActive: deps.isGoalToolActive,\n\t\t\tgetSettingsManager: deps.getSettingsManager,\n\t\t\tgetModelCapabilityProfile: deps.getModelCapabilityProfile,\n\t\t\tgetGoalRuntimeSnapshot: deps.getGoalRuntimeSnapshot,\n\t\t\thasInFlightLaneForGoal: (goalId) => this._hasInFlightLaneForGoal(goalId),\n\t\t\tcontinueGoalLoop: deps.continueGoalLoop,\n\t\t\tisForegroundBusy: deps.isForegroundBusy,\n\t\t\twaitForForegroundIdle: deps.waitForForegroundIdle,\n\t\t\tmarkGoalToolUnavailable: deps.markGoalToolUnavailable,\n\t\t\temit: deps.emit,\n\t\t});\n\t}\n\n\tprivate _getWorkerController(): WorkerDelegationController {\n\t\tthis._workers ??= new WorkerDelegationController(\n\t\t\tthis.deps,\n\t\t\tthis._getWorkerNotificationCoordinator(),\n\t\t\tthis._getWorkerLifecycle(),\n\t\t);\n\t\treturn this._workers;\n\t}\n\n\tprivate _getWorkerLifecycle(): WorkerLifecycle {\n\t\tif (this._workerLifecycle) return this._workerLifecycle;\n\t\tconst lifecycle = new WorkerLifecycle({\n\t\t\tagentDir: this.deps.getAgentDir(),\n\t\t\tsessionId: this.deps.getSessionId(),\n\t\t});\n\t\tthis._workerLifecycle = lifecycle;\n\t\tfor (const notification of lifecycle.getPendingTerminalNotifications()) {\n\t\t\tthis._getWorkerNotificationCoordinator().recordTerminal(notification.record, notification.notificationId);\n\t\t}\n\t\treturn lifecycle;\n\t}\n\n\tprivate _getWorkerNotificationCoordinator(): WorkerNotificationCoordinator {\n\t\tthis._workerNotifications ??= new WorkerNotificationCoordinator({\n\t\t\tgetWorkerRecords: () => this._workerLifecycle?.getAllRecords() ?? [],\n\t\t\temitStatus: (status) => {\n\t\t\t\ttry {\n\t\t\t\t\tthis.deps.emit({\n\t\t\t\t\t\ttype: \"delegate_workers\",\n\t\t\t\t\t\t...status,\n\t\t\t\t\t\tterminalSinceFlush: [...status.terminalSinceFlush],\n\t\t\t\t\t});\n\t\t\t\t} catch {\n\t\t\t\t\t// A partial integration must not crash the event-driven terminal outbox.\n\t\t\t\t}\n\t\t\t},\n\t\t\tnotify: (records) => this.deps.notifyWorkerTerminalHandoff(records),\n\t\t\twarn: (message) => this._safeWarn(message),\n\t\t\tmarkDurableDelivered: (notificationIds) => this._workerLifecycle?.markNotificationsDelivered(notificationIds),\n\t\t});\n\t\treturn this._workerNotifications;\n\t}\n\n\tprivate _getManagedLaneController(): ManagedLaneController {\n\t\tthis._managedLanes ??= new ManagedLaneController(\n\t\t\tthis.deps,\n\t\t\tthis._getWorkerLifecycle(),\n\t\t\t(record, notificationId) => this._recordWorkerTerminal(record, notificationId),\n\t\t\t(message) => this._safeWarn(message),\n\t\t);\n\t\treturn this._managedLanes;\n\t}\n\n\tprivate _hydrateManagedLanes(): void {\n\t\tif (this._managedLanes) {\n\t\t\tthis._managedLanes.ensureHydrated();\n\t\t\treturn;\n\t\t}\n\t\tconst hasPersistedActiveManagedLane = getLatestLaneRecordSnapshots(\n\t\t\tgetActiveSessionBranchEntries(this.deps.getSessionManager()),\n\t\t).some((record) => record.type === \"tmux-worker\" && (record.status === \"queued\" || record.status === \"running\"));\n\t\tif (hasPersistedActiveManagedLane) this._getManagedLaneController().ensureHydrated();\n\t}\n\n\t/** Live lane records tracked by this process (running and terminal). */\n\tgetLaneRecords(): LaneRecord[] {\n\t\tthis._hydrateManagedLanes();\n\t\tconst workerRecords =\n\t\t\tthis._workers?.getRecords() ??\n\t\t\t(this.deps.isDelegateToolActive?.() ? this._getWorkerController().getRecords() : []);\n\t\treturn [\n\t\t\t...this._laneTracker.getRecords(),\n\t\t\t...workerRecords,\n\t\t\t...(this._workerLifecycle?.getManagedRecords() ?? []),\n\t\t];\n\t}\n\n\t/** Does not materialize the worker controller when UAC omitted delegation. */\n\tgetTaskRuntimeSnapshot(): TaskRuntimeProjection | undefined {\n\t\treturn this._workerLifecycle?.getTaskRuntimeSnapshot();\n\t}\n\n\t/** Reconcile only when delegation has already been materialized; UAC omission stays zero-load. */\n\tsynchronizeGoalState(goal: GoalState): void {\n\t\tthis._workers?.synchronizeGoalState(goal);\n\t}\n\n\t/**\n\t * Resolve a tracked managed-lane dispatch. The caller's stable id is also the canonical durable\n\t * lane id, so this is an existence check rather than an id translation.\n\t */\n\tresolveManagedLaneId(callerLaneId: string): string | undefined {\n\t\treturn this._getManagedLaneController().resolve(callerLaneId);\n\t}\n\n\t/** Live count of active lanes — the real source for AutonomyStatusSnapshot.activeLaneCount. */\n\tgetActiveLaneCount(): number {\n\t\treturn this.getLaneRecords().filter((record) => record.status === \"queued\" || record.status === \"running\").length;\n\t}\n\n\t/** Belt-and-braces guard: whether ANY queued/running lane is tagged with this goalId. */\n\tprivate _hasInFlightLaneForGoal(goalId: string): boolean {\n\t\treturn this.getLaneRecords().some(\n\t\t\t(record) => record.goalId === goalId && (record.status === \"queued\" || record.status === \"running\"),\n\t\t);\n\t}\n\n\t/** Delegate the out-of-process dispatch/terminal claim to its single lifecycle owner. */\n\trecordManagedLane(event: ManagedLaneEvent): LaneRecord | undefined {\n\t\treturn this._getManagedLaneController().record(event);\n\t}\n\n\t/** Why the last idle research-lane evaluation skipped, for /autonomy diagnostics. */\n\tgetLastResearchLaneSkipReason(): string | undefined {\n\t\treturn this._research.getLastSkipReason();\n\t}\n\n\t/**\n\t * Abort in-flight research and delegate worker disposal to its single owning controller.\n\t *\n\t * This synchronous body is the LAST provably-safe write window for canceled/in-flight work.\n\t * `dispose()` (agent-session.ts) has already set the session's own disposed flag but has not yet\n\t * returned — no successor session (e.g. a `/reload` adoption) can exist yet, so an append here\n\t * cannot interleave with one; a post-await continuation resuming AFTER this method returns must\n\t * not append (see the disposed branch in `runWorkerDelegationOnce`). Persist FIRST, then\n\t * complete-in-memory, so a throw from one lane's persist cannot skip another's; each persist gets\n\t * its own try/catch — dispose must never throw.\n\t */\n\tabortInFlightLanes(): void {\n\t\tthis._goalAutoContinue.clearTimer();\n\t\tthis._research.abort();\n\t\tthis._fitness.abort();\n\t\tfor (const record of this._laneTracker.getRecords()) {\n\t\t\tif (record.status !== \"queued\" && record.status !== \"running\") continue;\n\t\t\tif (record.type === \"tmux-worker\") continue;\n\t\t\tconst canceled = this._laneTracker.complete(record.laneId, {\n\t\t\t\tstatus: \"canceled\",\n\t\t\t\treasonCode: \"session_disposed\",\n\t\t\t});\n\t\t\tif (!canceled) continue;\n\t\t\ttry {\n\t\t\t\tappendLaneRecordSnapshot(this.deps.getSessionManager(), canceled);\n\t\t\t} catch (error) {\n\t\t\t\tthis._safeWarn(\n\t\t\t\t\t`Failed to persist canceled lane record ${canceled.laneId}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tthis._managedLanes?.release();\n\n\t\tthis._workers?.abort();\n\t\tthis._workerNotifications?.dispose();\n\t}\n\n\tclearGoalAutoContinueTimer(): void {\n\t\tthis._goalAutoContinue.clearTimer();\n\t}\n\n\tscheduleGoalAutoContinueFromIdle(options?: PromptOptions): void {\n\t\tthis._goalAutoContinue.scheduleFromIdle(options);\n\t}\n\n\t/**\n\t * Single-flight entry point for EVERY goal-continuation loop invocation — idle autosteer\n\t * ({@link _runScheduledGoalAutoContinue}) AND the manual `/goal start` / `/goal-continue`\n\t * commands (reached through `AgentSession.continueGoalLoop`). Both paths ultimately submit\n\t * continuation prompts through the session's single `prompt()` path, so two loops racing throws\n\t * \"Agent is already processing\" from whichever submits second. `_isGoalAutoContinuing` is the\n\t * ONE owner of that mutex; `deps.continueGoalLoop` (the raw {@link GoalLoopController} loop)\n\t * must never be called directly outside this method, or the guard is bypassed.\n\t */\n\tasync continueGoalLoopExclusive(options: GoalContinuationLoopOptions): Promise<GoalContinuationLoopResult> {\n\t\treturn this._goalAutoContinue.continueExclusive(options);\n\t}\n\n\tclearResearchLaneTimer(): void {\n\t\tthis._research.clearTimer();\n\t}\n\n\tscheduleResearchLaneFromIdle(): void {\n\t\tthis._research.scheduleFromIdle();\n\t}\n\n\tresolveLaneModel(configuredPattern: string | undefined): Model<Api> | undefined {\n\t\treturn this._laneModels.resolveModel(configuredPattern);\n\t}\n\n\tgetOrchestrationProfileCatalog(): Array<{ profileId: string; role: string; description: string }> {\n\t\treturn this._getWorkerController().getProfileCatalog();\n\t}\n\n\tinspectTaskProfileOptions(): TaskProfileInspection {\n\t\treturn this._getWorkerController().inspectTaskProfileOptions();\n\t}\n\n\tcreateTaskProfile(input: TaskProfileCreateInput): TaskProfileCreateResult {\n\t\treturn this._getWorkerController().createTaskProfile(input);\n\t}\n\n\t/**\n\t * Run one bounded, read-only research pass and persist its results: evidence bundle snapshot,\n\t * terminal lane record, and spawned-usage cost report (single-hop invariant, idempotent on the\n\t * lane's reportId). Explicit calls (e.g. `/autonomy research`) express user intent and bypass the\n\t * enabled/mode/dedupe gates the idle scheduler enforces; budget and capability gates always apply.\n\t */\n\tasync runResearchLaneOnce(request?: {\n\t\tquery?: string;\n\t\tcontext?: string;\n\t\tgoalId?: string;\n\t}): Promise<ResearchLaneRunOutcome> {\n\t\treturn this._research.runOnce(request);\n\t}\n\t/** Start a durable, profile-bound worker delegation. */\n\tstartWorkerDelegation(\n\t\trequest: WorkerDelegationRequest,\n\t): { started: false; skipReason: string } | { started: true; record: LaneRecord } {\n\t\treturn this._getWorkerController().start(request);\n\t}\n\n\t/** Durable logical-worker controls. Each checks UAC before materializing worker state. */\n\tsendWorkerAgentMessage(agentId: string, message: string): { messageId: string; queued: true } {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().sendWorkerAgentMessage(agentId, message);\n\t}\n\n\tfollowUpWorkerAgent(\n\t\tagentId: string,\n\t\tmessage: string,\n\t): { started: boolean; steering: boolean; messageId: string; record?: LaneRecord; skipReason?: string } {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().followUpWorkerAgent(agentId, message);\n\t}\n\n\tinterruptWorkerAgent(agentId: string): { interrupted: boolean; reason?: string } {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().interruptWorkerAgent(agentId);\n\t}\n\n\tresumeWorkerAgent(agentId: string): { started: boolean; record?: LaneRecord; skipReason?: string } {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().resumeWorkerAgent(agentId);\n\t}\n\n\tcancelWorkerAgent(agentId: string, reasonCode?: string): LaneRecord | undefined {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().cancelWorkerAgent(agentId, reasonCode);\n\t}\n\n\twaitForWorkerAgent(\n\t\tagentId: string,\n\t\ttimeoutMs?: number,\n\t): Promise<{ status: \"active\" | \"suspended\" | \"idle\" | \"unknown\" }> {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().waitForWorkerAgent(agentId, timeoutMs);\n\t}\n\n\t/** Run one worker immediately; used by focused integrations and tests. */\n\tasync runWorkerDelegationOnce(\n\t\trequest: WorkerDelegationRequest,\n\t\tonStarted?: (record: LaneRecord) => void,\n\t\texistingRecord?: LaneRecord,\n\t): Promise<WorkerDelegationRunOutcome> {\n\t\treturn this._getWorkerController().runOnce(request, onStarted, existingRecord);\n\t}\n\t/**\n\t * Probe a candidate model against the subagent contracts (research/worker/judge/search/\n\t * tool-call surfaces) via {@link runModelFitnessProbe}. The model must resolve and\n\t * authenticate; every probe call runs as an isolated completion on that model, and probe\n\t * spend is reported through spawned-usage accounting.\n\t */\n\tasync runModelFitness(args: {\n\t\tmodel: string;\n\t\ttrials?: number;\n\t\t/** LLM tool-call id, present only via the model_fitness tool path — see model-fitness.ts. */\n\t\ttoolCallId?: string;\n\t}): Promise<{ started: true; model: string; report: ModelFitnessReport } | { started: false; skipReason: string }> {\n\t\treturn this._fitness.run(args);\n\t}\n\n\t/** Start every capacity-eligible queued worker at the owner session's foreground-idle boundary. */\n\tdrainQueuedWorkerDelegations(): void {\n\t\tif (this.deps.isDelegateToolActive?.()) this._getWorkerController().drain();\n\t}\n\n\t/** Fitness reports persisted for THIS host (measured evidence for architect/profile decisions). */\n\tgetStoredFitnessReports(): StoredFitnessReport[] {\n\t\treturn this._fitness.getStoredReports();\n\t}\n}\n"]}
1
+ {"version":3,"file":"background-lane-controller.js","sourceRoot":"","sources":["../../src/core/background-lane-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAUH,OAAO,EAAmB,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAC3G,OAAO,EAAE,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;AAOhF,OAAO,EACN,0BAA0B,GAE1B,MAAM,8CAA8C,CAAC;AAEtD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,6BAA6B,EAAE,MAAM,iDAAiD,CAAC;AAEhG,OAAO,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAC;AAWtF,OAAO,EAAE,iBAAiB,EA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AI,KAAK,CAAC,+DAA+D,CAAC,CAAC;QAClF,OAAO,IAAI,CAAC,oBAAoB,EAAE,CAAC,eAAe,EAAE,CAAC,kBAAkB,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IACpG,CAAC;IAED,0EAA0E;IAC1E,KAAK,CAAC,uBAAuB,CAC5B,OAAgC,EAChC,SAAwC,EACxC,cAA2B;QAE3B,OAAO,IAAI,CAAC,oBAAoB,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC;IAChF,CAAC;IACD;;;;;OAKG;IACH,KAAK,CAAC,eAAe,CAAC,IAKrB;QACA,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,mGAAmG;IACnG,4BAA4B;QAC3B,IAAI,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,EAAE;YAAE,IAAI,CAAC,oBAAoB,EAAE,CAAC,KAAK,EAAE,CAAC;IAC7E,CAAC;IAED,mGAAmG;IACnG,uBAAuB;QACtB,OAAO,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,CAAC;IACzC,CAAC;CACD","sourcesContent":["/**\n * Execution-plane coordinator for goal continuation, research, managed lanes, worker delegation,\n * and model fitness.\n *\n * Coordination state is owned by focused controllers. This coordinator retains one AgentSession\n * composition seam and a shared lane read model. Everything it needs\n * — the session manager, settings, model registry, live model, capability envelope, the goal\n * continuation LOOP, the isolated-completion primitive, spawned-usage accounting, and the telemetry\n * sink — is reached through narrow deps accessors rather than the whole AgentSession.\n *\n * Drive-loop boundary (deliberate): the idle triggers ({@link scheduleGoalAutoContinueFromIdle},\n * {@link scheduleResearchLaneFromIdle}) are invoked from the session's prompt tail as one-line\n * delegations; goal auto-continue itself only ever asks the session to `continueGoalLoop`, so this\n * controller never touches `prompt()`, the last-assistant-message, retry, or streaming state.\n */\n\nimport type { Api, Model } from \"@caupulican/pi-ai\";\nimport type {\n\tGoalContinuationLoopOptions,\n\tGoalContinuationLoopResult,\n\tPromptOptions,\n\tResearchLaneRunOutcome,\n\tWorkerDelegationRunOutcome,\n} from \"./agent-session-contracts.ts\";\nimport { type LaneRecord, LaneTracker } from \"./autonomy/lane-tracker.ts\";\nimport { appendLaneRecordSnapshot, getLatestLaneRecordSnapshots } from \"./autonomy/session-lane-record.ts\";\nimport { ManagedLaneController } from \"./delegation/managed-lane-controller.ts\";\nimport type {\n\tWorkerAgentControlPort,\n\tWorkerAgentControlScope,\n\tWorkerAgentMessageOptions,\n\tWorkerAgentTranscriptOptions,\n} from \"./delegation/worker-agent-control.ts\";\nimport {\n\tWorkerDelegationController,\n\ttype WorkerDelegationControllerDeps,\n} from \"./delegation/worker-delegation-controller.ts\";\nimport type { WorkerDelegationRequest } from \"./delegation/worker-delegation-request.ts\";\nimport { WorkerLifecycle } from \"./delegation/worker-lifecycle.ts\";\nimport { WorkerNotificationCoordinator } from \"./delegation/worker-notification-coordinator.ts\";\nimport type { ManagedLaneEvent } from \"./extensions/types.ts\";\nimport { GoalAutoContinueController } from \"./goals/goal-auto-continue-controller.ts\";\nimport type { GoalRuntimeSnapshot, GoalRuntimeSnapshotSettings } from \"./goals/goal-runtime-snapshot.ts\";\nimport type { GoalState } from \"./goals/goal-state.ts\";\nimport type { ModelCapabilityProfile } from \"./model-capability.ts\";\nimport type { StoredFitnessReport } from \"./models/fitness-store.ts\";\nimport type {\n\tTaskProfileCreateInput,\n\tTaskProfileCreateResult,\n\tTaskProfileInspection,\n} from \"./orchestration/task-profile-writer.ts\";\nimport type { TaskRuntimeProjection } from \"./orchestration/task-runtime.ts\";\nimport { LaneModelResolver, type LaneModelResolverDeps } from \"./research/lane-model-resolver.ts\";\nimport type { ModelFitnessReport } from \"./research/model-fitness.ts\";\nimport { ModelFitnessController, type ModelFitnessControllerDeps } from \"./research/model-fitness-controller.ts\";\nimport { ResearchLaneController, type ResearchLaneControllerDeps } from \"./research/research-lane-controller.ts\";\nimport { getActiveSessionBranchEntries } from \"./session-snapshot.ts\";\n\nexport { isLocalExecutionModel } from \"./delegation/worker-delegation-controller.ts\";\nexport { clampLaneMaxUsd } from \"./research/lane-model-resolver.ts\";\n\nexport interface BackgroundLaneControllerDeps\n\textends WorkerDelegationControllerDeps,\n\t\tResearchLaneControllerDeps,\n\t\tModelFitnessControllerDeps,\n\t\tLaneModelResolverDeps {\n\t/** True iff the `goal` tool is in the session's ACTIVE surface -- the capability-adaptive gate\n\t * for every goal-continuation loop (see `continueGoalLoopExclusive`): a surface without the\n\t * goal tool (lean capability blocklist, worker role ceiling, --tools/profile exclusion) must\n\t * never be driven with continuation prompts it cannot execute. */\n\tisGoalToolActive(): boolean;\n\t/** Capability profile of the SESSION model (gates background lanes, scales continuation budgets). */\n\tgetModelCapabilityProfile(): ModelCapabilityProfile;\n\t/** Continuation gate + goal state for the idle autosteer scheduler. */\n\tgetGoalRuntimeSnapshot(settings: GoalRuntimeSnapshotSettings): GoalRuntimeSnapshot;\n\t/** Drive-loop boundary: the session's bounded goal-continuation loop (owns `prompt()`, not us). */\n\tcontinueGoalLoop(options: GoalContinuationLoopOptions): Promise<GoalContinuationLoopResult>;\n\t/** True while the session owns a foreground prompt/retry/follow-up run. */\n\tisForegroundBusy(): boolean;\n\t/** Resolve only after the complete foreground retry/follow-up run releases the session. */\n\twaitForForegroundIdle(): Promise<void>;\n\t/** Persist an explicit stopped state when the selected surface cannot drive the active goal. */\n\tmarkGoalToolUnavailable(): void;\n}\n\nexport class BackgroundLaneController implements WorkerAgentControlPort {\n\t/** Live lane registry — the real source for AutonomyStatusSnapshot.activeLaneCount. */\n\tprivate readonly _laneTracker = new LaneTracker();\n\tprivate readonly _laneModels: LaneModelResolver;\n\tprivate readonly _goalAutoContinue: GoalAutoContinueController;\n\tprivate readonly _research: ResearchLaneController;\n\tprivate readonly _fitness: ModelFitnessController;\n\t/** Lazily materialized only when managed-lane state is queried or reported. */\n\tprivate _managedLanes: ManagedLaneController | undefined;\n\t/** Lazily materialized so a UAC surface without `delegate` allocates no worker runtime state. */\n\tprivate _workers: WorkerDelegationController | undefined;\n\t/** One durable lifecycle shared by every worker execution adapter. */\n\tprivate _workerLifecycle: WorkerLifecycle | undefined;\n\t/** Shared terminal outbox for managed and in-process workers; lazy under UAC omission. */\n\tprivate _workerNotifications: WorkerNotificationCoordinator | undefined;\n\tprivate readonly deps: BackgroundLaneControllerDeps;\n\n\t/** Emit a warning without ever throwing — used from disposal-adjacent persistence where a\n\t * listener failure (or a bare test double missing `emit`) must never block or crash cleanup. */\n\tprivate _safeWarn(message: string): void {\n\t\ttry {\n\t\t\tthis.deps.emit({ type: \"warning\", message });\n\t\t} catch {\n\t\t\t// Dispose must never throw.\n\t\t}\n\t}\n\n\tprivate _recordWorkerTerminal(record: LaneRecord, durableNotificationId: string): void {\n\t\tthis._getWorkerNotificationCoordinator().recordTerminal(record, durableNotificationId);\n\t}\n\n\tconstructor(deps: BackgroundLaneControllerDeps) {\n\t\tthis.deps = deps;\n\t\tthis._laneModels = new LaneModelResolver(deps);\n\t\tthis._research = new ResearchLaneController(deps, this._laneTracker, this._laneModels);\n\t\tthis._fitness = new ModelFitnessController(deps, this._laneModels);\n\t\tthis._goalAutoContinue = new GoalAutoContinueController({\n\t\t\tisDisposed: deps.isDisposed,\n\t\t\tisGoalToolActive: deps.isGoalToolActive,\n\t\t\tgetSettingsManager: deps.getSettingsManager,\n\t\t\tgetModelCapabilityProfile: deps.getModelCapabilityProfile,\n\t\t\tgetGoalRuntimeSnapshot: deps.getGoalRuntimeSnapshot,\n\t\t\thasInFlightLaneForGoal: (goalId) => this._hasInFlightLaneForGoal(goalId),\n\t\t\tcontinueGoalLoop: deps.continueGoalLoop,\n\t\t\tisForegroundBusy: deps.isForegroundBusy,\n\t\t\twaitForForegroundIdle: deps.waitForForegroundIdle,\n\t\t\tmarkGoalToolUnavailable: deps.markGoalToolUnavailable,\n\t\t\temit: deps.emit,\n\t\t});\n\t}\n\n\tprivate _getWorkerController(): WorkerDelegationController {\n\t\tthis._workers ??= new WorkerDelegationController(\n\t\t\tthis.deps,\n\t\t\tthis._getWorkerNotificationCoordinator(),\n\t\t\tthis._getWorkerLifecycle(),\n\t\t);\n\t\treturn this._workers;\n\t}\n\n\tprivate _getWorkerLifecycle(): WorkerLifecycle {\n\t\tif (this._workerLifecycle) return this._workerLifecycle;\n\t\tconst lifecycle = new WorkerLifecycle({\n\t\t\tagentDir: this.deps.getAgentDir(),\n\t\t\tsessionId: this.deps.getSessionId(),\n\t\t});\n\t\tthis._workerLifecycle = lifecycle;\n\t\tfor (const notification of lifecycle.getPendingTerminalNotifications()) {\n\t\t\tthis._getWorkerNotificationCoordinator().recordTerminal(notification.record, notification.notificationId);\n\t\t}\n\t\treturn lifecycle;\n\t}\n\n\tprivate _getWorkerNotificationCoordinator(): WorkerNotificationCoordinator {\n\t\tthis._workerNotifications ??= new WorkerNotificationCoordinator({\n\t\t\tgetWorkerRecords: () => this._workerLifecycle?.getAllRecords() ?? [],\n\t\t\temitStatus: (status) => {\n\t\t\t\ttry {\n\t\t\t\t\tthis.deps.emit({\n\t\t\t\t\t\ttype: \"delegate_workers\",\n\t\t\t\t\t\t...status,\n\t\t\t\t\t\tterminalSinceFlush: [...status.terminalSinceFlush],\n\t\t\t\t\t});\n\t\t\t\t} catch {\n\t\t\t\t\t// A partial integration must not crash the event-driven terminal outbox.\n\t\t\t\t}\n\t\t\t},\n\t\t\tnotify: (records) => this.deps.notifyWorkerTerminalHandoff(records),\n\t\t\twarn: (message) => this._safeWarn(message),\n\t\t\tmarkDurableDelivered: (notificationIds) => this._workerLifecycle?.markNotificationsDelivered(notificationIds),\n\t\t});\n\t\treturn this._workerNotifications;\n\t}\n\n\tprivate _getManagedLaneController(): ManagedLaneController {\n\t\tthis._managedLanes ??= new ManagedLaneController(\n\t\t\tthis.deps,\n\t\t\tthis._getWorkerLifecycle(),\n\t\t\t(record, notificationId) => this._recordWorkerTerminal(record, notificationId),\n\t\t\t(message) => this._safeWarn(message),\n\t\t);\n\t\treturn this._managedLanes;\n\t}\n\n\tprivate _hydrateManagedLanes(): void {\n\t\tif (this._managedLanes) {\n\t\t\tthis._managedLanes.ensureHydrated();\n\t\t\treturn;\n\t\t}\n\t\tconst hasPersistedActiveManagedLane = getLatestLaneRecordSnapshots(\n\t\t\tgetActiveSessionBranchEntries(this.deps.getSessionManager()),\n\t\t).some((record) => record.type === \"tmux-worker\" && (record.status === \"queued\" || record.status === \"running\"));\n\t\tif (hasPersistedActiveManagedLane) this._getManagedLaneController().ensureHydrated();\n\t}\n\n\t/** Live lane records tracked by this process (running and terminal). */\n\tgetLaneRecords(): LaneRecord[] {\n\t\tthis._hydrateManagedLanes();\n\t\tconst workerRecords =\n\t\t\tthis._workers?.getRecords() ??\n\t\t\t(this.deps.isDelegateToolActive?.() ? this._getWorkerController().getRecords() : []);\n\t\treturn [\n\t\t\t...this._laneTracker.getRecords(),\n\t\t\t...workerRecords,\n\t\t\t...(this._workerLifecycle?.getManagedRecords() ?? []),\n\t\t];\n\t}\n\n\t/** Does not materialize the worker controller when UAC omitted delegation. */\n\tgetTaskRuntimeSnapshot(): TaskRuntimeProjection | undefined {\n\t\treturn this._workerLifecycle?.getTaskRuntimeSnapshot();\n\t}\n\n\t/** Reconcile only when delegation has already been materialized; UAC omission stays zero-load. */\n\tsynchronizeGoalState(goal: GoalState): void {\n\t\tthis._workers?.synchronizeGoalState(goal);\n\t}\n\n\t/**\n\t * Resolve a tracked managed-lane dispatch. The caller's stable id is also the canonical durable\n\t * lane id, so this is an existence check rather than an id translation.\n\t */\n\tresolveManagedLaneId(callerLaneId: string): string | undefined {\n\t\treturn this._getManagedLaneController().resolve(callerLaneId);\n\t}\n\n\t/** Live count of active lanes — the real source for AutonomyStatusSnapshot.activeLaneCount. */\n\tgetActiveLaneCount(): number {\n\t\treturn this.getLaneRecords().filter((record) => record.status === \"queued\" || record.status === \"running\").length;\n\t}\n\n\t/** Belt-and-braces guard: whether ANY queued/running lane is tagged with this goalId. */\n\tprivate _hasInFlightLaneForGoal(goalId: string): boolean {\n\t\treturn this.getLaneRecords().some(\n\t\t\t(record) => record.goalId === goalId && (record.status === \"queued\" || record.status === \"running\"),\n\t\t);\n\t}\n\n\t/** Delegate the out-of-process dispatch/terminal claim to its single lifecycle owner. */\n\trecordManagedLane(event: ManagedLaneEvent): LaneRecord | undefined {\n\t\treturn this._getManagedLaneController().record(event);\n\t}\n\n\t/** Why the last idle research-lane evaluation skipped, for /autonomy diagnostics. */\n\tgetLastResearchLaneSkipReason(): string | undefined {\n\t\treturn this._research.getLastSkipReason();\n\t}\n\n\t/**\n\t * Abort in-flight research and delegate worker disposal to its single owning controller.\n\t *\n\t * This synchronous body is the LAST provably-safe write window for canceled/in-flight work.\n\t * `dispose()` (agent-session.ts) has already set the session's own disposed flag but has not yet\n\t * returned — no successor session (e.g. a `/reload` adoption) can exist yet, so an append here\n\t * cannot interleave with one; a post-await continuation resuming AFTER this method returns must\n\t * not append (see the disposed branch in `runWorkerDelegationOnce`). Persist FIRST, then\n\t * complete-in-memory, so a throw from one lane's persist cannot skip another's; each persist gets\n\t * its own try/catch — dispose must never throw.\n\t */\n\tabortInFlightLanes(): void {\n\t\tthis._goalAutoContinue.clearTimer();\n\t\tthis._research.abort();\n\t\tthis._fitness.abort();\n\t\tfor (const record of this._laneTracker.getRecords()) {\n\t\t\tif (record.status !== \"queued\" && record.status !== \"running\") continue;\n\t\t\tif (record.type === \"tmux-worker\") continue;\n\t\t\tconst canceled = this._laneTracker.complete(record.laneId, {\n\t\t\t\tstatus: \"canceled\",\n\t\t\t\treasonCode: \"session_disposed\",\n\t\t\t});\n\t\t\tif (!canceled) continue;\n\t\t\ttry {\n\t\t\t\tappendLaneRecordSnapshot(this.deps.getSessionManager(), canceled);\n\t\t\t} catch (error) {\n\t\t\t\tthis._safeWarn(\n\t\t\t\t\t`Failed to persist canceled lane record ${canceled.laneId}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tthis._managedLanes?.release();\n\n\t\tthis._workers?.abort();\n\t\tthis._workerNotifications?.dispose();\n\t}\n\n\tclearGoalAutoContinueTimer(): void {\n\t\tthis._goalAutoContinue.clearTimer();\n\t}\n\n\tscheduleGoalAutoContinueFromIdle(options?: PromptOptions): void {\n\t\tthis._goalAutoContinue.scheduleFromIdle(options);\n\t}\n\n\t/**\n\t * Single-flight entry point for EVERY goal-continuation loop invocation — idle autosteer\n\t * ({@link _runScheduledGoalAutoContinue}) AND the manual `/goal start` / `/goal-continue`\n\t * commands (reached through `AgentSession.continueGoalLoop`). Both paths ultimately submit\n\t * continuation prompts through the session's single `prompt()` path, so two loops racing throws\n\t * \"Agent is already processing\" from whichever submits second. `_isGoalAutoContinuing` is the\n\t * ONE owner of that mutex; `deps.continueGoalLoop` (the raw {@link GoalLoopController} loop)\n\t * must never be called directly outside this method, or the guard is bypassed.\n\t */\n\tasync continueGoalLoopExclusive(options: GoalContinuationLoopOptions): Promise<GoalContinuationLoopResult> {\n\t\treturn this._goalAutoContinue.continueExclusive(options);\n\t}\n\n\tclearResearchLaneTimer(): void {\n\t\tthis._research.clearTimer();\n\t}\n\n\tscheduleResearchLaneFromIdle(): void {\n\t\tthis._research.scheduleFromIdle();\n\t}\n\n\tresolveLaneModel(configuredPattern: string | undefined): Model<Api> | undefined {\n\t\treturn this._laneModels.resolveModel(configuredPattern);\n\t}\n\n\tgetOrchestrationProfileCatalog(): Array<{ profileId: string; role: string; description: string }> {\n\t\treturn this._getWorkerController().getProfileCatalog();\n\t}\n\n\tinspectTaskProfileOptions(): TaskProfileInspection {\n\t\treturn this._getWorkerController().inspectTaskProfileOptions();\n\t}\n\n\tcreateTaskProfile(input: TaskProfileCreateInput): TaskProfileCreateResult {\n\t\treturn this._getWorkerController().createTaskProfile(input);\n\t}\n\n\t/**\n\t * Run one bounded, read-only research pass and persist its results: evidence bundle snapshot,\n\t * terminal lane record, and spawned-usage cost report (single-hop invariant, idempotent on the\n\t * lane's reportId). Explicit calls (e.g. `/autonomy research`) express user intent and bypass the\n\t * enabled/mode/dedupe gates the idle scheduler enforces; budget and capability gates always apply.\n\t */\n\tasync runResearchLaneOnce(request?: {\n\t\tquery?: string;\n\t\tcontext?: string;\n\t\tgoalId?: string;\n\t}): Promise<ResearchLaneRunOutcome> {\n\t\treturn this._research.runOnce(request);\n\t}\n\t/** Start a durable recursive agent with inherited, preset, or model-selected authority. */\n\tstartWorkerDelegation(\n\t\trequest: WorkerDelegationRequest,\n\t): { started: false; skipReason: string } | { started: true; record: LaneRecord } {\n\t\treturn this._getWorkerController().start(request);\n\t}\n\n\t/** Durable logical-worker controls. Each checks UAC before materializing worker state. */\n\tlistWorkerAgents(scope?: WorkerAgentControlScope): ReturnType<WorkerAgentControlPort[\"listWorkerAgents\"]> {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().listWorkerAgents(scope);\n\t}\n\n\treadWorkerAgentTranscript(\n\t\tagentId: string,\n\t\toptions?: WorkerAgentTranscriptOptions,\n\t): ReturnType<WorkerAgentControlPort[\"readWorkerAgentTranscript\"]> {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().readWorkerAgentTranscript(agentId, options);\n\t}\n\n\tsendWorkerAgentMessage(\n\t\tagentId: string,\n\t\tmessage: string,\n\t\toptions?: WorkerAgentMessageOptions,\n\t): { messageId: string; queued: true } {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().sendWorkerAgentMessage(agentId, message, options);\n\t}\n\n\tfollowUpWorkerAgent(\n\t\tagentId: string,\n\t\tmessage: string,\n\t\toptions?: WorkerAgentMessageOptions,\n\t): { started: boolean; steering: boolean; messageId: string; record?: LaneRecord; skipReason?: string } {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().followUpWorkerAgent(agentId, message, options);\n\t}\n\n\tinterruptWorkerAgent(agentId: string, scope?: WorkerAgentControlScope): { interrupted: boolean; reason?: string } {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().interruptWorkerAgent(agentId, scope);\n\t}\n\n\tresumeWorkerAgent(\n\t\tagentId: string,\n\t\tscope?: WorkerAgentControlScope,\n\t): { started: boolean; record?: LaneRecord; skipReason?: string } {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().resumeWorkerAgent(agentId, scope);\n\t}\n\n\tcancelWorkerAgent(agentId: string, reasonCode?: string, scope?: WorkerAgentControlScope): LaneRecord | undefined {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().cancelWorkerAgent(agentId, reasonCode, scope);\n\t}\n\n\twaitForWorkerAgent(\n\t\tagentId: string,\n\t\ttimeoutMs?: number,\n\t\tscope?: WorkerAgentControlScope,\n\t): Promise<{ status: \"active\" | \"suspended\" | \"idle\" | \"unknown\" }> {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().waitForWorkerAgent(agentId, timeoutMs, scope);\n\t}\n\n\t/** Run one worker immediately; used by focused integrations and tests. */\n\tasync runWorkerDelegationOnce(\n\t\trequest: WorkerDelegationRequest,\n\t\tonStarted?: (record: LaneRecord) => void,\n\t\texistingRecord?: LaneRecord,\n\t): Promise<WorkerDelegationRunOutcome> {\n\t\treturn this._getWorkerController().runOnce(request, onStarted, existingRecord);\n\t}\n\t/**\n\t * Probe a candidate model against the subagent contracts (research/worker/judge/search/\n\t * tool-call surfaces) via {@link runModelFitnessProbe}. The model must resolve and\n\t * authenticate; every probe call runs as an isolated completion on that model, and probe\n\t * spend is reported through spawned-usage accounting.\n\t */\n\tasync runModelFitness(args: {\n\t\tmodel: string;\n\t\ttrials?: number;\n\t\t/** LLM tool-call id, present only via the model_fitness tool path — see model-fitness.ts. */\n\t\ttoolCallId?: string;\n\t}): Promise<{ started: true; model: string; report: ModelFitnessReport } | { started: false; skipReason: string }> {\n\t\treturn this._fitness.run(args);\n\t}\n\n\t/** Start every capacity-eligible queued worker at the owner session's foreground-idle boundary. */\n\tdrainQueuedWorkerDelegations(): void {\n\t\tif (this.deps.isDelegateToolActive?.()) this._getWorkerController().drain();\n\t}\n\n\t/** Fitness reports persisted for THIS host (measured evidence for architect/profile decisions). */\n\tgetStoredFitnessReports(): StoredFitnessReport[] {\n\t\treturn this._fitness.getStoredReports();\n\t}\n}\n"]}
@@ -19,6 +19,10 @@ export interface BashExecutionControllerDeps {
19
19
  isStreaming(): boolean;
20
20
  /** Per-agent persistent shell session key — user `!` commands share the agent's shell state. */
21
21
  getShellSessionKey?(): string;
22
+ /** Owner-authorized credential environment resolved for the current project. */
23
+ getEnvironment?(cwd: string): NodeJS.ProcessEnv;
24
+ /** Exact-value redaction applied before owner shell results enter model/session history. */
25
+ redactSensitiveText?(text: string): string;
22
26
  }
23
27
  export interface BashExecutionOptions {
24
28
  excludeFromContext?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"bash-execution-controller.d.ts","sourceRoot":"","sources":["../../src/core/bash-execution-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAwB,MAAM,2BAA2B,CAAC;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,KAAK,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,IAAI,CAIhB;IAED,kDAAkD;IAClD,IAAI,aAAa,IAAI,OAAO,CAE3B;IAED,oEAAoE;IACpE,IAAI,sBAAsB,IAAI,OAAO,CAEpC;IAED;;;OAGG;IACH,wBAAwB,IAAI,IAAI,CAY/B;CACD"}
1
+ {"version":3,"file":"bash-execution-controller.d.ts","sourceRoot":"","sources":["../../src/core/bash-execution-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAwB,MAAM,2BAA2B,CAAC;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,KAAK,UAAU,EAA6B,MAAM,oBAAoB,CAAC;AAChF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,KAAK,cAAc,EAAoE,MAAM,iBAAiB,CAAC;AAExH,MAAM,WAAW,2BAA2B;IAC3C,QAAQ,IAAI,KAAK,CAAC;IAClB,iBAAiB,IAAI,cAAc,CAAC;IACpC,kBAAkB,IAAI,eAAe,CAAC;IACtC,uFAAuF;IACvF,WAAW,IAAI,OAAO,CAAC;IACvB,gGAAgG;IAChG,kBAAkB,CAAC,IAAI,MAAM,CAAC;IAC9B,gFAAgF;IAChF,cAAc,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC;IAChD,4FAA4F;IAC5F,mBAAmB,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CAC3C;AAED,MAAM,WAAW,oBAAoB;IACpC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC3B,kFAAkF;IAClF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mGAAmG;IACnG,YAAY,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,qBAAa,uBAAuB;IACnC,OAAO,CAAC,qBAAqB,CAA8B;IAC3D,OAAO,CAAC,oBAAoB,CAA8B;IAC1D,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IAEzC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA8B;IAEnD,YAAY,IAAI,EAAE,2BAA2B,EAG5C;IAEK,WAAW,CAChB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,EACjC,OAAO,CAAC,EAAE,oBAAoB,GAC5B,OAAO,CAAC,UAAU,CAAC,CAoCrB;IAED;;;OAGG;IACH,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE;QAAE,kBAAkB,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CA2BtG;IAED;;OAEG;IACH,SAAS,IAAI,IAAI,CAIhB;IAED,kDAAkD;IAClD,IAAI,aAAa,IAAI,OAAO,CAE3B;IAED,oEAAoE;IACpE,IAAI,sBAAsB,IAAI,OAAO,CAEpC;IAED;;;OAGG;IACH,wBAAwB,IAAI,IAAI,CAY/B;CACD"}
@@ -23,6 +23,9 @@ export class BashExecutionController {
23
23
  const shellPath = this.deps.getSettingsManager().getShellPath();
24
24
  const platform = options?.platform ?? process.platform;
25
25
  const enableGitFilter = !options?.operations && !commandPrefix && !shellPath;
26
+ const cwd = this.deps.getSessionManager().getCwd();
27
+ const environment = { ...process.env, ...this.deps.getEnvironment?.(cwd) };
28
+ delete environment.BW_SESSION;
26
29
  const operations = createLocalPlatformShellOperations({
27
30
  shellPath,
28
31
  commandPrefix,
@@ -31,11 +34,12 @@ export class BashExecutionController {
31
34
  pythonEngine: options?.pythonEngine,
32
35
  }, platform);
33
36
  try {
34
- const result = await executeBashWithOperations(command, this.deps.getSessionManager().getCwd(), operations, {
37
+ const result = await executeBashWithOperations(command, cwd, operations, {
35
38
  onChunk,
36
39
  signal: abortController.signal,
37
40
  enableGitFilter,
38
41
  timeout: resolveCommandTimeoutSeconds(options?.timeout),
42
+ environment,
39
43
  });
40
44
  this.recordBashResult(command, result, options);
41
45
  return result;
@@ -49,14 +53,17 @@ export class BashExecutionController {
49
53
  * Used by executeBash and by extensions that handle bash execution themselves.
50
54
  */
51
55
  recordBashResult(command, result, options) {
56
+ const safeCommand = this.deps.redactSensitiveText?.(command) ?? command;
57
+ const safeOutput = this.deps.redactSensitiveText?.(result.output) ?? result.output;
58
+ const outputWasRedacted = safeOutput !== result.output;
52
59
  const bashMessage = {
53
60
  role: "bashExecution",
54
- command,
55
- output: result.output,
61
+ command: safeCommand,
62
+ output: safeOutput,
56
63
  exitCode: result.exitCode,
57
64
  cancelled: result.cancelled,
58
65
  truncated: result.truncated,
59
- fullOutputPath: result.fullOutputPath,
66
+ ...(outputWasRedacted ? {} : { fullOutputPath: result.fullOutputPath }),
60
67
  timestamp: Date.now(),
61
68
  excludeFromContext: options?.excludeFromContext,
62
69
  };
@@ -1 +1 @@
1
- {"version":3,"file":"bash-execution-controller.js","sourceRoot":"","sources":["../../src/core/bash-execution-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAmB,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAEhF,OAAO,EAAuB,kCAAkC,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAuBxH,MAAM,OAAO,uBAAuB;IAOnC,YAAY,IAAiC;QANrC,0BAAqB,GAAG,IAAI,GAAG,EAAmB,CAAC;QACnD,yBAAoB,GAA2B,EAAE,CAAC;QAMzD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,kBAAkB,EAAE,EAAE,IAAI,mBAAmB,UAAU,EAAE,EAAE,CAAC;IACzF,CAAC;IAED,KAAK,CAAC,WAAW,CACh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QAEnD,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC;YACrD,qBAAqB;YACrB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAEtD,kBAAkB;YAClB,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;QAC1D,CAAC;QAED,IAAI,CAAC,oBAAoB,GAAG,EAAE,CAAC;IAChC,CAAC;CACD","sourcesContent":["/**\n * Standalone bash-command execution (the `/bash` path + extension-driven bash).\n *\n * Extracted verbatim from agent-session.ts (god-file decomposition). Owns the bash abort controller\n * and the pending-message queue that defers appending a bash result while the agent is streaming (so\n * tool_use/tool_result ordering is never broken); the deferred messages are flushed by the session on\n * agent turn completion. Persists results through the session log via deps.\n */\n\nimport { randomUUID } from \"node:crypto\";\nimport type { Agent, BashExecutionMessage } from \"@caupulican/pi-agent-core\";\nimport type { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport { type BashResult, executeBashWithOperations } from \"./bash-executor.ts\";\nimport type { SettingsManager } from \"./settings-manager.ts\";\nimport { type BashOperations, createLocalPlatformShellOperations, resolveCommandTimeoutSeconds } from \"./tools/bash.ts\";\n\nexport interface BashExecutionControllerDeps {\n\tgetAgent(): Agent;\n\tgetSessionManager(): SessionManager;\n\tgetSettingsManager(): SettingsManager;\n\t/** Whether the agent is currently streaming — defers appending a bash result if so. */\n\tisStreaming(): boolean;\n\t/** Per-agent persistent shell session key — user `!` commands share the agent's shell state. */\n\tgetShellSessionKey?(): string;\n}\n\nexport interface BashExecutionOptions {\n\texcludeFromContext?: boolean;\n\toperations?: BashOperations;\n\t/** Injectable target platform for tests and embedded runtimes. */\n\tplatform?: NodeJS.Platform;\n\t/** Wall-clock timeout in seconds; non-positive values use the bounded default. */\n\ttimeout?: number;\n\t/** Route complex/state-mutating Bash constructs to the Python engine on Windows. Default: true. */\n\tpythonEngine?: boolean;\n}\n\nexport class BashExecutionController {\n\tprivate _bashAbortControllers = new Set<AbortController>();\n\tprivate _pendingBashMessages: BashExecutionMessage[] = [];\n\tprivate readonly shellSessionKey: string;\n\n\tprivate readonly deps: BashExecutionControllerDeps;\n\n\tconstructor(deps: BashExecutionControllerDeps) {\n\t\tthis.deps = deps;\n\t\tthis.shellSessionKey = deps.getShellSessionKey?.() ?? `bash-controller:${randomUUID()}`;\n\t}\n\n\tasync executeBash(\n\t\tcommand: string,\n\t\tonChunk?: (chunk: string) => void,\n\t\toptions?: BashExecutionOptions,\n\t): Promise<BashResult> {\n\t\tconst abortController = new AbortController();\n\t\tthis._bashAbortControllers.add(abortController);\n\n\t\tconst commandPrefix = this.deps.getSettingsManager().getShellCommandPrefix();\n\t\tconst shellPath = this.deps.getSettingsManager().getShellPath();\n\t\tconst platform = options?.platform ?? process.platform;\n\t\tconst enableGitFilter = !options?.operations && !commandPrefix && !shellPath;\n\t\tconst operations = createLocalPlatformShellOperations(\n\t\t\t{\n\t\t\t\tshellPath,\n\t\t\t\tcommandPrefix,\n\t\t\t\toperations: options?.operations,\n\t\t\t\tsessionKey: this.shellSessionKey,\n\t\t\t\tpythonEngine: options?.pythonEngine,\n\t\t\t},\n\t\t\tplatform,\n\t\t);\n\n\t\ttry {\n\t\t\tconst result = await executeBashWithOperations(command, this.deps.getSessionManager().getCwd(), operations, {\n\t\t\t\tonChunk,\n\t\t\t\tsignal: abortController.signal,\n\t\t\t\tenableGitFilter,\n\t\t\t\ttimeout: resolveCommandTimeoutSeconds(options?.timeout),\n\t\t\t});\n\n\t\t\tthis.recordBashResult(command, result, options);\n\t\t\treturn result;\n\t\t} finally {\n\t\t\tthis._bashAbortControllers.delete(abortController);\n\t\t}\n\t}\n\n\t/**\n\t * Record a bash execution result in session history.\n\t * Used by executeBash and by extensions that handle bash execution themselves.\n\t */\n\trecordBashResult(command: string, result: BashResult, options?: { excludeFromContext?: boolean }): void {\n\t\tconst bashMessage: BashExecutionMessage = {\n\t\t\trole: \"bashExecution\",\n\t\t\tcommand,\n\t\t\toutput: result.output,\n\t\t\texitCode: result.exitCode,\n\t\t\tcancelled: result.cancelled,\n\t\t\ttruncated: result.truncated,\n\t\t\tfullOutputPath: result.fullOutputPath,\n\t\t\ttimestamp: Date.now(),\n\t\t\texcludeFromContext: options?.excludeFromContext,\n\t\t};\n\n\t\t// If agent is streaming, defer adding to avoid breaking tool_use/tool_result ordering\n\t\tif (this.deps.isStreaming()) {\n\t\t\t// Queue for later - will be flushed on agent_end\n\t\t\tthis._pendingBashMessages.push(bashMessage);\n\t\t} else {\n\t\t\t// Add to agent state immediately\n\t\t\tthis.deps.getAgent().state.messages.push(bashMessage);\n\n\t\t\t// Save to session\n\t\t\tthis.deps.getSessionManager().appendMessage(bashMessage);\n\t\t}\n\t}\n\n\t/**\n\t * Cancel running bash command.\n\t */\n\tabortBash(): void {\n\t\tfor (const controller of this._bashAbortControllers) {\n\t\t\tcontroller.abort();\n\t\t}\n\t}\n\n\t/** Whether a bash command is currently running */\n\tget isBashRunning(): boolean {\n\t\treturn this._bashAbortControllers.size > 0;\n\t}\n\n\t/** Whether there are pending bash messages waiting to be flushed */\n\tget hasPendingBashMessages(): boolean {\n\t\treturn this._pendingBashMessages.length > 0;\n\t}\n\n\t/**\n\t * Flush pending bash messages to agent state and session.\n\t * Called after agent turn completes to maintain proper message ordering.\n\t */\n\tflushPendingBashMessages(): void {\n\t\tif (this._pendingBashMessages.length === 0) return;\n\n\t\tfor (const bashMessage of this._pendingBashMessages) {\n\t\t\t// Add to agent state\n\t\t\tthis.deps.getAgent().state.messages.push(bashMessage);\n\n\t\t\t// Save to session\n\t\t\tthis.deps.getSessionManager().appendMessage(bashMessage);\n\t\t}\n\n\t\tthis._pendingBashMessages = [];\n\t}\n}\n"]}
1
+ {"version":3,"file":"bash-execution-controller.js","sourceRoot":"","sources":["../../src/core/bash-execution-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG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AC,WAAW,CAAC,CAAC;YAEtD,kBAAkB;YAClB,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;QAC1D,CAAC;QAED,IAAI,CAAC,oBAAoB,GAAG,EAAE,CAAC;IAChC,CAAC;CACD","sourcesContent":["/**\n * Standalone bash-command execution (the `/bash` path + extension-driven bash).\n *\n * Extracted verbatim from agent-session.ts (god-file decomposition). Owns the bash abort controller\n * and the pending-message queue that defers appending a bash result while the agent is streaming (so\n * tool_use/tool_result ordering is never broken); the deferred messages are flushed by the session on\n * agent turn completion. Persists results through the session log via deps.\n */\n\nimport { randomUUID } from \"node:crypto\";\nimport type { Agent, BashExecutionMessage } from \"@caupulican/pi-agent-core\";\nimport type { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport { type BashResult, executeBashWithOperations } from \"./bash-executor.ts\";\nimport type { SettingsManager } from \"./settings-manager.ts\";\nimport { type BashOperations, createLocalPlatformShellOperations, resolveCommandTimeoutSeconds } from \"./tools/bash.ts\";\n\nexport interface BashExecutionControllerDeps {\n\tgetAgent(): Agent;\n\tgetSessionManager(): SessionManager;\n\tgetSettingsManager(): SettingsManager;\n\t/** Whether the agent is currently streaming — defers appending a bash result if so. */\n\tisStreaming(): boolean;\n\t/** Per-agent persistent shell session key — user `!` commands share the agent's shell state. */\n\tgetShellSessionKey?(): string;\n\t/** Owner-authorized credential environment resolved for the current project. */\n\tgetEnvironment?(cwd: string): NodeJS.ProcessEnv;\n\t/** Exact-value redaction applied before owner shell results enter model/session history. */\n\tredactSensitiveText?(text: string): string;\n}\n\nexport interface BashExecutionOptions {\n\texcludeFromContext?: boolean;\n\toperations?: BashOperations;\n\t/** Injectable target platform for tests and embedded runtimes. */\n\tplatform?: NodeJS.Platform;\n\t/** Wall-clock timeout in seconds; non-positive values use the bounded default. */\n\ttimeout?: number;\n\t/** Route complex/state-mutating Bash constructs to the Python engine on Windows. Default: true. */\n\tpythonEngine?: boolean;\n}\n\nexport class BashExecutionController {\n\tprivate _bashAbortControllers = new Set<AbortController>();\n\tprivate _pendingBashMessages: BashExecutionMessage[] = [];\n\tprivate readonly shellSessionKey: string;\n\n\tprivate readonly deps: BashExecutionControllerDeps;\n\n\tconstructor(deps: BashExecutionControllerDeps) {\n\t\tthis.deps = deps;\n\t\tthis.shellSessionKey = deps.getShellSessionKey?.() ?? `bash-controller:${randomUUID()}`;\n\t}\n\n\tasync executeBash(\n\t\tcommand: string,\n\t\tonChunk?: (chunk: string) => void,\n\t\toptions?: BashExecutionOptions,\n\t): Promise<BashResult> {\n\t\tconst abortController = new AbortController();\n\t\tthis._bashAbortControllers.add(abortController);\n\n\t\tconst commandPrefix = this.deps.getSettingsManager().getShellCommandPrefix();\n\t\tconst shellPath = this.deps.getSettingsManager().getShellPath();\n\t\tconst platform = options?.platform ?? process.platform;\n\t\tconst enableGitFilter = !options?.operations && !commandPrefix && !shellPath;\n\t\tconst cwd = this.deps.getSessionManager().getCwd();\n\t\tconst environment: NodeJS.ProcessEnv = { ...process.env, ...this.deps.getEnvironment?.(cwd) };\n\t\tdelete environment.BW_SESSION;\n\t\tconst operations = createLocalPlatformShellOperations(\n\t\t\t{\n\t\t\t\tshellPath,\n\t\t\t\tcommandPrefix,\n\t\t\t\toperations: options?.operations,\n\t\t\t\tsessionKey: this.shellSessionKey,\n\t\t\t\tpythonEngine: options?.pythonEngine,\n\t\t\t},\n\t\t\tplatform,\n\t\t);\n\n\t\ttry {\n\t\t\tconst result = await executeBashWithOperations(command, cwd, operations, {\n\t\t\t\tonChunk,\n\t\t\t\tsignal: abortController.signal,\n\t\t\t\tenableGitFilter,\n\t\t\t\ttimeout: resolveCommandTimeoutSeconds(options?.timeout),\n\t\t\t\tenvironment,\n\t\t\t});\n\n\t\t\tthis.recordBashResult(command, result, options);\n\t\t\treturn result;\n\t\t} finally {\n\t\t\tthis._bashAbortControllers.delete(abortController);\n\t\t}\n\t}\n\n\t/**\n\t * Record a bash execution result in session history.\n\t * Used by executeBash and by extensions that handle bash execution themselves.\n\t */\n\trecordBashResult(command: string, result: BashResult, options?: { excludeFromContext?: boolean }): void {\n\t\tconst safeCommand = this.deps.redactSensitiveText?.(command) ?? command;\n\t\tconst safeOutput = this.deps.redactSensitiveText?.(result.output) ?? result.output;\n\t\tconst outputWasRedacted = safeOutput !== result.output;\n\t\tconst bashMessage: BashExecutionMessage = {\n\t\t\trole: \"bashExecution\",\n\t\t\tcommand: safeCommand,\n\t\t\toutput: safeOutput,\n\t\t\texitCode: result.exitCode,\n\t\t\tcancelled: result.cancelled,\n\t\t\ttruncated: result.truncated,\n\t\t\t...(outputWasRedacted ? {} : { fullOutputPath: result.fullOutputPath }),\n\t\t\ttimestamp: Date.now(),\n\t\t\texcludeFromContext: options?.excludeFromContext,\n\t\t};\n\n\t\t// If agent is streaming, defer adding to avoid breaking tool_use/tool_result ordering\n\t\tif (this.deps.isStreaming()) {\n\t\t\t// Queue for later - will be flushed on agent_end\n\t\t\tthis._pendingBashMessages.push(bashMessage);\n\t\t} else {\n\t\t\t// Add to agent state immediately\n\t\t\tthis.deps.getAgent().state.messages.push(bashMessage);\n\n\t\t\t// Save to session\n\t\t\tthis.deps.getSessionManager().appendMessage(bashMessage);\n\t\t}\n\t}\n\n\t/**\n\t * Cancel running bash command.\n\t */\n\tabortBash(): void {\n\t\tfor (const controller of this._bashAbortControllers) {\n\t\t\tcontroller.abort();\n\t\t}\n\t}\n\n\t/** Whether a bash command is currently running */\n\tget isBashRunning(): boolean {\n\t\treturn this._bashAbortControllers.size > 0;\n\t}\n\n\t/** Whether there are pending bash messages waiting to be flushed */\n\tget hasPendingBashMessages(): boolean {\n\t\treturn this._pendingBashMessages.length > 0;\n\t}\n\n\t/**\n\t * Flush pending bash messages to agent state and session.\n\t * Called after agent turn completes to maintain proper message ordering.\n\t */\n\tflushPendingBashMessages(): void {\n\t\tif (this._pendingBashMessages.length === 0) return;\n\n\t\tfor (const bashMessage of this._pendingBashMessages) {\n\t\t\t// Add to agent state\n\t\t\tthis.deps.getAgent().state.messages.push(bashMessage);\n\n\t\t\t// Save to session\n\t\t\tthis.deps.getSessionManager().appendMessage(bashMessage);\n\t\t}\n\n\t\tthis._pendingBashMessages = [];\n\t}\n}\n"]}
@@ -15,6 +15,8 @@ export interface BashExecutorOptions {
15
15
  enableGitFilter?: boolean;
16
16
  /** Wall-clock timeout in seconds. Direct interactive/RPC callers provide the same bounded default as the agent tool. */
17
17
  timeout?: number;
18
+ /** Explicit process environment for both the filtered Git and shell execution paths. */
19
+ environment?: NodeJS.ProcessEnv;
18
20
  }
19
21
  export interface BashResult {
20
22
  /** Combined stdout + stderr output (sanitized, possibly truncated) */
@@ -1 +1 @@
1
- {"version":3,"file":"bash-executor.d.ts","sourceRoot":"","sources":["../../src/core/bash-executor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAWH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAOtD,MAAM,WAAW,mBAAmB;IACnC,+DAA+D;IAC/D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,mCAAmC;IACnC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,2FAA2F;IAC3F,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,wHAAwH;IACxH,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IAC1B,sEAAsE;IACtE,MAAM,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,mDAAmD;IACnD,SAAS,EAAE,OAAO,CAAC;IACnB,uCAAuC;IACvC,SAAS,EAAE,OAAO,CAAC;IACnB,yFAAyF;IACzF,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAUD;;;GAGG;AACH,wBAAsB,yBAAyB,CAC9C,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,cAAc,EAC1B,OAAO,CAAC,EAAE,mBAAmB,GAC3B,OAAO,CAAC,UAAU,CAAC,CAiKrB"}
1
+ {"version":3,"file":"bash-executor.d.ts","sourceRoot":"","sources":["../../src/core/bash-executor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAWH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAOtD,MAAM,WAAW,mBAAmB;IACnC,+DAA+D;IAC/D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,mCAAmC;IACnC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,2FAA2F;IAC3F,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,wHAAwH;IACxH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wFAAwF;IACxF,WAAW,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;CAChC;AAED,MAAM,WAAW,UAAU;IAC1B,sEAAsE;IACtE,MAAM,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,mDAAmD;IACnD,SAAS,EAAE,OAAO,CAAC;IACnB,uCAAuC;IACvC,SAAS,EAAE,OAAO,CAAC;IACnB,yFAAyF;IACzF,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAUD;;;GAGG;AACH,wBAAsB,yBAAyB,CAC9C,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,cAAc,EAC1B,OAAO,CAAC,EAAE,mBAAmB,GAC3B,OAAO,CAAC,UAAU,CAAC,CAkKrB"}
@@ -7,8 +7,8 @@
7
7
  */
8
8
  import { randomBytes } from "node:crypto";
9
9
  import { join } from "node:path";
10
- import { sanitizeBinaryOutput } from "@caupulican/pi-agent-core";
11
- import { DEFAULT_MAX_BYTES, truncateTail } from "@caupulican/pi-agent-core/node";
10
+ import { sanitizeBinaryOutput } from "@caupulican/pi-agent-core/shell-output";
11
+ import { DEFAULT_MAX_BYTES, truncateTail } from "@caupulican/pi-agent-core/truncate";
12
12
  import { getAgentDir } from "../config.js";
13
13
  import { stripAnsi } from "../utils/ansi.js";
14
14
  import { createSafeWriteStream, endWriteStream } from "../utils/safe-write-stream.js";
@@ -28,7 +28,7 @@ export async function executeBashWithOperations(command, cwd, operations, option
28
28
  if (options?.enableGitFilter) {
29
29
  const classification = classifyGitCommand(command, process.env);
30
30
  if (classification.eligible && classification.subcommand) {
31
- const res = await executeFilteredGit(cwd, classification.subcommand, classification.globalOptions || [], classification.subcommandArgs || [], { signal: options.signal, timeout: options.timeout });
31
+ const res = await executeFilteredGit(cwd, classification.subcommand, classification.globalOptions || [], classification.subcommandArgs || [], { signal: options.signal, timeout: options.timeout, environment: options.environment });
32
32
  if (res.exitCode !== -100) {
33
33
  const rawBytes = res.rawBytes ?? Buffer.from(res.rawOut, "utf-8");
34
34
  // The filter already spills oversized output to a temp file; reuse it
@@ -111,6 +111,7 @@ export async function executeBashWithOperations(command, cwd, operations, option
111
111
  onData,
112
112
  signal: options?.signal,
113
113
  timeout: options?.timeout,
114
+ env: options?.environment,
114
115
  });
115
116
  const fullOutput = outputChunks.join("");
116
117
  const truncationResult = truncateTail(fullOutput);
@@ -1 +1 @@
1
- {"version":3,"file":"bash-executor.js","sourceRoot":"","sources":["../../src/core/bash-executor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,cAAc,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UAAU,CAAC,CAAC;YAClD,IAAI,gBAAgB,CAAC,SAAS,EAAE,CAAC;gBAChC,cAAc,EAAE,CAAC;YAClB,CAAC;YACD,IAAI,cAAc,EAAE,CAAC;gBACpB,MAAM,cAAc,CAAC,cAAc,CAAC,CAAC;YACtC,CAAC;YACD,OAAO;gBACN,MAAM,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU;gBAC1E,QAAQ,EAAE,SAAS;gBACnB,SAAS,EAAE,IAAI;gBACf,SAAS,EAAE,gBAAgB,CAAC,SAAS;gBACrC,cAAc,EAAE,YAAY;aAC5B,CAAC;QACH,CAAC;QAED,IAAI,cAAc,EAAE,CAAC;YACpB,MAAM,cAAc,CAAC,cAAc,CAAC,CAAC;QACtC,CAAC;QAED,mFAAmF;QACnF,qFAAqF;QACrF,wEAAwE;QACxE,IAAI,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAChE,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YACvC,MAAM,IAAI,KAAK,CACd,wBAAwB,IAAI,wHAAwH,CACpJ,CAAC;QACH,CAAC;QAED,MAAM,GAAG,CAAC;IACX,CAAC;AACF,CAAC","sourcesContent":["/**\n * Bash command execution with streaming support and cancellation.\n *\n * This module provides a unified bash execution implementation used by:\n * - AgentSession.executeBash() for interactive and RPC modes\n * - Direct calls from modes that need bash execution\n */\n\nimport { randomBytes } from \"node:crypto\";\nimport type { WriteStream } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { sanitizeBinaryOutput } from \"@caupulican/pi-agent-core\";\nimport { DEFAULT_MAX_BYTES, truncateTail } from \"@caupulican/pi-agent-core/node\";\nimport { getAgentDir } from \"../config.ts\";\nimport { stripAnsi } from \"../utils/ansi.ts\";\nimport { createSafeWriteStream, endWriteStream } from \"../utils/safe-write-stream.ts\";\nimport { getProcessWorkRun } from \"../utils/work-directory.ts\";\nimport type { BashOperations } from \"./tools/bash.ts\";\nimport { classifyGitCommand, executeFilteredGit } from \"./tools/git-filter.ts\";\n\n// ============================================================================\n// Types\n// ============================================================================\n\nexport interface BashExecutorOptions {\n\t/** Callback for streaming output chunks (already sanitized) */\n\tonChunk?: (chunk: string) => void;\n\t/** AbortSignal for cancellation */\n\tsignal?: AbortSignal;\n\t/** Enable conservative pi-native git output filtering for local default execution paths */\n\tenableGitFilter?: boolean;\n\t/** Wall-clock timeout in seconds. Direct interactive/RPC callers provide the same bounded default as the agent tool. */\n\ttimeout?: number;\n}\n\nexport interface BashResult {\n\t/** Combined stdout + stderr output (sanitized, possibly truncated) */\n\toutput: string;\n\t/** Process exit code (undefined if killed/cancelled) */\n\texitCode: number | undefined;\n\t/** Whether the command was cancelled via signal */\n\tcancelled: boolean;\n\t/** Whether the output was truncated */\n\ttruncated: boolean;\n\t/** Path to temp file containing full output (if output exceeded truncation threshold) */\n\tfullOutputPath?: string;\n}\n\n// ============================================================================\n// Implementation\n// ============================================================================\n\nfunction getBashOutputPath(id: string): string {\n\treturn join(getProcessWorkRun(getAgentDir(), \"outputs\", \"bash\").path, `pi-bash-${id}.log`);\n}\n\n/**\n * Execute a bash command using custom BashOperations.\n * Used for remote execution (SSH, containers, etc.).\n */\nexport async function executeBashWithOperations(\n\tcommand: string,\n\tcwd: string,\n\toperations: BashOperations,\n\toptions?: BashExecutorOptions,\n): Promise<BashResult> {\n\tif (options?.enableGitFilter) {\n\t\tconst classification = classifyGitCommand(command, process.env);\n\t\tif (classification.eligible && classification.subcommand) {\n\t\t\tconst res = await executeFilteredGit(\n\t\t\t\tcwd,\n\t\t\t\tclassification.subcommand,\n\t\t\t\tclassification.globalOptions || [],\n\t\t\t\tclassification.subcommandArgs || [],\n\t\t\t\t{ signal: options.signal, timeout: options.timeout },\n\t\t\t);\n\t\t\tif (res.exitCode !== -100) {\n\t\t\t\tconst rawBytes = res.rawBytes ?? Buffer.from(res.rawOut, \"utf-8\");\n\t\t\t\t// The filter already spills oversized output to a temp file; reuse it\n\t\t\t\t// instead of materializing another full copy here.\n\t\t\t\tlet fullOutputPath = res.fullOutputPath;\n\t\t\t\tif (fullOutputPath === undefined && rawBytes.length > DEFAULT_MAX_BYTES) {\n\t\t\t\t\tconst id = randomBytes(8).toString(\"hex\");\n\t\t\t\t\tconst spillPath = getBashOutputPath(id);\n\t\t\t\t\tfullOutputPath = spillPath;\n\t\t\t\t\t// On stream failure (e.g. disk full), drop the advertised path instead of\n\t\t\t\t\t// pointing at a partial/missing file.\n\t\t\t\t\tconst tempFileStream = createSafeWriteStream(spillPath, () => {\n\t\t\t\t\t\tfullOutputPath = undefined;\n\t\t\t\t\t});\n\t\t\t\t\ttempFileStream.write(rawBytes);\n\t\t\t\t\t// Await the flush so the returned path points at a COMPLETE file, not one mid-write.\n\t\t\t\t\tawait endWriteStream(tempFileStream);\n\t\t\t\t}\n\t\t\t\toptions.onChunk?.(res.output);\n\t\t\t\treturn {\n\t\t\t\t\toutput: res.output,\n\t\t\t\t\texitCode: res.exitCode,\n\t\t\t\t\tcancelled: options.signal?.aborted ?? false,\n\t\t\t\t\ttruncated: res.fullOutputPath !== undefined || rawBytes.length > DEFAULT_MAX_BYTES,\n\t\t\t\t\tfullOutputPath,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\tconst outputChunks: string[] = [];\n\tlet outputBytes = 0;\n\tconst maxOutputBytes = DEFAULT_MAX_BYTES * 2;\n\n\tlet tempFilePath: string | undefined;\n\tlet tempFileStream: WriteStream | undefined;\n\tlet totalBytes = 0;\n\n\tconst ensureTempFile = () => {\n\t\tif (tempFilePath) {\n\t\t\treturn;\n\t\t}\n\t\tconst id = randomBytes(8).toString(\"hex\");\n\t\ttempFilePath = getBashOutputPath(id);\n\t\t// On stream failure (e.g. disk full), drop the artifact instead of\n\t\t// crashing the process; the rolling in-memory output is still returned.\n\t\ttempFileStream = createSafeWriteStream(tempFilePath, () => {\n\t\t\ttempFileStream = undefined;\n\t\t\ttempFilePath = undefined;\n\t\t});\n\t\tfor (const chunk of outputChunks) {\n\t\t\ttempFileStream.write(chunk);\n\t\t}\n\t};\n\n\tconst decoder = new TextDecoder();\n\n\tconst onData = (data: Buffer) => {\n\t\ttotalBytes += data.length;\n\n\t\t// Sanitize: strip ANSI, replace binary garbage, normalize newlines\n\t\tconst text = sanitizeBinaryOutput(stripAnsi(decoder.decode(data, { stream: true }))).replace(/\\r/g, \"\");\n\n\t\t// Start writing to temp file if exceeds threshold\n\t\tif (totalBytes > DEFAULT_MAX_BYTES) {\n\t\t\tensureTempFile();\n\t\t}\n\n\t\t// Guard writableEnded: custom BashOperations may deliver late onData\n\t\t// callbacks after an abort path has already ended the stream.\n\t\tif (tempFileStream && !tempFileStream.writableEnded) {\n\t\t\ttempFileStream.write(text);\n\t\t}\n\n\t\t// Keep rolling buffer\n\t\toutputChunks.push(text);\n\t\toutputBytes += text.length;\n\t\twhile (outputBytes > maxOutputBytes && outputChunks.length > 1) {\n\t\t\tconst removed = outputChunks.shift()!;\n\t\t\toutputBytes -= removed.length;\n\t\t}\n\n\t\t// Stream to callback\n\t\tif (options?.onChunk) {\n\t\t\toptions.onChunk(text);\n\t\t}\n\t};\n\n\ttry {\n\t\tconst result = await operations.exec(command, cwd, {\n\t\t\tonData,\n\t\t\tsignal: options?.signal,\n\t\t\ttimeout: options?.timeout,\n\t\t});\n\n\t\tconst fullOutput = outputChunks.join(\"\");\n\t\tconst truncationResult = truncateTail(fullOutput);\n\t\tif (truncationResult.truncated) {\n\t\t\tensureTempFile();\n\t\t}\n\t\tif (tempFileStream) {\n\t\t\t// Await the flush so fullOutputPath refers to a fully-written file on return, not one still\n\t\t\t// draining its buffer — otherwise a fast reader can see partial/empty content.\n\t\t\tawait endWriteStream(tempFileStream);\n\t\t}\n\t\tconst cancelled = options?.signal?.aborted ?? false;\n\n\t\treturn {\n\t\t\toutput: truncationResult.truncated ? truncationResult.content : fullOutput,\n\t\t\texitCode: cancelled ? undefined : (result.exitCode ?? undefined),\n\t\t\tcancelled,\n\t\t\ttruncated: truncationResult.truncated,\n\t\t\tfullOutputPath: tempFilePath,\n\t\t};\n\t} catch (err) {\n\t\t// Check if it was an abort\n\t\tif (options?.signal?.aborted) {\n\t\t\tconst fullOutput = outputChunks.join(\"\");\n\t\t\tconst truncationResult = truncateTail(fullOutput);\n\t\t\tif (truncationResult.truncated) {\n\t\t\t\tensureTempFile();\n\t\t\t}\n\t\t\tif (tempFileStream) {\n\t\t\t\tawait endWriteStream(tempFileStream);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\toutput: truncationResult.truncated ? truncationResult.content : fullOutput,\n\t\t\t\texitCode: undefined,\n\t\t\t\tcancelled: true,\n\t\t\t\ttruncated: truncationResult.truncated,\n\t\t\t\tfullOutputPath: tempFilePath,\n\t\t\t};\n\t\t}\n\n\t\tif (tempFileStream) {\n\t\t\tawait endWriteStream(tempFileStream);\n\t\t}\n\n\t\t// The silence watchdog (see tools/bash.ts) throws a raw `silence:<secs>` sentinel.\n\t\t// Map it to the same user-facing message the interactive bash tool shows, instead of\n\t\t// leaking the sentinel to callers of this path (interactive !cmd, RPC).\n\t\tif (err instanceof Error && err.message.startsWith(\"silence:\")) {\n\t\t\tconst secs = err.message.split(\":\")[1];\n\t\t\tthrow new Error(\n\t\t\t\t`Command killed after ${secs}s of silence (no output). If the command is legitimately quiet for long stretches, re-run it with an explicit timeout.`,\n\t\t\t);\n\t\t}\n\n\t\tthrow err;\n\t}\n}\n"]}
1
+ {"version":3,"file":"bash-executor.js","sourceRoot":"","sources":["../../src/core/bash-executor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCA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ACT,SAAS,EAAE,gBAAgB,CAAC,SAAS;YACrC,cAAc,EAAE,YAAY;SAC5B,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,2BAA2B;QAC3B,IAAI,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;YAC9B,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACzC,MAAM,gBAAgB,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;YAClD,IAAI,gBAAgB,CAAC,SAAS,EAAE,CAAC;gBAChC,cAAc,EAAE,CAAC;YAClB,CAAC;YACD,IAAI,cAAc,EAAE,CAAC;gBACpB,MAAM,cAAc,CAAC,cAAc,CAAC,CAAC;YACtC,CAAC;YACD,OAAO;gBACN,MAAM,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU;gBAC1E,QAAQ,EAAE,SAAS;gBACnB,SAAS,EAAE,IAAI;gBACf,SAAS,EAAE,gBAAgB,CAAC,SAAS;gBACrC,cAAc,EAAE,YAAY;aAC5B,CAAC;QACH,CAAC;QAED,IAAI,cAAc,EAAE,CAAC;YACpB,MAAM,cAAc,CAAC,cAAc,CAAC,CAAC;QACtC,CAAC;QAED,mFAAmF;QACnF,qFAAqF;QACrF,wEAAwE;QACxE,IAAI,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAChE,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YACvC,MAAM,IAAI,KAAK,CACd,wBAAwB,IAAI,wHAAwH,CACpJ,CAAC;QACH,CAAC;QAED,MAAM,GAAG,CAAC;IACX,CAAC;AACF,CAAC","sourcesContent":["/**\n * Bash command execution with streaming support and cancellation.\n *\n * This module provides a unified bash execution implementation used by:\n * - AgentSession.executeBash() for interactive and RPC modes\n * - Direct calls from modes that need bash execution\n */\n\nimport { randomBytes } from \"node:crypto\";\nimport type { WriteStream } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { sanitizeBinaryOutput } from \"@caupulican/pi-agent-core/shell-output\";\nimport { DEFAULT_MAX_BYTES, truncateTail } from \"@caupulican/pi-agent-core/truncate\";\nimport { getAgentDir } from \"../config.ts\";\nimport { stripAnsi } from \"../utils/ansi.ts\";\nimport { createSafeWriteStream, endWriteStream } from \"../utils/safe-write-stream.ts\";\nimport { getProcessWorkRun } from \"../utils/work-directory.ts\";\nimport type { BashOperations } from \"./tools/bash.ts\";\nimport { classifyGitCommand, executeFilteredGit } from \"./tools/git-filter.ts\";\n\n// ============================================================================\n// Types\n// ============================================================================\n\nexport interface BashExecutorOptions {\n\t/** Callback for streaming output chunks (already sanitized) */\n\tonChunk?: (chunk: string) => void;\n\t/** AbortSignal for cancellation */\n\tsignal?: AbortSignal;\n\t/** Enable conservative pi-native git output filtering for local default execution paths */\n\tenableGitFilter?: boolean;\n\t/** Wall-clock timeout in seconds. Direct interactive/RPC callers provide the same bounded default as the agent tool. */\n\ttimeout?: number;\n\t/** Explicit process environment for both the filtered Git and shell execution paths. */\n\tenvironment?: NodeJS.ProcessEnv;\n}\n\nexport interface BashResult {\n\t/** Combined stdout + stderr output (sanitized, possibly truncated) */\n\toutput: string;\n\t/** Process exit code (undefined if killed/cancelled) */\n\texitCode: number | undefined;\n\t/** Whether the command was cancelled via signal */\n\tcancelled: boolean;\n\t/** Whether the output was truncated */\n\ttruncated: boolean;\n\t/** Path to temp file containing full output (if output exceeded truncation threshold) */\n\tfullOutputPath?: string;\n}\n\n// ============================================================================\n// Implementation\n// ============================================================================\n\nfunction getBashOutputPath(id: string): string {\n\treturn join(getProcessWorkRun(getAgentDir(), \"outputs\", \"bash\").path, `pi-bash-${id}.log`);\n}\n\n/**\n * Execute a bash command using custom BashOperations.\n * Used for remote execution (SSH, containers, etc.).\n */\nexport async function executeBashWithOperations(\n\tcommand: string,\n\tcwd: string,\n\toperations: BashOperations,\n\toptions?: BashExecutorOptions,\n): Promise<BashResult> {\n\tif (options?.enableGitFilter) {\n\t\tconst classification = classifyGitCommand(command, process.env);\n\t\tif (classification.eligible && classification.subcommand) {\n\t\t\tconst res = await executeFilteredGit(\n\t\t\t\tcwd,\n\t\t\t\tclassification.subcommand,\n\t\t\t\tclassification.globalOptions || [],\n\t\t\t\tclassification.subcommandArgs || [],\n\t\t\t\t{ signal: options.signal, timeout: options.timeout, environment: options.environment },\n\t\t\t);\n\t\t\tif (res.exitCode !== -100) {\n\t\t\t\tconst rawBytes = res.rawBytes ?? Buffer.from(res.rawOut, \"utf-8\");\n\t\t\t\t// The filter already spills oversized output to a temp file; reuse it\n\t\t\t\t// instead of materializing another full copy here.\n\t\t\t\tlet fullOutputPath = res.fullOutputPath;\n\t\t\t\tif (fullOutputPath === undefined && rawBytes.length > DEFAULT_MAX_BYTES) {\n\t\t\t\t\tconst id = randomBytes(8).toString(\"hex\");\n\t\t\t\t\tconst spillPath = getBashOutputPath(id);\n\t\t\t\t\tfullOutputPath = spillPath;\n\t\t\t\t\t// On stream failure (e.g. disk full), drop the advertised path instead of\n\t\t\t\t\t// pointing at a partial/missing file.\n\t\t\t\t\tconst tempFileStream = createSafeWriteStream(spillPath, () => {\n\t\t\t\t\t\tfullOutputPath = undefined;\n\t\t\t\t\t});\n\t\t\t\t\ttempFileStream.write(rawBytes);\n\t\t\t\t\t// Await the flush so the returned path points at a COMPLETE file, not one mid-write.\n\t\t\t\t\tawait endWriteStream(tempFileStream);\n\t\t\t\t}\n\t\t\t\toptions.onChunk?.(res.output);\n\t\t\t\treturn {\n\t\t\t\t\toutput: res.output,\n\t\t\t\t\texitCode: res.exitCode,\n\t\t\t\t\tcancelled: options.signal?.aborted ?? false,\n\t\t\t\t\ttruncated: res.fullOutputPath !== undefined || rawBytes.length > DEFAULT_MAX_BYTES,\n\t\t\t\t\tfullOutputPath,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\tconst outputChunks: string[] = [];\n\tlet outputBytes = 0;\n\tconst maxOutputBytes = DEFAULT_MAX_BYTES * 2;\n\n\tlet tempFilePath: string | undefined;\n\tlet tempFileStream: WriteStream | undefined;\n\tlet totalBytes = 0;\n\n\tconst ensureTempFile = () => {\n\t\tif (tempFilePath) {\n\t\t\treturn;\n\t\t}\n\t\tconst id = randomBytes(8).toString(\"hex\");\n\t\ttempFilePath = getBashOutputPath(id);\n\t\t// On stream failure (e.g. disk full), drop the artifact instead of\n\t\t// crashing the process; the rolling in-memory output is still returned.\n\t\ttempFileStream = createSafeWriteStream(tempFilePath, () => {\n\t\t\ttempFileStream = undefined;\n\t\t\ttempFilePath = undefined;\n\t\t});\n\t\tfor (const chunk of outputChunks) {\n\t\t\ttempFileStream.write(chunk);\n\t\t}\n\t};\n\n\tconst decoder = new TextDecoder();\n\n\tconst onData = (data: Buffer) => {\n\t\ttotalBytes += data.length;\n\n\t\t// Sanitize: strip ANSI, replace binary garbage, normalize newlines\n\t\tconst text = sanitizeBinaryOutput(stripAnsi(decoder.decode(data, { stream: true }))).replace(/\\r/g, \"\");\n\n\t\t// Start writing to temp file if exceeds threshold\n\t\tif (totalBytes > DEFAULT_MAX_BYTES) {\n\t\t\tensureTempFile();\n\t\t}\n\n\t\t// Guard writableEnded: custom BashOperations may deliver late onData\n\t\t// callbacks after an abort path has already ended the stream.\n\t\tif (tempFileStream && !tempFileStream.writableEnded) {\n\t\t\ttempFileStream.write(text);\n\t\t}\n\n\t\t// Keep rolling buffer\n\t\toutputChunks.push(text);\n\t\toutputBytes += text.length;\n\t\twhile (outputBytes > maxOutputBytes && outputChunks.length > 1) {\n\t\t\tconst removed = outputChunks.shift()!;\n\t\t\toutputBytes -= removed.length;\n\t\t}\n\n\t\t// Stream to callback\n\t\tif (options?.onChunk) {\n\t\t\toptions.onChunk(text);\n\t\t}\n\t};\n\n\ttry {\n\t\tconst result = await operations.exec(command, cwd, {\n\t\t\tonData,\n\t\t\tsignal: options?.signal,\n\t\t\ttimeout: options?.timeout,\n\t\t\tenv: options?.environment,\n\t\t});\n\n\t\tconst fullOutput = outputChunks.join(\"\");\n\t\tconst truncationResult = truncateTail(fullOutput);\n\t\tif (truncationResult.truncated) {\n\t\t\tensureTempFile();\n\t\t}\n\t\tif (tempFileStream) {\n\t\t\t// Await the flush so fullOutputPath refers to a fully-written file on return, not one still\n\t\t\t// draining its buffer — otherwise a fast reader can see partial/empty content.\n\t\t\tawait endWriteStream(tempFileStream);\n\t\t}\n\t\tconst cancelled = options?.signal?.aborted ?? false;\n\n\t\treturn {\n\t\t\toutput: truncationResult.truncated ? truncationResult.content : fullOutput,\n\t\t\texitCode: cancelled ? undefined : (result.exitCode ?? undefined),\n\t\t\tcancelled,\n\t\t\ttruncated: truncationResult.truncated,\n\t\t\tfullOutputPath: tempFilePath,\n\t\t};\n\t} catch (err) {\n\t\t// Check if it was an abort\n\t\tif (options?.signal?.aborted) {\n\t\t\tconst fullOutput = outputChunks.join(\"\");\n\t\t\tconst truncationResult = truncateTail(fullOutput);\n\t\t\tif (truncationResult.truncated) {\n\t\t\t\tensureTempFile();\n\t\t\t}\n\t\t\tif (tempFileStream) {\n\t\t\t\tawait endWriteStream(tempFileStream);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\toutput: truncationResult.truncated ? truncationResult.content : fullOutput,\n\t\t\t\texitCode: undefined,\n\t\t\t\tcancelled: true,\n\t\t\t\ttruncated: truncationResult.truncated,\n\t\t\t\tfullOutputPath: tempFilePath,\n\t\t\t};\n\t\t}\n\n\t\tif (tempFileStream) {\n\t\t\tawait endWriteStream(tempFileStream);\n\t\t}\n\n\t\t// The silence watchdog (see tools/bash.ts) throws a raw `silence:<secs>` sentinel.\n\t\t// Map it to the same user-facing message the interactive bash tool shows, instead of\n\t\t// leaking the sentinel to callers of this path (interactive !cmd, RPC).\n\t\tif (err instanceof Error && err.message.startsWith(\"silence:\")) {\n\t\t\tconst secs = err.message.split(\":\")[1];\n\t\t\tthrow new Error(\n\t\t\t\t`Command killed after ${secs}s of silence (no output). If the command is legitimately quiet for long stretches, re-run it with an explicit timeout.`,\n\t\t\t);\n\t\t}\n\n\t\tthrow err;\n\t}\n}\n"]}
@@ -1,5 +1,5 @@
1
- import type { Agent } from "@caupulican/pi-agent-core";
2
- import { type ClassifiedError, classifyFailure } from "@caupulican/pi-agent-core";
1
+ import type { Agent } from "@caupulican/pi-agent-core/agent";
2
+ import { type ClassifiedError, classifyFailure } from "@caupulican/pi-agent-core/reliability";
3
3
  import type { AssistantMessage } from "@caupulican/pi-ai";
4
4
  import type { ModelRegistry } from "./model-registry.ts";
5
5
  import type { ModelRouterFailoverStatus } from "./model-router/status.ts";
@@ -1 +1 @@
1
- {"version":3,"file":"billing-failover-controller.d.ts","sourceRoot":"","sources":["../../src/core/billing-failover-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,KAAK,eAAe,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAClF,OAAO,KAAK,EAAO,gBAAgB,EAAS,MAAM,mBAAmB,CAAC;AAEtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAM1E,qBAAa,yBAAyB;IACrC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAyC;IAEnE,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAE/C;IAED,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAMhC;IAED,QAAQ,IAAI,MAAM,EAAE,CAEnB;CACD;AAED,MAAM,WAAW,6BAA6B;IAC7C,KAAK,EAAE,KAAK,CAAC;IACb,aAAa,EAAE,aAAa,CAAC;IAC7B,IAAI,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,SAAS,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACxD,SAAS,EAAE,yBAAyB,CAAC;IACrC,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,aAAa,CAAC,CAAC,IAAI,EAAE;QACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;KAC/C,GAAG,IAAI,CAAC;CACT;AAED,qBAAa,yBAAyB;IACrC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAgC;IACrD,OAAO,CAAC,UAAU,CAAqB;IAEvC,YAAY,IAAI,EAAE,6BAA6B,EAE9C;IAED,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEhC;IAED,iBAAiB,IAAI,MAAM,EAAE,CAE5B;IAED,aAAa,IAAI,MAAM,GAAG,SAAS,CAElC;IAED,SAAS,IAAI,yBAAyB,CAErC;IAEK,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,EAAE,UAAU,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAwBpG;CACD"}
1
+ {"version":3,"file":"billing-failover-controller.d.ts","sourceRoot":"","sources":["../../src/core/billing-failover-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,KAAK,eAAe,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAC9F,OAAO,KAAK,EAAO,gBAAgB,EAAS,MAAM,mBAAmB,CAAC;AAEtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAM1E,qBAAa,yBAAyB;IACrC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAyC;IAEnE,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAE/C;IAED,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAMhC;IAED,QAAQ,IAAI,MAAM,EAAE,CAEnB;CACD;AAED,MAAM,WAAW,6BAA6B;IAC7C,KAAK,EAAE,KAAK,CAAC;IACb,aAAa,EAAE,aAAa,CAAC;IAC7B,IAAI,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,SAAS,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACxD,SAAS,EAAE,yBAAyB,CAAC;IACrC,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,aAAa,CAAC,CAAC,IAAI,EAAE;QACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;KAC/C,GAAG,IAAI,CAAC;CACT;AAED,qBAAa,yBAAyB;IACrC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAgC;IACrD,OAAO,CAAC,UAAU,CAAqB;IAEvC,YAAY,IAAI,EAAE,6BAA6B,EAE9C;IAED,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEhC;IAED,iBAAiB,IAAI,MAAM,EAAE,CAE5B;IAED,aAAa,IAAI,MAAM,GAAG,SAAS,CAElC;IAED,SAAS,IAAI,yBAAyB,CAErC;IAEK,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,EAAE,UAAU,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAwBpG;CACD"}
@@ -1,4 +1,4 @@
1
- import { classifyFailure } from "@caupulican/pi-agent-core";
1
+ import { classifyFailure } from "@caupulican/pi-agent-core/reliability";
2
2
  import { decideBillingFailover } from "./billing-failover.js";
3
3
  const DEFAULT_MODEL_PER_PROVIDER = {
4
4
  "openai-codex": "gpt-5.6-sol",