@caupulican/pi-adaptative 0.86.14 → 0.90.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 (306) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/README.md +1 -1
  3. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
  4. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +14 -15
  5. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
  6. package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +14 -16
  7. package/dist/bundled-resources/skills/worker-profile-writer/SKILL.md +4 -4
  8. package/dist/core/agent-session.d.ts +23 -33
  9. package/dist/core/agent-session.d.ts.map +1 -1
  10. package/dist/core/agent-session.js +76 -109
  11. package/dist/core/agent-session.js.map +1 -1
  12. package/dist/core/autonomy/contracts.d.ts +1 -1
  13. package/dist/core/autonomy/contracts.js.map +1 -1
  14. package/dist/core/autonomy/gates.d.ts.map +1 -1
  15. package/dist/core/autonomy/gates.js +16 -0
  16. package/dist/core/autonomy/gates.js.map +1 -1
  17. package/dist/core/autonomy/subagent-prompt.d.ts +2 -1
  18. package/dist/core/autonomy/subagent-prompt.d.ts.map +1 -1
  19. package/dist/core/autonomy/subagent-prompt.js +2 -18
  20. package/dist/core/autonomy/subagent-prompt.js.map +1 -1
  21. package/dist/core/background-tool-task-controller.js +5 -5
  22. package/dist/core/background-tool-task-controller.js.map +1 -1
  23. package/dist/core/compaction-controller.d.ts +22 -2
  24. package/dist/core/compaction-controller.d.ts.map +1 -1
  25. package/dist/core/compaction-controller.js +75 -39
  26. package/dist/core/compaction-controller.js.map +1 -1
  27. package/dist/core/context/brain-curator.d.ts +2 -3
  28. package/dist/core/context/brain-curator.d.ts.map +1 -1
  29. package/dist/core/context/brain-curator.js +3 -20
  30. package/dist/core/context/brain-curator.js.map +1 -1
  31. package/dist/core/context/context-composition.d.ts +2 -1
  32. package/dist/core/context/context-composition.d.ts.map +1 -1
  33. package/dist/core/context/context-composition.js +6 -1
  34. package/dist/core/context/context-composition.js.map +1 -1
  35. package/dist/core/context/memory-prompt-block.js +1 -1
  36. package/dist/core/context/memory-prompt-block.js.map +1 -1
  37. package/dist/core/context/tool-output-packer.js +1 -1
  38. package/dist/core/context/tool-output-packer.js.map +1 -1
  39. package/dist/core/context-gc.js +10 -10
  40. package/dist/core/context-gc.js.map +1 -1
  41. package/dist/core/context-pipeline.d.ts +4 -4
  42. package/dist/core/context-pipeline.js +4 -4
  43. package/dist/core/context-pipeline.js.map +1 -1
  44. package/dist/core/default-tool-surface.d.ts.map +1 -1
  45. package/dist/core/default-tool-surface.js +1 -2
  46. package/dist/core/default-tool-surface.js.map +1 -1
  47. package/dist/core/delegation/session-worker-claim.d.ts +2 -2
  48. package/dist/core/delegation/session-worker-claim.js +2 -2
  49. package/dist/core/delegation/session-worker-claim.js.map +1 -1
  50. package/dist/core/delegation/worker-agent-control-coordinator.js +1 -1
  51. package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
  52. package/dist/core/delegation/worker-resource-materializer.js +3 -3
  53. package/dist/core/delegation/worker-resource-materializer.js.map +1 -1
  54. package/dist/core/delegation/worker-runner.d.ts +2 -13
  55. package/dist/core/delegation/worker-runner.d.ts.map +1 -1
  56. package/dist/core/delegation/worker-runner.js +5 -67
  57. package/dist/core/delegation/worker-runner.js.map +1 -1
  58. package/dist/core/extensions/builtin.js +4 -4
  59. package/dist/core/extensions/builtin.js.map +1 -1
  60. package/dist/core/extensions/runner.d.ts +6 -2
  61. package/dist/core/extensions/runner.d.ts.map +1 -1
  62. package/dist/core/extensions/runner.js +21 -9
  63. package/dist/core/extensions/runner.js.map +1 -1
  64. package/dist/core/extensions/types.d.ts +12 -3
  65. package/dist/core/extensions/types.d.ts.map +1 -1
  66. package/dist/core/extensions/types.js.map +1 -1
  67. package/dist/core/foreground-terminal-handoff-controller.js +2 -2
  68. package/dist/core/foreground-terminal-handoff-controller.js.map +1 -1
  69. package/dist/core/goals/compact-goal-context.d.ts.map +1 -1
  70. package/dist/core/goals/compact-goal-context.js +13 -9
  71. package/dist/core/goals/compact-goal-context.js.map +1 -1
  72. package/dist/core/goals/goal-continuation-prompt.js +1 -1
  73. package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
  74. package/dist/core/human-input-controller.js +1 -1
  75. package/dist/core/human-input-controller.js.map +1 -1
  76. package/dist/core/improvement-loop.js +13 -13
  77. package/dist/core/improvement-loop.js.map +1 -1
  78. package/dist/core/learning/reflection-engine.d.ts +2 -1
  79. package/dist/core/learning/reflection-engine.d.ts.map +1 -1
  80. package/dist/core/learning/reflection-engine.js +4 -24
  81. package/dist/core/learning/reflection-engine.js.map +1 -1
  82. package/dist/core/model-capability.d.ts.map +1 -1
  83. package/dist/core/model-capability.js +1 -1
  84. package/dist/core/model-capability.js.map +1 -1
  85. package/dist/core/model-router/route-judge.d.ts +2 -1
  86. package/dist/core/model-router/route-judge.d.ts.map +1 -1
  87. package/dist/core/model-router/route-judge.js +4 -12
  88. package/dist/core/model-router/route-judge.js.map +1 -1
  89. package/dist/core/models/perf-profile.d.ts +1 -1
  90. package/dist/core/models/perf-profile.d.ts.map +1 -1
  91. package/dist/core/models/perf-profile.js +2 -8
  92. package/dist/core/models/perf-profile.js.map +1 -1
  93. package/dist/core/orchestration/lane-tool-manifests.d.ts +1 -1
  94. package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
  95. package/dist/core/orchestration/lane-tool-manifests.js +1 -6
  96. package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
  97. package/dist/core/process-matrix/resume-launcher.js +3 -3
  98. package/dist/core/process-matrix/resume-launcher.js.map +1 -1
  99. package/dist/core/process-matrix/runtime.d.ts +2 -0
  100. package/dist/core/process-matrix/runtime.d.ts.map +1 -1
  101. package/dist/core/process-matrix/runtime.js +23 -19
  102. package/dist/core/process-matrix/runtime.js.map +1 -1
  103. package/dist/core/provider-prompt-contracts.d.ts +34 -0
  104. package/dist/core/provider-prompt-contracts.d.ts.map +1 -0
  105. package/dist/core/provider-prompt-contracts.js +133 -0
  106. package/dist/core/provider-prompt-contracts.js.map +1 -0
  107. package/dist/core/provider-request-context-controller.d.ts +40 -0
  108. package/dist/core/provider-request-context-controller.d.ts.map +1 -0
  109. package/dist/core/provider-request-context-controller.js +68 -0
  110. package/dist/core/provider-request-context-controller.js.map +1 -0
  111. package/dist/core/provider-request-runtime-controller.d.ts +22 -0
  112. package/dist/core/provider-request-runtime-controller.d.ts.map +1 -0
  113. package/dist/core/provider-request-runtime-controller.js +87 -0
  114. package/dist/core/provider-request-runtime-controller.js.map +1 -0
  115. package/dist/core/provider-tool-text.d.ts +7 -0
  116. package/dist/core/provider-tool-text.d.ts.map +1 -0
  117. package/dist/core/provider-tool-text.js +42 -0
  118. package/dist/core/provider-tool-text.js.map +1 -0
  119. package/dist/core/research/model-fitness.d.ts +2 -5
  120. package/dist/core/research/model-fitness.d.ts.map +1 -1
  121. package/dist/core/research/model-fitness.js +2 -20
  122. package/dist/core/research/model-fitness.js.map +1 -1
  123. package/dist/core/research/research-runner.d.ts +2 -1
  124. package/dist/core/research/research-runner.d.ts.map +1 -1
  125. package/dist/core/research/research-runner.js +6 -21
  126. package/dist/core/research/research-runner.js.map +1 -1
  127. package/dist/core/risk-classifier.d.ts.map +1 -1
  128. package/dist/core/risk-classifier.js +9 -1
  129. package/dist/core/risk-classifier.js.map +1 -1
  130. package/dist/core/runtime-builder.d.ts +3 -0
  131. package/dist/core/runtime-builder.d.ts.map +1 -1
  132. package/dist/core/runtime-builder.js +20 -25
  133. package/dist/core/runtime-builder.js.map +1 -1
  134. package/dist/core/scout-controller.d.ts +2 -1
  135. package/dist/core/scout-controller.d.ts.map +1 -1
  136. package/dist/core/scout-controller.js +2 -16
  137. package/dist/core/scout-controller.js.map +1 -1
  138. package/dist/core/sdk.d.ts +1 -1
  139. package/dist/core/sdk.js.map +1 -1
  140. package/dist/core/secrets/credential-exposure-guard.js +6 -6
  141. package/dist/core/secrets/credential-exposure-guard.js.map +1 -1
  142. package/dist/core/secrets/credential-manager.d.ts +11 -1
  143. package/dist/core/secrets/credential-manager.d.ts.map +1 -1
  144. package/dist/core/secrets/credential-manager.js +28 -7
  145. package/dist/core/secrets/credential-manager.js.map +1 -1
  146. package/dist/core/secrets/credential-migration-source.d.ts +20 -0
  147. package/dist/core/secrets/credential-migration-source.d.ts.map +1 -0
  148. package/dist/core/secrets/credential-migration-source.js +113 -0
  149. package/dist/core/secrets/credential-migration-source.js.map +1 -0
  150. package/dist/core/secrets/credential-session-connection.d.ts +9 -0
  151. package/dist/core/secrets/credential-session-connection.d.ts.map +1 -0
  152. package/dist/core/secrets/credential-session-connection.js +39 -0
  153. package/dist/core/secrets/credential-session-connection.js.map +1 -0
  154. package/dist/core/security/untrusted-boundary.d.ts +2 -2
  155. package/dist/core/security/untrusted-boundary.d.ts.map +1 -1
  156. package/dist/core/security/untrusted-boundary.js +3 -10
  157. package/dist/core/security/untrusted-boundary.js.map +1 -1
  158. package/dist/core/session-role.d.ts.map +1 -1
  159. package/dist/core/session-role.js +1 -2
  160. package/dist/core/session-role.js.map +1 -1
  161. package/dist/core/skill-vault.d.ts +98 -0
  162. package/dist/core/skill-vault.d.ts.map +1 -0
  163. package/dist/core/skill-vault.js +270 -0
  164. package/dist/core/skill-vault.js.map +1 -0
  165. package/dist/core/skills.d.ts +10 -9
  166. package/dist/core/skills.d.ts.map +1 -1
  167. package/dist/core/skills.js +42 -50
  168. package/dist/core/skills.js.map +1 -1
  169. package/dist/core/system-prompt-builder.d.ts +1 -1
  170. package/dist/core/system-prompt-builder.d.ts.map +1 -1
  171. package/dist/core/system-prompt-builder.js +20 -60
  172. package/dist/core/system-prompt-builder.js.map +1 -1
  173. package/dist/core/system-prompt.d.ts +4 -4
  174. package/dist/core/system-prompt.d.ts.map +1 -1
  175. package/dist/core/system-prompt.js +87 -121
  176. package/dist/core/system-prompt.js.map +1 -1
  177. package/dist/core/tasks/task-state.d.ts.map +1 -1
  178. package/dist/core/tasks/task-state.js +6 -7
  179. package/dist/core/tasks/task-state.js.map +1 -1
  180. package/dist/core/tool-capability-policy.d.ts.map +1 -1
  181. package/dist/core/tool-capability-policy.js +2 -1
  182. package/dist/core/tool-capability-policy.js.map +1 -1
  183. package/dist/core/tool-protocol-controller.d.ts.map +1 -1
  184. package/dist/core/tool-protocol-controller.js +4 -7
  185. package/dist/core/tool-protocol-controller.js.map +1 -1
  186. package/dist/core/tool-selection/promotion.d.ts.map +1 -1
  187. package/dist/core/tool-selection/promotion.js +2 -6
  188. package/dist/core/tool-selection/promotion.js.map +1 -1
  189. package/dist/core/toolkit/reflex-interpreter.d.ts +2 -1
  190. package/dist/core/toolkit/reflex-interpreter.d.ts.map +1 -1
  191. package/dist/core/toolkit/reflex-interpreter.js +2 -14
  192. package/dist/core/toolkit/reflex-interpreter.js.map +1 -1
  193. package/dist/core/tools/ask-question.js +6 -6
  194. package/dist/core/tools/ask-question.js.map +1 -1
  195. package/dist/core/tools/bash.d.ts.map +1 -1
  196. package/dist/core/tools/bash.js +8 -7
  197. package/dist/core/tools/bash.js.map +1 -1
  198. package/dist/core/tools/delegate-status.d.ts +17 -13
  199. package/dist/core/tools/delegate-status.d.ts.map +1 -1
  200. package/dist/core/tools/delegate-status.js +111 -226
  201. package/dist/core/tools/delegate-status.js.map +1 -1
  202. package/dist/core/tools/delegate.d.ts +29 -2
  203. package/dist/core/tools/delegate.d.ts.map +1 -1
  204. package/dist/core/tools/delegate.js +149 -48
  205. package/dist/core/tools/delegate.js.map +1 -1
  206. package/dist/core/tools/edit.d.ts +4 -1
  207. package/dist/core/tools/edit.d.ts.map +1 -1
  208. package/dist/core/tools/edit.js +34 -3
  209. package/dist/core/tools/edit.js.map +1 -1
  210. package/dist/core/tools/extensionify-runtime.js +4 -4
  211. package/dist/core/tools/extensionify-runtime.js.map +1 -1
  212. package/dist/core/tools/file-failure-recovery.d.ts +17 -0
  213. package/dist/core/tools/file-failure-recovery.d.ts.map +1 -0
  214. package/dist/core/tools/file-failure-recovery.js +43 -0
  215. package/dist/core/tools/file-failure-recovery.js.map +1 -0
  216. package/dist/core/tools/find.d.ts.map +1 -1
  217. package/dist/core/tools/find.js +2 -4
  218. package/dist/core/tools/find.js.map +1 -1
  219. package/dist/core/tools/goal.js +3 -3
  220. package/dist/core/tools/goal.js.map +1 -1
  221. package/dist/core/tools/grep.js +2 -2
  222. package/dist/core/tools/grep.js.map +1 -1
  223. package/dist/core/tools/index.d.ts +2 -1
  224. package/dist/core/tools/index.d.ts.map +1 -1
  225. package/dist/core/tools/index.js +2 -1
  226. package/dist/core/tools/index.js.map +1 -1
  227. package/dist/core/tools/ls.d.ts +3 -0
  228. package/dist/core/tools/ls.d.ts.map +1 -1
  229. package/dist/core/tools/ls.js +14 -0
  230. package/dist/core/tools/ls.js.map +1 -1
  231. package/dist/core/tools/model-fitness.js +4 -4
  232. package/dist/core/tools/model-fitness.js.map +1 -1
  233. package/dist/core/tools/profile-writer.d.ts +30 -16
  234. package/dist/core/tools/profile-writer.d.ts.map +1 -1
  235. package/dist/core/tools/profile-writer.js +98 -59
  236. package/dist/core/tools/profile-writer.js.map +1 -1
  237. package/dist/core/tools/python.js +6 -6
  238. package/dist/core/tools/python.js.map +1 -1
  239. package/dist/core/tools/read.d.ts +3 -0
  240. package/dist/core/tools/read.d.ts.map +1 -1
  241. package/dist/core/tools/read.js +17 -0
  242. package/dist/core/tools/read.js.map +1 -1
  243. package/dist/core/tools/run-process.js +4 -4
  244. package/dist/core/tools/run-process.js.map +1 -1
  245. package/dist/core/tools/run-toolkit-script.js +4 -4
  246. package/dist/core/tools/run-toolkit-script.js.map +1 -1
  247. package/dist/core/tools/secret-store.d.ts +32 -3
  248. package/dist/core/tools/secret-store.d.ts.map +1 -1
  249. package/dist/core/tools/secret-store.js +141 -34
  250. package/dist/core/tools/secret-store.js.map +1 -1
  251. package/dist/core/tools/skill.d.ts +29 -0
  252. package/dist/core/tools/skill.d.ts.map +1 -0
  253. package/dist/core/tools/skill.js +79 -0
  254. package/dist/core/tools/skill.js.map +1 -0
  255. package/dist/core/tools/task-steps.js +4 -4
  256. package/dist/core/tools/task-steps.js.map +1 -1
  257. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  258. package/dist/core/tools/tool-definition-wrapper.js +4 -0
  259. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  260. package/dist/core/tools/worktree-sync.js +6 -6
  261. package/dist/core/tools/worktree-sync.js.map +1 -1
  262. package/dist/core/tools/write.d.ts +4 -1
  263. package/dist/core/tools/write.d.ts.map +1 -1
  264. package/dist/core/tools/write.js +39 -3
  265. package/dist/core/tools/write.js.map +1 -1
  266. package/dist/index.d.ts +6 -3
  267. package/dist/index.d.ts.map +1 -1
  268. package/dist/index.js +5 -2
  269. package/dist/index.js.map +1 -1
  270. package/dist/modes/interactive/interactive-event-controller.js +1 -1
  271. package/dist/modes/interactive/interactive-event-controller.js.map +1 -1
  272. package/dist/modes/interactive/interactive-mode.js +1 -1
  273. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  274. package/dist/modes/interactive/report-commands.js +1 -1
  275. package/dist/modes/interactive/report-commands.js.map +1 -1
  276. package/dist/modes/interactive/secret-menu-controller.d.ts.map +1 -1
  277. package/dist/modes/interactive/secret-menu-controller.js +2 -18
  278. package/dist/modes/interactive/secret-menu-controller.js.map +1 -1
  279. package/dist/modes/interactive/session-flow-commands.js +1 -1
  280. package/dist/modes/interactive/session-flow-commands.js.map +1 -1
  281. package/docs/compaction.md +45 -25
  282. package/docs/extensions.md +23 -7
  283. package/docs/settings.md +3 -3
  284. package/docs/skills.md +14 -10
  285. package/docs/task-steps.md +2 -2
  286. package/docs/tmux-agent-manager.md +1 -1
  287. package/docs/tool-repair.md +18 -1
  288. package/docs/usage.md +4 -2
  289. package/docs/worker-profiles.md +3 -3
  290. package/docs/worktree-sync.md +2 -2
  291. package/examples/extensions/custom-compaction.ts +5 -17
  292. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  293. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  294. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  295. package/examples/extensions/sandbox/package-lock.json +2 -2
  296. package/examples/extensions/sandbox/package.json +1 -1
  297. package/examples/extensions/summarize.ts +3 -5
  298. package/examples/extensions/with-deps/package-lock.json +2 -2
  299. package/examples/extensions/with-deps/package.json +1 -1
  300. package/examples/sdk/04-skills.ts +1 -1
  301. package/npm-shrinkwrap.json +12 -12
  302. package/package.json +4 -4
  303. package/dist/core/util/json-size.d.ts +0 -3
  304. package/dist/core/util/json-size.d.ts.map +0 -1
  305. package/dist/core/util/json-size.js +0 -95
  306. package/dist/core/util/json-size.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"model-fitness.js","sourceRoot":"","sources":["../../../src/core/tools/model-fitness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAExE,MAAM,kBAAkB,GAAG,IAAI,CAAC,MAAM,CACrC;IACC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC;QAClB,WAAW,EACV,4IAA4I;KAC7I,CAAC;IACF,MAAM,EAAE,IAAI,CAAC,QAAQ,CACpB,IAAI,CAAC,MAAM,CAAC;QACX,WAAW,EACV,qGAAqG;KACtG,CAAC,CACF;CACD,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAC/B,CAAC;AAyBF,MAAM,UAAU,gCAAgC,CAAC,IAAkC;IAClF,OAAO;QACN,IAAI,EAAE,eAAe;QACrB,KAAK,EAAE,eAAe;QACtB,WAAW,EACV,6VAA6V;QAC9V,aAAa,EAAE,mFAAmF;QAClG,gBAAgB,EAAE;YACjB,4HAA4H;YAC5H,6IAA6I;YAC7I,+FAA+F;SAC/F;QACD,UAAU,EAAE,kBAAkB;QAC9B,KAAK,CAAC,OAAO,CACZ,UAAU,EACV,KAA4B;YAK5B,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;YAC1F,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;gBAClB,OAAO;oBACN,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,0BAA0B,GAAG,CAAC,UAAU,EAAE,EAAE,CAAC;oBACtF,OAAO,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE;iBACvD,CAAC;YACH,CAAC;YACD,OAAO;gBACN,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,wBAAwB,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC3F,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE;aAChE,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport type { ModelFitnessReport } from \"../research/model-fitness.ts\";\nimport { formatModelFitnessReport } from \"../research/model-fitness.ts\";\n\nconst modelFitnessSchema = Type.Object(\n\t{\n\t\tmodel: Type.String({\n\t\t\tdescription:\n\t\t\t\t'Model pattern to probe, e.g. \"ollama/qwen3:0.6b\" or any registered provider/model pattern. The model must be registered and authenticated.',\n\t\t}),\n\t\ttrials: Type.Optional(\n\t\t\tType.Number({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Trials per lane surface (research/worker), 1-20. Default 3. The judge always runs its 6-prompt set.\",\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type ModelFitnessToolInput = Static<typeof modelFitnessSchema>;\n\nexport interface ModelFitnessToolDetails {\n\tstarted: boolean;\n\tskipReason?: string;\n\tmodel?: string;\n\treport?: ModelFitnessReport;\n}\n\nexport interface ModelFitnessToolDependencies {\n\trunProbe: (args: {\n\t\tmodel: string;\n\t\ttrials?: number;\n\t\t/**\n\t\t * The LLM tool-call id for THIS invocation: the idempotency token a retry of the same\n\t\t * tool call reuses, so the spawned-usage reportId stays stable on a retry instead of falling\n\t\t * back to a bare (model, trials) identity — which two deliberately separate tool calls on the\n\t\t * same model/trials would otherwise collide on and silently under-count.\n\t\t */\n\t\ttoolCallId?: string;\n\t}) => Promise<{ started: true; model: string; report: ModelFitnessReport } | { started: false; skipReason: string }>;\n}\n\nexport function createModelFitnessToolDefinition(deps: ModelFitnessToolDependencies): ToolDefinition {\n\treturn {\n\t\tname: \"model_fitness\",\n\t\tlabel: \"model_fitness\",\n\t\tdescription:\n\t\t\t\"Probe whether a candidate model can drive the harness's subagent contracts: runs the real research-lane, delegated-worker, and routing-judge runners against the model and reports parse/success rates, judge discrimination, latency, and probe cost. Use it to evaluate small/local models (e.g. Ollama) before configuring them as lane or judge models.\",\n\t\tpromptSnippet: \"Benchmark a candidate model against the research/worker/judge subagent contracts.\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use model_fitness before pinning a model in a worker orchestration profile, researchLane.model, or modelRouter.judgeModel.\",\n\t\t\t\"A good lane model has high research/worker success; a good judge additionally routes trivial prompts cheap while keeping planning elevated.\",\n\t\t\t\"Probes spend real tokens on the probed model; prefer local/free models or small trial counts.\",\n\t\t],\n\t\tparameters: modelFitnessSchema,\n\t\tasync execute(\n\t\t\ttoolCallId,\n\t\t\tinput: ModelFitnessToolInput,\n\t\t): Promise<{\n\t\t\tcontent: Array<{ type: \"text\"; text: string }>;\n\t\t\tdetails: ModelFitnessToolDetails;\n\t\t}> {\n\t\t\tconst run = await deps.runProbe({ model: input.model, trials: input.trials, toolCallId });\n\t\t\tif (!run.started) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `model_fitness skipped: ${run.skipReason}` }],\n\t\t\t\t\tdetails: { started: false, skipReason: run.skipReason },\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\" as const, text: formatModelFitnessReport(run.model, run.report) }],\n\t\t\t\tdetails: { started: true, model: run.model, report: run.report },\n\t\t\t};\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"model-fitness.js","sourceRoot":"","sources":["../../../src/core/tools/model-fitness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAExE,MAAM,kBAAkB,GAAG,IAAI,CAAC,MAAM,CACrC;IACC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC;QAClB,WAAW,EACV,4IAA4I;KAC7I,CAAC;IACF,MAAM,EAAE,IAAI,CAAC,QAAQ,CACpB,IAAI,CAAC,MAAM,CAAC;QACX,WAAW,EACV,qGAAqG;KACtG,CAAC,CACF;CACD,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAC/B,CAAC;AAyBF,MAAM,UAAU,gCAAgC,CAAC,IAAkC;IAClF,OAAO;QACN,IAAI,EAAE,eAAe;QACrB,KAAK,EAAE,eAAe;QACtB,WAAW,EACV,6VAA6V;QAC9V,aAAa,EAAE,0DAA0D;QACzE,gBAAgB,EAAE;YACjB,yFAAyF;YACzF,8EAA8E;YAC9E,mEAAmE;SACnE;QACD,UAAU,EAAE,kBAAkB;QAC9B,KAAK,CAAC,OAAO,CACZ,UAAU,EACV,KAA4B;YAK5B,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;YAC1F,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;gBAClB,OAAO;oBACN,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,0BAA0B,GAAG,CAAC,UAAU,EAAE,EAAE,CAAC;oBACtF,OAAO,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE;iBACvD,CAAC;YACH,CAAC;YACD,OAAO;gBACN,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,wBAAwB,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC3F,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE;aAChE,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport type { ModelFitnessReport } from \"../research/model-fitness.ts\";\nimport { formatModelFitnessReport } from \"../research/model-fitness.ts\";\n\nconst modelFitnessSchema = Type.Object(\n\t{\n\t\tmodel: Type.String({\n\t\t\tdescription:\n\t\t\t\t'Model pattern to probe, e.g. \"ollama/qwen3:0.6b\" or any registered provider/model pattern. The model must be registered and authenticated.',\n\t\t}),\n\t\ttrials: Type.Optional(\n\t\t\tType.Number({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Trials per lane surface (research/worker), 1-20. Default 3. The judge always runs its 6-prompt set.\",\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type ModelFitnessToolInput = Static<typeof modelFitnessSchema>;\n\nexport interface ModelFitnessToolDetails {\n\tstarted: boolean;\n\tskipReason?: string;\n\tmodel?: string;\n\treport?: ModelFitnessReport;\n}\n\nexport interface ModelFitnessToolDependencies {\n\trunProbe: (args: {\n\t\tmodel: string;\n\t\ttrials?: number;\n\t\t/**\n\t\t * The LLM tool-call id for THIS invocation: the idempotency token a retry of the same\n\t\t * tool call reuses, so the spawned-usage reportId stays stable on a retry instead of falling\n\t\t * back to a bare (model, trials) identity — which two deliberately separate tool calls on the\n\t\t * same model/trials would otherwise collide on and silently under-count.\n\t\t */\n\t\ttoolCallId?: string;\n\t}) => Promise<{ started: true; model: string; report: ModelFitnessReport } | { started: false; skipReason: string }>;\n}\n\nexport function createModelFitnessToolDefinition(deps: ModelFitnessToolDependencies): ToolDefinition {\n\treturn {\n\t\tname: \"model_fitness\",\n\t\tlabel: \"model_fitness\",\n\t\tdescription:\n\t\t\t\"Probe whether a candidate model can drive the harness's subagent contracts: runs the real research-lane, delegated-worker, and routing-judge runners against the model and reports parse/success rates, judge discrimination, latency, and probe cost. Use it to evaluate small/local models (e.g. Ollama) before configuring them as lane or judge models.\",\n\t\tpromptSnippet: \"Benchmark model against research/worker/judge contracts.\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use before pinning model in worker profile, researchLane.model, modelRouter.judgeModel.\",\n\t\t\t\"Lane: high research/worker success. Judge: trivial cheap, planning elevated.\",\n\t\t\t\"Probes spend real tokens; prefer local/free models or few trials.\",\n\t\t],\n\t\tparameters: modelFitnessSchema,\n\t\tasync execute(\n\t\t\ttoolCallId,\n\t\t\tinput: ModelFitnessToolInput,\n\t\t): Promise<{\n\t\t\tcontent: Array<{ type: \"text\"; text: string }>;\n\t\t\tdetails: ModelFitnessToolDetails;\n\t\t}> {\n\t\t\tconst run = await deps.runProbe({ model: input.model, trials: input.trials, toolCallId });\n\t\t\tif (!run.started) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: `model_fitness skipped: ${run.skipReason}` }],\n\t\t\t\t\tdetails: { started: false, skipReason: run.skipReason },\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\" as const, text: formatModelFitnessReport(run.model, run.report) }],\n\t\t\t\tdetails: { started: true, model: run.model, report: run.report },\n\t\t\t};\n\t\t},\n\t};\n}\n"]}
@@ -1,11 +1,24 @@
1
- import { type Static, Type } from "typebox";
2
- import type { ToolDefinition } from "../extensions/types.ts";
3
- import type { TaskProfileCreateResult, TaskProfileInspection, TaskProfileWriterPort } from "../orchestration/task-profile-writer.ts";
4
- declare const profileWriterSchema: Type.TUnion<[Type.TObject<{
5
- action: Type.TLiteral<"inspect">;
6
- }>, Type.TObject<{
7
- action: Type.TLiteral<"create">;
8
- task: Type.TString;
1
+ import { Type } from "typebox";
2
+ import type { TaskProfileCreateInput, TaskProfileCreateResult, TaskProfileInspection, TaskProfileWriterPort } from "../orchestration/task-profile-writer.ts";
3
+ import type { OrchestrationPanelModel } from "./orchestration-panel.ts";
4
+ export declare const DELEGATE_PROFILE_ACTIONS: readonly ["profile_inspect", "profile_create"];
5
+ export type DelegateProfileAction = (typeof DELEGATE_PROFILE_ACTIONS)[number];
6
+ export interface DelegateProfileInput {
7
+ task?: string;
8
+ baseProfileId?: string;
9
+ model?: TaskProfileCreateInput["model"];
10
+ toolNames?: readonly string[];
11
+ resourceProfileNames?: readonly string[];
12
+ budget?: TaskProfileCreateInput["budget"];
13
+ }
14
+ export interface DelegateProfileToolDetails extends TaskProfileCreateResult {
15
+ started: boolean;
16
+ action: DelegateProfileAction;
17
+ kind: "profile";
18
+ inspection?: TaskProfileInspection;
19
+ }
20
+ export declare function createDelegateProfileParameterSchemas(): {
21
+ task: Type.TOptional<Type.TString>;
9
22
  baseProfileId: Type.TOptional<Type.TString>;
10
23
  model: Type.TOptional<Type.TObject<{
11
24
  provider: Type.TString;
@@ -22,12 +35,13 @@ declare const profileWriterSchema: Type.TUnion<[Type.TObject<{
22
35
  maxToolCalls: Type.TOptional<Type.TNumber>;
23
36
  requireApprovalAboveCostUsd: Type.TOptional<Type.TNumber>;
24
37
  }>>;
25
- }>]>;
26
- export type ProfileWriterToolInput = Static<typeof profileWriterSchema>;
27
- export interface ProfileWriterToolDetails extends TaskProfileCreateResult {
28
- action: "inspect" | "create";
29
- inspection?: TaskProfileInspection;
30
- }
31
- export declare function createProfileWriterToolDefinition(writer: TaskProfileWriterPort): ToolDefinition;
32
- export {};
38
+ };
39
+ export declare function delegateProfilePanelModel(details: DelegateProfileToolDetails): OrchestrationPanelModel;
40
+ export declare function executeDelegateProfileAction(action: DelegateProfileAction, input: DelegateProfileInput, writer: TaskProfileWriterPort): {
41
+ content: Array<{
42
+ type: "text";
43
+ text: string;
44
+ }>;
45
+ details: DelegateProfileToolDetails;
46
+ };
33
47
  //# sourceMappingURL=profile-writer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"profile-writer.d.ts","sourceRoot":"","sources":["../../../src/core/tools/profile-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE7D,OAAO,KAAK,EAEX,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,MAAM,yCAAyC,CAAC;AAgBjD,QAAA,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;IAuBvB,CAAC;AAEH,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAExE,MAAM,WAAW,wBAAyB,SAAQ,uBAAuB;IACxE,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC7B,UAAU,CAAC,EAAE,qBAAqB,CAAC;CACnC;AAED,wBAAgB,iCAAiC,CAAC,MAAM,EAAE,qBAAqB,GAAG,cAAc,CAuC/F"}
1
+ {"version":3,"file":"profile-writer.d.ts","sourceRoot":"","sources":["../../../src/core/tools/profile-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAQ/B,OAAO,KAAK,EACX,sBAAsB,EACtB,uBAA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1,67 +1,106 @@
1
1
  import { Type } from "typebox";
2
- import { ORCHESTRATION_THINKING_LEVELS } from "../orchestration/contracts.js";
3
- const thinkingLevelSchema = Type.Union(ORCHESTRATION_THINKING_LEVELS.map((level) => Type.Literal(level)));
4
- const budgetSchema = Type.Object({
5
- maxTokens: Type.Optional(Type.Number({ minimum: 0 })),
6
- maxWallClockMs: Type.Optional(Type.Number({ minimum: 0 })),
7
- maxCostUsd: Type.Optional(Type.Number({ minimum: 0 })),
8
- maxAttempts: Type.Optional(Type.Number({ minimum: 0 })),
9
- maxToolCalls: Type.Optional(Type.Number({ minimum: 0 })),
10
- requireApprovalAboveCostUsd: Type.Optional(Type.Number({ minimum: 0 })),
11
- }, { additionalProperties: false });
12
- const profileWriterSchema = Type.Union([
13
- Type.Object({ action: Type.Literal("inspect") }, { additionalProperties: false }),
14
- Type.Object({
15
- action: Type.Literal("create"),
16
- task: Type.String({ minLength: 1, maxLength: 3_500 }),
17
- baseProfileId: Type.Optional(Type.String({ minLength: 1 })),
2
+ import { MAX_ORCHESTRATION_COLLECTION_LENGTH, MAX_ORCHESTRATION_IDENTIFIER_LENGTH, MAX_ORCHESTRATION_MODEL_ID_LENGTH, MAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH, ORCHESTRATION_THINKING_LEVELS, } from "../orchestration/contracts.js";
3
+ export const DELEGATE_PROFILE_ACTIONS = ["profile_inspect", "profile_create"];
4
+ export function createDelegateProfileParameterSchemas() {
5
+ return {
6
+ task: Type.Optional(Type.String({ minLength: 1, maxLength: 3_500 })),
7
+ baseProfileId: Type.Optional(Type.String({ minLength: 1, maxLength: MAX_ORCHESTRATION_IDENTIFIER_LENGTH })),
18
8
  model: Type.Optional(Type.Object({
19
- provider: Type.String({ minLength: 1 }),
20
- modelId: Type.String({ minLength: 1 }),
21
- thinkingLevel: thinkingLevelSchema,
9
+ provider: Type.String({
10
+ minLength: 1,
11
+ maxLength: MAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH,
12
+ }),
13
+ modelId: Type.String({ minLength: 1, maxLength: MAX_ORCHESTRATION_MODEL_ID_LENGTH }),
14
+ thinkingLevel: Type.Union(ORCHESTRATION_THINKING_LEVELS.map((level) => Type.Literal(level))),
15
+ }, { additionalProperties: false })),
16
+ toolNames: Type.Optional(Type.Array(Type.String({ minLength: 1, maxLength: MAX_ORCHESTRATION_IDENTIFIER_LENGTH }), {
17
+ maxItems: MAX_ORCHESTRATION_COLLECTION_LENGTH,
18
+ })),
19
+ resourceProfileNames: Type.Optional(Type.Array(Type.String({ minLength: 1, maxLength: MAX_ORCHESTRATION_IDENTIFIER_LENGTH }), {
20
+ maxItems: MAX_ORCHESTRATION_COLLECTION_LENGTH,
21
+ })),
22
+ budget: Type.Optional(Type.Object({
23
+ maxTokens: Type.Optional(Type.Number({ minimum: 0 })),
24
+ maxWallClockMs: Type.Optional(Type.Number({ minimum: 0 })),
25
+ maxCostUsd: Type.Optional(Type.Number({ minimum: 0 })),
26
+ maxAttempts: Type.Optional(Type.Number({ minimum: 0 })),
27
+ maxToolCalls: Type.Optional(Type.Number({ minimum: 0 })),
28
+ requireApprovalAboveCostUsd: Type.Optional(Type.Number({ minimum: 0 })),
22
29
  }, { additionalProperties: false })),
23
- toolNames: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { maxItems: 64 })),
24
- resourceProfileNames: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { maxItems: 64 })),
25
- budget: Type.Optional(budgetSchema),
26
- }, { additionalProperties: false }),
27
- ]);
28
- export function createProfileWriterToolDefinition(writer) {
30
+ };
31
+ }
32
+ export function delegateProfilePanelModel(details) {
33
+ if (details.action === "profile_inspect") {
34
+ return {
35
+ label: "worker profiles",
36
+ action: "inspected",
37
+ status: "success",
38
+ summary: [
39
+ `${details.inspection?.baseProfiles.length ?? 0} bases`,
40
+ `${details.inspection?.models.length ?? 0} models`,
41
+ ],
42
+ };
43
+ }
44
+ return {
45
+ label: "worker profiles",
46
+ action: details.created ? "created" : "rejected",
47
+ status: details.created ? "success" : "warning",
48
+ rows: details.profileId
49
+ ? [
50
+ {
51
+ status: "succeeded",
52
+ label: details.profileId,
53
+ meta: details.baseProfileId ? [`base ${details.baseProfileId}`] : undefined,
54
+ },
55
+ ]
56
+ : undefined,
57
+ emptyText: details.reason,
58
+ };
59
+ }
60
+ export function executeDelegateProfileAction(action, input, writer) {
61
+ if (action === "profile_inspect") {
62
+ const inspection = writer.inspectTaskProfileOptions();
63
+ return {
64
+ content: [
65
+ {
66
+ type: "text",
67
+ text: `Authorized bases: ${inspection.baseProfiles.map((profile) => profile.profileId).join(", ") || "none"}. Available configured models: ${inspection.models.length}.`,
68
+ },
69
+ ],
70
+ details: { started: true, action, kind: "profile", created: false, inspection },
71
+ };
72
+ }
73
+ if (input.task === undefined) {
74
+ return {
75
+ content: [{ type: "text", text: "delegate profile_create requires task" }],
76
+ details: {
77
+ started: false,
78
+ action,
79
+ kind: "profile",
80
+ created: false,
81
+ reason: "missing_profile_task",
82
+ },
83
+ };
84
+ }
85
+ const request = {
86
+ task: input.task,
87
+ ...(input.baseProfileId !== undefined ? { baseProfileId: input.baseProfileId } : {}),
88
+ ...(input.model !== undefined ? { model: input.model } : {}),
89
+ ...(input.toolNames !== undefined ? { toolNames: input.toolNames } : {}),
90
+ ...(input.resourceProfileNames !== undefined ? { resourceProfileNames: input.resourceProfileNames } : {}),
91
+ ...(input.budget !== undefined ? { budget: input.budget } : {}),
92
+ };
93
+ const result = writer.createTaskProfile(request);
29
94
  return {
30
- name: "profile_writer",
31
- label: "profile_writer",
32
- description: "Inspect authorized worker bases or create an optional immutable session preset that only narrows a base. Direct delegation does not require a profile.",
33
- promptSnippet: "Inspect or create an optional session worker preset",
34
- promptGuidelines: [
35
- "Use this only when a reusable task-specific preset helps; delegate.authority can select execution directly.",
36
- "Pass the returned profileId unchanged to delegate; never invent ids or write one-off profile files.",
95
+ content: [
96
+ {
97
+ type: "text",
98
+ text: result.created
99
+ ? `Created immutable session task profile ${result.profileId} from ${result.baseProfileId}.`
100
+ : `delegate profile_create rejected the request: ${result.reason}.`,
101
+ },
37
102
  ],
38
- parameters: profileWriterSchema,
39
- execute(_toolCallId, input) {
40
- if (input.action === "inspect") {
41
- const inspection = writer.inspectTaskProfileOptions();
42
- return Promise.resolve({
43
- content: [
44
- {
45
- type: "text",
46
- text: `Authorized bases: ${inspection.baseProfiles.map((profile) => profile.profileId).join(", ") || "none"}. Available configured models: ${inspection.models.length}.`,
47
- },
48
- ],
49
- details: { action: "inspect", created: false, inspection },
50
- });
51
- }
52
- const result = writer.createTaskProfile(input);
53
- return Promise.resolve({
54
- content: [
55
- {
56
- type: "text",
57
- text: result.created
58
- ? `Created immutable session task profile ${result.profileId} from ${result.baseProfileId}.`
59
- : `profile_writer rejected the request: ${result.reason}.`,
60
- },
61
- ],
62
- details: { action: "create", ...result },
63
- });
64
- },
103
+ details: { started: result.created, action, kind: "profile", ...result },
65
104
  };
66
105
  }
67
106
  //# sourceMappingURL=profile-writer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"profile-writer.js","sourceRoot":"","sources":["../../../src/core/tools/profile-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AAQ9E,MAAM,mBAAmB,GAAG,IAAI,CAAC,KAAK,CAAC,6BAA6B,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAE1G,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAC/B;IACC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;IACrD,cAAc,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,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BACD,OAAO,EAAE,EAAE,MAAM,EAAE,SAAkB,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE;iBACnE,CAAC,CAAC;YACJ,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,CAAC,iBAAiB,CAAC,KAA+B,CAAC,CAAC;YACzE,OAAO,OAAO,CAAC,OAAO,CAAC;gBACtB,OAAO,EAAE;oBACR;wBACC,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,MAAM,CAAC,OAAO;4BACnB,CAAC,CAAC,0CAA0C,MAAM,CAAC,SAAS,SAAS,MAAM,CAAC,aAAa,GAAG;4BAC5F,CAAC,CAAC,wCAAwC,MAAM,CAAC,MAAM,GAAG;qBAC3D;iBACD;gBACD,OAAO,EAAE,EAAE,MAAM,EAAE,QAAiB,EAAE,GAAG,MAAM,EAAE;aACjD,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { ORCHESTRATION_THINKING_LEVELS } from \"../orchestration/contracts.ts\";\nimport type {\n\tTaskProfileCreateInput,\n\tTaskProfileCreateResult,\n\tTaskProfileInspection,\n\tTaskProfileWriterPort,\n} from \"../orchestration/task-profile-writer.ts\";\n\nconst thinkingLevelSchema = Type.Union(ORCHESTRATION_THINKING_LEVELS.map((level) => Type.Literal(level)));\n\nconst budgetSchema = Type.Object(\n\t{\n\t\tmaxTokens: Type.Optional(Type.Number({ minimum: 0 })),\n\t\tmaxWallClockMs: Type.Optional(Type.Number({ minimum: 0 })),\n\t\tmaxCostUsd: Type.Optional(Type.Number({ minimum: 0 })),\n\t\tmaxAttempts: Type.Optional(Type.Number({ minimum: 0 })),\n\t\tmaxToolCalls: Type.Optional(Type.Number({ minimum: 0 })),\n\t\trequireApprovalAboveCostUsd: Type.Optional(Type.Number({ minimum: 0 })),\n\t},\n\t{ additionalProperties: false },\n);\n\nconst profileWriterSchema = Type.Union([\n\tType.Object({ action: Type.Literal(\"inspect\") }, { additionalProperties: false }),\n\tType.Object(\n\t\t{\n\t\t\taction: Type.Literal(\"create\"),\n\t\t\ttask: Type.String({ minLength: 1, maxLength: 3_500 }),\n\t\t\tbaseProfileId: Type.Optional(Type.String({ minLength: 1 })),\n\t\t\tmodel: Type.Optional(\n\t\t\t\tType.Object(\n\t\t\t\t\t{\n\t\t\t\t\t\tprovider: Type.String({ minLength: 1 }),\n\t\t\t\t\t\tmodelId: Type.String({ minLength: 1 }),\n\t\t\t\t\t\tthinkingLevel: thinkingLevelSchema,\n\t\t\t\t\t},\n\t\t\t\t\t{ additionalProperties: false },\n\t\t\t\t),\n\t\t\t),\n\t\t\ttoolNames: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { maxItems: 64 })),\n\t\t\tresourceProfileNames: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { maxItems: 64 })),\n\t\t\tbudget: Type.Optional(budgetSchema),\n\t\t},\n\t\t{ additionalProperties: false },\n\t),\n]);\n\nexport type ProfileWriterToolInput = Static<typeof profileWriterSchema>;\n\nexport interface ProfileWriterToolDetails extends TaskProfileCreateResult {\n\taction: \"inspect\" | \"create\";\n\tinspection?: TaskProfileInspection;\n}\n\nexport function createProfileWriterToolDefinition(writer: TaskProfileWriterPort): ToolDefinition {\n\treturn {\n\t\tname: \"profile_writer\",\n\t\tlabel: \"profile_writer\",\n\t\tdescription:\n\t\t\t\"Inspect authorized worker bases or create an optional immutable session preset that only narrows a base. Direct delegation does not require a profile.\",\n\t\tpromptSnippet: \"Inspect or create an optional session worker preset\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use this only when a reusable task-specific preset helps; delegate.authority can select execution directly.\",\n\t\t\t\"Pass the returned profileId unchanged to delegate; never invent ids or write one-off profile files.\",\n\t\t],\n\t\tparameters: profileWriterSchema,\n\t\texecute(_toolCallId, input: ProfileWriterToolInput) {\n\t\t\tif (input.action === \"inspect\") {\n\t\t\t\tconst inspection = writer.inspectTaskProfileOptions();\n\t\t\t\treturn Promise.resolve({\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: `Authorized bases: ${inspection.baseProfiles.map((profile) => profile.profileId).join(\", \") || \"none\"}. Available configured models: ${inspection.models.length}.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { action: \"inspect\" as const, created: false, inspection },\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst result = writer.createTaskProfile(input as TaskProfileCreateInput);\n\t\t\treturn Promise.resolve({\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\ttext: result.created\n\t\t\t\t\t\t\t? `Created immutable session task profile ${result.profileId} from ${result.baseProfileId}.`\n\t\t\t\t\t\t\t: `profile_writer rejected the request: ${result.reason}.`,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdetails: { action: \"create\" as const, ...result },\n\t\t\t});\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"profile-writer.js","sourceRoot":"","sources":["../../../src/core/tools/profile-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EACN,mCAAmC,EACnC,mCAAmC,EACnC,iCAAiC,EACjC,uCAAuC,EACvC,6BAA6B,GAC7B,MAAM,+BAA+B,CAAC;AASvC,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,iBAAiB,EAAE,gBAAgB,CAAU,CAAC;AAoBvF,MAAM,UAAU,qCAAqC;IACpD,OAAO;QACN,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;QACpE,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,SA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GTH,\n\tMAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH,\n\tORCHESTRATION_THINKING_LEVELS,\n} from \"../orchestration/contracts.ts\";\nimport type {\n\tTaskProfileCreateInput,\n\tTaskProfileCreateResult,\n\tTaskProfileInspection,\n\tTaskProfileWriterPort,\n} from \"../orchestration/task-profile-writer.ts\";\nimport type { OrchestrationPanelModel } from \"./orchestration-panel.ts\";\n\nexport const DELEGATE_PROFILE_ACTIONS = [\"profile_inspect\", \"profile_create\"] as const;\n\nexport type DelegateProfileAction = (typeof DELEGATE_PROFILE_ACTIONS)[number];\n\nexport interface DelegateProfileInput {\n\ttask?: string;\n\tbaseProfileId?: string;\n\tmodel?: TaskProfileCreateInput[\"model\"];\n\ttoolNames?: readonly string[];\n\tresourceProfileNames?: readonly string[];\n\tbudget?: TaskProfileCreateInput[\"budget\"];\n}\n\nexport interface DelegateProfileToolDetails extends TaskProfileCreateResult {\n\tstarted: boolean;\n\taction: DelegateProfileAction;\n\tkind: \"profile\";\n\tinspection?: TaskProfileInspection;\n}\n\nexport function createDelegateProfileParameterSchemas() {\n\treturn {\n\t\ttask: Type.Optional(Type.String({ minLength: 1, maxLength: 3_500 })),\n\t\tbaseProfileId: Type.Optional(Type.String({ minLength: 1, maxLength: MAX_ORCHESTRATION_IDENTIFIER_LENGTH })),\n\t\tmodel: Type.Optional(\n\t\t\tType.Object(\n\t\t\t\t{\n\t\t\t\t\tprovider: Type.String({\n\t\t\t\t\t\tminLength: 1,\n\t\t\t\t\t\tmaxLength: MAX_ORCHESTRATION_MODEL_PROVIDER_LENGTH,\n\t\t\t\t\t}),\n\t\t\t\t\tmodelId: Type.String({ minLength: 1, maxLength: MAX_ORCHESTRATION_MODEL_ID_LENGTH }),\n\t\t\t\t\tthinkingLevel: Type.Union(ORCHESTRATION_THINKING_LEVELS.map((level) => Type.Literal(level))),\n\t\t\t\t},\n\t\t\t\t{ additionalProperties: false },\n\t\t\t),\n\t\t),\n\t\ttoolNames: Type.Optional(\n\t\t\tType.Array(Type.String({ minLength: 1, maxLength: MAX_ORCHESTRATION_IDENTIFIER_LENGTH }), {\n\t\t\t\tmaxItems: MAX_ORCHESTRATION_COLLECTION_LENGTH,\n\t\t\t}),\n\t\t),\n\t\tresourceProfileNames: Type.Optional(\n\t\t\tType.Array(Type.String({ minLength: 1, maxLength: MAX_ORCHESTRATION_IDENTIFIER_LENGTH }), {\n\t\t\t\tmaxItems: MAX_ORCHESTRATION_COLLECTION_LENGTH,\n\t\t\t}),\n\t\t),\n\t\tbudget: Type.Optional(\n\t\t\tType.Object(\n\t\t\t\t{\n\t\t\t\t\tmaxTokens: Type.Optional(Type.Number({ minimum: 0 })),\n\t\t\t\t\tmaxWallClockMs: Type.Optional(Type.Number({ minimum: 0 })),\n\t\t\t\t\tmaxCostUsd: Type.Optional(Type.Number({ minimum: 0 })),\n\t\t\t\t\tmaxAttempts: Type.Optional(Type.Number({ minimum: 0 })),\n\t\t\t\t\tmaxToolCalls: Type.Optional(Type.Number({ minimum: 0 })),\n\t\t\t\t\trequireApprovalAboveCostUsd: Type.Optional(Type.Number({ minimum: 0 })),\n\t\t\t\t},\n\t\t\t\t{ additionalProperties: false },\n\t\t\t),\n\t\t),\n\t};\n}\n\nexport function delegateProfilePanelModel(details: DelegateProfileToolDetails): OrchestrationPanelModel {\n\tif (details.action === \"profile_inspect\") {\n\t\treturn {\n\t\t\tlabel: \"worker profiles\",\n\t\t\taction: \"inspected\",\n\t\t\tstatus: \"success\",\n\t\t\tsummary: [\n\t\t\t\t`${details.inspection?.baseProfiles.length ?? 0} bases`,\n\t\t\t\t`${details.inspection?.models.length ?? 0} models`,\n\t\t\t],\n\t\t};\n\t}\n\treturn {\n\t\tlabel: \"worker profiles\",\n\t\taction: details.created ? \"created\" : \"rejected\",\n\t\tstatus: details.created ? \"success\" : \"warning\",\n\t\trows: details.profileId\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tstatus: \"succeeded\",\n\t\t\t\t\t\tlabel: details.profileId,\n\t\t\t\t\t\tmeta: details.baseProfileId ? [`base ${details.baseProfileId}`] : undefined,\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: undefined,\n\t\temptyText: details.reason,\n\t};\n}\n\nexport function executeDelegateProfileAction(\n\taction: DelegateProfileAction,\n\tinput: DelegateProfileInput,\n\twriter: TaskProfileWriterPort,\n): { content: Array<{ type: \"text\"; text: string }>; details: DelegateProfileToolDetails } {\n\tif (action === \"profile_inspect\") {\n\t\tconst inspection = writer.inspectTaskProfileOptions();\n\t\treturn {\n\t\t\tcontent: [\n\t\t\t\t{\n\t\t\t\t\ttype: \"text\",\n\t\t\t\t\ttext: `Authorized bases: ${inspection.baseProfiles.map((profile) => profile.profileId).join(\", \") || \"none\"}. Available configured models: ${inspection.models.length}.`,\n\t\t\t\t},\n\t\t\t],\n\t\t\tdetails: { started: true, action, kind: \"profile\", created: false, inspection },\n\t\t};\n\t}\n\n\tif (input.task === undefined) {\n\t\treturn {\n\t\t\tcontent: [{ type: \"text\", text: \"delegate profile_create requires task\" }],\n\t\t\tdetails: {\n\t\t\t\tstarted: false,\n\t\t\t\taction,\n\t\t\t\tkind: \"profile\",\n\t\t\t\tcreated: false,\n\t\t\t\treason: \"missing_profile_task\",\n\t\t\t},\n\t\t};\n\t}\n\tconst request: TaskProfileCreateInput = {\n\t\ttask: input.task,\n\t\t...(input.baseProfileId !== undefined ? { baseProfileId: input.baseProfileId } : {}),\n\t\t...(input.model !== undefined ? { model: input.model } : {}),\n\t\t...(input.toolNames !== undefined ? { toolNames: input.toolNames } : {}),\n\t\t...(input.resourceProfileNames !== undefined ? { resourceProfileNames: input.resourceProfileNames } : {}),\n\t\t...(input.budget !== undefined ? { budget: input.budget } : {}),\n\t};\n\tconst result = writer.createTaskProfile(request);\n\treturn {\n\t\tcontent: [\n\t\t\t{\n\t\t\t\ttype: \"text\",\n\t\t\t\ttext: result.created\n\t\t\t\t\t? `Created immutable session task profile ${result.profileId} from ${result.baseProfileId}.`\n\t\t\t\t\t: `delegate profile_create rejected the request: ${result.reason}.`,\n\t\t\t},\n\t\t],\n\t\tdetails: { started: result.created, action, kind: \"profile\", ...result },\n\t};\n}\n"]}
@@ -102,13 +102,13 @@ export function createPythonToolDefinition(baseCwd, options = {}) {
102
102
  name: "python",
103
103
  label: "python",
104
104
  description: `Run a bounded Python snippet or script without a shell. Pi resolves Python through uv, defaults to a ${DEFAULT_PYTHON_TIMEOUT_SECONDS}-second wall-clock timeout (maximum ${MAX_PYTHON_TIMEOUT_SECONDS}), streams bounded stdout/stderr, and spills truncated full output to the process work directory rather than the repository.`,
105
- promptSnippet: "Run bounded Python snippets or scripts through Pi's uv-managed runtime.",
105
+ promptSnippet: "Run bounded Python code/scripts through Pi's uv runtime.",
106
106
  promptGuidelines: [
107
- "Prefer python for bounded scripts, data shaping, structured transformations, and cross-platform logic when it is clearer than a shell pipeline.",
108
- "Prefer read/edit/write for small exact source edits. For Python file transformations, preserve encoding and newline style, write atomically, and verify the resulting diff.",
109
- "Keep work scoped: avoid recursive home/filesystem scans, pass explicit roots and filters, and request a larger timeout only when the bounded workload justifies it.",
110
- "Do not inspect or print credentials. When secret_store activates a bound profile, use its injected environment only through the credential-consuming program.",
111
- "Do not use python for destructive deletion, publish/push/release, or long-running services without explicit user approval.",
107
+ "Use python for bounded scripts/data transforms/cross-platform logic clearer than shell.",
108
+ "Small exact source edits: read/edit/write. Python transforms: preserve encoding/newlines, write atomically, verify diff.",
109
+ "Scope roots/filters; never scan home/filesystem recursively. Raise timeout only for justified bounded work.",
110
+ "Never inspect/print credentials; use activated environment only through credential consumer.",
111
+ "Explicit approval required: destructive deletion, publish/push/release, long-running services.",
112
112
  ],
113
113
  parameters: pythonSchema,
114
114
  async execute(_toolCallId, input, signal) {
@@ -1 +1 @@
1
- {"version":3,"file":"python.js","sourceRoot":"","sources":["../../../src/core/tools/python.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,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,EAAE,IAAI,CAAC,EAAE,CAAC;gBAChE,CAAC;gBACD,KAAK,MAAM,UAAU,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC;oBAC/E,IAAI,UAAU;wBAAE,IAAI,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,gBAAgB,UAAU,EAAE,CAAC,EAAE,CAAC;gBAChF,CAAC;YACF,CAAC;YACD,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7B,CAAC;KACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,OAAe,EAAE,OAA2B;IAC5E,OAAO,kBAAkB,CAAC,0BAA0B,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AACzE,CAAC","sourcesContent":["import { stat } from \"node:fs/promises\";\nimport { posix, win32 } from \"node:path\";\nimport type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport type { TruncationResult } from \"@caupulican/pi-agent-core/node\";\nimport { Text } from \"@caupulican/pi-tui\";\nimport { type Static, Type } from \"typebox\";\nimport { spawnProcess, waitForChildProcessWithTermination } from \"../../utils/child-process.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { ensurePythonRuntime, type PythonRuntimeOutcome } from \"../python-runtime.ts\";\nimport { withExclusiveMutationBarrier } from \"./file-mutation-queue.ts\";\nimport { OutputAccumulator } from \"./output-accumulator.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nexport const DEFAULT_PYTHON_TIMEOUT_SECONDS = 30;\nexport const MAX_PYTHON_TIMEOUT_SECONDS = 300;\nexport const MAX_PYTHON_OUTPUT_BYTES = 200_000;\nconst MIN_PYTHON_OUTPUT_BYTES = 1_000;\nconst PYTHON_KILL_GRACE_MS = 2_000;\n\nconst pythonSchema = Type.Object(\n\t{\n\t\tcode: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tdescription: \"Python code to execute on stdin. Provide exactly one of code or scriptPath.\",\n\t\t\t\tmaxLength: 200_000,\n\t\t\t}),\n\t\t),\n\t\tscriptPath: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tdescription: \"Python script path. Relative paths resolve from cwd; one leading @ is ignored.\",\n\t\t\t\tmaxLength: 32_768,\n\t\t\t}),\n\t\t),\n\t\targs: Type.Optional(\n\t\t\tType.Array(Type.String({ maxLength: 16_384 }), {\n\t\t\t\tdescription: \"Arguments passed directly to Python after '-' or scriptPath; no shell interpolation.\",\n\t\t\t\tmaxItems: 256,\n\t\t\t}),\n\t\t),\n\t\tcwd: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tdescription: \"Working directory. Defaults to Pi's cwd; relative paths resolve from Pi's cwd.\",\n\t\t\t\tmaxLength: 32_768,\n\t\t\t}),\n\t\t),\n\t\ttimeoutSeconds: Type.Optional(\n\t\t\tType.Number({\n\t\t\t\tdescription: `Wall-clock timeout. Defaults to ${DEFAULT_PYTHON_TIMEOUT_SECONDS} seconds and is capped at ${MAX_PYTHON_TIMEOUT_SECONDS}.`,\n\t\t\t}),\n\t\t),\n\t\tmaxOutputBytes: Type.Optional(\n\t\t\tType.Number({\n\t\t\t\tdescription: `Maximum returned bytes per stream before full output spills to a work artifact. Maximum ${MAX_PYTHON_OUTPUT_BYTES}.`,\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type PythonToolInput = Static<typeof pythonSchema>;\n\nexport interface PythonToolDetails {\n\tmode: \"code\" | \"script\";\n\tcwd: string;\n\tuvPath: string;\n\tpythonPath: string;\n\tscriptPath?: string;\n\targs: string[];\n\texitCode: number | null;\n\tsignal: string | null;\n\ttimedOut: boolean;\n\tstdoutTruncation?: TruncationResult;\n\tstderrTruncation?: TruncationResult;\n\tstdoutOutputPath?: string;\n\tstderrOutputPath?: string;\n\tstdoutOutputError?: string;\n\tstderrOutputError?: string;\n}\n\nexport interface PythonExecutionRequest {\n\tpython: string;\n\targs: string[];\n\tcwd: string;\n\tstdin?: string;\n\ttimeoutMs: number;\n\tsignal?: AbortSignal;\n\tenv: NodeJS.ProcessEnv;\n\tonStdout: (chunk: Buffer) => void;\n\tonStderr: (chunk: Buffer) => void;\n}\n\nexport interface PythonExecutionResult {\n\texitCode: number | null;\n\treason: \"exited\" | \"aborted\" | \"timeout\";\n\tsignal: string | null;\n}\n\nexport interface PythonOperations {\n\texec(request: PythonExecutionRequest): Promise<PythonExecutionResult>;\n}\n\nexport interface PythonToolOptions {\n\tresolveRuntime?: () => Promise<PythonRuntimeOutcome>;\n\toperations?: PythonOperations;\n\t/** Additional process environment resolved from the final execution cwd. */\n\tenvironment?: (cwd: string) => NodeJS.ProcessEnv;\n\t/** Owner-only variables that must never reach model-controlled Python. */\n\tomitEnvironmentVariables?: readonly string[];\n\t/** Override only for tests or embedded runtimes; production uses the process work directory. */\n\toutputDirectory?: string;\n}\n\nfunction stripAtPrefix(value: string): string {\n\treturn value.startsWith(\"@\") ? value.slice(1) : value;\n}\n\nexport function resolvePythonToolPath(\n\tbase: string,\n\trequested: string,\n\tplatform: NodeJS.Platform = process.platform,\n): string {\n\treturn (platform === \"win32\" ? win32 : posix).resolve(base, stripAtPrefix(requested));\n}\n\nasync function resolveWorkingDirectory(baseCwd: string, requested?: string): Promise<string> {\n\tconst cwd = requested ? resolvePythonToolPath(baseCwd, requested) : baseCwd;\n\tconst entry = await stat(cwd).catch(() => {\n\t\tthrow new Error(`cwd does not exist: ${cwd}`);\n\t});\n\tif (!entry.isDirectory()) throw new Error(`cwd is not a directory: ${cwd}`);\n\treturn cwd;\n}\n\nasync function resolveScriptPath(cwd: string, requested: string): Promise<string> {\n\tconst scriptPath = resolvePythonToolPath(cwd, requested);\n\tconst entry = await stat(scriptPath).catch(() => {\n\t\tthrow new Error(`scriptPath does not exist: ${scriptPath}`);\n\t});\n\tif (!entry.isFile()) throw new Error(`scriptPath is not a file: ${scriptPath}`);\n\treturn scriptPath;\n}\n\nfunction clampInteger(value: number | undefined, fallback: number, minimum: number, maximum: number): number {\n\tif (typeof value !== \"number\" || !Number.isFinite(value) || value <= 0) return fallback;\n\treturn Math.max(minimum, Math.min(maximum, Math.trunc(value)));\n}\n\nfunction createLocalPythonOperations(): PythonOperations {\n\treturn {\n\t\tasync exec(request) {\n\t\t\tif (request.signal?.aborted) throw new Error(\"Python execution aborted before start\");\n\t\t\tconst child = spawnProcess(request.python, request.args, {\n\t\t\t\tcwd: request.cwd,\n\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\tenv: request.env,\n\t\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t\t});\n\t\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => request.onStdout(chunk));\n\t\t\tchild.stderr?.on(\"data\", (chunk: Buffer) => request.onStderr(chunk));\n\t\t\tchild.stdin?.end(request.stdin ?? \"\");\n\t\t\tconst terminal = await waitForChildProcessWithTermination(child, {\n\t\t\t\tkillGraceMs: PYTHON_KILL_GRACE_MS,\n\t\t\t\tsignal: request.signal,\n\t\t\t\ttimeoutMs: request.timeoutMs,\n\t\t\t});\n\t\t\treturn { exitCode: terminal.code, reason: terminal.reason, signal: child.signalCode };\n\t\t},\n\t};\n}\n\nfunction renderStreamNotice(label: string, path: string | undefined, error: string | undefined): string | undefined {\n\tif (path) return `[${label} truncated; full output: ${path}]`;\n\tif (error) return `[${label} truncated; full-output artifact failed: ${error}]`;\n\treturn undefined;\n}\n\nexport function createPythonToolDefinition(\n\tbaseCwd: string,\n\toptions: PythonToolOptions = {},\n): ToolDefinition<typeof pythonSchema, PythonToolDetails> {\n\tconst resolveRuntime = options.resolveRuntime ?? (() => ensurePythonRuntime({ silent: true }));\n\tconst operations = options.operations ?? createLocalPythonOperations();\n\treturn {\n\t\tname: \"python\",\n\t\tlabel: \"python\",\n\t\tdescription: `Run a bounded Python snippet or script without a shell. Pi resolves Python through uv, defaults to a ${DEFAULT_PYTHON_TIMEOUT_SECONDS}-second wall-clock timeout (maximum ${MAX_PYTHON_TIMEOUT_SECONDS}), streams bounded stdout/stderr, and spills truncated full output to the process work directory rather than the repository.`,\n\t\tpromptSnippet: \"Run bounded Python snippets or scripts through Pi's uv-managed runtime.\",\n\t\tpromptGuidelines: [\n\t\t\t\"Prefer python for bounded scripts, data shaping, structured transformations, and cross-platform logic when it is clearer than a shell pipeline.\",\n\t\t\t\"Prefer read/edit/write for small exact source edits. For Python file transformations, preserve encoding and newline style, write atomically, and verify the resulting diff.\",\n\t\t\t\"Keep work scoped: avoid recursive home/filesystem scans, pass explicit roots and filters, and request a larger timeout only when the bounded workload justifies it.\",\n\t\t\t\"Do not inspect or print credentials. When secret_store activates a bound profile, use its injected environment only through the credential-consuming program.\",\n\t\t\t\"Do not use python for destructive deletion, publish/push/release, or long-running services without explicit user approval.\",\n\t\t],\n\t\tparameters: pythonSchema,\n\t\tasync execute(_toolCallId, input, signal) {\n\t\t\tconst hasCode = typeof input.code === \"string\";\n\t\t\tconst hasScript = typeof input.scriptPath === \"string\" && input.scriptPath.trim().length > 0;\n\t\t\tif (hasCode === hasScript) throw new Error(\"Provide exactly one of code or scriptPath.\");\n\t\t\tconst cwd = await resolveWorkingDirectory(baseCwd, input.cwd);\n\t\t\tconst scriptPath = hasScript ? await resolveScriptPath(cwd, input.scriptPath as string) : undefined;\n\t\t\tconst runtime = await resolveRuntime();\n\t\t\tif (runtime.status !== \"ready\") throw new Error(runtime.reason);\n\t\t\tconst args = input.args ? [...input.args] : [];\n\t\t\tconst timeoutSeconds = clampInteger(\n\t\t\t\tinput.timeoutSeconds,\n\t\t\t\tDEFAULT_PYTHON_TIMEOUT_SECONDS,\n\t\t\t\t1,\n\t\t\t\tMAX_PYTHON_TIMEOUT_SECONDS,\n\t\t\t);\n\t\t\tconst maxOutputBytes = clampInteger(\n\t\t\t\tinput.maxOutputBytes,\n\t\t\t\t50 * 1024,\n\t\t\t\tMIN_PYTHON_OUTPUT_BYTES,\n\t\t\t\tMAX_PYTHON_OUTPUT_BYTES,\n\t\t\t);\n\t\t\tconst accumulatorOptions = {\n\t\t\t\tmaxBytes: maxOutputBytes,\n\t\t\t\t...(options.outputDirectory ? { tempDirectory: options.outputDirectory } : {}),\n\t\t\t};\n\t\t\tconst stdout = new OutputAccumulator({ ...accumulatorOptions, tempFilePrefix: \"pi-python-stdout\" });\n\t\t\tconst stderr = new OutputAccumulator({ ...accumulatorOptions, tempFilePrefix: \"pi-python-stderr\" });\n\t\t\tconst finishStreams = () => {\n\t\t\t\tstdout.finish();\n\t\t\t\tstderr.finish();\n\t\t\t\treturn {\n\t\t\t\t\tstdout: stdout.snapshot({ persistIfTruncated: true }),\n\t\t\t\t\tstderr: stderr.snapshot({ persistIfTruncated: true }),\n\t\t\t\t};\n\t\t\t};\n\t\t\tlet execution: PythonExecutionResult;\n\t\t\ttry {\n\t\t\t\texecution = await withExclusiveMutationBarrier(() => {\n\t\t\t\t\tconst environment: NodeJS.ProcessEnv = {\n\t\t\t\t\t\t...process.env,\n\t\t\t\t\t\t...options.environment?.(cwd),\n\t\t\t\t\t\tPI_PYTHON_TOOL: \"1\",\n\t\t\t\t\t\tPYTHONDONTWRITEBYTECODE: \"1\",\n\t\t\t\t\t\tPYTHONIOENCODING: \"utf-8\",\n\t\t\t\t\t\tPYTHONUNBUFFERED: \"1\",\n\t\t\t\t\t\tPYTHONUTF8: \"1\",\n\t\t\t\t\t};\n\t\t\t\t\tfor (const name of options.omitEnvironmentVariables ?? []) delete environment[name];\n\t\t\t\t\treturn operations.exec({\n\t\t\t\t\t\tpython: runtime.pythonPath,\n\t\t\t\t\t\targs: scriptPath ? [\"-B\", scriptPath, ...args] : [\"-B\", \"-\", ...args],\n\t\t\t\t\t\tcwd,\n\t\t\t\t\t\tstdin: hasCode ? input.code : undefined,\n\t\t\t\t\t\ttimeoutMs: timeoutSeconds * 1000,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\tenv: environment,\n\t\t\t\t\t\tonStdout: (chunk) => stdout.append(chunk),\n\t\t\t\t\t\tonStderr: (chunk) => stderr.append(chunk),\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t\tconst snapshots = finishStreams();\n\t\t\t\tconst sections: string[] = [];\n\t\t\t\tif (snapshots.stdout.content) sections.push(snapshots.stdout.content.trimEnd());\n\t\t\t\tif (snapshots.stderr.content) sections.push(`[stderr]\\n${snapshots.stderr.content.trimEnd()}`);\n\t\t\t\tconst stdoutNotice = renderStreamNotice(\n\t\t\t\t\t\"stdout\",\n\t\t\t\t\tsnapshots.stdout.fullOutputPath,\n\t\t\t\t\tsnapshots.stdout.fullOutputError,\n\t\t\t\t);\n\t\t\t\tconst stderrNotice = renderStreamNotice(\n\t\t\t\t\t\"stderr\",\n\t\t\t\t\tsnapshots.stderr.fullOutputPath,\n\t\t\t\t\tsnapshots.stderr.fullOutputError,\n\t\t\t\t);\n\t\t\t\tif (stdoutNotice) sections.push(stdoutNotice);\n\t\t\t\tif (stderrNotice) sections.push(stderrNotice);\n\t\t\t\tconst status = `[python exitCode=${execution.exitCode ?? \"null\"}${execution.signal ? `; signal=${execution.signal}` : \"\"}]`;\n\t\t\t\tsections.push(status);\n\t\t\t\tconst text = sections.join(\"\\n\\n\");\n\t\t\t\tif (execution.reason === \"timeout\")\n\t\t\t\t\tthrow new Error(`${text}\\n\\nPython timed out after ${timeoutSeconds} seconds`);\n\t\t\t\tif (execution.reason === \"aborted\") throw new Error(`${text}\\n\\nPython execution aborted`);\n\t\t\t\tif (execution.exitCode !== 0) {\n\t\t\t\t\tconst termination = execution.signal\n\t\t\t\t\t\t? `signal ${execution.signal}`\n\t\t\t\t\t\t: `code ${execution.exitCode ?? \"unknown\"}`;\n\t\t\t\t\tthrow new Error(`${text}\\n\\nPython exited with ${termination}`);\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tmode: scriptPath ? \"script\" : \"code\",\n\t\t\t\t\t\tcwd,\n\t\t\t\t\t\tuvPath: runtime.uvPath,\n\t\t\t\t\t\tpythonPath: runtime.pythonPath,\n\t\t\t\t\t\tscriptPath,\n\t\t\t\t\t\targs,\n\t\t\t\t\t\texitCode: execution.exitCode,\n\t\t\t\t\t\tsignal: execution.signal,\n\t\t\t\t\t\ttimedOut: false,\n\t\t\t\t\t\t...(snapshots.stdout.truncation.truncated ? { stdoutTruncation: snapshots.stdout.truncation } : {}),\n\t\t\t\t\t\t...(snapshots.stderr.truncation.truncated ? { stderrTruncation: snapshots.stderr.truncation } : {}),\n\t\t\t\t\t\tstdoutOutputPath: snapshots.stdout.fullOutputPath,\n\t\t\t\t\t\tstderrOutputPath: snapshots.stderr.fullOutputPath,\n\t\t\t\t\t\tstdoutOutputError: snapshots.stdout.fullOutputError,\n\t\t\t\t\t\tstderrOutputError: snapshots.stderr.fullOutputError,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} finally {\n\t\t\t\tawait Promise.all([stdout.closeTempFile(), stderr.closeTempFile()]);\n\t\t\t}\n\t\t},\n\t\trenderCall(args, theme) {\n\t\t\tconst mode = args.scriptPath ? args.scriptPath : \"code\";\n\t\t\treturn new Text(`${theme.fg(\"toolTitle\", theme.bold(\"python\"))} ${theme.fg(\"muted\", mode)}`, 0, 0);\n\t\t},\n\t\trenderResult(result, { expanded, isPartial }, theme) {\n\t\t\tif (isPartial) return new Text(theme.fg(\"warning\", \"python running\"), 0, 0);\n\t\t\tconst details = result.details as PythonToolDetails | undefined;\n\t\t\tif (!details) return new Text(theme.fg(\"dim\", \"python done\"), 0, 0);\n\t\t\tconst status =\n\t\t\t\tdetails.exitCode === 0 && !details.timedOut ? \"python ok\" : `python exit ${details.exitCode ?? \"unknown\"}`;\n\t\t\tlet text = theme.fg(details.exitCode === 0 ? \"success\" : \"warning\", status);\n\t\t\tif (expanded) {\n\t\t\t\tconst content = result.content[0];\n\t\t\t\tif (content?.type === \"text\") {\n\t\t\t\t\tconst lines = content.text.split(\"\\n\").slice(-20);\n\t\t\t\t\tfor (const line of lines) text += `\\n${theme.fg(\"dim\", line)}`;\n\t\t\t\t}\n\t\t\t\tfor (const outputPath of [details.stdoutOutputPath, details.stderrOutputPath]) {\n\t\t\t\t\tif (outputPath) text += `\\n${theme.fg(\"muted\", `full output: ${outputPath}`)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new Text(text, 0, 0);\n\t\t},\n\t};\n}\n\nexport function createPythonTool(baseCwd: string, options?: PythonToolOptions): AgentTool<typeof pythonSchema> {\n\treturn wrapToolDefinition(createPythonToolDefinition(baseCwd, options));\n}\n"]}
1
+ {"version":3,"file":"python.js","sourceRoot":"","sources":["../../../src/core/tools/python.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAGzC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,kCAAkC,EAAE,MAAM,8BAA8B,CAAC;AAEhG,OAAO,EAAE,mBAAmB,EAA6B,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,CAAC,MAAM,8BAA8B,GAAG,EAAE,CAAC;AACjD,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAC9C,MAAM,CAAC,MAAM,uBAAuB,GAAG,OAAO,CAAC;AAC/C,MAAM,uBAAuB,GAAG,KAAK,CAAC;AACtC,MAAM,oBAAoB,GAAG,KAAK,CAAC;AAEnC,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAC/B;IACC,IAA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,IAAI,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YAC5E,IAAI,QAAQ,EAAE,CAAC;gBACd,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;gBAClC,IAAI,OAAO,EAAE,IAAI,KAAK,MAAM,EAAE,CAAC;oBAC9B,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;oBAClD,KAAK,MAAM,IAAI,IAAI,KAAK;wBAAE,IAAI,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;gBAChE,CAAC;gBACD,KAAK,MAAM,UAAU,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC;oBAC/E,IAAI,UAAU;wBAAE,IAAI,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,gBAAgB,UAAU,EAAE,CAAC,EAAE,CAAC;gBAChF,CAAC;YACF,CAAC;YACD,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7B,CAAC;KACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,OAAe,EAAE,OAA2B;IAC5E,OAAO,kBAAkB,CAAC,0BAA0B,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AACzE,CAAC","sourcesContent":["import { stat } from \"node:fs/promises\";\nimport { posix, win32 } from \"node:path\";\nimport type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport type { TruncationResult } from \"@caupulican/pi-agent-core/node\";\nimport { Text } from \"@caupulican/pi-tui\";\nimport { type Static, Type } from \"typebox\";\nimport { spawnProcess, waitForChildProcessWithTermination } from \"../../utils/child-process.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { ensurePythonRuntime, type PythonRuntimeOutcome } from \"../python-runtime.ts\";\nimport { withExclusiveMutationBarrier } from \"./file-mutation-queue.ts\";\nimport { OutputAccumulator } from \"./output-accumulator.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nexport const DEFAULT_PYTHON_TIMEOUT_SECONDS = 30;\nexport const MAX_PYTHON_TIMEOUT_SECONDS = 300;\nexport const MAX_PYTHON_OUTPUT_BYTES = 200_000;\nconst MIN_PYTHON_OUTPUT_BYTES = 1_000;\nconst PYTHON_KILL_GRACE_MS = 2_000;\n\nconst pythonSchema = Type.Object(\n\t{\n\t\tcode: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tdescription: \"Python code to execute on stdin. Provide exactly one of code or scriptPath.\",\n\t\t\t\tmaxLength: 200_000,\n\t\t\t}),\n\t\t),\n\t\tscriptPath: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tdescription: \"Python script path. Relative paths resolve from cwd; one leading @ is ignored.\",\n\t\t\t\tmaxLength: 32_768,\n\t\t\t}),\n\t\t),\n\t\targs: Type.Optional(\n\t\t\tType.Array(Type.String({ maxLength: 16_384 }), {\n\t\t\t\tdescription: \"Arguments passed directly to Python after '-' or scriptPath; no shell interpolation.\",\n\t\t\t\tmaxItems: 256,\n\t\t\t}),\n\t\t),\n\t\tcwd: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tdescription: \"Working directory. Defaults to Pi's cwd; relative paths resolve from Pi's cwd.\",\n\t\t\t\tmaxLength: 32_768,\n\t\t\t}),\n\t\t),\n\t\ttimeoutSeconds: Type.Optional(\n\t\t\tType.Number({\n\t\t\t\tdescription: `Wall-clock timeout. Defaults to ${DEFAULT_PYTHON_TIMEOUT_SECONDS} seconds and is capped at ${MAX_PYTHON_TIMEOUT_SECONDS}.`,\n\t\t\t}),\n\t\t),\n\t\tmaxOutputBytes: Type.Optional(\n\t\t\tType.Number({\n\t\t\t\tdescription: `Maximum returned bytes per stream before full output spills to a work artifact. Maximum ${MAX_PYTHON_OUTPUT_BYTES}.`,\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type PythonToolInput = Static<typeof pythonSchema>;\n\nexport interface PythonToolDetails {\n\tmode: \"code\" | \"script\";\n\tcwd: string;\n\tuvPath: string;\n\tpythonPath: string;\n\tscriptPath?: string;\n\targs: string[];\n\texitCode: number | null;\n\tsignal: string | null;\n\ttimedOut: boolean;\n\tstdoutTruncation?: TruncationResult;\n\tstderrTruncation?: TruncationResult;\n\tstdoutOutputPath?: string;\n\tstderrOutputPath?: string;\n\tstdoutOutputError?: string;\n\tstderrOutputError?: string;\n}\n\nexport interface PythonExecutionRequest {\n\tpython: string;\n\targs: string[];\n\tcwd: string;\n\tstdin?: string;\n\ttimeoutMs: number;\n\tsignal?: AbortSignal;\n\tenv: NodeJS.ProcessEnv;\n\tonStdout: (chunk: Buffer) => void;\n\tonStderr: (chunk: Buffer) => void;\n}\n\nexport interface PythonExecutionResult {\n\texitCode: number | null;\n\treason: \"exited\" | \"aborted\" | \"timeout\";\n\tsignal: string | null;\n}\n\nexport interface PythonOperations {\n\texec(request: PythonExecutionRequest): Promise<PythonExecutionResult>;\n}\n\nexport interface PythonToolOptions {\n\tresolveRuntime?: () => Promise<PythonRuntimeOutcome>;\n\toperations?: PythonOperations;\n\t/** Additional process environment resolved from the final execution cwd. */\n\tenvironment?: (cwd: string) => NodeJS.ProcessEnv;\n\t/** Owner-only variables that must never reach model-controlled Python. */\n\tomitEnvironmentVariables?: readonly string[];\n\t/** Override only for tests or embedded runtimes; production uses the process work directory. */\n\toutputDirectory?: string;\n}\n\nfunction stripAtPrefix(value: string): string {\n\treturn value.startsWith(\"@\") ? value.slice(1) : value;\n}\n\nexport function resolvePythonToolPath(\n\tbase: string,\n\trequested: string,\n\tplatform: NodeJS.Platform = process.platform,\n): string {\n\treturn (platform === \"win32\" ? win32 : posix).resolve(base, stripAtPrefix(requested));\n}\n\nasync function resolveWorkingDirectory(baseCwd: string, requested?: string): Promise<string> {\n\tconst cwd = requested ? resolvePythonToolPath(baseCwd, requested) : baseCwd;\n\tconst entry = await stat(cwd).catch(() => {\n\t\tthrow new Error(`cwd does not exist: ${cwd}`);\n\t});\n\tif (!entry.isDirectory()) throw new Error(`cwd is not a directory: ${cwd}`);\n\treturn cwd;\n}\n\nasync function resolveScriptPath(cwd: string, requested: string): Promise<string> {\n\tconst scriptPath = resolvePythonToolPath(cwd, requested);\n\tconst entry = await stat(scriptPath).catch(() => {\n\t\tthrow new Error(`scriptPath does not exist: ${scriptPath}`);\n\t});\n\tif (!entry.isFile()) throw new Error(`scriptPath is not a file: ${scriptPath}`);\n\treturn scriptPath;\n}\n\nfunction clampInteger(value: number | undefined, fallback: number, minimum: number, maximum: number): number {\n\tif (typeof value !== \"number\" || !Number.isFinite(value) || value <= 0) return fallback;\n\treturn Math.max(minimum, Math.min(maximum, Math.trunc(value)));\n}\n\nfunction createLocalPythonOperations(): PythonOperations {\n\treturn {\n\t\tasync exec(request) {\n\t\t\tif (request.signal?.aborted) throw new Error(\"Python execution aborted before start\");\n\t\t\tconst child = spawnProcess(request.python, request.args, {\n\t\t\t\tcwd: request.cwd,\n\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\tenv: request.env,\n\t\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t\t});\n\t\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => request.onStdout(chunk));\n\t\t\tchild.stderr?.on(\"data\", (chunk: Buffer) => request.onStderr(chunk));\n\t\t\tchild.stdin?.end(request.stdin ?? \"\");\n\t\t\tconst terminal = await waitForChildProcessWithTermination(child, {\n\t\t\t\tkillGraceMs: PYTHON_KILL_GRACE_MS,\n\t\t\t\tsignal: request.signal,\n\t\t\t\ttimeoutMs: request.timeoutMs,\n\t\t\t});\n\t\t\treturn { exitCode: terminal.code, reason: terminal.reason, signal: child.signalCode };\n\t\t},\n\t};\n}\n\nfunction renderStreamNotice(label: string, path: string | undefined, error: string | undefined): string | undefined {\n\tif (path) return `[${label} truncated; full output: ${path}]`;\n\tif (error) return `[${label} truncated; full-output artifact failed: ${error}]`;\n\treturn undefined;\n}\n\nexport function createPythonToolDefinition(\n\tbaseCwd: string,\n\toptions: PythonToolOptions = {},\n): ToolDefinition<typeof pythonSchema, PythonToolDetails> {\n\tconst resolveRuntime = options.resolveRuntime ?? (() => ensurePythonRuntime({ silent: true }));\n\tconst operations = options.operations ?? createLocalPythonOperations();\n\treturn {\n\t\tname: \"python\",\n\t\tlabel: \"python\",\n\t\tdescription: `Run a bounded Python snippet or script without a shell. Pi resolves Python through uv, defaults to a ${DEFAULT_PYTHON_TIMEOUT_SECONDS}-second wall-clock timeout (maximum ${MAX_PYTHON_TIMEOUT_SECONDS}), streams bounded stdout/stderr, and spills truncated full output to the process work directory rather than the repository.`,\n\t\tpromptSnippet: \"Run bounded Python code/scripts through Pi's uv runtime.\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use python for bounded scripts/data transforms/cross-platform logic clearer than shell.\",\n\t\t\t\"Small exact source edits: read/edit/write. Python transforms: preserve encoding/newlines, write atomically, verify diff.\",\n\t\t\t\"Scope roots/filters; never scan home/filesystem recursively. Raise timeout only for justified bounded work.\",\n\t\t\t\"Never inspect/print credentials; use activated environment only through credential consumer.\",\n\t\t\t\"Explicit approval required: destructive deletion, publish/push/release, long-running services.\",\n\t\t],\n\t\tparameters: pythonSchema,\n\t\tasync execute(_toolCallId, input, signal) {\n\t\t\tconst hasCode = typeof input.code === \"string\";\n\t\t\tconst hasScript = typeof input.scriptPath === \"string\" && input.scriptPath.trim().length > 0;\n\t\t\tif (hasCode === hasScript) throw new Error(\"Provide exactly one of code or scriptPath.\");\n\t\t\tconst cwd = await resolveWorkingDirectory(baseCwd, input.cwd);\n\t\t\tconst scriptPath = hasScript ? await resolveScriptPath(cwd, input.scriptPath as string) : undefined;\n\t\t\tconst runtime = await resolveRuntime();\n\t\t\tif (runtime.status !== \"ready\") throw new Error(runtime.reason);\n\t\t\tconst args = input.args ? [...input.args] : [];\n\t\t\tconst timeoutSeconds = clampInteger(\n\t\t\t\tinput.timeoutSeconds,\n\t\t\t\tDEFAULT_PYTHON_TIMEOUT_SECONDS,\n\t\t\t\t1,\n\t\t\t\tMAX_PYTHON_TIMEOUT_SECONDS,\n\t\t\t);\n\t\t\tconst maxOutputBytes = clampInteger(\n\t\t\t\tinput.maxOutputBytes,\n\t\t\t\t50 * 1024,\n\t\t\t\tMIN_PYTHON_OUTPUT_BYTES,\n\t\t\t\tMAX_PYTHON_OUTPUT_BYTES,\n\t\t\t);\n\t\t\tconst accumulatorOptions = {\n\t\t\t\tmaxBytes: maxOutputBytes,\n\t\t\t\t...(options.outputDirectory ? { tempDirectory: options.outputDirectory } : {}),\n\t\t\t};\n\t\t\tconst stdout = new OutputAccumulator({ ...accumulatorOptions, tempFilePrefix: \"pi-python-stdout\" });\n\t\t\tconst stderr = new OutputAccumulator({ ...accumulatorOptions, tempFilePrefix: \"pi-python-stderr\" });\n\t\t\tconst finishStreams = () => {\n\t\t\t\tstdout.finish();\n\t\t\t\tstderr.finish();\n\t\t\t\treturn {\n\t\t\t\t\tstdout: stdout.snapshot({ persistIfTruncated: true }),\n\t\t\t\t\tstderr: stderr.snapshot({ persistIfTruncated: true }),\n\t\t\t\t};\n\t\t\t};\n\t\t\tlet execution: PythonExecutionResult;\n\t\t\ttry {\n\t\t\t\texecution = await withExclusiveMutationBarrier(() => {\n\t\t\t\t\tconst environment: NodeJS.ProcessEnv = {\n\t\t\t\t\t\t...process.env,\n\t\t\t\t\t\t...options.environment?.(cwd),\n\t\t\t\t\t\tPI_PYTHON_TOOL: \"1\",\n\t\t\t\t\t\tPYTHONDONTWRITEBYTECODE: \"1\",\n\t\t\t\t\t\tPYTHONIOENCODING: \"utf-8\",\n\t\t\t\t\t\tPYTHONUNBUFFERED: \"1\",\n\t\t\t\t\t\tPYTHONUTF8: \"1\",\n\t\t\t\t\t};\n\t\t\t\t\tfor (const name of options.omitEnvironmentVariables ?? []) delete environment[name];\n\t\t\t\t\treturn operations.exec({\n\t\t\t\t\t\tpython: runtime.pythonPath,\n\t\t\t\t\t\targs: scriptPath ? [\"-B\", scriptPath, ...args] : [\"-B\", \"-\", ...args],\n\t\t\t\t\t\tcwd,\n\t\t\t\t\t\tstdin: hasCode ? input.code : undefined,\n\t\t\t\t\t\ttimeoutMs: timeoutSeconds * 1000,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\tenv: environment,\n\t\t\t\t\t\tonStdout: (chunk) => stdout.append(chunk),\n\t\t\t\t\t\tonStderr: (chunk) => stderr.append(chunk),\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t\tconst snapshots = finishStreams();\n\t\t\t\tconst sections: string[] = [];\n\t\t\t\tif (snapshots.stdout.content) sections.push(snapshots.stdout.content.trimEnd());\n\t\t\t\tif (snapshots.stderr.content) sections.push(`[stderr]\\n${snapshots.stderr.content.trimEnd()}`);\n\t\t\t\tconst stdoutNotice = renderStreamNotice(\n\t\t\t\t\t\"stdout\",\n\t\t\t\t\tsnapshots.stdout.fullOutputPath,\n\t\t\t\t\tsnapshots.stdout.fullOutputError,\n\t\t\t\t);\n\t\t\t\tconst stderrNotice = renderStreamNotice(\n\t\t\t\t\t\"stderr\",\n\t\t\t\t\tsnapshots.stderr.fullOutputPath,\n\t\t\t\t\tsnapshots.stderr.fullOutputError,\n\t\t\t\t);\n\t\t\t\tif (stdoutNotice) sections.push(stdoutNotice);\n\t\t\t\tif (stderrNotice) sections.push(stderrNotice);\n\t\t\t\tconst status = `[python exitCode=${execution.exitCode ?? \"null\"}${execution.signal ? `; signal=${execution.signal}` : \"\"}]`;\n\t\t\t\tsections.push(status);\n\t\t\t\tconst text = sections.join(\"\\n\\n\");\n\t\t\t\tif (execution.reason === \"timeout\")\n\t\t\t\t\tthrow new Error(`${text}\\n\\nPython timed out after ${timeoutSeconds} seconds`);\n\t\t\t\tif (execution.reason === \"aborted\") throw new Error(`${text}\\n\\nPython execution aborted`);\n\t\t\t\tif (execution.exitCode !== 0) {\n\t\t\t\t\tconst termination = execution.signal\n\t\t\t\t\t\t? `signal ${execution.signal}`\n\t\t\t\t\t\t: `code ${execution.exitCode ?? \"unknown\"}`;\n\t\t\t\t\tthrow new Error(`${text}\\n\\nPython exited with ${termination}`);\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tmode: scriptPath ? \"script\" : \"code\",\n\t\t\t\t\t\tcwd,\n\t\t\t\t\t\tuvPath: runtime.uvPath,\n\t\t\t\t\t\tpythonPath: runtime.pythonPath,\n\t\t\t\t\t\tscriptPath,\n\t\t\t\t\t\targs,\n\t\t\t\t\t\texitCode: execution.exitCode,\n\t\t\t\t\t\tsignal: execution.signal,\n\t\t\t\t\t\ttimedOut: false,\n\t\t\t\t\t\t...(snapshots.stdout.truncation.truncated ? { stdoutTruncation: snapshots.stdout.truncation } : {}),\n\t\t\t\t\t\t...(snapshots.stderr.truncation.truncated ? { stderrTruncation: snapshots.stderr.truncation } : {}),\n\t\t\t\t\t\tstdoutOutputPath: snapshots.stdout.fullOutputPath,\n\t\t\t\t\t\tstderrOutputPath: snapshots.stderr.fullOutputPath,\n\t\t\t\t\t\tstdoutOutputError: snapshots.stdout.fullOutputError,\n\t\t\t\t\t\tstderrOutputError: snapshots.stderr.fullOutputError,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} finally {\n\t\t\t\tawait Promise.all([stdout.closeTempFile(), stderr.closeTempFile()]);\n\t\t\t}\n\t\t},\n\t\trenderCall(args, theme) {\n\t\t\tconst mode = args.scriptPath ? args.scriptPath : \"code\";\n\t\t\treturn new Text(`${theme.fg(\"toolTitle\", theme.bold(\"python\"))} ${theme.fg(\"muted\", mode)}`, 0, 0);\n\t\t},\n\t\trenderResult(result, { expanded, isPartial }, theme) {\n\t\t\tif (isPartial) return new Text(theme.fg(\"warning\", \"python running\"), 0, 0);\n\t\t\tconst details = result.details as PythonToolDetails | undefined;\n\t\t\tif (!details) return new Text(theme.fg(\"dim\", \"python done\"), 0, 0);\n\t\t\tconst status =\n\t\t\t\tdetails.exitCode === 0 && !details.timedOut ? \"python ok\" : `python exit ${details.exitCode ?? \"unknown\"}`;\n\t\t\tlet text = theme.fg(details.exitCode === 0 ? \"success\" : \"warning\", status);\n\t\t\tif (expanded) {\n\t\t\t\tconst content = result.content[0];\n\t\t\t\tif (content?.type === \"text\") {\n\t\t\t\t\tconst lines = content.text.split(\"\\n\").slice(-20);\n\t\t\t\t\tfor (const line of lines) text += `\\n${theme.fg(\"dim\", line)}`;\n\t\t\t\t}\n\t\t\t\tfor (const outputPath of [details.stdoutOutputPath, details.stderrOutputPath]) {\n\t\t\t\t\tif (outputPath) text += `\\n${theme.fg(\"muted\", `full output: ${outputPath}`)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new Text(text, 0, 0);\n\t\t},\n\t};\n}\n\nexport function createPythonTool(baseCwd: string, options?: PythonToolOptions): AgentTool<typeof pythonSchema> {\n\treturn wrapToolDefinition(createPythonToolDefinition(baseCwd, options));\n}\n"]}
@@ -2,6 +2,7 @@ import type { AgentTool } from "@caupulican/pi-agent-core";
2
2
  import { type TruncationResult } from "@caupulican/pi-agent-core/node";
3
3
  import { type Static, Type } from "typebox";
4
4
  import type { ToolDefinition } from "../extensions/types.ts";
5
+ import { type FileFailureRecoveryAuthority } from "./file-failure-recovery.ts";
5
6
  declare const readSchema: Type.TObject<{
6
7
  path: Type.TString;
7
8
  offset: Type.TOptional<Type.TNumber>;
@@ -58,6 +59,8 @@ export interface ReadToolOptions {
58
59
  autoResizeImages?: boolean;
59
60
  /** Custom operations for file reading. Default: local filesystem */
60
61
  operations?: ReadOperations;
62
+ /** Shared backend identity for exact cross-tool recovery with custom operations. */
63
+ failureRecoveryAuthority?: FileFailureRecoveryAuthority;
61
64
  /** Whole-file load budget for text reads; larger files stream line slices instead. Default 16 MiB. */
62
65
  maxTextReadBytes?: number;
63
66
  /** Pathology guard for image reads; larger images return downscale guidance. Default 128 MiB. */
@@ -1 +1 @@
1
- {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/core/tools/read.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAIN,KAAK,gBAAgB,EAErB,MAAM,gCAAgC,CAAC;AAMxC,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAQ5C,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,wBAAwB,CAAC;AAKtF,QAAA,MAAM,UAAU;;;;;;;EAWd,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAgBD;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B,qCAAqC;IACrC,QAAQ,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,+CAA+C;IAC/C,MAAM,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,sEAAsE;IACtE,mBAAmB,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IACnF,8EAA8E;IAC9E,IAAI,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC3D;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAg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,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACjD,kEAAkE;IAClE,UAAU,EAAE,OAAO,CAAC;CACpB;AAiFD,MAAM,WAAW,eAAe;IAC/B,oEAAoE;IACpE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,oEAAoE;IACpE,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,oFAAoF;IACpF,wBAAwB,CAAC,EAAE,4BAA4B,CAAC;IACxD,sGAAsG;IACtG,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iGAAiG;IACjG,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAkJD,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CA+UhE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG"}
@@ -13,6 +13,7 @@ import { formatDimensionNote, resizeImage } from "../../utils/image-resize.js";
13
13
  import { detectSupportedImageMimeTypeFromFile } from "../../utils/mime.js";
14
14
  import { formatPathRelativeToCwdOrAbsolute } from "../../utils/paths.js";
15
15
  import { getProcessWorkRun } from "../../utils/work-directory.js";
16
+ import { FILE_CURRENT_TEXT_RECOVERY_TARGET_KIND, FILE_EXISTS_RECOVERY_TARGET_KIND, fileRecoveryTarget, selectFileFailureRecoveryAuthority, } from "./file-failure-recovery.js";
16
17
  import { resolveReadPathAsync, resolveToCwd } from "./path-utils.js";
17
18
  import { getTextOutput, renderToolPath, replaceTabs, str } from "./render-utils.js";
18
19
  import { wrapToolDefinition } from "./tool-definition-wrapper.js";
@@ -222,6 +223,7 @@ function formatReadResult(args, result, options, theme, showImages, _cwd, isErro
222
223
  export function createReadToolDefinition(cwd, options) {
223
224
  const autoResizeImages = options?.autoResizeImages ?? true;
224
225
  const ops = options?.operations ?? defaultReadOperations;
226
+ const failureRecoveryAuthority = selectFileFailureRecoveryAuthority(options?.operations !== undefined, options?.failureRecoveryAuthority);
225
227
  const maxTextReadBytes = options?.maxTextReadBytes ?? DEFAULT_MAX_TEXT_READ_BYTES;
226
228
  const maxImageReadBytes = options?.maxImageReadBytes ?? DEFAULT_MAX_IMAGE_READ_BYTES;
227
229
  return {
@@ -231,6 +233,21 @@ export function createReadToolDefinition(cwd, options) {
231
233
  promptSnippet: "Read file contents",
232
234
  promptGuidelines: ["Use read to examine files instead of cat or sed."],
233
235
  parameters: readSchema,
236
+ failureRecovery: {
237
+ getFailureTargets: (params, failure) => failure.failureCode === "file_not_found" && failureRecoveryAuthority
238
+ ? [fileRecoveryTarget(failureRecoveryAuthority, FILE_EXISTS_RECOVERY_TARGET_KIND, params.path, cwd)]
239
+ : [],
240
+ actions: failureRecoveryAuthority
241
+ ? [
242
+ {
243
+ kind: "correct",
244
+ authority: failureRecoveryAuthority.contractAuthority,
245
+ targetKind: FILE_CURRENT_TEXT_RECOVERY_TARGET_KIND,
246
+ instruction: "Use read on the failed edit path to obtain current text, then submit a changed edit with exact current text.",
247
+ },
248
+ ]
249
+ : [],
250
+ },
234
251
  async execute(_toolCallId, { path, offset, limit, lineNumbers, tail, filter, }, signal, _onUpdate, ctx) {
235
252
  return new Promise((resolve, reject) => {
236
253
  if (signal?.aborted) {