@nubl/maestro 0.0.0 → 0.1.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 (398) hide show
  1. package/README.md +56 -3
  2. package/dist/config.json.example +30 -0
  3. package/dist/maestro/adapters/fake/fake-harness-adapter.d.ts +24 -0
  4. package/dist/maestro/adapters/fake/fake-harness-adapter.d.ts.map +1 -0
  5. package/dist/maestro/adapters/fake/fake-harness-adapter.js +210 -0
  6. package/dist/maestro/adapters/fake/fake-harness-adapter.js.map +1 -0
  7. package/dist/maestro/adapters/pi/accept-groups.d.ts +35 -0
  8. package/dist/maestro/adapters/pi/accept-groups.d.ts.map +1 -0
  9. package/dist/maestro/adapters/pi/accept-groups.js +70 -0
  10. package/dist/maestro/adapters/pi/accept-groups.js.map +1 -0
  11. package/dist/maestro/adapters/pi/accept-runner.d.ts +37 -0
  12. package/dist/maestro/adapters/pi/accept-runner.d.ts.map +1 -0
  13. package/dist/maestro/adapters/pi/accept-runner.js +161 -0
  14. package/dist/maestro/adapters/pi/accept-runner.js.map +1 -0
  15. package/dist/maestro/adapters/pi/activity-file.d.ts +39 -0
  16. package/dist/maestro/adapters/pi/activity-file.d.ts.map +1 -0
  17. package/dist/maestro/adapters/pi/activity-file.js +454 -0
  18. package/dist/maestro/adapters/pi/activity-file.js.map +1 -0
  19. package/dist/maestro/adapters/pi/child/accept-check.d.ts +24 -0
  20. package/dist/maestro/adapters/pi/child/accept-check.d.ts.map +1 -0
  21. package/dist/maestro/adapters/pi/child/accept-check.js +82 -0
  22. package/dist/maestro/adapters/pi/child/accept-check.js.map +1 -0
  23. package/dist/maestro/adapters/pi/child/declared-skills.d.ts +51 -0
  24. package/dist/maestro/adapters/pi/child/declared-skills.d.ts.map +1 -0
  25. package/dist/maestro/adapters/pi/child/declared-skills.js +148 -0
  26. package/dist/maestro/adapters/pi/child/declared-skills.js.map +1 -0
  27. package/dist/maestro/adapters/pi/child/done-nudge.d.ts +38 -0
  28. package/dist/maestro/adapters/pi/child/done-nudge.d.ts.map +1 -0
  29. package/dist/maestro/adapters/pi/child/done-nudge.js +77 -0
  30. package/dist/maestro/adapters/pi/child/done-nudge.js.map +1 -0
  31. package/dist/maestro/adapters/pi/child/entry.d.ts +3 -0
  32. package/dist/maestro/adapters/pi/child/entry.d.ts.map +1 -0
  33. package/dist/maestro/adapters/pi/child/entry.js +3 -0
  34. package/dist/maestro/adapters/pi/child/entry.js.map +1 -0
  35. package/dist/maestro/adapters/pi/child/protocol.d.ts +56 -0
  36. package/dist/maestro/adapters/pi/child/protocol.d.ts.map +1 -0
  37. package/dist/maestro/adapters/pi/child/protocol.js +510 -0
  38. package/dist/maestro/adapters/pi/child/protocol.js.map +1 -0
  39. package/dist/maestro/adapters/pi/completion.d.ts +45 -0
  40. package/dist/maestro/adapters/pi/completion.d.ts.map +1 -0
  41. package/dist/maestro/adapters/pi/completion.js +295 -0
  42. package/dist/maestro/adapters/pi/completion.js.map +1 -0
  43. package/dist/maestro/adapters/pi/launch-command.d.ts +27 -0
  44. package/dist/maestro/adapters/pi/launch-command.d.ts.map +1 -0
  45. package/dist/maestro/adapters/pi/launch-command.js +75 -0
  46. package/dist/maestro/adapters/pi/launch-command.js.map +1 -0
  47. package/dist/maestro/adapters/pi/launch-operations.d.ts +78 -0
  48. package/dist/maestro/adapters/pi/launch-operations.d.ts.map +1 -0
  49. package/dist/maestro/adapters/pi/launch-operations.js +270 -0
  50. package/dist/maestro/adapters/pi/launch-operations.js.map +1 -0
  51. package/dist/maestro/adapters/pi/launch-resume.d.ts +4 -0
  52. package/dist/maestro/adapters/pi/launch-resume.d.ts.map +1 -0
  53. package/dist/maestro/adapters/pi/launch-resume.js +183 -0
  54. package/dist/maestro/adapters/pi/launch-resume.js.map +1 -0
  55. package/dist/maestro/adapters/pi/launch.d.ts +148 -0
  56. package/dist/maestro/adapters/pi/launch.d.ts.map +1 -0
  57. package/dist/maestro/adapters/pi/launch.js +655 -0
  58. package/dist/maestro/adapters/pi/launch.js.map +1 -0
  59. package/dist/maestro/adapters/pi/model-registry.d.ts +3 -0
  60. package/dist/maestro/adapters/pi/model-registry.d.ts.map +1 -0
  61. package/dist/maestro/adapters/pi/model-registry.js +29 -0
  62. package/dist/maestro/adapters/pi/model-registry.js.map +1 -0
  63. package/dist/maestro/adapters/pi/pi-harness-adapter.d.ts +95 -0
  64. package/dist/maestro/adapters/pi/pi-harness-adapter.d.ts.map +1 -0
  65. package/dist/maestro/adapters/pi/pi-harness-adapter.js +549 -0
  66. package/dist/maestro/adapters/pi/pi-harness-adapter.js.map +1 -0
  67. package/dist/maestro/adapters/pi/process-identity.d.ts +92 -0
  68. package/dist/maestro/adapters/pi/process-identity.d.ts.map +1 -0
  69. package/dist/maestro/adapters/pi/process-identity.js +248 -0
  70. package/dist/maestro/adapters/pi/process-identity.js.map +1 -0
  71. package/dist/maestro/adapters/pi/process-tree.d.ts +48 -0
  72. package/dist/maestro/adapters/pi/process-tree.d.ts.map +1 -0
  73. package/dist/maestro/adapters/pi/process-tree.js +69 -0
  74. package/dist/maestro/adapters/pi/process-tree.js.map +1 -0
  75. package/dist/maestro/adapters/pi/script-shell.d.ts +40 -0
  76. package/dist/maestro/adapters/pi/script-shell.d.ts.map +1 -0
  77. package/dist/maestro/adapters/pi/script-shell.js +43 -0
  78. package/dist/maestro/adapters/pi/script-shell.js.map +1 -0
  79. package/dist/maestro/adapters/pi/session.d.ts +207 -0
  80. package/dist/maestro/adapters/pi/session.d.ts.map +1 -0
  81. package/dist/maestro/adapters/pi/session.js +714 -0
  82. package/dist/maestro/adapters/pi/session.js.map +1 -0
  83. package/dist/maestro/adapters/pi/task-model-init.d.ts +4 -0
  84. package/dist/maestro/adapters/pi/task-model-init.d.ts.map +1 -0
  85. package/dist/maestro/adapters/pi/task-model-init.js +47 -0
  86. package/dist/maestro/adapters/pi/task-model-init.js.map +1 -0
  87. package/dist/maestro/core/accept.d.ts +150 -0
  88. package/dist/maestro/core/accept.d.ts.map +1 -0
  89. package/dist/maestro/core/accept.js +243 -0
  90. package/dist/maestro/core/accept.js.map +1 -0
  91. package/dist/maestro/core/activity.d.ts +4 -0
  92. package/dist/maestro/core/activity.d.ts.map +1 -0
  93. package/dist/maestro/core/activity.js +18 -0
  94. package/dist/maestro/core/activity.js.map +1 -0
  95. package/dist/maestro/core/child-busy.d.ts +14 -0
  96. package/dist/maestro/core/child-busy.d.ts.map +1 -0
  97. package/dist/maestro/core/child-busy.js +14 -0
  98. package/dist/maestro/core/child-busy.js.map +1 -0
  99. package/dist/maestro/core/config/guidelines-config.d.ts +8 -0
  100. package/dist/maestro/core/config/guidelines-config.d.ts.map +1 -0
  101. package/dist/maestro/core/config/guidelines-config.js +60 -0
  102. package/dist/maestro/core/config/guidelines-config.js.map +1 -0
  103. package/dist/maestro/core/config/herdr-config.d.ts +13 -0
  104. package/dist/maestro/core/config/herdr-config.d.ts.map +1 -0
  105. package/dist/maestro/core/config/herdr-config.js +65 -0
  106. package/dist/maestro/core/config/herdr-config.js.map +1 -0
  107. package/dist/maestro/core/config/model-config.d.ts +92 -0
  108. package/dist/maestro/core/config/model-config.d.ts.map +1 -0
  109. package/dist/maestro/core/config/model-config.js +522 -0
  110. package/dist/maestro/core/config/model-config.js.map +1 -0
  111. package/dist/maestro/core/config/outcome-ledger-config.d.ts +8 -0
  112. package/dist/maestro/core/config/outcome-ledger-config.d.ts.map +1 -0
  113. package/dist/maestro/core/config/outcome-ledger-config.js +49 -0
  114. package/dist/maestro/core/config/outcome-ledger-config.js.map +1 -0
  115. package/dist/maestro/core/config/pane-config.d.ts +15 -0
  116. package/dist/maestro/core/config/pane-config.d.ts.map +1 -0
  117. package/dist/maestro/core/config/pane-config.js +101 -0
  118. package/dist/maestro/core/config/pane-config.js.map +1 -0
  119. package/dist/maestro/core/config/persistent-config.d.ts +7 -0
  120. package/dist/maestro/core/config/persistent-config.d.ts.map +1 -0
  121. package/dist/maestro/core/config/persistent-config.js +72 -0
  122. package/dist/maestro/core/config/persistent-config.js.map +1 -0
  123. package/dist/maestro/core/config/role-config.d.ts +7 -0
  124. package/dist/maestro/core/config/role-config.d.ts.map +1 -0
  125. package/dist/maestro/core/config/role-config.js +74 -0
  126. package/dist/maestro/core/config/role-config.js.map +1 -0
  127. package/dist/maestro/core/config/spawning-config.d.ts +7 -0
  128. package/dist/maestro/core/config/spawning-config.d.ts.map +1 -0
  129. package/dist/maestro/core/config/spawning-config.js +65 -0
  130. package/dist/maestro/core/config/spawning-config.js.map +1 -0
  131. package/dist/maestro/core/config/supervision-config.d.ts +7 -0
  132. package/dist/maestro/core/config/supervision-config.d.ts.map +1 -0
  133. package/dist/maestro/core/config/supervision-config.js +69 -0
  134. package/dist/maestro/core/config/supervision-config.js.map +1 -0
  135. package/dist/maestro/core/config/task-model-init.d.ts +118 -0
  136. package/dist/maestro/core/config/task-model-init.d.ts.map +1 -0
  137. package/dist/maestro/core/config/task-model-init.js +168 -0
  138. package/dist/maestro/core/config/task-model-init.js.map +1 -0
  139. package/dist/maestro/core/config/task-model-types.d.ts +36 -0
  140. package/dist/maestro/core/config/task-model-types.d.ts.map +1 -0
  141. package/dist/maestro/core/config/task-model-types.js +17 -0
  142. package/dist/maestro/core/config/task-model-types.js.map +1 -0
  143. package/dist/maestro/core/config/type-guards.d.ts +22 -0
  144. package/dist/maestro/core/config/type-guards.d.ts.map +1 -0
  145. package/dist/maestro/core/config/type-guards.js +31 -0
  146. package/dist/maestro/core/config/type-guards.js.map +1 -0
  147. package/dist/maestro/core/deadline.d.ts +11 -0
  148. package/dist/maestro/core/deadline.d.ts.map +1 -0
  149. package/dist/maestro/core/deadline.js +30 -0
  150. package/dist/maestro/core/deadline.js.map +1 -0
  151. package/dist/maestro/core/declared-skills.d.ts +16 -0
  152. package/dist/maestro/core/declared-skills.d.ts.map +1 -0
  153. package/dist/maestro/core/declared-skills.js +52 -0
  154. package/dist/maestro/core/declared-skills.js.map +1 -0
  155. package/dist/maestro/core/delegation-depth.d.ts +38 -0
  156. package/dist/maestro/core/delegation-depth.d.ts.map +1 -0
  157. package/dist/maestro/core/delegation-depth.js +59 -0
  158. package/dist/maestro/core/delegation-depth.js.map +1 -0
  159. package/dist/maestro/core/git-environment.d.ts +3 -0
  160. package/dist/maestro/core/git-environment.d.ts.map +1 -0
  161. package/dist/maestro/core/git-environment.js +29 -0
  162. package/dist/maestro/core/git-environment.js.map +1 -0
  163. package/dist/maestro/core/harness-adapter.d.ts +89 -0
  164. package/dist/maestro/core/harness-adapter.d.ts.map +1 -0
  165. package/dist/maestro/core/harness-adapter.js +2 -0
  166. package/dist/maestro/core/harness-adapter.js.map +1 -0
  167. package/dist/maestro/core/host-text.d.ts +49 -0
  168. package/dist/maestro/core/host-text.d.ts.map +1 -0
  169. package/dist/maestro/core/host-text.js +106 -0
  170. package/dist/maestro/core/host-text.js.map +1 -0
  171. package/dist/maestro/core/index.d.ts +4 -0
  172. package/dist/maestro/core/index.d.ts.map +1 -0
  173. package/dist/maestro/core/index.js +2 -0
  174. package/dist/maestro/core/index.js.map +1 -0
  175. package/dist/maestro/core/lifecycle.d.ts +16 -0
  176. package/dist/maestro/core/lifecycle.d.ts.map +1 -0
  177. package/dist/maestro/core/lifecycle.js +429 -0
  178. package/dist/maestro/core/lifecycle.js.map +1 -0
  179. package/dist/maestro/core/opened-primary-workspace.d.ts +31 -0
  180. package/dist/maestro/core/opened-primary-workspace.d.ts.map +1 -0
  181. package/dist/maestro/core/opened-primary-workspace.js +49 -0
  182. package/dist/maestro/core/opened-primary-workspace.js.map +1 -0
  183. package/dist/maestro/core/platform-support.d.ts +15 -0
  184. package/dist/maestro/core/platform-support.d.ts.map +1 -0
  185. package/dist/maestro/core/platform-support.js +23 -0
  186. package/dist/maestro/core/platform-support.js.map +1 -0
  187. package/dist/maestro/core/realpath-without-opening.d.ts +9 -0
  188. package/dist/maestro/core/realpath-without-opening.d.ts.map +1 -0
  189. package/dist/maestro/core/realpath-without-opening.js +45 -0
  190. package/dist/maestro/core/realpath-without-opening.js.map +1 -0
  191. package/dist/maestro/core/roles/discovery.d.ts +64 -0
  192. package/dist/maestro/core/roles/discovery.d.ts.map +1 -0
  193. package/dist/maestro/core/roles/discovery.js +422 -0
  194. package/dist/maestro/core/roles/discovery.js.map +1 -0
  195. package/dist/maestro/core/routing.d.ts +115 -0
  196. package/dist/maestro/core/routing.d.ts.map +1 -0
  197. package/dist/maestro/core/routing.js +449 -0
  198. package/dist/maestro/core/routing.js.map +1 -0
  199. package/dist/maestro/core/script-launch.d.ts +47 -0
  200. package/dist/maestro/core/script-launch.d.ts.map +1 -0
  201. package/dist/maestro/core/script-launch.js +102 -0
  202. package/dist/maestro/core/script-launch.js.map +1 -0
  203. package/dist/maestro/core/shell.d.ts +2 -0
  204. package/dist/maestro/core/shell.d.ts.map +1 -0
  205. package/dist/maestro/core/shell.js +4 -0
  206. package/dist/maestro/core/shell.js.map +1 -0
  207. package/dist/maestro/core/specialist-notice.d.ts +36 -0
  208. package/dist/maestro/core/specialist-notice.d.ts.map +1 -0
  209. package/dist/maestro/core/specialist-notice.js +41 -0
  210. package/dist/maestro/core/specialist-notice.js.map +1 -0
  211. package/dist/maestro/core/status.d.ts +87 -0
  212. package/dist/maestro/core/status.d.ts.map +1 -0
  213. package/dist/maestro/core/status.js +369 -0
  214. package/dist/maestro/core/status.js.map +1 -0
  215. package/dist/maestro/core/supervision.d.ts +56 -0
  216. package/dist/maestro/core/supervision.d.ts.map +1 -0
  217. package/dist/maestro/core/supervision.js +249 -0
  218. package/dist/maestro/core/supervision.js.map +1 -0
  219. package/dist/maestro/core/surface-provider.d.ts +200 -0
  220. package/dist/maestro/core/surface-provider.d.ts.map +1 -0
  221. package/dist/maestro/core/surface-provider.js +71 -0
  222. package/dist/maestro/core/surface-provider.js.map +1 -0
  223. package/dist/maestro/core/types.d.ts +388 -0
  224. package/dist/maestro/core/types.d.ts.map +1 -0
  225. package/dist/maestro/core/types.js +2 -0
  226. package/dist/maestro/core/types.js.map +1 -0
  227. package/dist/maestro/core/undelivered-children.d.ts +27 -0
  228. package/dist/maestro/core/undelivered-children.d.ts.map +1 -0
  229. package/dist/maestro/core/undelivered-children.js +31 -0
  230. package/dist/maestro/core/undelivered-children.js.map +1 -0
  231. package/dist/maestro/core/wake.d.ts +32 -0
  232. package/dist/maestro/core/wake.d.ts.map +1 -0
  233. package/dist/maestro/core/wake.js +125 -0
  234. package/dist/maestro/core/wake.js.map +1 -0
  235. package/dist/maestro/core/worktree-cleanup.d.ts +75 -0
  236. package/dist/maestro/core/worktree-cleanup.d.ts.map +1 -0
  237. package/dist/maestro/core/worktree-cleanup.js +278 -0
  238. package/dist/maestro/core/worktree-cleanup.js.map +1 -0
  239. package/dist/maestro/core/worktree.d.ts +50 -0
  240. package/dist/maestro/core/worktree.d.ts.map +1 -0
  241. package/dist/maestro/core/worktree.js +23 -0
  242. package/dist/maestro/core/worktree.js.map +1 -0
  243. package/dist/maestro/engine.d.ts +5 -0
  244. package/dist/maestro/engine.d.ts.map +1 -0
  245. package/dist/maestro/engine.js +5 -0
  246. package/dist/maestro/engine.js.map +1 -0
  247. package/dist/maestro/pi/child.d.ts +8 -0
  248. package/dist/maestro/pi/child.d.ts.map +1 -0
  249. package/dist/maestro/pi/child.js +8 -0
  250. package/dist/maestro/pi/child.js.map +1 -0
  251. package/dist/maestro/pi/extension.d.ts +10 -0
  252. package/dist/maestro/pi/extension.d.ts.map +1 -0
  253. package/dist/maestro/pi/extension.js +8 -0
  254. package/dist/maestro/pi/extension.js.map +1 -0
  255. package/dist/maestro/pi/subagents-index.d.ts +9 -0
  256. package/dist/maestro/pi/subagents-index.d.ts.map +1 -0
  257. package/dist/maestro/pi/subagents-index.js +9 -0
  258. package/dist/maestro/pi/subagents-index.js.map +1 -0
  259. package/dist/maestro/pi.d.ts +9 -0
  260. package/dist/maestro/pi.d.ts.map +1 -0
  261. package/dist/maestro/pi.js +7 -0
  262. package/dist/maestro/pi.js.map +1 -0
  263. package/dist/maestro/runtime/accept-recheck.d.ts +32 -0
  264. package/dist/maestro/runtime/accept-recheck.d.ts.map +1 -0
  265. package/dist/maestro/runtime/accept-recheck.js +92 -0
  266. package/dist/maestro/runtime/accept-recheck.js.map +1 -0
  267. package/dist/maestro/runtime/delegated-marker.d.ts +112 -0
  268. package/dist/maestro/runtime/delegated-marker.d.ts.map +1 -0
  269. package/dist/maestro/runtime/delegated-marker.js +200 -0
  270. package/dist/maestro/runtime/delegated-marker.js.map +1 -0
  271. package/dist/maestro/runtime/host-surface-binding.d.ts +25 -0
  272. package/dist/maestro/runtime/host-surface-binding.d.ts.map +1 -0
  273. package/dist/maestro/runtime/host-surface-binding.js +2 -0
  274. package/dist/maestro/runtime/host-surface-binding.js.map +1 -0
  275. package/dist/maestro/runtime/index.d.ts +10 -0
  276. package/dist/maestro/runtime/index.d.ts.map +1 -0
  277. package/dist/maestro/runtime/index.js +6 -0
  278. package/dist/maestro/runtime/index.js.map +1 -0
  279. package/dist/maestro/runtime/pi-persistent-io.d.ts +7 -0
  280. package/dist/maestro/runtime/pi-persistent-io.d.ts.map +1 -0
  281. package/dist/maestro/runtime/pi-persistent-io.js +64 -0
  282. package/dist/maestro/runtime/pi-persistent-io.js.map +1 -0
  283. package/dist/maestro/runtime/pi-run-session-types.d.ts +328 -0
  284. package/dist/maestro/runtime/pi-run-session-types.d.ts.map +1 -0
  285. package/dist/maestro/runtime/pi-run-session-types.js +2 -0
  286. package/dist/maestro/runtime/pi-run-session-types.js.map +1 -0
  287. package/dist/maestro/runtime/pi-run-session.d.ts +12 -0
  288. package/dist/maestro/runtime/pi-run-session.d.ts.map +1 -0
  289. package/dist/maestro/runtime/pi-run-session.js +809 -0
  290. package/dist/maestro/runtime/pi-run-session.js.map +1 -0
  291. package/dist/maestro/runtime/run-session.d.ts +129 -0
  292. package/dist/maestro/runtime/run-session.d.ts.map +1 -0
  293. package/dist/maestro/runtime/run-session.js +680 -0
  294. package/dist/maestro/runtime/run-session.js.map +1 -0
  295. package/dist/maestro/runtime/surface-retention.d.ts +3 -0
  296. package/dist/maestro/runtime/surface-retention.d.ts.map +1 -0
  297. package/dist/maestro/runtime/surface-retention.js +5 -0
  298. package/dist/maestro/runtime/surface-retention.js.map +1 -0
  299. package/dist/maestro/runtime/task-model-init.d.ts +34 -0
  300. package/dist/maestro/runtime/task-model-init.d.ts.map +1 -0
  301. package/dist/maestro/runtime/task-model-init.js +78 -0
  302. package/dist/maestro/runtime/task-model-init.js.map +1 -0
  303. package/dist/maestro/runtime/worktree-operations.d.ts +31 -0
  304. package/dist/maestro/runtime/worktree-operations.d.ts.map +1 -0
  305. package/dist/maestro/runtime/worktree-operations.js +633 -0
  306. package/dist/maestro/runtime/worktree-operations.js.map +1 -0
  307. package/dist/maestro/surfaces/fake/fake-surface-provider.d.ts +54 -0
  308. package/dist/maestro/surfaces/fake/fake-surface-provider.d.ts.map +1 -0
  309. package/dist/maestro/surfaces/fake/fake-surface-provider.js +231 -0
  310. package/dist/maestro/surfaces/fake/fake-surface-provider.js.map +1 -0
  311. package/dist/maestro/testing/harness-adapter.conformance.d.ts +31 -0
  312. package/dist/maestro/testing/harness-adapter.conformance.d.ts.map +1 -0
  313. package/dist/maestro/testing/harness-adapter.conformance.js +181 -0
  314. package/dist/maestro/testing/harness-adapter.conformance.js.map +1 -0
  315. package/dist/maestro/testing/index.d.ts +5 -0
  316. package/dist/maestro/testing/index.d.ts.map +1 -0
  317. package/dist/maestro/testing/index.js +5 -0
  318. package/dist/maestro/testing/index.js.map +1 -0
  319. package/dist/maestro/testing/surface-provider.conformance.d.ts +20 -0
  320. package/dist/maestro/testing/surface-provider.conformance.d.ts.map +1 -0
  321. package/dist/maestro/testing/surface-provider.conformance.js +167 -0
  322. package/dist/maestro/testing/surface-provider.conformance.js.map +1 -0
  323. package/dist/pi-extension/subagents/catalog.d.ts +70 -0
  324. package/dist/pi-extension/subagents/catalog.d.ts.map +1 -0
  325. package/dist/pi-extension/subagents/catalog.js +231 -0
  326. package/dist/pi-extension/subagents/catalog.js.map +1 -0
  327. package/dist/pi-extension/subagents/config-path.d.ts +6 -0
  328. package/dist/pi-extension/subagents/config-path.d.ts.map +1 -0
  329. package/dist/pi-extension/subagents/config-path.js +21 -0
  330. package/dist/pi-extension/subagents/config-path.js.map +1 -0
  331. package/dist/pi-extension/subagents/control-tools.d.ts +21 -0
  332. package/dist/pi-extension/subagents/control-tools.d.ts.map +1 -0
  333. package/dist/pi-extension/subagents/control-tools.js +150 -0
  334. package/dist/pi-extension/subagents/control-tools.js.map +1 -0
  335. package/dist/pi-extension/subagents/controls.d.ts +52 -0
  336. package/dist/pi-extension/subagents/controls.d.ts.map +1 -0
  337. package/dist/pi-extension/subagents/controls.js +173 -0
  338. package/dist/pi-extension/subagents/controls.js.map +1 -0
  339. package/dist/pi-extension/subagents/deferred-tools.d.ts +43 -0
  340. package/dist/pi-extension/subagents/deferred-tools.d.ts.map +1 -0
  341. package/dist/pi-extension/subagents/deferred-tools.js +67 -0
  342. package/dist/pi-extension/subagents/deferred-tools.js.map +1 -0
  343. package/dist/pi-extension/subagents/delivery.d.ts +22 -0
  344. package/dist/pi-extension/subagents/delivery.d.ts.map +1 -0
  345. package/dist/pi-extension/subagents/delivery.js +365 -0
  346. package/dist/pi-extension/subagents/delivery.js.map +1 -0
  347. package/dist/pi-extension/subagents/extension.d.ts +100 -0
  348. package/dist/pi-extension/subagents/extension.d.ts.map +1 -0
  349. package/dist/pi-extension/subagents/extension.js +367 -0
  350. package/dist/pi-extension/subagents/extension.js.map +1 -0
  351. package/dist/pi-extension/subagents/launch-tools.d.ts +33 -0
  352. package/dist/pi-extension/subagents/launch-tools.d.ts.map +1 -0
  353. package/dist/pi-extension/subagents/launch-tools.js +373 -0
  354. package/dist/pi-extension/subagents/launch-tools.js.map +1 -0
  355. package/dist/pi-extension/subagents/launch.d.ts +86 -0
  356. package/dist/pi-extension/subagents/launch.d.ts.map +1 -0
  357. package/dist/pi-extension/subagents/launch.js +133 -0
  358. package/dist/pi-extension/subagents/launch.js.map +1 -0
  359. package/dist/pi-extension/subagents/model-registry.d.ts +13 -0
  360. package/dist/pi-extension/subagents/model-registry.d.ts.map +1 -0
  361. package/dist/pi-extension/subagents/model-registry.js +52 -0
  362. package/dist/pi-extension/subagents/model-registry.js.map +1 -0
  363. package/dist/pi-extension/subagents/observation.d.ts +38 -0
  364. package/dist/pi-extension/subagents/observation.d.ts.map +1 -0
  365. package/dist/pi-extension/subagents/observation.js +168 -0
  366. package/dist/pi-extension/subagents/observation.js.map +1 -0
  367. package/dist/pi-extension/subagents/persistent.d.ts +72 -0
  368. package/dist/pi-extension/subagents/persistent.d.ts.map +1 -0
  369. package/dist/pi-extension/subagents/persistent.js +322 -0
  370. package/dist/pi-extension/subagents/persistent.js.map +1 -0
  371. package/dist/pi-extension/subagents/presentation-hooks.d.ts +25 -0
  372. package/dist/pi-extension/subagents/presentation-hooks.d.ts.map +1 -0
  373. package/dist/pi-extension/subagents/presentation-hooks.js +2 -0
  374. package/dist/pi-extension/subagents/presentation-hooks.js.map +1 -0
  375. package/dist/pi-extension/subagents/presentation.d.ts +149 -0
  376. package/dist/pi-extension/subagents/presentation.d.ts.map +1 -0
  377. package/dist/pi-extension/subagents/presentation.js +419 -0
  378. package/dist/pi-extension/subagents/presentation.js.map +1 -0
  379. package/dist/pi-extension/subagents/state.d.ts +183 -0
  380. package/dist/pi-extension/subagents/state.d.ts.map +1 -0
  381. package/dist/pi-extension/subagents/state.js +92 -0
  382. package/dist/pi-extension/subagents/state.js.map +1 -0
  383. package/dist/pi-extension/subagents/task-models.d.ts +9 -0
  384. package/dist/pi-extension/subagents/task-models.d.ts.map +1 -0
  385. package/dist/pi-extension/subagents/task-models.js +293 -0
  386. package/dist/pi-extension/subagents/task-models.js.map +1 -0
  387. package/dist/pi-extension/subagents/tool-boundary.d.ts +16 -0
  388. package/dist/pi-extension/subagents/tool-boundary.d.ts.map +1 -0
  389. package/dist/pi-extension/subagents/tool-boundary.js +53 -0
  390. package/dist/pi-extension/subagents/tool-boundary.js.map +1 -0
  391. package/dist/pi-extension/subagents/worktree-tools.d.ts +16 -0
  392. package/dist/pi-extension/subagents/worktree-tools.d.ts.map +1 -0
  393. package/dist/pi-extension/subagents/worktree-tools.js +185 -0
  394. package/dist/pi-extension/subagents/worktree-tools.js.map +1 -0
  395. package/dist/provenance.json +5 -0
  396. package/package.json +540 -27
  397. package/index.d.ts +0 -1
  398. package/index.js +0 -2
@@ -0,0 +1,655 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
3
+ import { dirname, isAbsolute, join, win32 } from "node:path";
4
+ import { homedir } from "node:os";
5
+ import { getSubagentActivityFile } from "./activity-file.js";
6
+ import { createLifecycle, } from "../../core/lifecycle.js";
7
+ import { assertModelInScope, } from "../../core/routing.js";
8
+ import { DECLARED_SKILLS_ENV, formatDeclaredSkillsEnv, parseDeclaredSkills, } from "../../core/declared-skills.js";
9
+ import { shellQuote } from "../../core/shell.js";
10
+ import { ACCEPT_FILE_ENV } from "../../core/accept.js";
11
+ import { AcquisitionUncertainError, isAcquisitionUncertainError, WorktreeProvisioningError, } from "../../core/surface-provider.js";
12
+ import { getSubagentProcessIdentityFile, } from "./process-identity.js";
13
+ import { appendPersistentDeliveryLedger, createWorktreeSessionFork, seedSubagentSessionFile, writeSubagentSessionPolicy, } from "./session.js";
14
+ import { buildSubagentToolAllowlist, childDepthAssignment, modelScopeArgs, modelScopeAssignment, safeName, shellComment, DEFAULT_CHILD_ENTRY_PATH, timestampForFile, } from "./launch-command.js";
15
+ import { shellExitFileFor } from "./completion.js";
16
+ import { PI_LAUNCH_SESSION_ENV, } from "./launch-operations.js";
17
+ import { launchResumedPiSubagent } from "./launch-resume.js";
18
+ /** Ownership transfer, not a retryable rejection. The initialized child is real. */
19
+ export class AcquiredPiLaunchError extends Error {
20
+ child;
21
+ constructor(child, cause) {
22
+ super(`Launch outcome uncertain; ${child.worktree ? `worktree retained at ${child.worktree.path} (workspace ${child.worktree.workspaceId}); ` : `pane ${child.surface}; `}owner retained, no fallback: ${errorMessage(cause)}`, { cause });
23
+ this.name = "AcquiredPiLaunchError";
24
+ this.child = child;
25
+ child.launchFailure = this.message;
26
+ }
27
+ }
28
+ /**
29
+ * Launch one validated Pi-backed request. Lifecycle watching and parent
30
+ * delivery begin only after this transaction returns the running child.
31
+ */
32
+ export async function launchPiSubagent(request, operations) {
33
+ if (request.kind === "resume")
34
+ return launchResumedPiSubagent(request, operations);
35
+ if (operations.nativeExecution &&
36
+ (request.worktree || request.handoff || request.surface))
37
+ throw new Error("Herdr Core supports ordinary native execution only; managed worktrees, handoffs and supplied panes are deferred");
38
+ // Last checks before any resource exists: the plan must be in the live
39
+ // scope, and the scope must be representable as the child's --models.
40
+ assertModelInScope(request.runtimePlan.model, { scope: request.modelScope });
41
+ modelScopeArgs(request.modelScope);
42
+ // Declared skill names must follow Pi's rules; a handoff carries none.
43
+ if (!request.handoff)
44
+ parseDeclaredSkills(request.behavior.skills);
45
+ return launchFreshPiSubagent(request, operations);
46
+ }
47
+ export async function launchPiWorktreeHandoff(request, operations) {
48
+ if (!request.worktree || !request.handoff) {
49
+ throw new Error("A worktree handoff requires a worktree and active leaf");
50
+ }
51
+ const running = await launchPiSubagent(request, operations);
52
+ if (!running.worktree) {
53
+ throw new Error("Worktree handoff did not create a managed worktree");
54
+ }
55
+ try {
56
+ await operations.focusWorkspace?.(running.worktree.workspaceId);
57
+ }
58
+ catch (error) {
59
+ const focusError = errorMessage(error);
60
+ requireWorktreeOperations(operations).writeWorktreeManifest(running.worktree.manifestFile, {
61
+ state: "running",
62
+ focusError,
63
+ });
64
+ return {
65
+ running,
66
+ focusError,
67
+ };
68
+ }
69
+ return { running };
70
+ }
71
+ async function launchFreshPiSubagent(request, operations) {
72
+ const resolved = resolveLaunchRequest(request);
73
+ if (operations.nativeExecution)
74
+ return launchNativePiSubagent(resolved, operations);
75
+ let surface;
76
+ let running;
77
+ try {
78
+ request.acquisitionSignal?.throwIfAborted();
79
+ surface = await prepareLaunchSurface(resolved, operations);
80
+ request.acquisitionSignal?.throwIfAborted();
81
+ const session = prepareChildSession(resolved, surface, operations);
82
+ const handoffArtifacts = request.handoff
83
+ ? prepareTaskArtifacts(resolved, session, operations)
84
+ : undefined;
85
+ await confirmShellReady(session, operations);
86
+ const artifacts = handoffArtifacts ?? prepareTaskArtifacts(resolved, session, operations);
87
+ request.acquisitionSignal?.throwIfAborted();
88
+ const command = buildPiCommand(resolved, artifacts);
89
+ if (artifacts.worktree && !request.handoff) {
90
+ requireWorktreeOperations(operations).persistWorktreeResult(artifacts.worktree, "running");
91
+ }
92
+ request.acquisitionSignal?.throwIfAborted();
93
+ // Complete fallible initialization while this transaction still owns the
94
+ // surface, before any child can run or mutate its session artifacts.
95
+ const initialized = {
96
+ ...createRunningChild(resolved, artifacts),
97
+ surface: requiredSurface(artifacts),
98
+ };
99
+ try {
100
+ initialized.launchScriptFile = await startPiProcess(resolved, artifacts, command, initialized.launchScriptFile, operations);
101
+ }
102
+ catch (error) {
103
+ if (isAcquisitionUncertainError(error) &&
104
+ error.uncertainty.kind === "command-dispatch")
105
+ running = initialized;
106
+ throw error;
107
+ }
108
+ running = initialized;
109
+ if (request.handoff) {
110
+ if (!operations.waitForPiReady) {
111
+ throw new Error("Pi startup confirmation is unavailable");
112
+ }
113
+ await operations.waitForPiReady(requiredSurface(artifacts), artifacts.sessionFile, artifacts.targetCwd);
114
+ if (artifacts.worktree) {
115
+ requireWorktreeOperations(operations).persistWorktreeResult(artifacts.worktree, "running");
116
+ }
117
+ }
118
+ startProcessIdentityCapture(running, operations);
119
+ return running;
120
+ }
121
+ catch (error) {
122
+ if (!surface)
123
+ throw error;
124
+ if (running)
125
+ startProcessIdentityCapture(running, operations);
126
+ if (!surface.worktree) {
127
+ if (!request.surface) {
128
+ try {
129
+ await operations.closePane(requiredSurface(surface));
130
+ }
131
+ catch (rollback) {
132
+ if (running)
133
+ throw new AcquiredPiLaunchError(running, new Error(`${errorMessage(error)}; rollback unconfirmed: ${errorMessage(rollback)}`, { cause: error }));
134
+ throw new AcquisitionUncertainError(`${errorMessage(error)}; rollback unconfirmed: ${errorMessage(rollback)}; pane retained: ${surface.surface}; no fallback`, {
135
+ kind: "surface-create",
136
+ placement: "tab",
137
+ observedSurfaceId: surface.surface,
138
+ }, { cause: error });
139
+ }
140
+ }
141
+ if (running)
142
+ throw new AcquiredPiLaunchError(running, error);
143
+ throw error;
144
+ }
145
+ if (running) {
146
+ try {
147
+ const worktreeOps = requireWorktreeOperations(operations);
148
+ // Interactive handoffs have no runtime finalizer. Watched children capture there once.
149
+ const handoff = request.handoff
150
+ ? await worktreeOps.captureWorktreeHandoff(surface.worktree)
151
+ : undefined;
152
+ worktreeOps.persistWorktreeResult(surface.worktree, "failed", handoff);
153
+ worktreeOps.writeWorktreeManifest(surface.worktree.manifestFile, {
154
+ acquisitionUncertain: true,
155
+ error: errorMessage(error),
156
+ });
157
+ }
158
+ catch {
159
+ /* transfer ownership even if evidence persistence fails */
160
+ }
161
+ throw new AcquiredPiLaunchError(running, error);
162
+ }
163
+ const worktreeOps = requireWorktreeOperations(operations);
164
+ let handoff;
165
+ try {
166
+ handoff = await worktreeOps.captureWorktreeHandoff(surface.worktree);
167
+ }
168
+ catch {
169
+ /* preserve launch failure */
170
+ }
171
+ try {
172
+ worktreeOps.persistWorktreeResult(surface.worktree, "failed", handoff);
173
+ }
174
+ catch {
175
+ // The launch error remains authoritative when persistence also fails.
176
+ }
177
+ throw new Error(`Failed to launch subagent; worktree retained at ${surface.worktree.path} ` +
178
+ `(workspace ${surface.worktree.workspaceId}): ${errorMessage(error)}`);
179
+ }
180
+ }
181
+ async function launchNativePiSubagent(resolved, operations) {
182
+ const execution = operations.nativeExecution;
183
+ if (!execution)
184
+ throw new Error("Native execution unavailable");
185
+ const { request } = resolved;
186
+ request.acquisitionSignal?.throwIfAborted();
187
+ const session = prepareChildSession(resolved, {
188
+ targetCwd: resolved.sourceCwd,
189
+ effectiveAgentDir: resolved.localAgentDir ?? resolved.agentDir,
190
+ localAgentDir: resolved.localAgentDir,
191
+ }, operations);
192
+ const artifacts = prepareTaskArtifacts(resolved, session, operations);
193
+ const command = buildPiCommand(resolved, artifacts);
194
+ // This also writes the persistent dispatch ledger. Nothing fallible remains
195
+ // locally after submission, and no surface ID exists until Core replies.
196
+ const initialized = createRunningChild(resolved, artifacts);
197
+ try {
198
+ const surface = await execution.start({
199
+ cwd: artifacts.targetCwd,
200
+ command,
201
+ scriptPath: initialized.launchScriptFile,
202
+ scriptPreamble: shellComment(`Subagent launch script for ${request.name}`),
203
+ signal: request.acquisitionSignal,
204
+ });
205
+ return { ...initialized, surface };
206
+ }
207
+ catch (error) {
208
+ if (isAcquisitionUncertainError(error) &&
209
+ error.uncertainty.kind === "execution-start" &&
210
+ error.uncertainty.acquiredSurfaceId)
211
+ throw new AcquiredPiLaunchError({ ...initialized, surface: error.uncertainty.acquiredSurfaceId }, error);
212
+ throw error;
213
+ }
214
+ }
215
+ function requiredSurface(surface) {
216
+ if (!surface.surface)
217
+ throw new Error("Shell launch requires an acquired surface");
218
+ return surface.surface;
219
+ }
220
+ function resolveLaunchRequest(request) {
221
+ const id = request.id ?? Math.random().toString(16).slice(2, 10);
222
+ const agentDir = request.parent.agentDir ??
223
+ process.env.PI_CODING_AGENT_DIR ??
224
+ join(homedir(), ".pi", "agent");
225
+ const rawCwd = request.cwd ?? request.behavior.cwd;
226
+ const cwdBase = request.cwd == null && request.behavior.cwd != null
227
+ ? agentDir
228
+ : (request.parent.invocationCwd ?? request.parent.cwd);
229
+ const sourceCwd = rawCwd
230
+ ? isAbsolute(rawCwd) || win32.isAbsolute(rawCwd)
231
+ ? rawCwd
232
+ : join(cwdBase, rawCwd)
233
+ : request.parent.cwd;
234
+ const localAgentDir = rawCwd ? join(sourceCwd, ".pi", "agent") : null;
235
+ let sessionMode = request.behavior.sessionMode;
236
+ if (request.fork === true)
237
+ sessionMode = "fork";
238
+ else if (request.fork === false)
239
+ sessionMode = "standalone";
240
+ return {
241
+ request,
242
+ id,
243
+ startTime: Date.now(),
244
+ agentDir,
245
+ localAgentDir: localAgentDir && existsSync(localAgentDir) ? localAgentDir : null,
246
+ sourceCwd,
247
+ artifactDir: join(request.parent.sessionDir, "artifacts", request.parent.sessionId),
248
+ sessionMode,
249
+ taskDelivery: sessionMode === "fork" ? "direct" : "artifact",
250
+ };
251
+ }
252
+ async function prepareLaunchSurface(resolved, operations) {
253
+ const { request } = resolved;
254
+ if (!request.worktree) {
255
+ return {
256
+ surface: request.surface ??
257
+ (await operations.createPane(request.name, resolved.sourceCwd, {
258
+ signal: request.acquisitionSignal,
259
+ })),
260
+ targetCwd: resolved.sourceCwd,
261
+ effectiveAgentDir: resolved.localAgentDir ?? resolved.agentDir,
262
+ localAgentDir: resolved.localAgentDir,
263
+ };
264
+ }
265
+ if (request.surface)
266
+ throw new Error("A worktree subagent cannot use a pre-created pane");
267
+ const worktreeOps = requireWorktreeOperations(operations);
268
+ const baseRef = request.worktree.base ?? "HEAD";
269
+ const baseSha = await worktreeOps.resolveGitCommit(resolved.sourceCwd, baseRef);
270
+ const provisionCwd = await worktreeOps.resolveWorktreeProvisionCwd(resolved.sourceCwd);
271
+ const manifestFile = join(resolved.artifactDir, "worktree-runs", `${resolved.id}.json`);
272
+ const ownership = {
273
+ id: resolved.id,
274
+ name: request.name,
275
+ sourceCwd: resolved.sourceCwd,
276
+ branch: request.worktree.branch,
277
+ baseRef,
278
+ baseSha,
279
+ createdAt: resolved.startTime,
280
+ };
281
+ worktreeOps.writeWorktreeManifest(manifestFile, {
282
+ state: "provisioning",
283
+ ...ownership,
284
+ });
285
+ let created;
286
+ try {
287
+ created = await operations.createWorktree(request.name, provisionCwd, request.worktree.branch, baseSha, { signal: request.acquisitionSignal });
288
+ }
289
+ catch (error) {
290
+ const failedManifest = {
291
+ state: "failed",
292
+ ...ownership,
293
+ };
294
+ if (error instanceof WorktreeProvisioningError) {
295
+ Object.assign(failedManifest, error.recoveredWorktree);
296
+ }
297
+ if (isAcquisitionUncertainError(error) &&
298
+ error.uncertainty.kind === "worktree-create") {
299
+ Object.assign(failedManifest, error.uncertainty.recovered, {
300
+ acquisitionUncertain: true,
301
+ });
302
+ }
303
+ failedManifest.error = errorMessage(error);
304
+ try {
305
+ worktreeOps.writeWorktreeManifest(manifestFile, failedManifest);
306
+ }
307
+ catch {
308
+ /* original acquisition failure remains authoritative */
309
+ }
310
+ if (isAcquisitionUncertainError(error))
311
+ throw new AcquisitionUncertainError(`${error.message}; ownership manifest retained at ${manifestFile}`, error.uncertainty, { cause: error });
312
+ throw error;
313
+ }
314
+ const worktree = {
315
+ path: created.path,
316
+ workspaceId: created.workspaceId,
317
+ paneId: created.paneId,
318
+ branch: created.branch,
319
+ baseRef,
320
+ baseSha,
321
+ manifestFile,
322
+ };
323
+ if (created.diagnostics?.length)
324
+ worktree.diagnostics = created.diagnostics;
325
+ try {
326
+ worktreeOps.writeWorktreeManifest(manifestFile, {
327
+ state: "provisioned",
328
+ ...ownership,
329
+ ...worktree,
330
+ });
331
+ }
332
+ catch (error) {
333
+ // Preserve the known retained root even when a manifest update fails.
334
+ (worktree.diagnostics ??= []).push(`Manifest update failed: ${errorMessage(error)}`);
335
+ }
336
+ const isolatedAgentDir = join(created.path, ".pi", "agent");
337
+ const hasIsolatedAgentDir = existsSync(isolatedAgentDir);
338
+ return {
339
+ surface: created.paneId,
340
+ targetCwd: created.path,
341
+ effectiveAgentDir: hasIsolatedAgentDir
342
+ ? isolatedAgentDir
343
+ : resolved.agentDir,
344
+ localAgentDir: hasIsolatedAgentDir ? isolatedAgentDir : null,
345
+ worktree,
346
+ };
347
+ }
348
+ function prepareChildSession(resolved, surface, operations) {
349
+ const sessionDir = getDefaultSessionDirFor(surface.targetCwd, surface.effectiveAgentDir);
350
+ const timestamp = timestampForFile();
351
+ const uuid = [
352
+ resolved.id,
353
+ Math.random().toString(16).slice(2, 10),
354
+ Math.random().toString(16).slice(2, 10),
355
+ Math.random().toString(16).slice(2, 6),
356
+ ].join("-");
357
+ const sessionFile = join(sessionDir, `${timestamp}_${uuid}.jsonl`);
358
+ if (surface.worktree) {
359
+ surface.worktree.sessionFile = sessionFile;
360
+ requireWorktreeOperations(operations).writeWorktreeManifest(surface.worktree.manifestFile, { sessionFile });
361
+ }
362
+ const policy = writeSubagentSessionPolicy(sessionFile, {
363
+ owner: surface.worktree ? "managed-worktree" : "public",
364
+ tools: resolved.request.behavior.tools,
365
+ deniedTools: resolved.request.behavior.deniedTools,
366
+ persistent: resolved.request.behavior.persistent,
367
+ logicalId: resolved.request.behavior.logicalId ?? resolved.id,
368
+ generationId: resolved.request.behavior.generationId,
369
+ agent: resolved.request.handoff ? null : (resolved.request.agent ?? null),
370
+ selfSpawn: !resolved.request.handoff &&
371
+ Boolean(resolved.request.agent) &&
372
+ Boolean(resolved.request.behavior.selfSpawn),
373
+ worktree: surface.worktree
374
+ ? {
375
+ path: surface.worktree.path,
376
+ workspaceId: surface.worktree.workspaceId,
377
+ branch: surface.worktree.branch,
378
+ baseSha: surface.worktree.baseSha,
379
+ }
380
+ : undefined,
381
+ });
382
+ const activityFile = getSubagentActivityFile(resolved.artifactDir, resolved.id);
383
+ return {
384
+ ...surface,
385
+ sessionFile,
386
+ activityFile,
387
+ policy,
388
+ initialTaskId: policy.persistent
389
+ ? (resolved.request.behavior.taskId ?? randomUUID())
390
+ : undefined,
391
+ // A handoff Pi loads no child protocol extension, so it records nothing.
392
+ processIdentityFile: (surface.worktree || resolved.request.surface) &&
393
+ !resolved.request.handoff
394
+ ? getSubagentProcessIdentityFile(sessionFile)
395
+ : undefined,
396
+ };
397
+ }
398
+ async function confirmShellReady(session, operations) {
399
+ await operations.waitForShellReady(requiredSurface(session));
400
+ }
401
+ function buildWorktreeHandoffMessage(request, worktree, sessionFile) {
402
+ const task = request.task.slice(0, 2000);
403
+ return [
404
+ "Worktree handoff context:",
405
+ `Branch: ${worktree.branch}`,
406
+ `Base commit: ${worktree.baseSha}`,
407
+ `Worktree: ${worktree.path}`,
408
+ `Source session: ${request.parent.sessionFile}`,
409
+ `Fork session: ${sessionFile}`,
410
+ "",
411
+ "Requested task:",
412
+ task || "Continue the current work in this worktree.",
413
+ ].join("\n");
414
+ }
415
+ function prepareTaskArtifacts(resolved, session, operations) {
416
+ const { request } = resolved;
417
+ if (request.handoff) {
418
+ if (!session.worktree) {
419
+ throw new Error("A worktree handoff requires a managed worktree");
420
+ }
421
+ const handoffMessage = buildWorktreeHandoffMessage(request, session.worktree, session.sessionFile);
422
+ createWorktreeSessionFork({
423
+ parentSessionFile: request.parent.sessionFile,
424
+ leafId: request.handoff.leafId,
425
+ childSessionFile: session.sessionFile,
426
+ childCwd: session.targetCwd,
427
+ handoffMessage,
428
+ });
429
+ session.worktree.sourceSessionFile = request.parent.sessionFile;
430
+ session.worktree.handoffMessage = handoffMessage;
431
+ requireWorktreeOperations(operations).writeWorktreeManifest(session.worktree.manifestFile, {
432
+ sourceSessionFile: request.parent.sessionFile,
433
+ handoffMessage,
434
+ });
435
+ }
436
+ else if (resolved.sessionMode !== "standalone") {
437
+ seedSubagentSessionFile({
438
+ mode: resolved.sessionMode,
439
+ parentSessionFile: request.parent.sessionFile,
440
+ childSessionFile: session.sessionFile,
441
+ childCwd: session.targetCwd,
442
+ });
443
+ }
444
+ mkdirSync(dirname(session.activityFile), { recursive: true });
445
+ const identityInSystemPrompt = request.behavior.systemPromptMode && request.behavior.identity;
446
+ const roleBlock = request.behavior.identity && !identityInSystemPrompt
447
+ ? `\n\n${request.behavior.identity}`
448
+ : "";
449
+ const modeHint = request.behavior.autoExit
450
+ ? "Complete your task autonomously."
451
+ : "Complete your task. When finished, call the subagent_done tool. The user can interact with you at any time.";
452
+ const summaryInstruction = request.behavior.autoExit
453
+ ? "Your FINAL assistant message should summarize what you accomplished."
454
+ : "Your FINAL assistant message (before calling subagent_done or before the user exits) should summarize what you accomplished.";
455
+ const fullTask = request.handoff
456
+ ? request.task
457
+ : resolved.sessionMode === "fork"
458
+ ? request.task
459
+ : `${roleBlock}\n\n${modeHint}\n\n${request.task}\n\n${summaryInstruction}`;
460
+ let taskArg = fullTask;
461
+ if (resolved.taskDelivery === "artifact" && !request.handoff) {
462
+ const artifactPath = join(resolved.artifactDir, `context/${safeName(request.name) || "subagent"}-${timestampForFile(false)}.md`);
463
+ mkdirSync(dirname(artifactPath), { recursive: true });
464
+ writeFileSync(artifactPath, fullTask, "utf8");
465
+ taskArg = `@${artifactPath}`;
466
+ }
467
+ let systemPromptFile;
468
+ if (identityInSystemPrompt) {
469
+ systemPromptFile = join(resolved.artifactDir, `context/${safeName(request.name) || "subagent"}-sysprompt-${timestampForFile(false)}.md`);
470
+ mkdirSync(dirname(systemPromptFile), { recursive: true });
471
+ writeFileSync(systemPromptFile, identityInSystemPrompt, "utf8");
472
+ }
473
+ // A file, never the raw command in the launch environment or script.
474
+ let acceptFile;
475
+ if (request.accept && !request.handoff) {
476
+ acceptFile = join(resolved.artifactDir, `context/${safeName(request.name) || "subagent"}-accept-${resolved.id}.json`);
477
+ mkdirSync(dirname(acceptFile), { recursive: true });
478
+ writeFileSync(acceptFile, JSON.stringify({ version: 1, ...request.accept }), "utf8");
479
+ }
480
+ return { ...session, taskArg, systemPromptFile, acceptFile };
481
+ }
482
+ function buildPiCommand(resolved, artifacts) {
483
+ const { request } = resolved;
484
+ const parts = [
485
+ "pi",
486
+ "--session",
487
+ shellQuote(artifacts.sessionFile),
488
+ ...(request.handoff
489
+ ? []
490
+ : ["-e", shellQuote(request.childEntryPath ?? DEFAULT_CHILD_ENTRY_PATH)]),
491
+ "--model",
492
+ shellQuote(request.runtimePlan.model),
493
+ "--thinking",
494
+ shellQuote(request.runtimePlan.thinking),
495
+ ...modelScopeArgs(request.modelScope),
496
+ ];
497
+ if (artifacts.systemPromptFile) {
498
+ parts.push(request.behavior.systemPromptMode === "replace"
499
+ ? "--system-prompt"
500
+ : "--append-system-prompt", shellQuote(artifacts.systemPromptFile));
501
+ }
502
+ const notify = !request.handoff &&
503
+ request.behavior.persistent === true &&
504
+ request.behavior.notify === true;
505
+ const toolAllowlist = buildSubagentToolAllowlist(request.behavior.tools, request.behavior.autoExit, notify);
506
+ if (toolAllowlist)
507
+ parts.push("--tools", shellQuote(toolAllowlist));
508
+ if (!request.handoff)
509
+ parts.push(shellQuote(artifacts.taskArg));
510
+ const env = [
511
+ `${PI_LAUNCH_SESSION_ENV}=${shellQuote(artifacts.sessionFile)}`,
512
+ childDepthAssignment(resolved.request.handoff ? "handoff" : "child"),
513
+ modelScopeAssignment(request.modelScope),
514
+ // Explicit on every path, including a handoff, so an opt-in left in the
515
+ // pane's shell never reaches a session whose role did not declare it.
516
+ `PI_SUBAGENT_SELF_SPAWN=${!request.handoff && request.agent && request.behavior.selfSpawn ? "1" : "0"}`,
517
+ ];
518
+ if (artifacts.localAgentDir) {
519
+ env.push(`PI_CODING_AGENT_DIR=${shellQuote(artifacts.localAgentDir)}`);
520
+ }
521
+ else if (process.env.PI_CODING_AGENT_DIR) {
522
+ env.push(`PI_CODING_AGENT_DIR=${shellQuote(process.env.PI_CODING_AGENT_DIR)}`);
523
+ }
524
+ if (!request.handoff) {
525
+ if (request.behavior.deniedTools.length > 0) {
526
+ env.push(`PI_DENY_TOOLS=${shellQuote(request.behavior.deniedTools.join(","))}`);
527
+ }
528
+ env.push(`PI_SUBAGENT_NAME=${shellQuote(request.name)}`);
529
+ if (request.agent)
530
+ env.push(`PI_SUBAGENT_AGENT=${shellQuote(request.agent)}`);
531
+ env.push(`PI_SUBAGENT_AUTO_EXIT=${request.behavior.autoExit ? "1" : "0"}`);
532
+ if (artifacts.acceptFile)
533
+ env.push(`${ACCEPT_FILE_ENV}=${shellQuote(artifacts.acceptFile)}`);
534
+ // Names only, always set: the child's own Pi decides which skills exist.
535
+ env.push(`${DECLARED_SKILLS_ENV}=${shellQuote(formatDeclaredSkillsEnv(parseDeclaredSkills(request.behavior.skills)))}`);
536
+ if (request.behavior.persistent) {
537
+ env.push("PI_SUBAGENT_PERSISTENT=1");
538
+ env.push(`PI_SUBAGENT_GENERATION_ID=${shellQuote(artifacts.policy.generationId)}`);
539
+ env.push(`PI_SUBAGENT_TASK_ID=${shellQuote(artifacts.initialTaskId)}`);
540
+ // Explicit either way, so an opt-in left in the pane's shell never leaks.
541
+ env.push(`PI_SUBAGENT_NOTIFY=${notify ? "1" : "0"}`);
542
+ }
543
+ env.push(`PI_SUBAGENT_SESSION=${shellQuote(artifacts.sessionFile)}`);
544
+ env.push(`PI_SUBAGENT_ID=${shellQuote(resolved.id)}`);
545
+ env.push(`PI_SUBAGENT_ACTIVITY_FILE=${shellQuote(artifacts.activityFile)}`);
546
+ if (artifacts.surface)
547
+ env.push(`PI_SUBAGENT_SURFACE=${shellQuote(artifacts.surface)}`);
548
+ if (artifacts.processIdentityFile)
549
+ env.push(`PI_SUBAGENT_PROCESS_FILE=${shellQuote(artifacts.processIdentityFile)}`);
550
+ }
551
+ const piCommand = `cd ${shellQuote(artifacts.targetCwd)} && ` +
552
+ `${env.join(" ")} ${parts.join(" ")}`;
553
+ if (request.handoff)
554
+ return piCommand;
555
+ if (!artifacts.surface)
556
+ return `${piCommand}; piha_exit=$?; echo "__SUBAGENT_DONE_\${piha_exit}__"; exit "$piha_exit"`;
557
+ // A persistent stop needs exit evidence that a shell prompt cannot scroll
558
+ // off the screen, as the marker can (#143); the shell writes it after Pi exits.
559
+ if (request.behavior.persistent)
560
+ return `${piCommand}; piha_exit=$?; printf '%s\\n' "$piha_exit" > ${shellQuote(shellExitFileFor(artifacts.sessionFile))} 2>/dev/null; echo "__SUBAGENT_DONE_\${piha_exit}__"`;
561
+ return `${piCommand}; echo '__SUBAGENT_DONE_'$?'__'`;
562
+ }
563
+ async function startPiProcess(resolved, artifacts, command, launchScriptFile, operations) {
564
+ return await operations.runScript(requiredSurface(artifacts), command, {
565
+ scriptPath: launchScriptFile,
566
+ scriptPreamble: [
567
+ shellComment(`Subagent launch script for ${resolved.request.name}`),
568
+ shellComment(`Generated: ${new Date().toISOString()}`),
569
+ shellComment(`Session: ${artifacts.sessionFile}`),
570
+ shellComment(`Surface: ${artifacts.surface}`),
571
+ ].join("\n"),
572
+ });
573
+ }
574
+ function createRunningChild(resolved, artifacts) {
575
+ const child = {
576
+ id: resolved.id,
577
+ name: resolved.request.name,
578
+ task: resolved.request.task,
579
+ agent: resolved.request.agent,
580
+ ownsSurface: !artifacts.worktree && !resolved.request.surface,
581
+ startTime: resolved.startTime,
582
+ sessionFile: artifacts.sessionFile,
583
+ launchScriptFile: join(resolved.artifactDir, "subagent-scripts", `${safeName(resolved.request.name) || "subagent"}-${resolved.id}.sh`),
584
+ activityFile: artifacts.activityFile,
585
+ interactive: resolved.request.behavior.interactive,
586
+ runtimePlan: resolved.request.runtimePlan,
587
+ worktree: artifacts.worktree,
588
+ cwd: artifacts.targetCwd,
589
+ // A handoff loads no child protocol, so it never carries a check.
590
+ accept: resolved.request.handoff ? undefined : resolved.request.accept,
591
+ lifecycle: createLifecycle(resolved.startTime),
592
+ processIdentityFile: artifacts.processIdentityFile,
593
+ };
594
+ const { policy, initialTaskId } = artifacts;
595
+ if (policy.persistent) {
596
+ Object.assign(child, {
597
+ persistent: true,
598
+ logicalId: policy.logicalId,
599
+ generationId: policy.generationId,
600
+ policyHash: policy.policyHash,
601
+ policyTools: policy.tools,
602
+ policyDeniedTools: policy.deniedTools,
603
+ tasksCompleted: 0,
604
+ taskId: initialTaskId,
605
+ issuedTaskIds: [initialTaskId],
606
+ inboxSequence: 0,
607
+ observedTaskEvents: 0,
608
+ });
609
+ if (resolved.request.behavior.notify === true && !resolved.request.handoff)
610
+ child.notify = true;
611
+ appendPersistentDeliveryLedger(child.sessionFile, {
612
+ task: initialTaskId,
613
+ outcome: "dispatched",
614
+ generation: policy.generationId,
615
+ logicalId: policy.logicalId,
616
+ policyHash: policy.policyHash,
617
+ });
618
+ }
619
+ return child;
620
+ }
621
+ // Capture runs beside the launch so readiness never delays the acknowledgement;
622
+ // a cancel awaits it, and without a verified identity nothing is signalled. A
623
+ // cancel after an expired capture starts a fresh one bounded by its own budget.
624
+ export function startProcessIdentityCapture(child, operations, options) {
625
+ const file = child.processIdentityFile;
626
+ if (!file)
627
+ return;
628
+ const capture = operations.captureProcessIdentity;
629
+ if (!capture) {
630
+ child.processIdentityError = "process identity capture is unavailable";
631
+ return;
632
+ }
633
+ child.processIdentityError = undefined;
634
+ child.processIdentityCapture = Promise.resolve()
635
+ .then(() => capture(child.surface, { file, id: child.id, sessionFile: child.sessionFile }, options))
636
+ .then((identity) => (child.processIdentity = identity), (error) => {
637
+ child.processIdentityError = errorMessage(error);
638
+ return undefined;
639
+ });
640
+ }
641
+ function getDefaultSessionDirFor(cwd, agentDir) {
642
+ const safePath = `--${cwd.replace(/^[/\\]/, "").replace(/[/\\:]/g, "-")}--`;
643
+ const sessionDir = join(agentDir, "sessions", safePath);
644
+ mkdirSync(sessionDir, { recursive: true });
645
+ return sessionDir;
646
+ }
647
+ function requireWorktreeOperations(operations) {
648
+ if (!operations.worktree)
649
+ throw new Error("Worktree operations are unavailable");
650
+ return operations.worktree;
651
+ }
652
+ function errorMessage(error) {
653
+ return error instanceof Error ? error.message : String(error);
654
+ }
655
+ //# sourceMappingURL=launch.js.map