@pennixrv/trellis 0.7.0-beta.9 → 0.7.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (484) hide show
  1. package/README.md +1 -1
  2. package/dist/cli/index.d.ts.map +1 -1
  3. package/dist/cli/index.js +14 -26
  4. package/dist/cli/index.js.map +1 -1
  5. package/dist/commands/ablate.js +1 -1
  6. package/dist/commands/ablate.js.map +1 -1
  7. package/dist/commands/init.d.ts.map +1 -1
  8. package/dist/commands/init.js +30 -56
  9. package/dist/commands/init.js.map +1 -1
  10. package/dist/commands/task-progress.d.ts +2 -0
  11. package/dist/commands/task-progress.d.ts.map +1 -1
  12. package/dist/commands/task-progress.js +37 -30
  13. package/dist/commands/task-progress.js.map +1 -1
  14. package/dist/commands/{channel → teamwork}/adapters/claude.d.ts +3 -3
  15. package/dist/commands/teamwork/adapters/claude.d.ts.map +1 -0
  16. package/dist/commands/{channel → teamwork}/adapters/claude.js +3 -3
  17. package/dist/commands/teamwork/adapters/claude.js.map +1 -0
  18. package/dist/commands/{channel → teamwork}/adapters/codex.d.ts +1 -15
  19. package/dist/commands/teamwork/adapters/codex.d.ts.map +1 -0
  20. package/dist/commands/{channel → teamwork}/adapters/codex.js +5 -42
  21. package/dist/commands/teamwork/adapters/codex.js.map +1 -0
  22. package/dist/commands/{channel → teamwork}/adapters/index.d.ts +6 -6
  23. package/dist/commands/teamwork/adapters/index.d.ts.map +1 -0
  24. package/dist/commands/{channel → teamwork}/adapters/index.js +16 -52
  25. package/dist/commands/teamwork/adapters/index.js.map +1 -0
  26. package/dist/commands/{channel → teamwork}/adapters/types.d.ts +2 -2
  27. package/dist/commands/teamwork/adapters/types.d.ts.map +1 -0
  28. package/dist/commands/teamwork/adapters/types.js.map +1 -0
  29. package/dist/commands/{channel → teamwork}/agent-loader.d.ts +2 -4
  30. package/dist/commands/teamwork/agent-loader.d.ts.map +1 -0
  31. package/dist/commands/{channel → teamwork}/agent-loader.js +4 -35
  32. package/dist/commands/teamwork/agent-loader.js.map +1 -0
  33. package/dist/commands/teamwork/artifact.d.ts +177 -0
  34. package/dist/commands/teamwork/artifact.d.ts.map +1 -0
  35. package/dist/commands/teamwork/artifact.js +908 -0
  36. package/dist/commands/teamwork/artifact.js.map +1 -0
  37. package/dist/commands/{channel → teamwork}/context-loader.d.ts +1 -1
  38. package/dist/commands/teamwork/context-loader.d.ts.map +1 -0
  39. package/dist/commands/{channel → teamwork}/context-loader.js +12 -12
  40. package/dist/commands/teamwork/context-loader.js.map +1 -0
  41. package/dist/commands/{channel → teamwork}/context-trust.d.ts +6 -6
  42. package/dist/commands/teamwork/context-trust.d.ts.map +1 -0
  43. package/dist/commands/{channel → teamwork}/context-trust.js +16 -16
  44. package/dist/commands/teamwork/context-trust.js.map +1 -0
  45. package/dist/commands/teamwork/context.d.ts +16 -0
  46. package/dist/commands/teamwork/context.d.ts.map +1 -0
  47. package/dist/commands/{channel → teamwork}/context.js +17 -17
  48. package/dist/commands/teamwork/context.js.map +1 -0
  49. package/dist/commands/teamwork/coordinator.d.ts +89 -0
  50. package/dist/commands/teamwork/coordinator.d.ts.map +1 -0
  51. package/dist/commands/teamwork/coordinator.js +1198 -0
  52. package/dist/commands/teamwork/coordinator.js.map +1 -0
  53. package/dist/commands/teamwork/create.d.ts +23 -0
  54. package/dist/commands/teamwork/create.d.ts.map +1 -0
  55. package/dist/commands/teamwork/create.js +39 -0
  56. package/dist/commands/teamwork/create.js.map +1 -0
  57. package/dist/commands/{channel → teamwork}/dev-parse-trace.d.ts +1 -1
  58. package/dist/commands/teamwork/dev-parse-trace.d.ts.map +1 -0
  59. package/dist/commands/{channel → teamwork}/dev-parse-trace.js +1 -1
  60. package/dist/commands/teamwork/dev-parse-trace.js.map +1 -0
  61. package/dist/commands/{channel → teamwork}/guard.d.ts +27 -46
  62. package/dist/commands/teamwork/guard.d.ts.map +1 -0
  63. package/dist/commands/{channel → teamwork}/guard.js +54 -156
  64. package/dist/commands/teamwork/guard.js.map +1 -0
  65. package/dist/commands/teamwork/index.d.ts +3 -0
  66. package/dist/commands/teamwork/index.d.ts.map +1 -0
  67. package/dist/commands/{channel → teamwork}/index.js +135 -165
  68. package/dist/commands/teamwork/index.js.map +1 -0
  69. package/dist/commands/{channel → teamwork}/interrupt.d.ts +1 -1
  70. package/dist/commands/teamwork/interrupt.d.ts.map +1 -0
  71. package/dist/commands/teamwork/interrupt.js +22 -0
  72. package/dist/commands/teamwork/interrupt.js.map +1 -0
  73. package/dist/commands/teamwork/kill.d.ts +7 -0
  74. package/dist/commands/teamwork/kill.d.ts.map +1 -0
  75. package/dist/commands/{channel → teamwork}/kill.js +21 -21
  76. package/dist/commands/teamwork/kill.js.map +1 -0
  77. package/dist/commands/teamwork/list.d.ts +17 -0
  78. package/dist/commands/teamwork/list.d.ts.map +1 -0
  79. package/dist/commands/{channel → teamwork}/list.js +18 -27
  80. package/dist/commands/teamwork/list.js.map +1 -0
  81. package/dist/commands/{channel → teamwork}/messages.d.ts +1 -1
  82. package/dist/commands/teamwork/messages.d.ts.map +1 -0
  83. package/dist/commands/{channel → teamwork}/messages.js +18 -18
  84. package/dist/commands/teamwork/messages.js.map +1 -0
  85. package/dist/commands/teamwork/profiles.d.ts +25 -0
  86. package/dist/commands/teamwork/profiles.d.ts.map +1 -0
  87. package/dist/commands/teamwork/profiles.js +125 -0
  88. package/dist/commands/teamwork/profiles.js.map +1 -0
  89. package/dist/commands/teamwork/rm.d.ts +27 -0
  90. package/dist/commands/teamwork/rm.d.ts.map +1 -0
  91. package/dist/commands/{channel → teamwork}/rm.js +21 -22
  92. package/dist/commands/teamwork/rm.js.map +1 -0
  93. package/dist/commands/teamwork/run.d.ts +29 -0
  94. package/dist/commands/{channel → teamwork}/run.d.ts.map +1 -1
  95. package/dist/commands/teamwork/run.js +129 -0
  96. package/dist/commands/teamwork/run.js.map +1 -0
  97. package/dist/commands/{channel → teamwork}/send.d.ts +1 -1
  98. package/dist/commands/teamwork/send.d.ts.map +1 -0
  99. package/dist/commands/{channel → teamwork}/send.js +7 -7
  100. package/dist/commands/teamwork/send.js.map +1 -0
  101. package/dist/commands/{channel → teamwork}/spawn.d.ts +8 -12
  102. package/dist/commands/teamwork/spawn.d.ts.map +1 -0
  103. package/dist/commands/{channel → teamwork}/spawn.js +51 -112
  104. package/dist/commands/teamwork/spawn.js.map +1 -0
  105. package/dist/commands/teamwork/store/events.d.ts +22 -0
  106. package/dist/commands/teamwork/store/events.d.ts.map +1 -0
  107. package/dist/commands/{channel → teamwork}/store/events.js +8 -8
  108. package/dist/commands/teamwork/store/events.js.map +1 -0
  109. package/dist/commands/teamwork/store/filter.d.ts +3 -0
  110. package/dist/commands/teamwork/store/filter.d.ts.map +1 -0
  111. package/dist/commands/teamwork/store/filter.js +2 -0
  112. package/dist/commands/teamwork/store/filter.js.map +1 -0
  113. package/dist/commands/{channel → teamwork}/store/lock.d.ts +1 -1
  114. package/dist/commands/teamwork/store/lock.d.ts.map +1 -0
  115. package/dist/commands/{channel → teamwork}/store/lock.js +2 -2
  116. package/dist/commands/teamwork/store/lock.js.map +1 -0
  117. package/dist/commands/{channel → teamwork}/store/paths.d.ts +18 -32
  118. package/dist/commands/teamwork/store/paths.d.ts.map +1 -0
  119. package/dist/commands/{channel → teamwork}/store/paths.js +42 -109
  120. package/dist/commands/teamwork/store/paths.js.map +1 -0
  121. package/dist/commands/teamwork/store/schema.d.ts +18 -0
  122. package/dist/commands/teamwork/store/schema.d.ts.map +1 -0
  123. package/dist/commands/teamwork/store/schema.js +23 -0
  124. package/dist/commands/teamwork/store/schema.js.map +1 -0
  125. package/dist/commands/{channel → teamwork}/store/thread-state.d.ts +3 -3
  126. package/dist/commands/teamwork/store/thread-state.d.ts.map +1 -0
  127. package/dist/commands/{channel → teamwork}/store/thread-state.js +1 -1
  128. package/dist/commands/teamwork/store/thread-state.js.map +1 -0
  129. package/dist/commands/teamwork/store/watch.d.ts +19 -0
  130. package/dist/commands/teamwork/store/watch.d.ts.map +1 -0
  131. package/dist/commands/{channel → teamwork}/store/watch.js +8 -8
  132. package/dist/commands/teamwork/store/watch.js.map +1 -0
  133. package/dist/commands/teamwork/supervisor/idle.d.ts.map +1 -0
  134. package/dist/commands/teamwork/supervisor/idle.js.map +1 -0
  135. package/dist/commands/{channel → teamwork}/supervisor/inbox.d.ts +2 -2
  136. package/dist/commands/teamwork/supervisor/inbox.d.ts.map +1 -0
  137. package/dist/commands/{channel → teamwork}/supervisor/inbox.js +14 -14
  138. package/dist/commands/teamwork/supervisor/inbox.js.map +1 -0
  139. package/dist/commands/{channel → teamwork}/supervisor/shutdown.d.ts +3 -6
  140. package/dist/commands/teamwork/supervisor/shutdown.d.ts.map +1 -0
  141. package/dist/commands/{channel → teamwork}/supervisor/shutdown.js +7 -17
  142. package/dist/commands/teamwork/supervisor/shutdown.js.map +1 -0
  143. package/dist/commands/{channel → teamwork}/supervisor/stdout.d.ts +3 -5
  144. package/dist/commands/teamwork/supervisor/stdout.d.ts.map +1 -0
  145. package/dist/commands/{channel → teamwork}/supervisor/stdout.js +12 -23
  146. package/dist/commands/teamwork/supervisor/stdout.js.map +1 -0
  147. package/dist/commands/teamwork/supervisor/turns.d.ts.map +1 -0
  148. package/dist/commands/teamwork/supervisor/turns.js.map +1 -0
  149. package/dist/commands/{channel → teamwork}/supervisor/warning.d.ts +5 -5
  150. package/dist/commands/teamwork/supervisor/warning.d.ts.map +1 -0
  151. package/dist/commands/{channel → teamwork}/supervisor/warning.js +6 -6
  152. package/dist/commands/teamwork/supervisor/warning.js.map +1 -0
  153. package/dist/commands/{channel → teamwork}/supervisor.d.ts +21 -21
  154. package/dist/commands/teamwork/supervisor.d.ts.map +1 -0
  155. package/dist/commands/{channel → teamwork}/supervisor.js +53 -63
  156. package/dist/commands/teamwork/supervisor.js.map +1 -0
  157. package/dist/commands/teamwork/teammate-adapters.d.ts +31 -0
  158. package/dist/commands/teamwork/teammate-adapters.d.ts.map +1 -0
  159. package/dist/commands/teamwork/teammate-adapters.js +96 -0
  160. package/dist/commands/teamwork/teammate-adapters.js.map +1 -0
  161. package/dist/commands/teamwork/teammate-config.d.ts +19 -0
  162. package/dist/commands/teamwork/teammate-config.d.ts.map +1 -0
  163. package/dist/commands/teamwork/teammate-config.js +97 -0
  164. package/dist/commands/teamwork/teammate-config.js.map +1 -0
  165. package/dist/commands/teamwork/teammate-launch.d.ts +58 -0
  166. package/dist/commands/teamwork/teammate-launch.d.ts.map +1 -0
  167. package/dist/commands/teamwork/teammate-launch.js +125 -0
  168. package/dist/commands/teamwork/teammate-launch.js.map +1 -0
  169. package/dist/commands/teamwork/text-body.d.ts +13 -0
  170. package/dist/commands/teamwork/text-body.d.ts.map +1 -0
  171. package/dist/commands/{channel → teamwork}/text-body.js +3 -3
  172. package/dist/commands/teamwork/text-body.js.map +1 -0
  173. package/dist/commands/teamwork/threads.d.ts +35 -0
  174. package/dist/commands/teamwork/threads.d.ts.map +1 -0
  175. package/dist/commands/{channel → teamwork}/threads.js +19 -19
  176. package/dist/commands/teamwork/threads.js.map +1 -0
  177. package/dist/commands/teamwork/title.d.ts +12 -0
  178. package/dist/commands/teamwork/title.d.ts.map +1 -0
  179. package/dist/commands/teamwork/title.js +24 -0
  180. package/dist/commands/teamwork/title.js.map +1 -0
  181. package/dist/commands/{channel → teamwork}/wait.d.ts +1 -5
  182. package/dist/commands/teamwork/wait.d.ts.map +1 -0
  183. package/dist/commands/{channel → teamwork}/wait.js +8 -21
  184. package/dist/commands/teamwork/wait.js.map +1 -0
  185. package/dist/commands/update.d.ts.map +1 -1
  186. package/dist/commands/update.js +48 -89
  187. package/dist/commands/update.js.map +1 -1
  188. package/dist/commands/workflow.d.ts +1 -1
  189. package/dist/commands/workflow.d.ts.map +1 -1
  190. package/dist/commands/workflow.js +9 -10
  191. package/dist/commands/workflow.js.map +1 -1
  192. package/dist/configurators/claude.d.ts +0 -17
  193. package/dist/configurators/claude.d.ts.map +1 -1
  194. package/dist/configurators/claude.js +2 -61
  195. package/dist/configurators/claude.js.map +1 -1
  196. package/dist/configurators/shared.d.ts.map +1 -1
  197. package/dist/configurators/shared.js +2 -2
  198. package/dist/configurators/shared.js.map +1 -1
  199. package/dist/configurators/snow.js +1 -1
  200. package/dist/configurators/snow.js.map +1 -1
  201. package/dist/configurators/workflow.d.ts +1 -1
  202. package/dist/configurators/workflow.js +5 -5
  203. package/dist/configurators/workflow.js.map +1 -1
  204. package/dist/constants/paths.d.ts +1 -1
  205. package/dist/constants/paths.d.ts.map +1 -1
  206. package/dist/constants/paths.js +1 -1
  207. package/dist/constants/paths.js.map +1 -1
  208. package/dist/migrations/manifests/0.7.0-beta.10.json +9 -0
  209. package/dist/migrations/manifests/0.7.0-beta.11.json +9 -0
  210. package/dist/migrations/manifests/0.7.0-beta.12.json +9 -0
  211. package/dist/migrations/manifests/0.7.0-beta.13.json +9 -0
  212. package/dist/migrations/manifests/0.7.0-beta.14.json +9 -0
  213. package/dist/migrations/manifests/0.7.0-beta.15.json +9 -0
  214. package/dist/migrations/manifests/0.7.0-beta.16.json +9 -0
  215. package/dist/migrations/manifests/0.7.0-beta.17.json +9 -0
  216. package/dist/migrations/manifests/0.7.0-beta.18.json +9 -0
  217. package/dist/migrations/manifests/0.7.0-beta.19.json +9 -0
  218. package/dist/migrations/manifests/0.7.0-beta.20.json +9 -0
  219. package/dist/migrations/manifests/0.7.0-beta.21.json +17 -0
  220. package/dist/migrations/manifests/0.7.0-beta.22.json +9 -0
  221. package/dist/migrations/manifests/0.7.0-beta.23.json +9 -0
  222. package/dist/migrations/manifests/0.7.0-beta.24.json +9 -0
  223. package/dist/migrations/manifests/0.7.0-beta.25.json +9 -0
  224. package/dist/migrations/manifests/0.7.0-beta.26.json +9 -0
  225. package/dist/migrations/manifests/0.7.0-beta.27.json +9 -0
  226. package/dist/migrations/manifests/0.7.0-beta.28.json +9 -0
  227. package/dist/migrations/manifests/0.7.0-beta.29.json +9 -0
  228. package/dist/migrations/manifests/0.7.0-beta.30.json +9 -0
  229. package/dist/migrations/manifests/0.7.0-beta.31.json +9 -0
  230. package/dist/migrations/manifests/0.7.0-beta.32.json +9 -0
  231. package/dist/migrations/manifests/0.7.0-beta.33.json +9 -0
  232. package/dist/migrations/manifests/0.7.0-beta.34.json +9 -0
  233. package/dist/migrations/manifests/0.7.0-beta.35.json +9 -0
  234. package/dist/migrations/manifests/0.7.0-beta.36.json +9 -0
  235. package/dist/migrations/manifests/0.7.0-beta.37.json +9 -0
  236. package/dist/migrations/manifests/0.7.0-beta.38.json +9 -0
  237. package/dist/migrations/manifests/0.7.0-beta.39.json +9 -0
  238. package/dist/migrations/manifests/0.7.0-beta.40.json +9 -0
  239. package/dist/migrations/manifests/0.7.0-beta.41.json +9 -0
  240. package/dist/migrations/manifests/0.7.0-beta.42.json +9 -0
  241. package/dist/migrations/manifests/0.7.0-beta.43.json +9 -0
  242. package/dist/migrations/manifests/0.7.0-beta.44.json +9 -0
  243. package/dist/migrations/manifests/0.7.0-beta.45.json +9 -0
  244. package/dist/migrations/manifests/0.7.0-beta.46.json +9 -0
  245. package/dist/migrations/manifests/0.7.0-beta.47.json +9 -0
  246. package/dist/migrations/manifests/0.7.0-beta.48.json +9 -0
  247. package/dist/migrations/manifests/0.7.0-beta.49.json +13 -0
  248. package/dist/migrations/manifests/0.7.0-beta.50.json +12 -0
  249. package/dist/migrations/manifests/0.7.0-beta.51.json +9 -0
  250. package/dist/migrations/manifests/0.7.0-beta.52.json +9 -0
  251. package/dist/migrations/manifests/0.7.0-beta.53.json +27 -0
  252. package/dist/migrations/manifests/0.7.0-beta.54.json +8 -0
  253. package/dist/migrations/manifests/0.7.1-beta.0.json +9 -0
  254. package/dist/migrations/manifests/0.7.1.json +9 -0
  255. package/dist/templates/claude/hooks/statusline.py +0 -7
  256. package/dist/templates/codex/hooks/session-start.py +31 -38
  257. package/dist/templates/common/bundled-skills/trellis-decision-space-construction-and-merging/SKILL.md +10 -0
  258. package/dist/templates/common/bundled-skills/trellis-decision-space-construction-and-merging/workflow.md +40 -0
  259. package/dist/templates/common/bundled-skills/trellis-delivery-review-and-closeout/SKILL.md +10 -0
  260. package/dist/templates/common/bundled-skills/trellis-delivery-review-and-closeout/workflow.md +55 -0
  261. package/dist/templates/common/bundled-skills/trellis-goal-exploration-and-requirements/SKILL.md +10 -0
  262. package/dist/templates/common/bundled-skills/trellis-goal-exploration-and-requirements/workflow.md +33 -0
  263. package/dist/templates/common/bundled-skills/trellis-meta/SKILL.md +25 -25
  264. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-agents.md +1 -1
  265. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-skills-or-commands.md +13 -19
  266. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-spec-structure.md +1 -1
  267. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-task-lifecycle.md +27 -75
  268. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-workflow.md +17 -56
  269. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/overview.md +1 -1
  270. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/bundled-skills.md +14 -11
  271. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/generated-files.md +0 -33
  272. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/multi-agent-teamwork.md +32 -0
  273. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/spec-system.md +1 -1
  274. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/task-system.md +25 -111
  275. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/workflow.md +19 -60
  276. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/skills-and-commands.md +1 -1
  277. package/dist/templates/common/bundled-skills/trellis-session-insight/SKILL.md +1 -1
  278. package/dist/templates/common/bundled-skills/trellis-session-insight/references/cli-quick-reference.md +1 -1
  279. package/dist/templates/common/bundled-skills/trellis-solution-design-and-convergence/SKILL.md +10 -0
  280. package/dist/templates/common/bundled-skills/trellis-solution-design-and-convergence/workflow.md +36 -0
  281. package/dist/templates/common/bundled-skills/trellis-task-implementation/SKILL.md +10 -0
  282. package/dist/templates/common/bundled-skills/trellis-task-implementation/workflow.md +29 -0
  283. package/dist/templates/common/bundled-skills/trellis-teamwork/SKILL.md +73 -0
  284. package/dist/templates/common/bundled-skills/trellis-teamwork/references/coordination-modes.md +29 -0
  285. package/dist/templates/common/bundled-skills/trellis-teamwork/references/teammate-configuration-matrix.md +31 -0
  286. package/dist/templates/common/bundled-skills/trellis-teamwork/references/teammate-processes.md +37 -0
  287. package/dist/templates/common/bundled-skills/trellis-teamwork/references/teamwork-plan-construction.md +78 -0
  288. package/dist/templates/common/commands/continue.md +9 -49
  289. package/dist/templates/common/commands/finish-work.md +10 -58
  290. package/dist/templates/common/commands/start.md +19 -49
  291. package/dist/templates/common/skills/brainstorm.md +11 -199
  292. package/dist/templates/copilot/hooks/session-start.py +30 -26
  293. package/dist/templates/copilot/prompts/brainstorm.prompt.md +7 -160
  294. package/dist/templates/copilot/prompts/finish-work.prompt.md +11 -88
  295. package/dist/templates/copilot/prompts/record-session.prompt.md +4 -12
  296. package/dist/templates/copilot/prompts/start.prompt.md +12 -10
  297. package/dist/templates/dsh/DSH.md +2 -2
  298. package/dist/templates/kiro/agents/trellis.json +2 -2
  299. package/dist/templates/markdown/agents.md +14 -3
  300. package/dist/templates/markdown/spec/guides/cross-layer-thinking-guide.md.txt +9 -8
  301. package/dist/templates/markdown/spec/guides/cross-platform-thinking-guide.md.txt +1 -1
  302. package/dist/templates/markdown/workspace-index.md +0 -1
  303. package/dist/templates/omp/extensions/trellis/index.ts.txt +28 -17
  304. package/dist/templates/opencode/lib/session-utils.js +20 -25
  305. package/dist/templates/opencode/lib/trellis-context.js +4 -76
  306. package/dist/templates/opencode/plugins/inject-subagent-context.js +5 -4
  307. package/dist/templates/opencode/plugins/inject-workflow-state.js +14 -17
  308. package/dist/templates/shared-hooks/inject-shell-session-context.py +3 -3
  309. package/dist/templates/shared-hooks/inject-subagent-context.py +445 -67
  310. package/dist/templates/shared-hooks/inject-workflow-state.py +44 -36
  311. package/dist/templates/shared-hooks/session-start.py +21 -33
  312. package/dist/templates/trellis/agents/delegated-worktree-primary-agent.md +18 -0
  313. package/dist/templates/trellis/agents/teammate-profiles.json +8 -0
  314. package/dist/templates/trellis/agents/teammate.md +63 -0
  315. package/dist/templates/trellis/config.yaml +29 -38
  316. package/dist/templates/trellis/gitignore.txt +1 -0
  317. package/dist/templates/trellis/index.d.ts +8 -12
  318. package/dist/templates/trellis/index.d.ts.map +1 -1
  319. package/dist/templates/trellis/index.js +14 -25
  320. package/dist/templates/trellis/index.js.map +1 -1
  321. package/dist/templates/trellis/scripts/add_session.py +1 -1
  322. package/dist/templates/trellis/scripts/common/__init__.py +0 -1
  323. package/dist/templates/trellis/scripts/common/active_task.py +136 -100
  324. package/dist/templates/trellis/scripts/common/config.py +7 -9
  325. package/dist/templates/trellis/scripts/common/git_context.py +1 -1
  326. package/dist/templates/trellis/scripts/common/io.py +19 -0
  327. package/dist/templates/trellis/scripts/common/paths.py +0 -1
  328. package/dist/templates/trellis/scripts/common/safe_commit.py +11 -90
  329. package/dist/templates/trellis/scripts/common/session_context.py +1 -8
  330. package/dist/templates/trellis/scripts/common/spec_match.py +1 -1
  331. package/dist/templates/trellis/scripts/common/task_context.py +152 -59
  332. package/dist/templates/trellis/scripts/common/task_continuity.py +598 -0
  333. package/dist/templates/trellis/scripts/common/task_store.py +70 -548
  334. package/dist/templates/trellis/scripts/common/task_utils.py +4 -98
  335. package/dist/templates/trellis/scripts/common/task_workflow.py +1096 -0
  336. package/dist/templates/trellis/scripts/common/tasks.py +5 -8
  337. package/dist/templates/trellis/scripts/common/workflow_phase.py +8 -7
  338. package/dist/templates/trellis/scripts/hooks/linear_sync.py +3 -3
  339. package/dist/templates/trellis/scripts/task.py +119 -377
  340. package/dist/templates/trellis/workflow.md +111 -706
  341. package/dist/utils/agent-refs.d.ts +5 -5
  342. package/dist/utils/agent-refs.js +6 -6
  343. package/dist/utils/file-writer.d.ts +3 -2
  344. package/dist/utils/file-writer.d.ts.map +1 -1
  345. package/dist/utils/file-writer.js +3 -2
  346. package/dist/utils/file-writer.js.map +1 -1
  347. package/dist/utils/managed-paths.d.ts +0 -7
  348. package/dist/utils/managed-paths.d.ts.map +1 -1
  349. package/dist/utils/managed-paths.js +0 -40
  350. package/dist/utils/managed-paths.js.map +1 -1
  351. package/dist/utils/manifest-prune.d.ts.map +1 -1
  352. package/dist/utils/manifest-prune.js +2 -11
  353. package/dist/utils/manifest-prune.js.map +1 -1
  354. package/dist/utils/uninstall-scrubbers.d.ts.map +1 -1
  355. package/dist/utils/uninstall-scrubbers.js +3 -3
  356. package/dist/utils/uninstall-scrubbers.js.map +1 -1
  357. package/dist/utils/workflow-resolver.d.ts +10 -16
  358. package/dist/utils/workflow-resolver.d.ts.map +1 -1
  359. package/dist/utils/workflow-resolver.js +25 -36
  360. package/dist/utils/workflow-resolver.js.map +1 -1
  361. package/package.json +2 -2
  362. package/dist/commands/channel/adapters/claude.d.ts.map +0 -1
  363. package/dist/commands/channel/adapters/claude.js.map +0 -1
  364. package/dist/commands/channel/adapters/codex.d.ts.map +0 -1
  365. package/dist/commands/channel/adapters/codex.js.map +0 -1
  366. package/dist/commands/channel/adapters/index.d.ts.map +0 -1
  367. package/dist/commands/channel/adapters/index.js.map +0 -1
  368. package/dist/commands/channel/adapters/types.d.ts.map +0 -1
  369. package/dist/commands/channel/adapters/types.js.map +0 -1
  370. package/dist/commands/channel/agent-loader.d.ts.map +0 -1
  371. package/dist/commands/channel/agent-loader.js.map +0 -1
  372. package/dist/commands/channel/context-loader.d.ts.map +0 -1
  373. package/dist/commands/channel/context-loader.js.map +0 -1
  374. package/dist/commands/channel/context-trust.d.ts.map +0 -1
  375. package/dist/commands/channel/context-trust.js.map +0 -1
  376. package/dist/commands/channel/context.d.ts +0 -16
  377. package/dist/commands/channel/context.d.ts.map +0 -1
  378. package/dist/commands/channel/context.js.map +0 -1
  379. package/dist/commands/channel/create.d.ts +0 -29
  380. package/dist/commands/channel/create.d.ts.map +0 -1
  381. package/dist/commands/channel/create.js +0 -47
  382. package/dist/commands/channel/create.js.map +0 -1
  383. package/dist/commands/channel/dev-parse-trace.d.ts.map +0 -1
  384. package/dist/commands/channel/dev-parse-trace.js.map +0 -1
  385. package/dist/commands/channel/guard.d.ts.map +0 -1
  386. package/dist/commands/channel/guard.js.map +0 -1
  387. package/dist/commands/channel/index.d.ts +0 -3
  388. package/dist/commands/channel/index.d.ts.map +0 -1
  389. package/dist/commands/channel/index.js.map +0 -1
  390. package/dist/commands/channel/interrupt.d.ts.map +0 -1
  391. package/dist/commands/channel/interrupt.js +0 -22
  392. package/dist/commands/channel/interrupt.js.map +0 -1
  393. package/dist/commands/channel/kill.d.ts +0 -7
  394. package/dist/commands/channel/kill.d.ts.map +0 -1
  395. package/dist/commands/channel/kill.js.map +0 -1
  396. package/dist/commands/channel/list.d.ts +0 -18
  397. package/dist/commands/channel/list.d.ts.map +0 -1
  398. package/dist/commands/channel/list.js.map +0 -1
  399. package/dist/commands/channel/messages.d.ts.map +0 -1
  400. package/dist/commands/channel/messages.js.map +0 -1
  401. package/dist/commands/channel/rm.d.ts +0 -27
  402. package/dist/commands/channel/rm.d.ts.map +0 -1
  403. package/dist/commands/channel/rm.js.map +0 -1
  404. package/dist/commands/channel/run.d.ts +0 -32
  405. package/dist/commands/channel/run.js +0 -141
  406. package/dist/commands/channel/run.js.map +0 -1
  407. package/dist/commands/channel/send.d.ts.map +0 -1
  408. package/dist/commands/channel/send.js.map +0 -1
  409. package/dist/commands/channel/spawn.d.ts.map +0 -1
  410. package/dist/commands/channel/spawn.js.map +0 -1
  411. package/dist/commands/channel/store/events.d.ts +0 -22
  412. package/dist/commands/channel/store/events.d.ts.map +0 -1
  413. package/dist/commands/channel/store/events.js.map +0 -1
  414. package/dist/commands/channel/store/filter.d.ts +0 -3
  415. package/dist/commands/channel/store/filter.d.ts.map +0 -1
  416. package/dist/commands/channel/store/filter.js +0 -2
  417. package/dist/commands/channel/store/filter.js.map +0 -1
  418. package/dist/commands/channel/store/lock.d.ts.map +0 -1
  419. package/dist/commands/channel/store/lock.js.map +0 -1
  420. package/dist/commands/channel/store/paths.d.ts.map +0 -1
  421. package/dist/commands/channel/store/paths.js.map +0 -1
  422. package/dist/commands/channel/store/schema.d.ts +0 -27
  423. package/dist/commands/channel/store/schema.d.ts.map +0 -1
  424. package/dist/commands/channel/store/schema.js +0 -34
  425. package/dist/commands/channel/store/schema.js.map +0 -1
  426. package/dist/commands/channel/store/thread-state.d.ts.map +0 -1
  427. package/dist/commands/channel/store/thread-state.js.map +0 -1
  428. package/dist/commands/channel/store/watch.d.ts +0 -19
  429. package/dist/commands/channel/store/watch.d.ts.map +0 -1
  430. package/dist/commands/channel/store/watch.js.map +0 -1
  431. package/dist/commands/channel/supervisor/idle.d.ts.map +0 -1
  432. package/dist/commands/channel/supervisor/idle.js.map +0 -1
  433. package/dist/commands/channel/supervisor/inbox.d.ts.map +0 -1
  434. package/dist/commands/channel/supervisor/inbox.js.map +0 -1
  435. package/dist/commands/channel/supervisor/shutdown.d.ts.map +0 -1
  436. package/dist/commands/channel/supervisor/shutdown.js.map +0 -1
  437. package/dist/commands/channel/supervisor/stdout.d.ts.map +0 -1
  438. package/dist/commands/channel/supervisor/stdout.js.map +0 -1
  439. package/dist/commands/channel/supervisor/turns.d.ts.map +0 -1
  440. package/dist/commands/channel/supervisor/turns.js.map +0 -1
  441. package/dist/commands/channel/supervisor/warning.d.ts.map +0 -1
  442. package/dist/commands/channel/supervisor/warning.js.map +0 -1
  443. package/dist/commands/channel/supervisor.d.ts.map +0 -1
  444. package/dist/commands/channel/supervisor.js.map +0 -1
  445. package/dist/commands/channel/text-body.d.ts +0 -13
  446. package/dist/commands/channel/text-body.d.ts.map +0 -1
  447. package/dist/commands/channel/text-body.js.map +0 -1
  448. package/dist/commands/channel/threads.d.ts +0 -39
  449. package/dist/commands/channel/threads.d.ts.map +0 -1
  450. package/dist/commands/channel/threads.js.map +0 -1
  451. package/dist/commands/channel/title.d.ts +0 -12
  452. package/dist/commands/channel/title.d.ts.map +0 -1
  453. package/dist/commands/channel/title.js +0 -24
  454. package/dist/commands/channel/title.js.map +0 -1
  455. package/dist/commands/channel/wait.d.ts.map +0 -1
  456. package/dist/commands/channel/wait.js.map +0 -1
  457. package/dist/commands/channel/workers.d.ts +0 -9
  458. package/dist/commands/channel/workers.d.ts.map +0 -1
  459. package/dist/commands/channel/workers.js +0 -31
  460. package/dist/commands/channel/workers.js.map +0 -1
  461. package/dist/templates/common/bundled-skills/trellis-channel/SKILL.md +0 -69
  462. package/dist/templates/common/bundled-skills/trellis-channel/references/command-reference.md +0 -549
  463. package/dist/templates/common/bundled-skills/trellis-channel/references/forum.md +0 -233
  464. package/dist/templates/common/bundled-skills/trellis-channel/references/progress-debugging.md +0 -237
  465. package/dist/templates/common/bundled-skills/trellis-channel/references/subnode-work.md +0 -222
  466. package/dist/templates/common/bundled-skills/trellis-channel/references/workers.md +0 -295
  467. package/dist/templates/common/bundled-skills/trellis-channel/references/workflows.md +0 -131
  468. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/multi-agent-channel.md +0 -70
  469. package/dist/templates/common/bundled-skills/trellis-research-record/SKILL.md +0 -14
  470. package/dist/templates/copilot/prompts/parallel.prompt.md +0 -204
  471. package/dist/templates/trellis/agents/check.md +0 -70
  472. package/dist/templates/trellis/agents/implement.md +0 -71
  473. package/dist/templates/trellis/agents/subnode.env +0 -4
  474. package/dist/templates/trellis/agents/subnode.md +0 -76
  475. package/dist/templates/trellis/scripts/common/context_projection.py +0 -508
  476. package/dist/templates/trellis/scripts/common/continuation_record.py +0 -450
  477. package/dist/templates/trellis/scripts/common/ownership_record.py +0 -439
  478. package/dist/templates/trellis/scripts/subnode_artifact.py +0 -735
  479. package/dist/templates/trellis/scripts/workspace_note.py +0 -126
  480. /package/dist/commands/{channel → teamwork}/adapters/types.js +0 -0
  481. /package/dist/commands/{channel → teamwork}/supervisor/idle.d.ts +0 -0
  482. /package/dist/commands/{channel → teamwork}/supervisor/idle.js +0 -0
  483. /package/dist/commands/{channel → teamwork}/supervisor/turns.d.ts +0 -0
  484. /package/dist/commands/{channel → teamwork}/supervisor/turns.js +0 -0
@@ -1,439 +0,0 @@
1
- """Task-bound ownership transfer for formal cross-session handoff."""
2
-
3
- from __future__ import annotations
4
-
5
- import json
6
- import os
7
- import secrets
8
- import tempfile
9
- from datetime import datetime, timezone
10
- from pathlib import Path
11
- from typing import Any
12
-
13
- from .active_task import clear_active_task, clear_active_task_for_context, resolve_active_task, resolve_context_key, set_active_task
14
- from .continuation_record import (
15
- ContinuationError,
16
- SAFE_ID,
17
- SHA256,
18
- _digest,
19
- _project_file,
20
- _record_lock,
21
- _safe_task_id,
22
- _text,
23
- )
24
- from .io import read_json_checked
25
- from .paths import FILE_TASK_JSON, get_repo_root
26
-
27
-
28
- KIND = "trellis-handoff-ownership"
29
- SCHEMA_VERSION = 1
30
- STATES = {"quiescing", "sealed", "retiring", "ready", "claiming", "claimed", "consumed", "archived"}
31
- ARCHIVE_OBSERVATIONS = {"not_required", "observed"}
32
- MAX_RECORD_BYTES = 32 * 1024
33
-
34
-
35
- class OwnershipError(ContinuationError):
36
- """Raised when a handoff ownership transition is unsafe or stale."""
37
-
38
-
39
- def _identity(value: Any, label: str) -> str:
40
- value = _text(value, label, 160)
41
- if not SAFE_ID.fullmatch(value):
42
- raise OwnershipError(f"{label} is unsafe")
43
- return value
44
-
45
-
46
- def _record_path(root: Path, task_id: str, handoff_id: str) -> Path:
47
- task_id = _safe_task_id(task_id)
48
- handoff_id = _identity(handoff_id, "handoff_id")
49
- runtime = root / ".trellis" / ".runtime"
50
- records = runtime / "handoff-ownership"
51
- task_dir = records / task_id
52
- if runtime.is_symlink() or records.is_symlink() or task_dir.is_symlink():
53
- raise OwnershipError("ownership record directory is unsafe")
54
- return task_dir / f"{handoff_id}.json"
55
-
56
-
57
- def _now() -> str:
58
- return datetime.now(timezone.utc).isoformat(timespec="microseconds").replace("+00:00", "Z")
59
-
60
-
61
- def _task_snapshot(root: Path, task_path: str) -> dict[str, str]:
62
- path = _project_file(root, task_path, "task path")
63
- relative = path.relative_to(root).as_posix()
64
- if not relative.startswith(".trellis/tasks/"):
65
- raise OwnershipError("task path is outside .trellis/tasks")
66
- data, reason = read_json_checked(path / FILE_TASK_JSON)
67
- if data is None:
68
- raise OwnershipError(f"task.json is {reason}")
69
- task_id = _safe_task_id(data.get("id") or data.get("name"))
70
- return {"id": task_id, "path": relative, "status": _text(data.get("status"), "task.status", 64)}
71
-
72
-
73
- def _direct_context(root: Path, require_task: bool = False) -> tuple[str, Any]:
74
- context_key = resolve_context_key()
75
- if not context_key:
76
- raise OwnershipError("no_direct_session_identity")
77
- active = resolve_active_task(
78
- root,
79
- allow_single_session_fallback=False,
80
- allow_environment_context=True,
81
- )
82
- if active.source_type == "session-fallback":
83
- raise OwnershipError("session_fallback_untrusted")
84
- if active.context_key != context_key:
85
- raise OwnershipError("direct_session_identity_unstable")
86
- if require_task and not active.task_path:
87
- raise OwnershipError("no_direct_current_task")
88
- return context_key, active
89
-
90
-
91
- def _new_record(task: dict[str, str], handoff_id: str, core_digest: str, source: str) -> dict[str, Any]:
92
- if not SHA256.fullmatch(core_digest):
93
- raise OwnershipError("core_digest is invalid")
94
- return {
95
- "schema_version": SCHEMA_VERSION,
96
- "kind": KIND,
97
- "handoff_id": _identity(handoff_id, "handoff_id"),
98
- "core_digest": core_digest,
99
- "task": task,
100
- "source_session_id": source,
101
- "source_context_key": source,
102
- "consumer_session_id": None,
103
- "consumer_context_key": None,
104
- "state": "quiescing",
105
- "generation": 0,
106
- "fencing_token": secrets.token_hex(16),
107
- "archive_observation": None,
108
- "event_id": f"event-{secrets.token_hex(12)}",
109
- "previous_event_digest": None,
110
- "updated_at": _now(),
111
- }
112
-
113
-
114
- def _record_digest(record: dict[str, Any]) -> str:
115
- return _digest({key: value for key, value in record.items() if key != "integrity"})
116
-
117
-
118
- def _decode(path: Path) -> dict[str, Any]:
119
- if path.is_symlink() or not path.is_file() or path.stat().st_size > MAX_RECORD_BYTES:
120
- raise OwnershipError("ownership record is unsafe or too large")
121
- data, reason = read_json_checked(path)
122
- if data is None:
123
- raise OwnershipError(f"ownership record is {reason}")
124
- required = {
125
- "schema_version", "kind", "handoff_id", "core_digest", "task",
126
- "source_session_id", "source_context_key", "consumer_session_id",
127
- "consumer_context_key", "state", "generation", "fencing_token",
128
- "archive_observation", "event_id", "previous_event_digest", "updated_at", "integrity",
129
- }
130
- if set(data) != required or data["schema_version"] != SCHEMA_VERSION or data["kind"] != KIND:
131
- raise OwnershipError("ownership record schema is unsupported")
132
- _identity(data["handoff_id"], "handoff_id")
133
- if not SHA256.fullmatch(data["core_digest"]):
134
- raise OwnershipError("core_digest is invalid")
135
- task = data["task"]
136
- if not isinstance(task, dict) or set(task) != {"id", "path", "status"}:
137
- raise OwnershipError("ownership task is invalid")
138
- _safe_task_id(task["id"])
139
- _text(task["path"], "task.path", 1024)
140
- _text(task["status"], "task.status", 64)
141
- for key in ("source_session_id", "source_context_key"):
142
- _identity(data[key], key)
143
- for key in ("consumer_session_id", "consumer_context_key"):
144
- if data[key] is not None:
145
- _identity(data[key], key)
146
- if data["state"] not in STATES or not isinstance(data["generation"], int) or data["generation"] < 0:
147
- raise OwnershipError("ownership state is invalid")
148
- _identity(data["fencing_token"], "fencing_token")
149
- if data["archive_observation"] is not None and data["archive_observation"] not in ARCHIVE_OBSERVATIONS:
150
- raise OwnershipError("archive observation is invalid")
151
- _identity(data["event_id"], "event_id")
152
- if data["previous_event_digest"] is not None and not SHA256.fullmatch(data["previous_event_digest"]):
153
- raise OwnershipError("previous event digest is invalid")
154
- _text(data["updated_at"], "updated_at", 128)
155
- integrity = data["integrity"]
156
- if not isinstance(integrity, dict) or set(integrity) != {"record_digest"} or not SHA256.fullmatch(integrity["record_digest"]):
157
- raise OwnershipError("ownership integrity is invalid")
158
- if integrity["record_digest"] != _record_digest(data):
159
- raise OwnershipError("ownership record digest does not match")
160
- return data
161
-
162
-
163
- def _write(path: Path, record: dict[str, Any]) -> str:
164
- record["event_id"] = f"event-{secrets.token_hex(12)}"
165
- record["updated_at"] = _now()
166
- record["integrity"] = {"record_digest": _record_digest(record)}
167
- encoded = json.dumps(record, ensure_ascii=True, indent=2, sort_keys=True) + "\n"
168
- if len(encoded.encode("utf-8")) > MAX_RECORD_BYTES:
169
- raise OwnershipError("ownership record is too large")
170
- temporary: Path | None = None
171
- try:
172
- path.parent.mkdir(parents=True, exist_ok=True)
173
- with tempfile.NamedTemporaryFile("w", encoding="utf-8", dir=path.parent, delete=False) as handle:
174
- temporary = Path(handle.name)
175
- handle.write(encoded)
176
- handle.flush()
177
- os.fsync(handle.fileno())
178
- os.chmod(temporary, 0o600)
179
- os.replace(temporary, path)
180
- directory_fd = os.open(path.parent, os.O_RDONLY)
181
- try:
182
- os.fsync(directory_fd)
183
- finally:
184
- os.close(directory_fd)
185
- except OSError as exc:
186
- if temporary is not None:
187
- temporary.unlink(missing_ok=True)
188
- raise OwnershipError("ownership record atomic write failed") from exc
189
- return record["integrity"]["record_digest"]
190
-
191
-
192
- def _load(root: Path, task_id: str, handoff_id: str) -> tuple[Path, dict[str, Any]]:
193
- path = _record_path(root, task_id, handoff_id)
194
- if not path.exists():
195
- raise OwnershipError("ownership record is absent")
196
- return path, _decode(path)
197
-
198
-
199
- def _check(record: dict[str, Any], core_digest: str, expected_generation: int, actor: str) -> None:
200
- if record["core_digest"] != core_digest:
201
- raise OwnershipError("core_digest does not match")
202
- if record["generation"] != expected_generation:
203
- raise OwnershipError("expected ownership generation does not match")
204
- if record["source_session_id"] != actor and record.get("consumer_session_id") != actor:
205
- raise OwnershipError("session is not an ownership actor")
206
-
207
-
208
- def _public(record: dict[str, Any]) -> dict[str, Any]:
209
- return {
210
- "status": record["state"],
211
- "handoff_id": record["handoff_id"],
212
- "core_digest": record["core_digest"],
213
- "task": record["task"],
214
- "source_session_id": record["source_session_id"],
215
- "consumer_session_id": record["consumer_session_id"],
216
- "generation": record["generation"],
217
- "archive_observation": record["archive_observation"],
218
- "record_digest": record["integrity"]["record_digest"],
219
- "updated_at": record["updated_at"],
220
- }
221
-
222
-
223
- def quiesce(root: Path, task_path: str, handoff_id: str, core_digest: str, source_session_id: str) -> dict[str, Any]:
224
- actor, active = _direct_context(root, require_task=True)
225
- task = _task_snapshot(root, task_path)
226
- if active.source_type != "session" or active.context_key != actor or active.task_path != task["path"]:
227
- raise OwnershipError("source task is not the direct current task")
228
- if _identity(source_session_id, "source_session_id") != actor:
229
- raise OwnershipError("source_session_id does not match direct session")
230
- path = _record_path(root, task["id"], handoff_id)
231
- with _record_lock(path):
232
- if path.exists():
233
- raise OwnershipError("ownership record already exists")
234
- record = _new_record(task, handoff_id, core_digest, actor)
235
- digest = _write(path, record)
236
- return {"status": "quiescing", "generation": 0, "record_digest": digest}
237
-
238
-
239
- def seal(root: Path, task_id: str, handoff_id: str, core_digest: str, expected_generation: int) -> dict[str, Any]:
240
- actor, _ = _direct_context(root)
241
- path, record = _load(root, task_id, handoff_id)
242
- with _record_lock(path):
243
- record = _decode(path)
244
- _check(record, core_digest, expected_generation, actor)
245
- if record["state"] != "quiescing" or record["source_session_id"] != actor:
246
- raise OwnershipError("ownership record is not sealable by source")
247
- record["previous_event_digest"] = record["integrity"]["record_digest"]
248
- record["state"] = "sealed"
249
- record["generation"] += 1
250
- digest = _write(path, record)
251
- return _public(record) | {"record_digest": digest}
252
-
253
-
254
- def retire(root: Path, task_id: str, handoff_id: str, core_digest: str, expected_generation: int, archive_observation: str) -> dict[str, Any]:
255
- if archive_observation not in ARCHIVE_OBSERVATIONS:
256
- raise OwnershipError("archive observation is invalid")
257
- actor, active = _direct_context(root)
258
- path, record = _load(root, task_id, handoff_id)
259
- with _record_lock(path):
260
- record = _decode(path)
261
- _check(record, core_digest, expected_generation, actor)
262
- if record["source_session_id"] != actor or record["state"] not in {"sealed", "retiring"}:
263
- raise OwnershipError("ownership record is not retireable by source")
264
- if record["state"] == "sealed":
265
- if active.task_path != record["task"]["path"]:
266
- raise OwnershipError("source task is not bound for retirement")
267
- record["previous_event_digest"] = record["integrity"]["record_digest"]
268
- record["state"] = "retiring"
269
- record["archive_observation"] = archive_observation
270
- record["generation"] += 1
271
- record["fencing_token"] = secrets.token_hex(16)
272
- _write(path, record)
273
- elif record["archive_observation"] != archive_observation:
274
- raise OwnershipError("archive observation does not match retirement")
275
-
276
- active = resolve_active_task(root, allow_single_session_fallback=False)
277
- if active.context_key != actor:
278
- raise OwnershipError("direct_session_identity_unstable")
279
- if active.task_path == record["task"]["path"]:
280
- clear_active_task(root)
281
- elif active.task_path:
282
- raise OwnershipError("source task pointer changed during retirement")
283
- active = resolve_active_task(root, allow_single_session_fallback=False)
284
- if active.context_key != actor or active.task_path:
285
- raise OwnershipError("source task retirement could not be verified; recovery_required")
286
- record["previous_event_digest"] = record["integrity"]["record_digest"]
287
- record["state"] = "ready"
288
- record["generation"] += 1
289
- digest = _write(path, record)
290
- return _public(record) | {"record_digest": digest}
291
-
292
-
293
- def retire_handoff(root: Path, task_id: str, handoff_id: str, core_digest: str) -> dict[str, Any]:
294
- """Release one sealed handoff without requiring the departed source context."""
295
- path, record = _load(root, task_id, handoff_id)
296
- with _record_lock(path):
297
- record = _decode(path)
298
- if record["core_digest"] != core_digest:
299
- raise OwnershipError("core_digest does not match")
300
- if record["state"] == "ready":
301
- return _public(record)
302
- if record["state"] not in {"sealed", "retiring"}:
303
- raise OwnershipError("ownership record is not a sealed handoff")
304
- if record["state"] == "sealed":
305
- record["previous_event_digest"] = record["integrity"]["record_digest"]
306
- record["state"] = "retiring"
307
- record["generation"] += 1
308
- _write(path, record)
309
- cleared = clear_active_task_for_context(record["source_context_key"], record["task"]["path"], root)
310
- if cleared == "changed":
311
- raise OwnershipError("source task pointer changed during handoff retirement")
312
- record["previous_event_digest"] = record["integrity"]["record_digest"]
313
- record["state"] = "ready"
314
- record["generation"] += 1
315
- digest = _write(path, record)
316
- return _public(record) | {"record_digest": digest}
317
-
318
-
319
- def claim(root: Path, task_id: str, task_path: str, handoff_id: str, core_digest: str, expected_generation: int) -> dict[str, Any]:
320
- actor, active = _direct_context(root)
321
- path, record = _load(root, task_id, handoff_id)
322
- with _record_lock(path):
323
- record = _decode(path)
324
- if record["core_digest"] != core_digest:
325
- raise OwnershipError("expected ownership claim does not match")
326
- if record["state"] == "claimed" and record.get("consumer_session_id") == actor:
327
- if active.task_path != record["task"]["path"]:
328
- raise OwnershipError("claimed consumer task pointer is missing")
329
- return _public(record)
330
- if record["state"] == "claiming" and record.get("consumer_session_id") == actor:
331
- if active.task_path and active.task_path != record["task"]["path"]:
332
- raise OwnershipError("target task pointer changed during claim; recovery_required")
333
- if not active.task_path:
334
- bound = set_active_task(record["task"]["path"], root)
335
- if not bound:
336
- raise OwnershipError("target task binding failed; recovery_required")
337
- active = resolve_active_task(root, allow_single_session_fallback=False)
338
- if active.context_key != actor or active.task_path != record["task"]["path"]:
339
- raise OwnershipError("target task binding could not be verified; recovery_required")
340
- record["previous_event_digest"] = record["integrity"]["record_digest"]
341
- record["state"] = "claimed"
342
- record["generation"] += 1
343
- digest = _write(path, record)
344
- return _public(record) | {"record_digest": digest}
345
- if record["generation"] != expected_generation:
346
- raise OwnershipError("expected ownership claim does not match")
347
- if record["state"] != "ready":
348
- raise OwnershipError("ownership record is not claimable")
349
- if active.task_path:
350
- raise OwnershipError("target session already has a direct task")
351
- task = _task_snapshot(root, task_path)
352
- if task != record["task"]:
353
- raise OwnershipError("target task does not match ownership record")
354
- record["previous_event_digest"] = record["integrity"]["record_digest"]
355
- record["state"] = "claiming"
356
- record["consumer_session_id"] = actor
357
- record["consumer_context_key"] = actor
358
- record["generation"] += 1
359
- record["fencing_token"] = secrets.token_hex(16)
360
- _write(path, record)
361
- bound = set_active_task(task["path"], root)
362
- if not bound:
363
- raise OwnershipError("target task binding failed; recovery_required")
364
- active = resolve_active_task(root, allow_single_session_fallback=False)
365
- if active.context_key != actor or active.task_path != task["path"]:
366
- raise OwnershipError("target task binding could not be verified; recovery_required")
367
- record["previous_event_digest"] = record["integrity"]["record_digest"]
368
- record["state"] = "claimed"
369
- record["generation"] += 1
370
- digest = _write(path, record)
371
- return _public(record) | {"record_digest": digest}
372
-
373
-
374
- def consume(root: Path, task_id: str, handoff_id: str, core_digest: str, expected_generation: int) -> dict[str, Any]:
375
- actor, _ = _direct_context(root, require_task=True)
376
- path, record = _load(root, task_id, handoff_id)
377
- with _record_lock(path):
378
- record = _decode(path)
379
- if record["state"] == "consumed" and record.get("consumer_session_id") == actor:
380
- return _public(record)
381
- _check(record, core_digest, expected_generation, actor)
382
- if record["state"] != "claimed" or record.get("consumer_session_id") != actor:
383
- raise OwnershipError("ownership record is not consumable by current consumer")
384
- record["previous_event_digest"] = record["integrity"]["record_digest"]
385
- record["state"] = "consumed"
386
- record["generation"] += 1
387
- digest = _write(path, record)
388
- return _public(record) | {"record_digest": digest}
389
-
390
-
391
- def archive(root: Path, task_id: str, handoff_id: str, core_digest: str, expected_generation: int) -> dict[str, Any]:
392
- actor, _ = _direct_context(root, require_task=True)
393
- path, record = _load(root, task_id, handoff_id)
394
- with _record_lock(path):
395
- record = _decode(path)
396
- if record["state"] == "archived" and record.get("consumer_session_id") == actor:
397
- return _public(record)
398
- _check(record, core_digest, expected_generation, actor)
399
- if record["state"] != "consumed" or record.get("consumer_session_id") != actor:
400
- raise OwnershipError("ownership record is not archiveable by current consumer")
401
- record["previous_event_digest"] = record["integrity"]["record_digest"]
402
- record["state"] = "archived"
403
- record["generation"] += 1
404
- digest = _write(path, record)
405
- return _public(record) | {"record_digest": digest}
406
-
407
-
408
- def status(root: Path | None, task_id: str, handoff_id: str, core_digest: str) -> dict[str, Any]:
409
- root = (root or get_repo_root()).resolve()
410
- _, record = _load(root, task_id, handoff_id)
411
- if record["core_digest"] != core_digest:
412
- raise OwnershipError("core_digest does not match")
413
- return _public(record)
414
-
415
-
416
- def assert_task_mutation_allowed(root: Path, task_path: Path) -> None:
417
- """Reject ordinary task pointer changes that would bypass ownership fencing."""
418
- actor = resolve_context_key()
419
- if not actor:
420
- return
421
- try:
422
- task_id = _safe_task_id(task_path.name)
423
- except ContinuationError:
424
- return
425
- relative = task_path.relative_to(root).as_posix()
426
- records_dir = root / ".trellis" / ".runtime" / "handoff-ownership" / task_id
427
- if not records_dir.is_dir() or records_dir.is_symlink():
428
- return
429
- for record_path in sorted(records_dir.glob("*.json")):
430
- if record_path.is_symlink():
431
- raise OwnershipError("ownership record is unsafe")
432
- record = _decode(record_path)
433
- if record["state"] not in STATES:
434
- continue
435
- if record["task"]["path"] != relative:
436
- raise OwnershipError("ownership record task path does not match current task")
437
- if record.get("consumer_session_id") == actor:
438
- continue
439
- raise OwnershipError("fencing_conflict: task is owned by another handoff session")