trellis-herbivore 0.1.0

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