@pennixrv/trellis 0.6.17

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 (831) hide show
  1. package/LICENSE +235 -0
  2. package/README.md +168 -0
  3. package/bin/trellis.js +3 -0
  4. package/dist/cli/index.d.ts +3 -0
  5. package/dist/cli/index.d.ts.map +1 -0
  6. package/dist/cli/index.js +299 -0
  7. package/dist/cli/index.js.map +1 -0
  8. package/dist/commands/ablate.d.ts +14 -0
  9. package/dist/commands/ablate.d.ts.map +1 -0
  10. package/dist/commands/ablate.js +307 -0
  11. package/dist/commands/ablate.js.map +1 -0
  12. package/dist/commands/channel/adapters/claude.d.ts +53 -0
  13. package/dist/commands/channel/adapters/claude.d.ts.map +1 -0
  14. package/dist/commands/channel/adapters/claude.js +225 -0
  15. package/dist/commands/channel/adapters/claude.js.map +1 -0
  16. package/dist/commands/channel/adapters/codex.d.ts +93 -0
  17. package/dist/commands/channel/adapters/codex.d.ts.map +1 -0
  18. package/dist/commands/channel/adapters/codex.js +573 -0
  19. package/dist/commands/channel/adapters/codex.js.map +1 -0
  20. package/dist/commands/channel/adapters/index.d.ts +94 -0
  21. package/dist/commands/channel/adapters/index.d.ts.map +1 -0
  22. package/dist/commands/channel/adapters/index.js +116 -0
  23. package/dist/commands/channel/adapters/index.js.map +1 -0
  24. package/dist/commands/channel/adapters/types.d.ts +33 -0
  25. package/dist/commands/channel/adapters/types.d.ts.map +1 -0
  26. package/dist/commands/channel/adapters/types.js +2 -0
  27. package/dist/commands/channel/adapters/types.js.map +1 -0
  28. package/dist/commands/channel/agent-loader.d.ts +32 -0
  29. package/dist/commands/channel/agent-loader.d.ts.map +1 -0
  30. package/dist/commands/channel/agent-loader.js +158 -0
  31. package/dist/commands/channel/agent-loader.js.map +1 -0
  32. package/dist/commands/channel/context-loader.d.ts +26 -0
  33. package/dist/commands/channel/context-loader.d.ts.map +1 -0
  34. package/dist/commands/channel/context-loader.js +311 -0
  35. package/dist/commands/channel/context-loader.js.map +1 -0
  36. package/dist/commands/channel/context-trust.d.ts +31 -0
  37. package/dist/commands/channel/context-trust.d.ts.map +1 -0
  38. package/dist/commands/channel/context-trust.js +139 -0
  39. package/dist/commands/channel/context-trust.js.map +1 -0
  40. package/dist/commands/channel/context.d.ts +16 -0
  41. package/dist/commands/channel/context.d.ts.map +1 -0
  42. package/dist/commands/channel/context.js +83 -0
  43. package/dist/commands/channel/context.js.map +1 -0
  44. package/dist/commands/channel/create.d.ts +27 -0
  45. package/dist/commands/channel/create.d.ts.map +1 -0
  46. package/dist/commands/channel/create.js +39 -0
  47. package/dist/commands/channel/create.js.map +1 -0
  48. package/dist/commands/channel/dev-parse-trace.d.ts +14 -0
  49. package/dist/commands/channel/dev-parse-trace.d.ts.map +1 -0
  50. package/dist/commands/channel/dev-parse-trace.js +70 -0
  51. package/dist/commands/channel/dev-parse-trace.js.map +1 -0
  52. package/dist/commands/channel/guard.d.ts +150 -0
  53. package/dist/commands/channel/guard.d.ts.map +1 -0
  54. package/dist/commands/channel/guard.js +479 -0
  55. package/dist/commands/channel/guard.js.map +1 -0
  56. package/dist/commands/channel/index.d.ts +3 -0
  57. package/dist/commands/channel/index.d.ts.map +1 -0
  58. package/dist/commands/channel/index.js +535 -0
  59. package/dist/commands/channel/index.js.map +1 -0
  60. package/dist/commands/channel/interrupt.d.ts +10 -0
  61. package/dist/commands/channel/interrupt.d.ts.map +1 -0
  62. package/dist/commands/channel/interrupt.js +22 -0
  63. package/dist/commands/channel/interrupt.js.map +1 -0
  64. package/dist/commands/channel/kill.d.ts +7 -0
  65. package/dist/commands/channel/kill.d.ts.map +1 -0
  66. package/dist/commands/channel/kill.js +130 -0
  67. package/dist/commands/channel/kill.js.map +1 -0
  68. package/dist/commands/channel/list.d.ts +17 -0
  69. package/dist/commands/channel/list.d.ts.map +1 -0
  70. package/dist/commands/channel/list.js +233 -0
  71. package/dist/commands/channel/list.js.map +1 -0
  72. package/dist/commands/channel/messages.d.ts +15 -0
  73. package/dist/commands/channel/messages.d.ts.map +1 -0
  74. package/dist/commands/channel/messages.js +245 -0
  75. package/dist/commands/channel/messages.js.map +1 -0
  76. package/dist/commands/channel/rm.d.ts +27 -0
  77. package/dist/commands/channel/rm.d.ts.map +1 -0
  78. package/dist/commands/channel/rm.js +216 -0
  79. package/dist/commands/channel/rm.js.map +1 -0
  80. package/dist/commands/channel/run.d.ts +30 -0
  81. package/dist/commands/channel/run.d.ts.map +1 -0
  82. package/dist/commands/channel/run.js +134 -0
  83. package/dist/commands/channel/run.js.map +1 -0
  84. package/dist/commands/channel/send.d.ts +11 -0
  85. package/dist/commands/channel/send.d.ts.map +1 -0
  86. package/dist/commands/channel/send.js +24 -0
  87. package/dist/commands/channel/send.js.map +1 -0
  88. package/dist/commands/channel/spawn.d.ts +43 -0
  89. package/dist/commands/channel/spawn.d.ts.map +1 -0
  90. package/dist/commands/channel/spawn.js +247 -0
  91. package/dist/commands/channel/spawn.js.map +1 -0
  92. package/dist/commands/channel/store/events.d.ts +22 -0
  93. package/dist/commands/channel/store/events.d.ts.map +1 -0
  94. package/dist/commands/channel/store/events.js +43 -0
  95. package/dist/commands/channel/store/events.js.map +1 -0
  96. package/dist/commands/channel/store/filter.d.ts +3 -0
  97. package/dist/commands/channel/store/filter.d.ts.map +1 -0
  98. package/dist/commands/channel/store/filter.js +2 -0
  99. package/dist/commands/channel/store/filter.js.map +1 -0
  100. package/dist/commands/channel/store/lock.d.ts +23 -0
  101. package/dist/commands/channel/store/lock.d.ts.map +1 -0
  102. package/dist/commands/channel/store/lock.js +99 -0
  103. package/dist/commands/channel/store/lock.js.map +1 -0
  104. package/dist/commands/channel/store/paths.d.ts +77 -0
  105. package/dist/commands/channel/store/paths.d.ts.map +1 -0
  106. package/dist/commands/channel/store/paths.js +272 -0
  107. package/dist/commands/channel/store/paths.js.map +1 -0
  108. package/dist/commands/channel/store/schema.d.ts +27 -0
  109. package/dist/commands/channel/store/schema.d.ts.map +1 -0
  110. package/dist/commands/channel/store/schema.js +34 -0
  111. package/dist/commands/channel/store/schema.js.map +1 -0
  112. package/dist/commands/channel/store/thread-state.d.ts +5 -0
  113. package/dist/commands/channel/store/thread-state.d.ts.map +1 -0
  114. package/dist/commands/channel/store/thread-state.js +16 -0
  115. package/dist/commands/channel/store/thread-state.js.map +1 -0
  116. package/dist/commands/channel/store/watch.d.ts +19 -0
  117. package/dist/commands/channel/store/watch.d.ts.map +1 -0
  118. package/dist/commands/channel/store/watch.js +153 -0
  119. package/dist/commands/channel/store/watch.js.map +1 -0
  120. package/dist/commands/channel/supervisor/idle.d.ts +45 -0
  121. package/dist/commands/channel/supervisor/idle.d.ts.map +1 -0
  122. package/dist/commands/channel/supervisor/idle.js +70 -0
  123. package/dist/commands/channel/supervisor/idle.js.map +1 -0
  124. package/dist/commands/channel/supervisor/inbox.d.ts +30 -0
  125. package/dist/commands/channel/supervisor/inbox.d.ts.map +1 -0
  126. package/dist/commands/channel/supervisor/inbox.js +160 -0
  127. package/dist/commands/channel/supervisor/inbox.js.map +1 -0
  128. package/dist/commands/channel/supervisor/shutdown.d.ts +68 -0
  129. package/dist/commands/channel/supervisor/shutdown.d.ts.map +1 -0
  130. package/dist/commands/channel/supervisor/shutdown.js +146 -0
  131. package/dist/commands/channel/supervisor/shutdown.js.map +1 -0
  132. package/dist/commands/channel/supervisor/stdout.d.ts +71 -0
  133. package/dist/commands/channel/supervisor/stdout.d.ts.map +1 -0
  134. package/dist/commands/channel/supervisor/stdout.js +229 -0
  135. package/dist/commands/channel/supervisor/stdout.js.map +1 -0
  136. package/dist/commands/channel/supervisor/turns.d.ts +31 -0
  137. package/dist/commands/channel/supervisor/turns.d.ts.map +1 -0
  138. package/dist/commands/channel/supervisor/turns.js +45 -0
  139. package/dist/commands/channel/supervisor/turns.js.map +1 -0
  140. package/dist/commands/channel/supervisor/warning.d.ts +48 -0
  141. package/dist/commands/channel/supervisor/warning.d.ts.map +1 -0
  142. package/dist/commands/channel/supervisor/warning.js +77 -0
  143. package/dist/commands/channel/supervisor/warning.js.map +1 -0
  144. package/dist/commands/channel/supervisor.d.ts +91 -0
  145. package/dist/commands/channel/supervisor.d.ts.map +1 -0
  146. package/dist/commands/channel/supervisor.js +463 -0
  147. package/dist/commands/channel/supervisor.js.map +1 -0
  148. package/dist/commands/channel/text-body.d.ts +13 -0
  149. package/dist/commands/channel/text-body.d.ts.map +1 -0
  150. package/dist/commands/channel/text-body.js +47 -0
  151. package/dist/commands/channel/text-body.js.map +1 -0
  152. package/dist/commands/channel/threads.d.ts +39 -0
  153. package/dist/commands/channel/threads.d.ts.map +1 -0
  154. package/dist/commands/channel/threads.js +106 -0
  155. package/dist/commands/channel/threads.js.map +1 -0
  156. package/dist/commands/channel/title.d.ts +12 -0
  157. package/dist/commands/channel/title.d.ts.map +1 -0
  158. package/dist/commands/channel/title.js +24 -0
  159. package/dist/commands/channel/title.js.map +1 -0
  160. package/dist/commands/channel/wait.d.ts +17 -0
  161. package/dist/commands/channel/wait.d.ts.map +1 -0
  162. package/dist/commands/channel/wait.js +81 -0
  163. package/dist/commands/channel/wait.js.map +1 -0
  164. package/dist/commands/init.d.ts +71 -0
  165. package/dist/commands/init.d.ts.map +1 -0
  166. package/dist/commands/init.js +1603 -0
  167. package/dist/commands/init.js.map +1 -0
  168. package/dist/commands/mem.d.ts +30 -0
  169. package/dist/commands/mem.d.ts.map +1 -0
  170. package/dist/commands/mem.js +423 -0
  171. package/dist/commands/mem.js.map +1 -0
  172. package/dist/commands/uninstall.d.ts +36 -0
  173. package/dist/commands/uninstall.d.ts.map +1 -0
  174. package/dist/commands/uninstall.js +205 -0
  175. package/dist/commands/uninstall.js.map +1 -0
  176. package/dist/commands/update.d.ts +104 -0
  177. package/dist/commands/update.d.ts.map +1 -0
  178. package/dist/commands/update.js +2163 -0
  179. package/dist/commands/update.js.map +1 -0
  180. package/dist/commands/upgrade.d.ts +28 -0
  181. package/dist/commands/upgrade.d.ts.map +1 -0
  182. package/dist/commands/upgrade.js +84 -0
  183. package/dist/commands/upgrade.js.map +1 -0
  184. package/dist/commands/workflow.d.ts +35 -0
  185. package/dist/commands/workflow.d.ts.map +1 -0
  186. package/dist/commands/workflow.js +232 -0
  187. package/dist/commands/workflow.js.map +1 -0
  188. package/dist/configurators/antigravity.d.ts +7 -0
  189. package/dist/configurators/antigravity.d.ts.map +1 -0
  190. package/dist/configurators/antigravity.js +11 -0
  191. package/dist/configurators/antigravity.js.map +1 -0
  192. package/dist/configurators/claude.d.ts +23 -0
  193. package/dist/configurators/claude.d.ts.map +1 -0
  194. package/dist/configurators/claude.js +123 -0
  195. package/dist/configurators/claude.js.map +1 -0
  196. package/dist/configurators/codebuddy.d.ts +10 -0
  197. package/dist/configurators/codebuddy.d.ts.map +1 -0
  198. package/dist/configurators/codebuddy.js +24 -0
  199. package/dist/configurators/codebuddy.js.map +1 -0
  200. package/dist/configurators/codex.d.ts +57 -0
  201. package/dist/configurators/codex.d.ts.map +1 -0
  202. package/dist/configurators/codex.js +170 -0
  203. package/dist/configurators/codex.js.map +1 -0
  204. package/dist/configurators/copilot.d.ts +14 -0
  205. package/dist/configurators/copilot.d.ts.map +1 -0
  206. package/dist/configurators/copilot.js +46 -0
  207. package/dist/configurators/copilot.js.map +1 -0
  208. package/dist/configurators/cursor.d.ts +10 -0
  209. package/dist/configurators/cursor.d.ts.map +1 -0
  210. package/dist/configurators/cursor.js +23 -0
  211. package/dist/configurators/cursor.js.map +1 -0
  212. package/dist/configurators/devin.d.ts +8 -0
  213. package/dist/configurators/devin.d.ts.map +1 -0
  214. package/dist/configurators/devin.js +12 -0
  215. package/dist/configurators/devin.js.map +1 -0
  216. package/dist/configurators/droid.d.ts +10 -0
  217. package/dist/configurators/droid.d.ts.map +1 -0
  218. package/dist/configurators/droid.js +24 -0
  219. package/dist/configurators/droid.js.map +1 -0
  220. package/dist/configurators/dsh.d.ts +29 -0
  221. package/dist/configurators/dsh.d.ts.map +1 -0
  222. package/dist/configurators/dsh.js +64 -0
  223. package/dist/configurators/dsh.js.map +1 -0
  224. package/dist/configurators/gemini.d.ts +18 -0
  225. package/dist/configurators/gemini.d.ts.map +1 -0
  226. package/dist/configurators/gemini.js +39 -0
  227. package/dist/configurators/gemini.js.map +1 -0
  228. package/dist/configurators/grok.d.ts +17 -0
  229. package/dist/configurators/grok.d.ts.map +1 -0
  230. package/dist/configurators/grok.js +38 -0
  231. package/dist/configurators/grok.js.map +1 -0
  232. package/dist/configurators/index.d.ts +68 -0
  233. package/dist/configurators/index.d.ts.map +1 -0
  234. package/dist/configurators/index.js +191 -0
  235. package/dist/configurators/index.js.map +1 -0
  236. package/dist/configurators/kilo.d.ts +7 -0
  237. package/dist/configurators/kilo.d.ts.map +1 -0
  238. package/dist/configurators/kilo.js +11 -0
  239. package/dist/configurators/kilo.js.map +1 -0
  240. package/dist/configurators/kimi.d.ts +26 -0
  241. package/dist/configurators/kimi.d.ts.map +1 -0
  242. package/dist/configurators/kimi.js +74 -0
  243. package/dist/configurators/kimi.js.map +1 -0
  244. package/dist/configurators/kiro.d.ts +11 -0
  245. package/dist/configurators/kiro.d.ts.map +1 -0
  246. package/dist/configurators/kiro.js +30 -0
  247. package/dist/configurators/kiro.js.map +1 -0
  248. package/dist/configurators/omp.d.ts +6 -0
  249. package/dist/configurators/omp.d.ts.map +1 -0
  250. package/dist/configurators/omp.js +28 -0
  251. package/dist/configurators/omp.js.map +1 -0
  252. package/dist/configurators/opencode.d.ts +5 -0
  253. package/dist/configurators/opencode.d.ts.map +1 -0
  254. package/dist/configurators/opencode.js +80 -0
  255. package/dist/configurators/opencode.js.map +1 -0
  256. package/dist/configurators/pi.d.ts +5 -0
  257. package/dist/configurators/pi.d.ts.map +1 -0
  258. package/dist/configurators/pi.js +39 -0
  259. package/dist/configurators/pi.js.map +1 -0
  260. package/dist/configurators/qoder.d.ts +12 -0
  261. package/dist/configurators/qoder.d.ts.map +1 -0
  262. package/dist/configurators/qoder.js +30 -0
  263. package/dist/configurators/qoder.js.map +1 -0
  264. package/dist/configurators/reasonix.d.ts +17 -0
  265. package/dist/configurators/reasonix.d.ts.map +1 -0
  266. package/dist/configurators/reasonix.js +37 -0
  267. package/dist/configurators/reasonix.js.map +1 -0
  268. package/dist/configurators/shared.d.ts +187 -0
  269. package/dist/configurators/shared.d.ts.map +1 -0
  270. package/dist/configurators/shared.js +589 -0
  271. package/dist/configurators/shared.js.map +1 -0
  272. package/dist/configurators/snow.d.ts +25 -0
  273. package/dist/configurators/snow.d.ts.map +1 -0
  274. package/dist/configurators/snow.js +69 -0
  275. package/dist/configurators/snow.js.map +1 -0
  276. package/dist/configurators/trae.d.ts +16 -0
  277. package/dist/configurators/trae.d.ts.map +1 -0
  278. package/dist/configurators/trae.js +34 -0
  279. package/dist/configurators/trae.js.map +1 -0
  280. package/dist/configurators/workflow.d.ts +51 -0
  281. package/dist/configurators/workflow.d.ts.map +1 -0
  282. package/dist/configurators/workflow.js +210 -0
  283. package/dist/configurators/workflow.js.map +1 -0
  284. package/dist/configurators/zcode.d.ts +25 -0
  285. package/dist/configurators/zcode.d.ts.map +1 -0
  286. package/dist/configurators/zcode.js +67 -0
  287. package/dist/configurators/zcode.js.map +1 -0
  288. package/dist/constants/paths.d.ts +74 -0
  289. package/dist/constants/paths.d.ts.map +1 -0
  290. package/dist/constants/paths.js +83 -0
  291. package/dist/constants/paths.js.map +1 -0
  292. package/dist/constants/version.d.ts +9 -0
  293. package/dist/constants/version.d.ts.map +1 -0
  294. package/dist/constants/version.js +15 -0
  295. package/dist/constants/version.js.map +1 -0
  296. package/dist/index.d.ts +9 -0
  297. package/dist/index.d.ts.map +1 -0
  298. package/dist/index.js +9 -0
  299. package/dist/index.js.map +1 -0
  300. package/dist/migrations/index.d.ts +62 -0
  301. package/dist/migrations/index.d.ts.map +1 -0
  302. package/dist/migrations/index.js +187 -0
  303. package/dist/migrations/index.js.map +1 -0
  304. package/dist/migrations/manifests/0.1.9.json +30 -0
  305. package/dist/migrations/manifests/0.2.0.json +49 -0
  306. package/dist/migrations/manifests/0.2.12.json +9 -0
  307. package/dist/migrations/manifests/0.2.13.json +9 -0
  308. package/dist/migrations/manifests/0.2.14.json +175 -0
  309. package/dist/migrations/manifests/0.2.15.json +33 -0
  310. package/dist/migrations/manifests/0.3.0-beta.0.json +297 -0
  311. package/dist/migrations/manifests/0.3.0-beta.1.json +9 -0
  312. package/dist/migrations/manifests/0.3.0-beta.10.json +9 -0
  313. package/dist/migrations/manifests/0.3.0-beta.11.json +9 -0
  314. package/dist/migrations/manifests/0.3.0-beta.12.json +9 -0
  315. package/dist/migrations/manifests/0.3.0-beta.13.json +9 -0
  316. package/dist/migrations/manifests/0.3.0-beta.14.json +9 -0
  317. package/dist/migrations/manifests/0.3.0-beta.15.json +9 -0
  318. package/dist/migrations/manifests/0.3.0-beta.16.json +9 -0
  319. package/dist/migrations/manifests/0.3.0-beta.2.json +9 -0
  320. package/dist/migrations/manifests/0.3.0-beta.3.json +9 -0
  321. package/dist/migrations/manifests/0.3.0-beta.4.json +9 -0
  322. package/dist/migrations/manifests/0.3.0-beta.5.json +9 -0
  323. package/dist/migrations/manifests/0.3.0-beta.6.json +9 -0
  324. package/dist/migrations/manifests/0.3.0-beta.7.json +11 -0
  325. package/dist/migrations/manifests/0.3.0-beta.8.json +9 -0
  326. package/dist/migrations/manifests/0.3.0-beta.9.json +9 -0
  327. package/dist/migrations/manifests/0.3.0-rc.0.json +9 -0
  328. package/dist/migrations/manifests/0.3.0-rc.1.json +9 -0
  329. package/dist/migrations/manifests/0.3.0-rc.2.json +9 -0
  330. package/dist/migrations/manifests/0.3.0-rc.3.json +9 -0
  331. package/dist/migrations/manifests/0.3.0-rc.4.json +9 -0
  332. package/dist/migrations/manifests/0.3.0-rc.5.json +9 -0
  333. package/dist/migrations/manifests/0.3.0-rc.6.json +9 -0
  334. package/dist/migrations/manifests/0.3.0.json +11 -0
  335. package/dist/migrations/manifests/0.3.1.json +9 -0
  336. package/dist/migrations/manifests/0.3.10.json +9 -0
  337. package/dist/migrations/manifests/0.3.2.json +9 -0
  338. package/dist/migrations/manifests/0.3.3.json +9 -0
  339. package/dist/migrations/manifests/0.3.4.json +21 -0
  340. package/dist/migrations/manifests/0.3.5.json +9 -0
  341. package/dist/migrations/manifests/0.3.6.json +9 -0
  342. package/dist/migrations/manifests/0.3.7.json +9 -0
  343. package/dist/migrations/manifests/0.3.8.json +9 -0
  344. package/dist/migrations/manifests/0.3.9.json +9 -0
  345. package/dist/migrations/manifests/0.4.0-beta.1.json +228 -0
  346. package/dist/migrations/manifests/0.4.0-beta.10.json +9 -0
  347. package/dist/migrations/manifests/0.4.0-beta.2.json +9 -0
  348. package/dist/migrations/manifests/0.4.0-beta.3.json +9 -0
  349. package/dist/migrations/manifests/0.4.0-beta.4.json +9 -0
  350. package/dist/migrations/manifests/0.4.0-beta.5.json +9 -0
  351. package/dist/migrations/manifests/0.4.0-beta.6.json +9 -0
  352. package/dist/migrations/manifests/0.4.0-beta.7.json +9 -0
  353. package/dist/migrations/manifests/0.4.0-beta.8.json +34 -0
  354. package/dist/migrations/manifests/0.4.0-beta.9.json +9 -0
  355. package/dist/migrations/manifests/0.4.0-rc.0.json +9 -0
  356. package/dist/migrations/manifests/0.4.0-rc.1.json +9 -0
  357. package/dist/migrations/manifests/0.4.0.json +9 -0
  358. package/dist/migrations/manifests/0.5.0-beta.0.json +1646 -0
  359. package/dist/migrations/manifests/0.5.0-beta.1.json +9 -0
  360. package/dist/migrations/manifests/0.5.0-beta.10.json +9 -0
  361. package/dist/migrations/manifests/0.5.0-beta.11.json +9 -0
  362. package/dist/migrations/manifests/0.5.0-beta.12.json +9 -0
  363. package/dist/migrations/manifests/0.5.0-beta.13.json +9 -0
  364. package/dist/migrations/manifests/0.5.0-beta.14.json +9 -0
  365. package/dist/migrations/manifests/0.5.0-beta.15.json +116 -0
  366. package/dist/migrations/manifests/0.5.0-beta.16.json +9 -0
  367. package/dist/migrations/manifests/0.5.0-beta.17.json +9 -0
  368. package/dist/migrations/manifests/0.5.0-beta.18.json +9 -0
  369. package/dist/migrations/manifests/0.5.0-beta.19.json +9 -0
  370. package/dist/migrations/manifests/0.5.0-beta.2.json +9 -0
  371. package/dist/migrations/manifests/0.5.0-beta.3.json +9 -0
  372. package/dist/migrations/manifests/0.5.0-beta.4.json +9 -0
  373. package/dist/migrations/manifests/0.5.0-beta.5.json +222 -0
  374. package/dist/migrations/manifests/0.5.0-beta.6.json +9 -0
  375. package/dist/migrations/manifests/0.5.0-beta.7.json +9 -0
  376. package/dist/migrations/manifests/0.5.0-beta.8.json +9 -0
  377. package/dist/migrations/manifests/0.5.0-beta.9.json +48 -0
  378. package/dist/migrations/manifests/0.5.0-rc.0.json +9 -0
  379. package/dist/migrations/manifests/0.5.0-rc.1.json +9 -0
  380. package/dist/migrations/manifests/0.5.0-rc.2.json +9 -0
  381. package/dist/migrations/manifests/0.5.0-rc.3.json +9 -0
  382. package/dist/migrations/manifests/0.5.0-rc.4.json +9 -0
  383. package/dist/migrations/manifests/0.5.0-rc.5.json +9 -0
  384. package/dist/migrations/manifests/0.5.0-rc.6.json +9 -0
  385. package/dist/migrations/manifests/0.5.0-rc.7.json +9 -0
  386. package/dist/migrations/manifests/0.5.0.json +9 -0
  387. package/dist/migrations/manifests/0.5.1.json +9 -0
  388. package/dist/migrations/manifests/0.5.10.json +9 -0
  389. package/dist/migrations/manifests/0.5.11.json +16 -0
  390. package/dist/migrations/manifests/0.5.12.json +9 -0
  391. package/dist/migrations/manifests/0.5.13.json +9 -0
  392. package/dist/migrations/manifests/0.5.14.json +9 -0
  393. package/dist/migrations/manifests/0.5.15.json +9 -0
  394. package/dist/migrations/manifests/0.5.16.json +9 -0
  395. package/dist/migrations/manifests/0.5.17.json +9 -0
  396. package/dist/migrations/manifests/0.5.18.json +9 -0
  397. package/dist/migrations/manifests/0.5.19.json +9 -0
  398. package/dist/migrations/manifests/0.5.2.json +9 -0
  399. package/dist/migrations/manifests/0.5.3.json +9 -0
  400. package/dist/migrations/manifests/0.5.4.json +9 -0
  401. package/dist/migrations/manifests/0.5.5.json +9 -0
  402. package/dist/migrations/manifests/0.5.6.json +9 -0
  403. package/dist/migrations/manifests/0.5.7.json +16 -0
  404. package/dist/migrations/manifests/0.5.8.json +9 -0
  405. package/dist/migrations/manifests/0.5.9.json +9 -0
  406. package/dist/migrations/manifests/0.6.0-beta.0.json +16 -0
  407. package/dist/migrations/manifests/0.6.0-beta.1.json +9 -0
  408. package/dist/migrations/manifests/0.6.0-beta.10.json +9 -0
  409. package/dist/migrations/manifests/0.6.0-beta.11.json +9 -0
  410. package/dist/migrations/manifests/0.6.0-beta.12.json +9 -0
  411. package/dist/migrations/manifests/0.6.0-beta.13.json +9 -0
  412. package/dist/migrations/manifests/0.6.0-beta.14.json +9 -0
  413. package/dist/migrations/manifests/0.6.0-beta.15.json +9 -0
  414. package/dist/migrations/manifests/0.6.0-beta.16.json +9 -0
  415. package/dist/migrations/manifests/0.6.0-beta.17.json +9 -0
  416. package/dist/migrations/manifests/0.6.0-beta.18.json +16 -0
  417. package/dist/migrations/manifests/0.6.0-beta.19.json +9 -0
  418. package/dist/migrations/manifests/0.6.0-beta.2.json +9 -0
  419. package/dist/migrations/manifests/0.6.0-beta.20.json +9 -0
  420. package/dist/migrations/manifests/0.6.0-beta.21.json +9 -0
  421. package/dist/migrations/manifests/0.6.0-beta.22.json +9 -0
  422. package/dist/migrations/manifests/0.6.0-beta.23.json +88 -0
  423. package/dist/migrations/manifests/0.6.0-beta.3.json +9 -0
  424. package/dist/migrations/manifests/0.6.0-beta.4.json +9 -0
  425. package/dist/migrations/manifests/0.6.0-beta.5.json +9 -0
  426. package/dist/migrations/manifests/0.6.0-beta.6.json +16 -0
  427. package/dist/migrations/manifests/0.6.0-beta.7.json +9 -0
  428. package/dist/migrations/manifests/0.6.0-beta.8.json +9 -0
  429. package/dist/migrations/manifests/0.6.0-beta.9.json +9 -0
  430. package/dist/migrations/manifests/0.6.0-rc.0.json +9 -0
  431. package/dist/migrations/manifests/0.6.0.json +1 -0
  432. package/dist/migrations/manifests/0.6.1.json +9 -0
  433. package/dist/migrations/manifests/0.6.10.json +9 -0
  434. package/dist/migrations/manifests/0.6.11.json +9 -0
  435. package/dist/migrations/manifests/0.6.12.json +9 -0
  436. package/dist/migrations/manifests/0.6.13.json +9 -0
  437. package/dist/migrations/manifests/0.6.14.json +9 -0
  438. package/dist/migrations/manifests/0.6.15.json +9 -0
  439. package/dist/migrations/manifests/0.6.16.json +9 -0
  440. package/dist/migrations/manifests/0.6.17.json +9 -0
  441. package/dist/migrations/manifests/0.6.2.json +9 -0
  442. package/dist/migrations/manifests/0.6.3.json +24 -0
  443. package/dist/migrations/manifests/0.6.4.json +9 -0
  444. package/dist/migrations/manifests/0.6.5.json +9 -0
  445. package/dist/migrations/manifests/0.6.6.json +17 -0
  446. package/dist/migrations/manifests/0.6.7.json +9 -0
  447. package/dist/migrations/manifests/0.6.8.json +17 -0
  448. package/dist/migrations/manifests/0.6.9.json +9 -0
  449. package/dist/migrations/manifests/0.7.0-beta.0.json +9 -0
  450. package/dist/migrations/manifests/0.7.0-beta.1.json +9 -0
  451. package/dist/migrations/manifests/0.7.0-beta.2.json +9 -0
  452. package/dist/migrations/manifests/0.7.0-beta.3.json +9 -0
  453. package/dist/templates/claude/agents/trellis-check.md +115 -0
  454. package/dist/templates/claude/agents/trellis-implement.md +110 -0
  455. package/dist/templates/claude/agents/trellis-research.md +137 -0
  456. package/dist/templates/claude/hooks/statusline.py +332 -0
  457. package/dist/templates/claude/index.d.ts +31 -0
  458. package/dist/templates/claude/index.d.ts.map +1 -0
  459. package/dist/templates/claude/index.js +57 -0
  460. package/dist/templates/claude/index.js.map +1 -0
  461. package/dist/templates/claude/settings.json +73 -0
  462. package/dist/templates/codebuddy/agents/trellis-check.md +115 -0
  463. package/dist/templates/codebuddy/agents/trellis-implement.md +110 -0
  464. package/dist/templates/codebuddy/agents/trellis-research.md +137 -0
  465. package/dist/templates/codebuddy/index.d.ts +15 -0
  466. package/dist/templates/codebuddy/index.d.ts.map +1 -0
  467. package/dist/templates/codebuddy/index.js +15 -0
  468. package/dist/templates/codebuddy/index.js.map +1 -0
  469. package/dist/templates/codebuddy/settings.json +69 -0
  470. package/dist/templates/codex/agents/trellis-check.toml +56 -0
  471. package/dist/templates/codex/agents/trellis-implement.toml +37 -0
  472. package/dist/templates/codex/agents/trellis-research.toml +78 -0
  473. package/dist/templates/codex/config.toml +39 -0
  474. package/dist/templates/codex/hooks/session-start.py +552 -0
  475. package/dist/templates/codex/hooks.json +27 -0
  476. package/dist/templates/codex/index.d.ts +35 -0
  477. package/dist/templates/codex/index.d.ts.map +1 -0
  478. package/dist/templates/codex/index.js +67 -0
  479. package/dist/templates/codex/index.js.map +1 -0
  480. package/dist/templates/common/bundled-skills/trellis-channel/SKILL.md +67 -0
  481. package/dist/templates/common/bundled-skills/trellis-channel/references/command-reference.md +480 -0
  482. package/dist/templates/common/bundled-skills/trellis-channel/references/forum.md +233 -0
  483. package/dist/templates/common/bundled-skills/trellis-channel/references/progress-debugging.md +226 -0
  484. package/dist/templates/common/bundled-skills/trellis-channel/references/workers.md +276 -0
  485. package/dist/templates/common/bundled-skills/trellis-channel/references/workflows.md +128 -0
  486. package/dist/templates/common/bundled-skills/trellis-meta/SKILL.md +85 -0
  487. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/add-project-local-conventions.md +83 -0
  488. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-agents.md +56 -0
  489. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-context-loading.md +84 -0
  490. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-hooks.md +57 -0
  491. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-skills-or-commands.md +123 -0
  492. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-spec-structure.md +83 -0
  493. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-task-lifecycle.md +90 -0
  494. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-workflow.md +65 -0
  495. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/overview.md +55 -0
  496. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/bundled-skills.md +159 -0
  497. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/context-injection.md +68 -0
  498. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/generated-files.md +80 -0
  499. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/multi-agent-channel.md +69 -0
  500. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/overview.md +51 -0
  501. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/spec-system.md +102 -0
  502. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/task-system.md +130 -0
  503. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/workflow.md +75 -0
  504. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/workspace-memory.md +71 -0
  505. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/agents.md +83 -0
  506. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/hooks-and-settings.md +72 -0
  507. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/overview.md +59 -0
  508. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/platform-map.md +112 -0
  509. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/skills-and-commands.md +86 -0
  510. package/dist/templates/common/bundled-skills/trellis-session-insight/SKILL.md +81 -0
  511. package/dist/templates/common/bundled-skills/trellis-session-insight/references/cli-quick-reference.md +65 -0
  512. package/dist/templates/common/bundled-skills/trellis-session-insight/references/triggering-patterns.md +93 -0
  513. package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/SKILL.md +41 -0
  514. package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/references/mcp-setup.md +90 -0
  515. package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/references/repository-analysis.md +59 -0
  516. package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/references/spec-task-planning.md +61 -0
  517. package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/references/spec-writing.md +70 -0
  518. package/dist/templates/common/commands/continue.md +56 -0
  519. package/dist/templates/common/commands/finish-work.md +66 -0
  520. package/dist/templates/common/commands/start.md +59 -0
  521. package/dist/templates/common/index.d.ts +48 -0
  522. package/dist/templates/common/index.d.ts.map +1 -0
  523. package/dist/templates/common/index.js +104 -0
  524. package/dist/templates/common/index.js.map +1 -0
  525. package/dist/templates/common/skills/before-dev.md +46 -0
  526. package/dist/templates/common/skills/brainstorm.md +195 -0
  527. package/dist/templates/common/skills/break-loop.md +184 -0
  528. package/dist/templates/common/skills/check.md +106 -0
  529. package/dist/templates/common/skills/update-spec.md +351 -0
  530. package/dist/templates/copilot/copilot-instructions.md +11 -0
  531. package/dist/templates/copilot/hooks/session-start.py +548 -0
  532. package/dist/templates/copilot/hooks.json +19 -0
  533. package/dist/templates/copilot/index.d.ts +28 -0
  534. package/dist/templates/copilot/index.d.ts.map +1 -0
  535. package/dist/templates/copilot/index.js +61 -0
  536. package/dist/templates/copilot/index.js.map +1 -0
  537. package/dist/templates/copilot/prompts/before-dev.prompt.md +39 -0
  538. package/dist/templates/copilot/prompts/brainstorm.prompt.md +156 -0
  539. package/dist/templates/copilot/prompts/break-loop.prompt.md +129 -0
  540. package/dist/templates/copilot/prompts/check-cross-layer.prompt.md +170 -0
  541. package/dist/templates/copilot/prompts/check.prompt.md +110 -0
  542. package/dist/templates/copilot/prompts/create-command.prompt.md +116 -0
  543. package/dist/templates/copilot/prompts/finish-work.prompt.md +99 -0
  544. package/dist/templates/copilot/prompts/integrate-skill.prompt.md +223 -0
  545. package/dist/templates/copilot/prompts/onboard.prompt.md +362 -0
  546. package/dist/templates/copilot/prompts/parallel.prompt.md +204 -0
  547. package/dist/templates/copilot/prompts/record-session.prompt.md +66 -0
  548. package/dist/templates/copilot/prompts/start.prompt.md +63 -0
  549. package/dist/templates/copilot/prompts/update-spec.prompt.md +358 -0
  550. package/dist/templates/cursor/agents/trellis-check.md +114 -0
  551. package/dist/templates/cursor/agents/trellis-implement.md +109 -0
  552. package/dist/templates/cursor/agents/trellis-research.md +136 -0
  553. package/dist/templates/cursor/hooks.json +24 -0
  554. package/dist/templates/cursor/index.d.ts +13 -0
  555. package/dist/templates/cursor/index.d.ts.map +1 -0
  556. package/dist/templates/cursor/index.js +13 -0
  557. package/dist/templates/cursor/index.js.map +1 -0
  558. package/dist/templates/droid/droids/trellis-check.md +107 -0
  559. package/dist/templates/droid/droids/trellis-implement.md +102 -0
  560. package/dist/templates/droid/droids/trellis-research.md +137 -0
  561. package/dist/templates/droid/index.d.ts +15 -0
  562. package/dist/templates/droid/index.d.ts.map +1 -0
  563. package/dist/templates/droid/index.js +15 -0
  564. package/dist/templates/droid/index.js.map +1 -0
  565. package/dist/templates/droid/settings.json +69 -0
  566. package/dist/templates/dsh/DSH.md +56 -0
  567. package/dist/templates/dsh/index.d.ts +21 -0
  568. package/dist/templates/dsh/index.d.ts.map +1 -0
  569. package/dist/templates/dsh/index.js +25 -0
  570. package/dist/templates/dsh/index.js.map +1 -0
  571. package/dist/templates/extract.d.ts +40 -0
  572. package/dist/templates/extract.d.ts.map +1 -0
  573. package/dist/templates/extract.js +106 -0
  574. package/dist/templates/extract.js.map +1 -0
  575. package/dist/templates/gemini/agents/trellis-check.md +107 -0
  576. package/dist/templates/gemini/agents/trellis-implement.md +102 -0
  577. package/dist/templates/gemini/agents/trellis-research.md +136 -0
  578. package/dist/templates/gemini/index.d.ts +13 -0
  579. package/dist/templates/gemini/index.d.ts.map +1 -0
  580. package/dist/templates/gemini/index.js +13 -0
  581. package/dist/templates/gemini/index.js.map +1 -0
  582. package/dist/templates/gemini/settings.json +40 -0
  583. package/dist/templates/grok/agents/trellis-check.md +105 -0
  584. package/dist/templates/grok/agents/trellis-implement.md +116 -0
  585. package/dist/templates/grok/agents/trellis-research.md +146 -0
  586. package/dist/templates/grok/index.d.ts +16 -0
  587. package/dist/templates/grok/index.d.ts.map +1 -0
  588. package/dist/templates/grok/index.js +19 -0
  589. package/dist/templates/grok/index.js.map +1 -0
  590. package/dist/templates/kimi/agents/trellis-check.md +103 -0
  591. package/dist/templates/kimi/agents/trellis-implement.md +115 -0
  592. package/dist/templates/kimi/agents/trellis-research.md +144 -0
  593. package/dist/templates/kimi/index.d.ts +20 -0
  594. package/dist/templates/kimi/index.d.ts.map +1 -0
  595. package/dist/templates/kimi/index.js +23 -0
  596. package/dist/templates/kimi/index.js.map +1 -0
  597. package/dist/templates/kiro/agents/trellis-check.json +26 -0
  598. package/dist/templates/kiro/agents/trellis-implement.json +26 -0
  599. package/dist/templates/kiro/agents/trellis-research.json +30 -0
  600. package/dist/templates/kiro/agents/trellis.json +34 -0
  601. package/dist/templates/kiro/hooks/trellis-workflow-state.kiro.hook +14 -0
  602. package/dist/templates/kiro/index.d.ts +32 -0
  603. package/dist/templates/kiro/index.d.ts.map +1 -0
  604. package/dist/templates/kiro/index.js +28 -0
  605. package/dist/templates/kiro/index.js.map +1 -0
  606. package/dist/templates/markdown/agents.md +21 -0
  607. package/dist/templates/markdown/gitignore.txt +15 -0
  608. package/dist/templates/markdown/index.d.ts +27 -0
  609. package/dist/templates/markdown/index.d.ts.map +1 -0
  610. package/dist/templates/markdown/index.js +52 -0
  611. package/dist/templates/markdown/index.js.map +1 -0
  612. package/dist/templates/markdown/spec/backend/database-guidelines.md.txt +51 -0
  613. package/dist/templates/markdown/spec/backend/directory-structure.md.txt +54 -0
  614. package/dist/templates/markdown/spec/backend/error-handling.md.txt +51 -0
  615. package/dist/templates/markdown/spec/backend/index.md.txt +38 -0
  616. package/dist/templates/markdown/spec/backend/logging-guidelines.md.txt +51 -0
  617. package/dist/templates/markdown/spec/backend/quality-guidelines.md.txt +51 -0
  618. package/dist/templates/markdown/spec/frontend/component-guidelines.md.txt +59 -0
  619. package/dist/templates/markdown/spec/frontend/directory-structure.md.txt +54 -0
  620. package/dist/templates/markdown/spec/frontend/hook-guidelines.md.txt +51 -0
  621. package/dist/templates/markdown/spec/frontend/index.md.txt +39 -0
  622. package/dist/templates/markdown/spec/frontend/quality-guidelines.md.txt +51 -0
  623. package/dist/templates/markdown/spec/frontend/state-management.md.txt +51 -0
  624. package/dist/templates/markdown/spec/frontend/type-safety.md.txt +51 -0
  625. package/dist/templates/markdown/spec/guides/code-reuse-thinking-guide.md.txt +223 -0
  626. package/dist/templates/markdown/spec/guides/cross-layer-thinking-guide.md.txt +327 -0
  627. package/dist/templates/markdown/spec/guides/cross-platform-thinking-guide.md.txt +633 -0
  628. package/dist/templates/markdown/spec/guides/index.md.txt +97 -0
  629. package/dist/templates/markdown/workspace-index.md +125 -0
  630. package/dist/templates/markdown/worktree.yaml.txt +58 -0
  631. package/dist/templates/omp/agents/trellis-check.md +41 -0
  632. package/dist/templates/omp/agents/trellis-implement.md +45 -0
  633. package/dist/templates/omp/agents/trellis-research.md +30 -0
  634. package/dist/templates/omp/extensions/trellis/index.ts.txt +1105 -0
  635. package/dist/templates/omp/index.d.ts +4 -0
  636. package/dist/templates/omp/index.d.ts.map +1 -0
  637. package/dist/templates/omp/index.js +9 -0
  638. package/dist/templates/omp/index.js.map +1 -0
  639. package/dist/templates/opencode/agents/trellis-check.md +122 -0
  640. package/dist/templates/opencode/agents/trellis-implement.md +118 -0
  641. package/dist/templates/opencode/agents/trellis-research.md +145 -0
  642. package/dist/templates/opencode/lib/context-visibility.js +148 -0
  643. package/dist/templates/opencode/lib/session-utils.js +527 -0
  644. package/dist/templates/opencode/lib/trellis-context.js +627 -0
  645. package/dist/templates/opencode/package.json +5 -0
  646. package/dist/templates/opencode/plugins/inject-subagent-context.js +569 -0
  647. package/dist/templates/opencode/plugins/inject-workflow-state.js +240 -0
  648. package/dist/templates/opencode/plugins/session-start.js +65 -0
  649. package/dist/templates/pi/agents/trellis-check.md +37 -0
  650. package/dist/templates/pi/agents/trellis-implement.md +42 -0
  651. package/dist/templates/pi/agents/trellis-research.md +25 -0
  652. package/dist/templates/pi/extensions/trellis/index.ts.txt +2027 -0
  653. package/dist/templates/pi/index.d.ts +5 -0
  654. package/dist/templates/pi/index.d.ts.map +1 -0
  655. package/dist/templates/pi/index.js +12 -0
  656. package/dist/templates/pi/index.js.map +1 -0
  657. package/dist/templates/pi/settings.json +9 -0
  658. package/dist/templates/qoder/agents/trellis-check.md +108 -0
  659. package/dist/templates/qoder/agents/trellis-implement.md +103 -0
  660. package/dist/templates/qoder/agents/trellis-research.md +137 -0
  661. package/dist/templates/qoder/index.d.ts +15 -0
  662. package/dist/templates/qoder/index.d.ts.map +1 -0
  663. package/dist/templates/qoder/index.js +15 -0
  664. package/dist/templates/qoder/index.js.map +1 -0
  665. package/dist/templates/qoder/settings.json +59 -0
  666. package/dist/templates/reasonix/agents/trellis-check.md +36 -0
  667. package/dist/templates/reasonix/agents/trellis-implement.md +41 -0
  668. package/dist/templates/reasonix/index.d.ts +13 -0
  669. package/dist/templates/reasonix/index.d.ts.map +1 -0
  670. package/dist/templates/reasonix/index.js +16 -0
  671. package/dist/templates/reasonix/index.js.map +1 -0
  672. package/dist/templates/shared-hooks/index.d.ts +77 -0
  673. package/dist/templates/shared-hooks/index.d.ts.map +1 -0
  674. package/dist/templates/shared-hooks/index.js +140 -0
  675. package/dist/templates/shared-hooks/index.js.map +1 -0
  676. package/dist/templates/shared-hooks/inject-shell-session-context.py +292 -0
  677. package/dist/templates/shared-hooks/inject-subagent-context.py +1212 -0
  678. package/dist/templates/shared-hooks/inject-workflow-state.py +488 -0
  679. package/dist/templates/shared-hooks/session-start.py +949 -0
  680. package/dist/templates/snow/SNOW.md +86 -0
  681. package/dist/templates/snow/agents/trellis-check.md +135 -0
  682. package/dist/templates/snow/agents/trellis-implement.md +153 -0
  683. package/dist/templates/snow/agents/trellis-research.md +114 -0
  684. package/dist/templates/snow/hooks/beforeSubAgentStart.json +15 -0
  685. package/dist/templates/snow/hooks/onSessionStart.json +15 -0
  686. package/dist/templates/snow/hooks/onUserMessage.json +15 -0
  687. package/dist/templates/snow/hooks/write-trellis-context.py +644 -0
  688. package/dist/templates/snow/index.d.ts +26 -0
  689. package/dist/templates/snow/index.d.ts.map +1 -0
  690. package/dist/templates/snow/index.js +36 -0
  691. package/dist/templates/snow/index.js.map +1 -0
  692. package/dist/templates/template-utils.d.ts +26 -0
  693. package/dist/templates/template-utils.d.ts.map +1 -0
  694. package/dist/templates/template-utils.js +64 -0
  695. package/dist/templates/template-utils.js.map +1 -0
  696. package/dist/templates/trae/agents/trellis-check.md +108 -0
  697. package/dist/templates/trae/agents/trellis-implement.md +103 -0
  698. package/dist/templates/trae/agents/trellis-research.md +137 -0
  699. package/dist/templates/trae/hooks.json +39 -0
  700. package/dist/templates/trae/index.d.ts +15 -0
  701. package/dist/templates/trae/index.d.ts.map +1 -0
  702. package/dist/templates/trae/index.js +15 -0
  703. package/dist/templates/trae/index.js.map +1 -0
  704. package/dist/templates/trellis/agents/check.md +70 -0
  705. package/dist/templates/trellis/agents/implement.md +71 -0
  706. package/dist/templates/trellis/config.yaml +158 -0
  707. package/dist/templates/trellis/gitattributes.txt +9 -0
  708. package/dist/templates/trellis/gitignore.txt +32 -0
  709. package/dist/templates/trellis/index.d.ts +67 -0
  710. package/dist/templates/trellis/index.d.ts.map +1 -0
  711. package/dist/templates/trellis/index.js +121 -0
  712. package/dist/templates/trellis/index.js.map +1 -0
  713. package/dist/templates/trellis/scripts/__init__.py +5 -0
  714. package/dist/templates/trellis/scripts/add_session.py +1545 -0
  715. package/dist/templates/trellis/scripts/common/__init__.py +94 -0
  716. package/dist/templates/trellis/scripts/common/active_task.py +857 -0
  717. package/dist/templates/trellis/scripts/common/cli_adapter.py +950 -0
  718. package/dist/templates/trellis/scripts/common/config.py +482 -0
  719. package/dist/templates/trellis/scripts/common/developer.py +192 -0
  720. package/dist/templates/trellis/scripts/common/git.py +203 -0
  721. package/dist/templates/trellis/scripts/common/git_context.py +106 -0
  722. package/dist/templates/trellis/scripts/common/io.py +160 -0
  723. package/dist/templates/trellis/scripts/common/log.py +45 -0
  724. package/dist/templates/trellis/scripts/common/packages_context.py +238 -0
  725. package/dist/templates/trellis/scripts/common/paths.py +543 -0
  726. package/dist/templates/trellis/scripts/common/safe_commit.py +322 -0
  727. package/dist/templates/trellis/scripts/common/session_context.py +892 -0
  728. package/dist/templates/trellis/scripts/common/task_context.py +470 -0
  729. package/dist/templates/trellis/scripts/common/task_queue.py +188 -0
  730. package/dist/templates/trellis/scripts/common/task_store.py +1874 -0
  731. package/dist/templates/trellis/scripts/common/task_utils.py +498 -0
  732. package/dist/templates/trellis/scripts/common/tasks.py +122 -0
  733. package/dist/templates/trellis/scripts/common/trellis_config.py +239 -0
  734. package/dist/templates/trellis/scripts/common/types.py +110 -0
  735. package/dist/templates/trellis/scripts/common/workflow_phase.py +242 -0
  736. package/dist/templates/trellis/scripts/get_context.py +16 -0
  737. package/dist/templates/trellis/scripts/get_developer.py +26 -0
  738. package/dist/templates/trellis/scripts/hooks/linear_sync.py +243 -0
  739. package/dist/templates/trellis/scripts/init_developer.py +51 -0
  740. package/dist/templates/trellis/scripts/task.py +801 -0
  741. package/dist/templates/trellis/tasks/.gitkeep +0 -0
  742. package/dist/templates/trellis/workflow.md +721 -0
  743. package/dist/templates/zcode/agents/trellis-check.md +109 -0
  744. package/dist/templates/zcode/agents/trellis-implement.md +111 -0
  745. package/dist/templates/zcode/agents/trellis-research.md +133 -0
  746. package/dist/templates/zcode/config.json +52 -0
  747. package/dist/templates/zcode/index.d.ts +25 -0
  748. package/dist/templates/zcode/index.d.ts.map +1 -0
  749. package/dist/templates/zcode/index.js +29 -0
  750. package/dist/templates/zcode/index.js.map +1 -0
  751. package/dist/types/ai-tools.d.ts +105 -0
  752. package/dist/types/ai-tools.d.ts.map +1 -0
  753. package/dist/types/ai-tools.js +502 -0
  754. package/dist/types/ai-tools.js.map +1 -0
  755. package/dist/types/migration.d.ts +125 -0
  756. package/dist/types/migration.d.ts.map +1 -0
  757. package/dist/types/migration.js +8 -0
  758. package/dist/types/migration.js.map +1 -0
  759. package/dist/utils/ablation-store.d.ts +123 -0
  760. package/dist/utils/ablation-store.d.ts.map +1 -0
  761. package/dist/utils/ablation-store.js +749 -0
  762. package/dist/utils/ablation-store.js.map +1 -0
  763. package/dist/utils/agent-refs.d.ts +31 -0
  764. package/dist/utils/agent-refs.d.ts.map +1 -0
  765. package/dist/utils/agent-refs.js +63 -0
  766. package/dist/utils/agent-refs.js.map +1 -0
  767. package/dist/utils/atomic-write.d.ts +12 -0
  768. package/dist/utils/atomic-write.d.ts.map +1 -0
  769. package/dist/utils/atomic-write.js +30 -0
  770. package/dist/utils/atomic-write.js.map +1 -0
  771. package/dist/utils/compare-versions.d.ts +12 -0
  772. package/dist/utils/compare-versions.d.ts.map +1 -0
  773. package/dist/utils/compare-versions.js +86 -0
  774. package/dist/utils/compare-versions.js.map +1 -0
  775. package/dist/utils/cwd-guard.d.ts +38 -0
  776. package/dist/utils/cwd-guard.d.ts.map +1 -0
  777. package/dist/utils/cwd-guard.js +62 -0
  778. package/dist/utils/cwd-guard.js.map +1 -0
  779. package/dist/utils/file-writer.d.ts +36 -0
  780. package/dist/utils/file-writer.d.ts.map +1 -0
  781. package/dist/utils/file-writer.js +204 -0
  782. package/dist/utils/file-writer.js.map +1 -0
  783. package/dist/utils/managed-paths.d.ts +5 -0
  784. package/dist/utils/managed-paths.d.ts.map +1 -0
  785. package/dist/utils/managed-paths.js +51 -0
  786. package/dist/utils/managed-paths.js.map +1 -0
  787. package/dist/utils/managed-removal.d.ts +74 -0
  788. package/dist/utils/managed-removal.d.ts.map +1 -0
  789. package/dist/utils/managed-removal.js +270 -0
  790. package/dist/utils/managed-removal.js.map +1 -0
  791. package/dist/utils/manifest-prune.d.ts +61 -0
  792. package/dist/utils/manifest-prune.d.ts.map +1 -0
  793. package/dist/utils/manifest-prune.js +135 -0
  794. package/dist/utils/manifest-prune.js.map +1 -0
  795. package/dist/utils/posix.d.ts +13 -0
  796. package/dist/utils/posix.d.ts.map +1 -0
  797. package/dist/utils/posix.js +15 -0
  798. package/dist/utils/posix.js.map +1 -0
  799. package/dist/utils/project-detector.d.ts +46 -0
  800. package/dist/utils/project-detector.d.ts.map +1 -0
  801. package/dist/utils/project-detector.js +666 -0
  802. package/dist/utils/project-detector.js.map +1 -0
  803. package/dist/utils/proxy.d.ts +25 -0
  804. package/dist/utils/proxy.d.ts.map +1 -0
  805. package/dist/utils/proxy.js +60 -0
  806. package/dist/utils/proxy.js.map +1 -0
  807. package/dist/utils/registry-config.d.ts +7 -0
  808. package/dist/utils/registry-config.d.ts.map +1 -0
  809. package/dist/utils/registry-config.js +172 -0
  810. package/dist/utils/registry-config.js.map +1 -0
  811. package/dist/utils/task-json.d.ts +13 -0
  812. package/dist/utils/task-json.d.ts.map +1 -0
  813. package/dist/utils/task-json.js +12 -0
  814. package/dist/utils/task-json.js.map +1 -0
  815. package/dist/utils/template-fetcher.d.ts +161 -0
  816. package/dist/utils/template-fetcher.d.ts.map +1 -0
  817. package/dist/utils/template-fetcher.js +994 -0
  818. package/dist/utils/template-fetcher.js.map +1 -0
  819. package/dist/utils/template-hash.d.ts +127 -0
  820. package/dist/utils/template-hash.d.ts.map +1 -0
  821. package/dist/utils/template-hash.js +335 -0
  822. package/dist/utils/template-hash.js.map +1 -0
  823. package/dist/utils/uninstall-scrubbers.d.ts +66 -0
  824. package/dist/utils/uninstall-scrubbers.d.ts.map +1 -0
  825. package/dist/utils/uninstall-scrubbers.js +417 -0
  826. package/dist/utils/uninstall-scrubbers.js.map +1 -0
  827. package/dist/utils/workflow-resolver.d.ts +86 -0
  828. package/dist/utils/workflow-resolver.d.ts.map +1 -0
  829. package/dist/utils/workflow-resolver.js +265 -0
  830. package/dist/utils/workflow-resolver.js.map +1 -0
  831. package/package.json +89 -0
@@ -0,0 +1,2163 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import chalk from "chalk";
5
+ import inquirer from "inquirer";
6
+ import { DIR_NAMES, FILE_NAMES, PATHS } from "../constants/paths.js";
7
+ import { VERSION, PACKAGE_NAME } from "../constants/version.js";
8
+ import { getMigrationsForVersion, getAllMigrations, getMigrationMetadata, getConfigSectionsAddedBetween, } from "../migrations/index.js";
9
+ import { loadHashes, saveHashes, updateHashes, isTemplateModified, removeHash, renameHash, computeHash, shouldExcludeFromHash, } from "../utils/template-hash.js";
10
+ import { compareVersions } from "../utils/compare-versions.js";
11
+ import { toPosix } from "../utils/posix.js";
12
+ import { setupProxy } from "../utils/proxy.js";
13
+ import { emptyTaskJson } from "../utils/task-json.js";
14
+ // Import templates for comparison
15
+ import { getAllScripts, getAllAgents,
16
+ // Configuration
17
+ configYamlTemplate, gitignoreTemplate, workflowMdTemplate, } from "../templates/trellis/index.js";
18
+ import { agentsMdContent } from "../templates/markdown/index.js";
19
+ import { COPILOT_INSTRUCTIONS_BLOCK_END, COPILOT_INSTRUCTIONS_BLOCK_START, COPILOT_INSTRUCTIONS_PATH, getCopilotInstructions, } from "../templates/copilot/index.js";
20
+ import { ALL_MANAGED_DIRS, getConfiguredPlatforms, collectPlatformTemplates, } from "../configurators/index.js";
21
+ import { replacePythonCommandLiterals } from "../configurators/shared.js";
22
+ import { preserveCodexAgentModelKeys } from "../configurators/codex.js";
23
+ import { printZcodeSetupHint } from "../configurators/zcode.js";
24
+ import { ensureGitattributes } from "../configurators/workflow.js";
25
+ import { pruneOrphanManifestKeys } from "../utils/manifest-prune.js";
26
+ import { fetchRegistrySpecTemplates, collectDirectoryFiles, removeDirectory, parseRegistrySource, probeRegistryIndex, downloadTemplateById, } from "../utils/template-fetcher.js";
27
+ import { loadSpecRegistryConfig } from "../utils/registry-config.js";
28
+ import { cleanupEmptyDirs, TRELLIS_BLOCK_END, TRELLIS_BLOCK_START, } from "../utils/managed-paths.js";
29
+ export { cleanupEmptyDirs, TRELLIS_BLOCK_END, TRELLIS_BLOCK_START, } from "../utils/managed-paths.js";
30
+ const CLAUDE_SETTINGS_PATH = ".claude/settings.json";
31
+ const LEGACY_UNTRACKED_AGENTS_MD_BLOCK_HASHES = new Set([
32
+ // v0.5.0-beta.17 and earlier wrote AGENTS.md but did not hash-track it.
33
+ // This hash is the pristine Trellis-managed block before the Subagents
34
+ // section was added, so old untouched projects can be updated without a
35
+ // false "modified by you" conflict.
36
+ "c1f511b1cfc1902f2147da159f09cc51f380b0c9e341cdb3ac5dea5233f3e307",
37
+ ]);
38
+ // Paths that should never be touched (true user data)
39
+ // spec/ is user-customized content created during init; update should never modify it
40
+ const PROTECTED_PATHS = [
41
+ `${DIR_NAMES.WORKFLOW}/${DIR_NAMES.WORKSPACE}`, // workspace/
42
+ `${DIR_NAMES.WORKFLOW}/${DIR_NAMES.TASKS}`, // tasks/
43
+ `${DIR_NAMES.WORKFLOW}/${DIR_NAMES.SPEC}`, // spec/
44
+ `${DIR_NAMES.WORKFLOW}/.developer`,
45
+ `${DIR_NAMES.WORKFLOW}/.current-task`,
46
+ ];
47
+ function getManagedBlock(content, startMarker, endMarker) {
48
+ const start = content.indexOf(startMarker);
49
+ if (start === -1) {
50
+ return null;
51
+ }
52
+ const end = content.indexOf(endMarker, start);
53
+ if (end === -1) {
54
+ return null;
55
+ }
56
+ return content.slice(start, end + endMarker.length);
57
+ }
58
+ function getTrellisManagedBlock(content) {
59
+ return getManagedBlock(content, TRELLIS_BLOCK_START, TRELLIS_BLOCK_END);
60
+ }
61
+ function replaceManagedBlock(existingContent, templateContent, startMarker, endMarker) {
62
+ const existingStart = existingContent.indexOf(startMarker);
63
+ if (existingStart === -1) {
64
+ return null;
65
+ }
66
+ const existingEnd = existingContent.indexOf(endMarker, existingStart);
67
+ if (existingEnd === -1) {
68
+ return null;
69
+ }
70
+ const templateBlock = getManagedBlock(templateContent, startMarker, endMarker);
71
+ if (!templateBlock) {
72
+ return null;
73
+ }
74
+ return (existingContent.slice(0, existingStart) +
75
+ templateBlock +
76
+ existingContent.slice(existingEnd + endMarker.length));
77
+ }
78
+ function mergeManagedBlockContent(existingContent, templateContent, startMarker, endMarker) {
79
+ const replaced = replaceManagedBlock(existingContent, templateContent, startMarker, endMarker);
80
+ if (replaced !== null) {
81
+ return replaced;
82
+ }
83
+ const templateBlock = getManagedBlock(templateContent, startMarker, endMarker);
84
+ if (!templateBlock) {
85
+ return templateContent;
86
+ }
87
+ const trimmed = existingContent.replace(/\s+$/, "");
88
+ return `${trimmed}\n\n${templateBlock}\n`;
89
+ }
90
+ function buildManagedBlockTemplate(cwd, relativePath, templateContent, startMarker, endMarker) {
91
+ const fullPath = path.join(cwd, ...relativePath.split("/"));
92
+ if (!fs.existsSync(fullPath)) {
93
+ return templateContent;
94
+ }
95
+ const existingContent = fs.readFileSync(fullPath, "utf-8");
96
+ return mergeManagedBlockContent(existingContent, templateContent, startMarker, endMarker);
97
+ }
98
+ function buildAgentsMdTemplate(cwd) {
99
+ return buildManagedBlockTemplate(cwd, FILE_NAMES.AGENTS, agentsMdContent, TRELLIS_BLOCK_START, TRELLIS_BLOCK_END);
100
+ }
101
+ function buildCopilotInstructionsTemplate(cwd) {
102
+ return buildManagedBlockTemplate(cwd, COPILOT_INSTRUCTIONS_PATH, getCopilotInstructions(), COPILOT_INSTRUCTIONS_BLOCK_START, COPILOT_INSTRUCTIONS_BLOCK_END);
103
+ }
104
+ function isKnownUntrackedTemplate(relativePath, existingContent) {
105
+ if (relativePath !== FILE_NAMES.AGENTS) {
106
+ return false;
107
+ }
108
+ const managedBlock = getTrellisManagedBlock(existingContent);
109
+ if (!managedBlock) {
110
+ return false;
111
+ }
112
+ return LEGACY_UNTRACKED_AGENTS_MD_BLOCK_HASHES.has(computeHash(managedBlock));
113
+ }
114
+ function isSafeUntrackedCopilotInstructionsMerge(relativePath, existingContent, newContent) {
115
+ if (relativePath !== COPILOT_INSTRUCTIONS_PATH) {
116
+ return false;
117
+ }
118
+ if (getManagedBlock(existingContent, COPILOT_INSTRUCTIONS_BLOCK_START, COPILOT_INSTRUCTIONS_BLOCK_END)) {
119
+ return false;
120
+ }
121
+ return (mergeManagedBlockContent(existingContent, getCopilotInstructions(), COPILOT_INSTRUCTIONS_BLOCK_START, COPILOT_INSTRUCTIONS_BLOCK_END) === newContent);
122
+ }
123
+ /**
124
+ * Check if a path is blocked by PROTECTED_PATHS
125
+ */
126
+ function isProtectedPath(filePath) {
127
+ return PROTECTED_PATHS.some((pp) => filePath === pp || filePath.startsWith(pp.endsWith("/") ? pp : pp + "/"));
128
+ }
129
+ /**
130
+ * Collect and classify safe-file-delete migrations
131
+ *
132
+ * safe-file-delete auto-executes (no --migrate needed) when:
133
+ * - File exists
134
+ * - Content hash matches allowed_hashes
135
+ * - Path is not protected or in update.skip
136
+ * - Path is not owned by the current template set
137
+ */
138
+ function collectSafeFileDeletes(migrations, cwd, skipPaths, currentTemplatePaths,
139
+ /**
140
+ * Bypass `update.skip` for safe-file-delete. Enable this for breaking releases
141
+ * where honoring skip would leave the project half-migrated (old files at
142
+ * protected paths sitting next to the new architecture forever). The hash
143
+ * check in `allowed_hashes` is still the ultimate safety net — user-modified
144
+ * files still stay put with a "skip-modified" warning.
145
+ */
146
+ bypassUpdateSkip = false) {
147
+ // Historical migrations are loaded forever, so current template ownership
148
+ // must win when a later release intentionally restores a retired path.
149
+ const safeDeletes = migrations.filter((m) => m.type === "safe-file-delete" && !currentTemplatePaths.has(m.from));
150
+ const results = [];
151
+ for (const item of safeDeletes) {
152
+ const fullPath = path.join(cwd, item.from);
153
+ // Check: file exists?
154
+ if (!fs.existsSync(fullPath)) {
155
+ results.push({ item, action: "skip-missing" });
156
+ continue;
157
+ }
158
+ // Check: protected path? (user data dirs — always protected, never bypassed)
159
+ if (isProtectedPath(item.from)) {
160
+ results.push({ item, action: "skip-protected" });
161
+ continue;
162
+ }
163
+ // Check: update.skip? (can be bypassed for breaking releases)
164
+ if (!bypassUpdateSkip &&
165
+ skipPaths.some((skip) => item.from === skip ||
166
+ item.from.startsWith(skip.endsWith("/") ? skip : skip + "/"))) {
167
+ results.push({ item, action: "skip-update-skip" });
168
+ continue;
169
+ }
170
+ // Check: hash matches allowed_hashes?
171
+ if (!item.allowed_hashes || item.allowed_hashes.length === 0) {
172
+ // No allowed hashes defined — skip for safety
173
+ results.push({ item, action: "skip-modified" });
174
+ continue;
175
+ }
176
+ try {
177
+ const content = fs.readFileSync(fullPath, "utf-8");
178
+ const fileHash = computeHash(content);
179
+ if (item.allowed_hashes.includes(fileHash)) {
180
+ results.push({ item, action: "delete" });
181
+ }
182
+ else {
183
+ results.push({ item, action: "skip-modified" });
184
+ }
185
+ }
186
+ catch {
187
+ results.push({ item, action: "skip-missing" });
188
+ }
189
+ }
190
+ return results;
191
+ }
192
+ /**
193
+ * Print safe-file-delete summary
194
+ */
195
+ function printSafeFileDeleteSummary(classified) {
196
+ const toDelete = classified.filter((c) => c.action === "delete");
197
+ const modified = classified.filter((c) => c.action === "skip-modified");
198
+ const updateSkip = classified.filter((c) => c.action === "skip-update-skip");
199
+ if (toDelete.length === 0 &&
200
+ modified.length === 0 &&
201
+ updateSkip.length === 0) {
202
+ return;
203
+ }
204
+ console.log(chalk.cyan(" Deprecated commands cleanup:"));
205
+ if (toDelete.length > 0) {
206
+ for (const c of toDelete) {
207
+ console.log(chalk.green(` āœ• ${c.item.from}${c.item.description ? ` (${c.item.description})` : ""}`));
208
+ }
209
+ }
210
+ if (modified.length > 0) {
211
+ for (const c of modified) {
212
+ console.log(chalk.yellow(` ? ${c.item.from} (modified, skipped)`));
213
+ }
214
+ }
215
+ if (updateSkip.length > 0) {
216
+ for (const c of updateSkip) {
217
+ console.log(chalk.gray(` ā—‹ ${c.item.from} (skipped, update.skip)`));
218
+ }
219
+ }
220
+ console.log("");
221
+ }
222
+ /**
223
+ * Execute safe-file-delete items (delete files + clean up empty dirs)
224
+ */
225
+ function executeSafeFileDeletes(classified, cwd) {
226
+ const toDelete = classified.filter((c) => c.action === "delete");
227
+ let deleted = 0;
228
+ for (const c of toDelete) {
229
+ const fullPath = path.join(cwd, c.item.from);
230
+ try {
231
+ fs.unlinkSync(fullPath);
232
+ removeHash(cwd, c.item.from);
233
+ cleanupEmptyDirs(cwd, path.dirname(c.item.from));
234
+ deleted++;
235
+ }
236
+ catch {
237
+ // File may have been removed between classify and execute
238
+ }
239
+ }
240
+ return deleted;
241
+ }
242
+ /**
243
+ * Load update.skip paths from .trellis/config.yaml
244
+ *
245
+ * Parses simple YAML structure:
246
+ * update:
247
+ * skip:
248
+ * - path1
249
+ * - path2
250
+ *
251
+ * @internal Exported for testing only
252
+ */
253
+ export function loadUpdateSkipPaths(cwd) {
254
+ const configPath = path.join(cwd, DIR_NAMES.WORKFLOW, "config.yaml");
255
+ if (!fs.existsSync(configPath))
256
+ return [];
257
+ try {
258
+ const content = fs.readFileSync(configPath, "utf-8");
259
+ const lines = content.split("\n");
260
+ const paths = [];
261
+ let inUpdate = false;
262
+ let inSkip = false;
263
+ for (const line of lines) {
264
+ const trimmed = line.trimEnd();
265
+ // Check for "update:" section (no indentation or at root level)
266
+ if (/^update:\s*$/.test(trimmed)) {
267
+ inUpdate = true;
268
+ inSkip = false;
269
+ continue;
270
+ }
271
+ // Check for "skip:" under update (indented)
272
+ if (inUpdate && /^\s+skip:\s*$/.test(trimmed)) {
273
+ inSkip = true;
274
+ continue;
275
+ }
276
+ // Collect list items under skip
277
+ if (inSkip) {
278
+ const match = trimmed.match(/^\s+-\s+(.+)$/);
279
+ if (match) {
280
+ paths.push(match[1].trim().replace(/^['"]|['"]$/g, ""));
281
+ continue;
282
+ }
283
+ // If line is non-empty and not a list item, we've left the skip section
284
+ if (trimmed !== "" && !trimmed.startsWith("#")) {
285
+ inSkip = false;
286
+ inUpdate = false;
287
+ }
288
+ }
289
+ // If we're in update but hit a non-indented line, we've left the update section
290
+ if (inUpdate &&
291
+ trimmed !== "" &&
292
+ !trimmed.startsWith(" ") &&
293
+ !trimmed.startsWith("#")) {
294
+ inUpdate = false;
295
+ inSkip = false;
296
+ }
297
+ }
298
+ return paths;
299
+ }
300
+ catch {
301
+ // Config exists but failed to parse — warn user that skip rules won't apply
302
+ console.warn(`Warning: failed to parse ${configPath}, update.skip rules will not be applied`);
303
+ return [];
304
+ }
305
+ }
306
+ /**
307
+ * Extract a "section" from a config.yaml-style template by sectionHeading.
308
+ *
309
+ * A section is delimited by `#---...---` separator lines (the same pattern
310
+ * used in the bundled `config.yaml` template). The first line inside the
311
+ * separator block whose `# ` content matches `sectionHeading` identifies the
312
+ * section; the section spans from that opening separator block through the
313
+ * line preceding the next `#---` separator block (or EOF).
314
+ *
315
+ * Returns the extracted text including its leading separator block, or `null`
316
+ * when no matching section is found.
317
+ *
318
+ * @internal Exported for testing only.
319
+ */
320
+ export function extractConfigSection(template, sectionHeading) {
321
+ const lines = template.split("\n");
322
+ const isSeparator = (line) => /^#-{3,}\s*$/.test(line.trimEnd());
323
+ for (let i = 0; i < lines.length; i++) {
324
+ if (!isSeparator(lines[i]))
325
+ continue;
326
+ // Look ahead for `# <heading>` then another separator that closes the
327
+ // heading block.
328
+ const headingLine = lines[i + 1];
329
+ const closingSeparator = lines[i + 2];
330
+ if (headingLine === undefined || closingSeparator === undefined)
331
+ continue;
332
+ if (!headingLine.startsWith("# "))
333
+ continue;
334
+ if (!isSeparator(closingSeparator))
335
+ continue;
336
+ if (headingLine.slice(2).trim() !== sectionHeading)
337
+ continue;
338
+ // Section starts at i; find the next separator block to bound it.
339
+ let end = lines.length;
340
+ for (let j = i + 3; j < lines.length; j++) {
341
+ if (isSeparator(lines[j])) {
342
+ end = j;
343
+ break;
344
+ }
345
+ }
346
+ return lines.slice(i, end).join("\n").replace(/\n+$/, "");
347
+ }
348
+ return null;
349
+ }
350
+ /**
351
+ * Apply additive config.yaml sections introduced between two versions.
352
+ *
353
+ * Walks the supplied entries, dedupes by `file+sentinel`, and for each unique
354
+ * entry: if the user file exists and lacks the sentinel, extracts the named
355
+ * section from `templateContent` and appends it. Idempotent — re-running the
356
+ * step on a file that already contains the sentinel is a no-op.
357
+ *
358
+ * @internal Exported for testing only.
359
+ */
360
+ export function applyConfigSectionsAdded(entries, cwd, bundledTemplates) {
361
+ const seen = new Set();
362
+ let appended = 0;
363
+ for (const entry of entries) {
364
+ const dedupeKey = `${entry.file}::${entry.sentinel}`;
365
+ if (seen.has(dedupeKey))
366
+ continue;
367
+ seen.add(dedupeKey);
368
+ const targetPath = path.join(cwd, entry.file);
369
+ if (!fs.existsSync(targetPath))
370
+ continue;
371
+ let userContent;
372
+ try {
373
+ userContent = fs.readFileSync(targetPath, "utf-8");
374
+ }
375
+ catch {
376
+ continue;
377
+ }
378
+ if (userContent.includes(entry.sentinel))
379
+ continue;
380
+ const template = bundledTemplates.get(entry.file);
381
+ if (!template)
382
+ continue;
383
+ const section = extractConfigSection(template, entry.sectionHeading);
384
+ if (!section)
385
+ continue;
386
+ const separator = userContent.endsWith("\n") ? "\n" : "\n\n";
387
+ const newContent = userContent + separator + section + "\n";
388
+ try {
389
+ fs.writeFileSync(targetPath, newContent);
390
+ }
391
+ catch {
392
+ continue;
393
+ }
394
+ console.log(chalk.green(` + Added config section "${entry.sectionHeading}" to ${entry.file}`));
395
+ appended++;
396
+ }
397
+ return { appended };
398
+ }
399
+ /**
400
+ * Collect all template files that should be managed by update
401
+ * Only collects templates for platforms that are already configured (have directories)
402
+ */
403
+ /**
404
+ * Detect if legacy Codex upgrade is needed.
405
+ *
406
+ * Old Trellis versions used `.agents/skills/` as codex's configDir.
407
+ * New versions use `.codex/` for Codex-specific config and `.agents/skills/`
408
+ * as a shared layer.
409
+ *
410
+ * Detection: Trellis-tracked hashes contain `.agents/skills/` entries
411
+ * but `.codex/` does not exist. This avoids misclassifying repos that
412
+ * have `.agents/skills/` from other tools (Kimi CLI, Amp, etc.).
413
+ *
414
+ * Returns true if upgrade is needed. Does NOT perform the upgrade —
415
+ * caller should run configurePlatform("codex") after backup/confirm.
416
+ */
417
+ function needsCodexUpgrade(cwd) {
418
+ if (fs.existsSync(path.join(cwd, ".codex"))) {
419
+ return false;
420
+ }
421
+ // Legacy Codex marker: old Codex installs tracked command-as-skill files
422
+ // under `.agents/skills/` before `.codex/` existed as a separate config dir.
423
+ // A current or future non-Codex platform may own those paths too, so do not
424
+ // trigger the Codex backfill when a configured non-Codex platform declares
425
+ // the marker paths in its templates.
426
+ const hashes = loadHashes(cwd);
427
+ const legacyMarkers = [
428
+ ".agents/skills/trellis-continue/SKILL.md",
429
+ ".agents/skills/trellis-finish-work/SKILL.md",
430
+ ];
431
+ const hasLegacyMarker = legacyMarkers.some((key) => hashes[key] !== undefined);
432
+ if (!hasLegacyMarker) {
433
+ return false;
434
+ }
435
+ for (const platformId of getConfiguredPlatforms(cwd)) {
436
+ if (platformId === "codex") {
437
+ continue;
438
+ }
439
+ const platformFiles = collectPlatformTemplates(platformId);
440
+ if (platformFiles && legacyMarkers.some((key) => platformFiles.has(key))) {
441
+ return false;
442
+ }
443
+ }
444
+ return true;
445
+ }
446
+ function preserveExistingClaudeStatusLine(cwd, templates) {
447
+ const newSettingsContent = templates.get(CLAUDE_SETTINGS_PATH);
448
+ if (!newSettingsContent)
449
+ return;
450
+ const settingsPath = path.join(cwd, CLAUDE_SETTINGS_PATH);
451
+ if (!fs.existsSync(settingsPath))
452
+ return;
453
+ try {
454
+ const existingSettings = JSON.parse(fs.readFileSync(settingsPath, "utf-8"));
455
+ if (!Object.prototype.hasOwnProperty.call(existingSettings, "statusLine")) {
456
+ return;
457
+ }
458
+ const newSettings = JSON.parse(newSettingsContent);
459
+ if (Object.prototype.hasOwnProperty.call(newSettings, "statusLine")) {
460
+ return;
461
+ }
462
+ newSettings.statusLine = existingSettings.statusLine;
463
+ templates.set(CLAUDE_SETTINGS_PATH, `${JSON.stringify(newSettings, null, 2)}\n`);
464
+ }
465
+ catch {
466
+ // Invalid local JSON is handled by the normal conflict path.
467
+ }
468
+ }
469
+ function preserveExistingRegistryConfig(cwd, template) {
470
+ const registry = loadSpecRegistryConfig(cwd);
471
+ if (!registry)
472
+ return template;
473
+ return (template.trimEnd() +
474
+ "\n\n" +
475
+ "#-------------------------------------------------------------------------------\n" +
476
+ "# Registry\n" +
477
+ "#-------------------------------------------------------------------------------\n\n" +
478
+ "# Source used to install .trellis/spec. trellis update refreshes this\n" +
479
+ "# hash-tracked spec template while preserving local edits through the\n" +
480
+ "# normal update conflict flow.\n" +
481
+ "registry:\n" +
482
+ " spec:\n" +
483
+ ` source: ${registry.source}\n` +
484
+ (registry.template ? ` template: ${registry.template}\n` : ""));
485
+ }
486
+ async function collectRegistrySpecTemplates(cwd) {
487
+ const config = loadSpecRegistryConfig(cwd);
488
+ if (!config)
489
+ return new Map();
490
+ let registry;
491
+ try {
492
+ registry = parseRegistrySource(config.source);
493
+ }
494
+ catch (error) {
495
+ console.log(chalk.yellow(`Warning: invalid registry.spec.source in .trellis/config.yaml: ${error instanceof Error ? error.message : String(error)}`));
496
+ return new Map();
497
+ }
498
+ const probe = await probeRegistryIndex(`${registry.rawBaseUrl}/index.json`, registry);
499
+ if (probe.templates.length > 0) {
500
+ if (!config.template) {
501
+ console.log(chalk.gray("Registry spec update skipped: marketplace registries require registry.spec.template."));
502
+ return new Map();
503
+ }
504
+ const template = probe.templates.find((candidate) => candidate.id === config.template);
505
+ if (!template) {
506
+ console.log(chalk.yellow(`Warning: registry spec update skipped: template "${config.template}" was not found in registry index.`));
507
+ return new Map();
508
+ }
509
+ const tempRoot = await fs.promises.mkdtemp(path.join(os.tmpdir(), "trellis-registry-template-"));
510
+ try {
511
+ const result = await downloadTemplateById(tempRoot, config.template, "overwrite", template, registry, undefined, probe.backend);
512
+ if (!result.success) {
513
+ console.log(chalk.yellow(`Warning: registry spec update skipped: ${result.message}`));
514
+ return new Map();
515
+ }
516
+ return collectDirectoryFiles(path.join(tempRoot, PATHS.SPEC), PATHS.SPEC);
517
+ }
518
+ finally {
519
+ await removeDirectory(tempRoot);
520
+ }
521
+ }
522
+ if (!probe.isNotFound) {
523
+ console.log(chalk.yellow(`Warning: registry spec update skipped: ${probe.error?.message ?? "could not reach registry"}`));
524
+ return new Map();
525
+ }
526
+ const result = await fetchRegistrySpecTemplates(registry, probe.backend);
527
+ if (!result.success) {
528
+ console.log(chalk.yellow(`Warning: registry spec update skipped: ${result.message ?? "download failed"}`));
529
+ return new Map();
530
+ }
531
+ return result.files;
532
+ }
533
+ async function collectTemplateFiles(cwd, extraPlatforms,
534
+ /**
535
+ * Bypass `update.skip` when collecting templates. Enable this for breaking
536
+ * releases so new files (e.g. `continue.md` added in 0.5.0) and template
537
+ * updates can land even under skip-protected paths. Without this, users with
538
+ * `.claude/commands/` in their skip list would silently miss new commands.
539
+ * Existing user customizations are still guarded at WRITE time via the
540
+ * "Modified by you" conflict prompt — they can skip per-file there.
541
+ */
542
+ bypassUpdateSkip = false) {
543
+ const files = new Map();
544
+ const platforms = getConfiguredPlatforms(cwd);
545
+ if (extraPlatforms) {
546
+ for (const p of extraPlatforms) {
547
+ platforms.add(p);
548
+ }
549
+ }
550
+ // Python scripts (single source of truth: getAllScripts())
551
+ for (const [scriptPath, content] of getAllScripts()) {
552
+ files.set(`${PATHS.SCRIPTS}/${scriptPath}`, content);
553
+ }
554
+ // Channel runtime agent definitions (single source of truth: getAllAgents()).
555
+ // Backfilled by `trellis update` if missing so users who installed before the
556
+ // bundled agents existed pick them up. Edited files take the standard
557
+ // modified-file prompt path.
558
+ for (const [agentFile, content] of getAllAgents()) {
559
+ files.set(`${PATHS.AGENTS}/${agentFile}`, content);
560
+ }
561
+ // Configuration
562
+ files.set(`${DIR_NAMES.WORKFLOW}/config.yaml`, preserveExistingRegistryConfig(cwd, configYamlTemplate));
563
+ files.set(`${DIR_NAMES.WORKFLOW}/.gitignore`, gitignoreTemplate);
564
+ // workflow.md is included here because it is runtime-parsed by
565
+ // get_context.py and shared hooks. Keep it on the normal template update
566
+ // path: if the installed file still matches the tracked hash, update the
567
+ // whole file. If the user edited it, the standard modified-file prompt /
568
+ // --force behavior applies. Partial tag-block merging is unsafe because
569
+ // platform routing markers outside [workflow-state:*] blocks are also
570
+ // script-consumed.
571
+ files.set(`${DIR_NAMES.WORKFLOW}/workflow.md`, workflowMdTemplate);
572
+ // workspace/index.md stays excluded — it's runtime-appended by add_session.py
573
+ // (journal index) and has no script-parsed structure.
574
+ files.set(FILE_NAMES.AGENTS, buildAgentsMdTemplate(cwd));
575
+ // Platform-specific templates (only for configured platforms)
576
+ for (const platformId of platforms) {
577
+ const platformFiles = collectPlatformTemplates(platformId);
578
+ if (platformFiles) {
579
+ for (const [filePath, content] of platformFiles) {
580
+ files.set(filePath, content);
581
+ }
582
+ if (platformId === "copilot") {
583
+ files.set(COPILOT_INSTRUCTIONS_PATH, buildCopilotInstructionsTemplate(cwd));
584
+ }
585
+ }
586
+ }
587
+ // Users configure sub-agent models by editing `model` /
588
+ // `model_reasoning_effort` directly on the generated agent tomls. Preserve
589
+ // those two keys from the on-disk files into the freshly rendered desired
590
+ // content so a project whose only local edit is these keys is not flagged
591
+ // as a modified-file conflict by the hash comparison below.
592
+ if (platforms.has("codex")) {
593
+ preserveCodexAgentModelKeys(cwd, files);
594
+ }
595
+ preserveExistingClaudeStatusLine(cwd, files);
596
+ for (const [filePath, content] of await collectRegistrySpecTemplates(cwd)) {
597
+ files.set(filePath, content);
598
+ }
599
+ // Apply update.skip from config.yaml (unless bypassed for breaking release)
600
+ if (!bypassUpdateSkip) {
601
+ const skipPaths = loadUpdateSkipPaths(cwd);
602
+ if (skipPaths.length > 0) {
603
+ for (const [filePath] of [...files]) {
604
+ if (skipPaths.some((skip) => filePath === skip ||
605
+ filePath.startsWith(skip.endsWith("/") ? skip : skip + "/"))) {
606
+ files.delete(filePath);
607
+ }
608
+ }
609
+ }
610
+ }
611
+ // Apply python3→python replacement for Windows consistency with init-time writes
612
+ for (const [filePath, content] of files) {
613
+ files.set(filePath, replacePythonCommandLiterals(content));
614
+ }
615
+ return files;
616
+ }
617
+ /**
618
+ * Analyze changes between current files and templates
619
+ *
620
+ * Uses hash tracking to distinguish between:
621
+ * - User didn't modify + template same = skip (unchangedFiles)
622
+ * - User didn't modify + template updated = auto-update (autoUpdateFiles)
623
+ * - User modified = needs confirmation (changedFiles)
624
+ */
625
+ function analyzeChanges(cwd, hashes, templates) {
626
+ const result = {
627
+ newFiles: [],
628
+ unchangedFiles: [],
629
+ autoUpdateFiles: [],
630
+ changedFiles: [],
631
+ userDeletedFiles: [],
632
+ protectedPaths: PROTECTED_PATHS,
633
+ };
634
+ for (const [relativePath, newContent] of templates) {
635
+ const fullPath = path.join(cwd, relativePath);
636
+ const exists = fs.existsSync(fullPath);
637
+ const change = {
638
+ path: fullPath,
639
+ relativePath,
640
+ newContent,
641
+ status: "new",
642
+ };
643
+ if (!exists) {
644
+ const storedHash = hashes[relativePath];
645
+ if (storedHash) {
646
+ // Previously installed but user deleted — respect deletion
647
+ result.userDeletedFiles.push(change);
648
+ }
649
+ else {
650
+ change.status = "new";
651
+ result.newFiles.push(change);
652
+ }
653
+ }
654
+ else {
655
+ const existingContent = fs.readFileSync(fullPath, "utf-8");
656
+ if (existingContent === newContent) {
657
+ // Content same as template - already up to date
658
+ change.status = "unchanged";
659
+ result.unchangedFiles.push(change);
660
+ }
661
+ else {
662
+ // Content differs - check if user modified or template updated
663
+ const storedHash = hashes[relativePath];
664
+ const currentHash = computeHash(existingContent);
665
+ if ((storedHash && storedHash === currentHash) ||
666
+ (!storedHash &&
667
+ isKnownUntrackedTemplate(relativePath, existingContent)) ||
668
+ (!storedHash &&
669
+ isSafeUntrackedCopilotInstructionsMerge(relativePath, existingContent, newContent))) {
670
+ // Either the tracked hash matches, or this is a known pristine template
671
+ // from before the path was hash-tracked. Safe to auto-update.
672
+ change.status = "changed";
673
+ result.autoUpdateFiles.push(change);
674
+ }
675
+ else {
676
+ // Hash differs (or no stored hash) - user modified the file
677
+ // Needs confirmation
678
+ change.status = "changed";
679
+ result.changedFiles.push(change);
680
+ }
681
+ }
682
+ }
683
+ }
684
+ return result;
685
+ }
686
+ /**
687
+ * Receipt entries that are wrong or missing for a file that is already
688
+ * byte-identical to its template.
689
+ *
690
+ * Nothing else repairs these. `analyzeChanges` classifies such a file
691
+ * `unchanged`, and the write-back draws only from `newFiles`,
692
+ * `autoUpdateFiles` and overwritten `changedFiles` — so a poisoned or absent
693
+ * entry beside a pristine file survives every subsequent `trellis update`,
694
+ * however many times it is run. Identical template content across versions is
695
+ * not what saves such an entry from going stale; it is precisely what freezes
696
+ * it, because the file never leaves the `unchanged` bucket.
697
+ *
698
+ * Recording the template's hash here cannot bless a local edit. Membership in
699
+ * `unchangedFiles` means the file on disk already *is* the template, byte for
700
+ * byte, so the value written is the one a correct receipt would already hold.
701
+ * A genuinely customized file differs from its template, lands in
702
+ * `changedFiles`, and is never seen by this function.
703
+ *
704
+ * That also leaves the mixed-ownership paths — `AGENTS.md`,
705
+ * `.github/copilot-instructions.md`, `.trellis/config.yaml` — free to differ
706
+ * from their recorded hash, which for them is the correct state: once the
707
+ * repository has appended its own content they are no longer `unchanged`.
708
+ */
709
+ function collectUnchangedFileHashRepairs(changes, hashes) {
710
+ const files = new Map();
711
+ for (const file of changes.unchangedFiles) {
712
+ const key = toPosix(file.relativePath);
713
+ const recorded = hashes[key];
714
+ if (recorded === undefined) {
715
+ // A missing entry is only an omission for a path the receipt is meant
716
+ // to carry. `EXCLUDE_FROM_HASH` holds paths deliberately left out —
717
+ // `.trellis/.gitignore` among them — and adding those here would put
718
+ // this path in disagreement with `initializeHashes` about what the
719
+ // receipt tracks at all.
720
+ if (!shouldExcludeFromHash(key)) {
721
+ files.set(key, file.newContent);
722
+ }
723
+ continue;
724
+ }
725
+ // An entry that already exists and disagrees with the file is repaired
726
+ // whatever the path: a wrong value is strictly worse than an absent one,
727
+ // because it reads as a real local modification.
728
+ if (recorded !== computeHash(file.newContent)) {
729
+ files.set(key, file.newContent);
730
+ }
731
+ }
732
+ return files;
733
+ }
734
+ /**
735
+ * Print change summary
736
+ */
737
+ function printChangeSummary(changes) {
738
+ console.log("\nScanning for changes...\n");
739
+ if (changes.newFiles.length > 0) {
740
+ console.log(chalk.green(" New files (will add):"));
741
+ for (const file of changes.newFiles) {
742
+ console.log(chalk.green(` + ${file.relativePath}`));
743
+ }
744
+ console.log("");
745
+ }
746
+ if (changes.autoUpdateFiles.length > 0) {
747
+ console.log(chalk.cyan(" Template updated (will auto-update):"));
748
+ for (const file of changes.autoUpdateFiles) {
749
+ console.log(chalk.cyan(` ↑ ${file.relativePath}`));
750
+ }
751
+ console.log("");
752
+ }
753
+ if (changes.unchangedFiles.length > 0) {
754
+ console.log(chalk.gray(" Unchanged files (will skip):"));
755
+ for (const file of changes.unchangedFiles.slice(0, 5)) {
756
+ console.log(chalk.gray(` ā—‹ ${file.relativePath}`));
757
+ }
758
+ if (changes.unchangedFiles.length > 5) {
759
+ console.log(chalk.gray(` ... and ${changes.unchangedFiles.length - 5} more`));
760
+ }
761
+ console.log("");
762
+ }
763
+ if (changes.changedFiles.length > 0) {
764
+ console.log(chalk.yellow(" Modified by you (need your decision):"));
765
+ for (const file of changes.changedFiles) {
766
+ console.log(chalk.yellow(` ? ${file.relativePath}`));
767
+ }
768
+ console.log("");
769
+ }
770
+ if (changes.userDeletedFiles.length > 0) {
771
+ console.log(chalk.gray(" Deleted by you (preserved):"));
772
+ for (const file of changes.userDeletedFiles) {
773
+ console.log(chalk.gray(` \u2715 ${file.relativePath}`));
774
+ }
775
+ console.log("");
776
+ }
777
+ // Only show protected paths that actually exist
778
+ const existingProtectedPaths = changes.protectedPaths.filter((p) => {
779
+ const fullPath = path.join(process.cwd(), p);
780
+ return fs.existsSync(fullPath);
781
+ });
782
+ if (existingProtectedPaths.length > 0) {
783
+ console.log(chalk.gray(" User data (preserved):"));
784
+ for (const protectedPath of existingProtectedPaths) {
785
+ console.log(chalk.gray(` ā—‹ ${protectedPath}/`));
786
+ }
787
+ console.log("");
788
+ }
789
+ }
790
+ /**
791
+ * Prompt user for conflict resolution
792
+ */
793
+ async function promptConflictResolution(file, options, applyToAll) {
794
+ // If we have a batch action, use it
795
+ if (applyToAll.action) {
796
+ return applyToAll.action;
797
+ }
798
+ // Check command-line options
799
+ if (options.force) {
800
+ return "overwrite";
801
+ }
802
+ if (options.skipAll) {
803
+ return "skip";
804
+ }
805
+ if (options.createNew) {
806
+ return "create-new";
807
+ }
808
+ // Interactive prompt
809
+ const { action } = await inquirer.prompt([
810
+ {
811
+ type: "list",
812
+ name: "action",
813
+ message: `${file.relativePath} has changes.`,
814
+ choices: [
815
+ {
816
+ name: "[1] Overwrite - Replace with new version",
817
+ value: "overwrite",
818
+ },
819
+ { name: "[2] Skip - Keep your current version", value: "skip" },
820
+ {
821
+ name: "[3] Create copy - Save new version as .new",
822
+ value: "create-new",
823
+ },
824
+ { name: "[a] Apply Overwrite to all", value: "overwrite-all" },
825
+ { name: "[s] Apply Skip to all", value: "skip-all" },
826
+ { name: "[n] Apply Create copy to all", value: "create-new-all" },
827
+ ],
828
+ default: "skip",
829
+ },
830
+ ]);
831
+ if (action === "overwrite-all") {
832
+ applyToAll.action = "overwrite";
833
+ return "overwrite";
834
+ }
835
+ if (action === "skip-all") {
836
+ applyToAll.action = "skip";
837
+ return "skip";
838
+ }
839
+ if (action === "create-new-all") {
840
+ applyToAll.action = "create-new";
841
+ return "create-new";
842
+ }
843
+ return action;
844
+ }
845
+ /**
846
+ * Create a timestamped backup directory path
847
+ */
848
+ function createBackupDirPath(cwd) {
849
+ const timestamp = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
850
+ return path.join(cwd, DIR_NAMES.WORKFLOW, `.backup-${timestamp}`);
851
+ }
852
+ /**
853
+ * Backup a single file to the backup directory
854
+ */
855
+ function backupFile(cwd, backupDir, relativePath) {
856
+ const srcPath = path.join(cwd, relativePath);
857
+ if (!fs.existsSync(srcPath))
858
+ return;
859
+ const backupPath = path.join(backupDir, relativePath);
860
+ fs.mkdirSync(path.dirname(backupPath), { recursive: true });
861
+ fs.copyFileSync(srcPath, backupPath);
862
+ }
863
+ /**
864
+ * Directories to backup as complete snapshot (derived from platform registry)
865
+ */
866
+ const BACKUP_DIRS = ALL_MANAGED_DIRS;
867
+ /** Root-level managed files to include in update backups. */
868
+ const BACKUP_FILES = [FILE_NAMES.AGENTS];
869
+ /**
870
+ * Patterns to exclude from backup (user data that shouldn't be backed up)
871
+ */
872
+ const BACKUP_EXCLUDE_PATTERNS = [
873
+ ".backup-", // Previous backups
874
+ "/node_modules", // Installed dependencies; restore via package manager
875
+ "/workspace/", // Developer workspace (user data)
876
+ "/tasks/", // Task data (user data)
877
+ "/spec/", // Spec files (user-customized content)
878
+ "/backlog/", // Backlog data (user data)
879
+ "/agent-traces/", // Agent traces (user data, legacy name)
880
+ // Platform-native worktree dirs — these are full sub-repos the CLI
881
+ // spawns for parallel sessions. Backing them up on every update would
882
+ // snapshot the entire nested working tree. Confirmed conventions:
883
+ // Claude Code: .claude/worktrees/
884
+ // Cursor CLI: .cursor/worktrees/
885
+ // Gemini CLI: .gemini/worktrees/
886
+ // Matches any platform using the same convention (future-proof).
887
+ "/worktrees/",
888
+ "/worktree/",
889
+ ];
890
+ /**
891
+ * Check if a path should be excluded from backup
892
+ * @internal Exported for testing only
893
+ */
894
+ export function shouldExcludeFromBackup(relativePath) {
895
+ // Normalize Windows backslashes to forward slashes so patterns like
896
+ // "/worktrees/" / "/tasks/" match regardless of host OS. Without this,
897
+ // Windows `path.relative` returns `.claude\worktrees\...` and none of
898
+ // the slash-prefixed exclude patterns trigger — which causes
899
+ // `collectAllFiles` to descend into platform worktrees (full nested
900
+ // project copies) and explode the scan. Same normalization pattern
901
+ // used by `isManagedPath` in configurators/index.ts.
902
+ const normalized = relativePath.replace(/\\/g, "/");
903
+ for (const pattern of BACKUP_EXCLUDE_PATTERNS) {
904
+ if (normalized.includes(pattern)) {
905
+ return true;
906
+ }
907
+ }
908
+ return false;
909
+ }
910
+ /**
911
+ * Create complete snapshot backup of all managed directories
912
+ * Backs up all managed platform/workflow directories entirely
913
+ * (excluding user data like workspace/, tasks/, backlog/)
914
+ */
915
+ function createFullBackup(cwd) {
916
+ const backupDir = createBackupDirPath(cwd);
917
+ let hasFiles = false;
918
+ for (const dir of BACKUP_DIRS) {
919
+ const dirPath = path.join(cwd, dir);
920
+ if (!fs.existsSync(dirPath))
921
+ continue;
922
+ const files = collectAllFiles(dirPath, cwd);
923
+ for (const fullPath of files) {
924
+ const relativePath = path.relative(cwd, fullPath);
925
+ // Skip excluded paths
926
+ if (shouldExcludeFromBackup(relativePath))
927
+ continue;
928
+ // Create backup
929
+ if (!hasFiles) {
930
+ fs.mkdirSync(backupDir, { recursive: true });
931
+ hasFiles = true;
932
+ }
933
+ backupFile(cwd, backupDir, relativePath);
934
+ }
935
+ }
936
+ for (const relativePath of BACKUP_FILES) {
937
+ const fullPath = path.join(cwd, relativePath);
938
+ if (!fs.existsSync(fullPath))
939
+ continue;
940
+ if (shouldExcludeFromBackup(relativePath))
941
+ continue;
942
+ if (!hasFiles) {
943
+ fs.mkdirSync(backupDir, { recursive: true });
944
+ hasFiles = true;
945
+ }
946
+ backupFile(cwd, backupDir, relativePath);
947
+ }
948
+ return hasFiles ? backupDir : null;
949
+ }
950
+ /**
951
+ * Update version file
952
+ */
953
+ function updateVersionFile(cwd) {
954
+ const versionPath = path.join(cwd, DIR_NAMES.WORKFLOW, ".version");
955
+ fs.writeFileSync(versionPath, VERSION);
956
+ }
957
+ /**
958
+ * Get current installed version
959
+ */
960
+ function getInstalledVersion(cwd) {
961
+ const versionPath = path.join(cwd, DIR_NAMES.WORKFLOW, ".version");
962
+ if (fs.existsSync(versionPath)) {
963
+ return fs.readFileSync(versionPath, "utf-8").trim();
964
+ }
965
+ return "unknown";
966
+ }
967
+ /**
968
+ * Fetch latest version from npm registry
969
+ */
970
+ async function getLatestNpmVersion() {
971
+ try {
972
+ const response = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`);
973
+ if (!response.ok) {
974
+ return null;
975
+ }
976
+ const data = (await response.json());
977
+ return data.version ?? null;
978
+ }
979
+ catch {
980
+ return null;
981
+ }
982
+ }
983
+ /**
984
+ * Recursively collect all files in a directory
985
+ */
986
+ function collectAllFiles(dirPath, cwd = process.cwd()) {
987
+ if (!fs.existsSync(dirPath))
988
+ return [];
989
+ const rootStat = fs.statSync(dirPath);
990
+ if (rootStat.isFile()) {
991
+ return [dirPath];
992
+ }
993
+ if (!rootStat.isDirectory()) {
994
+ return [];
995
+ }
996
+ const files = [];
997
+ const stack = [dirPath];
998
+ while (stack.length > 0) {
999
+ const currentDir = stack.pop();
1000
+ if (!currentDir)
1001
+ continue;
1002
+ const entries = fs.readdirSync(currentDir, { withFileTypes: true });
1003
+ for (const entry of entries) {
1004
+ const fullPath = path.join(currentDir, entry.name);
1005
+ const relativePath = path.relative(cwd, fullPath);
1006
+ // Never follow symlinks / Windows directory junctions — a junction
1007
+ // pointing at an ancestor would loop the scan forever. Node's
1008
+ // `isSymbolicLink()` returns true for NTFS junctions since v12.
1009
+ if (entry.isSymbolicLink())
1010
+ continue;
1011
+ if (entry.isDirectory()) {
1012
+ if (!shouldExcludeFromBackup(relativePath)) {
1013
+ stack.push(fullPath);
1014
+ }
1015
+ }
1016
+ else if (entry.isFile()) {
1017
+ files.push(fullPath);
1018
+ }
1019
+ }
1020
+ }
1021
+ return files;
1022
+ }
1023
+ /**
1024
+ * Whether every file under `dirRelativePath` byte-matches the CURRENT
1025
+ * template content for its path. Stricter than {@link isDirectorySafeToReplace},
1026
+ * which also accepts files that are merely unmodified relative to an old
1027
+ * stored hash (i.e. stale-but-untouched). Used to decide the safe *direction*
1028
+ * of a rename-dir merge when both source and target exist: if the target
1029
+ * already holds canonical current-version bytes, the source (however it got
1030
+ * there) must not be allowed to overwrite it with older/differently-flavored
1031
+ * content (#447 — a legacy `.pi/skills/` copy rendered with the Pi-specific
1032
+ * resolver must not clobber the shared, neutral `.agents/skills/` content
1033
+ * Codex/Gemini already wrote).
1034
+ */
1035
+ function dirMatchesCurrentTemplates(cwd, dirRelativePath, templates) {
1036
+ const dirFullPath = path.join(cwd, dirRelativePath);
1037
+ if (!fs.existsSync(dirFullPath))
1038
+ return false;
1039
+ const files = collectAllFiles(dirFullPath, cwd);
1040
+ if (files.length === 0)
1041
+ return false;
1042
+ for (const fullPath of files) {
1043
+ const relativePath = toPosix(path.relative(cwd, fullPath));
1044
+ const templateContent = templates.get(relativePath);
1045
+ if (templateContent === undefined)
1046
+ return false;
1047
+ if (fs.readFileSync(fullPath, "utf-8") !== templateContent)
1048
+ return false;
1049
+ }
1050
+ return true;
1051
+ }
1052
+ /**
1053
+ * Check if a directory only contains unmodified template files
1054
+ * Returns true if safe to delete:
1055
+ * - All files are tracked and unmodified, OR
1056
+ * - All files match current template content (even if not tracked)
1057
+ */
1058
+ function isDirectorySafeToReplace(cwd, dirRelativePath, hashes, templates) {
1059
+ const dirFullPath = path.join(cwd, dirRelativePath);
1060
+ if (!fs.existsSync(dirFullPath))
1061
+ return true;
1062
+ const files = collectAllFiles(dirFullPath, cwd);
1063
+ if (files.length === 0)
1064
+ return true; // Empty directory is safe
1065
+ for (const fullPath of files) {
1066
+ // POSIX-normalize: hashes/templates keys are persisted as POSIX, but
1067
+ // `path.relative` returns OS-native separators (backslash on Windows).
1068
+ const relativePath = toPosix(path.relative(cwd, fullPath));
1069
+ const storedHash = hashes[relativePath];
1070
+ const templateContent = templates.get(relativePath);
1071
+ // Check if file matches template content (handles untracked files)
1072
+ if (templateContent) {
1073
+ const currentContent = fs.readFileSync(fullPath, "utf-8");
1074
+ if (currentContent === templateContent) {
1075
+ // File matches template - safe
1076
+ continue;
1077
+ }
1078
+ }
1079
+ // Check if file is tracked and unmodified
1080
+ if (storedHash && !isTemplateModified(cwd, relativePath, hashes)) {
1081
+ // Tracked and unmodified - safe
1082
+ continue;
1083
+ }
1084
+ // File is either user-created or user-modified - not safe
1085
+ return false;
1086
+ }
1087
+ return true;
1088
+ }
1089
+ /**
1090
+ * Recursively delete a directory
1091
+ */
1092
+ function removeDirectoryRecursive(dirPath) {
1093
+ if (!fs.existsSync(dirPath))
1094
+ return;
1095
+ fs.rmSync(dirPath, { recursive: true, force: true });
1096
+ }
1097
+ /**
1098
+ * Check if a file is safe to overwrite (matches template content)
1099
+ */
1100
+ function isFileSafeToReplace(cwd, relativePath, templates) {
1101
+ const fullPath = path.join(cwd, relativePath);
1102
+ if (!fs.existsSync(fullPath))
1103
+ return true;
1104
+ const templateContent = templates.get(relativePath);
1105
+ if (!templateContent)
1106
+ return false; // Not a template file
1107
+ const currentContent = fs.readFileSync(fullPath, "utf-8");
1108
+ return currentContent === templateContent;
1109
+ }
1110
+ /**
1111
+ * Classify migrations based on file state and user modifications
1112
+ */
1113
+ /**
1114
+ * Whether the manifest records any file under `dirRelativePath` — i.e. whether
1115
+ * Trellis actually created this directory. Used to gate rename-dir migrations:
1116
+ * a directory Trellis never wrote (e.g. a user's own `.windsurf/` editor
1117
+ * config that merely shares a path with a retired Trellis platform dir) must
1118
+ * not be auto-moved.
1119
+ */
1120
+ export function dirHasManifestEntries(dirRelativePath, hashes) {
1121
+ const prefix = dirRelativePath.endsWith("/")
1122
+ ? dirRelativePath
1123
+ : dirRelativePath + "/";
1124
+ return Object.keys(hashes).some((key) => key === dirRelativePath || key.startsWith(prefix));
1125
+ }
1126
+ export function classifyMigrations(migrations, cwd, hashes, templates) {
1127
+ const result = {
1128
+ auto: [],
1129
+ confirm: [],
1130
+ conflict: [],
1131
+ skip: [],
1132
+ };
1133
+ for (const item of migrations) {
1134
+ // safe-file-delete handled separately (not via --migrate)
1135
+ if (item.type === "safe-file-delete")
1136
+ continue;
1137
+ // Enforce PROTECTED_PATHS — never migrate FROM protected paths (prevents moving/deleting user data)
1138
+ if (isProtectedPath(item.from)) {
1139
+ result.skip.push(item);
1140
+ continue;
1141
+ }
1142
+ // For non-rename types, also block writing TO protected paths
1143
+ // rename/rename-dir are allowed to target protected paths (e.g., 0.2.0 renames into .trellis/workspace)
1144
+ if (item.to &&
1145
+ isProtectedPath(item.to) &&
1146
+ item.type !== "rename" &&
1147
+ item.type !== "rename-dir") {
1148
+ result.skip.push(item);
1149
+ continue;
1150
+ }
1151
+ const oldPath = path.join(cwd, item.from);
1152
+ const oldExists = fs.existsSync(oldPath);
1153
+ if (!oldExists) {
1154
+ // Old file doesn't exist, nothing to migrate
1155
+ result.skip.push(item);
1156
+ continue;
1157
+ }
1158
+ if (item.type === "rename" && item.to) {
1159
+ const newPath = path.join(cwd, item.to);
1160
+ const newExists = fs.existsSync(newPath);
1161
+ if (newExists) {
1162
+ // Both exist - check if new file matches template (safe to overwrite)
1163
+ if (isFileSafeToReplace(cwd, item.to, templates)) {
1164
+ // New file is just template content - safe to delete and rename
1165
+ result.auto.push(item);
1166
+ }
1167
+ else {
1168
+ // New file has user content - conflict
1169
+ result.conflict.push(item);
1170
+ }
1171
+ }
1172
+ else if (isTemplateModified(cwd, item.from, hashes)) {
1173
+ // User has modified the file - needs confirmation
1174
+ result.confirm.push(item);
1175
+ }
1176
+ else {
1177
+ // Unmodified template - safe to auto-migrate
1178
+ result.auto.push(item);
1179
+ }
1180
+ }
1181
+ else if (item.type === "rename-dir" && item.to) {
1182
+ const newPath = path.join(cwd, item.to);
1183
+ const newExists = fs.existsSync(newPath);
1184
+ if (newExists) {
1185
+ // Target exists - check if it only contains unmodified template files
1186
+ if (isDirectorySafeToReplace(cwd, item.to, hashes, templates)) {
1187
+ // Safe to delete target and rename source
1188
+ result.auto.push(item);
1189
+ }
1190
+ else {
1191
+ // Target has user modifications - conflict
1192
+ result.conflict.push(item);
1193
+ }
1194
+ }
1195
+ else if (dirHasManifestEntries(item.from, hashes)) {
1196
+ // Trellis created this directory (the manifest tracks files under it),
1197
+ // so the rename is ours to make.
1198
+ result.auto.push(item);
1199
+ }
1200
+ else {
1201
+ // Target absent and the source has no manifest record: this is very
1202
+ // likely a user-owned directory that merely shares a path with a
1203
+ // retired Trellis platform dir (e.g. a real `.windsurf/` editor
1204
+ // config). Skipping avoids silently moving the user's data out from
1205
+ // under their editor — even under --force, since skip never executes.
1206
+ result.skip.push(item);
1207
+ }
1208
+ }
1209
+ else if (item.type === "delete") {
1210
+ if (isTemplateModified(cwd, item.from, hashes)) {
1211
+ // User has modified - needs confirmation before delete
1212
+ result.confirm.push(item);
1213
+ }
1214
+ else {
1215
+ // Unmodified - safe to auto-delete
1216
+ result.auto.push(item);
1217
+ }
1218
+ }
1219
+ }
1220
+ return result;
1221
+ }
1222
+ /**
1223
+ * Print migration summary
1224
+ */
1225
+ function printMigrationSummary(classified) {
1226
+ const total = classified.auto.length +
1227
+ classified.confirm.length +
1228
+ classified.conflict.length +
1229
+ classified.skip.length;
1230
+ if (total === 0) {
1231
+ console.log(chalk.gray(" No migrations to apply.\n"));
1232
+ return;
1233
+ }
1234
+ if (classified.auto.length > 0) {
1235
+ console.log(chalk.green(" āœ“ Auto-migrate (unmodified):"));
1236
+ for (const item of classified.auto) {
1237
+ if (item.type === "rename") {
1238
+ console.log(chalk.green(` ${item.from} → ${item.to}`));
1239
+ }
1240
+ else if (item.type === "rename-dir") {
1241
+ console.log(chalk.green(` [dir] ${item.from}/ → ${item.to}/`));
1242
+ }
1243
+ else {
1244
+ console.log(chalk.green(` āœ• ${item.from}`));
1245
+ }
1246
+ }
1247
+ console.log("");
1248
+ }
1249
+ if (classified.confirm.length > 0) {
1250
+ console.log(chalk.yellow(" ⚠ Requires confirmation (modified by user):"));
1251
+ for (const item of classified.confirm) {
1252
+ if (item.type === "rename") {
1253
+ console.log(chalk.yellow(` ${item.from} → ${item.to}`));
1254
+ }
1255
+ else {
1256
+ console.log(chalk.yellow(` āœ• ${item.from}`));
1257
+ }
1258
+ }
1259
+ console.log("");
1260
+ }
1261
+ if (classified.conflict.length > 0) {
1262
+ console.log(chalk.red(" ⊘ Conflict (both old and new exist):"));
1263
+ for (const item of classified.conflict) {
1264
+ if (item.type === "rename-dir") {
1265
+ console.log(chalk.red(` [dir] ${item.from}/ ↔ ${item.to}/`));
1266
+ }
1267
+ else {
1268
+ console.log(chalk.red(` ${item.from} ↔ ${item.to}`));
1269
+ }
1270
+ }
1271
+ console.log(chalk.gray(" → Resolve manually: merge or delete one, then re-run update"));
1272
+ console.log("");
1273
+ }
1274
+ if (classified.skip.length > 0) {
1275
+ console.log(chalk.gray(" ā—‹ Skipping (not found, protected, or not Trellis-owned):"));
1276
+ for (const item of classified.skip.slice(0, 3)) {
1277
+ console.log(chalk.gray(` ${item.from}`));
1278
+ }
1279
+ if (classified.skip.length > 3) {
1280
+ console.log(chalk.gray(` ... and ${classified.skip.length - 3} more`));
1281
+ }
1282
+ console.log("");
1283
+ }
1284
+ }
1285
+ /**
1286
+ * Prompt user for migration action on a single item.
1287
+ *
1288
+ * Design notes:
1289
+ * - Default is `backup-rename`: safest — preserves user's content as a .backup
1290
+ * alongside the rename, so Enter-to-continue never destroys work or leaves
1291
+ * stale paths behind.
1292
+ * - "Skip" leaves a stale old path that won't be cleaned by later updates —
1293
+ * warn explicitly so users understand the consequence.
1294
+ * - Show manifest description + why-flagged so users can make an informed
1295
+ * choice without needing to dig through the diff.
1296
+ */
1297
+ async function promptMigrationAction(item) {
1298
+ const headline = item.type === "rename"
1299
+ ? `${chalk.cyan(item.from)} → ${chalk.green(item.to)}`
1300
+ : `${chalk.red("Delete")} ${chalk.cyan(item.from)}`;
1301
+ const description = item.description ?? "No description provided in manifest.";
1302
+ // Actions with inline guidance so users see the trade-off per choice.
1303
+ const renameLabel = item.type === "rename"
1304
+ ? "[r] Rename anyway — use if the file is unchanged, or any edits are fine to move as-is"
1305
+ : "[d] Delete anyway — use if you don't need this file (already migrated to replacement)";
1306
+ const backupLabel = item.type === "rename"
1307
+ ? "[b] Backup original, then proceed — SAFEST: writes <new-path>.backup with your current content, then renames"
1308
+ : "[b] Backup original, then proceed — SAFEST: writes <path>.backup with your current content, then deletes";
1309
+ const skipLabel = item.type === "rename"
1310
+ ? "[s] Skip — leaves the old path in place (you'll see it flagged on future updates until cleaned up manually)"
1311
+ : "[s] Skip — keeps the deprecated file (you'll see it flagged on future updates until cleaned up manually)";
1312
+ // Prefer the per-migration `reason` (version-specific context authored in the
1313
+ // manifest) over a generic fallback. Hardcoding version-specific hints here
1314
+ // rots fast — every release gets a new set of edge cases.
1315
+ const whyFlagged = item.reason
1316
+ ? chalk.gray(item.reason
1317
+ .split("\n")
1318
+ .map((line) => ` ${line}`)
1319
+ .join("\n"))
1320
+ : chalk.gray(` Why prompted: file content doesn't match the Trellis template hash\n` +
1321
+ ` for this path — usually local customization. If unsure, pick [b].`);
1322
+ const message = [
1323
+ headline,
1324
+ "",
1325
+ chalk.bold(" What:") + " " + description,
1326
+ whyFlagged,
1327
+ "",
1328
+ chalk.bold(" Choose:"),
1329
+ ].join("\n");
1330
+ const { choice } = await inquirer.prompt([
1331
+ {
1332
+ type: "list",
1333
+ name: "choice",
1334
+ message,
1335
+ choices: [
1336
+ { name: backupLabel, value: "backup-rename" },
1337
+ { name: renameLabel, value: "rename" },
1338
+ { name: skipLabel, value: "skip" },
1339
+ ],
1340
+ default: "backup-rename",
1341
+ },
1342
+ ]);
1343
+ return choice;
1344
+ }
1345
+ /**
1346
+ * Sort migrations for safe execution order
1347
+ * - rename-dir with deeper paths first (to handle nested directories)
1348
+ * - rename-dir before rename/delete
1349
+ */
1350
+ /** @internal Exported for testing only */
1351
+ export function sortMigrationsForExecution(migrations) {
1352
+ return [...migrations].sort((a, b) => {
1353
+ // rename-dir should be sorted by path depth (deeper first)
1354
+ if (a.type === "rename-dir" && b.type === "rename-dir") {
1355
+ const aDepth = a.from.split("/").length;
1356
+ const bDepth = b.from.split("/").length;
1357
+ return bDepth - aDepth; // Deeper paths first
1358
+ }
1359
+ // rename-dir before rename/delete (directories first)
1360
+ if (a.type === "rename-dir" && b.type !== "rename-dir")
1361
+ return -1;
1362
+ if (a.type !== "rename-dir" && b.type === "rename-dir")
1363
+ return 1;
1364
+ return 0;
1365
+ });
1366
+ }
1367
+ /**
1368
+ * Execute classified migrations
1369
+ *
1370
+ * @param options.force - Force migrate modified files without asking
1371
+ * @param options.skipAll - Skip all modified files without asking
1372
+ * If neither is set, prompts interactively for modified files
1373
+ */
1374
+ export async function executeMigrations(classified, cwd, options, templates) {
1375
+ const result = {
1376
+ renamed: 0,
1377
+ deleted: 0,
1378
+ skipped: 0,
1379
+ conflicts: classified.conflict.length,
1380
+ };
1381
+ // Sort migrations for safe execution order
1382
+ const sortedAuto = sortMigrationsForExecution(classified.auto);
1383
+ // 1. Execute auto migrations (unmodified files and directories)
1384
+ for (const item of sortedAuto) {
1385
+ if (item.type === "rename" && item.to) {
1386
+ const oldPath = path.join(cwd, item.from);
1387
+ const newPath = path.join(cwd, item.to);
1388
+ // Ensure target directory exists
1389
+ fs.mkdirSync(path.dirname(newPath), { recursive: true });
1390
+ fs.renameSync(oldPath, newPath);
1391
+ // Update hash tracking
1392
+ renameHash(cwd, item.from, item.to);
1393
+ // Make executable if it's a script
1394
+ if (item.to.endsWith(".sh") || item.to.endsWith(".py")) {
1395
+ fs.chmodSync(newPath, "755");
1396
+ }
1397
+ // Clean up empty source directory
1398
+ cleanupEmptyDirs(cwd, path.dirname(item.from));
1399
+ result.renamed++;
1400
+ }
1401
+ else if (item.type === "rename-dir" && item.to) {
1402
+ const oldPath = path.join(cwd, item.from);
1403
+ const newPath = path.join(cwd, item.to);
1404
+ const oldPrefix = item.from.endsWith("/") ? item.from : item.from + "/";
1405
+ const newPrefix = item.to.endsWith("/") ? item.to : item.to + "/";
1406
+ // Target already exists and already holds canonical, current-version
1407
+ // content (e.g. Codex/Gemini already wrote the shared `.agents/skills/`
1408
+ // root before Pi's legacy `.pi/skills/` copy gets retired). Renaming
1409
+ // the source in would clobber good content with older/differently-
1410
+ // flavored bytes, so just drop the now-redundant source instead (#447).
1411
+ if (fs.existsSync(newPath) &&
1412
+ dirMatchesCurrentTemplates(cwd, item.to, templates)) {
1413
+ removeDirectoryRecursive(oldPath);
1414
+ const hashes = loadHashes(cwd);
1415
+ const updatedHashes = {};
1416
+ for (const [hashPath, hashValue] of Object.entries(hashes)) {
1417
+ if (hashPath.startsWith(oldPrefix))
1418
+ continue; // source retired
1419
+ updatedHashes[hashPath] = hashValue;
1420
+ }
1421
+ saveHashes(cwd, updatedHashes);
1422
+ result.deleted++;
1423
+ continue;
1424
+ }
1425
+ // If target exists (safe to replace, already checked in classification)
1426
+ // delete it first before renaming
1427
+ if (fs.existsSync(newPath)) {
1428
+ removeDirectoryRecursive(newPath);
1429
+ }
1430
+ // Ensure parent directory exists
1431
+ fs.mkdirSync(path.dirname(newPath), { recursive: true });
1432
+ // Rename the entire directory (includes all user files)
1433
+ fs.renameSync(oldPath, newPath);
1434
+ // Batch update hash tracking for all files in the directory
1435
+ const hashes = loadHashes(cwd);
1436
+ const updatedHashes = {};
1437
+ for (const [hashPath, hashValue] of Object.entries(hashes)) {
1438
+ if (hashPath.startsWith(oldPrefix)) {
1439
+ // Rename path: old prefix -> new prefix
1440
+ const newHashPath = newPrefix + hashPath.slice(oldPrefix.length);
1441
+ updatedHashes[newHashPath] = hashValue;
1442
+ }
1443
+ else if (hashPath.startsWith(newPrefix)) {
1444
+ // Skip old hashes from deleted target directory
1445
+ // (they will be replaced by renamed source files)
1446
+ continue;
1447
+ }
1448
+ else {
1449
+ // Keep unchanged
1450
+ updatedHashes[hashPath] = hashValue;
1451
+ }
1452
+ }
1453
+ saveHashes(cwd, updatedHashes);
1454
+ result.renamed++;
1455
+ }
1456
+ else if (item.type === "delete") {
1457
+ const filePath = path.join(cwd, item.from);
1458
+ fs.unlinkSync(filePath);
1459
+ // Remove from hash tracking
1460
+ removeHash(cwd, item.from);
1461
+ // Clean up empty directory
1462
+ cleanupEmptyDirs(cwd, path.dirname(item.from));
1463
+ result.deleted++;
1464
+ }
1465
+ }
1466
+ // 2. Handle confirm items (modified files)
1467
+ // Note: All files are already backed up by createMigrationBackup before execution
1468
+ for (const item of classified.confirm) {
1469
+ let action;
1470
+ if (options.force) {
1471
+ // Force mode: proceed (already backed up)
1472
+ action = "rename";
1473
+ }
1474
+ else if (options.skipAll) {
1475
+ // Skip mode: skip all modified files
1476
+ action = "skip";
1477
+ }
1478
+ else {
1479
+ // Default: interactive prompt
1480
+ action = await promptMigrationAction(item);
1481
+ }
1482
+ if (action === "skip") {
1483
+ result.skipped++;
1484
+ continue;
1485
+ }
1486
+ // For `backup-rename`, leave an inline .backup copy of the user's modified
1487
+ // original next to the new location (for rename) or in place (for delete).
1488
+ // This is in addition to the full project snapshot at .trellis/.backup-*/;
1489
+ // the inline copy is more discoverable when the user wants to diff or merge
1490
+ // their customizations against the new template.
1491
+ if (item.type === "rename" && item.to) {
1492
+ const oldPath = path.join(cwd, item.from);
1493
+ const newPath = path.join(cwd, item.to);
1494
+ fs.mkdirSync(path.dirname(newPath), { recursive: true });
1495
+ if (action === "backup-rename") {
1496
+ // Copy original alongside the new path before the rename overwrites nothing
1497
+ // (target dir is guaranteed fresh since `conflict` is handled elsewhere).
1498
+ fs.copyFileSync(oldPath, newPath + ".backup");
1499
+ }
1500
+ fs.renameSync(oldPath, newPath);
1501
+ renameHash(cwd, item.from, item.to);
1502
+ if (item.to.endsWith(".sh") || item.to.endsWith(".py")) {
1503
+ fs.chmodSync(newPath, "755");
1504
+ }
1505
+ // Clean up empty source directory
1506
+ cleanupEmptyDirs(cwd, path.dirname(item.from));
1507
+ result.renamed++;
1508
+ }
1509
+ else if (item.type === "delete") {
1510
+ const filePath = path.join(cwd, item.from);
1511
+ if (action === "backup-rename") {
1512
+ // Keep a .backup copy in place before deletion so the user can recover
1513
+ // inline without digging through .trellis/.backup-*/.
1514
+ fs.copyFileSync(filePath, filePath + ".backup");
1515
+ }
1516
+ fs.unlinkSync(filePath);
1517
+ removeHash(cwd, item.from);
1518
+ // Clean up empty directory
1519
+ cleanupEmptyDirs(cwd, path.dirname(item.from));
1520
+ result.deleted++;
1521
+ }
1522
+ }
1523
+ // 3. Skip count already tracked (old files not found)
1524
+ result.skipped += classified.skip.length;
1525
+ return result;
1526
+ }
1527
+ /**
1528
+ * Print migration result summary
1529
+ */
1530
+ function printMigrationResult(result) {
1531
+ const parts = [];
1532
+ if (result.renamed > 0) {
1533
+ parts.push(`${result.renamed} renamed`);
1534
+ }
1535
+ if (result.deleted > 0) {
1536
+ parts.push(`${result.deleted} deleted`);
1537
+ }
1538
+ if (result.skipped > 0) {
1539
+ parts.push(`${result.skipped} skipped`);
1540
+ }
1541
+ if (result.conflicts > 0) {
1542
+ parts.push(`${result.conflicts} conflict${result.conflicts > 1 ? "s" : ""}`);
1543
+ }
1544
+ if (parts.length > 0) {
1545
+ console.log(chalk.cyan(`Migration complete: ${parts.join(", ")}`));
1546
+ }
1547
+ }
1548
+ /**
1549
+ * One-time 0.2.0 migration: rename `traces-*.md` → `journal-*.md` in every
1550
+ * developer workspace directory.
1551
+ *
1552
+ * Never overwrites an existing `journal-N.md`: a newer session may already
1553
+ * have created it, and `.trellis/workspace/` is excluded from the update
1554
+ * backup (see `BACKUP_EXCLUDE_PATTERNS`), so clobbering it would be
1555
+ * unrecoverable data loss. Conflicting `traces-N.md` files are left in place
1556
+ * and reported instead.
1557
+ */
1558
+ export function renameTracesToJournal(workspaceDir) {
1559
+ const skipped = [];
1560
+ let renamed = 0;
1561
+ if (!fs.existsSync(workspaceDir))
1562
+ return { renamed, skipped };
1563
+ for (const dev of fs.readdirSync(workspaceDir)) {
1564
+ const devPath = path.join(workspaceDir, dev);
1565
+ if (!fs.statSync(devPath).isDirectory())
1566
+ continue;
1567
+ for (const file of fs.readdirSync(devPath)) {
1568
+ if (!(file.startsWith("traces-") && file.endsWith(".md")))
1569
+ continue;
1570
+ const oldPath = path.join(devPath, file);
1571
+ const newPath = path.join(devPath, file.replace("traces-", "journal-"));
1572
+ if (fs.existsSync(newPath)) {
1573
+ skipped.push(oldPath);
1574
+ continue;
1575
+ }
1576
+ fs.renameSync(oldPath, newPath);
1577
+ renamed++;
1578
+ }
1579
+ }
1580
+ return { renamed, skipped };
1581
+ }
1582
+ /**
1583
+ * Main update command
1584
+ */
1585
+ export async function update(options) {
1586
+ const cwd = process.cwd();
1587
+ // Check if Trellis is initialized
1588
+ if (!fs.existsSync(path.join(cwd, DIR_NAMES.WORKFLOW))) {
1589
+ console.log(chalk.red("Error: Trellis not initialized in this directory."));
1590
+ console.log(chalk.gray("Run 'trellis init' first."));
1591
+ return;
1592
+ }
1593
+ console.log(chalk.cyan("\nTrellis Update"));
1594
+ console.log(chalk.cyan("══════════════\n"));
1595
+ // Set up proxy before any network calls (npm version check)
1596
+ setupProxy();
1597
+ // Get versions
1598
+ const projectVersion = getInstalledVersion(cwd);
1599
+ const cliVersion = VERSION;
1600
+ const latestNpmVersion = await getLatestNpmVersion();
1601
+ // Version comparison
1602
+ const cliVsProject = compareVersions(cliVersion, projectVersion);
1603
+ const cliVsNpm = latestNpmVersion
1604
+ ? compareVersions(cliVersion, latestNpmVersion)
1605
+ : 0;
1606
+ // Display versions with context
1607
+ console.log(`Project version: ${chalk.white(projectVersion)}`);
1608
+ console.log(`CLI version: ${chalk.white(cliVersion)}`);
1609
+ if (latestNpmVersion) {
1610
+ console.log(`Latest on npm: ${chalk.white(latestNpmVersion)}`);
1611
+ }
1612
+ else {
1613
+ console.log(chalk.gray("Latest on npm: (unable to fetch)"));
1614
+ }
1615
+ console.log("");
1616
+ // Check if CLI is outdated compared to npm
1617
+ if (cliVsNpm < 0 && latestNpmVersion) {
1618
+ console.log(chalk.yellow(`āš ļø Your CLI (${cliVersion}) is behind npm (${latestNpmVersion}).`));
1619
+ console.log(chalk.yellow(` Run: trellis upgrade\n`));
1620
+ }
1621
+ // Check for downgrade situation
1622
+ if (cliVsProject < 0) {
1623
+ console.log(chalk.red(`āŒ Cannot update: CLI version (${cliVersion}) < project version (${projectVersion})`));
1624
+ console.log(chalk.red(` This would DOWNGRADE your project!\n`));
1625
+ if (!options.allowDowngrade) {
1626
+ console.log(chalk.gray("Solutions:"));
1627
+ console.log(chalk.gray(` 1. Update your CLI: trellis upgrade`));
1628
+ console.log(chalk.gray(` 2. Force downgrade: trellis update --allow-downgrade\n`));
1629
+ return;
1630
+ }
1631
+ console.log(chalk.yellow("āš ļø --allow-downgrade flag set. Proceeding with downgrade...\n"));
1632
+ }
1633
+ // Migration metadata is displayed at the end to prevent scrolling off screen
1634
+ // Load template hashes for modification detection
1635
+ let hashes = loadHashes(cwd);
1636
+ const zcodeConfigured = getConfiguredPlatforms(cwd).has("zcode");
1637
+ const isFirstHashTracking = Object.keys(hashes).length === 0;
1638
+ // Handle unknown version - skip regular migrations but safe-file-delete still runs
1639
+ const isUnknownVersion = projectVersion === "unknown";
1640
+ if (isUnknownVersion) {
1641
+ console.log(chalk.yellow("āš ļø No version file found. Skipping migrations — run trellis init to fix."));
1642
+ console.log(chalk.gray(" Template updates will still be applied."));
1643
+ console.log(chalk.gray(" Safe file cleanup will still run (hash-verified).\n"));
1644
+ }
1645
+ // Detect legacy Codex (has .agents/skills/ tracked by Trellis but no .codex/)
1646
+ // NOTE: this MUST happen before pruneOrphanManifestKeys below, since the
1647
+ // detector reads the raw manifest looking for .agents/skills/ markers that
1648
+ // the prune step would otherwise consider orphans (codex hasn't been added
1649
+ // to configuredPlatforms yet at this point).
1650
+ const codexUpgradeNeeded = needsCodexUpgrade(cwd);
1651
+ if (codexUpgradeNeeded) {
1652
+ console.log(chalk.yellow(" Legacy Codex detected: .agents/skills/ tracked without .codex/ — will create .codex/ directory"));
1653
+ }
1654
+ // Self-heal poisoned manifests: prune entries that no current platform
1655
+ // configurator owns. This silently removes user-owned paths that early
1656
+ // buggy versions of `trellis init` over-hashed (e.g. .codex/sessions/*).
1657
+ // Include codex in known-platforms when codexUpgradeNeeded so legacy Codex
1658
+ // markers under .agents/skills/ survive into the upgrade flow.
1659
+ {
1660
+ const configuredPlatforms = new Set(getConfiguredPlatforms(cwd));
1661
+ if (codexUpgradeNeeded)
1662
+ configuredPlatforms.add("codex");
1663
+ const prune = pruneOrphanManifestKeys(cwd, [...configuredPlatforms], hashes);
1664
+ if (prune.pruned.length > 0) {
1665
+ console.log(chalk.gray(` Pruned ${prune.pruned.length} orphan manifest entries from .template-hashes.json`));
1666
+ hashes = prune.hashes;
1667
+ }
1668
+ }
1669
+ // For breaking releases with recommendMigrate + --migrate, bypass update.skip
1670
+ // across the board (safe-file-delete, new file writes, template updates).
1671
+ // Why: honoring skip here leaves users forever half-migrated — old deprecated
1672
+ // files persist under skip-protected paths, new commands like `continue.md`
1673
+ // never land, and every future update re-flags the same mess. Rename
1674
+ // migrations already ignore update.skip; this makes the rest consistent
1675
+ // during a breaking upgrade. User customizations are still guarded by the
1676
+ // per-file conflict prompt ("Modified by you") at write time.
1677
+ const breakingBypass = options.migrate === true &&
1678
+ cliVsProject > 0 &&
1679
+ projectVersion !== "unknown" &&
1680
+ (() => {
1681
+ const md = getMigrationMetadata(projectVersion, cliVersion);
1682
+ return md.breaking && md.recommendMigrate;
1683
+ })();
1684
+ // Collect templates (used for both migration classification and change analysis)
1685
+ const templates = await collectTemplateFiles(cwd, codexUpgradeNeeded ? new Set(["codex"]) : undefined, breakingBypass);
1686
+ // Load update.skip paths (used for both safe-file-delete and template collection)
1687
+ const skipPaths = loadUpdateSkipPaths(cwd);
1688
+ // Collect safe-file-delete items from ALL manifests (hash match is the safety net)
1689
+ // This runs regardless of version — unknown version still gets safe cleanup
1690
+ const allMigrations = getAllMigrations();
1691
+ const safeFileDeletes = collectSafeFileDeletes(allMigrations, cwd, skipPaths, new Set(templates.keys()), breakingBypass);
1692
+ const hasSafeDeletes = safeFileDeletes.filter((c) => c.action === "delete").length > 0;
1693
+ // Check for pending regular migrations (skip if unknown version)
1694
+ let pendingMigrations = isUnknownVersion
1695
+ ? []
1696
+ : getMigrationsForVersion(projectVersion, cliVersion);
1697
+ // Also check for "orphaned" migrations - where source still exists but version says we shouldn't migrate
1698
+ // This handles cases where version was updated but migrations weren't applied
1699
+ const orphanedMigrations = allMigrations.filter((item) => {
1700
+ // Only check rename and rename-dir migrations
1701
+ if (item.type !== "rename" && item.type !== "rename-dir")
1702
+ return false;
1703
+ if (!item.from || !item.to)
1704
+ return false;
1705
+ const oldPath = path.join(cwd, item.from);
1706
+ const newPath = path.join(cwd, item.to);
1707
+ // Orphaned if: source exists AND target doesn't exist
1708
+ // AND this migration isn't already in pendingMigrations
1709
+ const sourceExists = fs.existsSync(oldPath);
1710
+ const targetExists = fs.existsSync(newPath);
1711
+ const alreadyPending = pendingMigrations.some((m) => m.from === item.from && m.to === item.to);
1712
+ return sourceExists && !targetExists && !alreadyPending;
1713
+ });
1714
+ // Add orphaned migrations to pending (they need to be applied)
1715
+ if (orphanedMigrations.length > 0) {
1716
+ console.log(chalk.yellow("āš ļø Detected incomplete migrations from previous updates:"));
1717
+ for (const item of orphanedMigrations) {
1718
+ console.log(chalk.yellow(` ${item.from} → ${item.to}`));
1719
+ }
1720
+ console.log("");
1721
+ pendingMigrations = [...pendingMigrations, ...orphanedMigrations];
1722
+ }
1723
+ const hasMigrations = pendingMigrations.length > 0;
1724
+ // Classify migrations (stored for later backup creation)
1725
+ let classifiedMigrations = null;
1726
+ if (hasMigrations) {
1727
+ console.log(chalk.cyan("Analyzing migrations...\n"));
1728
+ classifiedMigrations = classifyMigrations(pendingMigrations, cwd, hashes, templates);
1729
+ printMigrationSummary(classifiedMigrations);
1730
+ // Hard-stop: pending rename/delete work from a breaking release requires --migrate.
1731
+ // Why: without --migrate, those entries are skipped and update()'s later path silently
1732
+ // bumps the version stamp, leaving old paths orphaned next to new templates. Force
1733
+ // explicit opt-in so the user can't half-migrate by accident.
1734
+ const pendingMigrationCount = classifiedMigrations.auto.length +
1735
+ classifiedMigrations.confirm.length +
1736
+ classifiedMigrations.conflict.length;
1737
+ if (pendingMigrationCount > 0 &&
1738
+ !options.migrate &&
1739
+ !options.dryRun &&
1740
+ cliVsProject > 0 &&
1741
+ projectVersion !== "unknown") {
1742
+ const gateMetadata = getMigrationMetadata(projectVersion, cliVersion);
1743
+ if (gateMetadata.breaking && gateMetadata.recommendMigrate) {
1744
+ console.log(chalk.bgRed.white.bold(" āœ– MIGRATION REQUIRED ") +
1745
+ chalk.red(` Breaking changes between ${projectVersion} → ${cliVersion} require --migrate.`));
1746
+ console.log("");
1747
+ console.log(chalk.yellow(` Run: trellis update --migrate`));
1748
+ console.log("");
1749
+ console.log(chalk.gray(" Without --migrate, renamed/relocated files from breaking releases aren't moved,\n" +
1750
+ " leaving your project with stale paths alongside new templates.\n" +
1751
+ " Use --dry-run to preview what --migrate will do."));
1752
+ process.exit(1);
1753
+ }
1754
+ }
1755
+ // Soft hint: non-breaking migrations or projects that chose not to set recommendMigrate
1756
+ if (!options.migrate) {
1757
+ const autoCount = classifiedMigrations.auto.length;
1758
+ const confirmCount = classifiedMigrations.confirm.length;
1759
+ if (autoCount > 0 || confirmCount > 0) {
1760
+ console.log(chalk.gray(`Tip: Use --migrate to apply migrations (prompts for modified files).`));
1761
+ if (confirmCount > 0) {
1762
+ console.log(chalk.gray(` Use --migrate -f to force all, or --migrate -s to skip modified.\n`));
1763
+ }
1764
+ else {
1765
+ console.log("");
1766
+ }
1767
+ }
1768
+ }
1769
+ }
1770
+ // Print safe-file-delete summary (always shown, runs without --migrate)
1771
+ if (safeFileDeletes.length > 0) {
1772
+ printSafeFileDeleteSummary(safeFileDeletes);
1773
+ }
1774
+ // Analyze changes (pass hashes for modification detection)
1775
+ const changes = analyzeChanges(cwd, hashes, templates);
1776
+ const unchangedFileHashRepairs = collectUnchangedFileHashRepairs(changes, hashes);
1777
+ // Print summary
1778
+ printChangeSummary(changes);
1779
+ // First-time hash tracking hint
1780
+ if (isFirstHashTracking && changes.changedFiles.length > 0) {
1781
+ console.log(chalk.cyan("ā„¹ļø First update with hash tracking enabled."));
1782
+ console.log(chalk.gray(" Changed files shown above may not be actual user modifications."));
1783
+ console.log(chalk.gray(" After this update, hash tracking will accurately detect changes.\n"));
1784
+ }
1785
+ // Ensure project-root .gitattributes carries the journal merge=union rule.
1786
+ // Additive-only (see ensureGitattributes) — runs regardless of whether
1787
+ // other template files changed, so it must sit before the "nothing to do"
1788
+ // early-return below. Never touches disk in --dry-run.
1789
+ if (!options.dryRun) {
1790
+ ensureGitattributes(cwd);
1791
+ }
1792
+ // Check if there's anything to do
1793
+ const isUpgrade = cliVsProject > 0;
1794
+ const isDowngrade = cliVsProject < 0;
1795
+ const isSameVersion = cliVsProject === 0;
1796
+ // Check if we have pending migrations that need to be applied
1797
+ const hasPendingMigrations = options.migrate &&
1798
+ classifiedMigrations &&
1799
+ (classifiedMigrations.auto.length > 0 ||
1800
+ classifiedMigrations.confirm.length > 0);
1801
+ if (changes.newFiles.length === 0 &&
1802
+ changes.autoUpdateFiles.length === 0 &&
1803
+ changes.changedFiles.length === 0 &&
1804
+ !hasPendingMigrations &&
1805
+ !hasSafeDeletes) {
1806
+ // The "already up to date" exit still has to repair the receipt: this is
1807
+ // exactly the clean tree where every file is `unchanged`, so it is the run
1808
+ // where a wrong entry would otherwise be skipped again.
1809
+ if (!options.dryRun && unchangedFileHashRepairs.size > 0) {
1810
+ updateHashes(cwd, unchangedFileHashRepairs);
1811
+ }
1812
+ if (isSameVersion) {
1813
+ console.log(chalk.green("āœ“ Already up to date!"));
1814
+ }
1815
+ else {
1816
+ // Version changed but no file changes needed — still update the version stamp
1817
+ updateVersionFile(cwd);
1818
+ if (isUpgrade) {
1819
+ console.log(chalk.green(`āœ“ No file changes needed for ${projectVersion} → ${cliVersion}`));
1820
+ }
1821
+ else if (isDowngrade) {
1822
+ console.log(chalk.green(`āœ“ No file changes needed for ${projectVersion} → ${cliVersion} (downgrade)`));
1823
+ }
1824
+ }
1825
+ if (zcodeConfigured)
1826
+ printZcodeSetupHint();
1827
+ return;
1828
+ }
1829
+ // Show what this operation will do
1830
+ if (isUpgrade) {
1831
+ console.log(chalk.green(`This will UPGRADE: ${projectVersion} → ${cliVersion}\n`));
1832
+ }
1833
+ else if (isDowngrade) {
1834
+ console.log(chalk.red(`āš ļø This will DOWNGRADE: ${projectVersion} → ${cliVersion}\n`));
1835
+ }
1836
+ // Show breaking change warning before confirm
1837
+ if (cliVsProject > 0 && projectVersion !== "unknown") {
1838
+ const preConfirmMetadata = getMigrationMetadata(projectVersion, cliVersion);
1839
+ if (preConfirmMetadata.breaking) {
1840
+ console.log(chalk.cyan("═".repeat(60)));
1841
+ console.log(chalk.bgRed.white.bold(" āš ļø BREAKING CHANGES ") +
1842
+ chalk.red.bold(" Review the changes above carefully!"));
1843
+ if (preConfirmMetadata.changelog.length > 0) {
1844
+ console.log("");
1845
+ console.log(chalk.white(preConfirmMetadata.changelog[0]));
1846
+ }
1847
+ if (preConfirmMetadata.recommendMigrate && !options.migrate) {
1848
+ console.log("");
1849
+ console.log(chalk.bgGreen.black.bold(" šŸ’” RECOMMENDED ") +
1850
+ chalk.green.bold(" Run with --migrate to complete the migration"));
1851
+ }
1852
+ // Notice when update.skip is bypassed so user isn't surprised when
1853
+ // skipPaths-protected files get cleaned up during this breaking upgrade.
1854
+ if (breakingBypass && skipPaths.length > 0) {
1855
+ const willBypass = safeFileDeletes.filter((c) => c.action === "delete" &&
1856
+ skipPaths.some((skip) => c.item.from === skip ||
1857
+ c.item.from.startsWith(skip.endsWith("/") ? skip : skip + "/")));
1858
+ if (willBypass.length > 0) {
1859
+ console.log("");
1860
+ console.log(chalk.bgYellow.black.bold(" ⚠ update.skip BYPASSED ") +
1861
+ chalk.yellow.bold(` Breaking release — ${willBypass.length.toString()} file(s) under your update.skip paths will be cleaned up.`));
1862
+ console.log(chalk.gray(" Hash-verified: only files matching known Trellis templates are deleted. Your local customizations (hash mismatch) are still preserved."));
1863
+ }
1864
+ }
1865
+ console.log(chalk.cyan("═".repeat(60)));
1866
+ console.log("");
1867
+ }
1868
+ }
1869
+ // Dry run mode
1870
+ if (options.dryRun) {
1871
+ console.log(chalk.gray("[Dry run] No changes made."));
1872
+ return;
1873
+ }
1874
+ // Batch-resolution flags are explicit consent for non-interactive runs.
1875
+ // Prompting here breaks CI and `node ... update --force --migrate` smoke tests.
1876
+ if (!options.force && !options.skipAll && !options.createNew) {
1877
+ const { proceed } = await inquirer.prompt([
1878
+ {
1879
+ type: "confirm",
1880
+ name: "proceed",
1881
+ message: "Proceed?",
1882
+ default: true,
1883
+ },
1884
+ ]);
1885
+ if (!proceed) {
1886
+ console.log(chalk.yellow("Update cancelled."));
1887
+ return;
1888
+ }
1889
+ }
1890
+ // Create complete backup of all managed platform/workflow directories
1891
+ const backupDir = createFullBackup(cwd);
1892
+ if (backupDir) {
1893
+ console.log(chalk.gray(`\nBackup created: ${path.relative(cwd, backupDir)}/`));
1894
+ }
1895
+ // Execute migrations if --migrate flag is set
1896
+ if (options.migrate && classifiedMigrations) {
1897
+ const migrationResult = await executeMigrations(classifiedMigrations, cwd, {
1898
+ force: options.force,
1899
+ skipAll: options.skipAll,
1900
+ }, templates);
1901
+ printMigrationResult(migrationResult);
1902
+ // Hardcoded: Rename traces-*.md to journal-*.md in workspace directories
1903
+ // Why hardcoded: The migration system only supports fixed path renames, not pattern-based.
1904
+ // traces-*.md files are in .trellis/workspace/{developer}/ with variable developer names
1905
+ // and variable file numbers (traces-1.md, traces-2.md, etc.), so we can't enumerate them
1906
+ // in the migration manifest. This is a one-time migration for the 0.2.0 naming redesign.
1907
+ const workspaceDir = path.join(cwd, PATHS.WORKSPACE);
1908
+ const { renamed: journalRenamed, skipped: journalSkipped } = renameTracesToJournal(workspaceDir);
1909
+ if (journalRenamed > 0) {
1910
+ console.log(chalk.cyan(`Renamed ${journalRenamed} traces file(s) to journal`));
1911
+ }
1912
+ for (const oldPath of journalSkipped) {
1913
+ console.warn(chalk.yellow(`Kept ${path.relative(cwd, oldPath)}: its journal target already exists`));
1914
+ }
1915
+ }
1916
+ // Execute safe-file-delete (after backup, before template writes)
1917
+ let safeDeleted = 0;
1918
+ if (hasSafeDeletes) {
1919
+ safeDeleted = executeSafeFileDeletes(safeFileDeletes, cwd);
1920
+ if (safeDeleted > 0) {
1921
+ console.log(chalk.cyan(`\nCleaned up ${safeDeleted} deprecated command file(s)`));
1922
+ }
1923
+ }
1924
+ // Track results
1925
+ let added = 0;
1926
+ let autoUpdated = 0;
1927
+ let updated = 0;
1928
+ let skipped = 0;
1929
+ let createdNew = 0;
1930
+ // Add new files
1931
+ if (changes.newFiles.length > 0) {
1932
+ console.log(chalk.blue("\nAdding new files..."));
1933
+ for (const file of changes.newFiles) {
1934
+ const dir = path.dirname(file.path);
1935
+ fs.mkdirSync(dir, { recursive: true });
1936
+ fs.writeFileSync(file.path, file.newContent);
1937
+ // Make scripts executable
1938
+ if (file.relativePath.endsWith(".sh") ||
1939
+ file.relativePath.endsWith(".py")) {
1940
+ fs.chmodSync(file.path, "755");
1941
+ }
1942
+ console.log(chalk.green(` + ${file.relativePath}`));
1943
+ added++;
1944
+ }
1945
+ }
1946
+ // Auto-update files (template updated, user didn't modify)
1947
+ if (changes.autoUpdateFiles.length > 0) {
1948
+ console.log(chalk.blue("\nAuto-updating template files..."));
1949
+ for (const file of changes.autoUpdateFiles) {
1950
+ fs.writeFileSync(file.path, file.newContent);
1951
+ // Make scripts executable
1952
+ if (file.relativePath.endsWith(".sh") ||
1953
+ file.relativePath.endsWith(".py")) {
1954
+ fs.chmodSync(file.path, "755");
1955
+ }
1956
+ console.log(chalk.cyan(` ↑ ${file.relativePath}`));
1957
+ autoUpdated++;
1958
+ }
1959
+ }
1960
+ // Handle changed files
1961
+ if (changes.changedFiles.length > 0) {
1962
+ console.log(chalk.blue("\n--- Resolving conflicts ---\n"));
1963
+ const applyToAll = { action: null };
1964
+ for (const file of changes.changedFiles) {
1965
+ const action = await promptConflictResolution(file, options, applyToAll);
1966
+ if (action === "overwrite") {
1967
+ fs.writeFileSync(file.path, file.newContent);
1968
+ if (file.relativePath.endsWith(".sh") ||
1969
+ file.relativePath.endsWith(".py")) {
1970
+ fs.chmodSync(file.path, "755");
1971
+ }
1972
+ console.log(chalk.yellow(` āœ“ Overwritten: ${file.relativePath}`));
1973
+ updated++;
1974
+ }
1975
+ else if (action === "create-new") {
1976
+ const newPath = file.path + ".new";
1977
+ fs.writeFileSync(newPath, file.newContent);
1978
+ console.log(chalk.blue(` āœ“ Created: ${file.relativePath}.new`));
1979
+ createdNew++;
1980
+ }
1981
+ else {
1982
+ console.log(chalk.gray(` ā—‹ Skipped: ${file.relativePath}`));
1983
+ skipped++;
1984
+ }
1985
+ }
1986
+ }
1987
+ // Append additive config.yaml sections introduced between versions.
1988
+ // Sentinel-gated, so users keep their customizations and re-running update
1989
+ // on already-migrated files is a no-op. Skipped on unknown / downgrade.
1990
+ let configSectionsAppended = 0;
1991
+ if (cliVsProject > 0 && projectVersion !== "unknown") {
1992
+ const sectionEntries = getConfigSectionsAddedBetween(projectVersion, cliVersion);
1993
+ if (sectionEntries.length > 0) {
1994
+ const { appended } = applyConfigSectionsAdded(sectionEntries, cwd, templates);
1995
+ configSectionsAppended = appended;
1996
+ }
1997
+ }
1998
+ // Update version file
1999
+ updateVersionFile(cwd);
2000
+ // Update template hashes for new, auto-updated, and overwritten files
2001
+ const filesToHash = new Map(unchangedFileHashRepairs);
2002
+ for (const file of changes.newFiles) {
2003
+ filesToHash.set(file.relativePath, file.newContent);
2004
+ }
2005
+ // Auto-updated files always get new hash
2006
+ for (const file of changes.autoUpdateFiles) {
2007
+ filesToHash.set(file.relativePath, file.newContent);
2008
+ }
2009
+ // Only hash overwritten files (not skipped or .new copies)
2010
+ for (const file of changes.changedFiles) {
2011
+ const fullPath = path.join(cwd, file.relativePath);
2012
+ if (fs.existsSync(fullPath)) {
2013
+ const content = fs.readFileSync(fullPath, "utf-8");
2014
+ if (content === file.newContent) {
2015
+ filesToHash.set(file.relativePath, file.newContent);
2016
+ }
2017
+ }
2018
+ }
2019
+ if (filesToHash.size > 0) {
2020
+ updateHashes(cwd, filesToHash);
2021
+ }
2022
+ // Print summary
2023
+ console.log(chalk.cyan("\n--- Summary ---\n"));
2024
+ if (added > 0) {
2025
+ console.log(` Added: ${added} file(s)`);
2026
+ }
2027
+ if (autoUpdated > 0) {
2028
+ console.log(` Auto-updated: ${autoUpdated} file(s)`);
2029
+ }
2030
+ if (updated > 0) {
2031
+ console.log(` Updated: ${updated} file(s)`);
2032
+ }
2033
+ if (skipped > 0) {
2034
+ console.log(` Skipped: ${skipped} file(s)`);
2035
+ }
2036
+ if (createdNew > 0) {
2037
+ console.log(` Created .new copies: ${createdNew} file(s)`);
2038
+ }
2039
+ if (safeDeleted > 0) {
2040
+ console.log(` Cleaned up: ${safeDeleted} deprecated file(s)`);
2041
+ }
2042
+ if (configSectionsAppended > 0) {
2043
+ console.log(` Config sections added: ${configSectionsAppended}`);
2044
+ }
2045
+ if (backupDir) {
2046
+ console.log(` Backup: ${path.relative(cwd, backupDir)}/`);
2047
+ }
2048
+ const actionWord = isDowngrade ? "Downgrade" : "Update";
2049
+ console.log(chalk.green(`\nāœ… ${actionWord} complete! (${projectVersion} → ${cliVersion})`));
2050
+ if (createdNew > 0) {
2051
+ console.log(chalk.gray("\nTip: Review .new files and merge changes manually if needed."));
2052
+ }
2053
+ // Create migration task if there are breaking changes with migration guides
2054
+ if (cliVsProject > 0 && projectVersion !== "unknown") {
2055
+ const metadata = getMigrationMetadata(projectVersion, cliVersion);
2056
+ if (metadata.breaking && metadata.migrationGuides.length > 0) {
2057
+ // Create task directory
2058
+ const today = new Date();
2059
+ const monthDay = `${String(today.getMonth() + 1).padStart(2, "0")}-${String(today.getDate()).padStart(2, "0")}`;
2060
+ const taskSlug = `migrate-to-${cliVersion}`;
2061
+ const taskDirName = `${monthDay}-${taskSlug}`;
2062
+ const tasksDir = path.join(cwd, DIR_NAMES.WORKFLOW, DIR_NAMES.TASKS);
2063
+ const taskDir = path.join(tasksDir, taskDirName);
2064
+ // Check if task already exists
2065
+ if (!fs.existsSync(taskDir)) {
2066
+ fs.mkdirSync(taskDir, { recursive: true });
2067
+ // Get current developer for assignee.
2068
+ // `.developer` is a key=value file (written by init_developer.py):
2069
+ // name=<developer-name>
2070
+ // initialized_at=<iso8601>
2071
+ // Reading it raw and .trim()-ing embeds the entire file contents
2072
+ // (including the `name=` prefix and the `initialized_at` line) into
2073
+ // the assignee field, producing bogus assignees like
2074
+ // "name=suyuan\ninitialized_at=2026-04-07T23:41:21.978312" that
2075
+ // later break session-start task rendering.
2076
+ const developerFile = path.join(cwd, DIR_NAMES.WORKFLOW, ".developer");
2077
+ let currentDeveloper = "unknown";
2078
+ if (fs.existsSync(developerFile)) {
2079
+ const raw = fs.readFileSync(developerFile, "utf-8");
2080
+ const nameMatch = raw.match(/^\s*name\s*=\s*(.+?)\s*$/m);
2081
+ if (nameMatch) {
2082
+ currentDeveloper = nameMatch[1];
2083
+ }
2084
+ }
2085
+ // Build task.json — canonical 24-field shape via shared factory.
2086
+ const taskTitle = `Migrate to v${cliVersion}`;
2087
+ const todayStr = today.toISOString().split("T")[0];
2088
+ const taskJson = emptyTaskJson({
2089
+ id: taskSlug,
2090
+ name: taskSlug,
2091
+ title: taskTitle,
2092
+ description: `Breaking change migration from v${projectVersion} to v${cliVersion}`,
2093
+ status: "planning",
2094
+ scope: "migration",
2095
+ priority: "P1",
2096
+ creator: "trellis-update",
2097
+ assignee: currentDeveloper,
2098
+ createdAt: todayStr,
2099
+ });
2100
+ // Write task.json
2101
+ const taskJsonPath = path.join(taskDir, "task.json");
2102
+ fs.writeFileSync(taskJsonPath, JSON.stringify(taskJson, null, 2));
2103
+ // Build PRD content
2104
+ let prdContent = `# Migration Task: Upgrade to v${cliVersion}\n\n`;
2105
+ prdContent += `**Created**: ${todayStr}\n`;
2106
+ prdContent += `**From Version**: ${projectVersion}\n`;
2107
+ prdContent += `**To Version**: ${cliVersion}\n`;
2108
+ prdContent += `**Assignee**: ${currentDeveloper}\n\n`;
2109
+ prdContent += `## Status\n\n- [ ] Review migration guide\n- [ ] Update custom files\n- [ ] Run \`trellis update --migrate\`\n- [ ] Test workflows\n\n`;
2110
+ for (const { version, guide, aiInstructions, } of metadata.migrationGuides) {
2111
+ prdContent += `---\n\n## v${version} Migration Guide\n\n`;
2112
+ prdContent += guide;
2113
+ prdContent += "\n\n";
2114
+ if (aiInstructions) {
2115
+ prdContent += `### AI Assistant Instructions\n\n`;
2116
+ prdContent += `When helping with this migration:\n\n`;
2117
+ prdContent += aiInstructions;
2118
+ prdContent += "\n\n";
2119
+ }
2120
+ }
2121
+ // Write PRD
2122
+ const prdPath = path.join(taskDir, "prd.md");
2123
+ fs.writeFileSync(prdPath, prdContent);
2124
+ console.log("");
2125
+ console.log(chalk.bgCyan.black.bold(" šŸ“‹ MIGRATION TASK CREATED "));
2126
+ console.log(chalk.cyan(`A task has been created to help you complete the migration:`));
2127
+ console.log(chalk.white(` ${DIR_NAMES.WORKFLOW}/${DIR_NAMES.TASKS}/${taskDirName}/`));
2128
+ console.log("");
2129
+ console.log(chalk.gray("Use AI to help: Ask Claude/Cursor to read the task and fix your custom files."));
2130
+ }
2131
+ }
2132
+ }
2133
+ if (zcodeConfigured)
2134
+ printZcodeSetupHint();
2135
+ // Display breaking change warnings at the very end (so they don't scroll off screen)
2136
+ if (cliVsProject > 0 && projectVersion !== "unknown") {
2137
+ const finalMetadata = getMigrationMetadata(projectVersion, cliVersion);
2138
+ if (finalMetadata.breaking || finalMetadata.changelog.length > 0) {
2139
+ console.log("");
2140
+ console.log(chalk.cyan("═".repeat(60)));
2141
+ if (finalMetadata.breaking) {
2142
+ console.log(chalk.bgRed.white.bold(" āš ļø BREAKING CHANGES ") +
2143
+ chalk.red.bold(" This update contains breaking changes!"));
2144
+ console.log("");
2145
+ }
2146
+ if (finalMetadata.changelog.length > 0) {
2147
+ console.log(chalk.cyan.bold("šŸ“‹ What's Changed:"));
2148
+ for (const entry of finalMetadata.changelog) {
2149
+ console.log(chalk.white(` ${entry}`));
2150
+ }
2151
+ console.log("");
2152
+ }
2153
+ if (finalMetadata.recommendMigrate && !options.migrate) {
2154
+ console.log(chalk.bgGreen.black.bold(" šŸ’” RECOMMENDED ") +
2155
+ chalk.green.bold(" Run with --migrate to complete the migration"));
2156
+ console.log(chalk.gray(" This will remove legacy files and apply all changes."));
2157
+ console.log("");
2158
+ }
2159
+ console.log(chalk.cyan("═".repeat(60)));
2160
+ }
2161
+ }
2162
+ }
2163
+ //# sourceMappingURL=update.js.map