@caupulican/pi-adaptative 0.81.38 → 0.81.39

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 (433) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/dist/bundled-resources/extensions/tmux-agent-manager/README.md +18 -1
  3. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts +131 -0
  4. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts.map +1 -0
  5. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js +196 -0
  6. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js.map +1 -0
  7. package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.ts +308 -0
  8. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts +22 -2
  9. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
  10. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +585 -24
  11. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
  12. package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +749 -27
  13. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/__init__.py +43 -0
  14. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/fs.py +270 -0
  15. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/search.py +252 -0
  16. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/strings.py +399 -0
  17. package/dist/bundled-resources/runtimes/pi-shell-engine/commands/text.py +575 -0
  18. package/dist/bundled-resources/runtimes/pi-shell-engine/context.py +52 -0
  19. package/dist/bundled-resources/runtimes/pi-shell-engine/errors.py +49 -0
  20. package/dist/bundled-resources/runtimes/pi-shell-engine/exec.py +734 -0
  21. package/dist/bundled-resources/runtimes/pi-shell-engine/expand.py +238 -0
  22. package/dist/bundled-resources/runtimes/pi-shell-engine/main.py +132 -0
  23. package/dist/bundled-resources/runtimes/pi-shell-engine/nodes.py +116 -0
  24. package/dist/bundled-resources/runtimes/pi-shell-engine/parser.py +287 -0
  25. package/dist/bundled-resources/runtimes/pi-shell-engine/proc.py +137 -0
  26. package/dist/bundled-resources/runtimes/pi-shell-engine/state.py +100 -0
  27. package/dist/bundled-resources/runtimes/pi-shell-engine/tokens.py +579 -0
  28. package/dist/bundled-resources/skills/tool-call-repair/SKILL.md +19 -9
  29. package/dist/bundled-resources/skills/tool-call-repair/references/failure-grammar.md +22 -5
  30. package/dist/bundled-resources/skills/tool-call-repair/references/repair-catalogue.md +5 -5
  31. package/dist/bundled-resources/skills/tool-call-repair/references/text-protocol-grammar.md +28 -7
  32. package/dist/cli/args.d.ts +3 -0
  33. package/dist/cli/args.d.ts.map +1 -1
  34. package/dist/cli/args.js +15 -0
  35. package/dist/cli/args.js.map +1 -1
  36. package/dist/core/agent-paths.d.ts +49 -0
  37. package/dist/core/agent-paths.d.ts.map +1 -0
  38. package/dist/core/agent-paths.js +107 -0
  39. package/dist/core/agent-paths.js.map +1 -0
  40. package/dist/core/agent-session-services.d.ts.map +1 -1
  41. package/dist/core/agent-session-services.js +3 -3
  42. package/dist/core/agent-session-services.js.map +1 -1
  43. package/dist/core/agent-session.d.ts +234 -17
  44. package/dist/core/agent-session.d.ts.map +1 -1
  45. package/dist/core/agent-session.js +484 -62
  46. package/dist/core/agent-session.js.map +1 -1
  47. package/dist/core/autonomy/contracts.d.ts +9 -0
  48. package/dist/core/autonomy/contracts.d.ts.map +1 -1
  49. package/dist/core/autonomy/contracts.js.map +1 -1
  50. package/dist/core/autonomy/lane-tracker.d.ts +10 -1
  51. package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
  52. package/dist/core/autonomy/lane-tracker.js +5 -1
  53. package/dist/core/autonomy/lane-tracker.js.map +1 -1
  54. package/dist/core/background-lane-controller.d.ts +122 -6
  55. package/dist/core/background-lane-controller.d.ts.map +1 -1
  56. package/dist/core/background-lane-controller.js +446 -89
  57. package/dist/core/background-lane-controller.js.map +1 -1
  58. package/dist/core/bash-execution-controller.d.ts +4 -0
  59. package/dist/core/bash-execution-controller.d.ts.map +1 -1
  60. package/dist/core/bash-execution-controller.js +7 -1
  61. package/dist/core/bash-execution-controller.js.map +1 -1
  62. package/dist/core/compaction-support.d.ts +13 -3
  63. package/dist/core/compaction-support.d.ts.map +1 -1
  64. package/dist/core/compaction-support.js +43 -7
  65. package/dist/core/compaction-support.js.map +1 -1
  66. package/dist/core/context/context-audit.d.ts +33 -1
  67. package/dist/core/context/context-audit.d.ts.map +1 -1
  68. package/dist/core/context/context-audit.js +31 -5
  69. package/dist/core/context/context-audit.js.map +1 -1
  70. package/dist/core/context-gc.d.ts.map +1 -1
  71. package/dist/core/context-gc.js +16 -1
  72. package/dist/core/context-gc.js.map +1 -1
  73. package/dist/core/context-pipeline.d.ts +26 -4
  74. package/dist/core/context-pipeline.d.ts.map +1 -1
  75. package/dist/core/context-pipeline.js +137 -14
  76. package/dist/core/context-pipeline.js.map +1 -1
  77. package/dist/core/cost-guard.d.ts +19 -3
  78. package/dist/core/cost-guard.d.ts.map +1 -1
  79. package/dist/core/cost-guard.js +18 -3
  80. package/dist/core/cost-guard.js.map +1 -1
  81. package/dist/core/delegation/session-worker-result.d.ts +34 -4
  82. package/dist/core/delegation/session-worker-result.d.ts.map +1 -1
  83. package/dist/core/delegation/session-worker-result.js +64 -4
  84. package/dist/core/delegation/session-worker-result.js.map +1 -1
  85. package/dist/core/delegation/worker-result.d.ts +42 -1
  86. package/dist/core/delegation/worker-result.d.ts.map +1 -1
  87. package/dist/core/delegation/worker-result.js +68 -0
  88. package/dist/core/delegation/worker-result.js.map +1 -1
  89. package/dist/core/extensions/loader.d.ts.map +1 -1
  90. package/dist/core/extensions/loader.js +20 -0
  91. package/dist/core/extensions/loader.js.map +1 -1
  92. package/dist/core/extensions/runner.d.ts.map +1 -1
  93. package/dist/core/extensions/runner.js +1 -0
  94. package/dist/core/extensions/runner.js.map +1 -1
  95. package/dist/core/extensions/types.d.ts +51 -0
  96. package/dist/core/extensions/types.d.ts.map +1 -1
  97. package/dist/core/extensions/types.js.map +1 -1
  98. package/dist/core/goal-loop-controller.d.ts +17 -1
  99. package/dist/core/goal-loop-controller.d.ts.map +1 -1
  100. package/dist/core/goal-loop-controller.js +79 -11
  101. package/dist/core/goal-loop-controller.js.map +1 -1
  102. package/dist/core/goals/goal-continuation-controller.d.ts +48 -2
  103. package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
  104. package/dist/core/goals/goal-continuation-controller.js +77 -0
  105. package/dist/core/goals/goal-continuation-controller.js.map +1 -1
  106. package/dist/core/goals/goal-continuation-defaults.d.ts +39 -0
  107. package/dist/core/goals/goal-continuation-defaults.d.ts.map +1 -1
  108. package/dist/core/goals/goal-continuation-defaults.js +42 -0
  109. package/dist/core/goals/goal-continuation-defaults.js.map +1 -1
  110. package/dist/core/goals/goal-continuation-prompt.d.ts +4 -0
  111. package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -1
  112. package/dist/core/goals/goal-continuation-prompt.js +51 -10
  113. package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
  114. package/dist/core/goals/goal-runtime-snapshot.d.ts +101 -2
  115. package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -1
  116. package/dist/core/goals/goal-runtime-snapshot.js +87 -4
  117. package/dist/core/goals/goal-runtime-snapshot.js.map +1 -1
  118. package/dist/core/goals/goal-state.d.ts +89 -1
  119. package/dist/core/goals/goal-state.d.ts.map +1 -1
  120. package/dist/core/goals/goal-state.js +71 -5
  121. package/dist/core/goals/goal-state.js.map +1 -1
  122. package/dist/core/goals/goal-tool-core.d.ts +56 -2
  123. package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
  124. package/dist/core/goals/goal-tool-core.js +111 -5
  125. package/dist/core/goals/goal-tool-core.js.map +1 -1
  126. package/dist/core/goals/session-goal-state.d.ts +11 -2
  127. package/dist/core/goals/session-goal-state.d.ts.map +1 -1
  128. package/dist/core/goals/session-goal-state.js +32 -17
  129. package/dist/core/goals/session-goal-state.js.map +1 -1
  130. package/dist/core/keybindings.d.ts +10 -0
  131. package/dist/core/keybindings.d.ts.map +1 -1
  132. package/dist/core/keybindings.js +10 -2
  133. package/dist/core/keybindings.js.map +1 -1
  134. package/dist/core/learning/observation-store.d.ts +12 -3
  135. package/dist/core/learning/observation-store.d.ts.map +1 -1
  136. package/dist/core/learning/observation-store.js +30 -15
  137. package/dist/core/learning/observation-store.js.map +1 -1
  138. package/dist/core/learning/skill-curator.d.ts +5 -1
  139. package/dist/core/learning/skill-curator.d.ts.map +1 -1
  140. package/dist/core/learning/skill-curator.js +21 -19
  141. package/dist/core/learning/skill-curator.js.map +1 -1
  142. package/dist/core/local-runtime-controller.d.ts +65 -3
  143. package/dist/core/local-runtime-controller.d.ts.map +1 -1
  144. package/dist/core/local-runtime-controller.js +186 -26
  145. package/dist/core/local-runtime-controller.js.map +1 -1
  146. package/dist/core/memory/providers/file-store.d.ts +1 -1
  147. package/dist/core/memory/providers/file-store.d.ts.map +1 -1
  148. package/dist/core/memory/providers/file-store.js +6 -6
  149. package/dist/core/memory/providers/file-store.js.map +1 -1
  150. package/dist/core/model-capability.d.ts +34 -0
  151. package/dist/core/model-capability.d.ts.map +1 -1
  152. package/dist/core/model-capability.js +42 -1
  153. package/dist/core/model-capability.js.map +1 -1
  154. package/dist/core/model-router/tool-escalation.d.ts +15 -0
  155. package/dist/core/model-router/tool-escalation.d.ts.map +1 -1
  156. package/dist/core/model-router/tool-escalation.js +23 -1
  157. package/dist/core/model-router/tool-escalation.js.map +1 -1
  158. package/dist/core/model-router-controller.d.ts +34 -7
  159. package/dist/core/model-router-controller.d.ts.map +1 -1
  160. package/dist/core/model-router-controller.js +95 -16
  161. package/dist/core/model-router-controller.js.map +1 -1
  162. package/dist/core/models/adaptation-store.d.ts +7 -0
  163. package/dist/core/models/adaptation-store.d.ts.map +1 -1
  164. package/dist/core/models/adaptation-store.js +47 -11
  165. package/dist/core/models/adaptation-store.js.map +1 -1
  166. package/dist/core/models/default-model-suggestions.d.ts.map +1 -1
  167. package/dist/core/models/default-model-suggestions.js +17 -0
  168. package/dist/core/models/default-model-suggestions.js.map +1 -1
  169. package/dist/core/models/fitness-store.d.ts +3 -0
  170. package/dist/core/models/fitness-store.d.ts.map +1 -1
  171. package/dist/core/models/fitness-store.js +11 -2
  172. package/dist/core/models/fitness-store.js.map +1 -1
  173. package/dist/core/models/llamacpp-runtime.d.ts +180 -0
  174. package/dist/core/models/llamacpp-runtime.d.ts.map +1 -0
  175. package/dist/core/models/llamacpp-runtime.js +475 -0
  176. package/dist/core/models/llamacpp-runtime.js.map +1 -0
  177. package/dist/core/models/local-registration.d.ts +40 -0
  178. package/dist/core/models/local-registration.d.ts.map +1 -1
  179. package/dist/core/models/local-registration.js +94 -5
  180. package/dist/core/models/local-registration.js.map +1 -1
  181. package/dist/core/models/local-runtime.d.ts.map +1 -1
  182. package/dist/core/models/local-runtime.js +6 -5
  183. package/dist/core/models/local-runtime.js.map +1 -1
  184. package/dist/core/models/model-ref.d.ts +7 -0
  185. package/dist/core/models/model-ref.d.ts.map +1 -1
  186. package/dist/core/models/model-ref.js +26 -0
  187. package/dist/core/models/model-ref.js.map +1 -1
  188. package/dist/core/models/needle-runtime.d.ts +257 -0
  189. package/dist/core/models/needle-runtime.d.ts.map +1 -0
  190. package/dist/core/models/needle-runtime.js +519 -0
  191. package/dist/core/models/needle-runtime.js.map +1 -0
  192. package/dist/core/models/prism-llamacpp-lifecycle.d.ts +89 -0
  193. package/dist/core/models/prism-llamacpp-lifecycle.d.ts.map +1 -0
  194. package/dist/core/models/prism-llamacpp-lifecycle.js +121 -0
  195. package/dist/core/models/prism-llamacpp-lifecycle.js.map +1 -0
  196. package/dist/core/package-manager.d.ts.map +1 -1
  197. package/dist/core/package-manager.js +11 -10
  198. package/dist/core/package-manager.js.map +1 -1
  199. package/dist/core/process-matrix/codes.d.ts +72 -0
  200. package/dist/core/process-matrix/codes.d.ts.map +1 -0
  201. package/dist/core/process-matrix/codes.js +15 -0
  202. package/dist/core/process-matrix/codes.js.map +1 -0
  203. package/dist/core/process-matrix/runtime.d.ts +63 -0
  204. package/dist/core/process-matrix/runtime.d.ts.map +1 -0
  205. package/dist/core/process-matrix/runtime.js +310 -0
  206. package/dist/core/process-matrix/runtime.js.map +1 -0
  207. package/dist/core/process-matrix/store.d.ts +22 -0
  208. package/dist/core/process-matrix/store.d.ts.map +1 -0
  209. package/dist/core/process-matrix/store.js +80 -0
  210. package/dist/core/process-matrix/store.js.map +1 -0
  211. package/dist/core/process-matrix/supervisor.d.ts +72 -0
  212. package/dist/core/process-matrix/supervisor.d.ts.map +1 -0
  213. package/dist/core/process-matrix/supervisor.js +130 -0
  214. package/dist/core/process-matrix/supervisor.js.map +1 -0
  215. package/dist/core/profile-registry.d.ts +7 -0
  216. package/dist/core/profile-registry.d.ts.map +1 -1
  217. package/dist/core/profile-registry.js +20 -0
  218. package/dist/core/profile-registry.js.map +1 -1
  219. package/dist/core/python-runtime.d.ts.map +1 -1
  220. package/dist/core/python-runtime.js +3 -3
  221. package/dist/core/python-runtime.js.map +1 -1
  222. package/dist/core/reflection-controller.d.ts +29 -5
  223. package/dist/core/reflection-controller.d.ts.map +1 -1
  224. package/dist/core/reflection-controller.js +215 -126
  225. package/dist/core/reflection-controller.js.map +1 -1
  226. package/dist/core/reload-blockers.d.ts +36 -0
  227. package/dist/core/reload-blockers.d.ts.map +1 -1
  228. package/dist/core/reload-blockers.js +44 -0
  229. package/dist/core/reload-blockers.js.map +1 -1
  230. package/dist/core/resource-loader.d.ts.map +1 -1
  231. package/dist/core/resource-loader.js +8 -7
  232. package/dist/core/resource-loader.js.map +1 -1
  233. package/dist/core/runtime-builder.d.ts +58 -5
  234. package/dist/core/runtime-builder.d.ts.map +1 -1
  235. package/dist/core/runtime-builder.js +209 -25
  236. package/dist/core/runtime-builder.js.map +1 -1
  237. package/dist/core/scout-controller.d.ts +6 -0
  238. package/dist/core/scout-controller.d.ts.map +1 -1
  239. package/dist/core/scout-controller.js +66 -52
  240. package/dist/core/scout-controller.js.map +1 -1
  241. package/dist/core/sdk.d.ts.map +1 -1
  242. package/dist/core/sdk.js +3 -3
  243. package/dist/core/sdk.js.map +1 -1
  244. package/dist/core/session-role.d.ts +31 -0
  245. package/dist/core/session-role.d.ts.map +1 -0
  246. package/dist/core/session-role.js +52 -0
  247. package/dist/core/session-role.js.map +1 -0
  248. package/dist/core/settings-manager.d.ts +42 -3
  249. package/dist/core/settings-manager.d.ts.map +1 -1
  250. package/dist/core/settings-manager.js +94 -60
  251. package/dist/core/settings-manager.js.map +1 -1
  252. package/dist/core/system-prompt-builder.d.ts +12 -0
  253. package/dist/core/system-prompt-builder.d.ts.map +1 -1
  254. package/dist/core/system-prompt-builder.js +6 -0
  255. package/dist/core/system-prompt-builder.js.map +1 -1
  256. package/dist/core/system-prompt.d.ts +14 -1
  257. package/dist/core/system-prompt.d.ts.map +1 -1
  258. package/dist/core/system-prompt.js +20 -3
  259. package/dist/core/system-prompt.js.map +1 -1
  260. package/dist/core/tasks/session-task-state.d.ts +11 -2
  261. package/dist/core/tasks/session-task-state.d.ts.map +1 -1
  262. package/dist/core/tasks/session-task-state.js +27 -11
  263. package/dist/core/tasks/session-task-state.js.map +1 -1
  264. package/dist/core/tasks/task-contract-monitor.d.ts +45 -0
  265. package/dist/core/tasks/task-contract-monitor.d.ts.map +1 -0
  266. package/dist/core/tasks/task-contract-monitor.js +56 -0
  267. package/dist/core/tasks/task-contract-monitor.js.map +1 -0
  268. package/dist/core/tasks/task-state.d.ts +8 -0
  269. package/dist/core/tasks/task-state.d.ts.map +1 -1
  270. package/dist/core/tasks/task-state.js +28 -1
  271. package/dist/core/tasks/task-state.js.map +1 -1
  272. package/dist/core/tool-gate-controller.d.ts.map +1 -1
  273. package/dist/core/tool-gate-controller.js +5 -0
  274. package/dist/core/tool-gate-controller.js.map +1 -1
  275. package/dist/core/tool-recovery-log-records.d.ts +7 -0
  276. package/dist/core/tool-recovery-log-records.d.ts.map +1 -1
  277. package/dist/core/tool-recovery-log-records.js +14 -6
  278. package/dist/core/tool-recovery-log-records.js.map +1 -1
  279. package/dist/core/tool-selection/promotion.d.ts +54 -0
  280. package/dist/core/tool-selection/promotion.d.ts.map +1 -0
  281. package/dist/core/tool-selection/promotion.js +81 -0
  282. package/dist/core/tool-selection/promotion.js.map +1 -0
  283. package/dist/core/tool-selection/tool-performance-store.d.ts +37 -0
  284. package/dist/core/tool-selection/tool-performance-store.d.ts.map +1 -1
  285. package/dist/core/tool-selection/tool-performance-store.js +87 -3
  286. package/dist/core/tool-selection/tool-performance-store.js.map +1 -1
  287. package/dist/core/tool-selection/tool-selection-controller.d.ts +45 -0
  288. package/dist/core/tool-selection/tool-selection-controller.d.ts.map +1 -1
  289. package/dist/core/tool-selection/tool-selection-controller.js +96 -0
  290. package/dist/core/tool-selection/tool-selection-controller.js.map +1 -1
  291. package/dist/core/tools/bash.d.ts +18 -0
  292. package/dist/core/tools/bash.d.ts.map +1 -1
  293. package/dist/core/tools/bash.js +95 -16
  294. package/dist/core/tools/bash.js.map +1 -1
  295. package/dist/core/tools/delegate-status.d.ts +14 -0
  296. package/dist/core/tools/delegate-status.d.ts.map +1 -1
  297. package/dist/core/tools/delegate-status.js +82 -7
  298. package/dist/core/tools/delegate-status.js.map +1 -1
  299. package/dist/core/tools/delegate.d.ts.map +1 -1
  300. package/dist/core/tools/delegate.js +25 -8
  301. package/dist/core/tools/delegate.js.map +1 -1
  302. package/dist/core/tools/goal.d.ts +94 -3
  303. package/dist/core/tools/goal.d.ts.map +1 -1
  304. package/dist/core/tools/goal.js +165 -15
  305. package/dist/core/tools/goal.js.map +1 -1
  306. package/dist/core/tools/model-fitness.d.ts +7 -0
  307. package/dist/core/tools/model-fitness.d.ts.map +1 -1
  308. package/dist/core/tools/model-fitness.js +2 -2
  309. package/dist/core/tools/model-fitness.js.map +1 -1
  310. package/dist/core/tools/shell-contract-router.d.ts +6 -1
  311. package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
  312. package/dist/core/tools/shell-contract-router.js +23 -2
  313. package/dist/core/tools/shell-contract-router.js.map +1 -1
  314. package/dist/core/tools/shell-session.d.ts +89 -0
  315. package/dist/core/tools/shell-session.d.ts.map +1 -0
  316. package/dist/core/tools/shell-session.js +432 -0
  317. package/dist/core/tools/shell-session.js.map +1 -0
  318. package/dist/core/tools/task-steps.d.ts +4 -0
  319. package/dist/core/tools/task-steps.d.ts.map +1 -1
  320. package/dist/core/tools/task-steps.js +63 -8
  321. package/dist/core/tools/task-steps.js.map +1 -1
  322. package/dist/core/tools/tmux-dispatch.d.ts +86 -0
  323. package/dist/core/tools/tmux-dispatch.d.ts.map +1 -0
  324. package/dist/core/tools/tmux-dispatch.js +91 -0
  325. package/dist/core/tools/tmux-dispatch.js.map +1 -0
  326. package/dist/core/tools/windows-shell-engine.d.ts +42 -0
  327. package/dist/core/tools/windows-shell-engine.d.ts.map +1 -0
  328. package/dist/core/tools/windows-shell-engine.js +153 -0
  329. package/dist/core/tools/windows-shell-engine.js.map +1 -0
  330. package/dist/core/tools/windows-shell-state.d.ts +40 -0
  331. package/dist/core/tools/windows-shell-state.d.ts.map +1 -0
  332. package/dist/core/tools/windows-shell-state.js +59 -0
  333. package/dist/core/tools/windows-shell-state.js.map +1 -0
  334. package/dist/core/tools/worktree-sync.d.ts +24 -0
  335. package/dist/core/tools/worktree-sync.d.ts.map +1 -0
  336. package/dist/core/tools/worktree-sync.js +338 -0
  337. package/dist/core/tools/worktree-sync.js.map +1 -0
  338. package/dist/core/trust-manager.d.ts +4 -1
  339. package/dist/core/trust-manager.d.ts.map +1 -1
  340. package/dist/core/trust-manager.js +20 -2
  341. package/dist/core/trust-manager.js.map +1 -1
  342. package/dist/core/util/atomic-file.d.ts +55 -0
  343. package/dist/core/util/atomic-file.d.ts.map +1 -0
  344. package/dist/core/util/atomic-file.js +255 -0
  345. package/dist/core/util/atomic-file.js.map +1 -0
  346. package/dist/core/util/minimatch-cache.d.ts +33 -0
  347. package/dist/core/util/minimatch-cache.d.ts.map +1 -0
  348. package/dist/core/util/minimatch-cache.js +0 -0
  349. package/dist/core/util/minimatch-cache.js.map +1 -0
  350. package/dist/core/worktree-sync/codes.d.ts +227 -0
  351. package/dist/core/worktree-sync/codes.d.ts.map +1 -0
  352. package/dist/core/worktree-sync/codes.js +14 -0
  353. package/dist/core/worktree-sync/codes.js.map +1 -0
  354. package/dist/core/worktree-sync/git-engine.d.ts +156 -0
  355. package/dist/core/worktree-sync/git-engine.d.ts.map +1 -0
  356. package/dist/core/worktree-sync/git-engine.js +1191 -0
  357. package/dist/core/worktree-sync/git-engine.js.map +1 -0
  358. package/dist/core/worktree-sync/lane-gate.d.ts +75 -0
  359. package/dist/core/worktree-sync/lane-gate.d.ts.map +1 -0
  360. package/dist/core/worktree-sync/lane-gate.js +360 -0
  361. package/dist/core/worktree-sync/lane-gate.js.map +1 -0
  362. package/dist/core/worktree-sync/runtime.d.ts +47 -0
  363. package/dist/core/worktree-sync/runtime.d.ts.map +1 -0
  364. package/dist/core/worktree-sync/runtime.js +96 -0
  365. package/dist/core/worktree-sync/runtime.js.map +1 -0
  366. package/dist/core/worktree-sync/store.d.ts +69 -0
  367. package/dist/core/worktree-sync/store.d.ts.map +1 -0
  368. package/dist/core/worktree-sync/store.js +247 -0
  369. package/dist/core/worktree-sync/store.js.map +1 -0
  370. package/dist/core/worktree-sync/watcher.d.ts +29 -0
  371. package/dist/core/worktree-sync/watcher.d.ts.map +1 -0
  372. package/dist/core/worktree-sync/watcher.js +93 -0
  373. package/dist/core/worktree-sync/watcher.js.map +1 -0
  374. package/dist/main.d.ts.map +1 -1
  375. package/dist/main.js +94 -0
  376. package/dist/main.js.map +1 -1
  377. package/dist/migrations.d.ts +9 -0
  378. package/dist/migrations.d.ts.map +1 -1
  379. package/dist/migrations.js +38 -0
  380. package/dist/migrations.js.map +1 -1
  381. package/dist/modes/interactive/auto-learn-controller.d.ts +16 -1
  382. package/dist/modes/interactive/auto-learn-controller.d.ts.map +1 -1
  383. package/dist/modes/interactive/auto-learn-controller.js +50 -8
  384. package/dist/modes/interactive/auto-learn-controller.js.map +1 -1
  385. package/dist/modes/interactive/components/profile-resource-editor.d.ts.map +1 -1
  386. package/dist/modes/interactive/components/profile-resource-editor.js +23 -1
  387. package/dist/modes/interactive/components/profile-resource-editor.js.map +1 -1
  388. package/dist/modes/interactive/interactive-mode.d.ts +1 -0
  389. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  390. package/dist/modes/interactive/interactive-mode.js +4 -0
  391. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  392. package/dist/modes/interactive/local-model-commands.d.ts +43 -0
  393. package/dist/modes/interactive/local-model-commands.d.ts.map +1 -1
  394. package/dist/modes/interactive/local-model-commands.js +290 -3
  395. package/dist/modes/interactive/local-model-commands.js.map +1 -1
  396. package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
  397. package/dist/modes/interactive/session-flow-commands.js +24 -4
  398. package/dist/modes/interactive/session-flow-commands.js.map +1 -1
  399. package/dist/utils/fs-watch.d.ts +11 -0
  400. package/dist/utils/fs-watch.d.ts.map +1 -1
  401. package/dist/utils/fs-watch.js +20 -2
  402. package/dist/utils/fs-watch.js.map +1 -1
  403. package/dist/utils/highlight-js-languages.d.ts +4 -0
  404. package/dist/utils/highlight-js-languages.d.ts.map +1 -0
  405. package/dist/utils/highlight-js-languages.js +573 -0
  406. package/dist/utils/highlight-js-languages.js.map +1 -0
  407. package/dist/utils/shell.d.ts +7 -1
  408. package/dist/utils/shell.d.ts.map +1 -1
  409. package/dist/utils/shell.js +21 -6
  410. package/dist/utils/shell.js.map +1 -1
  411. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  412. package/dist/utils/syntax-highlight.js +53 -5
  413. package/dist/utils/syntax-highlight.js.map +1 -1
  414. package/dist/utils/tools-manager.d.ts.map +1 -1
  415. package/dist/utils/tools-manager.js +112 -1
  416. package/dist/utils/tools-manager.js.map +1 -1
  417. package/docs/process-matrix.md +120 -0
  418. package/docs/settings.md +3 -0
  419. package/docs/tmux-agent-manager.md +85 -2
  420. package/docs/windows.md +52 -3
  421. package/docs/work-directory.md +29 -0
  422. package/docs/worktree-sync.md +250 -0
  423. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  424. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  425. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  426. package/examples/extensions/sandbox/package-lock.json +2 -2
  427. package/examples/extensions/sandbox/package.json +1 -1
  428. package/examples/extensions/with-deps/package-lock.json +2 -2
  429. package/examples/extensions/with-deps/package.json +1 -1
  430. package/npm-shrinkwrap.json +12 -12
  431. package/package.json +10 -4
  432. package/docs/integration-sweep-builder-blueprint-2026-07-09.md +0 -365
  433. package/docs/integration-sweep-resume-2026-07-09.md +0 -407
@@ -6,7 +6,11 @@ import * as path from "node:path";
6
6
  import { fileURLToPath } from "node:url";
7
7
  import { getProcessWorkRun } from "@caupulican/pi-adaptative";
8
8
  import { Type } from "typebox";
9
+ import { buildGrant, buildGrantUsageEntry, buildLaunchProfileFlags, buildTombstone, countGrantUsages, decodeTmuxWorkerUsageClaim, describeGrant, GRANT_CUSTOM_TYPE, GRANT_USAGE_CUSTOM_TYPE, grantCovers, isTmuxDispatchGrant, isTmuxDispatchGrantTombstone, launchProfileSourceFromGrant, ONE_SHOT_LAUNCH_PROFILE_SOURCE, } from "./dispatch-grant.js";
9
10
  export const piConfig = { tools: ["tmux_agent_manager"] };
11
+ function agentLaneId(jobId, agentId) {
12
+ return `tmux:${jobId}:${agentId}`;
13
+ }
10
14
  const EXTENSION_ROOT = path.dirname(fileURLToPath(import.meta.url));
11
15
  export function getTmuxAgentManagerDataRoot() {
12
16
  const agentDir = process.env.PI_ADAPTATIVE_CODING_AGENT_DIR ||
@@ -343,7 +347,7 @@ function normalizeAgents(params) {
343
347
  throw new Error(`agent ${name} needs command when provider=custom`);
344
348
  const tools = Array.isArray(agent.tools) && agent.tools.length > 0 ? agent.tools : undefined;
345
349
  const command = tools ? `${baseCommand} --tools ${tools.join(",")}` : baseCommand;
346
- return { provider, name, command, cwd: agent.cwd, tools };
350
+ return { provider, name, command, cwd: agent.cwd, tools, worktreeLane: agent.worktreeLane };
347
351
  });
348
352
  }
349
353
  function defaultProviderInvocation(provider) {
@@ -543,6 +547,7 @@ function buildFireTaskPlan(ctx, params) {
543
547
  promptPath: path.join(jobDir, `${slug}.prompt.md`),
544
548
  logPath: path.join(jobDir, `${slug}.log`),
545
549
  resultPath: path.join(jobDir, `${slug}.result.json`),
550
+ worktreeLane: agent.worktreeLane,
546
551
  };
547
552
  });
548
553
  const job = {
@@ -613,6 +618,57 @@ function targetDisplayName(agent, index) {
613
618
  function tmuxSessionExists(name) {
614
619
  return runTmux(["has-session", "-t", name], 2_000).ok;
615
620
  }
621
+ function tmuxPaneExists(sessionName, paneId) {
622
+ const result = runTmux(["list-panes", "-t", sessionName, "-F", "#{pane_id}"], 2_000);
623
+ if (!result.ok)
624
+ return false;
625
+ return result.stdout
626
+ .split(/\s+/)
627
+ .map((line) => line.trim())
628
+ .includes(paneId);
629
+ }
630
+ /** True when tmux already has a pipe-pane consumer attached to this pane (tmux's own `#{pane_pipe}`
631
+ * format flag). Session-level reconcile MUST check this before re-arming: a pane that still has an
632
+ * active pipe already has a live watcher; replacing it would close that watcher's stdin and race its
633
+ * own EOF-triggered `finish(failed, pane-stream-ended)` against the real marker that may be about to
634
+ * arrive, possibly recording a false failure for a job that was about to succeed on its own. Re-arming
635
+ * is only safe (and only useful) when tmux reports no pipe is currently attached. */
636
+ function tmuxPaneHasPipe(paneId) {
637
+ const result = runTmux(["display-message", "-p", "-t", paneId, "#{pane_pipe}"], 2_000);
638
+ return result.ok && result.stdout.trim() === "1";
639
+ }
640
+ function turnMarkers(job, agent, turn) {
641
+ if (turn <= 1)
642
+ return { doneMarker: agent.doneMarker, blockedMarker: agent.blockedMarker };
643
+ const base = `TMUX_${crypto.createHash("sha1").update(`${job.id}:${agent.id}:${turn}`).digest("hex").slice(0, 10).toUpperCase()}`;
644
+ return { doneMarker: `${base}_DONE`, blockedMarker: `${base}_BLOCKED` };
645
+ }
646
+ function turnResultPath(jobDir, agentId, turn, baseResultPath) {
647
+ return turn <= 1 ? baseResultPath : path.join(jobDir, `${agentId}.turn-${turn}.result.json`);
648
+ }
649
+ function turnPromptPath(jobDir, agentId, turn, basePromptPath) {
650
+ return turn <= 1 ? basePromptPath : path.join(jobDir, `${agentId}.turn-${turn}.prompt.md`);
651
+ }
652
+ function turnWatcherPath(job, turn) {
653
+ return turn <= 1 ? job.watcherPath : path.join(job.jobDir, `pane-watcher.turn-${turn}.sh`);
654
+ }
655
+ /** The result-file path the CURRENT turn's watcher will write to for this agent (turn 1 keeps the
656
+ * fixed back-compat path). Stop handling must target this path, not the fixed one, or a stop signal
657
+ * issued mid-follow-up would land on a stale turn's file that nothing is watching anymore. */
658
+ function currentResultPath(job, agent) {
659
+ return turnResultPath(job.jobDir, agent.id, agent.currentTurn ?? 1, agent.resultPath);
660
+ }
661
+ /** Atomically read-modify-write job.json, always from a FRESH read (never from a caller's possibly
662
+ * stale in-memory copy), mirroring the temp+rename pattern the original notify path used. */
663
+ function persistJobPatch(jobId, mutate) {
664
+ const jobPath = path.join(jobsRoot(), jobId, "job.json");
665
+ const current = JSON.parse(fs.readFileSync(jobPath, "utf8"));
666
+ const mutated = mutate(current) ?? current;
667
+ const temporaryPath = `${jobPath}.tmp-${process.pid}-${Date.now()}`;
668
+ fs.writeFileSync(temporaryPath, `${JSON.stringify(mutated, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
669
+ fs.renameSync(temporaryPath, jobPath);
670
+ return mutated;
671
+ }
616
672
  function sendCommandToPane(paneId, command) {
617
673
  runTmux(["send-keys", "-t", paneId, "-l", command]);
618
674
  runTmux(["send-keys", "-t", paneId, "Enter"]);
@@ -655,6 +711,65 @@ function injectPromptToPane(paneId, prompt, provider) {
655
711
  runTmux(["send-keys", "-t", paneId, "-l", text], 10_000);
656
712
  runTmux(["send-keys", "-t", paneId, provider === "agy" ? "C-m" : "Enter"], 3_000);
657
713
  }
714
+ /** Write a fresh per-turn prompt + single-agent watcher script and arm `pipe-pane -O` for it. Used by
715
+ * send_followup to open a NEW turn on an already-live pane. Does not inject the prompt text into the
716
+ * pane itself — callers do that separately via injectPromptToPane, after this has armed the watcher,
717
+ * so the completion contract is listening before the worker can possibly reply. */
718
+ function dispatchAgentTurn(job, agent, turn, promptText) {
719
+ if (!agent.paneId)
720
+ throw new Error(`tmux agent ${agent.name} has no recorded pane id`);
721
+ const markers = turnMarkers(job, agent, turn);
722
+ const resultPath = turnResultPath(job.jobDir, agent.id, turn, agent.resultPath);
723
+ const promptPath = turnPromptPath(job.jobDir, agent.id, turn, agent.promptPath);
724
+ const watcherPath = turnWatcherPath(job, turn);
725
+ fs.writeFileSync(promptPath, `${promptText}\n`, { mode: 0o600 });
726
+ const turnSpec = {
727
+ id: job.id,
728
+ sessionName: job.sessionName,
729
+ deadlineSeconds: job.deadlineSeconds,
730
+ agents: [
731
+ { ...agent, doneMarker: markers.doneMarker, blockedMarker: markers.blockedMarker, resultPath, promptPath },
732
+ ],
733
+ };
734
+ fs.writeFileSync(watcherPath, makePaneWatcherScript(turnSpec), { mode: 0o700 });
735
+ fs.chmodSync(watcherPath, 0o700);
736
+ const armed = runTmux([
737
+ "pipe-pane",
738
+ "-O",
739
+ "-t",
740
+ agent.paneId,
741
+ `sh ${quoteShell(watcherPath)} ${quoteShell(agent.id)}`,
742
+ ]);
743
+ if (!armed.ok)
744
+ throw new Error(`Failed to arm completion watcher for turn ${turn}: ${armed.error || armed.stderr || armed.stdout}`);
745
+ return { promptPath, resultPath, watcherPath };
746
+ }
747
+ /** Session-level reconcile's resume step: re-arm `pipe-pane` for an agent whose current turn is still
748
+ * pending on a pane tmux confirms is alive AND has no pipe already attached (see tmuxPaneHasPipe). Only
749
+ * regenerates the watcher SCRIPT file if it is missing (e.g. this is the first reconcile after a reload
750
+ * whose disk state predates a crash) — the prompt was already injected once and is not re-sent. */
751
+ function rearmAgentWatcher(job, agent) {
752
+ if (!agent.paneId)
753
+ return;
754
+ const turn = agent.currentTurn ?? 1;
755
+ const markers = turnMarkers(job, agent, turn);
756
+ const resultPath = turnResultPath(job.jobDir, agent.id, turn, agent.resultPath);
757
+ const promptPath = turnPromptPath(job.jobDir, agent.id, turn, agent.promptPath);
758
+ const watcherPath = turnWatcherPath(job, turn);
759
+ if (!fs.existsSync(watcherPath)) {
760
+ const turnSpec = {
761
+ id: job.id,
762
+ sessionName: job.sessionName,
763
+ deadlineSeconds: job.deadlineSeconds,
764
+ agents: [
765
+ { ...agent, doneMarker: markers.doneMarker, blockedMarker: markers.blockedMarker, resultPath, promptPath },
766
+ ],
767
+ };
768
+ fs.writeFileSync(watcherPath, makePaneWatcherScript(turnSpec), { mode: 0o700 });
769
+ fs.chmodSync(watcherPath, 0o700);
770
+ }
771
+ runTmux(["pipe-pane", "-O", "-t", agent.paneId, `sh ${quoteShell(watcherPath)} ${quoteShell(agent.id)}`]);
772
+ }
658
773
  function stopTmuxSession(sessionName, dryRun, confirm) {
659
774
  if (!sessionName)
660
775
  throw new Error("session name required");
@@ -675,10 +790,11 @@ function isAlreadyExistsError(error) {
675
790
  }
676
791
  function markStopRequested(job) {
677
792
  for (const agent of job.agents) {
678
- if (fs.existsSync(agent.resultPath))
793
+ const resultPath = currentResultPath(job, agent);
794
+ if (fs.existsSync(resultPath))
679
795
  continue;
680
796
  try {
681
- fs.writeFileSync(`${agent.resultPath}.stop-requested`, `${new Date().toISOString()}\n`, {
797
+ fs.writeFileSync(`${resultPath}.stop-requested`, `${new Date().toISOString()}\n`, {
682
798
  encoding: "utf8",
683
799
  mode: 0o600,
684
800
  flag: "wx",
@@ -692,11 +808,12 @@ function markStopRequested(job) {
692
808
  }
693
809
  function clearStopRequested(job) {
694
810
  for (const agent of job.agents)
695
- fs.rmSync(`${agent.resultPath}.stop-requested`, { force: true });
811
+ fs.rmSync(`${currentResultPath(job, agent)}.stop-requested`, { force: true });
696
812
  }
697
813
  function persistStoppedResults(job) {
698
814
  for (const agent of job.agents) {
699
- if (!fs.existsSync(agent.resultPath)) {
815
+ const resultPath = currentResultPath(job, agent);
816
+ if (!fs.existsSync(resultPath)) {
700
817
  const result = {
701
818
  jobId: job.id,
702
819
  agentId: agent.id,
@@ -709,7 +826,7 @@ function persistStoppedResults(job) {
709
826
  notifiedBy: "stop-action-event",
710
827
  };
711
828
  try {
712
- fs.writeFileSync(agent.resultPath, `${JSON.stringify(result, null, 2)}\n`, {
829
+ fs.writeFileSync(resultPath, `${JSON.stringify(result, null, 2)}\n`, {
713
830
  encoding: "utf8",
714
831
  mode: 0o600,
715
832
  flag: "wx",
@@ -720,7 +837,7 @@ function persistStoppedResults(job) {
720
837
  throw error;
721
838
  }
722
839
  }
723
- fs.rmSync(`${agent.resultPath}.stop-requested`, { force: true });
840
+ fs.rmSync(`${resultPath}.stop-requested`, { force: true });
724
841
  }
725
842
  }
726
843
  function stopTmuxSessionWithJobSignals(sessionName, jobs, dryRun, confirm) {
@@ -769,8 +886,10 @@ function loadJob(id) {
769
886
  if (!Array.isArray(parsed.agents))
770
887
  throw new Error(`tmux job has invalid agents: ${id}`);
771
888
  for (const agent of parsed.agents) {
889
+ // Read from the CURRENT turn's result path (turn 1 is the fixed back-compat path) so a job
890
+ // mid-follow-up is correctly seen as non-terminal until the NEW turn settles.
772
891
  try {
773
- agent.result = JSON.parse(fs.readFileSync(agent.resultPath, "utf8"));
892
+ agent.result = JSON.parse(fs.readFileSync(currentResultPath(parsed, agent), "utf8"));
774
893
  }
775
894
  catch {
776
895
  delete agent.result;
@@ -815,7 +934,13 @@ function listJobs() {
815
934
  workspaceName: job.workspaceName,
816
935
  sessionName: job.sessionName,
817
936
  createdAt: job.createdAt,
818
- agents: job.agents.map((agent) => ({ name: agent.name, status: agent.result?.status || "pending" })),
937
+ orphaned: Boolean(job.orphanedAt),
938
+ dismissed: Boolean(job.dismissedAt),
939
+ agents: job.agents.map((agent) => ({
940
+ name: agent.name,
941
+ status: agent.result?.status || "pending",
942
+ turn: agent.currentTurn ?? 1,
943
+ })),
819
944
  };
820
945
  }
821
946
  catch (error) {
@@ -845,7 +970,111 @@ function setVariable(jobId, name, value) {
845
970
  fs.writeFileSync(job.varsPath, `${JSON.stringify(current, null, 2)}\n`, { mode: 0o600 });
846
971
  return { varsPath: job.varsPath, variables: current.variables, updatedAt: current.updatedAt };
847
972
  }
848
- async function executeTool(_toolCallId, params, _signal, _onUpdate, ctx) {
973
+ // ---------------------------------------------------------------------------
974
+ // STANDING GRANT — approval-gated tmux dispatch. The pure decode/decision logic lives in
975
+ // dispatch-grant.ts; the functions below are the session-access GLUE: read the latest grant custom
976
+ // entry (skipping past malformed payloads, but stopping DEAD on a tombstone — never resurrecting an
977
+ // older grant beneath a revocation), count spend, and gate a real launch.
978
+ // ---------------------------------------------------------------------------
979
+ /** Most recent VALID `tmux-dispatch-grant` entry on the active branch, or undefined when there is
980
+ * none, it was revoked (a tombstone is a hard stop — never skipped to find an older grant), or every
981
+ * entry found fails to decode. Mirrors the branch-walk idiom used by goal/task session state. */
982
+ function resolveLatestGrantEntry(ctx) {
983
+ let fromId;
984
+ for (;;) {
985
+ const entry = ctx.sessionManager.getLatestCustomEntryOnBranch(GRANT_CUSTOM_TYPE, fromId);
986
+ if (!entry)
987
+ return undefined;
988
+ if (isTmuxDispatchGrantTombstone(entry.data))
989
+ return undefined;
990
+ if (isTmuxDispatchGrant(entry.data))
991
+ return entry.data;
992
+ if (!entry.parentId)
993
+ return undefined;
994
+ fromId = entry.parentId;
995
+ }
996
+ }
997
+ /** Decoded `data` payloads of every custom entry of `customType` on the active branch (root→leaf
998
+ * order), for spend-counting — a single `getLatestCustomEntryOnBranch` call only ever returns ONE
999
+ * entry, but budget spend requires ALL of them. */
1000
+ function collectCustomEntryData(ctx, customType) {
1001
+ const result = [];
1002
+ for (const entry of ctx.sessionManager.getBranch()) {
1003
+ const loose = entry;
1004
+ if (loose.type === "custom" && loose.customType === customType)
1005
+ result.push(loose.data);
1006
+ }
1007
+ return result;
1008
+ }
1009
+ /** Gate a REAL tmux dispatch (fire_task non-dryRun, send_followup) per the standing-grant doctrine:
1010
+ * a valid covering grant dispatches UNATTENDED (spending one usage); absent that, an
1011
+ * interactive host may approve a ONE-SHOT launch; absent BOTH, this REFUSES — never a silent launch.
1012
+ * Returns the covering grant when one authorized this launch (so the caller can derive launch-profile
1013
+ * flags from its envelope), or `{}` for a one-shot approval (no envelope to derive from — the caller
1014
+ * falls back to the conservative default profile). */
1015
+ async function authorizeLaunch(bridge, ctx, request) {
1016
+ if (request.agents.length === 0)
1017
+ throw new Error("tmux dispatch refused: launch has no agents");
1018
+ const grant = resolveLatestGrantEntry(ctx);
1019
+ // A standing grant names one provider. It must cover every child and spend one unit for every
1020
+ // child process; a matching first pane must never authorize an unrestricted mixed team.
1021
+ if (grant && request.agents.every((agent) => grantCovers(grant, { agent, goalId: request.goalId }))) {
1022
+ const used = countGrantUsages(grant.grantId, collectCustomEntryData(ctx, GRANT_USAGE_CUSTOM_TYPE));
1023
+ if (grant.budget.maxLaunches - used >= request.agents.length) {
1024
+ if (!bridge.appendEntry)
1025
+ throw new Error("this host does not support session custom entries; cannot spend the tmux dispatch grant.");
1026
+ for (let index = 0; index < request.agents.length; index++) {
1027
+ bridge.appendEntry(GRANT_USAGE_CUSTOM_TYPE, buildGrantUsageEntry(grant.grantId, `${request.jobId}:${index}`));
1028
+ }
1029
+ return { grant };
1030
+ }
1031
+ }
1032
+ if (ctx.hasUI) {
1033
+ const approved = await ctx.ui.confirm("tmux dispatch approval", [
1034
+ `No standing grant currently authorizes every child of: ${request.description}.`,
1035
+ `Agents: ${request.agents.join(", ")}${request.goalId ? `, goal: ${request.goalId}` : ""}.`,
1036
+ "Approve this ONE-SHOT launch? Run tmux_agent_manager action=grant_dispatch to authorize future launches without this prompt.",
1037
+ ].join("\n"));
1038
+ if (!approved)
1039
+ throw new Error(`tmux dispatch declined by the owner: ${request.description}`);
1040
+ return {};
1041
+ }
1042
+ throw new Error(`no standing grant for tmux dispatch; run grant_dispatch first: every child must be covered. ${request.description}. Refusing to launch without a grant or interactive approval.`);
1043
+ }
1044
+ /** Render grant/one-shot-derived launch-profile flags into a pi child's start command. Values
1045
+ * are shell-quoted; flags are not (they're fixed literals, never user input). */
1046
+ function appendLaunchProfileFlags(command, flags) {
1047
+ const rendered = flags.map((flag) => flag.value !== undefined ? `${flag.flag} ${quoteShell(flag.value)}` : flag.flag);
1048
+ return [command, ...rendered].join(" ");
1049
+ }
1050
+ /** Apply the launch profile to every provider="pi" agent in the job (fire_task only — send_followup
1051
+ * reuses an already-launched pane, so there is no new child command to configure). Non-pi agents are
1052
+ * bounded by the grant only at the launch layer (agent/budget/count); their internal tool-loop
1053
+ * enforcement is the target CLI's own responsibility (documented limitation, not a hidden gap). */
1054
+ function applyLaunchProfile(job, source) {
1055
+ for (const agent of job.agents) {
1056
+ if (agent.provider !== "pi")
1057
+ continue;
1058
+ // Per-agent flags: `worktreeLane` is a per-agent property (only a lane-first goal->tmux
1059
+ // dispatch sets it), so the shared `source` envelope is extended with it just for this agent's
1060
+ // flag build -- every other agent in a multi-agent team keeps the plain grant-derived profile.
1061
+ const flags = buildLaunchProfileFlags(agent.worktreeLane ? { ...source, worktreeLane: agent.worktreeLane } : source);
1062
+ agent.command = appendLaunchProfileFlags(agent.command || defaultProviderInvocation(agent.provider), flags);
1063
+ }
1064
+ }
1065
+ /** Read an OPTIONAL, cooperative worker-reported usage claim for the turn that just went terminal (a
1066
+ * sibling `<result-path>.usage.json` file next to the watcher's own result file). Absent file ⇒ no
1067
+ * claim was offered ⇒ nothing is reported (never fabricated). */
1068
+ function readWorkerUsageClaim(job, agent) {
1069
+ const usagePath = `${currentResultPath(job, agent)}.usage.json`;
1070
+ try {
1071
+ return decodeTmuxWorkerUsageClaim(JSON.parse(fs.readFileSync(usagePath, "utf8")));
1072
+ }
1073
+ catch {
1074
+ return undefined;
1075
+ }
1076
+ }
1077
+ async function executeTool(_toolCallId, params, _signal, _onUpdate, ctx, bridge) {
849
1078
  const action = params.action || "status";
850
1079
  const detection = detectTmux();
851
1080
  if (action === "status")
@@ -901,6 +1130,62 @@ async function executeTool(_toolCallId, params, _signal, _onUpdate, ctx) {
901
1130
  details: { action, jobId: params.jobId, variableName: params.variableName, result },
902
1131
  };
903
1132
  }
1133
+ if (action === "grant_dispatch") {
1134
+ if (!params.agent)
1135
+ throw new Error("grant_dispatch requires agent");
1136
+ if (!Object.hasOwn(PROVIDER_COMMANDS, params.agent))
1137
+ throw new Error(`grant_dispatch: unsupported agent: ${params.agent}`);
1138
+ const grantParams = {
1139
+ agent: params.agent,
1140
+ goalId: params.goalId,
1141
+ allowedTools: params.allowedTools,
1142
+ resourceProfile: params.resourceProfile,
1143
+ writePaths: params.writePaths,
1144
+ maxLaunches: typeof params.maxLaunches === "number" ? params.maxLaunches : Number.NaN,
1145
+ expiresInMinutes: params.expiresInMinutes,
1146
+ maxUsdAdvisory: params.maxUsdAdvisory,
1147
+ };
1148
+ const grant = buildGrant(grantParams);
1149
+ const summary = describeGrant(grant);
1150
+ // OWNER-AUTHORIZED, NEVER SILENT: an interactive host must explicitly confirm the exact
1151
+ // grant details; a non-interactive host (print/rpc, or the unattended goal loop) has no confirm
1152
+ // surface, so it needs an explicit opt-in flag instead — absent either, refuse to create the grant.
1153
+ if (ctx.hasUI) {
1154
+ const approved = await ctx.ui.confirm("Authorize tmux dispatch grant", summary);
1155
+ if (!approved)
1156
+ throw new Error("grant_dispatch was declined by the owner.");
1157
+ }
1158
+ else if (bridge.getFlag?.("allow-tmux-dispatch") !== true) {
1159
+ throw new Error("grant_dispatch requires interactive approval; no UI is available in this mode. Pass --allow-tmux-dispatch to authorize grant creation non-interactively.");
1160
+ }
1161
+ if (!bridge.appendEntry)
1162
+ throw new Error("this host does not support session custom entries; cannot persist a tmux dispatch grant.");
1163
+ bridge.appendEntry(GRANT_CUSTOM_TYPE, grant);
1164
+ return {
1165
+ content: [{ type: "text", text: `Created tmux dispatch grant ${grant.grantId}.\n${summary}` }],
1166
+ details: { action, grant },
1167
+ };
1168
+ }
1169
+ if (action === "revoke_grant") {
1170
+ const activeGrant = resolveLatestGrantEntry(ctx);
1171
+ const targetGrantId = firstString(params.grantId) || activeGrant?.grantId;
1172
+ if (!targetGrantId)
1173
+ throw new Error("revoke_grant: no active tmux dispatch grant to revoke.");
1174
+ if (activeGrant && activeGrant.grantId !== targetGrantId)
1175
+ throw new Error(`revoke_grant: grantId ${targetGrantId} is not the active grant (active: ${activeGrant.grantId}).`);
1176
+ if (!bridge.appendEntry)
1177
+ throw new Error("this host does not support session custom entries; cannot revoke a tmux dispatch grant.");
1178
+ bridge.appendEntry(GRANT_CUSTOM_TYPE, buildTombstone(targetGrantId));
1179
+ return {
1180
+ content: [
1181
+ {
1182
+ type: "text",
1183
+ text: `Revoked tmux dispatch grant ${targetGrantId}. Future launches need a new grant_dispatch or interactive/opt-in approval.`,
1184
+ },
1185
+ ],
1186
+ details: { action, grantId: targetGrantId },
1187
+ };
1188
+ }
904
1189
  const guard = await guardTmux(ctx, detection, `tmux ${action}`);
905
1190
  if (!guard.allowed)
906
1191
  return { content: [{ type: "text", text: guard.text }], details: { action, detection, guard, skipped: true } };
@@ -965,6 +1250,22 @@ async function executeTool(_toolCallId, params, _signal, _onUpdate, ctx) {
965
1250
  };
966
1251
  if (tmuxSessionExists(job.sessionName))
967
1252
  throw new Error(`tmux session already exists: ${job.sessionName}. Use stop_job/stop_session first or choose a different workspaceName.`);
1253
+ // APPROVAL-GATED LAUNCH: resolved before any tmux/FS side effect. A standing grant must
1254
+ // authorize every child provider and spend its budget per child process.
1255
+ const authorization = await authorizeLaunch(bridge, ctx, {
1256
+ agents: job.agents.map((agent) => agent.provider),
1257
+ goalId: params.goalId,
1258
+ jobId: job.id,
1259
+ description: `fire_task launch of job ${job.id} (${job.agents.length} child process${job.agents.length === 1 ? "" : "es"}: ${job.agents.map((agent) => `${agent.name}/${agent.provider}`).join(", ")})`,
1260
+ });
1261
+ applyLaunchProfile(job, {
1262
+ ...(authorization.grant ? launchProfileSourceFromGrant(authorization.grant) : ONE_SHOT_LAUNCH_PROFILE_SOURCE),
1263
+ // Process-matrix parent identity: the dispatched child self-registers as a worker of THIS
1264
+ // session and winds down gracefully if this session disappears (see dispatch-grant.ts's
1265
+ // `LaunchProfileSource.parentPid`/`parentSession` doc).
1266
+ parentPid: process.pid,
1267
+ parentSession: ctx.sessionManager.getSessionId?.() ?? ctx.sessionManager.getSessionFile(),
1268
+ });
968
1269
  const archivedJobDir = prepareJobDirForLaunch(job, params.force);
969
1270
  const panes = job.agents.map((agent) => ({
970
1271
  title: agent.name,
@@ -981,6 +1282,13 @@ async function executeTool(_toolCallId, params, _signal, _onUpdate, ctx) {
981
1282
  if (!agent.paneId)
982
1283
  continue;
983
1284
  injectPromptToPane(agent.paneId, fs.readFileSync(agent.promptPath, "utf8"), agent.provider);
1285
+ bridge.reportManagedLane?.({
1286
+ laneId: agentLaneId(job.id, agent.id),
1287
+ phase: "dispatch",
1288
+ status: "launched",
1289
+ goalId: params.goalId,
1290
+ worktreeLaneKey: agent.worktreeLane,
1291
+ });
984
1292
  }
985
1293
  return {
986
1294
  content: [
@@ -1001,6 +1309,122 @@ async function executeTool(_toolCallId, params, _signal, _onUpdate, ctx) {
1001
1309
  details: { action, detection, job, runs: launch.runs, paneIds: launch.paneIds, watcherPanes, archivedJobDir },
1002
1310
  };
1003
1311
  }
1312
+ if (action === "send_followup") {
1313
+ if (!params.jobId)
1314
+ throw new Error("send_followup requires jobId");
1315
+ const followupTask = firstString(params.task, params.body);
1316
+ if (!followupTask)
1317
+ throw new Error("send_followup requires task (or body) with the follow-up objective");
1318
+ const job = loadJob(params.jobId);
1319
+ if (job.dismissedAt)
1320
+ throw new Error(`tmux job ${job.id} was dismissed; use fire_task to relaunch instead of send_followup`);
1321
+ if (job.agents.length === 0)
1322
+ throw new Error(`tmux job has no agents: ${job.id}`);
1323
+ const targetAgent = params.agentId ? job.agents.find((agent) => agent.id === params.agentId) : job.agents[0];
1324
+ if (!targetAgent)
1325
+ throw new Error(`tmux job ${job.id} has no agent ${params.agentId}`);
1326
+ if (!targetAgent.paneId)
1327
+ throw new Error(`tmux agent ${targetAgent.name} has no recorded pane id; cannot send a follow-up`);
1328
+ if (targetAgent.pendingTurn !== undefined)
1329
+ throw new Error(`send_followup refused: turn ${targetAgent.pendingTurn} for ${targetAgent.id} is pending reconciliation; refusing to risk a duplicate prompt`);
1330
+ const turn = (targetAgent.currentTurn ?? 1) + 1;
1331
+ const markers = turnMarkers(job, targetAgent, turn);
1332
+ const promptText = managedPrompt(followupTask, job.id, targetAgent, markers.doneMarker, markers.blockedMarker, job.varsPath);
1333
+ if (params.dryRun === true)
1334
+ return {
1335
+ content: [
1336
+ {
1337
+ type: "text",
1338
+ text: `DRY RUN tmux send_followup\nJob: ${job.id}\nAgent: ${targetAgent.name}\nTurn: ${turn}`,
1339
+ },
1340
+ ],
1341
+ details: { action, detection, dryRun: true, jobId: job.id, agentId: targetAgent.id, turn },
1342
+ };
1343
+ if (!tmuxSessionExists(job.sessionName))
1344
+ throw new Error(`tmux session is gone: ${job.sessionName}. The worker pane cannot receive a follow-up; use fire_task to relaunch.`);
1345
+ if (!tmuxPaneExists(job.sessionName, targetAgent.paneId))
1346
+ throw new Error(`tmux pane ${targetAgent.paneId} for ${targetAgent.name} is gone. The worker cannot receive a follow-up; use fire_task to relaunch.`);
1347
+ // APPROVAL-GATED LAUNCH (doctrine-regression mandatory): a follow-up dispatches a fresh
1348
+ // turn into an already-running child, so there is no new child command to profile — only the
1349
+ // grant/one-shot authorization is resolved here (no applyLaunchProfile call).
1350
+ await authorizeLaunch(bridge, ctx, {
1351
+ agents: [targetAgent.provider],
1352
+ goalId: params.goalId,
1353
+ jobId: `${job.id}:turn:${turn}`,
1354
+ description: `send_followup turn ${turn} to ${targetAgent.name} in job ${job.id}`,
1355
+ });
1356
+ // Reserve before watcher/prompt side effects. Reconcile re-arms a reserved turn but never
1357
+ // re-injects it, so crash recovery cannot duplicate a provider prompt.
1358
+ const reserved = persistJobPatch(job.id, (current) => {
1359
+ const agent = current.agents.find((entry) => entry.id === targetAgent.id);
1360
+ if (!agent || agent.pendingTurn !== undefined)
1361
+ return undefined;
1362
+ agent.currentTurn = turn;
1363
+ agent.pendingTurn = turn;
1364
+ agent.result = undefined;
1365
+ current.currentTurn = turn;
1366
+ return current;
1367
+ });
1368
+ const reservedAgent = reserved.agents.find((agent) => agent.id === targetAgent.id);
1369
+ if (!reservedAgent || reservedAgent.pendingTurn !== turn)
1370
+ throw new Error(`send_followup refused: failed to reserve turn ${turn} for ${targetAgent.id}`);
1371
+ const written = dispatchAgentTurn(reserved, reservedAgent, turn, promptText);
1372
+ injectPromptToPane(reservedAgent.paneId, promptText, reservedAgent.provider);
1373
+ persistJobPatch(job.id, (current) => {
1374
+ const agent = current.agents.find((entry) => entry.id === reservedAgent.id);
1375
+ if (!agent || agent.pendingTurn !== turn)
1376
+ return undefined;
1377
+ delete agent.pendingTurn;
1378
+ return current;
1379
+ });
1380
+ bridge.reportManagedLane?.({
1381
+ laneId: agentLaneId(job.id, targetAgent.id),
1382
+ phase: "dispatch",
1383
+ status: "follow-up",
1384
+ goalId: params.goalId,
1385
+ request: { turn },
1386
+ worktreeLaneKey: targetAgent.worktreeLane,
1387
+ });
1388
+ return {
1389
+ content: [
1390
+ {
1391
+ type: "text",
1392
+ text: [
1393
+ `Sent follow-up turn ${turn} to ${targetAgent.name} in job ${job.id}.`,
1394
+ `Session: ${job.sessionName}`,
1395
+ `Prompt: ${written.promptPath}`,
1396
+ `Completion: event-driven pane watcher re-armed for turn ${turn} (no polling).`,
1397
+ ].join("\n"),
1398
+ },
1399
+ ],
1400
+ details: { action, detection, jobId: job.id, agentId: targetAgent.id, turn, ...written },
1401
+ };
1402
+ }
1403
+ if (action === "dismiss") {
1404
+ if (!params.jobId)
1405
+ throw new Error("dismiss requires jobId");
1406
+ const job = loadJob(params.jobId);
1407
+ if (job.dismissedAt)
1408
+ return {
1409
+ content: [{ type: "text", text: `tmux job ${job.id} was already dismissed.` }],
1410
+ details: { action, jobId: job.id, alreadyDismissed: true },
1411
+ };
1412
+ persistJobPatch(job.id, (current) => {
1413
+ current.dismissedAt = new Date().toISOString();
1414
+ return current;
1415
+ });
1416
+ for (const agent of job.agents)
1417
+ bridge.reportManagedLane?.({ laneId: agentLaneId(job.id, agent.id), phase: "terminal", status: "dismissed" });
1418
+ return {
1419
+ content: [
1420
+ {
1421
+ type: "text",
1422
+ text: `Dismissed tmux job ${job.id}. Session '${job.sessionName}' left running (not killed); attach with: tmux attach -t ${job.sessionName}. Use stop_session/stop_job to terminate it.`,
1423
+ },
1424
+ ],
1425
+ details: { action, jobId: job.id, sessionName: job.sessionName },
1426
+ };
1427
+ }
1004
1428
  if (action === "notify") {
1005
1429
  const title = firstString(params.title, "Pi") || "Pi";
1006
1430
  const body = firstString(params.body, "Pi needs attention") || "Pi needs attention";
@@ -1082,18 +1506,78 @@ function formatFireTaskHandoff(job) {
1082
1506
  "This event woke the parent; do not poll. Continue safe scoped work from the bounded handoff and inspect terminal artifacts only if needed for a material claim.",
1083
1507
  ].join("\n");
1084
1508
  }
1085
- function markFireTaskNotified(job) {
1086
- const current = JSON.parse(fs.readFileSync(job.jobPath, "utf8"));
1087
- current.notifiedAt = new Date().toISOString();
1088
- const temporaryPath = `${job.jobPath}.tmp-${process.pid}-${Date.now()}`;
1089
- fs.writeFileSync(temporaryPath, `${JSON.stringify(current, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
1090
- fs.renameSync(temporaryPath, job.jobPath);
1091
- job.notifiedAt = current.notifiedAt;
1509
+ /** Diff live tmux sessions against this session's job records. Mirrors the invariant behind
1510
+ * `LocalRuntimeController.reconcile` (local-runtime-controller.ts): reconcile only ever OBSERVES —
1511
+ * it never kills a session it did not provably start. A job whose tmux session is gone is marked
1512
+ * orphaned (informational, one-shot); a job whose session is alive but current turn is still
1513
+ * pending is resumed by re-arming its watcher, but ONLY when tmux confirms no pipe is already
1514
+ * attached to that pane (see tmuxPaneHasPipe) — otherwise a live watcher would be raced and could
1515
+ * be made to report a false failure. */
1516
+ function reconcileTmuxSessions(ctx, bridge) {
1517
+ const sessionFile = ctx.sessionManager.getSessionFile();
1518
+ const jobs = loadJobPlans().filter((job) => job.parentSessionFile === sessionFile && !job.dismissedAt);
1519
+ if (jobs.length === 0)
1520
+ return;
1521
+ const detection = detectTmux();
1522
+ if (!detection.cliAvailable)
1523
+ return;
1524
+ const liveSessions = new Set(detection.sessions);
1525
+ for (const job of jobs) {
1526
+ if (!liveSessions.has(job.sessionName)) {
1527
+ if (!isFireTaskTerminal(job) && !job.orphanedAt) {
1528
+ persistJobPatch(job.id, (current) => {
1529
+ current.orphanedAt = new Date().toISOString();
1530
+ return current;
1531
+ });
1532
+ if (ctx.hasUI)
1533
+ ctx.ui.notify(`tmux job ${job.id} is orphaned: session '${job.sessionName}' is gone and the job never reached a terminal state. Nothing was killed; this is informational only.`, "warning");
1534
+ // Nothing is killed here — only the LANE record is released. A dead session means the
1535
+ // worker itself can no longer report its own terminal state, so a goal bound to it would
1536
+ // wait forever without this: release the managed lane per non-terminal agent so the goal's
1537
+ // continuation stops waiting on a worker that will never report back.
1538
+ for (const agent of job.agents) {
1539
+ if (agent.result !== undefined)
1540
+ continue;
1541
+ bridge.reportManagedLane?.({
1542
+ laneId: agentLaneId(job.id, agent.id),
1543
+ phase: "terminal",
1544
+ status: "orphaned",
1545
+ reasonCode: "tmux_session_orphaned",
1546
+ });
1547
+ }
1548
+ }
1549
+ continue;
1550
+ }
1551
+ if (isFireTaskTerminal(job))
1552
+ continue;
1553
+ for (const agent of job.agents) {
1554
+ if (agent.result !== undefined)
1555
+ continue;
1556
+ if (!agent.paneId || !tmuxPaneExists(job.sessionName, agent.paneId))
1557
+ continue;
1558
+ if (tmuxPaneHasPipe(agent.paneId))
1559
+ continue;
1560
+ rearmAgentWatcher(job, agent);
1561
+ bridge.reportManagedLane?.({
1562
+ laneId: agentLaneId(job.id, agent.id),
1563
+ phase: "dispatch",
1564
+ status: "resumed",
1565
+ worktreeLaneKey: agent.worktreeLane,
1566
+ });
1567
+ }
1568
+ }
1092
1569
  }
1093
1570
  export default function tmuxAgentManagerExtension(pi) {
1094
1571
  let handoffContext;
1095
1572
  let handoffTail = Promise.resolve();
1096
1573
  const jobWatchers = new Map();
1574
+ const bridge = pi;
1575
+ // Non-interactive opt-in for grant_dispatch: optional-chained so a lightweight test double
1576
+ // that doesn't implement registerFlag still loads the extension; a real host always has it.
1577
+ bridge.registerFlag?.("allow-tmux-dispatch", {
1578
+ type: "boolean",
1579
+ description: "Authorize tmux_agent_manager grant_dispatch to create a standing tmux dispatch grant without interactive approval (print/rpc/non-interactive mode only).",
1580
+ });
1097
1581
  const closeJobWatchers = () => {
1098
1582
  for (const watcher of jobWatchers.values())
1099
1583
  watcher.close();
@@ -1101,9 +1585,15 @@ export default function tmuxAgentManagerExtension(pi) {
1101
1585
  };
1102
1586
  const refreshJobHandoffs = async (ctx) => {
1103
1587
  const sessionFile = ctx.sessionManager.getSessionFile();
1104
- const jobs = loadJobPlans().filter((job) => !job.parentSessionFile || job.parentSessionFile === sessionFile);
1588
+ const jobs = loadJobPlans().filter((job) => (!job.parentSessionFile || job.parentSessionFile === sessionFile) && !job.dismissedAt);
1105
1589
  for (const job of jobs) {
1106
- if (!isFireTaskTerminal(job) || job.notifiedAt)
1590
+ if (!isFireTaskTerminal(job))
1591
+ continue;
1592
+ // Per-turn notify: a job is not permanently "closed" after its first terminal turn — a
1593
+ // follow-up reopens it, so the gate is per-agent (notifiedTurn < currentTurn), not a
1594
+ // single whole-job notifiedAt flag.
1595
+ const pendingAgents = job.agents.filter((agent) => (agent.notifiedTurn ?? 0) < (agent.currentTurn ?? 1));
1596
+ if (pendingAgents.length === 0)
1107
1597
  continue;
1108
1598
  pi.sendMessage({
1109
1599
  customType: "tmux-background-completion",
@@ -1115,7 +1605,31 @@ export default function tmuxAgentManagerExtension(pi) {
1115
1605
  agents: job.agents.map((agent) => ({ id: agent.id, name: agent.name, status: agent.result?.status })),
1116
1606
  },
1117
1607
  }, { triggerTurn: true, deliverAs: "followUp" });
1118
- markFireTaskNotified(job);
1608
+ persistJobPatch(job.id, (current) => {
1609
+ current.notifiedAt = new Date().toISOString();
1610
+ for (const agent of current.agents) {
1611
+ const inMemoryAgent = job.agents.find((entry) => entry.id === agent.id);
1612
+ agent.notifiedTurn = inMemoryAgent?.currentTurn ?? agent.currentTurn ?? 1;
1613
+ }
1614
+ return current;
1615
+ });
1616
+ for (const agent of pendingAgents) {
1617
+ // Advisory-only, and only ever reported when the worker itself chose to write the
1618
+ // claim file — never fabricated, never a hard cross-process cap.
1619
+ const usage = readWorkerUsageClaim(job, agent);
1620
+ bridge.reportManagedLane?.({
1621
+ laneId: agentLaneId(job.id, agent.id),
1622
+ phase: "terminal",
1623
+ status: agent.result?.status,
1624
+ usage,
1625
+ });
1626
+ if (usage) {
1627
+ bridge.reportSpawnedUsage?.(usage, {
1628
+ label: "tmux-worker",
1629
+ reportId: `tmux-worker:${job.sessionName}:${job.id}:${agent.currentTurn ?? 1}`,
1630
+ });
1631
+ }
1632
+ }
1119
1633
  if (ctx.hasUI)
1120
1634
  ctx.ui.notify(`tmux background task ${job.id} completed.`, "info");
1121
1635
  }
@@ -1163,6 +1677,7 @@ export default function tmuxAgentManagerExtension(pi) {
1163
1677
  pi.on("session_start", async (_event, ctx) => {
1164
1678
  handoffContext = ctx;
1165
1679
  closeJobWatchers();
1680
+ reconcileTmuxSessions(ctx, bridge);
1166
1681
  await queueJobHandoffRefresh(ctx);
1167
1682
  });
1168
1683
  pi.on("session_shutdown", async () => {
@@ -1180,9 +1695,14 @@ export default function tmuxAgentManagerExtension(pi) {
1180
1695
  "Prefer action=fire_task for interactive worker batches. It returns after event watchers and prompts are armed; do not wait, poll, or peek for completion.",
1181
1696
  "Use action=list_templates/show_template before assembling repeated teams; pass teamTemplate when a built-in team fits.",
1182
1697
  "Use action=workspace_plan before launch_workspace when designing a pane layout.",
1698
+ "Use action=send_followup to re-inject a new prompt into a live fire_task job's pane mid-run, without relaunching. It re-arms the completion watcher for a fresh turn and reuses the same event-driven handoff.",
1699
+ "Use action=dismiss to stop tracking a job without killing its tmux session; the pane keeps running and can still be attached to or stopped later with stop_job/stop_session.",
1183
1700
  "Use stop_job/stop_session dry-run first, then confirm=yes-tmux-stop for real cleanup.",
1184
1701
  "Do not put secrets in task text or command strings; prompts, commands, and logs persist under ~/.pi/agent/work/background/tmux-agent-manager/state/jobs.",
1185
1702
  "tmux display/status actions are metadata only; validate worker result/log files before claiming task completion.",
1703
+ "fire_task and send_followup are APPROVAL-GATED: a real (non-dryRun) dispatch needs either a standing grant (action=grant_dispatch, once per session/goal) or a one-shot interactive approval. With no grant and no UI available, the dispatch is refused, never silent — run grant_dispatch first.",
1704
+ "Use action=grant_dispatch to authorize repeated unattended dispatch: set agent, maxLaunches, and optionally goalId/allowedTools/resourceProfile/writePaths/expiresInMinutes. Requires interactive confirmation, or the --allow-tmux-dispatch flag when no UI is available. Use action=revoke_grant to end it early.",
1705
+ "A grant-covered pi child launches with a RESTRICTED profile (--tools/--resource-profile or --no-extensions --no-skills, plus a scoped --append-system-prompt naming the grant and its hard stops) — the envelope lives in the CHILD's own launch config, not an in-process sandbox. Non-pi agents (agy/claude/codex/opencode/custom) are bounded by the grant at launch only; their internal tool loop is that CLI's own responsibility.",
1186
1706
  ],
1187
1707
  parameters: Type.Object({
1188
1708
  action: Type.Optional(Type.Union([
@@ -1195,6 +1715,8 @@ export default function tmuxAgentManagerExtension(pi) {
1195
1715
  Type.Literal("workspace_plan"),
1196
1716
  Type.Literal("launch_workspace"),
1197
1717
  Type.Literal("fire_task"),
1718
+ Type.Literal("send_followup"),
1719
+ Type.Literal("dismiss"),
1198
1720
  Type.Literal("job_status"),
1199
1721
  Type.Literal("list_jobs"),
1200
1722
  Type.Literal("set_variable"),
@@ -1203,8 +1725,10 @@ export default function tmuxAgentManagerExtension(pi) {
1203
1725
  Type.Literal("show_template"),
1204
1726
  Type.Literal("stop_job"),
1205
1727
  Type.Literal("stop_session"),
1728
+ Type.Literal("grant_dispatch"),
1729
+ Type.Literal("revoke_grant"),
1206
1730
  ], {
1207
- description: "status, setup_help, guard, notify, set_status, clear_status, workspace_plan, launch_workspace, fire_task, job_status, list_jobs, set_variable, list_variables, list_templates, show_template, stop_job, or stop_session. Default status.",
1731
+ description: "status, setup_help, guard, notify, set_status, clear_status, workspace_plan, launch_workspace, fire_task, send_followup, dismiss, job_status, list_jobs, set_variable, list_variables, list_templates, show_template, stop_job, stop_session, grant_dispatch, or revoke_grant. Default status.",
1208
1732
  })),
1209
1733
  title: Type.Optional(Type.String({ description: "Notification title or workspace title context." })),
1210
1734
  body: Type.Optional(Type.String({ description: "Notification body/status text, or fallback task text for fire_task." })),
@@ -1225,10 +1749,13 @@ export default function tmuxAgentManagerExtension(pi) {
1225
1749
  description: "Built-in team template name for workspace/fire_task, or target for show_template. Use list_templates first. Current templates include provider-prompt-smoke, full-provider-review, builder-validator, plus JSON templates under templates/.",
1226
1750
  })),
1227
1751
  task: Type.Optional(Type.String({
1228
- description: "Fire-and-forget worker objective. Required for fire_task unless body is provided.",
1752
+ description: "Fire-and-forget worker objective. Required for fire_task unless body is provided. Also used as the follow-up objective for send_followup.",
1229
1753
  })),
1230
1754
  jobId: Type.Optional(Type.String({
1231
- description: "Job id for fire_task (optional), job_status/list_variables/set_variable (required).",
1755
+ description: "Job id for fire_task (optional), job_status/list_variables/set_variable/send_followup/dismiss (required).",
1756
+ })),
1757
+ agentId: Type.Optional(Type.String({
1758
+ description: "Target agent id for send_followup. Defaults to the job's first (primary) agent. Multi-agent-per-turn follow-up is not supported; only one agent's pane receives each follow-up.",
1232
1759
  })),
1233
1760
  variableName: Type.Optional(Type.String({
1234
1761
  description: "For set_variable: named condition/decision variable workers read only at the decision point.",
@@ -1261,9 +1788,43 @@ export default function tmuxAgentManagerExtension(pi) {
1261
1788
  description: "For fire_task only: archive an existing job directory with the same jobId before launch. Existing tmux sessions are still refused; stop them first.",
1262
1789
  })),
1263
1790
  confirm: Type.Optional(Type.String({ description: "Required for real stop_job/stop_session: yes-tmux-stop." })),
1791
+ goalId: Type.Optional(Type.String({
1792
+ description: "Goal this dispatch/grant is scoped to. For grant_dispatch: an unscoped grant (omitted) covers any goal; a scoped grant covers only launches naming the same goalId. For fire_task/send_followup: tags the request for grant-coverage matching.",
1793
+ })),
1794
+ agent: Type.Optional(Type.Union([
1795
+ Type.Literal("pi"),
1796
+ Type.Literal("codex"),
1797
+ Type.Literal("agy"),
1798
+ Type.Literal("claude"),
1799
+ Type.Literal("opencode"),
1800
+ Type.Literal("custom"),
1801
+ ], { description: "grant_dispatch: the provider this standing grant authorizes." })),
1802
+ allowedTools: Type.Optional(Type.Array(Type.String(), {
1803
+ description: "grant_dispatch: tool allowlist pushed into the child pi's own --tools flag. Defaults to a read-biased safe set (read, grep, find, ls) when omitted.",
1804
+ })),
1805
+ resourceProfile: Type.Optional(Type.String({
1806
+ description: "grant_dispatch: resource profile name pushed into the child pi's own --resource-profile flag. When omitted, the child launches with --no-extensions --no-skills instead.",
1807
+ })),
1808
+ writePaths: Type.Optional(Type.Array(Type.String(), {
1809
+ description: "grant_dispatch: write paths named in the child's scoped --append-system-prompt role text.",
1810
+ })),
1811
+ maxLaunches: Type.Optional(Type.Number({
1812
+ description: "grant_dispatch: number of real fire_task/send_followup dispatches this grant authorizes.",
1813
+ minimum: 1,
1814
+ })),
1815
+ expiresInMinutes: Type.Optional(Type.Number({
1816
+ description: "grant_dispatch: grant validity window from creation. Omit for a grant that never expires (until revoke_grant).",
1817
+ minimum: 1,
1818
+ })),
1819
+ maxUsdAdvisory: Type.Optional(Type.Number({
1820
+ description: "grant_dispatch: advisory USD ceiling. Never enforced across the process boundary (the child bills under its own auth) — a claim to review only.",
1821
+ })),
1822
+ grantId: Type.Optional(Type.String({
1823
+ description: "revoke_grant: grant id to revoke. Omit to revoke whichever grant is currently active.",
1824
+ })),
1264
1825
  }),
1265
1826
  async execute(toolCallId, params, signal, onUpdate, ctx) {
1266
- const result = await executeTool(toolCallId, params, signal, onUpdate, ctx);
1827
+ const result = await executeTool(toolCallId, params, signal, onUpdate, ctx, bridge);
1267
1828
  await queueJobHandoffRefresh(ctx);
1268
1829
  return result;
1269
1830
  },