@caupulican/pi-adaptative 0.94.0 → 0.95.0

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 (371) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/dist/bundled-resources/extensions/tmux-agent-manager/README.md +32 -13
  3. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts +7 -4
  4. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
  5. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +173 -293
  6. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
  7. package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +247 -392
  8. package/dist/bundled-resources/extensions/tmux-agent-manager/launch-profile.d.ts +52 -0
  9. package/dist/bundled-resources/extensions/tmux-agent-manager/launch-profile.d.ts.map +1 -0
  10. package/dist/bundled-resources/extensions/tmux-agent-manager/launch-profile.js +118 -0
  11. package/dist/bundled-resources/extensions/tmux-agent-manager/launch-profile.js.map +1 -0
  12. package/dist/bundled-resources/extensions/tmux-agent-manager/launch-profile.ts +169 -0
  13. package/dist/bundled-resources/extensions/tmux-agent-manager/templates/builder-validator.json +1 -1
  14. package/dist/bundled-resources/extensions/tmux-agent-manager/templates/provider-prompt-smoke.json +1 -1
  15. package/dist/bundled-resources/skills/pi-harness-learning/SKILL.md +13 -7
  16. package/dist/bundled-resources/skills/worker-profile-writer/SKILL.md +11 -11
  17. package/dist/core/agent-paths.d.ts +2 -0
  18. package/dist/core/agent-paths.d.ts.map +1 -1
  19. package/dist/core/agent-paths.js +7 -0
  20. package/dist/core/agent-paths.js.map +1 -1
  21. package/dist/core/agent-session.d.ts +11 -41
  22. package/dist/core/agent-session.d.ts.map +1 -1
  23. package/dist/core/agent-session.js +98 -161
  24. package/dist/core/agent-session.js.map +1 -1
  25. package/dist/core/autonomy/envelope-enforcement.d.ts +6 -1
  26. package/dist/core/autonomy/envelope-enforcement.d.ts.map +1 -1
  27. package/dist/core/autonomy/envelope-enforcement.js +26 -25
  28. package/dist/core/autonomy/envelope-enforcement.js.map +1 -1
  29. package/dist/core/autonomy/lane-private-paths.d.ts.map +1 -1
  30. package/dist/core/autonomy/lane-private-paths.js +2 -1
  31. package/dist/core/autonomy/lane-private-paths.js.map +1 -1
  32. package/dist/core/autonomy/lane-tool-surface.d.ts +8 -8
  33. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  34. package/dist/core/autonomy/lane-tool-surface.js +45 -30
  35. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  36. package/dist/core/autonomy/worker-session-private-scope.d.ts +12 -0
  37. package/dist/core/autonomy/worker-session-private-scope.d.ts.map +1 -0
  38. package/dist/core/autonomy/worker-session-private-scope.js +42 -0
  39. package/dist/core/autonomy/worker-session-private-scope.js.map +1 -0
  40. package/dist/core/autonomy/worker-tool-adapter-registry.d.ts +65 -0
  41. package/dist/core/autonomy/worker-tool-adapter-registry.d.ts.map +1 -0
  42. package/dist/core/autonomy/worker-tool-adapter-registry.js +145 -0
  43. package/dist/core/autonomy/worker-tool-adapter-registry.js.map +1 -0
  44. package/dist/core/background-lane-controller.d.ts +9 -1
  45. package/dist/core/background-lane-controller.d.ts.map +1 -1
  46. package/dist/core/background-lane-controller.js +76 -6
  47. package/dist/core/background-lane-controller.js.map +1 -1
  48. package/dist/core/background-tool-task-controller.d.ts +23 -2
  49. package/dist/core/background-tool-task-controller.d.ts.map +1 -1
  50. package/dist/core/background-tool-task-controller.js +132 -17
  51. package/dist/core/background-tool-task-controller.js.map +1 -1
  52. package/dist/core/context/long-term-memory-trigger.d.ts +3 -1
  53. package/dist/core/context/long-term-memory-trigger.d.ts.map +1 -1
  54. package/dist/core/context/long-term-memory-trigger.js +1 -1
  55. package/dist/core/context/long-term-memory-trigger.js.map +1 -1
  56. package/dist/core/context/okf-memory-provider.d.ts +3 -0
  57. package/dist/core/context/okf-memory-provider.d.ts.map +1 -1
  58. package/dist/core/context/okf-memory-provider.js +66 -31
  59. package/dist/core/context/okf-memory-provider.js.map +1 -1
  60. package/dist/core/context/okf-memory.d.ts +18 -1
  61. package/dist/core/context/okf-memory.d.ts.map +1 -1
  62. package/dist/core/context/okf-memory.js +48 -0
  63. package/dist/core/context/okf-memory.js.map +1 -1
  64. package/dist/core/cost-guard-controller.d.ts +37 -0
  65. package/dist/core/cost-guard-controller.d.ts.map +1 -0
  66. package/dist/core/cost-guard-controller.js +71 -0
  67. package/dist/core/cost-guard-controller.js.map +1 -0
  68. package/dist/core/cost-guard.d.ts +9 -4
  69. package/dist/core/cost-guard.d.ts.map +1 -1
  70. package/dist/core/cost-guard.js +7 -3
  71. package/dist/core/cost-guard.js.map +1 -1
  72. package/dist/core/delegation/worker-agent-control.d.ts +4 -0
  73. package/dist/core/delegation/worker-agent-control.d.ts.map +1 -1
  74. package/dist/core/delegation/worker-agent-control.js.map +1 -1
  75. package/dist/core/delegation/worker-attempt-executor.d.ts +1 -1
  76. package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -1
  77. package/dist/core/delegation/worker-attempt-executor.js +0 -1
  78. package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
  79. package/dist/core/delegation/worker-authority-resolver.d.ts +16 -3
  80. package/dist/core/delegation/worker-authority-resolver.d.ts.map +1 -1
  81. package/dist/core/delegation/worker-authority-resolver.js +114 -55
  82. package/dist/core/delegation/worker-authority-resolver.js.map +1 -1
  83. package/dist/core/delegation/worker-claim.d.ts +1 -2
  84. package/dist/core/delegation/worker-claim.d.ts.map +1 -1
  85. package/dist/core/delegation/worker-claim.js.map +1 -1
  86. package/dist/core/delegation/worker-delegation-controller.d.ts +19 -6
  87. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
  88. package/dist/core/delegation/worker-delegation-controller.js +125 -40
  89. package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
  90. package/dist/core/delegation/worker-delegation-request.d.ts +3 -3
  91. package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
  92. package/dist/core/delegation/worker-delegation-request.js +13 -19
  93. package/dist/core/delegation/worker-delegation-request.js.map +1 -1
  94. package/dist/core/delegation/worker-execution-policy.d.ts +3 -2
  95. package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -1
  96. package/dist/core/delegation/worker-execution-policy.js +54 -39
  97. package/dist/core/delegation/worker-execution-policy.js.map +1 -1
  98. package/dist/core/delegation/worker-fleet-limits.d.ts +3 -3
  99. package/dist/core/delegation/worker-fleet-limits.d.ts.map +1 -1
  100. package/dist/core/delegation/worker-fleet-limits.js +7 -7
  101. package/dist/core/delegation/worker-fleet-limits.js.map +1 -1
  102. package/dist/core/delegation/worker-machine-scope.d.ts +12 -0
  103. package/dist/core/delegation/worker-machine-scope.d.ts.map +1 -0
  104. package/dist/core/delegation/worker-machine-scope.js +38 -0
  105. package/dist/core/delegation/worker-machine-scope.js.map +1 -0
  106. package/dist/core/delegation/worker-notification-coordinator.d.ts +10 -0
  107. package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -1
  108. package/dist/core/delegation/worker-notification-coordinator.js +69 -3
  109. package/dist/core/delegation/worker-notification-coordinator.js.map +1 -1
  110. package/dist/core/delegation/worker-recovery-coordinator.d.ts.map +1 -1
  111. package/dist/core/delegation/worker-recovery-coordinator.js +6 -1
  112. package/dist/core/delegation/worker-recovery-coordinator.js.map +1 -1
  113. package/dist/core/delegation/worker-runner.d.ts +5 -7
  114. package/dist/core/delegation/worker-runner.d.ts.map +1 -1
  115. package/dist/core/delegation/worker-runner.js +1 -4
  116. package/dist/core/delegation/worker-runner.js.map +1 -1
  117. package/dist/core/delegation/worker-write-reservation-coordinator.d.ts +3 -2
  118. package/dist/core/delegation/worker-write-reservation-coordinator.d.ts.map +1 -1
  119. package/dist/core/delegation/worker-write-reservation-coordinator.js +50 -25
  120. package/dist/core/delegation/worker-write-reservation-coordinator.js.map +1 -1
  121. package/dist/core/durable-custom-message-turn-controller.d.ts +6 -0
  122. package/dist/core/durable-custom-message-turn-controller.d.ts.map +1 -1
  123. package/dist/core/durable-custom-message-turn-controller.js +38 -15
  124. package/dist/core/durable-custom-message-turn-controller.js.map +1 -1
  125. package/dist/core/extension-binding-controller.d.ts +5 -1
  126. package/dist/core/extension-binding-controller.d.ts.map +1 -1
  127. package/dist/core/extension-binding-controller.js +15 -0
  128. package/dist/core/extension-binding-controller.js.map +1 -1
  129. package/dist/core/extensions/factory-runtime.d.ts.map +1 -1
  130. package/dist/core/extensions/factory-runtime.js +5 -0
  131. package/dist/core/extensions/factory-runtime.js.map +1 -1
  132. package/dist/core/extensions/runner.d.ts.map +1 -1
  133. package/dist/core/extensions/runner.js +1 -0
  134. package/dist/core/extensions/runner.js.map +1 -1
  135. package/dist/core/extensions/types.d.ts +8 -4
  136. package/dist/core/extensions/types.d.ts.map +1 -1
  137. package/dist/core/extensions/types.js.map +1 -1
  138. package/dist/core/foreground-terminal-handoff-controller.d.ts +31 -0
  139. package/dist/core/foreground-terminal-handoff-controller.d.ts.map +1 -1
  140. package/dist/core/foreground-terminal-handoff-controller.js +239 -55
  141. package/dist/core/foreground-terminal-handoff-controller.js.map +1 -1
  142. package/dist/core/goals/goal-session-controller.d.ts +2 -0
  143. package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
  144. package/dist/core/goals/goal-session-controller.js +8 -0
  145. package/dist/core/goals/goal-session-controller.js.map +1 -1
  146. package/dist/core/goals/goal-tool-core.d.ts +5 -4
  147. package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
  148. package/dist/core/goals/goal-tool-core.js +23 -19
  149. package/dist/core/goals/goal-tool-core.js.map +1 -1
  150. package/dist/core/learning/auto-learn-settings.d.ts +84 -0
  151. package/dist/core/learning/auto-learn-settings.d.ts.map +1 -0
  152. package/dist/core/learning/auto-learn-settings.js +66 -0
  153. package/dist/core/learning/auto-learn-settings.js.map +1 -0
  154. package/dist/core/learning/learning-audit.d.ts +5 -1
  155. package/dist/core/learning/learning-audit.d.ts.map +1 -1
  156. package/dist/core/learning/learning-audit.js +32 -1
  157. package/dist/core/learning/learning-audit.js.map +1 -1
  158. package/dist/core/learning/reflection-engine.d.ts +24 -0
  159. package/dist/core/learning/reflection-engine.d.ts.map +1 -1
  160. package/dist/core/learning/reflection-engine.js +104 -8
  161. package/dist/core/learning/reflection-engine.js.map +1 -1
  162. package/dist/core/local-prefix-warm-controller.d.ts +24 -0
  163. package/dist/core/local-prefix-warm-controller.d.ts.map +1 -0
  164. package/dist/core/local-prefix-warm-controller.js +79 -0
  165. package/dist/core/local-prefix-warm-controller.js.map +1 -0
  166. package/dist/core/memory/okf-project-memory-store.d.ts +28 -0
  167. package/dist/core/memory/okf-project-memory-store.d.ts.map +1 -0
  168. package/dist/core/memory/okf-project-memory-store.js +111 -0
  169. package/dist/core/memory/okf-project-memory-store.js.map +1 -0
  170. package/dist/core/memory/providers/file-store.d.ts +44 -1
  171. package/dist/core/memory/providers/file-store.d.ts.map +1 -1
  172. package/dist/core/memory/providers/file-store.js +341 -24
  173. package/dist/core/memory/providers/file-store.js.map +1 -1
  174. package/dist/core/memory/worker-memory-tools.d.ts +5 -0
  175. package/dist/core/memory/worker-memory-tools.d.ts.map +1 -0
  176. package/dist/core/memory/worker-memory-tools.js +5 -0
  177. package/dist/core/memory/worker-memory-tools.js.map +1 -0
  178. package/dist/core/memory-controller.d.ts +10 -1
  179. package/dist/core/memory-controller.d.ts.map +1 -1
  180. package/dist/core/memory-controller.js +72 -8
  181. package/dist/core/memory-controller.js.map +1 -1
  182. package/dist/core/model-capability.d.ts +7 -0
  183. package/dist/core/model-capability.d.ts.map +1 -1
  184. package/dist/core/model-capability.js +12 -0
  185. package/dist/core/model-capability.js.map +1 -1
  186. package/dist/core/model-registry.d.ts.map +1 -1
  187. package/dist/core/model-registry.js +2 -10
  188. package/dist/core/model-registry.js.map +1 -1
  189. package/dist/core/model-router-controller.d.ts +3 -2
  190. package/dist/core/model-router-controller.d.ts.map +1 -1
  191. package/dist/core/model-router-controller.js +3 -2
  192. package/dist/core/model-router-controller.js.map +1 -1
  193. package/dist/core/orchestration/contracts.d.ts +16 -12
  194. package/dist/core/orchestration/contracts.d.ts.map +1 -1
  195. package/dist/core/orchestration/contracts.js +2 -2
  196. package/dist/core/orchestration/contracts.js.map +1 -1
  197. package/dist/core/orchestration/lane-tool-manifests.d.ts +2 -2
  198. package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
  199. package/dist/core/orchestration/lane-tool-manifests.js +6 -1
  200. package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
  201. package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
  202. package/dist/core/orchestration/profile-registry.js +14 -0
  203. package/dist/core/orchestration/profile-registry.js.map +1 -1
  204. package/dist/core/orchestration/task-profile-writer.d.ts +7 -4
  205. package/dist/core/orchestration/task-profile-writer.d.ts.map +1 -1
  206. package/dist/core/orchestration/task-profile-writer.js +71 -59
  207. package/dist/core/orchestration/task-profile-writer.js.map +1 -1
  208. package/dist/core/orchestration/thinking-level-schema.d.ts +7 -0
  209. package/dist/core/orchestration/thinking-level-schema.d.ts.map +1 -0
  210. package/dist/core/orchestration/thinking-level-schema.js +19 -0
  211. package/dist/core/orchestration/thinking-level-schema.js.map +1 -0
  212. package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -1
  213. package/dist/core/orchestration/worker-execution-contract.js +12 -5
  214. package/dist/core/orchestration/worker-execution-contract.js.map +1 -1
  215. package/dist/core/provider-prompt-contracts.d.ts +1 -4
  216. package/dist/core/provider-prompt-contracts.d.ts.map +1 -1
  217. package/dist/core/provider-prompt-contracts.js +13 -29
  218. package/dist/core/provider-prompt-contracts.js.map +1 -1
  219. package/dist/core/provider-request-context-controller.d.ts +2 -0
  220. package/dist/core/provider-request-context-controller.d.ts.map +1 -1
  221. package/dist/core/provider-request-context-controller.js +10 -3
  222. package/dist/core/provider-request-context-controller.js.map +1 -1
  223. package/dist/core/reflection-controller.d.ts +63 -27
  224. package/dist/core/reflection-controller.d.ts.map +1 -1
  225. package/dist/core/reflection-controller.js +300 -132
  226. package/dist/core/reflection-controller.js.map +1 -1
  227. package/dist/core/runtime-builder.d.ts +1 -0
  228. package/dist/core/runtime-builder.d.ts.map +1 -1
  229. package/dist/core/runtime-builder.js +25 -14
  230. package/dist/core/runtime-builder.js.map +1 -1
  231. package/dist/core/secrets/credential-exposure-guard.d.ts.map +1 -1
  232. package/dist/core/secrets/credential-exposure-guard.js +55 -10
  233. package/dist/core/secrets/credential-exposure-guard.js.map +1 -1
  234. package/dist/core/session-role.d.ts +6 -8
  235. package/dist/core/session-role.d.ts.map +1 -1
  236. package/dist/core/session-role.js +8 -18
  237. package/dist/core/session-role.js.map +1 -1
  238. package/dist/core/settings-manager.d.ts +13 -16
  239. package/dist/core/settings-manager.d.ts.map +1 -1
  240. package/dist/core/settings-manager.js +53 -50
  241. package/dist/core/settings-manager.js.map +1 -1
  242. package/dist/core/skill-vault.d.ts +15 -0
  243. package/dist/core/skill-vault.d.ts.map +1 -1
  244. package/dist/core/skill-vault.js +79 -45
  245. package/dist/core/skill-vault.js.map +1 -1
  246. package/dist/core/skills.d.ts +3 -0
  247. package/dist/core/skills.d.ts.map +1 -1
  248. package/dist/core/skills.js +6 -6
  249. package/dist/core/skills.js.map +1 -1
  250. package/dist/core/system-prompt-builder.d.ts +2 -0
  251. package/dist/core/system-prompt-builder.d.ts.map +1 -1
  252. package/dist/core/system-prompt-builder.js +52 -12
  253. package/dist/core/system-prompt-builder.js.map +1 -1
  254. package/dist/core/system-prompt.js +1 -1
  255. package/dist/core/system-prompt.js.map +1 -1
  256. package/dist/core/tool-capability-policy.d.ts +3 -0
  257. package/dist/core/tool-capability-policy.d.ts.map +1 -1
  258. package/dist/core/tool-capability-policy.js +13 -2
  259. package/dist/core/tool-capability-policy.js.map +1 -1
  260. package/dist/core/toolkit/script-runner.d.ts +2 -1
  261. package/dist/core/toolkit/script-runner.d.ts.map +1 -1
  262. package/dist/core/toolkit/script-runner.js +10 -2
  263. package/dist/core/toolkit/script-runner.js.map +1 -1
  264. package/dist/core/tools/delegate-status.d.ts +3 -1
  265. package/dist/core/tools/delegate-status.d.ts.map +1 -1
  266. package/dist/core/tools/delegate-status.js +5 -1
  267. package/dist/core/tools/delegate-status.js.map +1 -1
  268. package/dist/core/tools/delegate.d.ts +4 -13
  269. package/dist/core/tools/delegate.d.ts.map +1 -1
  270. package/dist/core/tools/delegate.js +173 -73
  271. package/dist/core/tools/delegate.js.map +1 -1
  272. package/dist/core/tools/goal.d.ts +3 -4
  273. package/dist/core/tools/goal.d.ts.map +1 -1
  274. package/dist/core/tools/goal.js +24 -7
  275. package/dist/core/tools/goal.js.map +1 -1
  276. package/dist/core/tools/profile-writer.d.ts +2 -8
  277. package/dist/core/tools/profile-writer.d.ts.map +1 -1
  278. package/dist/core/tools/profile-writer.js +6 -18
  279. package/dist/core/tools/profile-writer.js.map +1 -1
  280. package/dist/core/tools/run-toolkit-script.d.ts +1 -1
  281. package/dist/core/tools/run-toolkit-script.d.ts.map +1 -1
  282. package/dist/core/tools/run-toolkit-script.js +2 -2
  283. package/dist/core/tools/run-toolkit-script.js.map +1 -1
  284. package/dist/core/tools/skill-audit.d.ts +28 -1
  285. package/dist/core/tools/skill-audit.d.ts.map +1 -1
  286. package/dist/core/tools/skill-audit.js +56 -12
  287. package/dist/core/tools/skill-audit.js.map +1 -1
  288. package/dist/core/tools/skill.d.ts +12 -1
  289. package/dist/core/tools/skill.d.ts.map +1 -1
  290. package/dist/core/tools/skill.js +52 -0
  291. package/dist/core/tools/skill.js.map +1 -1
  292. package/dist/core/tools/skillify.d.ts.map +1 -1
  293. package/dist/core/tools/skillify.js +16 -7
  294. package/dist/core/tools/skillify.js.map +1 -1
  295. package/dist/core/tools/task-steps.js +1 -1
  296. package/dist/core/tools/task-steps.js.map +1 -1
  297. package/dist/core/tools/tmux-dispatch.d.ts +4 -16
  298. package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
  299. package/dist/core/tools/tmux-dispatch.js +5 -20
  300. package/dist/core/tools/tmux-dispatch.js.map +1 -1
  301. package/dist/core/tools/tool-task.d.ts +1 -0
  302. package/dist/core/tools/tool-task.d.ts.map +1 -1
  303. package/dist/core/tools/tool-task.js +13 -8
  304. package/dist/core/tools/tool-task.js.map +1 -1
  305. package/dist/core/util/atomic-file.d.ts +2 -0
  306. package/dist/core/util/atomic-file.d.ts.map +1 -1
  307. package/dist/core/util/atomic-file.js +4 -0
  308. package/dist/core/util/atomic-file.js.map +1 -1
  309. package/dist/core/worktree-sync/codes.d.ts +1 -2
  310. package/dist/core/worktree-sync/codes.d.ts.map +1 -1
  311. package/dist/core/worktree-sync/codes.js +1 -2
  312. package/dist/core/worktree-sync/codes.js.map +1 -1
  313. package/dist/core/worktree-sync/lane-gate.d.ts +4 -8
  314. package/dist/core/worktree-sync/lane-gate.d.ts.map +1 -1
  315. package/dist/core/worktree-sync/lane-gate.js +5 -51
  316. package/dist/core/worktree-sync/lane-gate.js.map +1 -1
  317. package/dist/index.d.ts +5 -0
  318. package/dist/index.d.ts.map +1 -1
  319. package/dist/index.js +7 -0
  320. package/dist/index.js.map +1 -1
  321. package/dist/modes/interactive/auto-learn-controller.d.ts +6 -7
  322. package/dist/modes/interactive/auto-learn-controller.d.ts.map +1 -1
  323. package/dist/modes/interactive/auto-learn-controller.js +32 -207
  324. package/dist/modes/interactive/auto-learn-controller.js.map +1 -1
  325. package/dist/modes/interactive/autonomy-commands.js +2 -2
  326. package/dist/modes/interactive/autonomy-commands.js.map +1 -1
  327. package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -1
  328. package/dist/modes/interactive/components/activity-lane.js +12 -23
  329. package/dist/modes/interactive/components/activity-lane.js.map +1 -1
  330. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  331. package/dist/modes/interactive/components/custom-message.js +142 -1
  332. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  333. package/dist/modes/interactive/components/fitness-role-selector.d.ts.map +1 -1
  334. package/dist/modes/interactive/components/fitness-role-selector.js +2 -2
  335. package/dist/modes/interactive/components/fitness-role-selector.js.map +1 -1
  336. package/dist/modes/interactive/components/footer.js +1 -1
  337. package/dist/modes/interactive/components/footer.js.map +1 -1
  338. package/dist/modes/interactive/components/settings-selector.d.ts +4 -0
  339. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  340. package/dist/modes/interactive/components/settings-selector.js +150 -73
  341. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  342. package/dist/modes/interactive/report-commands.d.ts.map +1 -1
  343. package/dist/modes/interactive/report-commands.js +8 -4
  344. package/dist/modes/interactive/report-commands.js.map +1 -1
  345. package/dist/modes/interactive/settings-selector-flow.d.ts.map +1 -1
  346. package/dist/modes/interactive/settings-selector-flow.js +10 -0
  347. package/dist/modes/interactive/settings-selector-flow.js.map +1 -1
  348. package/docs/extensions.md +8 -0
  349. package/docs/harness-architecture.md +28 -32
  350. package/docs/index.md +1 -1
  351. package/docs/process-matrix.md +8 -6
  352. package/docs/resources.md +1 -1
  353. package/docs/settings.md +61 -51
  354. package/docs/tmux-agent-manager.md +47 -40
  355. package/docs/usage.md +1 -1
  356. package/docs/worker-profiles.md +8 -6
  357. package/docs/worktree-sync.md +26 -20
  358. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  359. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  360. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  361. package/examples/extensions/sandbox/package-lock.json +2 -2
  362. package/examples/extensions/sandbox/package.json +1 -1
  363. package/examples/extensions/with-deps/package-lock.json +2 -2
  364. package/examples/extensions/with-deps/package.json +1 -1
  365. package/npm-shrinkwrap.json +12 -12
  366. package/package.json +4 -4
  367. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts +0 -133
  368. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts.map +0 -1
  369. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js +0 -199
  370. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js.map +0 -1
  371. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.ts +0 -312
@@ -14,7 +14,12 @@ export declare function extractToolPathArguments(toolName: string, params: unkno
14
14
  export declare function isPathWithinEnvelope(envelope: CapabilityEnvelope, rawPath: string, cwd: string): boolean;
15
15
  export interface EnvelopeScopedTool {
16
16
  name: string;
17
- execute: (...args: unknown[]) => unknown;
17
+ /**
18
+ * The `never` parameter keeps this structural boundary compatible with both the synchronous
19
+ * fixtures used by the path-policy tests and the strongly typed async `AgentTool.execute`
20
+ * implementations. The wrapper itself preserves the concrete execute signature below.
21
+ */
22
+ execute: (...args: never[]) => unknown;
18
23
  }
19
24
  /**
20
25
  * Wrap a tool so path-bearing arguments are scope-checked when it RUNS, consulting canonical
@@ -1 +1 @@
1
- {"version":3,"file":"envelope-enforcement.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/envelope-enforcement.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAezD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,EAAE,CAiB9D;AAED,wFAAwF;AACxF,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,EAAE,CAwBpF;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAoCxG;AAED,MAAM,WAAW,kBAAkB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;CACzC;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,kBAAkB,EACrE,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,kBAAkB,EAC5B,GAAG,EAAE,MAAM,GACT,CAAC,CA8BH"}
1
+ {"version":3,"file":"envelope-enforcement.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/envelope-enforcement.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAezD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,EAAE,CAiB9D;AAED,wFAAwF;AACxF,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,EAAE,CAwBpF;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAoCxG;AAED,MAAM,WAAW,kBAAkB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC;CACvC;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,kBAAkB,EACrE,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,kBAAkB,EAC5B,GAAG,EAAE,MAAM,GACT,CAAC,CAgCH"}
@@ -120,34 +120,35 @@ export function isPathWithinEnvelope(envelope, rawPath, cwd) {
120
120
  * shape-identical; params are conventionally the second execute argument (toolCallId, params, …).
121
121
  */
122
122
  export function wrapToolWithEnvelopeScope(tool, envelope, cwd) {
123
- return {
124
- ...tool,
125
- execute: (...args) => {
126
- const params = args[1];
127
- const pathAccess = resolveToolCallPathAccess(envelope.capabilities, tool.name, params);
128
- if (pathAccess !== "none") {
129
- for (const rawPath of extractToolPathArguments(tool.name, params)) {
130
- if (!isPathWithinEnvelope(envelope, rawPath, cwd)) {
131
- return {
132
- content: [
133
- {
134
- type: "text",
135
- text: `envelope_path_denied: "${rawPath}" is outside envelope ${envelope.id}'s path scope. The tool was NOT run.`,
136
- },
137
- ],
138
- details: {
139
- outcome: "envelope_path_denied",
140
- tool: tool.name,
141
- path: rawPath,
142
- envelopeId: envelope.id,
123
+ const execute = (...args) => {
124
+ const params = args[1];
125
+ const pathAccess = resolveToolCallPathAccess(envelope.capabilities, tool.name, params);
126
+ if (pathAccess !== "none") {
127
+ for (const rawPath of extractToolPathArguments(tool.name, params)) {
128
+ if (!isPathWithinEnvelope(envelope, rawPath, cwd)) {
129
+ return {
130
+ content: [
131
+ {
132
+ type: "text",
133
+ text: `envelope_path_denied: "${rawPath}" is outside envelope ${envelope.id}'s path scope. The tool was NOT run.`,
143
134
  },
144
- isError: true,
145
- };
146
- }
135
+ ],
136
+ details: {
137
+ outcome: "envelope_path_denied",
138
+ tool: tool.name,
139
+ path: rawPath,
140
+ envelopeId: envelope.id,
141
+ },
142
+ isError: true,
143
+ };
147
144
  }
148
145
  }
149
- return tool.execute(...args);
150
- },
146
+ }
147
+ return tool.execute(...args);
148
+ };
149
+ return {
150
+ ...tool,
151
+ execute,
151
152
  };
152
153
  }
153
154
  //# sourceMappingURL=envelope-enforcement.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"envelope-enforcement.js","sourceRoot":"","sources":["../../../src/core/autonomy/envelope-enforcement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAEzE,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;;;;;;GAOG;AAEH,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,CAAU,CAAC;AAC3G,MAAM,uBAAuB,GAAG,CAAC,OAAO,EAAE,OAAO,CAAU,CAAC;AAE5D,MAAM,UAAU,oBAAoB,CAAC,MAAe;I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YAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YACvB,MAAM,UAAU,GAAG,yBAAyB,CAAC,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YACvF,IAAI,UAAU,KAAK,MAAM,EAAE,CAAC;gBAC3B,KAAK,MAAM,OAAO,IAAI,wBAAwB,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC;oBACnE,IAAI,CAAC,oBAAoB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC;wBACnD,OAAO;4BACN,OAAO,EAAE;gCACR;oCACC,IAAI,EAAE,MAAM;oCACZ,IAAI,EAAE,0BAA0B,OAAO,yBAAyB,QAAQ,CAAC,EAAE,sCAAsC;iCACjH;6BACD;4BACD,OAAO,EAAE;gCACR,OAAO,EAAE,sBAAsB;gCAC/B,IAAI,EAAE,IAAI,CAAC,IAAI;gCACf,IAAI,EAAE,OAAO;gCACb,UAAU,EAAE,QAAQ,CAAC,EAAE;6BACvB;4BACD,OAAO,EAAE,IAAI;yBACb,CAAC;oBACH,CAAC;gBACF,CAAC;YACF,CAAC;YACD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;QAC9B,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { resolve } from \"node:path\";\nimport { resolveToolCallPathAccess } from \"../tool-capability-policy.ts\";\nimport type { CapabilityEnvelope } from \"./contracts.ts\";\nimport { isPathWithinScope, safeRealpathSync } from \"./path-scope.ts\";\n\n/**\n * Tool-level envelope enforcement (G2 prerequisite for code-writing workers): the capability\n * envelope's `allowedPaths`/`deniedPaths` were previously VALIDATION-ONLY — recorded on the\n * envelope but never checked when a tool actually ran. This module wraps tools so path-bearing\n * arguments are checked AT EXECUTION TIME, structurally refusing out-of-scope paths the same way\n * a failed script can never look like success: the refusal is an isError result with a stable\n * outcome code, never a silent no-op.\n */\n\nconst PATH_ARGUMENT_KEYS = [\"path\", \"file_path\", \"filePath\", \"cwd\", \"directory\", \"dir\", \"target\"] as const;\nconst PATH_LIST_ARGUMENT_KEYS = [\"paths\", \"files\"] as const;\n\nexport function extractPathArguments(params: unknown): string[] {\n\tif (!params || typeof params !== \"object\") return [];\n\tconst record = params as Record<string, unknown>;\n\tconst found: string[] = [];\n\tfor (const key of PATH_ARGUMENT_KEYS) {\n\t\tconst value = record[key];\n\t\tif (typeof value === \"string\" && value.trim()) found.push(value.trim());\n\t}\n\tfor (const key of PATH_LIST_ARGUMENT_KEYS) {\n\t\tconst value = record[key];\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (const entry of value) {\n\t\t\t\tif (typeof entry === \"string\" && entry.trim()) found.push(entry.trim());\n\t\t\t}\n\t\t}\n\t}\n\treturn found;\n}\n\n/** Tool-aware path projection shared by every envelope/gateway enforcement boundary. */\nexport function extractToolPathArguments(toolName: string, params: unknown): string[] {\n\tconst normalizedToolName = toolName.toLowerCase();\n\tconst paths = extractPathArguments(params);\n\tif (normalizedToolName === \"secret_store\" && params && typeof params === \"object\") {\n\t\tconst record = params as Record<string, unknown>;\n\t\tif (record.action === \"migrate\" && Array.isArray(record.sources)) {\n\t\t\tfor (const source of record.sources) {\n\t\t\t\tif (!source || typeof source !== \"object\" || !(\"path\" in source)) continue;\n\t\t\t\tconst sourcePath = source.path;\n\t\t\t\tif (typeof sourcePath === \"string\" && sourcePath.trim()) paths.push(sourcePath.trim());\n\t\t\t}\n\t\t}\n\t\tif (record.action === \"discover\" && paths.length === 0) paths.push(\".\");\n\t}\n\tif (\n\t\tpaths.length === 0 &&\n\t\t(normalizedToolName === \"find\" ||\n\t\t\tnormalizedToolName === \"grep\" ||\n\t\t\tnormalizedToolName === \"ls\" ||\n\t\t\tnormalizedToolName === \"pipeline\")\n\t) {\n\t\tpaths.push(\".\");\n\t}\n\treturn paths;\n}\n\n/**\n * Deny wins over allow; an empty/absent allow list means \"no positive scope restriction\"\n * (only denies apply) — mirroring the resource-profile filter semantics.\n *\n * Both the target and every scope root are resolved through the real filesystem\n * (symlinks expanded in the existing prefix) before comparison: a pre-existing symlink\n * under an allowed root cannot smuggle a write outside the scope, and a shortcut into a\n * denied subtree is still denied. An unresolvable target fails closed.\n */\nexport function isPathWithinEnvelope(envelope: CapabilityEnvelope, rawPath: string, cwd: string): boolean {\n\tconst lexicalTarget = resolve(cwd, rawPath);\n\tconst allowed = envelope.allowedPaths ?? [];\n\tif (allowed.length > 0) {\n\t\tconst couldBeAllowed = allowed.some((root) => {\n\t\t\tconst lexicalRoot = resolve(cwd, root);\n\t\t\tif (isPathWithinScope(lexicalTarget, lexicalRoot)) return true;\n\t\t\ttry {\n\t\t\t\treturn isPathWithinScope(lexicalTarget, safeRealpathSync(lexicalRoot));\n\t\t\t} catch {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t});\n\t\tif (!couldBeAllowed) return false;\n\t}\n\tlet target: string;\n\ttry {\n\t\ttarget = safeRealpathSync(lexicalTarget);\n\t} catch {\n\t\treturn false;\n\t}\n\tfor (const denied of envelope.deniedPaths ?? []) {\n\t\ttry {\n\t\t\tif (isPathWithinScope(target, safeRealpathSync(resolve(cwd, denied)))) return false;\n\t\t} catch {\n\t\t\t// Mirror checkPathScope: an unresolvable deny root cannot match anything.\n\t\t}\n\t}\n\tif (allowed.length === 0) return true;\n\treturn allowed.some((root) => {\n\t\ttry {\n\t\t\treturn isPathWithinScope(target, safeRealpathSync(resolve(cwd, root)));\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t});\n}\n\nexport interface EnvelopeScopedTool {\n\tname: string;\n\texecute: (...args: unknown[]) => unknown;\n}\n\n/**\n * Wrap a tool so path-bearing arguments are scope-checked when it RUNS, consulting canonical\n * tool capability policy so only tools whose policy declares path-scope access\n * (resolveToolCallPathAccess !== \"none\") are checked against envelope boundaries. The wrapped tool is\n * shape-identical; params are conventionally the second execute argument (toolCallId, params, …).\n */\nexport function wrapToolWithEnvelopeScope<T extends EnvelopeScopedTool>(\n\ttool: T,\n\tenvelope: CapabilityEnvelope,\n\tcwd: string,\n): T {\n\treturn {\n\t\t...tool,\n\t\texecute: (...args: unknown[]) => {\n\t\t\tconst params = args[1];\n\t\t\tconst pathAccess = resolveToolCallPathAccess(envelope.capabilities, tool.name, params);\n\t\t\tif (pathAccess !== \"none\") {\n\t\t\t\tfor (const rawPath of extractToolPathArguments(tool.name, params)) {\n\t\t\t\t\tif (!isPathWithinEnvelope(envelope, rawPath, cwd)) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\t\ttext: `envelope_path_denied: \"${rawPath}\" is outside envelope ${envelope.id}'s path scope. The tool was NOT run.`,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\toutcome: \"envelope_path_denied\",\n\t\t\t\t\t\t\t\ttool: tool.name,\n\t\t\t\t\t\t\t\tpath: rawPath,\n\t\t\t\t\t\t\t\tenvelopeId: envelope.id,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tisError: true,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tool.execute(...args);\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"envelope-enforcement.js","sourceRoot":"","sources":["../../../src/core/autonomy/envelope-enforcement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAEzE,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;;;;;;GAOG;AAEH,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,W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;;GAKG;AACH,MAAM,UAAU,yBAAyB,CACxC,IAAO,EACP,QAA4B,EAC5B,GAAW;IAGX,MAAM,OAAO,GAAG,CAAC,GAAG,IAAyB,EAAuB,EAAE;QACrE,MAAM,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACvB,MAAM,UAAU,GAAG,yBAAyB,CAAC,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACvF,IAAI,UAAU,KAAK,MAAM,EAAE,CAAC;YAC3B,KAAK,MAAM,OAAO,IAAI,wBAAwB,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC;gBACnE,IAAI,CAAC,oBAAoB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC;oBACnD,OAAO;wBACN,OAAO,EAAE;4BACR;gCACC,IAAI,EAAE,MAAM;gCACZ,IAAI,EAAE,0BAA0B,OAAO,yBAAyB,QAAQ,CAAC,EAAE,sCAAsC;6BACjH;yBACD;wBACD,OAAO,EAAE;4BACR,OAAO,EAAE,sBAAsB;4BAC/B,IAAI,EAAE,IAAI,CAAC,IAAI;4BACf,IAAI,EAAE,OAAO;4BACb,UAAU,EAAE,QAAQ,CAAC,EAAE;yBACvB;wBACD,OAAO,EAAE,IAAI;qBACU,CAAC;gBAC1B,CAAC;YACF,CAAC;QACF,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAwB,CAAC;IACrD,CAAC,CAAC;IACF,OAAO;QACN,GAAG,IAAI;QACP,OAAO;KACF,CAAC;AACR,CAAC","sourcesContent":["import { resolve } from \"node:path\";\nimport { resolveToolCallPathAccess } from \"../tool-capability-policy.ts\";\nimport type { CapabilityEnvelope } from \"./contracts.ts\";\nimport { isPathWithinScope, safeRealpathSync } from \"./path-scope.ts\";\n\n/**\n * Tool-level envelope enforcement (G2 prerequisite for code-writing workers): the capability\n * envelope's `allowedPaths`/`deniedPaths` were previously VALIDATION-ONLY — recorded on the\n * envelope but never checked when a tool actually ran. This module wraps tools so path-bearing\n * arguments are checked AT EXECUTION TIME, structurally refusing out-of-scope paths the same way\n * a failed script can never look like success: the refusal is an isError result with a stable\n * outcome code, never a silent no-op.\n */\n\nconst PATH_ARGUMENT_KEYS = [\"path\", \"file_path\", \"filePath\", \"cwd\", \"directory\", \"dir\", \"target\"] as const;\nconst PATH_LIST_ARGUMENT_KEYS = [\"paths\", \"files\"] as const;\n\nexport function extractPathArguments(params: unknown): string[] {\n\tif (!params || typeof params !== \"object\") return [];\n\tconst record = params as Record<string, unknown>;\n\tconst found: string[] = [];\n\tfor (const key of PATH_ARGUMENT_KEYS) {\n\t\tconst value = record[key];\n\t\tif (typeof value === \"string\" && value.trim()) found.push(value.trim());\n\t}\n\tfor (const key of PATH_LIST_ARGUMENT_KEYS) {\n\t\tconst value = record[key];\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (const entry of value) {\n\t\t\t\tif (typeof entry === \"string\" && entry.trim()) found.push(entry.trim());\n\t\t\t}\n\t\t}\n\t}\n\treturn found;\n}\n\n/** Tool-aware path projection shared by every envelope/gateway enforcement boundary. */\nexport function extractToolPathArguments(toolName: string, params: unknown): string[] {\n\tconst normalizedToolName = toolName.toLowerCase();\n\tconst paths = extractPathArguments(params);\n\tif (normalizedToolName === \"secret_store\" && params && typeof params === \"object\") {\n\t\tconst record = params as Record<string, unknown>;\n\t\tif (record.action === \"migrate\" && Array.isArray(record.sources)) {\n\t\t\tfor (const source of record.sources) {\n\t\t\t\tif (!source || typeof source !== \"object\" || !(\"path\" in source)) continue;\n\t\t\t\tconst sourcePath = source.path;\n\t\t\t\tif (typeof sourcePath === \"string\" && sourcePath.trim()) paths.push(sourcePath.trim());\n\t\t\t}\n\t\t}\n\t\tif (record.action === \"discover\" && paths.length === 0) paths.push(\".\");\n\t}\n\tif (\n\t\tpaths.length === 0 &&\n\t\t(normalizedToolName === \"find\" ||\n\t\t\tnormalizedToolName === \"grep\" ||\n\t\t\tnormalizedToolName === \"ls\" ||\n\t\t\tnormalizedToolName === \"pipeline\")\n\t) {\n\t\tpaths.push(\".\");\n\t}\n\treturn paths;\n}\n\n/**\n * Deny wins over allow; an empty/absent allow list means \"no positive scope restriction\"\n * (only denies apply) — mirroring the resource-profile filter semantics.\n *\n * Both the target and every scope root are resolved through the real filesystem\n * (symlinks expanded in the existing prefix) before comparison: a pre-existing symlink\n * under an allowed root cannot smuggle a write outside the scope, and a shortcut into a\n * denied subtree is still denied. An unresolvable target fails closed.\n */\nexport function isPathWithinEnvelope(envelope: CapabilityEnvelope, rawPath: string, cwd: string): boolean {\n\tconst lexicalTarget = resolve(cwd, rawPath);\n\tconst allowed = envelope.allowedPaths ?? [];\n\tif (allowed.length > 0) {\n\t\tconst couldBeAllowed = allowed.some((root) => {\n\t\t\tconst lexicalRoot = resolve(cwd, root);\n\t\t\tif (isPathWithinScope(lexicalTarget, lexicalRoot)) return true;\n\t\t\ttry {\n\t\t\t\treturn isPathWithinScope(lexicalTarget, safeRealpathSync(lexicalRoot));\n\t\t\t} catch {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t});\n\t\tif (!couldBeAllowed) return false;\n\t}\n\tlet target: string;\n\ttry {\n\t\ttarget = safeRealpathSync(lexicalTarget);\n\t} catch {\n\t\treturn false;\n\t}\n\tfor (const denied of envelope.deniedPaths ?? []) {\n\t\ttry {\n\t\t\tif (isPathWithinScope(target, safeRealpathSync(resolve(cwd, denied)))) return false;\n\t\t} catch {\n\t\t\t// Mirror checkPathScope: an unresolvable deny root cannot match anything.\n\t\t}\n\t}\n\tif (allowed.length === 0) return true;\n\treturn allowed.some((root) => {\n\t\ttry {\n\t\t\treturn isPathWithinScope(target, safeRealpathSync(resolve(cwd, root)));\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t});\n}\n\nexport interface EnvelopeScopedTool {\n\tname: string;\n\t/**\n\t * The `never` parameter keeps this structural boundary compatible with both the synchronous\n\t * fixtures used by the path-policy tests and the strongly typed async `AgentTool.execute`\n\t * implementations. The wrapper itself preserves the concrete execute signature below.\n\t */\n\texecute: (...args: never[]) => unknown;\n}\n\n/**\n * Wrap a tool so path-bearing arguments are scope-checked when it RUNS, consulting canonical\n * tool capability policy so only tools whose policy declares path-scope access\n * (resolveToolCallPathAccess !== \"none\") are checked against envelope boundaries. The wrapped tool is\n * shape-identical; params are conventionally the second execute argument (toolCallId, params, …).\n */\nexport function wrapToolWithEnvelopeScope<T extends EnvelopeScopedTool>(\n\ttool: T,\n\tenvelope: CapabilityEnvelope,\n\tcwd: string,\n): T {\n\ttype Execute = T[\"execute\"];\n\tconst execute = (...args: Parameters<Execute>): ReturnType<Execute> => {\n\t\tconst params = args[1];\n\t\tconst pathAccess = resolveToolCallPathAccess(envelope.capabilities, tool.name, params);\n\t\tif (pathAccess !== \"none\") {\n\t\t\tfor (const rawPath of extractToolPathArguments(tool.name, params)) {\n\t\t\t\tif (!isPathWithinEnvelope(envelope, rawPath, cwd)) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\ttext: `envelope_path_denied: \"${rawPath}\" is outside envelope ${envelope.id}'s path scope. The tool was NOT run.`,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\toutcome: \"envelope_path_denied\",\n\t\t\t\t\t\t\ttool: tool.name,\n\t\t\t\t\t\t\tpath: rawPath,\n\t\t\t\t\t\t\tenvelopeId: envelope.id,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tisError: true,\n\t\t\t\t\t} as ReturnType<Execute>;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn tool.execute(...args) as ReturnType<Execute>;\n\t};\n\treturn {\n\t\t...tool,\n\t\texecute,\n\t} as T;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"lane-private-paths.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/lane-private-paths.ts"],"names":[],"mappings":"AAGA,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAYjF"}
1
+ {"version":3,"file":"lane-private-paths.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/lane-private-paths.ts"],"names":[],"mappings":"AAGA,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAajF"}
@@ -1,10 +1,11 @@
1
1
  import path from "node:path";
2
- import { configFile, getWorkRoot, sessionsDir, stateDir } from "../agent-paths.js";
2
+ import { configFile, getWorkRoot, okfMemoryDir, sessionsDir, stateDir } from "../agent-paths.js";
3
3
  export function getPrivateLaneDeniedPaths(cwd, agentDir) {
4
4
  return [
5
5
  configFile(agentDir, "auth.json"),
6
6
  configFile(agentDir, "MEMORY.md"),
7
7
  configFile(agentDir, "USER.md"),
8
+ okfMemoryDir(agentDir),
8
9
  configFile(agentDir, "settings.json"),
9
10
  configFile(agentDir, "models.json"),
10
11
  sessionsDir(agentDir),
@@ -1 +1 @@
1
- {"version":3,"file":"lane-private-paths.js","sourceRoot":"","sources":["../../../src/core/autonomy/lane-private-paths.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEnF,MAAM,UAAU,yBAAyB,CAAC,GAAW,EAAE,QAAgB;IACtE,OAAO;QACN,UAAU,CAAC,QAAQ,EAAE,WAAW,CAAC;QACjC,UAAU,CAAC,QAAQ,EAAE,WAAW,CAAC;QACjC,UAAU,CAAC,QAAQ,EAAE,SAAS,CAAC;QAC/B,UAAU,CAAC,QAAQ,EAAE,eAAe,CAAC;QACrC,UAAU,CAAC,QAAQ,EAAE,aAAa,CAAC;QACnC,WAAW,CAAC,QAAQ,CAAC;QACrB,QAAQ,CAAC,QAAQ,CAAC;QAClB,WAAW,CAAC,QAAQ,CAAC;QACrB,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,eAAe,CAAC;KACtC,CAAC;AACH,CAAC","sourcesContent":["import path from \"node:path\";\nimport { configFile, getWorkRoot, sessionsDir, stateDir } from \"../agent-paths.ts\";\n\nexport function getPrivateLaneDeniedPaths(cwd: string, agentDir: string): string[] {\n\treturn [\n\t\tconfigFile(agentDir, \"auth.json\"),\n\t\tconfigFile(agentDir, \"MEMORY.md\"),\n\t\tconfigFile(agentDir, \"USER.md\"),\n\t\tconfigFile(agentDir, \"settings.json\"),\n\t\tconfigFile(agentDir, \"models.json\"),\n\t\tsessionsDir(agentDir),\n\t\tstateDir(agentDir),\n\t\tgetWorkRoot(agentDir),\n\t\tpath.join(cwd, \".pi\", \"settings.json\"),\n\t];\n}\n"]}
1
+ {"version":3,"file":"lane-private-paths.js","sourceRoot":"","sources":["../../../src/core/autonomy/lane-private-paths.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEjG,MAAM,UAAU,yBAAyB,CAAC,GAAW,EAAE,QAAgB;IACtE,OAAO;QACN,UAAU,CAAC,QAAQ,EAAE,WAAW,CAAC;QACjC,UAAU,CAAC,QAAQ,EAAE,WAAW,CAAC;QACjC,UAAU,CAAC,QAAQ,EAAE,SAAS,CAAC;QAC/B,YAAY,CAAC,QAAQ,CAAC;QACtB,UAAU,CAAC,QAAQ,EAAE,eAAe,CAAC;QACrC,UAAU,CAAC,QAAQ,EAAE,aAAa,CAAC;QACnC,WAAW,CAAC,QAAQ,CAAC;QACrB,QAAQ,CAAC,QAAQ,CAAC;QAClB,WAAW,CAAC,QAAQ,CAAC;QACrB,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,eAAe,CAAC;KACtC,CAAC;AACH,CAAC","sourcesContent":["import path from \"node:path\";\nimport { configFile, getWorkRoot, okfMemoryDir, sessionsDir, stateDir } from \"../agent-paths.ts\";\n\nexport function getPrivateLaneDeniedPaths(cwd: string, agentDir: string): string[] {\n\treturn [\n\t\tconfigFile(agentDir, \"auth.json\"),\n\t\tconfigFile(agentDir, \"MEMORY.md\"),\n\t\tconfigFile(agentDir, \"USER.md\"),\n\t\tokfMemoryDir(agentDir),\n\t\tconfigFile(agentDir, \"settings.json\"),\n\t\tconfigFile(agentDir, \"models.json\"),\n\t\tsessionsDir(agentDir),\n\t\tstateDir(agentDir),\n\t\tgetWorkRoot(agentDir),\n\t\tpath.join(cwd, \".pi\", \"settings.json\"),\n\t];\n}\n"]}
@@ -2,6 +2,7 @@ import type { AgentLoopConfig, AgentTool } from "@caupulican/pi-agent-core";
2
2
  import { CapabilityGateway, type GatewayInitialUsage, type SharedCapabilityBudget } from "../orchestration/capability-gateway.ts";
3
3
  import type { ExecutionGrant, OrchestrationExecutionPolicy, ToolCapabilityManifest } from "../orchestration/contracts.ts";
4
4
  import type { NormalizedProfile } from "../profile-registry.ts";
5
+ import type { WorkerToolAdapterRegistry } from "./worker-tool-adapter-registry.ts";
5
6
  export interface LaneToolSurface {
6
7
  /** Fresh tools owned by this lane only; no foreground tool instances or extension state leak in. */
7
8
  tools: AgentTool[];
@@ -13,7 +14,7 @@ export interface LaneToolSurface {
13
14
  deniedTools: string[];
14
15
  /** Explicit grants that bind to no classified lane candidate (opaque tools stay fail-closed). */
15
16
  unboundAllowPatterns: string[];
16
- /** Per-call path and capability gate for the isolated child loop. */
17
+ /** Per-call path and capability gate for the isolated worker loop. */
17
18
  beforeToolCall: NonNullable<AgentLoopConfig["beforeToolCall"]>;
18
19
  /** Canonical cumulative authority/budget meter for a compiled worker grant. */
19
20
  gateway?: CapabilityGateway;
@@ -38,20 +39,19 @@ export interface LaneToolSurfaceOptions {
38
39
  /** Compiled policy path. When present, it is the only authorization source for this surface. */
39
40
  grant?: ExecutionGrant;
40
41
  toolManifests?: readonly ToolCapabilityManifest[];
41
- /** Runtime-owned classified tools composed specifically for this lane (for example delegation control). */
42
- additionalTools?: readonly AgentTool[];
43
42
  /** Durable cumulative active usage to seed the compiled grant's gateway on resume. */
44
43
  initialUsage?: GatewayInitialUsage;
45
- /** Root-tree aggregate meter shared by this attempt and every descendant. */
44
+ /** Owner aggregate meter shared across retries and verification for this durable worker task. */
46
45
  sharedBudget?: SharedCapabilityBudget;
46
+ /** Host-owned fresh factories for worker-safe foreground/extension tools. */
47
+ workerToolAdapters?: WorkerToolAdapterRegistry;
47
48
  }
48
49
  /**
49
50
  * Materialize a fresh, fail-closed tool surface for one isolated lane.
50
51
  *
51
- * Admission selects classified built-ins plus runtime-owned injected controls. A compiled grant is
52
- * the only authority source for worker lanes; host shell and recursive delegation are materialized
53
- * when named by that grant. Write/edit additionally require the global write switch and a positive
54
- * path scope.
52
+ * Admission selects only tools this isolated lane can materialize. A compiled grant is the only
53
+ * authority source for worker lanes. Write/edit additionally require the global write switch and a
54
+ * positive path scope.
55
55
  */
56
56
  export declare function createLaneToolSurface(options: LaneToolSurfaceOptions): LaneToolSurface;
57
57
  //# sourceMappingURL=lane-tool-surface.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lane-tool-surface.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/lane-tool-surface.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAG5E,OAAO,EACN,iBAAiB,EAEjB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EACX,cAAc,EACd,4BAA4B,EAC5B,sBAAsB,EACtB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAA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CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAChD,4FAA4F;IAC5F,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,qGAAqG;IACrG,eAAe,CAAC,EAAE,4BAA4B,CAAC;IAC/C,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,mGAAmG;IACnG,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yGAAyG;IACzG,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,gGAAgG;IAChG,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,aAAa,CAAC,EAAE,SAAS,sBAAsB,EAAE,CAAC;IAClD,sFAAsF;IACtF,YAAY,CAAC,EAAE,mBAAmB,CAAC;IACnC,iGAAiG;IACjG,YAAY,CAAC,EAAE,sBAAsB,CAAC;IACtC,6EAA6E;IAC7E,kBAAkB,CAAC,EAAE,yBAAyB,CAAC;CAC/C;AAqFD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,GAAG,eAAe,CA8ItF"}
@@ -1,8 +1,10 @@
1
1
  import path from "node:path";
2
2
  import { Type } from "typebox";
3
3
  import { STABLE_SHELL_TOOL_NAME } from "../default-tool-surface.js";
4
+ import { WORKER_MEMORY_READ_TOOL_NAME } from "../memory/worker-memory-tools.js";
4
5
  import { CapabilityGateway, CapabilityGatewayDeniedError, } from "../orchestration/capability-gateway.js";
5
- import { wrapToolWithCredentialExposureGuard } from "../secrets/credential-exposure-guard.js";
6
+ import { wrapToolWithCredentialExposureGuard, } from "../secrets/credential-exposure-guard.js";
7
+ import { redactKnownSecrets } from "../security/secret-text.js";
6
8
  import { matchesResourceProfilePattern } from "../settings-manager.js";
7
9
  import { createBashTool } from "../tools/bash.js";
8
10
  import { createEditTool } from "../tools/edit.js";
@@ -10,14 +12,15 @@ import { FileMutationIntentController } from "../tools/file-mutation-intent.js";
10
12
  import { createFindTool } from "../tools/find.js";
11
13
  import { createGrepTool } from "../tools/grep.js";
12
14
  import { createLsTool } from "../tools/ls.js";
15
+ import { createPythonTool } from "../tools/python.js";
13
16
  import { createReadTool } from "../tools/read.js";
14
17
  import { createRunProcessTool } from "../tools/run-process.js";
15
18
  import { disposeShellExecutionSession } from "../tools/shell-execution-session.js";
16
19
  import { createWriteTool } from "../tools/write.js";
17
20
  import { evaluateToolGate } from "./gates.js";
18
21
  const READ_ONLY_LANE_TOOL_NAMES = ["read", "grep", "find", "ls"];
19
- const MEMORY_LANE_TOOL_NAME = "memory";
20
22
  const WRITE_LANE_TOOL_NAMES = ["write", "edit"];
23
+ const PYTHON_LANE_TOOL_NAME = "python";
21
24
  const PROCESS_LANE_TOOL_NAME = "run_process";
22
25
  const MAX_LANE_MEMORY_QUERY_CHARS = 4_096;
23
26
  const laneMemorySchema = Type.Object({
@@ -41,7 +44,7 @@ function strictLaneProfilePatterns(profile) {
41
44
  function resolveWriteRoots(cwd, writePaths) {
42
45
  return writePaths.map((entry) => (path.isAbsolute(entry) ? path.resolve(entry) : path.resolve(cwd, entry)));
43
46
  }
44
- function createLaneTools(cwd, names, fileMutationIntents, additionalTools, readMemory, executionPolicy, processMaxWallClockMs = 0, shellSessionKey, shellOutputDirectory) {
47
+ function createLaneTools(cwd, names, fileMutationIntents, privatePathBoundary, readMemory, executionPolicy, processMaxWallClockMs = 0, shellSessionKey, shellOutputDirectory, workerToolAdapters) {
45
48
  const factories = new Map([
46
49
  ["read", () => createReadTool(cwd)],
47
50
  ["grep", () => createGrepTool(cwd)],
@@ -49,6 +52,7 @@ function createLaneTools(cwd, names, fileMutationIntents, additionalTools, readM
49
52
  ["ls", () => createLsTool(cwd)],
50
53
  ["write", () => createWriteTool(cwd, { intentController: fileMutationIntents })],
51
54
  ["edit", () => createEditTool(cwd, { intentController: fileMutationIntents })],
55
+ [PYTHON_LANE_TOOL_NAME, () => createPythonTool(cwd)],
52
56
  ]);
53
57
  if (executionPolicy) {
54
58
  factories.set(PROCESS_LANE_TOOL_NAME, () => createRunProcessTool(cwd, { policy: executionPolicy, maxWallClockMs: processMaxWallClockMs }));
@@ -61,8 +65,8 @@ function createLaneTools(cwd, names, fileMutationIntents, additionalTools, readM
61
65
  }));
62
66
  }
63
67
  if (readMemory) {
64
- factories.set(MEMORY_LANE_TOOL_NAME, () => ({
65
- name: MEMORY_LANE_TOOL_NAME,
68
+ factories.set(WORKER_MEMORY_READ_TOOL_NAME, () => ({
69
+ name: WORKER_MEMORY_READ_TOOL_NAME,
66
70
  label: "Read Memory",
67
71
  description: "Retrieve bounded, source-labeled standing memory relevant to this delegated task. Read-only: no memory writes or lifecycle actions are available.",
68
72
  parameters: laneMemorySchema,
@@ -79,47 +83,49 @@ function createLaneTools(cwd, names, fileMutationIntents, additionalTools, readM
79
83
  }));
80
84
  }
81
85
  return names.flatMap((name) => {
82
- const additional = additionalTools.get(name);
83
- if (additional)
84
- return [additional];
85
86
  const factory = factories.get(name);
86
- return factory ? [wrapToolWithCredentialExposureGuard(factory(), cwd)] : [];
87
+ if (factory)
88
+ return [wrapToolWithCredentialExposureGuard(factory(), cwd, privatePathBoundary)];
89
+ if (!workerToolAdapters)
90
+ return [];
91
+ const materialized = workerToolAdapters.materialize(name, { cwd, credentialBoundary: privatePathBoundary });
92
+ if (!materialized.ok)
93
+ throw new Error(materialized.reason);
94
+ return [wrapToolWithCredentialExposureGuard(materialized.tool, cwd, privatePathBoundary)];
87
95
  });
88
96
  }
89
97
  /**
90
98
  * Materialize a fresh, fail-closed tool surface for one isolated lane.
91
99
  *
92
- * Admission selects classified built-ins plus runtime-owned injected controls. A compiled grant is
93
- * the only authority source for worker lanes; host shell and recursive delegation are materialized
94
- * when named by that grant. Write/edit additionally require the global write switch and a positive
95
- * path scope.
100
+ * Admission selects only tools this isolated lane can materialize. A compiled grant is the only
101
+ * authority source for worker lanes. Write/edit additionally require the global write switch and a
102
+ * positive path scope.
96
103
  */
97
104
  export function createLaneToolSurface(options) {
98
105
  const fileMutationIntents = new FileMutationIntentController();
99
- const additionalTools = new Map();
100
- for (const tool of options.additionalTools ?? []) {
101
- if (!tool.name.trim())
102
- throw new Error("An injected lane tool must have a name.");
103
- if (additionalTools.has(tool.name))
104
- throw new Error(`Injected lane tool '${tool.name}' is duplicated.`);
105
- additionalTools.set(tool.name, tool);
106
- }
107
106
  const writeCapable = options.writeEnabled === true && (options.writePaths?.length ?? 0) > 0;
107
+ const pythonCapable = options.toolManifests?.some((manifest) => manifest.toolName === PYTHON_LANE_TOOL_NAME) === true;
108
108
  const builtInCandidateNames = [
109
109
  ...READ_ONLY_LANE_TOOL_NAMES,
110
- ...(options.readMemory ? [MEMORY_LANE_TOOL_NAME] : []),
110
+ ...(options.readMemory ? [WORKER_MEMORY_READ_TOOL_NAME] : []),
111
111
  ...(writeCapable ? WRITE_LANE_TOOL_NAMES : []),
112
+ ...(pythonCapable ? [PYTHON_LANE_TOOL_NAME] : []),
112
113
  ...(options.executionPolicy ? [PROCESS_LANE_TOOL_NAME] : []),
113
114
  ...(options.shellSessionKey ? [STABLE_SHELL_TOOL_NAME] : []),
114
115
  ];
115
- for (const name of additionalTools.keys()) {
116
- if (builtInCandidateNames.includes(name)) {
117
- throw new Error(`Injected lane tool '${name}' conflicts with a built-in lane tool.`);
118
- }
116
+ const builtInNameSet = new Set(builtInCandidateNames);
117
+ const conflictingAdapter = options.workerToolAdapters?.names().find((name) => builtInNameSet.has(name));
118
+ if (conflictingAdapter) {
119
+ throw new Error(`Worker tool adapter '${conflictingAdapter}' conflicts with a built-in lane tool.`);
119
120
  }
120
- const candidateNames = [...builtInCandidateNames, ...additionalTools.keys()];
121
+ const candidateNames = [...builtInCandidateNames, ...(options.workerToolAdapters?.names() ?? [])];
122
+ const candidateNameSet = new Set(candidateNames);
121
123
  const patterns = strictLaneProfilePatterns(options.profile);
122
124
  const compiledToolNames = new Set(options.grant?.allowedTools ?? []);
125
+ const unmaterializedGrantTool = options.grant?.allowedTools.find((name) => !candidateNameSet.has(name));
126
+ if (unmaterializedGrantTool) {
127
+ throw new Error(`Compiled lane grant references unmaterializable tool '${unmaterializedGrantTool}'.`);
128
+ }
123
129
  const deniedTools = candidateNames.filter((name) => options.grant ? !compiledToolNames.has(name) : matchesResourceProfilePattern(name, patterns.block));
124
130
  const unboundAllowPatterns = options.grant
125
131
  ? []
@@ -142,12 +148,21 @@ export function createLaneToolSurface(options) {
142
148
  })
143
149
  : undefined;
144
150
  const deniedPaths = options.deniedPaths?.map((entry) => path.resolve(entry));
151
+ const privatePathBoundary = deniedPaths && deniedPaths.length > 0
152
+ ? {
153
+ redactSensitiveText: redactKnownSecrets,
154
+ protectedFiles: deniedPaths,
155
+ protectedDirectories: deniedPaths,
156
+ }
157
+ : undefined;
145
158
  const readEnvelope = {
146
159
  id: "isolated-lane-read-tools",
147
160
  capabilities: [
148
161
  "filesystem.read",
149
- ...(allowedToolSet.has(MEMORY_LANE_TOOL_NAME) ? ["memory.query"] : []),
150
- ...(allowedToolSet.has(PROCESS_LANE_TOOL_NAME) || allowedToolSet.has(STABLE_SHELL_TOOL_NAME)
162
+ ...(allowedToolSet.has(WORKER_MEMORY_READ_TOOL_NAME) ? ["memory.query"] : []),
163
+ ...(allowedToolSet.has(PYTHON_LANE_TOOL_NAME) ||
164
+ allowedToolSet.has(PROCESS_LANE_TOOL_NAME) ||
165
+ allowedToolSet.has(STABLE_SHELL_TOOL_NAME)
151
166
  ? ["process.exec"]
152
167
  : []),
153
168
  ],
@@ -165,7 +180,7 @@ export function createLaneToolSurface(options) {
165
180
  ...(deniedPaths && deniedPaths.length > 0 ? { deniedPaths } : {}),
166
181
  };
167
182
  return {
168
- tools: createLaneTools(options.cwd, allowedTools, fileMutationIntents, additionalTools, options.readMemory, options.executionPolicy, options.processMaxWallClockMs, options.shellSessionKey, options.shellOutputDirectory),
183
+ tools: createLaneTools(options.cwd, allowedTools, fileMutationIntents, privatePathBoundary, options.readMemory, options.executionPolicy, options.processMaxWallClockMs, options.shellSessionKey, options.shellOutputDirectory, options.workerToolAdapters),
169
184
  dispose: async () => {
170
185
  if (options.shellSessionKey)
171
186
  disposeShellExecutionSession(options.shellSessionKey);
@@ -1 +1 @@
1
- {"version":3,"file":"lane-tool-surface.js","sourceRoot":"","sources":["../../../src/core/autonomy/lane-tool-surface.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EACN,iBAAiB,EACjB,4BAA4B,GAG5B,MAAM,wCAAwC,CAAC;AAOhD,OAAO,EAAE,mCAAmC,EAAE,MAAM,yCAAyC,CAAC;AAC9F,OAAO,EAAE,6BAA6B,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,4BAA4B,EAAE,MAAM,kCAAkC,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,4BAA4B,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,yBAAyB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAU,CAAC;AAC1E,MAAM,qBAAqB,GAAG,QAAi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gBAChB,QAAQ,EAAE,wBAAwB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY;aACpF,CAAC,CAAC;YACH,IAAI,OAAO,CAAC,OAAO,KAAK,OAAO;gBAAE,OAAO,SAAS,CAAC;YAClD,OAAO;gBACN,KAAK,EAAE,IAAI;gBACX,MAAM,EAAE,sBAAsB,OAAO,CAAC,UAAU,MAAM,OAAO,CAAC,OAAO,IAAI,2BAA2B,EAAE;aACtG,CAAC;QACH,CAAC;QACD,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC/B,CAAC;AACH,CAAC","sourcesContent":["import path from \"node:path\";\nimport type { AgentLoopConfig, AgentTool } from \"@caupulican/pi-agent-core\";\nimport { type Static, Type } from \"typebox\";\nimport { STABLE_SHELL_TOOL_NAME } from \"../default-tool-surface.ts\";\nimport {\n\tCapabilityGateway,\n\tCapabilityGatewayDeniedError,\n\ttype GatewayInitialUsage,\n\ttype SharedCapabilityBudget,\n} from \"../orchestration/capability-gateway.ts\";\nimport type {\n\tExecutionGrant,\n\tOrchestrationExecutionPolicy,\n\tToolCapabilityManifest,\n} from \"../orchestration/contracts.ts\";\nimport type { NormalizedProfile } from \"../profile-registry.ts\";\nimport { wrapToolWithCredentialExposureGuard } from \"../secrets/credential-exposure-guard.ts\";\nimport { matchesResourceProfilePattern } from \"../settings-manager.ts\";\nimport { createBashTool } from \"../tools/bash.ts\";\nimport { createEditTool } from \"../tools/edit.ts\";\nimport { FileMutationIntentController } from \"../tools/file-mutation-intent.ts\";\nimport { createFindTool } from \"../tools/find.ts\";\nimport { createGrepTool } from \"../tools/grep.ts\";\nimport { createLsTool } from \"../tools/ls.ts\";\nimport { createReadTool } from \"../tools/read.ts\";\nimport { createRunProcessTool } from \"../tools/run-process.ts\";\nimport { disposeShellExecutionSession } from \"../tools/shell-execution-session.ts\";\nimport { createWriteTool } from \"../tools/write.ts\";\nimport type { CapabilityEnvelope } from \"./contracts.ts\";\nimport { evaluateToolGate } from \"./gates.ts\";\n\nconst READ_ONLY_LANE_TOOL_NAMES = [\"read\", \"grep\", \"find\", \"ls\"] as const;\nconst MEMORY_LANE_TOOL_NAME = \"memory\" as const;\nconst WRITE_LANE_TOOL_NAMES = [\"write\", \"edit\"] as const;\nconst PROCESS_LANE_TOOL_NAME = \"run_process\" as const;\nconst MAX_LANE_MEMORY_QUERY_CHARS = 4_096;\nconst laneMemorySchema = Type.Object({\n\tquery: Type.String({\n\t\tmaxLength: MAX_LANE_MEMORY_QUERY_CHARS,\n\t\tdescription: \"What relevant standing memory or prior evidence to retrieve\",\n\t}),\n});\ntype LaneMemoryParams = Static<typeof laneMemorySchema>;\nconst WRITE_LANE_TOOL_NAME_SET = new Set<string>(WRITE_LANE_TOOL_NAMES);\n\nexport interface LaneToolSurface {\n\t/** Fresh tools owned by this lane only; no foreground tool instances or extension state leak in. */\n\ttools: AgentTool[];\n\t/** Release exact mutation payload leases owned by this isolated lane. */\n\tdispose(): Promise<void>;\n\t/** Exact names after profile globs are expanded. Safe to persist in a capability envelope. */\n\tallowedTools: string[];\n\t/** Exact safe-candidate names denied by the profile's block patterns. */\n\tdeniedTools: string[];\n\t/** Explicit grants that bind to no classified lane candidate (opaque tools stay fail-closed). */\n\tunboundAllowPatterns: string[];\n\t/** Per-call path and capability gate for the isolated child loop. */\n\tbeforeToolCall: NonNullable<AgentLoopConfig[\"beforeToolCall\"]>;\n\t/** Canonical cumulative authority/budget meter for a compiled worker grant. */\n\tgateway?: CapabilityGateway;\n}\n\nexport interface LaneToolSurfaceOptions {\n\tcwd: string;\n\tprofile?: NormalizedProfile;\n\t/** Private harness state that generic file tools must never traverse. */\n\tdeniedPaths?: readonly string[];\n\t/** Orchestrator-requested, policy-filtered read-only memory retrieval. Omitted means no memory tool. */\n\treadMemory?: (query: string) => Promise<string>;\n\t/** Research never sets this. Workers require both this flag and at least one write path. */\n\twriteEnabled?: boolean;\n\twritePaths?: readonly string[];\n\t/** Present only for process-capable owner profiles; absent means no process tool is materialized. */\n\texecutionPolicy?: OrchestrationExecutionPolicy;\n\tprocessMaxWallClockMs?: number;\n\t/** Stable per-agent shell identity. Omitted when the compiled plan does not grant a host shell. */\n\tshellSessionKey?: string;\n\t/** Host-owned managed directory for complete shell output; never inferred from process-global config. */\n\tshellOutputDirectory?: string;\n\t/** Compiled policy path. When present, it is the only authorization source for this surface. */\n\tgrant?: ExecutionGrant;\n\ttoolManifests?: readonly ToolCapabilityManifest[];\n\t/** Runtime-owned classified tools composed specifically for this lane (for example delegation control). */\n\tadditionalTools?: readonly AgentTool[];\n\t/** Durable cumulative active usage to seed the compiled grant's gateway on resume. */\n\tinitialUsage?: GatewayInitialUsage;\n\t/** Root-tree aggregate meter shared by this attempt and every descendant. */\n\tsharedBudget?: SharedCapabilityBudget;\n}\n\nfunction strictLaneProfilePatterns(profile: NormalizedProfile | undefined): {\n\tallow: string[];\n\tblock: string[];\n} {\n\tif (!profile) return { allow: [], block: [] };\n\tconst filter = profile.resources.tools;\n\tconst allow = [...(filter?.allow ?? [])];\n\tconst block = [...(filter?.block ?? [])];\n\t// Strict UAC: a shipped profile is the complete authority grant. Grant-all must be explicit.\n\tif (allow.length === 0 && block.length === 0) return { allow: [], block: [\"*\"] };\n\treturn { allow, block };\n}\n\nfunction resolveWriteRoots(cwd: string, writePaths: readonly string[]): string[] {\n\treturn writePaths.map((entry) => (path.isAbsolute(entry) ? path.resolve(entry) : path.resolve(cwd, entry)));\n}\n\nfunction createLaneTools(\n\tcwd: string,\n\tnames: readonly string[],\n\tfileMutationIntents: FileMutationIntentController,\n\tadditionalTools: ReadonlyMap<string, AgentTool>,\n\treadMemory?: (query: string) => Promise<string>,\n\texecutionPolicy?: OrchestrationExecutionPolicy,\n\tprocessMaxWallClockMs = 0,\n\tshellSessionKey?: string,\n\tshellOutputDirectory?: string,\n): AgentTool[] {\n\tconst factories = new Map<string, () => AgentTool>([\n\t\t[\"read\", () => createReadTool(cwd)],\n\t\t[\"grep\", () => createGrepTool(cwd)],\n\t\t[\"find\", () => createFindTool(cwd)],\n\t\t[\"ls\", () => createLsTool(cwd)],\n\t\t[\"write\", () => createWriteTool(cwd, { intentController: fileMutationIntents })],\n\t\t[\"edit\", () => createEditTool(cwd, { intentController: fileMutationIntents })],\n\t]);\n\tif (executionPolicy) {\n\t\tfactories.set(PROCESS_LANE_TOOL_NAME, () =>\n\t\t\tcreateRunProcessTool(cwd, { policy: executionPolicy, maxWallClockMs: processMaxWallClockMs }),\n\t\t);\n\t}\n\tif (shellSessionKey) {\n\t\tfactories.set(STABLE_SHELL_TOOL_NAME, () =>\n\t\t\tcreateBashTool(cwd, {\n\t\t\t\tsessionKey: shellSessionKey,\n\t\t\t\tprewarmWindowsShell: true,\n\t\t\t\t...(shellOutputDirectory ? { outputDirectory: shellOutputDirectory } : {}),\n\t\t\t}),\n\t\t);\n\t}\n\tif (readMemory) {\n\t\tfactories.set(MEMORY_LANE_TOOL_NAME, () => ({\n\t\t\tname: MEMORY_LANE_TOOL_NAME,\n\t\t\tlabel: \"Read Memory\",\n\t\t\tdescription:\n\t\t\t\t\"Retrieve bounded, source-labeled standing memory relevant to this delegated task. Read-only: no memory writes or lifecycle actions are available.\",\n\t\t\tparameters: laneMemorySchema,\n\t\t\texecute: async (_toolCallId, params) => {\n\t\t\t\tconst query = (params as LaneMemoryParams).query?.trim();\n\t\t\t\tif (!query || query.length > MAX_LANE_MEMORY_QUERY_CHARS) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`memory_query_invalid: query must contain from 1 through ${MAX_LANE_MEMORY_QUERY_CHARS} characters.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: await readMemory(query) }],\n\t\t\t\t\tdetails: { readOnly: true },\n\t\t\t\t};\n\t\t\t},\n\t\t}));\n\t}\n\treturn names.flatMap((name) => {\n\t\tconst additional = additionalTools.get(name);\n\t\tif (additional) return [additional];\n\t\tconst factory = factories.get(name);\n\t\treturn factory ? [wrapToolWithCredentialExposureGuard(factory(), cwd)] : [];\n\t});\n}\n\n/**\n * Materialize a fresh, fail-closed tool surface for one isolated lane.\n *\n * Admission selects classified built-ins plus runtime-owned injected controls. A compiled grant is\n * the only authority source for worker lanes; host shell and recursive delegation are materialized\n * when named by that grant. Write/edit additionally require the global write switch and a positive\n * path scope.\n */\nexport function createLaneToolSurface(options: LaneToolSurfaceOptions): LaneToolSurface {\n\tconst fileMutationIntents = new FileMutationIntentController();\n\tconst additionalTools = new Map<string, AgentTool>();\n\tfor (const tool of options.additionalTools ?? []) {\n\t\tif (!tool.name.trim()) throw new Error(\"An injected lane tool must have a name.\");\n\t\tif (additionalTools.has(tool.name)) throw new Error(`Injected lane tool '${tool.name}' is duplicated.`);\n\t\tadditionalTools.set(tool.name, tool);\n\t}\n\tconst writeCapable = options.writeEnabled === true && (options.writePaths?.length ?? 0) > 0;\n\tconst builtInCandidateNames = [\n\t\t...READ_ONLY_LANE_TOOL_NAMES,\n\t\t...(options.readMemory ? [MEMORY_LANE_TOOL_NAME] : []),\n\t\t...(writeCapable ? WRITE_LANE_TOOL_NAMES : []),\n\t\t...(options.executionPolicy ? [PROCESS_LANE_TOOL_NAME] : []),\n\t\t...(options.shellSessionKey ? [STABLE_SHELL_TOOL_NAME] : []),\n\t];\n\tfor (const name of additionalTools.keys()) {\n\t\tif (builtInCandidateNames.includes(name as (typeof builtInCandidateNames)[number])) {\n\t\t\tthrow new Error(`Injected lane tool '${name}' conflicts with a built-in lane tool.`);\n\t\t}\n\t}\n\tconst candidateNames = [...builtInCandidateNames, ...additionalTools.keys()];\n\tconst patterns = strictLaneProfilePatterns(options.profile);\n\tconst compiledToolNames = new Set(options.grant?.allowedTools ?? []);\n\tconst deniedTools = candidateNames.filter((name) =>\n\t\toptions.grant ? !compiledToolNames.has(name) : matchesResourceProfilePattern(name, patterns.block),\n\t);\n\tconst unboundAllowPatterns = options.grant\n\t\t? []\n\t\t: patterns.allow.filter(\n\t\t\t\t(pattern) => !candidateNames.some((name) => matchesResourceProfilePattern(name, [pattern])),\n\t\t\t);\n\tconst allowedTools = options.grant\n\t\t? candidateNames.filter((name) => compiledToolNames.has(name))\n\t\t: candidateNames.filter(\n\t\t\t\t(name) =>\n\t\t\t\t\t(patterns.allow.length === 0 || matchesResourceProfilePattern(name, patterns.allow)) &&\n\t\t\t\t\t!matchesResourceProfilePattern(name, patterns.block),\n\t\t\t);\n\tconst allowedToolSet = new Set<string>(allowedTools);\n\tconst manifestsByName = new Map(options.toolManifests?.map((manifest) => [manifest.toolName, manifest]) ?? []);\n\tif (options.grant?.allowedTools.some((name) => !manifestsByName.has(name))) {\n\t\tthrow new Error(\"Compiled lane grant references a tool without a capability manifest.\");\n\t}\n\tconst gateway = options.grant\n\t\t? new CapabilityGateway({\n\t\t\t\tgrant: options.grant,\n\t\t\t\tcwd: options.cwd,\n\t\t\t\t...(options.initialUsage !== undefined ? { initialUsage: options.initialUsage } : {}),\n\t\t\t\t...(options.sharedBudget ? { sharedBudget: options.sharedBudget } : {}),\n\t\t\t})\n\t\t: undefined;\n\tconst deniedPaths = options.deniedPaths?.map((entry) => path.resolve(entry));\n\tconst readEnvelope: CapabilityEnvelope = {\n\t\tid: \"isolated-lane-read-tools\",\n\t\tcapabilities: [\n\t\t\t\"filesystem.read\",\n\t\t\t...(allowedToolSet.has(MEMORY_LANE_TOOL_NAME) ? ([\"memory.query\"] as const) : []),\n\t\t\t...(allowedToolSet.has(PROCESS_LANE_TOOL_NAME) || allowedToolSet.has(STABLE_SHELL_TOOL_NAME)\n\t\t\t\t? ([\"process.exec\"] as const)\n\t\t\t\t: []),\n\t\t],\n\t\tallowedTools,\n\t\tdeniedTools,\n\t\tallowedPaths: [path.resolve(options.cwd)],\n\t\t...(deniedPaths && deniedPaths.length > 0 ? { deniedPaths } : {}),\n\t};\n\tconst writeEnvelope: CapabilityEnvelope = {\n\t\tid: \"isolated-lane-write-tools\",\n\t\tcapabilities: [\"filesystem.write\"],\n\t\tallowedTools,\n\t\tdeniedTools,\n\t\tallowedPaths: resolveWriteRoots(options.cwd, options.writePaths ?? []),\n\t\t...(deniedPaths && deniedPaths.length > 0 ? { deniedPaths } : {}),\n\t};\n\n\treturn {\n\t\ttools: createLaneTools(\n\t\t\toptions.cwd,\n\t\t\tallowedTools,\n\t\t\tfileMutationIntents,\n\t\t\tadditionalTools,\n\t\t\toptions.readMemory,\n\t\t\toptions.executionPolicy,\n\t\t\toptions.processMaxWallClockMs,\n\t\t\toptions.shellSessionKey,\n\t\t\toptions.shellOutputDirectory,\n\t\t),\n\t\tdispose: async () => {\n\t\t\tif (options.shellSessionKey) disposeShellExecutionSession(options.shellSessionKey);\n\t\t\tawait fileMutationIntents.dispose();\n\t\t},\n\t\tallowedTools,\n\t\tdeniedTools,\n\t\tunboundAllowPatterns,\n\t\tbeforeToolCall: async ({ toolCall, args }) => {\n\t\t\tif (!allowedToolSet.has(toolCall.name)) {\n\t\t\t\treturn { block: true, reason: `Lane tool '${toolCall.name}' is outside the materialized UAC surface.` };\n\t\t\t}\n\t\t\tif (gateway) {\n\t\t\t\tconst manifest = manifestsByName.get(toolCall.name);\n\t\t\t\tif (!manifest) {\n\t\t\t\t\treturn { block: true, reason: `Lane tool '${toolCall.name}' has no compiled capability manifest.` };\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tgateway.authorizeToolCall(manifest, toolCall.name, args);\n\t\t\t\t\treturn undefined;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (error instanceof CapabilityGatewayDeniedError) {\n\t\t\t\t\t\tif (error.status === \"budget_exhausted\") throw error;\n\t\t\t\t\t\treturn { block: true, reason: `Lane tool blocked (${error.reasonCode}): ${error.message}` };\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst outcome = evaluateToolGate({\n\t\t\t\ttoolName: toolCall.name,\n\t\t\t\targs,\n\t\t\t\tcwd: options.cwd,\n\t\t\t\tenvelope: WRITE_LANE_TOOL_NAME_SET.has(toolCall.name) ? writeEnvelope : readEnvelope,\n\t\t\t});\n\t\t\tif (outcome.outcome === \"allow\") return undefined;\n\t\t\treturn {\n\t\t\t\tblock: true,\n\t\t\t\treason: `Lane tool blocked (${outcome.reasonCode}): ${outcome.message ?? \"capability gate denied it\"}`,\n\t\t\t};\n\t\t},\n\t\t...(gateway ? { gateway } : {}),\n\t};\n}\n"]}
1
+ {"version":3,"file":"lane-tool-surface.js","sourceRoot":"","sources":["../../../src/core/autonomy/lane-tool-surface.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,4BAA4B,EAAE,MAAM,kCAAkC,CAAC;AAChF,OAAO,EACN,iBAAiB,EACjB,4BAA4B,GAG5B,MAAM,wCAAwC,CAAC;AAOhD,OAAO,EAEN,mCAAmC,GACnC,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,4BAA4B,EAAE,MAAM,kCAAkC,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,cAAc,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,GAAG;gBAChB,QAAQ,EAAE,wBAAwB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY;aACpF,CAAC,CAAC;YACH,IAAI,OAAO,CAAC,OAAO,KAAK,OAAO;gBAAE,OAAO,SAAS,CAAC;YAClD,OAAO;gBACN,KAAK,EAAE,IAAI;gBACX,MAAM,EAAE,sBAAsB,OAAO,CAAC,UAAU,MAAM,OAAO,CAAC,OAAO,IAAI,2BAA2B,EAAE;aACtG,CAAC;QACH,CAAC;QACD,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC/B,CAAC;AACH,CAAC","sourcesContent":["import path from \"node:path\";\nimport type { AgentLoopConfig, AgentTool } from \"@caupulican/pi-agent-core\";\nimport { type Static, Type } from \"typebox\";\nimport { STABLE_SHELL_TOOL_NAME } from \"../default-tool-surface.ts\";\nimport { WORKER_MEMORY_READ_TOOL_NAME } from \"../memory/worker-memory-tools.ts\";\nimport {\n\tCapabilityGateway,\n\tCapabilityGatewayDeniedError,\n\ttype GatewayInitialUsage,\n\ttype SharedCapabilityBudget,\n} from \"../orchestration/capability-gateway.ts\";\nimport type {\n\tExecutionGrant,\n\tOrchestrationExecutionPolicy,\n\tToolCapabilityManifest,\n} from \"../orchestration/contracts.ts\";\nimport type { NormalizedProfile } from \"../profile-registry.ts\";\nimport {\n\ttype CredentialExposureBoundary,\n\twrapToolWithCredentialExposureGuard,\n} from \"../secrets/credential-exposure-guard.ts\";\nimport { redactKnownSecrets } from \"../security/secret-text.ts\";\nimport { matchesResourceProfilePattern } from \"../settings-manager.ts\";\nimport { createBashTool } from \"../tools/bash.ts\";\nimport { createEditTool } from \"../tools/edit.ts\";\nimport { FileMutationIntentController } from \"../tools/file-mutation-intent.ts\";\nimport { createFindTool } from \"../tools/find.ts\";\nimport { createGrepTool } from \"../tools/grep.ts\";\nimport { createLsTool } from \"../tools/ls.ts\";\nimport { createPythonTool } from \"../tools/python.ts\";\nimport { createReadTool } from \"../tools/read.ts\";\nimport { createRunProcessTool } from \"../tools/run-process.ts\";\nimport { disposeShellExecutionSession } from \"../tools/shell-execution-session.ts\";\nimport { createWriteTool } from \"../tools/write.ts\";\nimport type { CapabilityEnvelope } from \"./contracts.ts\";\nimport { evaluateToolGate } from \"./gates.ts\";\nimport type { WorkerToolAdapterRegistry } from \"./worker-tool-adapter-registry.ts\";\n\nconst READ_ONLY_LANE_TOOL_NAMES = [\"read\", \"grep\", \"find\", \"ls\"] as const;\nconst WRITE_LANE_TOOL_NAMES = [\"write\", \"edit\"] as const;\nconst PYTHON_LANE_TOOL_NAME = \"python\" as const;\nconst PROCESS_LANE_TOOL_NAME = \"run_process\" as const;\nconst MAX_LANE_MEMORY_QUERY_CHARS = 4_096;\nconst laneMemorySchema = Type.Object({\n\tquery: Type.String({\n\t\tmaxLength: MAX_LANE_MEMORY_QUERY_CHARS,\n\t\tdescription: \"What relevant standing memory or prior evidence to retrieve\",\n\t}),\n});\ntype LaneMemoryParams = Static<typeof laneMemorySchema>;\nconst WRITE_LANE_TOOL_NAME_SET = new Set<string>(WRITE_LANE_TOOL_NAMES);\n\nexport interface LaneToolSurface {\n\t/** Fresh tools owned by this lane only; no foreground tool instances or extension state leak in. */\n\ttools: AgentTool[];\n\t/** Release exact mutation payload leases owned by this isolated lane. */\n\tdispose(): Promise<void>;\n\t/** Exact names after profile globs are expanded. Safe to persist in a capability envelope. */\n\tallowedTools: string[];\n\t/** Exact safe-candidate names denied by the profile's block patterns. */\n\tdeniedTools: string[];\n\t/** Explicit grants that bind to no classified lane candidate (opaque tools stay fail-closed). */\n\tunboundAllowPatterns: string[];\n\t/** Per-call path and capability gate for the isolated worker loop. */\n\tbeforeToolCall: NonNullable<AgentLoopConfig[\"beforeToolCall\"]>;\n\t/** Canonical cumulative authority/budget meter for a compiled worker grant. */\n\tgateway?: CapabilityGateway;\n}\n\nexport interface LaneToolSurfaceOptions {\n\tcwd: string;\n\tprofile?: NormalizedProfile;\n\t/** Private harness state that generic file tools must never traverse. */\n\tdeniedPaths?: readonly string[];\n\t/** Orchestrator-requested, policy-filtered read-only memory retrieval. Omitted means no memory tool. */\n\treadMemory?: (query: string) => Promise<string>;\n\t/** Research never sets this. Workers require both this flag and at least one write path. */\n\twriteEnabled?: boolean;\n\twritePaths?: readonly string[];\n\t/** Present only for process-capable owner profiles; absent means no process tool is materialized. */\n\texecutionPolicy?: OrchestrationExecutionPolicy;\n\tprocessMaxWallClockMs?: number;\n\t/** Stable per-agent shell identity. Omitted when the compiled plan does not grant a host shell. */\n\tshellSessionKey?: string;\n\t/** Host-owned managed directory for complete shell output; never inferred from process-global config. */\n\tshellOutputDirectory?: string;\n\t/** Compiled policy path. When present, it is the only authorization source for this surface. */\n\tgrant?: ExecutionGrant;\n\ttoolManifests?: readonly ToolCapabilityManifest[];\n\t/** Durable cumulative active usage to seed the compiled grant's gateway on resume. */\n\tinitialUsage?: GatewayInitialUsage;\n\t/** Owner aggregate meter shared across retries and verification for this durable worker task. */\n\tsharedBudget?: SharedCapabilityBudget;\n\t/** Host-owned fresh factories for worker-safe foreground/extension tools. */\n\tworkerToolAdapters?: WorkerToolAdapterRegistry;\n}\n\nfunction strictLaneProfilePatterns(profile: NormalizedProfile | undefined): {\n\tallow: string[];\n\tblock: string[];\n} {\n\tif (!profile) return { allow: [], block: [] };\n\tconst filter = profile.resources.tools;\n\tconst allow = [...(filter?.allow ?? [])];\n\tconst block = [...(filter?.block ?? [])];\n\t// Strict UAC: a shipped profile is the complete authority grant. Grant-all must be explicit.\n\tif (allow.length === 0 && block.length === 0) return { allow: [], block: [\"*\"] };\n\treturn { allow, block };\n}\n\nfunction resolveWriteRoots(cwd: string, writePaths: readonly string[]): string[] {\n\treturn writePaths.map((entry) => (path.isAbsolute(entry) ? path.resolve(entry) : path.resolve(cwd, entry)));\n}\n\nfunction createLaneTools(\n\tcwd: string,\n\tnames: readonly string[],\n\tfileMutationIntents: FileMutationIntentController,\n\tprivatePathBoundary?: CredentialExposureBoundary,\n\treadMemory?: (query: string) => Promise<string>,\n\texecutionPolicy?: OrchestrationExecutionPolicy,\n\tprocessMaxWallClockMs = 0,\n\tshellSessionKey?: string,\n\tshellOutputDirectory?: string,\n\tworkerToolAdapters?: WorkerToolAdapterRegistry,\n): AgentTool[] {\n\tconst factories = new Map<string, () => AgentTool>([\n\t\t[\"read\", () => createReadTool(cwd)],\n\t\t[\"grep\", () => createGrepTool(cwd)],\n\t\t[\"find\", () => createFindTool(cwd)],\n\t\t[\"ls\", () => createLsTool(cwd)],\n\t\t[\"write\", () => createWriteTool(cwd, { intentController: fileMutationIntents })],\n\t\t[\"edit\", () => createEditTool(cwd, { intentController: fileMutationIntents })],\n\t\t[PYTHON_LANE_TOOL_NAME, () => createPythonTool(cwd)],\n\t]);\n\tif (executionPolicy) {\n\t\tfactories.set(PROCESS_LANE_TOOL_NAME, () =>\n\t\t\tcreateRunProcessTool(cwd, { policy: executionPolicy, maxWallClockMs: processMaxWallClockMs }),\n\t\t);\n\t}\n\tif (shellSessionKey) {\n\t\tfactories.set(STABLE_SHELL_TOOL_NAME, () =>\n\t\t\tcreateBashTool(cwd, {\n\t\t\t\tsessionKey: shellSessionKey,\n\t\t\t\tprewarmWindowsShell: true,\n\t\t\t\t...(shellOutputDirectory ? { outputDirectory: shellOutputDirectory } : {}),\n\t\t\t}),\n\t\t);\n\t}\n\tif (readMemory) {\n\t\tfactories.set(WORKER_MEMORY_READ_TOOL_NAME, () => ({\n\t\t\tname: WORKER_MEMORY_READ_TOOL_NAME,\n\t\t\tlabel: \"Read Memory\",\n\t\t\tdescription:\n\t\t\t\t\"Retrieve bounded, source-labeled standing memory relevant to this delegated task. Read-only: no memory writes or lifecycle actions are available.\",\n\t\t\tparameters: laneMemorySchema,\n\t\t\texecute: async (_toolCallId, params) => {\n\t\t\t\tconst query = (params as LaneMemoryParams).query?.trim();\n\t\t\t\tif (!query || query.length > MAX_LANE_MEMORY_QUERY_CHARS) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`memory_query_invalid: query must contain from 1 through ${MAX_LANE_MEMORY_QUERY_CHARS} characters.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: await readMemory(query) }],\n\t\t\t\t\tdetails: { readOnly: true },\n\t\t\t\t};\n\t\t\t},\n\t\t}));\n\t}\n\treturn names.flatMap((name) => {\n\t\tconst factory = factories.get(name);\n\t\tif (factory) return [wrapToolWithCredentialExposureGuard(factory(), cwd, privatePathBoundary)];\n\t\tif (!workerToolAdapters) return [];\n\t\tconst materialized = workerToolAdapters.materialize(name, { cwd, credentialBoundary: privatePathBoundary });\n\t\tif (!materialized.ok) throw new Error(materialized.reason);\n\t\treturn [wrapToolWithCredentialExposureGuard(materialized.tool, cwd, privatePathBoundary)];\n\t});\n}\n\n/**\n * Materialize a fresh, fail-closed tool surface for one isolated lane.\n *\n * Admission selects only tools this isolated lane can materialize. A compiled grant is the only\n * authority source for worker lanes. Write/edit additionally require the global write switch and a\n * positive path scope.\n */\nexport function createLaneToolSurface(options: LaneToolSurfaceOptions): LaneToolSurface {\n\tconst fileMutationIntents = new FileMutationIntentController();\n\tconst writeCapable = options.writeEnabled === true && (options.writePaths?.length ?? 0) > 0;\n\tconst pythonCapable =\n\t\toptions.toolManifests?.some((manifest) => manifest.toolName === PYTHON_LANE_TOOL_NAME) === true;\n\tconst builtInCandidateNames = [\n\t\t...READ_ONLY_LANE_TOOL_NAMES,\n\t\t...(options.readMemory ? [WORKER_MEMORY_READ_TOOL_NAME] : []),\n\t\t...(writeCapable ? WRITE_LANE_TOOL_NAMES : []),\n\t\t...(pythonCapable ? [PYTHON_LANE_TOOL_NAME] : []),\n\t\t...(options.executionPolicy ? [PROCESS_LANE_TOOL_NAME] : []),\n\t\t...(options.shellSessionKey ? [STABLE_SHELL_TOOL_NAME] : []),\n\t];\n\tconst builtInNameSet = new Set<string>(builtInCandidateNames);\n\tconst conflictingAdapter = options.workerToolAdapters?.names().find((name) => builtInNameSet.has(name));\n\tif (conflictingAdapter) {\n\t\tthrow new Error(`Worker tool adapter '${conflictingAdapter}' conflicts with a built-in lane tool.`);\n\t}\n\tconst candidateNames = [...builtInCandidateNames, ...(options.workerToolAdapters?.names() ?? [])];\n\tconst candidateNameSet = new Set<string>(candidateNames);\n\tconst patterns = strictLaneProfilePatterns(options.profile);\n\tconst compiledToolNames = new Set(options.grant?.allowedTools ?? []);\n\tconst unmaterializedGrantTool = options.grant?.allowedTools.find((name) => !candidateNameSet.has(name));\n\tif (unmaterializedGrantTool) {\n\t\tthrow new Error(`Compiled lane grant references unmaterializable tool '${unmaterializedGrantTool}'.`);\n\t}\n\tconst deniedTools = candidateNames.filter((name) =>\n\t\toptions.grant ? !compiledToolNames.has(name) : matchesResourceProfilePattern(name, patterns.block),\n\t);\n\tconst unboundAllowPatterns = options.grant\n\t\t? []\n\t\t: patterns.allow.filter(\n\t\t\t\t(pattern) => !candidateNames.some((name) => matchesResourceProfilePattern(name, [pattern])),\n\t\t\t);\n\tconst allowedTools = options.grant\n\t\t? candidateNames.filter((name) => compiledToolNames.has(name))\n\t\t: candidateNames.filter(\n\t\t\t\t(name) =>\n\t\t\t\t\t(patterns.allow.length === 0 || matchesResourceProfilePattern(name, patterns.allow)) &&\n\t\t\t\t\t!matchesResourceProfilePattern(name, patterns.block),\n\t\t\t);\n\tconst allowedToolSet = new Set<string>(allowedTools);\n\tconst manifestsByName = new Map(options.toolManifests?.map((manifest) => [manifest.toolName, manifest]) ?? []);\n\tif (options.grant?.allowedTools.some((name) => !manifestsByName.has(name))) {\n\t\tthrow new Error(\"Compiled lane grant references a tool without a capability manifest.\");\n\t}\n\tconst gateway = options.grant\n\t\t? new CapabilityGateway({\n\t\t\t\tgrant: options.grant,\n\t\t\t\tcwd: options.cwd,\n\t\t\t\t...(options.initialUsage !== undefined ? { initialUsage: options.initialUsage } : {}),\n\t\t\t\t...(options.sharedBudget ? { sharedBudget: options.sharedBudget } : {}),\n\t\t\t})\n\t\t: undefined;\n\tconst deniedPaths = options.deniedPaths?.map((entry) => path.resolve(entry));\n\tconst privatePathBoundary =\n\t\tdeniedPaths && deniedPaths.length > 0\n\t\t\t? {\n\t\t\t\t\tredactSensitiveText: redactKnownSecrets,\n\t\t\t\t\tprotectedFiles: deniedPaths,\n\t\t\t\t\tprotectedDirectories: deniedPaths,\n\t\t\t\t}\n\t\t\t: undefined;\n\tconst readEnvelope: CapabilityEnvelope = {\n\t\tid: \"isolated-lane-read-tools\",\n\t\tcapabilities: [\n\t\t\t\"filesystem.read\",\n\t\t\t...(allowedToolSet.has(WORKER_MEMORY_READ_TOOL_NAME) ? ([\"memory.query\"] as const) : []),\n\t\t\t...(allowedToolSet.has(PYTHON_LANE_TOOL_NAME) ||\n\t\t\tallowedToolSet.has(PROCESS_LANE_TOOL_NAME) ||\n\t\t\tallowedToolSet.has(STABLE_SHELL_TOOL_NAME)\n\t\t\t\t? ([\"process.exec\"] as const)\n\t\t\t\t: []),\n\t\t],\n\t\tallowedTools,\n\t\tdeniedTools,\n\t\tallowedPaths: [path.resolve(options.cwd)],\n\t\t...(deniedPaths && deniedPaths.length > 0 ? { deniedPaths } : {}),\n\t};\n\tconst writeEnvelope: CapabilityEnvelope = {\n\t\tid: \"isolated-lane-write-tools\",\n\t\tcapabilities: [\"filesystem.write\"],\n\t\tallowedTools,\n\t\tdeniedTools,\n\t\tallowedPaths: resolveWriteRoots(options.cwd, options.writePaths ?? []),\n\t\t...(deniedPaths && deniedPaths.length > 0 ? { deniedPaths } : {}),\n\t};\n\n\treturn {\n\t\ttools: createLaneTools(\n\t\t\toptions.cwd,\n\t\t\tallowedTools,\n\t\t\tfileMutationIntents,\n\t\t\tprivatePathBoundary,\n\t\t\toptions.readMemory,\n\t\t\toptions.executionPolicy,\n\t\t\toptions.processMaxWallClockMs,\n\t\t\toptions.shellSessionKey,\n\t\t\toptions.shellOutputDirectory,\n\t\t\toptions.workerToolAdapters,\n\t\t),\n\t\tdispose: async () => {\n\t\t\tif (options.shellSessionKey) disposeShellExecutionSession(options.shellSessionKey);\n\t\t\tawait fileMutationIntents.dispose();\n\t\t},\n\t\tallowedTools,\n\t\tdeniedTools,\n\t\tunboundAllowPatterns,\n\t\tbeforeToolCall: async ({ toolCall, args }) => {\n\t\t\tif (!allowedToolSet.has(toolCall.name)) {\n\t\t\t\treturn { block: true, reason: `Lane tool '${toolCall.name}' is outside the materialized UAC surface.` };\n\t\t\t}\n\t\t\tif (gateway) {\n\t\t\t\tconst manifest = manifestsByName.get(toolCall.name);\n\t\t\t\tif (!manifest) {\n\t\t\t\t\treturn { block: true, reason: `Lane tool '${toolCall.name}' has no compiled capability manifest.` };\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tgateway.authorizeToolCall(manifest, toolCall.name, args);\n\t\t\t\t\treturn undefined;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (error instanceof CapabilityGatewayDeniedError) {\n\t\t\t\t\t\tif (error.status === \"budget_exhausted\") throw error;\n\t\t\t\t\t\treturn { block: true, reason: `Lane tool blocked (${error.reasonCode}): ${error.message}` };\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst outcome = evaluateToolGate({\n\t\t\t\ttoolName: toolCall.name,\n\t\t\t\targs,\n\t\t\t\tcwd: options.cwd,\n\t\t\t\tenvelope: WRITE_LANE_TOOL_NAME_SET.has(toolCall.name) ? writeEnvelope : readEnvelope,\n\t\t\t});\n\t\t\tif (outcome.outcome === \"allow\") return undefined;\n\t\t\treturn {\n\t\t\t\tblock: true,\n\t\t\t\treason: `Lane tool blocked (${outcome.reasonCode}): ${outcome.message ?? \"capability gate denied it\"}`,\n\t\t\t};\n\t\t},\n\t\t...(gateway ? { gateway } : {}),\n\t};\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import type { CapabilityEnvelope } from "./contracts.ts";
2
+ export declare const PI_WORKER_ALLOWED_PATHS_ENV = "PI_WORKER_ALLOWED_PATHS";
3
+ export declare function parseWorkerSessionAllowedPaths(raw: string | undefined): readonly string[];
4
+ export declare function encodeWorkerSessionAllowedPaths(paths: readonly string[]): string;
5
+ /**
6
+ * Structural filesystem envelope for a standalone worker process (for example a Pi child launched
7
+ * in tmux). An empty allow list deliberately preserves the worker's host-wide project access while
8
+ * the private harness roots remain denied. Process tools are not path-confined by this envelope:
9
+ * bash/python are explicit host-trust boundaries and retain their OS-visible filesystem surface.
10
+ */
11
+ export declare function buildWorkerSessionPrivatePathEnvelope(cwd: string, agentDir: string, allowedPaths?: readonly string[]): CapabilityEnvelope;
12
+ //# sourceMappingURL=worker-session-private-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-session-private-scope.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/worker-session-private-scope.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAGzD,eAAO,MAAM,2BAA2B,4BAA4B,CAAC;AAErE,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,MAAM,EAAE,CAoBzF;AAED,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAEhF;AAED;;;;;GAKG;AACH,wBAAgB,qCAAqC,CACpD,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,YAAY,GAAE,SAAS,MAAM,EAA6E,GACxG,kBAAkB,CAUpB"}
@@ -0,0 +1,42 @@
1
+ import * as path from "node:path";
2
+ import { getPrivateLaneDeniedPaths } from "./lane-private-paths.js";
3
+ export const PI_WORKER_ALLOWED_PATHS_ENV = "PI_WORKER_ALLOWED_PATHS";
4
+ export function parseWorkerSessionAllowedPaths(raw) {
5
+ if (raw === undefined)
6
+ return Object.freeze([]);
7
+ let parsed;
8
+ try {
9
+ parsed = JSON.parse(raw);
10
+ }
11
+ catch {
12
+ throw new Error(`${PI_WORKER_ALLOWED_PATHS_ENV} must be a JSON array of absolute paths.`);
13
+ }
14
+ if (!Array.isArray(parsed) ||
15
+ !parsed.every((entry) => typeof entry === "string" &&
16
+ entry.trim().length > 0 &&
17
+ (path.isAbsolute(entry) || path.win32.isAbsolute(entry)))) {
18
+ throw new Error(`${PI_WORKER_ALLOWED_PATHS_ENV} must be a JSON array of absolute paths.`);
19
+ }
20
+ return Object.freeze([...new Set(parsed.map((entry) => entry.trim()))]);
21
+ }
22
+ export function encodeWorkerSessionAllowedPaths(paths) {
23
+ return JSON.stringify(parseWorkerSessionAllowedPaths(JSON.stringify(paths)));
24
+ }
25
+ /**
26
+ * Structural filesystem envelope for a standalone worker process (for example a Pi child launched
27
+ * in tmux). An empty allow list deliberately preserves the worker's host-wide project access while
28
+ * the private harness roots remain denied. Process tools are not path-confined by this envelope:
29
+ * bash/python are explicit host-trust boundaries and retain their OS-visible filesystem surface.
30
+ */
31
+ export function buildWorkerSessionPrivatePathEnvelope(cwd, agentDir, allowedPaths = parseWorkerSessionAllowedPaths(process.env[PI_WORKER_ALLOWED_PATHS_ENV])) {
32
+ const capabilities = Object.freeze(["filesystem.read", "filesystem.write"]);
33
+ const immutableAllowedPaths = Object.freeze([...allowedPaths]);
34
+ const deniedPaths = Object.freeze(getPrivateLaneDeniedPaths(cwd, agentDir));
35
+ return Object.freeze({
36
+ id: "worker-session-private-paths",
37
+ capabilities,
38
+ allowedPaths: immutableAllowedPaths,
39
+ deniedPaths,
40
+ });
41
+ }
42
+ //# sourceMappingURL=worker-session-private-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-session-private-scope.js","sourceRoot":"","sources":["../../../src/core/autonomy/worker-session-private-scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;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,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;IAE1G,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,iBAAiB,EAAE,kBAAkB,CAAU,CAAC,CAAC;IACrF,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC;IAC/D,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,yBAAyB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC5E,OAAO,MAAM,CAAC,MAAM,CAAC;QACpB,EAAE,EAAE,8BAA8B;QAClC,YAAY;QACZ,YAAY,EAAE,qBAAqB;QACnC,WAAW;KACX,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import * as path from \"node:path\";\nimport type { CapabilityEnvelope } from \"./contracts.ts\";\nimport { getPrivateLaneDeniedPaths } from \"./lane-private-paths.ts\";\n\nexport const PI_WORKER_ALLOWED_PATHS_ENV = \"PI_WORKER_ALLOWED_PATHS\";\n\nexport function parseWorkerSessionAllowedPaths(raw: string | undefined): readonly string[] {\n\tif (raw === undefined) return Object.freeze([]);\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(raw);\n\t} catch {\n\t\tthrow new Error(`${PI_WORKER_ALLOWED_PATHS_ENV} must be a JSON array of absolute paths.`);\n\t}\n\tif (\n\t\t!Array.isArray(parsed) ||\n\t\t!parsed.every(\n\t\t\t(entry) =>\n\t\t\t\ttypeof entry === \"string\" &&\n\t\t\t\tentry.trim().length > 0 &&\n\t\t\t\t(path.isAbsolute(entry) || path.win32.isAbsolute(entry)),\n\t\t)\n\t) {\n\t\tthrow new Error(`${PI_WORKER_ALLOWED_PATHS_ENV} must be a JSON array of absolute paths.`);\n\t}\n\treturn Object.freeze([...new Set(parsed.map((entry) => entry.trim()))]);\n}\n\nexport function encodeWorkerSessionAllowedPaths(paths: readonly string[]): string {\n\treturn JSON.stringify(parseWorkerSessionAllowedPaths(JSON.stringify(paths)));\n}\n\n/**\n * Structural filesystem envelope for a standalone worker process (for example a Pi child launched\n * in tmux). An empty allow list deliberately preserves the worker's host-wide project access while\n * the private harness roots remain denied. Process tools are not path-confined by this envelope:\n * bash/python are explicit host-trust boundaries and retain their OS-visible filesystem surface.\n */\nexport function buildWorkerSessionPrivatePathEnvelope(\n\tcwd: string,\n\tagentDir: string,\n\tallowedPaths: readonly string[] = parseWorkerSessionAllowedPaths(process.env[PI_WORKER_ALLOWED_PATHS_ENV]),\n): CapabilityEnvelope {\n\tconst capabilities = Object.freeze([\"filesystem.read\", \"filesystem.write\"] as const);\n\tconst immutableAllowedPaths = Object.freeze([...allowedPaths]);\n\tconst deniedPaths = Object.freeze(getPrivateLaneDeniedPaths(cwd, agentDir));\n\treturn Object.freeze({\n\t\tid: \"worker-session-private-paths\",\n\t\tcapabilities,\n\t\tallowedPaths: immutableAllowedPaths,\n\t\tdeniedPaths,\n\t});\n}\n"]}