trellis-herbivore 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (629) hide show
  1. package/bin/trellis.js +3 -0
  2. package/dist/cli/index.d.ts +3 -0
  3. package/dist/cli/index.d.ts.map +1 -0
  4. package/dist/cli/index.js +174 -0
  5. package/dist/cli/index.js.map +1 -0
  6. package/dist/commands/channel/adapters/claude.d.ts +38 -0
  7. package/dist/commands/channel/adapters/claude.d.ts.map +1 -0
  8. package/dist/commands/channel/adapters/claude.js +209 -0
  9. package/dist/commands/channel/adapters/claude.js.map +1 -0
  10. package/dist/commands/channel/adapters/codex.d.ts +77 -0
  11. package/dist/commands/channel/adapters/codex.d.ts.map +1 -0
  12. package/dist/commands/channel/adapters/codex.js +495 -0
  13. package/dist/commands/channel/adapters/codex.js.map +1 -0
  14. package/dist/commands/channel/adapters/index.d.ts +79 -0
  15. package/dist/commands/channel/adapters/index.d.ts.map +1 -0
  16. package/dist/commands/channel/adapters/index.js +109 -0
  17. package/dist/commands/channel/adapters/index.js.map +1 -0
  18. package/dist/commands/channel/adapters/types.d.ts +33 -0
  19. package/dist/commands/channel/adapters/types.d.ts.map +1 -0
  20. package/dist/commands/channel/adapters/types.js +2 -0
  21. package/dist/commands/channel/adapters/types.js.map +1 -0
  22. package/dist/commands/channel/agent-loader.d.ts +32 -0
  23. package/dist/commands/channel/agent-loader.d.ts.map +1 -0
  24. package/dist/commands/channel/agent-loader.js +154 -0
  25. package/dist/commands/channel/agent-loader.js.map +1 -0
  26. package/dist/commands/channel/context-loader.d.ts +26 -0
  27. package/dist/commands/channel/context-loader.d.ts.map +1 -0
  28. package/dist/commands/channel/context-loader.js +290 -0
  29. package/dist/commands/channel/context-loader.js.map +1 -0
  30. package/dist/commands/channel/context.d.ts +16 -0
  31. package/dist/commands/channel/context.d.ts.map +1 -0
  32. package/dist/commands/channel/context.js +83 -0
  33. package/dist/commands/channel/context.js.map +1 -0
  34. package/dist/commands/channel/create.d.ts +27 -0
  35. package/dist/commands/channel/create.d.ts.map +1 -0
  36. package/dist/commands/channel/create.js +39 -0
  37. package/dist/commands/channel/create.js.map +1 -0
  38. package/dist/commands/channel/dev-parse-trace.d.ts +14 -0
  39. package/dist/commands/channel/dev-parse-trace.d.ts.map +1 -0
  40. package/dist/commands/channel/dev-parse-trace.js +70 -0
  41. package/dist/commands/channel/dev-parse-trace.js.map +1 -0
  42. package/dist/commands/channel/index.d.ts +3 -0
  43. package/dist/commands/channel/index.d.ts.map +1 -0
  44. package/dist/commands/channel/index.js +496 -0
  45. package/dist/commands/channel/index.js.map +1 -0
  46. package/dist/commands/channel/kill.d.ts +7 -0
  47. package/dist/commands/channel/kill.d.ts.map +1 -0
  48. package/dist/commands/channel/kill.js +121 -0
  49. package/dist/commands/channel/kill.js.map +1 -0
  50. package/dist/commands/channel/list.d.ts +17 -0
  51. package/dist/commands/channel/list.d.ts.map +1 -0
  52. package/dist/commands/channel/list.js +233 -0
  53. package/dist/commands/channel/list.js.map +1 -0
  54. package/dist/commands/channel/messages.d.ts +16 -0
  55. package/dist/commands/channel/messages.d.ts.map +1 -0
  56. package/dist/commands/channel/messages.js +237 -0
  57. package/dist/commands/channel/messages.js.map +1 -0
  58. package/dist/commands/channel/rm.d.ts +27 -0
  59. package/dist/commands/channel/rm.d.ts.map +1 -0
  60. package/dist/commands/channel/rm.js +216 -0
  61. package/dist/commands/channel/rm.js.map +1 -0
  62. package/dist/commands/channel/run.d.ts +31 -0
  63. package/dist/commands/channel/run.d.ts.map +1 -0
  64. package/dist/commands/channel/run.js +137 -0
  65. package/dist/commands/channel/run.js.map +1 -0
  66. package/dist/commands/channel/send.d.ts +12 -0
  67. package/dist/commands/channel/send.d.ts.map +1 -0
  68. package/dist/commands/channel/send.js +24 -0
  69. package/dist/commands/channel/send.js.map +1 -0
  70. package/dist/commands/channel/spawn.d.ts +25 -0
  71. package/dist/commands/channel/spawn.d.ts.map +1 -0
  72. package/dist/commands/channel/spawn.js +192 -0
  73. package/dist/commands/channel/spawn.js.map +1 -0
  74. package/dist/commands/channel/store/events.d.ts +39 -0
  75. package/dist/commands/channel/store/events.d.ts.map +1 -0
  76. package/dist/commands/channel/store/events.js +87 -0
  77. package/dist/commands/channel/store/events.js.map +1 -0
  78. package/dist/commands/channel/store/filter.d.ts +3 -0
  79. package/dist/commands/channel/store/filter.d.ts.map +1 -0
  80. package/dist/commands/channel/store/filter.js +2 -0
  81. package/dist/commands/channel/store/filter.js.map +1 -0
  82. package/dist/commands/channel/store/lock.d.ts +23 -0
  83. package/dist/commands/channel/store/lock.d.ts.map +1 -0
  84. package/dist/commands/channel/store/lock.js +99 -0
  85. package/dist/commands/channel/store/lock.js.map +1 -0
  86. package/dist/commands/channel/store/paths.d.ts +63 -0
  87. package/dist/commands/channel/store/paths.d.ts.map +1 -0
  88. package/dist/commands/channel/store/paths.js +246 -0
  89. package/dist/commands/channel/store/paths.js.map +1 -0
  90. package/dist/commands/channel/store/schema.d.ts +27 -0
  91. package/dist/commands/channel/store/schema.d.ts.map +1 -0
  92. package/dist/commands/channel/store/schema.js +34 -0
  93. package/dist/commands/channel/store/schema.js.map +1 -0
  94. package/dist/commands/channel/store/thread-state.d.ts +5 -0
  95. package/dist/commands/channel/store/thread-state.d.ts.map +1 -0
  96. package/dist/commands/channel/store/thread-state.js +16 -0
  97. package/dist/commands/channel/store/thread-state.js.map +1 -0
  98. package/dist/commands/channel/store/watch.d.ts +19 -0
  99. package/dist/commands/channel/store/watch.d.ts.map +1 -0
  100. package/dist/commands/channel/store/watch.js +130 -0
  101. package/dist/commands/channel/store/watch.js.map +1 -0
  102. package/dist/commands/channel/supervisor/inbox.d.ts +25 -0
  103. package/dist/commands/channel/supervisor/inbox.d.ts.map +1 -0
  104. package/dist/commands/channel/supervisor/inbox.js +99 -0
  105. package/dist/commands/channel/supervisor/inbox.js.map +1 -0
  106. package/dist/commands/channel/supervisor/shutdown.d.ts +66 -0
  107. package/dist/commands/channel/supervisor/shutdown.d.ts.map +1 -0
  108. package/dist/commands/channel/supervisor/shutdown.js +143 -0
  109. package/dist/commands/channel/supervisor/shutdown.js.map +1 -0
  110. package/dist/commands/channel/supervisor/stdout.d.ts +49 -0
  111. package/dist/commands/channel/supervisor/stdout.d.ts.map +1 -0
  112. package/dist/commands/channel/supervisor/stdout.js +107 -0
  113. package/dist/commands/channel/supervisor/stdout.js.map +1 -0
  114. package/dist/commands/channel/supervisor.d.ts +47 -0
  115. package/dist/commands/channel/supervisor.d.ts.map +1 -0
  116. package/dist/commands/channel/supervisor.js +283 -0
  117. package/dist/commands/channel/supervisor.js.map +1 -0
  118. package/dist/commands/channel/text-body.d.ts +13 -0
  119. package/dist/commands/channel/text-body.d.ts.map +1 -0
  120. package/dist/commands/channel/text-body.js +47 -0
  121. package/dist/commands/channel/text-body.js.map +1 -0
  122. package/dist/commands/channel/threads.d.ts +39 -0
  123. package/dist/commands/channel/threads.d.ts.map +1 -0
  124. package/dist/commands/channel/threads.js +106 -0
  125. package/dist/commands/channel/threads.js.map +1 -0
  126. package/dist/commands/channel/title.d.ts +12 -0
  127. package/dist/commands/channel/title.d.ts.map +1 -0
  128. package/dist/commands/channel/title.js +24 -0
  129. package/dist/commands/channel/title.js.map +1 -0
  130. package/dist/commands/channel/wait.d.ts +18 -0
  131. package/dist/commands/channel/wait.d.ts.map +1 -0
  132. package/dist/commands/channel/wait.js +76 -0
  133. package/dist/commands/channel/wait.js.map +1 -0
  134. package/dist/commands/init.d.ts +57 -0
  135. package/dist/commands/init.d.ts.map +1 -0
  136. package/dist/commands/init.js +1466 -0
  137. package/dist/commands/init.js.map +1 -0
  138. package/dist/commands/mem.d.ts +234 -0
  139. package/dist/commands/mem.d.ts.map +1 -0
  140. package/dist/commands/mem.js +1869 -0
  141. package/dist/commands/mem.js.map +1 -0
  142. package/dist/commands/uninstall.d.ts +27 -0
  143. package/dist/commands/uninstall.d.ts.map +1 -0
  144. package/dist/commands/uninstall.js +339 -0
  145. package/dist/commands/uninstall.js.map +1 -0
  146. package/dist/commands/update.d.ts +72 -0
  147. package/dist/commands/update.d.ts.map +1 -0
  148. package/dist/commands/update.js +1926 -0
  149. package/dist/commands/update.js.map +1 -0
  150. package/dist/commands/upgrade.d.ts +28 -0
  151. package/dist/commands/upgrade.d.ts.map +1 -0
  152. package/dist/commands/upgrade.js +84 -0
  153. package/dist/commands/upgrade.js.map +1 -0
  154. package/dist/configurators/antigravity.d.ts +7 -0
  155. package/dist/configurators/antigravity.d.ts.map +1 -0
  156. package/dist/configurators/antigravity.js +19 -0
  157. package/dist/configurators/antigravity.js.map +1 -0
  158. package/dist/configurators/claude.d.ts +9 -0
  159. package/dist/configurators/claude.d.ts.map +1 -0
  160. package/dist/configurators/claude.js +72 -0
  161. package/dist/configurators/claude.js.map +1 -0
  162. package/dist/configurators/codebuddy.d.ts +10 -0
  163. package/dist/configurators/codebuddy.d.ts.map +1 -0
  164. package/dist/configurators/codebuddy.js +30 -0
  165. package/dist/configurators/codebuddy.js.map +1 -0
  166. package/dist/configurators/codex.d.ts +8 -0
  167. package/dist/configurators/codex.d.ts.map +1 -0
  168. package/dist/configurators/codex.js +87 -0
  169. package/dist/configurators/codex.js.map +1 -0
  170. package/dist/configurators/copilot.d.ts +10 -0
  171. package/dist/configurators/copilot.d.ts.map +1 -0
  172. package/dist/configurators/copilot.js +51 -0
  173. package/dist/configurators/copilot.js.map +1 -0
  174. package/dist/configurators/cursor.d.ts +10 -0
  175. package/dist/configurators/cursor.d.ts.map +1 -0
  176. package/dist/configurators/cursor.js +29 -0
  177. package/dist/configurators/cursor.js.map +1 -0
  178. package/dist/configurators/droid.d.ts +10 -0
  179. package/dist/configurators/droid.d.ts.map +1 -0
  180. package/dist/configurators/droid.js +30 -0
  181. package/dist/configurators/droid.js.map +1 -0
  182. package/dist/configurators/gemini.d.ts +16 -0
  183. package/dist/configurators/gemini.d.ts.map +1 -0
  184. package/dist/configurators/gemini.js +38 -0
  185. package/dist/configurators/gemini.js.map +1 -0
  186. package/dist/configurators/index.d.ts +65 -0
  187. package/dist/configurators/index.d.ts.map +1 -0
  188. package/dist/configurators/index.js +367 -0
  189. package/dist/configurators/index.js.map +1 -0
  190. package/dist/configurators/kilo.d.ts +7 -0
  191. package/dist/configurators/kilo.d.ts.map +1 -0
  192. package/dist/configurators/kilo.js +19 -0
  193. package/dist/configurators/kilo.js.map +1 -0
  194. package/dist/configurators/kiro.d.ts +8 -0
  195. package/dist/configurators/kiro.d.ts.map +1 -0
  196. package/dist/configurators/kiro.js +24 -0
  197. package/dist/configurators/kiro.js.map +1 -0
  198. package/dist/configurators/opencode.d.ts +14 -0
  199. package/dist/configurators/opencode.d.ts.map +1 -0
  200. package/dist/configurators/opencode.js +96 -0
  201. package/dist/configurators/opencode.js.map +1 -0
  202. package/dist/configurators/pi.d.ts +3 -0
  203. package/dist/configurators/pi.d.ts.map +1 -0
  204. package/dist/configurators/pi.js +45 -0
  205. package/dist/configurators/pi.js.map +1 -0
  206. package/dist/configurators/qoder.d.ts +11 -0
  207. package/dist/configurators/qoder.d.ts.map +1 -0
  208. package/dist/configurators/qoder.js +31 -0
  209. package/dist/configurators/qoder.js.map +1 -0
  210. package/dist/configurators/shared.d.ts +178 -0
  211. package/dist/configurators/shared.d.ts.map +1 -0
  212. package/dist/configurators/shared.js +538 -0
  213. package/dist/configurators/shared.js.map +1 -0
  214. package/dist/configurators/windsurf.d.ts +7 -0
  215. package/dist/configurators/windsurf.d.ts.map +1 -0
  216. package/dist/configurators/windsurf.js +19 -0
  217. package/dist/configurators/windsurf.js.map +1 -0
  218. package/dist/configurators/workflow.d.ts +29 -0
  219. package/dist/configurators/workflow.d.ts.map +1 -0
  220. package/dist/configurators/workflow.js +163 -0
  221. package/dist/configurators/workflow.js.map +1 -0
  222. package/dist/constants/paths.d.ts +70 -0
  223. package/dist/constants/paths.d.ts.map +1 -0
  224. package/dist/constants/paths.js +79 -0
  225. package/dist/constants/paths.js.map +1 -0
  226. package/dist/constants/version.d.ts +9 -0
  227. package/dist/constants/version.d.ts.map +1 -0
  228. package/dist/constants/version.js +15 -0
  229. package/dist/constants/version.js.map +1 -0
  230. package/dist/index.d.ts +9 -0
  231. package/dist/index.d.ts.map +1 -0
  232. package/dist/index.js +9 -0
  233. package/dist/index.js.map +1 -0
  234. package/dist/migrations/index.d.ts +62 -0
  235. package/dist/migrations/index.d.ts.map +1 -0
  236. package/dist/migrations/index.js +187 -0
  237. package/dist/migrations/index.js.map +1 -0
  238. package/dist/migrations/manifests/0.1.9.json +30 -0
  239. package/dist/migrations/manifests/0.2.0.json +49 -0
  240. package/dist/migrations/manifests/0.2.12.json +9 -0
  241. package/dist/migrations/manifests/0.2.13.json +9 -0
  242. package/dist/migrations/manifests/0.2.14.json +175 -0
  243. package/dist/migrations/manifests/0.2.15.json +33 -0
  244. package/dist/migrations/manifests/0.3.0-beta.0.json +297 -0
  245. package/dist/migrations/manifests/0.3.0-beta.1.json +9 -0
  246. package/dist/migrations/manifests/0.3.0-beta.10.json +9 -0
  247. package/dist/migrations/manifests/0.3.0-beta.11.json +9 -0
  248. package/dist/migrations/manifests/0.3.0-beta.12.json +9 -0
  249. package/dist/migrations/manifests/0.3.0-beta.13.json +9 -0
  250. package/dist/migrations/manifests/0.3.0-beta.14.json +9 -0
  251. package/dist/migrations/manifests/0.3.0-beta.15.json +9 -0
  252. package/dist/migrations/manifests/0.3.0-beta.16.json +9 -0
  253. package/dist/migrations/manifests/0.3.0-beta.2.json +9 -0
  254. package/dist/migrations/manifests/0.3.0-beta.3.json +9 -0
  255. package/dist/migrations/manifests/0.3.0-beta.4.json +9 -0
  256. package/dist/migrations/manifests/0.3.0-beta.5.json +9 -0
  257. package/dist/migrations/manifests/0.3.0-beta.6.json +9 -0
  258. package/dist/migrations/manifests/0.3.0-beta.7.json +11 -0
  259. package/dist/migrations/manifests/0.3.0-beta.8.json +9 -0
  260. package/dist/migrations/manifests/0.3.0-beta.9.json +9 -0
  261. package/dist/migrations/manifests/0.3.0-rc.0.json +9 -0
  262. package/dist/migrations/manifests/0.3.0-rc.1.json +9 -0
  263. package/dist/migrations/manifests/0.3.0-rc.2.json +9 -0
  264. package/dist/migrations/manifests/0.3.0-rc.3.json +9 -0
  265. package/dist/migrations/manifests/0.3.0-rc.4.json +9 -0
  266. package/dist/migrations/manifests/0.3.0-rc.5.json +9 -0
  267. package/dist/migrations/manifests/0.3.0-rc.6.json +9 -0
  268. package/dist/migrations/manifests/0.3.0.json +11 -0
  269. package/dist/migrations/manifests/0.3.1.json +9 -0
  270. package/dist/migrations/manifests/0.3.10.json +9 -0
  271. package/dist/migrations/manifests/0.3.2.json +9 -0
  272. package/dist/migrations/manifests/0.3.3.json +9 -0
  273. package/dist/migrations/manifests/0.3.4.json +21 -0
  274. package/dist/migrations/manifests/0.3.5.json +9 -0
  275. package/dist/migrations/manifests/0.3.6.json +9 -0
  276. package/dist/migrations/manifests/0.3.7.json +9 -0
  277. package/dist/migrations/manifests/0.3.8.json +9 -0
  278. package/dist/migrations/manifests/0.3.9.json +9 -0
  279. package/dist/migrations/manifests/0.4.0-beta.1.json +228 -0
  280. package/dist/migrations/manifests/0.4.0-beta.10.json +9 -0
  281. package/dist/migrations/manifests/0.4.0-beta.2.json +9 -0
  282. package/dist/migrations/manifests/0.4.0-beta.3.json +9 -0
  283. package/dist/migrations/manifests/0.4.0-beta.4.json +9 -0
  284. package/dist/migrations/manifests/0.4.0-beta.5.json +9 -0
  285. package/dist/migrations/manifests/0.4.0-beta.6.json +9 -0
  286. package/dist/migrations/manifests/0.4.0-beta.7.json +9 -0
  287. package/dist/migrations/manifests/0.4.0-beta.8.json +34 -0
  288. package/dist/migrations/manifests/0.4.0-beta.9.json +9 -0
  289. package/dist/migrations/manifests/0.4.0-rc.0.json +9 -0
  290. package/dist/migrations/manifests/0.4.0-rc.1.json +9 -0
  291. package/dist/migrations/manifests/0.4.0.json +9 -0
  292. package/dist/migrations/manifests/0.5.0-beta.0.json +1646 -0
  293. package/dist/migrations/manifests/0.5.0-beta.1.json +9 -0
  294. package/dist/migrations/manifests/0.5.0-beta.10.json +9 -0
  295. package/dist/migrations/manifests/0.5.0-beta.11.json +9 -0
  296. package/dist/migrations/manifests/0.5.0-beta.12.json +9 -0
  297. package/dist/migrations/manifests/0.5.0-beta.13.json +9 -0
  298. package/dist/migrations/manifests/0.5.0-beta.14.json +9 -0
  299. package/dist/migrations/manifests/0.5.0-beta.15.json +116 -0
  300. package/dist/migrations/manifests/0.5.0-beta.16.json +9 -0
  301. package/dist/migrations/manifests/0.5.0-beta.17.json +9 -0
  302. package/dist/migrations/manifests/0.5.0-beta.18.json +9 -0
  303. package/dist/migrations/manifests/0.5.0-beta.19.json +9 -0
  304. package/dist/migrations/manifests/0.5.0-beta.2.json +9 -0
  305. package/dist/migrations/manifests/0.5.0-beta.3.json +9 -0
  306. package/dist/migrations/manifests/0.5.0-beta.4.json +9 -0
  307. package/dist/migrations/manifests/0.5.0-beta.5.json +222 -0
  308. package/dist/migrations/manifests/0.5.0-beta.6.json +9 -0
  309. package/dist/migrations/manifests/0.5.0-beta.7.json +9 -0
  310. package/dist/migrations/manifests/0.5.0-beta.8.json +9 -0
  311. package/dist/migrations/manifests/0.5.0-beta.9.json +48 -0
  312. package/dist/migrations/manifests/0.5.0-rc.0.json +9 -0
  313. package/dist/migrations/manifests/0.5.0-rc.1.json +9 -0
  314. package/dist/migrations/manifests/0.5.0-rc.2.json +9 -0
  315. package/dist/migrations/manifests/0.5.0-rc.3.json +9 -0
  316. package/dist/migrations/manifests/0.5.0-rc.4.json +9 -0
  317. package/dist/migrations/manifests/0.5.0-rc.5.json +9 -0
  318. package/dist/migrations/manifests/0.5.0-rc.6.json +9 -0
  319. package/dist/migrations/manifests/0.5.0-rc.7.json +9 -0
  320. package/dist/migrations/manifests/0.5.0.json +9 -0
  321. package/dist/migrations/manifests/0.5.1.json +9 -0
  322. package/dist/migrations/manifests/0.5.10.json +9 -0
  323. package/dist/migrations/manifests/0.5.11.json +16 -0
  324. package/dist/migrations/manifests/0.5.12.json +9 -0
  325. package/dist/migrations/manifests/0.5.13.json +9 -0
  326. package/dist/migrations/manifests/0.5.14.json +9 -0
  327. package/dist/migrations/manifests/0.5.15.json +9 -0
  328. package/dist/migrations/manifests/0.5.2.json +9 -0
  329. package/dist/migrations/manifests/0.5.3.json +9 -0
  330. package/dist/migrations/manifests/0.5.4.json +9 -0
  331. package/dist/migrations/manifests/0.5.5.json +9 -0
  332. package/dist/migrations/manifests/0.5.6.json +9 -0
  333. package/dist/migrations/manifests/0.5.7.json +16 -0
  334. package/dist/migrations/manifests/0.5.8.json +9 -0
  335. package/dist/migrations/manifests/0.5.9.json +9 -0
  336. package/dist/migrations/manifests/0.6.0-beta.0.json +16 -0
  337. package/dist/migrations/manifests/0.6.0-beta.1.json +9 -0
  338. package/dist/migrations/manifests/0.6.0-beta.10.json +9 -0
  339. package/dist/migrations/manifests/0.6.0-beta.11.json +9 -0
  340. package/dist/migrations/manifests/0.6.0-beta.12.json +9 -0
  341. package/dist/migrations/manifests/0.6.0-beta.13.json +9 -0
  342. package/dist/migrations/manifests/0.6.0-beta.14.json +9 -0
  343. package/dist/migrations/manifests/0.6.0-beta.2.json +9 -0
  344. package/dist/migrations/manifests/0.6.0-beta.3.json +9 -0
  345. package/dist/migrations/manifests/0.6.0-beta.4.json +9 -0
  346. package/dist/migrations/manifests/0.6.0-beta.5.json +9 -0
  347. package/dist/migrations/manifests/0.6.0-beta.6.json +16 -0
  348. package/dist/migrations/manifests/0.6.0-beta.7.json +9 -0
  349. package/dist/migrations/manifests/0.6.0-beta.8.json +9 -0
  350. package/dist/migrations/manifests/0.6.0-beta.9.json +9 -0
  351. package/dist/templates/claude/agents/trellis-check.md +114 -0
  352. package/dist/templates/claude/agents/trellis-implement.md +113 -0
  353. package/dist/templates/claude/agents/trellis-research.md +137 -0
  354. package/dist/templates/claude/index.d.ts +22 -0
  355. package/dist/templates/claude/index.d.ts.map +1 -0
  356. package/dist/templates/claude/index.js +46 -0
  357. package/dist/templates/claude/index.js.map +1 -0
  358. package/dist/templates/claude/settings.json +73 -0
  359. package/dist/templates/codebuddy/agents/trellis-check.md +109 -0
  360. package/dist/templates/codebuddy/agents/trellis-implement.md +110 -0
  361. package/dist/templates/codebuddy/agents/trellis-research.md +137 -0
  362. package/dist/templates/codebuddy/index.d.ts +15 -0
  363. package/dist/templates/codebuddy/index.d.ts.map +1 -0
  364. package/dist/templates/codebuddy/index.js +15 -0
  365. package/dist/templates/codebuddy/index.js.map +1 -0
  366. package/dist/templates/codebuddy/settings.json +59 -0
  367. package/dist/templates/codex/agents/trellis-check.toml +84 -0
  368. package/dist/templates/codex/agents/trellis-implement.toml +65 -0
  369. package/dist/templates/codex/agents/trellis-research.toml +73 -0
  370. package/dist/templates/codex/config.toml +35 -0
  371. package/dist/templates/codex/hooks/session-start.py +545 -0
  372. package/dist/templates/codex/hooks.json +15 -0
  373. package/dist/templates/codex/index.d.ts +39 -0
  374. package/dist/templates/codex/index.d.ts.map +1 -0
  375. package/dist/templates/codex/index.js +85 -0
  376. package/dist/templates/codex/index.js.map +1 -0
  377. package/dist/templates/codex/skills/before-dev/SKILL.md +40 -0
  378. package/dist/templates/codex/skills/brainstorm/SKILL.md +112 -0
  379. package/dist/templates/codex/skills/break-loop/SKILL.md +130 -0
  380. package/dist/templates/codex/skills/check/SKILL.md +98 -0
  381. package/dist/templates/codex/skills/check-cross-layer/SKILL.md +158 -0
  382. package/dist/templates/codex/skills/create-command/SKILL.md +101 -0
  383. package/dist/templates/codex/skills/finish-work/SKILL.md +90 -0
  384. package/dist/templates/codex/skills/improve-ut/SKILL.md +69 -0
  385. package/dist/templates/codex/skills/integrate-skill/SKILL.md +221 -0
  386. package/dist/templates/codex/skills/onboard/SKILL.md +363 -0
  387. package/dist/templates/codex/skills/record-session/SKILL.md +67 -0
  388. package/dist/templates/codex/skills/start/SKILL.md +64 -0
  389. package/dist/templates/codex/skills/update-spec/SKILL.md +335 -0
  390. package/dist/templates/common/bundled-skills/trellis-meta/SKILL.md +73 -0
  391. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/add-project-local-conventions.md +83 -0
  392. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-agents.md +54 -0
  393. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-context-loading.md +84 -0
  394. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-hooks.md +57 -0
  395. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-skills-or-commands.md +78 -0
  396. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-spec-structure.md +83 -0
  397. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-task-lifecycle.md +90 -0
  398. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-workflow.md +65 -0
  399. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/overview.md +55 -0
  400. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/context-injection.md +68 -0
  401. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/generated-files.md +80 -0
  402. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/overview.md +51 -0
  403. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/spec-system.md +102 -0
  404. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/task-system.md +103 -0
  405. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/workflow.md +75 -0
  406. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/workspace-memory.md +71 -0
  407. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/agents.md +80 -0
  408. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/hooks-and-settings.md +69 -0
  409. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/overview.md +59 -0
  410. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/platform-map.md +74 -0
  411. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/skills-and-commands.md +83 -0
  412. package/dist/templates/common/commands/continue.md +56 -0
  413. package/dist/templates/common/commands/finish-work.md +66 -0
  414. package/dist/templates/common/commands/start.md +59 -0
  415. package/dist/templates/common/index.d.ts +48 -0
  416. package/dist/templates/common/index.d.ts.map +1 -0
  417. package/dist/templates/common/index.js +104 -0
  418. package/dist/templates/common/index.js.map +1 -0
  419. package/dist/templates/common/skills/before-dev.md +35 -0
  420. package/dist/templates/common/skills/brainstorm.md +112 -0
  421. package/dist/templates/common/skills/break-loop.md +125 -0
  422. package/dist/templates/common/skills/check.md +93 -0
  423. package/dist/templates/common/skills/update-spec.md +351 -0
  424. package/dist/templates/copilot/hooks/session-start.py +547 -0
  425. package/dist/templates/copilot/hooks.json +19 -0
  426. package/dist/templates/copilot/index.d.ts +23 -0
  427. package/dist/templates/copilot/index.d.ts.map +1 -0
  428. package/dist/templates/copilot/index.js +54 -0
  429. package/dist/templates/copilot/index.js.map +1 -0
  430. package/dist/templates/copilot/prompts/before-dev.prompt.md +39 -0
  431. package/dist/templates/copilot/prompts/brainstorm.prompt.md +111 -0
  432. package/dist/templates/copilot/prompts/break-loop.prompt.md +129 -0
  433. package/dist/templates/copilot/prompts/check-cross-layer.prompt.md +157 -0
  434. package/dist/templates/copilot/prompts/check.prompt.md +97 -0
  435. package/dist/templates/copilot/prompts/create-command.prompt.md +116 -0
  436. package/dist/templates/copilot/prompts/finish-work.prompt.md +99 -0
  437. package/dist/templates/copilot/prompts/integrate-skill.prompt.md +223 -0
  438. package/dist/templates/copilot/prompts/onboard.prompt.md +362 -0
  439. package/dist/templates/copilot/prompts/parallel.prompt.md +204 -0
  440. package/dist/templates/copilot/prompts/record-session.prompt.md +66 -0
  441. package/dist/templates/copilot/prompts/start.prompt.md +63 -0
  442. package/dist/templates/copilot/prompts/update-spec.prompt.md +358 -0
  443. package/dist/templates/cursor/agents/trellis-check.md +108 -0
  444. package/dist/templates/cursor/agents/trellis-implement.md +109 -0
  445. package/dist/templates/cursor/agents/trellis-research.md +136 -0
  446. package/dist/templates/cursor/hooks.json +30 -0
  447. package/dist/templates/cursor/index.d.ts +13 -0
  448. package/dist/templates/cursor/index.d.ts.map +1 -0
  449. package/dist/templates/cursor/index.js +13 -0
  450. package/dist/templates/cursor/index.js.map +1 -0
  451. package/dist/templates/droid/droids/trellis-check.md +101 -0
  452. package/dist/templates/droid/droids/trellis-implement.md +102 -0
  453. package/dist/templates/droid/droids/trellis-research.md +137 -0
  454. package/dist/templates/droid/index.d.ts +15 -0
  455. package/dist/templates/droid/index.d.ts.map +1 -0
  456. package/dist/templates/droid/index.js +15 -0
  457. package/dist/templates/droid/index.js.map +1 -0
  458. package/dist/templates/droid/settings.json +59 -0
  459. package/dist/templates/extract.d.ts +40 -0
  460. package/dist/templates/extract.d.ts.map +1 -0
  461. package/dist/templates/extract.js +106 -0
  462. package/dist/templates/extract.js.map +1 -0
  463. package/dist/templates/gemini/agents/trellis-check.md +101 -0
  464. package/dist/templates/gemini/agents/trellis-implement.md +102 -0
  465. package/dist/templates/gemini/agents/trellis-research.md +136 -0
  466. package/dist/templates/gemini/index.d.ts +13 -0
  467. package/dist/templates/gemini/index.d.ts.map +1 -0
  468. package/dist/templates/gemini/index.js +13 -0
  469. package/dist/templates/gemini/index.js.map +1 -0
  470. package/dist/templates/gemini/settings.json +28 -0
  471. package/dist/templates/kiro/agents/trellis-check.json +26 -0
  472. package/dist/templates/kiro/agents/trellis-implement.json +26 -0
  473. package/dist/templates/kiro/agents/trellis-research.json +30 -0
  474. package/dist/templates/kiro/index.d.ts +18 -0
  475. package/dist/templates/kiro/index.d.ts.map +1 -0
  476. package/dist/templates/kiro/index.js +18 -0
  477. package/dist/templates/kiro/index.js.map +1 -0
  478. package/dist/templates/markdown/agents.md +21 -0
  479. package/dist/templates/markdown/gitignore.txt +15 -0
  480. package/dist/templates/markdown/index.d.ts +27 -0
  481. package/dist/templates/markdown/index.d.ts.map +1 -0
  482. package/dist/templates/markdown/index.js +52 -0
  483. package/dist/templates/markdown/index.js.map +1 -0
  484. package/dist/templates/markdown/spec/backend/database-guidelines.md.txt +51 -0
  485. package/dist/templates/markdown/spec/backend/directory-structure.md.txt +54 -0
  486. package/dist/templates/markdown/spec/backend/error-handling.md.txt +51 -0
  487. package/dist/templates/markdown/spec/backend/index.md.txt +38 -0
  488. package/dist/templates/markdown/spec/backend/logging-guidelines.md.txt +51 -0
  489. package/dist/templates/markdown/spec/backend/quality-guidelines.md.txt +51 -0
  490. package/dist/templates/markdown/spec/frontend/component-guidelines.md.txt +59 -0
  491. package/dist/templates/markdown/spec/frontend/directory-structure.md.txt +54 -0
  492. package/dist/templates/markdown/spec/frontend/hook-guidelines.md.txt +51 -0
  493. package/dist/templates/markdown/spec/frontend/index.md.txt +39 -0
  494. package/dist/templates/markdown/spec/frontend/quality-guidelines.md.txt +51 -0
  495. package/dist/templates/markdown/spec/frontend/state-management.md.txt +51 -0
  496. package/dist/templates/markdown/spec/frontend/type-safety.md.txt +51 -0
  497. package/dist/templates/markdown/spec/guides/code-reuse-thinking-guide.md.txt +223 -0
  498. package/dist/templates/markdown/spec/guides/cross-layer-thinking-guide.md.txt +259 -0
  499. package/dist/templates/markdown/spec/guides/cross-platform-thinking-guide.md.txt +595 -0
  500. package/dist/templates/markdown/spec/guides/index.md.txt +97 -0
  501. package/dist/templates/markdown/workspace-index.md +125 -0
  502. package/dist/templates/markdown/worktree.yaml.txt +58 -0
  503. package/dist/templates/opencode/agents/trellis-check.md +116 -0
  504. package/dist/templates/opencode/agents/trellis-implement.md +118 -0
  505. package/dist/templates/opencode/agents/trellis-research.md +145 -0
  506. package/dist/templates/opencode/lib/session-utils.js +521 -0
  507. package/dist/templates/opencode/lib/trellis-context.js +381 -0
  508. package/dist/templates/opencode/package.json +5 -0
  509. package/dist/templates/opencode/plugins/inject-subagent-context.js +513 -0
  510. package/dist/templates/opencode/plugins/inject-workflow-state.js +159 -0
  511. package/dist/templates/opencode/plugins/session-start.js +101 -0
  512. package/dist/templates/pi/agents/trellis-check.md +36 -0
  513. package/dist/templates/pi/agents/trellis-implement.md +41 -0
  514. package/dist/templates/pi/agents/trellis-research.md +25 -0
  515. package/dist/templates/pi/extensions/trellis/index.ts.txt +1174 -0
  516. package/dist/templates/pi/index.d.ts +5 -0
  517. package/dist/templates/pi/index.d.ts.map +1 -0
  518. package/dist/templates/pi/index.js +12 -0
  519. package/dist/templates/pi/index.js.map +1 -0
  520. package/dist/templates/pi/settings.json +21 -0
  521. package/dist/templates/qoder/agents/trellis-check.md +102 -0
  522. package/dist/templates/qoder/agents/trellis-implement.md +103 -0
  523. package/dist/templates/qoder/agents/trellis-research.md +137 -0
  524. package/dist/templates/qoder/index.d.ts +15 -0
  525. package/dist/templates/qoder/index.d.ts.map +1 -0
  526. package/dist/templates/qoder/index.js +15 -0
  527. package/dist/templates/qoder/index.js.map +1 -0
  528. package/dist/templates/qoder/settings.json +47 -0
  529. package/dist/templates/shared-hooks/index.d.ts +50 -0
  530. package/dist/templates/shared-hooks/index.d.ts.map +1 -0
  531. package/dist/templates/shared-hooks/index.js +89 -0
  532. package/dist/templates/shared-hooks/index.js.map +1 -0
  533. package/dist/templates/shared-hooks/inject-shell-session-context.py +183 -0
  534. package/dist/templates/shared-hooks/inject-subagent-context.py +771 -0
  535. package/dist/templates/shared-hooks/inject-workflow-state.py +363 -0
  536. package/dist/templates/shared-hooks/session-start.py +827 -0
  537. package/dist/templates/template-utils.d.ts +26 -0
  538. package/dist/templates/template-utils.d.ts.map +1 -0
  539. package/dist/templates/template-utils.js +60 -0
  540. package/dist/templates/template-utils.js.map +1 -0
  541. package/dist/templates/trellis/config.yaml +90 -0
  542. package/dist/templates/trellis/gitignore.txt +32 -0
  543. package/dist/templates/trellis/index.d.ts +52 -0
  544. package/dist/templates/trellis/index.d.ts.map +1 -0
  545. package/dist/templates/trellis/index.js +97 -0
  546. package/dist/templates/trellis/index.js.map +1 -0
  547. package/dist/templates/trellis/scripts/__init__.py +5 -0
  548. package/dist/templates/trellis/scripts/add_session.py +547 -0
  549. package/dist/templates/trellis/scripts/common/__init__.py +92 -0
  550. package/dist/templates/trellis/scripts/common/active_task.py +626 -0
  551. package/dist/templates/trellis/scripts/common/cli_adapter.py +811 -0
  552. package/dist/templates/trellis/scripts/common/config.py +445 -0
  553. package/dist/templates/trellis/scripts/common/developer.py +190 -0
  554. package/dist/templates/trellis/scripts/common/git.py +31 -0
  555. package/dist/templates/trellis/scripts/common/git_context.py +106 -0
  556. package/dist/templates/trellis/scripts/common/io.py +37 -0
  557. package/dist/templates/trellis/scripts/common/log.py +45 -0
  558. package/dist/templates/trellis/scripts/common/packages_context.py +238 -0
  559. package/dist/templates/trellis/scripts/common/paths.py +447 -0
  560. package/dist/templates/trellis/scripts/common/safe_commit.py +285 -0
  561. package/dist/templates/trellis/scripts/common/session_context.py +821 -0
  562. package/dist/templates/trellis/scripts/common/task_context.py +223 -0
  563. package/dist/templates/trellis/scripts/common/task_queue.py +188 -0
  564. package/dist/templates/trellis/scripts/common/task_store.py +698 -0
  565. package/dist/templates/trellis/scripts/common/task_utils.py +274 -0
  566. package/dist/templates/trellis/scripts/common/tasks.py +112 -0
  567. package/dist/templates/trellis/scripts/common/trellis_config.py +131 -0
  568. package/dist/templates/trellis/scripts/common/types.py +110 -0
  569. package/dist/templates/trellis/scripts/common/workflow_phase.py +212 -0
  570. package/dist/templates/trellis/scripts/get_context.py +16 -0
  571. package/dist/templates/trellis/scripts/get_developer.py +26 -0
  572. package/dist/templates/trellis/scripts/hooks/linear_sync.py +243 -0
  573. package/dist/templates/trellis/scripts/init_developer.py +51 -0
  574. package/dist/templates/trellis/scripts/task.py +500 -0
  575. package/dist/templates/trellis/tasks/.gitkeep +0 -0
  576. package/dist/templates/trellis/workflow.md +690 -0
  577. package/dist/types/ai-tools.d.ts +95 -0
  578. package/dist/types/ai-tools.d.ts.map +1 -0
  579. package/dist/types/ai-tools.js +280 -0
  580. package/dist/types/ai-tools.js.map +1 -0
  581. package/dist/types/migration.d.ts +125 -0
  582. package/dist/types/migration.d.ts.map +1 -0
  583. package/dist/types/migration.js +8 -0
  584. package/dist/types/migration.js.map +1 -0
  585. package/dist/utils/compare-versions.d.ts +12 -0
  586. package/dist/utils/compare-versions.d.ts.map +1 -0
  587. package/dist/utils/compare-versions.js +86 -0
  588. package/dist/utils/compare-versions.js.map +1 -0
  589. package/dist/utils/cwd-guard.d.ts +38 -0
  590. package/dist/utils/cwd-guard.d.ts.map +1 -0
  591. package/dist/utils/cwd-guard.js +62 -0
  592. package/dist/utils/cwd-guard.js.map +1 -0
  593. package/dist/utils/file-writer.d.ts +36 -0
  594. package/dist/utils/file-writer.d.ts.map +1 -0
  595. package/dist/utils/file-writer.js +203 -0
  596. package/dist/utils/file-writer.js.map +1 -0
  597. package/dist/utils/manifest-prune.d.ts +61 -0
  598. package/dist/utils/manifest-prune.d.ts.map +1 -0
  599. package/dist/utils/manifest-prune.js +136 -0
  600. package/dist/utils/manifest-prune.js.map +1 -0
  601. package/dist/utils/posix.d.ts +13 -0
  602. package/dist/utils/posix.d.ts.map +1 -0
  603. package/dist/utils/posix.js +15 -0
  604. package/dist/utils/posix.js.map +1 -0
  605. package/dist/utils/project-detector.d.ts +46 -0
  606. package/dist/utils/project-detector.d.ts.map +1 -0
  607. package/dist/utils/project-detector.js +666 -0
  608. package/dist/utils/project-detector.js.map +1 -0
  609. package/dist/utils/proxy.d.ts +25 -0
  610. package/dist/utils/proxy.d.ts.map +1 -0
  611. package/dist/utils/proxy.js +60 -0
  612. package/dist/utils/proxy.js.map +1 -0
  613. package/dist/utils/task-json.d.ts +13 -0
  614. package/dist/utils/task-json.d.ts.map +1 -0
  615. package/dist/utils/task-json.js +12 -0
  616. package/dist/utils/task-json.js.map +1 -0
  617. package/dist/utils/template-fetcher.d.ts +150 -0
  618. package/dist/utils/template-fetcher.d.ts.map +1 -0
  619. package/dist/utils/template-fetcher.js +907 -0
  620. package/dist/utils/template-fetcher.js.map +1 -0
  621. package/dist/utils/template-hash.d.ts +123 -0
  622. package/dist/utils/template-hash.d.ts.map +1 -0
  623. package/dist/utils/template-hash.js +334 -0
  624. package/dist/utils/template-hash.js.map +1 -0
  625. package/dist/utils/uninstall-scrubbers.d.ts +66 -0
  626. package/dist/utils/uninstall-scrubbers.d.ts.map +1 -0
  627. package/dist/utils/uninstall-scrubbers.js +342 -0
  628. package/dist/utils/uninstall-scrubbers.js.map +1 -0
  629. package/package.json +90 -0
@@ -0,0 +1,1466 @@
1
+ import { execSync } from "node:child_process";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import readline from "node:readline";
5
+ import chalk from "chalk";
6
+ import figlet from "figlet";
7
+ import inquirer from "inquirer";
8
+ import { createWorkflowStructure } from "../configurators/workflow.js";
9
+ import { getInitToolChoices, resolveCliFlag, configurePlatform, getConfiguredPlatforms, getPlatformsWithPythonHooks, } from "../configurators/index.js";
10
+ import { getPythonCommandForPlatform, setResolvedPythonCommand, } from "../configurators/shared.js";
11
+ import { AI_TOOLS } from "../types/ai-tools.js";
12
+ import { DIR_NAMES, FILE_NAMES, PATHS } from "../constants/paths.js";
13
+ import { VERSION } from "../constants/version.js";
14
+ import { agentsMdContent } from "../templates/markdown/index.js";
15
+ import { setWriteMode, startRecordingWrites, stopRecordingWrites, writeFile, } from "../utils/file-writer.js";
16
+ import { emptyTaskJson } from "../utils/task-json.js";
17
+ import { detectProjectType, detectMonorepo, sanitizePkgName, } from "../utils/project-detector.js";
18
+ import { initializeHashes } from "../utils/template-hash.js";
19
+ import { isCwdHomedir, homedirGuardMessage, homedirBypassEnabled, } from "../utils/cwd-guard.js";
20
+ import { fetchTemplateIndex, probeRegistryIndex, downloadTemplateById, downloadRegistryDirect, parseRegistrySource, TIMEOUTS, TEMPLATE_INDEX_URL, } from "../utils/template-fetcher.js";
21
+ import { setupProxy, maskProxyUrl } from "../utils/proxy.js";
22
+ const MIN_PYTHON_MAJOR = 3;
23
+ const MIN_PYTHON_MINOR = 9;
24
+ const PYTHON_VERSION_RE = /Python (\d+)\.(\d+)/;
25
+ export function isSupportedPythonVersion(versionOutput) {
26
+ const match = versionOutput.match(PYTHON_VERSION_RE);
27
+ if (!match)
28
+ return false;
29
+ const major = Number(match[1]);
30
+ const minor = Number(match[2]);
31
+ return (major > MIN_PYTHON_MAJOR ||
32
+ (major === MIN_PYTHON_MAJOR && minor >= MIN_PYTHON_MINOR));
33
+ }
34
+ function detectPythonVersion(command) {
35
+ try {
36
+ return execSync(`${command} --version`, {
37
+ encoding: "utf-8",
38
+ stdio: "pipe",
39
+ }).trim();
40
+ }
41
+ catch (err) {
42
+ const code = err?.code;
43
+ if (code === "EPERM" || code === "EACCES") {
44
+ return "sandbox-restricted";
45
+ }
46
+ return null;
47
+ }
48
+ }
49
+ export function requireSupportedPython(command) {
50
+ // Final escape hatch — set when the user knows python3 is on PATH but
51
+ // the probe keeps failing for environment-specific reasons.
52
+ if (process.env.TRELLIS_SKIP_PYTHON_CHECK === "1") {
53
+ return `version check skipped (TRELLIS_SKIP_PYTHON_CHECK=1)`;
54
+ }
55
+ const versionOutput = detectPythonVersion(command);
56
+ if (versionOutput === "sandbox-restricted") {
57
+ console.warn(chalk.yellow(`⚠ Python version check skipped — sandboxed environment blocked ` +
58
+ `child_process spawn (EPERM/EACCES). Assuming "${command}" is on ` +
59
+ `PATH. If init fails later, re-run on the host or set ` +
60
+ `TRELLIS_SKIP_PYTHON_CHECK=1.`));
61
+ return `version unknown (sandbox-restricted)`;
62
+ }
63
+ if (!versionOutput) {
64
+ throw new Error(`Python command "${command}" not found. Trellis init requires Python ≥ 3.9.`);
65
+ }
66
+ if (!isSupportedPythonVersion(versionOutput)) {
67
+ throw new Error(`${versionOutput} detected via "${command}", but Trellis init requires Python ≥ 3.9.`);
68
+ }
69
+ return versionOutput;
70
+ }
71
+ /**
72
+ * Candidate Python command list per platform.
73
+ *
74
+ * Windows: `python` is the usual python.org installer choice, but Microsoft
75
+ * Store ships `python3`, and the `py` launcher is `py -3`. We try all three
76
+ * before giving up — fixes #236 where users with only `python3` (not
77
+ * `python`) had `trellis init` fail outright.
78
+ *
79
+ * Non-Windows: `python3` is canonical; `python` is a fallback for systems
80
+ * where Python 3 is the only Python and is named `python` (some Arch
81
+ * configs, conda envs).
82
+ */
83
+ const PYTHON_CANDIDATES = {
84
+ win32: ["python", "python3", "py -3"],
85
+ other: ["python3", "python"],
86
+ };
87
+ /**
88
+ * Detect a working Python ≥ 3.9 command on the host platform.
89
+ *
90
+ * Honors `TRELLIS_PYTHON_CMD` (explicit override, no probe) and
91
+ * `TRELLIS_SKIP_PYTHON_CHECK=1` (skip probe, trust platform default).
92
+ *
93
+ * Otherwise tries each candidate in `PYTHON_CANDIDATES` in order and returns
94
+ * the first whose `--version` matches `Python ≥ 3.9`. Caches the result via
95
+ * `setResolvedPythonCommand` so all downstream template / configurator
96
+ * writes pick up the resolved value.
97
+ *
98
+ * Throws a helpful, Windows-aware error if no candidate works.
99
+ */
100
+ export function resolveSupportedPython() {
101
+ // Explicit override — user knows their environment.
102
+ const override = process.env.TRELLIS_PYTHON_CMD?.trim();
103
+ if (override) {
104
+ setResolvedPythonCommand(override);
105
+ return { command: override, version: "set via TRELLIS_PYTHON_CMD" };
106
+ }
107
+ // Skip probe entirely.
108
+ if (process.env.TRELLIS_SKIP_PYTHON_CHECK === "1") {
109
+ const fallback = getPythonCommandForPlatform();
110
+ setResolvedPythonCommand(fallback);
111
+ return {
112
+ command: fallback,
113
+ version: "version check skipped (TRELLIS_SKIP_PYTHON_CHECK=1)",
114
+ };
115
+ }
116
+ const candidates = process.platform === "win32"
117
+ ? PYTHON_CANDIDATES.win32
118
+ : PYTHON_CANDIDATES.other;
119
+ const probeFailures = [];
120
+ for (const candidate of candidates) {
121
+ const probe = detectPythonVersion(candidate);
122
+ if (probe === "sandbox-restricted") {
123
+ console.warn(chalk.yellow(`⚠ Python version check skipped — sandboxed environment blocked ` +
124
+ `child_process spawn (EPERM/EACCES). Assuming "${candidate}" is ` +
125
+ `on PATH. If init fails later, re-run on the host or set ` +
126
+ `TRELLIS_SKIP_PYTHON_CHECK=1.`));
127
+ setResolvedPythonCommand(candidate);
128
+ return {
129
+ command: candidate,
130
+ version: "version unknown (sandbox-restricted)",
131
+ };
132
+ }
133
+ if (!probe) {
134
+ probeFailures.push(`${candidate}: not found`);
135
+ continue;
136
+ }
137
+ if (!isSupportedPythonVersion(probe)) {
138
+ probeFailures.push(`${candidate}: ${probe} (< 3.9)`);
139
+ continue;
140
+ }
141
+ setResolvedPythonCommand(candidate);
142
+ return { command: candidate, version: probe };
143
+ }
144
+ const isWindows = process.platform === "win32";
145
+ const installHint = isWindows
146
+ ? `Install Python ≥ 3.9 from https://www.python.org/downloads/windows/ — make sure ` +
147
+ `"Add Python to PATH" is checked in the installer. Or, if Python is ` +
148
+ `installed under a different name, set TRELLIS_PYTHON_CMD=<your-cmd> ` +
149
+ `before re-running init (e.g. \`set TRELLIS_PYTHON_CMD=py -3\`).`
150
+ : `Install Python ≥ 3.9 from https://www.python.org/downloads/ or via your ` +
151
+ `package manager. Or set TRELLIS_PYTHON_CMD=<your-cmd> before re-running.`;
152
+ throw new Error(`No supported Python command found. Tried: ${candidates.join(", ")}.\n` +
153
+ `Probe results:\n ${probeFailures.join("\n ")}\n\n` +
154
+ `Trellis init requires Python ≥ 3.9. ${installHint}\n` +
155
+ `Last-resort escape hatch: set TRELLIS_SKIP_PYTHON_CHECK=1 to skip the probe entirely.`);
156
+ }
157
+ function getOsDisplayName(platform = process.platform) {
158
+ switch (platform) {
159
+ case "win32":
160
+ return "Windows";
161
+ case "darwin":
162
+ return "macOS";
163
+ case "linux":
164
+ return "Linux";
165
+ default:
166
+ return platform;
167
+ }
168
+ }
169
+ function logPythonAdaptationNotice(command) {
170
+ const osName = getOsDisplayName();
171
+ console.log(chalk.blue(`📌 ${osName} detected: Trellis rendered Python commands as "${command}" in generated hooks, settings, and help text`));
172
+ }
173
+ // =============================================================================
174
+ // Bootstrap Task Creation
175
+ // =============================================================================
176
+ const BOOTSTRAP_TASK_NAME = "00-bootstrap-guidelines";
177
+ /**
178
+ * Slugify a developer name for safe use in task directory names.
179
+ *
180
+ * Unlike `sanitizePkgName` (which only strips npm @scope/ prefixes), this
181
+ * handles arbitrary developer input: spaces, Unicode letters, punctuation,
182
+ * path separators. Returns "user" fallback when input slugifies to empty.
183
+ *
184
+ * Exported for unit testing; not part of the public API.
185
+ */
186
+ export function slugifyDeveloperName(name) {
187
+ const slug = name
188
+ .toLowerCase()
189
+ .normalize("NFKD")
190
+ .replace(/[^\p{Letter}\p{Number}]+/gu, "-")
191
+ .replace(/^-+|-+$/g, "");
192
+ return slug || "user";
193
+ }
194
+ /**
195
+ * Write a task skeleton (task.json + prd.md).
196
+ *
197
+ * Idempotent: if the task dir already exists, returns true without touching
198
+ * anything. Shared by both creator bootstrap and joiner onboarding flows.
199
+ */
200
+ function writeTaskSkeleton(cwd, taskName, taskJson, prdContent) {
201
+ const taskDir = path.join(cwd, PATHS.TASKS, taskName);
202
+ if (fs.existsSync(taskDir))
203
+ return true; // idempotent
204
+ try {
205
+ fs.mkdirSync(taskDir, { recursive: true });
206
+ fs.writeFileSync(path.join(taskDir, FILE_NAMES.TASK_JSON), JSON.stringify(taskJson, null, 2), "utf-8");
207
+ fs.writeFileSync(path.join(taskDir, FILE_NAMES.PRD), prdContent, "utf-8");
208
+ return true;
209
+ }
210
+ catch {
211
+ return false;
212
+ }
213
+ }
214
+ /**
215
+ * Compute the bootstrap checklist items (previously stored as structured
216
+ * `subtasks: [{name, status}]` in task.json). Per task 04-21-task-schema-unify
217
+ * (D1), these live as markdown `- [ ]` items in prd.md instead, so task.json
218
+ * stays canonical with `subtasks: string[]` (child task dir names, same as
219
+ * task_store.py).
220
+ */
221
+ function getBootstrapChecklistItems(projectType, packages) {
222
+ if (packages && packages.length > 0) {
223
+ const items = packages.map((pkg) => `Fill guidelines for ${pkg.name}`);
224
+ items.push("Add code examples");
225
+ return items;
226
+ }
227
+ if (projectType === "frontend") {
228
+ return ["Fill frontend guidelines", "Add code examples"];
229
+ }
230
+ if (projectType === "backend") {
231
+ return ["Fill backend guidelines", "Add code examples"];
232
+ }
233
+ return [
234
+ "Fill backend guidelines",
235
+ "Fill frontend guidelines",
236
+ "Add code examples",
237
+ ];
238
+ }
239
+ function getBootstrapRelatedFiles(projectType, packages) {
240
+ if (packages && packages.length > 0) {
241
+ return packages.map((pkg) => `.trellis/spec/${sanitizePkgName(pkg.name)}/`);
242
+ }
243
+ if (projectType === "frontend") {
244
+ return [".trellis/spec/frontend/"];
245
+ }
246
+ if (projectType === "backend") {
247
+ return [".trellis/spec/backend/"];
248
+ }
249
+ return [".trellis/spec/backend/", ".trellis/spec/frontend/"];
250
+ }
251
+ function getBootstrapPrdContent(projectType, pythonCmd, packages) {
252
+ const checklistItems = getBootstrapChecklistItems(projectType, packages);
253
+ const checklistMarkdown = checklistItems
254
+ .map((item) => `- [ ] ${item}`)
255
+ .join("\n");
256
+ const header = `# Bootstrap Task: Fill Project Development Guidelines
257
+
258
+ **You (the AI) are running this task. The developer does not read this file.**
259
+
260
+ The developer just ran \`trellis init\` on this project for the first time.
261
+ \`.trellis/\` now exists with empty spec scaffolding, and this bootstrap task
262
+ exists under \`.trellis/tasks/\`. When they want to work on it, they should start
263
+ this task from a session that provides Trellis session identity.
264
+
265
+ **Your job**: help them populate \`.trellis/spec/\` with the team's real
266
+ coding conventions. Every future AI session — this project's
267
+ \`trellis-implement\` and \`trellis-check\` sub-agents — auto-loads spec files
268
+ listed in per-task jsonl manifests. Empty spec = sub-agents write generic
269
+ code. Real spec = sub-agents match the team's actual patterns.
270
+
271
+ Don't dump instructions. Open with a short greeting, figure out if the repo
272
+ has any existing convention docs (CLAUDE.md, .cursorrules, etc.), and drive
273
+ the rest conversationally.
274
+
275
+ ---
276
+
277
+ ## Status (update the checkboxes as you complete each item)
278
+
279
+ ${checklistMarkdown}
280
+
281
+ ---
282
+
283
+ ## Spec files to populate
284
+ `;
285
+ const backendSection = `
286
+
287
+ ### Backend guidelines
288
+
289
+ | File | What to document |
290
+ |------|------------------|
291
+ | \`.trellis/spec/backend/directory-structure.md\` | Where different file types go (routes, services, utils) |
292
+ | \`.trellis/spec/backend/database-guidelines.md\` | ORM, migrations, query patterns, naming conventions |
293
+ | \`.trellis/spec/backend/error-handling.md\` | How errors are caught, logged, and returned |
294
+ | \`.trellis/spec/backend/logging-guidelines.md\` | Log levels, format, what to log |
295
+ | \`.trellis/spec/backend/quality-guidelines.md\` | Code review standards, testing requirements |
296
+ `;
297
+ const frontendSection = `
298
+
299
+ ### Frontend guidelines
300
+
301
+ | File | What to document |
302
+ |------|------------------|
303
+ | \`.trellis/spec/frontend/directory-structure.md\` | Component/page/hook organization |
304
+ | \`.trellis/spec/frontend/component-guidelines.md\` | Component patterns, props conventions |
305
+ | \`.trellis/spec/frontend/hook-guidelines.md\` | Custom hook naming, patterns |
306
+ | \`.trellis/spec/frontend/state-management.md\` | State library, patterns, what goes where |
307
+ | \`.trellis/spec/frontend/type-safety.md\` | TypeScript conventions, type organization |
308
+ | \`.trellis/spec/frontend/quality-guidelines.md\` | Linting, testing, accessibility |
309
+ `;
310
+ const footer = `
311
+
312
+ ### Thinking guides (already populated)
313
+
314
+ \`.trellis/spec/guides/\` contains general thinking guides pre-filled with
315
+ best practices. Customize only if something clearly doesn't fit this project.
316
+
317
+ ---
318
+
319
+ ## How to fill the spec
320
+
321
+ ### Step 1: Import from existing convention files first (preferred)
322
+
323
+ Search the repo for existing convention docs. If any exist, read them and
324
+ extract the relevant rules into the matching \`.trellis/spec/\` files —
325
+ usually much faster than documenting from scratch.
326
+
327
+ | File / Directory | Tool |
328
+ |------|------|
329
+ | \`CLAUDE.md\` / \`CLAUDE.local.md\` | Claude Code |
330
+ | \`AGENTS.md\` | Codex / Claude Code / agent-compatible tools |
331
+ | \`.cursorrules\` | Cursor |
332
+ | \`.cursor/rules/*.mdc\` | Cursor (rules directory) |
333
+ | \`.windsurfrules\` | Windsurf |
334
+ | \`.clinerules\` | Cline |
335
+ | \`.roomodes\` | Roo Code |
336
+ | \`.github/copilot-instructions.md\` | GitHub Copilot |
337
+ | \`.vscode/settings.json\` → \`github.copilot.chat.codeGeneration.instructions\` | VS Code Copilot |
338
+ | \`CONVENTIONS.md\` / \`.aider.conf.yml\` | aider |
339
+ | \`CONTRIBUTING.md\` | General project conventions |
340
+ | \`.editorconfig\` | Editor formatting rules |
341
+
342
+ ### Step 2: Analyze the codebase for anything not covered by existing docs
343
+
344
+ Scan real code to discover patterns. Before writing each spec file:
345
+ - Find 2-3 real examples of each pattern in the codebase.
346
+ - Reference real file paths (not hypothetical ones).
347
+ - Document anti-patterns the team clearly avoids.
348
+
349
+ ### Step 3: Document reality, not ideals
350
+
351
+ **Critical**: write what the code *actually does*, not what it should do.
352
+ Sub-agents match the spec, so aspirational patterns that don't exist in the
353
+ codebase will cause sub-agents to write code that looks out of place.
354
+
355
+ If the team has known tech debt, document the current state — improvement
356
+ is a separate conversation, not a bootstrap concern.
357
+
358
+ ---
359
+
360
+ ## Quick explainer of the runtime (share when they ask "why do we need spec at all")
361
+
362
+ - Every AI coding task spawns two sub-agents: \`trellis-implement\` (writes
363
+ code) and \`trellis-check\` (verifies quality).
364
+ - Each task has \`implement.jsonl\` / \`check.jsonl\` manifests listing which
365
+ spec files to load.
366
+ - The platform hook auto-injects those spec files + the task's \`prd.md\`
367
+ into every sub-agent prompt, so the sub-agent codes/reviews per team
368
+ conventions without anyone pasting them manually.
369
+ - Source of truth: \`.trellis/spec/\`. That's why filling it well now pays
370
+ off forever.
371
+
372
+ ---
373
+
374
+ ## Completion
375
+
376
+ When the developer confirms the checklist items above are done with real
377
+ examples (not placeholders), guide them to run:
378
+
379
+ \`\`\`bash
380
+ ${pythonCmd} ./.trellis/scripts/task.py finish
381
+ ${pythonCmd} ./.trellis/scripts/task.py archive 00-bootstrap-guidelines
382
+ \`\`\`
383
+
384
+ After archive, every new developer who joins this project will get a
385
+ \`00-join-<slug>\` onboarding task instead of this bootstrap task.
386
+
387
+ ---
388
+
389
+ ## Suggested opening line
390
+
391
+ "Welcome to Trellis! Your init just set me up to help you fill the project
392
+ spec — a one-time setup so every future AI session follows the team's
393
+ conventions instead of writing generic code. Before we start, do you have
394
+ any existing convention docs (CLAUDE.md, .cursorrules, CONTRIBUTING.md,
395
+ etc.) I can pull from, or should I scan the codebase from scratch?"
396
+ `;
397
+ let content = header;
398
+ if (packages && packages.length > 0) {
399
+ // Monorepo: generate per-package sections
400
+ for (const pkg of packages) {
401
+ const pkgType = pkg.type === "unknown" ? "fullstack" : pkg.type;
402
+ const specName = sanitizePkgName(pkg.name);
403
+ content += `\n### Package: ${pkg.name} (\`spec/${specName}/\`)\n`;
404
+ if (pkgType !== "frontend") {
405
+ content += `\n- Backend guidelines: \`.trellis/spec/${specName}/backend/\`\n`;
406
+ }
407
+ if (pkgType !== "backend") {
408
+ content += `\n- Frontend guidelines: \`.trellis/spec/${specName}/frontend/\`\n`;
409
+ }
410
+ }
411
+ }
412
+ else if (projectType === "frontend") {
413
+ content += frontendSection;
414
+ }
415
+ else if (projectType === "backend") {
416
+ content += backendSection;
417
+ }
418
+ else {
419
+ // fullstack
420
+ content += backendSection;
421
+ content += frontendSection;
422
+ }
423
+ content += footer;
424
+ return content;
425
+ }
426
+ function getBootstrapTaskJson(developer, projectType, packages) {
427
+ const today = new Date().toISOString().split("T")[0];
428
+ const relatedFiles = getBootstrapRelatedFiles(projectType, packages);
429
+ // Canonical 24-field shape via emptyTaskJson factory.
430
+ // Checklist items (previously stored as structured `subtasks`) are now
431
+ // rendered as `- [ ]` items in prd.md; task.json.subtasks is always
432
+ // string[] (child task dir names) per the canonical schema.
433
+ return emptyTaskJson({
434
+ id: BOOTSTRAP_TASK_NAME,
435
+ name: BOOTSTRAP_TASK_NAME,
436
+ title: "Bootstrap Guidelines",
437
+ description: "Fill in project development guidelines for AI agents",
438
+ status: "in_progress",
439
+ dev_type: "docs",
440
+ priority: "P1",
441
+ creator: developer,
442
+ assignee: developer,
443
+ createdAt: today,
444
+ relatedFiles,
445
+ notes: `First-time setup task created by trellis init (${projectType} project)`,
446
+ });
447
+ }
448
+ /**
449
+ * Create bootstrap task for first-time setup
450
+ */
451
+ function createBootstrapTask(cwd, developer, pythonCmd, projectType, packages) {
452
+ const taskJson = getBootstrapTaskJson(developer, projectType, packages);
453
+ const prdContent = getBootstrapPrdContent(projectType, pythonCmd, packages);
454
+ return writeTaskSkeleton(cwd, BOOTSTRAP_TASK_NAME, taskJson, prdContent);
455
+ }
456
+ // =============================================================================
457
+ // Joiner Onboarding Task Creation
458
+ // =============================================================================
459
+ /**
460
+ * task.json factory for joiner onboarding. Mirrors the bootstrap factory but
461
+ * uses dev_type "docs", higher priority "P1", and the developer-specific task
462
+ * name (so multiple joiners in the same checkout don't collide).
463
+ */
464
+ function getJoinerTaskJson(developer, taskName) {
465
+ const today = new Date().toISOString().split("T")[0];
466
+ return emptyTaskJson({
467
+ id: taskName,
468
+ name: taskName,
469
+ title: `Joining: Onboard to this Trellis project (${developer})`,
470
+ description: "Onboard a new developer to an existing Trellis project: learn the workflow, conventions, and find assigned work",
471
+ status: "in_progress",
472
+ dev_type: "docs",
473
+ priority: "P1",
474
+ creator: developer,
475
+ assignee: developer,
476
+ createdAt: today,
477
+ notes: "Generated by trellis init for a new developer joining an existing Trellis project",
478
+ });
479
+ }
480
+ /**
481
+ * PRD content for joiner onboarding. Kept concise (~80 lines) — deeper
482
+ * guidance lives in skills and docs.
483
+ */
484
+ function getJoinerPrdContent(developer, pythonCmd) {
485
+ const slug = slugifyDeveloperName(developer);
486
+ return `# Joiner Onboarding Task
487
+
488
+ **You (the AI) are running this task. The developer does not read this file.**
489
+
490
+ \`${developer}\` just ran \`trellis init\` on a fresh clone, saw "Developer
491
+ initialized", and will now start asking you questions in chat. This joiner task
492
+ exists under \`.trellis/tasks/\`; when they want to work on it, they should
493
+ start it from a session that provides Trellis session identity.
494
+
495
+ Your job is to orient them to Trellis. Don't dump all of this at them — open
496
+ with a short greeting, ask where they want to start, and fill in the rest as
497
+ they engage.
498
+
499
+ ---
500
+
501
+ ## Topics to cover (adapt order to their questions)
502
+
503
+ ### 1. What Trellis is + the workflow
504
+
505
+ Trellis is a workflow layer over Claude Code / Cursor / etc. that keeps AI
506
+ agents consistent with project-specific conventions instead of writing generic
507
+ code every session.
508
+
509
+ - **Three phases**: Plan (brainstorm → \`prd.md\`) → Execute (code + check) →
510
+ Finish (capture + wrap). Full reference: \`.trellis/workflow.md\`.
511
+ - **Task lifecycle**: planning → in_progress → done → archive, under
512
+ \`.trellis/tasks/\`.
513
+ - **Core slash commands**:
514
+ - \`/trellis:continue\` — resume the current session's active task
515
+ - \`/trellis:finish-work\` — wrap up a finished task
516
+ - \`/trellis:start\` — session boot from scratch (not needed here; the
517
+ SessionStart hook does its job automatically)
518
+
519
+ ### 2. Runtime mechanics (explain when they ask "how does it know what to do")
520
+
521
+ - **SessionStart hook** runs \`get_context.py\` and injects identity, git
522
+ status, session active task, active tasks, and workflow phase into the AI
523
+ conversation at every session start.
524
+ - **\`<workflow-state>\` tag** is auto-injected with every user message,
525
+ carrying the current task + phase hint.
526
+ - **\`/trellis:continue\`** loads the Phase Index, reads \`prd.md\` + recent
527
+ activity, and routes to the right skill (\`trellis-brainstorm\` for planning,
528
+ \`trellis-implement\` for coding, \`trellis-check\` for verification).
529
+ - **\`trellis-implement\` sub-agent** is spawned when code needs to be written.
530
+ The platform hook reads \`{TASK_DIR}/implement.jsonl\` and auto-injects those
531
+ spec files + \`prd.md\` into the sub-agent's prompt so it codes per project
532
+ conventions.
533
+ - **\`trellis-check\` sub-agent** follows the same pattern with \`check.jsonl\`
534
+ — reviews changes against specs, auto-fixes issues, runs lint/typecheck.
535
+
536
+ File layout (mention when they ask "where does what live"):
537
+ - \`.trellis/.runtime/sessions/<session>.json\` — session active-task state, gitignored
538
+ - \`.trellis/tasks/<task>/{implement,check}.jsonl\` — per-task context manifests
539
+ - \`.trellis/spec/\` — project-wide conventions (source of truth)
540
+ - \`.trellis/workspace/${developer}/journal-*.md\` — their session log,
541
+ rotated at ~2000 lines
542
+
543
+ ### 3. This project's actual conventions
544
+
545
+ - Summarize \`.trellis/spec/\` for them — what coding conventions this
546
+ specific team enforces.
547
+ - Point at the last 5 entries in \`.trellis/tasks/archive/\` as a rhythm
548
+ example of how people actually work here. **If archive is empty** (the
549
+ project just started), skip this — don't invent examples.
550
+ - Not your job in this onboarding to teach them the business code itself —
551
+ the README and their teammates handle that.
552
+
553
+ ### 4. Their assigned work
554
+
555
+ - Check if \`.trellis/workspace/${developer}/\` already exists — if yes, it's
556
+ their journal from another machine and worth mentioning.
557
+ - Run \`${pythonCmd} ./.trellis/scripts/task.py list --assignee ${developer}\` to
558
+ show tasks assigned to them. (Quote the name if it contains spaces.)
559
+ - Remind them that the "My Tasks" section appears in the SessionStart context
560
+ on every new session.
561
+
562
+ ---
563
+
564
+ ## Optional: walk through a small task end-to-end
565
+
566
+ If they want to practice before touching real work, offer to pick a tiny
567
+ P3 task or a typo fix and run the full cycle together: \`/trellis:continue\`
568
+ → you implement via sub-agents → \`/trellis:finish-work\`.
569
+
570
+ ---
571
+
572
+ ## Completion
573
+
574
+ When they feel oriented (or after you've covered the four topics with
575
+ reasonable back-and-forth), guide them to run:
576
+
577
+ \`\`\`bash
578
+ ${pythonCmd} ./.trellis/scripts/task.py finish
579
+ ${pythonCmd} ./.trellis/scripts/task.py archive 00-join-${slug}
580
+ \`\`\`
581
+
582
+ ---
583
+
584
+ ## Suggested opening line
585
+
586
+ "Welcome! Your \`trellis init\` set me up to onboard you to this project. I
587
+ can walk you through the workflow, show you the runtime mechanics under the
588
+ hood, summarize the team's spec, or jump to what you're already curious about
589
+ — which would you prefer?"
590
+ `;
591
+ }
592
+ /**
593
+ * Create joiner onboarding task for a new developer on an existing Trellis
594
+ * project. Task name is slugified to be filesystem-safe for arbitrary
595
+ * developer names (spaces, Unicode, punctuation).
596
+ */
597
+ function createJoinerOnboardingTask(cwd, developer, pythonCmd) {
598
+ const slug = slugifyDeveloperName(developer);
599
+ const taskName = `00-join-${slug}`;
600
+ const taskJson = getJoinerTaskJson(developer, taskName);
601
+ const prdContent = getJoinerPrdContent(developer, pythonCmd);
602
+ return writeTaskSkeleton(cwd, taskName, taskJson, prdContent);
603
+ }
604
+ /**
605
+ * Handle re-init when .trellis/ already exists.
606
+ * Returns true if handled (caller should return), false if user chose full re-init.
607
+ */
608
+ async function handleReinit(cwd, options, developerName, pythonCmd) {
609
+ const TOOLS = getInitToolChoices();
610
+ const configuredPlatforms = getConfiguredPlatforms(cwd);
611
+ const configuredNames = [...configuredPlatforms]
612
+ .map((id) => AI_TOOLS[id].name)
613
+ .join(", ");
614
+ // Determine explicit platform flags
615
+ const explicitTools = TOOLS.filter((t) => options[t.key]).map((t) => t.key);
616
+ let doAddPlatforms = explicitTools.length > 0;
617
+ let doAddDeveloper = !!options.user;
618
+ let platformsToAdd = explicitTools;
619
+ // No explicit flags → show menu
620
+ if (!doAddPlatforms && !doAddDeveloper) {
621
+ if (options.yes) {
622
+ console.log(chalk.gray(`Already initialized with: ${configuredNames}`));
623
+ console.log(chalk.gray("Use platform flags (e.g., --codex) or -u <name> to add platforms/developer."));
624
+ return true;
625
+ }
626
+ console.log(chalk.gray(`\n Already initialized with: ${configuredNames}\n`));
627
+ const { action } = await inquirer.prompt([
628
+ {
629
+ type: "list",
630
+ name: "action",
631
+ message: "Trellis is already initialized. What would you like to do?",
632
+ choices: [
633
+ { name: "Add AI platform(s)", value: "add-platform" },
634
+ {
635
+ name: "Set up developer identity on this device",
636
+ value: "add-developer",
637
+ },
638
+ { name: "Full re-initialize", value: "full" },
639
+ ],
640
+ },
641
+ ]);
642
+ if (action === "full") {
643
+ return false; // Fall through to full init
644
+ }
645
+ if (action === "add-platform")
646
+ doAddPlatforms = true;
647
+ if (action === "add-developer")
648
+ doAddDeveloper = true;
649
+ }
650
+ // --- Add platforms ---
651
+ if (doAddPlatforms) {
652
+ if (platformsToAdd.length === 0) {
653
+ // Interactive: show only unconfigured platforms
654
+ const unconfigured = TOOLS.filter((t) => {
655
+ const pid = resolveCliFlag(t.key);
656
+ return pid && !configuredPlatforms.has(pid);
657
+ });
658
+ if (unconfigured.length === 0) {
659
+ console.log(chalk.green("✓ All available platforms are already configured."));
660
+ }
661
+ else {
662
+ const answers = await inquirer.prompt([
663
+ {
664
+ type: "checkbox",
665
+ name: "tools",
666
+ message: "Select platforms to add:",
667
+ choices: unconfigured.map((t) => ({
668
+ name: t.name,
669
+ value: t.key,
670
+ })),
671
+ },
672
+ ]);
673
+ platformsToAdd = answers.tools;
674
+ }
675
+ }
676
+ const reinitWritten = startRecordingWrites(cwd);
677
+ try {
678
+ for (const tool of platformsToAdd) {
679
+ const platformId = resolveCliFlag(tool);
680
+ if (platformId) {
681
+ if (configuredPlatforms.has(platformId)) {
682
+ console.log(chalk.gray(` ○ ${AI_TOOLS[platformId].name} already configured, skipping`));
683
+ }
684
+ else {
685
+ console.log(chalk.blue(`📝 Configuring ${AI_TOOLS[platformId].name}...`));
686
+ await configurePlatform(platformId, cwd);
687
+ }
688
+ }
689
+ }
690
+ }
691
+ finally {
692
+ stopRecordingWrites();
693
+ }
694
+ // Update template hashes. Merge mode: preserve previously-tracked
695
+ // platforms' hashes, layer in the newly-added platform's writes.
696
+ const hashedCount = initializeHashes(cwd, {
697
+ trackedPaths: reinitWritten,
698
+ merge: true,
699
+ });
700
+ if (hashedCount > 0) {
701
+ console.log(chalk.gray(`📋 Tracking ${hashedCount} template files for updates`));
702
+ }
703
+ }
704
+ // --- Add developer ---
705
+ if (doAddDeveloper) {
706
+ let devName = developerName;
707
+ if (!devName) {
708
+ devName = await askInput("Your name: ");
709
+ while (!devName) {
710
+ console.log(chalk.yellow("Name is required"));
711
+ devName = await askInput("Your name: ");
712
+ }
713
+ }
714
+ // Capture pre-init state: if .developer did not exist before we ran
715
+ // init_developer.py, this checkout had no identity → treat as a new
716
+ // joiner onboarding onto an existing Trellis project.
717
+ const hadDeveloperFileBefore = fs.existsSync(path.join(cwd, DIR_NAMES.WORKFLOW, FILE_NAMES.DEVELOPER));
718
+ try {
719
+ const scriptPath = path.join(cwd, PATHS.SCRIPTS, "init_developer.py");
720
+ execSync(`${pythonCmd} "${scriptPath}" "${devName}"`, {
721
+ cwd,
722
+ stdio: "pipe",
723
+ });
724
+ console.log(chalk.green(`✓ Developer "${devName}" initialized`));
725
+ }
726
+ catch {
727
+ console.log(chalk.yellow("⚠ Could not initialize developer. Run manually:"));
728
+ console.log(chalk.gray(` ${pythonCmd} .trellis/scripts/init_developer.py ${devName}`));
729
+ }
730
+ // Create joiner onboarding task for fresh checkouts (no prior .developer).
731
+ // Runs outside the init_developer try/catch so failures surface as warnings.
732
+ if (!hadDeveloperFileBefore) {
733
+ try {
734
+ if (!createJoinerOnboardingTask(cwd, devName, pythonCmd)) {
735
+ console.warn(chalk.yellow("⚠ Failed to create joiner onboarding task"));
736
+ }
737
+ }
738
+ catch (err) {
739
+ console.warn(chalk.yellow(`⚠ Joiner onboarding setup failed: ${err instanceof Error ? err.message : String(err)}`));
740
+ }
741
+ }
742
+ }
743
+ return true;
744
+ }
745
+ const _cliFlagCheck = true;
746
+ /**
747
+ * Write monorepo package configuration to config.yaml (non-destructive patch).
748
+ * Appends packages: and default_package: without disturbing existing config.
749
+ */
750
+ function writeMonorepoConfig(cwd, packages) {
751
+ const configPath = path.join(cwd, DIR_NAMES.WORKFLOW, "config.yaml");
752
+ let content = "";
753
+ try {
754
+ content = fs.readFileSync(configPath, "utf-8");
755
+ }
756
+ catch {
757
+ // Config not created yet; will be created by createWorkflowStructure
758
+ return;
759
+ }
760
+ // Don't overwrite if packages: already exists (re-init case)
761
+ if (/^packages\s*:/m.test(content)) {
762
+ return;
763
+ }
764
+ const lines = ["\n# Auto-detected monorepo packages", "packages:"];
765
+ for (const pkg of packages) {
766
+ lines.push(` ${sanitizePkgName(pkg.name)}:`);
767
+ lines.push(` path: ${pkg.path}`);
768
+ if (pkg.isSubmodule) {
769
+ lines.push(" type: submodule");
770
+ }
771
+ else if (pkg.isGitRepo) {
772
+ lines.push(" git: true");
773
+ }
774
+ }
775
+ // Use first non-submodule package as default, fallback to first package
776
+ const defaultPkg = packages.find((p) => !p.isSubmodule)?.name ?? packages[0]?.name;
777
+ if (defaultPkg) {
778
+ lines.push(`default_package: ${defaultPkg}`);
779
+ }
780
+ fs.writeFileSync(configPath, content.trimEnd() + "\n" + lines.join("\n") + "\n", "utf-8");
781
+ }
782
+ export async function init(options) {
783
+ // Refuse to run in $HOME — running here would scoop platform runtime data
784
+ // (Claude/Codex/OpenCode session histories etc.) into the trellis hash
785
+ // manifest, and a subsequent `trellis uninstall` would wipe it.
786
+ if (isCwdHomedir() && !homedirBypassEnabled()) {
787
+ console.error(chalk.red(homedirGuardMessage("init")));
788
+ process.exit(1);
789
+ }
790
+ const cwd = process.cwd();
791
+ const isFirstInit = !fs.existsSync(path.join(cwd, DIR_NAMES.WORKFLOW));
792
+ // Captured here (before createWorkflowStructure + init_developer run) so
793
+ // the three-branch dispatch at the bottom can tell "fresh clone joiner"
794
+ // (.trellis/ exists, .developer missing) apart from "creator first init".
795
+ const hadDeveloperFileAtStart = fs.existsSync(path.join(cwd, DIR_NAMES.WORKFLOW, FILE_NAMES.DEVELOPER));
796
+ // Generate ASCII art banner dynamically using FIGlet "Rebel" font
797
+ const banner = figlet.textSync("Trellis", { font: "Rebel" });
798
+ console.log(chalk.cyan(`\n${banner.trimEnd()}`));
799
+ console.log(chalk.gray("\n All-in-one AI framework & toolkit for Claude Code & Cursor\n"));
800
+ // Set up proxy before any network calls
801
+ const proxyUrl = setupProxy();
802
+ if (proxyUrl) {
803
+ console.log(chalk.gray(` Using proxy: ${maskProxyUrl(proxyUrl)}\n`));
804
+ }
805
+ // Set write mode based on options
806
+ let writeMode = "ask";
807
+ if (options.force) {
808
+ writeMode = "force";
809
+ console.log(chalk.gray("Mode: Force overwrite existing files\n"));
810
+ }
811
+ else if (options.skipExisting) {
812
+ writeMode = "skip";
813
+ console.log(chalk.gray("Mode: Skip existing files\n"));
814
+ }
815
+ else if (options.yes) {
816
+ // -y implies non-interactive: never prompt on conflicts. Default to skip
817
+ // (preserve user files) — explicit --force is required to overwrite.
818
+ writeMode = "skip";
819
+ console.log(chalk.gray("Mode: Non-interactive (skip existing files)\n"));
820
+ }
821
+ setWriteMode(writeMode);
822
+ // Detect developer name from git config or options
823
+ let developerName = options.user;
824
+ if (!developerName) {
825
+ // Only detect from git if current directory is a git repo
826
+ const isGitRepo = fs.existsSync(path.join(cwd, ".git"));
827
+ if (isGitRepo) {
828
+ try {
829
+ developerName = execSync("git config user.name", {
830
+ cwd,
831
+ encoding: "utf-8",
832
+ }).trim();
833
+ }
834
+ catch {
835
+ // Git not available or no user.name configured
836
+ }
837
+ }
838
+ }
839
+ if (developerName) {
840
+ console.log(chalk.blue("👤 Developer:"), chalk.gray(developerName));
841
+ }
842
+ const { command: pythonCmd } = resolveSupportedPython();
843
+ // ==========================================================================
844
+ // Re-init fast path: skip full flow when .trellis/ already exists
845
+ // ==========================================================================
846
+ // Aborted-init recovery (issue #204): if .trellis/ exists but tasks/ is
847
+ // empty, the previous init never reached bootstrap creation. Fall through
848
+ // to the full flow so the main-dispatch tasksEmpty fallback fires —
849
+ // handleReinit's joiner branch would otherwise mis-route the recovery.
850
+ const tasksDirEarly = path.join(cwd, PATHS.TASKS);
851
+ const tasksEmptyEarly = !fs.existsSync(tasksDirEarly) || fs.readdirSync(tasksDirEarly).length === 0;
852
+ if (!isFirstInit &&
853
+ !options.force &&
854
+ !options.skipExisting &&
855
+ !tasksEmptyEarly) {
856
+ const reinitDone = await handleReinit(cwd, options, developerName, pythonCmd);
857
+ if (reinitDone)
858
+ return;
859
+ // reinitDone === false means user chose "full re-initialize" → fall through
860
+ }
861
+ if (!developerName && !options.yes) {
862
+ // Ask for developer name if not detected and not in yes mode
863
+ console.log(chalk.gray("\nTrellis supports team collaboration - each developer has their own\n" +
864
+ `workspace directory (${PATHS.WORKSPACE}/{name}/) to track AI sessions.\n` +
865
+ "Tip: Usually this is your git username (git config user.name).\n"));
866
+ developerName = await askInput("Your name: ");
867
+ while (!developerName) {
868
+ console.log(chalk.yellow("Name is required"));
869
+ developerName = await askInput("Your name: ");
870
+ }
871
+ console.log(chalk.blue("👤 Developer:"), chalk.gray(developerName));
872
+ }
873
+ // Detect project type (silent - no output)
874
+ const detectedType = detectProjectType(cwd);
875
+ // Parse custom registry source early (needed by both monorepo + single-repo flows)
876
+ let registry;
877
+ if (options.registry) {
878
+ try {
879
+ registry = parseRegistrySource(options.registry);
880
+ }
881
+ catch (error) {
882
+ console.log(chalk.red(error instanceof Error ? error.message : "Invalid registry source"));
883
+ return;
884
+ }
885
+ }
886
+ // Determine template strategy from flags (needed before monorepo template downloads)
887
+ let templateStrategy = "skip";
888
+ if (options.overwrite) {
889
+ templateStrategy = "overwrite";
890
+ }
891
+ else if (options.append) {
892
+ templateStrategy = "append";
893
+ }
894
+ // ==========================================================================
895
+ // Monorepo Detection
896
+ // ==========================================================================
897
+ let monorepoPackages;
898
+ let remoteSpecPackages;
899
+ if (options.monorepo !== false) {
900
+ // options.monorepo: true = --monorepo, false = --no-monorepo, undefined = auto
901
+ const detected = detectMonorepo(cwd);
902
+ if (options.monorepo === true && !detected) {
903
+ console.log(chalk.red("Error: --monorepo specified but no multi-package layout detected."));
904
+ console.log("");
905
+ console.log(chalk.gray("Checked:"));
906
+ console.log(chalk.gray(" ✗ pnpm-workspace.yaml"));
907
+ console.log(chalk.gray(" ✗ package.json workspaces"));
908
+ console.log(chalk.gray(" ✗ Cargo.toml [workspace]"));
909
+ console.log(chalk.gray(" ✗ go.work"));
910
+ console.log(chalk.gray(" ✗ pyproject.toml [tool.uv.workspace]"));
911
+ console.log(chalk.gray(" ✗ .gitmodules"));
912
+ console.log(chalk.gray(" ✗ sibling .git directories (need ≥ 2)"));
913
+ console.log("");
914
+ console.log("To configure manually, add to .trellis/config.yaml:");
915
+ console.log("");
916
+ console.log(chalk.cyan(" packages:"));
917
+ console.log(chalk.cyan(" frontend:"));
918
+ console.log(chalk.cyan(" path: ./frontend"));
919
+ console.log(chalk.cyan(" git: true # if it has its own .git"));
920
+ console.log(chalk.cyan(" backend:"));
921
+ console.log(chalk.cyan(" path: ./backend"));
922
+ console.log(chalk.cyan(" git: true"));
923
+ return;
924
+ }
925
+ if (detected && detected.length > 0) {
926
+ let enableMonorepo = false;
927
+ if (options.monorepo === true || options.yes) {
928
+ enableMonorepo = true;
929
+ }
930
+ else {
931
+ // Show detected packages and ask
932
+ console.log(chalk.blue("\n🔍 Detected monorepo packages:"));
933
+ for (const pkg of detected) {
934
+ const tag = pkg.isSubmodule
935
+ ? chalk.gray(" (submodule)")
936
+ : pkg.isGitRepo
937
+ ? chalk.gray(" (git repo)")
938
+ : "";
939
+ console.log(chalk.gray(` - ${pkg.name}`) +
940
+ chalk.gray(` (${pkg.path})`) +
941
+ chalk.gray(` [${pkg.type}]`) +
942
+ tag);
943
+ }
944
+ console.log("");
945
+ const { useMonorepo } = await inquirer.prompt([
946
+ {
947
+ type: "confirm",
948
+ name: "useMonorepo",
949
+ message: "Enable monorepo mode?",
950
+ default: true,
951
+ },
952
+ ]);
953
+ enableMonorepo = useMonorepo;
954
+ }
955
+ if (enableMonorepo) {
956
+ monorepoPackages = detected;
957
+ remoteSpecPackages = new Set();
958
+ // Per-package template selection (unless -y mode: all use blank spec)
959
+ if (!options.yes && !options.template) {
960
+ for (const pkg of detected) {
961
+ const { specSource } = await inquirer.prompt([
962
+ {
963
+ type: "list",
964
+ name: "specSource",
965
+ message: `Spec source for ${pkg.name} (${pkg.path}):`,
966
+ choices: [
967
+ { name: "From scratch (Trellis default)", value: "blank" },
968
+ { name: "Download remote template", value: "remote" },
969
+ ],
970
+ default: "blank",
971
+ },
972
+ ]);
973
+ if (specSource === "remote") {
974
+ // Use existing template download flow, targeting spec/<name>/
975
+ const destDir = path.join(cwd, PATHS.SPEC, sanitizePkgName(pkg.name));
976
+ console.log(chalk.blue(`📦 Select template for ${pkg.name}...`));
977
+ // Fetch templates if not already done
978
+ const templates = await fetchTemplateIndex();
979
+ const specTemplates = templates
980
+ .filter((t) => t.type === "spec")
981
+ .map((t) => ({
982
+ name: `${t.id} (${t.name})`,
983
+ value: t.id,
984
+ }));
985
+ if (specTemplates.length > 0) {
986
+ const { templateId } = await inquirer.prompt([
987
+ {
988
+ type: "list",
989
+ name: "templateId",
990
+ message: `Select template for ${pkg.name}:`,
991
+ choices: specTemplates,
992
+ },
993
+ ]);
994
+ const result = await downloadTemplateById(cwd, templateId, templateStrategy, templates.find((t) => t.id === templateId), undefined, destDir);
995
+ if (result.success) {
996
+ console.log(chalk.green(` ${result.message}`));
997
+ remoteSpecPackages.add(sanitizePkgName(pkg.name));
998
+ }
999
+ else {
1000
+ console.log(chalk.yellow(` ${result.message}`));
1001
+ console.log(chalk.gray(" Falling back to blank spec..."));
1002
+ }
1003
+ }
1004
+ else {
1005
+ console.log(chalk.gray(" No templates available. Using blank spec."));
1006
+ }
1007
+ }
1008
+ }
1009
+ }
1010
+ else if (options.template) {
1011
+ // --template as default for all packages
1012
+ for (const pkg of detected) {
1013
+ const destDir = path.join(cwd, PATHS.SPEC, sanitizePkgName(pkg.name));
1014
+ const result = await downloadTemplateById(cwd, options.template, templateStrategy, undefined, registry, destDir);
1015
+ if (result.success && !result.skipped) {
1016
+ remoteSpecPackages.add(sanitizePkgName(pkg.name));
1017
+ }
1018
+ }
1019
+ }
1020
+ }
1021
+ }
1022
+ }
1023
+ // Tool definitions derived from platform registry
1024
+ const TOOLS = getInitToolChoices();
1025
+ // Build tools from explicit flags
1026
+ const explicitTools = TOOLS.filter((t) => options[t.key]).map((t) => t.key);
1027
+ let tools;
1028
+ if (explicitTools.length > 0) {
1029
+ // Explicit flags take precedence (works with or without -y)
1030
+ tools = explicitTools;
1031
+ }
1032
+ else if (options.yes) {
1033
+ // No explicit tools + -y: default to Cursor and Claude
1034
+ tools = TOOLS.filter((t) => t.defaultChecked).map((t) => t.key);
1035
+ }
1036
+ else {
1037
+ // Interactive mode
1038
+ const answers = await inquirer.prompt([
1039
+ {
1040
+ type: "checkbox",
1041
+ name: "tools",
1042
+ message: "Select AI tools to configure:",
1043
+ choices: TOOLS.map((t) => ({
1044
+ name: t.name,
1045
+ value: t.key,
1046
+ checked: t.defaultChecked,
1047
+ })),
1048
+ },
1049
+ ]);
1050
+ tools = answers.tools;
1051
+ }
1052
+ // Treat unknown project type as fullstack
1053
+ const projectType = detectedType === "unknown" ? "fullstack" : detectedType;
1054
+ if (tools.length === 0) {
1055
+ console.log(chalk.yellow("No tools selected. At least one tool is required."));
1056
+ return;
1057
+ }
1058
+ // ==========================================================================
1059
+ // Template Selection (single-repo only; monorepo handles templates above)
1060
+ // ==========================================================================
1061
+ let selectedTemplate = null;
1062
+ // Pre-fetched templates list (used to pass selected SpecTemplate to downloadTemplateById)
1063
+ let fetchedTemplates = [];
1064
+ let registryBackend;
1065
+ // Determine the index URL based on registry
1066
+ const indexUrl = registry
1067
+ ? `${registry.rawBaseUrl}/index.json`
1068
+ : TEMPLATE_INDEX_URL;
1069
+ if (monorepoPackages) {
1070
+ // Monorepo: template selection already handled above
1071
+ }
1072
+ else if (options.template) {
1073
+ // Template specified via --template flag
1074
+ selectedTemplate = options.template;
1075
+ }
1076
+ else if (!options.yes) {
1077
+ // Interactive mode: show template selection
1078
+ const timeoutSec = TIMEOUTS.INDEX_FETCH_MS / 1000;
1079
+ const sourceLabel = registry ? registry.gigetSource : TEMPLATE_INDEX_URL;
1080
+ console.log(chalk.gray(` Fetching available templates from ${sourceLabel}`));
1081
+ let elapsed = 0;
1082
+ const ticker = setInterval(() => {
1083
+ elapsed++;
1084
+ process.stdout.write(`\r${chalk.gray(` Loading... ${elapsed}s/${timeoutSec}s`)}`);
1085
+ }, 1000);
1086
+ process.stdout.write(chalk.gray(` Loading... 0s/${timeoutSec}s`));
1087
+ let templates;
1088
+ let registryProbeNotFound = false;
1089
+ let registryProbeError;
1090
+ if (registry) {
1091
+ const probeResult = await probeRegistryIndex(indexUrl, registry);
1092
+ templates = probeResult.templates;
1093
+ registryProbeNotFound = probeResult.isNotFound;
1094
+ registryProbeError = probeResult.error;
1095
+ registryBackend = probeResult.backend;
1096
+ }
1097
+ else {
1098
+ templates = await fetchTemplateIndex(indexUrl);
1099
+ }
1100
+ clearInterval(ticker);
1101
+ // Clear the loading line
1102
+ process.stdout.write("\r\x1b[2K");
1103
+ fetchedTemplates = templates;
1104
+ if (templates.length === 0 && registry && registryProbeNotFound) {
1105
+ // Custom registry: confirmed no index.json — will try direct download later
1106
+ console.log(chalk.gray(" No index.json found at registry. Will download as direct spec template."));
1107
+ }
1108
+ else if (templates.length === 0 && registry) {
1109
+ // Custom registry: transient error (not a 404) — abort, don't misclassify
1110
+ console.log(chalk.red(` ${registryProbeError?.message ?? "Could not reach registry. Check your connection and try again."}`));
1111
+ return;
1112
+ }
1113
+ else if (templates.length === 0) {
1114
+ console.log(chalk.gray(" Could not fetch templates (offline or server unavailable)."));
1115
+ console.log(chalk.gray(" Using blank templates.\n"));
1116
+ }
1117
+ if (templates.length > 0) {
1118
+ // Build template choices
1119
+ const specTemplates = templates
1120
+ .filter((t) => t.type === "spec")
1121
+ .map((t) => ({
1122
+ name: `${t.id} (${t.name})`,
1123
+ value: t.id,
1124
+ }));
1125
+ const templateChoices = registry
1126
+ ? specTemplates
1127
+ : [
1128
+ {
1129
+ name: "from scratch (default)",
1130
+ value: "blank",
1131
+ },
1132
+ ...specTemplates,
1133
+ {
1134
+ name: "custom (enter a registry source)",
1135
+ value: "__custom__",
1136
+ },
1137
+ ];
1138
+ // Loop to allow returning from custom source input back to the picker
1139
+ let templatePicked = false;
1140
+ while (templateChoices.length > 0 && !templatePicked) {
1141
+ const templateAnswer = await inquirer.prompt([
1142
+ {
1143
+ type: "list",
1144
+ name: "template",
1145
+ message: "Select a spec template:",
1146
+ choices: templateChoices,
1147
+ default: registry ? undefined : "blank",
1148
+ },
1149
+ ]);
1150
+ if (templateAnswer.template === "__custom__") {
1151
+ // Prompt for custom registry source (empty → back to picker)
1152
+ const customSource = await askInput("Enter registry source (e.g., gh:myorg/myrepo/specs), or press Enter to go back: ");
1153
+ if (!customSource) {
1154
+ continue; // Back to picker
1155
+ }
1156
+ try {
1157
+ registry = parseRegistrySource(customSource);
1158
+ fetchedTemplates = []; // Reset so direct-download guard works correctly
1159
+ // Probe index.json to detect marketplace vs direct download
1160
+ const customIndexUrl = `${registry.rawBaseUrl}/index.json`;
1161
+ console.log(chalk.gray(` Checking for templates at ${registry.gigetSource}...`));
1162
+ const customProbe = await probeRegistryIndex(customIndexUrl, registry);
1163
+ const customTemplates = customProbe.templates;
1164
+ registryBackend = customProbe.backend;
1165
+ if (customTemplates.length > 0) {
1166
+ // Marketplace mode: show picker with custom templates
1167
+ fetchedTemplates = customTemplates;
1168
+ const customChoices = customTemplates
1169
+ .filter((t) => t.type === "spec")
1170
+ .map((t) => ({
1171
+ name: `${t.id} (${t.name})`,
1172
+ value: t.id,
1173
+ }));
1174
+ if (customChoices.length > 0) {
1175
+ const customAnswer = await inquirer.prompt([
1176
+ {
1177
+ type: "list",
1178
+ name: "template",
1179
+ message: "Select a spec template:",
1180
+ choices: customChoices,
1181
+ },
1182
+ ]);
1183
+ selectedTemplate = customAnswer.template;
1184
+ // Check if spec directory already exists and ask what to do
1185
+ const specDir = path.join(cwd, PATHS.SPEC);
1186
+ if (fs.existsSync(specDir) &&
1187
+ !options.overwrite &&
1188
+ !options.append) {
1189
+ const actionAnswer = await inquirer.prompt([
1190
+ {
1191
+ type: "list",
1192
+ name: "action",
1193
+ message: `Directory ${PATHS.SPEC} already exists. What do you want to do?`,
1194
+ choices: [
1195
+ { name: "Skip (keep existing)", value: "skip" },
1196
+ {
1197
+ name: "Overwrite (replace all)",
1198
+ value: "overwrite",
1199
+ },
1200
+ {
1201
+ name: "Append (add missing files only)",
1202
+ value: "append",
1203
+ },
1204
+ ],
1205
+ default: "skip",
1206
+ },
1207
+ ]);
1208
+ templateStrategy = actionAnswer.action;
1209
+ }
1210
+ }
1211
+ templatePicked = true;
1212
+ }
1213
+ else if (customProbe.isNotFound) {
1214
+ // No index.json → direct download mode
1215
+ templatePicked = true;
1216
+ }
1217
+ else {
1218
+ // Transient error (not 404) — loop back, don't misclassify
1219
+ console.log(chalk.yellow(` ${customProbe.error?.message ?? "Could not reach registry. Try again or enter a different source."}`));
1220
+ registry = undefined; // Reset so we don't fall through to direct download
1221
+ }
1222
+ }
1223
+ catch (error) {
1224
+ console.log(chalk.red(error instanceof Error
1225
+ ? error.message
1226
+ : "Invalid registry source"));
1227
+ // Loop back to picker
1228
+ }
1229
+ }
1230
+ else {
1231
+ templatePicked = true;
1232
+ if (templateAnswer.template !== "blank") {
1233
+ selectedTemplate = templateAnswer.template;
1234
+ // Check if spec directory already exists and ask what to do
1235
+ const specDir = path.join(cwd, PATHS.SPEC);
1236
+ if (fs.existsSync(specDir) &&
1237
+ !options.overwrite &&
1238
+ !options.append) {
1239
+ const actionAnswer = await inquirer.prompt([
1240
+ {
1241
+ type: "list",
1242
+ name: "action",
1243
+ message: `Directory ${PATHS.SPEC} already exists. What do you want to do?`,
1244
+ choices: [
1245
+ { name: "Skip (keep existing)", value: "skip" },
1246
+ { name: "Overwrite (replace all)", value: "overwrite" },
1247
+ {
1248
+ name: "Append (add missing files only)",
1249
+ value: "append",
1250
+ },
1251
+ ],
1252
+ default: "skip",
1253
+ },
1254
+ ]);
1255
+ templateStrategy = actionAnswer.action;
1256
+ }
1257
+ }
1258
+ }
1259
+ }
1260
+ }
1261
+ }
1262
+ // -y mode with --registry (no --template): probe index.json to detect mode
1263
+ // Skip when monorepo mode already handled templates above
1264
+ if (options.yes && registry && !selectedTemplate && !monorepoPackages) {
1265
+ const probeResult = await probeRegistryIndex(`${registry.rawBaseUrl}/index.json`, registry);
1266
+ registryBackend = probeResult.backend;
1267
+ if (probeResult.templates.length > 0) {
1268
+ // Marketplace mode requires interactive selection — can't auto-select
1269
+ console.log(chalk.red("Error: Registry is a marketplace with multiple templates. " +
1270
+ "Use --template <id> to specify which one, or remove -y for interactive selection."));
1271
+ return;
1272
+ }
1273
+ if (!probeResult.isNotFound) {
1274
+ // Transient error (not 404) — abort, don't misclassify as direct-download
1275
+ console.log(chalk.red(`Error: ${probeResult.error?.message ?? "Could not reach registry. Check your connection and try again."}`));
1276
+ return;
1277
+ }
1278
+ // isNotFound=true → no index.json, proceed with direct download (fetchedTemplates stays empty)
1279
+ }
1280
+ // ==========================================================================
1281
+ // Download Remote Template (if selected or direct registry download)
1282
+ // ==========================================================================
1283
+ let useRemoteTemplate = false;
1284
+ if (selectedTemplate) {
1285
+ // Marketplace mode: download specific template by ID
1286
+ console.log(chalk.blue(`📦 Downloading template "${selectedTemplate}"...`));
1287
+ console.log(chalk.gray(" This may take a moment on slow connections."));
1288
+ // Find pre-fetched SpecTemplate to avoid double-fetch
1289
+ const prefetched = fetchedTemplates.find((t) => t.id === selectedTemplate);
1290
+ const result = await downloadTemplateById(cwd, selectedTemplate, templateStrategy, prefetched, registry, undefined, registryBackend);
1291
+ if (result.success) {
1292
+ if (result.skipped) {
1293
+ console.log(chalk.gray(` ${result.message}`));
1294
+ }
1295
+ else {
1296
+ console.log(chalk.green(` ${result.message}`));
1297
+ useRemoteTemplate = true;
1298
+ }
1299
+ }
1300
+ else {
1301
+ console.log(chalk.yellow(` ${result.message}`));
1302
+ console.log(chalk.gray(" Falling back to blank templates..."));
1303
+ const retryCmd = registry
1304
+ ? `trellis init --registry ${registry.gigetSource} --template ${selectedTemplate}`
1305
+ : `trellis init --template ${selectedTemplate}`;
1306
+ console.log(chalk.gray(` You can retry later: ${retryCmd}`));
1307
+ }
1308
+ }
1309
+ else if (registry && fetchedTemplates.length === 0) {
1310
+ // Direct download mode: registry has no index.json, download directory directly
1311
+ console.log(chalk.blue(`📦 Downloading spec from ${registry.gigetSource}...`));
1312
+ console.log(chalk.gray(" This may take a moment on slow connections."));
1313
+ // Ask about existing spec dir in interactive mode
1314
+ if (!options.yes && !options.overwrite && !options.append) {
1315
+ const specDir = path.join(cwd, PATHS.SPEC);
1316
+ if (fs.existsSync(specDir)) {
1317
+ const actionAnswer = await inquirer.prompt([
1318
+ {
1319
+ type: "list",
1320
+ name: "action",
1321
+ message: `Directory ${PATHS.SPEC} already exists. What do you want to do?`,
1322
+ choices: [
1323
+ { name: "Skip (keep existing)", value: "skip" },
1324
+ { name: "Overwrite (replace all)", value: "overwrite" },
1325
+ { name: "Append (add missing files only)", value: "append" },
1326
+ ],
1327
+ default: "skip",
1328
+ },
1329
+ ]);
1330
+ templateStrategy = actionAnswer.action;
1331
+ }
1332
+ }
1333
+ const result = await downloadRegistryDirect(cwd, registry, templateStrategy, undefined, registryBackend);
1334
+ if (result.success) {
1335
+ if (result.skipped) {
1336
+ console.log(chalk.gray(` ${result.message}`));
1337
+ }
1338
+ else {
1339
+ console.log(chalk.green(` ${result.message}`));
1340
+ useRemoteTemplate = true;
1341
+ }
1342
+ }
1343
+ else {
1344
+ console.log(chalk.yellow(` ${result.message}`));
1345
+ console.log(chalk.gray(" Falling back to blank templates..."));
1346
+ console.log(chalk.gray(` You can retry later: trellis init --registry ${registry.gigetSource}`));
1347
+ }
1348
+ }
1349
+ // ==========================================================================
1350
+ // Create Workflow Structure
1351
+ // ==========================================================================
1352
+ // Record every successful write from here through createRootFiles. The
1353
+ // captured set is the source of truth for `.template-hashes.json`'s
1354
+ // platform/root entries — replacing the previous "walk every managed dir"
1355
+ // approach that swept user-owned runtime files into the manifest
1356
+ // (.codex/sessions/, .claude/projects/, pre-existing AGENTS.md).
1357
+ const writtenPaths = startRecordingWrites(cwd);
1358
+ try {
1359
+ // Create workflow structure with project type
1360
+ console.log(chalk.blue("📁 Creating workflow structure..."));
1361
+ await createWorkflowStructure(cwd, {
1362
+ projectType,
1363
+ skipSpecTemplates: useRemoteTemplate,
1364
+ packages: monorepoPackages,
1365
+ remoteSpecPackages,
1366
+ });
1367
+ // Write monorepo packages to config.yaml (non-destructive patch)
1368
+ if (monorepoPackages) {
1369
+ writeMonorepoConfig(cwd, monorepoPackages);
1370
+ console.log(chalk.blue("📦 Monorepo packages written to config.yaml"));
1371
+ }
1372
+ // Write version file for update tracking
1373
+ const versionPath = path.join(cwd, DIR_NAMES.WORKFLOW, ".version");
1374
+ fs.writeFileSync(versionPath, VERSION);
1375
+ // Configure selected tools by copying entire directories (dogfooding)
1376
+ for (const tool of tools) {
1377
+ const platformId = resolveCliFlag(tool);
1378
+ if (platformId) {
1379
+ console.log(chalk.blue(`📝 Configuring ${AI_TOOLS[platformId].name}...`));
1380
+ await configurePlatform(platformId, cwd);
1381
+ }
1382
+ }
1383
+ const pythonPlatforms = getPlatformsWithPythonHooks();
1384
+ const hasSelectedPythonPlatform = pythonPlatforms.some((id) => tools.includes(AI_TOOLS[id].cliFlag));
1385
+ if (hasSelectedPythonPlatform) {
1386
+ logPythonAdaptationNotice(pythonCmd);
1387
+ }
1388
+ // Create root files (skip if exists)
1389
+ await createRootFiles(cwd);
1390
+ }
1391
+ finally {
1392
+ stopRecordingWrites();
1393
+ }
1394
+ // Initialize template hashes for modification tracking
1395
+ const hashedCount = initializeHashes(cwd, { trackedPaths: writtenPaths });
1396
+ if (hashedCount > 0) {
1397
+ console.log(chalk.gray(`📋 Tracking ${hashedCount} template files for updates`));
1398
+ }
1399
+ // Initialize developer identity (silent - no output)
1400
+ if (developerName) {
1401
+ try {
1402
+ const scriptPath = path.join(cwd, PATHS.SCRIPTS, "init_developer.py");
1403
+ execSync(`${pythonCmd} "${scriptPath}" "${developerName}"`, {
1404
+ cwd,
1405
+ stdio: "pipe", // Silent
1406
+ });
1407
+ }
1408
+ catch {
1409
+ // Silent failure - user can run init_developer.py manually
1410
+ }
1411
+ // Three-branch dispatch using flags captured at init() start (before
1412
+ // createWorkflowStructure/init_developer ran, so they reflect the disk
1413
+ // state of the user's checkout, not the state this init just produced):
1414
+ // isFirstInit=true → creator bootstrap (new project)
1415
+ // isFirstInit=false + no .developer file → joiner onboarding (fresh clone)
1416
+ // isFirstInit=false + .developer exists → same-dev re-init, no task
1417
+ //
1418
+ // Tasks-empty fallback (issue #204): if .trellis/ exists but tasks dir is
1419
+ // empty, the previous init aborted before creating the bootstrap task. Run
1420
+ // bootstrap creation regardless of isFirstInit. writeTaskSkeleton is
1421
+ // idempotent so repeated triggers are safe.
1422
+ //
1423
+ // Runs OUTSIDE the init_developer try/catch (which uses stdio: "pipe")
1424
+ // so joiner failures surface as warnings instead of being silently
1425
+ // swallowed.
1426
+ const tasksDir = path.join(cwd, PATHS.TASKS);
1427
+ const tasksEmpty = !fs.existsSync(tasksDir) || fs.readdirSync(tasksDir).length === 0;
1428
+ if (isFirstInit || tasksEmpty) {
1429
+ createBootstrapTask(cwd, developerName, pythonCmd, projectType, monorepoPackages);
1430
+ }
1431
+ else if (!hadDeveloperFileAtStart) {
1432
+ try {
1433
+ if (!createJoinerOnboardingTask(cwd, developerName, pythonCmd)) {
1434
+ console.warn(chalk.yellow("⚠ Failed to create joiner onboarding task"));
1435
+ }
1436
+ }
1437
+ catch (err) {
1438
+ console.warn(chalk.yellow(`⚠ Joiner onboarding setup failed: ${err instanceof Error ? err.message : String(err)}`));
1439
+ }
1440
+ }
1441
+ }
1442
+ }
1443
+ /**
1444
+ * Simple readline-based input (no flickering like inquirer)
1445
+ */
1446
+ function askInput(prompt) {
1447
+ const rl = readline.createInterface({
1448
+ input: process.stdin,
1449
+ output: process.stdout,
1450
+ });
1451
+ return new Promise((resolve) => {
1452
+ rl.question(prompt, (answer) => {
1453
+ rl.close();
1454
+ resolve(answer.trim());
1455
+ });
1456
+ });
1457
+ }
1458
+ async function createRootFiles(cwd) {
1459
+ const agentsPath = path.join(cwd, FILE_NAMES.AGENTS);
1460
+ // Write AGENTS.md from template
1461
+ const agentsWritten = await writeFile(agentsPath, agentsMdContent);
1462
+ if (agentsWritten) {
1463
+ console.log(chalk.blue("📄 Created AGENTS.md"));
1464
+ }
1465
+ }
1466
+ //# sourceMappingURL=init.js.map