@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,518 @@
1
+ """Codex turn exit evidence; not a task lifecycle or permission authority."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import hashlib
7
+ import json
8
+ import os
9
+ from pathlib import Path
10
+ import re
11
+ import shlex
12
+ import sys
13
+ import time
14
+ import uuid
15
+
16
+ from .active_task import _context_path, _write_json, resolve_context_key
17
+ from .io import JSON_READ_MISSING, read_json_checked, write_json
18
+ from .task_move import layout_lock, require_settled_layout
19
+ from .task_utils import resolve_task_dir
20
+ from .task_workflow import PHASE_IDS, TaskWorkflowError, _artifact_digest, _state, design_preflight
21
+
22
+ KINDS = ("bounded_reply", "task_complete", "waiting_authorization",
23
+ "waiting_input", "external_block", "user_stop")
24
+ SCOPES = ("explanation", "inspection", "handoff_admission", "maintenance")
25
+ TICKET_ID = re.compile(r"[0-9a-f]{32}\Z")
26
+ MAX_CORRECTIONS = 2
27
+ TICKET_SECONDS = 30
28
+
29
+
30
+ class TurnError(ValueError):
31
+ pass
32
+
33
+
34
+ def _digest(value: object) -> str:
35
+ return hashlib.sha256(json.dumps(value, ensure_ascii=False, sort_keys=True,
36
+ separators=(",", ":")).encode()).hexdigest()
37
+
38
+
39
+ def _text(value: object, name: str, limit: int = 512) -> str:
40
+ if not isinstance(value, str) or not value.strip() or len(value) > limit:
41
+ raise TurnError(f"TASK_TURN_INVALID: missing or invalid {name}")
42
+ return value
43
+
44
+
45
+ def _runtime_path(root: Path, path: Path) -> Path:
46
+ runtime = root / ".trellis/.runtime"
47
+ path.relative_to(runtime)
48
+ if runtime.is_symlink():
49
+ raise TurnError("TASK_TURN_WITHHELD: redirected runtime")
50
+ current = runtime
51
+ for part in path.relative_to(runtime).parts:
52
+ current = current / part
53
+ if current.is_symlink():
54
+ raise TurnError("TASK_TURN_WITHHELD: redirected runtime")
55
+ if path.exists() and not path.is_file():
56
+ raise TurnError("TASK_TURN_WITHHELD: runtime record is not a regular file")
57
+ return path
58
+
59
+
60
+ def _read(path: Path, *, missing: bool = False) -> dict:
61
+ value, reason = read_json_checked(path)
62
+ if value is None:
63
+ if missing and reason == JSON_READ_MISSING:
64
+ return {}
65
+ raise TurnError("TASK_TURN_WITHHELD: runtime record is " + str(reason))
66
+ return value
67
+
68
+
69
+ def _session(root: Path, key: str) -> tuple[Path, dict]:
70
+ path = _runtime_path(root, _context_path(root, key))
71
+ return path, _read(path, missing=True)
72
+
73
+
74
+ def _save(path: Path, context: dict) -> None:
75
+ if not _write_json(path, context):
76
+ raise TurnError("TASK_TURN_WRITE_FAILED: could not save session")
77
+
78
+
79
+ def _turn(context: dict, session: str | None = None, turn_id: str | None = None) -> dict:
80
+ value = context.get("turn")
81
+ if (not isinstance(value, dict)
82
+ or set(value) != {"schema_version", "session_id", "turn_id", "prompt_digest", "corrections",
83
+ "evidence", "answers", "interrupted", "observed_task"}
84
+ or type(value.get("schema_version")) is not int
85
+ or value["schema_version"] != 1
86
+ or type(value.get("corrections")) is not int
87
+ or not 0 <= value["corrections"] <= MAX_CORRECTIONS
88
+ or not isinstance(value.get("answers"), dict)
89
+ or not isinstance(value.get("interrupted"), bool)
90
+ or not isinstance(value.get("session_id"), str) or not value["session_id"]
91
+ or not isinstance(value.get("turn_id"), str) or not value["turn_id"]
92
+ or not re.fullmatch(r"[0-9a-f]{64}", str(value.get("prompt_digest")))
93
+ or session is not None and value.get("session_id") != session
94
+ or turn_id is not None and value.get("turn_id") != turn_id):
95
+ raise TurnError("TASK_TURN_WITHHELD: missing, stale or incompatible turn")
96
+ for call_id, answer in value["answers"].items():
97
+ if (not isinstance(call_id, str) or not call_id
98
+ or not isinstance(answer, dict) or set(answer) != {"input_digest", "response_digest", "status"}
99
+ or not re.fullmatch(r"[0-9a-f]{64}", str(answer["input_digest"]))
100
+ or answer["response_digest"] is not None and not re.fullmatch(r"[0-9a-f]{64}", str(answer["response_digest"]))
101
+ or not isinstance(answer["status"], str)
102
+ or answer["status"] not in {"pending", "complete", "incomplete"}):
103
+ raise TurnError("TASK_TURN_WITHHELD: incompatible answer observation")
104
+ return value
105
+
106
+
107
+ def _identity(event: dict) -> tuple[str, str, str]:
108
+ session = _text(event.get("session_id"), "native session_id")
109
+ turn_id = _text(event.get("turn_id"), "native turn_id")
110
+ key = resolve_context_key(event, platform="codex", allow_environment_context=False)
111
+ if key is None:
112
+ raise TurnError("TASK_TURN_WITHHELD: direct Codex identity is required")
113
+ return key, session, turn_id
114
+
115
+
116
+ def _snapshot(root: Path, context: dict, turn: dict) -> dict | None:
117
+ ref = context.get("current_task") or turn.get("observed_task")
118
+ if ref is None:
119
+ return None
120
+ if not isinstance(ref, str):
121
+ raise TurnError("TASK_TURN_WITHHELD: invalid task pointer")
122
+ # Native basename resolution also handles a task moved by complete/cancel.
123
+ directory = resolve_task_dir(ref if (root / ref).exists() else Path(ref).name, root)
124
+ if directory is None:
125
+ raise TurnError("TASK_TURN_WITHHELD: task is missing or ambiguous")
126
+ task = _read(directory / "task.json")
127
+ meta = task.get("meta", {})
128
+ if not isinstance(meta, dict):
129
+ raise TurnError("TASK_TURN_WITHHELD: invalid task metadata")
130
+ state = _state(meta) if meta.get("task_workflow") is not None else None
131
+ artifacts = {}
132
+ if state:
133
+ for phase, record in state["phases"].items():
134
+ artifacts[phase] = _artifact_digest(directory, record["artifact_refs"])
135
+ phase_id = state["current_phase_id"] if state else None
136
+ return {"id": task.get("id") or task.get("name"),
137
+ "path": directory.relative_to(root).as_posix(), "status": task.get("status"),
138
+ "record_digest": _digest(task), "artifacts": artifacts,
139
+ "phase_id": phase_id,
140
+ "phase_status": state["phases"][phase_id]["status"] if state and phase_id else None,
141
+ "route_revision": state["task_route_revision"] if state else None,
142
+ "input_revision": state["input_revision"] if state else None,
143
+ "closeout": state.get("closeout_disposition") if state else None,
144
+ "accepted_contract": (state["phases"][phase_id].get("outcome_kind") == "implementation_contract"
145
+ and state.get("implementation_authorization") is None) if state and phase_id == PHASE_IDS[2] else False}
146
+
147
+
148
+ def begin(root: Path, event: dict) -> dict:
149
+ key, session, turn_id = _identity(event)
150
+ prompt = _text(event.get("prompt"), "prompt", 1024 * 1024)
151
+ with layout_lock(root):
152
+ require_settled_layout(root)
153
+ path, context = _session(root, key)
154
+ previous = _turn(context) if "turn" in context else None
155
+ if previous and previous["turn_id"] == turn_id and previous["prompt_digest"] == _digest(prompt):
156
+ _turn(context, session, turn_id)
157
+ return previous
158
+ turn = {"schema_version": 1, "session_id": session, "turn_id": turn_id,
159
+ "prompt_digest": _digest(prompt),
160
+ "corrections": 0,
161
+ "evidence": None, "answers": {}, "interrupted": False,
162
+ }
163
+ snapshot = _snapshot(root, context, {})
164
+ turn["observed_task"] = snapshot["path"] if snapshot else None
165
+ context["turn"] = turn
166
+ _save(path, context)
167
+ return turn
168
+
169
+
170
+ def _invocation(root: Path, command: str) -> tuple[list[str], str | None, list[str]]:
171
+ if os.name != "posix":
172
+ raise TurnError("TASK_TURN_UNSUPPORTED: invocation rewriting requires a verified POSIX shell")
173
+ # Only single-quoted literals can contain shell expansion characters.
174
+ outside_literals = re.sub(r"""(?:"(?:\\.|[^"\\])*"|'[^']*'|\\.)""",
175
+ lambda match: "" if match[0].startswith("'") else match[0], command)
176
+ if any(c in command for c in ("\n", "\r", "\0")) or any(c in outside_literals for c in ("$", "`", "#")):
177
+ raise TurnError("TASK_TURN_WITHHELD: expansions and multiline shell commands are unsupported")
178
+ lexer = shlex.shlex(command, posix=True, punctuation_chars=";&|<>()")
179
+ lexer.whitespace_split = True
180
+ lexer.commenters = ""
181
+ tokens = list(lexer)
182
+ if any(token and all(c in ";&|<>()" for c in token) for token in tokens):
183
+ raise TurnError("TASK_TURN_WITHHELD: use one direct Python task.py turn command")
184
+ if len(tokens) < 4 or (tokens[0] not in {"python", "python3"} and
185
+ (not Path(tokens[0]).is_absolute() or Path(tokens[0]).resolve() != Path(sys.executable).resolve())):
186
+ raise TurnError("TASK_TURN_WITHHELD: use Python directly")
187
+ index = 3 if tokens[1:3] == ["-X", "utf8"] else 1
188
+ if (len(tokens) <= index + 2 or (root / tokens[index]).resolve() != (root / ".trellis/scripts/task.py").resolve()
189
+ or tokens[index + 1] != "turn" or tokens[index + 2] not in {"show", "record", "--help", "-h"}):
190
+ raise TurnError("TASK_TURN_WITHHELD: not a native turn invocation")
191
+ argv = tokens[index + 2:]
192
+ ticket = None
193
+ if "--invocation-ticket" in argv:
194
+ if len(argv) < 3 or argv[-2] != "--invocation-ticket" or argv.count("--invocation-ticket") != 1:
195
+ raise TurnError("TASK_TURN_WITHHELD: invalid invocation ticket argument")
196
+ ticket = argv[-1]
197
+ argv = argv[:-2]
198
+ return argv, ticket, tokens[:index + 2]
199
+
200
+
201
+ def _ticket_path(root: Path, ticket_id: str) -> Path:
202
+ if not TICKET_ID.fullmatch(ticket_id):
203
+ raise TurnError("TASK_TURN_WITHHELD: invalid invocation ticket")
204
+ return _runtime_path(root, root / ".trellis/.runtime/shell-tickets" / f"turn-{ticket_id}.json")
205
+
206
+
207
+ def _expire_tickets(root: Path) -> None:
208
+ directory = root / ".trellis/.runtime/shell-tickets"
209
+ for path in directory.glob("turn-*.json"):
210
+ if not TICKET_ID.fullmatch(path.stem[5:]):
211
+ continue
212
+ try:
213
+ ticket = _read(_runtime_path(root, path))
214
+ except TurnError:
215
+ continue
216
+ if (set(ticket) == {"schema_version", "context_key", "session_id", "turn_id", "tool_use_id",
217
+ "cwd", "argv_digest", "snapshot_digest", "expires_at_epoch", "used"}
218
+ and type(ticket.get("schema_version")) is int and ticket["schema_version"] == 1
219
+ and ticket.get("cwd") == str(root.resolve())
220
+ and type(ticket.get("used")) is bool
221
+ and type(ticket.get("expires_at_epoch")) in (int, float)
222
+ and ticket["expires_at_epoch"] < time.time()):
223
+ path.unlink()
224
+
225
+
226
+ def ticket_input(root: Path, event: dict) -> dict | None:
227
+ tool_input = event.get("tool_input")
228
+ if not isinstance(tool_input, dict):
229
+ raise TurnError("TASK_TURN_WITHHELD: invalid Bash input")
230
+ command = _text(tool_input.get("command"), "Bash command", 16384)
231
+ argv, existing, prefix = _invocation(root, command)
232
+ if not existing and (argv == ["show"] or argv in [
233
+ ["--help"], ["-h"], ["record", "--help"], ["record", "-h"],
234
+ ["show", "--help"], ["show", "-h"]]):
235
+ return None
236
+ key, session, turn_id = _identity(event)
237
+ call_id = _text(event.get("tool_use_id"), "tool_use_id")
238
+ cwd = Path(_text(event.get("cwd"), "cwd", 4096)).resolve()
239
+ if cwd != root.resolve():
240
+ raise TurnError("TASK_TURN_WITHHELD: run turn commands from the project root")
241
+ with layout_lock(root):
242
+ require_settled_layout(root)
243
+ _, context = _session(root, key)
244
+ turn = _turn(context, session, turn_id)
245
+ if turn["interrupted"]:
246
+ raise TurnError("TASK_TURN_WITHHELD: user interrupted this turn")
247
+ snapshot = _digest(_snapshot(root, context, turn))
248
+ if existing:
249
+ ticket = _read(_ticket_path(root, existing))
250
+ _check_ticket(ticket, root, argv, turn)
251
+ if ticket.get("tool_use_id") != call_id:
252
+ raise TurnError("TASK_TURN_WITHHELD: rewritten call identity changed")
253
+ return {**tool_input, "command": shlex.join([*prefix, *argv, "--invocation-ticket", existing])}
254
+ _expire_tickets(root)
255
+ ticket_id = uuid.uuid4().hex
256
+ ticket = {"schema_version": 1, "context_key": key, "session_id": session,
257
+ "turn_id": turn_id, "tool_use_id": call_id, "cwd": str(root.resolve()),
258
+ "argv_digest": _digest(argv), "snapshot_digest": snapshot,
259
+ "expires_at_epoch": time.time() + TICKET_SECONDS, "used": False}
260
+ ticket_path = _ticket_path(root, ticket_id)
261
+ ticket_path.parent.mkdir(parents=True, exist_ok=True)
262
+ if ticket_path.exists():
263
+ raise TurnError("TASK_TURN_WITHHELD: invocation ticket collision")
264
+ if not write_json(ticket_path, ticket):
265
+ raise TurnError("TASK_TURN_WRITE_FAILED: could not issue invocation ticket")
266
+ return {**tool_input, "command": shlex.join([*prefix, *argv, "--invocation-ticket", ticket_id])}
267
+
268
+
269
+ def _check_ticket(ticket: dict, root: Path, argv: list[str], turn: dict) -> None:
270
+ if (ticket.get("schema_version") != 1 or ticket.get("used") is not False
271
+ or ticket.get("cwd") != str(root.resolve())
272
+ or ticket.get("session_id") != turn["session_id"] or ticket.get("turn_id") != turn["turn_id"]
273
+ or ticket.get("argv_digest") != _digest(argv)
274
+ or type(ticket.get("expires_at_epoch")) not in (int, float)
275
+ or not 0 <= ticket["expires_at_epoch"] - time.time() <= TICKET_SECONDS):
276
+ raise TurnError("TASK_TURN_WITHHELD: expired, replayed or mismatched invocation")
277
+
278
+
279
+ def _evidence(root: Path, args: argparse.Namespace, turn: dict, snapshot: dict | None) -> dict:
280
+ refs = args.evidence_ref or []
281
+ if not refs or any(not re.fullmatch(r"[A-Za-z0-9_.:/@-]{1,512}", ref) for ref in refs):
282
+ raise TurnError("TASK_TURN_INVALID: nonempty evidence references are required")
283
+ kind = args.kind
284
+ if kind not in KINDS:
285
+ raise TurnError("TASK_TURN_INVALID: unsupported exit kind")
286
+ result = {"kind": kind, "evidence_refs": refs, "snapshot_digest": _digest(snapshot)}
287
+ if kind == "bounded_reply":
288
+ result["scope"] = args.scope
289
+ elif kind in {"waiting_authorization", "waiting_input", "external_block"}:
290
+ result["no_independent_work"] = args.no_independent_work
291
+ result["scope"] = args.scope
292
+ text = _text(args.blocker if kind == "external_block" else args.question,
293
+ "explicit final blocker" if kind == "external_block" else "explicit final question")
294
+ result.update(final_text_digest=_digest(text), final_text_length=len(text))
295
+ if any(value is not None for value in (args.approval_result_ref, args.approval_artifact_revision, args.approval_outcome)):
296
+ if kind != "waiting_authorization" or snapshot is None or args.scope is not None:
297
+ raise TurnError("TASK_TURN_WITHHELD: candidate markers require a task-bound authorization question")
298
+ ref = _text(args.approval_result_ref, "approval result reference")
299
+ revision = _text(args.approval_artifact_revision, "approval artifact revision")
300
+ task_dir = root / snapshot["path"]
301
+ try:
302
+ state = _state(_read(task_dir / "task.json")["meta"])
303
+ candidate = design_preflight(task_dir, state, args.approval_outcome, ref, revision)
304
+ except TaskWorkflowError as error:
305
+ raise TurnError(f"{error.code}: {error}") from error
306
+ result["approval_candidate"] = {"digest": _digest(candidate), "result_ref": ref,
307
+ "artifact_revision": revision, "outcome": args.approval_outcome}
308
+ elif kind == "user_stop":
309
+ result["user_prompt_digest"] = _digest(_text(args.user_instruction, "user instruction", 1024 * 1024))
310
+ if not _valid_exit(result, snapshot, turn):
311
+ raise TurnError("TASK_TURN_WITHHELD: exit evidence does not match native task, scope or user input")
312
+ return result
313
+
314
+
315
+ def _valid_exit(evidence: object, snapshot: dict | None, turn: dict) -> bool:
316
+ if not isinstance(evidence, dict) or evidence.get("kind") not in KINDS or evidence.get("snapshot_digest") != _digest(snapshot):
317
+ return False
318
+ refs = evidence.get("evidence_refs")
319
+ if not isinstance(refs, list) or not refs or not all(isinstance(ref, str) and re.fullmatch(r"[A-Za-z0-9_.:/@-]{1,512}", ref) for ref in refs):
320
+ return False
321
+ kind = evidence["kind"]
322
+ if kind == "bounded_reply":
323
+ return evidence.get("scope") in SCOPES
324
+ if kind == "task_complete":
325
+ return snapshot is not None and snapshot["status"] in {"completed", "cancelled"}
326
+ if kind == "user_stop":
327
+ return evidence.get("user_prompt_digest") == turn["prompt_digest"]
328
+ if evidence.get("no_independent_work") is not True:
329
+ return False
330
+ scope = evidence.get("scope")
331
+ if scope is not None:
332
+ return kind in {"waiting_input", "external_block"} and scope in SCOPES
333
+ if snapshot is None:
334
+ return kind in {"waiting_input", "waiting_authorization", "external_block"}
335
+ if snapshot["status"] in {"completed", "cancelled"}:
336
+ return False
337
+ if kind == "external_block":
338
+ return (snapshot["phase_status"] == "blocked" or
339
+ snapshot["phase_id"] is None and snapshot["closeout"] in {"delivery_ready", "no_go", "cancelled"})
340
+ return (snapshot["phase_status"] == "waiting_user"
341
+ or kind == "waiting_authorization" and snapshot["phase_status"] == "accepted" and snapshot["accepted_contract"])
342
+
343
+
344
+ def cli(root: Path, args: argparse.Namespace, argv: list[str]) -> dict:
345
+ with layout_lock(root):
346
+ require_settled_layout(root)
347
+ ticket_id = args.invocation_ticket
348
+ if ticket_id is None:
349
+ if args.turn_action == "record":
350
+ raise TurnError("TASK_TURN_WITHHELD: record requires the exact PreToolUse invocation ticket")
351
+ key = resolve_context_key()
352
+ if key is None:
353
+ return {"status": "unavailable", "reason": "no direct session identity"}
354
+ _, context = _session(root, key)
355
+ return {"status": "observed" if "turn" in context else "absent",
356
+ "turn": _turn(context) if "turn" in context else None}
357
+ ticket_path = _ticket_path(root, ticket_id)
358
+ ticket = _read(ticket_path)
359
+ key = _text(ticket.get("context_key"), "ticket context_key")
360
+ if not re.fullmatch(r"[A-Za-z0-9_.-]+", key):
361
+ raise TurnError("TASK_TURN_WITHHELD: invalid ticket context key")
362
+ path, context = _session(root, key)
363
+ turn = _turn(context)
364
+ _check_ticket(ticket, root, argv, turn)
365
+ direct = resolve_context_key(allow_environment_context=True)
366
+ if direct is not None and direct != key:
367
+ raise TurnError("TASK_TURN_WITHHELD: native session and ticket disagree")
368
+ if turn["interrupted"]:
369
+ raise TurnError("TASK_TURN_WITHHELD: interrupted turn")
370
+ snapshot = _snapshot(root, context, turn)
371
+ if ticket.get("snapshot_digest") != _digest(snapshot):
372
+ raise TurnError("TASK_TURN_WITHHELD: task or artifact revision changed")
373
+ evidence = _evidence(root, args, turn, snapshot) if args.turn_action == "record" else None
374
+ # Burn first: a crash can withhold evidence, never reuse a successful call.
375
+ ticket["used"] = True
376
+ if not write_json(ticket_path, ticket):
377
+ raise TurnError("TASK_TURN_WRITE_FAILED: could not consume invocation ticket")
378
+ if evidence is not None:
379
+ turn["evidence"] = evidence
380
+ if snapshot:
381
+ turn["observed_task"] = snapshot["path"]
382
+ _save(path, context)
383
+ return {"status": "recorded" if evidence is not None else "observed", "turn": turn}
384
+
385
+
386
+ def observe(root: Path, event: dict) -> dict:
387
+ key, session, turn_id = _identity(event)
388
+ with layout_lock(root):
389
+ path, context = _session(root, key)
390
+ turn = _turn(context, session, turn_id)
391
+ snapshot = _snapshot(root, context, turn)
392
+ if snapshot:
393
+ turn["observed_task"] = snapshot["path"]
394
+ if event.get("tool_name") != "request_user_input":
395
+ _save(path, context)
396
+ return {}
397
+ call_id = _text(event.get("tool_use_id"), "tool_use_id")
398
+ input_digest = _digest(event.get("tool_input"))
399
+ response_digest = _digest(event.get("tool_response"))
400
+ prior = turn["answers"].get(call_id)
401
+ if not isinstance(prior, dict) or prior.get("input_digest") != input_digest:
402
+ turn["evidence"] = None
403
+ _save(path, context)
404
+ raise TurnError("TASK_TURN_WITHHELD: answer has no matching native question invocation")
405
+ if prior.get("status") != "pending":
406
+ if prior.get("response_digest") != response_digest:
407
+ turn["evidence"] = None
408
+ _save(path, context)
409
+ raise TurnError("TASK_TURN_WITHHELD: conflicting duplicate answer")
410
+ return {}
411
+ response = event.get("tool_response")
412
+ if isinstance(response, str):
413
+ try:
414
+ response = json.loads(response)
415
+ except ValueError:
416
+ response = None
417
+ tool_input = event.get("tool_input")
418
+ questions = tool_input.get("questions") if isinstance(tool_input, dict) else None
419
+ questions = questions if isinstance(questions, list) else []
420
+ answers = response.get("answers") if isinstance(response, dict) else None
421
+ ids = [q.get("id") if isinstance(q, dict) else None for q in questions]
422
+ complete = (0 < len(ids) <= 3 and all(isinstance(i, str) and i for i in ids)
423
+ and len(set(ids)) == len(ids) and isinstance(answers, dict) and set(ids) == set(answers)
424
+ and all(isinstance(q, dict) and isinstance(q.get("question"), str) and q["question"].strip()
425
+ for q in questions)
426
+ and all(isinstance(answers[i], dict) and isinstance(answers[i].get("answers"), list)
427
+ and answers[i]["answers"] and all(isinstance(v, str) and v.strip() for v in answers[i]["answers"]) for i in ids))
428
+ turn["answers"][call_id] = {"input_digest": input_digest, "response_digest": response_digest,
429
+ "status": "complete" if complete else "incomplete"}
430
+ turn["evidence"] = None
431
+ _save(path, context)
432
+ return {"hookSpecificOutput": {"hookEventName": "PostToolUse", "additionalContext":
433
+ "A real answer returned. Record it, resume a resolved phase wait, and continue authorized work."
434
+ if complete else "No complete answer is established. Do not invent a choice; follow the host cancellation/empty-answer contract and continue independent authorized work."}}
435
+
436
+
437
+ def question_started(root: Path, event: dict) -> None:
438
+ key, session, turn_id = _identity(event)
439
+ call_id = _text(event.get("tool_use_id"), "tool_use_id")
440
+ input_digest = _digest(event.get("tool_input"))
441
+ with layout_lock(root):
442
+ path, context = _session(root, key)
443
+ turn = _turn(context, session, turn_id)
444
+ prior = turn["answers"].get(call_id)
445
+ if prior is not None:
446
+ if not isinstance(prior, dict) or prior.get("input_digest") != input_digest:
447
+ turn["evidence"] = None
448
+ _save(path, context)
449
+ raise TurnError("TASK_TURN_WITHHELD: question invocation identity changed")
450
+ return
451
+ turn["answers"][call_id] = {"input_digest": input_digest, "response_digest": None, "status": "pending"}
452
+ turn["evidence"] = None
453
+ _save(path, context)
454
+
455
+
456
+ def stop(root: Path, event: dict) -> dict:
457
+ key, session, turn_id = _identity(event)
458
+ with layout_lock(root):
459
+ path, context = _session(root, key)
460
+ turn = _turn(context, session, turn_id)
461
+ if turn["interrupted"]:
462
+ return {"continue": False, "systemMessage": "Trellis: user interruption preserved; no automatic continuation."}
463
+ evidence = turn.get("evidence")
464
+ snapshot = _snapshot(root, context, turn)
465
+ valid = _valid_exit(evidence, snapshot, turn)
466
+ if valid and snapshot is not None and isinstance(evidence, dict) and "approval_candidate" in evidence:
467
+ expected = evidence["approval_candidate"]
468
+ try:
469
+ task_dir = root / snapshot["path"]
470
+ state = _state(_read(task_dir / "task.json")["meta"])
471
+ candidate = design_preflight(task_dir, state, expected["outcome"], expected["result_ref"], expected["artifact_revision"])
472
+ valid = expected["digest"] == _digest(candidate)
473
+ except (TaskWorkflowError, KeyError, TypeError):
474
+ valid = False
475
+ if valid and isinstance(evidence, dict) and evidence.get("kind") in {"waiting_authorization", "waiting_input", "external_block"}:
476
+ message = event.get("last_assistant_message")
477
+ length = evidence.get("final_text_length")
478
+ valid = (isinstance(message, str) and len(message) <= 65536 and type(length) is int
479
+ and 0 < length <= 512 and any(_digest(message[i:i + length]) == evidence["final_text_digest"]
480
+ for i in range(len(message) - length + 1)))
481
+ if valid:
482
+ return {}
483
+ if turn["corrections"] >= MAX_CORRECTIONS:
484
+ return {"continue": False, "systemMessage": "TASK_TURN_PROTECTION_FAILED: correction limit reached; task remains unfinished. Inspect turn evidence before continuing manually."}
485
+ reason = ("Trellis turn guard: continue independent authorized work or ask the actual blocking question; "
486
+ "record native task.py turn evidence before ending. This feedback is not a user answer or approval. "
487
+ "Correction " + str(turn["corrections"] + 1) + " of " + str(MAX_CORRECTIONS) + ".")
488
+ turn["corrections"] += 1
489
+ _save(path, context)
490
+ return {"decision": "block", "reason": reason}
491
+
492
+
493
+ def interrupt(root: Path, event: dict) -> None:
494
+ key, session, turn_id = _identity(event)
495
+ with layout_lock(root):
496
+ path, context = _session(root, key)
497
+ turn = _turn(context, session, turn_id)
498
+ turn.update(interrupted=True, evidence=None)
499
+ _save(path, context)
500
+
501
+
502
+ def add_turn_commands(subparsers: argparse._SubParsersAction) -> None:
503
+ parser = subparsers.add_parser("turn", help="Observe or record native current-turn exit evidence")
504
+ actions = parser.add_subparsers(dest="turn_action", required=True)
505
+ show = actions.add_parser("show", help="Read current native turn; missing identity never grants exit evidence")
506
+ show.add_argument("--invocation-ticket")
507
+ record = actions.add_parser("record", help="Record exit evidence using the exact hook-issued invocation")
508
+ record.add_argument("--invocation-ticket")
509
+ record.add_argument("--kind", choices=KINDS, required=True)
510
+ record.add_argument("--scope", choices=SCOPES)
511
+ record.add_argument("--evidence-ref", action="append", required=True)
512
+ record.add_argument("--no-independent-work", action="store_true")
513
+ record.add_argument("--question")
514
+ record.add_argument("--blocker")
515
+ record.add_argument("--approval-result-ref")
516
+ record.add_argument("--approval-artifact-revision")
517
+ record.add_argument("--approval-outcome", choices=("implementation_contract", "analysis_conclusion", "no_go"))
518
+ record.add_argument("--user-instruction")