@nubl/maestro 0.0.1 → 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 +55 -2
  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,183 @@
1
+ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
2
+ import type { PiRunSession, PiProgressEvidence, SummarySource } from "../../maestro/runtime/index.ts";
3
+ import type { ResolvedRuntimePlan } from "../../maestro/core/routing.ts";
4
+ import type { AcceptOutcome } from "../../maestro/core/accept.ts";
5
+ import type { SubagentStatusState } from "../../maestro/core/status.ts";
6
+ import type { SubagentActivityState } from "../../maestro/core/types.ts";
7
+ import type { LifecycleProjection, SubagentLifecycle } from "../../maestro/core/lifecycle.ts";
8
+ import type { NoticeBudget } from "../../maestro/core/specialist-notice.ts";
9
+ import type { WorktreeHandoff, WorktreeLaunch } from "../../maestro/core/worktree.ts";
10
+ export declare const WIDGET_INTERVAL_KEY: unique symbol;
11
+ export declare const STATUS_INTERVAL_KEY: unique symbol;
12
+ export declare const RUNTIME_KEY: symbol;
13
+ export declare function readGlobalSlot<T>(key: symbol): T | undefined;
14
+ export declare function writeGlobalSlot<T>(key: symbol, value: T): void;
15
+ export type NoProgressClassification = PiProgressEvidence["classification"];
16
+ export type NoProgressSessionTail = Pick<PiProgressEvidence, "classification" | "lastEntryKind">;
17
+ export interface ModelFailure {
18
+ model: string;
19
+ error: string;
20
+ }
21
+ /**
22
+ * Result from running a single subagent.
23
+ */
24
+ export interface SubagentResult {
25
+ name: string;
26
+ task: string;
27
+ summary: string;
28
+ summarySource: SummarySource;
29
+ sessionFile?: string;
30
+ exitCode: number;
31
+ elapsed: number;
32
+ error?: string;
33
+ /** Settled provider/agent error text from the child, preserved verbatim. */
34
+ errorMessage?: string;
35
+ /** Ordered models launched for this run, including failed fallback attempts. */
36
+ fallbackAttempts?: string[];
37
+ /** Ordered raw errors associated with failed model attempts. */
38
+ fallbackFailures?: ModelFailure[];
39
+ ping?: {
40
+ name: string;
41
+ message: string;
42
+ };
43
+ worktree?: WorktreeHandoff;
44
+ runtimePlan?: ResolvedRuntimePlan;
45
+ /** The accept verdict; absent means no check was requested. */
46
+ accept?: AcceptOutcome;
47
+ }
48
+ /**
49
+ * State for a launched (but not yet completed) subagent.
50
+ */
51
+ export interface RunningSubagent {
52
+ id: string;
53
+ name: string;
54
+ task: string;
55
+ agent?: string;
56
+ surface: string;
57
+ startTime: number;
58
+ sessionFile: string;
59
+ launchScriptFile?: string;
60
+ activityFile?: string;
61
+ activity?: SubagentActivityState;
62
+ activityRead?: {
63
+ ok: boolean;
64
+ reason?: "missing" | "invalid" | "wrong-id";
65
+ error?: string;
66
+ };
67
+ abortController?: AbortController;
68
+ /**
69
+ * Optional legacy status snapshot retained only for hydrating pre-lifecycle
70
+ * runtime entries after /reload. Live observation uses `lifecycle` only.
71
+ */
72
+ statusState?: SubagentStatusState;
73
+ lifecycle: SubagentLifecycle;
74
+ /** Last projected kind used to detect stalled/recovered transitions. */
75
+ lastProjectedKind?: LifecycleProjection["kind"];
76
+ /** One active no-progress warning episode, reset when durable progress resumes. */
77
+ noProgressEpisode?: {
78
+ active: true;
79
+ progressAt: number;
80
+ idleMs: number;
81
+ classification: NoProgressClassification;
82
+ lastEntryKind: NoProgressSessionTail["lastEntryKind"];
83
+ };
84
+ /**
85
+ * When true, status transitions (stalled/recovered) do not wake the parent
86
+ * session via a steer message. The widget still updates locally. Used for
87
+ * long-running agents where the user drives the conversation in the
88
+ * subagent's pane.
89
+ */
90
+ interactive: boolean;
91
+ /** Parent-resolved model/thinking selection and provenance. */
92
+ runtimePlan: ResolvedRuntimePlan | undefined;
93
+ worktree?: WorktreeLaunch;
94
+ persistent?: boolean;
95
+ logicalId?: string;
96
+ generationId?: string;
97
+ policyHash?: string;
98
+ policyTools?: string[] | null;
99
+ policyDeniedTools?: string[];
100
+ tasksCompleted?: number;
101
+ taskId?: string;
102
+ /** Task IDs this parent dispatched; the child-writable ledger never decides. */
103
+ issuedTaskIds?: string[];
104
+ /** Events for tasks the parent never issued, ignored after one notice. */
105
+ ignoredTaskEvents?: number;
106
+ /** The parent opted this specialist into notices at launch (ADR-0019). */
107
+ notify?: boolean;
108
+ /** Parent-owned notice accounting; survives reload, not a process crash. */
109
+ noticeBudget?: NoticeBudget;
110
+ inboxSequence?: number;
111
+ observedTaskEvents?: number;
112
+ /** Parent-owned send/ack progress survives reload, not a process crash. */
113
+ persistentTaskDeliveries?: Map<string, "sending" | "sent" | "acknowledged">;
114
+ stopState?: "requested" | "pending" | "failed";
115
+ /** Identity changes before every stop publication, even one that fails. */
116
+ stopAttempt?: {
117
+ cancelNotice?: () => void;
118
+ };
119
+ stopFailure?: string;
120
+ stopTimeout?: ReturnType<typeof setTimeout>;
121
+ stopTimeoutMs?: number;
122
+ crashNotified?: boolean;
123
+ cancelState?: "requested" | "confirmed" | "unconfirmed";
124
+ }
125
+ /**
126
+ * Work held while no live parent API was bound: a settled completion, whose
127
+ * running row stays delivery-pending and RunSession keeps ownership until it is
128
+ * released, a stop-failure notice awaiting a live send, or a fallback attempt
129
+ * waiting to prepare from the live context.
130
+ */
131
+ export interface HeldDelivery {
132
+ /** Running-row id of the held completion or waiting attempt. */
133
+ id: string;
134
+ /** Resume with the replacement's live API, or `undefined` when the parent exits. */
135
+ release(api: ExtensionAPI | undefined): void;
136
+ }
137
+ export interface SubagentRuntime {
138
+ runningSubagents: Map<string, RunningSubagent>;
139
+ /** Persistent launches acquiring resources but not yet represented by a row. */
140
+ persistentReservations?: Set<string>;
141
+ session?: PiRunSession;
142
+ /** The latest loaded extension API; it can be unbound or already invalidated. */
143
+ pi?: ExtensionAPI;
144
+ latestCtx?: ExtensionContext;
145
+ /**
146
+ * The parent API proven live: bound at session_start and by this load's own
147
+ * tool calls, cleared at session_shutdown before Pi invalidates it. Absent
148
+ * across a reload or session-replacement gap, when nothing may be sent.
149
+ */
150
+ liveApi?: ExtensionAPI;
151
+ /** Completions, stop notices and fallback preparations awaiting a live API. Optional for older slots. */
152
+ heldDeliveries?: HeldDelivery[];
153
+ /**
154
+ * Set by a preserving session_shutdown (reload, new, resume, fork) and cleared
155
+ * when the replacement binds its live API or the parent quits. Only in this gap
156
+ * does a missing context mean "wait" rather than "fail".
157
+ */
158
+ reloadGap?: boolean;
159
+ modelCatalog?: string;
160
+ }
161
+ /** Bind the live parent API and release every delivery held for it. */
162
+ export declare function bindLiveApi(runtime: SubagentRuntime, api: ExtensionAPI): void;
163
+ /**
164
+ * The live parent context for preparing a launch. In a reload gap, wait for the
165
+ * replacement session to bind it; `undefined` means none is coming (the parent
166
+ * quit) or, outside a gap, that none exists.
167
+ */
168
+ export declare function awaitLiveContext(runtime: SubagentRuntime, id: string, cancelled?: AbortSignal): Promise<ExtensionContext | undefined>;
169
+ /**
170
+ * Wait for the next live parent API; `undefined` means the parent exited or
171
+ * `cancelled` aborted, which ends the wait at once and leaves the queue.
172
+ */
173
+ export declare function holdDelivery(runtime: SubagentRuntime, id: string, cancelled?: AbortSignal): Promise<ExtensionAPI | undefined>;
174
+ /** Release the current held batch once, in order; failed notices may requeue. */
175
+ export declare function releaseHeldDeliveries(runtime: SubagentRuntime, api: ExtensionAPI | undefined): void;
176
+ /**
177
+ * Any running subagent except a persistent specialist idle between tasks or
178
+ * one whose stop failed, which may never leave the table.
179
+ */
180
+ export declare function hasWorkingSubagents(subagents: Iterable<RunningSubagent>): boolean;
181
+ export declare function shouldDeliverSubagentCompletion(running: Pick<RunningSubagent, "lifecycle">): boolean;
182
+ export declare function selectCompletionApi<T>(previous: T, current: T | undefined): T;
183
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../pi-extension/subagents/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,YAAY,EACZ,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,wBAAgB,YAAY,CAC3B,OAAO,EAAE,eAAe,EACxB,EAAE,EAAE,MAAM,EACV,SAAS,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAmBnC;AAED,iFAAiF;AACjF,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,eAAe,EACxB,GAAG,EAAE,YAAY,GAAG,SAAS,GAC3B,IAAI,CAMN;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAClC,SAAS,EAAE,QAAQ,CAAC,eAAe,CAAC,GAClC,OAAO,CAOT;AAED,wBAAgB,+BAA+B,CAC9C,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC,GACzC,OAAO,CAGT;AAED,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,SAAS,GAAG,CAAC,CAE7E"}
@@ -0,0 +1,92 @@
1
+ import { SUBAGENT_RUNTIME_KEY } from "../../maestro/core/undelivered-children.js";
2
+ // Survive /reload: replace presentation timers while keeping active completion
3
+ // watchers and their registry alive. Old module closures continue watching the
4
+ // children; the reloaded module adopts the shared registry for status/interrupts.
5
+ export const WIDGET_INTERVAL_KEY = Symbol.for("pi-subagents/widget-interval");
6
+ export const STATUS_INTERVAL_KEY = Symbol.for("pi-subagents/status-interval");
7
+ export const RUNTIME_KEY = SUBAGENT_RUNTIME_KEY;
8
+ export function readGlobalSlot(key) {
9
+ // SAFETY: `globalThis` has no index signature for our extension-private
10
+ // symbol keys; only this module ever writes the values read back here.
11
+ return globalThis[key];
12
+ }
13
+ export function writeGlobalSlot(key, value) {
14
+ // SAFETY: see readGlobalSlot above; this module is the sole writer.
15
+ globalThis[key] = value;
16
+ }
17
+ /** Bind the live parent API and release every delivery held for it. */
18
+ export function bindLiveApi(runtime, api) {
19
+ runtime.liveApi = api;
20
+ runtime.reloadGap = false;
21
+ releaseHeldDeliveries(runtime, api);
22
+ }
23
+ /**
24
+ * The live parent context for preparing a launch. In a reload gap, wait for the
25
+ * replacement session to bind it; `undefined` means none is coming (the parent
26
+ * quit) or, outside a gap, that none exists.
27
+ */
28
+ export async function awaitLiveContext(runtime, id, cancelled) {
29
+ if (runtime.latestCtx || !runtime.reloadGap)
30
+ return runtime.latestCtx;
31
+ // session_start and tool calls set latestCtx before bindLiveApi releases.
32
+ return (await holdDelivery(runtime, id, cancelled))
33
+ ? runtime.latestCtx
34
+ : undefined;
35
+ }
36
+ /**
37
+ * Wait for the next live parent API; `undefined` means the parent exited or
38
+ * `cancelled` aborted, which ends the wait at once and leaves the queue.
39
+ */
40
+ export function holdDelivery(runtime, id, cancelled) {
41
+ return new Promise((resolve) => {
42
+ const held = {
43
+ id,
44
+ release(api) {
45
+ cancelled?.removeEventListener("abort", onCancel);
46
+ resolve(api);
47
+ },
48
+ };
49
+ const onCancel = () => {
50
+ const queue = runtime.heldDeliveries;
51
+ const at = queue?.indexOf(held) ?? -1;
52
+ if (at >= 0)
53
+ queue?.splice(at, 1);
54
+ held.release(undefined);
55
+ };
56
+ if (cancelled?.aborted)
57
+ return resolve(undefined);
58
+ cancelled?.addEventListener("abort", onCancel, { once: true });
59
+ (runtime.heldDeliveries ??= []).push(held);
60
+ });
61
+ }
62
+ /** Release the current held batch once, in order; failed notices may requeue. */
63
+ export function releaseHeldDeliveries(runtime, api) {
64
+ // Include notices collecting asynchronous evidence, not just queued retries.
65
+ if (!api)
66
+ for (const running of runtime.runningSubagents.values())
67
+ running.stopAttempt?.cancelNotice?.();
68
+ for (const held of runtime.heldDeliveries?.splice(0) ?? [])
69
+ held.release(api);
70
+ }
71
+ /**
72
+ * Any running subagent except a persistent specialist idle between tasks or
73
+ * one whose stop failed, which may never leave the table.
74
+ */
75
+ export function hasWorkingSubagents(subagents) {
76
+ for (const running of subagents) {
77
+ if (running.stopState === "failed")
78
+ continue;
79
+ if (running.persistent && !running.taskId && !running.stopState)
80
+ continue;
81
+ return true;
82
+ }
83
+ return false;
84
+ }
85
+ export function shouldDeliverSubagentCompletion(running) {
86
+ // Authoritative gate: only pending deliveries may be sent.
87
+ return running.lifecycle.delivery === "pending";
88
+ }
89
+ export function selectCompletionApi(previous, current) {
90
+ return current ?? previous;
91
+ }
92
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.js","sourceRoot":"","sources":["../../../pi-extension/subagents/state.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAOlF,+EAA+E;AAC/E,+EAA+E;AAC/E,kFAAkF;AAClF,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;AAC9E,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;AAC9E,MAAM,CAAC,MAAM,WAAW,GAAG,oBAAoB,CAAC;AAEhD,MAAM,UAAU,cAAc,CAAI,GAAW;IAC5C,wEAAwE;IACxE,uEAAuE;IACvE,OAAQ,UAA4C,CAAC,GAAG,CAAC,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,eAAe,CAAI,GAAW,EAAE,KAAQ;IACvD,oEAAoE;IACnE,UAA4C,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAC5D,CAAC;AAwJD,uEAAuE;AACvE,MAAM,UAAU,WAAW,CAAC,OAAwB,EAAE,GAAiB;IACtE,OAAO,CAAC,OAAO,GAAG,GAAG,CAAC;IACtB,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;IAC1B,qBAAqB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACrC,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACrC,OAAwB,EACxB,EAAU,EACV,SAAuB;IAEvB,IAAI,OAAO,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,SAAS;QAAE,OAAO,OAAO,CAAC,SAAS,CA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,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC,MAAM,EAAE;YACtD,OAAO,CAAC,WAAW,EAAE,YAAY,EAAE,EAAE,CAAC;IACxC,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE;QAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAC/E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAClC,SAAoC;IAEpC,KAAK,MAAM,OAAO,IAAI,SAAS,EAAE,CAAC;QACjC,IAAI,OAAO,CAAC,SAAS,KAAK,QAAQ;YAAE,SAAS;QAC7C,IAAI,OAAO,CAAC,UAAU,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS;YAAE,SAAS;QAC1E,OAAO,IAAI,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,UAAU,+BAA+B,CAC9C,OAA2C;IAE3C,2DAA2D;IAC3D,OAAO,OAAO,CAAC,SAAS,CAAC,QAAQ,KAAK,SAAS,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAI,QAAW,EAAE,OAAsB;IACzE,OAAO,OAAO,IAAI,QAAQ,CAAC;AAC5B,CAAC","sourcesContent":["import type {\n\tExtensionAPI,\n\tExtensionContext,\n} from \"@earendil-works/pi-coding-agent\";\nimport type {\n\tPiRunSession,\n\tPiProgressEvidence,\n\tSummarySource,\n} from \"../../maestro/runtime/index.ts\";\nimport type { ResolvedRuntimePlan } from \"../../maestro/core/routing.ts\";\nimport type { AcceptOutcome } from \"../../maestro/core/accept.ts\";\nimport type { SubagentStatusState } from \"../../maestro/core/status.ts\";\nimport type { SubagentActivityState } from \"../../maestro/core/types.ts\";\nimport type {\n\tLifecycleProjection,\n\tSubagentLifecycle,\n} from \"../../maestro/core/lifecycle.ts\";\nimport { SUBAGENT_RUNTIME_KEY } from \"../../maestro/core/undelivered-children.ts\";\nimport type { NoticeBudget } from \"../../maestro/core/specialist-notice.ts\";\nimport type {\n\tWorktreeHandoff,\n\tWorktreeLaunch,\n} from \"../../maestro/core/worktree.ts\";\n\n// Survive /reload: replace presentation timers while keeping active completion\n// watchers and their registry alive. Old module closures continue watching the\n// children; the reloaded module adopts the shared registry for status/interrupts.\nexport const WIDGET_INTERVAL_KEY = Symbol.for(\"pi-subagents/widget-interval\");\nexport const STATUS_INTERVAL_KEY = Symbol.for(\"pi-subagents/status-interval\");\nexport const RUNTIME_KEY = SUBAGENT_RUNTIME_KEY;\n\nexport function readGlobalSlot<T>(key: symbol): T | undefined {\n\t// SAFETY: `globalThis` has no index signature for our extension-private\n\t// symbol keys; only this module ever writes the values read back here.\n\treturn (globalThis as Record<symbol, T | undefined>)[key];\n}\n\nexport function writeGlobalSlot<T>(key: symbol, value: T): void {\n\t// SAFETY: see readGlobalSlot above; this module is the sole writer.\n\t(globalThis as Record<symbol, T | undefined>)[key] = value;\n}\n\nexport type NoProgressClassification = PiProgressEvidence[\"classification\"];\nexport type NoProgressSessionTail = Pick<\n\tPiProgressEvidence,\n\t\"classification\" | \"lastEntryKind\"\n>;\n\nexport interface ModelFailure {\n\tmodel: string;\n\terror: string;\n}\n\n/**\n * Result from running a single subagent.\n */\nexport interface SubagentResult {\n\tname: string;\n\ttask: string;\n\tsummary: string;\n\tsummarySource: SummarySource;\n\tsessionFile?: string;\n\texitCode: number;\n\telapsed: number;\n\terror?: string;\n\t/** Settled provider/agent error text from the child, preserved verbatim. */\n\terrorMessage?: string;\n\t/** Ordered models launched for this run, including failed fallback attempts. */\n\tfallbackAttempts?: string[];\n\t/** Ordered raw errors associated with failed model attempts. */\n\tfallbackFailures?: ModelFailure[];\n\tping?: { name: string; message: string };\n\tworktree?: WorktreeHandoff;\n\truntimePlan?: ResolvedRuntimePlan;\n\t/** The accept verdict; absent means no check was requested. */\n\taccept?: AcceptOutcome;\n}\n\n/**\n * State for a launched (but not yet completed) subagent.\n */\nexport interface RunningSubagent {\n\tid: string;\n\tname: string;\n\ttask: string;\n\tagent?: string;\n\tsurface: string;\n\tstartTime: number;\n\tsessionFile: string;\n\tlaunchScriptFile?: string;\n\tactivityFile?: string;\n\tactivity?: SubagentActivityState;\n\tactivityRead?: {\n\t\tok: boolean;\n\t\treason?: \"missing\" | \"invalid\" | \"wrong-id\";\n\t\terror?: string;\n\t};\n\tabortController?: AbortController;\n\t/**\n\t * Optional legacy status snapshot retained only for hydrating pre-lifecycle\n\t * runtime entries after /reload. Live observation uses `lifecycle` only.\n\t */\n\tstatusState?: SubagentStatusState;\n\tlifecycle: SubagentLifecycle;\n\t/** Last projected kind used to detect stalled/recovered transitions. */\n\tlastProjectedKind?: LifecycleProjection[\"kind\"];\n\t/** One active no-progress warning episode, reset when durable progress resumes. */\n\tnoProgressEpisode?: {\n\t\tactive: true;\n\t\tprogressAt: number;\n\t\tidleMs: number;\n\t\tclassification: NoProgressClassification;\n\t\tlastEntryKind: NoProgressSessionTail[\"lastEntryKind\"];\n\t};\n\t/**\n\t * When true, status transitions (stalled/recovered) do not wake the parent\n\t * session via a steer message. The widget still updates locally. Used for\n\t * long-running agents where the user drives the conversation in the\n\t * subagent's pane.\n\t */\n\tinteractive: boolean;\n\t/** Parent-resolved model/thinking selection and provenance. */\n\truntimePlan: ResolvedRuntimePlan | undefined;\n\tworktree?: WorktreeLaunch;\n\tpersistent?: boolean;\n\tlogicalId?: string;\n\tgenerationId?: string;\n\tpolicyHash?: string;\n\tpolicyTools?: string[] | null;\n\tpolicyDeniedTools?: string[];\n\ttasksCompleted?: number;\n\ttaskId?: string;\n\t/** Task IDs this parent dispatched; the child-writable ledger never decides. */\n\tissuedTaskIds?: string[];\n\t/** Events for tasks the parent never issued, ignored after one notice. */\n\tignoredTaskEvents?: number;\n\t/** The parent opted this specialist into notices at launch (ADR-0019). */\n\tnotify?: boolean;\n\t/** Parent-owned notice accounting; survives reload, not a process crash. */\n\tnoticeBudget?: NoticeBudget;\n\tinboxSequence?: number;\n\tobservedTaskEvents?: number;\n\t/** Parent-owned send/ack progress survives reload, not a process crash. */\n\tpersistentTaskDeliveries?: Map<string, \"sending\" | \"sent\" | \"acknowledged\">;\n\tstopState?: \"requested\" | \"pending\" | \"failed\";\n\t/** Identity changes before every stop publication, even one that fails. */\n\tstopAttempt?: { cancelNotice?: () => void };\n\tstopFailure?: string;\n\tstopTimeout?: ReturnType<typeof setTimeout>;\n\tstopTimeoutMs?: number;\n\tcrashNotified?: boolean;\n\tcancelState?: \"requested\" | \"confirmed\" | \"unconfirmed\";\n}\n\n/**\n * Work held while no live parent API was bound: a settled completion, whose\n * running row stays delivery-pending and RunSession keeps ownership until it is\n * released, a stop-failure notice awaiting a live send, or a fallback attempt\n * waiting to prepare from the live context.\n */\nexport interface HeldDelivery {\n\t/** Running-row id of the held completion or waiting attempt. */\n\tid: string;\n\t/** Resume with the replacement's live API, or `undefined` when the parent exits. */\n\trelease(api: ExtensionAPI | undefined): void;\n}\n\nexport interface SubagentRuntime {\n\trunningSubagents: Map<string, RunningSubagent>;\n\t/** Persistent launches acquiring resources but not yet represented by a row. */\n\tpersistentReservations?: Set<string>;\n\tsession?: PiRunSession;\n\t/** The latest loaded extension API; it can be unbound or already invalidated. */\n\tpi?: ExtensionAPI;\n\tlatestCtx?: ExtensionContext;\n\t/**\n\t * The parent API proven live: bound at session_start and by this load's own\n\t * tool calls, cleared at session_shutdown before Pi invalidates it. Absent\n\t * across a reload or session-replacement gap, when nothing may be sent.\n\t */\n\tliveApi?: ExtensionAPI;\n\t/** Completions, stop notices and fallback preparations awaiting a live API. Optional for older slots. */\n\theldDeliveries?: HeldDelivery[];\n\t/**\n\t * Set by a preserving session_shutdown (reload, new, resume, fork) and cleared\n\t * when the replacement binds its live API or the parent quits. Only in this gap\n\t * does a missing context mean \"wait\" rather than \"fail\".\n\t */\n\treloadGap?: boolean;\n\tmodelCatalog?: string;\n}\n\n/** Bind the live parent API and release every delivery held for it. */\nexport function bindLiveApi(runtime: SubagentRuntime, api: ExtensionAPI): void {\n\truntime.liveApi = api;\n\truntime.reloadGap = false;\n\treleaseHeldDeliveries(runtime, api);\n}\n\n/**\n * The live parent context for preparing a launch. In a reload gap, wait for the\n * replacement session to bind it; `undefined` means none is coming (the parent\n * quit) or, outside a gap, that none exists.\n */\nexport async function awaitLiveContext(\n\truntime: SubagentRuntime,\n\tid: string,\n\tcancelled?: AbortSignal,\n): Promise<ExtensionContext | undefined> {\n\tif (runtime.latestCtx || !runtime.reloadGap) return runtime.latestCtx;\n\t// session_start and tool calls set latestCtx before bindLiveApi releases.\n\treturn (await holdDelivery(runtime, id, cancelled))\n\t\t? runtime.latestCtx\n\t\t: undefined;\n}\n\n/**\n * Wait for the next live parent API; `undefined` means the parent exited or\n * `cancelled` aborted, which ends the wait at once and leaves the queue.\n */\nexport function holdDelivery(\n\truntime: SubagentRuntime,\n\tid: string,\n\tcancelled?: AbortSignal,\n): Promise<ExtensionAPI | undefined> {\n\treturn new Promise((resolve) => {\n\t\tconst held: HeldDelivery = {\n\t\t\tid,\n\t\t\trelease(api) {\n\t\t\t\tcancelled?.removeEventListener(\"abort\", onCancel);\n\t\t\t\tresolve(api);\n\t\t\t},\n\t\t};\n\t\tconst onCancel = () => {\n\t\t\tconst queue = runtime.heldDeliveries;\n\t\t\tconst at = queue?.indexOf(held) ?? -1;\n\t\t\tif (at >= 0) queue?.splice(at, 1);\n\t\t\theld.release(undefined);\n\t\t};\n\t\tif (cancelled?.aborted) return resolve(undefined);\n\t\tcancelled?.addEventListener(\"abort\", onCancel, { once: true });\n\t\t(runtime.heldDeliveries ??= []).push(held);\n\t});\n}\n\n/** Release the current held batch once, in order; failed notices may requeue. */\nexport function releaseHeldDeliveries(\n\truntime: SubagentRuntime,\n\tapi: ExtensionAPI | undefined,\n): void {\n\t// Include notices collecting asynchronous evidence, not just queued retries.\n\tif (!api)\n\t\tfor (const running of runtime.runningSubagents.values())\n\t\t\trunning.stopAttempt?.cancelNotice?.();\n\tfor (const held of runtime.heldDeliveries?.splice(0) ?? []) held.release(api);\n}\n\n/**\n * Any running subagent except a persistent specialist idle between tasks or\n * one whose stop failed, which may never leave the table.\n */\nexport function hasWorkingSubagents(\n\tsubagents: Iterable<RunningSubagent>,\n): boolean {\n\tfor (const running of subagents) {\n\t\tif (running.stopState === \"failed\") continue;\n\t\tif (running.persistent && !running.taskId && !running.stopState) continue;\n\t\treturn true;\n\t}\n\treturn false;\n}\n\nexport function shouldDeliverSubagentCompletion(\n\trunning: Pick<RunningSubagent, \"lifecycle\">,\n): boolean {\n\t// Authoritative gate: only pending deliveries may be sent.\n\treturn running.lifecycle.delivery === \"pending\";\n}\n\nexport function selectCompletionApi<T>(previous: T, current: T | undefined): T {\n\treturn current ?? previous;\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ /** The subagents_write_task_models tool (parent sessions only). */
3
+ export declare function registerTaskModelTool(pi: ExtensionAPI, { shouldRegister, configExamplePath, }: {
4
+ shouldRegister: (name: string) => boolean;
5
+ configExamplePath?: string;
6
+ }): void;
7
+ /** The /subagents-init command and its cross-extension start event. */
8
+ export declare function registerTaskModelInit(pi: ExtensionAPI): void;
9
+ //# sourceMappingURL=task-models.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-models.d.ts","sourceRoot":"","sources":["../../../pi-extension/subagents/task-models.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACX,YAAY,EAEZ,MAAM,iCAAiC,CAAC;AAkJzC,mEAAmE;AACnE,wBAAgB,qBAAqB,CACpC,EAAE,EAAE,YAAY,EAChB,EACC,cAAc,EACd,iBAAiB,GACjB,EAAE;IAAE,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IAAC,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1E,IAAI,CAqON;AAED,uEAAuE;AACvE,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAoF5D"}
@@ -0,0 +1,293 @@
1
+ import { encodeHostValue, HOST_ERROR_CHARS, } from "../../maestro/core/host-text.js";
2
+ import { Type } from "@sinclair/typebox";
3
+ import { startTaskModelInit, } from "../../maestro/runtime/index.js";
4
+ import { THINKING_LEVELS, parseExactModelRef, } from "../../maestro/core/routing.js";
5
+ import { wrapPiModelRegistry } from "./model-registry.js";
6
+ import { MISSING_CONFIG_REVISION, prepareTaskModelWrite, describeTaskModelWriteFailure, validateTaskModelProposal, parseRankingBasis, readModelConfigSnapshot, writeTaskModelConfig, } from "../../maestro/core/config/model-config.js";
7
+ import { DIRECT_WRITER_TOOL, TASK_MODEL_INIT_APPROVAL_EVENT, TASK_MODEL_INIT_START_EVENT, } from "../../maestro/core/config/task-model-init.js";
8
+ import { TASK_CATEGORIES, TASK_CATEGORY_DESCRIPTIONS, } from "../../maestro/core/config/task-model-types.js";
9
+ import { getSubagentsConfigDir, getSubagentsConfigExamplePath, getSubagentsConfigPath, } from "./config-path.js";
10
+ import { readGlobalSlot, writeGlobalSlot } from "./state.js";
11
+ import { isFunction, isString } from "../../maestro/core/config/type-guards.js";
12
+ function hasMethods(value, names) {
13
+ return value != null && names.every((name) => isFunction(value[name]));
14
+ }
15
+ /**
16
+ * Read a TASK_MODEL_INIT_START_EVENT v1 payload. A v1 request whose context or
17
+ * preferences cannot run init still gets an offer, so its emitter reports why
18
+ * instead of concluding that no host is loaded.
19
+ */
20
+ function parseInitStartRequest(raw) {
21
+ if (raw?.apiVersion !== 1 || !isFunction(raw.offer))
22
+ return undefined;
23
+ const { offer, context, preferences } = raw;
24
+ const usable = isString(preferences) &&
25
+ hasMethods(context, ["isIdle", "hasPendingMessages"]) &&
26
+ hasMethods(context.modelRegistry, ["getAvailable"]);
27
+ return {
28
+ offer: (value) => offer.call(raw, value),
29
+ // The members init reads were checked above; the rest is the emitting
30
+ // command's own live context.
31
+ input: usable ? { context, preferences } : undefined,
32
+ };
33
+ }
34
+ // Keep this init-only schema out of normal requests. A successful write
35
+ // always deactivates it, including after reload or explicit user activation.
36
+ function releaseWriterAfterInit(pi) {
37
+ pi.setActiveTools(pi.getActiveTools().filter((name) => name !== DIRECT_WRITER_TOOL));
38
+ }
39
+ function approvalJson(value) {
40
+ return JSON.stringify(value ?? null).replace(/[|\p{Cc}\p{Cf}\p{Default_Ignorable_Code_Point}\u2028\u2029]/gu, (char) => char
41
+ .split("")
42
+ .map((unit) => `\\u${unit.charCodeAt(0).toString(16).padStart(4, "0")}`)
43
+ .join(""));
44
+ }
45
+ const TASK_MODEL_APPROVAL_SLOT = Symbol.for("pi-herdr-agents/task-model-approval-open");
46
+ const DECLINE_TASK_MODELS = "No, keep current";
47
+ const SAVE_TASK_MODELS = "Yes, save";
48
+ function taskModelApprovalMessage(prepared) {
49
+ const { before, after } = prepared;
50
+ const changes = [];
51
+ for (const category of TASK_CATEGORIES) {
52
+ const previous = `${approvalJson(before.tasks?.[category])} / ${approvalJson(before.tasksThinking?.[category])}`;
53
+ const next = `${approvalJson(after.tasks?.[category])} / ${approvalJson(after.tasksThinking?.[category])}`;
54
+ if (previous !== next)
55
+ changes.push(`${category}: ${previous} -> ${next}`);
56
+ }
57
+ const lines = [`Save to ${approvalJson(prepared.configPath)}`];
58
+ if (prepared.realConfigPath !== prepared.configPath)
59
+ lines.push(`Real path: ${approvalJson(prepared.realConfigPath)}`);
60
+ if (prepared.newFile)
61
+ lines.push(`Create new file; top-level keys: ${prepared.topLevelKeys.join(", ")}. Other settings: {"status":{"enabled":true}}.`);
62
+ lines.push("Models / thinking (null = unset):", ...changes, `${TASK_CATEGORIES.length - changes.length} categories unchanged.`);
63
+ if (JSON.stringify(before.tasksMeta) !== JSON.stringify(after.tasksMeta))
64
+ lines.push(`Metadata: ${approvalJson(before.tasksMeta)} -> ${approvalJson(after.tasksMeta)}`);
65
+ return lines.join("\n");
66
+ }
67
+ /** The subagents_write_task_models tool (parent sessions only). */
68
+ export function registerTaskModelTool(pi, { shouldRegister, configExamplePath, }) {
69
+ if (!process.env.PI_SUBAGENT_ID && shouldRegister(DIRECT_WRITER_TOOL)) {
70
+ let pendingApproval;
71
+ pi.on("session_shutdown", async () => {
72
+ const pending = pendingApproval;
73
+ if (!pending)
74
+ return;
75
+ pending.controller.abort();
76
+ await pending.finished;
77
+ });
78
+ pi.registerTool({
79
+ name: DIRECT_WRITER_TOOL,
80
+ label: "Write task model preferences",
81
+ defaultActive: false,
82
+ description: `Validate task preferences, show exact before/after for user approval, then atomically replace models.tasks, models.tasksThinking and models.tasksMeta in the durable Pi agent config, preserving unrelated settings. Every call shows exact before/after for changed categories and requires user approval through a refusal-first selector (60-second timeout), even when another extension already approved it. No-UI, print/JSON and child sessions are refused without writing. Supported categories: ${TASK_CATEGORIES.join(", ")}. Partial nonempty categories are accepted; omitted categories are removed. Rejects duplicate exact refs within a category. Review the active authenticated registry and existing preferences first. Optional expectedConfigRevision also binds the proposal's starting revision: it fails without replacing configuration when the config file no longer matches the revision the proposal was read from. Optional basis records what the ranking rests on; its kind must equal tasksMeta.method, and it is returned but not saved. Concurrent approvals refuse immediately rather than stack. The full replacement bytes and real directory are prepared before approval and rechecked before rename. New files disclose their minimal status/models seed. Cooperating writes use an advisory lock, not a filesystem authorization boundary. Returns normalized saved preferences, missing categories, the configRevision of the written file, and any basis; reload required.`,
83
+ parameters: Type.Object({
84
+ tasks: Type.Object(Object.fromEntries(TASK_CATEGORIES.map((category) => [
85
+ category,
86
+ Type.Optional(Type.Array(Type.String({ minLength: 1 }), {
87
+ minItems: 1,
88
+ description: TASK_CATEGORY_DESCRIPTIONS[category],
89
+ })),
90
+ ])), { additionalProperties: false, minProperties: 1 }),
91
+ tasksThinking: Type.Optional(Type.Union([
92
+ Type.Object(Object.fromEntries(TASK_CATEGORIES.map((category) => [
93
+ category,
94
+ Type.Optional(Type.Union(THINKING_LEVELS.map((level) => Type.Literal(level)))),
95
+ ])), {
96
+ additionalProperties: false,
97
+ description: "Category thinking, clamped per fallback candidate. Replaces the map when supplied ({} clears and removes it); omitted or null preserves thinking for retained categories. Entries require a submitted task category.",
98
+ }),
99
+ Type.Null(),
100
+ ])),
101
+ tasksMeta: Type.Object({
102
+ generatedAt: Type.String(),
103
+ method: Type.Union([
104
+ Type.Literal("research"),
105
+ Type.Literal("registry-only"),
106
+ ]),
107
+ }),
108
+ expectedConfigRevision: Type.Optional(Type.Union([
109
+ Type.Literal(MISSING_CONFIG_REVISION),
110
+ Type.String({ pattern: "^sha256:[0-9a-f]{64}$" }),
111
+ ], {
112
+ description: `Revision of the config the proposal was read from: "sha256:" plus 64 lowercase hex digits of the exact file bytes, or "${MISSING_CONFIG_REVISION}" when the file is absent. A mismatch fails without writing; re-read, re-propose, and re-approve. Omit to propose against the current config; user approval still binds the exact snapshot shown.`,
113
+ })),
114
+ basis: Type.Optional(Type.Union([
115
+ Type.Object({ kind: Type.Literal("registry-only") }, { additionalProperties: false }),
116
+ Type.Object({
117
+ kind: Type.Literal("research"),
118
+ sources: Type.Array(Type.Object({
119
+ url: Type.String({ minLength: 1 }),
120
+ influence: Type.String({ minLength: 1 }),
121
+ }, { additionalProperties: false }), { minItems: 1 }),
122
+ uncertainty: Type.String({ minLength: 1 }),
123
+ }, { additionalProperties: false }),
124
+ ], {
125
+ description: 'What the ranking rests on, as submitted by the proposer and not independently verified: {"kind":"registry-only"}, or {"kind":"research"} with the http(s) sources consulted in this run, how each informed the ranking, and the remaining uncertainty. kind must equal tasksMeta.method. Not saved. Omit for a legacy write.',
126
+ })),
127
+ }),
128
+ execute: async (_id, params, signal, _update, ctx) => {
129
+ if (process.env.PI_SUBAGENT_ID)
130
+ throw new Error("Task model preferences not written: child sessions cannot approve task-model writes. Use a parent session with a user-facing UI.");
131
+ if (!ctx.hasUI || ctx.mode === "print" || ctx.mode === "json")
132
+ throw new Error("Task model preferences not written: user approval requires a dialog-capable UI; no-UI, print and JSON sessions cannot write.");
133
+ if (signal?.aborted)
134
+ throw new Error("Task model preferences not written: approval cancelled.");
135
+ if (readGlobalSlot(TASK_MODEL_APPROVAL_SLOT))
136
+ throw new Error("Task model preferences not written: another approval is already open. Retry after it finishes.");
137
+ writeGlobalSlot(TASK_MODEL_APPROVAL_SLOT, true);
138
+ const controller = new AbortController();
139
+ const approvalSignal = signal
140
+ ? AbortSignal.any([signal, controller.signal])
141
+ : controller.signal;
142
+ let finishApproval = () => { };
143
+ const finished = new Promise((resolve) => {
144
+ finishApproval = resolve;
145
+ });
146
+ pendingApproval = { controller, finished };
147
+ let onAbort = () => { };
148
+ const aborted = new Promise((resolve) => {
149
+ onAbort = () => resolve(undefined);
150
+ });
151
+ approvalSignal.addEventListener("abort", onAbort, { once: true });
152
+ try {
153
+ const registry = wrapPiModelRegistry(ctx.modelRegistry);
154
+ // SAFETY: TypeBox validates the tool payload; the write seam performs stricter schema validation.
155
+ const tasks = params.tasks;
156
+ // SAFETY: TypeBox validates the tool payload; the write seam performs stricter schema validation.
157
+ const tasksMeta = params.tasksMeta;
158
+ // Present-but-invalid values (including null) fail before anything is written.
159
+ const basis = Object.hasOwn(params, "basis")
160
+ ? parseRankingBasis(params.basis, tasksMeta.method)
161
+ : undefined;
162
+ const options = {
163
+ // SAFETY: the write seam validates the map's category keys and levels.
164
+ tasksThinking: params.tasksThinking,
165
+ };
166
+ if (Object.hasOwn(params, "expectedConfigRevision"))
167
+ options.expectedConfigRevision = params.expectedConfigRevision;
168
+ const configPath = getSubagentsConfigPath();
169
+ const examplePath = configExamplePath ?? getSubagentsConfigExamplePath();
170
+ const isAuthenticatedCandidate = (candidate) => {
171
+ const parsed = parseExactModelRef(candidate);
172
+ const model = parsed && registry.find(parsed.provider, parsed.modelId);
173
+ return !!model && registry.hasConfiguredAuth(model);
174
+ };
175
+ const proposal = validateTaskModelProposal(configPath, tasks, tasksMeta, isAuthenticatedCandidate, options);
176
+ const prepared = prepareTaskModelWrite(configPath, proposal, options.expectedConfigRevision);
177
+ const message = taskModelApprovalMessage(prepared);
178
+ // Hiding a Pi selector may leave its promise pending, even after abort.
179
+ // Our own abort race must settle before shutdown invalidates this API.
180
+ const approved = await Promise.race([
181
+ ctx.ui.select(`Approve task model preferences\n${message}${basis ? `\nRanking basis: ${basis.kind} (submitted, unverified; not saved).` : ""}`, [DECLINE_TASK_MODELS, SAVE_TASK_MODELS], { timeout: 60_000, signal: approvalSignal }),
182
+ aborted,
183
+ ]);
184
+ if (approved !== SAVE_TASK_MODELS || approvalSignal.aborted)
185
+ throw new Error("Task model preferences not written: approval declined, cancelled or timed out. Obtain fresh approval before retrying.");
186
+ let saved;
187
+ try {
188
+ saved = writeTaskModelConfig(configPath, examplePath, prepared.after.tasks ?? {}, prepared.after.tasksMeta ?? tasksMeta, isAuthenticatedCandidate, {
189
+ tasksThinking: prepared.after.tasksThinking ?? {},
190
+ expectedConfigRevision: prepared.configRevision,
191
+ approvedWrite: prepared,
192
+ });
193
+ }
194
+ catch (error) {
195
+ throw new Error(`${error instanceof Error ? error.message : String(error)} ${describeTaskModelWriteFailure(prepared)}`, { cause: error });
196
+ }
197
+ releaseWriterAfterInit(pi);
198
+ const details = basis ? { ...saved, basis } : saved;
199
+ return {
200
+ content: [
201
+ {
202
+ type: "text",
203
+ text: `Wrote task model preferences. Reload required.\n${JSON.stringify(details, null, 2)}`,
204
+ },
205
+ ],
206
+ details,
207
+ };
208
+ }
209
+ finally {
210
+ approvalSignal.removeEventListener("abort", onAbort);
211
+ pendingApproval = undefined;
212
+ writeGlobalSlot(TASK_MODEL_APPROVAL_SLOT, false);
213
+ finishApproval();
214
+ }
215
+ },
216
+ });
217
+ }
218
+ }
219
+ /** The /subagents-init command and its cross-extension start event. */
220
+ export function registerTaskModelInit(pi) {
221
+ if (!process.env.PI_SUBAGENT_ID) {
222
+ const runTaskModelInit = (ctx, preferences) => {
223
+ if (!ctx.hasUI || ctx.mode === "print" || ctx.mode === "json")
224
+ return {
225
+ kind: "not-started",
226
+ reason: "task-model init requires a dialog-capable UI for approval",
227
+ };
228
+ if (!ctx.isIdle() || ctx.hasPendingMessages())
229
+ return {
230
+ kind: "not-started",
231
+ reason: "a turn is in progress or messages are queued. Nothing was queued; retry when idle",
232
+ };
233
+ // Pi refuses a prompt without a model only after submission; refuse first.
234
+ if (!ctx.model)
235
+ return {
236
+ kind: "not-started",
237
+ reason: "no model is selected, so Pi cannot run the init prompt. Select a model, then retry",
238
+ };
239
+ let activatedWriter = false;
240
+ const outcome = startTaskModelInit({
241
+ preferences,
242
+ readConfig: () => readModelConfigSnapshot(getSubagentsConfigDir()),
243
+ projectActiveRegistry: (project) => project(ctx.modelRegistry),
244
+ emitApprovalRequest: (brief, offer) => pi.events.emit(TASK_MODEL_INIT_APPROVAL_EVENT, Object.freeze({
245
+ apiVersion: 1,
246
+ brief,
247
+ context: ctx,
248
+ offer,
249
+ })),
250
+ activateTool: (name) => {
251
+ if (name !== DIRECT_WRITER_TOOL)
252
+ return;
253
+ const active = pi.getActiveTools();
254
+ if (active.includes(name))
255
+ return;
256
+ pi.setActiveTools([...active, name]);
257
+ activatedWriter = pi.getActiveTools().includes(name);
258
+ },
259
+ isToolActive: (name) => pi.getActiveTools().includes(name),
260
+ submit: (prompt) => pi.sendUserMessage(prompt),
261
+ });
262
+ if (outcome.kind === "not-started" && activatedWriter)
263
+ releaseWriterAfterInit(pi);
264
+ return outcome;
265
+ };
266
+ pi.registerCommand("subagents-init", {
267
+ description: "Draft task-category model preferences from the live registry; optional arguments set ranking preferences",
268
+ handler: async (args, ctx) => {
269
+ const outcome = runTaskModelInit(ctx, args);
270
+ if (outcome.kind === "not-started")
271
+ ctx.ui.notify(`Task-model init not started: ${encodeHostValue(outcome.reason, HOST_ERROR_CHARS)}. Nothing was written.`, "warning");
272
+ },
273
+ });
274
+ // Another extension's command may start the same init; it renders the outcome.
275
+ const stopInitStart = pi.events.on(TASK_MODEL_INIT_START_EVENT, (raw) => {
276
+ const request = parseInitStartRequest(raw);
277
+ if (!request)
278
+ return;
279
+ const { input } = request;
280
+ request.offer({
281
+ owner: "pi-herdr-agents",
282
+ start: () => input
283
+ ? runTaskModelInit(input.context, input.preferences)
284
+ : {
285
+ kind: "not-started",
286
+ reason: "the start request lacks a usable command context or preferences text",
287
+ },
288
+ });
289
+ });
290
+ pi.on("session_shutdown", () => stopInitStart());
291
+ }
292
+ }
293
+ //# sourceMappingURL=task-models.js.map