@pennixrv/trellis 0.7.2-beta.2 → 0.7.2-beta.21

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 (438) hide show
  1. package/README.md +14 -0
  2. package/dist/commands/init.d.ts.map +1 -1
  3. package/dist/commands/init.js +105 -107
  4. package/dist/commands/init.js.map +1 -1
  5. package/dist/commands/teamwork/adapters/acp.d.ts.map +1 -1
  6. package/dist/commands/teamwork/adapters/acp.js +3 -0
  7. package/dist/commands/teamwork/adapters/acp.js.map +1 -1
  8. package/dist/commands/teamwork/adapters/index.d.ts +1 -1
  9. package/dist/commands/teamwork/adapters/index.d.ts.map +1 -1
  10. package/dist/commands/teamwork/artifact.d.ts +2 -0
  11. package/dist/commands/teamwork/artifact.d.ts.map +1 -1
  12. package/dist/commands/teamwork/artifact.js +4 -2
  13. package/dist/commands/teamwork/artifact.js.map +1 -1
  14. package/dist/commands/teamwork/batch-reservation.d.ts.map +1 -1
  15. package/dist/commands/teamwork/batch-reservation.js +16 -8
  16. package/dist/commands/teamwork/batch-reservation.js.map +1 -1
  17. package/dist/commands/teamwork/batch.d.ts +15 -1
  18. package/dist/commands/teamwork/batch.d.ts.map +1 -1
  19. package/dist/commands/teamwork/batch.js +279 -24
  20. package/dist/commands/teamwork/batch.js.map +1 -1
  21. package/dist/commands/teamwork/coordinator.d.ts +3 -0
  22. package/dist/commands/teamwork/coordinator.d.ts.map +1 -1
  23. package/dist/commands/teamwork/coordinator.js +22 -3
  24. package/dist/commands/teamwork/coordinator.js.map +1 -1
  25. package/dist/commands/teamwork/create.d.ts +1 -0
  26. package/dist/commands/teamwork/create.d.ts.map +1 -1
  27. package/dist/commands/teamwork/create.js +4 -0
  28. package/dist/commands/teamwork/create.js.map +1 -1
  29. package/dist/commands/teamwork/evidence-references.d.ts +19 -0
  30. package/dist/commands/teamwork/evidence-references.d.ts.map +1 -0
  31. package/dist/commands/teamwork/evidence-references.js +249 -0
  32. package/dist/commands/teamwork/evidence-references.js.map +1 -0
  33. package/dist/commands/teamwork/foreground-wait.d.ts +4 -1
  34. package/dist/commands/teamwork/foreground-wait.d.ts.map +1 -1
  35. package/dist/commands/teamwork/foreground-wait.js +15 -1
  36. package/dist/commands/teamwork/foreground-wait.js.map +1 -1
  37. package/dist/commands/teamwork/index.d.ts.map +1 -1
  38. package/dist/commands/teamwork/index.js +47 -5
  39. package/dist/commands/teamwork/index.js.map +1 -1
  40. package/dist/commands/teamwork/list.d.ts +1 -0
  41. package/dist/commands/teamwork/list.d.ts.map +1 -1
  42. package/dist/commands/teamwork/list.js +4 -1
  43. package/dist/commands/teamwork/list.js.map +1 -1
  44. package/dist/commands/teamwork/prompt.js +1 -1
  45. package/dist/commands/teamwork/prompt.js.map +1 -1
  46. package/dist/commands/teamwork/rm.d.ts +27 -4
  47. package/dist/commands/teamwork/rm.d.ts.map +1 -1
  48. package/dist/commands/teamwork/rm.js +155 -51
  49. package/dist/commands/teamwork/rm.js.map +1 -1
  50. package/dist/commands/teamwork/run.d.ts.map +1 -1
  51. package/dist/commands/teamwork/run.js +10 -1
  52. package/dist/commands/teamwork/run.js.map +1 -1
  53. package/dist/commands/teamwork/runtime.d.ts +1 -1
  54. package/dist/commands/teamwork/runtime.d.ts.map +1 -1
  55. package/dist/commands/teamwork/runtime.js +14 -4
  56. package/dist/commands/teamwork/runtime.js.map +1 -1
  57. package/dist/commands/teamwork/spawn.d.ts.map +1 -1
  58. package/dist/commands/teamwork/spawn.js +4 -1
  59. package/dist/commands/teamwork/spawn.js.map +1 -1
  60. package/dist/commands/teamwork/supervisor/stdout.d.ts.map +1 -1
  61. package/dist/commands/teamwork/supervisor/stdout.js +7 -0
  62. package/dist/commands/teamwork/supervisor/stdout.js.map +1 -1
  63. package/dist/commands/teamwork/supervisor.d.ts +1 -1
  64. package/dist/commands/teamwork/supervisor.d.ts.map +1 -1
  65. package/dist/commands/teamwork/teammate-adapters.d.ts +3 -0
  66. package/dist/commands/teamwork/teammate-adapters.d.ts.map +1 -1
  67. package/dist/commands/teamwork/teammate-adapters.js +14 -5
  68. package/dist/commands/teamwork/teammate-adapters.js.map +1 -1
  69. package/dist/commands/teamwork/teammate-launch.d.ts +3 -1
  70. package/dist/commands/teamwork/teammate-launch.d.ts.map +1 -1
  71. package/dist/commands/teamwork/teammate-launch.js +7 -5
  72. package/dist/commands/teamwork/teammate-launch.js.map +1 -1
  73. package/dist/commands/teamwork/workers.d.ts +8 -0
  74. package/dist/commands/teamwork/workers.d.ts.map +1 -0
  75. package/dist/commands/teamwork/workers.js +67 -0
  76. package/dist/commands/teamwork/workers.js.map +1 -0
  77. package/dist/commands/update.d.ts.map +1 -1
  78. package/dist/commands/update.js +109 -55
  79. package/dist/commands/update.js.map +1 -1
  80. package/dist/commands/workflow.d.ts.map +1 -1
  81. package/dist/commands/workflow.js +5 -7
  82. package/dist/commands/workflow.js.map +1 -1
  83. package/dist/configurators/codebuddy.d.ts +1 -8
  84. package/dist/configurators/codebuddy.d.ts.map +1 -1
  85. package/dist/configurators/codebuddy.js +2 -12
  86. package/dist/configurators/codebuddy.js.map +1 -1
  87. package/dist/configurators/codex.d.ts +0 -36
  88. package/dist/configurators/codex.d.ts.map +1 -1
  89. package/dist/configurators/codex.js +2 -99
  90. package/dist/configurators/codex.js.map +1 -1
  91. package/dist/configurators/copilot.d.ts +1 -12
  92. package/dist/configurators/copilot.d.ts.map +1 -1
  93. package/dist/configurators/copilot.js +2 -20
  94. package/dist/configurators/copilot.js.map +1 -1
  95. package/dist/configurators/cursor.d.ts +1 -8
  96. package/dist/configurators/cursor.d.ts.map +1 -1
  97. package/dist/configurators/cursor.js +2 -12
  98. package/dist/configurators/cursor.js.map +1 -1
  99. package/dist/configurators/droid.d.ts +1 -8
  100. package/dist/configurators/droid.d.ts.map +1 -1
  101. package/dist/configurators/droid.js +2 -12
  102. package/dist/configurators/droid.js.map +1 -1
  103. package/dist/configurators/dsh.d.ts +1 -21
  104. package/dist/configurators/dsh.d.ts.map +1 -1
  105. package/dist/configurators/dsh.js +4 -37
  106. package/dist/configurators/dsh.js.map +1 -1
  107. package/dist/configurators/gemini.d.ts +1 -16
  108. package/dist/configurators/gemini.d.ts.map +1 -1
  109. package/dist/configurators/gemini.js +3 -21
  110. package/dist/configurators/gemini.js.map +1 -1
  111. package/dist/configurators/grok.d.ts +1 -12
  112. package/dist/configurators/grok.d.ts.map +1 -1
  113. package/dist/configurators/grok.js +2 -18
  114. package/dist/configurators/grok.js.map +1 -1
  115. package/dist/configurators/kimi.d.ts +1 -21
  116. package/dist/configurators/kimi.d.ts.map +1 -1
  117. package/dist/configurators/kimi.js +2 -38
  118. package/dist/configurators/kimi.js.map +1 -1
  119. package/dist/configurators/kiro.d.ts +1 -9
  120. package/dist/configurators/kiro.d.ts.map +1 -1
  121. package/dist/configurators/kiro.js +1 -9
  122. package/dist/configurators/kiro.js.map +1 -1
  123. package/dist/configurators/omp.d.ts.map +1 -1
  124. package/dist/configurators/omp.js +1 -5
  125. package/dist/configurators/omp.js.map +1 -1
  126. package/dist/configurators/pi.d.ts.map +1 -1
  127. package/dist/configurators/pi.js +2 -5
  128. package/dist/configurators/pi.js.map +1 -1
  129. package/dist/configurators/qoder.d.ts +1 -10
  130. package/dist/configurators/qoder.d.ts.map +1 -1
  131. package/dist/configurators/qoder.js +3 -15
  132. package/dist/configurators/qoder.js.map +1 -1
  133. package/dist/configurators/reasonix.d.ts +1 -12
  134. package/dist/configurators/reasonix.d.ts.map +1 -1
  135. package/dist/configurators/reasonix.js +3 -22
  136. package/dist/configurators/reasonix.js.map +1 -1
  137. package/dist/configurators/shared.d.ts +1 -24
  138. package/dist/configurators/shared.d.ts.map +1 -1
  139. package/dist/configurators/shared.js +5 -184
  140. package/dist/configurators/shared.js.map +1 -1
  141. package/dist/configurators/snow.d.ts +1 -20
  142. package/dist/configurators/snow.d.ts.map +1 -1
  143. package/dist/configurators/snow.js +2 -25
  144. package/dist/configurators/snow.js.map +1 -1
  145. package/dist/configurators/trae.d.ts +1 -14
  146. package/dist/configurators/trae.d.ts.map +1 -1
  147. package/dist/configurators/trae.js +3 -19
  148. package/dist/configurators/trae.js.map +1 -1
  149. package/dist/configurators/workflow.d.ts +2 -0
  150. package/dist/configurators/workflow.d.ts.map +1 -1
  151. package/dist/configurators/workflow.js +72 -56
  152. package/dist/configurators/workflow.js.map +1 -1
  153. package/dist/configurators/zcode.d.ts +1 -13
  154. package/dist/configurators/zcode.d.ts.map +1 -1
  155. package/dist/configurators/zcode.js +2 -18
  156. package/dist/configurators/zcode.js.map +1 -1
  157. package/dist/migrations/manifests/0.5.0-beta.5.json +1 -212
  158. package/dist/migrations/manifests/0.7.2-beta.10.json +9 -0
  159. package/dist/migrations/manifests/0.7.2-beta.11.json +9 -0
  160. package/dist/migrations/manifests/0.7.2-beta.12.json +9 -0
  161. package/dist/migrations/manifests/0.7.2-beta.13.json +9 -0
  162. package/dist/migrations/manifests/0.7.2-beta.14.json +9 -0
  163. package/dist/migrations/manifests/0.7.2-beta.15.json +9 -0
  164. package/dist/migrations/manifests/0.7.2-beta.16.json +9 -0
  165. package/dist/migrations/manifests/0.7.2-beta.17.json +9 -0
  166. package/dist/migrations/manifests/0.7.2-beta.18.json +9 -0
  167. package/dist/migrations/manifests/0.7.2-beta.19.json +11 -0
  168. package/dist/migrations/manifests/0.7.2-beta.20.json +9 -0
  169. package/dist/migrations/manifests/0.7.2-beta.21.json +9 -0
  170. package/dist/migrations/manifests/0.7.2-beta.3.json +9 -0
  171. package/dist/migrations/manifests/0.7.2-beta.4.json +9 -0
  172. package/dist/migrations/manifests/0.7.2-beta.5.json +9 -0
  173. package/dist/migrations/manifests/0.7.2-beta.6.json +9 -0
  174. package/dist/migrations/manifests/0.7.2-beta.7.json +9 -0
  175. package/dist/migrations/manifests/0.7.2-beta.8.json +9 -0
  176. package/dist/migrations/manifests/0.7.2-beta.9.json +9 -0
  177. package/dist/migrations/retired-native-paths.d.ts +109 -0
  178. package/dist/migrations/retired-native-paths.d.ts.map +1 -0
  179. package/dist/migrations/retired-native-paths.js +263 -0
  180. package/dist/migrations/retired-native-paths.js.map +1 -0
  181. package/dist/templates/claude/index.d.ts +1 -16
  182. package/dist/templates/claude/index.d.ts.map +1 -1
  183. package/dist/templates/claude/index.js +5 -32
  184. package/dist/templates/claude/index.js.map +1 -1
  185. package/dist/templates/claude/settings.json +0 -22
  186. package/dist/templates/codebuddy/index.d.ts +2 -3
  187. package/dist/templates/codebuddy/index.d.ts.map +1 -1
  188. package/dist/templates/codebuddy/index.js +2 -3
  189. package/dist/templates/codebuddy/index.js.map +1 -1
  190. package/dist/templates/codebuddy/settings.json +0 -10
  191. package/dist/templates/codex/config.toml +2 -19
  192. package/dist/templates/codex/hooks/session-start.py +25 -30
  193. package/dist/templates/codex/hooks.json +0 -12
  194. package/dist/templates/codex/index.d.ts +0 -5
  195. package/dist/templates/codex/index.d.ts.map +1 -1
  196. package/dist/templates/codex/index.js +0 -13
  197. package/dist/templates/codex/index.js.map +1 -1
  198. package/dist/templates/common/bundled-skills/trellis-decision-space-construction-and-merging/SKILL.md +2 -0
  199. package/dist/templates/common/bundled-skills/trellis-decision-space-construction-and-merging/workflow.md +7 -3
  200. package/dist/templates/common/bundled-skills/trellis-delivery-review-and-closeout/SKILL.md +2 -0
  201. package/dist/templates/common/bundled-skills/trellis-delivery-review-and-closeout/workflow.md +2 -0
  202. package/dist/templates/common/bundled-skills/trellis-goal-exploration-and-requirements/SKILL.md +2 -0
  203. package/dist/templates/common/bundled-skills/trellis-meta/SKILL.md +7 -7
  204. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-agents.md +9 -51
  205. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-context-loading.md +3 -15
  206. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-hooks.md +1 -2
  207. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/context-injection.md +4 -9
  208. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/generated-files.md +2 -2
  209. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/multi-agent-teamwork.md +6 -0
  210. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/overview.md +1 -1
  211. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/spec-system.md +10 -8
  212. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/agents.md +9 -79
  213. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/hooks-and-settings.md +2 -4
  214. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/overview.md +3 -6
  215. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/platform-map.md +24 -103
  216. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/skills-and-commands.md +1 -1
  217. package/dist/templates/common/bundled-skills/trellis-session-insight/SKILL.md +1 -1
  218. package/dist/templates/common/bundled-skills/trellis-solution-design-and-convergence/SKILL.md +2 -0
  219. package/dist/templates/common/bundled-skills/trellis-solution-design-and-convergence/workflow.md +14 -5
  220. package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/SKILL.md +6 -4
  221. package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/references/spec-task-planning.md +5 -9
  222. package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/references/spec-writing.md +8 -0
  223. package/dist/templates/common/bundled-skills/trellis-task-implementation/SKILL.md +2 -0
  224. package/dist/templates/common/bundled-skills/trellis-task-implementation/workflow.md +1 -1
  225. package/dist/templates/common/bundled-skills/trellis-teamwork/SKILL.md +8 -1
  226. package/dist/templates/common/bundled-skills/trellis-teamwork/references/teammate-processes.md +21 -1
  227. package/dist/templates/common/bundled-skills/trellis-teamwork/references/teamwork-plan-construction.md +13 -2
  228. package/dist/templates/common/bundled-skills/trellis-worktree-delegation/SKILL.md +14 -0
  229. package/dist/templates/common/bundled-skills/trellis-worktree-delegation/workflow.md +17 -0
  230. package/dist/templates/common/commands/continue.md +8 -0
  231. package/dist/templates/common/commands/start.md +2 -0
  232. package/dist/templates/common/skills/before-dev.md +3 -1
  233. package/dist/templates/common/skills/check.md +3 -1
  234. package/dist/templates/common/skills/request-intake.md +5 -3
  235. package/dist/templates/copilot/hooks/session-start.py +11 -30
  236. package/dist/templates/cursor/hooks.json +0 -7
  237. package/dist/templates/cursor/index.d.ts +1 -11
  238. package/dist/templates/cursor/index.d.ts.map +1 -1
  239. package/dist/templates/cursor/index.js +2 -10
  240. package/dist/templates/cursor/index.js.map +1 -1
  241. package/dist/templates/droid/index.d.ts +2 -3
  242. package/dist/templates/droid/index.d.ts.map +1 -1
  243. package/dist/templates/droid/index.js +2 -3
  244. package/dist/templates/droid/index.js.map +1 -1
  245. package/dist/templates/droid/settings.json +0 -10
  246. package/dist/templates/dsh/DSH.md +2 -33
  247. package/dist/templates/dsh/index.d.ts +1 -19
  248. package/dist/templates/dsh/index.d.ts.map +1 -1
  249. package/dist/templates/dsh/index.js +2 -21
  250. package/dist/templates/dsh/index.js.map +1 -1
  251. package/dist/templates/gemini/index.d.ts +1 -11
  252. package/dist/templates/gemini/index.d.ts.map +1 -1
  253. package/dist/templates/gemini/index.js +2 -10
  254. package/dist/templates/gemini/index.js.map +1 -1
  255. package/dist/templates/kiro/agents/trellis.json +1 -1
  256. package/dist/templates/kiro/index.d.ts +1 -13
  257. package/dist/templates/kiro/index.d.ts.map +1 -1
  258. package/dist/templates/kiro/index.js +1 -13
  259. package/dist/templates/kiro/index.js.map +1 -1
  260. package/dist/templates/markdown/agents.md +15 -3
  261. package/dist/templates/markdown/index.d.ts +1 -0
  262. package/dist/templates/markdown/index.d.ts.map +1 -1
  263. package/dist/templates/markdown/index.js +1 -0
  264. package/dist/templates/markdown/index.js.map +1 -1
  265. package/dist/templates/markdown/spec/index.md.txt +20 -0
  266. package/dist/templates/omp/extensions/trellis/index.ts.txt +11 -51
  267. package/dist/templates/omp/index.d.ts +0 -2
  268. package/dist/templates/omp/index.d.ts.map +1 -1
  269. package/dist/templates/omp/index.js +1 -4
  270. package/dist/templates/omp/index.js.map +1 -1
  271. package/dist/templates/opencode/lib/session-utils.js +17 -5
  272. package/dist/templates/opencode/lib/trellis-context.js +12 -321
  273. package/dist/templates/opencode/plugins/inject-shell-session-context.js +93 -0
  274. package/dist/templates/opencode/plugins/inject-workflow-state.js +4 -10
  275. package/dist/templates/opencode/plugins/session-start.js +2 -6
  276. package/dist/templates/pi/extensions/trellis/index.ts.txt +8 -1432
  277. package/dist/templates/pi/index.d.ts +1 -2
  278. package/dist/templates/pi/index.d.ts.map +1 -1
  279. package/dist/templates/pi/index.js +2 -5
  280. package/dist/templates/pi/index.js.map +1 -1
  281. package/dist/templates/qoder/index.d.ts +2 -3
  282. package/dist/templates/qoder/index.d.ts.map +1 -1
  283. package/dist/templates/qoder/index.js +2 -3
  284. package/dist/templates/qoder/index.js.map +1 -1
  285. package/dist/templates/shared-hooks/guard-teamwork-wait.py +118 -12
  286. package/dist/templates/shared-hooks/index.d.ts +2 -56
  287. package/dist/templates/shared-hooks/index.d.ts.map +1 -1
  288. package/dist/templates/shared-hooks/index.js +3 -70
  289. package/dist/templates/shared-hooks/index.js.map +1 -1
  290. package/dist/templates/shared-hooks/inject-spec-context.py +6 -35
  291. package/dist/templates/shared-hooks/inject-workflow-state.py +18 -77
  292. package/dist/templates/shared-hooks/session-start.py +8 -6
  293. package/dist/templates/snow/SNOW.md +6 -18
  294. package/dist/templates/snow/hooks/write-trellis-context.py +51 -133
  295. package/dist/templates/snow/index.d.ts +2 -21
  296. package/dist/templates/snow/index.d.ts.map +1 -1
  297. package/dist/templates/snow/index.js +3 -24
  298. package/dist/templates/snow/index.js.map +1 -1
  299. package/dist/templates/template-utils.d.ts +1 -2
  300. package/dist/templates/template-utils.d.ts.map +1 -1
  301. package/dist/templates/template-utils.js +1 -11
  302. package/dist/templates/template-utils.js.map +1 -1
  303. package/dist/templates/trae/index.d.ts +2 -3
  304. package/dist/templates/trae/index.d.ts.map +1 -1
  305. package/dist/templates/trae/index.js +2 -3
  306. package/dist/templates/trae/index.js.map +1 -1
  307. package/dist/templates/trellis/agents/delegated-worktree-primary-agent.md +20 -22
  308. package/dist/templates/trellis/agents/teammate.md +6 -2
  309. package/dist/templates/trellis/agents/worktree-delegation-node.md +24 -0
  310. package/dist/templates/trellis/config.yaml +7 -36
  311. package/dist/templates/trellis/gitignore.txt +4 -0
  312. package/dist/templates/trellis/index.d.ts +1 -0
  313. package/dist/templates/trellis/index.d.ts.map +1 -1
  314. package/dist/templates/trellis/index.js +3 -0
  315. package/dist/templates/trellis/index.js.map +1 -1
  316. package/dist/templates/trellis/scripts/common/active_task.py +23 -31
  317. package/dist/templates/trellis/scripts/common/config.py +1 -36
  318. package/dist/templates/trellis/scripts/common/git_context.py +13 -4
  319. package/dist/templates/trellis/scripts/common/io.py +2 -2
  320. package/dist/templates/trellis/scripts/common/packages_context.py +29 -1
  321. package/dist/templates/trellis/scripts/common/session_context.py +25 -50
  322. package/dist/templates/trellis/scripts/common/task_context.py +5 -3
  323. package/dist/templates/trellis/scripts/common/task_continuity.py +42 -9
  324. package/dist/templates/trellis/scripts/common/task_move.py +2 -2
  325. package/dist/templates/trellis/scripts/common/task_runtime.py +211 -0
  326. package/dist/templates/trellis/scripts/common/task_store.py +8 -78
  327. package/dist/templates/trellis/scripts/common/task_workflow.py +9 -26
  328. package/dist/templates/trellis/scripts/common/workflow_phase.py +3 -36
  329. package/dist/templates/trellis/scripts/common/workflow_selection.py +12 -2
  330. package/dist/templates/trellis/scripts/common/worktree_delegation.py +603 -0
  331. package/dist/templates/trellis/scripts/task.py +41 -2
  332. package/dist/templates/trellis/workflow.md +25 -10
  333. package/dist/templates/zcode/config.json +0 -10
  334. package/dist/templates/zcode/index.d.ts +3 -22
  335. package/dist/templates/zcode/index.d.ts.map +1 -1
  336. package/dist/templates/zcode/index.js +3 -24
  337. package/dist/templates/zcode/index.js.map +1 -1
  338. package/dist/types/ai-tools.d.ts +0 -4
  339. package/dist/types/ai-tools.d.ts.map +1 -1
  340. package/dist/types/ai-tools.js +4 -109
  341. package/dist/types/ai-tools.js.map +1 -1
  342. package/dist/utils/ablation-store.d.ts.map +1 -1
  343. package/dist/utils/ablation-store.js +24 -0
  344. package/dist/utils/ablation-store.js.map +1 -1
  345. package/dist/utils/asset-backup.d.ts.map +1 -1
  346. package/dist/utils/asset-backup.js +25 -20
  347. package/dist/utils/asset-backup.js.map +1 -1
  348. package/dist/utils/file-writer.d.ts +2 -0
  349. package/dist/utils/file-writer.d.ts.map +1 -1
  350. package/dist/utils/file-writer.js +1 -1
  351. package/dist/utils/file-writer.js.map +1 -1
  352. package/dist/utils/managed-markdown.d.ts +5 -0
  353. package/dist/utils/managed-markdown.d.ts.map +1 -0
  354. package/dist/utils/managed-markdown.js +64 -0
  355. package/dist/utils/managed-markdown.js.map +1 -0
  356. package/dist/utils/managed-removal.d.ts +2 -0
  357. package/dist/utils/managed-removal.d.ts.map +1 -1
  358. package/dist/utils/managed-removal.js +26 -2
  359. package/dist/utils/managed-removal.js.map +1 -1
  360. package/dist/utils/manifest-prune.d.ts.map +1 -1
  361. package/dist/utils/manifest-prune.js +5 -12
  362. package/dist/utils/manifest-prune.js.map +1 -1
  363. package/dist/utils/retired-native-assets.d.ts +17 -0
  364. package/dist/utils/retired-native-assets.d.ts.map +1 -0
  365. package/dist/utils/retired-native-assets.js +235 -0
  366. package/dist/utils/retired-native-assets.js.map +1 -0
  367. package/dist/utils/uninstall-scrubbers.d.ts.map +1 -1
  368. package/dist/utils/uninstall-scrubbers.js +6 -12
  369. package/dist/utils/uninstall-scrubbers.js.map +1 -1
  370. package/package.json +2 -2
  371. package/dist/templates/claude/agents/trellis-check.md +0 -115
  372. package/dist/templates/claude/agents/trellis-implement.md +0 -110
  373. package/dist/templates/claude/agents/trellis-research.md +0 -137
  374. package/dist/templates/codebuddy/agents/trellis-check.md +0 -115
  375. package/dist/templates/codebuddy/agents/trellis-implement.md +0 -110
  376. package/dist/templates/codebuddy/agents/trellis-research.md +0 -137
  377. package/dist/templates/codex/agents/trellis-check.toml +0 -56
  378. package/dist/templates/codex/agents/trellis-implement.toml +0 -37
  379. package/dist/templates/codex/agents/trellis-research.toml +0 -78
  380. package/dist/templates/cursor/agents/trellis-check.md +0 -114
  381. package/dist/templates/cursor/agents/trellis-implement.md +0 -109
  382. package/dist/templates/cursor/agents/trellis-research.md +0 -136
  383. package/dist/templates/droid/droids/trellis-check.md +0 -107
  384. package/dist/templates/droid/droids/trellis-implement.md +0 -102
  385. package/dist/templates/droid/droids/trellis-research.md +0 -137
  386. package/dist/templates/dsh/agents/trellis-check.md +0 -99
  387. package/dist/templates/dsh/agents/trellis-implement.md +0 -106
  388. package/dist/templates/dsh/agents/trellis-research.md +0 -134
  389. package/dist/templates/gemini/agents/trellis-check.md +0 -107
  390. package/dist/templates/gemini/agents/trellis-implement.md +0 -102
  391. package/dist/templates/gemini/agents/trellis-research.md +0 -136
  392. package/dist/templates/grok/agents/trellis-check.md +0 -105
  393. package/dist/templates/grok/agents/trellis-implement.md +0 -116
  394. package/dist/templates/grok/agents/trellis-research.md +0 -146
  395. package/dist/templates/grok/index.d.ts +0 -16
  396. package/dist/templates/grok/index.d.ts.map +0 -1
  397. package/dist/templates/grok/index.js +0 -19
  398. package/dist/templates/grok/index.js.map +0 -1
  399. package/dist/templates/kimi/agents/trellis-check.md +0 -103
  400. package/dist/templates/kimi/agents/trellis-implement.md +0 -115
  401. package/dist/templates/kimi/agents/trellis-research.md +0 -144
  402. package/dist/templates/kimi/index.d.ts +0 -20
  403. package/dist/templates/kimi/index.d.ts.map +0 -1
  404. package/dist/templates/kimi/index.js +0 -23
  405. package/dist/templates/kimi/index.js.map +0 -1
  406. package/dist/templates/kiro/agents/trellis-check.json +0 -26
  407. package/dist/templates/kiro/agents/trellis-implement.json +0 -26
  408. package/dist/templates/kiro/agents/trellis-research.json +0 -30
  409. package/dist/templates/omp/agents/trellis-check.md +0 -41
  410. package/dist/templates/omp/agents/trellis-implement.md +0 -45
  411. package/dist/templates/omp/agents/trellis-research.md +0 -30
  412. package/dist/templates/opencode/agents/trellis-check.md +0 -122
  413. package/dist/templates/opencode/agents/trellis-implement.md +0 -118
  414. package/dist/templates/opencode/agents/trellis-research.md +0 -145
  415. package/dist/templates/opencode/plugins/inject-subagent-context.js +0 -569
  416. package/dist/templates/pi/agents/trellis-check.md +0 -37
  417. package/dist/templates/pi/agents/trellis-implement.md +0 -42
  418. package/dist/templates/pi/agents/trellis-research.md +0 -25
  419. package/dist/templates/qoder/agents/trellis-check.md +0 -108
  420. package/dist/templates/qoder/agents/trellis-implement.md +0 -103
  421. package/dist/templates/qoder/agents/trellis-research.md +0 -137
  422. package/dist/templates/reasonix/agents/trellis-check.md +0 -36
  423. package/dist/templates/reasonix/agents/trellis-implement.md +0 -41
  424. package/dist/templates/reasonix/index.d.ts +0 -13
  425. package/dist/templates/reasonix/index.d.ts.map +0 -1
  426. package/dist/templates/reasonix/index.js +0 -16
  427. package/dist/templates/reasonix/index.js.map +0 -1
  428. package/dist/templates/shared-hooks/inject-subagent-context.py +0 -1217
  429. package/dist/templates/snow/agents/trellis-check.md +0 -135
  430. package/dist/templates/snow/agents/trellis-implement.md +0 -153
  431. package/dist/templates/snow/agents/trellis-research.md +0 -114
  432. package/dist/templates/snow/hooks/beforeSubAgentStart.json +0 -15
  433. package/dist/templates/trae/agents/trellis-check.md +0 -108
  434. package/dist/templates/trae/agents/trellis-implement.md +0 -103
  435. package/dist/templates/trae/agents/trellis-research.md +0 -137
  436. package/dist/templates/zcode/agents/trellis-check.md +0 -109
  437. package/dist/templates/zcode/agents/trellis-implement.md +0 -111
  438. package/dist/templates/zcode/agents/trellis-research.md +0 -133
@@ -0,0 +1,603 @@
1
+ """Versioned controller-only worktree delegation; Paseo owns native resources."""
2
+ from __future__ import annotations
3
+
4
+ import hashlib
5
+ import json
6
+ import os
7
+ from pathlib import Path
8
+ import re
9
+ import shutil
10
+ import subprocess
11
+ import uuid
12
+ from typing import NoReturn
13
+
14
+ from .io import read_json_checked, write_json, write_text_atomic
15
+ from .paths import get_repo_root
16
+
17
+ MAX_BYTES = 256 * 1024
18
+ SAFE_ID = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$")
19
+
20
+
21
+ def fail(message: str) -> NoReturn:
22
+ from .task_workflow import TaskWorkflowError
23
+ raise TaskWorkflowError("TASK_DELEGATE_WITHHELD", message)
24
+
25
+
26
+ def digest(value) -> str:
27
+ data = value if isinstance(value, bytes) else json.dumps(value, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode()
28
+ return hashlib.sha256(data).hexdigest()
29
+
30
+
31
+ def read(path: Path) -> dict:
32
+ if path.is_symlink() or not path.is_file() or path.stat().st_size > MAX_BYTES:
33
+ fail(f"invalid bounded regular JSON file: {path}")
34
+ value, reason = read_json_checked(path)
35
+ if value is None:
36
+ fail(f"cannot read {path}: {reason}")
37
+ return value
38
+
39
+
40
+ def save(path: Path, value: dict):
41
+ path.parent.mkdir(parents=True, exist_ok=True)
42
+ if path.is_symlink() or not write_json(path, value):
43
+ fail(f"could not atomically save {path}; preserve current state")
44
+
45
+
46
+ def runtime_path(root: Path, task_id: str) -> Path:
47
+ if not SAFE_ID.fullmatch(task_id):
48
+ fail("unsafe task identity")
49
+ path = root / ".trellis/.runtime/delegation" / task_id / "record.json"
50
+ if path.resolve() != path.absolute():
51
+ fail("redirected delegation runtime")
52
+ return path
53
+
54
+
55
+ def resolve_record(root: Path, task_dir: Path, data: dict):
56
+ """One resolver for current runtime and historical task-meta consumers."""
57
+ path = runtime_path(root, task_dir.name)
58
+ return read(path) if path.exists() else data.get("meta", {}).get("delegated_worktree_execution_record")
59
+
60
+
61
+ def git(root: Path, *args: str) -> str:
62
+ result = subprocess.run(["git", *args], cwd=root, capture_output=True, text=True, encoding="utf8", timeout=30)
63
+ if result.returncode:
64
+ fail(f"Git identity/check failed: {args[0]}")
65
+ return result.stdout.strip()
66
+
67
+
68
+ def identity(root: Path) -> dict:
69
+ root = root.resolve(strict=True)
70
+ if Path(git(root, "rev-parse", "--show-toplevel")).resolve() != root:
71
+ fail("target must be the exact checkout root")
72
+ return {"checkout": str(root), "common_dir": str(Path(git(root, "rev-parse", "--path-format=absolute", "--git-common-dir")).resolve())}
73
+
74
+
75
+ def task_inputs(child_dir: Path, *, require_authorization: bool = True):
76
+ from .task_workflow import _load, _task_dir, _state, implementation_start_ready, TaskWorkflowError
77
+ from .task_continuity import assert_task_mutation_allowed
78
+ child, _ = _load(child_dir)
79
+ if not child.get("parent"):
80
+ fail("child must be linked to an authorized controller task")
81
+ parent_dir = _task_dir(child["parent"])
82
+ parent, meta = _load(parent_dir)
83
+ if child.get("status") not in {"planning", "in_progress"}:
84
+ raise TaskWorkflowError("TASK_DELEGATE_CHILD_TERMINAL", "child task is terminal")
85
+ if child_dir.name not in parent.get("children", []):
86
+ fail("child links or lifecycle are invalid")
87
+ assert_task_mutation_allowed(get_repo_root(), parent_dir, parent)
88
+ assert_task_mutation_allowed(get_repo_root(), child_dir, child)
89
+ if require_authorization and (parent.get("status") != "in_progress" or not implementation_start_ready(parent, parent_dir)):
90
+ raise TaskWorkflowError("TASK_DELEGATE_IMPLEMENTATION_NOT_AUTHORIZED", "current parent implementation authorization required")
91
+ return child, parent, _state(meta), parent_dir
92
+
93
+
94
+ def file_ref(task_dir: Path, ref: str) -> Path:
95
+ if not isinstance(ref, str) or not ref or Path(ref).is_absolute():
96
+ fail("metadata reference must be a nonempty relative path")
97
+ path = task_dir / ref
98
+ try:
99
+ path.resolve(strict=True).relative_to(task_dir.resolve())
100
+ except (ValueError, OSError):
101
+ fail("metadata reference must stay in the child task")
102
+ if path.resolve() != path.absolute() or not path.is_file() or path.stat().st_size > MAX_BYTES:
103
+ fail("metadata reference must be a bounded regular file")
104
+ return path
105
+
106
+
107
+ def freeze(root: Path, child_dir: Path, target: Path, branch: str | None, integration: str, settings_ref: str, requirements_ref: str, base_commit: str | None = None) -> dict:
108
+ child, parent, state, _ = task_inputs(child_dir)
109
+ target_identity = identity(target)
110
+ settings_path, requirements_path = file_ref(child_dir, settings_ref), file_ref(child_dir, requirements_ref)
111
+ settings, requirements = read(settings_path), read(requirements_path)
112
+ if settings.get("version") != 1 or settings.get("provider") != "codex" or settings.get("mode") != "full-access" or not settings.get("model") or not settings.get("effort"):
113
+ fail("settings v1 require explicit codex/model/effort/full-access; resolve defaults through capability first")
114
+ if set(settings) - {"version", "provider", "model", "effort", "mode", "daemon_home", "sandbox", "approval", "reviewer", "context"}:
115
+ fail("unknown settings field")
116
+ if any(settings.get(k, "native_default") != "native_default" for k in ["sandbox", "approval", "reviewer", "context"]):
117
+ fail("bottom-level permissions and context must retain native defaults")
118
+ fields = {"version", "required_rules", "required_skills", "required_tools", "checks", "resources", "allowed_paths", "forbidden_paths", "setup_ref", "teamwork_permission"}
119
+ if requirements.get("version") != 1 or set(requirements) - fields or not isinstance(requirements.get("allowed_paths"), list) or not requirements["allowed_paths"]:
120
+ fail("requirements v1 and nonempty allowed_paths required")
121
+ for key in fields - {"version", "setup_ref", "teamwork_permission"}:
122
+ if key in requirements and (not isinstance(requirements[key], list) or any(not isinstance(item, str) or not item or "\0" in item for item in requirements[key])):
123
+ fail(f"requirements {key} must contain nonempty strings")
124
+ if requirements.get("teamwork_permission", "none") not in {"none", "read_only"}:
125
+ fail("Teamwork may only be absent or read_only")
126
+ if "setup_ref" in requirements:
127
+ file_ref(child_dir, requirements["setup_ref"])
128
+ if not isinstance(branch, str) or not branch:
129
+ fail("child execution branch must be set through the native task interface")
130
+ for ref in [settings_ref, requirements_ref, "prd.md"]:
131
+ file_ref(child_dir, ref)
132
+ git(target, "check-ref-format", "--branch", branch)
133
+ git(target, "check-ref-format", "--branch", integration)
134
+ if branch == integration:
135
+ fail("execution branch must differ from integration branch")
136
+ base = base_commit or git(target, "rev-parse", "--verify", "--end-of-options", f"{integration}^{{commit}}")
137
+ git(target, "merge-base", "--is-ancestor", base, integration)
138
+ role = file_ref(root, ".trellis/agents/delegated-worktree-primary-agent.md")
139
+ node_method = file_ref(root, ".trellis/agents/worktree-delegation-node.md")
140
+ authorization = state["implementation_authorization"]
141
+ binding = {"format_version": 2, "parent_task_id": parent["id"], "child_task_id": child["id"], "parent_route_revision": state["task_route_revision"], "parent_contract_revision": authorization["contract_revision"], "approval_ref": authorization["approval_ref"], "target_locator": str(target), "integration_branch": integration, "execution_branch": branch, "base_commit": base, "contract_sha256": digest(file_ref(child_dir, "prd.md").read_bytes()), "role_sha256": digest(role.read_bytes()), "node_method_sha256": digest(node_method.read_bytes()), "setup_sha256": digest(file_ref(child_dir, requirements["setup_ref"]).read_bytes()) if requirements.get("setup_ref") else None, "settings_sha256": digest(settings_path.read_bytes()), "requirements_sha256": digest(requirements_path.read_bytes()), "settings_ref": settings_ref, "requirements_ref": requirements_ref}
142
+ binding["binding_revision"] = digest(binding)
143
+ return {"binding": binding, "target_identity": target_identity, "settings": settings, "requirements": requirements}
144
+
145
+
146
+ def adapter(record: dict, operation: str, payload: dict):
147
+ request = {"version": 1, "operation": operation, "attempt_id": record.get("attempt_id"), "binding_revision": record.get("binding", {}).get("binding_revision"), "daemon_selector": {"home": record["settings"].get("daemon_home")} if record["settings"].get("daemon_home") else {}, "payload": payload}
148
+ if record.get("daemon_identity"):
149
+ request["daemon_selector"]["server_id"] = record["daemon_identity"]["server_id"]
150
+ try:
151
+ # A regular temp file bounds what the controller reads even if a broken
152
+ # adapter emits excessive output. Never execute candidate-report commands.
153
+ import tempfile
154
+ with tempfile.TemporaryFile() as output, tempfile.TemporaryFile() as errors:
155
+ result = subprocess.run(["trellis-paseo-adapter"], input=json.dumps(request).encode(), stdout=output, stderr=errors, timeout=3700 if operation == "wait" else 120)
156
+ output.seek(0)
157
+ raw = output.read(MAX_BYTES + 1)
158
+ value = json.loads(raw) if len(raw) <= MAX_BYTES else None
159
+ except (OSError, subprocess.TimeoutExpired, ValueError):
160
+ fail("adapter unavailable or outcome unknown; preserve intent and reconcile; install/check trellis-paseo-adapter through Lifecycle")
161
+ if not isinstance(value, dict) or value.get("version") != 1 or value.get("operation") != operation or value.get("attempt_id") != request["attempt_id"] or value.get("binding_revision") != request["binding_revision"]:
162
+ fail("adapter response identity/shape unknown; preserve intent and reconcile")
163
+ if result.returncode or value.get("ok") is not True or not isinstance(value.get("observations"), dict):
164
+ fail(f"adapter {value.get('error', {}).get('category', 'outcome_unknown')}; inspect native resources before retry")
165
+ observed = value["observations"]
166
+ if record.get("daemon_identity") and observed.get("identity") != record["daemon_identity"]:
167
+ fail("daemon identity changed; reconcile before continuing")
168
+ return observed
169
+
170
+
171
+ def inspection_pages(record: dict, payload: dict):
172
+ cursor, seen, identity = None, set(), None
173
+ while True:
174
+ observed = adapter(record, "inspect", {**payload, "page_size": 100, **({"cursor": cursor} if cursor else {})})
175
+ page = observed.get("page_info")
176
+ if not isinstance(page, dict) or type(page.get("complete")) is not bool or "next_cursor" not in page:
177
+ fail("adapter inspection pagination is unavailable or incomplete; update the optional adapter")
178
+ following = page["next_cursor"]
179
+ if (following is not None and (not isinstance(following, str) or not following or following in seen)
180
+ or page["complete"] != (following is None) or not isinstance(observed.get("agents"), list)):
181
+ fail("adapter inspection pagination is inconsistent; preserve native resources")
182
+ if identity is not None and observed.get("identity") != identity:
183
+ fail("daemon identity changed during inspection")
184
+ identity = observed.get("identity")
185
+ yield observed
186
+ if following is None:
187
+ return
188
+ seen.add(following)
189
+ cursor = following
190
+
191
+
192
+ def current(root: Path, child_dir: Path, *, require_authorization: bool = True) -> tuple[dict, Path]:
193
+ path = runtime_path(root, child_dir.name)
194
+ record = read(path)
195
+ b = record["binding"]
196
+ if not require_authorization:
197
+ child, parent, _, _ = task_inputs(child_dir, require_authorization=False)
198
+ if record.get("control_project_id") != digest(str(root).encode()) or b.get("parent_task_id") != parent["id"] or b.get("child_task_id") != child["id"] or b.get("binding_revision") != digest({k: v for k, v in b.items() if k != "binding_revision"}) or identity(Path(b["target_locator"])) != record.get("target_identity"):
199
+ fail("existing controller/target binding identity does not match; preserve resources")
200
+ return record, path
201
+ if b.get("format_version") != 2:
202
+ fail("incomplete legacy binding; inspect/interrupt and retain the old attempt before rebinding")
203
+ frozen = freeze(root, child_dir, Path(b["target_locator"]), b["execution_branch"], b["integration_branch"], b["settings_ref"], b["requirements_ref"], b["base_commit"])
204
+ if frozen != {k: record[k] for k in frozen}:
205
+ fail("frozen input or target identity changed; preserve current attempt and rebind only after closure")
206
+ return record, path
207
+
208
+
209
+ def assert_worktree(record: dict):
210
+ tree = Path(record["worktree_path"])
211
+ actual = identity(tree)
212
+ if actual["common_dir"] != record["target_identity"]["common_dir"] or git(tree, "branch", "--show-current") != record["binding"]["execution_branch"]:
213
+ fail("native worktree identity does not match current binding")
214
+ git(tree, "merge-base", "--is-ancestor", record["binding"]["base_commit"], "HEAD")
215
+ return tree
216
+
217
+
218
+ def projection(root: Path, child_dir: Path, record: dict, path: Path):
219
+ b = record["binding"]
220
+ sources = {"role": file_ref(root, ".trellis/agents/delegated-worktree-primary-agent.md"), "node_method": file_ref(root, ".trellis/agents/worktree-delegation-node.md"), "contract": file_ref(child_dir, "prd.md")}
221
+ if record["requirements"].get("setup_ref"):
222
+ sources["setup"] = file_ref(child_dir, record["requirements"]["setup_ref"])
223
+ if b.get("format_version") != 2 or not SAFE_ID.fullmatch(record["attempt_id"]):
224
+ fail("complete frozen binding and safe attempt identity required")
225
+ snapshots = {}
226
+ directory = path.parent / "inputs" / record["attempt_id"]
227
+ if directory.resolve() != directory.absolute():
228
+ fail("redirected frozen input directory")
229
+ directory.mkdir(parents=True, exist_ok=True)
230
+ for name, source in sources.items():
231
+ content = source.read_bytes()
232
+ if len(content) > MAX_BYTES or digest(content) != b[f"{name}_sha256"]:
233
+ fail("approved source input changed before projection; preserve the attempt")
234
+ snapshot = directory / f"{name}.md"
235
+ if snapshot.exists() or snapshot.is_symlink():
236
+ if snapshot.is_symlink() or not snapshot.is_file() or snapshot.stat().st_size > MAX_BYTES or digest(snapshot.read_bytes()) != b[f"{name}_sha256"]:
237
+ fail("frozen input snapshot changed; preserve the attempt")
238
+ elif not write_text_atomic(snapshot, content.decode("utf8"), newline=""):
239
+ fail("could not save frozen input snapshot")
240
+ snapshots[f"{name}_ref"] = str(snapshot)
241
+ context = {"version": 1, "control_root": str(root), "control_task": str(child_dir), "record_ref": str(path), "attempt_id": record["attempt_id"], "binding_revision": b["binding_revision"], "binding": b, "workspace_id": record.get("workspace_id"), "agent_id": record.get("agent_id"), "target": record.get("worktree_path"), "execution_permission": record.get("execution_permission", "preparation"), **snapshots, "requirements": record["requirements"], "settings": record["settings"], "ready_path": str(Path(record["worktree_path"]) / ".trellis-delegation" / record["attempt_id"] / "ready.json"), "result_path": str(Path(record["worktree_path"]) / ".trellis-delegation" / record["attempt_id"] / "result.json")}
242
+ save(path.with_name("context.json"), context)
243
+ return path.with_name("context.json")
244
+
245
+
246
+ def candidate(record: dict, name: str, *, current_head=True):
247
+ tree = assert_worktree(record)
248
+ directory = tree / ".trellis-delegation" / record["attempt_id"]
249
+ path = directory / f"{name}.json"
250
+ if directory.resolve() != directory or (tree / ".trellis-delegation").is_symlink():
251
+ fail("redirected candidate directory")
252
+ if directory.exists() and any(p.name not in {"ready.json", "result.json", "blocked.json"} or p.is_symlink() or not p.is_file() or p.stat().st_size > MAX_BYTES for p in directory.iterdir()):
253
+ fail("candidate directory contains unexpected data; preserve it")
254
+ if not path.exists():
255
+ return None
256
+ value = read(path)
257
+ b = record["binding"]
258
+ expected = {"version": 1, "kind": name, "attempt_id": record["attempt_id"], "binding_revision": b["binding_revision"], "base_commit": b["base_commit"], "workspace_id": record["workspace_id"], "agent_id": record["agent_id"]}
259
+ if any(value.get(k) != v for k, v in expected.items()) or (current_head and value.get("head_commit") != git(tree, "rev-parse", "HEAD")) or "acceptance" in value:
260
+ fail("candidate identity/head/authority does not match the current attempt")
261
+ if not isinstance(value.get("observations"), dict) or not isinstance(value.get("limitations"), list):
262
+ fail("candidate observations/limitations are malformed")
263
+ return value
264
+
265
+
266
+ def clean_result(record: dict, result: dict):
267
+ tree = assert_worktree(record)
268
+ base, head = record["binding"]["base_commit"], result["head_commit"]
269
+ changed = git(tree, "diff", "--name-only", base, head).splitlines()
270
+ commits = git(tree, "rev-list", f"{base}..{head}").splitlines()
271
+ if set(changed) != set(result.get("changed_paths", [])) or set(commits) != set(result.get("source_commits", [])):
272
+ fail("result commits/paths do not match native Git")
273
+ import fnmatch
274
+ req = record["requirements"]
275
+ if any(p.startswith((".trellis-delegation/", ".trellis/tasks/", ".trellis/.runtime/")) or not any(fnmatch.fnmatchcase(p, a) for a in req["allowed_paths"]) or any(fnmatch.fnmatchcase(p, f) for f in req.get("forbidden_paths", [])) for p in changed):
276
+ fail("source changes exceed the authorized paths")
277
+ # No hidden committed runtime files, even if a later commit deletes them.
278
+ for commit in commits:
279
+ if git(tree, "diff-tree", "--no-commit-id", "--name-only", "-r", "-m", commit, "--", ".trellis-delegation", ".trellis/tasks", ".trellis/.runtime"):
280
+ fail("source history modifies protected controller/runtime facts")
281
+ dirty = git(tree, "status", "--porcelain", "--untracked-files=all").splitlines()
282
+ allowed = {f"?? .trellis-delegation/{record['attempt_id']}/{name}.json" for name in ["ready", "result", "blocked"]}
283
+ if any(line not in allowed for line in dirty):
284
+ fail("source worktree has unpreserved changes")
285
+ if not isinstance(result.get("checks"), list) or not isinstance(result.get("remaining"), list):
286
+ fail("result checks/remaining required")
287
+ return changed
288
+
289
+
290
+ def prepare_agent(root: Path, child_dir: Path, record: dict, path: Path):
291
+ context = projection(root, child_dir, record, path)
292
+ role = Path(read(context)["role_ref"]).read_text(encoding="utf8")
293
+ if role.startswith("---\n"):
294
+ role = role.split("\n---\n", 1)[1].lstrip("\n")
295
+ codegraph = "codegraph" in record["requirements"].get("required_tools", [])
296
+ tool = shutil.which("codegraph") if codegraph else None
297
+ if codegraph and not tool:
298
+ fail("required CodeGraph executable is unavailable to the controller")
299
+ tool_payload = {"codegraph_command": str(Path(tool).resolve(strict=True))} if tool else {}
300
+ record["intent"] = "prepare-agent"
301
+ save(path, record)
302
+ agent = adapter(record, "prepare-agent", {"workspace_id": record["workspace_id"], "cwd": record["worktree_path"], "model": record["settings"]["model"], "effort": record["settings"]["effort"], "role": role, "context": str(context), "prompt": f"prepare:读取 {context},只准备并提交 ready.json;当前 agent_id 映射由主控落盘,身份不完整时只报告阻断。", "codegraph": codegraph, **tool_payload, "labels": {"trellis.control": record["control_project_id"], "trellis.child": record["binding"]["child_task_id"], "trellis.attempt": record["attempt_id"]}})["agent"]
303
+ if not agent or not agent.get("id") or agent.get("workspaceId") != record["workspace_id"]:
304
+ fail("agent creation outcome unknown; preserve intent")
305
+ record.update({"agent_id": agent["id"], "status": "running", "intent": None})
306
+ save(path, record)
307
+ projection(root, child_dir, record, path)
308
+
309
+
310
+ def recover(root: Path, child_dir: Path, record: dict, path: Path, args):
311
+ if not record.get("attempt_id") or not record.get("intent"):
312
+ fail("recovery requires an unresolved attempt intent")
313
+ workspace_id = args.workspace_id or record.get("workspace_id")
314
+ if not workspace_id:
315
+ fail("explicit native workspace-id required; inspect native resources first")
316
+ agent_id = args.agent_id or record.get("agent_id")
317
+ payload = {"target": record["binding"]["target_locator"], "workspace_id": workspace_id}
318
+ if agent_id:
319
+ observed = adapter(record, "inspect", {**payload, "agent_id": agent_id})
320
+ else:
321
+ observed = None
322
+ found = []
323
+ for page in inspection_pages(record, payload):
324
+ if observed is None:
325
+ observed = {key: value for key, value in page.items() if key not in {"agents", "page_info"}}
326
+ found.extend(a for a in page["agents"] if a and a.get("labels", {}).get("trellis.attempt") == record["attempt_id"])
327
+ if observed is None:
328
+ fail("native inspection returned no complete page")
329
+ observed["agents"] = found
330
+ spaces = observed.get("workspaces", [])
331
+ if len(spaces) != 1 or spaces[0].get("id") != workspace_id or not spaces[0].get("workspaceDirectory"):
332
+ fail("native workspace identity is unverified")
333
+ adopted = {**record, "workspace_id": workspace_id, "worktree_path": str(Path(spaces[0]["workspaceDirectory"]).resolve())}
334
+ assert_worktree(adopted)
335
+ if record.get("workspace_id") and (record["workspace_id"] != workspace_id or record["worktree_path"] != adopted["worktree_path"]):
336
+ fail("recovery cannot switch existing workspace mappings")
337
+ if agent_id:
338
+ agents = [a for a in observed.get("agents", []) if a and a.get("id") == agent_id]
339
+ if len(agents) != 1:
340
+ fail("exact native agent-id not found; no fuzzy or prefix adoption")
341
+ agent = agents[0]
342
+ if agent.get("workspaceId") != workspace_id or Path(agent.get("cwd", "")).resolve() != Path(adopted["worktree_path"]) or agent.get("labels", {}).get("trellis.attempt") != record["attempt_id"] or agent.get("labels", {}).get("trellis.control") != record["control_project_id"]:
343
+ fail("native agent labels/workspace/cwd do not match the pending attempt")
344
+ if record.get("agent_id") and record["agent_id"] != agent_id:
345
+ fail("recovery cannot replace an existing agent")
346
+ adopted.update({"agent_id": agent_id, "status": "running"})
347
+ elif record["intent"] == "prepare-agent" and args.delivery_evidence_ref:
348
+ if any(a and a.get("labels", {}).get("trellis.attempt") == record["attempt_id"] for a in observed.get("agents", [])):
349
+ fail("native attempt agent exists; map its exact ID instead of asserting absence")
350
+ file_ref(child_dir, args.delivery_evidence_ref)
351
+ adopted["status"] = "workspace_created"
352
+ elif record["intent"] != "prepare-workspace":
353
+ fail("unknown agent creation must be mapped before any new agent is created")
354
+ else:
355
+ adopted["status"] = "workspace_created"
356
+ evidence = {"observation": observed, "intent": record["intent"]}
357
+ if record["intent"] in {"send_pending", "interrupt_pending", "prepare-agent"} and (not agent_id or record["intent"] != "prepare-agent"):
358
+ if not args.delivery_evidence_ref:
359
+ fail("controller-owned native delivery/interrupt evidence required; idle alone cannot resolve unknown delivery")
360
+ evidence["delivery_evidence"] = file_ref(child_dir, args.delivery_evidence_ref).read_text(encoding="utf8")
361
+ if not args.execute:
362
+ return {"status": "ready", "recovery": evidence, "adopted": adopted}
363
+ if not args.reason or not args.approval_ref:
364
+ fail("explicit recovery reason and existing approval reference required")
365
+ adopted.setdefault("recovery_receipts", []).append({**evidence, "reason": args.reason, "approval_ref": args.approval_ref})
366
+ adopted["intent"] = None
367
+ save(path, adopted)
368
+ projection(root, child_dir, adopted, path)
369
+ return adopted
370
+
371
+
372
+ def wait_for_node(args):
373
+ from .task_workflow import _task_dir, _task_lock
374
+ from .task_move import layout_lock, require_settled_layout
375
+ root = get_repo_root().resolve()
376
+ with layout_lock(root):
377
+ require_settled_layout(root)
378
+ child_dir = _task_dir(args.child_task)
379
+ with _task_lock(child_dir):
380
+ task_inputs(child_dir)
381
+ record, _ = current(root, child_dir)
382
+ if not record.get("agent_id") or record["status"] == "retired":
383
+ fail("wait requires a current mapped agent")
384
+ # Long native waits must leave the controller free to inspect or interrupt.
385
+ observations = adapter(record, "wait", {"agent_id": record["agent_id"], "cwd": record["worktree_path"], "timeout_ms": args.timeout_ms})
386
+ with layout_lock(root):
387
+ require_settled_layout(root)
388
+ child_dir = _task_dir(args.child_task)
389
+ with _task_lock(child_dir):
390
+ task_inputs(child_dir)
391
+ latest, _ = current(root, child_dir)
392
+ if any(latest.get(k) != record.get(k) for k in ["binding", "attempt_id", "agent_id", "workspace_id", "worktree_path"]) or latest["status"] == "retired":
393
+ fail("wait target changed; inspect current binding instead of using stale observations")
394
+ reports = {name: candidate(latest, name, current_head=False) for name in ["ready", "result", "blocked"]}
395
+ print(json.dumps({"record": latest, "observations": observations, "candidates": reports}, ensure_ascii=False))
396
+ return 0
397
+
398
+
399
+ def run(args):
400
+ from .task_workflow import _task_dir, _task_lock
401
+ root = get_repo_root().resolve()
402
+ child_dir = _task_dir(args.child_task)
403
+ with _task_lock(child_dir):
404
+ path = runtime_path(root, child_dir.name)
405
+ operation = args.command.removeprefix("delegate-")
406
+ if operation == "inspect":
407
+ from .task_workflow import _load
408
+
409
+ child, _ = _load(child_dir)
410
+ if child.get("status") in {"completed", "cancelled"}:
411
+ record = resolve_record(root, child_dir, child)
412
+ print(json.dumps({"record": record, "historical": True,
413
+ "observations": {}, "candidates": {}}, ensure_ascii=False))
414
+ return 0
415
+ if operation == "bind":
416
+ if getattr(args, "result_path", None):
417
+ fail("legacy --result-path cannot start protocol v1; reconcile old attempts first")
418
+ child, _, _, _ = task_inputs(child_dir)
419
+ previous = resolve_record(root, child_dir, child)
420
+ if previous and previous.get("status") != "retired":
421
+ fail("an existing attempt is not retired; inspect/reconcile instead of rebinding")
422
+ if not args.target_repo or not args.integration_branch or not args.settings_ref or not args.requirements_ref:
423
+ fail("explicit --target-repo, --integration-branch, --settings-ref and --requirements-ref required")
424
+ record = freeze(root, child_dir, Path(args.target_repo).resolve(), child.get("branch"), args.integration_branch, args.settings_ref, args.requirements_ref)
425
+ record.update({"status": "bound", "control_project_id": digest(str(root).encode()), "execution_permission": "preparation"})
426
+ if previous:
427
+ save(path.with_name(f"retired-{previous['attempt_id']}.json"), previous)
428
+ save(path, record)
429
+ else:
430
+ safety_control = operation in {"inspect", "observe", "interrupt"} or (operation == "reconcile" and not args.recover and args.disposition == "retained")
431
+ _, _, state, _ = task_inputs(child_dir, require_authorization=not safety_control)
432
+ if operation == "start":
433
+ admission = state.get("route_dependency_admission") or {}
434
+ if admission.get("admission_state") != "ready":
435
+ from .task_workflow import TaskWorkflowError
436
+ raise TaskWorkflowError("TASK_DELEGATE_ADMISSION_REQUIRED", "current route dependency admission is not ready")
437
+ record, path = current(root, child_dir, require_authorization=not safety_control)
438
+ b = record["binding"]
439
+ if operation == "start":
440
+ if record["status"] == "workspace_created" and not record.get("intent"):
441
+ assert_worktree(record)
442
+ prepare_agent(root, child_dir, record, path)
443
+ print(json.dumps(record, ensure_ascii=False))
444
+ return 0
445
+ if record["status"] != "bound":
446
+ fail("attempt already exists; use inspect/observe/reconcile without creating another writer")
447
+ _, _, state, _ = task_inputs(child_dir)
448
+ admission = state.get("route_dependency_admission") or {}
449
+ if admission.get("admission_state") != "ready" or admission.get("task_route_revision") != state["task_route_revision"] or not admission.get("evidence_refs") or not {"pennix-lifecycle", "paseo", "git"}.issubset(admission.get("dependencies", [])):
450
+ fail("current evidenced Lifecycle/Paseo/Git admission is required")
451
+ observed = adapter(record, "capability", {"cwd": b["target_locator"]})
452
+ record["daemon_identity"] = observed["identity"]
453
+ models = observed.get("models", [])
454
+ modes = observed.get("modes", [])
455
+ if isinstance(models, dict):
456
+ models = models.get("models", [])
457
+ if isinstance(modes, dict):
458
+ modes = modes.get("modes", [])
459
+ selected = next((m for m in models if m.get("id") == record["settings"]["model"]), None)
460
+ if not selected or not any(m.get("id") == "full-access" for m in modes):
461
+ fail("requested Codex model/full-access mode is not available")
462
+ options = selected.get("thinkingOptions", [])
463
+ if not any(o.get("id") == record["settings"]["effort"] for o in options):
464
+ fail("requested effort is not supported by the selected model")
465
+ for existing in inspection_pages(record, {"target": b["target_locator"]}):
466
+ if existing.get("lifecycle", {}).get("autoArchiveAfterMerge") is not False:
467
+ fail("native autoArchiveAfterMerge must be explicitly disabled before delegation; preserve worktrees until owner closeout")
468
+ for agent in existing["agents"]:
469
+ if agent and agent.get("status") not in {"closed", "idle"} and agent.get("cwd") and Path(agent["cwd"]).exists() and identity(Path(agent["cwd"]))["common_dir"] == record["target_identity"]["common_dir"] and git(Path(agent["cwd"]), "branch", "--show-current") == b["execution_branch"]:
470
+ fail("another target writer is active; reconcile before starting")
471
+ if subprocess.run(["git", "show-ref", "--verify", "--quiet", f"refs/heads/{b['execution_branch']}"], cwd=b["target_locator"]).returncode != 1:
472
+ fail("execution branch already exists; do not create or reset it")
473
+ for other in (root / ".trellis/.runtime/delegation").glob("*/record.json"):
474
+ if other != path:
475
+ item = read(other)
476
+ if item.get("target_identity") == record["target_identity"] and item.get("binding", {}).get("execution_branch") == b["execution_branch"] and item.get("status") not in {"bound", "retired"}:
477
+ fail("another controller record owns this target branch")
478
+ record.update({"attempt_id": uuid.uuid4().hex, "status": "starting", "intent": "prepare-workspace"})
479
+ save(path, record)
480
+ workspace = adapter(record, "prepare-workspace", {"target": b["target_locator"], "branch": b["execution_branch"], "base_commit": b["base_commit"], "title": f"trellis-{record['attempt_id']}"})["workspace"]
481
+ if not isinstance(workspace, dict) or not workspace.get("id") or not workspace.get("workspaceDirectory"):
482
+ fail("workspace creation outcome unknown; preserve intent")
483
+ record.update({"workspace_id": workspace["id"], "worktree_path": str(Path(workspace["workspaceDirectory"]).resolve()), "status": "workspace_created"})
484
+ save(path, record)
485
+ assert_worktree(record)
486
+ prepare_agent(root, child_dir, record, path)
487
+ elif operation in {"inspect", "observe", "interrupt"}:
488
+ if operation == "interrupt":
489
+ if record.get("intent"):
490
+ fail("resolve prior intent before interrupt; native emergency cancellation remains available")
491
+ record["intent"] = "interrupt_pending"
492
+ save(path, record)
493
+ observations = adapter(record, "interrupt" if operation == "interrupt" else "observe" if record.get("agent_id") else "inspect", {"agent_id": record["agent_id"], "cwd": record["worktree_path"]} if record.get("agent_id") else {"target": b["target_locator"], **({"workspace_id": record["workspace_id"]} if record.get("workspace_id") else {})})
494
+ if operation == "interrupt":
495
+ record.setdefault("interrupt_receipts", []).append(observations)
496
+ record["intent"] = None
497
+ save(path, record)
498
+ reports = {name: candidate(record, name, current_head=False) for name in ["ready", "result", "blocked"]} if record.get("worktree_path") else {}
499
+ print(json.dumps({"record": record, "observations": observations, "candidates": reports}, ensure_ascii=False))
500
+ return 0
501
+ elif operation in {"execute", "followup"}:
502
+ if record.get("status") != "running" or not record.get("agent_id") or not record.get("workspace_id"):
503
+ fail("execute/followup requires a current running attempt; retired attempts cannot send")
504
+ if record.get("intent"):
505
+ fail("prior creation/send outcome unresolved; inspect and reconcile first")
506
+ observed = adapter(record, "observe", {"agent_id": record["agent_id"], "cwd": record["worktree_path"]})["agent"]
507
+ runtime = observed.get("runtimeInfo") or {}
508
+ if observed.get("activeTurn") or observed.get("status") != "idle" or runtime.get("modeId") != "full-access" or runtime.get("model") != record["settings"]["model"] or runtime.get("thinkingOptionId") != record["settings"]["effort"]:
509
+ fail("agent is active or settings are unverified/drifted")
510
+ ready = candidate(record, "ready", current_head=operation == "execute")
511
+ if not ready or ready.get("missing") != []:
512
+ fail("current ready candidate with no missing requirements required")
513
+ record["ready_evidence"] = ready
514
+ record["execution_permission"] = "implementation"
515
+ context = projection(root, child_dir, record, path)
516
+ message = f"{operation}:重新读取 {context},按当前绑定与许可完成本包并提交 result.json。"
517
+ if operation == "followup":
518
+ message += file_ref(child_dir, args.instructions_ref).read_text(encoding="utf8")
519
+ record["intent"] = "send_pending"
520
+ record["send_pending"] = {"client_message_id": str(uuid.uuid4()), "sha256": digest(message.encode())}
521
+ save(path, record)
522
+ receipt = adapter(record, operation, {"agent_id": record["agent_id"], "cwd": record["worktree_path"], "prompt": message, "client_message_id": record["send_pending"]["client_message_id"]})
523
+ record.setdefault("followup_receipts", []).append({**record.pop("send_pending"), **receipt})
524
+ record["intent"] = None
525
+ save(path, record)
526
+ elif operation == "reconcile":
527
+ if args.recover:
528
+ print(json.dumps(recover(root, child_dir, record, path, args), ensure_ascii=False))
529
+ return 0
530
+ if record.get("status") == "retired":
531
+ print(json.dumps(record, ensure_ascii=False)); return 0
532
+ if not record.get("agent_id"):
533
+ fail("partial creation requires explicit native resource mapping before retirement; preserve intent")
534
+ observation = adapter(record, "observe", {"agent_id": record["agent_id"], "cwd": record["worktree_path"]})
535
+ agent = observation["agent"]
536
+ if not agent or agent.get("activeTurn") or agent.get("status") not in {"idle", "closed"}:
537
+ fail("native writer is active or unknown")
538
+ result = candidate(record, "result")
539
+ if not result and args.disposition != "retained":
540
+ fail("bounded result and preserved source evidence required before retirement")
541
+ if result:
542
+ clean_result(record, result)
543
+ if args.disposition == "integrated":
544
+ if result is None:
545
+ fail("integrated closure requires a result")
546
+ git(Path(b["target_locator"]), "merge-base", "--is-ancestor", result["head_commit"], b["integration_branch"])
547
+ tree = assert_worktree(record)
548
+ evidence = {"result": result, "observation": observation, "disposition": args.disposition, "preserved_worktree": str(tree), "head_commit": git(tree, "rev-parse", "HEAD"), "git_status": git(tree, "status", "--porcelain", "--untracked-files=all")}
549
+ if not args.execute:
550
+ print(json.dumps({"status": "ready", "evidence": evidence}, ensure_ascii=False)); return 0
551
+ if not args.reason or not args.approval_ref or not args.writer_evidence_ref:
552
+ fail("reason, approval-ref and controller-owned writer-evidence-ref required; idle/cancel alone do not prove background writers stopped")
553
+ evidence["writer_evidence"] = file_ref(child_dir, args.writer_evidence_ref).read_text(encoding="utf8")
554
+ record.update({"status": "retired", "intent": None, "result_evidence": result, "closure_evidence": {**evidence, "reason": args.reason, "approval_ref": args.approval_ref}})
555
+ save(path, record)
556
+ else:
557
+ fail("unsupported delegation operation")
558
+ print(json.dumps(record, ensure_ascii=False))
559
+ return 0
560
+
561
+
562
+ def node_context() -> dict | None:
563
+ raw = os.environ.get("TRELLIS_DELEGATION_CONTEXT")
564
+ if not raw:
565
+ return None
566
+ context = read(Path(raw))
567
+ record = read(Path(context["record_ref"]))
568
+ if context.get("version") != 1 or record.get("status") == "retired" or context.get("attempt_id") != record.get("attempt_id") or context.get("binding_revision") != record.get("binding", {}).get("binding_revision") or context.get("agent_id") != os.environ.get("PASEO_AGENT_ID") or not context.get("agent_id") or git(Path.cwd(), "rev-parse", "--show-toplevel") != str(Path(context.get("target", "")).resolve()):
569
+ fail("delegated context/resource/cwd is missing, stale or mismatched; do not enter ordinary controller workflow")
570
+ assert_worktree(record)
571
+ if context.get("execution_permission") != record.get("execution_permission") or context.get("binding") != record.get("binding") or context.get("target") != record.get("worktree_path"):
572
+ fail("delegated execution projection is stale")
573
+ control = Path(context["control_task"])
574
+ child = read(control / "task.json")
575
+ from .task_utils import resolve_task_dir
576
+ parent_dir = resolve_task_dir(child["parent"], Path(context["control_root"]))
577
+ if parent_dir is None:
578
+ fail("current parent task is missing")
579
+ parent = read(parent_dir / "task.json")
580
+ state = parent.get("meta", {}).get("task_workflow", {})
581
+ b = record["binding"]
582
+ auth = state.get("implementation_authorization") or {}
583
+ if parent.get("status") != "in_progress" or state.get("current_phase_id") != "task_implementation" or state.get("task_route_revision") != b["parent_route_revision"] or auth.get("contract_revision") != b["parent_contract_revision"]:
584
+ fail("parent authorization changed; stop delegated implementation")
585
+ from .task_workflow import implementation_start_ready
586
+ if not implementation_start_ready(parent, parent_dir):
587
+ fail("parent implementation contract is no longer current")
588
+ if b.get("format_version") != 2:
589
+ fail("incomplete legacy binding; stop and ask the controller to retain/rebind")
590
+ inputs = [(control, "prd.md", "contract"), (control, b["settings_ref"], "settings"), (control, b["requirements_ref"], "requirements"), (Path(context["control_root"]), ".trellis/agents/delegated-worktree-primary-agent.md", "role"), (Path(context["control_root"]), ".trellis/agents/worktree-delegation-node.md", "node_method")]
591
+ if record["requirements"].get("setup_ref"):
592
+ inputs.append((control, record["requirements"]["setup_ref"], "setup"))
593
+ for directory, ref, name in inputs:
594
+ key = f"{name}_sha256"
595
+ if digest(file_ref(directory, ref).read_bytes()) != b[key]:
596
+ fail("delegated input changed; wait for controller revalidation")
597
+ if name not in {"settings", "requirements"}:
598
+ expected = Path(context["record_ref"]).parent / "inputs" / record["attempt_id"] / f"{name}.md"
599
+ if context.get(f"{name}_ref") != str(expected) or digest(file_ref(expected.parent, expected.name).read_bytes()) != b[key]:
600
+ fail("delegated frozen snapshot is missing, redirected or stale")
601
+ if context.get("requirements") != record["requirements"] or context.get("settings") != record["settings"]:
602
+ fail("delegated inline inputs are stale")
603
+ return context