@pennixrv/trellis 0.7.2-beta.3 → 0.7.2-beta.31

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 (477) hide show
  1. package/README.md +14 -0
  2. package/dist/cli/index.js +4 -0
  3. package/dist/cli/index.js.map +1 -1
  4. package/dist/commands/ablate.d.ts.map +1 -1
  5. package/dist/commands/ablate.js +13 -0
  6. package/dist/commands/ablate.js.map +1 -1
  7. package/dist/commands/init.d.ts +2 -0
  8. package/dist/commands/init.d.ts.map +1 -1
  9. package/dist/commands/init.js +138 -120
  10. package/dist/commands/init.js.map +1 -1
  11. package/dist/commands/teamwork/adapters/acp.d.ts.map +1 -1
  12. package/dist/commands/teamwork/adapters/acp.js +3 -0
  13. package/dist/commands/teamwork/adapters/acp.js.map +1 -1
  14. package/dist/commands/teamwork/adapters/index.d.ts +1 -1
  15. package/dist/commands/teamwork/adapters/index.d.ts.map +1 -1
  16. package/dist/commands/teamwork/artifact.d.ts +2 -0
  17. package/dist/commands/teamwork/artifact.d.ts.map +1 -1
  18. package/dist/commands/teamwork/artifact.js +4 -2
  19. package/dist/commands/teamwork/artifact.js.map +1 -1
  20. package/dist/commands/teamwork/batch-reservation.d.ts.map +1 -1
  21. package/dist/commands/teamwork/batch-reservation.js +16 -8
  22. package/dist/commands/teamwork/batch-reservation.js.map +1 -1
  23. package/dist/commands/teamwork/batch.d.ts +15 -1
  24. package/dist/commands/teamwork/batch.d.ts.map +1 -1
  25. package/dist/commands/teamwork/batch.js +279 -24
  26. package/dist/commands/teamwork/batch.js.map +1 -1
  27. package/dist/commands/teamwork/coordinator.d.ts +3 -0
  28. package/dist/commands/teamwork/coordinator.d.ts.map +1 -1
  29. package/dist/commands/teamwork/coordinator.js +22 -3
  30. package/dist/commands/teamwork/coordinator.js.map +1 -1
  31. package/dist/commands/teamwork/create.d.ts +1 -0
  32. package/dist/commands/teamwork/create.d.ts.map +1 -1
  33. package/dist/commands/teamwork/create.js +4 -0
  34. package/dist/commands/teamwork/create.js.map +1 -1
  35. package/dist/commands/teamwork/evidence-references.d.ts +19 -0
  36. package/dist/commands/teamwork/evidence-references.d.ts.map +1 -0
  37. package/dist/commands/teamwork/evidence-references.js +249 -0
  38. package/dist/commands/teamwork/evidence-references.js.map +1 -0
  39. package/dist/commands/teamwork/foreground-wait.d.ts +4 -1
  40. package/dist/commands/teamwork/foreground-wait.d.ts.map +1 -1
  41. package/dist/commands/teamwork/foreground-wait.js +15 -1
  42. package/dist/commands/teamwork/foreground-wait.js.map +1 -1
  43. package/dist/commands/teamwork/index.d.ts.map +1 -1
  44. package/dist/commands/teamwork/index.js +47 -5
  45. package/dist/commands/teamwork/index.js.map +1 -1
  46. package/dist/commands/teamwork/list.d.ts +1 -0
  47. package/dist/commands/teamwork/list.d.ts.map +1 -1
  48. package/dist/commands/teamwork/list.js +4 -1
  49. package/dist/commands/teamwork/list.js.map +1 -1
  50. package/dist/commands/teamwork/prompt.js +1 -1
  51. package/dist/commands/teamwork/prompt.js.map +1 -1
  52. package/dist/commands/teamwork/rm.d.ts +27 -4
  53. package/dist/commands/teamwork/rm.d.ts.map +1 -1
  54. package/dist/commands/teamwork/rm.js +155 -51
  55. package/dist/commands/teamwork/rm.js.map +1 -1
  56. package/dist/commands/teamwork/run.d.ts.map +1 -1
  57. package/dist/commands/teamwork/run.js +10 -1
  58. package/dist/commands/teamwork/run.js.map +1 -1
  59. package/dist/commands/teamwork/runtime.d.ts +1 -1
  60. package/dist/commands/teamwork/runtime.d.ts.map +1 -1
  61. package/dist/commands/teamwork/runtime.js +14 -4
  62. package/dist/commands/teamwork/runtime.js.map +1 -1
  63. package/dist/commands/teamwork/spawn.d.ts.map +1 -1
  64. package/dist/commands/teamwork/spawn.js +4 -1
  65. package/dist/commands/teamwork/spawn.js.map +1 -1
  66. package/dist/commands/teamwork/supervisor/stdout.d.ts.map +1 -1
  67. package/dist/commands/teamwork/supervisor/stdout.js +7 -0
  68. package/dist/commands/teamwork/supervisor/stdout.js.map +1 -1
  69. package/dist/commands/teamwork/supervisor.d.ts +1 -1
  70. package/dist/commands/teamwork/supervisor.d.ts.map +1 -1
  71. package/dist/commands/teamwork/teammate-adapters.d.ts +3 -0
  72. package/dist/commands/teamwork/teammate-adapters.d.ts.map +1 -1
  73. package/dist/commands/teamwork/teammate-adapters.js +14 -5
  74. package/dist/commands/teamwork/teammate-adapters.js.map +1 -1
  75. package/dist/commands/teamwork/teammate-launch.d.ts +3 -1
  76. package/dist/commands/teamwork/teammate-launch.d.ts.map +1 -1
  77. package/dist/commands/teamwork/teammate-launch.js +7 -5
  78. package/dist/commands/teamwork/teammate-launch.js.map +1 -1
  79. package/dist/commands/teamwork/workers.d.ts +8 -0
  80. package/dist/commands/teamwork/workers.d.ts.map +1 -0
  81. package/dist/commands/teamwork/workers.js +67 -0
  82. package/dist/commands/teamwork/workers.js.map +1 -0
  83. package/dist/commands/update.d.ts.map +1 -1
  84. package/dist/commands/update.js +188 -59
  85. package/dist/commands/update.js.map +1 -1
  86. package/dist/commands/workflow.d.ts.map +1 -1
  87. package/dist/commands/workflow.js +5 -7
  88. package/dist/commands/workflow.js.map +1 -1
  89. package/dist/configurators/codebuddy.d.ts +1 -8
  90. package/dist/configurators/codebuddy.d.ts.map +1 -1
  91. package/dist/configurators/codebuddy.js +2 -12
  92. package/dist/configurators/codebuddy.js.map +1 -1
  93. package/dist/configurators/codex.d.ts +0 -36
  94. package/dist/configurators/codex.d.ts.map +1 -1
  95. package/dist/configurators/codex.js +13 -106
  96. package/dist/configurators/codex.js.map +1 -1
  97. package/dist/configurators/copilot.d.ts +1 -12
  98. package/dist/configurators/copilot.d.ts.map +1 -1
  99. package/dist/configurators/copilot.js +2 -20
  100. package/dist/configurators/copilot.js.map +1 -1
  101. package/dist/configurators/cursor.d.ts +1 -8
  102. package/dist/configurators/cursor.d.ts.map +1 -1
  103. package/dist/configurators/cursor.js +2 -12
  104. package/dist/configurators/cursor.js.map +1 -1
  105. package/dist/configurators/droid.d.ts +1 -8
  106. package/dist/configurators/droid.d.ts.map +1 -1
  107. package/dist/configurators/droid.js +2 -12
  108. package/dist/configurators/droid.js.map +1 -1
  109. package/dist/configurators/dsh.d.ts +1 -21
  110. package/dist/configurators/dsh.d.ts.map +1 -1
  111. package/dist/configurators/dsh.js +4 -37
  112. package/dist/configurators/dsh.js.map +1 -1
  113. package/dist/configurators/gemini.d.ts +1 -16
  114. package/dist/configurators/gemini.d.ts.map +1 -1
  115. package/dist/configurators/gemini.js +3 -21
  116. package/dist/configurators/gemini.js.map +1 -1
  117. package/dist/configurators/grok.d.ts +1 -12
  118. package/dist/configurators/grok.d.ts.map +1 -1
  119. package/dist/configurators/grok.js +2 -18
  120. package/dist/configurators/grok.js.map +1 -1
  121. package/dist/configurators/kimi.d.ts +1 -21
  122. package/dist/configurators/kimi.d.ts.map +1 -1
  123. package/dist/configurators/kimi.js +2 -38
  124. package/dist/configurators/kimi.js.map +1 -1
  125. package/dist/configurators/kiro.d.ts +1 -9
  126. package/dist/configurators/kiro.d.ts.map +1 -1
  127. package/dist/configurators/kiro.js +1 -9
  128. package/dist/configurators/kiro.js.map +1 -1
  129. package/dist/configurators/omp.d.ts.map +1 -1
  130. package/dist/configurators/omp.js +1 -5
  131. package/dist/configurators/omp.js.map +1 -1
  132. package/dist/configurators/pi.d.ts.map +1 -1
  133. package/dist/configurators/pi.js +2 -5
  134. package/dist/configurators/pi.js.map +1 -1
  135. package/dist/configurators/qoder.d.ts +1 -10
  136. package/dist/configurators/qoder.d.ts.map +1 -1
  137. package/dist/configurators/qoder.js +3 -15
  138. package/dist/configurators/qoder.js.map +1 -1
  139. package/dist/configurators/reasonix.d.ts +1 -12
  140. package/dist/configurators/reasonix.d.ts.map +1 -1
  141. package/dist/configurators/reasonix.js +3 -22
  142. package/dist/configurators/reasonix.js.map +1 -1
  143. package/dist/configurators/shared.d.ts +1 -24
  144. package/dist/configurators/shared.d.ts.map +1 -1
  145. package/dist/configurators/shared.js +5 -184
  146. package/dist/configurators/shared.js.map +1 -1
  147. package/dist/configurators/snow.d.ts +1 -20
  148. package/dist/configurators/snow.d.ts.map +1 -1
  149. package/dist/configurators/snow.js +2 -25
  150. package/dist/configurators/snow.js.map +1 -1
  151. package/dist/configurators/trae.d.ts +1 -14
  152. package/dist/configurators/trae.d.ts.map +1 -1
  153. package/dist/configurators/trae.js +3 -19
  154. package/dist/configurators/trae.js.map +1 -1
  155. package/dist/configurators/workflow.d.ts +5 -0
  156. package/dist/configurators/workflow.d.ts.map +1 -1
  157. package/dist/configurators/workflow.js +85 -57
  158. package/dist/configurators/workflow.js.map +1 -1
  159. package/dist/configurators/zcode.d.ts +1 -13
  160. package/dist/configurators/zcode.d.ts.map +1 -1
  161. package/dist/configurators/zcode.js +2 -18
  162. package/dist/configurators/zcode.js.map +1 -1
  163. package/dist/migrations/manifests/0.5.0-beta.5.json +1 -212
  164. package/dist/migrations/manifests/0.7.2-beta.10.json +9 -0
  165. package/dist/migrations/manifests/0.7.2-beta.11.json +9 -0
  166. package/dist/migrations/manifests/0.7.2-beta.12.json +9 -0
  167. package/dist/migrations/manifests/0.7.2-beta.13.json +9 -0
  168. package/dist/migrations/manifests/0.7.2-beta.14.json +9 -0
  169. package/dist/migrations/manifests/0.7.2-beta.15.json +9 -0
  170. package/dist/migrations/manifests/0.7.2-beta.16.json +9 -0
  171. package/dist/migrations/manifests/0.7.2-beta.17.json +9 -0
  172. package/dist/migrations/manifests/0.7.2-beta.18.json +9 -0
  173. package/dist/migrations/manifests/0.7.2-beta.19.json +11 -0
  174. package/dist/migrations/manifests/0.7.2-beta.20.json +9 -0
  175. package/dist/migrations/manifests/0.7.2-beta.21.json +9 -0
  176. package/dist/migrations/manifests/0.7.2-beta.22.json +9 -0
  177. package/dist/migrations/manifests/0.7.2-beta.23.json +9 -0
  178. package/dist/migrations/manifests/0.7.2-beta.24.json +8 -0
  179. package/dist/migrations/manifests/0.7.2-beta.25.json +8 -0
  180. package/dist/migrations/manifests/0.7.2-beta.26.json +8 -0
  181. package/dist/migrations/manifests/0.7.2-beta.27.json +8 -0
  182. package/dist/migrations/manifests/0.7.2-beta.28.json +8 -0
  183. package/dist/migrations/manifests/0.7.2-beta.29.json +8 -0
  184. package/dist/migrations/manifests/0.7.2-beta.30.json +10 -0
  185. package/dist/migrations/manifests/0.7.2-beta.31.json +9 -0
  186. package/dist/migrations/manifests/0.7.2-beta.4.json +9 -0
  187. package/dist/migrations/manifests/0.7.2-beta.5.json +9 -0
  188. package/dist/migrations/manifests/0.7.2-beta.6.json +9 -0
  189. package/dist/migrations/manifests/0.7.2-beta.7.json +9 -0
  190. package/dist/migrations/manifests/0.7.2-beta.8.json +9 -0
  191. package/dist/migrations/manifests/0.7.2-beta.9.json +9 -0
  192. package/dist/migrations/retired-native-paths.d.ts +109 -0
  193. package/dist/migrations/retired-native-paths.d.ts.map +1 -0
  194. package/dist/migrations/retired-native-paths.js +263 -0
  195. package/dist/migrations/retired-native-paths.js.map +1 -0
  196. package/dist/templates/claude/index.d.ts +1 -16
  197. package/dist/templates/claude/index.d.ts.map +1 -1
  198. package/dist/templates/claude/index.js +5 -32
  199. package/dist/templates/claude/index.js.map +1 -1
  200. package/dist/templates/claude/settings.json +0 -22
  201. package/dist/templates/codebuddy/index.d.ts +2 -3
  202. package/dist/templates/codebuddy/index.d.ts.map +1 -1
  203. package/dist/templates/codebuddy/index.js +2 -3
  204. package/dist/templates/codebuddy/index.js.map +1 -1
  205. package/dist/templates/codebuddy/settings.json +0 -10
  206. package/dist/templates/codex/config.toml +4 -19
  207. package/dist/templates/codex/hooks/session-start.py +25 -30
  208. package/dist/templates/codex/hooks/turn-guard.py +74 -0
  209. package/dist/templates/codex/hooks.json +57 -6
  210. package/dist/templates/codex/index.d.ts +0 -5
  211. package/dist/templates/codex/index.d.ts.map +1 -1
  212. package/dist/templates/codex/index.js +0 -13
  213. package/dist/templates/codex/index.js.map +1 -1
  214. package/dist/templates/common/bundled-skills/trellis-decision-space-construction-and-merging/SKILL.md +2 -0
  215. package/dist/templates/common/bundled-skills/trellis-decision-space-construction-and-merging/workflow.md +13 -3
  216. package/dist/templates/common/bundled-skills/trellis-delivery-review-and-closeout/SKILL.md +2 -0
  217. package/dist/templates/common/bundled-skills/trellis-delivery-review-and-closeout/workflow.md +17 -9
  218. package/dist/templates/common/bundled-skills/trellis-goal-exploration-and-requirements/SKILL.md +2 -0
  219. package/dist/templates/common/bundled-skills/trellis-goal-exploration-and-requirements/workflow.md +7 -3
  220. package/dist/templates/common/bundled-skills/trellis-meta/SKILL.md +7 -7
  221. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-agents.md +9 -51
  222. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-context-loading.md +3 -15
  223. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-hooks.md +1 -2
  224. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/bundled-skills.md +1 -1
  225. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/context-injection.md +4 -9
  226. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/generated-files.md +2 -2
  227. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/multi-agent-teamwork.md +6 -0
  228. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/overview.md +1 -1
  229. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/spec-system.md +10 -8
  230. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/agents.md +9 -79
  231. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/hooks-and-settings.md +2 -4
  232. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/overview.md +3 -6
  233. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/platform-map.md +24 -103
  234. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/skills-and-commands.md +1 -1
  235. package/dist/templates/common/bundled-skills/trellis-session-insight/SKILL.md +1 -1
  236. package/dist/templates/common/bundled-skills/trellis-solution-design-and-convergence/SKILL.md +2 -0
  237. package/dist/templates/common/bundled-skills/trellis-solution-design-and-convergence/workflow.md +27 -6
  238. package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/SKILL.md +9 -7
  239. package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/references/mcp-setup.md +12 -84
  240. package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/references/repository-analysis.md +5 -25
  241. package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/references/spec-task-planning.md +5 -9
  242. package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/references/spec-writing.md +8 -0
  243. package/dist/templates/common/bundled-skills/trellis-task-implementation/SKILL.md +2 -0
  244. package/dist/templates/common/bundled-skills/trellis-task-implementation/workflow.md +7 -3
  245. package/dist/templates/common/bundled-skills/trellis-teamwork/SKILL.md +8 -1
  246. package/dist/templates/common/bundled-skills/trellis-teamwork/references/teammate-processes.md +21 -1
  247. package/dist/templates/common/bundled-skills/trellis-teamwork/references/teamwork-plan-construction.md +13 -2
  248. package/dist/templates/common/bundled-skills/trellis-worktree-delegation/SKILL.md +14 -0
  249. package/dist/templates/common/bundled-skills/trellis-worktree-delegation/workflow.md +86 -0
  250. package/dist/templates/common/commands/continue.md +16 -1
  251. package/dist/templates/common/commands/start.md +2 -0
  252. package/dist/templates/common/skills/before-dev.md +3 -1
  253. package/dist/templates/common/skills/check.md +3 -1
  254. package/dist/templates/common/skills/request-intake.md +14 -1
  255. package/dist/templates/copilot/hooks/session-start.py +11 -30
  256. package/dist/templates/cursor/hooks.json +0 -7
  257. package/dist/templates/cursor/index.d.ts +1 -11
  258. package/dist/templates/cursor/index.d.ts.map +1 -1
  259. package/dist/templates/cursor/index.js +2 -10
  260. package/dist/templates/cursor/index.js.map +1 -1
  261. package/dist/templates/droid/index.d.ts +2 -3
  262. package/dist/templates/droid/index.d.ts.map +1 -1
  263. package/dist/templates/droid/index.js +2 -3
  264. package/dist/templates/droid/index.js.map +1 -1
  265. package/dist/templates/droid/settings.json +0 -10
  266. package/dist/templates/dsh/DSH.md +2 -33
  267. package/dist/templates/dsh/index.d.ts +1 -19
  268. package/dist/templates/dsh/index.d.ts.map +1 -1
  269. package/dist/templates/dsh/index.js +2 -21
  270. package/dist/templates/dsh/index.js.map +1 -1
  271. package/dist/templates/gemini/index.d.ts +1 -11
  272. package/dist/templates/gemini/index.d.ts.map +1 -1
  273. package/dist/templates/gemini/index.js +2 -10
  274. package/dist/templates/gemini/index.js.map +1 -1
  275. package/dist/templates/kiro/index.d.ts +1 -13
  276. package/dist/templates/kiro/index.d.ts.map +1 -1
  277. package/dist/templates/kiro/index.js +1 -13
  278. package/dist/templates/kiro/index.js.map +1 -1
  279. package/dist/templates/markdown/agents.md +9 -14
  280. package/dist/templates/markdown/index.d.ts +1 -0
  281. package/dist/templates/markdown/index.d.ts.map +1 -1
  282. package/dist/templates/markdown/index.js +1 -0
  283. package/dist/templates/markdown/index.js.map +1 -1
  284. package/dist/templates/markdown/spec/index.md.txt +20 -0
  285. package/dist/templates/omp/extensions/trellis/index.ts.txt +27 -60
  286. package/dist/templates/omp/index.d.ts +0 -2
  287. package/dist/templates/omp/index.d.ts.map +1 -1
  288. package/dist/templates/omp/index.js +1 -4
  289. package/dist/templates/omp/index.js.map +1 -1
  290. package/dist/templates/opencode/lib/session-utils.js +17 -5
  291. package/dist/templates/opencode/lib/trellis-context.js +12 -321
  292. package/dist/templates/opencode/plugins/inject-shell-session-context.js +93 -0
  293. package/dist/templates/opencode/plugins/inject-workflow-state.js +19 -17
  294. package/dist/templates/opencode/plugins/session-start.js +2 -6
  295. package/dist/templates/pi/extensions/trellis/index.ts.txt +17 -1436
  296. package/dist/templates/pi/index.d.ts +1 -2
  297. package/dist/templates/pi/index.d.ts.map +1 -1
  298. package/dist/templates/pi/index.js +2 -5
  299. package/dist/templates/pi/index.js.map +1 -1
  300. package/dist/templates/qoder/index.d.ts +2 -3
  301. package/dist/templates/qoder/index.d.ts.map +1 -1
  302. package/dist/templates/qoder/index.js +2 -3
  303. package/dist/templates/qoder/index.js.map +1 -1
  304. package/dist/templates/shared-hooks/guard-teamwork-wait.py +118 -12
  305. package/dist/templates/shared-hooks/index.d.ts +2 -56
  306. package/dist/templates/shared-hooks/index.d.ts.map +1 -1
  307. package/dist/templates/shared-hooks/index.js +4 -70
  308. package/dist/templates/shared-hooks/index.js.map +1 -1
  309. package/dist/templates/shared-hooks/inject-shell-session-context.py +46 -1
  310. package/dist/templates/shared-hooks/inject-spec-context.py +6 -35
  311. package/dist/templates/shared-hooks/inject-workflow-state.py +66 -104
  312. package/dist/templates/shared-hooks/session-start.py +8 -6
  313. package/dist/templates/snow/SNOW.md +6 -18
  314. package/dist/templates/snow/hooks/write-trellis-context.py +51 -133
  315. package/dist/templates/snow/index.d.ts +2 -21
  316. package/dist/templates/snow/index.d.ts.map +1 -1
  317. package/dist/templates/snow/index.js +3 -24
  318. package/dist/templates/snow/index.js.map +1 -1
  319. package/dist/templates/template-utils.d.ts +1 -2
  320. package/dist/templates/template-utils.d.ts.map +1 -1
  321. package/dist/templates/template-utils.js +1 -11
  322. package/dist/templates/template-utils.js.map +1 -1
  323. package/dist/templates/trae/index.d.ts +2 -3
  324. package/dist/templates/trae/index.d.ts.map +1 -1
  325. package/dist/templates/trae/index.js +2 -3
  326. package/dist/templates/trae/index.js.map +1 -1
  327. package/dist/templates/trellis/agents/delegated-worktree-primary-agent.md +22 -22
  328. package/dist/templates/trellis/agents/teammate.md +6 -2
  329. package/dist/templates/trellis/agents/worktree-delegation-node.md +32 -0
  330. package/dist/templates/trellis/config.yaml +7 -36
  331. package/dist/templates/trellis/gitignore.txt +4 -0
  332. package/dist/templates/trellis/index.d.ts +1 -0
  333. package/dist/templates/trellis/index.d.ts.map +1 -1
  334. package/dist/templates/trellis/index.js +9 -0
  335. package/dist/templates/trellis/index.js.map +1 -1
  336. package/dist/templates/trellis/scripts/common/active_task.py +23 -31
  337. package/dist/templates/trellis/scripts/common/config.py +16 -36
  338. package/dist/templates/trellis/scripts/common/git_context.py +13 -4
  339. package/dist/templates/trellis/scripts/common/io.py +2 -2
  340. package/dist/templates/trellis/scripts/common/markdown_format.py +107 -0
  341. package/dist/templates/trellis/scripts/common/packages_context.py +29 -1
  342. package/dist/templates/trellis/scripts/common/session_context.py +25 -50
  343. package/dist/templates/trellis/scripts/common/task_context.py +5 -3
  344. package/dist/templates/trellis/scripts/common/task_continuity.py +66 -9
  345. package/dist/templates/trellis/scripts/common/task_move.py +11 -5
  346. package/dist/templates/trellis/scripts/common/task_runtime.py +211 -0
  347. package/dist/templates/trellis/scripts/common/task_store.py +12 -82
  348. package/dist/templates/trellis/scripts/common/task_turn.py +518 -0
  349. package/dist/templates/trellis/scripts/common/task_workflow.py +383 -395
  350. package/dist/templates/trellis/scripts/common/workflow_phase.py +3 -36
  351. package/dist/templates/trellis/scripts/common/workflow_selection.py +35 -40
  352. package/dist/templates/trellis/scripts/common/worktree_delegation.py +690 -0
  353. package/dist/templates/trellis/scripts/common/worktree_delegation_contract.py +446 -0
  354. package/dist/templates/trellis/scripts/common/worktree_delegation_messages.py +376 -0
  355. package/dist/templates/trellis/scripts/common/worktree_delegation_transport.py +57 -0
  356. package/dist/templates/trellis/scripts/markdown_format.py +40 -0
  357. package/dist/templates/trellis/scripts/task.py +73 -10
  358. package/dist/templates/trellis/workflow.md +52 -11
  359. package/dist/templates/zcode/config.json +0 -10
  360. package/dist/templates/zcode/index.d.ts +3 -22
  361. package/dist/templates/zcode/index.d.ts.map +1 -1
  362. package/dist/templates/zcode/index.js +3 -24
  363. package/dist/templates/zcode/index.js.map +1 -1
  364. package/dist/types/ai-tools.d.ts +0 -4
  365. package/dist/types/ai-tools.d.ts.map +1 -1
  366. package/dist/types/ai-tools.js +4 -109
  367. package/dist/types/ai-tools.js.map +1 -1
  368. package/dist/utils/ablation-store.d.ts.map +1 -1
  369. package/dist/utils/ablation-store.js +41 -1
  370. package/dist/utils/ablation-store.js.map +1 -1
  371. package/dist/utils/asset-backup.d.ts +1 -0
  372. package/dist/utils/asset-backup.d.ts.map +1 -1
  373. package/dist/utils/asset-backup.js +131 -31
  374. package/dist/utils/asset-backup.js.map +1 -1
  375. package/dist/utils/atomic-write.d.ts +1 -1
  376. package/dist/utils/atomic-write.d.ts.map +1 -1
  377. package/dist/utils/atomic-write.js +8 -2
  378. package/dist/utils/atomic-write.js.map +1 -1
  379. package/dist/utils/codex-config-ownership.d.ts +13 -0
  380. package/dist/utils/codex-config-ownership.d.ts.map +1 -0
  381. package/dist/utils/codex-config-ownership.js +64 -0
  382. package/dist/utils/codex-config-ownership.js.map +1 -0
  383. package/dist/utils/file-writer.d.ts +2 -0
  384. package/dist/utils/file-writer.d.ts.map +1 -1
  385. package/dist/utils/file-writer.js +1 -1
  386. package/dist/utils/file-writer.js.map +1 -1
  387. package/dist/utils/managed-markdown.d.ts +5 -0
  388. package/dist/utils/managed-markdown.d.ts.map +1 -0
  389. package/dist/utils/managed-markdown.js +64 -0
  390. package/dist/utils/managed-markdown.js.map +1 -0
  391. package/dist/utils/managed-removal.d.ts +2 -0
  392. package/dist/utils/managed-removal.d.ts.map +1 -1
  393. package/dist/utils/managed-removal.js +62 -8
  394. package/dist/utils/managed-removal.js.map +1 -1
  395. package/dist/utils/manifest-prune.d.ts.map +1 -1
  396. package/dist/utils/manifest-prune.js +5 -12
  397. package/dist/utils/manifest-prune.js.map +1 -1
  398. package/dist/utils/project-init.d.ts +26 -0
  399. package/dist/utils/project-init.d.ts.map +1 -0
  400. package/dist/utils/project-init.js +484 -0
  401. package/dist/utils/project-init.js.map +1 -0
  402. package/dist/utils/retired-native-assets.d.ts +17 -0
  403. package/dist/utils/retired-native-assets.d.ts.map +1 -0
  404. package/dist/utils/retired-native-assets.js +221 -0
  405. package/dist/utils/retired-native-assets.js.map +1 -0
  406. package/dist/utils/uninstall-scrubbers.d.ts.map +1 -1
  407. package/dist/utils/uninstall-scrubbers.js +6 -12
  408. package/dist/utils/uninstall-scrubbers.js.map +1 -1
  409. package/package.json +2 -2
  410. package/dist/templates/claude/agents/trellis-check.md +0 -115
  411. package/dist/templates/claude/agents/trellis-implement.md +0 -110
  412. package/dist/templates/claude/agents/trellis-research.md +0 -137
  413. package/dist/templates/codebuddy/agents/trellis-check.md +0 -115
  414. package/dist/templates/codebuddy/agents/trellis-implement.md +0 -110
  415. package/dist/templates/codebuddy/agents/trellis-research.md +0 -137
  416. package/dist/templates/codex/agents/trellis-check.toml +0 -56
  417. package/dist/templates/codex/agents/trellis-implement.toml +0 -37
  418. package/dist/templates/codex/agents/trellis-research.toml +0 -78
  419. package/dist/templates/cursor/agents/trellis-check.md +0 -114
  420. package/dist/templates/cursor/agents/trellis-implement.md +0 -109
  421. package/dist/templates/cursor/agents/trellis-research.md +0 -136
  422. package/dist/templates/droid/droids/trellis-check.md +0 -107
  423. package/dist/templates/droid/droids/trellis-implement.md +0 -102
  424. package/dist/templates/droid/droids/trellis-research.md +0 -137
  425. package/dist/templates/dsh/agents/trellis-check.md +0 -99
  426. package/dist/templates/dsh/agents/trellis-implement.md +0 -106
  427. package/dist/templates/dsh/agents/trellis-research.md +0 -134
  428. package/dist/templates/gemini/agents/trellis-check.md +0 -107
  429. package/dist/templates/gemini/agents/trellis-implement.md +0 -102
  430. package/dist/templates/gemini/agents/trellis-research.md +0 -136
  431. package/dist/templates/grok/agents/trellis-check.md +0 -105
  432. package/dist/templates/grok/agents/trellis-implement.md +0 -116
  433. package/dist/templates/grok/agents/trellis-research.md +0 -146
  434. package/dist/templates/grok/index.d.ts +0 -16
  435. package/dist/templates/grok/index.d.ts.map +0 -1
  436. package/dist/templates/grok/index.js +0 -19
  437. package/dist/templates/grok/index.js.map +0 -1
  438. package/dist/templates/kimi/agents/trellis-check.md +0 -103
  439. package/dist/templates/kimi/agents/trellis-implement.md +0 -115
  440. package/dist/templates/kimi/agents/trellis-research.md +0 -144
  441. package/dist/templates/kimi/index.d.ts +0 -20
  442. package/dist/templates/kimi/index.d.ts.map +0 -1
  443. package/dist/templates/kimi/index.js +0 -23
  444. package/dist/templates/kimi/index.js.map +0 -1
  445. package/dist/templates/kiro/agents/trellis-check.json +0 -26
  446. package/dist/templates/kiro/agents/trellis-implement.json +0 -26
  447. package/dist/templates/kiro/agents/trellis-research.json +0 -30
  448. package/dist/templates/omp/agents/trellis-check.md +0 -41
  449. package/dist/templates/omp/agents/trellis-implement.md +0 -45
  450. package/dist/templates/omp/agents/trellis-research.md +0 -30
  451. package/dist/templates/opencode/agents/trellis-check.md +0 -122
  452. package/dist/templates/opencode/agents/trellis-implement.md +0 -118
  453. package/dist/templates/opencode/agents/trellis-research.md +0 -145
  454. package/dist/templates/opencode/plugins/inject-subagent-context.js +0 -569
  455. package/dist/templates/pi/agents/trellis-check.md +0 -37
  456. package/dist/templates/pi/agents/trellis-implement.md +0 -42
  457. package/dist/templates/pi/agents/trellis-research.md +0 -25
  458. package/dist/templates/qoder/agents/trellis-check.md +0 -108
  459. package/dist/templates/qoder/agents/trellis-implement.md +0 -103
  460. package/dist/templates/qoder/agents/trellis-research.md +0 -137
  461. package/dist/templates/reasonix/agents/trellis-check.md +0 -36
  462. package/dist/templates/reasonix/agents/trellis-implement.md +0 -41
  463. package/dist/templates/reasonix/index.d.ts +0 -13
  464. package/dist/templates/reasonix/index.d.ts.map +0 -1
  465. package/dist/templates/reasonix/index.js +0 -16
  466. package/dist/templates/reasonix/index.js.map +0 -1
  467. package/dist/templates/shared-hooks/inject-subagent-context.py +0 -1217
  468. package/dist/templates/snow/agents/trellis-check.md +0 -135
  469. package/dist/templates/snow/agents/trellis-implement.md +0 -153
  470. package/dist/templates/snow/agents/trellis-research.md +0 -114
  471. package/dist/templates/snow/hooks/beforeSubAgentStart.json +0 -15
  472. package/dist/templates/trae/agents/trellis-check.md +0 -108
  473. package/dist/templates/trae/agents/trellis-implement.md +0 -103
  474. package/dist/templates/trae/agents/trellis-research.md +0 -137
  475. package/dist/templates/zcode/agents/trellis-check.md +0 -109
  476. package/dist/templates/zcode/agents/trellis-implement.md +0 -111
  477. package/dist/templates/zcode/agents/trellis-research.md +0 -133
@@ -0,0 +1,376 @@
1
+ """Frozen message inputs, native consumption, candidates and resource closure."""
2
+ from __future__ import annotations
3
+
4
+ from pathlib import Path
5
+ import uuid
6
+
7
+ from .io import write_text_atomic
8
+ from . import worktree_delegation_contract as contract
9
+ from .worktree_delegation_contract import (
10
+ MAX_BYTES, SAFE_ID, assert_worktree, clean_result, digest, fail, file_ref, git,
11
+ package_admission, read, save,
12
+ )
13
+ from .worktree_delegation_transport import adapter
14
+
15
+
16
+ def projection(root: Path, child_dir: Path, record: dict, path: Path):
17
+ b = record["binding"]
18
+ 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")}
19
+ if record["requirements"].get("setup_ref"):
20
+ sources["setup"] = file_ref(child_dir, record["requirements"]["setup_ref"])
21
+ if b.get("format_version") not in {2, 3} or not SAFE_ID.fullmatch(record["attempt_id"]):
22
+ fail("complete frozen binding and safe attempt identity required")
23
+ snapshots = {}
24
+ directory = path.parent / "inputs" / record["attempt_id"]
25
+ if directory.resolve() != directory.absolute():
26
+ fail("redirected frozen input directory")
27
+ directory.mkdir(parents=True, exist_ok=True)
28
+ for name, source in sources.items():
29
+ content = source.read_bytes()
30
+ if len(content) > MAX_BYTES or digest(content) != b[f"{name}_sha256"]:
31
+ fail("approved source input changed before projection; preserve the attempt")
32
+ snapshot = directory / f"{name}.md"
33
+ if snapshot.exists() or snapshot.is_symlink():
34
+ 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"]:
35
+ fail("frozen input snapshot changed; preserve the attempt")
36
+ elif not write_text_atomic(snapshot, content.decode("utf8"), newline=""):
37
+ fail("could not save frozen input snapshot")
38
+ snapshots[f"{name}_ref"] = str(snapshot)
39
+ 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")}
40
+ save(path.with_name("context.json"), context)
41
+ if b.get("format_version") == 3 and record.get("agent_id"):
42
+ context["version"] = 2
43
+ context["inputs"] = record.get("inputs", [])
44
+ save(path.with_name("context.json"), context)
45
+ locator = root / ".trellis/.runtime/delegation-agents" / record["agent_id"] / "context.json"
46
+ save(locator, {"version": 1, "kind": "delegation_agent_locator", "agent_id": record["agent_id"],
47
+ "context_ref": str(path.with_name("context.json"))})
48
+ return locator
49
+ return path.with_name("context.json")
50
+
51
+
52
+ def agent_payload(record: dict):
53
+ return {"agent_id": record["agent_id"], "cwd": record["worktree_path"]}
54
+
55
+
56
+ def native_lifecycle(record: dict, *, rpc=None):
57
+ rpc = rpc or adapter
58
+ observed = rpc(record, "inspect", {"target": record["binding"]["target_locator"],
59
+ "workspace_id": record["workspace_id"], "agent_id": record["agent_id"]})
60
+ if observed.get("lifecycle", {}).get("autoArchiveAfterMerge") is not False:
61
+ fail("native autoArchiveAfterMerge must remain explicitly disabled before business input or acceptance")
62
+ agents = observed.get("agents", [])
63
+ if (len(agents) != 1 or agents[0].get("id") != record["agent_id"]
64
+ or agents[0].get("labels", {}).get("trellis.attempt") != record["attempt_id"]
65
+ or agents[0].get("labels", {}).get("trellis.control") != record["control_project_id"]):
66
+ fail("native agent labels changed; do not send or accept against another package")
67
+ return observed
68
+
69
+
70
+ def refresh_delivery(record: dict, path: Path, *, rpc=None):
71
+ """Public projected user messages associate our message IDs with native turns."""
72
+ rpc = rpc or adapter
73
+ queue = rpc(record, "queue", agent_payload(record))
74
+ if not isinstance(queue.get("items"), list) or type(queue.get("held")) is not bool:
75
+ fail("native queue inventory is incomplete")
76
+ queued = {item["id"] for item in queue["items"]}
77
+ inputs = {item["id"]: item for item in record.get("inputs", [])}
78
+ seen, turns, foreign_turns = set(), {}, set()
79
+ cursor, epoch = None, None
80
+ while True:
81
+ page = rpc(record, "timeline", {**agent_payload(record), "direction": "before" if cursor else "tail",
82
+ "limit": 100, **({"cursor": cursor} if cursor else {})})
83
+ if (not isinstance(page.get("entries"), list) or not isinstance(page.get("epoch"), str)
84
+ or page.get("gap") is not False or page.get("stale_cursor") is not False
85
+ or type(page.get("has_older")) is not bool or type(page.get("has_newer")) is not bool):
86
+ fail("native timeline has a gap or unverified pagination; preserve pending inputs")
87
+ if epoch is not None and (page["epoch"] != epoch or page.get("reset")):
88
+ fail("native timeline epoch changed while reading; preserve pending inputs")
89
+ epoch = page["epoch"]
90
+ for entry in page["entries"]:
91
+ if entry.get("kind") != "user_message":
92
+ continue
93
+ ids, turn = entry.get("message_ids"), entry.get("turn_id")
94
+ if not isinstance(ids, list) or not isinstance(turn, str) or not turn:
95
+ fail("native user message/turn association is unavailable")
96
+ controlled = [key for key in ids if key in inputs]
97
+ if not controlled:
98
+ foreign_turns.add(turn)
99
+ for key in controlled:
100
+ previous = turns.get(key)
101
+ if previous and previous != turn:
102
+ fail("one input is associated with multiple native turns")
103
+ turns[key] = turn
104
+ if not page["has_older"]:
105
+ break
106
+ following = page.get("start_cursor")
107
+ if (not isinstance(following, dict) or following.get("epoch") != epoch
108
+ or type(following.get("seq")) is not int):
109
+ fail("native timeline continuation cursor is unavailable")
110
+ marker = (epoch, following["seq"])
111
+ if marker in seen:
112
+ fail("native timeline pagination repeats")
113
+ seen.add(marker)
114
+ cursor = following
115
+ prior_epoch = record.get("timeline_epoch")
116
+ if set(inputs) != {item["id"] for item in record.get("inputs", [])}:
117
+ fail("input inventory changed during observation; refresh without sending")
118
+ if prior_epoch is not None and prior_epoch != epoch:
119
+ # The complete new projection must independently prove every previously consumed message.
120
+ if any(item.get("turn_id") and key not in turns for key, item in inputs.items()):
121
+ fail("replacement timeline cannot prove previously consumed inputs")
122
+ for key, item in inputs.items():
123
+ if key in turns:
124
+ if key in queued:
125
+ fail("input is both queued and consumed; retry observation without sending")
126
+ item.update({"delivery": "consumed", "turn_id": turns[key],
127
+ "foreign_input": turns[key] in foreign_turns})
128
+ elif key in queued:
129
+ item["delivery"] = "queued"
130
+ elif item.get("delivery") not in {"withdrawn"}:
131
+ item["delivery"] = "unknown"
132
+ record["timeline_epoch"] = epoch
133
+ record["queue_evidence"] = queue
134
+ save(path, record)
135
+ return queue
136
+
137
+
138
+ def send_input(root: Path, child_dir: Path, record: dict, path: Path, stage: str, instructions: str = "", *, rpc=None):
139
+ rpc = rpc or adapter
140
+ package_admission(root, child_dir, record, path)
141
+ if record.get("intent") or record.get("cancel_requested") or record.get("quarantined"):
142
+ fail("pending operation or quarantine prevents new input")
143
+ tree = assert_worktree(record)
144
+ observed = native_lifecycle(record, rpc=rpc)["agents"][0]
145
+ if stage != "prepare":
146
+ runtime = observed.get("runtimeInfo") or {}
147
+ model = runtime.get("model") or observed.get("model")
148
+ mode = runtime.get("modeId") or observed.get("currentModeId")
149
+ effort = runtime.get("thinkingOptionId") or observed.get("effectiveThinkingOptionId") or observed.get("thinkingOptionId")
150
+ if (observed.get("provider") != "codex" or observed.get("status") not in {"idle", "running", "error"}
151
+ or model != record["settings"]["model"] or mode != "full-access"
152
+ or effort != record["settings"]["effort"]):
153
+ fail("native provider/model/mode/effort is unavailable or drifted before business input")
154
+ if record.get("intent") or record.get("cancel_requested") or record.get("quarantined"):
155
+ fail("input preflight became stale; preserve the pending operation without sending")
156
+ if stage == "prepare" and record.get("inputs"):
157
+ fail("preparation input already exists; recover its delivery instead of resending")
158
+ if stage == "execute":
159
+ if any(item["stage"] != "prepare" for item in record.get("inputs", [])):
160
+ fail("initial business input was already allocated during preflight")
161
+ if git(tree, "rev-parse", "HEAD") != record["binding"]["base_commit"]:
162
+ fail("first business write requires the exact approved HEAD")
163
+ if stage != "prepare":
164
+ ready = candidate(record, "ready", current_head=stage == "execute")
165
+ if not ready or ready.get("missing") != []:
166
+ fail("current consumed preparation candidate with no missing requirements required")
167
+ record["ready_evidence"] = ready
168
+ if stage == "followup" and not any(item["stage"] == "execute" for item in record.get("inputs", [])):
169
+ fail("followup cannot bypass the first prepared execution input")
170
+ if stage != "prepare":
171
+ record["execution_permission"] = "implementation"
172
+ key = str(uuid.uuid4())
173
+ item = {"id": key, "stage": stage, "delivery": "unknown", "turn_id": None}
174
+ record.setdefault("inputs", []).append(item)
175
+ projection(root, child_dir, record, path)
176
+ context_path = path.parent / "inputs" / record["attempt_id"] / key / "context.json"
177
+ context = read(path.with_name("context.json"))
178
+ report_dir = tree / ".trellis-delegation" / record["attempt_id"] / key
179
+ context.update({"input_id": key, "stage": stage,
180
+ **{f"{kind}_path": str(report_dir / f"{kind}.json") for kind in ("ready", "result", "blocked")}})
181
+ save(context_path, context)
182
+ prompt = f"{stage}: read the frozen input context at {context_path}. Write only the assigned candidate; do not ask the user.\n{instructions}"
183
+ prompt_path = context_path.with_name("prompt.txt")
184
+ if not write_text_atomic(prompt_path, prompt, newline=""):
185
+ fail("could not persist the exact input")
186
+ item.update({"context_ref": str(context_path), "prompt_ref": str(prompt_path)})
187
+ record.update({"intent": "send_pending", "send_pending": {"client_message_id": key, "stage": stage}})
188
+ save(path, record)
189
+ receipt = rpc(record, "followup" if stage == "followup" else "execute",
190
+ {**agent_payload(record), "prompt": prompt, "client_message_id": key})
191
+ native = receipt.get("receipt", {})
192
+ if not isinstance(native, dict) or (native.get("messageId") not in {None, key}
193
+ or native.get("activeTurnBehavior") not in {None, "queue"}):
194
+ fail("native send receipt cannot identify this input; preserve intent")
195
+ item = next(item for item in record["inputs"] if item["id"] == key)
196
+ item["receipt"] = native
197
+ record.update({"intent": None})
198
+ record.pop("send_pending", None)
199
+ save(path, record)
200
+ projection(root, child_dir, record, path)
201
+
202
+
203
+ def candidate_input(record: dict, name: str):
204
+ stage = "prepare" if name == "ready" else None
205
+ return next((item for item in reversed(record.get("inputs", []))
206
+ if (item["stage"] == stage if stage else item["stage"] != "prepare")), None)
207
+
208
+
209
+ def candidate(record: dict, name: str, *, current_head=True, input_id: str | None = None):
210
+ tree = assert_worktree(record)
211
+ directory = tree / ".trellis-delegation" / record["attempt_id"]
212
+ modern = record["binding"].get("format_version") == 3
213
+ input_item = (next((item for item in record.get("inputs", []) if item["id"] == input_id), None)
214
+ if input_id else candidate_input(record, name)) if modern else None
215
+ if modern:
216
+ if input_item is None:
217
+ return None
218
+ directory /= input_item["id"]
219
+ path = directory / f"{name}.json"
220
+ if input_item is not None and not path.exists() and input_item.get("turn_id"):
221
+ peers = [tree / ".trellis-delegation" / record["attempt_id"] / item["id"] / f"{name}.json"
222
+ for item in record["inputs"] if item.get("turn_id") == input_item["turn_id"]]
223
+ existing = [peer for peer in peers if peer.exists()]
224
+ if existing:
225
+ path, directory = existing[-1], existing[-1].parent
226
+ if any(read(peer) != read(path) for peer in existing[:-1]):
227
+ fail("conflicting candidates for one consumed native input batch")
228
+ if directory.resolve() != directory or (tree / ".trellis-delegation").is_symlink():
229
+ fail("redirected candidate directory")
230
+ 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()):
231
+ fail("candidate directory contains unexpected data; preserve it")
232
+ if not path.exists():
233
+ return None
234
+ value = read(path)
235
+ b = record["binding"]
236
+ 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"]}
237
+ if input_item is not None:
238
+ expected["version"] = 2
239
+ if input_item.get("delivery") != "consumed" or input_item.get("foreign_input") or not input_item.get("turn_id"):
240
+ fail("candidate input has no uncontaminated native consumption evidence")
241
+ batch = [item["id"] for item in record["inputs"] if item.get("turn_id") == input_item["turn_id"]]
242
+ if (not isinstance(value.get("input_ids"), list)
243
+ or any(not isinstance(key, str) for key in value["input_ids"])
244
+ or set(value["input_ids"]) != set(batch)
245
+ or len(value["input_ids"]) != len(batch)):
246
+ fail("candidate must identify exactly the consumed controlled input batch")
247
+ 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:
248
+ fail("candidate identity/head/authority does not match the current attempt")
249
+ if not isinstance(value.get("observations"), dict) or not isinstance(value.get("limitations"), list):
250
+ fail("candidate observations/limitations are malformed")
251
+ if name == "ready" and not isinstance(value.get("missing"), list):
252
+ fail("ready candidate must contain a missing-requirements list")
253
+ if name == "result":
254
+ for key in ("changed_paths", "source_commits", "checks", "remaining"):
255
+ if not isinstance(value.get(key), list):
256
+ fail(f"result candidate requires a {key} list")
257
+ for key in ("changed_paths", "source_commits"):
258
+ if (any(not isinstance(item, str) or not item for item in value[key])
259
+ or len(value[key]) != len(set(value[key]))):
260
+ fail(f"result {key} must contain unique nonempty strings")
261
+ return value
262
+
263
+
264
+ def close_native(record: dict, path: Path, *, cancel: bool, rpc=None):
265
+ rpc = rpc or adapter
266
+ pending = record.get("safety_intent", {})
267
+ observed = rpc(record, "observe", agent_payload(record)).get("agent") or {}
268
+ already_closed = observed.get("status") == "closed" and not observed.get("activeTurn")
269
+ if not cancel and (observed.get("activeTurn") or observed.get("status") not in {"idle", "closed"}):
270
+ fail("normal closure requires an idle or closed native writer; do not cancel active input implicitly")
271
+ if pending.get("operation") in {"interrupt", "archive-agent", "close-agent"} and not already_closed:
272
+ fail("previous stop/archive outcome remains unknown; observe native closure without replaying it")
273
+ record.update({"cancel_requested": True, "execution_permission": "none"})
274
+ save(path, record)
275
+ # Unknown or unconsumed cancellation is never a normal same-context continuation.
276
+ if cancel and any(item.get("delivery") != "consumed" for item in record.get("inputs", [])):
277
+ record["quarantined"] = True
278
+ save(path, record)
279
+ if cancel and not already_closed:
280
+ record["safety_intent"] = {"operation": "interrupt"}
281
+ save(path, record)
282
+ rpc(record, "interrupt", agent_payload(record))
283
+ refresh_delivery(record, path, rpc=rpc)
284
+ queue = record["queue_evidence"]
285
+ controlled = {item["id"]: item for item in record.get("inputs", [])}
286
+ for item in queue["items"]:
287
+ if item["id"] not in controlled:
288
+ fail("foreign queued input remains; preserve the quarantined agent and checkout claim")
289
+ if not cancel:
290
+ fail("normal closure requires all queued inputs to finish")
291
+ record["safety_intent"] = {"operation": "withdraw", "input_id": item["id"]}
292
+ save(path, record)
293
+ result = rpc(record, "withdraw", {**agent_payload(record), "client_message_id": item["id"]})
294
+ record.setdefault("withdrawals", {})[item["id"]] = result
295
+ if result.get("withdrawn") is True:
296
+ controlled[item["id"]]["delivery"] = "withdrawn"
297
+ elif result.get("reason") not in {"already_dispatching", "not_found"}:
298
+ fail("withdrawal result is unknown; preserve the safety intent")
299
+ save(path, record)
300
+ work = rpc(record, "background", agent_payload(record))
301
+ if not isinstance(work.get("items"), list):
302
+ fail("background work inventory is unavailable")
303
+ for item in work["items"]:
304
+ if not cancel or item.get("can_stop") is not True or not item.get("stop_token"):
305
+ fail("background writer remains; preserve the checkout claim")
306
+ record["safety_intent"] = {"operation": "stop-background", "item_id": item["id"]}
307
+ save(path, record)
308
+ rpc(record, "stop-background", {**agent_payload(record), "item_id": item["id"], "stop_token": item["stop_token"]})
309
+ if not already_closed:
310
+ record["safety_intent"] = {"operation": "close-agent"}
311
+ save(path, record)
312
+ rpc(record, "close-agent", agent_payload(record))
313
+ refresh_delivery(record, path, rpc=rpc)
314
+ observation = rpc(record, "observe", agent_payload(record))
315
+ work = rpc(record, "background", agent_payload(record))
316
+ agent = observation.get("agent") or {}
317
+ if (agent.get("id") != record["agent_id"] or agent.get("status") != "closed" or agent.get("activeTurn")
318
+ or record["queue_evidence"]["items"] or work.get("items") != []):
319
+ fail("native runtime, queue or background writers are not confirmed closed")
320
+ if any(item.get("delivery") not in {"consumed", "withdrawn"} for item in record.get("inputs", [])):
321
+ fail("unknown input delivery remains; empty queue is not withdrawal evidence")
322
+ record["native_closure"] = {"observation": observation, "queue": record["queue_evidence"],
323
+ "background": work, "inputs_resolved": True}
324
+ record.pop("safety_intent", None)
325
+ if record.get("intent") in {"interrupt_pending", "send_pending"}:
326
+ record["intent"] = None
327
+ record.pop("send_pending", None)
328
+ save(path, record)
329
+ return record["native_closure"]
330
+
331
+
332
+ def owner_takeover(record: dict, path: Path, child_dir: Path, args, *, rpc=None):
333
+ rpc = rpc or adapter
334
+ contract.task_inputs(child_dir)
335
+ if args.disposition != "integrated":
336
+ fail("owner takeover must explicitly request integrated acceptance")
337
+ from .task_workflow import _assert_delegated_record_closed
338
+ _assert_delegated_record_closed(child_dir.name, record)
339
+ if record["closure_evidence"].get("disposition") != "retained":
340
+ fail("owner takeover is only for preserved source, not already accepted deliveries")
341
+ source = read(file_ref(child_dir, args.owner_result_ref))
342
+ expected = {"version": 1, "kind": "owner_result", "attempt_id": record["attempt_id"],
343
+ "binding_revision": record["binding"]["binding_revision"], "base_commit": record["binding"]["base_commit"]}
344
+ if any(source.get(key) != value for key, value in expected.items()) or source.get("remaining") != []:
345
+ fail("owner result must identify the preserved binding and resolve its remaining work")
346
+ observation = rpc(record, "observe", agent_payload(record))
347
+ agent = observation.get("agent") or {}
348
+ queue = rpc(record, "queue", agent_payload(record))
349
+ background = rpc(record, "background", agent_payload(record))
350
+ if (agent.get("id") != record["agent_id"] or agent.get("status") != "closed" or agent.get("activeTurn")
351
+ or queue.get("items") != [] or background.get("items") != []):
352
+ fail("preserved native resources are no longer closed")
353
+ from .task_continuity import _record_lock
354
+ claim = Path(git(Path(record["worktree_path"]), "rev-parse", "--absolute-git-dir")) / "trellis-delegation-owner.json"
355
+ with _record_lock(claim):
356
+ if claim.exists():
357
+ fail("a new implementation owner holds the preserved checkout")
358
+ if git(Path(record["worktree_path"]), "rev-parse", "HEAD") != source.get("head_commit"):
359
+ fail("owner source result does not identify the current checkout HEAD")
360
+ clean_result(record, source, path)
361
+ git(Path(record["binding"]["target_locator"]), "merge-base", "--is-ancestor",
362
+ source["head_commit"], record["binding"]["integration_branch"])
363
+ if not args.execute:
364
+ return {"status": "ready", "owner_result": source}
365
+ if not args.reason or not args.approval_ref or not args.writer_evidence_ref:
366
+ fail("owner takeover requires reason, approval and current external-writer evidence")
367
+ writers = file_ref(child_dir, args.writer_evidence_ref).read_text(encoding="utf8")
368
+ record["retained_evidence"] = record["closure_evidence"]
369
+ record["owner_acceptance"] = {"version": 1, "origin": "owner_takeover", "head_commit": source["head_commit"],
370
+ "source_commits": source["source_commits"], "result_revision": digest(source),
371
+ "acceptance_ref": args.owner_result_ref, **expected}
372
+ record["closure_evidence"] = {**record["closure_evidence"], "disposition": "integrated",
373
+ "owner_result": source, "reason": args.reason, "approval_ref": args.approval_ref,
374
+ "writer_evidence": writers}
375
+ save(path, record)
376
+ return record
@@ -0,0 +1,57 @@
1
+ """Bounded public adapter transport and complete native inspection pagination."""
2
+ from __future__ import annotations
3
+
4
+ import json
5
+ import subprocess
6
+
7
+ from .worktree_delegation_contract import MAX_BYTES, fail
8
+
9
+
10
+ def adapter(record: dict, operation: str, payload: dict):
11
+ 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}
12
+ if record.get("daemon_identity"):
13
+ request["daemon_selector"]["home"] = record["daemon_identity"]["home"]
14
+ if record.get("daemon_identity") and operation != "inspect":
15
+ request["daemon_selector"]["server_id"] = record["daemon_identity"]["server_id"]
16
+ try:
17
+ # A regular temp file bounds what the controller reads even if a broken
18
+ # adapter emits excessive output. Never execute candidate-report commands.
19
+ import tempfile
20
+ with tempfile.TemporaryFile() as output, tempfile.TemporaryFile() as errors:
21
+ result = subprocess.run(["trellis-paseo-adapter"], input=json.dumps(request).encode(), stdout=output, stderr=errors, timeout=3700 if operation == "wait" else 120)
22
+ output.seek(0)
23
+ raw = output.read(MAX_BYTES + 1)
24
+ value = json.loads(raw) if len(raw) <= MAX_BYTES else None
25
+ except (OSError, subprocess.TimeoutExpired, ValueError):
26
+ fail("adapter unavailable or outcome unknown; preserve intent and reconcile; install/check trellis-paseo-adapter through Lifecycle")
27
+ 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"]:
28
+ fail("adapter response identity/shape unknown; preserve intent and reconcile")
29
+ if result.returncode or value.get("ok") is not True or not isinstance(value.get("observations"), dict):
30
+ fail(f"adapter {value.get('error', {}).get('category', 'outcome_unknown')}; inspect native resources before retry")
31
+ observed = value["observations"]
32
+ if record.get("daemon_identity") and observed.get("identity") != record["daemon_identity"] and (
33
+ operation != "inspect" or observed.get("identity", {}).get("home") != record["daemon_identity"]["home"]):
34
+ fail("daemon identity changed; reconcile before continuing")
35
+ return observed
36
+
37
+
38
+ def inspection_pages(record: dict, payload: dict, *, rpc=None):
39
+ rpc = rpc or adapter
40
+ cursor, seen, identity = None, set(), None
41
+ while True:
42
+ observed = rpc(record, "inspect", {**payload, "page_size": 100, **({"cursor": cursor} if cursor else {})})
43
+ page = observed.get("page_info")
44
+ if not isinstance(page, dict) or type(page.get("complete")) is not bool or "next_cursor" not in page:
45
+ fail("adapter inspection pagination is unavailable or incomplete; update the optional adapter")
46
+ following = page["next_cursor"]
47
+ if (following is not None and (not isinstance(following, str) or not following or following in seen)
48
+ or page["complete"] != (following is None) or not isinstance(observed.get("agents"), list)):
49
+ fail("adapter inspection pagination is inconsistent; preserve native resources")
50
+ if identity is not None and observed.get("identity") != identity:
51
+ fail("daemon identity changed during inspection")
52
+ identity = observed.get("identity")
53
+ yield observed
54
+ if following is None:
55
+ return
56
+ seen.add(following)
57
+ cursor = following
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env python3
2
+ """Check explicit UTF-8 Markdown files and optionally print a read-only fix diff."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ from difflib import unified_diff
8
+ from pathlib import Path
9
+ import sys
10
+
11
+ from common.markdown_format import inspect_markdown, preview_corrections
12
+
13
+
14
+ def main() -> int:
15
+ parser = argparse.ArgumentParser(description=__doc__)
16
+ parser.add_argument("--preview", action="store_true", help="show only deterministic fixes as a diff")
17
+ parser.add_argument("files", nargs="+", type=Path)
18
+ args = parser.parse_args()
19
+ status = 0
20
+ for path in args.files:
21
+ try:
22
+ text = path.read_bytes().decode("utf-8")
23
+ except (OSError, UnicodeError) as error:
24
+ print(f"{path}: cannot read Markdown: {error}", file=sys.stderr)
25
+ status = 2
26
+ continue
27
+ issues = inspect_markdown(text)
28
+ for issue in issues:
29
+ print(issue.diagnostic(str(path), text), file=sys.stderr)
30
+ if args.preview:
31
+ fixed = preview_corrections(text, issues)
32
+ for line in unified_diff(text.splitlines(), fixed.splitlines(), str(path), str(path) + " (preview)", lineterm=""):
33
+ print(line)
34
+ if issues:
35
+ status = max(status, 1)
36
+ return status
37
+
38
+
39
+ if __name__ == "__main__":
40
+ sys.exit(main())