@baoanaz/cviauto 0.6.5

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