@baoanaz/cviauto 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (740) hide show
  1. package/LICENSE +235 -0
  2. package/README.md +46 -0
  3. package/bin/trellis.js +3 -0
  4. package/dist/cli/index.d.ts +3 -0
  5. package/dist/cli/index.d.ts.map +1 -0
  6. package/dist/cli/index.js +209 -0
  7. package/dist/cli/index.js.map +1 -0
  8. package/dist/commands/channel/adapters/claude.d.ts +29 -0
  9. package/dist/commands/channel/adapters/claude.d.ts.map +1 -0
  10. package/dist/commands/channel/adapters/claude.js +203 -0
  11. package/dist/commands/channel/adapters/claude.js.map +1 -0
  12. package/dist/commands/channel/adapters/codex.d.ts +85 -0
  13. package/dist/commands/channel/adapters/codex.d.ts.map +1 -0
  14. package/dist/commands/channel/adapters/codex.js +505 -0
  15. package/dist/commands/channel/adapters/codex.js.map +1 -0
  16. package/dist/commands/channel/adapters/index.d.ts +84 -0
  17. package/dist/commands/channel/adapters/index.d.ts.map +1 -0
  18. package/dist/commands/channel/adapters/index.js +115 -0
  19. package/dist/commands/channel/adapters/index.js.map +1 -0
  20. package/dist/commands/channel/adapters/types.d.ts +33 -0
  21. package/dist/commands/channel/adapters/types.d.ts.map +1 -0
  22. package/dist/commands/channel/adapters/types.js +2 -0
  23. package/dist/commands/channel/adapters/types.js.map +1 -0
  24. package/dist/commands/channel/agent-loader.d.ts +32 -0
  25. package/dist/commands/channel/agent-loader.d.ts.map +1 -0
  26. package/dist/commands/channel/agent-loader.js +154 -0
  27. package/dist/commands/channel/agent-loader.js.map +1 -0
  28. package/dist/commands/channel/context-loader.d.ts +26 -0
  29. package/dist/commands/channel/context-loader.d.ts.map +1 -0
  30. package/dist/commands/channel/context-loader.js +290 -0
  31. package/dist/commands/channel/context-loader.js.map +1 -0
  32. package/dist/commands/channel/context.d.ts +16 -0
  33. package/dist/commands/channel/context.d.ts.map +1 -0
  34. package/dist/commands/channel/context.js +83 -0
  35. package/dist/commands/channel/context.js.map +1 -0
  36. package/dist/commands/channel/create.d.ts +27 -0
  37. package/dist/commands/channel/create.d.ts.map +1 -0
  38. package/dist/commands/channel/create.js +39 -0
  39. package/dist/commands/channel/create.js.map +1 -0
  40. package/dist/commands/channel/dev-parse-trace.d.ts +14 -0
  41. package/dist/commands/channel/dev-parse-trace.d.ts.map +1 -0
  42. package/dist/commands/channel/dev-parse-trace.js +70 -0
  43. package/dist/commands/channel/dev-parse-trace.js.map +1 -0
  44. package/dist/commands/channel/guard.d.ts +150 -0
  45. package/dist/commands/channel/guard.d.ts.map +1 -0
  46. package/dist/commands/channel/guard.js +474 -0
  47. package/dist/commands/channel/guard.js.map +1 -0
  48. package/dist/commands/channel/index.d.ts +3 -0
  49. package/dist/commands/channel/index.d.ts.map +1 -0
  50. package/dist/commands/channel/index.js +531 -0
  51. package/dist/commands/channel/index.js.map +1 -0
  52. package/dist/commands/channel/interrupt.d.ts +10 -0
  53. package/dist/commands/channel/interrupt.d.ts.map +1 -0
  54. package/dist/commands/channel/interrupt.js +22 -0
  55. package/dist/commands/channel/interrupt.js.map +1 -0
  56. package/dist/commands/channel/kill.d.ts +7 -0
  57. package/dist/commands/channel/kill.d.ts.map +1 -0
  58. package/dist/commands/channel/kill.js +121 -0
  59. package/dist/commands/channel/kill.js.map +1 -0
  60. package/dist/commands/channel/list.d.ts +17 -0
  61. package/dist/commands/channel/list.d.ts.map +1 -0
  62. package/dist/commands/channel/list.js +233 -0
  63. package/dist/commands/channel/list.js.map +1 -0
  64. package/dist/commands/channel/messages.d.ts +15 -0
  65. package/dist/commands/channel/messages.d.ts.map +1 -0
  66. package/dist/commands/channel/messages.js +245 -0
  67. package/dist/commands/channel/messages.js.map +1 -0
  68. package/dist/commands/channel/rm.d.ts +27 -0
  69. package/dist/commands/channel/rm.d.ts.map +1 -0
  70. package/dist/commands/channel/rm.js +216 -0
  71. package/dist/commands/channel/rm.js.map +1 -0
  72. package/dist/commands/channel/run.d.ts +30 -0
  73. package/dist/commands/channel/run.d.ts.map +1 -0
  74. package/dist/commands/channel/run.js +130 -0
  75. package/dist/commands/channel/run.js.map +1 -0
  76. package/dist/commands/channel/send.d.ts +11 -0
  77. package/dist/commands/channel/send.d.ts.map +1 -0
  78. package/dist/commands/channel/send.js +24 -0
  79. package/dist/commands/channel/send.js.map +1 -0
  80. package/dist/commands/channel/spawn.d.ts +40 -0
  81. package/dist/commands/channel/spawn.d.ts.map +1 -0
  82. package/dist/commands/channel/spawn.js +244 -0
  83. package/dist/commands/channel/spawn.js.map +1 -0
  84. package/dist/commands/channel/store/events.d.ts +39 -0
  85. package/dist/commands/channel/store/events.d.ts.map +1 -0
  86. package/dist/commands/channel/store/events.js +87 -0
  87. package/dist/commands/channel/store/events.js.map +1 -0
  88. package/dist/commands/channel/store/filter.d.ts +3 -0
  89. package/dist/commands/channel/store/filter.d.ts.map +1 -0
  90. package/dist/commands/channel/store/filter.js +2 -0
  91. package/dist/commands/channel/store/filter.js.map +1 -0
  92. package/dist/commands/channel/store/lock.d.ts +23 -0
  93. package/dist/commands/channel/store/lock.d.ts.map +1 -0
  94. package/dist/commands/channel/store/lock.js +99 -0
  95. package/dist/commands/channel/store/lock.js.map +1 -0
  96. package/dist/commands/channel/store/paths.d.ts +63 -0
  97. package/dist/commands/channel/store/paths.d.ts.map +1 -0
  98. package/dist/commands/channel/store/paths.js +246 -0
  99. package/dist/commands/channel/store/paths.js.map +1 -0
  100. package/dist/commands/channel/store/schema.d.ts +27 -0
  101. package/dist/commands/channel/store/schema.d.ts.map +1 -0
  102. package/dist/commands/channel/store/schema.js +34 -0
  103. package/dist/commands/channel/store/schema.js.map +1 -0
  104. package/dist/commands/channel/store/thread-state.d.ts +5 -0
  105. package/dist/commands/channel/store/thread-state.d.ts.map +1 -0
  106. package/dist/commands/channel/store/thread-state.js +16 -0
  107. package/dist/commands/channel/store/thread-state.js.map +1 -0
  108. package/dist/commands/channel/store/watch.d.ts +19 -0
  109. package/dist/commands/channel/store/watch.d.ts.map +1 -0
  110. package/dist/commands/channel/store/watch.js +146 -0
  111. package/dist/commands/channel/store/watch.js.map +1 -0
  112. package/dist/commands/channel/supervisor/idle.d.ts +46 -0
  113. package/dist/commands/channel/supervisor/idle.d.ts.map +1 -0
  114. package/dist/commands/channel/supervisor/idle.js +72 -0
  115. package/dist/commands/channel/supervisor/idle.js.map +1 -0
  116. package/dist/commands/channel/supervisor/inbox.d.ts +30 -0
  117. package/dist/commands/channel/supervisor/inbox.d.ts.map +1 -0
  118. package/dist/commands/channel/supervisor/inbox.js +160 -0
  119. package/dist/commands/channel/supervisor/inbox.js.map +1 -0
  120. package/dist/commands/channel/supervisor/shutdown.d.ts +68 -0
  121. package/dist/commands/channel/supervisor/shutdown.d.ts.map +1 -0
  122. package/dist/commands/channel/supervisor/shutdown.js +146 -0
  123. package/dist/commands/channel/supervisor/shutdown.js.map +1 -0
  124. package/dist/commands/channel/supervisor/stdout.d.ts +51 -0
  125. package/dist/commands/channel/supervisor/stdout.d.ts.map +1 -0
  126. package/dist/commands/channel/supervisor/stdout.js +121 -0
  127. package/dist/commands/channel/supervisor/stdout.js.map +1 -0
  128. package/dist/commands/channel/supervisor/turns.d.ts +31 -0
  129. package/dist/commands/channel/supervisor/turns.d.ts.map +1 -0
  130. package/dist/commands/channel/supervisor/turns.js +45 -0
  131. package/dist/commands/channel/supervisor/turns.js.map +1 -0
  132. package/dist/commands/channel/supervisor/warning.d.ts +48 -0
  133. package/dist/commands/channel/supervisor/warning.d.ts.map +1 -0
  134. package/dist/commands/channel/supervisor/warning.js +77 -0
  135. package/dist/commands/channel/supervisor/warning.js.map +1 -0
  136. package/dist/commands/channel/supervisor.d.ts +59 -0
  137. package/dist/commands/channel/supervisor.d.ts.map +1 -0
  138. package/dist/commands/channel/supervisor.js +376 -0
  139. package/dist/commands/channel/supervisor.js.map +1 -0
  140. package/dist/commands/channel/text-body.d.ts +13 -0
  141. package/dist/commands/channel/text-body.d.ts.map +1 -0
  142. package/dist/commands/channel/text-body.js +47 -0
  143. package/dist/commands/channel/text-body.js.map +1 -0
  144. package/dist/commands/channel/threads.d.ts +39 -0
  145. package/dist/commands/channel/threads.d.ts.map +1 -0
  146. package/dist/commands/channel/threads.js +106 -0
  147. package/dist/commands/channel/threads.js.map +1 -0
  148. package/dist/commands/channel/title.d.ts +12 -0
  149. package/dist/commands/channel/title.d.ts.map +1 -0
  150. package/dist/commands/channel/title.js +24 -0
  151. package/dist/commands/channel/title.js.map +1 -0
  152. package/dist/commands/channel/wait.d.ts +17 -0
  153. package/dist/commands/channel/wait.d.ts.map +1 -0
  154. package/dist/commands/channel/wait.js +75 -0
  155. package/dist/commands/channel/wait.js.map +1 -0
  156. package/dist/commands/init.d.ts +66 -0
  157. package/dist/commands/init.d.ts.map +1 -0
  158. package/dist/commands/init.js +1704 -0
  159. package/dist/commands/init.js.map +1 -0
  160. package/dist/commands/mem.d.ts +30 -0
  161. package/dist/commands/mem.d.ts.map +1 -0
  162. package/dist/commands/mem.js +424 -0
  163. package/dist/commands/mem.js.map +1 -0
  164. package/dist/commands/uninstall.d.ts +27 -0
  165. package/dist/commands/uninstall.d.ts.map +1 -0
  166. package/dist/commands/uninstall.js +340 -0
  167. package/dist/commands/uninstall.js.map +1 -0
  168. package/dist/commands/update.d.ts +72 -0
  169. package/dist/commands/update.d.ts.map +1 -0
  170. package/dist/commands/update.js +2023 -0
  171. package/dist/commands/update.js.map +1 -0
  172. package/dist/commands/upgrade.d.ts +28 -0
  173. package/dist/commands/upgrade.d.ts.map +1 -0
  174. package/dist/commands/upgrade.js +88 -0
  175. package/dist/commands/upgrade.js.map +1 -0
  176. package/dist/commands/workflow.d.ts +35 -0
  177. package/dist/commands/workflow.d.ts.map +1 -0
  178. package/dist/commands/workflow.js +232 -0
  179. package/dist/commands/workflow.js.map +1 -0
  180. package/dist/configurators/antigravity.d.ts +7 -0
  181. package/dist/configurators/antigravity.d.ts.map +1 -0
  182. package/dist/configurators/antigravity.js +19 -0
  183. package/dist/configurators/antigravity.js.map +1 -0
  184. package/dist/configurators/claude.d.ts +12 -0
  185. package/dist/configurators/claude.d.ts.map +1 -0
  186. package/dist/configurators/claude.js +107 -0
  187. package/dist/configurators/claude.js.map +1 -0
  188. package/dist/configurators/codebuddy.d.ts +10 -0
  189. package/dist/configurators/codebuddy.d.ts.map +1 -0
  190. package/dist/configurators/codebuddy.js +30 -0
  191. package/dist/configurators/codebuddy.js.map +1 -0
  192. package/dist/configurators/codex.d.ts +8 -0
  193. package/dist/configurators/codex.d.ts.map +1 -0
  194. package/dist/configurators/codex.js +73 -0
  195. package/dist/configurators/codex.js.map +1 -0
  196. package/dist/configurators/copilot.d.ts +10 -0
  197. package/dist/configurators/copilot.d.ts.map +1 -0
  198. package/dist/configurators/copilot.js +51 -0
  199. package/dist/configurators/copilot.js.map +1 -0
  200. package/dist/configurators/cursor.d.ts +10 -0
  201. package/dist/configurators/cursor.d.ts.map +1 -0
  202. package/dist/configurators/cursor.js +29 -0
  203. package/dist/configurators/cursor.js.map +1 -0
  204. package/dist/configurators/devin.d.ts +7 -0
  205. package/dist/configurators/devin.d.ts.map +1 -0
  206. package/dist/configurators/devin.js +19 -0
  207. package/dist/configurators/devin.js.map +1 -0
  208. package/dist/configurators/droid.d.ts +10 -0
  209. package/dist/configurators/droid.d.ts.map +1 -0
  210. package/dist/configurators/droid.js +30 -0
  211. package/dist/configurators/droid.js.map +1 -0
  212. package/dist/configurators/gemini.d.ts +16 -0
  213. package/dist/configurators/gemini.d.ts.map +1 -0
  214. package/dist/configurators/gemini.js +38 -0
  215. package/dist/configurators/gemini.js.map +1 -0
  216. package/dist/configurators/index.d.ts +86 -0
  217. package/dist/configurators/index.d.ts.map +1 -0
  218. package/dist/configurators/index.js +430 -0
  219. package/dist/configurators/index.js.map +1 -0
  220. package/dist/configurators/kilo.d.ts +7 -0
  221. package/dist/configurators/kilo.d.ts.map +1 -0
  222. package/dist/configurators/kilo.js +19 -0
  223. package/dist/configurators/kilo.js.map +1 -0
  224. package/dist/configurators/kiro.d.ts +10 -0
  225. package/dist/configurators/kiro.d.ts.map +1 -0
  226. package/dist/configurators/kiro.js +33 -0
  227. package/dist/configurators/kiro.js.map +1 -0
  228. package/dist/configurators/opencode.d.ts +14 -0
  229. package/dist/configurators/opencode.d.ts.map +1 -0
  230. package/dist/configurators/opencode.js +102 -0
  231. package/dist/configurators/opencode.js.map +1 -0
  232. package/dist/configurators/pi.d.ts +3 -0
  233. package/dist/configurators/pi.d.ts.map +1 -0
  234. package/dist/configurators/pi.js +55 -0
  235. package/dist/configurators/pi.js.map +1 -0
  236. package/dist/configurators/qoder.d.ts +11 -0
  237. package/dist/configurators/qoder.d.ts.map +1 -0
  238. package/dist/configurators/qoder.js +31 -0
  239. package/dist/configurators/qoder.js.map +1 -0
  240. package/dist/configurators/reasonix.d.ts +23 -0
  241. package/dist/configurators/reasonix.d.ts.map +1 -0
  242. package/dist/configurators/reasonix.js +60 -0
  243. package/dist/configurators/reasonix.js.map +1 -0
  244. package/dist/configurators/shared.d.ts +172 -0
  245. package/dist/configurators/shared.d.ts.map +1 -0
  246. package/dist/configurators/shared.js +530 -0
  247. package/dist/configurators/shared.js.map +1 -0
  248. package/dist/configurators/trae.d.ts +17 -0
  249. package/dist/configurators/trae.d.ts.map +1 -0
  250. package/dist/configurators/trae.js +42 -0
  251. package/dist/configurators/trae.js.map +1 -0
  252. package/dist/configurators/workflow.d.ts +37 -0
  253. package/dist/configurators/workflow.d.ts.map +1 -0
  254. package/dist/configurators/workflow.js +177 -0
  255. package/dist/configurators/workflow.js.map +1 -0
  256. package/dist/configurators/zcode.d.ts +19 -0
  257. package/dist/configurators/zcode.d.ts.map +1 -0
  258. package/dist/configurators/zcode.js +54 -0
  259. package/dist/configurators/zcode.js.map +1 -0
  260. package/dist/constants/paths.d.ts +74 -0
  261. package/dist/constants/paths.d.ts.map +1 -0
  262. package/dist/constants/paths.js +83 -0
  263. package/dist/constants/paths.js.map +1 -0
  264. package/dist/constants/version.d.ts +9 -0
  265. package/dist/constants/version.d.ts.map +1 -0
  266. package/dist/constants/version.js +15 -0
  267. package/dist/constants/version.js.map +1 -0
  268. package/dist/index.d.ts +9 -0
  269. package/dist/index.d.ts.map +1 -0
  270. package/dist/index.js +9 -0
  271. package/dist/index.js.map +1 -0
  272. package/dist/migrations/index.d.ts +62 -0
  273. package/dist/migrations/index.d.ts.map +1 -0
  274. package/dist/migrations/index.js +187 -0
  275. package/dist/migrations/index.js.map +1 -0
  276. package/dist/migrations/manifests/0.1.9.json +30 -0
  277. package/dist/migrations/manifests/0.2.0.json +49 -0
  278. package/dist/migrations/manifests/0.2.12.json +9 -0
  279. package/dist/migrations/manifests/0.2.13.json +9 -0
  280. package/dist/migrations/manifests/0.2.14.json +175 -0
  281. package/dist/migrations/manifests/0.2.15.json +33 -0
  282. package/dist/migrations/manifests/0.3.0-beta.0.json +297 -0
  283. package/dist/migrations/manifests/0.3.0-beta.1.json +9 -0
  284. package/dist/migrations/manifests/0.3.0-beta.10.json +9 -0
  285. package/dist/migrations/manifests/0.3.0-beta.11.json +9 -0
  286. package/dist/migrations/manifests/0.3.0-beta.12.json +9 -0
  287. package/dist/migrations/manifests/0.3.0-beta.13.json +9 -0
  288. package/dist/migrations/manifests/0.3.0-beta.14.json +9 -0
  289. package/dist/migrations/manifests/0.3.0-beta.15.json +9 -0
  290. package/dist/migrations/manifests/0.3.0-beta.16.json +9 -0
  291. package/dist/migrations/manifests/0.3.0-beta.2.json +9 -0
  292. package/dist/migrations/manifests/0.3.0-beta.3.json +9 -0
  293. package/dist/migrations/manifests/0.3.0-beta.4.json +9 -0
  294. package/dist/migrations/manifests/0.3.0-beta.5.json +9 -0
  295. package/dist/migrations/manifests/0.3.0-beta.6.json +9 -0
  296. package/dist/migrations/manifests/0.3.0-beta.7.json +11 -0
  297. package/dist/migrations/manifests/0.3.0-beta.8.json +9 -0
  298. package/dist/migrations/manifests/0.3.0-beta.9.json +9 -0
  299. package/dist/migrations/manifests/0.3.0-rc.0.json +9 -0
  300. package/dist/migrations/manifests/0.3.0-rc.1.json +9 -0
  301. package/dist/migrations/manifests/0.3.0-rc.2.json +9 -0
  302. package/dist/migrations/manifests/0.3.0-rc.3.json +9 -0
  303. package/dist/migrations/manifests/0.3.0-rc.4.json +9 -0
  304. package/dist/migrations/manifests/0.3.0-rc.5.json +9 -0
  305. package/dist/migrations/manifests/0.3.0-rc.6.json +9 -0
  306. package/dist/migrations/manifests/0.3.0.json +11 -0
  307. package/dist/migrations/manifests/0.3.1.json +9 -0
  308. package/dist/migrations/manifests/0.3.10.json +9 -0
  309. package/dist/migrations/manifests/0.3.2.json +9 -0
  310. package/dist/migrations/manifests/0.3.3.json +9 -0
  311. package/dist/migrations/manifests/0.3.4.json +21 -0
  312. package/dist/migrations/manifests/0.3.5.json +9 -0
  313. package/dist/migrations/manifests/0.3.6.json +9 -0
  314. package/dist/migrations/manifests/0.3.7.json +9 -0
  315. package/dist/migrations/manifests/0.3.8.json +9 -0
  316. package/dist/migrations/manifests/0.3.9.json +9 -0
  317. package/dist/migrations/manifests/0.4.0-beta.1.json +300 -0
  318. package/dist/migrations/manifests/0.4.0-beta.10.json +9 -0
  319. package/dist/migrations/manifests/0.4.0-beta.2.json +9 -0
  320. package/dist/migrations/manifests/0.4.0-beta.3.json +9 -0
  321. package/dist/migrations/manifests/0.4.0-beta.4.json +9 -0
  322. package/dist/migrations/manifests/0.4.0-beta.5.json +9 -0
  323. package/dist/migrations/manifests/0.4.0-beta.6.json +9 -0
  324. package/dist/migrations/manifests/0.4.0-beta.7.json +9 -0
  325. package/dist/migrations/manifests/0.4.0-beta.8.json +42 -0
  326. package/dist/migrations/manifests/0.4.0-beta.9.json +9 -0
  327. package/dist/migrations/manifests/0.4.0-rc.0.json +9 -0
  328. package/dist/migrations/manifests/0.4.0-rc.1.json +9 -0
  329. package/dist/migrations/manifests/0.4.0.json +9 -0
  330. package/dist/migrations/manifests/0.5.0-beta.0.json +1646 -0
  331. package/dist/migrations/manifests/0.5.0-beta.1.json +9 -0
  332. package/dist/migrations/manifests/0.5.0-beta.10.json +9 -0
  333. package/dist/migrations/manifests/0.5.0-beta.11.json +9 -0
  334. package/dist/migrations/manifests/0.5.0-beta.12.json +9 -0
  335. package/dist/migrations/manifests/0.5.0-beta.13.json +9 -0
  336. package/dist/migrations/manifests/0.5.0-beta.14.json +9 -0
  337. package/dist/migrations/manifests/0.5.0-beta.15.json +116 -0
  338. package/dist/migrations/manifests/0.5.0-beta.16.json +9 -0
  339. package/dist/migrations/manifests/0.5.0-beta.17.json +9 -0
  340. package/dist/migrations/manifests/0.5.0-beta.18.json +9 -0
  341. package/dist/migrations/manifests/0.5.0-beta.19.json +9 -0
  342. package/dist/migrations/manifests/0.5.0-beta.2.json +9 -0
  343. package/dist/migrations/manifests/0.5.0-beta.3.json +9 -0
  344. package/dist/migrations/manifests/0.5.0-beta.4.json +9 -0
  345. package/dist/migrations/manifests/0.5.0-beta.5.json +222 -0
  346. package/dist/migrations/manifests/0.5.0-beta.6.json +9 -0
  347. package/dist/migrations/manifests/0.5.0-beta.7.json +9 -0
  348. package/dist/migrations/manifests/0.5.0-beta.8.json +9 -0
  349. package/dist/migrations/manifests/0.5.0-beta.9.json +48 -0
  350. package/dist/migrations/manifests/0.5.0-rc.0.json +9 -0
  351. package/dist/migrations/manifests/0.5.0-rc.1.json +9 -0
  352. package/dist/migrations/manifests/0.5.0-rc.2.json +9 -0
  353. package/dist/migrations/manifests/0.5.0-rc.3.json +9 -0
  354. package/dist/migrations/manifests/0.5.0-rc.4.json +9 -0
  355. package/dist/migrations/manifests/0.5.0-rc.5.json +9 -0
  356. package/dist/migrations/manifests/0.5.0-rc.6.json +9 -0
  357. package/dist/migrations/manifests/0.5.0-rc.7.json +9 -0
  358. package/dist/migrations/manifests/0.5.0.json +9 -0
  359. package/dist/migrations/manifests/0.5.1.json +9 -0
  360. package/dist/migrations/manifests/0.5.10.json +9 -0
  361. package/dist/migrations/manifests/0.5.11.json +16 -0
  362. package/dist/migrations/manifests/0.5.12.json +9 -0
  363. package/dist/migrations/manifests/0.5.13.json +9 -0
  364. package/dist/migrations/manifests/0.5.14.json +9 -0
  365. package/dist/migrations/manifests/0.5.15.json +9 -0
  366. package/dist/migrations/manifests/0.5.16.json +9 -0
  367. package/dist/migrations/manifests/0.5.17.json +9 -0
  368. package/dist/migrations/manifests/0.5.18.json +9 -0
  369. package/dist/migrations/manifests/0.5.19.json +9 -0
  370. package/dist/migrations/manifests/0.5.2.json +9 -0
  371. package/dist/migrations/manifests/0.5.3.json +9 -0
  372. package/dist/migrations/manifests/0.5.4.json +9 -0
  373. package/dist/migrations/manifests/0.5.5.json +9 -0
  374. package/dist/migrations/manifests/0.5.6.json +9 -0
  375. package/dist/migrations/manifests/0.5.7.json +16 -0
  376. package/dist/migrations/manifests/0.5.8.json +9 -0
  377. package/dist/migrations/manifests/0.5.9.json +9 -0
  378. package/dist/migrations/manifests/0.6.0-beta.0.json +16 -0
  379. package/dist/migrations/manifests/0.6.0-beta.1.json +9 -0
  380. package/dist/migrations/manifests/0.6.0-beta.10.json +9 -0
  381. package/dist/migrations/manifests/0.6.0-beta.11.json +9 -0
  382. package/dist/migrations/manifests/0.6.0-beta.12.json +9 -0
  383. package/dist/migrations/manifests/0.6.0-beta.13.json +9 -0
  384. package/dist/migrations/manifests/0.6.0-beta.14.json +9 -0
  385. package/dist/migrations/manifests/0.6.0-beta.15.json +9 -0
  386. package/dist/migrations/manifests/0.6.0-beta.16.json +9 -0
  387. package/dist/migrations/manifests/0.6.0-beta.17.json +9 -0
  388. package/dist/migrations/manifests/0.6.0-beta.18.json +16 -0
  389. package/dist/migrations/manifests/0.6.0-beta.19.json +9 -0
  390. package/dist/migrations/manifests/0.6.0-beta.2.json +9 -0
  391. package/dist/migrations/manifests/0.6.0-beta.20.json +9 -0
  392. package/dist/migrations/manifests/0.6.0-beta.21.json +9 -0
  393. package/dist/migrations/manifests/0.6.0-beta.22.json +9 -0
  394. package/dist/migrations/manifests/0.6.0-beta.23.json +88 -0
  395. package/dist/migrations/manifests/0.6.0-beta.3.json +9 -0
  396. package/dist/migrations/manifests/0.6.0-beta.4.json +9 -0
  397. package/dist/migrations/manifests/0.6.0-beta.5.json +9 -0
  398. package/dist/migrations/manifests/0.6.0-beta.6.json +16 -0
  399. package/dist/migrations/manifests/0.6.0-beta.7.json +9 -0
  400. package/dist/migrations/manifests/0.6.0-beta.8.json +9 -0
  401. package/dist/migrations/manifests/0.6.0-beta.9.json +9 -0
  402. package/dist/migrations/manifests/0.6.0-rc.0.json +9 -0
  403. package/dist/migrations/manifests/0.6.0.json +9 -0
  404. package/dist/migrations/manifests/0.6.1.json +9 -0
  405. package/dist/migrations/manifests/0.6.2.json +9 -0
  406. package/dist/migrations/manifests/0.6.3.json +24 -0
  407. package/dist/migrations/manifests/0.6.4.json +9 -0
  408. package/dist/migrations/manifests/0.6.5.json +9 -0
  409. package/dist/templates/claude/agents/trellis-check.md +115 -0
  410. package/dist/templates/claude/agents/trellis-implement.md +110 -0
  411. package/dist/templates/claude/agents/trellis-research.md +137 -0
  412. package/dist/templates/claude/hooks/statusline.py +324 -0
  413. package/dist/templates/claude/index.d.ts +31 -0
  414. package/dist/templates/claude/index.d.ts.map +1 -0
  415. package/dist/templates/claude/index.js +58 -0
  416. package/dist/templates/claude/index.js.map +1 -0
  417. package/dist/templates/claude/settings.json +73 -0
  418. package/dist/templates/codebuddy/agents/trellis-check.md +115 -0
  419. package/dist/templates/codebuddy/agents/trellis-implement.md +110 -0
  420. package/dist/templates/codebuddy/agents/trellis-research.md +137 -0
  421. package/dist/templates/codebuddy/index.d.ts +15 -0
  422. package/dist/templates/codebuddy/index.d.ts.map +1 -0
  423. package/dist/templates/codebuddy/index.js +15 -0
  424. package/dist/templates/codebuddy/index.js.map +1 -0
  425. package/dist/templates/codebuddy/settings.json +59 -0
  426. package/dist/templates/codex/agents/trellis-check.toml +59 -0
  427. package/dist/templates/codex/agents/trellis-implement.toml +40 -0
  428. package/dist/templates/codex/agents/trellis-research.toml +73 -0
  429. package/dist/templates/codex/config.toml +28 -0
  430. package/dist/templates/codex/hooks/session-start.py +545 -0
  431. package/dist/templates/codex/hooks.json +15 -0
  432. package/dist/templates/codex/index.d.ts +39 -0
  433. package/dist/templates/codex/index.d.ts.map +1 -0
  434. package/dist/templates/codex/index.js +86 -0
  435. package/dist/templates/codex/index.js.map +1 -0
  436. package/dist/templates/codex/skills/before-dev/SKILL.md +40 -0
  437. package/dist/templates/codex/skills/brainstorm/SKILL.md +130 -0
  438. package/dist/templates/codex/skills/break-loop/SKILL.md +130 -0
  439. package/dist/templates/codex/skills/check/SKILL.md +98 -0
  440. package/dist/templates/codex/skills/check-cross-layer/SKILL.md +158 -0
  441. package/dist/templates/codex/skills/create-command/SKILL.md +101 -0
  442. package/dist/templates/codex/skills/finish-work/SKILL.md +98 -0
  443. package/dist/templates/codex/skills/improve-ut/SKILL.md +69 -0
  444. package/dist/templates/codex/skills/integrate-skill/SKILL.md +221 -0
  445. package/dist/templates/codex/skills/onboard/SKILL.md +363 -0
  446. package/dist/templates/codex/skills/record-session/SKILL.md +67 -0
  447. package/dist/templates/codex/skills/start/SKILL.md +64 -0
  448. package/dist/templates/codex/skills/update-spec/SKILL.md +335 -0
  449. package/dist/templates/common/bundled-skills/trellis-channel/SKILL.md +67 -0
  450. package/dist/templates/common/bundled-skills/trellis-channel/references/command-reference.md +480 -0
  451. package/dist/templates/common/bundled-skills/trellis-channel/references/forum.md +233 -0
  452. package/dist/templates/common/bundled-skills/trellis-channel/references/progress-debugging.md +226 -0
  453. package/dist/templates/common/bundled-skills/trellis-channel/references/workers.md +276 -0
  454. package/dist/templates/common/bundled-skills/trellis-channel/references/workflows.md +128 -0
  455. package/dist/templates/common/bundled-skills/trellis-meta/SKILL.md +85 -0
  456. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/add-project-local-conventions.md +83 -0
  457. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-agents.md +56 -0
  458. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-context-loading.md +84 -0
  459. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-hooks.md +57 -0
  460. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-skills-or-commands.md +123 -0
  461. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-spec-structure.md +83 -0
  462. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-task-lifecycle.md +90 -0
  463. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/change-workflow.md +66 -0
  464. package/dist/templates/common/bundled-skills/trellis-meta/references/customize-local/overview.md +55 -0
  465. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/bundled-skills.md +146 -0
  466. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/context-injection.md +68 -0
  467. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/generated-files.md +80 -0
  468. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/multi-agent-channel.md +69 -0
  469. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/overview.md +51 -0
  470. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/spec-system.md +102 -0
  471. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/task-system.md +130 -0
  472. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/workflow.md +75 -0
  473. package/dist/templates/common/bundled-skills/trellis-meta/references/local-architecture/workspace-memory.md +71 -0
  474. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/agents.md +82 -0
  475. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/hooks-and-settings.md +72 -0
  476. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/overview.md +59 -0
  477. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/platform-map.md +88 -0
  478. package/dist/templates/common/bundled-skills/trellis-meta/references/platform-files/skills-and-commands.md +85 -0
  479. package/dist/templates/common/bundled-skills/trellis-session-insight/SKILL.md +81 -0
  480. package/dist/templates/common/bundled-skills/trellis-session-insight/references/cli-quick-reference.md +65 -0
  481. package/dist/templates/common/bundled-skills/trellis-session-insight/references/triggering-patterns.md +93 -0
  482. package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/SKILL.md +41 -0
  483. package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/references/mcp-setup.md +90 -0
  484. package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/references/repository-analysis.md +59 -0
  485. package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/references/spec-task-planning.md +61 -0
  486. package/dist/templates/common/bundled-skills/trellis-spec-bootstrap/references/spec-writing.md +70 -0
  487. package/dist/templates/common/commands/continue.md +57 -0
  488. package/dist/templates/common/commands/finish-work.md +74 -0
  489. package/dist/templates/common/commands/start.md +59 -0
  490. package/dist/templates/common/index.d.ts +48 -0
  491. package/dist/templates/common/index.d.ts.map +1 -0
  492. package/dist/templates/common/index.js +104 -0
  493. package/dist/templates/common/index.js.map +1 -0
  494. package/dist/templates/common/skills/before-dev.md +35 -0
  495. package/dist/templates/common/skills/brainstorm.md +168 -0
  496. package/dist/templates/common/skills/break-loop.md +184 -0
  497. package/dist/templates/common/skills/check.md +93 -0
  498. package/dist/templates/common/skills/update-spec.md +351 -0
  499. package/dist/templates/copilot/hooks/session-start.py +547 -0
  500. package/dist/templates/copilot/hooks.json +19 -0
  501. package/dist/templates/copilot/index.d.ts +23 -0
  502. package/dist/templates/copilot/index.d.ts.map +1 -0
  503. package/dist/templates/copilot/index.js +54 -0
  504. package/dist/templates/copilot/index.js.map +1 -0
  505. package/dist/templates/copilot/prompts/before-dev.prompt.md +39 -0
  506. package/dist/templates/copilot/prompts/brainstorm.prompt.md +129 -0
  507. package/dist/templates/copilot/prompts/break-loop.prompt.md +129 -0
  508. package/dist/templates/copilot/prompts/check-cross-layer.prompt.md +157 -0
  509. package/dist/templates/copilot/prompts/check.prompt.md +97 -0
  510. package/dist/templates/copilot/prompts/create-command.prompt.md +116 -0
  511. package/dist/templates/copilot/prompts/finish-work.prompt.md +107 -0
  512. package/dist/templates/copilot/prompts/integrate-skill.prompt.md +223 -0
  513. package/dist/templates/copilot/prompts/onboard.prompt.md +362 -0
  514. package/dist/templates/copilot/prompts/parallel.prompt.md +204 -0
  515. package/dist/templates/copilot/prompts/record-session.prompt.md +66 -0
  516. package/dist/templates/copilot/prompts/start.prompt.md +63 -0
  517. package/dist/templates/copilot/prompts/update-spec.prompt.md +358 -0
  518. package/dist/templates/cursor/agents/trellis-check.md +114 -0
  519. package/dist/templates/cursor/agents/trellis-implement.md +109 -0
  520. package/dist/templates/cursor/agents/trellis-research.md +136 -0
  521. package/dist/templates/cursor/hooks.json +24 -0
  522. package/dist/templates/cursor/index.d.ts +13 -0
  523. package/dist/templates/cursor/index.d.ts.map +1 -0
  524. package/dist/templates/cursor/index.js +13 -0
  525. package/dist/templates/cursor/index.js.map +1 -0
  526. package/dist/templates/droid/droids/trellis-check.md +107 -0
  527. package/dist/templates/droid/droids/trellis-implement.md +102 -0
  528. package/dist/templates/droid/droids/trellis-research.md +137 -0
  529. package/dist/templates/droid/index.d.ts +15 -0
  530. package/dist/templates/droid/index.d.ts.map +1 -0
  531. package/dist/templates/droid/index.js +15 -0
  532. package/dist/templates/droid/index.js.map +1 -0
  533. package/dist/templates/droid/settings.json +59 -0
  534. package/dist/templates/extract.d.ts +40 -0
  535. package/dist/templates/extract.d.ts.map +1 -0
  536. package/dist/templates/extract.js +106 -0
  537. package/dist/templates/extract.js.map +1 -0
  538. package/dist/templates/gemini/agents/trellis-check.md +107 -0
  539. package/dist/templates/gemini/agents/trellis-implement.md +102 -0
  540. package/dist/templates/gemini/agents/trellis-research.md +136 -0
  541. package/dist/templates/gemini/index.d.ts +13 -0
  542. package/dist/templates/gemini/index.d.ts.map +1 -0
  543. package/dist/templates/gemini/index.js +13 -0
  544. package/dist/templates/gemini/index.js.map +1 -0
  545. package/dist/templates/gemini/settings.json +28 -0
  546. package/dist/templates/kiro/agents/trellis-check.json +14 -0
  547. package/dist/templates/kiro/agents/trellis-implement.json +14 -0
  548. package/dist/templates/kiro/agents/trellis-research.json +22 -0
  549. package/dist/templates/kiro/agents/trellis.json +20 -0
  550. package/dist/templates/kiro/hooks/cviauto-workflow-state.kiro.hook +14 -0
  551. package/dist/templates/kiro/index.d.ts +32 -0
  552. package/dist/templates/kiro/index.d.ts.map +1 -0
  553. package/dist/templates/kiro/index.js +28 -0
  554. package/dist/templates/kiro/index.js.map +1 -0
  555. package/dist/templates/markdown/agents.md +21 -0
  556. package/dist/templates/markdown/gitignore.txt +15 -0
  557. package/dist/templates/markdown/index.d.ts +27 -0
  558. package/dist/templates/markdown/index.d.ts.map +1 -0
  559. package/dist/templates/markdown/index.js +52 -0
  560. package/dist/templates/markdown/index.js.map +1 -0
  561. package/dist/templates/markdown/spec/backend/database-guidelines.md.txt +51 -0
  562. package/dist/templates/markdown/spec/backend/directory-structure.md.txt +54 -0
  563. package/dist/templates/markdown/spec/backend/error-handling.md.txt +51 -0
  564. package/dist/templates/markdown/spec/backend/index.md.txt +38 -0
  565. package/dist/templates/markdown/spec/backend/logging-guidelines.md.txt +51 -0
  566. package/dist/templates/markdown/spec/backend/quality-guidelines.md.txt +51 -0
  567. package/dist/templates/markdown/spec/frontend/component-guidelines.md.txt +59 -0
  568. package/dist/templates/markdown/spec/frontend/directory-structure.md.txt +54 -0
  569. package/dist/templates/markdown/spec/frontend/hook-guidelines.md.txt +51 -0
  570. package/dist/templates/markdown/spec/frontend/index.md.txt +39 -0
  571. package/dist/templates/markdown/spec/frontend/quality-guidelines.md.txt +51 -0
  572. package/dist/templates/markdown/spec/frontend/state-management.md.txt +51 -0
  573. package/dist/templates/markdown/spec/frontend/type-safety.md.txt +51 -0
  574. package/dist/templates/markdown/spec/guides/code-reuse-thinking-guide.md.txt +223 -0
  575. package/dist/templates/markdown/spec/guides/cross-layer-thinking-guide.md.txt +327 -0
  576. package/dist/templates/markdown/spec/guides/cross-platform-thinking-guide.md.txt +633 -0
  577. package/dist/templates/markdown/spec/guides/index.md.txt +97 -0
  578. package/dist/templates/markdown/workspace-index.md +125 -0
  579. package/dist/templates/markdown/worktree.yaml.txt +58 -0
  580. package/dist/templates/opencode/agents/trellis-check.md +122 -0
  581. package/dist/templates/opencode/agents/trellis-implement.md +118 -0
  582. package/dist/templates/opencode/agents/trellis-research.md +145 -0
  583. package/dist/templates/opencode/lib/cviauto-context.js +418 -0
  584. package/dist/templates/opencode/lib/session-utils.js +609 -0
  585. package/dist/templates/opencode/package.json +5 -0
  586. package/dist/templates/opencode/plugins/inject-subagent-context.js +570 -0
  587. package/dist/templates/opencode/plugins/inject-workflow-state.js +175 -0
  588. package/dist/templates/opencode/plugins/session-start.js +140 -0
  589. package/dist/templates/pi/agents/trellis-check.md +37 -0
  590. package/dist/templates/pi/agents/trellis-implement.md +42 -0
  591. package/dist/templates/pi/agents/trellis-research.md +25 -0
  592. package/dist/templates/pi/extensions/trellis/index.ts.txt +1680 -0
  593. package/dist/templates/pi/index.d.ts +5 -0
  594. package/dist/templates/pi/index.d.ts.map +1 -0
  595. package/dist/templates/pi/index.js +12 -0
  596. package/dist/templates/pi/index.js.map +1 -0
  597. package/dist/templates/pi/settings.json +6 -0
  598. package/dist/templates/qoder/agents/trellis-check.md +108 -0
  599. package/dist/templates/qoder/agents/trellis-implement.md +103 -0
  600. package/dist/templates/qoder/agents/trellis-research.md +137 -0
  601. package/dist/templates/qoder/index.d.ts +15 -0
  602. package/dist/templates/qoder/index.d.ts.map +1 -0
  603. package/dist/templates/qoder/index.js +15 -0
  604. package/dist/templates/qoder/index.js.map +1 -0
  605. package/dist/templates/qoder/settings.json +47 -0
  606. package/dist/templates/reasonix/agents/trellis-check.md +36 -0
  607. package/dist/templates/reasonix/agents/trellis-implement.md +41 -0
  608. package/dist/templates/reasonix/index.d.ts +13 -0
  609. package/dist/templates/reasonix/index.d.ts.map +1 -0
  610. package/dist/templates/reasonix/index.js +16 -0
  611. package/dist/templates/reasonix/index.js.map +1 -0
  612. package/dist/templates/shared-hooks/index.d.ts +58 -0
  613. package/dist/templates/shared-hooks/index.d.ts.map +1 -0
  614. package/dist/templates/shared-hooks/index.js +101 -0
  615. package/dist/templates/shared-hooks/index.js.map +1 -0
  616. package/dist/templates/shared-hooks/inject-shell-session-context.py +183 -0
  617. package/dist/templates/shared-hooks/inject-subagent-context.py +786 -0
  618. package/dist/templates/shared-hooks/inject-workflow-state.py +408 -0
  619. package/dist/templates/shared-hooks/session-start.py +844 -0
  620. package/dist/templates/template-utils.d.ts +28 -0
  621. package/dist/templates/template-utils.d.ts.map +1 -0
  622. package/dist/templates/template-utils.js +95 -0
  623. package/dist/templates/template-utils.js.map +1 -0
  624. package/dist/templates/trae/agents/trellis-check.md +108 -0
  625. package/dist/templates/trae/agents/trellis-implement.md +103 -0
  626. package/dist/templates/trae/agents/trellis-research.md +137 -0
  627. package/dist/templates/trae/hooks.json +27 -0
  628. package/dist/templates/trae/index.d.ts +15 -0
  629. package/dist/templates/trae/index.d.ts.map +1 -0
  630. package/dist/templates/trae/index.js +15 -0
  631. package/dist/templates/trae/index.js.map +1 -0
  632. package/dist/templates/trellis/agents/check.md +70 -0
  633. package/dist/templates/trellis/agents/implement.md +71 -0
  634. package/dist/templates/trellis/config.yaml +110 -0
  635. package/dist/templates/trellis/gitignore.txt +40 -0
  636. package/dist/templates/trellis/index.d.ts +65 -0
  637. package/dist/templates/trellis/index.d.ts.map +1 -0
  638. package/dist/templates/trellis/index.js +119 -0
  639. package/dist/templates/trellis/index.js.map +1 -0
  640. package/dist/templates/trellis/scripts/__init__.py +5 -0
  641. package/dist/templates/trellis/scripts/add_session.py +567 -0
  642. package/dist/templates/trellis/scripts/common/__init__.py +92 -0
  643. package/dist/templates/trellis/scripts/common/active_task.py +628 -0
  644. package/dist/templates/trellis/scripts/common/cli_adapter.py +851 -0
  645. package/dist/templates/trellis/scripts/common/config.py +444 -0
  646. package/dist/templates/trellis/scripts/common/cviauto_config.py +131 -0
  647. package/dist/templates/trellis/scripts/common/developer.py +190 -0
  648. package/dist/templates/trellis/scripts/common/git.py +31 -0
  649. package/dist/templates/trellis/scripts/common/git_context.py +106 -0
  650. package/dist/templates/trellis/scripts/common/io.py +37 -0
  651. package/dist/templates/trellis/scripts/common/log.py +45 -0
  652. package/dist/templates/trellis/scripts/common/packages_context.py +238 -0
  653. package/dist/templates/trellis/scripts/common/paths.py +447 -0
  654. package/dist/templates/trellis/scripts/common/safe_commit.py +315 -0
  655. package/dist/templates/trellis/scripts/common/session_context.py +821 -0
  656. package/dist/templates/trellis/scripts/common/task_context.py +223 -0
  657. package/dist/templates/trellis/scripts/common/task_queue.py +188 -0
  658. package/dist/templates/trellis/scripts/common/task_store.py +747 -0
  659. package/dist/templates/trellis/scripts/common/task_utils.py +274 -0
  660. package/dist/templates/trellis/scripts/common/tasks.py +112 -0
  661. package/dist/templates/trellis/scripts/common/types.py +110 -0
  662. package/dist/templates/trellis/scripts/common/workflow_phase.py +212 -0
  663. package/dist/templates/trellis/scripts/get_context.py +16 -0
  664. package/dist/templates/trellis/scripts/get_developer.py +26 -0
  665. package/dist/templates/trellis/scripts/hooks/linear_sync.py +243 -0
  666. package/dist/templates/trellis/scripts/init_developer.py +51 -0
  667. package/dist/templates/trellis/scripts/task.py +500 -0
  668. package/dist/templates/trellis/tasks/.gitkeep +0 -0
  669. package/dist/templates/trellis/workflow.md +697 -0
  670. package/dist/templates/zcode/agents/trellis-check.md +102 -0
  671. package/dist/templates/zcode/agents/trellis-implement.md +102 -0
  672. package/dist/templates/zcode/index.d.ts +15 -0
  673. package/dist/templates/zcode/index.d.ts.map +1 -0
  674. package/dist/templates/zcode/index.js +18 -0
  675. package/dist/templates/zcode/index.js.map +1 -0
  676. package/dist/types/ai-tools.d.ts +95 -0
  677. package/dist/types/ai-tools.d.ts.map +1 -0
  678. package/dist/types/ai-tools.js +330 -0
  679. package/dist/types/ai-tools.js.map +1 -0
  680. package/dist/types/migration.d.ts +125 -0
  681. package/dist/types/migration.d.ts.map +1 -0
  682. package/dist/types/migration.js +8 -0
  683. package/dist/types/migration.js.map +1 -0
  684. package/dist/utils/agent-refs.d.ts +31 -0
  685. package/dist/utils/agent-refs.d.ts.map +1 -0
  686. package/dist/utils/agent-refs.js +63 -0
  687. package/dist/utils/agent-refs.js.map +1 -0
  688. package/dist/utils/compare-versions.d.ts +12 -0
  689. package/dist/utils/compare-versions.d.ts.map +1 -0
  690. package/dist/utils/compare-versions.js +86 -0
  691. package/dist/utils/compare-versions.js.map +1 -0
  692. package/dist/utils/cwd-guard.d.ts +38 -0
  693. package/dist/utils/cwd-guard.d.ts.map +1 -0
  694. package/dist/utils/cwd-guard.js +62 -0
  695. package/dist/utils/cwd-guard.js.map +1 -0
  696. package/dist/utils/file-writer.d.ts +36 -0
  697. package/dist/utils/file-writer.d.ts.map +1 -0
  698. package/dist/utils/file-writer.js +203 -0
  699. package/dist/utils/file-writer.js.map +1 -0
  700. package/dist/utils/manifest-prune.d.ts +61 -0
  701. package/dist/utils/manifest-prune.d.ts.map +1 -0
  702. package/dist/utils/manifest-prune.js +137 -0
  703. package/dist/utils/manifest-prune.js.map +1 -0
  704. package/dist/utils/posix.d.ts +13 -0
  705. package/dist/utils/posix.d.ts.map +1 -0
  706. package/dist/utils/posix.js +15 -0
  707. package/dist/utils/posix.js.map +1 -0
  708. package/dist/utils/project-detector.d.ts +46 -0
  709. package/dist/utils/project-detector.d.ts.map +1 -0
  710. package/dist/utils/project-detector.js +666 -0
  711. package/dist/utils/project-detector.js.map +1 -0
  712. package/dist/utils/proxy.d.ts +25 -0
  713. package/dist/utils/proxy.d.ts.map +1 -0
  714. package/dist/utils/proxy.js +60 -0
  715. package/dist/utils/proxy.js.map +1 -0
  716. package/dist/utils/registry-config.d.ts +7 -0
  717. package/dist/utils/registry-config.d.ts.map +1 -0
  718. package/dist/utils/registry-config.js +171 -0
  719. package/dist/utils/registry-config.js.map +1 -0
  720. package/dist/utils/task-json.d.ts +13 -0
  721. package/dist/utils/task-json.d.ts.map +1 -0
  722. package/dist/utils/task-json.js +12 -0
  723. package/dist/utils/task-json.js.map +1 -0
  724. package/dist/utils/template-fetcher.d.ts +161 -0
  725. package/dist/utils/template-fetcher.d.ts.map +1 -0
  726. package/dist/utils/template-fetcher.js +956 -0
  727. package/dist/utils/template-fetcher.js.map +1 -0
  728. package/dist/utils/template-hash.d.ts +123 -0
  729. package/dist/utils/template-hash.d.ts.map +1 -0
  730. package/dist/utils/template-hash.js +334 -0
  731. package/dist/utils/template-hash.js.map +1 -0
  732. package/dist/utils/uninstall-scrubbers.d.ts +64 -0
  733. package/dist/utils/uninstall-scrubbers.d.ts.map +1 -0
  734. package/dist/utils/uninstall-scrubbers.js +367 -0
  735. package/dist/utils/uninstall-scrubbers.js.map +1 -0
  736. package/dist/utils/workflow-resolver.d.ts +86 -0
  737. package/dist/utils/workflow-resolver.d.ts.map +1 -0
  738. package/dist/utils/workflow-resolver.js +265 -0
  739. package/dist/utils/workflow-resolver.js.map +1 -0
  740. package/package.json +89 -0
@@ -0,0 +1,1680 @@
1
+ import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
2
+ import { createHash, randomBytes } from "node:crypto";
3
+ import { delimiter, dirname, isAbsolute, join, resolve } from "node:path";
4
+ import { spawn, spawnSync } from "node:child_process";
5
+
6
+ // ── Types ──────────────────────────────────────────────────────────────
7
+ type JsonObject = Record<string, unknown>;
8
+ type TextContent = { type: "text"; text: string };
9
+ interface PiToolResult {
10
+ content: TextContent[];
11
+ details?: unknown;
12
+ }
13
+ interface PiExtensionContext {
14
+ hasUI?: boolean;
15
+ sessionManager?: {
16
+ getSessionId?: () => string;
17
+ getSessionFile?: () => string | undefined;
18
+ };
19
+ ui?: {
20
+ notify?: (msg: string, type?: "info" | "warning" | "error") => void;
21
+ };
22
+ }
23
+ interface SubagentInput {
24
+ agent?: string;
25
+ prompt?: string;
26
+ mode?: "single" | "parallel" | "chain";
27
+ prompts?: string[];
28
+ model?: string;
29
+ thinking?: string;
30
+ }
31
+ interface AgentConfig {
32
+ model?: string;
33
+ thinking?: string;
34
+ tools?: string[];
35
+ fallbackModels: string[];
36
+ }
37
+ interface PiRunConfig {
38
+ model?: string;
39
+ thinking?: string;
40
+ tools?: string[];
41
+ }
42
+
43
+ // ── Lazy-load pi-tui (avoid failing top-level imports) ─────────────────
44
+ let _piTui: {
45
+ visibleWidth?: (s: string) => number;
46
+ truncateToWidth?: (s: string, w: number, ellipsis?: string) => string;
47
+ } | null = null;
48
+ function piTui() {
49
+ if (!_piTui) {
50
+ try {
51
+ _piTui = require("@earendil-works/pi-tui");
52
+ } catch {
53
+ _piTui = {};
54
+ }
55
+ }
56
+ return _piTui;
57
+ }
58
+ function trunc(s: string, w: number) {
59
+ const t = piTui();
60
+ return t.truncateToWidth
61
+ ? t.truncateToWidth(s, w, "…")
62
+ : s.length <= w
63
+ ? s
64
+ : w > 1
65
+ ? s.slice(0, w - 1) + "…"
66
+ : s.slice(0, w);
67
+ }
68
+
69
+ // ── Constants ─────────────────────────────────────────────────────────
70
+ const TRELLIS_AGENT_JSONL: Record<string, string> = {
71
+ "cviauto-implement": "implement.jsonl",
72
+ "trellis-implement": "implement.jsonl",
73
+ implement: "implement.jsonl",
74
+ "cviauto-check": "check.jsonl",
75
+ "trellis-check": "check.jsonl",
76
+ check: "check.jsonl",
77
+ };
78
+ const MAX_STDOUT = 8 * 1024 * 1024;
79
+ const MAX_STDERR = 1024 * 1024;
80
+ const MAX_TAIL = 256 * 1024;
81
+ const MAX_LINE_BUFFER = 1024 * 1024;
82
+ const MAX_TOOL_ARG_CHARS = 2048;
83
+ const MAX_TOOLS = 256;
84
+ const MAX_PARALLEL_PROMPTS = 6;
85
+ const ABORT_KILL_GRACE_MS = 1500;
86
+ const SESSION_OVERVIEW_TIMEOUT_MS = 1500;
87
+ const THROTTLE_MS = 500;
88
+ const FIRST_REPLY_NOTICE = `<first-reply-notice>
89
+ First visible reply: say once in Chinese that Cviauto SessionStart context is loaded, then answer directly.
90
+ This notice is one-shot: do not repeat it after the first assistant reply in the same session.
91
+ </first-reply-notice>`;
92
+
93
+ // ── State types ───────────────────────────────────────────────────────
94
+ type RunStatus = "pending" | "running" | "succeeded" | "failed" | "cancelled";
95
+ type ToolStatus = "running" | "succeeded" | "failed";
96
+
97
+ interface Usage {
98
+ input: number;
99
+ output: number;
100
+ cacheRead: number;
101
+ cacheWrite: number;
102
+ cost: number;
103
+ ctxTokens: number;
104
+ turns: number;
105
+ }
106
+ interface ToolTrace {
107
+ id: string;
108
+ name: string;
109
+ args: string;
110
+ status: ToolStatus;
111
+ startedAt: number;
112
+ finishedAt?: number;
113
+ }
114
+ interface RunState {
115
+ id: string;
116
+ agent: string;
117
+ prompt: string;
118
+ step?: number;
119
+ status: RunStatus;
120
+ startedAt?: number;
121
+ finishedAt?: number;
122
+ finalText: string;
123
+ textTail: string;
124
+ thinkingTail: string;
125
+ stderrTail: string;
126
+ tools: ToolTrace[];
127
+ usage: Usage;
128
+ model?: string;
129
+ thinking?: string;
130
+ errorMessage?: string;
131
+ }
132
+ interface ProgressDetails {
133
+ kind: "trellis-subagent-progress";
134
+ agent: string;
135
+ mode: "single" | "parallel" | "chain";
136
+ startedAt: number;
137
+ updatedAt: number;
138
+ final: boolean;
139
+ runs: RunState[];
140
+ }
141
+
142
+ // ── Native partial-update card state ──────────────────────────────────
143
+ interface NativeCardHandle {
144
+ state: JsonObject;
145
+ invalidate: () => void;
146
+ updatedAt: number;
147
+ }
148
+ const MAX_NATIVE_CARDS = 20;
149
+ const nativeCards = new Map<string, NativeCardHandle>();
150
+ let activeSubagentToolCallId: string | null = null;
151
+ function rememberNativeCard(id: string, card: NativeCardHandle) {
152
+ nativeCards.set(id, card);
153
+ const active = activeSubagentToolCallId
154
+ ? nativeCards.get(activeSubagentToolCallId)
155
+ : undefined;
156
+ if (!active || card.updatedAt >= active.updatedAt)
157
+ activeSubagentToolCallId = id;
158
+ for (const key of nativeCards.keys()) {
159
+ if (nativeCards.size <= MAX_NATIVE_CARDS) break;
160
+ if (key !== activeSubagentToolCallId) nativeCards.delete(key);
161
+ }
162
+ }
163
+ function totalUsage(d: ProgressDetails): Usage {
164
+ const u: Usage = {
165
+ input: 0,
166
+ output: 0,
167
+ cacheRead: 0,
168
+ cacheWrite: 0,
169
+ cost: 0,
170
+ ctxTokens: 0,
171
+ turns: 0,
172
+ };
173
+ for (const r of d.runs) {
174
+ u.input += r.usage.input;
175
+ u.output += r.usage.output;
176
+ u.cacheRead += r.usage.cacheRead;
177
+ u.cacheWrite += r.usage.cacheWrite;
178
+ u.cost += r.usage.cost;
179
+ u.ctxTokens = Math.max(u.ctxTokens, r.usage.ctxTokens);
180
+ u.turns += r.usage.turns;
181
+ }
182
+ return u;
183
+ }
184
+ function activeRun(d: ProgressDetails) {
185
+ return d.runs.find((r) => r.status === "running") ?? d.runs.at(-1);
186
+ }
187
+ function toolArgs(t: ToolTrace) {
188
+ try {
189
+ return JSON.parse(t.args) as Record<string, unknown>;
190
+ } catch {
191
+ return {};
192
+ }
193
+ }
194
+ function bashCommand(t: ToolTrace) {
195
+ const a = toolArgs(t);
196
+ return String(a.command || "").toLowerCase();
197
+ }
198
+ function isSearchTool(t: ToolTrace) {
199
+ return t.name === "read" || t.name === "grep" || t.name === "find";
200
+ }
201
+ function isMutationTool(t: ToolTrace) {
202
+ return t.name === "edit" || t.name === "write";
203
+ }
204
+ function isValidationCommand(t: ToolTrace) {
205
+ const c = bashCommand(t);
206
+ return /\b(test|typecheck|lint|build|gofmt|go test|npm run|pnpm|vitest|tsc)\b/.test(
207
+ c,
208
+ );
209
+ }
210
+ function isInspectionCommand(t: ToolTrace) {
211
+ const c = bashCommand(t);
212
+ return /\b(rg|grep|find|git diff|git status|ls|tree)\b/.test(c);
213
+ }
214
+ function thinkingIntent(text: string) {
215
+ const s = text.toLowerCase();
216
+ if (/error|failed|failure|panic|exception|报错|失败|错误|异常/.test(s))
217
+ return "Analyzing failure cause";
218
+ if (/test|verify|check|typecheck|lint|验证|测试|检查/.test(s))
219
+ return "Planning verification steps";
220
+ if (/plan|approach|design|strategy|方案|计划|思路|设计/.test(s))
221
+ return "Structuring the implementation approach";
222
+ if (/implement|change|edit|modify|refactor|实现|修改|重构/.test(s))
223
+ return "Reasoning through code changes";
224
+ if (/inspect|search|locate|read|context|定位|搜索|阅读|上下文/.test(s))
225
+ return "Locating relevant context";
226
+ return "";
227
+ }
228
+ function behaviorSummary(r: RunState) {
229
+ if (r.status === "succeeded") return "Task completed and result returned";
230
+ if (r.status === "failed")
231
+ return "Task failed and error details were retained";
232
+
233
+ const runningTool = r.tools.findLast((t) => t.status === "running");
234
+ if (runningTool) {
235
+ if (isMutationTool(runningTool)) return "Applying the plan to code";
236
+ if (runningTool.name === "bash" && isValidationCommand(runningTool))
237
+ return "Verifying whether the implementation passes";
238
+ if (runningTool.name === "bash" && isInspectionCommand(runningTool))
239
+ return "Inspecting current code state";
240
+ if (isSearchTool(runningTool)) return "Locating relevant code and context";
241
+ if (runningTool.name === "bash")
242
+ return "Validating assumptions with commands";
243
+ return "Using tools to advance the task";
244
+ }
245
+
246
+ const recent = r.tools.slice(-5);
247
+ if (recent.some((t) => t.status === "failed"))
248
+ return "Investigating tool or command failure";
249
+ if (recent.some(isMutationTool)) return "Reviewing recent changes";
250
+ if (recent.some((t) => t.name === "bash" && isValidationCommand(t)))
251
+ return "Analyzing verification results";
252
+ if (
253
+ recent.length >= 2 &&
254
+ recent.every(
255
+ (t) => isSearchTool(t) || (t.name === "bash" && isInspectionCommand(t)),
256
+ )
257
+ )
258
+ return "Mapping code structure and impact";
259
+
260
+ const intent = thinkingIntent(`${r.thinkingTail}\n${r.textTail}`);
261
+ if (intent) return intent;
262
+ if (!r.tools.length) return "Understanding the task and planning execution";
263
+ return "Advancing the task and preparing next steps";
264
+ }
265
+ function progressState(d: ProgressDetails) {
266
+ const running = d.runs.filter((r) => r.status === "running").length;
267
+ const failed = d.runs.some((r) => r.status === "failed");
268
+ return failed
269
+ ? "failed"
270
+ : d.final
271
+ ? "completed"
272
+ : running
273
+ ? `${running} running`
274
+ : "pending";
275
+ }
276
+ function progressDone(d: ProgressDetails) {
277
+ return d.runs.filter((r) => r.status !== "pending" && r.status !== "running")
278
+ .length;
279
+ }
280
+ function summaryText(text: string) {
281
+ return `${text.trim().replace(/[。.!?…]+$/u, "")}...`;
282
+ }
283
+ function splitModelThinking(model?: string, fallbackThinking?: string) {
284
+ const m = model?.match(/^(.*):(off|minimal|low|medium|high|xhigh)$/i);
285
+ return {
286
+ model: m ? m[1] : model,
287
+ thinking: (m?.[2] ?? fallbackThinking)?.toLowerCase(),
288
+ };
289
+ }
290
+ function modelLabel(r: RunState) {
291
+ const { model, thinking } = splitModelThinking(r.model, r.thinking);
292
+ if (!model) return undefined;
293
+ return thinking && thinking !== "off" ? `${model}(${thinking})` : model;
294
+ }
295
+ function applyRunConfig(r: RunState, cfg: PiRunConfig) {
296
+ const parsed = splitModelThinking(cfg.model, cfg.thinking);
297
+ r.model = parsed.model;
298
+ r.thinking = parsed.thinking;
299
+ }
300
+ function runElapsed(d: ProgressDetails, r: RunState) {
301
+ const start = r.startedAt ?? d.startedAt;
302
+ const end =
303
+ r.finishedAt ?? (r.status === "running" ? Date.now() : d.updatedAt);
304
+ return fmtDur(Math.max(0, end - start));
305
+ }
306
+ function runHeader(d: ProgressDetails, r: RunState) {
307
+ const usage = fmtUsage(r.usage, modelLabel(r)) || fmtUsage(totalUsage(d));
308
+ return `${r.agent} · ${progressDone(d)}/${d.runs.length} done · ${progressState(d)} · ${runElapsed(d, r)}${usage ? ` · ${usage}` : ""}`;
309
+ }
310
+ function renderRunBlock(
311
+ lines: string[],
312
+ d: ProgressDetails,
313
+ run: RunState,
314
+ expanded: boolean,
315
+ ) {
316
+ const step = run.step ? `step ${run.step} · ` : "";
317
+ lines.push(` - ${step}${runHeader(d, run)}`);
318
+ const summary = behaviorSummary(run);
319
+ if (summary) lines.push(` › ${summaryText(summary)}`);
320
+ const visibleTools = expanded ? run.tools.slice(-8) : run.tools.slice(-1);
321
+ for (const t of visibleTools)
322
+ lines.push(` ${toolIcon(t.status)} ${toolBrief(t)}`);
323
+ if (expanded && run.errorMessage) {
324
+ lines.push(` ✗ ${oneLine(run.errorMessage, 120)}`);
325
+ }
326
+ }
327
+ function renderProgressCard(
328
+ d: ProgressDetails,
329
+ expanded: boolean,
330
+ w: number,
331
+ ): string[] {
332
+ const r = activeRun(d);
333
+ if (!r) return [];
334
+ const spinner = ["◐", "◓", "◑", "◒"][Math.floor(Date.now() / 250) % 4]!;
335
+ const icon = d.final
336
+ ? d.runs.some((x) => x.status === "failed")
337
+ ? "✗"
338
+ : "✓"
339
+ : spinner;
340
+ const totalElapsed = fmtDur(
341
+ (d.final ? d.updatedAt : Date.now()) - d.startedAt,
342
+ );
343
+ const lines: string[] = [
344
+ `${icon} subagent ${d.mode} · total ${totalElapsed}`,
345
+ ];
346
+
347
+ if (!expanded) {
348
+ renderRunBlock(lines, d, r, false);
349
+ lines.push(" Alt+O expand latest subagent card");
350
+ return lines.map((l) => trunc(l, w));
351
+ }
352
+
353
+ for (const run of d.runs) renderRunBlock(lines, d, run, true);
354
+ lines.push(" Alt+O collapse latest subagent card");
355
+ const max = 48;
356
+ const shown =
357
+ lines.length > max
358
+ ? [
359
+ ...lines.slice(0, max - 1),
360
+ ` … ${lines.length - max + 1} lines hidden`,
361
+ ]
362
+ : lines;
363
+ return shown.map((l) => trunc(l, w));
364
+ }
365
+ function progressKey(d: ProgressDetails) {
366
+ return d.runs
367
+ .map((r) => {
368
+ const t = r.tools.at(-1);
369
+ return [
370
+ r.id,
371
+ r.status,
372
+ r.tools.length,
373
+ t?.id ?? "",
374
+ t?.status ?? "",
375
+ r.usage.turns,
376
+ r.usage.input,
377
+ r.usage.output,
378
+ r.usage.cacheRead,
379
+ r.usage.cacheWrite,
380
+ r.usage.ctxTokens,
381
+ r.model ?? "",
382
+ r.thinking ?? "",
383
+ r.errorMessage ?? "",
384
+ ].join("~");
385
+ })
386
+ .join("|");
387
+ }
388
+
389
+ // ── Utilities ─────────────────────────────────────────────────────────
390
+ function isObj(v: unknown): v is JsonObject {
391
+ return typeof v === "object" && v !== null && !Array.isArray(v);
392
+ }
393
+ function str(v: unknown): string | null {
394
+ return typeof v === "string" && v.trim() ? v.trim() : null;
395
+ }
396
+ function num(v: unknown): number {
397
+ return typeof v === "number" && Number.isFinite(v) ? v : 0;
398
+ }
399
+ function hash(s: string) {
400
+ return createHash("sha256").update(s).digest("hex").slice(0, 24);
401
+ }
402
+ function readText(p: string) {
403
+ try {
404
+ return readFileSync(p, "utf-8");
405
+ } catch {
406
+ return "";
407
+ }
408
+ }
409
+ function exists(p: string) {
410
+ try {
411
+ return statSync(p).isFile();
412
+ } catch {
413
+ return false;
414
+ }
415
+ }
416
+ function shellQuote(v: string) {
417
+ return `'${v.replace(/'/g, `'\\''`)}'`;
418
+ }
419
+ function callStr(cb: (() => string | undefined) | undefined): string | null {
420
+ if (!cb) return null;
421
+ try {
422
+ return str(cb());
423
+ } catch {
424
+ return null;
425
+ }
426
+ }
427
+ function lookupStr(data: unknown, keys: string[]): string | null {
428
+ if (!isObj(data)) return null;
429
+ for (const k of keys) {
430
+ const v = str(data[k]);
431
+ if (v) return v;
432
+ }
433
+ for (const nk of [
434
+ "input",
435
+ "properties",
436
+ "event",
437
+ "hook_input",
438
+ "hookInput",
439
+ ]) {
440
+ const nested = data[nk];
441
+ const v = lookupStr(nested, keys);
442
+ if (v) return v;
443
+ }
444
+ return null;
445
+ }
446
+ function cmdHasTrellisCtx(cmd: string) {
447
+ const t = cmd.trimStart();
448
+ return (
449
+ /^export\s+TRELLIS_CONTEXT_ID=/.test(t) ||
450
+ /^TRELLIS_CONTEXT_ID=/.test(t) ||
451
+ /^env\s+.*TRELLIS_CONTEXT_ID=/.test(t)
452
+ );
453
+ }
454
+ function fmtDur(ms: number) {
455
+ if (ms < 1000) return `${ms}ms`;
456
+ const s = Math.floor(ms / 1000);
457
+ if (s < 60) return `${s}s`;
458
+ return `${Math.floor(s / 60)}m${s % 60}s`;
459
+ }
460
+ function fmtNum(n: number) {
461
+ if (!n) return "0";
462
+ if (Math.abs(n) < 1000) return `${n}`;
463
+ if (Math.abs(n) < 1000000) return `${(n / 1000).toFixed(1)}k`;
464
+ return `${(n / 1000000).toFixed(1)}m`;
465
+ }
466
+ function fmtUsage(u: Usage, m?: string) {
467
+ const p: string[] = [];
468
+ if (u.turns) p.push(`${u.turns}t`);
469
+ if (u.input) p.push(`↑${fmtNum(u.input)}`);
470
+ if (u.output) p.push(`↓${fmtNum(u.output)}`);
471
+ if (u.cost) p.push(`$${u.cost.toFixed(3)}`);
472
+ if (u.ctxTokens) p.push(`ctx:${fmtNum(u.ctxTokens)}`);
473
+ if (m) p.push(m);
474
+ return p.join(" ");
475
+ }
476
+ function statusIcon(s: RunStatus) {
477
+ return s === "pending"
478
+ ? "○"
479
+ : s === "running"
480
+ ? "●"
481
+ : s === "succeeded"
482
+ ? "✓"
483
+ : s === "failed"
484
+ ? "✗"
485
+ : "⊘";
486
+ }
487
+ function toolIcon(s: ToolStatus) {
488
+ return s === "running" ? "•" : s === "succeeded" ? "✓" : "✗";
489
+ }
490
+ function latest(text: string, n: number) {
491
+ return text
492
+ .split(/\r?\n/)
493
+ .map((l) => l.trimEnd())
494
+ .filter((l) => l.trim())
495
+ .slice(-n);
496
+ }
497
+ function appendTail(cur: string, next: string, max: number) {
498
+ if (!next) return cur;
499
+ const c = cur + next;
500
+ return c.length <= max ? c : c.slice(-max);
501
+ }
502
+ function extractText(content: unknown): string {
503
+ if (typeof content === "string") return content;
504
+ if (!Array.isArray(content)) return "";
505
+ return content
506
+ .map((b) =>
507
+ isObj(b) && b.type === "text" && typeof b.text === "string" ? b.text : "",
508
+ )
509
+ .join("");
510
+ }
511
+ function extractThinking(content: unknown): string {
512
+ if (!Array.isArray(content)) return "";
513
+ return content
514
+ .map((b) =>
515
+ isObj(b) && b.type === "thinking" && typeof b.thinking === "string"
516
+ ? b.thinking
517
+ : "",
518
+ )
519
+ .join("\n");
520
+ }
521
+ function newUsage(): Usage {
522
+ return {
523
+ input: 0,
524
+ output: 0,
525
+ cacheRead: 0,
526
+ cacheWrite: 0,
527
+ cost: 0,
528
+ ctxTokens: 0,
529
+ turns: 0,
530
+ };
531
+ }
532
+ function newRun(
533
+ id: string,
534
+ agent: string,
535
+ prompt: string,
536
+ step?: number,
537
+ ): RunState {
538
+ return {
539
+ id,
540
+ agent,
541
+ prompt: trunc(prompt.replace(/\s+/g, " ").trim(), 120) || "(empty)",
542
+ step,
543
+ status: "pending",
544
+ finalText: "",
545
+ textTail: "",
546
+ thinkingTail: "",
547
+ stderrTail: "",
548
+ tools: [],
549
+ usage: newUsage(),
550
+ };
551
+ }
552
+ function cloneProgress(d: ProgressDetails): ProgressDetails {
553
+ return {
554
+ ...d,
555
+ runs: d.runs.map((r) => ({
556
+ ...r,
557
+ tools: r.tools.map((t) => ({ ...t })),
558
+ usage: { ...r.usage },
559
+ })),
560
+ };
561
+ }
562
+
563
+ function oneLine(v: unknown, max = 80) {
564
+ return String(v || "...")
565
+ .replace(/\s+/g, " ")
566
+ .trim()
567
+ .slice(0, max);
568
+ }
569
+ function summarizeToolArgs(name: string, args: unknown): string {
570
+ const a = isObj(args) ? args : {};
571
+ const summary: JsonObject = {};
572
+ if ("path" in a) summary.path = oneLine(a.path, 240);
573
+ if ("file_path" in a) summary.file_path = oneLine(a.file_path, 240);
574
+ if ("command" in a) summary.command = oneLine(a.command, 240);
575
+ if ("pattern" in a) summary.pattern = oneLine(a.pattern, 120);
576
+ if ("limit" in a) summary.limit = a.limit;
577
+ if ("offset" in a) summary.offset = a.offset;
578
+ if (name === "edit" && Array.isArray(a.edits))
579
+ summary.edits = `${a.edits.length} edit(s)`;
580
+ if (name === "write" && "content" in a)
581
+ summary.content = `<${String(a.content ?? "").length} chars>`;
582
+ const json = JSON.stringify(
583
+ Object.keys(summary).length ? summary : { tool: name },
584
+ );
585
+ return json.length <= MAX_TOOL_ARG_CHARS
586
+ ? json
587
+ : json.slice(0, MAX_TOOL_ARG_CHARS);
588
+ }
589
+ function toolBrief(t: ToolTrace): string {
590
+ const a = toolArgs(t);
591
+ if (t.name === "read") return `read: ${oneLine(a.path || a.file_path, 80)}`;
592
+ if (t.name === "bash") return `bash: ${oneLine(a.command, 60)}`;
593
+ if (t.name === "write") return `write: ${oneLine(a.path || a.file_path, 80)}`;
594
+ if (t.name === "edit") return `edit: ${oneLine(a.path || a.file_path, 80)}`;
595
+ if (t.name === "grep") return `grep: ${oneLine(a.pattern, 50)}`;
596
+ if (t.name === "find") return `find: ${oneLine(a.pattern || "*", 50)}`;
597
+ return oneLine(t.name, 50);
598
+ }
599
+
600
+ // ── Pi CLI path resolution ────────────────────────────────────────────
601
+ const PI_CLI_SEGMENTS = [
602
+ ["node_modules", "@earendil-works", "pi-coding-agent", "dist", "cli.js"],
603
+ ["node_modules", "@mariozechner", "pi-coding-agent", "dist", "cli.js"],
604
+ ];
605
+
606
+ function resolvePiCli(): { command: string; args: string[] } {
607
+ const envCli = str(process.env.TRELLIS_PI_CLI_JS);
608
+ if (envCli) {
609
+ const p = resolve(envCli);
610
+ if (!exists(p)) throw new Error(`TRELLIS_PI_CLI_JS missing: ${p}`);
611
+ return { command: process.execPath, args: [p] };
612
+ }
613
+ const candidates: string[] = [];
614
+ for (const arg of process.argv)
615
+ if (/pi-coding-agent[\\/]dist[\\/]cli\.js$/i.test(arg))
616
+ candidates.push(resolve(arg));
617
+ const prefix =
618
+ str(process.env.npm_config_prefix) ?? str(process.env.NPM_CONFIG_PREFIX);
619
+ const appData = str(process.env.APPDATA);
620
+ const pathVal = process.env.PATH ?? process.env.Path ?? "";
621
+ const addBase = (base: string) => {
622
+ for (const seg of PI_CLI_SEGMENTS) candidates.push(join(base, ...seg));
623
+ };
624
+ if (prefix) {
625
+ addBase(prefix);
626
+ addBase(join(prefix, "lib"));
627
+ }
628
+ if (appData) addBase(join(appData, "npm"));
629
+ for (const entry of pathVal.split(delimiter)) {
630
+ const e = entry.trim();
631
+ if (!e) continue;
632
+ addBase(e);
633
+ addBase(dirname(e));
634
+ addBase(join(dirname(e), "lib"));
635
+ }
636
+ for (const c of [...new Set(candidates)])
637
+ if (exists(c)) return { command: process.execPath, args: [c] };
638
+ return { command: "pi", args: [] };
639
+ }
640
+
641
+ function resolveRunCfg(
642
+ input: SubagentInput,
643
+ agentCfg: AgentConfig,
644
+ inheritedThinking?: string,
645
+ ): PiRunConfig {
646
+ const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh"];
647
+ const normalize = (v: unknown): string | undefined => {
648
+ const s = typeof v === "string" && v.trim() ? v.trim().toLowerCase() : "";
649
+ return THINKING_LEVELS.includes(s) ? s : undefined;
650
+ };
651
+ const suffixRe = /:(off|minimal|low|medium|high|xhigh)$/i;
652
+ const inputModel = str(input.model);
653
+ const agentModel = agentCfg.model;
654
+ const rawModel = inputModel ?? agentModel;
655
+ const inputSuffixThinking = normalize(inputModel?.match(suffixRe)?.[1]);
656
+ const agentSuffixThinking = normalize(agentModel?.match(suffixRe)?.[1]);
657
+ const baseModel = rawModel?.replace(suffixRe, "");
658
+ const thinking =
659
+ normalize(input.thinking) ??
660
+ inputSuffixThinking ??
661
+ normalize(agentCfg.thinking) ??
662
+ agentSuffixThinking ??
663
+ normalize(inheritedThinking);
664
+ if (baseModel && thinking && thinking !== "off")
665
+ return { model: `${baseModel}:${thinking}`, thinking, tools: agentCfg.tools };
666
+ return { model: baseModel || rawModel, thinking, tools: agentCfg.tools };
667
+ }
668
+
669
+ function buildPiArgs(cfg: PiRunConfig): string[] {
670
+ const args = ["--mode", "json", "-p", "--no-session"];
671
+ if (cfg.model)
672
+ args.push(
673
+ "--model",
674
+ cfg.thinking && cfg.thinking !== "off" && !cfg.model.includes(":")
675
+ ? `${cfg.model}:${cfg.thinking}`
676
+ : cfg.model,
677
+ );
678
+ else if (cfg.thinking && cfg.thinking !== "off")
679
+ args.push("--thinking", cfg.thinking);
680
+ if (cfg.tools && cfg.tools.length > 0)
681
+ args.push("--tools", cfg.tools.join(","));
682
+ return args;
683
+ }
684
+
685
+ // ── BoundedBufferCollector ─────────────────────────────────────────────
686
+ class BBC {
687
+ private c: Buffer[] = [];
688
+ private len = 0;
689
+ private trunc = 0;
690
+ constructor(private max: number) {}
691
+ append(b: Buffer) {
692
+ if (b.length >= this.max) {
693
+ this.trunc += this.len + b.length - this.max;
694
+ this.c = [b.subarray(b.length - this.max)];
695
+ this.len = this.max;
696
+ return;
697
+ }
698
+ this.c.push(b);
699
+ this.len += b.length;
700
+ while (this.len > this.max) {
701
+ const f = this.c[0]!;
702
+ if (f.length <= this.len - this.max) {
703
+ this.c.shift();
704
+ this.len -= f.length;
705
+ this.trunc += f.length;
706
+ } else {
707
+ const ov = this.len - this.max;
708
+ this.c[0] = f.subarray(ov);
709
+ this.len -= ov;
710
+ this.trunc += ov;
711
+ break;
712
+ }
713
+ }
714
+ }
715
+ toString() {
716
+ const body = Buffer.concat(this.c, this.len).toString("utf-8");
717
+ return this.trunc ? `[${this.trunc} bytes truncated]\n${body}` : body;
718
+ }
719
+ }
720
+
721
+ // ── Cviauto Context ────────────────────────────────────────────────────
722
+ function findRoot(start: string): string {
723
+ let c = resolve(start);
724
+ while (true) {
725
+ if (existsSync(join(c, ".cviauto")) || existsSync(join(c, ".pi"))) return c;
726
+ const p = dirname(c);
727
+ if (p === c) return resolve(start);
728
+ c = p;
729
+ }
730
+ }
731
+ function splitFM(c: string) {
732
+ const m = c.replace(/^\uFEFF/, "").match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/);
733
+ return m
734
+ ? { fm: m[1] ?? "", body: c.slice(m[0].length) }
735
+ : { fm: "", body: c };
736
+ }
737
+ function stripFM(c: string) {
738
+ return splitFM(c).body.trimStart();
739
+ }
740
+ function parseAgentFM(c: string): AgentConfig {
741
+ const cfg: AgentConfig = { fallbackModels: [] };
742
+ const { fm } = splitFM(c);
743
+ const lines = fm.split(/\r?\n/);
744
+ for (let i = 0; i < lines.length; i++) {
745
+ const m = (lines[i] ?? "").match(/^([A-Za-z][A-Za-z0-9_-]*)\s*:\s*(.*)$/);
746
+ if (!m) continue;
747
+ const k = m[1] ?? "",
748
+ v = m[2] ?? "";
749
+ if (k === "model")
750
+ cfg.model = v.trim().replace(/^["']|["']$/g, "") || undefined;
751
+ else if (k === "thinking")
752
+ cfg.thinking = (v.trim().replace(/^["']|["']$/g, "") || undefined) as
753
+ | string
754
+ | undefined;
755
+ else if (k === "fallbackModels" || k === "fallback_models") {
756
+ if (v.trim()) {
757
+ cfg.fallbackModels = v
758
+ .trim()
759
+ .replace(/^\[|\]$/g, "")
760
+ .split(",")
761
+ .map((s) => s.trim().replace(/^["']|["']$/g, ""))
762
+ .filter(Boolean);
763
+ } else {
764
+ i++;
765
+ while (i < lines.length && /^\s+-\s/.test(lines[i] ?? "")) {
766
+ const item = (lines[i] ?? "")
767
+ .trim()
768
+ .replace(/^-\s+/, "")
769
+ .replace(/^["']|["']$/g, "");
770
+ if (item) cfg.fallbackModels.push(item);
771
+ i++;
772
+ }
773
+ i--;
774
+ }
775
+ } else if (k === "tools") {
776
+ // Pi tool names are lowercase (read, bash, edit, write, grep, find, ls).
777
+ // Normalize to lowercase so mixed-case frontmatter still matches.
778
+ if (v.trim()) {
779
+ cfg.tools = v
780
+ .trim()
781
+ .split(",")
782
+ .map((s) => s.trim().replace(/^["']|["']$/g, "").toLowerCase())
783
+ .filter(Boolean);
784
+ }
785
+ }
786
+ }
787
+ return cfg;
788
+ }
789
+
790
+ function contextKey(input?: unknown, ctx?: PiExtensionContext): string | null {
791
+ const ov = str(process.env.TRELLIS_CONTEXT_ID);
792
+ if (ov) return ov.replace(/[^A-Za-z0-9._-]+/g, "_").slice(0, 160) || hash(ov);
793
+ const sessionId =
794
+ callStr(ctx?.sessionManager?.getSessionId) ??
795
+ str(process.env.PI_SESSION_ID) ??
796
+ str(process.env.PI_SESSIONID) ??
797
+ lookupStr(input, ["session_id", "sessionId", "sessionID"]);
798
+ if (sessionId)
799
+ return `pi_${sessionId.replace(/[^A-Za-z0-9._-]+/g, "_") || hash(sessionId)}`;
800
+ const transcriptPath =
801
+ callStr(ctx?.sessionManager?.getSessionFile) ??
802
+ lookupStr(input, ["transcript_path", "transcriptPath", "transcript"]);
803
+ if (transcriptPath) return `pi_transcript_${hash(transcriptPath)}`;
804
+ return null;
805
+ }
806
+
807
+ function readTaskDir(root: string, key: string | null): string | null {
808
+ if (!key) return null;
809
+ try {
810
+ const ctx = JSON.parse(
811
+ readText(join(root, ".cviauto", ".runtime", "sessions", `${key}.json`)),
812
+ ) as JsonObject;
813
+ let ref = str(ctx.current_task);
814
+ if (!ref) return null;
815
+ ref = ref;
816
+ ref = ref.replace(/\\/g, "/").replace(/^\.\//, "");
817
+ if (ref.startsWith("tasks/")) ref = `.cviauto/${ref}`;
818
+ return ref.startsWith(".cviauto/")
819
+ ? join(root, ref)
820
+ : isAbsolute(ref)
821
+ ? ref
822
+ : join(root, ".cviauto", "tasks", ref);
823
+ } catch {
824
+ return null;
825
+ }
826
+ }
827
+ function sessionHasTask(root: string, key: string): boolean {
828
+ try {
829
+ const ctx = JSON.parse(
830
+ readText(join(root, ".cviauto", ".runtime", "sessions", `${key}.json`)),
831
+ ) as JsonObject;
832
+ return !!str(ctx.current_task);
833
+ } catch {
834
+ return false;
835
+ }
836
+ }
837
+ function adoptKey(root: string, key: string): string {
838
+ if (sessionHasTask(root, key)) return key;
839
+ try {
840
+ const dir = join(root, ".cviauto", ".runtime", "sessions");
841
+ const keys = readdirSync(dir)
842
+ .filter(
843
+ (f) => f.endsWith(".json") && sessionHasTask(root, f.slice(0, -5)),
844
+ )
845
+ .map((f) => f.slice(0, -5));
846
+ const proc = keys.filter((k) => k.startsWith("pi_process_"));
847
+ const cands = proc.length ? proc : keys;
848
+ return cands.length === 1 ? cands[0]! : key;
849
+ } catch {
850
+ return key;
851
+ }
852
+ }
853
+
854
+ // ── Workflow State Breadcrumb ─────────────────────────────────────────
855
+ const WF_RE =
856
+ /\[workflow-state:([A-Za-z0-9_-]+)\]\s*\n([\s\S]*?)\n\s*\[\/workflow-state:\1\]/g;
857
+ function workflowBreadcrumb(root: string, key: string | null): string {
858
+ const wf = readText(join(root, ".cviauto", "workflow.md"));
859
+ if (!wf) return "";
860
+ const templates: Record<string, string> = {};
861
+ for (const m of wf.matchAll(WF_RE)) {
862
+ const s = m[1] ?? "",
863
+ b = (m[2] ?? "").trim();
864
+ if (s && b) templates[s] = b;
865
+ }
866
+ const dir = readTaskDir(root, key);
867
+ let header = "Status: no_task",
868
+ lookup = "no_task";
869
+ if (dir) {
870
+ try {
871
+ const d = JSON.parse(readText(join(dir, "task.json"))) as JsonObject;
872
+ const status = str(d.status) ?? "";
873
+ const id = str(d.id) ?? dir.split(/[\\/]/).pop() ?? "";
874
+ if (status) {
875
+ header = `Task: ${id} (${status})`;
876
+ lookup = status;
877
+ }
878
+ } catch {}
879
+ }
880
+ const body = templates[lookup] ?? "Refer to workflow.md for current step.";
881
+ return `<workflow-state>\n${header}\n${body}\n</workflow-state>`;
882
+ }
883
+
884
+ // ── Session Overview ───────────────────────────────────────────────────
885
+ function runContextScript(root: string, key: string | null, args: string[]): string {
886
+ const script = join(root, ".cviauto", "scripts", "get_context.py");
887
+ if (!exists(script)) return "";
888
+ try {
889
+ const py = process.platform === "win32" ? "python" : "python3";
890
+ const result = spawnSync(py, [script, ...args], {
891
+ cwd: root,
892
+ env: key ? { ...process.env, TRELLIS_CONTEXT_ID: key } : process.env,
893
+ encoding: "utf-8",
894
+ timeout: SESSION_OVERVIEW_TIMEOUT_MS,
895
+ windowsHide: true,
896
+ });
897
+ if (result.status !== 0) return "";
898
+ const stdout = (result.stdout ?? "").trim();
899
+ return stdout;
900
+ } catch {
901
+ return "";
902
+ }
903
+ }
904
+
905
+ function sessionOverview(root: string, key: string | null): string {
906
+ const stdout = runContextScript(root, key, []);
907
+ return stdout ? `<session-overview>\n${stdout}\n</session-overview>` : "";
908
+ }
909
+
910
+ function workflowOverview(root: string, key: string | null): string {
911
+ const stdout = runContextScript(root, key, [
912
+ "--mode",
913
+ "phase",
914
+ "--platform",
915
+ "pi",
916
+ ]);
917
+ return stdout ? `<cviauto-workflow>\n${stdout}\n</cviauto-workflow>` : "";
918
+ }
919
+
920
+ function buildStartupContext(
921
+ root: string,
922
+ key: string | null,
923
+ overview: string,
924
+ ): string {
925
+ const workflow = workflowOverview(root, key);
926
+ return [
927
+ "<session-context>\nCviauto compact SessionStart context. Use it to orient the session; load details on demand.\n</session-context>",
928
+ FIRST_REPLY_NOTICE,
929
+ overview,
930
+ workflow,
931
+ "<ready>\nUse the current workflow state to decide whether to create, continue, or skip a Cviauto task.\n</ready>",
932
+ ]
933
+ .filter(Boolean)
934
+ .join("\n\n");
935
+ }
936
+
937
+ function buildContext(root: string, agent: string, key: string | null): string {
938
+ const dir = readTaskDir(root, key);
939
+ if (!dir)
940
+ return "No active Cviauto task found. Read .cviauto/ before proceeding.";
941
+ const prd = readText(join(dir, "prd.md"));
942
+ const design = readText(join(dir, "design.md"));
943
+ const impl = readText(join(dir, "implement.md"));
944
+ const jsonlName = TRELLIS_AGENT_JSONL[agent] ?? "";
945
+ let spec = "";
946
+ if (jsonlName) {
947
+ const chunks: string[] = [];
948
+ for (const line of readText(join(dir, jsonlName)).split(/\r?\n/)) {
949
+ const t = line.trim();
950
+ if (!t) continue;
951
+ try {
952
+ const r = JSON.parse(t) as JsonObject;
953
+ const f = typeof r.file === "string" ? r.file : "";
954
+ if (f) {
955
+ const c = readText(join(root, f));
956
+ if (c) chunks.push(`## ${f}\n\n${c}`);
957
+ }
958
+ } catch {}
959
+ }
960
+ spec = chunks.join("\n\n---\n\n");
961
+ }
962
+ return [
963
+ `## Cviauto Task Context`,
964
+ `Task directory: ${dir}`,
965
+ "",
966
+ "### prd.md",
967
+ prd || "(missing)",
968
+ design ? "\n### design.md\n" + design : "",
969
+ impl ? "\n### implement.md\n" + impl : "",
970
+ spec ? "\n### Curated Spec / Research Context\n" + spec : "",
971
+ ].join("\n");
972
+ }
973
+
974
+ function normalizeAgent(agent: string | undefined): string {
975
+ const name = agent ?? "cviauto-implement";
976
+ return name.startsWith("cviauto-") || name.startsWith("trellis-")
977
+ ? name
978
+ : `cviauto-${name}`;
979
+ }
980
+
981
+ function isTrellisAgent(root: string, agent: string): boolean {
982
+ return existsSync(join(root, ".pi", "agents", `${agent}.md`));
983
+ }
984
+
985
+ function buildPrompt(
986
+ root: string,
987
+ input: SubagentInput,
988
+ key: string | null,
989
+ ): string {
990
+ const agent = normalizeAgent(input.agent);
991
+ const raw = readText(join(root, ".pi", "agents", `${agent}.md`));
992
+ const def = stripFM(raw);
993
+ const ctx = buildContext(root, agent, key);
994
+ return [
995
+ "## Cviauto Agent Definition",
996
+ def || "(missing)",
997
+ "",
998
+ ctx,
999
+ "",
1000
+ "## Delegated Task",
1001
+ input.prompt ?? "",
1002
+ ].join("\n");
1003
+ }
1004
+
1005
+ // ── Event parsing ─────────────────────────────────────────────────────
1006
+ function parseJsonEvent(line: string): JsonObject | null {
1007
+ const t = line.trim();
1008
+ if (!t) return null;
1009
+ const i = t.indexOf("{");
1010
+ if (i < 0) return null;
1011
+ try {
1012
+ const p = JSON.parse(t.slice(i));
1013
+ return isObj(p) ? p : null;
1014
+ } catch {
1015
+ return null;
1016
+ }
1017
+ }
1018
+
1019
+ function applyEvent(r: RunState, evt: JsonObject): boolean {
1020
+ const type = typeof evt.type === "string" ? evt.type : "";
1021
+ if (!type) return false;
1022
+ if (type === "agent_start" || type === "turn_start") {
1023
+ r.status = "running";
1024
+ r.startedAt ??= Date.now();
1025
+ return true;
1026
+ }
1027
+ if (type === "message_update") {
1028
+ const ae = isObj(evt.assistantMessageEvent)
1029
+ ? evt.assistantMessageEvent
1030
+ : null;
1031
+ if (!ae || typeof ae.delta !== "string") return false;
1032
+ if (ae.type === "thinking_delta") {
1033
+ r.thinkingTail = appendTail(r.thinkingTail, ae.delta, MAX_TAIL);
1034
+ return true;
1035
+ }
1036
+ if (ae.type === "text_delta") {
1037
+ r.textTail = appendTail(r.textTail, ae.delta, MAX_TAIL);
1038
+ return true;
1039
+ }
1040
+ return false;
1041
+ }
1042
+ if (type === "message_end" && isObj(evt.message)) {
1043
+ const msg = evt.message;
1044
+ if (msg.role !== "assistant") return false;
1045
+ r.usage.turns += 1;
1046
+ const u = isObj(msg.usage) ? msg.usage : null;
1047
+ const cost = isObj(u?.cost) ? u.cost : null;
1048
+ r.usage.input += num(u?.input);
1049
+ r.usage.output += num(u?.output);
1050
+ r.usage.cacheRead += num(u?.cacheRead);
1051
+ r.usage.cacheWrite += num(u?.cacheWrite);
1052
+ r.usage.cost += num(cost?.total);
1053
+ r.usage.ctxTokens = num(u?.totalTokens);
1054
+ const thinking = extractThinking(msg.content);
1055
+ if (thinking) r.thinkingTail = appendTail("", thinking, MAX_TAIL);
1056
+ const text = extractText(msg.content);
1057
+ if (text) {
1058
+ r.finalText = text;
1059
+ r.textTail = appendTail("", text, MAX_TAIL);
1060
+ }
1061
+ if (typeof msg.model === "string") {
1062
+ const parsed = splitModelThinking(msg.model, r.thinking);
1063
+ r.model = parsed.model;
1064
+ r.thinking = parsed.thinking;
1065
+ }
1066
+ if (typeof msg.errorMessage === "string") r.errorMessage = msg.errorMessage;
1067
+ return true;
1068
+ }
1069
+ if (type === "tool_execution_start") {
1070
+ const id =
1071
+ typeof evt.toolCallId === "string"
1072
+ ? evt.toolCallId
1073
+ : hash(`${Date.now()}`);
1074
+ const name = typeof evt.toolName === "string" ? evt.toolName : "tool";
1075
+ const args = summarizeToolArgs(name, evt.args);
1076
+ const existing = r.tools.findIndex((t) => t.id === id);
1077
+ if (existing >= 0)
1078
+ r.tools[existing] = { ...r.tools[existing]!, args, status: "running" };
1079
+ else
1080
+ r.tools.push({
1081
+ id,
1082
+ name,
1083
+ args,
1084
+ status: "running",
1085
+ startedAt: Date.now(),
1086
+ });
1087
+ if (r.tools.length > MAX_TOOLS)
1088
+ r.tools.splice(0, r.tools.length - MAX_TOOLS);
1089
+ return true;
1090
+ }
1091
+ if (type === "tool_execution_end") {
1092
+ const id = typeof evt.toolCallId === "string" ? evt.toolCallId : "";
1093
+ const idx = r.tools.findIndex((t) => t.id === id);
1094
+ if (idx >= 0)
1095
+ r.tools[idx] = {
1096
+ ...r.tools[idx]!,
1097
+ status: evt.isError ? "failed" : "succeeded",
1098
+ finishedAt: Date.now(),
1099
+ };
1100
+ return true;
1101
+ }
1102
+ if (type === "agent_end") {
1103
+ r.finishedAt = Date.now();
1104
+ if (r.status === "running" || r.status === "pending")
1105
+ r.status = "succeeded";
1106
+ return true;
1107
+ }
1108
+ return false;
1109
+ }
1110
+
1111
+ function finalize(r: RunState, fallback: string): string {
1112
+ return r.finalText || fallback.trim() || r.stderrTail.trim();
1113
+ }
1114
+ function formatPiOutput(stdout: string, stderr: string): string {
1115
+ let ft = "";
1116
+ for (const line of stdout.split(/\r?\n/)) {
1117
+ const t = line.trim();
1118
+ if (!t) continue;
1119
+ try {
1120
+ const evt = JSON.parse(t) as JsonObject;
1121
+ const msg = isObj(evt.message) ? evt.message : null;
1122
+ if (msg?.role === "assistant") {
1123
+ const txt = extractText(msg.content);
1124
+ if (txt) ft = txt;
1125
+ }
1126
+ } catch {}
1127
+ }
1128
+ return ft || stdout || stderr;
1129
+ }
1130
+
1131
+ // ── runPi: subprocess execution + event processing ───────────────────
1132
+ function runPi(
1133
+ root: string,
1134
+ prompt: string,
1135
+ cfg: PiRunConfig,
1136
+ state: RunState,
1137
+ emit: () => void,
1138
+ key?: string | null,
1139
+ signal?: AbortSignal,
1140
+ ): Promise<{ output: string; failed: boolean }> {
1141
+ return new Promise((resolve) => {
1142
+ if (signal?.aborted) {
1143
+ state.status = "cancelled";
1144
+ state.errorMessage = "cancelled";
1145
+ state.finishedAt = Date.now();
1146
+ emit();
1147
+ resolve({ output: "cancelled", failed: true });
1148
+ return;
1149
+ }
1150
+ const inv = resolvePiCli();
1151
+ const childEnv = {
1152
+ ...process.env,
1153
+ TRELLIS_SUBAGENT_CHILD: "1",
1154
+ ...(key ? { TRELLIS_CONTEXT_ID: key } : {}),
1155
+ };
1156
+ const cli = spawn(inv.command, [...inv.args, ...buildPiArgs(cfg)], {
1157
+ cwd: root,
1158
+ env: childEnv,
1159
+ stdio: ["pipe", "pipe", "pipe"],
1160
+ windowsHide: true,
1161
+ });
1162
+ const stdout = new BBC(MAX_STDOUT);
1163
+ const stderr = new BBC(MAX_STDERR);
1164
+ let buf = "";
1165
+ let settled = false;
1166
+ let aborted = false;
1167
+ let killTimer: ReturnType<typeof setTimeout> | null = null;
1168
+ const abort = () => {
1169
+ aborted = true;
1170
+ cli.kill();
1171
+ killTimer = setTimeout(() => {
1172
+ if (!settled && cli.exitCode === null) cli.kill("SIGKILL");
1173
+ }, ABORT_KILL_GRACE_MS);
1174
+ killTimer?.unref?.();
1175
+ };
1176
+ const done = (v: { output: string; failed: boolean }) => {
1177
+ if (settled) return;
1178
+ settled = true;
1179
+ if (killTimer) clearTimeout(killTimer);
1180
+ signal?.removeEventListener("abort", abort);
1181
+ emit();
1182
+ resolve(v);
1183
+ };
1184
+ signal?.addEventListener("abort", abort, { once: true });
1185
+ state.status = "running";
1186
+ state.startedAt = Date.now();
1187
+ emit();
1188
+ const processLine = (line: string) => {
1189
+ const evt = parseJsonEvent(line);
1190
+ if (evt && applyEvent(state, evt)) emit();
1191
+ };
1192
+ cli.stdout?.on("data", (d: Buffer) => {
1193
+ stdout.append(d);
1194
+ buf += d.toString("utf-8");
1195
+ if (buf.length > MAX_LINE_BUFFER) buf = buf.slice(-MAX_LINE_BUFFER);
1196
+ const lines = buf.split(/\r?\n/);
1197
+ buf = lines.pop() ?? "";
1198
+ for (const l of lines) processLine(l);
1199
+ });
1200
+ cli.stderr?.on("data", (d: Buffer) => {
1201
+ stderr.append(d);
1202
+ state.stderrTail = appendTail(
1203
+ state.stderrTail,
1204
+ d.toString("utf-8"),
1205
+ MAX_TAIL,
1206
+ );
1207
+ });
1208
+ cli.stdin?.on("error", (e: Error & { code?: string }) => {
1209
+ if (!aborted && e.code !== "EPIPE")
1210
+ done({ output: e.message, failed: true });
1211
+ });
1212
+ cli.on("error", (e) => {
1213
+ state.status = aborted ? "cancelled" : "failed";
1214
+ state.errorMessage = e instanceof Error ? e.message : String(e);
1215
+ state.finishedAt = Date.now();
1216
+ done({ output: finalize(state, state.errorMessage), failed: true });
1217
+ });
1218
+ cli.on("close", (code) => {
1219
+ if (buf.trim()) processLine(buf);
1220
+ const out = stdout.toString();
1221
+ const err = stderr.toString();
1222
+ state.stderrTail = appendTail("", err, MAX_TAIL);
1223
+ state.finishedAt = Date.now();
1224
+ if (aborted) {
1225
+ state.status = "cancelled";
1226
+ state.errorMessage = "cancelled";
1227
+ done({ output: finalize(state, "cancelled"), failed: true });
1228
+ return;
1229
+ }
1230
+ if (code === 0) {
1231
+ if (state.status === "pending" || state.status === "running")
1232
+ state.status = "succeeded";
1233
+ done({
1234
+ output: finalize(state, formatPiOutput(out, err)),
1235
+ failed: false,
1236
+ });
1237
+ return;
1238
+ }
1239
+ state.status = "failed";
1240
+ state.errorMessage = err || out || `exit ${code ?? "?"}`;
1241
+ done({ output: finalize(state, state.errorMessage), failed: true });
1242
+ });
1243
+ cli.stdin?.end(prompt);
1244
+ });
1245
+ }
1246
+
1247
+ // ── runSubagent: orchestrate single/parallel/chain via native partial updates ──
1248
+ async function runSubagent(
1249
+ root: string,
1250
+ input: SubagentInput,
1251
+ key: string | null,
1252
+ signal?: AbortSignal,
1253
+ onUpdate?: (r: PiToolResult) => void,
1254
+ inheritedThinking?: string,
1255
+ ): Promise<{ output: string; details: ProgressDetails; failed: boolean }> {
1256
+ const agentName = normalizeAgent(input.agent);
1257
+ const agentRaw = readText(join(root, ".pi", "agents", `${agentName}.md`));
1258
+ const agentCfg = parseAgentFM(agentRaw);
1259
+ const runCfg = resolveRunCfg(input, agentCfg, inheritedThinking);
1260
+ const mode = input.mode ?? "single";
1261
+ const startedAt = Date.now();
1262
+ const details: ProgressDetails = {
1263
+ kind: "trellis-subagent-progress",
1264
+ agent: agentName,
1265
+ mode,
1266
+ startedAt,
1267
+ updatedAt: startedAt,
1268
+ final: false,
1269
+ runs: [],
1270
+ };
1271
+ let lastEmit = 0;
1272
+ let lastPartialKey = "";
1273
+ let closed = false;
1274
+ const pushPartial = (force = false) => {
1275
+ if (closed || !onUpdate) return;
1276
+ const key = progressKey(details);
1277
+ if (!force && key === lastPartialKey) return;
1278
+ lastPartialKey = key;
1279
+ onUpdate({
1280
+ // Keep native partial content stable; renderResult owns the visible progress UI.
1281
+ content: [{ type: "text", text: "subagent running" }],
1282
+ details: cloneProgress(details),
1283
+ });
1284
+ };
1285
+ const emit = (force = false) => {
1286
+ const now = Date.now();
1287
+ if (!force && now - lastEmit < THROTTLE_MS) return;
1288
+ lastEmit = now;
1289
+ details.updatedAt = now;
1290
+ pushPartial(force);
1291
+ };
1292
+ const finish = (output: string, failed: boolean) => {
1293
+ closed = true;
1294
+ details.final = true;
1295
+ details.updatedAt = Date.now();
1296
+ return { output, details: cloneProgress(details), failed };
1297
+ };
1298
+
1299
+ try {
1300
+ if (mode === "parallel") {
1301
+ const prompts = input.prompts ?? (input.prompt ? [input.prompt] : []);
1302
+ details.runs = prompts.map((p, i) => {
1303
+ const r = newRun(`${agentName}-${i + 1}`, agentName, p);
1304
+ applyRunConfig(r, runCfg);
1305
+ return r;
1306
+ });
1307
+ emit(true);
1308
+ const results = await Promise.all(
1309
+ prompts.map((p, i) =>
1310
+ runPi(
1311
+ root,
1312
+ buildPrompt(root, { ...input, prompt: p }, key),
1313
+ runCfg,
1314
+ details.runs[i]!,
1315
+ emit,
1316
+ key,
1317
+ signal,
1318
+ ),
1319
+ ),
1320
+ );
1321
+ return finish(
1322
+ results.map((r) => r.output).join("\n\n---\n\n"),
1323
+ results.some((r) => r.failed),
1324
+ );
1325
+ }
1326
+ if (mode === "chain") {
1327
+ let prev = "";
1328
+ let failed = false;
1329
+ for (let i = 0; i < (input.prompts?.length ?? 1); i++) {
1330
+ const p = input.prompts?.[i] ?? input.prompt ?? "";
1331
+ const rs = newRun(`${agentName}-${i + 1}`, agentName, p, i + 1);
1332
+ applyRunConfig(rs, runCfg);
1333
+ details.runs.push(rs);
1334
+ emit(true);
1335
+ const result = await runPi(
1336
+ root,
1337
+ buildPrompt(
1338
+ root,
1339
+ {
1340
+ ...input,
1341
+ prompt: prev ? `${p}\n\nPrevious output:\n${prev}` : p,
1342
+ },
1343
+ key,
1344
+ ),
1345
+ runCfg,
1346
+ rs,
1347
+ emit,
1348
+ key,
1349
+ signal,
1350
+ );
1351
+ prev = result.output;
1352
+ failed = failed || result.failed;
1353
+ if (result.failed) break;
1354
+ }
1355
+ return finish(prev, failed);
1356
+ }
1357
+ const rs = newRun(`${agentName}-1`, agentName, input.prompt ?? "");
1358
+ applyRunConfig(rs, runCfg);
1359
+ details.runs = [rs];
1360
+ emit(true);
1361
+ const result = await runPi(
1362
+ root,
1363
+ buildPrompt(root, input, key),
1364
+ runCfg,
1365
+ rs,
1366
+ emit,
1367
+ key,
1368
+ signal,
1369
+ );
1370
+ return finish(result.output, result.failed);
1371
+ } catch (e) {
1372
+ const message = e instanceof Error ? e.message : String(e);
1373
+ const r = activeRun(details);
1374
+ if (r) {
1375
+ r.status = "failed";
1376
+ r.errorMessage = message;
1377
+ r.finishedAt = Date.now();
1378
+ }
1379
+ return finish(message, true);
1380
+ }
1381
+ }
1382
+
1383
+ // ── Extension ──────────────────────────────────────────────────────────
1384
+ export default function trellisExtension(pi: {
1385
+ registerTool?: (tool: JsonObject) => void;
1386
+ registerShortcut?: (
1387
+ key: string,
1388
+ opts: {
1389
+ description?: string;
1390
+ handler: (ctx: PiExtensionContext) => unknown;
1391
+ },
1392
+ ) => void;
1393
+ on?: (
1394
+ event: string,
1395
+ handler: (event: unknown, ctx?: PiExtensionContext) => unknown,
1396
+ ) => void;
1397
+ getThinkingLevel?: () => string;
1398
+ }): void {
1399
+ if (process.env.TRELLIS_SUBAGENT_CHILD === "1") return;
1400
+ const root = findRoot(process.cwd());
1401
+ const procKey = `pi_process_${hash([root, process.pid, Date.now(), randomBytes(8).toString("hex")].join(":"))}`;
1402
+ let curKey: string | null = null;
1403
+
1404
+ const getKey = (input?: unknown, ctx?: PiExtensionContext) => {
1405
+ const k = adoptKey(root, contextKey(input, ctx) ?? curKey ?? procKey);
1406
+ curKey = k;
1407
+ return k;
1408
+ };
1409
+
1410
+ // Per-turn cache to avoid double-spawning python
1411
+ let turnCache: {
1412
+ key: string | null;
1413
+ ts: number;
1414
+ wf: string;
1415
+ ov: string;
1416
+ } | null = null;
1417
+ const getTurnCtx = (k: string | null) => {
1418
+ const now = Date.now();
1419
+ if (turnCache && turnCache.key === k && now - turnCache.ts < 1500)
1420
+ return turnCache;
1421
+ turnCache = {
1422
+ key: k,
1423
+ ts: now,
1424
+ wf: workflowBreadcrumb(root, k),
1425
+ ov: sessionOverview(root, k),
1426
+ };
1427
+ return turnCache;
1428
+ };
1429
+ const startupKeys = new Set<string>();
1430
+ const getStartupCtx = (
1431
+ k: string | null,
1432
+ turn: { ov: string },
1433
+ ): string => {
1434
+ const key = k ?? "default";
1435
+ if (startupKeys.has(key)) return "";
1436
+ startupKeys.add(key);
1437
+ return buildStartupContext(root, k, turn.ov);
1438
+ };
1439
+
1440
+ // Toggle only the latest subagent native card; do not use Pi global tool expansion.
1441
+ const toggleDetail = (ctx: PiExtensionContext) => {
1442
+ const id = activeSubagentToolCallId;
1443
+ const card = id ? nativeCards.get(id) : undefined;
1444
+ if (!card) {
1445
+ ctx.ui?.notify?.("No subagent card to toggle yet.", "warning");
1446
+ return;
1447
+ }
1448
+ card.state.localExpanded = card.state.localExpanded !== true;
1449
+ card.invalidate();
1450
+ };
1451
+
1452
+ pi.registerShortcut?.("alt+o", {
1453
+ description: "Toggle latest subagent card details",
1454
+ handler: async (ctx: PiExtensionContext) => toggleDetail(ctx),
1455
+ });
1456
+
1457
+ // Tool registration
1458
+ pi.registerTool?.({
1459
+ name: "cviauto_subagent",
1460
+ label: "Cviauto Subagent",
1461
+ description: "Run a Cviauto project sub-agent with active task context.",
1462
+ promptSnippet:
1463
+ 'Sub-agent dispatch protocol (Cviauto): your dispatch prompt MUST start with one line "Active task: <task path from `task.py current`>" before any other instructions.',
1464
+ promptGuidelines: [
1465
+ 'Use subagent for task delegation. Your dispatch prompt MUST start with "Active task: <task path from `task.py current`>".',
1466
+ ],
1467
+ parameters: {
1468
+ type: "object",
1469
+ properties: {
1470
+ agent: {
1471
+ type: "string",
1472
+ description:
1473
+ "Agent name, such as cviauto-implement or cviauto-check.",
1474
+ },
1475
+ prompt: {
1476
+ type: "string",
1477
+ description: "Task prompt for the sub-agent.",
1478
+ },
1479
+ mode: { type: "string", enum: ["single", "parallel", "chain"] },
1480
+ prompts: {
1481
+ type: "array",
1482
+ items: { type: "string" },
1483
+ maxItems: MAX_PARALLEL_PROMPTS,
1484
+ },
1485
+ model: {
1486
+ type: "string",
1487
+ description:
1488
+ "Optional Pi model override for the child sub-agent process.",
1489
+ },
1490
+ thinking: {
1491
+ type: "string",
1492
+ description:
1493
+ "Optional Pi thinking level override for the child sub-agent process.",
1494
+ enum: ["off", "minimal", "low", "medium", "high", "xhigh"],
1495
+ },
1496
+ },
1497
+ },
1498
+ execute: async (
1499
+ id: string,
1500
+ input: SubagentInput,
1501
+ signal?: AbortSignal,
1502
+ onUpdate?: (r: PiToolResult) => void,
1503
+ ctx?: PiExtensionContext,
1504
+ ) => {
1505
+ activeSubagentToolCallId = id;
1506
+ const agentName = normalizeAgent(input.agent);
1507
+ if (!isTrellisAgent(root, agentName)) {
1508
+ return {
1509
+ content: [
1510
+ {
1511
+ type: "text",
1512
+ text:
1513
+ "`cviauto_subagent` is only for Cviauto workflow agents with a definition file in .pi/agents/.\n\n" +
1514
+ `No definition found for: ${agentName}\n\n` +
1515
+ "For general-purpose sub-agents, use one of these community tools:\n" +
1516
+ "- `subagent` tool from npm:pi-subagents (nicobailon/pi-subagents)\n" +
1517
+ "- `Agent` tool from npm:@tintinweb/pi-subagents\n\n" +
1518
+ "If neither is installed, ask the user to either:\n" +
1519
+ `- Create .pi/agents/${agentName}.md for your custom Cviauto agent\n` +
1520
+ "- Install a community subagent package: pi install -l npm:@tintinweb/pi-subagents",
1521
+ },
1522
+ ],
1523
+ details: { agent: agentName, error: "not a cviauto workflow agent" },
1524
+ };
1525
+ }
1526
+ const mode = input.mode ?? "single";
1527
+ const prompt = input.prompt?.trim();
1528
+ const prompts = input.prompts?.map((p) => p.trim()).filter(Boolean);
1529
+ if (mode === "single" && !prompt)
1530
+ throw new Error("subagent prompt is required for single mode");
1531
+ if (
1532
+ (mode === "parallel" || mode === "chain") &&
1533
+ !prompt &&
1534
+ !prompts?.length
1535
+ )
1536
+ throw new Error(
1537
+ "subagent prompt or prompts are required for parallel/chain mode",
1538
+ );
1539
+ if (
1540
+ mode === "parallel" &&
1541
+ prompts &&
1542
+ prompts.length > MAX_PARALLEL_PROMPTS
1543
+ )
1544
+ throw new Error(
1545
+ `subagent parallel mode supports at most ${MAX_PARALLEL_PROMPTS} prompts`,
1546
+ );
1547
+ const cleanInput: SubagentInput = {
1548
+ ...input,
1549
+ prompt,
1550
+ prompts: prompts?.length ? prompts : undefined,
1551
+ };
1552
+ const key = getKey(cleanInput, ctx);
1553
+ const inheritedThinking = pi.getThinkingLevel?.();
1554
+ const result = await runSubagent(
1555
+ root,
1556
+ cleanInput,
1557
+ key,
1558
+ signal,
1559
+ onUpdate,
1560
+ inheritedThinking,
1561
+ );
1562
+ return {
1563
+ content: [{ type: "text", text: result.output }],
1564
+ details: result.details,
1565
+ };
1566
+ },
1567
+ // Hide the call renderer so the native card only shows result/progress once.
1568
+ renderCall: () => ({
1569
+ render() {
1570
+ return [];
1571
+ },
1572
+ invalidate() {},
1573
+ }),
1574
+ renderResult: (
1575
+ result: PiToolResult,
1576
+ _opts?: { expanded?: boolean; isPartial?: boolean },
1577
+ _theme?: unknown,
1578
+ context?: unknown,
1579
+ ) => {
1580
+ const ctxObj = isObj(context) ? context : null;
1581
+ const toolCallId = str(ctxObj?.toolCallId);
1582
+ const state = isObj(ctxObj?.state) ? (ctxObj.state as JsonObject) : null;
1583
+ const invalidate =
1584
+ typeof ctxObj?.invalidate === "function"
1585
+ ? (ctxObj.invalidate as () => void)
1586
+ : null;
1587
+ const isProgress =
1588
+ isObj(result.details) &&
1589
+ result.details.kind === "trellis-subagent-progress";
1590
+ if (toolCallId && state && invalidate) {
1591
+ const updatedAt = isProgress
1592
+ ? (result.details as ProgressDetails).updatedAt
1593
+ : Date.now();
1594
+ rememberNativeCard(toolCallId, { state, invalidate, updatedAt });
1595
+ }
1596
+ return {
1597
+ render(w: number) {
1598
+ if (isProgress) {
1599
+ const expanded = state?.localExpanded === true;
1600
+ return renderProgressCard(
1601
+ result.details as ProgressDetails,
1602
+ expanded,
1603
+ w,
1604
+ );
1605
+ }
1606
+ return [trunc(result.content?.[0]?.text ?? "(no output)", w)];
1607
+ },
1608
+ invalidate() {},
1609
+ };
1610
+ },
1611
+ });
1612
+
1613
+ // Events
1614
+ pi.on?.("session_start", (event, ctx) => {
1615
+ getKey(event, ctx);
1616
+ ctx?.ui?.notify?.(
1617
+ "Cviauto project context is available. Use /cviauto-start to bootstrap or /cviauto-continue to resume.",
1618
+ "info",
1619
+ );
1620
+ });
1621
+ pi.on?.("session_shutdown", () => {
1622
+ nativeCards.clear();
1623
+ activeSubagentToolCallId = null;
1624
+ });
1625
+ pi.on?.("tool_call", (event, ctx) => {
1626
+ const k = getKey(event, ctx);
1627
+ const ev = event as { toolName?: string; input?: JsonObject };
1628
+ if (
1629
+ ev.toolName === "bash" &&
1630
+ isObj(ev.input) &&
1631
+ typeof ev.input.command === "string" &&
1632
+ !cmdHasTrellisCtx(ev.input.command)
1633
+ )
1634
+ ev.input.command = `export TRELLIS_CONTEXT_ID=${shellQuote(k)}; ${ev.input.command}`;
1635
+ });
1636
+ // Preserve progress details from execute(); mark failed subagent results through
1637
+ // the official tool_result patch hook instead of throwing away renderer details.
1638
+ pi.on?.("tool_result", (event) => {
1639
+ const ev = event as { toolName?: string; details?: unknown };
1640
+ if (
1641
+ ev.toolName === "cviauto_subagent" &&
1642
+ isObj(ev.details) &&
1643
+ ev.details.kind === "trellis-subagent-progress" &&
1644
+ Array.isArray(ev.details.runs) &&
1645
+ ev.details.runs.some(
1646
+ (r) => isObj(r) && (r.status === "failed" || r.status === "cancelled"),
1647
+ )
1648
+ )
1649
+ return { isError: true };
1650
+ return undefined;
1651
+ });
1652
+ pi.on?.("input", (event, ctx) => {
1653
+ const k = getKey(event, ctx);
1654
+ const ev = event as { text?: string };
1655
+ if (typeof ev.text !== "string" || !ev.text.trim())
1656
+ return { action: "continue" };
1657
+ const { wf, ov } = getTurnCtx(k);
1658
+ const injection = [wf, ov].filter(Boolean).join("\n\n");
1659
+ if (!injection) return { action: "continue" };
1660
+ return {
1661
+ action: "transform",
1662
+ text: [ev.text, injection].join("\n\n"),
1663
+ };
1664
+ });
1665
+ pi.on?.("before_agent_start", (event, ctx) => {
1666
+ const k = getKey(event, ctx);
1667
+ const cur = (event as { systemPrompt?: string }).systemPrompt ?? "";
1668
+ const ctxText = buildContext(root, "cviauto-implement", k);
1669
+ const turn = getTurnCtx(k);
1670
+ const startup = getStartupCtx(k, turn);
1671
+ return {
1672
+ systemPrompt: [cur, startup, ctxText, turn.wf, turn.ov]
1673
+ .filter(Boolean)
1674
+ .join("\n\n"),
1675
+ };
1676
+ });
1677
+ pi.on?.("context", (event, ctx) => {
1678
+ getKey(event, ctx);
1679
+ });
1680
+ }