agentix-cli 0.25.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/README.md +2 -0
  2. package/dist/{App-6Y7B3YQH.js → App-U52IPUK2.js} +2 -2
  3. package/dist/{ChatApp-KIEUJ2DS.js → ChatApp-XP4OMHPL.js} +2 -2
  4. package/dist/agent-V2CA4TXD.js +2 -0
  5. package/dist/article-fields-L4D2BOGY.js +2 -0
  6. package/dist/article-quality-44ONVGLN.js +3 -0
  7. package/dist/article-quality-44ONVGLN.js.map +1 -0
  8. package/dist/{audit-JU3HWISB.js → audit-4245CX6P.js} +2 -2
  9. package/dist/backfill-MTD2B62I.js +6 -0
  10. package/dist/backfill-MTD2B62I.js.map +1 -0
  11. package/dist/{board-dashboard-CQ5F4GPD.js → board-dashboard-TTMAYRLG.js} +2445 -519
  12. package/dist/board-dashboard-TTMAYRLG.js.map +1 -0
  13. package/dist/{builtin-FRKAQMFS.js → builtin-B67DMJ3M.js} +2 -2
  14. package/dist/calibration-ILS5OI44.js +2 -0
  15. package/dist/chunk-2T5W3ETS.js +5 -0
  16. package/dist/{chunk-FDMWOPEL.js.map → chunk-2T5W3ETS.js.map} +1 -1
  17. package/dist/chunk-3SCPRYJB.js +5 -0
  18. package/dist/chunk-3SCPRYJB.js.map +1 -0
  19. package/dist/chunk-4BR7D2OU.js +36 -0
  20. package/dist/chunk-4BR7D2OU.js.map +1 -0
  21. package/dist/{chunk-P4VWIVKN.js → chunk-52ZPELD2.js} +403 -29
  22. package/dist/chunk-52ZPELD2.js.map +1 -0
  23. package/dist/{chunk-5U35WAZF.js → chunk-77OV7346.js} +6 -6
  24. package/dist/chunk-77OV7346.js.map +1 -0
  25. package/dist/chunk-AJ5RMU7X.js +2 -0
  26. package/dist/chunk-AJ5RMU7X.js.map +1 -0
  27. package/dist/chunk-AJONZWLT.js +2 -0
  28. package/dist/chunk-AJONZWLT.js.map +1 -0
  29. package/dist/chunk-AX2PWSRT.js +114 -0
  30. package/dist/chunk-AX2PWSRT.js.map +1 -0
  31. package/dist/chunk-BH3GTCZ6.js +2 -0
  32. package/dist/chunk-BH3GTCZ6.js.map +1 -0
  33. package/dist/chunk-BPIRO4YD.js +126 -0
  34. package/dist/chunk-BPIRO4YD.js.map +1 -0
  35. package/dist/chunk-CJQQIRPD.js +13 -0
  36. package/dist/chunk-CJQQIRPD.js.map +1 -0
  37. package/dist/chunk-DCDQZR7I.js +24 -0
  38. package/dist/chunk-DCDQZR7I.js.map +1 -0
  39. package/dist/chunk-EVWEG3VD.js +3 -0
  40. package/dist/chunk-EVWEG3VD.js.map +1 -0
  41. package/dist/chunk-F4HZTZHW.js +2 -0
  42. package/dist/chunk-F4HZTZHW.js.map +1 -0
  43. package/dist/chunk-F6CNF7V3.js +25 -0
  44. package/dist/chunk-F6CNF7V3.js.map +1 -0
  45. package/dist/chunk-FIEJDZVC.js +121 -0
  46. package/dist/chunk-FIEJDZVC.js.map +1 -0
  47. package/dist/chunk-FIOB3MEX.js +2 -0
  48. package/dist/{chunk-H5D7ATXS.js → chunk-FKBGJYWQ.js} +5 -5
  49. package/dist/chunk-FKBGJYWQ.js.map +1 -0
  50. package/dist/chunk-GDWJUGB5.js +9 -0
  51. package/dist/chunk-GDWJUGB5.js.map +1 -0
  52. package/dist/{chunk-TRJTTBE2.js → chunk-IB3F7VBE.js} +7 -7
  53. package/dist/{chunk-TRJTTBE2.js.map → chunk-IB3F7VBE.js.map} +1 -1
  54. package/dist/chunk-IBUSGCLQ.js +109 -0
  55. package/dist/chunk-IBUSGCLQ.js.map +1 -0
  56. package/dist/{chunk-LDHPMJ7M.js → chunk-IWMW5432.js} +3 -3
  57. package/dist/chunk-IWMW5432.js.map +1 -0
  58. package/dist/chunk-K33GIBSE.js +2 -0
  59. package/dist/chunk-K33GIBSE.js.map +1 -0
  60. package/dist/chunk-L2IZPR6P.js +45 -0
  61. package/dist/chunk-L2IZPR6P.js.map +1 -0
  62. package/dist/chunk-L2WSPY6S.js +2 -0
  63. package/dist/chunk-L2WSPY6S.js.map +1 -0
  64. package/dist/chunk-LCIREYTD.js +54 -0
  65. package/dist/chunk-LCIREYTD.js.map +1 -0
  66. package/dist/chunk-LNRB5MCU.js +530 -0
  67. package/dist/chunk-LNRB5MCU.js.map +1 -0
  68. package/dist/chunk-OPHIXXGI.js +157 -0
  69. package/dist/chunk-OPHIXXGI.js.map +1 -0
  70. package/dist/{chunk-JTJIPNXY.js → chunk-PNWNVOEZ.js} +1 -1
  71. package/dist/chunk-PNWNVOEZ.js.map +1 -0
  72. package/dist/{chunk-LNXCJWOU.js → chunk-UFAGYX73.js} +45 -47
  73. package/dist/chunk-UFAGYX73.js.map +1 -0
  74. package/dist/{chunk-DJEZ2HVU.js → chunk-VDMYBPYB.js} +1 -1
  75. package/dist/chunk-VDMYBPYB.js.map +1 -0
  76. package/dist/chunk-VTE7L6LO.js +5 -0
  77. package/dist/{chunk-G57RZCXM.js.map → chunk-VTE7L6LO.js.map} +1 -1
  78. package/dist/chunk-W5C2GDNC.js +32 -0
  79. package/dist/{chunk-JP5IEXR7.js.map → chunk-W5C2GDNC.js.map} +1 -1
  80. package/dist/chunk-WPMX3VGI.js +3 -0
  81. package/dist/chunk-WPMX3VGI.js.map +1 -0
  82. package/dist/chunk-WZ72HX5C.js +1182 -0
  83. package/dist/chunk-WZ72HX5C.js.map +1 -0
  84. package/dist/chunk-ZTEU5JVQ.js +2 -0
  85. package/dist/chunk-ZTEU5JVQ.js.map +1 -0
  86. package/dist/{chunk-2WVX3LEC.js → chunk-ZVP6GB4G.js} +1 -1
  87. package/dist/chunk-ZVP6GB4G.js.map +1 -0
  88. package/dist/cli.js +1 -1
  89. package/dist/cli.js.map +1 -1
  90. package/dist/client-PX25MD47.js +2 -0
  91. package/dist/{compaction-NWEMOSHA.js → compaction-FD4R23HZ.js} +4 -4
  92. package/dist/config-HL5F36V4.js +2 -0
  93. package/dist/config-mutator-HBX53OMJ.js +2 -0
  94. package/dist/{conflict-detector-D7VIYPDI.js → conflict-detector-ZPOT3M2C.js} +2 -2
  95. package/dist/conflict-detector-ZPOT3M2C.js.map +1 -0
  96. package/dist/context-planner-AQHJMVY2.js +17 -0
  97. package/dist/context-planner-AQHJMVY2.js.map +1 -0
  98. package/dist/debug-3MEUO2P2.js +2 -0
  99. package/dist/{discover-XJXQXXIO.js → discover-D4VVRNAI.js} +2 -2
  100. package/dist/discover-D4VVRNAI.js.map +1 -0
  101. package/dist/doctor-PBAH6XL3.js +2 -0
  102. package/dist/editor-chat-OB7IQOB5.js +137 -0
  103. package/dist/editor-chat-OB7IQOB5.js.map +1 -0
  104. package/dist/entry-triage-LK34TSQD.js +2 -0
  105. package/dist/entry-triage-LK34TSQD.js.map +1 -0
  106. package/dist/facts-YVEJOM7O.js +22 -0
  107. package/dist/facts-YVEJOM7O.js.map +1 -0
  108. package/dist/heal-FVLBHYP7.js +2 -0
  109. package/dist/index.d.ts +1073 -65
  110. package/dist/index.js +13 -13
  111. package/dist/index.js.map +1 -1
  112. package/dist/{ingest-whatsapp-LZE62INA.js → ingest-whatsapp-NS4OWDOU.js} +2 -2
  113. package/dist/loader-4ZGTK7LD.js +2 -0
  114. package/dist/loader-BOKE5M5S.js +2 -0
  115. package/dist/memory-extract-F5ZHWY5E.js +2 -0
  116. package/dist/{migrate-v2-QO7SLKIM.js → migrate-v2-V4WN2VVM.js} +2 -2
  117. package/dist/ntfy-X7EPB3TG.js +4 -0
  118. package/dist/ntfy-X7EPB3TG.js.map +1 -0
  119. package/dist/processes-WU23U2OJ.js +2 -0
  120. package/dist/program-YGXVCV2Y.js +2 -0
  121. package/dist/{projects-api-KRME2YKZ.js → projects-api-QE6L65SK.js} +2 -2
  122. package/dist/{projects-mutate-3NHVG437.js → projects-mutate-MY7JTLSZ.js} +2 -2
  123. package/dist/providers-KO2DODIO.js +2 -0
  124. package/dist/query-ZKTFJMNE.js +2 -0
  125. package/dist/questions-4B4KSPXG.js +3 -0
  126. package/dist/questions-4B4KSPXG.js.map +1 -0
  127. package/dist/recipes-7S4MC5OJ.js +2 -0
  128. package/dist/registry-PSZDPFZK.js +2 -0
  129. package/dist/review-candidates-AEUXRQQC.js +4 -0
  130. package/dist/review-candidates-AEUXRQQC.js.map +1 -0
  131. package/dist/review-store-B4YE3EFK.js +4 -0
  132. package/dist/review-store-B4YE3EFK.js.map +1 -0
  133. package/dist/{rotation-memo-B3EXXSEH.js → rotation-memo-7T75BLEX.js} +2 -2
  134. package/dist/routing-4PV66BK6.js +2 -0
  135. package/dist/routing-4PV66BK6.js.map +1 -0
  136. package/dist/runner-YRBVNYTY.js +2 -0
  137. package/dist/scheduler-GZZAN6ZG.js +2 -0
  138. package/dist/seat-VZ7AVO27.js +2 -0
  139. package/dist/select-F5I5PO2O.js +2 -0
  140. package/dist/select-F5I5PO2O.js.map +1 -0
  141. package/dist/store-MCOA6N4F.js +2 -0
  142. package/dist/{subagent-WV7QKQ3L.js → subagent-2SJHSSJS.js} +2 -2
  143. package/dist/{surface-usage-PRL6Z4U3.js → surface-usage-NS74AXSE.js} +2 -2
  144. package/dist/timers-PCB4ZIBD.js +2 -0
  145. package/dist/triage-backtest-JNO7RKX7.js +2 -0
  146. package/dist/triage-backtest-JNO7RKX7.js.map +1 -0
  147. package/dist/types-H5ENIUIT.js +2 -0
  148. package/dist/types-OIFU3KSQ.js +2 -0
  149. package/dist/web/workflow-editor.global.js +1542 -0
  150. package/dist/web/workflow-editor.global.js.map +1 -0
  151. package/dist/{whatsapp-state-XMTCSRXU.js → whatsapp-state-6D6FHHD2.js} +2 -2
  152. package/dist/wiki-N5SMP3DT.js +2 -0
  153. package/dist/wiki-N5SMP3DT.js.map +1 -0
  154. package/dist/workflows/templates/branching.yaml +1 -1
  155. package/dist/{workspace-setup-TBQAHYHJ.js → workspace-setup-B3F3TUDE.js} +2 -2
  156. package/dist/workspace-setup-B3F3TUDE.js.map +1 -0
  157. package/package.json +1 -1
  158. package/dist/agent-QGZIAZMY.js +0 -2
  159. package/dist/architect-SEPWMWS4.js +0 -2
  160. package/dist/board-dashboard-CQ5F4GPD.js.map +0 -1
  161. package/dist/chunk-2WVX3LEC.js.map +0 -1
  162. package/dist/chunk-3WQFCIB6.js +0 -24
  163. package/dist/chunk-3WQFCIB6.js.map +0 -1
  164. package/dist/chunk-4YCH6IZV.js +0 -2
  165. package/dist/chunk-53GCFZPR.js +0 -116
  166. package/dist/chunk-53GCFZPR.js.map +0 -1
  167. package/dist/chunk-53NRX2NA.js +0 -2
  168. package/dist/chunk-53NRX2NA.js.map +0 -1
  169. package/dist/chunk-5U35WAZF.js.map +0 -1
  170. package/dist/chunk-BFXONUUN.js +0 -108
  171. package/dist/chunk-BFXONUUN.js.map +0 -1
  172. package/dist/chunk-BFZUG66X.js +0 -45
  173. package/dist/chunk-BFZUG66X.js.map +0 -1
  174. package/dist/chunk-DJEZ2HVU.js.map +0 -1
  175. package/dist/chunk-FDMWOPEL.js +0 -5
  176. package/dist/chunk-FDWOECJY.js +0 -54
  177. package/dist/chunk-FDWOECJY.js.map +0 -1
  178. package/dist/chunk-G57RZCXM.js +0 -5
  179. package/dist/chunk-H5D7ATXS.js.map +0 -1
  180. package/dist/chunk-HA3XI7Z2.js +0 -155
  181. package/dist/chunk-HA3XI7Z2.js.map +0 -1
  182. package/dist/chunk-HR4JSRZS.js +0 -3
  183. package/dist/chunk-HR4JSRZS.js.map +0 -1
  184. package/dist/chunk-ISEBLHWX.js +0 -118
  185. package/dist/chunk-ISEBLHWX.js.map +0 -1
  186. package/dist/chunk-JP5IEXR7.js +0 -32
  187. package/dist/chunk-JTJIPNXY.js.map +0 -1
  188. package/dist/chunk-JXWAGMI2.js +0 -13
  189. package/dist/chunk-JXWAGMI2.js.map +0 -1
  190. package/dist/chunk-KUCCW2VG.js +0 -431
  191. package/dist/chunk-KUCCW2VG.js.map +0 -1
  192. package/dist/chunk-LDHPMJ7M.js.map +0 -1
  193. package/dist/chunk-LNXCJWOU.js.map +0 -1
  194. package/dist/chunk-NGSIRE4X.js +0 -126
  195. package/dist/chunk-NGSIRE4X.js.map +0 -1
  196. package/dist/chunk-P4VWIVKN.js.map +0 -1
  197. package/dist/chunk-Q6YO7LYE.js +0 -47
  198. package/dist/chunk-Q6YO7LYE.js.map +0 -1
  199. package/dist/chunk-SR3X25TN.js +0 -3
  200. package/dist/chunk-SR3X25TN.js.map +0 -1
  201. package/dist/chunk-TMKLHTCG.js +0 -971
  202. package/dist/chunk-TMKLHTCG.js.map +0 -1
  203. package/dist/chunk-VJUTQAPJ.js +0 -2
  204. package/dist/chunk-VJUTQAPJ.js.map +0 -1
  205. package/dist/client-GGVVLOOF.js +0 -2
  206. package/dist/config-7FSZFRTQ.js +0 -2
  207. package/dist/config-mutator-POCOYYJ4.js +0 -2
  208. package/dist/conflict-detector-D7VIYPDI.js.map +0 -1
  209. package/dist/context-planner-45GEWKGL.js +0 -17
  210. package/dist/context-planner-45GEWKGL.js.map +0 -1
  211. package/dist/debug-N3B5NVJU.js +0 -2
  212. package/dist/discover-XJXQXXIO.js.map +0 -1
  213. package/dist/doctor-DHLBEKA4.js +0 -2
  214. package/dist/heal-HZ3EQD52.js +0 -2
  215. package/dist/loader-5CA3O5GM.js +0 -2
  216. package/dist/loader-6IHUCPVO.js +0 -2
  217. package/dist/memory-extract-AENFVVO5.js +0 -2
  218. package/dist/processes-UIC4XXA6.js +0 -2
  219. package/dist/program-WVAVJFND.js +0 -2
  220. package/dist/providers-L27BJ5A6.js +0 -2
  221. package/dist/query-HZYYRCLU.js +0 -2
  222. package/dist/recipes-EPLE2SNT.js +0 -2
  223. package/dist/registry-T36ZIAWV.js +0 -2
  224. package/dist/runner-BFYDWPUO.js +0 -2
  225. package/dist/scheduler-GH7TIKYS.js +0 -2
  226. package/dist/store-I3HEWVLQ.js +0 -2
  227. package/dist/timers-5LPZN55J.js +0 -2
  228. package/dist/types-VECTMYTO.js +0 -2
  229. package/dist/types-Y6ZCZ52Z.js +0 -2
  230. package/dist/wiki-M6YNRFC4.js +0 -2
  231. /package/dist/{App-6Y7B3YQH.js.map → App-U52IPUK2.js.map} +0 -0
  232. /package/dist/{ChatApp-KIEUJ2DS.js.map → ChatApp-XP4OMHPL.js.map} +0 -0
  233. /package/dist/{agent-QGZIAZMY.js.map → agent-V2CA4TXD.js.map} +0 -0
  234. /package/dist/{architect-SEPWMWS4.js.map → article-fields-L4D2BOGY.js.map} +0 -0
  235. /package/dist/{audit-JU3HWISB.js.map → audit-4245CX6P.js.map} +0 -0
  236. /package/dist/{builtin-FRKAQMFS.js.map → builtin-B67DMJ3M.js.map} +0 -0
  237. /package/dist/{chunk-4YCH6IZV.js.map → calibration-ILS5OI44.js.map} +0 -0
  238. /package/dist/{client-GGVVLOOF.js.map → chunk-FIOB3MEX.js.map} +0 -0
  239. /package/dist/{config-7FSZFRTQ.js.map → client-PX25MD47.js.map} +0 -0
  240. /package/dist/{compaction-NWEMOSHA.js.map → compaction-FD4R23HZ.js.map} +0 -0
  241. /package/dist/{config-mutator-POCOYYJ4.js.map → config-HL5F36V4.js.map} +0 -0
  242. /package/dist/{debug-N3B5NVJU.js.map → config-mutator-HBX53OMJ.js.map} +0 -0
  243. /package/dist/{doctor-DHLBEKA4.js.map → debug-3MEUO2P2.js.map} +0 -0
  244. /package/dist/{heal-HZ3EQD52.js.map → doctor-PBAH6XL3.js.map} +0 -0
  245. /package/dist/{loader-5CA3O5GM.js.map → heal-FVLBHYP7.js.map} +0 -0
  246. /package/dist/{ingest-whatsapp-LZE62INA.js.map → ingest-whatsapp-NS4OWDOU.js.map} +0 -0
  247. /package/dist/{loader-6IHUCPVO.js.map → loader-4ZGTK7LD.js.map} +0 -0
  248. /package/dist/{memory-extract-AENFVVO5.js.map → loader-BOKE5M5S.js.map} +0 -0
  249. /package/dist/{processes-UIC4XXA6.js.map → memory-extract-F5ZHWY5E.js.map} +0 -0
  250. /package/dist/{migrate-v2-QO7SLKIM.js.map → migrate-v2-V4WN2VVM.js.map} +0 -0
  251. /package/dist/{program-WVAVJFND.js.map → processes-WU23U2OJ.js.map} +0 -0
  252. /package/dist/{providers-L27BJ5A6.js.map → program-YGXVCV2Y.js.map} +0 -0
  253. /package/dist/{projects-api-KRME2YKZ.js.map → projects-api-QE6L65SK.js.map} +0 -0
  254. /package/dist/{projects-mutate-3NHVG437.js.map → projects-mutate-MY7JTLSZ.js.map} +0 -0
  255. /package/dist/{query-HZYYRCLU.js.map → providers-KO2DODIO.js.map} +0 -0
  256. /package/dist/{recipes-EPLE2SNT.js.map → query-ZKTFJMNE.js.map} +0 -0
  257. /package/dist/{registry-T36ZIAWV.js.map → recipes-7S4MC5OJ.js.map} +0 -0
  258. /package/dist/{runner-BFYDWPUO.js.map → registry-PSZDPFZK.js.map} +0 -0
  259. /package/dist/{rotation-memo-B3EXXSEH.js.map → rotation-memo-7T75BLEX.js.map} +0 -0
  260. /package/dist/{scheduler-GH7TIKYS.js.map → runner-YRBVNYTY.js.map} +0 -0
  261. /package/dist/{store-I3HEWVLQ.js.map → scheduler-GZZAN6ZG.js.map} +0 -0
  262. /package/dist/{surface-usage-PRL6Z4U3.js.map → seat-VZ7AVO27.js.map} +0 -0
  263. /package/dist/{timers-5LPZN55J.js.map → store-MCOA6N4F.js.map} +0 -0
  264. /package/dist/{subagent-WV7QKQ3L.js.map → subagent-2SJHSSJS.js.map} +0 -0
  265. /package/dist/{types-VECTMYTO.js.map → surface-usage-NS74AXSE.js.map} +0 -0
  266. /package/dist/{types-Y6ZCZ52Z.js.map → timers-PCB4ZIBD.js.map} +0 -0
  267. /package/dist/{wiki-M6YNRFC4.js.map → types-H5ENIUIT.js.map} +0 -0
  268. /package/dist/{workspace-setup-TBQAHYHJ.js.map → types-OIFU3KSQ.js.map} +0 -0
  269. /package/dist/{whatsapp-state-XMTCSRXU.js.map → whatsapp-state-6D6FHHD2.js.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/program.ts","../src/commands/daemon.ts","../src/commands/init.ts","../src/commands/setup.ts","../src/commands/token.ts","../src/commands/manage.ts","../src/commands/db.ts","../src/commands/ledger.ts","../src/intent/replay.ts","../src/commands/trace.ts","../src/commands/guard.ts","../src/guard/seeds.ts","../src/commands/attach.ts","../src/attach/install.ts","../src/commands/process.ts","../src/commands/rag.ts","../src/commands/backlog.ts","../src/commands/schedule.ts","../src/utils/nl-cron.ts","../src/commands/connect.ts","../src/connect/telegram.ts","../src/utils/dotenv-mutator.ts","../src/connect/discord.ts","../src/connect/whatsapp.ts","../src/connect/mesh.ts","../src/commands/usage.ts","../src/commands/board.ts","../src/commands/wiki.ts","../src/commands/graph.ts","../src/commands/procedure.ts","../src/commands/procedure-extract.ts","../src/commands/workflow.ts","../src/workflows/templates/index.ts","../src/commands/webhook.ts","../src/commands/business.ts","../src/commands/plan.ts","../src/commands/notifications.ts","../src/commands/retention.ts","../src/commands/actions.ts","../src/commands/watch.ts","../src/commands/tui.ts","../src/commands/deprecation.ts","../src/commands/chat.ts","../src/commands/memory.ts","../src/commands/serve.ts","../src/commands/demo.ts","../src/commands/whatsapp.ts","../src/commands/plugin.ts","../src/commands/completion.ts"],"sourcesContent":["import { Command } from \"commander\"\nimport { daemon } from \"@/commands/daemon\"\nimport { init } from \"@/commands/init\"\nimport { setup } from \"@/commands/setup\"\nimport { token } from \"@/commands/token\"\nimport { doctor } from \"@/commands/doctor\"\nimport { agent, channel, cron, mesh, skillCmd, references, hook, migrate, configCmd } from \"@/commands/manage\"\nimport { db as dbCmd } from \"@/commands/db\"\nimport { ledger as ledgerCmd } from \"@/commands/ledger\"\nimport { trace as traceCmd } from \"@/commands/trace\"\nimport { guard as guardCmd } from \"@/commands/guard\"\nimport { attach as attachCmd } from \"@/commands/attach\"\nimport { process_ as processCmd } from \"@/commands/process\"\nimport { rag as ragCmd } from \"@/commands/rag\"\nimport { backlog } from \"@/commands/backlog\"\nimport { schedule } from \"@/commands/schedule\"\nimport { connect } from \"@/commands/connect\"\nimport { usage } from \"@/commands/usage\"\nimport { board } from \"@/commands/board\"\nimport { wiki } from \"@/commands/wiki\"\nimport { graph } from \"@/commands/graph\"\nimport { procedure } from \"@/commands/procedure\"\nimport { workflow } from \"@/commands/workflow\"\nimport { webhook } from \"@/commands/webhook\"\nimport { business } from \"@/commands/business\"\nimport { plan } from \"@/commands/plan\"\nimport { notifications } from \"@/commands/notifications\"\nimport { retention } from \"@/commands/retention\"\nimport { actions as actionsCmd } from \"@/commands/actions\"\nimport { watch } from \"@/commands/watch\"\nimport { tui } from \"@/commands/tui\"\nimport { chat } from \"@/commands/chat\"\nimport { memory as memoryCmd } from \"@/commands/memory\"\nimport { serve } from \"@/commands/serve\"\nimport { demo } from \"@/commands/demo\"\nimport { whatsapp } from \"@/commands/whatsapp\"\nimport { plugin as pluginCmd } from \"@/commands/plugin\"\nimport { completion } from \"@/commands/completion\"\nimport { getPackageInfo } from \"@/utils/get-package-info\"\nimport { commandPath, recordSurfaceUse, shouldRecordCommand } from \"@/observability/surface-usage\"\n\n/**\n * Build the full commander tree. Shared between the CLI entrypoint and the\n * `completion` command (which walks the tree to emit a shell completion script).\n */\nexport async function buildProgram(): Promise<Command> {\n const packageInfo = await getPackageInfo()\n\n const program = new Command()\n .name(\"agentx\")\n .description(\n \"self-hosted multi-agent orchestrator — Telegram, WhatsApp, crons, A2A mesh, wiki knowledge\"\n )\n .version(\n packageInfo.version || \"1.0.0\",\n \"-v, --version\",\n \"display the version number\"\n )\n\n // Count which commands operators actually run. Names only — never args.\n // The 46-command surface has no usage data behind it, so decisions about\n // what to keep are currently opinion; this makes them evidence.\n // See docs/architecture/surface-reduction.md.\n program.hook(\"preAction\", (_thisCommand, actionCommand) => {\n const path = commandPath(actionCommand as any)\n if (shouldRecordCommand(path)) recordSurfaceUse(\"cli\", path)\n })\n\n // --- Core: what `agentx --help` shows -----------------------------------\n //\n // Getting set up, running the daemon, and the handful of things an operator\n // reaches for while the fleet is live.\n for (const cmd of [\n setup, init, connect, // get running\n daemon, doctor, // operate\n agent, channel, schedule, // configure the things that carry work\n attachCmd, // wear an agent in your editor\n guardCmd, // safety\n usage, // what it cost, what gets used\n serve, // MCP\n token, configCmd, completion,\n ]) program.addCommand(cmd)\n\n // --- Advanced: registered, documented, hidden from the default help ------\n //\n // 268 commands and subcommands accumulated here. The evidence for cutting\n // the list down is unusually direct: on clawd — the node carrying 95% of\n // fleet traffic — `~/.bash_history` contains ZERO `agentx <subcommand>`\n // invocations. Production is operated with systemctl, journalctl, a text\n // editor and the dashboard. The CLI is a development surface.\n //\n // So these are hidden, NOT removed. Every one still runs, still has its own\n // `--help`, and still completes in the shell; they just stop competing for\n // attention with the fifteen commands above. Hiding is reversible in a line\n // and costs nobody anything, which is the right trade while the usage soak\n // is still young — see docs/architecture/surface-reduction.md.\n //\n // The help footer below names them all, so nothing here is secret.\n for (const cmd of ADVANCED) program.addCommand(cmd, { hidden: true })\n\n program.addHelpText(\"after\", () => {\n const names = ADVANCED.map((c) => c.name()).sort()\n return [\n \"\",\n `Advanced (${names.length}, hidden — run \\`agentx <command> --help\\` for any of them):`,\n wrapNames(names, 74, \" \"),\n \"\",\n ].join(\"\\n\")\n })\n\n return program\n}\n\n/** Registered and fully functional, just not in the default help listing. */\nconst ADVANCED = [\n // Knowledge + memory\n wiki, graph, memoryCmd, procedure, references, ragCmd,\n // Workflow / BPM\n workflow, webhook, board, backlog, business, plan,\n // Observability + forensics\n ledgerCmd, traceCmd, processCmd, watch, dbCmd,\n // Fleet + extension\n mesh, skillCmd, pluginCmd, hook, actionsCmd,\n // Scheduling internals (`schedule` is the friendly front door)\n cron,\n // Housekeeping\n migrate, retention, notifications,\n // Channel-specific + demo\n whatsapp, demo,\n // Deprecated — superseded by `agentx attach`\n chat, tui,\n]\n\n/** Pack names into indented lines of at most `width` characters. */\nfunction wrapNames(names: string[], width: number, indent: string): string {\n const lines: string[] = []\n let line = \"\"\n for (const n of names) {\n if (line && (line.length + n.length + 2) > width) {\n lines.push(indent + line)\n line = \"\"\n }\n line += (line ? \", \" : \"\") + n\n }\n if (line) lines.push(indent + line)\n return lines.join(\"\\n\")\n}\n","import { Command } from \"commander\"\nimport { AgentXDaemon } from \"@/daemon\"\nimport { loadDaemonConfig, validateWorkspaces } from \"@/daemon/config\"\nimport chalk from \"chalk\"\nimport { existsSync, readFileSync } from \"fs\"\n\n// --- agentx daemon: start/stop/status/logs ---\n\n/**\n * Best-effort check that a live PID is actually an agentx/node daemon rather\n * than an unrelated process the OS assigned our recycled PID to. Returns true\n * only when the process command line clearly looks like agentx; on any doubt\n * (unknown platform, ps failure) it errs toward true so we never spawn a\n * duplicate daemon on a healthy host.\n */\nasync function isLikelyAgentxProcess(pid: number): Promise<boolean> {\n try {\n const { execFileSync } = await import(\"child_process\")\n // `ps -p <pid> -o command=` works on both macOS and Linux and prints the\n // full command line with no header.\n const cmd = execFileSync(\"ps\", [\"-p\", String(pid), \"-o\", \"command=\"], {\n encoding: \"utf-8\",\n timeout: 2000,\n }).trim()\n if (!cmd) return false // no such process line — treat as stale\n // agentx daemons run as `node .../cli.js daemon ...` (or `agentx daemon`).\n return /\\bnode\\b/.test(cmd) || /agentx|agentix|cli\\.js/.test(cmd)\n } catch {\n // ps unavailable or errored — fall back to the conservative assumption\n // that the PID is a real daemon so we don't double-spawn.\n return true\n }\n}\n\nexport const daemon = new Command()\n .name(\"daemon\")\n .description(\"manage the agentx daemon — start, stop, status, logs\")\n\n// agentx daemon start\ndaemon\n .command(\"start\")\n .description(\"start the daemon (default if no subcommand)\")\n .option(\"-c, --config <path>\", \"path to agentx.json\")\n .option(\"-d, --detach\", \"run in background (detached)\")\n .option(\"--port <port>\", \"override bind port\")\n .action(async (opts) => {\n if (opts.detach) {\n const { spawn } = await import(\"child_process\")\n const { openSync, writeFileSync, existsSync } = await import(\"fs\")\n\n // Use the actual node binary + entrypoint that's running this command.\n // The previous version hardcoded `node dist/cli.js`, which broke for\n // npm-installed users (no dist/cli.js relative to their CWD): the spawn\n // succeeded with a PID, the child crashed immediately on missing module,\n // and stdio:\"ignore\" hid the failure — leaving the operator with a\n // \"Daemon started\" success line and a daemon that was never alive.\n const cli = process.argv[1]\n if (!cli || !existsSync(cli)) {\n console.error(chalk.red(` Cannot resolve agentx CLI entrypoint (process.argv[1]=${cli || \"?\"}).`))\n console.error(chalk.dim(` Try running without --detach to see the underlying error.`))\n process.exit(1)\n }\n const args = [cli, \"daemon\", \"start\"]\n if (opts.config) args.push(\"-c\", opts.config)\n if (opts.port) args.push(\"--port\", opts.port)\n\n // Open the log file and pipe child stdout+stderr into it. Without this\n // (the previous code did stdio:\"ignore\"), every detach-mode crash was\n // invisible — the user was told to `tail -f /tmp/agentx-daemon.log`,\n // but nothing ever wrote to that path, so the file didn't exist.\n const logPath = \"/tmp/agentx-daemon.log\"\n let logFd: number\n try {\n logFd = openSync(logPath, \"a\")\n } catch (e: any) {\n console.error(chalk.red(` Failed to open ${logPath} for writing: ${e.message}`))\n process.exit(1)\n }\n\n const child = spawn(process.execPath, args, {\n detached: true,\n stdio: [\"ignore\", logFd, logFd],\n cwd: process.cwd(),\n })\n child.unref()\n\n writeFileSync(\"/tmp/agentx-daemon.pid\", String(child.pid))\n console.log(chalk.green(`Daemon started in background (PID: ${child.pid})`))\n console.log(chalk.dim(` Logs: tail -f ${logPath}`))\n console.log(chalk.dim(` Stop: agentx daemon stop`))\n // Brief sanity probe — if the child died in the first 1s (e.g. claude\n // CLI missing, port already bound, config invalid), tell the operator\n // to look at the log file rather than letting them discover it after\n // `agentx daemon watch` fails 30 seconds later.\n await new Promise((ok) => setTimeout(ok, 1000))\n try {\n process.kill(child.pid!, 0)\n } catch {\n console.log()\n console.log(chalk.yellow(` Daemon exited within 1s — check ${logPath} for the error:`))\n console.log(chalk.dim(` tail -n 40 ${logPath}`))\n }\n return\n }\n\n // Single-instance guard — only one daemon can run at a time.\n // If another process is alive with the recorded PID, exit immediately.\n const { readFileSync, writeFileSync, mkdirSync, existsSync } = await import(\"fs\")\n const { resolve } = await import(\"path\")\n const lockDir = resolve(process.cwd(), \".agentx\")\n if (!existsSync(lockDir)) mkdirSync(lockDir, { recursive: true })\n const pidPath = resolve(lockDir, \"daemon.pid\")\n\n if (existsSync(pidPath)) {\n const oldPid = parseInt(readFileSync(pidPath, \"utf-8\").trim(), 10)\n if (oldPid && oldPid !== process.pid) {\n let alive = false\n try {\n process.kill(oldPid, 0) // throws if process doesn't exist\n alive = true\n } catch {\n // Old process is dead — we can proceed\n }\n // A bare kill(pid, 0) only proves *some* process holds that PID.\n // PIDs get recycled — the OS may have reassigned our old PID to an\n // unrelated process (e.g. a macOS system extension), which would\n // wedge startup forever behind a false \"already running\". Confirm\n // the live PID is actually a node/agentx process before yielding.\n if (alive && (await isLikelyAgentxProcess(oldPid))) {\n console.error(`Another agentx daemon is already running (PID ${oldPid}). Exiting.`)\n process.exit(0)\n }\n }\n }\n writeFileSync(pidPath, String(process.pid))\n\n // Auto-load .env from the working directory so `{{env.FOO}}` in\n // workflows + agent prompts just works without editing systemd\n // units. Existing process.env values win — we never overwrite what\n // the runtime was launched with.\n try { loadDotenv(resolve(process.cwd(), \".env\")) } catch { /* best effort */ }\n\n const d = new AgentXDaemon(opts.config)\n await d.start()\n })\n\n/** Minimal .env parser: KEY=VALUE lines. Quotes around the value are\n * stripped. Blank lines + comments ignored. No substitution, no export\n * keyword — we don't want to pull dotenv for this. Variables already in\n * process.env take precedence so a systemd override always wins. */\nfunction loadDotenv(path: string): void {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n if (!existsSync(path)) return\n const text = readFileSync(path, \"utf-8\")\n for (const raw of text.split(\"\\n\")) {\n const line = raw.trim()\n if (!line || line.startsWith(\"#\")) continue\n const eq = line.indexOf(\"=\")\n if (eq < 0) continue\n const key = line.slice(0, eq).trim()\n if (!key || process.env[key] !== undefined) continue\n let val = line.slice(eq + 1).trim()\n if ((val.startsWith(\"\\\"\") && val.endsWith(\"\\\"\")) || (val.startsWith(\"'\") && val.endsWith(\"'\"))) {\n val = val.slice(1, -1)\n }\n process.env[key] = val\n }\n}\n\n// agentx daemon stop\ndaemon\n .command(\"stop\")\n .description(\"stop the running daemon\")\n .action(async () => {\n const { readFileSync, existsSync, unlinkSync } = await import(\"fs\")\n const { resolve } = await import(\"path\")\n\n // Check both PID file locations\n const pidFiles = [\n resolve(process.cwd(), \".agentx/daemon.pid\"),\n \"/tmp/agentx-daemon.pid\",\n ]\n\n for (const pidFile of pidFiles) {\n if (!existsSync(pidFile)) continue\n try {\n const pid = parseInt(readFileSync(pidFile, \"utf-8\").trim(), 10)\n process.kill(pid, \"SIGTERM\")\n // Wait briefly for graceful shutdown\n await new Promise(r => setTimeout(r, 2000))\n try { unlinkSync(pidFile) } catch {}\n console.log(chalk.green(`Daemon stopped (PID: ${pid})`))\n return\n } catch {\n try { unlinkSync(pidFile) } catch {}\n }\n }\n\n // Fallback: kill by process name\n const { execSync } = await import(\"child_process\")\n try {\n execSync(\"pkill -f 'node dist/cli.js daemon'\", { stdio: \"ignore\" })\n console.log(chalk.green(\"Daemon stopped\"))\n } catch {\n console.log(chalk.yellow(\"No daemon process found\"))\n }\n })\n\n// agentx daemon status\ndaemon\n .command(\"status\")\n .alias(\"st\")\n .description(\"show daemon status, agents, crons, and mesh\")\n .option(\"-c, --config <path>\", \"path to agentx.json\")\n .option(\"--json\", \"output as JSON\")\n .action(async (opts) => {\n // Try connecting to running daemon first\n try {\n const config = loadDaemonConfig(opts.config)\n const [host, port] = config.node.bind.split(\":\")\n const url = `http://${host || \"127.0.0.1\"}:${port}/health`\n const res = await fetch(url, { signal: AbortSignal.timeout(3000) })\n const data = await res.json() as any\n\n if (opts.json) {\n console.log(JSON.stringify(data, null, 2))\n return\n }\n\n console.log()\n console.log(chalk.bold(` ${data.node.name}`) + chalk.dim(` (${data.node.id})`))\n console.log(chalk.green(\" Status: running\") + chalk.dim(` — uptime ${formatDuration(data.uptime)}`))\n console.log()\n\n // Agents\n console.log(chalk.bold(\" Agents:\"))\n for (const a of data.agents) {\n const active = a.active > 0 ? chalk.yellow(` [${a.active} active]`) : \"\"\n const errors = a.errors > 0 ? chalk.red(` (${a.errors} errors)`) : \"\"\n console.log(` ${chalk.cyan(a.name)} ${chalk.dim(`(${a.tier})`)}${active}${errors}`)\n console.log(chalk.dim(` ${a.workspace}`))\n }\n\n // Crons\n const enabledCrons = data.crons.filter((c: any) => c.enabled)\n if (data.crons.length) {\n console.log()\n console.log(chalk.bold(` Crons: ${enabledCrons.length} enabled / ${data.crons.length} total`))\n for (const c of data.crons) {\n const icon = c.enabled ? chalk.green(\"●\") : chalk.dim(\"○\")\n const next = c.nextRun ? chalk.dim(` next: ${new Date(c.nextRun).toLocaleTimeString()}`) : \"\"\n console.log(` ${icon} ${c.id}${next}`)\n }\n }\n\n // Mesh\n if (data.mesh?.length) {\n console.log()\n console.log(chalk.bold(\" Mesh:\"))\n for (const p of data.mesh) {\n const icon = p.healthy ? chalk.green(\"●\") : chalk.red(\"●\")\n const skills = p.skills?.length ? chalk.dim(` (${p.skills.length} agents)`) : \"\"\n console.log(` ${icon} ${p.peer} ${chalk.dim(p.peerUrl)}${skills}`)\n }\n }\n\n console.log()\n } catch (e: any) {\n if (e.cause?.code === \"ECONNREFUSED\" || e.name === \"TimeoutError\") {\n console.log(chalk.red(\" Daemon is not running\"))\n console.log(chalk.dim(\" Start with: agentx daemon start\"))\n } else {\n // No running daemon — show config info\n try {\n const config = loadDaemonConfig(opts.config)\n const warnings = validateWorkspaces(config)\n console.log()\n console.log(chalk.bold(` ${config.node.name}`) + chalk.dim(` (${config.node.id})`))\n console.log(chalk.yellow(\" Status: stopped\"))\n console.log(chalk.dim(` ${Object.keys(config.agents).length} agents, ${Object.keys(config.crons).length} crons configured`))\n if (warnings.length) {\n console.log()\n for (const w of warnings) console.log(chalk.yellow(` ⚠ ${w}`))\n }\n console.log()\n } catch (err: any) {\n console.log(chalk.red(` ${err.message}`))\n }\n }\n }\n })\n\n// agentx daemon logs\ndaemon\n .command(\"logs\")\n .description(\"tail daemon logs\")\n .option(\"-n, --lines <n>\", \"number of lines\", \"50\")\n .option(\"-f, --follow\", \"follow log output\", false)\n .action(async (opts) => {\n const { execSync, spawn: spawnProc } = await import(\"child_process\")\n const logFile = \"/tmp/agentx-daemon.log\"\n\n const { existsSync } = await import(\"fs\")\n if (!existsSync(logFile)) {\n console.log(chalk.yellow(\"No log file found at /tmp/agentx-daemon.log\"))\n return\n }\n\n if (opts.follow) {\n const tail = spawnProc(\"tail\", [\"-f\", \"-n\", opts.lines, logFile], { stdio: \"inherit\" })\n process.on(\"SIGINT\", () => { tail.kill(); process.exit(0) })\n } else {\n execSync(`tail -n ${opts.lines} ${logFile}`, { stdio: \"inherit\" })\n }\n })\n\n// agentx daemon watch — live stream of agent activity\ndaemon\n .command(\"watch\")\n .description(\"stream live agent activity (SSE)\")\n .option(\"-c, --config <path>\", \"path to agentx.json\")\n .action(async (opts) => {\n const config = loadDaemonConfig(opts.config)\n const bind = config.node.bind || \"127.0.0.1:18800\"\n const url = `http://${bind.replace(\"0.0.0.0\", \"127.0.0.1\")}/events`\n\n console.log(chalk.dim(` Connecting to ${url}...`))\n console.log(chalk.dim(\" Press Ctrl+C to stop\\n\"))\n\n try {\n const res = await fetch(url)\n if (!res.ok || !res.body) {\n console.log(chalk.red(` Failed: ${res.status}`))\n return\n }\n const reader = res.body.getReader()\n const decoder = new TextDecoder()\n let buffer = \"\"\n\n while (true) {\n const { done, value } = await reader.read()\n if (done) break\n buffer += decoder.decode(value, { stream: true })\n const lines = buffer.split(\"\\n\")\n buffer = lines.pop() || \"\"\n for (const line of lines) {\n if (line.startsWith(\"data: \")) {\n try {\n const data = JSON.parse(line.slice(6))\n const time = new Date(data.time).toLocaleTimeString()\n const msg = data.message?.replace(/^\\[agentx\\]\\s*/, \"\") || \"\"\n // Color-code by content\n if (msg.includes(\"executing\")) console.log(`${chalk.dim(time)} ${chalk.cyan(\"▶\")} ${msg}`)\n else if (msg.includes(\"completed\")) console.log(`${chalk.dim(time)} ${chalk.green(\"✓\")} ${msg}`)\n else if (msg.includes(\"error\") || msg.includes(\"Error\")) console.log(`${chalk.dim(time)} ${chalk.red(\"✗\")} ${msg}`)\n else if (msg.includes(\"Routing\")) console.log(`${chalk.dim(time)} ${chalk.yellow(\"→\")} ${msg}`)\n else if (msg.includes(\"mention\")) console.log(`${chalk.dim(time)} ${chalk.magenta(\"@\")} ${msg}`)\n else if (msg.includes(\"Skipping\")) console.log(`${chalk.dim(time)} ${chalk.dim(\"⊘\")} ${chalk.dim(msg)}`)\n else console.log(`${chalk.dim(time)} ${msg}`)\n } catch { /* skip malformed */ }\n } else if (line.startsWith(\"event: status\")) {\n // First event — show current state\n }\n }\n }\n } catch (e: any) {\n console.log(chalk.red(` Connection failed: ${e.message}`))\n console.log(chalk.dim(\" Is the daemon running? Diagnostic order:\"))\n console.log(chalk.dim(\" 1) agentx daemon status # is the daemon up?\"))\n console.log(chalk.dim(\" 2) tail -n 60 /tmp/agentx-daemon.log # detach-mode crash log\"))\n console.log(chalk.dim(\" 3) journalctl -u agentx -n 60 # systemd-managed installs\"))\n console.log(chalk.dim(\" If the log file is missing, the daemon never started — re-run without --detach\"))\n console.log(chalk.dim(\" to see the error in the foreground.\"))\n }\n })\n\n// agentx daemon send — send a task to an agent\ndaemon\n .command(\"send <agent> <message...>\")\n .description(\"send a task to an agent via the daemon API\")\n .option(\"-c, --config <path>\", \"path to agentx.json\")\n .option(\"--peer <peer>\", \"send to a mesh peer's agent\")\n .option(\"--json\", \"output raw JSON response\")\n .action(async (agent, messageParts, opts) => {\n const message = messageParts.join(\" \")\n\n try {\n const config = loadDaemonConfig(opts.config)\n const [host, port] = config.node.bind.split(\":\")\n const baseUrl = `http://${host || \"127.0.0.1\"}:${port}`\n\n let url: string\n let body: Record<string, unknown>\n\n if (opts.peer) {\n url = `${baseUrl}/mesh/task`\n body = { peer: opts.peer, message, agent }\n } else {\n url = `${baseUrl}/task`\n body = { agent, message }\n }\n\n console.log(chalk.dim(` Sending to ${opts.peer ? `${opts.peer}/${agent}` : agent}...`))\n\n const res = await fetch(url, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n })\n\n const data = await res.json() as any\n\n if (opts.json) {\n console.log(JSON.stringify(data, null, 2))\n } else if (data.error) {\n console.log(chalk.red(` Error: ${data.error}`))\n } else {\n console.log()\n console.log(data.content || data.response || \"No response\")\n if (data.duration) {\n console.log(chalk.dim(`\\n (${(data.duration / 1000).toFixed(1)}s)`))\n }\n }\n } catch (e: any) {\n console.log(chalk.red(` Failed: ${e.message}`))\n console.log(chalk.dim(\" Is the daemon running? Try: agentx daemon status\"))\n }\n })\n\n// agentx daemon deploy — rsync dist to a remote server\ndaemon\n .command(\"deploy <host>\")\n .description(\"deploy agentx to a remote server via rsync\")\n .option(\"-i, --identity <key>\", \"SSH identity file\")\n .option(\"-u, --user <user>\", \"SSH user\", \"root\")\n .option(\"-p, --path <path>\", \"remote agentx path\", \"~/agentx\")\n .option(\"--restart\", \"restart remote daemon after deploy\", false)\n .option(\"--skip-checks\", \"skip build and test before deploy\", false)\n .action(async (host, opts) => {\n const { execSync } = await import(\"child_process\")\n const sshKey = opts.identity ? `-e \"ssh -i ${opts.identity}\"` : \"\"\n const remote = `${opts.user}@${host}:${opts.path}/dist/`\n\n // Pre-deploy checks\n if (!opts.skipChecks) {\n try {\n console.log(chalk.dim(\" Running tests...\"))\n execSync(\"npx vitest run --reporter=dot\", { stdio: \"pipe\", cwd: process.cwd() })\n console.log(chalk.green(\" ✓ Tests passed\"))\n } catch (e: any) {\n console.log(chalk.red(\" ✗ Tests failed — aborting deploy\"))\n console.log(chalk.dim(\" Use --skip-checks to deploy anyway\"))\n return\n }\n\n // Check dist exists and is recent\n const { existsSync, statSync } = await import(\"fs\")\n const { resolve } = await import(\"path\")\n const cliPath = resolve(process.cwd(), \"dist/cli.js\")\n if (!existsSync(cliPath)) {\n console.log(chalk.red(\" ✗ dist/ not found — run build first\"))\n return\n }\n const age = Date.now() - statSync(cliPath).mtimeMs\n if (age > 300_000) {\n console.log(chalk.yellow(\" ⚠ dist/ is older than 5 minutes — rebuilding...\"))\n execSync(\"npx tsup --no-dts\", { stdio: \"pipe\", cwd: process.cwd() })\n console.log(chalk.green(\" ✓ Build complete\"))\n }\n }\n\n console.log(chalk.dim(` Deploying to ${opts.user}@${host}:${opts.path}...`))\n\n try {\n execSync(`rsync -avzL --delete ${sshKey} dist/ ${remote}`, {\n stdio: \"inherit\",\n cwd: process.cwd(),\n })\n console.log(chalk.green(\" ✓ Deploy complete\"))\n\n if (opts.restart) {\n console.log(chalk.dim(\" Restarting remote daemon...\"))\n const ssh = opts.identity ? `ssh -i ${opts.identity}` : \"ssh\"\n execSync(\n `${ssh} ${opts.user}@${host} \"pkill -f 'node dist/cli.js daemon' 2>/dev/null; sleep 2; cd ${opts.path} && nohup node dist/cli.js daemon start > /tmp/agentx-daemon.log 2>&1 &\"`,\n { stdio: \"inherit\" },\n )\n console.log(chalk.green(\" Remote daemon restarted\"))\n }\n } catch (e: any) {\n console.log(chalk.red(` Deploy failed: ${e.message}`))\n }\n })\n\n// Default: `agentx daemon` without subcommand starts the daemon\ndaemon.action(async (opts) => {\n const d = new AgentXDaemon(opts.config)\n await d.start()\n})\n\nfunction formatDuration(seconds: number): string {\n if (seconds < 60) return `${Math.round(seconds)}s`\n if (seconds < 3600) return `${Math.round(seconds / 60)}m`\n if (seconds < 86400) return `${Math.round(seconds / 3600)}h ${Math.round((seconds % 3600) / 60)}m`\n return `${Math.round(seconds / 86400)}d ${Math.round((seconds % 86400) / 3600)}h`\n}\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { existsSync, readFileSync, writeFileSync, mkdirSync, copyFileSync } from \"fs\"\nimport { hostname } from \"os\"\nimport { resolve, join } from \"path\"\n\n// --- agentx init: interactive setup for new installations ---\n\nexport const init = new Command()\n .name(\"init\")\n .description(\"initialize agentx configuration in the current directory\")\n .option(\"--force\", \"overwrite existing config\")\n .action(async (opts) => {\n const cwd = process.cwd()\n const configPath = resolve(cwd, \"agentx.json\")\n const envPath = resolve(cwd, \".env\")\n const sessionsDir = resolve(cwd, \".agentx/sessions\")\n\n console.log()\n console.log(chalk.bold(\" agentx init\"))\n console.log()\n\n // Check existing config\n if (existsSync(configPath) && !opts.force) {\n console.log(chalk.yellow(` agentx.json already exists. Use --force to overwrite.`))\n console.log()\n return\n }\n\n // Find example config\n const examplePaths = [\n resolve(cwd, \"agentx.example.json\"),\n resolve(cwd, \"node_modules/agentix-cli/agentx.example.json\"),\n ]\n\n let example: string | undefined\n for (const p of examplePaths) {\n if (existsSync(p)) {\n example = readFileSync(p, \"utf-8\")\n break\n }\n }\n\n if (!example) {\n // Generate minimal config\n example = JSON.stringify({\n node: {\n id: hostname().toLowerCase().replace(/[^a-z0-9-]/g, \"-\"),\n name: hostname(),\n bind: \"127.0.0.1:18800\",\n },\n providers: {\n claude: { apiKey: \"${ANTHROPIC_API_KEY}\" },\n },\n agents: {\n assistant: {\n name: \"Assistant\",\n workspace: cwd,\n tier: \"claude-code\",\n model: \"claude-sonnet-4-6\",\n mentions: [\"@assistant\", \"assistant\"],\n maxConcurrent: 2,\n systemPrompt: \"You are a helpful assistant.\",\n permissionMode: \"default\",\n },\n },\n channels: {\n telegram: {\n enabled: false,\n accounts: {},\n policy: { dm: \"pair\", group: \"mention-required\" },\n },\n whatsapp: { enabled: false },\n },\n crons: {},\n mesh: {\n enabled: false,\n peers: [],\n discovery: \"static\",\n healthCheck: { interval: 60, timeout: 10 },\n },\n }, null, 2)\n }\n\n // Write config\n writeFileSync(configPath, example)\n console.log(chalk.green(` ✓ Created agentx.json`))\n\n // Create .env template\n if (!existsSync(envPath)) {\n writeFileSync(envPath, [\n \"# AgentX environment variables\",\n \"# ANTHROPIC_API_KEY=sk-ant-...\",\n \"# TG_BOT_TOKEN=123456:ABC...\",\n \"# MESH_TOKEN=your-mesh-secret\",\n \"\",\n ].join(\"\\n\"))\n console.log(chalk.green(` ✓ Created .env template`))\n }\n\n // Create session dir\n if (!existsSync(sessionsDir)) {\n mkdirSync(sessionsDir, { recursive: true })\n console.log(chalk.green(` ✓ Created .agentx/sessions/`))\n }\n\n // Create workspace .claude dir\n const claudeDir = resolve(cwd, \".claude\")\n if (!existsSync(claudeDir)) {\n mkdirSync(claudeDir, { recursive: true })\n console.log(chalk.green(` ✓ Created .claude/`))\n }\n\n console.log()\n console.log(chalk.bold(\" Next steps:\"))\n console.log(` 1. Edit ${chalk.cyan(\"agentx.json\")} — configure agents, channels, crons`)\n console.log(` 2. Edit ${chalk.cyan(\".env\")} — add API keys and bot tokens`)\n console.log(` 3. Run ${chalk.cyan(\"agentx daemon start\")} — start the daemon`)\n console.log(` 4. Run ${chalk.cyan(\"agentx daemon status\")} — verify everything`)\n console.log()\n })\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { spawn } from \"child_process\"\nimport { existsSync } from \"fs\"\nimport { dirname, resolve } from \"path\"\nimport { fileURLToPath } from \"url\"\nimport { wizardState } from \"@/daemon/setup-wizard\"\nimport { loadDaemonConfig } from \"@/daemon/config\"\n\n// --- agentx setup: launch the web setup wizard ---\n//\n// The wizard itself is a web form served by the board-dashboard process (on\n// port 4202). This command starts that process (if it isn't already running)\n// and opens the wizard URL in the user's default browser — zero CLI prompts.\n\nexport const setup = new Command()\n .name(\"setup\")\n .description(\"open the web setup wizard to create or extend your AgentX install\")\n .option(\"--port <n>\", \"dashboard port (default: from agentx.json, else 4202)\")\n .option(\"--no-open\", \"don't try to open the browser\")\n .action(async (opts) => {\n const state = wizardState()\n const port = opts.port ? parseInt(opts.port, 10) : resolveDashboardPort()\n const url = `http://127.0.0.1:${port}/setup`\n\n console.log()\n if (state.configExists) {\n console.log(chalk.dim(` Found agentx.json — the wizard will extend your current install.`))\n } else {\n console.log(chalk.dim(` No agentx.json yet — the wizard will create one.`))\n }\n console.log(chalk.bold(` Opening ${url}`))\n console.log()\n\n // If the board server isn't already listening, start it in the background.\n const alreadyUp = await probe(url).catch(() => false)\n if (!alreadyUp) {\n console.log(chalk.dim(` Starting dashboard server on port ${port} (Ctrl-C to quit)…`))\n const cli = resolveCliEntry()\n const child = spawn(process.execPath, [cli, \"board\", \"serve\", \"--port\", String(port)], {\n stdio: \"inherit\",\n detached: false,\n })\n // Give the server a beat to bind before opening the browser.\n await new Promise((ok) => setTimeout(ok, 1200))\n if (opts.open !== false) openBrowser(url)\n // Stay attached so the user sees the server logs.\n await new Promise<void>((ok) => child.on(\"exit\", () => ok()))\n } else {\n console.log(chalk.dim(` Dashboard is already running.`))\n if (opts.open !== false) openBrowser(url)\n }\n })\n\nfunction resolveDashboardPort(): number {\n try {\n const cfg = loadDaemonConfig()\n return cfg.dashboard.port || 4202\n } catch {\n return 4202\n }\n}\n\nfunction resolveCliEntry(): string {\n // When installed via npm, this module runs from dist/; cli.js sits beside it.\n // The bundle is ESM, so CommonJS __dirname is not defined.\n // In dev, we fall back to the current script so `tsx` works too.\n const candidate = resolve(dirname(fileURLToPath(import.meta.url)), \"cli.js\")\n return existsSync(candidate) ? candidate : (process.argv[1] || candidate)\n}\n\nasync function probe(url: string): Promise<boolean> {\n try {\n const r = await fetch(url, { method: \"GET\" })\n return r.ok || r.status === 302\n } catch { return false }\n}\n\nfunction openBrowser(url: string): void {\n const cmd = process.platform === \"darwin\" ? \"open\"\n : process.platform === \"win32\" ? \"start\"\n : \"xdg-open\"\n try {\n // spawn() reports a missing binary (ENOENT) via an async \"error\" event on\n // the child, NOT a synchronous throw — so the try/catch alone wouldn't\n // catch it. Headless Linux servers commonly lack xdg-open; without the\n // listener the unhandled error propagates and kills the wizard process.\n const child = spawn(cmd, [url], { stdio: \"ignore\", detached: true })\n child.once(\"error\", () => {\n console.log(chalk.dim(` Couldn't auto-open the browser. Visit ${url} manually.`))\n })\n child.unref()\n } catch {\n console.log(chalk.dim(` Couldn't auto-open the browser. Visit ${url} manually.`))\n }\n}\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { TokenStore } from \"@/daemon/token-store\"\n\n// --- agentx token: mint / list / revoke scoped API tokens ---\n\nexport const token = new Command()\n .name(\"token\")\n .description(\"scoped API tokens for external access (mesh peers, integrations)\")\n\ntoken\n .command(\"create\")\n .description(\"mint a new token — prints the secret once, store it somewhere safe\")\n .requiredOption(\"--name <name>\", \"human-readable label (e.g. 'Slack integration')\")\n .option(\"--scope <scopes>\", \"comma-separated scopes (default: dashboard:read)\", \"dashboard:read\")\n .option(\"--expires <days>\", \"expire after N days (default: no expiry)\")\n .action((opts) => {\n try {\n const store = new TokenStore()\n const scopes = String(opts.scope).split(\",\").map((s) => s.trim()).filter(Boolean)\n const days = opts.expires ? parseInt(opts.expires, 10) : undefined\n if (opts.expires && (!days || days < 1)) throw new Error(\"--expires must be a positive integer (days)\")\n const { token: secret, record } = store.create({ name: opts.name, scopes, expiresInDays: days })\n console.log()\n console.log(chalk.bold(\" Token created.\"))\n console.log()\n console.log(` id: ${chalk.cyan(record.id)}`)\n console.log(` name: ${record.name}`)\n console.log(` scopes: ${record.scopes.join(\", \")}`)\n console.log(` expires: ${record.expiresAt || chalk.dim(\"never\")}`)\n console.log()\n console.log(chalk.yellow(\" ⚠ This is the only time the full secret will be shown.\"))\n console.log()\n console.log(` ${chalk.green.bold(secret)}`)\n console.log()\n console.log(chalk.dim(\" Use it via the Authorization header:\"))\n console.log(chalk.dim(` curl -H \"Authorization: Bearer ${secret.slice(0, 16)}...\" ...`))\n console.log()\n } catch (e: any) {\n console.log(chalk.red(` ${e.message}`))\n process.exit(1)\n }\n })\n\ntoken\n .command(\"list\")\n .alias(\"ls\")\n .description(\"show all issued tokens (secrets not included)\")\n .action(() => {\n try {\n const records = new TokenStore().list()\n if (records.length === 0) {\n console.log(chalk.dim(\"\\n No tokens issued.\\n\"))\n return\n }\n console.log()\n for (const r of records) {\n const status = r.revokedAt\n ? chalk.red(\"revoked\")\n : r.expiresAt && Date.parse(r.expiresAt) < Date.now()\n ? chalk.red(\"expired\")\n : chalk.green(\"active\")\n console.log(` ${chalk.cyan(r.id)} ${status} ${r.name}`)\n console.log(chalk.dim(` prefix: ${r.prefix}… scopes: ${r.scopes.join(\", \")}`))\n console.log(chalk.dim(` created: ${r.createdAt}${r.expiresAt ? ` expires: ${r.expiresAt}` : \"\"}${r.lastUsedAt ? ` last used: ${r.lastUsedAt}` : \"\"}`))\n }\n console.log()\n } catch (e: any) {\n console.log(chalk.red(` ${e.message}`))\n process.exit(1)\n }\n })\n\ntoken\n .command(\"revoke <id>\")\n .description(\"immediately invalidate a token\")\n .action((id: string) => {\n try {\n const rec = new TokenStore().revoke(id)\n if (!rec) {\n console.log(chalk.red(` Token ${id} not found.`))\n process.exit(1)\n }\n console.log(chalk.green(`\\n ✓ Revoked ${id} (${rec.name})\\n`))\n } catch (e: any) {\n console.log(chalk.red(` ${e.message}`))\n process.exit(1)\n }\n })\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport prompts from \"prompts\"\nimport { readFileSync, writeFileSync, existsSync, mkdirSync, cpSync, readdirSync } from \"fs\"\nimport { resolve, join, dirname } from \"path\"\nimport { fileURLToPath } from \"url\"\nimport { loadDaemonConfig, validateWorkspaces } from \"@/daemon/config\"\nimport { applyConfigMutation } from \"@/daemon/config-mutator\"\n\n// --- agentx agent/channel/cron/mesh/skill/hook management commands ---\n\nfunction loadConfig(): any {\n const p = resolve(process.cwd(), \"agentx.json\")\n if (!existsSync(p)) throw new Error(\"No agentx.json found. Run: agentx init\")\n return JSON.parse(readFileSync(p, \"utf-8\"))\n}\n\n/**\n * Persist a mutated config. Goes through applyConfigMutation so every caller\n * gets pre-save Zod validation and an automatic daemon hot-reload when one is\n * running. Returns a promise; callers inside async .action handlers should\n * await it so the reload signal lands before the CLI process exits.\n */\nfunction saveConfig(config: any): Promise<void> {\n return applyConfigMutation((current) => {\n for (const k of Object.keys(current)) delete current[k]\n Object.assign(current, config)\n }).then((result) => {\n if (!result.success) {\n console.error(chalk.red(` Config save failed: ${result.error}`))\n return\n }\n if (result.reloaded) {\n console.error(chalk.dim(\" (daemon hot-reloaded)\"))\n } else if (result.reloadSkipped && !/ECONNREFUSED|unreachable|fetch failed/i.test(result.reloadSkipped)) {\n console.error(chalk.dim(` (daemon reload skipped: ${result.reloadSkipped})`))\n }\n })\n}\n\n// ==================== agentx agent ====================\n\nexport const agent = new Command()\n .name(\"agent\")\n .description(\"manage agents — add, list, remove\")\n\nagent\n .command(\"list\")\n .alias(\"ls\")\n .description(\"list configured agents\")\n .action(() => {\n const config = loadConfig()\n console.log()\n for (const [id, a] of Object.entries(config.agents || {}) as any) {\n const mentions = a.mentions?.join(\", \") || \"\"\n console.log(` ${chalk.cyan(id)} — ${a.name} (${a.tier})`)\n console.log(chalk.dim(` workspace: ${a.workspace}`))\n if (mentions) console.log(chalk.dim(` mentions: ${mentions}`))\n }\n console.log()\n })\n\nagent\n .command(\"add\")\n .description(\"add a new agent interactively\")\n .action(async () => {\n const config = loadConfig()\n\n const answers = await prompts([\n { type: \"text\", name: \"id\", message: \"Agent ID (kebab-case)\", validate: (v: string) => /^[a-z0-9-]+$/.test(v) || \"Use lowercase, numbers, hyphens\" },\n { type: \"text\", name: \"name\", message: \"Display name\" },\n { type: \"text\", name: \"workspace\", message: \"Workspace path\", initial: resolve(process.cwd(), \"agents/\") },\n { type: \"select\", name: \"tier\", message: \"Execution tier\", choices: [\n { title: \"claude-code (subscription, full features)\", value: \"claude-code\" },\n { title: \"codex-cli (OpenAI Codex CLI)\", value: \"codex-cli\" },\n { title: \"opencode (configured OpenCode providers)\", value: \"opencode\" },\n { title: \"sdk (API key, programmatic)\", value: \"sdk\" },\n { title: \"orchestrator (any provider)\", value: \"orchestrator\" },\n ]},\n { type: \"text\", name: \"model\", message: \"Model\", initial: \"claude-sonnet-4-6\" },\n { type: \"list\", name: \"mentions\", message: \"Mention patterns (comma-separated)\", separator: \",\" },\n { type: \"number\", name: \"maxConcurrent\", message: \"Max concurrent tasks\", initial: 2 },\n { type: \"text\", name: \"systemPrompt\", message: \"System prompt\" },\n ])\n\n if (!answers.id) return\n\n // Create workspace + .claude dir\n const ws = answers.workspace.endsWith(answers.id) ? answers.workspace : join(answers.workspace, answers.id)\n mkdirSync(resolve(ws, \".claude/skills\"), { recursive: true })\n\n const agentDef = {\n name: answers.name,\n workspace: ws,\n tier: answers.tier,\n model: answers.model,\n mentions: answers.mentions?.map((m: string) => m.trim()).filter(Boolean) || [],\n maxConcurrent: answers.maxConcurrent,\n systemPrompt: answers.systemPrompt,\n permissionMode: \"default\",\n }\n\n // Set up workspace with Claude Code best practices\n // (CLAUDE.md, AGENTS.md, .claude/settings.json, .claude/rules/)\n const { setupWorkspace } = await import(\"@/agents/workspace-setup\")\n const setup = setupWorkspace(answers.id, agentDef as any, \"19900\", (...args: unknown[]) => {\n console.log(chalk.dim(` ${args.join(\" \")}`))\n })\n\n // Install wiki skill\n const wikiSkillSrc = resolve(process.cwd(), \"src/wiki/SKILL.md\")\n const wikiSkillDist = resolve(dirname(fileURLToPath(import.meta.url)), \"../wiki/SKILL.md\")\n const skillSrc = existsSync(wikiSkillSrc) ? wikiSkillSrc : wikiSkillDist\n if (existsSync(skillSrc)) {\n mkdirSync(resolve(ws, \".claude/skills/wiki\"), { recursive: true })\n cpSync(skillSrc, resolve(ws, \".claude/skills/wiki/SKILL.md\"))\n }\n\n // Add to config\n config.agents = config.agents || {}\n config.agents[answers.id] = agentDef\n\n await saveConfig(config)\n console.log(chalk.green(`\\n Agent \"${answers.id}\" added`))\n console.log(chalk.dim(` Workspace: ${ws}`))\n console.log(chalk.dim(` Created: ${setup.created.length} files (CLAUDE.md, AGENTS.md, settings, rules)`))\n console.log()\n })\n\nagent\n .command(\"remove <id>\")\n .alias(\"rm\")\n .description(\"remove an agent from config (keeps workspace)\")\n .action(async (id) => {\n const config = loadConfig()\n if (!config.agents?.[id]) {\n console.log(chalk.red(` Agent \"${id}\" not found`))\n return\n }\n delete config.agents[id]\n await saveConfig(config)\n console.log(chalk.green(` Agent \"${id}\" removed from config (workspace preserved)`))\n })\n\n// agentx agent capability — set intents / maxDelegationDepth / contextReferences /\n// contextStrategy without hand-editing agentx.json. These are the Phase 5/8 fields\n// the second-pass parity audit flagged as CLI-only-via-JSON.\nagent\n .command(\"capability <id>\")\n .alias(\"caps\")\n .description(\"set agent capability flags (intents, maxDelegationDepth, contextReferences, contextStrategy)\")\n .option(\"--intents <csv>\", \"comma-separated intent allow-list (set to '-' to clear)\")\n .option(\"--max-delegation-depth <n>\", \"max distinct upstream agents on the same subject before refusal (0 disables)\")\n .option(\"--context-references <bool>\", \"render the deterministic [Verified References] block (true|false)\")\n .option(\"--context-strategy <name>\", \"per-agent override: layered | planner\")\n .option(\"--max-execution-minutes <n>\", \"wall-clock cap on a single Claude Code call (1–240)\")\n .option(\"--show\", \"just print the current capability fields\")\n .action(async (id: string, opts) => {\n const config = loadConfig()\n const a = config.agents?.[id]\n if (!a) { console.log(chalk.red(` Agent \"${id}\" not found`)); process.exit(1) }\n if (opts.show) {\n console.log()\n console.log(chalk.bold(` ${id}`))\n console.log(` intents ${(a.intents && a.intents.length) ? (a.intents as string[]).join(\", \") : chalk.dim(\"(any)\")}`)\n console.log(` maxDelegationDepth ${a.maxDelegationDepth ?? 5}`)\n console.log(` contextReferences ${a.contextReferences ? \"on\" : chalk.dim(\"off\")}`)\n console.log(` contextStrategy ${a.contextStrategy || chalk.dim(\"(global default)\")}`)\n console.log(` maxExecutionMinutes ${a.maxExecutionMinutes ?? 20}`)\n console.log()\n return\n }\n const changes: string[] = []\n if (opts.intents !== undefined) {\n if (opts.intents === \"-\" || opts.intents === \"\") {\n a.intents = []\n changes.push(\"intents cleared (permissive)\")\n } else {\n a.intents = String(opts.intents).split(\",\").map((s) => s.trim()).filter(Boolean)\n changes.push(`intents=[${a.intents.join(\", \")}]`)\n }\n }\n if (opts.maxDelegationDepth !== undefined) {\n const n = parseInt(opts.maxDelegationDepth, 10)\n if (!Number.isFinite(n) || n < 0 || n > 50) { console.log(chalk.red(\" --max-delegation-depth must be 0..50\")); process.exit(1) }\n a.maxDelegationDepth = n\n changes.push(`maxDelegationDepth=${n}`)\n }\n if (opts.contextReferences !== undefined) {\n const v = String(opts.contextReferences).toLowerCase()\n if (![\"true\", \"false\", \"on\", \"off\", \"1\", \"0\"].includes(v)) { console.log(chalk.red(\" --context-references must be true|false\")); process.exit(1) }\n a.contextReferences = v === \"true\" || v === \"on\" || v === \"1\"\n changes.push(`contextReferences=${a.contextReferences}`)\n }\n if (opts.contextStrategy !== undefined) {\n if (opts.contextStrategy === \"-\" || opts.contextStrategy === \"\") {\n delete (a as any).contextStrategy\n changes.push(\"contextStrategy cleared (uses global default)\")\n } else if (![\"layered\", \"planner\"].includes(opts.contextStrategy)) {\n console.log(chalk.red(\" --context-strategy must be layered|planner (or '-' to clear)\"))\n process.exit(1)\n } else {\n a.contextStrategy = opts.contextStrategy\n changes.push(`contextStrategy=${opts.contextStrategy}`)\n }\n }\n if (opts.maxExecutionMinutes !== undefined) {\n const n = parseInt(opts.maxExecutionMinutes, 10)\n if (!Number.isFinite(n) || n < 1 || n > 240) { console.log(chalk.red(\" --max-execution-minutes must be 1..240\")); process.exit(1) }\n a.maxExecutionMinutes = n\n changes.push(`maxExecutionMinutes=${n}`)\n }\n if (changes.length === 0) { console.log(chalk.yellow(\" no changes — pass at least one flag, or use --show\")); process.exit(1) }\n await saveConfig(config)\n console.log(chalk.green(` ✓ ${id}: ${changes.join(\", \")}`))\n console.log(chalk.dim(` Restart the daemon (or POST /reload) for the change to take effect.`))\n })\n\n// ==================== agentx agent integrations ====================\n//\n// Per-agent third-party integration registry. Declarations live in\n// agentx.json's agents[].integrations[]; secrets live in env vars / keyring.\n\nconst integrations = new Command()\n .name(\"integrations\")\n .alias(\"integ\")\n .description(\"manage per-agent third-party credentials (telegram-bot, hubspot, gitlab-user, gmail, etc.)\")\n\nintegrations\n .command(\"list <agentId>\")\n .alias(\"ls\")\n .description(\"list integrations declared on an agent\")\n .option(\"--json\", \"emit JSON\")\n .action(async (agentId: string, opts) => {\n const cfg = loadConfig()\n const a = cfg.agents?.[agentId]\n if (!a) { console.log(chalk.red(` Agent \"${agentId}\" not found`)); process.exit(1) }\n const list = (a.integrations as any[] | undefined) ?? []\n if (opts.json) { console.log(JSON.stringify(list, null, 2)); return }\n if (!list.length) {\n console.log(chalk.dim(`\\n ${agentId}: no integrations declared. Add one with: agentx agent integrations add ${agentId}\\n`))\n return\n }\n console.log()\n console.log(chalk.bold(` ${agentId}`))\n for (const i of list) {\n const enabled = i.enabled !== false\n const statusBits: string[] = []\n const creds = i.credentials ?? {}\n for (const [k, v] of Object.entries(creds)) {\n if (typeof v === \"string\" && /^[A-Z][A-Z0-9_]*$/.test(v)) {\n statusBits.push(process.env[v] ? chalk.green(`${k}:${v}=set`) : chalk.yellow(`${k}:${v}=UNSET`))\n } else if (k === \"auth\" && v === \"keyring\") {\n statusBits.push(chalk.dim(\"auth:keyring\"))\n } else if (k === \"sessionDir\" && typeof v === \"string\") {\n statusBits.push(chalk.dim(`sessionDir:${v}`))\n }\n }\n const meta = Object.entries(i.metadata ?? {})\n .map(([k, v]) => `${k}=${v}`)\n .join(\" \")\n console.log(` ${enabled ? chalk.cyan(i.kind.padEnd(14)) : chalk.dim(i.kind.padEnd(14))} ${chalk.bold(i.label)}`)\n if (statusBits.length) console.log(` ${statusBits.join(\" \")}`)\n if (meta) console.log(` ${chalk.dim(meta)}`)\n if (!enabled) console.log(` ${chalk.dim(\"(disabled)\")}`)\n }\n console.log()\n })\n\nintegrations\n .command(\"add <agentId>\")\n .description(\"declare a new integration on an agent\")\n .option(\"--kind <name>\", \"service kind (e.g. telegram-bot, hubspot, gitlab-user, gmail)\")\n .option(\"--label <text>\", \"human-readable label (must be unique within (agent, kind))\")\n .option(\"--token-env <name>\", \"env-var holding the secret (uppercase identifier)\")\n .option(\"--auth <mode>\", \"alternative to --token-env: 'keyring' for OS keyring\")\n .option(\"--session-dir <path>\", \"for whatsapp / mtproto: file-based session directory\")\n .option(\"--metadata <kvList>\", \"comma-separated key=value pairs (e.g. 'username=anis,email=anis@noqta.tn')\")\n .option(\"--no-prompt\", \"fail instead of prompting for missing values\")\n .action(async (agentId: string, opts) => {\n const cfg = loadConfig()\n if (!cfg.agents?.[agentId]) { console.log(chalk.red(` Agent \"${agentId}\" not found`)); process.exit(1) }\n const interactive = opts.prompt !== false\n\n const { INTEGRATION_KINDS } = await import(\"@/daemon/config\")\n let kind = String(opts.kind || \"\").trim()\n if (!kind && interactive) {\n const r = await prompts({\n type: \"autocomplete\",\n name: \"kind\",\n message: \"Service kind\",\n choices: (INTEGRATION_KINDS as readonly string[]).map((k) => ({ title: k, value: k })),\n })\n kind = (r.kind || \"\").trim()\n }\n if (!kind) { console.log(chalk.red(\" --kind is required\")); process.exit(1) }\n\n let label = String(opts.label || \"\").trim()\n if (!label && interactive) {\n const r = await prompts({\n type: \"text\",\n name: \"label\",\n message: `Label (e.g. \"@cx_bot\", \"Noqta CRM\", \"anis@noqta.tn\")`,\n })\n label = (r.label || \"\").trim()\n }\n if (!label) { console.log(chalk.red(\" --label is required\")); process.exit(1) }\n\n let tokenEnv = String(opts.tokenEnv || \"\").trim()\n let auth = String(opts.auth || \"\").trim()\n let sessionDir = String(opts.sessionDir || \"\").trim()\n if (!tokenEnv && !auth && !sessionDir && interactive) {\n const r = await prompts({\n type: \"select\",\n name: \"scheme\",\n message: \"Credential scheme\",\n choices: [\n { title: \"Env var (e.g. HUBSPOT_TOKEN_CX)\", value: \"tokenEnv\" },\n { title: \"OS keyring\", value: \"keyring\" },\n { title: \"File-based session (whatsapp / mtproto)\", value: \"sessionDir\" },\n ],\n })\n if (r.scheme === \"tokenEnv\") {\n const t = await prompts({\n type: \"text\",\n name: \"tokenEnv\",\n message: \"Env var name (uppercase)\",\n initial: `${kind.replace(/-/g, \"_\").toUpperCase()}_${agentId.replace(/-/g, \"_\").toUpperCase()}`,\n })\n tokenEnv = (t.tokenEnv || \"\").trim()\n } else if (r.scheme === \"keyring\") {\n auth = \"keyring\"\n } else if (r.scheme === \"sessionDir\") {\n const s = await prompts({\n type: \"text\",\n name: \"sessionDir\",\n message: \"Session directory path\",\n initial: `.agentx/${kind}-sessions/${agentId}`,\n })\n sessionDir = (s.sessionDir || \"\").trim()\n }\n }\n\n let metadata: Record<string, string | number | boolean> = {}\n if (opts.metadata) {\n for (const pair of String(opts.metadata).split(\",\")) {\n const [k, ...rest] = pair.split(\"=\")\n if (!k) continue\n metadata[k.trim()] = rest.join(\"=\").trim()\n }\n } else if (interactive) {\n const r = await prompts({\n type: \"text\",\n name: \"metadata\",\n message: \"Metadata (k=v,k=v) — non-secret only, optional\",\n })\n if (r.metadata) {\n for (const pair of String(r.metadata).split(\",\")) {\n const [k, ...rest] = pair.split(\"=\")\n if (!k) continue\n metadata[k.trim()] = rest.join(\"=\").trim()\n }\n }\n }\n\n const credentials: Record<string, string> = {}\n if (tokenEnv) {\n if (!/^[A-Z][A-Z0-9_]*$/.test(tokenEnv)) {\n console.log(chalk.red(` --token-env must be uppercase identifier (got \"${tokenEnv}\")`)); process.exit(1)\n }\n credentials.tokenEnv = tokenEnv\n }\n if (auth === \"keyring\") credentials.auth = \"keyring\"\n if (sessionDir) credentials.sessionDir = sessionDir\n if (!Object.keys(credentials).length) { console.log(chalk.red(\" one of --token-env / --auth / --session-dir is required\")); process.exit(1) }\n\n cfg.agents[agentId].integrations = (cfg.agents[agentId].integrations as any[] | undefined) ?? []\n if (cfg.agents[agentId].integrations.find((i: any) => i.kind === kind && i.label === label)) {\n console.log(chalk.red(` Integration (${kind}, ${label}) already exists on ${agentId}`)); process.exit(1)\n }\n cfg.agents[agentId].integrations.push({ kind, label, credentials, metadata, enabled: true })\n await saveConfig(cfg)\n console.log(chalk.green(` ✓ ${agentId}: added ${kind} integration \"${label}\"`))\n if (tokenEnv && !process.env[tokenEnv]) {\n console.log(chalk.yellow(` ⚠ env var ${tokenEnv} is not set — set it on the daemon environment before use`))\n }\n })\n\nintegrations\n .command(\"remove <agentId> <kindOrLabel>\")\n .alias(\"rm\")\n .description(\"remove an integration (matched by kind, label, or 'kind:label')\")\n .action(async (agentId: string, target: string) => {\n const cfg = loadConfig()\n const a = cfg.agents?.[agentId]\n if (!a) { console.log(chalk.red(` Agent \"${agentId}\" not found`)); process.exit(1) }\n const list = (a.integrations as any[] | undefined) ?? []\n const [tk, tl] = target.includes(\":\") ? target.split(\":\", 2) : [target, \"\"]\n const idx = list.findIndex((i: any) => (i.kind === tk && (!tl || i.label === tl)) || i.label === target)\n if (idx === -1) { console.log(chalk.red(` No integration matched \"${target}\"`)); process.exit(1) }\n const removed = list.splice(idx, 1)[0]\n await saveConfig(cfg)\n console.log(chalk.green(` ✓ removed ${removed.kind} integration \"${removed.label}\" from ${agentId}`))\n })\n\nintegrations\n .command(\"test <agentId> [kindOrLabel]\")\n .description(\"validate env vars are set for one or all integrations on an agent\")\n .action(async (agentId: string, target?: string) => {\n const cfg = loadConfig()\n const a = cfg.agents?.[agentId]\n if (!a) { console.log(chalk.red(` Agent \"${agentId}\" not found`)); process.exit(1) }\n const list = (a.integrations as any[] | undefined) ?? []\n const filtered = target\n ? list.filter((i: any) => i.kind === target || i.label === target || `${i.kind}:${i.label}` === target)\n : list\n if (!filtered.length) { console.log(chalk.yellow(\" no integrations to test\")); return }\n let bad = 0\n console.log()\n for (const i of filtered) {\n const creds = i.credentials ?? {}\n const issues: string[] = []\n for (const [k, v] of Object.entries(creds)) {\n if (typeof v === \"string\" && /^[A-Z][A-Z0-9_]*$/.test(v) && !process.env[v]) {\n issues.push(`${k}: env var ${v} is unset`)\n }\n }\n if (issues.length) {\n bad += 1\n console.log(` ${chalk.red(\"✗\")} ${i.kind} \"${i.label}\"`)\n for (const issue of issues) console.log(` ${chalk.dim(issue)}`)\n } else {\n console.log(` ${chalk.green(\"✓\")} ${i.kind} \"${i.label}\"`)\n }\n }\n console.log()\n if (bad > 0) process.exit(1)\n })\n\nagent.addCommand(integrations)\n\n// ==================== agentx channel ====================\n\nexport const channel = new Command()\n .name(\"channel\")\n .description(\"manage channels — add telegram/whatsapp/discord, list\")\n\nchannel\n .command(\"list\")\n .alias(\"ls\")\n .description(\"list configured channels and bindings\")\n .action(() => {\n const config = loadConfig()\n console.log()\n\n // Telegram\n const tg = config.channels?.telegram\n if (tg?.enabled) {\n console.log(chalk.bold(\" Telegram:\"))\n for (const [name, acc] of Object.entries(tg.accounts || {}) as any) {\n console.log(` ${chalk.cyan(name)} -> agent: ${acc.agentBinding}`)\n }\n } else {\n console.log(chalk.dim(\" Telegram: disabled\"))\n }\n\n // WhatsApp\n const wa = config.channels?.whatsapp\n if (wa?.enabled) {\n console.log(chalk.bold(\" WhatsApp:\"))\n console.log(` default agent: ${wa.defaultAgent || \"(none)\"}`)\n console.log(` session: ${wa.sessionDir || \".agentx/whatsapp-sessions\"}`)\n for (const route of wa.routes || []) {\n const target = route.contact ? `contact ${route.contact}` : `group \"${route.group}\"`\n console.log(` ${target} -> agent: ${route.agent}`)\n }\n } else {\n console.log(chalk.dim(\" WhatsApp: disabled\"))\n }\n\n // Discord\n const dc = config.channels?.discord\n if (dc?.enabled) {\n console.log(chalk.bold(\" Discord:\"))\n console.log(` agent: ${dc.agentBinding || \"(none)\"}`)\n } else {\n console.log(chalk.dim(\" Discord: disabled\"))\n }\n\n // GitLab\n const gl = config.channels?.gitlab\n if (gl?.enabled) {\n console.log(chalk.bold(\" GitLab:\"))\n console.log(` host: ${gl.host}`)\n console.log(` webhook: :${gl.webhookPort}`)\n for (const route of gl.routes || []) {\n console.log(` ${route.project} -> agent: ${route.agent}`)\n }\n } else {\n console.log(chalk.dim(\" GitLab: disabled\"))\n }\n\n console.log()\n })\n\nchannel\n .command(\"add\")\n .description(\"add a channel (telegram, whatsapp, or discord)\")\n .action(async () => {\n const config = loadConfig()\n const agentIds = Object.keys(config.agents || {})\n if (!agentIds.length) {\n console.log(chalk.red(\" No agents configured. Run: agentx agent add\"))\n return\n }\n\n const agentChoices = agentIds.map(id => ({ title: `${id} (${config.agents[id].name})`, value: id }))\n\n const { channelType } = await prompts({\n type: \"select\",\n name: \"channelType\",\n message: \"Channel type\",\n choices: [\n { title: \"Telegram — bot via BotFather token\", value: \"telegram\" },\n { title: \"WhatsApp — link via QR code (self-chat or contacts)\", value: \"whatsapp\" },\n { title: \"Discord — bot via Discord developer portal\", value: \"discord\" },\n { title: \"GitLab — webhook for issues, MRs, comments, pipelines\", value: \"gitlab\" },\n ],\n })\n\n if (!channelType) return\n\n config.channels = config.channels || {}\n\n // --- Telegram ---\n if (channelType === \"telegram\") {\n const answers = await prompts([\n { type: \"text\", name: \"accountName\", message: \"Account name (e.g. 'default', 'devops')\" },\n { type: \"text\", name: \"token\", message: \"Bot token (from @BotFather)\" },\n { type: \"select\", name: \"agentBinding\", message: \"Bind to agent\", choices: agentChoices },\n ])\n\n if (!answers.accountName || !answers.token) return\n\n try {\n const res = await fetch(`https://api.telegram.org/bot${answers.token}/getMe`)\n const data = await res.json() as any\n if (!data.ok) throw new Error(data.description)\n console.log(chalk.green(` Bot verified: @${data.result.username}`))\n\n const botHandle = `@${data.result.username}`\n const agentMentions = config.agents[answers.agentBinding].mentions || []\n if (!agentMentions.includes(botHandle)) {\n agentMentions.push(botHandle, data.result.username)\n config.agents[answers.agentBinding].mentions = agentMentions\n }\n } catch (e: any) {\n console.log(chalk.red(` Invalid token: ${e.message}`))\n return\n }\n\n config.channels.telegram = config.channels.telegram || { enabled: false, accounts: {}, policy: { dm: \"pair\", group: \"mention-required\" } }\n config.channels.telegram.enabled = true\n config.channels.telegram.accounts[answers.accountName] = {\n token: answers.token,\n agentBinding: answers.agentBinding,\n }\n\n await saveConfig(config)\n console.log(chalk.green(` Telegram \"${answers.accountName}\" added -> ${answers.agentBinding}`))\n }\n\n // --- WhatsApp ---\n if (channelType === \"whatsapp\") {\n const answers = await prompts([\n { type: \"select\", name: \"defaultAgent\", message: \"Default agent for WhatsApp messages\", choices: agentChoices },\n { type: \"text\", name: \"sessionDir\", message: \"Session directory\", initial: \".agentx/whatsapp-sessions\" },\n { type: \"confirm\", name: \"addRoute\", message: \"Add a contact/group route?\", initial: true },\n ])\n\n if (!answers.defaultAgent) return\n\n const routes: any[] = []\n let addMore = answers.addRoute\n\n while (addMore) {\n const route = await prompts([\n { type: \"select\", name: \"type\", message: \"Route type\", choices: [\n { title: \"Contact (phone number)\", value: \"contact\" },\n { title: \"Group (name match)\", value: \"group\" },\n ]},\n { type: \"text\", name: \"value\", message: (prev: string) => prev === \"contact\" ? \"Phone number (e.g. +21624309128)\" : \"Group name (partial match)\" },\n { type: \"select\", name: \"agent\", message: \"Route to agent\", choices: agentChoices },\n { type: \"confirm\", name: \"more\", message: \"Add another route?\", initial: false },\n ])\n\n if (route.value && route.agent) {\n routes.push({\n [route.type]: route.value,\n agent: route.agent,\n })\n }\n addMore = route.more\n }\n\n config.channels.whatsapp = {\n enabled: true,\n sessionDir: answers.sessionDir,\n defaultAgent: answers.defaultAgent,\n routes,\n }\n\n await saveConfig(config)\n mkdirSync(resolve(process.cwd(), answers.sessionDir), { recursive: true })\n console.log(chalk.green(` WhatsApp enabled (${routes.length} routes, default: ${answers.defaultAgent})`))\n console.log(chalk.dim(\" Start daemon to scan QR code: agentx daemon start\"))\n }\n\n // --- Discord ---\n if (channelType === \"discord\") {\n const answers = await prompts([\n { type: \"text\", name: \"token\", message: \"Discord bot token (from developer portal)\" },\n { type: \"select\", name: \"agentBinding\", message: \"Bind to agent\", choices: agentChoices },\n ])\n\n if (!answers.token) return\n\n config.channels.discord = {\n enabled: true,\n token: answers.token,\n agentBinding: answers.agentBinding,\n }\n\n await saveConfig(config)\n console.log(chalk.green(` Discord added -> ${answers.agentBinding}`))\n }\n\n // --- GitLab ---\n if (channelType === \"gitlab\") {\n const answers = await prompts([\n { type: \"text\", name: \"host\", message: \"GitLab instance URL\", initial: \"https://gitlab.example.com\" },\n { type: \"text\", name: \"token\", message: \"GitLab API token (PRIVATE-TOKEN)\" },\n { type: \"number\", name: \"webhookPort\", message: \"Webhook listen port\", initial: 18810 },\n { type: \"text\", name: \"webhookSecret\", message: \"Webhook secret (X-Gitlab-Token, optional)\" },\n { type: \"confirm\", name: \"addRoute\", message: \"Add a project route?\", initial: true },\n ])\n\n if (!answers.token) return\n\n const routes: any[] = []\n let addMore = answers.addRoute\n\n while (addMore) {\n const route = await prompts([\n { type: \"text\", name: \"project\", message: \"GitLab project path (e.g. group/project, or * for default)\" },\n { type: \"select\", name: \"agent\", message: \"Route to agent\", choices: agentChoices },\n { type: \"confirm\", name: \"more\", message: \"Add another route?\", initial: false },\n ])\n\n if (route.project && route.agent) {\n routes.push({ project: route.project, agent: route.agent })\n }\n addMore = route.more\n }\n\n config.channels.gitlab = {\n enabled: true,\n host: answers.host,\n token: answers.token,\n webhookPort: answers.webhookPort,\n webhookSecret: answers.webhookSecret || undefined,\n routes,\n }\n\n await saveConfig(config)\n console.log(chalk.green(` GitLab enabled (${routes.length} routes, webhook :${answers.webhookPort})`))\n console.log(chalk.dim(` Add webhook in GitLab: ${answers.host}/<project>/-/hooks`))\n console.log(chalk.dim(` URL: http://your-server:${answers.webhookPort}/`))\n if (answers.webhookSecret) {\n console.log(chalk.dim(` Secret token: ${answers.webhookSecret}`))\n }\n console.log(chalk.dim(\" Events: Comments, Issues, Merge requests, Pipeline\"))\n }\n\n console.log(chalk.dim(\" Restart daemon to apply: agentx daemon stop && agentx daemon start\"))\n console.log()\n })\n\n// ==================== agentx cron ====================\n\nexport const cron = new Command()\n .name(\"cron\")\n .description(\"manage cron jobs — add, list, enable, disable\")\n\ncron\n .command(\"list\")\n .alias(\"ls\")\n .description(\"list cron jobs\")\n .action(() => {\n const config = loadConfig()\n console.log()\n for (const [id, c] of Object.entries(config.crons || {}) as any) {\n const icon = c.enabled ? chalk.green(\"●\") : chalk.dim(\"○\")\n console.log(` ${icon} ${chalk.cyan(id)} — ${c.schedule} (${c.timezone})`)\n console.log(chalk.dim(` agent: ${c.agent} | timeout: ${c.timeout}s`))\n }\n if (!Object.keys(config.crons || {}).length) {\n console.log(chalk.dim(\" No cron jobs configured\"))\n }\n console.log()\n })\n\ncron\n .command(\"add\")\n .description(\"add a cron job\")\n .action(async () => {\n const config = loadConfig()\n const agentIds = Object.keys(config.agents || {})\n\n const answers = await prompts([\n { type: \"text\", name: \"id\", message: \"Job ID (kebab-case)\" },\n { type: \"text\", name: \"schedule\", message: \"Cron expression (e.g. '0 9 * * *')\" },\n { type: \"text\", name: \"timezone\", message: \"Timezone\", initial: \"UTC\" },\n { type: \"select\", name: \"agent\", message: \"Agent\", choices: agentIds.map(id => ({ title: id, value: id })) },\n { type: \"text\", name: \"prompt\", message: \"Task prompt\" },\n { type: \"number\", name: \"timeout\", message: \"Timeout (seconds)\", initial: 600 },\n { type: \"confirm\", name: \"enabled\", message: \"Enable now?\", initial: false },\n ])\n\n if (!answers.id || !answers.schedule) return\n\n config.crons = config.crons || {}\n config.crons[answers.id] = {\n enabled: answers.enabled,\n schedule: answers.schedule,\n timezone: answers.timezone,\n agent: answers.agent,\n prompt: answers.prompt,\n timeout: answers.timeout,\n onError: [\"log\"],\n }\n\n await saveConfig(config)\n console.log(chalk.green(` Cron \"${answers.id}\" added (${answers.enabled ? \"enabled\" : \"disabled\"})`))\n console.log()\n })\n\ncron\n .command(\"enable <id>\")\n .description(\"enable a cron job\")\n .action(async (id) => {\n const config = loadConfig()\n if (!config.crons?.[id]) { console.log(chalk.red(` Cron \"${id}\" not found`)); return }\n config.crons[id].enabled = true\n await saveConfig(config)\n console.log(chalk.green(` Cron \"${id}\" enabled`))\n })\n\ncron\n .command(\"disable <id>\")\n .description(\"disable a cron job\")\n .action(async (id) => {\n const config = loadConfig()\n if (!config.crons?.[id]) { console.log(chalk.red(` Cron \"${id}\" not found`)); return }\n config.crons[id].enabled = false\n await saveConfig(config)\n console.log(chalk.green(` Cron \"${id}\" disabled`))\n })\n\n// ==================== agentx mesh ====================\n\nexport const mesh = new Command()\n .name(\"mesh\")\n .description(\"manage mesh peers — add, list, remove\")\n\nmesh\n .command(\"list\")\n .alias(\"ls\")\n .description(\"list mesh peers\")\n .action(async () => {\n const config = loadConfig()\n console.log()\n if (!config.mesh?.enabled) {\n console.log(chalk.dim(\" Mesh: disabled\"))\n } else {\n console.log(chalk.bold(\" Mesh peers:\"))\n for (const peer of config.mesh.peers || []) {\n // Try health check\n let status = chalk.red(\"unreachable\")\n try {\n const res = await fetch(`${peer.url}/health`, { signal: AbortSignal.timeout(3000) })\n const data = await res.json() as any\n status = chalk.green(`healthy — ${data.agents?.length || 0} agents`)\n } catch {}\n console.log(` ${chalk.cyan(peer.name)} ${chalk.dim(peer.url)} ${status}`)\n }\n }\n console.log()\n })\n\nmesh\n .command(\"add\")\n .description(\"add a mesh peer (another agentx server)\")\n .action(async () => {\n const config = loadConfig()\n\n const answers = await prompts([\n { type: \"text\", name: \"name\", message: \"Peer name (e.g. 'server-2')\" },\n { type: \"text\", name: \"url\", message: \"Peer URL (e.g. 'http://100.67.108.119:18800')\" },\n { type: \"text\", name: \"token\", message: \"Auth token (optional, press enter to skip)\" },\n ])\n\n if (!answers.name || !answers.url) return\n\n // Verify connectivity\n try {\n const res = await fetch(`${answers.url}/.well-known/agent-card.json`, { signal: AbortSignal.timeout(5000) })\n const card = await res.json() as any\n console.log(chalk.green(` Connected: ${card.name} (${card.skills?.length || 0} agents)`))\n } catch {\n console.log(chalk.yellow(\" Could not reach peer (adding anyway)\"))\n }\n\n config.mesh = config.mesh || { enabled: false, peers: [], discovery: \"static\", healthCheck: { interval: 60, timeout: 10 } }\n config.mesh.enabled = true\n config.mesh.peers = config.mesh.peers || []\n config.mesh.peers.push({\n url: answers.url,\n name: answers.name,\n ...(answers.token ? { token: answers.token } : {}),\n })\n\n await saveConfig(config)\n console.log(chalk.green(` Peer \"${answers.name}\" added`))\n console.log()\n })\n\nmesh\n .command(\"remove <name>\")\n .alias(\"rm\")\n .description(\"remove a mesh peer\")\n .action(async (name) => {\n const config = loadConfig()\n if (!config.mesh?.peers) return\n config.mesh.peers = config.mesh.peers.filter((p: any) => p.name !== name)\n if (config.mesh.peers.length === 0) config.mesh.enabled = false\n await saveConfig(config)\n console.log(chalk.green(` Peer \"${name}\" removed`))\n })\n\n// agentx mesh health — tune the per-peer health-check cadence (heartbeat\n// interval + timeout). Intentionally narrow knob: lower interval if\n// you need fast peer-down detection, raise it on flaky / battery-\n// constrained mobile peers to reduce wake noise.\nmesh\n .command(\"health\")\n .description(\"tune mesh peer health checks (interval + timeout, in seconds)\")\n .option(\"--interval <s>\", \"seconds between health probes (default 60)\")\n .option(\"--timeout <s>\", \"per-probe timeout in seconds (default 10)\")\n .option(\"--show\", \"just print the current values\")\n .action(async (opts) => {\n const config = loadConfig() as any\n config.mesh = config.mesh || {}\n config.mesh.healthCheck = config.mesh.healthCheck || {}\n if (opts.show) {\n console.log(` interval ${config.mesh.healthCheck.interval ?? 60}s`)\n console.log(` timeout ${config.mesh.healthCheck.timeout ?? 10}s`)\n return\n }\n const changes: string[] = []\n if (opts.interval !== undefined) {\n const n = parseInt(opts.interval, 10)\n if (!Number.isFinite(n) || n < 5 || n > 3600) { console.log(chalk.red(\" --interval must be 5..3600 seconds\")); process.exit(1) }\n config.mesh.healthCheck.interval = n\n changes.push(`interval=${n}s`)\n }\n if (opts.timeout !== undefined) {\n const n = parseInt(opts.timeout, 10)\n if (!Number.isFinite(n) || n < 1 || n > 60) { console.log(chalk.red(\" --timeout must be 1..60 seconds\")); process.exit(1) }\n config.mesh.healthCheck.timeout = n\n changes.push(`timeout=${n}s`)\n }\n if (changes.length === 0) { console.log(chalk.yellow(\" no changes — pass --interval and/or --timeout, or --show\")); process.exit(1) }\n await saveConfig(config)\n console.log(chalk.green(` ✓ mesh.healthCheck: ${changes.join(\", \")}`))\n console.log(chalk.dim(\" Restart the daemon for the new cadence to take effect.\"))\n })\n\n// ==================== agentx skill ====================\n\nexport const skillCmd = new Command()\n .name(\"skill\")\n .description(\"manage skills — add to agent(s), list\")\n\nskillCmd\n .command(\"add <skillPath>\")\n .description(\"add a skill to agent(s)\")\n .option(\"-a, --agent <agents...>\", \"target agent ID(s)\")\n .option(\"--all\", \"add to all agents\")\n .action(async (skillPath, opts) => {\n const config = loadConfig()\n const srcPath = resolve(skillPath)\n\n if (!existsSync(srcPath)) {\n console.log(chalk.red(` Skill not found: ${srcPath}`))\n return\n }\n\n // Determine skill name\n const skillName = existsSync(join(srcPath, \"SKILL.md\"))\n ? srcPath.split(\"/\").pop()!\n : srcPath.replace(/\\/SKILL\\.md$/, \"\").split(\"/\").pop()!\n\n // Determine target agents\n let targets: string[]\n if (opts.all) {\n targets = Object.keys(config.agents || {})\n } else if (opts.agent) {\n targets = opts.agent\n } else {\n const agentIds = Object.keys(config.agents || {})\n const answer = await prompts({\n type: \"multiselect\",\n name: \"agents\",\n message: \"Install to which agents?\",\n choices: agentIds.map(id => ({ title: `${id} (${config.agents[id].name})`, value: id })),\n })\n targets = answer.agents || []\n }\n\n for (const agentId of targets) {\n const agent = config.agents[agentId]\n if (!agent) { console.log(chalk.yellow(` Agent \"${agentId}\" not found, skipping`)); continue }\n\n const destDir = resolve(agent.workspace, \".claude/skills\", skillName)\n mkdirSync(destDir, { recursive: true })\n\n if (existsSync(join(srcPath, \"SKILL.md\"))) {\n // Copy entire skill directory\n cpSync(srcPath, destDir, { recursive: true })\n } else if (srcPath.endsWith(\".md\")) {\n // Single SKILL.md file\n cpSync(srcPath, join(destDir, \"SKILL.md\"))\n }\n\n console.log(chalk.green(` ${skillName} -> ${agentId} (${agent.workspace})`))\n }\n console.log()\n })\n\nskillCmd\n .command(\"list\")\n .alias(\"ls\")\n .description(\"list skills per agent\")\n .action(() => {\n const config = loadConfig()\n console.log()\n for (const [id, a] of Object.entries(config.agents || {}) as any) {\n const skillsDir = resolve(a.workspace, \".claude/skills\")\n const skills = existsSync(skillsDir)\n ? readdirSync(skillsDir).filter((f: string) => !f.startsWith(\".\"))\n : []\n console.log(` ${chalk.cyan(id)}: ${skills.length ? skills.join(\", \") : chalk.dim(\"(none)\")}`)\n }\n console.log()\n })\n\n// --- skill sync ---\n// Redeploy a skill's SKILL.md from the source location to every agent\n// workspace in agentx.json. Prevents stale skill copies after the source\n// is updated — e.g. the wiki skill bumped from v3.0.0 → v3.1.0 in Phase 4\n// but deployed copies in 25 workspaces stayed on v3.0.0 until a manual\n// redeploy. Complements `skill add` (which copies one skill to selected\n// workspaces) with `skill sync` (which re-copies a skill to ALL workspaces\n// that already have it, or everyone if --all-workspaces).\nskillCmd\n .command(\"sync <name>\")\n .description(\"redeploy a skill's SKILL.md from source to agent workspaces (by default, only those that already have it)\")\n .option(\"--source <path>\", \"explicit source path (defaults to src/<name>/SKILL.md or skills/<name>/SKILL.md)\")\n .option(\"--agent <id>\", \"restrict to a single agent's workspace\")\n .option(\"--all-workspaces\", \"also seed into workspaces that don't have the skill yet\")\n .option(\"--dry-run\", \"report what would change, don't write\")\n .action(async (name, opts) => {\n const { createHash } = await import(\"node:crypto\")\n\n // Resolve source\n const cwd = process.cwd()\n const candidates = opts.source\n ? [opts.source]\n : [\n resolve(cwd, \"src\", name, \"SKILL.md\"),\n resolve(cwd, \"skills\", name, \"SKILL.md\"),\n ]\n const src = candidates.find(p => existsSync(p))\n if (!src) {\n console.log(chalk.red(` No SKILL.md found for \"${name}\". Searched:`))\n for (const c of candidates) console.log(chalk.dim(` ${c}`))\n return\n }\n const srcContent = readFileSync(src, \"utf-8\")\n const srcHash = createHash(\"sha256\").update(srcContent).digest(\"hex\").slice(0, 12)\n const srcVersion = (srcContent.match(/^version:\\s*(.+)$/m)?.[1] || \"?\").trim()\n\n let config\n try { config = loadDaemonConfig() } catch (e: any) {\n console.log(chalk.red(` Can't load agentx.json: ${e.message}`))\n return\n }\n\n const entries = Object.entries(config.agents || {}) as Array<[string, any]>\n const targets = opts.agent ? entries.filter(([id]) => id === opts.agent) : entries\n if (targets.length === 0) {\n console.log(chalk.yellow(opts.agent ? ` Agent \"${opts.agent}\" not in config.` : \" No agents in config.\"))\n return\n }\n\n console.log()\n console.log(chalk.bold(` Skill sync — ${name}`))\n console.log(chalk.dim(` Source: ${src}`))\n console.log(chalk.dim(` Version: ${srcVersion} · hash ${srcHash}`))\n console.log(chalk.dim(` Mode: ${opts.dryRun ? \"dry-run\" : \"commit\"}${opts.allWorkspaces ? \" · seed missing\" : \" · only-existing\"}`))\n console.log()\n\n let newN = 0, updatedN = 0, unchangedN = 0, skippedN = 0\n for (const [agentId, def] of targets) {\n const ws = def.workspace as string\n if (!ws || !existsSync(ws)) {\n console.log(` ${chalk.yellow(\"✗\")} ${agentId.padEnd(22)} ${chalk.dim(\"(workspace missing: \" + (ws || \"undefined\") + \")\")}`)\n skippedN++\n continue\n }\n const dstDir = resolve(ws, \".claude/skills\", name)\n const dst = resolve(dstDir, \"SKILL.md\")\n\n if (!existsSync(dst)) {\n if (!opts.allWorkspaces) {\n console.log(` ${chalk.dim(\"·\")} ${agentId.padEnd(22)} ${chalk.dim(\"(skipped — no existing copy; use --all-workspaces to seed)\")}`)\n skippedN++\n continue\n }\n if (!opts.dryRun) {\n mkdirSync(dstDir, { recursive: true })\n writeFileSync(dst, srcContent)\n }\n console.log(` ${chalk.green(\"+\")} ${agentId.padEnd(22)} ${chalk.dim(\"→ seeded v\" + srcVersion)}`)\n newN++\n continue\n }\n\n const dstContent = readFileSync(dst, \"utf-8\")\n const dstHash = createHash(\"sha256\").update(dstContent).digest(\"hex\").slice(0, 12)\n if (dstHash === srcHash) {\n console.log(` ${chalk.dim(\"=\")} ${agentId.padEnd(22)} ${chalk.dim(\"up to date (v\" + srcVersion + \")\")}`)\n unchangedN++\n continue\n }\n\n const dstVersion = (dstContent.match(/^version:\\s*(.+)$/m)?.[1] || \"?\").trim()\n if (!opts.dryRun) writeFileSync(dst, srcContent)\n console.log(` ${chalk.yellow(\"↻\")} ${agentId.padEnd(22)} ${chalk.dim(`v${dstVersion} → v${srcVersion}`)}`)\n updatedN++\n }\n\n console.log()\n const verb = opts.dryRun ? \"would\" : \"did\"\n console.log(chalk.dim(` Summary: ${verb} seed ${newN}, ${verb} update ${updatedN}, ${unchangedN} already current, ${skippedN} skipped.`))\n if (opts.dryRun && (newN > 0 || updatedN > 0)) {\n console.log(chalk.dim(\" Dry-run — rerun without --dry-run to write.\"))\n }\n console.log()\n })\n\n// --- skill audit ---\n// Lint every skill against the references registry: unresolved IDs, missing\n// delegate skills, raw infrastructure facts that should be cited from\n// references. Exits non-zero on any FAILING — wire it into CI.\nskillCmd\n .command(\"audit\")\n .description(\"lint installed skills against the references registry; exits non-zero on FAILING\")\n .option(\"--cwd <cwd>\", \"where to load skills from\", process.cwd())\n .option(\n \"--references-cwd <cwd>\",\n \"where to load references and recipes from (defaults to --cwd; useful when references live in the agentx repo and skills live under ~/.claude)\",\n )\n .option(\"--json\", \"emit JSON instead of a human report\")\n .option(\"--workspace <id>\", \"audit a single agent workspace by id (skills + references; overrides --cwd)\")\n .option(\n \"--all-workspaces\",\n \"audit every agent workspace in agentx.json; references default to the current cwd\",\n )\n .action(async (opts) => {\n const { loadLocalSkills } = await import(\"@/agent/skills/loader\")\n const { auditAll } = await import(\"@/agent/skills/audit\")\n const { loadReferences } = await import(\"@/agents/references/loader\")\n const { loadRecipes } = await import(\"@/agents/references/recipes\")\n\n const skillsRoots: string[] = []\n if (opts.workspace) {\n const config = loadConfig()\n const agent = config.agents?.[opts.workspace]\n if (!agent) {\n console.log(chalk.red(` Agent \"${opts.workspace}\" not found in agentx.json`))\n process.exit(1)\n }\n skillsRoots.push(resolve(agent.workspace))\n } else if (opts.allWorkspaces) {\n const config = loadConfig()\n for (const agent of Object.values(config.agents || {}) as any[]) {\n if (agent?.workspace) skillsRoots.push(resolve(agent.workspace))\n }\n } else {\n skillsRoots.push(resolve(opts.cwd))\n }\n const refsRoot = resolve(opts.referencesCwd || opts.cwd)\n\n const skillBatches = await Promise.all(skillsRoots.map(r => loadLocalSkills(r)))\n const skills = skillBatches.flat()\n const [references, recipes] = await Promise.all([\n loadReferences(refsRoot),\n loadRecipes(refsRoot),\n ])\n const results = auditAll({ skills, references, recipes })\n\n if (opts.json) {\n console.log(\n JSON.stringify(\n results.map(r => ({\n name: r.name,\n verdict: r.verdict,\n reasons: r.reasons,\n path: r.skill?.path,\n })),\n null,\n 2,\n ),\n )\n } else {\n const summary = { PASS: 0, REVIEW: 0, FAILING: 0 }\n for (const r of results) summary[r.verdict]++\n console.log()\n for (const r of results) {\n const tag =\n r.verdict === \"PASS\"\n ? chalk.green(\"PASS \")\n : r.verdict === \"REVIEW\"\n ? chalk.yellow(\"REVIEW \")\n : chalk.red(\"FAILING\")\n console.log(` ${tag} ${chalk.bold(r.name)}${r.skill?.path ? chalk.dim(` (${r.skill.path})`) : \"\"}`)\n for (const reason of r.reasons) console.log(` ${chalk.dim(\"·\")} ${reason}`)\n }\n console.log()\n console.log(\n ` ${chalk.green(`${summary.PASS} PASS`)} ${chalk.yellow(`${summary.REVIEW} REVIEW`)} ${chalk.red(`${summary.FAILING} FAILING`)}`,\n )\n console.log()\n }\n\n process.exit(results.some(r => r.verdict === \"FAILING\") ? 1 : 0)\n })\n\n// ==================== agentx references ====================\n//\n// Operator-private fact registry. Generic to any project — Noqta runs KSI in\n// .agentx/references/ksi/, the next operator runs their own clients the same\n// way. The engine ships only the schema + a generic example template.\n\nexport const references = new Command()\n .name(\"references\")\n .alias(\"refs\")\n .description(\"manage the deterministic references registry — facts cited by skills and resolved into agent context\")\n\nreferences\n .command(\"init <namespace>\")\n .description(\"scaffold .agentx/references/<namespace>/ from the example template (operator-private)\")\n .option(\"--cwd <cwd>\", \"working directory\", process.cwd())\n .option(\"--force\", \"overwrite existing files\")\n .action((namespace: string, opts) => {\n if (!/^[a-z0-9][a-z0-9-]*$/.test(namespace)) {\n console.log(chalk.red(` Invalid namespace \"${namespace}\". Use lowercase letters, digits, and hyphens.`))\n process.exit(1)\n }\n const cwd = resolve(opts.cwd)\n const exampleRoot = resolve(cwd, \"references/example\")\n const exampleRecipe = resolve(cwd, \"references/recipes/example.yaml\")\n if (!existsSync(exampleRoot)) {\n console.log(chalk.red(` Example template not found at ${exampleRoot}. Are you running this from the agentx repo root?`))\n process.exit(1)\n }\n const targetRoot = resolve(cwd, \".agentx/references\", namespace)\n const targetRecipes = resolve(cwd, \".agentx/references/recipes\")\n mkdirSync(targetRoot, { recursive: true })\n mkdirSync(targetRecipes, { recursive: true })\n\n const exampleFiles = readdirSync(exampleRoot).filter(f => f.endsWith(\".yaml\") || f.endsWith(\".yml\"))\n let copied = 0\n let skipped = 0\n for (const file of exampleFiles) {\n const dest = join(targetRoot, file)\n if (existsSync(dest) && !opts.force) {\n console.log(chalk.dim(` skip ${dest} (exists; --force to overwrite)`))\n skipped++\n continue\n }\n // Re-namespace: replace `namespace: example.<x>` with `namespace: <ns>.<x>`\n const src = readFileSync(join(exampleRoot, file), \"utf-8\")\n const rewritten = src.replace(/^namespace:\\s*example\\./m, `namespace: ${namespace}.`)\n writeFileSync(dest, rewritten)\n console.log(chalk.green(` + ${dest}`))\n copied++\n }\n const recipeDest = join(targetRecipes, `${namespace}.yaml`)\n if (existsSync(recipeDest) && !opts.force) {\n console.log(chalk.dim(` skip ${recipeDest} (exists; --force to overwrite)`))\n skipped++\n } else if (existsSync(exampleRecipe)) {\n const src = readFileSync(exampleRecipe, \"utf-8\").replaceAll(\"example.\", `${namespace}.`)\n writeFileSync(recipeDest, src)\n console.log(chalk.green(` + ${recipeDest}`))\n copied++\n }\n console.log()\n console.log(chalk.dim(` ${copied} written, ${skipped} skipped. Edit the placeholders, then:`))\n console.log(chalk.dim(` 1. set contextReferences: true on the relevant agents in agentx.json`))\n console.log(chalk.dim(` 2. agentx skill audit # verify references resolve`))\n console.log(chalk.dim(` 3. systemctl restart agentx # pick up the new registry`))\n console.log()\n })\n\nreferences\n .command(\"discover <namespace>\")\n .description(\"scan installed skills and write detected facts to .agentx/references/<namespace>/\")\n .option(\"--cwd <cwd>\", \"where to scan for skills\", process.cwd())\n .option(\"--references-cwd <cwd>\", \"where to WRITE the YAML files (defaults to --cwd; useful when skills live under ~/.claude and references live in the agentx repo)\")\n .option(\"--from <skills>\", \"comma-separated skill name/tag substrings to filter by (default: namespace itself)\")\n .option(\"--gitlab-host <url>\", \"validate project URLs against this host (e.g. https://gitlab.noqta.tn)\")\n .option(\"--write\", \"write the YAML files (default: dry-run preview)\")\n .option(\"--force\", \"overwrite existing files when --write is set\")\n .action(async (namespace: string, opts) => {\n if (!/^[a-z0-9][a-z0-9-]*$/.test(namespace)) {\n console.log(chalk.red(` Invalid namespace \"${namespace}\". Use lowercase letters, digits, and hyphens.`))\n process.exit(1)\n }\n const { loadLocalSkills } = await import(\"@/agent/skills/loader\")\n const { discoverFromSkills, renderDiscovery } = await import(\"@/agents/references/discover\")\n const cwd = resolve(opts.cwd)\n const filter = (opts.from\n ? String(opts.from)\n .split(\",\")\n .map((s: string) => s.trim())\n .filter(Boolean)\n : [namespace])\n const skills = await loadLocalSkills(cwd)\n const result = discoverFromSkills(skills, {\n namespace,\n filter,\n gitlabHost: opts.gitlabHost,\n })\n\n console.log()\n if (result.scannedSkills.length === 0) {\n console.log(chalk.yellow(` No skills matched filter [${filter.join(\", \")}] under ${cwd}`))\n console.log(chalk.dim(\" Tip: pass --from <skill-name>,<other> to widen the filter.\"))\n console.log()\n return\n }\n console.log(chalk.dim(` Scanned skills: ${result.scannedSkills.join(\", \")}`))\n const counts = Object.fromEntries(\n Object.entries(result.byKind).map(([k, v]) => [k, v.length]),\n )\n console.log(` Discovered: ssh=${counts.ssh} gitlab=${counts.gitlab} paths=${counts.path} contacts=${counts.contact}`)\n\n const files = renderDiscovery(result, namespace)\n const writeRoot = resolve(opts.referencesCwd || opts.cwd)\n const targetDir = resolve(writeRoot, \".agentx/references\", namespace)\n\n if (!opts.write) {\n console.log()\n console.log(chalk.dim(` Dry-run — would write to ${targetDir}/`))\n for (const [name, content] of Object.entries(files)) {\n console.log(chalk.cyan(`\\n --- ${name} ---`))\n console.log(content.split(\"\\n\").slice(0, 30).map(l => ` ${l}`).join(\"\\n\"))\n if (content.split(\"\\n\").length > 30) console.log(chalk.dim(` … (${content.split(\"\\n\").length - 30} more lines truncated in preview)`))\n }\n console.log()\n console.log(chalk.dim(` Re-run with --write to commit these to ${targetDir}/`))\n console.log()\n return\n }\n\n mkdirSync(targetDir, { recursive: true })\n let written = 0\n let skipped = 0\n for (const [name, content] of Object.entries(files)) {\n const dest = join(targetDir, name)\n if (existsSync(dest) && !opts.force) {\n console.log(chalk.dim(` skip ${dest} (exists; --force to overwrite)`))\n skipped++\n continue\n }\n writeFileSync(dest, content)\n console.log(chalk.green(` + ${dest}`))\n written++\n }\n console.log()\n console.log(chalk.dim(` ${written} written, ${skipped} skipped. Review every card — flagged ones (tags include \"needs-review\") are best-effort guesses.`))\n console.log(chalk.dim(` Then: agentx skill audit → set contextReferences: true on the relevant agents → systemctl restart agentx`))\n console.log()\n })\n\nreferences\n .command(\"list\")\n .alias(\"ls\")\n .description(\"list every loaded reference (debug)\")\n .option(\"--cwd <cwd>\", \"working directory\", process.cwd())\n .option(\"--json\", \"emit JSON\")\n .action(async (opts) => {\n const { loadReferences } = await import(\"@/agents/references/loader\")\n const idx = await loadReferences(resolve(opts.cwd))\n const cards = [...idx.byId.values()].sort((a, b) => a.id.localeCompare(b.id))\n if (opts.json) {\n console.log(JSON.stringify(cards, null, 2))\n return\n }\n console.log()\n if (cards.length === 0) {\n console.log(chalk.dim(\" (no references loaded — try `agentx references init <namespace>`)\"))\n console.log()\n return\n }\n for (const card of cards) {\n const src = idx.sourceById.get(card.id)\n console.log(` ${chalk.cyan(card.id)} ${chalk.dim(`(${card.kind})`)}`)\n console.log(` ${card.summary}`)\n if (src) console.log(chalk.dim(` ${src}`))\n }\n console.log()\n console.log(chalk.dim(` ${cards.length} reference(s) loaded.`))\n console.log()\n })\n\n// ==================== agentx hook ====================\n\nexport const hook = new Command()\n .name(\"hook\")\n .description(\"manage hooks — add to agent workspace\")\n\nhook\n .command(\"add <agent>\")\n .description(\"add a hook to an agent's workspace settings\")\n .action(async (agentId) => {\n const config = loadConfig()\n const agent = config.agents?.[agentId]\n if (!agent) { console.log(chalk.red(` Agent \"${agentId}\" not found`)); return }\n\n const settingsPath = resolve(agent.workspace, \".claude/settings.json\")\n const settings = existsSync(settingsPath) ? JSON.parse(readFileSync(settingsPath, \"utf-8\")) : {}\n\n const answers = await prompts([\n { type: \"select\", name: \"event\", message: \"Hook event\", choices: [\n { title: \"PreToolUse — before any tool runs\", value: \"PreToolUse\" },\n { title: \"PostToolUse — after any tool runs\", value: \"PostToolUse\" },\n { title: \"SessionStart — when session begins\", value: \"SessionStart\" },\n { title: \"Notification — on notifications\", value: \"Notification\" },\n { title: \"Stop — before session stops\", value: \"Stop\" },\n ]},\n { type: \"select\", name: \"type\", message: \"Hook type\", choices: [\n { title: \"command — run a shell command\", value: \"command\" },\n { title: \"http — POST to a URL\", value: \"http\" },\n ]},\n { type: \"text\", name: \"value\", message: (prev: any) => prev === \"command\" ? \"Shell command\" : \"URL\" },\n { type: \"text\", name: \"matcher\", message: \"Matcher regex (optional, e.g. 'Bash' to match tool)\" },\n ])\n\n if (!answers.event || !answers.value) return\n\n settings.hooks = settings.hooks || {}\n settings.hooks[answers.event] = settings.hooks[answers.event] || []\n\n const hookDef: any = {\n type: answers.type,\n ...(answers.type === \"command\" ? { command: answers.value } : { url: answers.value }),\n }\n\n const entry: any = { hooks: [hookDef] }\n if (answers.matcher) entry.matcher = answers.matcher\n\n settings.hooks[answers.event].push(entry)\n\n mkdirSync(resolve(agent.workspace, \".claude\"), { recursive: true })\n writeFileSync(settingsPath, JSON.stringify(settings, null, 2))\n console.log(chalk.green(` Hook added to ${agentId}: ${answers.event} -> ${answers.type}`))\n console.log()\n })\n\n// ==================== agentx migrate ====================\n\nexport const migrate = new Command()\n .name(\"migrate\")\n .description(\"import configuration from OpenClaw or other tools\")\n\nmigrate\n .command(\"openclaw [configPath]\")\n .description(\"import agents, channels, and crons from OpenClaw config\")\n .option(\"--dry-run\", \"show what would be imported without writing\")\n .action(async (configPath, opts) => {\n // Find OpenClaw config\n const searchPaths = [\n configPath,\n resolve(process.env.HOME || \"\", \".openclaw/openclaw.json\"),\n resolve(process.env.HOME || \"\", \".openclaw/clawdbot.json\"),\n ].filter(Boolean)\n\n let ocPath: string | undefined\n for (const p of searchPaths) {\n if (p && existsSync(p)) { ocPath = p; break }\n }\n\n if (!ocPath) {\n console.log(chalk.red(\" OpenClaw config not found. Pass the path: agentx migrate openclaw /path/to/config.json\"))\n return\n }\n\n console.log(chalk.dim(` Reading: ${ocPath}`))\n const oc = JSON.parse(readFileSync(ocPath, \"utf-8\"))\n\n const config = existsSync(resolve(process.cwd(), \"agentx.json\"))\n ? loadConfig()\n : { node: { id: \"imported\", name: \"Imported\", bind: \"127.0.0.1:18800\" }, providers: {}, agents: {}, channels: { telegram: { enabled: false, accounts: {}, policy: { dm: \"pair\", group: \"mention-required\" } }, whatsapp: { enabled: false } }, crons: {}, mesh: { enabled: false, peers: [] } }\n\n // Import agents\n const agents = oc.agents?.list || []\n const bindings = oc.bindings || []\n const bindMap: Record<string, string> = {}\n for (const b of bindings) {\n if (b.match?.channel === \"telegram\") {\n bindMap[b.match.accountId] = b.agentId\n }\n }\n // Default account -> main agent\n if (agents.find((a: any) => a.id === \"main\" || a.default)) {\n bindMap[\"default\"] = \"main\"\n }\n\n let agentCount = 0\n for (const a of agents) {\n if (a.workspace?.startsWith(\"/data\")) continue // skip remote devices\n\n const axId = a.id.replace(/-agent$/, \"\").replace(/^main$/, \"main-agent\")\n const mentions = a.groupChat?.mentionPatterns || []\n if (!mentions.some((m: string) => m === axId)) mentions.push(axId)\n\n config.agents[axId] = {\n name: a.name,\n workspace: a.workspace,\n tier: \"claude-code\",\n model: \"claude-sonnet-4-6\",\n mentions,\n maxConcurrent: a.id === \"main\" ? 2 : 1,\n systemPrompt: `You are ${a.name} on AgentX.`,\n permissionMode: \"bypassPermissions\",\n }\n agentCount++\n\n if (!opts.dryRun) {\n mkdirSync(resolve(a.workspace, \".claude/skills\"), { recursive: true })\n // Set up workspace with Claude Code best practices\n const { setupWorkspace } = await import(\"@/agents/workspace-setup\")\n setupWorkspace(axId, config.agents[axId] as any)\n }\n }\n console.log(` ${chalk.green(agentCount)} agents imported (workspaces set up with Claude Code best practices)`)\n\n // Import Telegram accounts\n const tgAccounts = oc.channels?.telegram?.accounts || {}\n let tgCount = 0\n for (const [name, acc] of Object.entries(tgAccounts) as any) {\n if (!acc.botToken) continue\n const boundAgent = bindMap[name]\n const axAgentId = boundAgent?.replace(/-agent$/, \"\").replace(/^main$/, \"main-agent\") || \"default\"\n\n config.channels.telegram.accounts[name] = {\n token: acc.botToken,\n agentBinding: axAgentId,\n }\n config.channels.telegram.enabled = true\n tgCount++\n }\n console.log(` ${chalk.green(tgCount)} Telegram accounts imported`)\n\n // Import cron jobs (from separate file if exists)\n const cronPath = resolve(ocPath, \"../cron/jobs.json\")\n if (existsSync(cronPath)) {\n const cronData = JSON.parse(readFileSync(cronPath, \"utf-8\"))\n let cronCount = 0\n for (const job of cronData.jobs || []) {\n const axId = job.name || job.id\n const agentId = job.agentId?.replace(/-agent$/, \"\").replace(/^main$/, \"main-agent\") || \"default\"\n config.crons[axId] = {\n enabled: job.enabled || false,\n schedule: job.schedule?.expr || \"0 9 * * *\",\n timezone: job.schedule?.tz || \"UTC\",\n agent: agentId,\n prompt: job.payload?.message || \"\",\n timeout: job.payload?.timeoutSeconds || 600,\n onError: [\"log\"],\n }\n cronCount++\n }\n console.log(` ${chalk.green(cronCount)} cron jobs imported`)\n }\n\n if (opts.dryRun) {\n console.log(chalk.yellow(\"\\n Dry run — nothing written\"))\n console.log(JSON.stringify(config, null, 2))\n } else {\n await saveConfig(config)\n console.log(chalk.green(\"\\n Migration complete! Review agentx.json and run: agentx daemon start\"))\n }\n console.log()\n })\n\n// ==================== agentx config ====================\n\nexport const configCmd = new Command()\n .name(\"config\")\n .description(\"validate and inspect configuration\")\n\nconfigCmd\n .command(\"check\")\n .description(\"validate agentx.json and check all workspaces\")\n .option(\"-c, --config <path>\", \"path to agentx.json\")\n .action(async (opts) => {\n console.log()\n try {\n const config = loadDaemonConfig(opts.config)\n console.log(chalk.green(\" ✓ Config valid\"))\n console.log(chalk.dim(` Node: ${config.node.name} (${config.node.id})`))\n console.log(chalk.dim(` Bind: ${config.node.bind}`))\n console.log(chalk.dim(` Agents: ${Object.keys(config.agents).length}`))\n console.log(chalk.dim(` Crons: ${Object.keys(config.crons).length}`))\n console.log(chalk.dim(` Mesh peers: ${config.mesh.peers.length}`))\n\n // Channels\n const tgAccounts = Object.keys(config.channels.telegram.accounts).length\n console.log(chalk.dim(` Telegram: ${config.channels.telegram.enabled ? `${tgAccounts} accounts` : \"disabled\"}`))\n console.log(chalk.dim(` WhatsApp: ${config.channels.whatsapp.enabled ? `${config.channels.whatsapp.routes.length} routes` : \"disabled\"}`))\n\n // Warnings\n const warnings = validateWorkspaces(config)\n if (warnings.length) {\n console.log()\n console.log(chalk.yellow(\" Warnings:\"))\n for (const w of warnings) {\n console.log(chalk.yellow(` ⚠ ${w}`))\n }\n } else {\n console.log(chalk.green(\" ✓ All workspaces valid\"))\n }\n\n // Check agent workspaces\n console.log()\n for (const [id, agent] of Object.entries(config.agents)) {\n const ws = agent.workspace\n const hasClaudeDir = existsSync(resolve(ws, \".claude\"))\n const hasClaudeMd = existsSync(resolve(ws, \"CLAUDE.md\"))\n const hasSettings = existsSync(resolve(ws, \".claude/settings.json\"))\n const skillCount = existsSync(resolve(ws, \".claude/skills\"))\n ? readdirSync(resolve(ws, \".claude/skills\")).filter(f => !f.startsWith(\".\")).length\n : 0\n\n const checks = [\n hasClaudeDir ? chalk.green(\"✓\") : chalk.red(\"✗\"),\n \".claude\",\n hasClaudeMd ? chalk.green(\"✓\") : chalk.yellow(\"○\"),\n \"CLAUDE.md\",\n hasSettings ? chalk.green(\"✓\") : chalk.yellow(\"○\"),\n \"settings\",\n `${skillCount} skills`,\n ]\n console.log(` ${chalk.cyan(id)}: ${checks.join(\" \")}`)\n }\n } catch (e: any) {\n console.log(chalk.red(` ✗ ${e.message}`))\n }\n console.log()\n })\n\nconfigCmd\n .command(\"show\")\n .description(\"print the resolved configuration\")\n .option(\"-c, --config <path>\", \"path to agentx.json\")\n .action((opts) => {\n try {\n const config = loadDaemonConfig(opts.config)\n console.log(JSON.stringify(config, null, 2))\n } catch (e: any) {\n console.log(chalk.red(e.message))\n }\n })\n\n// --- config get/set/unset — dot-path edits with Zod validation + hot-reload ---\n\nfunction parseValue(raw: string, asString: boolean): unknown {\n if (asString) return raw\n // Try JSON first — handles numbers, booleans, arrays, objects, quoted strings.\n try { return JSON.parse(raw) } catch { /* fall through */ }\n // Treat \"a,b,c\" as an array of trimmed strings (common shorthand).\n if (raw.includes(\",\") && !raw.includes(\" \")) {\n return raw.split(\",\").map(s => s.trim()).filter(Boolean)\n }\n return raw\n}\n\nfunction formatValue(v: unknown): string {\n if (v === undefined) return chalk.dim(\"(unset)\")\n if (typeof v === \"string\") return v\n return JSON.stringify(v, null, 2)\n}\n\nconfigCmd\n .command(\"get <path>\")\n .description(\"read a config value by dot-path (e.g. agents.devops.model)\")\n .option(\"-c, --config <path>\", \"path to agentx.json\")\n .option(\"--raw\", \"show ${VAR} tokens instead of env-expanded values\")\n .option(\"--json\", \"output as JSON (for scripting)\")\n .action(async (path: string, opts) => {\n const { readFileSync, existsSync } = await import(\"fs\")\n const { resolve } = await import(\"path\")\n const { getAtPath } = await import(\"@/daemon/config-mutator\")\n const { expandEnvVars } = await import(\"@/daemon/config\")\n\n const cfgPath = opts.config || resolve(process.cwd(), \"agentx.json\")\n if (!existsSync(cfgPath)) {\n console.log(chalk.red(` No config at ${cfgPath}`))\n process.exit(1)\n }\n const raw = JSON.parse(readFileSync(cfgPath, \"utf-8\"))\n const source = opts.raw ? raw : expandEnvVars(raw)\n const value = getAtPath(source, path)\n if (opts.json) {\n console.log(JSON.stringify(value))\n } else {\n console.log(formatValue(value))\n }\n })\n\nconfigCmd\n .command(\"set <path> <value>\")\n .description(\"write a config value by dot-path; validates against schema and hot-reloads the daemon\")\n .option(\"-c, --config <path>\", \"path to agentx.json\")\n .option(\"--string\", \"treat the value as a literal string (skip JSON parsing)\")\n .option(\"--dry-run\", \"validate and diff without writing\")\n .action(async (path: string, value: string, opts) => {\n const { applyConfigMutation, setAtPath, getAtPath } = await import(\"@/daemon/config-mutator\")\n const parsed = parseValue(value, !!opts.string)\n\n const result = await applyConfigMutation((cfg) => {\n setAtPath(cfg, path, parsed)\n }, { configPath: opts.config, dryRun: !!opts.dryRun })\n\n if (!result.success) {\n console.log(chalk.red(` ✗ ${result.error}`))\n process.exit(1)\n }\n\n const written = getAtPath(result.after, path)\n if (opts.dryRun) {\n console.log(chalk.yellow(` (dry-run) ${chalk.cyan(path)} would become: ${formatValue(written)}`))\n } else {\n console.log(chalk.green(` ✓ ${chalk.cyan(path)} = ${formatValue(written)}`))\n if (result.reloaded) {\n console.log(chalk.dim(\" Daemon hot-reloaded.\"))\n } else if (result.reloadSkipped && !/ECONNREFUSED|unreachable|fetch failed/i.test(result.reloadSkipped)) {\n console.log(chalk.dim(` (daemon reload skipped: ${result.reloadSkipped})`))\n }\n }\n })\n\nconfigCmd\n .command(\"unset <path>\")\n .description(\"remove a config value by dot-path (validates + hot-reloads)\")\n .option(\"-c, --config <path>\", \"path to agentx.json\")\n .option(\"--dry-run\", \"validate without writing\")\n .action(async (path: string, opts) => {\n const { applyConfigMutation, getAtPath, unsetAtPath } = await import(\"@/daemon/config-mutator\")\n\n const result = await applyConfigMutation((cfg) => {\n if (getAtPath(cfg, path) === undefined) {\n // No-op — still succeeds, writes nothing meaningful, but keeps the\n // caller's flow consistent.\n return\n }\n unsetAtPath(cfg, path)\n }, { configPath: opts.config, dryRun: !!opts.dryRun })\n\n if (!result.success) {\n console.log(chalk.red(` ✗ ${result.error}`))\n process.exit(1)\n }\n\n const stillThere = getAtPath(result.after, path)\n if (stillThere !== undefined) {\n console.log(chalk.dim(` (no-op) ${chalk.cyan(path)} was not set`))\n return\n }\n\n if (opts.dryRun) {\n console.log(chalk.yellow(` (dry-run) ${chalk.cyan(path)} would be removed`))\n } else {\n console.log(chalk.green(` ✓ ${chalk.cyan(path)} removed`))\n if (result.reloaded) {\n console.log(chalk.dim(\" Daemon hot-reloaded.\"))\n }\n }\n })\n\n// --- agentx config governance ---\n//\n// Read-only view of the governance flags that admit dispatches into the\n// ledger pipeline. v1 is read-only because every flag is read once at\n// daemon startup; flipping in place would require restart anyway. The\n// view answers the question operators ask first when something doesn't\n// dispatch: \"is governance even enabled, and at what level?\"\n\nconfigCmd\n .command(\"governance\")\n .description(\"show resolved governance flags (read-only; flags read once at startup)\")\n .option(\"-c, --config <path>\", \"path to agentx.json\")\n .option(\"--json\", \"emit JSON\")\n .action((opts) => {\n let businessEnabled = false\n let projectsCount = 0\n let configError: string | undefined\n try {\n const cfg = loadDaemonConfig(opts.config)\n businessEnabled = !!(cfg as any).business?.enabled\n projectsCount = ((cfg as any).business?.projects ?? []).length\n } catch (e: any) {\n configError = e?.message ?? String(e)\n }\n\n const ledgerMode = (process.env.INTENT_LEDGER_MODE || \"off\").toLowerCase()\n const pmGateRaw = (process.env.INTENT_PM_GATE_ENABLED || \"\").toLowerCase()\n const pmGate = pmGateRaw === \"true\" || pmGateRaw === \"1\" || pmGateRaw === \"yes\"\n const pmGateActive = pmGate && businessEnabled\n const ledgerValid = [\"off\", \"shadow\", \"authoritative\"].includes(ledgerMode)\n\n if (opts.json) {\n console.log(JSON.stringify({\n ledger: { mode: ledgerMode, valid: ledgerValid },\n pmGate: {\n envSet: pmGate,\n businessEnabled,\n active: pmGateActive,\n projects: projectsCount,\n },\n configError,\n }, null, 2))\n return\n }\n\n console.log()\n console.log(chalk.bold(\" Governance flags\"))\n console.log()\n if (configError) {\n console.log(chalk.yellow(` Note: agentx.json couldn't be loaded — ${configError}`))\n console.log()\n }\n\n const modeColor = ledgerMode === \"authoritative\" ? chalk.green\n : ledgerMode === \"shadow\" ? chalk.cyan\n : ledgerMode === \"off\" ? chalk.dim\n : chalk.red\n console.log(` INTENT_LEDGER_MODE ${modeColor(ledgerMode)}${ledgerValid ? \"\" : chalk.red(\" (invalid — must be off|shadow|authoritative)\")}`)\n\n const pmStatus = pmGateActive\n ? chalk.green(\"active\")\n : pmGate\n ? chalk.yellow(\"env=true but business.enabled=false → inactive\")\n : chalk.dim(\"disabled\")\n console.log(` INTENT_PM_GATE_ENABLED ${pmStatus}`)\n console.log(chalk.dim(` business.enabled ${businessEnabled ? chalk.green(\"true\") : chalk.dim(\"false\")}`))\n console.log(chalk.dim(` business.projects[] ${projectsCount}`))\n\n console.log()\n console.log(chalk.dim(\" These flags are read once at daemon startup. Flipping requires a restart.\"))\n console.log(chalk.dim(\" See: https://github.com/anis-marrouchi/agentx/blob/master/docs/architecture/research-rescue-plan.md\"))\n console.log()\n })\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { resolve } from \"path\"\nimport { existsSync } from \"fs\"\nimport { openDb } from \"@/storage/sqlite\"\n\n// --- agentx db ---\n//\n// Read-only CLI for exploring the operational SQLite at .agentx/db.sqlite\n// (built by the Move 2 storage layer). Named queries for the data the\n// daemon's bus subscribers persist. The escape hatch `agentx db query`\n// runs raw SQL for anything not exposed as a named subcommand.\n//\n// Defaults to human-readable column output; `--json` emits a JSON array\n// per row (one row per object) for piping into jq / dashboards.\n\nexport const db = new Command()\n .name(\"db\")\n .description(\"explore the operational SQLite store at .agentx/db.sqlite\")\n\nfunction openReadOnly(cwd: string) {\n const path = resolve(cwd, \".agentx/db.sqlite\")\n if (!existsSync(path)) {\n console.log(chalk.red(` No SQLite at ${path}`))\n console.log(chalk.dim(` Make sure the daemon has started since Move 2 shipped — the file is created on first boot.`))\n process.exit(1)\n }\n const handle = openDb({ path })\n if (!handle) {\n console.log(chalk.red(` Could not open ${path}`))\n console.log(chalk.dim(` If you see \"NODE_MODULE_VERSION mismatch\", run \\`pnpm rebuild better-sqlite3\\` under the daemon's Node version.`))\n process.exit(1)\n }\n return handle\n}\n\nfunction emit(rows: any[], asJson: boolean): void {\n if (asJson) {\n console.log(JSON.stringify(rows, null, 2))\n return\n }\n if (rows.length === 0) {\n console.log(chalk.dim(\" (no rows)\"))\n return\n }\n // Column rendering: compute widths + print a header / separator / rows.\n const cols = Object.keys(rows[0])\n const widths = cols.map(c =>\n Math.max(c.length, ...rows.map(r => String(r[c] ?? \"\").length))\n )\n const fmt = (cells: any[]) =>\n cells.map((v, i) => String(v ?? \"\").padEnd(widths[i])).join(\" \")\n console.log(fmt(cols))\n console.log(cols.map((_, i) => \"-\".repeat(widths[i])).join(\" \"))\n for (const row of rows) console.log(fmt(cols.map(c => row[c])))\n}\n\n// --- db tasks ---\n\ndb\n .command(\"tasks\")\n .description(\"recent task_history rows (one per agent task)\")\n .option(\"--cwd <cwd>\", \"working directory\", process.cwd())\n .option(\"-a, --agent <id>\", \"filter by agent id\")\n .option(\"-d, --day <YYYY-MM-DD>\", \"filter by start day (UTC)\")\n .option(\"-s, --status <status>\", \"ok | error\")\n .option(\"-n, --limit <n>\", \"max rows\", \"20\")\n .option(\"--json\", \"emit JSON\")\n .action((opts) => {\n const handle = openReadOnly(resolve(opts.cwd))\n const where: string[] = []\n const params: Record<string, any> = {}\n if (opts.agent) { where.push(\"agent_id = @agent\"); params.agent = opts.agent }\n if (opts.day) { where.push(\"started_at LIKE @day\"); params.day = `${opts.day}%` }\n if (opts.status) { where.push(\"status = @status\"); params.status = opts.status }\n const sql = `\n SELECT agent_id, channel, status, duration_ms,\n input_tokens, output_tokens,\n substr(message_preview, 1, 60) AS message,\n started_at\n FROM task_history\n ${where.length ? \"WHERE \" + where.join(\" AND \") : \"\"}\n ORDER BY started_at DESC\n LIMIT @limit\n `\n const rows = handle.prepare(sql).all({ ...params, limit: Number(opts.limit) })\n emit(rows, !!opts.json)\n })\n\n// --- db rotations ---\n\ndb\n .command(\"rotations\")\n .description(\"session rotation events (stale | tier-2 | max-turns)\")\n .option(\"--cwd <cwd>\", \"working directory\", process.cwd())\n .option(\"-a, --agent <id>\", \"filter by agent id\")\n .option(\"-r, --reason <r>\", \"stale | tier-2 | max-turns\")\n .option(\"-n, --limit <n>\", \"max rows\", \"20\")\n .option(\"--summary\", \"group by agent + reason\")\n .option(\"--json\", \"emit JSON\")\n .action((opts) => {\n const handle = openReadOnly(resolve(opts.cwd))\n const where: string[] = []\n const params: Record<string, any> = {}\n if (opts.agent) { where.push(\"agent_id = @agent\"); params.agent = opts.agent }\n if (opts.reason) { where.push(\"reason = @reason\"); params.reason = opts.reason }\n const whereSql = where.length ? \"WHERE \" + where.join(\" AND \") : \"\"\n const sql = opts.summary\n ? `\n SELECT agent_id, reason, COUNT(*) AS n,\n ROUND(AVG(last_turn_input_tokens)) AS avg_input_tokens,\n MAX(last_turn_input_tokens) AS max_input_tokens\n FROM rotations\n ${whereSql}\n GROUP BY agent_id, reason\n ORDER BY n DESC\n `\n : `\n SELECT agent_id, channel, reason, last_turn_input_tokens, rotated_at\n FROM rotations\n ${whereSql}\n ORDER BY rotated_at DESC\n LIMIT @limit\n `\n const rows = handle.prepare(sql).all({ ...params, limit: Number(opts.limit) })\n emit(rows, !!opts.json)\n })\n\n// --- db usage ---\n\ndb\n .command(\"usage\")\n .description(\"token usage rolled up per (agent, model, day)\")\n .option(\"--cwd <cwd>\", \"working directory\", process.cwd())\n .option(\"-a, --agent <id>\", \"filter by agent id\")\n .option(\"-d, --day <YYYY-MM-DD>\", \"filter by day (UTC)\")\n .option(\"--json\", \"emit JSON\")\n .action((opts) => {\n const handle = openReadOnly(resolve(opts.cwd))\n const where: string[] = []\n const params: Record<string, any> = {}\n if (opts.agent) { where.push(\"agent_id = @agent\"); params.agent = opts.agent }\n if (opts.day) { where.push(\"day = @day\"); params.day = opts.day }\n const sql = `\n SELECT day, agent_id, model, tasks,\n input_tokens AS in_tok, output_tokens AS out_tok,\n cache_read_tokens AS cache_read, cache_create_tokens AS cache_create\n FROM usage_daily\n ${where.length ? \"WHERE \" + where.join(\" AND \") : \"\"}\n ORDER BY day DESC, agent_id\n `\n const rows = handle.prepare(sql).all(params)\n emit(rows, !!opts.json)\n })\n\n// --- db routes ---\n\ndb\n .command(\"routes\")\n .description(\"inbound routing decisions captured by the pipeline trace\")\n .option(\"--cwd <cwd>\", \"working directory\", process.cwd())\n .option(\"-c, --channel <ch>\", \"filter by channel (telegram, gitlab, github, ...)\")\n .option(\"-k, --kind <k>\", \"match | drop\")\n .option(\"-n, --limit <n>\", \"max rows\", \"20\")\n .option(\"--summary\", \"group by channel + kind + deciding stage\")\n .option(\"--json\", \"emit JSON\")\n .action((opts) => {\n const handle = openReadOnly(resolve(opts.cwd))\n const where: string[] = []\n const params: Record<string, any> = {}\n if (opts.channel) { where.push(\"channel = @channel\"); params.channel = opts.channel }\n if (opts.kind) { where.push(\"kind = @kind\"); params.kind = opts.kind }\n const whereSql = where.length ? \"WHERE \" + where.join(\" AND \") : \"\"\n const sql = opts.summary\n ? `\n SELECT channel, kind, deciding_stage, COUNT(*) AS n\n FROM route_traces\n ${whereSql}\n GROUP BY channel, kind, deciding_stage\n ORDER BY n DESC\n `\n : `\n SELECT channel, chat_id, kind, deciding_stage, agent_id,\n substr(reason, 1, 60) AS reason, at\n FROM route_traces\n ${whereSql}\n ORDER BY at DESC\n LIMIT @limit\n `\n const rows = handle.prepare(sql).all({ ...params, limit: Number(opts.limit) })\n emit(rows, !!opts.json)\n })\n\n// --- db errors ---\n\ndb\n .command(\"errors\")\n .description(\"failed tasks (status='error') with their error message\")\n .option(\"--cwd <cwd>\", \"working directory\", process.cwd())\n .option(\"-a, --agent <id>\", \"filter by agent id\")\n .option(\"-n, --limit <n>\", \"max rows\", \"20\")\n .option(\"--json\", \"emit JSON\")\n .action((opts) => {\n const handle = openReadOnly(resolve(opts.cwd))\n const where: string[] = [\"status = 'error'\"]\n const params: Record<string, any> = {}\n if (opts.agent) { where.push(\"agent_id = @agent\"); params.agent = opts.agent }\n const sql = `\n SELECT agent_id, channel, duration_ms,\n substr(error, 1, 120) AS error,\n started_at\n FROM task_history\n WHERE ${where.join(\" AND \")}\n ORDER BY started_at DESC\n LIMIT @limit\n `\n const rows = handle.prepare(sql).all({ ...params, limit: Number(opts.limit) })\n emit(rows, !!opts.json)\n })\n\n// --- db tables / schema ---\n\ndb\n .command(\"tables\")\n .description(\"list tables + row counts\")\n .option(\"--cwd <cwd>\", \"working directory\", process.cwd())\n .option(\"--json\", \"emit JSON\")\n .action((opts) => {\n const handle = openReadOnly(resolve(opts.cwd))\n const tables = handle\n .prepare(\"SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' ORDER BY name\")\n .all() as { name: string }[]\n const rows = tables.map(t => ({\n table: t.name,\n rows: (handle.prepare(`SELECT COUNT(*) AS c FROM ${t.name}`).get() as { c: number }).c,\n }))\n emit(rows, !!opts.json)\n })\n\n// --- db query ---\n\ndb\n .command(\"query <sql>\")\n .description(\"run an arbitrary read-only SQL query (escape hatch)\")\n .option(\"--cwd <cwd>\", \"working directory\", process.cwd())\n .option(\"--json\", \"emit JSON\")\n .action((sql, opts) => {\n const handle = openReadOnly(resolve(opts.cwd))\n // Best-effort guard against accidental writes — read-only flag isn't on\n // (we share the daemon's open() helper). Reject the obvious DDL/DML.\n if (/^\\s*(insert|update|delete|drop|alter|create|attach|vacuum|pragma)\\b/i.test(sql)) {\n console.log(chalk.red(\" Refusing to run a write/DDL statement via `agentx db query`.\"))\n console.log(chalk.dim(\" Use `sqlite3 .agentx/db.sqlite` directly if you really mean it.\"))\n process.exit(2)\n }\n try {\n const rows = handle.prepare(sql).all()\n emit(rows, !!opts.json)\n } catch (e: any) {\n console.log(chalk.red(` ${e.message}`))\n process.exit(1)\n }\n })\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { mkdtempSync } from \"fs\"\nimport { tmpdir } from \"os\"\nimport { resolve, join } from \"path\"\nimport { existsSync } from \"fs\"\nimport Database from \"better-sqlite3\"\nimport { IntentLedger } from \"@/intent/ledger\"\nimport { replay } from \"@/intent/replay\"\nimport type { IntentDecision, IntentEvent, IntentResolution } from \"@/intent/types\"\n\n// --- agentx ledger ---\n//\n// Read-only triage CLI for the intent ledger at .agentx/intent/ledger.sqlite,\n// the canonical record of every dispatch decision (Phase 1 of the\n// architectural rescue, see docs/architecture/research-rescue-plan.md).\n//\n// Built for the 1b shadow-mode soak: an operator runs these commands\n// against a freshly-rsync'd copy of the ledger to inspect divergences,\n// in-flight dispatches, and source-by-source activity. The CLI does not\n// modify the ledger — opens read-only.\n//\n// Use `--path` to point at an alternate ledger (e.g., one rsync'd\n// locally from clawd-server). Default is .agentx/intent/ledger.sqlite\n// in the cwd.\n\nexport const ledger = new Command()\n .name(\"ledger\")\n .description(\"inspect the intent ledger (.agentx/intent/ledger.sqlite)\")\n\ninterface OpenOpts {\n cwd?: string\n path?: string\n}\n\nfunction openReadOnly(opts: OpenOpts) {\n const root = resolve(opts.cwd ?? process.cwd())\n const path = resolve(root, opts.path ?? \".agentx/intent/ledger.sqlite\")\n if (!existsSync(path)) {\n console.log(chalk.red(` No ledger at ${path}`))\n console.log(chalk.dim(` Make sure the daemon has run with INTENT_LEDGER_MODE != \"off\". The file is created on first ledger write.`))\n process.exit(1)\n }\n try {\n return new Database(path, { readonly: true })\n } catch (e: any) {\n console.log(chalk.red(` Could not open ${path}: ${e.message}`))\n if (/NODE_MODULE_VERSION/.test(e.message)) {\n console.log(chalk.dim(` Run \\`pnpm rebuild better-sqlite3\\` under the daemon's Node version.`))\n }\n process.exit(1)\n }\n}\n\nfunction emit(rows: any[], asJson: boolean): void {\n if (asJson) {\n console.log(JSON.stringify(rows, null, 2))\n return\n }\n if (rows.length === 0) {\n console.log(chalk.dim(\" (no rows)\"))\n return\n }\n const cols = Object.keys(rows[0])\n const widths = cols.map((c) =>\n Math.max(c.length, ...rows.map((r) => String(r[c] ?? \"\").length)),\n )\n const fmt = (cells: any[]) =>\n cells.map((v, i) => String(v ?? \"\").padEnd(widths[i])).join(\" \")\n console.log(fmt(cols))\n console.log(cols.map((_, i) => \"-\".repeat(widths[i])).join(\" \"))\n for (const row of rows) console.log(fmt(cols.map((c) => row[c])))\n}\n\n/** Convert a duration string (\"1h\", \"30m\", \"7d\") to milliseconds.\n * Returns null if unparseable. */\nfunction durationToMs(input: string): number | null {\n const m = /^(\\d+)\\s*([smhd])$/.exec(input.trim())\n if (!m) return null\n const n = Number(m[1])\n const unit = m[2]\n const factor = unit === \"s\" ? 1000 : unit === \"m\" ? 60_000 : unit === \"h\" ? 3600_000 : 86_400_000\n return n * factor\n}\n\nfunction parseSince(input: string | undefined): number | undefined {\n if (!input) return undefined\n const ms = durationToMs(input)\n if (ms === null) {\n // Maybe an absolute ms epoch\n const n = Number(input)\n if (Number.isFinite(n) && n > 0) return n\n console.log(chalk.red(` Invalid --since \"${input}\". Use a duration like \"1h\", \"30m\", \"7d\", or an ms epoch.`))\n process.exit(1)\n }\n return Date.now() - ms\n}\n\n// ---------------------------------------------------------------------------\n// agentx ledger stats\n// ---------------------------------------------------------------------------\n\nledger\n .command(\"stats\")\n .description(\"overview: events by source, decisions, divergences, in-flight count\")\n .option(\"--cwd <cwd>\", \"working directory\", process.cwd())\n .option(\"--path <path>\", \"ledger path relative to cwd\", \".agentx/intent/ledger.sqlite\")\n .option(\"--since <duration>\", \"limit to events newer than (e.g. 1h, 24h, 7d)\")\n .option(\"--json\", \"emit JSON\")\n .action((opts) => {\n const db = openReadOnly(opts)\n const since = parseSince(opts.since)\n const sinceClause = since !== undefined ? \"WHERE ts >= @since\" : \"\"\n const sinceClauseDecisions = since !== undefined ? \"WHERE decided_at >= @since\" : \"\"\n const sinceClauseDivergences = sinceClause\n\n const eventsBySource = db\n .prepare(`SELECT source, COUNT(*) as n FROM intent_events ${sinceClause} GROUP BY source ORDER BY n DESC`)\n .all({ since })\n const totalDecisions = (db\n .prepare(`SELECT COUNT(*) as n FROM intent_decisions ${sinceClauseDecisions}`)\n .get({ since }) as { n: number }).n\n const decisionsByOutcome = db\n .prepare(`SELECT outcome, COUNT(*) as n FROM intent_decisions ${sinceClauseDecisions} GROUP BY outcome ORDER BY n DESC`)\n .all({ since })\n const totalDivergences = (db\n .prepare(`SELECT COUNT(*) as n FROM intent_divergences ${sinceClauseDivergences}`)\n .get({ since }) as { n: number }).n\n const divergencesBySource = db\n .prepare(`SELECT source, COUNT(*) as n FROM intent_divergences ${sinceClauseDivergences} GROUP BY source ORDER BY n DESC`)\n .all({ since })\n const inFlight = (db\n .prepare(`\n SELECT COUNT(*) as n FROM intent_decisions d\n LEFT JOIN intent_resolutions r\n ON r.decision_event_id = d.event_id AND r.decision_decided_by = d.decided_by\n WHERE d.outcome = 'dispatched' AND r.decision_event_id IS NULL\n `)\n .get() as { n: number }).n\n\n if (opts.json) {\n console.log(JSON.stringify({\n since: since ?? null,\n eventsBySource, totalDecisions, decisionsByOutcome,\n totalDivergences, divergencesBySource, inFlight,\n }, null, 2))\n return\n }\n\n console.log(chalk.bold(\"Events by source\"))\n emit(eventsBySource, false)\n console.log()\n console.log(chalk.bold(`Decisions: ${totalDecisions}`))\n emit(decisionsByOutcome, false)\n console.log()\n console.log(chalk.bold(`Divergences: ${totalDivergences}`))\n emit(divergencesBySource, false)\n console.log()\n console.log(chalk.bold(`In-flight (dispatched, no resolution): ${inFlight}`))\n })\n\n// ---------------------------------------------------------------------------\n// agentx ledger divergences\n// ---------------------------------------------------------------------------\n\nledger\n .command(\"divergences\")\n .description(\"recent divergence rows (newest first)\")\n .option(\"--cwd <cwd>\", \"working directory\", process.cwd())\n .option(\"--path <path>\", \"ledger path relative to cwd\", \".agentx/intent/ledger.sqlite\")\n .option(\"-s, --source <name>\", \"filter by source (telegram, gitlab, workflow, cron, mesh, github)\")\n .option(\"--since <duration>\", \"limit to divergences newer than (e.g. 1h, 24h)\")\n .option(\"-n, --limit <n>\", \"max rows\", \"50\")\n .option(\"--json\", \"emit JSON\")\n .action((opts) => {\n const db = openReadOnly(opts)\n const since = parseSince(opts.since)\n const where: string[] = []\n const params: Record<string, any> = { limit: Number(opts.limit) }\n if (opts.source) { where.push(\"source = @source\"); params.source = opts.source }\n if (since !== undefined) { where.push(\"ts >= @since\"); params.since = since }\n const whereSql = where.length ? `WHERE ${where.join(\" AND \")}` : \"\"\n const rows = db\n .prepare(`\n SELECT\n datetime(ts/1000, 'unixepoch') AS at,\n source,\n decided_by,\n ledger_outcome AS L_outcome,\n COALESCE(ledger_agent_id, '-') AS L_agent,\n legacy_outcome AS X_outcome,\n COALESCE(legacy_agent_id, '-') AS X_agent,\n substr(COALESCE(legacy_reason, ledger_reason, ''), 1, 60) AS reason\n FROM intent_divergences\n ${whereSql}\n ORDER BY ts DESC\n LIMIT @limit\n `)\n .all(params)\n emit(rows, !!opts.json)\n })\n\n// ---------------------------------------------------------------------------\n// agentx ledger active\n// ---------------------------------------------------------------------------\n\nledger\n .command(\"active\")\n .description(\"currently in-flight dispatched decisions (no resolution yet)\")\n .option(\"--cwd <cwd>\", \"working directory\", process.cwd())\n .option(\"--path <path>\", \"ledger path relative to cwd\", \".agentx/intent/ledger.sqlite\")\n .option(\"-s, --source <name>\", \"filter by source\")\n .option(\"-n, --limit <n>\", \"max rows\", \"50\")\n .option(\"--json\", \"emit JSON\")\n .action((opts) => {\n const db = openReadOnly(opts)\n const where: string[] = [\"d.outcome = 'dispatched'\", \"r.decision_event_id IS NULL\"]\n const params: Record<string, any> = { limit: Number(opts.limit) }\n if (opts.source) { where.push(\"e.source = @source\"); params.source = opts.source }\n const rows = db\n .prepare(`\n SELECT\n datetime(d.decided_at/1000, 'unixepoch') AS dispatched_at,\n e.source,\n d.decided_by,\n COALESCE(d.agent_id, '-') AS agent,\n COALESCE(e.project, '-') AS project,\n COALESCE(e.subject, '-') AS subject,\n ROUND((strftime('%s', 'now')*1000 - d.decided_at) / 1000.0) AS age_s\n FROM intent_decisions d\n JOIN intent_events e ON e.id = d.event_id\n LEFT JOIN intent_resolutions r\n ON r.decision_event_id = d.event_id AND r.decision_decided_by = d.decided_by\n WHERE ${where.join(\" AND \")}\n ORDER BY d.decided_at DESC\n LIMIT @limit\n `)\n .all(params)\n emit(rows, !!opts.json)\n })\n\n// ---------------------------------------------------------------------------\n// agentx ledger events\n// ---------------------------------------------------------------------------\n\nledger\n .command(\"events\")\n .description(\"recent events (newest first)\")\n .option(\"--cwd <cwd>\", \"working directory\", process.cwd())\n .option(\"--path <path>\", \"ledger path relative to cwd\", \".agentx/intent/ledger.sqlite\")\n .option(\"-s, --source <name>\", \"filter by source\")\n .option(\"-p, --project <name>\", \"filter by project\")\n .option(\"--since <duration>\", \"limit to newer than (e.g. 1h, 24h)\")\n .option(\"-n, --limit <n>\", \"max rows\", \"30\")\n .option(\"--json\", \"emit JSON\")\n .action((opts) => {\n const db = openReadOnly(opts)\n const since = parseSince(opts.since)\n const where: string[] = []\n const params: Record<string, any> = { limit: Number(opts.limit) }\n if (opts.source) { where.push(\"source = @source\"); params.source = opts.source }\n if (opts.project) { where.push(\"project = @project\"); params.project = opts.project }\n if (since !== undefined) { where.push(\"ts >= @since\"); params.since = since }\n const whereSql = where.length ? `WHERE ${where.join(\" AND \")}` : \"\"\n const rows = db\n .prepare(`\n SELECT\n datetime(ts/1000, 'unixepoch') AS at,\n source,\n COALESCE(project, '-') AS project,\n COALESCE(subject, '-') AS subject,\n COALESCE(intent, '-') AS intent\n FROM intent_events\n ${whereSql}\n ORDER BY ts DESC\n LIMIT @limit\n `)\n .all(params)\n emit(rows, !!opts.json)\n })\n\n// ---------------------------------------------------------------------------\n// agentx ledger lineage\n// ---------------------------------------------------------------------------\n//\n// Walk the (project, subject) correlation for an event and print every\n// decision + resolution that landed on the same subject in chronological\n// order. Answers \"what's the dispatch lineage of this event?\" without\n// the operator having to write SQL. Foundation for a future in-product\n// diff viewer (deferred); the CLI version is the 80/20.\n\nledger\n .command(\"lineage <eventOrSubject>\")\n .description(\"walk the dispatch chain on the same (project, subject) and print every decision + resolution\")\n .option(\"--cwd <cwd>\", \"working directory\", process.cwd())\n .option(\"--path <path>\", \"ledger path relative to cwd\", \".agentx/intent/ledger.sqlite\")\n .option(\"--by-subject\", \"treat the argument as `<project>:<subject>` instead of an event id\")\n .option(\"--json\", \"emit JSON\")\n .action((eventOrSubject: string, opts) => {\n const db = openReadOnly(opts)\n\n let project: string | null = null\n let subject: string | null = null\n\n if (opts.bySubject) {\n const idx = eventOrSubject.indexOf(\":\")\n if (idx < 0) {\n console.log(chalk.red(` --by-subject expects \"<project>:<subject>\"`))\n process.exit(1)\n }\n project = eventOrSubject.slice(0, idx)\n subject = eventOrSubject.slice(idx + 1)\n } else {\n const row = db\n .prepare(`SELECT project, subject FROM intent_events WHERE id = ?`)\n .get(eventOrSubject) as { project: string | null; subject: string | null } | undefined\n if (!row) {\n console.log(chalk.red(` no event with id ${eventOrSubject}`))\n process.exit(1)\n }\n project = row.project\n subject = row.subject\n if (project === null || subject === null) {\n console.log(chalk.yellow(` event ${eventOrSubject} has no (project, subject) — lineage requires both`))\n if (project) console.log(chalk.dim(` project: ${project}`))\n if (subject) console.log(chalk.dim(` subject: ${subject}`))\n process.exit(1)\n }\n }\n\n // All events sharing this (project, subject), ordered by ts.\n const events = db\n .prepare(\n `SELECT id, ts, source, COALESCE(intent, '-') AS intent, COALESCE(source_event_id, '-') AS source_event_id\n FROM intent_events WHERE project = ? AND subject = ? ORDER BY ts ASC`,\n )\n .all(project, subject) as Array<{\n id: string; ts: number; source: string; intent: string; source_event_id: string\n }>\n\n if (events.length === 0) {\n console.log(chalk.dim(` (no events for ${project}:${subject})`))\n return\n }\n\n // All decisions + resolutions for those events, grouped by event_id.\n const eventIds = events.map((e) => e.id)\n const placeholders = eventIds.map((_, i) => `@id${i}`).join(\", \")\n const params = Object.fromEntries(eventIds.map((id, i) => [`id${i}`, id]))\n\n const decisions = db\n .prepare(`\n SELECT d.event_id, d.decided_at, d.decided_by, d.agent_id, d.outcome, d.reason,\n r.resolved_at, r.status AS resolution_status, r.duration_ms, r.result_summary\n FROM intent_decisions d\n LEFT JOIN intent_resolutions r\n ON r.decision_event_id = d.event_id AND r.decision_decided_by = d.decided_by\n WHERE d.event_id IN (${placeholders})\n ORDER BY d.decided_at ASC\n `)\n .all(params) as Array<{\n event_id: string; decided_at: number; decided_by: string; agent_id: string | null;\n outcome: string; reason: string | null;\n resolved_at: number | null; resolution_status: string | null;\n duration_ms: number | null; result_summary: string | null;\n }>\n\n if (opts.json) {\n const grouped = events.map((e) => ({\n event: e,\n decisions: decisions.filter((d) => d.event_id === e.id),\n }))\n console.log(JSON.stringify({ project, subject, lineage: grouped }, null, 2))\n return\n }\n\n const distinctAgents = new Set<string>()\n for (const d of decisions) {\n if (d.outcome === \"dispatched\" && d.agent_id) distinctAgents.add(d.agent_id)\n }\n\n console.log()\n console.log(chalk.bold(` Lineage for ${chalk.cyan(project + \":\" + subject)}`))\n console.log(chalk.dim(` ${events.length} event(s), ${decisions.length} decision(s), ${distinctAgents.size} distinct agent(s) dispatched`))\n console.log()\n\n for (const e of events) {\n const dt = new Date(e.ts).toISOString().slice(0, 19).replace(\"T\", \" \")\n console.log(` ${chalk.dim(dt)} ${chalk.bold(e.id)} ${chalk.dim(`(${e.source}/${e.intent})`)}`)\n const evDecisions = decisions.filter((d) => d.event_id === e.id)\n if (evDecisions.length === 0) {\n console.log(chalk.dim(` (no decisions yet)`))\n continue\n }\n for (const d of evDecisions) {\n const outcome = d.outcome === \"dispatched\"\n ? chalk.green(d.outcome)\n : d.outcome === \"dropped\"\n ? chalk.dim(d.outcome)\n : chalk.yellow(d.outcome)\n const agent = d.agent_id ? chalk.cyan(d.agent_id) : chalk.dim(\"-\")\n const reason = d.reason ? chalk.dim(` — ${d.reason.slice(0, 60)}`) : \"\"\n console.log(` ${chalk.dim(d.decided_by)} → ${outcome} ${agent}${reason}`)\n if (d.resolution_status) {\n const status = d.resolution_status === \"ok\"\n ? chalk.green(d.resolution_status)\n : chalk.red(d.resolution_status)\n const dur = d.duration_ms ? `${(d.duration_ms / 1000).toFixed(1)}s` : \"-\"\n console.log(` ${chalk.dim(\"resolved\")} ${status} ${chalk.dim(dur)}`)\n } else if (d.outcome === \"dispatched\") {\n console.log(` ${chalk.yellow(\"(in-flight, no resolution)\")}`)\n }\n }\n }\n console.log()\n })\n\n// ---------------------------------------------------------------------------\n// agentx ledger replay\n// ---------------------------------------------------------------------------\n//\n// Reads (events, decisions, resolutions) from the source ledger and\n// replays them onto a fresh tmp ledger via src/intent/replay.ts.\n// Reports any divergences. The Phase 7 regression test in CLI form.\n//\n// Usage:\n// agentx ledger replay # all rows\n// agentx ledger replay --since 24h # last 24h only\n// agentx ledger replay --source gitlab # one source only\n// agentx ledger replay --path /tmp/clawd-ledger/ledger.sqlite\n\nledger\n .command(\"replay\")\n .description(\"replay the source ledger onto a fresh tmp ledger; report divergences\")\n .option(\"--cwd <cwd>\", \"working directory\", process.cwd())\n .option(\"--path <path>\", \"ledger path relative to cwd\", \".agentx/intent/ledger.sqlite\")\n .option(\"--since <duration>\", \"limit to events newer than (e.g. 1h, 24h, 7d)\")\n .option(\"-s, --source <name>\", \"filter to one source\")\n .option(\"-n, --limit <n>\", \"max events to replay (defaults to all)\")\n .option(\"--json\", \"emit JSON\")\n .action((opts) => {\n const sourceDb = openReadOnly(opts)\n const since = parseSince(opts.since)\n\n // Pull events from the source ledger as IntentEvent[].\n const eventWhere: string[] = []\n const eventParams: Record<string, any> = {}\n if (opts.source) { eventWhere.push(\"source = @source\"); eventParams.source = opts.source }\n if (since !== undefined) { eventWhere.push(\"ts >= @since\"); eventParams.since = since }\n const eventLimit = opts.limit ? `LIMIT ${Number(opts.limit)}` : \"\"\n const events: IntentEvent[] = (sourceDb\n .prepare(`\n SELECT id, ts, source, source_event_id, project, subject, intent, raw_json\n FROM intent_events\n ${eventWhere.length ? \"WHERE \" + eventWhere.join(\" AND \") : \"\"}\n ORDER BY ts ASC\n ${eventLimit}\n `)\n .all(eventParams) as Array<any>)\n .map((r) => ({\n id: r.id, ts: r.ts, source: r.source,\n sourceEventId: r.source_event_id, project: r.project, subject: r.subject,\n intent: r.intent, rawJson: r.raw_json,\n }))\n\n // Pull decisions + resolutions for those events. Joining by event id\n // keeps the snapshot internally consistent — no orphan rows.\n if (events.length === 0) {\n console.log(chalk.dim(\" (no events match filter)\"))\n return\n }\n const eventIds = new Set(events.map((e) => e.id))\n const placeholders = events.map((_, i) => `@id${i}`).join(\", \")\n const eventIdParams: Record<string, any> = Object.fromEntries(\n events.map((e, i) => [`id${i}`, e.id]),\n )\n\n const decisions: IntentDecision[] = (sourceDb\n .prepare(`\n SELECT event_id, decided_at, decided_by, agent_id, outcome, reason\n FROM intent_decisions\n WHERE event_id IN (${placeholders})\n `)\n .all(eventIdParams) as Array<any>)\n .map((r) => ({\n eventId: r.event_id, decidedAt: r.decided_at, decidedBy: r.decided_by,\n agentId: r.agent_id, outcome: r.outcome, reason: r.reason,\n }))\n\n const resolutions: IntentResolution[] = (sourceDb\n .prepare(`\n SELECT decision_event_id, decision_decided_by, resolved_at, status, duration_ms, result_summary\n FROM intent_resolutions\n WHERE decision_event_id IN (${placeholders})\n `)\n .all(eventIdParams) as Array<any>)\n .map((r) => ({\n decisionEventId: r.decision_event_id, decisionDecidedBy: r.decision_decided_by,\n resolvedAt: r.resolved_at, status: r.status,\n durationMs: r.duration_ms, resultSummary: r.result_summary,\n }))\n\n void eventIds // for clarity; not used directly\n\n // Open a fresh tmp ledger and run the replay.\n const tmpDir = mkdtempSync(join(tmpdir(), \"agentx-ledger-replay-\"))\n const target = new IntentLedger({ path: join(tmpDir, \"target.sqlite\") })\n try {\n const result = replay(target, events, decisions, resolutions)\n\n if (opts.json) {\n console.log(JSON.stringify(result, null, 2))\n return\n }\n\n console.log(chalk.bold(`Replayed ${result.eventsCount} events, ${result.decisionsCount} decisions, ${resolutions.length} resolutions`))\n if (result.divergences.length === 0) {\n console.log(chalk.green(` ✓ 0 divergences — ledger mechanics are deterministic on this snapshot`))\n } else {\n console.log(chalk.red(` ✗ ${result.divergences.length} divergences`))\n emit(\n result.divergences.map((d) => ({\n event_id: d.eventId,\n decided_by: d.decidedBy,\n recorded: `${d.expected.outcome}/${d.expected.agentId ?? \"-\"}`,\n replayed: `${d.actual.outcome}/${d.actual.agentId ?? \"-\"}`,\n reason: d.reason.slice(0, 80),\n })),\n false,\n )\n }\n } finally {\n target.close()\n }\n })\n","import { decideAndCommit, type DispatchPolicy, type PolicyDecision } from \"./decide\"\nimport type { IntentLedger } from \"./ledger\"\nimport type { IntentDecision, IntentEvent, IntentEventInput, IntentResolution } from \"./types\"\n\n// Ledger replay — Phase 7 of the architectural rescue.\n//\n// Given a snapshot of events + decisions from a source ledger, replay\n// each event through `decideAndCommit` on a fresh target ledger and\n// compare the resulting decisions against what was originally\n// recorded.\n//\n// This validates Inv-Idempotence + Inv-ActiveTaskSafety operationally:\n// if 30 days of production traffic replay identically, decideAndCommit\n// is deterministic given ledger state (the formal property checked\n// statically by Phase 2's TLA+ spec).\n//\n// Replay is also the foundation for counterfactuals: \"if I'd dispatched\n// to agent B instead of A at decision row X, what would the rest of\n// the ledger look like?\" That extension lives in `counterfactual.ts`\n// (deferred to a follow-up commit).\n//\n// **Policy reconstruction.** Replay needs to call `decideAndCommit`,\n// which needs a `DispatchPolicy`. Real policies are runtime objects\n// keyed by `decidedBy` string; we don't store them. The replay reuses\n// the recorded decision as the policy's output — i.e., the\n// \"playback policy\" returns whatever was originally decided. This lets\n// the ledger's mechanics (idempotency, active-task safety) re-fire\n// independently and surface any divergence in those mechanics, which\n// is the exact scope of the regression test.\n//\n// **What replay does NOT verify.** Real policy disagreement (the policy\n// would decide differently today than it did originally) is invisible\n// to playback because we feed it the historical answer. Catching\n// real policy drift requires re-running the actual policies, which\n// the live shadow soak does — that's a complementary signal, not a\n// replacement for replay.\n\nexport interface ReplayDivergence {\n eventId: string\n decidedBy: string\n expected: { agentId: string | null; outcome: string }\n actual: { agentId: string | null; outcome: string }\n /** Free-form narrative of what diverged. Useful for triage. */\n reason: string\n}\n\nexport interface ReplayResult {\n /** Number of events replayed. */\n eventsCount: number\n /** Number of decisions replayed (one per (event, decidedBy) pair). */\n decisionsCount: number\n /** Decisions whose replayed outcome did not match the recorded one. */\n divergences: ReplayDivergence[]\n /** Decisions skipped because the recorded `decidedBy` does not exist\n * on the target ledger's policy registry — useful when replaying a\n * ledger from a code base that has since dropped a decider. Empty\n * when not applicable. */\n skipped: ReplayDivergence[]\n}\n\n/**\n * Replay a snapshot of (events, decisions, resolutions) onto `target`\n * (which should be empty). Returns an equivalence report.\n *\n * Decisions and resolutions are merged into a single timeline ordered\n * by their original timestamps so the ledger's active-task safety\n * lookup reproduces the original behavior: a resolution that arrived\n * between two decisions in the source will be applied at the same\n * point in the replay, freeing the slot for the second decision the\n * same way it did originally.\n *\n * Resolutions arrive without a separate replay decision (resolutions\n * are unconditional `recordResolution` writes) — they're just\n * forwarded to the target. Decisions are replayed via `decideAndCommit`\n * so the ledger's mechanics (idempotency, active-task safety) re-fire\n * and any divergence in those mechanics surfaces.\n */\nexport function replay(\n target: IntentLedger,\n events: IntentEvent[],\n decisions: IntentDecision[],\n resolutions: IntentResolution[] = [],\n): ReplayResult {\n // Index events by id so playback can find them when iterating decisions.\n const eventById = new Map<string, IntentEvent>()\n for (const e of events) eventById.set(e.id, e)\n\n // Build a single timeline of decisions + resolutions, sorted by\n // their original timestamp. Same-timestamp ties: decisions before\n // resolutions (a decision recorded at T cannot be resolved before T).\n type Entry =\n | { kind: \"decision\"; ts: number; decision: IntentDecision }\n | { kind: \"resolution\"; ts: number; resolution: IntentResolution }\n const timeline: Entry[] = []\n for (const d of decisions) timeline.push({ kind: \"decision\", ts: d.decidedAt, decision: d })\n for (const r of resolutions) timeline.push({ kind: \"resolution\", ts: r.resolvedAt, resolution: r })\n timeline.sort((a, b) => {\n if (a.ts !== b.ts) return a.ts - b.ts\n if (a.kind === b.kind) return 0\n return a.kind === \"decision\" ? -1 : 1\n })\n\n const divergences: ReplayDivergence[] = []\n let decisionsCount = 0\n\n for (const entry of timeline) {\n if (entry.kind === \"resolution\") {\n // Resolutions just forward to the target. If the corresponding\n // decision wasn't replayed (skipped because of missing event),\n // the FK in `intent_resolutions` will throw — caught and recorded\n // as a divergence to keep replay non-fatal.\n try {\n target.recordResolution(entry.resolution)\n } catch (e: any) {\n divergences.push({\n eventId: entry.resolution.decisionEventId,\n decidedBy: entry.resolution.decisionDecidedBy,\n expected: { agentId: null, outcome: \"resolved\" },\n actual: { agentId: null, outcome: \"resolution-failed\" },\n reason: `recordResolution threw: ${e?.message ?? e}`,\n })\n }\n continue\n }\n\n const recorded = entry.decision\n const event = eventById.get(recorded.eventId)\n if (!event) {\n // Decision with no matching event in the snapshot — the snapshot\n // is incomplete.\n divergences.push({\n eventId: recorded.eventId,\n decidedBy: recorded.decidedBy,\n expected: { agentId: recorded.agentId, outcome: recorded.outcome },\n actual: { agentId: null, outcome: \"skipped\" },\n reason: \"decision references event not in snapshot\",\n })\n continue\n }\n\n const policy = buildPlaybackPolicy(recorded)\n const eventInput: IntentEventInput = {\n // Preserve the source's event id so resolutions (which reference\n // the original event id) FK-resolve correctly in the target.\n // Without this, recordEvent generates a fresh ULID and the\n // resolution's FK fails.\n id: event.id,\n ts: event.ts,\n source: event.source,\n sourceEventId: event.sourceEventId,\n project: event.project,\n subject: event.subject,\n intent: event.intent,\n rawJson: event.rawJson,\n }\n\n const replayed = decideAndCommit(target, eventInput, policy, () => recorded.decidedAt)\n decisionsCount += 1\n\n if (\n replayed.outcome !== recorded.outcome ||\n replayed.agentId !== recorded.agentId\n ) {\n divergences.push({\n eventId: event.id,\n decidedBy: recorded.decidedBy,\n expected: { agentId: recorded.agentId, outcome: recorded.outcome },\n actual: { agentId: replayed.agentId, outcome: replayed.outcome },\n reason: classifyDivergence(recorded, replayed),\n })\n }\n }\n\n return {\n eventsCount: events.length,\n decisionsCount,\n divergences,\n skipped: [],\n }\n}\n\n/** Build a \"playback policy\" that reproduces the recorded decision. The\n * policy is consulted only when the ledger's mechanics don't force the\n * outcome (active-task safety can override → \"deduped\"). When the\n * recorded outcome is \"deduped\", the policy returns null because that\n * outcome is ledger-managed and never produced by a policy. */\nfunction buildPlaybackPolicy(recorded: IntentDecision): DispatchPolicy {\n return {\n decidedBy: recorded.decidedBy,\n decide: (): PolicyDecision | null => {\n if (recorded.outcome === \"deduped\") return null\n return {\n agentId: recorded.agentId,\n outcome: recorded.outcome as PolicyDecision[\"outcome\"],\n reason: recorded.reason,\n }\n },\n }\n}\n\n/** Categorize the kind of replay divergence for triage. Not exhaustive\n * — operators add new categories by reading the divergence rows. */\nfunction classifyDivergence(\n recorded: IntentDecision,\n replayed: IntentDecision,\n): string {\n if (recorded.outcome === \"dispatched\" && replayed.outcome === \"deduped\") {\n return \"active-task-safety-now-fires (slot held by earlier decision)\"\n }\n if (recorded.outcome === \"deduped\" && replayed.outcome === \"halted\") {\n return \"policy-returned-null (recorded as deduped means the live system\" +\n \" hit active-task safety; playback policy returned null because\" +\n \" deduped is illegal at the policy layer — investigate whether the\" +\n \" in-flight decision is present in the snapshot)\"\n }\n if (recorded.agentId !== replayed.agentId) {\n return `agent-changed (recorded=${recorded.agentId} replayed=${replayed.agentId})`\n }\n if (recorded.outcome !== replayed.outcome) {\n return `outcome-changed (recorded=${recorded.outcome} replayed=${replayed.outcome})`\n }\n return \"unknown\"\n}\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { resolve } from \"path\"\nimport { existsSync } from \"fs\"\nimport Database from \"better-sqlite3\"\nimport { getTrace, listTraces, type TraceRecord, type TraceStepRecord } from \"@/storage/traces\"\n\n// --- agentx trace ---\n//\n// Read-only triage CLI for the per-task execution traces persisted at\n// .agentx/db.sqlite (improvement plan #2). Pairs with the\n// HTTP endpoints (GET /traces, GET /traces/:taskId) — same store, two\n// access surfaces. Operators in a hurry tail this; dashboard consumers\n// hit the HTTP routes.\n//\n// Use `--path` to point at an alternate db (e.g., one rsync'd from\n// a remote daemon). Default is .agentx/db.sqlite in the cwd.\n\nexport const trace = new Command()\n .name(\"trace\")\n .description(\"inspect per-task execution traces (.agentx/db.sqlite)\")\n\ninterface OpenOpts {\n cwd?: string\n path?: string\n}\n\nfunction openReadOnly(opts: OpenOpts) {\n const root = resolve(opts.cwd ?? process.cwd())\n const path = resolve(root, opts.path ?? \".agentx/db.sqlite\")\n if (!existsSync(path)) {\n console.log(chalk.red(` No db at ${path}`))\n console.log(chalk.dim(` The file is created on first SQLite write — start the daemon and run a task.`))\n process.exit(1)\n }\n try {\n return new Database(path, { readonly: true })\n } catch (e: any) {\n console.log(chalk.red(` Could not open ${path}: ${e.message}`))\n if (/NODE_MODULE_VERSION/.test(e.message)) {\n console.log(chalk.dim(` Run \\`pnpm rebuild better-sqlite3\\` under the daemon's Node version.`))\n }\n process.exit(1)\n }\n}\n\nfunction durationToMs(input: string): number | null {\n const m = /^(\\d+)\\s*([smhd])$/.exec(input.trim())\n if (!m) return null\n const n = Number(m[1])\n const unit = m[2]\n const factor = unit === \"s\" ? 1000 : unit === \"m\" ? 60_000 : unit === \"h\" ? 3600_000 : 86_400_000\n return n * factor\n}\n\nfunction parseSince(input: string | undefined): number | undefined {\n if (!input) return undefined\n const ms = durationToMs(input)\n if (ms === null) {\n const n = Number(input)\n if (Number.isFinite(n) && n > 0) return n\n console.log(chalk.red(` Invalid --since \"${input}\". Use \"1h\", \"30m\", \"7d\", or an ms epoch.`))\n process.exit(1)\n }\n return Date.now() - ms!\n}\n\nfunction fmtAge(ms: number): string {\n const s = Math.round((Date.now() - ms) / 1000)\n if (s < 60) return `${s}s ago`\n if (s < 3600) return `${Math.round(s / 60)}m ago`\n if (s < 86400) return `${Math.round(s / 3600)}h ago`\n return `${Math.round(s / 86400)}d ago`\n}\n\nfunction statusColor(s: string): (text: string) => string {\n if (s === \"ok\") return chalk.green\n if (s === \"error\" || s === \"timeout\") return chalk.red\n if (s === \"in-flight\") return chalk.yellow\n return chalk.dim\n}\n\n// ---------------------------------------------------------------------------\n// agentx trace list\n// ---------------------------------------------------------------------------\n\ntrace\n .command(\"list\")\n .description(\"list recent traces (newest first)\")\n .option(\"--cwd <cwd>\", \"working directory\", process.cwd())\n .option(\"--path <path>\", \"db path relative to cwd\", \".agentx/db.sqlite\")\n .option(\"--agent <id>\", \"filter by agentId\")\n .option(\"--channel <name>\", \"filter by channel (telegram|whatsapp|gitlab|...)\")\n .option(\"--chat <id>\", \"filter by chatId\")\n .option(\"--workflow <runId>\", \"filter by workflowRunId\")\n .option(\"--status <s>\", \"filter by status (in-flight|ok|error|timeout)\")\n .option(\"--since <duration>\", \"limit to traces newer than (e.g. 1h, 24h, 7d)\")\n .option(\"--limit <n>\", \"max rows\", \"50\")\n .option(\"--json\", \"emit JSON\")\n .action((opts) => {\n const db = openReadOnly(opts)\n const traces = listTraces(db, {\n agentId: opts.agent,\n channel: opts.channel,\n chatId: opts.chat,\n workflowRunId: opts.workflow,\n status: opts.status,\n since: parseSince(opts.since),\n limit: parseInt(opts.limit, 10) || 50,\n })\n\n if (opts.json) {\n console.log(JSON.stringify(traces, null, 2))\n return\n }\n if (traces.length === 0) {\n console.log(chalk.dim(\" (no traces)\"))\n return\n }\n\n for (const t of traces) {\n const status = statusColor(t.status)(t.status.padEnd(9))\n const dur = t.durationMs != null ? `${(t.durationMs / 1000).toFixed(2)}s` : \"—\"\n const wf = t.workflowRunId ? chalk.cyan(` wf=${t.workflowRunId}`) : \"\"\n const tokens = t.inputTokens != null\n ? chalk.dim(` ${t.inputTokens}/${t.outputTokens ?? 0} tok`)\n : \"\"\n console.log(\n `${chalk.dim(t.taskId)} ${status} ${chalk.bold(t.agentId)}` +\n `${chalk.dim(` ${t.channel ?? \"—\"}:${t.chatId ?? \"—\"}`)}${wf}` +\n ` ${chalk.dim(\"·\")} ${dur}${tokens} ${chalk.dim(fmtAge(t.startedAt))}`,\n )\n if (t.error) console.log(` ${chalk.red(\"error:\")} ${t.error}`)\n }\n })\n\n// ---------------------------------------------------------------------------\n// agentx trace show <taskId>\n// ---------------------------------------------------------------------------\n\ntrace\n .command(\"show <taskId>\")\n .description(\"show one trace with its full ordered step log\")\n .option(\"--cwd <cwd>\", \"working directory\", process.cwd())\n .option(\"--path <path>\", \"db path relative to cwd\", \".agentx/db.sqlite\")\n .option(\"--json\", \"emit JSON\")\n .action((taskId: string, opts) => {\n const db = openReadOnly(opts)\n const rec = getTrace(db, taskId)\n if (!rec) {\n console.log(chalk.red(` No trace at ${taskId}`))\n process.exit(1)\n }\n if (opts.json) {\n console.log(JSON.stringify(rec, null, 2))\n return\n }\n printTrace(rec.task, rec.steps)\n })\n\nfunction printTrace(t: TraceRecord, steps: TraceStepRecord[]): void {\n const status = statusColor(t.status)(t.status)\n console.log(chalk.bold(`Trace ${t.taskId}`))\n console.log(` ${chalk.dim(\"agent\")} ${t.agentId}`)\n console.log(` ${chalk.dim(\"channel\")} ${t.channel ?? \"—\"}:${t.chatId ?? \"—\"}`)\n if (t.workflowRunId) {\n const wfPart = [t.workflowId, t.workflowNodeId].filter(Boolean).join(\"/\")\n console.log(` ${chalk.dim(\"workflow\")} ${chalk.cyan(t.workflowRunId)}${wfPart ? chalk.dim(` (${wfPart})`) : \"\"}`)\n }\n if (t.intentEventId) {\n console.log(` ${chalk.dim(\"intent\")} ${t.intentEventId} ${chalk.dim(`(${t.intentDecidedBy ?? \"?\"})`)}`)\n }\n if (t.model) console.log(` ${chalk.dim(\"model\")} ${t.model}`)\n if (t.resumeSessionId) console.log(` ${chalk.dim(\"resume\")} ${t.resumeSessionId.slice(0, 12)}…`)\n if (t.finalSessionId) console.log(` ${chalk.dim(\"final\")} ${t.finalSessionId.slice(0, 12)}…`)\n console.log(` ${chalk.dim(\"status\")} ${status}`)\n if (t.durationMs != null) {\n console.log(` ${chalk.dim(\"duration\")} ${(t.durationMs / 1000).toFixed(2)}s`)\n }\n if (t.inputTokens != null || t.outputTokens != null) {\n console.log(` ${chalk.dim(\"tokens\")} in=${t.inputTokens ?? 0} out=${t.outputTokens ?? 0} ` +\n `cache_read=${t.cacheReadTokens ?? 0} cache_create=${t.cacheCreateTokens ?? 0}`)\n }\n if (t.error) console.log(` ${chalk.red(\"error\")} ${t.error}`)\n if (t.messagePreview) console.log(` ${chalk.dim(\"message\")} ${t.messagePreview}`)\n console.log()\n\n if (steps.length === 0) {\n console.log(chalk.dim(` (no recorded steps — task may have been on a non-streaming tier or completed before any tool call)`))\n return\n }\n console.log(chalk.bold(`Steps (${steps.length}):`))\n for (const s of steps) {\n const stepStatus = s.status ? statusColor(s.status)(s.status) : chalk.dim(\"—\")\n const action = s.action ? chalk.cyan(s.action) : \"\"\n console.log(` ${chalk.dim(`#${s.seq}`)} ${chalk.bold(s.name)}${action ? \" \" + action : \"\"} ${stepStatus}` +\n `${s.ms != null ? chalk.dim(` ${s.ms}ms`) : \"\"}`)\n if (s.inputSummary) {\n const lines = s.inputSummary.split(\"\\n\").slice(0, 8)\n console.log(lines.map((l) => ` ${chalk.dim(\"→\")} ${l}`).join(\"\\n\"))\n if (s.inputSummary.split(\"\\n\").length > 8) console.log(` ${chalk.dim(\"…\")}`)\n }\n if (s.outputSummary) {\n const lines = s.outputSummary.split(\"\\n\").slice(0, 8)\n console.log(lines.map((l) => ` ${chalk.dim(\"←\")} ${l}`).join(\"\\n\"))\n if (s.outputSummary.split(\"\\n\").length > 8) console.log(` ${chalk.dim(\"…\")}`)\n }\n if (s.error) console.log(` ${chalk.red(\"error:\")} ${s.error}`)\n }\n}\n\n// --- agentx trace replay <taskId> [--diff] ----------------------------------\n//\n// Handoff item #11. Loads a recorded task by id, re-fires it via the daemon's\n// POST /task with the same agent + a fresh session, and prints the new run's\n// reply. With --diff, shows a side-by-side comparison of original input,\n// original output (if captured), and the new output — directly answers\n// \"did my prompt change fix it?\" without rerunning by hand.\n//\n// Replay reads the trace from a local SQLite db (or one rsync'd from a\n// remote daemon via --path). Old rows pre-migration-v8 fall back to\n// messagePreview (capped 200 chars), with a warning that the input\n// may be truncated relative to the original.\n\ntrace\n .command(\"replay <taskId>\")\n .description(\"re-run a recorded task against the current agent config (handoff item #11)\")\n .option(\"--cwd <dir>\", \"project root\", process.cwd())\n .option(\"--path <p>\", \"sqlite db path (relative to --cwd)\", \".agentx/db.sqlite\")\n .option(\"--daemon <url>\", \"daemon API base URL\", \"http://127.0.0.1:18800\")\n .option(\"--diff\", \"show original input + output vs new output side-by-side\")\n .option(\"--no-fresh\", \"do NOT freshSession (default is fresh — required for clean replay)\")\n .action(async (taskId: string, opts) => {\n const db = openReadOnly(opts)\n const trace = getTrace(db, taskId)\n if (!trace) {\n console.log(chalk.red(` task not found: ${taskId}`))\n console.log(chalk.dim(` agentx trace list — see what's available`))\n process.exit(1)\n }\n const t = trace.task\n const message = t.originalMessage ?? t.messagePreview\n if (!message) {\n console.log(chalk.red(` task ${taskId} has no recorded input message — cannot replay`))\n process.exit(1)\n }\n const truncated = !t.originalMessage && t.messagePreview != null\n if (truncated) {\n console.log(chalk.yellow(` ⚠ pre-migration-v8 row: input message was capped at 200 chars; replay uses the preview`))\n }\n\n console.log()\n console.log(chalk.bold(` replay ${chalk.cyan(taskId)}`))\n console.log(chalk.dim(` agent=${t.agentId} channel=${t.channel ?? \"—\"} chatId=${t.chatId ?? \"—\"}`))\n console.log(chalk.dim(` original status=${t.status} duration=${t.durationMs ?? \"?\"}ms tokens=in:${t.inputTokens ?? 0}/out:${t.outputTokens ?? 0}`))\n console.log()\n\n const base = String(opts.daemon).replace(/\\/+$/, \"\")\n const body = {\n agent: t.agentId,\n message,\n freshSession: opts.fresh !== false,\n context: {\n channel: t.channel ?? \"api\",\n // Per-replay chatId so the new run doesn't pollute (or get polluted by)\n // the original conversation's session. Operators can pin to the original\n // chatId via --no-fresh + a different invocation if they want continuity.\n chatId: `replay-${taskId.toLowerCase().slice(-8)}-${Date.now().toString(36)}`,\n },\n }\n const startedAt = Date.now()\n let res: Response\n try {\n res = await fetch(`${base}/task`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n })\n } catch (e: any) {\n console.log(chalk.red(` daemon unreachable at ${base}: ${e.message || e}`))\n process.exit(1)\n }\n const reply = await res.json().catch(() => ({})) as {\n content?: string\n error?: string\n duration?: number\n usage?: { inputTokens?: number; outputTokens?: number }\n }\n const durationMs = Date.now() - startedAt\n\n if (!res.ok) {\n console.log(chalk.red(` replay failed (${res.status}): ${reply.error || \"unknown error\"}`))\n process.exit(1)\n }\n\n if (opts.diff) {\n console.log(chalk.bold(\" INPUT (replayed verbatim)\"))\n console.log()\n printBlock(message)\n console.log()\n console.log(chalk.bold(` ORIGINAL OUTPUT ${chalk.dim(`status=${t.status} ${t.durationMs ?? \"?\"}ms`)}`))\n console.log()\n if (t.finalResponse) {\n printBlock(t.finalResponse)\n } else {\n console.log(chalk.yellow(` (not captured — pre-migration-v8 row, or response was empty)`))\n }\n console.log()\n console.log(chalk.bold(` CURRENT OUTPUT ${chalk.dim(`status=${reply.error ? \"error\" : \"ok\"} ${durationMs}ms tokens=in:${reply.usage?.inputTokens ?? 0}/out:${reply.usage?.outputTokens ?? 0}`)}`))\n console.log()\n printBlock(reply.content ?? \"(empty reply)\")\n if (reply.error) console.log(chalk.red(` error: ${reply.error}`))\n console.log()\n // Quick literal-diff signal — true when the two strings differ.\n // This is intentionally simple (no character-level diff) — operators\n // skim for \"did anything change?\" before deep-reading both blocks.\n const same = (t.finalResponse ?? \"\").trim() === (reply.content ?? \"\").trim()\n if (t.finalResponse) {\n console.log(same\n ? chalk.dim(\" outputs are identical\")\n : chalk.yellow(\" outputs differ — read both blocks to see what changed\"))\n console.log()\n }\n } else {\n console.log(chalk.green(` ✓ replayed in ${durationMs}ms`))\n console.log()\n printBlock(reply.content ?? \"(empty reply)\")\n if (reply.error) console.log(chalk.red(`\\n error: ${reply.error}`))\n console.log()\n console.log(chalk.dim(` agentx trace replay ${taskId} --diff to compare against the original output`))\n console.log()\n }\n })\n\n/** Print a multi-line block with consistent indent + a left bar so the block\n * visually separates from surrounding chrome. Caps very long blocks at 60\n * lines with a \"…+N more\" footer; the full content is still in the trace\n * store for those who need it. */\nfunction printBlock(text: string): void {\n const lines = text.split(\"\\n\")\n const max = 60\n const shown = lines.slice(0, max)\n for (const l of shown) console.log(` ${chalk.dim(\"│\")} ${l}`)\n if (lines.length > max) {\n console.log(` ${chalk.dim(\"│\")} ${chalk.dim(`…+${lines.length - max} more lines`)}`)\n }\n}\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { existsSync, mkdirSync, writeFileSync } from \"fs\"\nimport { resolve, join, dirname } from \"path\"\nimport {\n runGuard,\n runCheckFromStdin,\n listDecisions,\n loadPolicy,\n guessInstallRoot,\n GUARDRAILS_DIR,\n type GuardMode,\n type Verdict,\n} from \"@/guard\"\nimport { SEED_FILES } from \"@/guard/seeds\"\n\n// --- agentx guard ---\n//\n// Destructive-action guardrails (PRD: AgentX Destructive-Action Guardrails).\n// `check` is the PreToolUse hook entrypoint (stdin -> stdout). The rest are\n// operator tools: dry-run a command (`test`), read the audit trail (`log`),\n// scaffold policy (`init`), and ping the daemon (`reload`).\n\nexport const guard = new Command().name(\"guard\").description(\"destructive-action guardrails — policy, checks, audit\")\n\nfunction actionColor(a: string): (s: string) => string {\n if (a === \"deny\") return chalk.red\n if (a === \"escalate\" || a === \"ask\") return chalk.yellow\n if (a === \"warn\") return chalk.magenta\n return chalk.green\n}\n\nfunction rootOf(opts: { root?: string }): string {\n return opts.root ? resolve(opts.root) : guessInstallRoot()\n}\n\n// ---------------------------------------------------------------------------\n// agentx guard check (PreToolUse hook entrypoint — reads stdin)\n// ---------------------------------------------------------------------------\nguard\n .command(\"check\")\n .description(\"PreToolUse hook entrypoint: read a tool-call payload on stdin, emit a Claude Code decision\")\n .option(\"--agent <id>\", \"agent id this workspace belongs to\")\n .option(\"--root <dir>\", \"AgentX install root (holds .agentx/guardrails + .agentx/db.sqlite)\")\n .option(\"--env <name>\", \"environment scope (e.g. production)\")\n .action(async (opts) => {\n await runCheckFromStdin({ root: rootOf(opts), agentId: opts.agent, env: opts.env })\n // Always exit 0 — the guard fails open at the hook layer; real blocking is\n // via the JSON decision on stdout, never a nonzero exit.\n process.exit(0)\n })\n\n// ---------------------------------------------------------------------------\n// agentx guard test \"<command>\" (dry-run through the engine)\n// ---------------------------------------------------------------------------\nguard\n .command(\"test <command>\")\n .description(\"dry-run a command through the policy engine and print the verdict\")\n .option(\"--agent <id>\", \"evaluate as this agent\")\n .option(\"--env <name>\", \"environment scope\")\n .option(\"--tool <name>\", \"tool name\", \"Bash\")\n .option(\"--cwd <dir>\", \"workspace cwd for $VAR/.env resolution\", process.cwd())\n .option(\"--root <dir>\", \"AgentX install root (policy source)\")\n .option(\"--enforce\", \"evaluate as if mode=enforce (show what WOULD block)\")\n .option(\"--json\", \"emit JSON\")\n .action((command: string, opts) => {\n const root = rootOf(opts)\n const modeOverride: GuardMode | undefined = opts.enforce ? \"enforce\" : undefined\n const { verdict, mode, ms } = runGuard(\n { tool: opts.tool, command, cwd: opts.cwd, agentId: opts.agent, env: opts.env },\n { root, agentId: opts.agent, env: opts.env, modeOverride, noAudit: true },\n )\n if (opts.json) {\n console.log(JSON.stringify({ verdict, mode, ms }, null, 2))\n return\n }\n printVerdict(verdict, mode, ms)\n })\n\nfunction printVerdict(v: Verdict, mode: string, ms: number) {\n const col = actionColor(v.action)\n console.log()\n console.log(` policy verdict ${col(v.action.toUpperCase())}${v.matched ? \"\" : chalk.dim(\" (no rule matched)\")}`)\n console.log(` enforced as ${actionColor(v.effectiveAction)(v.effectiveAction)} ${chalk.dim(`(mode=${mode})`)}`)\n if (v.ruleId) console.log(` rule ${chalk.cyan(v.ruleId)}${v.severity ? chalk.dim(` [${v.severity}]`) : \"\"}`)\n if (v.resolvedTarget) console.log(` resolved target ${chalk.yellow(v.resolvedTarget)}`)\n if (v.message) console.log(` message ${v.message}`)\n console.log(` ${chalk.dim(`evaluated in ${ms}ms`)}`)\n console.log()\n}\n\n// ---------------------------------------------------------------------------\n// agentx guard log (read the audit trail)\n// ---------------------------------------------------------------------------\nguard\n .command(\"log\")\n .description(\"read the guardrail decision audit trail (newest first)\")\n .option(\"--root <dir>\", \"AgentX install root (holds .agentx/db.sqlite)\")\n .option(\"--verdict <v>\", \"filter by verdict (deny|escalate|warn|allow)\")\n .option(\"--agent <id>\", \"filter by agent\")\n .option(\"--task <id>\", \"filter by task id\")\n .option(\"-n, --limit <n>\", \"max rows\", \"30\")\n .option(\"--json\", \"emit JSON\")\n .action((opts) => {\n const rows = listDecisions({\n root: rootOf(opts),\n verdict: opts.verdict,\n agentId: opts.agent,\n taskId: opts.task,\n limit: parseInt(opts.limit, 10) || 30,\n })\n if (opts.json) {\n console.log(JSON.stringify(rows, null, 2))\n return\n }\n if (rows.length === 0) {\n console.log(chalk.dim(\" (no guardrail decisions recorded yet)\"))\n return\n }\n for (const r of rows) {\n const when = new Date(r.ts).toISOString().replace(\"T\", \" \").slice(0, 19)\n const col = actionColor(r.verdict)\n const eff = r.effective_action !== r.verdict ? chalk.dim(`->${r.effective_action}`) : \"\"\n console.log(\n ` ${chalk.dim(when)} ${col(r.verdict.toUpperCase().padEnd(8))}${eff} ` +\n `${chalk.cyan((r.agent_id ?? \"?\").padEnd(16))} ${chalk.dim((r.matched_rule ?? \"-\").padEnd(24))} ` +\n `${(r.command ?? \"\").slice(0, 70)}`,\n )\n if (r.resolved_target) console.log(chalk.dim(` target: ${r.resolved_target}`))\n }\n })\n\n// ---------------------------------------------------------------------------\n// agentx guard init (scaffold .agentx/guardrails/)\n// ---------------------------------------------------------------------------\nguard\n .command(\"init\")\n .description(\"scaffold .agentx/guardrails/ with a starter policy + protected-resource example\")\n .option(\"--root <dir>\", \"where to create .agentx/guardrails/\", process.cwd())\n .option(\"--force\", \"overwrite existing files\")\n .action((opts) => {\n const base = join(resolve(opts.root), GUARDRAILS_DIR)\n let created = 0\n for (const f of SEED_FILES) {\n const path = join(base, f.relPath)\n if (existsSync(path) && !opts.force) {\n console.log(chalk.dim(` skip (exists) ${f.relPath}`))\n continue\n }\n mkdirSync(dirname(path), { recursive: true })\n writeFileSync(path, f.content)\n console.log(chalk.green(` created ${f.relPath}`))\n created++\n }\n console.log()\n console.log(` Guardrails scaffolded under ${chalk.cyan(base)}`)\n console.log(chalk.dim(` Edit environments/production.yaml with YOUR prod hosts/URLs, then`))\n console.log(chalk.dim(` \\`agentx guard test \"<cmd>\" --enforce\\` to preview, and flip mode: enforce when ready.`))\n })\n\n// ---------------------------------------------------------------------------\n// agentx guard reload (ping the daemon; policy is read live regardless)\n// ---------------------------------------------------------------------------\nguard\n .command(\"reload\")\n .description(\"signal the daemon to reload (note: guard policy is read live per tool call already)\")\n .option(\"--url <url>\", \"daemon base url\", process.env.AGENTX_DAEMON_URL || \"http://localhost:19900\")\n .action(async (opts) => {\n try {\n const res = await fetch(`${String(opts.url).replace(/\\/$/, \"\")}/reload`, { method: \"POST\" })\n if (res.ok) console.log(chalk.green(` daemon reloaded (${opts.url})`))\n else console.log(chalk.yellow(` daemon reachable but returned ${res.status}`))\n } catch (e: any) {\n console.log(chalk.dim(` daemon not reachable (${e.message}). Policy files are still read live on each check.`))\n }\n })\n\n// ---------------------------------------------------------------------------\n// agentx guard policy (show the resolved policy for an agent)\n// ---------------------------------------------------------------------------\nguard\n .command(\"policy\")\n .description(\"print the resolved (merged) policy for an agent\")\n .option(\"--agent <id>\", \"agent id\")\n .option(\"--root <dir>\", \"AgentX install root\")\n .action((opts) => {\n const p = loadPolicy(rootOf(opts), opts.agent)\n console.log(JSON.stringify(p, null, 2))\n })\n","// Seed policy templates for `agentx guard init`. Kept as strings (not files)\n// so the CLI can scaffold `.agentx/guardrails/` on any node without shipping\n// example files in the npm tarball. The repo's own `.agentx/guardrails/` is a\n// committed instance of these for the local (MacBook) node.\n\nexport const SEED_POLICY_YAML = `# AgentX destructive-action guardrails — global policy\n#\n# This file + environments/*.yaml + agents/<id>.yaml are deep-merged\n# (most specific wins). The built-in catalog (prisma / rm -rf / docker /\n# terraform / git push --force ... patterns) is ALWAYS applied underneath.\n# The guard reads policy live on every tool call — edits take effect on the\n# next command, no daemon restart needed.\nversion: 1\n\n# warn = compute + audit but never block (Phase 1 rollout stance).\n# enforce = honor the verdict (deny blocks; escalate asks).\n# off = kill-switch, allow everything.\n# Flip to enforce once \\`agentx guard log\\` shows an acceptable false-positive rate.\nmode: warn\n\ndefaults:\n fail_mode: closed # guard error on a protected-target command => deny\n unmatched: allow # commands no rule matches run freely (keep routine work fast)\n\n# Extra global rules beyond the catalog go here. Example:\n# rules:\n# - id: no-prod-ssh\n# match: { tool: Bash, command_regex: \"ssh \", target_in: production }\n# action: escalate\n# severity: high\nrules: []\n`\n\nexport const SEED_PRODUCTION_YAML = `# Production protected resources.\n#\n# The catalog rules reference \\`target_in: production\\`, so DECLARING this set is\n# what arms them. \\`resolve_env: true\\` expands $VAR / \\${VAR} and reads .env* in\n# the workspace before matching — so \\`--shadow-database-url $DATABASE_URL\\` is\n# caught even though the literal string \"production\" never appears in the command\n# (this is exactly the 2026-07-21 incident class).\nprotected_resources:\n production:\n resolve_env: true\n db_urls:\n - \"\\${PROD_DATABASE_URL}\"\n hosts:\n - \"api.hackathonat.com\"\n - \"185.164.25.107\"\n # buckets:\n # - \"my-prod-uploads\"\n # contexts: # k8s contexts, droplet ids, cluster names\n # - \"do-fra1-prod\"\n\n# Production-only rules beyond the catalog:\nrules: []\n`\n\nexport const SEED_CODER_AGENT_YAML = `# Per-agent override for coder-agent. Top-level rules here are auto-scoped to\n# this agent (the filename names it). coder agents never touch production.\nrules:\n - id: coder-no-prod\n match:\n target_in: production\n action: deny\n severity: critical\n message: \"coder-agent is not permitted to run commands against production.\"\n`\n\nexport interface SeedFile {\n relPath: string\n content: string\n}\n\nexport const SEED_FILES: SeedFile[] = [\n { relPath: \"policy.yaml\", content: SEED_POLICY_YAML },\n { relPath: \"environments/production.yaml\", content: SEED_PRODUCTION_YAML },\n { relPath: \"agents/coder-agent.yaml\", content: SEED_CODER_AGENT_YAML },\n]\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport {\n installAttachHooks,\n uninstallAttachHooks,\n attachHooksInstalled,\n userSettingsPath,\n configuredDaemonPort,\n} from \"@/attach/install\"\nimport { DELIVERY_MODES, isDeliveryMode, type AttachSession, type DeliveryMode } from \"@/attach\"\n\n// --- agentx attach ---\n//\n// Wear an agentx identity in the Claude Code session you already have open.\n//\n// Normally the daemon spawns a `claude` subprocess per task. Attach inverts\n// that: this session registers as the agent, and channel messages addressed\n// to it are queued here instead of spawning anything. agentx keeps doing what\n// it is actually good at — identity, routing, memory, guard, channels — and\n// the loop is the one you are already typing into.\n//\n// Binding is a runtime operation against the daemon. The hooks (installed\n// once, at user scope) are dumb pipes that ask the daemon on every event, so\n// attach/detach takes effect immediately with no file edits and no restart.\n\nexport const attach = new Command()\n .name(\"attach\")\n .description(\"wear an agentx agent identity in this Claude Code session\")\n\nconst DEFAULT_URL =\n process.env.AGENTX_DAEMON_URL || `http://127.0.0.1:${configuredDaemonPort()}`\n\n/** Claude Code exports its session id into the shell of every Bash tool call.\n * That is what lets `agentx attach` bind the exact session it is running\n * inside rather than guessing from cwd. It is undocumented, so `--session`\n * stays available and the error text explains the fallback. */\nfunction currentSessionId(explicit?: string): string | undefined {\n return explicit || process.env.CLAUDE_CODE_SESSION_ID || undefined\n}\n\nasync function api(url: string, path: string, body?: unknown): Promise<any> {\n const res = await fetch(`${url}${path}`, {\n method: body ? \"POST\" : \"GET\",\n headers: { \"Content-Type\": \"application/json\" },\n body: body ? JSON.stringify(body) : undefined,\n })\n const text = await res.text()\n let json: any = null\n try {\n json = text ? JSON.parse(text) : null\n } catch {\n /* non-JSON body */\n }\n if (!res.ok) throw new Error(json?.error || text || `HTTP ${res.status}`)\n return json\n}\n\nfunction daemonHint(e: unknown): string {\n const msg = (e as any)?.message ?? String(e)\n if (/ECONNREFUSED|fetch failed/i.test(msg)) {\n return `daemon not reachable — start it with ${chalk.cyan(\"agentx daemon start\")}`\n }\n return msg\n}\n\nfunction modeColor(m: DeliveryMode): (s: string) => string {\n if (m === \"auto\") return chalk.yellow\n if (m === \"manual\") return chalk.gray\n return chalk.green\n}\n\nfunction printSession(s: AttachSession & { pending?: number }, mark = false): void {\n const who = s.agentIds.length ? s.agentIds.join(\", \") : chalk.gray(\"(not bound)\")\n const pending = s.pending ? chalk.yellow(`${s.pending} pending`) : chalk.gray(\"empty\")\n const here = mark ? chalk.cyan(\" ← this session\") : \"\"\n console.log(\n ` ${chalk.bold(who)} ${modeColor(s.mode)(s.mode)} ${pending} ${chalk.gray(s.sessionId)}${here}`,\n )\n if (s.cwd) console.log(` ${chalk.gray(s.cwd)}`)\n}\n\n// ---------------------------------------------------------------------------\n// agentx attach <agent> — bind this session\n// ---------------------------------------------------------------------------\nattach\n .command(\"as <agent>\", { isDefault: true })\n .description(\"bind this Claude Code session to an agent identity\")\n .option(\"-m, --mode <mode>\", `delivery mode: ${DELIVERY_MODES.join(\" | \")}`, \"notify\")\n .option(\"--session <id>\", \"Claude Code session id (defaults to $CLAUDE_CODE_SESSION_ID)\")\n .option(\"--url <url>\", \"daemon base url\", DEFAULT_URL)\n .action(async (agent: string, opts) => {\n const sessionId = currentSessionId(opts.session)\n if (!sessionId) {\n console.error(chalk.red(\"Could not determine the Claude Code session id.\"))\n console.error(\n `Run this inside a Claude Code session, or pass ${chalk.cyan(\"--session <id>\")} ` +\n `(list them with ${chalk.cyan(\"agentx attach list\")}).`,\n )\n process.exit(1)\n }\n if (!isDeliveryMode(opts.mode)) {\n console.error(chalk.red(`Invalid mode \"${opts.mode}\". Expected one of: ${DELIVERY_MODES.join(\", \")}`))\n process.exit(1)\n }\n\n if (!attachHooksInstalled()) {\n console.error(chalk.yellow(\"Attach hooks are not installed yet.\"))\n console.error(`Run ${chalk.cyan(\"agentx attach install\")} once, then try again.`)\n process.exit(1)\n }\n\n try {\n const r = await api(opts.url, \"/attach/bind\", {\n sessionId,\n agentId: agent,\n mode: opts.mode,\n cwd: process.cwd(),\n })\n console.log(\n `${chalk.green(\"✓\")} This session is now wearing ${chalk.bold(agent)} ` +\n `(${modeColor(opts.mode)(opts.mode)}).`,\n )\n const pending = Number(r?.pending ?? 0)\n if (pending > 0) {\n console.log(chalk.yellow(` ${pending} message(s) already queued for it.`))\n }\n console.log(\n chalk.gray(\n opts.mode === \"auto\"\n ? \" Queued messages will be answered automatically at the end of each turn.\"\n : opts.mode === \"notify\"\n ? \" You'll be told when messages arrive; run /inbox to answer them.\"\n : \" Nothing will interrupt you; run /inbox to check for messages.\",\n ),\n )\n } catch (e) {\n console.error(chalk.red(`Bind failed: ${daemonHint(e)}`))\n process.exit(1)\n }\n })\n\n// ---------------------------------------------------------------------------\n// agentx attach detach\n// ---------------------------------------------------------------------------\nattach\n .command(\"detach\")\n .description(\"stop wearing an identity in this session (queued work falls back to spawned agents)\")\n .option(\"--agent <id>\", \"release only this identity (default: all)\")\n .option(\"--session <id>\", \"Claude Code session id (defaults to $CLAUDE_CODE_SESSION_ID)\")\n .option(\"--url <url>\", \"daemon base url\", DEFAULT_URL)\n .action(async (opts) => {\n const sessionId = currentSessionId(opts.session)\n if (!sessionId) {\n console.error(chalk.red(\"Could not determine the Claude Code session id. Pass --session <id>.\"))\n process.exit(1)\n }\n try {\n await api(opts.url, \"/attach/detach\", { sessionId, agentId: opts.agent })\n console.log(`${chalk.green(\"✓\")} Detached. New messages will spawn agents the normal way.`)\n } catch (e) {\n console.error(chalk.red(`Detach failed: ${daemonHint(e)}`))\n process.exit(1)\n }\n })\n\n// ---------------------------------------------------------------------------\n// agentx attach list / status\n// ---------------------------------------------------------------------------\nattach\n .command(\"list\")\n .alias(\"status\")\n .description(\"show every attached session on this machine\")\n .option(\"--url <url>\", \"daemon base url\", DEFAULT_URL)\n .option(\"--json\", \"raw JSON output\")\n .action(async (opts) => {\n const here = currentSessionId()\n try {\n const r = await api(opts.url, \"/attach/sessions\")\n const sessions: Array<AttachSession & { pending: number }> = r?.sessions ?? []\n if (opts.json) {\n console.log(JSON.stringify({ hooksInstalled: attachHooksInstalled(), sessions }, null, 2))\n return\n }\n\n console.log()\n console.log(\n attachHooksInstalled()\n ? `${chalk.green(\"✓\")} Attach hooks installed ${chalk.gray(userSettingsPath())}`\n : `${chalk.yellow(\"!\")} Attach hooks not installed — run ${chalk.cyan(\"agentx attach install\")}`,\n )\n console.log()\n\n const bound = sessions.filter((s) => s.agentIds.length > 0)\n if (bound.length === 0) {\n console.log(chalk.gray(\" No session is wearing an identity right now.\"))\n } else {\n for (const s of bound) printSession(s, s.sessionId === here)\n }\n const idle = sessions.length - bound.length\n if (idle > 0) console.log(chalk.gray(`\\n ${idle} registered session(s) with no binding.`))\n console.log()\n } catch (e) {\n console.error(chalk.red(`Could not read attach state: ${daemonHint(e)}`))\n process.exit(1)\n }\n })\n\n// ---------------------------------------------------------------------------\n// agentx attach install / uninstall\n// ---------------------------------------------------------------------------\nattach\n .command(\"install\")\n .description(\"wire the attach hooks into ~/.claude/settings.json (one time, all sessions)\")\n .option(\"--port <n>\", \"daemon port the hooks should call (default: node.bind in agentx.json)\")\n .option(\"--path <file>\", \"settings file to patch (default: ~/.claude/settings.json)\")\n .option(\"--no-guard\", \"skip the PreToolUse guard hook (not recommended)\")\n .action((opts) => {\n try {\n const port = String(opts.port || configuredDaemonPort())\n const r = installAttachHooks(port, { path: opts.path, withGuard: opts.guard })\n console.log(\n r.changed\n ? `${chalk.green(\"✓\")} Installed attach hooks in ${chalk.gray(r.path)}`\n : `${chalk.green(\"✓\")} Attach hooks already up to date in ${chalk.gray(r.path)}`,\n )\n console.log(chalk.gray(` Events: ${r.events.join(\", \")} → 127.0.0.1:${port}`))\n if (r.guardInstalled) {\n console.log(chalk.gray(\" PreToolUse guard installed at user scope.\"))\n console.log(\n chalk.gray(\n \" (An attached session runs under your permissions, not the agent's workspace\\n\" +\n \" settings — without this an attached production identity would be less\\n\" +\n \" guarded than a spawned one.)\",\n ),\n )\n } else {\n console.log(\n chalk.yellow(\n \" ! Guard hook skipped. An attached production identity will run unguarded.\",\n ),\n )\n }\n console.log()\n console.log(`Next: ${chalk.cyan(\"agentx attach <agent>\")} inside a Claude Code session.`)\n } catch (e: any) {\n console.error(chalk.red(`Install failed: ${e?.message ?? e}`))\n process.exit(1)\n }\n })\n\nattach\n .command(\"uninstall\")\n .description(\"remove the attach hooks from ~/.claude/settings.json\")\n .option(\"--path <file>\", \"settings file to patch (default: ~/.claude/settings.json)\")\n .option(\"--remove-guard\", \"also remove the PreToolUse guard hook\")\n .action((opts) => {\n try {\n const r = uninstallAttachHooks({ path: opts.path, keepGuard: !opts.removeGuard })\n console.log(\n r.changed\n ? `${chalk.green(\"✓\")} Removed attach hooks from ${chalk.gray(r.path)} (${r.events.join(\", \")})`\n : `${chalk.gray(\"Nothing to remove.\")}`,\n )\n if (!opts.removeGuard) {\n console.log(chalk.gray(\" PreToolUse guard left in place — pass --remove-guard to drop it too.\"))\n }\n } catch (e: any) {\n console.error(chalk.red(`Uninstall failed: ${e?.message ?? e}`))\n process.exit(1)\n }\n })\n","import { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\"\nimport { homedir } from \"os\"\nimport { dirname, resolve } from \"path\"\n\n// --- Installing the attach hooks into Claude Code ---\n//\n// Attach mode needs four hook events wired into the human's own Claude Code\n// settings, not into an agent workspace: the whole point is that the session\n// you already have open becomes addressable. So these go to the USER scope\n// (~/.claude/settings.json) and apply to every session on the machine.\n//\n// That sounds invasive; it isn't. The hooks are dumb pipes. They post to the\n// daemon and forward whatever comes back. For the overwhelming majority of\n// sessions — the ones that never run `agentx attach` — the daemon has no\n// binding for them and answers with an empty body, which Claude Code treats\n// as \"carry on\". State lives in the daemon, never in the settings file, so\n// attaching and detaching is a runtime operation with no file edits and no\n// session restart.\n//\n// The same install also carries the PreToolUse guard hook. An attached\n// session answering as a production identity runs under the human's own\n// permissions rather than the agent workspace's settings.json, so without\n// this an attached `clawd` would be LESS guarded than a spawned one. That\n// asymmetry is exactly the kind of thing that causes the incident the guard\n// was built for, so the installer refuses to leave it open.\n\nexport const ATTACH_MARKER = \"/attach/\"\nexport const GUARD_MARKER = \"/guard/check\"\n\ntype HookEntry = { matcher?: string; hooks: Array<{ type: string; command: string; timeout?: number }> }\n\n/** One-line curl to the daemon. `--data-binary @-` streams the hook's stdin\n * payload through unread; `|| true` means a stopped daemon degrades to \"no\n * opinion\" instead of erroring in the human's session. */\nfunction hookCommand(route: string, port: string, query = \"\"): string {\n const url = `http://127.0.0.1:${port}${route}${query}`\n return `curl -s --max-time 3 -H 'Content-Type: application/json' --data-binary @- '${url}' 2>/dev/null || true`\n}\n\nfunction entry(route: string, port: string, matcher?: string): HookEntry {\n const e: HookEntry = { hooks: [{ type: \"command\", command: hookCommand(route, port), timeout: 10 }] }\n if (matcher !== undefined) e.matcher = matcher\n return e\n}\n\n/** The hook block attach mode owns, keyed by event name. */\nexport function attachHookBlock(port: string): Record<string, HookEntry[]> {\n return {\n SessionStart: [entry(\"/attach/session-start\", port, \"\")],\n UserPromptSubmit: [entry(\"/attach/prompt\", port)],\n Stop: [entry(\"/attach/stop\", port)],\n SessionEnd: [entry(\"/attach/session-end\", port)],\n }\n}\n\n/** PreToolUse guard, user-scope. Mirrors the per-workspace form in\n * agents/workspace-setup.ts but without an `?agent=` — an attached session's\n * identity is a runtime binding, so the daemon resolves it per call. */\nexport function guardHookEntries(port: string): HookEntry[] {\n const command = hookCommand(\"/guard/check\", port)\n return [\n { matcher: \"Bash\", hooks: [{ type: \"command\", command, timeout: 10 }] },\n { matcher: \"Write|Edit\", hooks: [{ type: \"command\", command, timeout: 10 }] },\n ]\n}\n\nfunction isOurs(e: any, marker: string): boolean {\n return (\n Array.isArray(e?.hooks) &&\n e.hooks.some((h: any) => typeof h?.command === \"string\" && h.command.includes(marker))\n )\n}\n\nexport interface InstallResult {\n path: string\n changed: boolean\n events: string[]\n guardInstalled: boolean\n}\n\nexport function userSettingsPath(): string {\n return resolve(homedir(), \".claude/settings.json\")\n}\n\n/**\n * The port the hooks should call. Read from `node.bind` in agentx.json rather\n * than assumed: this is per-install (18800 on one node here, 19900 on\n * another), and a hook pointed at the wrong port fails silently — `|| true`\n * turns it into \"no opinion\", so a bad default would look like attach mode\n * simply never firing. Falls back to 19900 only when there is no config.\n */\nexport function configuredDaemonPort(root: string = process.cwd()): string {\n for (const dir of [root, resolve(root, \"..\")]) {\n const cfg = resolve(dir, \"agentx.json\")\n if (!existsSync(cfg)) continue\n try {\n const bind = JSON.parse(readFileSync(cfg, \"utf-8\"))?.node?.bind\n const port = String(bind ?? \"\").split(\":\")[1]\n if (port) return port\n } catch {\n /* fall through to the default */\n }\n }\n return \"19900\"\n}\n\n/**\n * Add (or refresh) the attach hooks. Idempotent: existing agentx entries are\n * replaced rather than appended, so a changed port self-heals instead of\n * stacking duplicates. Hooks belonging to anything else are preserved\n * untouched — this file is the human's, and we are a guest in it.\n */\nexport function installAttachHooks(\n port: string,\n opts: { path?: string; withGuard?: boolean } = {},\n): InstallResult {\n const path = opts.path ?? userSettingsPath()\n const withGuard = opts.withGuard !== false\n\n let settings: Record<string, any> = {}\n if (existsSync(path)) {\n try {\n settings = JSON.parse(readFileSync(path, \"utf-8\"))\n } catch (e: any) {\n throw new Error(`${path} is not valid JSON (${e?.message}) — refusing to overwrite it`)\n }\n }\n\n const before = JSON.stringify(settings)\n const hooks = (settings.hooks ??= {})\n const events: string[] = []\n\n for (const [event, desired] of Object.entries(attachHookBlock(port))) {\n const others = Array.isArray(hooks[event])\n ? hooks[event].filter((e: any) => !isOurs(e, ATTACH_MARKER))\n : []\n hooks[event] = [...others, ...desired]\n events.push(event)\n }\n\n let guardInstalled = false\n if (withGuard) {\n const others = Array.isArray(hooks.PreToolUse)\n ? hooks.PreToolUse.filter((e: any) => !isOurs(e, GUARD_MARKER))\n : []\n hooks.PreToolUse = [...others, ...guardHookEntries(port)]\n guardInstalled = true\n }\n\n const changed = JSON.stringify(settings) !== before\n if (changed) {\n mkdirSync(dirname(path), { recursive: true })\n writeFileSync(path, `${JSON.stringify(settings, null, 2)}\\n`)\n }\n return { path, changed, events, guardInstalled }\n}\n\n/** Remove every hook agentx installed. Leaves the rest of the file alone,\n * and drops hook events that end up empty rather than leaving `[]` behind. */\nexport function uninstallAttachHooks(opts: { path?: string; keepGuard?: boolean } = {}): InstallResult {\n const path = opts.path ?? userSettingsPath()\n if (!existsSync(path)) return { path, changed: false, events: [], guardInstalled: false }\n\n let settings: Record<string, any>\n try {\n settings = JSON.parse(readFileSync(path, \"utf-8\"))\n } catch (e: any) {\n throw new Error(`${path} is not valid JSON (${e?.message}) — refusing to rewrite it`)\n }\n\n const before = JSON.stringify(settings)\n const hooks = settings.hooks\n const events: string[] = []\n if (hooks && typeof hooks === \"object\") {\n for (const event of Object.keys(hooks)) {\n if (!Array.isArray(hooks[event])) continue\n const marker = event === \"PreToolUse\" ? GUARD_MARKER : ATTACH_MARKER\n if (event === \"PreToolUse\" && opts.keepGuard !== false) continue\n const kept = hooks[event].filter((e: any) => !isOurs(e, marker))\n if (kept.length !== hooks[event].length) events.push(event)\n if (kept.length === 0) delete hooks[event]\n else hooks[event] = kept\n }\n if (Object.keys(hooks).length === 0) delete settings.hooks\n }\n\n const changed = JSON.stringify(settings) !== before\n if (changed) writeFileSync(path, `${JSON.stringify(settings, null, 2)}\\n`)\n return { path, changed, events, guardInstalled: false }\n}\n\n/** Are our hooks currently present? Used by `agentx attach status` and doctor. */\nexport function attachHooksInstalled(path = userSettingsPath()): boolean {\n if (!existsSync(path)) return false\n try {\n const s = JSON.parse(readFileSync(path, \"utf-8\"))\n return Boolean(s?.hooks?.Stop?.some?.((e: any) => isOurs(e, ATTACH_MARKER)))\n } catch {\n return false\n }\n}\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { loadDaemonConfig } from \"@/daemon/config\"\n\n// --- agentx process — operator surface for the persistent claude registry ---\n//\n// Two subcommands:\n// agentx process list list every live handle\n// agentx process kill <agentId> <channel> <chatId> force-rotate one handle\n//\n// Both talk to the local daemon's HTTP API. The registry is in-memory\n// (no SQLite persistence) so a daemon restart fully resets it; this CLI\n// is the only mid-flight operator surface short of a restart.\n\nexport const process_ = new Command()\n .name(\"process\")\n .description(\"inspect / rotate persistent claude processes (--persistentProcess agents)\")\n\ninterface ResolvedDaemon {\n baseUrl: string\n token: string\n}\n\nfunction resolveDaemon(opts: { node?: string; token?: string; config?: string }): ResolvedDaemon {\n let baseUrl = typeof opts.node === \"string\" ? opts.node : \"\"\n let token = typeof opts.token === \"string\" ? opts.token : \"\"\n if (!baseUrl || !token) {\n try {\n const cfg = loadDaemonConfig(opts.config)\n if (!baseUrl) baseUrl = cfg.dashboard?.daemonUrl || \"\"\n if (!token) token = cfg.dashboard?.token || \"\"\n } catch { /* fall back to defaults */ }\n }\n if (!baseUrl) baseUrl = \"http://localhost:18800\"\n return { baseUrl: baseUrl.replace(/\\/+$/, \"\"), token }\n}\n\nfunction authHeaders(token: string, contentType?: string): Record<string, string> {\n const h: Record<string, string> = {}\n if (token) h[\"Authorization\"] = `Bearer ${token}`\n if (contentType) h[\"Content-Type\"] = contentType\n return h\n}\n\nfunction fmtAge(ms: number): string {\n const s = Math.round((Date.now() - ms) / 1000)\n if (s < 60) return `${s}s`\n if (s < 3600) return `${Math.round(s / 60)}m`\n if (s < 86400) return `${Math.round(s / 3600)}h`\n return `${Math.round(s / 86400)}d`\n}\n\nfunction stateColor(s: string): (text: string) => string {\n if (s === \"busy\") return chalk.magenta\n if (s === \"warm-hot\") return chalk.green\n if (s === \"warm-cold\") return chalk.cyan\n if (s === \"idle\") return chalk.yellow\n if (s === \"dead\") return chalk.red\n return chalk.dim\n}\n\n// ---------------------------------------------------------------------------\n// agentx process list\n// ---------------------------------------------------------------------------\n\nprocess_\n .command(\"list\")\n .description(\"list every live persistent claude process\")\n .option(\"-c, --config <path>\", \"daemon config file\")\n .option(\"--node <url>\", \"daemon URL (defaults to dashboard.daemonUrl)\")\n .option(\"--token <token>\", \"bearer token (defaults to dashboard.token)\")\n .option(\"--json\", \"emit JSON\")\n .action(async (opts) => {\n const { baseUrl, token } = resolveDaemon(opts)\n let res: Response\n try {\n res = await fetch(`${baseUrl}/api/processes`, { headers: authHeaders(token) })\n } catch (e: any) {\n console.log(chalk.red(` could not reach daemon at ${baseUrl}: ${e.message || e}`))\n process.exit(1)\n }\n if (res.status === 503) {\n console.log(chalk.dim(` daemon at ${baseUrl} has no agents with persistentProcess: true`))\n return\n }\n if (!res.ok) {\n console.log(chalk.red(` HTTP ${res.status} from ${baseUrl}/processes`))\n process.exit(1)\n }\n const body = (await res.json()) as { processes: Array<Record<string, any>> }\n const procs = body.processes ?? []\n\n if (opts.json) {\n console.log(JSON.stringify(procs, null, 2))\n return\n }\n if (procs.length === 0) {\n console.log(chalk.dim(` (no processes)`))\n return\n }\n\n for (const p of procs) {\n const state = stateColor(p.state)(p.state.padEnd(9))\n const age = fmtAge(p.spawnedAt)\n const lastTurn = p.lastTurnAt ? fmtAge(p.lastTurnAt) + \" ago\" : \"—\"\n const tokens = p.lastInputTokens ? chalk.dim(`last_in=${p.lastInputTokens} tok`) : \"\"\n const session = p.claudeSessionId ? chalk.dim(`sess=${p.claudeSessionId.slice(0, 8)}…`) : chalk.dim(\"sess=—\")\n const pending = p.pendingTaskId ? chalk.cyan(`task=${String(p.pendingTaskId).slice(0, 12)}`) : \"\"\n console.log(\n `${state} ${chalk.bold(p.key.agentId)}${chalk.dim(\":\" + p.key.channel + \":\" + p.key.chatId)}` +\n ` ${chalk.dim(\"·\")} pid=${p.pid ?? \"?\"} age=${age} turn#${p.turnCount} last=${lastTurn} ${session} ${tokens} ${pending}`,\n )\n if (p.deadReason) console.log(` ${chalk.red(\"dead:\")} ${p.deadReason}`)\n }\n })\n\n// ---------------------------------------------------------------------------\n// agentx process kill\n// ---------------------------------------------------------------------------\n\nprocess_\n .command(\"kill <agentId> <channel> <chatId>\")\n .description(\"force-kill one persistent process (the next dispatch will spawn fresh)\")\n .option(\"-c, --config <path>\", \"daemon config file\")\n .option(\"--node <url>\", \"daemon URL (defaults to dashboard.daemonUrl)\")\n .option(\"--token <token>\", \"bearer token (defaults to dashboard.token)\")\n .option(\"-r, --reason <reason>\", \"kill reason (recorded on the dead-process snapshot)\", \"operator-cli\")\n .action(async (agentId: string, channel: string, chatId: string, opts) => {\n const { baseUrl, token } = resolveDaemon(opts)\n let res: Response\n try {\n res = await fetch(`${baseUrl}/api/processes/kill`, {\n method: \"POST\",\n headers: authHeaders(token, \"application/json\"),\n body: JSON.stringify({ agentId, channel, chatId, reason: opts.reason }),\n })\n } catch (e: any) {\n console.log(chalk.red(` could not reach daemon at ${baseUrl}: ${e.message || e}`))\n process.exit(1)\n }\n if (res.status === 503) {\n console.log(chalk.dim(` daemon has no persistent-process registry`))\n return\n }\n if (!res.ok) {\n let msg = `HTTP ${res.status}`\n try { const body = (await res.json()) as { error?: string }; if (body.error) msg += ` — ${body.error}` } catch { /* */ }\n console.log(chalk.red(` ${msg}`))\n process.exit(1)\n }\n console.log(chalk.green(` killed ${agentId}:${channel}:${chatId}`))\n })\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { existsSync, rmSync } from \"fs\"\nimport { resolve } from \"path\"\nimport { buildIndex, indexInfo, lexicalSearch } from \"@/rag/lexical-index\"\n\n// --- agentx rag ---\n//\n// Improvement plan #7 — embedding-free retrieval-augmented context.\n//\n// agentx rag add <agentId> <glob>... build/refresh an agent's index\n// agentx rag list list every agent's index status\n// agentx rag search <agentId> <query> query the index (debug surface)\n// agentx rag clear <agentId> delete the index\n//\n// Index format is JSON-serialized minisearch state. Tiny, portable,\n// rsyncable. Lives at .agentx/rag/<agentId>/index.json.\n\nexport const rag = new Command()\n .name(\"rag\")\n .description(\"manage per-agent lexical (BM25) RAG indexes (improvement plan #7)\")\n\nrag\n .command(\"add <agentId>\")\n .description(\"build or refresh an agent's lexical index from one or more globs\")\n .argument(\"<globs...>\", \"glob patterns relative to cwd (e.g. './docs/**/*.md')\")\n .option(\"-v, --verbose\", \"log each indexed file\")\n .action(async (agentId: string, globs: string[], opts) => {\n if (globs.length === 0) {\n console.log(chalk.red(` No globs provided. Example: agentx rag add ${agentId} './docs/**/*.md'`))\n process.exit(1)\n }\n const verbose = !!opts.verbose\n const start = Date.now()\n const r = await buildIndex(agentId, globs, { verbose })\n const ms = Date.now() - start\n console.log(chalk.green(` ✓ indexed ${r.docs} doc(s) for ${chalk.bold(agentId)} in ${ms}ms`))\n console.log(chalk.dim(` → ${r.path}`))\n })\n\nrag\n .command(\"list\")\n .description(\"list every agent's index, sizes, paths\")\n .option(\"-c, --cwd <path>\", \"search root\", process.cwd())\n .action(async (opts) => {\n const root = resolve(opts.cwd, \".agentx\", \"rag\")\n if (!existsSync(root)) {\n console.log(chalk.dim(\" (no indexes yet — try `agentx rag add <agentId> <glob>`)\"))\n return\n }\n const { readdirSync } = await import(\"fs\")\n const agents = readdirSync(root).filter((d) => existsSync(resolve(root, d, \"index.json\")))\n if (agents.length === 0) {\n console.log(chalk.dim(\" (no indexes)\"))\n return\n }\n for (const a of agents.sort()) {\n const info = indexInfo(a)\n console.log(` ${chalk.bold(a)} ${info.docs} doc(s) ${chalk.dim(info.path)}`)\n }\n })\n\nrag\n .command(\"search <agentId> <query>\")\n .description(\"query an agent's index — useful for debugging recall before the agent calls rag.lexical\")\n .option(\"-k, --k <n>\", \"top-k results\", \"5\")\n .option(\"--json\", \"emit JSON\")\n .action((agentId: string, query: string, opts) => {\n const k = parseInt(opts.k, 10) || 5\n const hits = lexicalSearch(agentId, query, { k })\n if (opts.json) {\n console.log(JSON.stringify(hits, null, 2))\n return\n }\n if (hits.length === 0) {\n const info = indexInfo(agentId)\n if (!info.exists) {\n console.log(chalk.red(` no index for ${agentId} — run \\`agentx rag add ${agentId} <glob>\\` first`))\n } else {\n console.log(chalk.dim(` (no hits in ${info.docs} indexed docs)`))\n }\n return\n }\n for (const h of hits) {\n console.log(` ${chalk.bold(h.title)} ${chalk.dim(`(${h.score.toFixed(2)})`)}`)\n console.log(` ${chalk.dim(h.path)}`)\n console.log(` ${chalk.dim(h.snippet.slice(0, 200))}`)\n }\n })\n\nrag\n .command(\"clear <agentId>\")\n .description(\"delete an agent's index\")\n .action((agentId: string) => {\n const path = resolve(process.cwd(), \".agentx\", \"rag\", agentId)\n if (!existsSync(path)) {\n console.log(chalk.dim(` no index for ${agentId} — nothing to clear`))\n return\n }\n rmSync(path, { recursive: true, force: true })\n console.log(chalk.green(` ✓ cleared index for ${agentId}`))\n })\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport prompts from \"prompts\"\nimport { loadDaemonConfig, type DaemonConfig } from \"@/daemon/config\"\nimport { BacklogStore, sourceBacklogId, type BacklogItem, type BacklogSource } from \"@/business/backlog-store\"\nimport { syncBacklogItemToSource, resolveAssigneesForSource } from \"@/business/backlog-sync\"\n\nexport const backlog = new Command()\n .name(\"backlog\")\n .description(\"manage the local backlog used by business workSource=backlog\")\n\n// ---------- Helpers ----------\n\ninterface Daemon {\n config: DaemonConfig\n storePath: string\n store: BacklogStore\n}\n\nfunction loadCtx(configPath?: string): Daemon {\n const config = loadDaemonConfig(configPath)\n const ws = (config as any).business?.workSource\n const storePath = ws?.type === \"backlog\" ? ws.path : \".agentx/backlog.md\"\n return { config, storePath, store: new BacklogStore(storePath) }\n}\n\nfunction fmtSource(s: BacklogItem[\"source\"]): string {\n if (!s) return chalk.dim(\"manual\")\n return chalk.cyan(`${s.type}:${s.project}#${s.iid}`)\n}\n\nfunction fmtStatus(status: BacklogItem[\"status\"]): string {\n return ({\n todo: chalk.gray(\"todo\"),\n doing: chalk.yellow(\"doing\"),\n blocked: chalk.red(\"blocked\"),\n done: chalk.green(\"done\"),\n })[status]\n}\n\n// ---------- list ----------\n\nbacklog\n .command(\"list\", { isDefault: true })\n .description(\"list backlog items\")\n .option(\"--status <status>\", \"filter by status (todo|doing|blocked|done)\")\n .option(\"--assignee <agent>\", \"filter by assignee\")\n .option(\"--source <type>\", \"filter by source.type (gitlab|github|manual)\")\n .option(\"-c, --config <path>\", \"config path\")\n .action(async (opts: { status?: string; assignee?: string; source?: string; config?: string }) => {\n const { store } = loadCtx(opts.config)\n let items = store.list()\n if (opts.status) items = items.filter((i) => i.status === opts.status)\n if (opts.assignee) items = items.filter((i) => i.assignee === opts.assignee)\n if (opts.source) {\n items = items.filter((i) =>\n opts.source === \"manual\" ? !i.source : i.source?.type === opts.source,\n )\n }\n\n if (!items.length) {\n console.log(chalk.dim(\" (no items)\"))\n return\n }\n\n console.log()\n for (const it of items) {\n const assignee = it.assignee ? chalk.magenta(`@${it.assignee}`) : chalk.dim(\"unassigned\")\n console.log(` ${fmtStatus(it.status).padEnd(7)} ${fmtSource(it.source)} ${assignee} ${it.title}`)\n if (it.source?.url) console.log(chalk.dim(` ${it.source.url}`))\n }\n console.log()\n console.log(chalk.dim(` ${items.length} item${items.length === 1 ? \"\" : \"s\"} — ${store.jsonPath()}`))\n })\n\n// ---------- claim ----------\n\nbacklog\n .command(\"claim <id> <agent>\")\n .description(\"assign an item to an agent and set status=doing\")\n .option(\"-c, --config <path>\", \"config path\")\n .action(async (id: string, agent: string, opts: { config?: string }) => {\n const ctx = loadCtx(opts.config)\n const item = ctx.store.findById(id)\n if (!item) {\n console.error(chalk.red(` item ${id} not found`))\n process.exit(1)\n }\n const updated = ctx.store.update(id, { assignee: agent, status: \"doing\" })\n console.log(chalk.green(` claimed: ${updated.title} -> ${agent}`))\n\n if (updated.source) {\n const usernames = resolveAssigneesForSource([agent], updated.source, ctx.config)\n const result = await syncBacklogItemToSource(updated, {\n assigneeUsernames: usernames,\n addLabels: [\"Doing\"],\n removeLabels: [\"To Do\"],\n }, ctx.config, (...a) => console.log(chalk.dim(\" sync:\"), ...a))\n console.log(result.ok\n ? chalk.dim(` synced -> ${result.url ?? updated.source.type}`)\n : chalk.yellow(` sync failed: ${result.error}`),\n )\n }\n })\n\n// ---------- done ----------\n\nbacklog\n .command(\"done <id>\")\n .description(\"mark an item as done; closes the upstream issue if linked\")\n .option(\"--note <text>\", \"comment to post upstream\")\n .option(\"--close\", \"also close the upstream issue (default: only labels change)\", false)\n .option(\"-c, --config <path>\", \"config path\")\n .action(async (id: string, opts: { note?: string; close?: boolean; config?: string }) => {\n const ctx = loadCtx(opts.config)\n const item = ctx.store.findById(id)\n if (!item) {\n console.error(chalk.red(` item ${id} not found`))\n process.exit(1)\n }\n const updated = ctx.store.update(id, { status: \"done\" })\n console.log(chalk.green(` done: ${updated.title}`))\n\n if (updated.source) {\n const result = await syncBacklogItemToSource(updated, {\n addLabels: [\"Done\"],\n removeLabels: [\"Doing\"],\n state: opts.close ? \"closed\" : undefined,\n note: opts.note,\n }, ctx.config, (...a) => console.log(chalk.dim(\" sync:\"), ...a))\n console.log(result.ok\n ? chalk.dim(` synced -> ${result.url ?? updated.source.type}`)\n : chalk.yellow(` sync failed: ${result.error}`),\n )\n }\n })\n\n// ---------- remove ----------\n\nbacklog\n .command(\"remove <id>\")\n .description(\"remove an item from the local backlog (does NOT touch upstream)\")\n .option(\"-c, --config <path>\", \"config path\")\n .action(async (id: string, opts: { config?: string }) => {\n const { store } = loadCtx(opts.config)\n const removed = store.remove(id)\n if (!removed) {\n console.error(chalk.red(` item ${id} not found`))\n process.exit(1)\n }\n console.log(chalk.green(` removed ${id}`))\n })\n\n// ---------- import ----------\n\nbacklog\n .command(\"import\")\n .description(\"import open issues from gitlab/github into the backlog (interactive)\")\n .option(\"--source <type>\", \"source type (gitlab|github)\")\n .option(\"--project <id>\", \"project id (group/repo for gitlab, owner/repo for github)\")\n .option(\"--assignee <agent>\", \"assign all imported items to this agentId\")\n .option(\"-c, --config <path>\", \"config path\")\n .action(async (opts: { source?: string; project?: string; assignee?: string; config?: string }) => {\n const ctx = loadCtx(opts.config)\n\n // Resolve which sources are configured.\n const gitlabReady = !!ctx.config.channels.gitlab?.token\n const githubReady = !!ctx.config.channels.github?.token\n if (!gitlabReady && !githubReady) {\n console.error(chalk.red(\" no source configured — set channels.gitlab.token or channels.github.token in agentx.json\"))\n process.exit(1)\n }\n\n let source = opts.source\n if (!source) {\n const choices = [\n gitlabReady && { title: \"GitLab\", value: \"gitlab\" },\n githubReady && { title: \"GitHub\", value: \"github\" },\n ].filter(Boolean) as Array<{ title: string; value: string }>\n const ans = await prompts({ type: \"select\", name: \"source\", message: \"Source\", choices })\n source = ans.source\n if (!source) return\n }\n\n if (source === \"gitlab\" && !gitlabReady) {\n console.error(chalk.red(\" channels.gitlab.token not configured\"))\n process.exit(1)\n }\n if (source === \"github\" && !githubReady) {\n console.error(chalk.red(\" channels.github.token not configured\"))\n process.exit(1)\n }\n\n // Project.\n let project = opts.project\n if (!project) {\n const candidates = source === \"gitlab\"\n ? collectGitlabProjects(ctx.config)\n : collectGithubProjects(ctx.config)\n if (candidates.length) {\n const ans = await prompts({\n type: \"autocomplete\",\n name: \"project\",\n message: \"Project (type to filter, or pick + then Enter for custom)\",\n choices: [\n ...candidates.map((p) => ({ title: p, value: p })),\n { title: \"(custom — type below)\", value: \"__CUSTOM__\" },\n ],\n })\n project = ans.project\n if (project === \"__CUSTOM__\") {\n const c = await prompts({ type: \"text\", name: \"p\", message: source === \"gitlab\" ? \"Group/path\" : \"owner/repo\" })\n project = c.p\n }\n } else {\n const c = await prompts({\n type: \"text\",\n name: \"p\",\n message: source === \"gitlab\" ? \"Group/path\" : \"owner/repo\",\n })\n project = c.p\n }\n }\n if (!project) return\n\n // Optional search filter pre-fetch (server-side).\n const searchAns = await prompts({\n type: \"text\",\n name: \"search\",\n message: \"Search filter (optional — leave empty for all open)\",\n })\n const search = (searchAns.search || \"\").trim()\n\n console.log(chalk.dim(` fetching open issues from ${source}:${project}${search ? ` (search: ${search})` : \"\"}…`))\n const issues = source === \"gitlab\"\n ? await fetchGitlabIssues(ctx.config, project, search)\n : await fetchGithubIssues(ctx.config, project, search)\n\n if (!issues.length) {\n console.log(chalk.yellow(\" no open issues matched\"))\n return\n }\n console.log(chalk.dim(` ${issues.length} open issue${issues.length === 1 ? \"\" : \"s\"}`))\n\n const projectId = project\n // Mark already-imported items so the user can see them.\n const existing = new Set(ctx.store.list().map((i) => i.id))\n const choices = issues.map((iss) => {\n const id = sourceBacklogId({ type: source as any, project: projectId, iid: iss.iid, url: iss.url })\n const already = existing.has(id)\n const labels = iss.labels.length ? ` [${iss.labels.slice(0, 3).join(\",\")}]` : \"\"\n return {\n title: `#${iss.iid} ${iss.title}${labels}${already ? chalk.dim(\" (already imported)\") : \"\"}`,\n value: iss,\n disabled: already,\n }\n })\n\n const pick = await prompts({\n type: \"autocompleteMultiselect\",\n name: \"selected\",\n message: \"Pick issues to import (space to toggle, Enter to confirm)\",\n instructions: false,\n choices,\n min: 1,\n })\n\n const selected = (pick.selected || []) as ImportIssue[]\n if (!selected.length) {\n console.log(chalk.dim(\" nothing selected\"))\n return\n }\n\n const toAdd = selected.map((iss): Omit<BacklogItem, \"createdAt\" | \"updatedAt\"> => {\n const src: BacklogSource = {\n type: source as \"gitlab\" | \"github\",\n host: source === \"gitlab\" ? hostnameFromGitlab(ctx.config) : undefined,\n project: projectId,\n iid: iss.iid,\n url: iss.url,\n }\n return {\n id: sourceBacklogId(src),\n title: iss.title,\n description: iss.description,\n assignee: opts.assignee || iss.assignee,\n labels: iss.labels,\n milestone: iss.milestone,\n status: \"todo\",\n source: src,\n importedAt: new Date().toISOString(),\n }\n })\n\n const added = ctx.store.addMany(toAdd)\n console.log(chalk.green(` imported ${added.length} item${added.length === 1 ? \"\" : \"s\"}`))\n for (const it of added) {\n console.log(chalk.dim(` ${it.id} — ${it.title}`))\n }\n })\n\n// ---------- Source helpers ----------\n\ninterface ImportIssue {\n iid: number\n title: string\n description?: string\n labels: string[]\n milestone?: string\n assignee?: string\n url: string\n}\n\nfunction hostnameFromGitlab(daemon: DaemonConfig): string | undefined {\n const host = daemon.channels.gitlab?.host\n if (!host) return undefined\n return host.replace(/^https?:\\/\\//, \"\").replace(/\\/+$/, \"\")\n}\n\nfunction collectGitlabProjects(daemon: DaemonConfig): string[] {\n const set = new Set<string>()\n for (const r of daemon.channels.gitlab?.routes ?? []) if (r.project && r.project !== \"*\") set.add(r.project)\n const ws = (daemon as any).business?.workSource\n if (ws?.type === \"gitlab\") for (const p of ws.projects ?? []) set.add(p)\n for (const p of (daemon as any).business?.projects ?? []) {\n if (p?.id && p.id.includes(\"/\")) set.add(p.id)\n }\n return [...set].sort()\n}\n\nfunction collectGithubProjects(daemon: DaemonConfig): string[] {\n const set = new Set<string>()\n for (const r of daemon.channels.github?.routes ?? []) if (r.repo && r.repo !== \"*\") set.add(r.repo)\n return [...set].sort()\n}\n\nasync function fetchGitlabIssues(daemon: DaemonConfig, project: string, search: string): Promise<ImportIssue[]> {\n const gl = daemon.channels.gitlab!\n const params = new URLSearchParams({\n state: \"opened\",\n scope: \"all\",\n per_page: \"100\",\n order_by: \"updated_at\",\n sort: \"desc\",\n })\n if (search) params.set(\"search\", search)\n\n const res = await fetch(\n `${gl.host}/api/v4/projects/${encodeURIComponent(project)}/issues?${params}`,\n { headers: { \"PRIVATE-TOKEN\": gl.token! } },\n )\n if (!res.ok) {\n throw new Error(`GitLab ${res.status}: ${await res.text().catch(() => \"\")}`)\n }\n const arr: any = await res.json()\n if (!Array.isArray(arr)) return []\n return arr.map((i: any): ImportIssue => ({\n iid: i.iid,\n title: i.title,\n description: i.description || undefined,\n labels: Array.isArray(i.labels) ? i.labels.map((l: any) => (typeof l === \"string\" ? l : l.name)) : [],\n milestone: i.milestone?.title || undefined,\n assignee: i.assignee?.username || i.assignees?.[0]?.username || undefined,\n url: i.web_url,\n }))\n}\n\nasync function fetchGithubIssues(daemon: DaemonConfig, project: string, search: string): Promise<ImportIssue[]> {\n const gh = daemon.channels.github!\n const headers = {\n \"Authorization\": `Bearer ${gh.token!}`,\n \"Accept\": \"application/vnd.github+json\",\n \"X-GitHub-Api-Version\": \"2022-11-28\",\n }\n\n // GitHub: separate `search` API for text filter (covers title+body); without\n // a query, list issues directly. Search API includes pull requests in `issues`,\n // so filter `is:issue` explicitly.\n let url: string\n if (search) {\n const q = `repo:${project} is:issue is:open ${search}`\n url = `https://api.github.com/search/issues?q=${encodeURIComponent(q)}&per_page=100&sort=updated&order=desc`\n const res = await fetch(url, { headers })\n if (!res.ok) throw new Error(`GitHub ${res.status}: ${await res.text().catch(() => \"\")}`)\n const data: any = await res.json()\n const items: any[] = data.items ?? []\n return items.map(githubMap)\n }\n\n url = `https://api.github.com/repos/${project}/issues?state=open&per_page=100&sort=updated&direction=desc`\n const res = await fetch(url, { headers })\n if (!res.ok) throw new Error(`GitHub ${res.status}: ${await res.text().catch(() => \"\")}`)\n const arr: any = await res.json()\n if (!Array.isArray(arr)) return []\n // /issues returns PRs too; drop them.\n return arr.filter((i: any) => !i.pull_request).map(githubMap)\n}\n\nfunction githubMap(i: any): ImportIssue {\n return {\n iid: i.number,\n title: i.title,\n description: i.body || undefined,\n labels: Array.isArray(i.labels) ? i.labels.map((l: any) => (typeof l === \"string\" ? l : l.name)) : [],\n milestone: i.milestone?.title || undefined,\n assignee: i.assignee?.login || i.assignees?.[0]?.login || undefined,\n url: i.html_url,\n }\n}\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { existsSync, readFileSync } from \"fs\"\nimport { resolve } from \"path\"\nimport prompts from \"prompts\"\nimport { applyConfigMutation, setAtPath, getAtPath, unsetAtPath } from \"@/daemon/config-mutator\"\nimport { expandEnvVars } from \"@/daemon/config\"\nimport { parseEnglishToCron, slugifyScheduleId } from \"@/utils/nl-cron\"\n\n// --- agentx schedule — natural-language cron layer ---\n//\n// Writes the same `crons.<id>` shape the low-level `agentx cron` command\n// manages, but takes English phrases and a --do prompt instead of raw cron\n// syntax. Both verbs coexist; `cron` is the escape hatch.\n\ntype OnErrorValue = \"log\" | \"notify\" | \"disable\"\n\nfunction loadRawConfig(configPath?: string): any {\n const p = configPath || resolve(process.cwd(), \"agentx.json\")\n if (!existsSync(p)) {\n console.log(chalk.red(` No config at ${p}. Run: agentx init`))\n process.exit(1)\n }\n return JSON.parse(readFileSync(p, \"utf-8\"))\n}\n\nfunction parseOnError(flag: string | undefined): OnErrorValue[] {\n if (!flag) return [\"log\"]\n return flag\n .split(\",\")\n .map((s) => s.trim().toLowerCase())\n .filter((s): s is OnErrorValue => s === \"log\" || s === \"notify\" || s === \"disable\")\n}\n\nasync function resolveNotifyTarget(\n flag: string | undefined,\n cfg: any,\n): Promise<{ channel: string; chatId: string; accountId?: string } | undefined> {\n if (!flag) return undefined\n if (flag === \"me\") {\n const dest = cfg?.notifications?.destination\n if (dest?.channel && dest?.chatId) {\n return { channel: dest.channel, chatId: dest.chatId, accountId: dest.accountId }\n }\n console.log(chalk.yellow(\" --notify me: no notifications.destination set yet.\"))\n const { channel, chatId, accountId } = await prompts([\n { type: \"text\", name: \"channel\", message: \"Destination channel (telegram/whatsapp/discord):\" },\n { type: \"text\", name: \"chatId\", message: \"Destination chatId:\" },\n { type: \"text\", name: \"accountId\", message: \"Account id (optional):\" },\n ])\n if (!channel || !chatId) return undefined\n return { channel, chatId, accountId: accountId || undefined }\n }\n // shorthand channel:chatId[:account]\n const parts = flag.split(\":\")\n if (parts.length >= 2) {\n return { channel: parts[0], chatId: parts[1], accountId: parts[2] }\n }\n console.log(chalk.red(` Unrecognized --notify value: ${flag} (use \"me\" or \"channel:chatId[:account]\")`))\n return undefined\n}\n\nexport const schedule = new Command()\n .name(\"schedule\")\n .description(\"schedule agents with natural-language cron: \\\"every morning at 9\\\" --agent devops --do \\\"Post standup\\\"\")\n\n// ── agentx schedule \"every morning at 9\" --agent X --do \"...\" [--notify me] ──\nschedule\n .argument(\"[when]\", 'natural-language schedule, e.g. \"every morning at 9\"')\n .option(\"--agent <id>\", \"agent to run\")\n .option(\"--do <prompt>\", \"prompt to run at each tick (required unless --id exists)\")\n .option(\"--id <name>\", \"explicit cron id (default: auto-slug of <when>-<agent>)\")\n .option(\"--notify <target>\", '\"me\" (use notifications.destination) or \"channel:chatId[:accountId]\"')\n .option(\"--on-error <modes>\", 'comma list of \"log|notify|disable\" (default: log; notify implies \"notify\")')\n .option(\"--timezone <tz>\", \"IANA timezone (default: Africa/Tunis)\", \"Africa/Tunis\")\n .option(\"--timeout <seconds>\", \"max run time\", \"600\")\n .option(\"--model <model>\", \"override model\")\n .option(\"--disabled\", \"create but leave disabled\")\n .option(\"--dry-run\", \"print what would be written without writing\")\n .action(async (when: string | undefined, opts) => {\n if (!when) {\n schedule.help()\n return\n }\n if (!opts.agent) {\n console.log(chalk.red(' --agent is required. Try: agentx schedule \"every morning at 9\" --agent devops --do \"...\"'))\n process.exit(1)\n }\n if (!opts.do && !opts.id) {\n console.log(chalk.red(' --do \"<prompt>\" is required'))\n process.exit(1)\n }\n\n const parsed = parseEnglishToCron(when)\n if (!parsed) {\n console.log(chalk.red(` Couldn't parse: \"${when}\"`))\n console.log(chalk.dim(` Try: \"every morning at 9\", \"weekdays at 6pm\", \"every 15 minutes\",`))\n console.log(chalk.dim(` \"every monday at 10am\", \"1st of every month at noon\",`))\n console.log(chalk.dim(` \"daily at 9:30am\", \"every hour\", \"hourly\"`))\n process.exit(1)\n }\n\n const cfg = loadRawConfig(opts.config)\n const expanded = expandEnvVars(cfg)\n\n // Validate agent exists\n if (!cfg.agents?.[opts.agent]) {\n console.log(chalk.red(` Agent \"${opts.agent}\" not found in agentx.json`))\n console.log(chalk.dim(` Available: ${Object.keys(cfg.agents || {}).join(\", \") || \"(none)\"}`))\n process.exit(1)\n }\n\n const onErrorModes = parseOnError(opts.onError)\n const notify = await resolveNotifyTarget(opts.notify, expanded)\n // If --notify is set and user didn't explicitly ask for \"notify\" in onError, add it.\n if (notify && !onErrorModes.includes(\"notify\")) onErrorModes.push(\"notify\")\n\n const id: string = opts.id || slugifyScheduleId(parsed.matched, opts.agent)\n\n const job: any = {\n enabled: !opts.disabled,\n schedule: parsed.cron,\n timezone: opts.timezone,\n agent: opts.agent,\n prompt: opts.do,\n timeout: parseInt(opts.timeout, 10),\n onError: onErrorModes,\n }\n if (opts.model) job.model = opts.model\n if (notify) job.notify = notify\n\n const result = await applyConfigMutation(\n (c) => setAtPath(c, `crons.${id}`, job),\n { configPath: opts.config, dryRun: !!opts.dryRun },\n )\n\n if (!result.success) {\n console.log(chalk.red(` ✗ ${result.error}`))\n process.exit(1)\n }\n\n const verb = opts.dryRun ? \"would add\" : \"Added\"\n console.log(chalk.green(` ✓ ${verb} cron ${chalk.cyan(id)}`))\n console.log(chalk.dim(` Schedule: ${parsed.cron} (${parsed.human}, ${opts.timezone})`))\n console.log(chalk.dim(` Agent: ${opts.agent}`))\n if (notify) console.log(chalk.dim(` Notify: ${notify.channel} ${notify.chatId}`))\n if (onErrorModes.length) console.log(chalk.dim(` On error: ${onErrorModes.join(\", \")}`))\n if (!opts.dryRun && result.reloaded) console.log(chalk.dim(\" Daemon hot-reloaded.\"))\n })\n\n// ── agentx schedule list ──\nschedule\n .command(\"list\")\n .alias(\"ls\")\n .description(\"list all scheduled jobs with human-readable descriptions\")\n .option(\"-c, --config <path>\", \"path to agentx.json\")\n .action(async (opts) => {\n const cfg = loadRawConfig(opts.config)\n const crons = cfg.crons || {}\n const entries = Object.entries(crons)\n if (!entries.length) {\n console.log(chalk.dim(\" No scheduled jobs\"))\n return\n }\n console.log()\n for (const [id, def] of entries as any) {\n const tag = def.enabled ? chalk.green(\"●\") : chalk.dim(\"○\")\n let human = def.schedule\n try {\n const cronstrue = (await import(\"cronstrue\")).default\n human = cronstrue.toString(def.schedule, { use24HourTimeFormat: false })\n } catch { /* keep raw */ }\n console.log(` ${tag} ${chalk.cyan(id.padEnd(32))} ${chalk.dim(def.schedule.padEnd(14))} ${chalk.dim(\"→\")} ${def.agent}`)\n console.log(chalk.dim(` ${human} (${def.timezone || \"UTC\"})`))\n if (def.notify) {\n console.log(chalk.dim(` notify: ${def.notify.channel} ${def.notify.chatId}`))\n }\n }\n console.log()\n })\n\n// ── agentx schedule on/off <id> ──\nfor (const [verb, enabled] of [[\"on\", true], [\"off\", false]] as const) {\n schedule\n .command(`${verb} <id>`)\n .description(`${enabled ? \"enable\" : \"disable\"} a scheduled job`)\n .action(async (id: string) => {\n const result = await applyConfigMutation((cfg) => {\n if (!getAtPath(cfg, `crons.${id}`)) {\n throw new Error(`cron \"${id}\" not found`)\n }\n setAtPath(cfg, `crons.${id}.enabled`, enabled)\n })\n if (!result.success) {\n console.log(chalk.red(` ✗ ${result.error}`))\n process.exit(1)\n }\n console.log(chalk.green(` ✓ ${id} ${enabled ? \"enabled\" : \"disabled\"}`))\n if (result.reloaded) console.log(chalk.dim(\" Daemon hot-reloaded.\"))\n })\n}\n\n// ── agentx schedule remove <id> ──\nschedule\n .command(\"remove <id>\")\n .alias(\"rm\")\n .description(\"remove a scheduled job\")\n .action(async (id: string) => {\n const result = await applyConfigMutation((cfg) => {\n if (!getAtPath(cfg, `crons.${id}`)) {\n throw new Error(`cron \"${id}\" not found`)\n }\n unsetAtPath(cfg, `crons.${id}`)\n })\n if (!result.success) {\n console.log(chalk.red(` ✗ ${result.error}`))\n process.exit(1)\n }\n console.log(chalk.green(` ✓ ${id} removed`))\n if (result.reloaded) console.log(chalk.dim(\" Daemon hot-reloaded.\"))\n })\n\n// ── agentx schedule parse \"<english>\" — preview a parse without writing ──\nschedule\n .command(\"parse <when...>\")\n .description(\"preview a natural-language parse without writing anything\")\n .action((words: string[]) => {\n const when = words.join(\" \")\n const r = parseEnglishToCron(when)\n if (!r) {\n console.log(chalk.red(` ✗ could not parse: \"${when}\"`))\n process.exit(1)\n }\n console.log(chalk.green(` \"${when}\"`))\n console.log(chalk.dim(` → ${r.cron}`))\n console.log(chalk.dim(` → ${r.human}`))\n })\n","import cronstrue from \"cronstrue\"\n\n// --- Natural-language → cron ---\n//\n// Hand-coded pattern matcher for the dozen English phrasings people actually\n// type. Covers every morning/evening, weekdays/weekends, every N minutes,\n// every Monday, daily at X, first of every month, etc.\n//\n// Returns `null` for anything unrecognized rather than guessing — the caller\n// should surface the error to the user with a list of supported phrasings.\n\nexport interface NlCronResult {\n /** Standard 5-field cron expression. */\n cron: string\n /** Human-readable rendering from cronstrue. */\n human: string\n /** The bit of input that matched (useful for error messages + id generation). */\n matched: string\n}\n\ninterface Time { h: number; m: number }\n\nconst DAY_OF_WEEK: Record<string, number> = {\n sun: 0, sunday: 0,\n mon: 1, monday: 1,\n tue: 2, tuesday: 2, tues: 2,\n wed: 3, wednesday: 3,\n thu: 4, thursday: 4, thurs: 4,\n fri: 5, friday: 5,\n sat: 6, saturday: 6,\n}\n\nconst DEFAULT_TIMES: Record<string, Time> = {\n morning: { h: 9, m: 0 },\n afternoon: { h: 14, m: 0 },\n evening: { h: 18, m: 0 },\n night: { h: 22, m: 0 },\n noon: { h: 12, m: 0 },\n midnight: { h: 0, m: 0 },\n}\n\nfunction humanize(cron: string): string {\n try {\n return cronstrue.toString(cron, { use24HourTimeFormat: false })\n } catch {\n return cron\n }\n}\n\n/**\n * Pull out the first \"at HH(:MM)?(am|pm)?\" clause. Also accepts bare\n * \"noon\" / \"midnight\". Returns null if nothing time-like is present.\n */\nfunction extractTime(text: string): Time | null {\n // \"at noon\" / \"at midnight\" / standalone \"noon\" / \"midnight\"\n if (/\\b(noon|midday)\\b/.test(text)) return DEFAULT_TIMES.noon\n if (/\\bmidnight\\b/.test(text)) return DEFAULT_TIMES.midnight\n\n // \"at 9\" / \"at 9am\" / \"at 9:30am\" / \"at 14:30\" / \"by 9am\"\n const m = text.match(/\\b(?:at|by|@)\\s*(\\d{1,2})(?::(\\d{2}))?\\s*(am|pm)?\\b/)\n if (m) {\n let h = parseInt(m[1], 10)\n const min = m[2] ? parseInt(m[2], 10) : 0\n const ampm = m[3]\n if (ampm === \"pm\" && h < 12) h += 12\n if (ampm === \"am\" && h === 12) h = 0\n if (h > 23 || min > 59) return null\n return { h, m: min }\n }\n\n return null\n}\n\n/**\n * Main entry. Returns `null` if we don't recognize the phrasing.\n */\nexport function parseEnglishToCron(raw: string): NlCronResult | null {\n const text = raw.trim().toLowerCase()\n if (!text) return null\n\n // ── every N minutes / every minute ─────────────────────────────────\n let m: RegExpMatchArray | null\n if ((m = text.match(/\\bevery\\s+(\\d+)\\s*(minutes|mins|m)\\b/))) {\n const n = parseInt(m[1], 10)\n if (n < 1 || n > 59) return null\n return { cron: `*/${n} * * * *`, human: humanize(`*/${n} * * * *`), matched: m[0] }\n }\n if (/\\bevery\\s+minute\\b/.test(text)) {\n return { cron: `* * * * *`, human: humanize(`* * * * *`), matched: \"every minute\" }\n }\n\n // ── every hour / hourly / every N hours ────────────────────────────\n if ((m = text.match(/\\bevery\\s+(\\d+)\\s*(hours|hrs|h)\\b/))) {\n const n = parseInt(m[1], 10)\n if (n < 1 || n > 23) return null\n return { cron: `0 */${n} * * *`, human: humanize(`0 */${n} * * *`), matched: m[0] }\n }\n if (/\\b(every hour|hourly)\\b/.test(text)) {\n return { cron: `0 * * * *`, human: humanize(`0 * * * *`), matched: \"every hour\" }\n }\n\n const time = extractTime(text)\n\n // ── keyword-default times (every morning/evening/…) ────────────────\n let dayKeywordTime: Time | null = null\n for (const [kw, t] of Object.entries(DEFAULT_TIMES)) {\n if (kw === \"noon\" || kw === \"midnight\") continue\n if (new RegExp(`\\\\b(every\\\\s+)?${kw}s?\\\\b`).test(text)) {\n dayKeywordTime = t\n break\n }\n }\n const resolvedTime = time || dayKeywordTime\n // If we have no time at all, we can't build a cron for most patterns.\n\n // ── first / nth day of every month ─────────────────────────────────\n const domMatch = text.match(/\\b(first|1st|2nd|3rd|last|(\\d+)(?:st|nd|rd|th)?)\\s+(day\\s+)?of\\s+(every|each|the)\\s+month\\b/)\n if (domMatch) {\n const tok = domMatch[1]\n let dom = 1\n if (tok === \"last\") return null // cron doesn't cleanly support L; punt\n else if (/^\\d+(st|nd|rd|th)?$/.test(tok)) dom = parseInt(tok, 10)\n else if (tok === \"first\" || tok === \"1st\") dom = 1\n else if (tok === \"2nd\") dom = 2\n else if (tok === \"3rd\") dom = 3\n if (dom < 1 || dom > 31) return null\n const t = resolvedTime || { h: 9, m: 0 }\n const cron = `${t.m} ${t.h} ${dom} * *`\n return { cron, human: humanize(cron), matched: domMatch[0] }\n }\n\n // ── named days of the week (mon, tue…) ─────────────────────────────\n // \"every monday at 9\" / \"on mondays\" / \"every monday and friday at 10\"\n //\n // We require a structural anchor (\"every\"/\"on\"/\"each\") before the first day\n // to avoid false positives like \"sun aligns with mars\".\n const dayTokens: number[] = []\n const dayWordsAlt = Object.keys(DAY_OF_WEEK).join(\"|\")\n const anchorRe = new RegExp(`\\\\b(?:every|on|each|by)\\\\s+((?:${dayWordsAlt})s?(?:\\\\s*(?:,|and|&)\\\\s*(?:${dayWordsAlt})s?)*)\\\\b`)\n const anchor = text.match(anchorRe)\n if (anchor) {\n const list = anchor[1]\n for (const w of Object.keys(DAY_OF_WEEK)) {\n if (new RegExp(`\\\\b${w}s?\\\\b`).test(list)) {\n const n = DAY_OF_WEEK[w]\n if (!dayTokens.includes(n)) dayTokens.push(n)\n }\n }\n }\n if (dayTokens.length) {\n const t = resolvedTime || { h: 9, m: 0 }\n dayTokens.sort((a, b) => a - b)\n const dow = dayTokens.join(\",\")\n const cron = `${t.m} ${t.h} * * ${dow}`\n return { cron, human: humanize(cron), matched: `on ${dow}` }\n }\n\n // ── weekdays / weekends ────────────────────────────────────────────\n if (/\\b(weekday|workday|business day)s?\\b/.test(text)) {\n const t = resolvedTime || { h: 9, m: 0 }\n const cron = `${t.m} ${t.h} * * 1-5`\n return { cron, human: humanize(cron), matched: \"weekdays\" }\n }\n if (/\\bweekends?\\b/.test(text)) {\n const t = resolvedTime || { h: 9, m: 0 }\n const cron = `${t.m} ${t.h} * * 0,6`\n return { cron, human: humanize(cron), matched: \"weekends\" }\n }\n\n // ── daily / every day ──────────────────────────────────────────────\n if (/\\b(every day|daily|each day)\\b/.test(text) || dayKeywordTime) {\n const t = resolvedTime || { h: 9, m: 0 }\n const cron = `${t.m} ${t.h} * * *`\n return { cron, human: humanize(cron), matched: dayKeywordTime ? (Object.entries(DEFAULT_TIMES).find(([, v]) => v === dayKeywordTime)?.[0] || \"daily\") : \"daily\" }\n }\n\n // ── bare \"at 9am\" → assume daily ───────────────────────────────────\n if (time) {\n const cron = `${time.m} ${time.h} * * *`\n return { cron, human: humanize(cron), matched: `at ${time.h}:${String(time.m).padStart(2, \"0\")}` }\n }\n\n return null\n}\n\n/** Build a stable slug for cron id from the matched phrase + agent. */\nexport function slugifyScheduleId(phrase: string, agent: string): string {\n const slug = phrase\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\")\n .slice(0, 40)\n return `${slug || \"job\"}-${agent}`\n}\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { connectTelegram } from \"@/connect/telegram\"\nimport { connectDiscord } from \"@/connect/discord\"\nimport { connectWhatsApp } from \"@/connect/whatsapp\"\nimport { invite as meshInvite, join as meshJoin } from \"@/connect/mesh\"\n\n// --- agentx connect <channel> ---\n//\n// Unified browser-cooperating pairing flow. Replaces manual \"paste token\n// into .env, edit agentx.json, restart daemon\" onboarding.\n//\n// V1 surfaces two channels: telegram (highest-pain) and mesh (only remaining\n// manual .env step in Journey 8). WhatsApp / Discord / GitLab follow.\n\nexport const connect = new Command()\n .name(\"connect\")\n .description(\"connect a channel or mesh peer — no manual file editing required\")\n\nconnect\n .command(\"telegram\")\n .description(\"pair a Telegram bot — persists token in .env, binds to an agent, auto-detects default chat\")\n .option(\"--agent <id>\", \"agent to bind the bot to (skips the prompt)\")\n .option(\"--account <name>\", \"account label in channels.telegram.accounts (defaults to agent id)\")\n .option(\"--skip-chat-capture\", \"don't listen for the first message after pairing\")\n .option(\"-c, --config <path>\", \"path to agentx.json\")\n .action(async (opts) => {\n await connectTelegram({\n agent: opts.agent,\n account: opts.account,\n configPath: opts.config,\n skipChatCapture: !!opts.skipChatCapture,\n })\n })\n\nconnect\n .command(\"discord\")\n .description(\"pair a Discord bot — verify token, emit install URL, save to .env\")\n .option(\"--agent <id>\", \"agent to bind the bot to\")\n .option(\"-c, --config <path>\", \"path to agentx.json\")\n .action(async (opts) => {\n await connectDiscord({ agent: opts.agent, configPath: opts.config })\n })\n\nconnect\n .command(\"whatsapp\")\n .description(\"pair WhatsApp via QR (prints in terminal), then writes channels.whatsapp config\")\n .option(\"--agent <id>\", \"default agent for inbound messages\")\n .option(\"--session-dir <path>\", \"session directory (default: .agentx/whatsapp-sessions)\")\n .option(\"--skip-pair\", \"skip QR pairing (use when session already exists)\")\n .option(\"-c, --config <path>\", \"path to agentx.json\")\n .action(async (opts) => {\n await connectWhatsApp({\n agent: opts.agent,\n sessionDir: opts.sessionDir,\n skipPair: !!opts.skipPair,\n configPath: opts.config,\n })\n })\n\nconst mesh = connect\n .command(\"mesh\")\n .description(\"mesh invite + join — replaces manual MESH_TOKEN copy-paste\")\n\nmesh\n .command(\"invite\")\n .description(\"emit a single-use join link for another AgentX node\")\n .option(\"--url <url>\", \"this node's URL as peers should reach it (Tailscale IP etc.)\")\n .option(\"-c, --config <path>\", \"path to agentx.json\")\n .action(async (opts) => {\n await meshInvite({ url: opts.url, configPath: opts.config })\n })\n\nmesh\n .command(\"join <link>\")\n .description(\"accept an invite link from another AgentX node\")\n .option(\"-c, --config <path>\", \"path to agentx.json\")\n .action(async (link: string, opts) => {\n await meshJoin(link, { configPath: opts.config })\n })\n\n// Default help: when the user types `agentx connect` with no subcommand, nudge.\nconnect.action(() => {\n console.log()\n console.log(chalk.bold(\" agentx connect — which channel?\"))\n console.log()\n console.log(` ${chalk.cyan(\"agentx connect telegram\")} — pair a Telegram bot`)\n console.log(` ${chalk.cyan(\"agentx connect discord\")} — pair a Discord bot, emit install URL`)\n console.log(` ${chalk.cyan(\"agentx connect whatsapp\")} — pair WhatsApp via QR`)\n console.log(` ${chalk.cyan(\"agentx connect mesh invite\")} — emit a mesh join link for another node`)\n console.log(` ${chalk.cyan(\"agentx connect mesh join <link>\")} — accept a mesh invite`)\n console.log()\n console.log(chalk.dim(\" GitLab connect is the next slice.\"))\n console.log()\n})\n","import chalk from \"chalk\"\nimport prompts from \"prompts\"\nimport { applyConfigMutation, setAtPath, getAtPath } from \"@/daemon/config-mutator\"\nimport { setDotEnv } from \"@/utils/dotenv-mutator\"\n\n// --- agentx connect telegram ---\n//\n// Replaces the channel-add path for Telegram. The improvements over the old\n// prompt-for-everything flow:\n// 1. Token is persisted to .env under TG_<ACCOUNT>_BOT_TOKEN, never inline\n// in agentx.json. The config holds only `${TG_<ACCOUNT>_BOT_TOKEN}`.\n// 2. After pairing, the CLI polls getUpdates until the user sends a message\n// from the chat they want to be \"me\". The first inbound message's chatId\n// is captured and written to notifications.destination so `--notify me`\n// just works.\n// 3. A quick getMe verifies the token before anything is written. Invalid\n// tokens never reach the config.\n\nconst BOTFATHER_URL = \"https://t.me/BotFather\"\n\nasync function getMe(token: string): Promise<{ username: string; first_name: string; id: number } | null> {\n try {\n const res = await fetch(`https://api.telegram.org/bot${token}/getMe`, { signal: AbortSignal.timeout(8000) })\n if (!res.ok) return null\n const j: any = await res.json()\n return j?.ok ? j.result : null\n } catch { return null }\n}\n\nasync function pollFirstMessage(token: string, timeoutMs: number): Promise<{ chatId: number; chatTitle?: string; from: string } | null> {\n const deadline = Date.now() + timeoutMs\n let offset = 0\n // Learn the current offset so we only catch fresh messages.\n try {\n const r = await fetch(`https://api.telegram.org/bot${token}/getUpdates?offset=-1&timeout=0`, { signal: AbortSignal.timeout(5000) })\n const j: any = await r.json()\n if (j?.result?.length) offset = j.result[0].update_id + 1\n } catch { /* start from 0 */ }\n\n while (Date.now() < deadline) {\n try {\n const res = await fetch(\n `https://api.telegram.org/bot${token}/getUpdates?offset=${offset}&timeout=10`,\n { signal: AbortSignal.timeout(15000) },\n )\n const j: any = await res.json()\n for (const u of j?.result || []) {\n offset = Math.max(offset, u.update_id + 1)\n const msg = u.message || u.edited_message || u.channel_post\n if (msg?.chat?.id) {\n return {\n chatId: msg.chat.id,\n chatTitle: msg.chat.title || msg.chat.username || msg.chat.first_name,\n from: msg.from?.first_name || msg.from?.username || \"unknown\",\n }\n }\n }\n } catch { /* transient; retry */ }\n }\n return null\n}\n\nexport interface ConnectTelegramOpts {\n agent?: string\n account?: string\n configPath?: string\n skipChatCapture?: boolean\n}\n\nexport async function connectTelegram(opts: ConnectTelegramOpts = {}): Promise<void> {\n console.log()\n console.log(chalk.bold(\" Connect Telegram\"))\n console.log()\n console.log(chalk.dim(` 1. Open ${BOTFATHER_URL}`))\n console.log(chalk.dim(` /newbot (or /mybots → pick existing → API Token)`))\n console.log(chalk.dim(` 2. Copy the HTTP API token — looks like 123456789:ABCdef...`))\n console.log()\n\n const { openBrowser } = await prompts({\n type: \"confirm\",\n name: \"openBrowser\",\n message: \"Open BotFather in your browser?\",\n initial: true,\n })\n if (openBrowser) {\n try {\n const { spawn } = await import(\"child_process\")\n const opener = process.platform === \"darwin\" ? \"open\" : process.platform === \"win32\" ? \"start\" : \"xdg-open\"\n spawn(opener, [BOTFATHER_URL], { stdio: \"ignore\", detached: true }).unref()\n } catch { /* non-fatal */ }\n }\n\n const { token } = await prompts({\n type: \"password\",\n name: \"token\",\n message: \"Paste the bot token from BotFather:\",\n validate: (t: string) => /^\\d+:[A-Za-z0-9_-]{20,}$/.test(t.trim()) || \"That doesn't look like a Telegram token\",\n })\n if (!token) { console.log(chalk.red(\" Aborted\")); process.exit(1) }\n\n // --- Verify token ---\n process.stdout.write(\" Verifying token... \")\n const me = await getMe(token.trim())\n if (!me) {\n console.log(chalk.red(\"✗ invalid or revoked\"))\n process.exit(1)\n }\n console.log(chalk.green(`✓ ${me.first_name} (@${me.username})`))\n\n // --- Existing config ---\n const { readFileSync, existsSync } = await import(\"fs\")\n const { resolve } = await import(\"path\")\n const cfgPath = opts.configPath || resolve(process.cwd(), \"agentx.json\")\n if (!existsSync(cfgPath)) {\n console.log(chalk.red(` No agentx.json at ${cfgPath}. Run: agentx init`))\n process.exit(1)\n }\n const raw = JSON.parse(readFileSync(cfgPath, \"utf-8\"))\n\n const agents = Object.keys(raw.agents || {})\n if (agents.length === 0) {\n console.log(chalk.red(` No agents configured. Run: agentx agent add`))\n process.exit(1)\n }\n\n let agent = opts.agent\n if (!agent) {\n const r = await prompts({\n type: \"select\",\n name: \"agent\",\n message: \"Bind this bot to which agent?\",\n choices: agents.map((id) => ({ title: id, value: id })),\n initial: 0,\n })\n agent = r.agent\n }\n if (!agent) { console.log(chalk.red(\" Aborted\")); process.exit(1) }\n\n // Account name — default to the agent id (one bot per agent is the common case).\n // If that collides with an existing account, prompt.\n const accounts = raw.channels?.telegram?.accounts || {}\n let account = opts.account || agent\n if (accounts[account] && accounts[account].agentBinding !== agent) {\n const r = await prompts({\n type: \"text\",\n name: \"account\",\n message: `Account \"${account}\" is already in use. Pick a different label:`,\n initial: `${agent}-2`,\n validate: (s: string) => /^[a-z0-9-]+$/i.test(s) || \"lowercase letters, digits, hyphens only\",\n })\n account = r.account\n }\n if (!account) { console.log(chalk.red(\" Aborted\")); process.exit(1) }\n\n // --- Persist token to .env, reference it from config ---\n const envVar = `TG_${account.toUpperCase().replace(/-/g, \"_\")}_BOT_TOKEN`\n setDotEnv(envVar, token.trim())\n process.env[envVar] = token.trim() // so validation downstream sees it\n\n const result = await applyConfigMutation((cfg) => {\n setAtPath(cfg, \"channels.telegram.enabled\", true)\n setAtPath(cfg, `channels.telegram.accounts.${account}`, {\n token: `\\${${envVar}}`,\n agentBinding: agent,\n })\n // Nudge agent.mentions to include the bot handle, if not already there.\n const mentions: string[] = getAtPath(cfg, `agents.${agent}.mentions`) as any || []\n const handle = `@${me.username}`\n if (!mentions.includes(handle)) {\n mentions.push(handle)\n setAtPath(cfg, `agents.${agent}.mentions`, mentions)\n }\n }, { configPath: opts.configPath })\n\n if (!result.success) {\n console.log(chalk.red(` ✗ ${result.error}`))\n process.exit(1)\n }\n\n console.log()\n console.log(chalk.green(` ✓ Bot @${me.username} bound to agent \"${agent}\"`))\n console.log(chalk.dim(` Token stored in .env as ${envVar}`))\n console.log(chalk.dim(` Mentions updated to include @${me.username}`))\n if (result.reloaded) console.log(chalk.dim(\" Daemon hot-reloaded.\"))\n else console.log(chalk.dim(\" Start the daemon to begin polling (agentx daemon start)\"))\n\n // --- Auto-detect chatId for notifications.destination ---\n if (opts.skipChatCapture) return\n\n console.log()\n const { capture } = await prompts({\n type: \"confirm\",\n name: \"capture\",\n message: `Listen for a message so we can set this as your default --notify target?`,\n initial: true,\n })\n if (!capture) return\n\n console.log()\n console.log(chalk.dim(` Send any message to @${me.username} from the chat you want to use.`))\n console.log(chalk.dim(` Waiting up to 90s...`))\n const first = await pollFirstMessage(token.trim(), 90_000)\n if (!first) {\n console.log(chalk.yellow(` No message received — skipping. You can set it later with:`))\n console.log(chalk.dim(` agentx config set notifications.destination.channel telegram`))\n console.log(chalk.dim(` agentx config set notifications.destination.chatId <chatId>`))\n console.log(chalk.dim(` agentx config set notifications.destination.accountId ${account}`))\n return\n }\n\n const destResult = await applyConfigMutation((cfg) => {\n setAtPath(cfg, \"notifications.destination\", {\n channel: \"telegram\",\n chatId: String(first.chatId),\n accountId: account,\n })\n }, { configPath: opts.configPath })\n\n if (!destResult.success) {\n console.log(chalk.red(` ✗ failed to save destination: ${destResult.error}`))\n return\n }\n\n console.log(chalk.green(` ✓ Default --notify target set`))\n console.log(chalk.dim(` Chat: ${first.chatTitle || first.chatId} (from ${first.from})`))\n console.log(chalk.dim(` From now on, --notify me resolves to this chat.`))\n if (destResult.reloaded) console.log(chalk.dim(\" Daemon hot-reloaded.\"))\n}\n","import { readFileSync, writeFileSync, existsSync } from \"fs\"\nimport { resolve } from \"path\"\n\n// --- .env mutator ---\n//\n// Line-preserving read/write for .env files. Comments, blank lines, and\n// original key order are kept intact. Used by `agentx connect <channel>`\n// (and anything else that needs to persist secrets) so we never hand the\n// user a file-editor instruction.\n\nexport type DotEnvLine =\n | { kind: \"kv\"; key: string; value: string; raw: string }\n | { kind: \"comment\"; raw: string }\n | { kind: \"blank\"; raw: string }\n\nconst KV_RE = /^\\s*([A-Za-z_][A-Za-z0-9_]*)\\s*=\\s*(.*)$/\n\nfunction parseValue(raw: string): string {\n // Strip matching surrounding quotes — write path re-adds them as needed.\n const s = raw.trim()\n if ((s.startsWith('\"') && s.endsWith('\"')) || (s.startsWith(\"'\") && s.endsWith(\"'\"))) {\n return s.slice(1, -1)\n }\n return s\n}\n\nfunction quoteIfNeeded(value: string): string {\n if (/[\\s#\"'\\\\]/.test(value) || value === \"\") return JSON.stringify(value)\n return value\n}\n\nexport function readDotEnv(path: string = \".env\"): DotEnvLine[] {\n const abs = resolve(path)\n if (!existsSync(abs)) return []\n const content = readFileSync(abs, \"utf-8\")\n const lines: DotEnvLine[] = []\n for (const raw of content.split(/\\r?\\n/)) {\n if (raw.trim() === \"\") {\n lines.push({ kind: \"blank\", raw })\n continue\n }\n if (raw.trim().startsWith(\"#\")) {\n lines.push({ kind: \"comment\", raw })\n continue\n }\n const m = raw.match(KV_RE)\n if (m) {\n lines.push({ kind: \"kv\", key: m[1], value: parseValue(m[2]), raw })\n } else {\n // Unparseable line — preserve verbatim as \"comment\" so we don't trample it\n lines.push({ kind: \"comment\", raw })\n }\n }\n // Strip a single trailing blank line (every file ends with \\n → one empty split)\n if (lines.length && lines[lines.length - 1].kind === \"blank\") lines.pop()\n return lines\n}\n\nexport function serializeDotEnv(lines: DotEnvLine[]): string {\n return lines.map((l) => {\n if (l.kind === \"kv\") return `${l.key}=${quoteIfNeeded(l.value)}`\n return l.raw\n }).join(\"\\n\") + \"\\n\"\n}\n\n/**\n * Set a key to a value, preserving ordering & comments.\n * - If the key exists, the line is rewritten in place.\n * - If it doesn't, the key is appended (with a blank separator if the file\n * doesn't already end in one).\n */\nexport function setDotEnv(key: string, value: string, path: string = \".env\"): void {\n const abs = resolve(path)\n const lines = readDotEnv(abs)\n\n const idx = lines.findIndex((l) => l.kind === \"kv\" && l.key === key)\n if (idx >= 0) {\n lines[idx] = { kind: \"kv\", key, value, raw: `${key}=${quoteIfNeeded(value)}` }\n } else {\n if (lines.length && lines[lines.length - 1].kind !== \"blank\") {\n lines.push({ kind: \"blank\", raw: \"\" })\n }\n lines.push({ kind: \"kv\", key, value, raw: `${key}=${quoteIfNeeded(value)}` })\n }\n\n writeFileSync(abs, serializeDotEnv(lines))\n}\n\n/**\n * Append a key only if it isn't already present. Use this when you don't want\n * to clobber an existing value (e.g. a MESH_TOKEN the user already rotated).\n */\nexport function appendDotEnv(key: string, value: string, path: string = \".env\"): boolean {\n const lines = readDotEnv(path)\n if (lines.some((l) => l.kind === \"kv\" && l.key === key)) return false\n setDotEnv(key, value, path)\n return true\n}\n\nexport function getDotEnv(key: string, path: string = \".env\"): string | undefined {\n const lines = readDotEnv(path)\n const hit = lines.find((l): l is Extract<DotEnvLine, { kind: \"kv\" }> => l.kind === \"kv\" && l.key === key)\n return hit?.value\n}\n\nexport function unsetDotEnv(key: string, path: string = \".env\"): boolean {\n const abs = resolve(path)\n const lines = readDotEnv(abs)\n const idx = lines.findIndex((l) => l.kind === \"kv\" && l.key === key)\n if (idx < 0) return false\n lines.splice(idx, 1)\n // Collapse double-blank that may result\n if (idx > 0 && idx < lines.length && lines[idx - 1].kind === \"blank\" && lines[idx].kind === \"blank\") {\n lines.splice(idx, 1)\n }\n writeFileSync(abs, serializeDotEnv(lines))\n return true\n}\n","import chalk from \"chalk\"\nimport prompts from \"prompts\"\nimport { spawn } from \"child_process\"\nimport { applyConfigMutation, setAtPath } from \"@/daemon/config-mutator\"\nimport { setDotEnv } from \"@/utils/dotenv-mutator\"\n\n// --- agentx connect discord ---\n//\n// Discord's flow is 2-step: create an application (with bot token) in the\n// Developer Portal, then install it to a server via an OAuth URL. We can't\n// automate step 1 (Discord has no API to create apps), but we can verify\n// the bot token, save it to .env, and compose the install URL for the user.\n\nconst DEV_PORTAL = \"https://discord.com/developers/applications\"\n\n// Default bot permissions: View Channels + Send Messages + Read Message History + Use Slash Commands\n// Integer is a bitfield. 274877991936 = send + view + read history + manage webhooks. Plain chatty bots use 67584.\nconst DEFAULT_PERMISSIONS = \"67584\"\n\nasync function fetchMe(token: string): Promise<{ id: string; username: string; discriminator?: string } | null> {\n try {\n const res = await fetch(\"https://discord.com/api/v10/users/@me\", {\n headers: { Authorization: `Bot ${token}` },\n signal: AbortSignal.timeout(8000),\n })\n if (!res.ok) return null\n return (await res.json()) as any\n } catch { return null }\n}\n\nexport interface ConnectDiscordOpts {\n agent?: string\n configPath?: string\n}\n\nfunction openInBrowser(url: string): void {\n try {\n const opener = process.platform === \"darwin\" ? \"open\" : process.platform === \"win32\" ? \"start\" : \"xdg-open\"\n spawn(opener, [url], { stdio: \"ignore\", detached: true }).unref()\n } catch { /* non-fatal */ }\n}\n\nexport async function connectDiscord(opts: ConnectDiscordOpts = {}): Promise<void> {\n console.log()\n console.log(chalk.bold(\" Connect Discord\"))\n console.log()\n console.log(chalk.dim(\" 1. Open the Discord Developer Portal\"))\n console.log(chalk.dim(` ${DEV_PORTAL}`))\n console.log(chalk.dim(\" 2. New Application → Bot → Reset Token → copy the token\"))\n console.log(chalk.dim(\" 3. Under Bot → Privileged Gateway Intents,\"))\n console.log(chalk.dim(\" enable 'MESSAGE CONTENT INTENT'\"))\n console.log()\n\n const { openBrowser } = await prompts({\n type: \"confirm\",\n name: \"openBrowser\",\n message: \"Open the Developer Portal in your browser?\",\n initial: true,\n })\n if (openBrowser) openInBrowser(DEV_PORTAL)\n\n const { token } = await prompts({\n type: \"password\",\n name: \"token\",\n message: \"Paste the bot token:\",\n validate: (t: string) => t.trim().length > 20 || \"that looks too short for a Discord token\",\n })\n if (!token) { console.log(chalk.red(\" Aborted\")); process.exit(1) }\n\n process.stdout.write(\" Verifying token... \")\n const me = await fetchMe(token.trim())\n if (!me) {\n console.log(chalk.red(\"✗ invalid or revoked — did you enable MESSAGE CONTENT INTENT and copy the right token?\"))\n process.exit(1)\n }\n const displayName = me.discriminator && me.discriminator !== \"0\" ? `${me.username}#${me.discriminator}` : me.username\n console.log(chalk.green(`✓ ${displayName} (bot id ${me.id})`))\n\n // --- Agent binding ---\n const { readFileSync, existsSync } = await import(\"fs\")\n const { resolve } = await import(\"path\")\n const cfgPath = opts.configPath || resolve(process.cwd(), \"agentx.json\")\n if (!existsSync(cfgPath)) {\n console.log(chalk.red(` No agentx.json at ${cfgPath}. Run: agentx init`))\n process.exit(1)\n }\n const raw = JSON.parse(readFileSync(cfgPath, \"utf-8\"))\n const agents = Object.keys(raw.agents || {})\n if (agents.length === 0) {\n console.log(chalk.red(\" No agents configured. Run: agentx agent add\"))\n process.exit(1)\n }\n\n let agent = opts.agent\n if (!agent) {\n const r = await prompts({\n type: \"select\",\n name: \"agent\",\n message: \"Bind this bot to which agent?\",\n choices: agents.map((id) => ({ title: id, value: id })),\n initial: 0,\n })\n agent = r.agent\n }\n if (!agent) { console.log(chalk.red(\" Aborted\")); process.exit(1) }\n\n // --- Persist token + config ---\n const envVar = \"DISCORD_BOT_TOKEN\"\n setDotEnv(envVar, token.trim())\n process.env[envVar] = token.trim()\n\n const result = await applyConfigMutation((cfg) => {\n setAtPath(cfg, \"channels.discord.enabled\", true)\n setAtPath(cfg, \"channels.discord.token\", `\\${${envVar}}`)\n setAtPath(cfg, \"channels.discord.agentBinding\", agent)\n }, { configPath: opts.configPath })\n\n if (!result.success) {\n console.log(chalk.red(` ✗ ${result.error}`))\n process.exit(1)\n }\n\n console.log()\n console.log(chalk.green(` ✓ Discord bot ${displayName} bound to agent \"${agent}\"`))\n console.log(chalk.dim(` Token stored in .env as ${envVar}`))\n if (result.reloaded) console.log(chalk.dim(\" Daemon hot-reloaded.\"))\n else console.log(chalk.dim(\" Restart the daemon to start Discord polling.\"))\n\n // --- Install URL (bot id = application id for a bot user) ---\n console.log()\n console.log(chalk.bold(\" Install the bot to a server\"))\n console.log()\n const installUrl = `https://discord.com/oauth2/authorize?client_id=${me.id}&scope=bot&permissions=${DEFAULT_PERMISSIONS}`\n console.log(` ${chalk.cyan(installUrl)}`)\n console.log()\n const { openInstall } = await prompts({\n type: \"confirm\",\n name: \"openInstall\",\n message: \"Open the install URL in your browser now?\",\n initial: true,\n })\n if (openInstall) openInBrowser(installUrl)\n\n console.log()\n console.log(chalk.dim(\" After you pick a server, the bot will come online on the next daemon restart.\"))\n console.log(chalk.dim(\" Mention the bot in any channel to route messages to the agent.\"))\n}\n","import chalk from \"chalk\"\nimport prompts from \"prompts\"\nimport { existsSync, mkdirSync, readdirSync, readFileSync } from \"fs\"\nimport { resolve } from \"path\"\nimport { applyConfigMutation, setAtPath } from \"@/daemon/config-mutator\"\n\n// --- agentx connect whatsapp ---\n//\n// Runs a pairing-only Baileys session inside the CLI, prints the QR, waits\n// for the scan, and persists the session files. After that the daemon picks\n// the session up automatically on start. This removes the \"run daemon, find\n// the QR in logs, scan\" two-step from the legacy channel add flow.\n\nconst DEFAULT_SESSION_DIR = \".agentx/whatsapp-sessions\"\n\nfunction daemonRunning(): boolean {\n const pidFile = resolve(process.cwd(), \".agentx/daemon.pid\")\n if (!existsSync(pidFile)) return false\n try {\n const pid = parseInt(readFileSync(pidFile, \"utf-8\").trim(), 10)\n if (!pid) return false\n // process.kill with signal 0 only probes existence, doesn't actually signal.\n process.kill(pid, 0)\n return true\n } catch {\n return false\n }\n}\n\nfunction sessionExists(dir: string): boolean {\n if (!existsSync(dir)) return false\n try { return readdirSync(dir).some((f) => f.includes(\"creds\") || f.endsWith(\".json\")) } catch { return false }\n}\n\nexport interface ConnectWhatsAppOpts {\n agent?: string\n sessionDir?: string\n configPath?: string\n skipPair?: boolean\n}\n\nasync function pairSession(sessionDir: string, log: (s: string) => void): Promise<boolean> {\n let baileys: any\n try {\n // @ts-ignore optional dep\n baileys = await import(\"@whiskeysockets/baileys\")\n } catch {\n log(chalk.red(\" WhatsApp pairing needs @whiskeysockets/baileys.\"))\n log(chalk.red(\" Install with: pnpm add @whiskeysockets/baileys (or npm install)\"))\n return false\n }\n\n const { makeWASocket, useMultiFileAuthState } = baileys.default || baileys\n mkdirSync(sessionDir, { recursive: true })\n const { state, saveCreds } = await useMultiFileAuthState(sessionDir)\n\n let version: [number, number, number] | undefined\n try { version = (await baileys.fetchLatestBaileysVersion()).version } catch { /* fallback */ }\n\n const silentLogger = {\n level: \"silent\",\n trace: () => {}, debug: () => {}, info: () => {},\n warn: () => {}, fatal: () => {}, error: () => {},\n child: () => silentLogger,\n } as any\n\n const sock = makeWASocket({\n auth: {\n creds: state.creds,\n keys: baileys.makeCacheableSignalKeyStore\n ? baileys.makeCacheableSignalKeyStore(state.keys, silentLogger)\n : state.keys,\n },\n ...(version ? { version } : {}),\n logger: silentLogger,\n printQRInTerminal: false,\n browser: [\"agentx-connect\", \"pairing\", \"1.0\"],\n syncFullHistory: false,\n markOnlineOnConnect: false,\n })\n\n sock.ev.on(\"creds.update\", saveCreds)\n\n return await new Promise<boolean>((resolveP) => {\n const timeoutMs = 120_000\n const deadline = setTimeout(() => {\n log(chalk.yellow(\" Timed out waiting for scan (2min).\"))\n try { sock.end(undefined) } catch { /* ignore */ }\n resolveP(false)\n }, timeoutMs)\n\n sock.ev.on(\"connection.update\", async (u: any) => {\n if (u.qr) {\n log(chalk.dim(\" Scan this QR with WhatsApp → Linked devices → Link a device:\"))\n log(\"\")\n try {\n const { default: qrcode } = await import(\"qrcode-terminal\") as any\n qrcode.generate(u.qr, { small: true })\n } catch {\n log(` QR: ${u.qr}`)\n }\n log(\"\")\n }\n if (u.connection === \"open\") {\n clearTimeout(deadline)\n log(chalk.green(\" ✓ Paired\"))\n try { sock.end(undefined) } catch { /* ignore */ }\n resolveP(true)\n }\n if (u.connection === \"close\" && !u.qr) {\n // If we haven't opened yet and close is final, abort.\n const reason = u.lastDisconnect?.error?.output?.statusCode\n // 401 = \"Unauthorized\" / kicked. 515 = reset. Otherwise just let it retry via new QR.\n if (reason === 401) {\n clearTimeout(deadline)\n log(chalk.red(\" ✗ Authorization failed — rescan required\"))\n resolveP(false)\n }\n }\n })\n })\n}\n\nexport async function connectWhatsApp(opts: ConnectWhatsAppOpts = {}): Promise<void> {\n console.log()\n console.log(chalk.bold(\" Connect WhatsApp\"))\n console.log()\n\n if (daemonRunning()) {\n console.log(chalk.yellow(\" ⚠ The daemon is running. Stop it first so pairing can open a fresh Baileys session:\"))\n console.log(chalk.dim(\" agentx daemon stop\"))\n console.log()\n const { cont } = await prompts({ type: \"confirm\", name: \"cont\", message: \"Continue anyway? (expect errors)\", initial: false })\n if (!cont) { console.log(chalk.red(\" Aborted\")); process.exit(1) }\n }\n\n const cfgPath = opts.configPath || resolve(process.cwd(), \"agentx.json\")\n if (!existsSync(cfgPath)) {\n console.log(chalk.red(` No agentx.json at ${cfgPath}. Run: agentx init`))\n process.exit(1)\n }\n const raw = JSON.parse(readFileSync(cfgPath, \"utf-8\"))\n\n const sessionDir = opts.sessionDir || raw.channels?.whatsapp?.sessionDir || DEFAULT_SESSION_DIR\n const absSession = resolve(process.cwd(), sessionDir)\n\n // --- Agent binding ---\n const agents = Object.keys(raw.agents || {})\n if (agents.length === 0) {\n console.log(chalk.red(\" No agents configured. Run: agentx agent add\"))\n process.exit(1)\n }\n\n let agent = opts.agent\n if (!agent) {\n const r = await prompts({\n type: \"select\",\n name: \"agent\",\n message: \"Default agent for incoming messages:\",\n choices: agents.map((id) => ({ title: id, value: id })),\n initial: 0,\n })\n agent = r.agent\n }\n if (!agent) { console.log(chalk.red(\" Aborted\")); process.exit(1) }\n\n // --- Decide whether to re-pair ---\n let shouldPair = !opts.skipPair\n if (sessionExists(absSession) && shouldPair) {\n const { keep } = await prompts({\n type: \"confirm\",\n name: \"keep\",\n message: `An existing session was found at ${sessionDir}. Keep it (recommended), or pair again?`,\n initial: true,\n })\n shouldPair = !keep\n if (keep) console.log(chalk.dim(\" Keeping existing session — skipping QR pair.\"))\n }\n\n // --- Pair ---\n if (shouldPair) {\n const ok = await pairSession(absSession, (s) => console.log(s))\n if (!ok) {\n console.log(chalk.red(\" Pairing failed. You can retry with `agentx connect whatsapp`.\"))\n process.exit(1)\n }\n }\n\n // --- Persist config ---\n const result = await applyConfigMutation((cfg) => {\n setAtPath(cfg, \"channels.whatsapp.enabled\", true)\n setAtPath(cfg, \"channels.whatsapp.sessionDir\", sessionDir)\n setAtPath(cfg, \"channels.whatsapp.defaultAgent\", agent)\n }, { configPath: opts.configPath })\n\n if (!result.success) {\n console.log(chalk.red(` ✗ ${result.error}`))\n process.exit(1)\n }\n\n console.log()\n console.log(chalk.green(` ✓ WhatsApp bound to agent \"${agent}\"`))\n console.log(chalk.dim(` Session: ${sessionDir}`))\n console.log(chalk.dim(\" Start the daemon to begin receiving:\"))\n console.log(chalk.dim(\" agentx daemon start\"))\n console.log(chalk.dim(\" Add routes later with:\"))\n console.log(chalk.dim(` agentx config set channels.whatsapp.routes '[{\"contact\":\"+1234567890\",\"agent\":\"${agent}\"}]'`))\n console.log()\n}\n","import { randomBytes } from \"crypto\"\nimport chalk from \"chalk\"\nimport prompts from \"prompts\"\nimport { applyConfigMutation, getAtPath, setAtPath } from \"@/daemon/config-mutator\"\nimport { getDotEnv, setDotEnv } from \"@/utils/dotenv-mutator\"\n\n// --- agentx connect mesh ---\n//\n// One-command mesh pairing for two AgentX nodes on the same private network\n// (Tailscale / WireGuard / VPN). Replaces the manual \"generate a MESH_TOKEN,\n// copy it to both .env files, add peer to each agentx.json\" sequence.\n//\n// Node A: agentx connect mesh invite\n// → prints agentx-mesh://join/<base64({url, token, name})>\n// Node B: agentx connect mesh join <link>\n// → persists the shared token + adds A as a peer\n\nconst PROTOCOL = \"agentx-mesh:\"\nconst PATH_PREFIX = \"//join/\"\n\nexport interface MeshInvitePayload {\n url: string\n token: string\n name: string\n version: 1\n}\n\nfunction b64urlEncode(input: string): string {\n return Buffer.from(input, \"utf-8\").toString(\"base64url\")\n}\n\nfunction b64urlDecode(input: string): string {\n return Buffer.from(input, \"base64url\").toString(\"utf-8\")\n}\n\nexport function encodeInvite(payload: MeshInvitePayload): string {\n return `${PROTOCOL}${PATH_PREFIX}${b64urlEncode(JSON.stringify(payload))}`\n}\n\nexport function decodeInvite(link: string): MeshInvitePayload {\n if (!link.startsWith(`${PROTOCOL}${PATH_PREFIX}`)) {\n throw new Error(`Not a mesh invite link — expected ${PROTOCOL}${PATH_PREFIX}…`)\n }\n const raw = link.slice(PROTOCOL.length + PATH_PREFIX.length)\n const parsed = JSON.parse(b64urlDecode(raw))\n if (parsed.version !== 1) throw new Error(`Unsupported invite version: ${parsed.version}`)\n if (typeof parsed.url !== \"string\" || typeof parsed.token !== \"string\" || typeof parsed.name !== \"string\") {\n throw new Error(\"Invite payload missing required fields (url, token, name)\")\n }\n return parsed\n}\n\nfunction generateToken(): string {\n // 32 bytes → 64-char hex; plenty of entropy and stays readable in a URL.\n return randomBytes(32).toString(\"hex\")\n}\n\nfunction resolveBindUrl(raw: any): string {\n const bind: string = raw?.node?.bind || \"127.0.0.1:18800\"\n const [host, port] = bind.split(\":\")\n // Invites need a routable address, not 0.0.0.0. We don't know the Tailscale IP,\n // so we let the user confirm before sending.\n return `http://${host}:${port}`\n}\n\nfunction nodeName(raw: any): string {\n return raw?.node?.name || raw?.node?.id || \"node\"\n}\n\n/**\n * invite() — produce a join link for the OTHER node to consume.\n * Creates a MESH_TOKEN in .env if one doesn't exist yet.\n */\nexport async function invite(opts: { url?: string; configPath?: string }): Promise<void> {\n // Read the raw config to get node info + existing token ref\n const { readFileSync, existsSync } = await import(\"fs\")\n const { resolve } = await import(\"path\")\n const cfgPath = opts.configPath || resolve(process.cwd(), \"agentx.json\")\n if (!existsSync(cfgPath)) {\n console.log(chalk.red(` No agentx.json at ${cfgPath}. Run: agentx init`))\n process.exit(1)\n }\n const raw = JSON.parse(readFileSync(cfgPath, \"utf-8\"))\n\n // 1. Ensure a token exists\n let token = getDotEnv(\"MESH_TOKEN\")\n if (!token) {\n token = generateToken()\n setDotEnv(\"MESH_TOKEN\", token)\n console.log(chalk.dim(` Generated new MESH_TOKEN (32 bytes) and saved to .env`))\n }\n\n // 2. Resolve the URL — default from node.bind, but confirm because 0.0.0.0 isn't routable.\n let url = opts.url || resolveBindUrl(raw)\n const needsHint = url.includes(\"0.0.0.0\") || url.includes(\"127.0.0.1\") || url.includes(\"localhost\")\n if (needsHint && !opts.url) {\n const { url: entered } = await prompts({\n type: \"text\",\n name: \"url\",\n message: \"This node's URL as peers should reach it (e.g. http://100.x.x.x:18800):\",\n initial: url,\n validate: (v: string) => /^https?:\\/\\//.test(v) || \"must start with http:// or https://\",\n })\n if (!entered) { console.log(chalk.red(\" Aborted\")); process.exit(1) }\n url = entered\n }\n\n // 3. Make sure mesh is enabled\n const result = await applyConfigMutation((cfg) => {\n setAtPath(cfg, \"mesh.enabled\", true)\n }, { configPath: opts.configPath })\n if (!result.success) {\n console.log(chalk.red(` ✗ ${result.error}`))\n process.exit(1)\n }\n\n const link = encodeInvite({ url, token, name: nodeName(raw), version: 1 })\n\n console.log()\n console.log(chalk.bold(\" Mesh invite\"))\n console.log()\n console.log(` ${chalk.cyan(link)}`)\n console.log()\n console.log(chalk.dim(` Run on the other node:`))\n console.log(chalk.dim(` agentx connect mesh join \"${link}\"`))\n console.log()\n console.log(chalk.yellow(` Share over a trusted channel only — whoever holds this link can join your mesh.`))\n console.log()\n}\n\n/**\n * join(link) — consume a join link on the OTHER node. Adds the sender as a\n * peer and stores the shared token in .env.\n */\nexport async function join(link: string, opts: { configPath?: string } = {}): Promise<void> {\n let payload: MeshInvitePayload\n try {\n payload = decodeInvite(link)\n } catch (e: any) {\n console.log(chalk.red(` ✗ ${e.message}`))\n process.exit(1)\n }\n\n // Store the shared token (or confirm overwrite if MESH_TOKEN already exists but differs)\n const existing = getDotEnv(\"MESH_TOKEN\")\n if (existing && existing !== payload.token) {\n const { overwrite } = await prompts({\n type: \"confirm\",\n name: \"overwrite\",\n message: \"A different MESH_TOKEN already exists in .env. Overwrite with the invite's token?\",\n initial: false,\n })\n if (!overwrite) { console.log(chalk.red(\" Aborted (keeping existing .env)\")); process.exit(1) }\n }\n setDotEnv(\"MESH_TOKEN\", payload.token)\n\n // Add the peer (idempotent on name)\n const result = await applyConfigMutation((cfg) => {\n setAtPath(cfg, \"mesh.enabled\", true)\n const peers: any[] = getAtPath(cfg, \"mesh.peers\") as any || []\n const idx = peers.findIndex((p) => p.name === payload.name)\n const peer = { name: payload.name, url: payload.url, token: \"${MESH_TOKEN}\" }\n if (idx >= 0) peers[idx] = peer\n else peers.push(peer)\n setAtPath(cfg, \"mesh.peers\", peers)\n }, { configPath: opts.configPath })\n\n if (!result.success) {\n console.log(chalk.red(` ✗ ${result.error}`))\n process.exit(1)\n }\n\n console.log(chalk.green(` ✓ Joined mesh`))\n console.log(chalk.dim(` Peer: ${payload.name} @ ${payload.url}`))\n console.log(chalk.dim(` Shared token stored in .env as MESH_TOKEN`))\n if (result.reloaded) console.log(chalk.dim(\" Daemon hot-reloaded.\"))\n else console.log(chalk.dim(\" Restart the daemon to start the mesh (agentx daemon start).\"))\n console.log()\n\n // Health check against the peer — advisory only\n try {\n const res = await fetch(`${payload.url.replace(/\\/$/, \"\")}/.well-known/agent-card.json`, {\n signal: AbortSignal.timeout(5000),\n })\n if (res.ok) {\n const card: any = await res.json()\n const agents = Array.isArray(card.agents) ? card.agents.length : \"?\"\n console.log(chalk.dim(` Reachable — ${payload.name} exposes ${agents} agents`))\n } else {\n console.log(chalk.yellow(` Peer returned HTTP ${res.status} — double-check the URL`))\n }\n } catch (e: any) {\n console.log(chalk.yellow(` Could not reach ${payload.url} right now (${e?.cause?.code || e.message}) — verify VPN / Tailscale when the peer daemon is up`))\n }\n}\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { loadDaemonConfig } from \"@/daemon/config\"\n\nexport const usage = new Command()\n .name(\"usage\")\n .description(\"token usage analysis and reporting\")\n\n// agentx usage — quick today summary\nusage\n .command(\"today\", { isDefault: true })\n .description(\"show today's token usage\")\n .action(async () => {\n try {\n const config = loadDaemonConfig()\n const [host, port] = config.node.bind.split(\":\")\n const res = await fetch(`http://${host || \"127.0.0.1\"}:${port}/usage`, { signal: AbortSignal.timeout(3000) })\n const data = await res.json() as any\n\n console.log()\n console.log(chalk.bold(` Token Usage (last 7 days)`))\n console.log()\n\n if (data.totalTasks === 0) {\n console.log(chalk.dim(\" No tasks recorded yet\"))\n console.log()\n return\n }\n\n const fmt = (n: number) => n.toLocaleString()\n\n console.log(` Total: ${chalk.bold(fmt(data.totalTokens))} tokens across ${data.totalTasks} tasks`)\n console.log(` Input: ${fmt(data.totalInput)}`)\n console.log(` Output: ${fmt(data.totalOutput)}`)\n console.log(` Cache read: ${fmt(data.totalCacheRead)}`)\n console.log(` Cache create: ${fmt(data.totalCacheCreate)}`)\n if (data.cacheHitRatio > 0) {\n console.log(` Cache hit: ${(data.cacheHitRatio * 100).toFixed(1)}%`)\n }\n if (data.totalErrors > 0) {\n console.log(` Errors: ${chalk.red(String(data.totalErrors))}`)\n }\n\n console.log()\n console.log(chalk.bold(\" By Agent:\"))\n const agents = Object.entries(data.byAgent || {}) as Array<[string, any]>\n agents.sort((a, b) => b[1].total - a[1].total)\n\n for (const [id, ag] of agents) {\n const total = fmt(ag.total || (ag.input + ag.output + ag.cacheRead + ag.cacheCreate))\n const avgMs = ag.avgDuration ? `${(ag.avgDuration / 1000).toFixed(1)}s avg` : \"\"\n console.log(` ${chalk.cyan(id)}: ${total} tokens (${ag.tasks} tasks) ${chalk.dim(avgMs)}`)\n }\n console.log()\n } catch (e: any) {\n if (e.cause?.code === \"ECONNREFUSED\") {\n console.log(chalk.red(\" Daemon not running. Start with: agentx daemon start\"))\n } else {\n console.log(chalk.red(` ${e.message}`))\n }\n }\n })\n\n// `agentx usage serve` was removed — the same data now lives at\n// /admin/cost on the dashboard, so there's no second port to keep\n// running. Anyone with a stale `usage serve` bookmark gets a redirect\n// from the dashboard root pointing to /admin/cost.\n\n// agentx usage report — run Python analyzer\nusage\n .command(\"report\")\n .description(\"run full session analysis (parses Claude Code JSONL files)\")\n .option(\"--days <n>\", \"analyze last N days\", \"7\")\n .action(async (opts) => {\n const { execSync } = await import(\"child_process\")\n const { existsSync } = await import(\"fs\")\n const { resolve } = await import(\"path\")\n\n const scriptPath = resolve(process.cwd(), \"scripts/token-report.py\")\n if (!existsSync(scriptPath)) {\n console.log(chalk.red(` Script not found: ${scriptPath}`))\n console.log(chalk.dim(\" The token analyzer script should be at scripts/token-report.py\"))\n return\n }\n\n console.log(chalk.dim(\" Analyzing Claude Code sessions...\"))\n try {\n execSync(`SINCE_DAYS=${opts.days} python3 \"${scriptPath}\"`, { stdio: \"inherit\" })\n } catch {\n console.log(chalk.red(\" Analysis failed. Is Python 3 installed?\"))\n }\n })\n\n// ---------------------------------------------------------------------------\n// agentx usage surfaces — which CLI commands and dashboard pages get used\n// ---------------------------------------------------------------------------\n//\n// The evidence side of the surface-reduction work. `usage today` answers\n// \"what did the agents cost\"; this answers \"which of the 46 commands and 16\n// pages does anyone actually open\". Reads straight from SQLite — no daemon\n// needed, and it works on a node whose daemon is stopped.\n//\n// See docs/architecture/surface-reduction.md for the bar a surface must clear.\nusage\n .command(\"surfaces\")\n .description(\"which CLI commands and dashboard pages are actually used\")\n .option(\"--days <n>\", \"window in days\", \"30\")\n .option(\"--kind <kind>\", \"cli | page (default: both)\")\n .option(\"--unused\", \"list registered surfaces with ZERO recorded use instead\")\n .option(\"--json\", \"raw JSON output\")\n .action(async (opts) => {\n const { listSurfaceUse } = await import(\"@/observability/surface-usage\")\n const kind = opts.kind === \"cli\" || opts.kind === \"page\" ? opts.kind : undefined\n const rows = listSurfaceUse({ kind, sinceDays: Number(opts.days) || 30 })\n\n if (opts.unused) {\n const { buildProgram } = await import(\"@/program\")\n const program = await buildProgram()\n const seen = new Set(rows.filter((r) => r.kind === \"cli\").map((r) => r.name))\n const registered: string[] = []\n const walk = (cmd: any, prefix: string) => {\n for (const sub of cmd.commands ?? []) {\n const name = prefix ? `${prefix} ${sub.name()}` : sub.name()\n registered.push(name)\n walk(sub, name)\n }\n }\n walk(program, \"\")\n const unused = registered.filter((c) => !seen.has(c)).sort()\n\n if (opts.json) {\n console.log(JSON.stringify({ windowDays: Number(opts.days) || 30, unused }, null, 2))\n return\n }\n console.log()\n console.log(chalk.bold(` Never used in the last ${opts.days} days (${unused.length}/${registered.length})`))\n console.log()\n for (const c of unused) console.log(` ${chalk.dim(\"·\")} ${c}`)\n console.log()\n console.log(chalk.dim(\" Zero use is necessary but not sufficient to remove a surface —\"))\n console.log(chalk.dim(\" it must also fail the impact test. See docs/architecture/surface-reduction.md\"))\n console.log()\n return\n }\n\n if (opts.json) {\n console.log(JSON.stringify(rows, null, 2))\n return\n }\n\n if (rows.length === 0) {\n console.log()\n console.log(chalk.dim(` No surface usage recorded in the last ${opts.days} days.`))\n console.log(chalk.dim(\" Counting starts once this build has been running for a while.\"))\n console.log()\n return\n }\n\n console.log()\n console.log(chalk.bold(` Surface usage — last ${opts.days} days`))\n console.log()\n let lastKind = \"\"\n for (const r of rows) {\n if (r.kind !== lastKind) {\n console.log(chalk.dim(` ${r.kind === \"cli\" ? \"CLI commands\" : \"Dashboard pages\"}`))\n lastKind = r.kind\n }\n const count = String(r.count).padStart(6)\n const days = chalk.dim(`${r.days}d`)\n console.log(` ${chalk.cyan(count)} ${r.name.padEnd(28)} ${days}`)\n }\n console.log()\n console.log(chalk.dim(` ${rows.length} surface(s) with recorded use. See --unused for the rest.`))\n console.log()\n })\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { loadDaemonConfig } from \"@/daemon/config\"\nimport { mutateAgentxConfig } from \"@/daemon/config-mutate\"\n\nexport const board = new Command()\n .name(\"board\")\n .description(\"kanban board dashboard — visual work view over configured sources\")\n\n// agentx board serve — start the dashboard HTTP server\nboard\n .command(\"serve\", { isDefault: true })\n .description(\"start the dashboard server (live view always; boards if configured)\")\n .option(\"--port <n>\", \"override dashboard.port\")\n .option(\"--bind <host>\", \"override dashboard.bind (e.g. 0.0.0.0)\")\n .action(async (opts) => {\n try {\n const config = resolveServerConfig(opts.port, opts.bind)\n const { startBoardDashboard } = await import(\"@/daemon/board-dashboard\")\n startBoardDashboard(config)\n } catch (e: any) {\n console.log(chalk.red(` ${e.message}`))\n if (process.env.DEBUG && e.stack) console.log(chalk.dim(e.stack))\n process.exit(1)\n }\n })\n\n/**\n * Load agentx.json if it exists; otherwise fabricate a minimal config so the\n * dashboard can serve the setup wizard. Without this, `agentx setup` on a\n * fresh machine would crash with \"No config found\" before the user has a\n * chance to create one.\n */\nfunction resolveServerConfig(portOpt?: string, bindOpt?: string): any {\n try {\n const cfg = loadDaemonConfig()\n if (portOpt) cfg.dashboard.port = parseInt(portOpt, 10)\n if (bindOpt) cfg.dashboard.bind = bindOpt\n return cfg\n } catch (e: any) {\n console.log(chalk.yellow(\" No agentx.json found — starting dashboard in setup-only mode.\"))\n console.log(chalk.dim(\" Visit http://127.0.0.1:\" + (portOpt || \"4202\") + \" to run the wizard.\\n\"))\n return {\n node: { id: \"setup\", name: \"Setup\", bind: \"127.0.0.1:18800\" },\n providers: {},\n agents: {},\n channels: {},\n crons: {},\n mesh: { enabled: false, peers: [], discovery: \"static\", healthCheck: { interval: 60, timeout: 10 } },\n boards: [],\n dashboard: {\n enabled: true,\n port: portOpt ? parseInt(portOpt, 10) : 4202,\n bind: bindOpt || \"127.0.0.1\",\n daemonUrl: \"http://localhost:18800\",\n daemons: [],\n },\n business: undefined,\n session: { staleMinutes: 120 },\n }\n }\n}\n\n// agentx board list — show configured boards (quick sanity check)\nboard\n .command(\"list\")\n .description(\"list configured boards\")\n .action(() => {\n try {\n const config = loadDaemonConfig()\n if (!config.boards?.length) {\n console.log(chalk.dim(\"\\n No boards configured.\\n\"))\n return\n }\n console.log()\n for (const b of config.boards) {\n console.log(` ${chalk.cyan(b.id)} — ${b.name}`)\n const src = b.source as any\n console.log(chalk.dim(` source: ${src.type}${src.projects ? \" (\" + src.projects.join(\", \") + \")\" : \"\"}`))\n if (b.primaryToolLabel) console.log(chalk.dim(` primary label: ${b.primaryToolLabel}`))\n console.log(chalk.dim(` window: ${b.timeRangeDays} days`))\n }\n console.log()\n } catch (e: any) {\n console.log(chalk.red(` ${e.message}`))\n process.exit(1)\n }\n })\n\n// agentx board add — append a board to agentx.json\nboard\n .command(\"add <id>\")\n .description(\"add a GitLab board to agentx.json\")\n .requiredOption(\"--name <name>\", \"human-readable board name\")\n .requiredOption(\"--projects <paths>\", \"comma-separated GitLab project paths (e.g. 'mtgl/system,mtgl/website')\")\n .option(\"--label <label>\", \"primary tool label ANDed into every query (e.g. 'Tool::Claude')\")\n .option(\"--days <n>\", \"open-window time range in days\", \"30\")\n .option(\"--closed-days <n>\", \"closed-window in days\", \"30\")\n .action((id: string, opts) => {\n try {\n mutateConfig((cfg) => {\n if (!Array.isArray(cfg.boards)) cfg.boards = []\n if (cfg.boards.find((b: any) => b.id === id)) {\n throw new Error(`board \"${id}\" already exists`)\n }\n const projects = String(opts.projects).split(\",\").map((s) => s.trim()).filter(Boolean)\n if (projects.length === 0) throw new Error(\"--projects must include at least one path\")\n const board: any = {\n id,\n name: opts.name,\n source: { type: \"gitlab\", projects },\n timeRangeDays: parseInt(opts.days, 10) || 30,\n closedWindowDays: parseInt(opts.closedDays, 10) || 30,\n }\n if (opts.label) board.primaryToolLabel = opts.label\n cfg.boards.push(board)\n return `added board \"${id}\" (${projects.join(\", \")})`\n })\n } catch (e: any) {\n console.log(chalk.red(` ${e.message}`))\n process.exit(1)\n }\n })\n\n// agentx board edit — update a board in place\nboard\n .command(\"edit <id>\")\n .description(\"edit board fields without re-creating it\")\n .option(\"--name <name>\", \"rename\")\n .option(\"--projects <paths>\", \"comma-separated GitLab project paths (replaces the list)\")\n .option(\"--label <label>\", \"primary tool label (set to '-' to clear)\")\n .option(\"--days <n>\", \"open-window time range in days\")\n .option(\"--closed-days <n>\", \"closed-window in days\")\n .action((id: string, opts) => {\n try {\n mutateConfig((cfg) => {\n const list = Array.isArray(cfg.boards) ? cfg.boards : []\n const b = list.find((x: any) => x.id === id)\n if (!b) throw new Error(`board \"${id}\" not found`)\n const changes: string[] = []\n if (opts.name) { b.name = opts.name; changes.push(`name=\"${opts.name}\"`) }\n if (opts.projects) {\n const projects = String(opts.projects).split(\",\").map((s) => s.trim()).filter(Boolean)\n if (projects.length === 0) throw new Error(\"--projects must include at least one path\")\n b.source = { ...(b.source || { type: \"gitlab\" }), type: \"gitlab\", projects }\n changes.push(`projects=${projects.length}`)\n }\n if (opts.label !== undefined) {\n if (opts.label === \"-\") { delete b.primaryToolLabel; changes.push(\"label cleared\") }\n else { b.primaryToolLabel = opts.label; changes.push(`label=\"${opts.label}\"`) }\n }\n if (opts.days) { b.timeRangeDays = parseInt(opts.days, 10) || b.timeRangeDays; changes.push(`days=${b.timeRangeDays}`) }\n if (opts.closedDays) { b.closedWindowDays = parseInt(opts.closedDays, 10) || b.closedWindowDays; changes.push(`closed-days=${b.closedWindowDays}`) }\n if (changes.length === 0) throw new Error(\"no changes — pass at least one option\")\n return `board \"${id}\" updated (${changes.join(\", \")})`\n })\n } catch (e: any) {\n console.log(chalk.red(` ${e.message}`))\n process.exit(1)\n }\n })\n\n// agentx board column ... — manage a board's column flow\nconst column = board\n .command(\"column\")\n .description(\"manage a board's columns (add / remove / edit / list)\")\n\ncolumn\n .command(\"list <boardId>\")\n .description(\"list columns on a board, in order\")\n .action((boardId: string) => {\n try {\n const cfg = JSON.parse(require(\"fs\").readFileSync(\"agentx.json\", \"utf-8\"))\n const b = (cfg.boards || []).find((x: any) => x.id === boardId)\n if (!b) throw new Error(`board \"${boardId}\" not found`)\n const cols = b.columns || []\n if (cols.length === 0) { console.log(chalk.dim(` no columns (board falls back to GitLab default flow)`)); return }\n for (const c of cols) {\n const map = c.kind === \"scoped-label\" ? `scoped=\"${c.scopedLabel}\"` :\n c.kind === \"label\" ? `label=\"${c.mapsToLabel || \"\"}\"` :\n c.kind === \"open-backlog\" ? `prefix=\"${c.scopedPrefix}\"` :\n c.kind\n console.log(` ${chalk.cyan(c.id.padEnd(12))} ${c.title.padEnd(14)} ${chalk.dim(map)}`)\n }\n } catch (e: any) {\n console.log(chalk.red(` ${e.message}`))\n process.exit(1)\n }\n })\n\ncolumn\n .command(\"add <boardId> <columnId>\")\n .description(\"add a column to a board\")\n .requiredOption(\"--title <title>\", \"column title\")\n .option(\"--kind <kind>\", \"open-backlog | scoped-label | closed | label\", \"scoped-label\")\n .option(\"--scoped <label>\", \"for kind=scoped-label, the full label (e.g. 'Status::Doing')\")\n .option(\"--label <label>\", \"for kind=label, the label name to add/remove\")\n .option(\"--scoped-prefix <prefix>\", \"for kind=open-backlog/scoped-label\", \"Status\")\n .option(\"--accent <color>\", \"hex/CSS color for the column accent bar\")\n .action((boardId: string, columnId: string, opts) => {\n try {\n mutateConfig((cfg) => {\n const list = Array.isArray(cfg.boards) ? cfg.boards : []\n const b = list.find((x: any) => x.id === boardId)\n if (!b) throw new Error(`board \"${boardId}\" not found`)\n b.columns = b.columns || []\n if (b.columns.find((c: any) => c.id === columnId)) {\n throw new Error(`column \"${columnId}\" already exists on board \"${boardId}\"`)\n }\n const col: any = { id: columnId, title: opts.title, kind: opts.kind, scopedPrefix: opts.scopedPrefix }\n if (opts.kind === \"scoped-label\") {\n if (!opts.scoped) throw new Error(\"--scoped required for kind=scoped-label\")\n col.scopedLabel = opts.scoped\n }\n if (opts.kind === \"label\") {\n if (!opts.label) throw new Error(\"--label required for kind=label\")\n col.mapsToLabel = opts.label\n }\n if (opts.accent) col.accent = opts.accent\n b.columns.push(col)\n return `column \"${columnId}\" added to board \"${boardId}\"`\n })\n } catch (e: any) {\n console.log(chalk.red(` ${e.message}`))\n process.exit(1)\n }\n })\n\ncolumn\n .command(\"remove <boardId> <columnId>\")\n .alias(\"rm\")\n .description(\"remove a column from a board\")\n .action((boardId: string, columnId: string) => {\n try {\n mutateConfig((cfg) => {\n const list = Array.isArray(cfg.boards) ? cfg.boards : []\n const b = list.find((x: any) => x.id === boardId)\n if (!b) throw new Error(`board \"${boardId}\" not found`)\n const before = (b.columns || []).length\n b.columns = (b.columns || []).filter((c: any) => c.id !== columnId)\n if (b.columns.length === before) throw new Error(`column \"${columnId}\" not found`)\n return `column \"${columnId}\" removed from board \"${boardId}\"`\n })\n } catch (e: any) {\n console.log(chalk.red(` ${e.message}`))\n process.exit(1)\n }\n })\n\n// agentx board remove — drop a board by id\nboard\n .command(\"remove <id>\")\n .alias(\"rm\")\n .description(\"remove a board from agentx.json\")\n .action((id: string) => {\n try {\n mutateConfig((cfg) => {\n if (!Array.isArray(cfg.boards) || cfg.boards.length === 0) throw new Error(\"no boards configured\")\n const before = cfg.boards.length\n cfg.boards = cfg.boards.filter((b: any) => b.id !== id)\n if (cfg.boards.length === before) throw new Error(`board \"${id}\" not found`)\n return `removed board \"${id}\"`\n })\n } catch (e: any) {\n console.log(chalk.red(` ${e.message}`))\n process.exit(1)\n }\n })\n\n/**\n * CLI-friendly wrapper around the shared mutateAgentxConfig helper — prints\n * colourized success + backup hint so `agentx board add/remove` feels the same\n * as it did before the refactor.\n */\nfunction mutateConfig(mutator: (cfg: any) => string): void {\n const { summary, backupPath } = mutateAgentxConfig((cfg) => mutator(cfg))\n console.log(chalk.green(`\\n ✓ ${summary}\\n`))\n if (backupPath) console.log(chalk.dim(` Backup: ${backupPath}`))\n console.log(chalk.dim(` Restart the dashboard to pick up the change if not auto-reloading.\\n`))\n}\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { WikiHub } from \"@/wiki\"\nimport type { WikiMode } from \"@/wiki/hub\"\nimport { startWikiServer } from \"@/wiki/serve\"\nimport { buildAbsorbPrompt } from \"@/wiki/prompts\"\nimport { runPromotion } from \"@/wiki/promote\"\nimport { GraphStore } from \"@/graph\"\nimport { resolve, relative, dirname } from \"path\"\nimport { execSync } from \"child_process\"\nimport { writeFileSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, existsSync } from \"fs\"\n\nfunction getHub(dir?: string, mode?: WikiMode): WikiHub {\n return new WikiHub(dir || resolve(process.cwd(), \".agentx/wiki\"), undefined, mode || \"graph\")\n}\n\nfunction modeLabel(mode: WikiMode): string {\n if (mode === \"graph\") return \"Knowledge Graph\"\n if (mode === \"flat\") return \"Karpathy Flat\"\n return \"Unified\"\n}\n\nexport const wiki = new Command()\n .name(\"wiki\")\n .description(\"wiki knowledge base management\")\n\n// agentx wiki status\nwiki\n .command(\"status\")\n .description(\"show wiki status per agent\")\n .option(\"--dir <path>\", \"wiki directory\")\n .option(\"--mode <mode>\", \"graph (default, canonical) | unified | flat (legacy, back-compat)\", \"graph\")\n .action((opts) => {\n const mode = opts.mode as WikiMode\n const hub = getHub(opts.dir, mode)\n const agents = hub.summary()\n const shared = hub.getSharedStore()\n const totalEntries = shared.listEntries().length\n\n console.log()\n console.log(chalk.bold(` Wiki Hub Status [${modeLabel(mode)}]`))\n console.log()\n console.log(` Total raw entries: ${totalEntries}`)\n console.log(` Agents: ${agents.length}`)\n console.log()\n\n for (const agent of agents) {\n const status = agent.unabsorbed > 0\n ? chalk.yellow(`${agent.unabsorbed} unabsorbed`)\n : chalk.green(\"up to date\")\n\n console.log(` ${chalk.cyan(agent.agentId)}`)\n console.log(` Entries: ${agent.totalEntries} Articles: ${agent.totalArticles} ${status}`)\n\n if (agent.articles.length > 0) {\n for (const a of agent.articles.slice(0, 3)) {\n console.log(chalk.dim(` - ${a.title} [${(a.tags || []).slice(0, 3).join(\", \")}]`))\n }\n if (agent.articles.length > 3) {\n console.log(chalk.dim(` ... and ${agent.articles.length - 3} more`))\n }\n }\n console.log()\n }\n\n const totalUnabsorbed = agents.reduce((s, a) => s + a.unabsorbed, 0)\n if (totalUnabsorbed > 0) {\n console.log(chalk.dim(` ${totalUnabsorbed} raw entries on disk. Absorb is deprecated — see 'agentx wiki absorb --help'.`))\n console.log()\n }\n })\n\n// agentx wiki lint\nwiki\n .command(\"lint\")\n .description(\"check wiki for issues per agent\")\n .option(\"--dir <path>\", \"wiki directory\")\n .option(\"--mode <mode>\", \"graph (default, canonical) | unified | flat (legacy, back-compat)\", \"graph\")\n .option(\"--agent <id>\", \"lint a specific agent's wiki\")\n .action((opts) => {\n const hub = getHub(opts.dir, opts.mode as WikiMode)\n const agents = opts.agent ? [opts.agent] : hub.listAgents()\n let totalIssues = 0\n\n console.log()\n for (const agentId of agents) {\n const store = hub.getAgentWiki(agentId)\n const issues = store.lint()\n totalIssues += issues.length\n\n if (issues.length === 0) {\n console.log(` ${chalk.cyan(agentId)}: ${chalk.green(\"healthy\")}`)\n } else {\n console.log(` ${chalk.cyan(agentId)}: ${chalk.yellow(`${issues.length} issues`)}`)\n for (const issue of issues) {\n const icon = issue.type === \"broken-link\" ? \"x\" : issue.type === \"orphan\" ? \"?\" : \"!\"\n console.log(` [${icon}] ${chalk.dim(issue.type)} ${issue.article}: ${issue.message}`)\n }\n }\n }\n\n console.log()\n if (totalIssues === 0) {\n console.log(chalk.green(\" All agent wikis are healthy\"))\n }\n console.log()\n })\n\n// agentx wiki absorb — Farzapedia-faithful compilation.\n// Reads unabsorbed raw entries, classifies by type, writes articles with\n// wikilinked `related`, updates the catalog. Phase 4 un-gated this after\n// the query + prune layers landed; see docs/blog/wiki-karpathy-review.\nwiki\n .command(\"absorb\")\n .description(\"compile unabsorbed entries into typed per-agent wiki articles (Farzapedia-faithful)\")\n .option(\"--dir <path>\", \"wiki directory\")\n .option(\"--mode <mode>\", \"graph (default, canonical) | unified | flat (legacy, back-compat)\", \"graph\")\n .option(\"--agent <id>\", \"absorb only this agent\")\n .option(\"--dry-run\", \"preview without running\")\n .option(\"--max <n>\", \"max entries per agent\", \"10\")\n .action(async (opts) => {\n const mode = opts.mode as WikiMode\n const hub = getHub(opts.dir, mode)\n const agents = opts.agent ? [opts.agent] : hub.listAgents()\n const maxEntries = parseInt(opts.max)\n\n // Build a lookup so each absorbed article can carry the intent path\n // its source entries were classified into. Without this, graphPath stays\n // empty and the wiki retrieval scorer multiplies the graph weight by 0.\n // Best-effort: graph may be disabled, store may be empty — we just fall\n // through to legacy behaviour (graphPath undefined) in those cases.\n const graphStore = (() => {\n try {\n const baseDir = resolve(process.cwd(), \".agentx/graph\")\n if (!existsSync(baseDir)) return null\n return new GraphStore({ baseDir })\n } catch { return null }\n })()\n const fpToPath = new Map<string, string[]>()\n if (graphStore) {\n try {\n const idx = graphStore.loadIndex()\n for (const [fp, e] of Object.entries(idx.entries)) {\n fpToPath.set(fp, (e as any).path)\n }\n } catch { /* leave map empty */ }\n }\n const lookupPath = (entry: { content: string; source?: string; meta?: Record<string, unknown> }): string[] | undefined => {\n // Preferred: entry was stamped with the classifier's path at creation\n // time (registry.ts addEntry call). Free, exact, no fingerprint dance.\n const stamped = (entry.meta as any)?.intentPath\n if (Array.isArray(stamped) && stamped.every((s: unknown) => typeof s === \"string\") && stamped.length > 0) {\n return stamped\n }\n // Fallback for legacy entries: try the fingerprint cache. Often misses\n // because entry.content has a \"User: \" prefix and entry.source can\n // include @<node>; surfaced here for completeness, not as a guarantee.\n if (!graphStore || fpToPath.size === 0) return undefined\n const sender = String((entry.meta as any)?.sender ?? \"\")\n const fp = graphStore.fingerprint({\n text: entry.content,\n channel: entry.source,\n sender,\n })\n return fpToPath.get(fp)\n }\n const pickGraphPath = (sources: string[], entries: Array<{ id: string; content: string; source: string; meta?: Record<string, unknown> }>): string[] | undefined => {\n const counts = new Map<string, { path: string[]; n: number }>()\n for (const sid of sources) {\n const entry = entries.find((e) => e.id === sid)\n if (!entry) continue\n const path = lookupPath(entry)\n if (!path?.length) continue\n const key = path.join(\"/\")\n const cur = counts.get(key)\n if (cur) cur.n++\n else counts.set(key, { path, n: 1 })\n }\n if (counts.size === 0) return undefined\n let best: { path: string[]; n: number } | undefined\n for (const v of counts.values()) if (!best || v.n > best.n) best = v\n return best?.path\n }\n\n let totalAbsorbed = 0\n let totalWithPath = 0\n\n for (const agentId of agents) {\n const unabsorbed = hub.getUnabsorbedEntries(agentId).slice(0, maxEntries)\n\n if (unabsorbed.length === 0) {\n console.log(` ${chalk.cyan(agentId)}: ${chalk.green(\"all absorbed\")}`)\n continue\n }\n\n console.log()\n console.log(chalk.bold(` ${chalk.cyan(agentId)}: ${unabsorbed.length} entries to absorb`))\n for (const e of unabsorbed.slice(0, 3)) {\n console.log(chalk.dim(` [${e.date} via ${e.source}] ${e.content.slice(0, 80)}...`))\n }\n if (unabsorbed.length > 3) console.log(chalk.dim(` ... and ${unabsorbed.length - 3} more`))\n\n if (opts.dryRun) continue\n\n // Get this agent's wiki store\n const agentWiki = hub.getAgentWiki(agentId)\n\n // Build prompt using mode-specific template\n const existingIndex = agentWiki.rebuildIndex()\n const worldview = agentWiki.getWorldview() || hub.getSharedStore().getWorldview() || \"\"\n const entryTexts = unabsorbed.map(e =>\n `--- ENTRY ${e.id} [${e.date} ${e.agentId} via ${e.source}] ---\\n${e.content}\\n--- END ENTRY ---`\n ).join(\"\\n\\n\")\n\n const prompt = buildAbsorbPrompt(mode, agentId, worldview, existingIndex.articles, entryTexts, unabsorbed.length)\n console.log(chalk.dim(` Mode: ${modeLabel(mode)}`))\n\n // Write prompt and run Claude\n const tmpDir = resolve(agentWiki[\"baseDir\"], \"_tmp\")\n mkdirSync(tmpDir, { recursive: true })\n const promptPath = resolve(tmpDir, \"absorb-prompt.txt\")\n writeFileSync(promptPath, prompt)\n\n console.log(chalk.dim(` Compiling with Claude...`))\n\n try {\n let rawOutput: string\n try {\n rawOutput = execSync(\n `cat '${promptPath}' | claude -p - --output-format json --max-turns 3 --model sonnet --disallowedTools \"Bash Read Write Edit Glob Grep Agent WebSearch WebFetch NotebookEdit\"`,\n { encoding: \"utf-8\", timeout: 900_000, maxBuffer: 10 * 1024 * 1024 },\n )\n } catch (execErr: any) {\n rawOutput = execErr.stdout || \"\"\n if (!rawOutput) throw execErr\n }\n\n // Parse Claude's response — may be JSON envelope or raw text\n let responseText = rawOutput\n\n // Try to extract \"result\" from Claude's JSON envelope\n try {\n const envelope = JSON.parse(rawOutput)\n responseText = envelope.result || envelope.content || \"\"\n if (!responseText) {\n console.log(chalk.dim(` Claude envelope keys: ${Object.keys(envelope).join(\", \")}`))\n console.log(chalk.dim(` is_error: ${envelope.is_error}, stop_reason: ${envelope.stop_reason}`))\n }\n } catch {\n // Not a JSON envelope — use as-is\n }\n\n // Parse response — could be { articles: [...], gaps: [...] } or bare [...]\n let articles: Array<{ path: string; title: string; tags: string[]; content: string; sources: string[]; type?: string; related?: string[] }>\n let gaps: string[] = []\n\n // Find outermost JSON object or array. New prompt emits { articles, gaps };\n // legacy arrays are tolerated for back-compat during migration.\n const objStart = responseText.indexOf(\"{\")\n const arrStart = responseText.indexOf(\"[\")\n const jsonStart = (objStart >= 0 && (arrStart < 0 || objStart < arrStart)) ? objStart : arrStart\n\n if (jsonStart === -1) {\n console.log(chalk.red(` No JSON found in response`))\n console.log(chalk.dim(responseText.slice(0, 500)))\n continue\n }\n\n const openChar = responseText[jsonStart]\n const closeChar = openChar === \"{\" ? \"}\" : \"]\"\n let depth = 0\n let jsonEnd = -1\n for (let i = jsonStart; i < responseText.length; i++) {\n if (responseText[i] === openChar) depth++\n else if (responseText[i] === closeChar) { depth--; if (depth === 0) { jsonEnd = i + 1; break } }\n }\n\n if (jsonEnd === -1) { console.log(chalk.red(` Unbalanced JSON`)); continue }\n\n const jsonStr = responseText.slice(jsonStart, jsonEnd)\n try {\n const parsed = JSON.parse(jsonStr)\n if (Array.isArray(parsed)) {\n articles = parsed\n } else {\n articles = parsed.articles || []\n gaps = parsed.gaps || []\n }\n } catch (parseErr: any) {\n console.log(chalk.red(` JSON parse error: ${parseErr.message}`))\n console.log(chalk.dim(` First 300 chars: ${jsonStr.slice(0, 300)}`))\n continue\n }\n\n for (const article of articles) {\n const now = new Date().toISOString().slice(0, 10)\n const graphPath = pickGraphPath(article.sources || [], unabsorbed)\n agentWiki.writeArticle(article.path, {\n title: article.title,\n type: article.type as any,\n related: Array.isArray(article.related) ? article.related : undefined,\n tags: article.tags || [],\n owner: agentId,\n access: \"public\",\n created: now,\n lastUpdated: now,\n sources: article.sources || [],\n graphPath,\n }, article.content, agentId)\n\n const typeTag = article.type ? chalk.magenta(`[${article.type}]`) + \" \" : \"\"\n const relStr = Array.isArray(article.related) && article.related.length\n ? ` → ${article.related.slice(0, 3).join(\", \")}${article.related.length > 3 ? \", …\" : \"\"}`\n : \"\"\n console.log(` ${chalk.green(\"+\")} ${typeTag}${article.path}: ${article.title}${chalk.dim(relStr)}`)\n const tagStr = (article.tags || []).slice(0, 4).join(\", \")\n if (tagStr) console.log(chalk.dim(` tags: ${tagStr}`))\n if (graphPath?.length) {\n console.log(chalk.dim(` graphPath: ${graphPath.join(\" › \")}`))\n totalWithPath++\n }\n totalAbsorbed++\n }\n\n // Show gaps (missing puzzle pieces)\n if (gaps.length > 0) {\n console.log()\n console.log(chalk.yellow(` Gaps detected (${gaps.length} missing pieces):`))\n for (const gap of gaps) {\n console.log(chalk.yellow(` ? ${gap}`))\n }\n }\n\n agentWiki.rebuildIndex()\n } catch (e: any) {\n console.log(chalk.red(` Absorb failed: ${e.message?.slice(0, 200)}`))\n if (e.stderr) console.log(chalk.dim(String(e.stderr).slice(0, 300)))\n if (e.stdout) console.log(chalk.dim(\"stdout: \" + String(e.stdout).slice(0, 300)))\n }\n }\n\n console.log()\n if (opts.dryRun) {\n console.log(chalk.dim(\" Dry run — no changes made\"))\n } else if (totalAbsorbed > 0) {\n console.log(chalk.green(` ${totalAbsorbed} articles compiled across ${agents.length} agent(s)`))\n if (graphStore) {\n const pct = totalAbsorbed > 0 ? Math.round((totalWithPath / totalAbsorbed) * 100) : 0\n console.log(chalk.dim(` ${totalWithPath}/${totalAbsorbed} carry graphPath (${pct}%) — wiki retrieval graph weight is now non-zero for those`))\n }\n }\n console.log()\n })\n\n// agentx wiki promote — memory→wiki promotion. Reads per-agent memories\n// (.agentx/agent-memory/), has an LLM judge which are durable and\n// cross-agent relevant, and writes them as [[wikilinked]] articles in the\n// SHARED store under owner \"memory-promoter\". Idempotent via stamps in\n// article sources[] + the _memory-promotions.json skip ledger — the\n// planned follow-up documented in agents/agent-memory.ts.\nwiki\n .command(\"promote\")\n .description(\"promote per-agent memories into shared, authoritative wiki articles\")\n .option(\"--dir <path>\", \"wiki directory (default .agentx/wiki)\")\n .option(\"--memory-dir <path>\", \"the .agentx dir holding agent-memory/ (default .agentx)\")\n .option(\"--since <duration>\", \"memory window, e.g. 24h, 7d\", \"7d\")\n .option(\"--agent <id>\", \"only this agent's memories\")\n .option(\"--types <list>\", \"comma-separated memory types\", \"project,reference,feedback\")\n .option(\"--max <n>\", \"max candidate memories per run\", \"20\")\n .option(\"--via <agentId>\", \"route the LLM call through an agent — uses the agent's own session, no API key\")\n .option(\"--model <model>\", \"direct Anthropic API — needs ANTHROPIC_API_KEY\")\n .option(\"--daemon <url>\", \"daemon API base URL for --via\", \"http://127.0.0.1:18800\")\n .option(\"--commit\", \"write articles and ledger (default: dry-run)\", false)\n .action(async (opts) => {\n const sinceMs = parsePromoteSince(opts.since)\n const types = String(opts.types).split(\",\").map((t: string) => t.trim()).filter(Boolean)\n const validTypes = [\"user\", \"feedback\", \"project\", \"reference\"]\n const badType = types.find((t: string) => !validTypes.includes(t))\n if (badType) {\n console.log(chalk.red(` Invalid memory type \"${badType}\". Valid: ${validTypes.join(\", \")}`))\n process.exit(1)\n }\n if (opts.commit && !opts.via && !opts.model) {\n console.log(chalk.red(\" --commit needs an LLM: pass --via <agentId> or --model <model>\"))\n process.exit(1)\n }\n\n console.log()\n console.log(chalk.bold(\" Memory → Wiki Promotion\"))\n console.log()\n\n const report = await runPromotion({\n wikiDir: opts.dir ? resolve(opts.dir) : undefined,\n memoryRoot: opts.memoryDir ? resolve(opts.memoryDir) : undefined,\n sinceMs,\n agentFilter: opts.agent,\n types: types as import(\"@/agents/agent-memory\").MemoryType[],\n max: Number(opts.max) || 20,\n viaAgent: opts.via,\n model: opts.model,\n daemonUrl: opts.daemon,\n commit: opts.commit,\n log: (msg) => console.log(chalk.dim(` ${msg}`)),\n })\n\n if (report.candidates.length === 0) {\n console.log(chalk.dim(\" Nothing unpromoted in window\"))\n console.log()\n return\n }\n\n console.log(` ${report.candidates.length} candidate(s) in ${report.clusters.length} cluster(s):`)\n for (const cluster of report.clusters) {\n const c = cluster.candidates[0]\n const corr = cluster.corroboratingAgents.length > 1\n ? chalk.green(` ×${cluster.corroboratingAgents.length} agents`)\n : \"\"\n console.log(` ${chalk.cyan(`[${c.memory.type}]`)} ${c.memory.name}${corr} ${chalk.dim(`(${cluster.corroboratingAgents.join(\", \")}, conf ${cluster.confidence.toFixed(2)})`)}`)\n console.log(chalk.dim(` ${c.memory.description}`))\n }\n console.log()\n\n if (report.dryRun) {\n console.log(chalk.dim(\" Dry run — pass --commit to promote\"))\n console.log()\n return\n }\n\n for (const w of report.written) {\n const typeTag = w.type ? chalk.magenta(`[${w.type}]`) + \" \" : \"\"\n const relStr = w.related?.length\n ? ` → ${w.related.slice(0, 3).join(\", \")}${w.related.length > 3 ? \", …\" : \"\"}`\n : \"\"\n console.log(` ${chalk.green(\"+\")} ${typeTag}${w.path}: ${w.title}${chalk.dim(relStr)}`)\n console.log(chalk.dim(` from: ${w.stamps.join(\", \")}`))\n }\n for (const s of report.skipped) {\n console.log(` ${chalk.yellow(\"-\")} ${s.stamp} ${chalk.dim(`— ${s.reason}`)}`)\n }\n if (report.gaps.length) {\n console.log()\n console.log(chalk.yellow(` Gaps (${report.gaps.length}):`))\n for (const gap of report.gaps) console.log(chalk.yellow(` ? ${gap}`))\n }\n for (const wmsg of report.warnings) console.log(chalk.dim(` ! ${wmsg}`))\n for (const err of report.errors) console.log(chalk.red(` x ${err}`))\n console.log()\n console.log(\n report.errors.length\n ? chalk.red(` ${report.written.length} promoted, ${report.errors.length} error(s)`)\n : chalk.green(` ${report.written.length} promoted, ${report.skipped.length} skipped`),\n )\n console.log()\n if (report.errors.length) process.exit(1)\n })\n\n/** \"24h\" / \"7d\" / \"30m\" → window in ms. (Same grammar as workflow absorb's\n * parseSince, but returns the window size — runPromotion applies the clock.) */\nfunction parsePromoteSince(input: string | undefined): number | undefined {\n if (!input) return undefined\n const m = /^(\\d+)\\s*([smhd])$/.exec(input.trim())\n if (!m) {\n console.log(chalk.red(` Invalid --since \"${input}\". Use \"30m\", \"24h\", or \"7d\".`))\n process.exit(1)\n }\n const n = Number(m[1])\n const unit = m[2]\n return n * (unit === \"s\" ? 1000 : unit === \"m\" ? 60_000 : unit === \"h\" ? 3600_000 : 86_400_000)\n}\n\n// agentx wiki ab-test — compare old BM25 preload vs new agentic query on\n// real messages pulled from .agentx/task-history. Emits a markdown report\n// with both retrieval paths side-by-side so the operator can rate.\nwiki\n .command(\"ab-test\")\n .description(\"side-by-side comparison: BM25 preload (old) vs agentic query (new) on real task-history messages\")\n .option(\"--dir <path>\", \"wiki directory\")\n .option(\"--agent <id>\", \"which agent to test against (required)\")\n .option(\"--history <path>\", \"task-history root\", resolve(process.cwd(), \".agentx/task-history\"))\n .option(\"--n <n>\", \"number of messages to sample (newest first)\", \"10\")\n .option(\"--out <path>\", \"markdown output file (default: stdout)\")\n .option(\"--selector-model <m>\", \"agentic selector model\", \"haiku\")\n .option(\"--synth-model <m>\", \"agentic synthesis model\", \"sonnet\")\n .action(async (opts) => {\n const { agenticQuery } = await import(\"@/wiki/query\")\n const { readdirSync: rd, readFileSync: rf, existsSync: ex } = await import(\"fs\")\n const { resolve: rv, join: jn } = await import(\"path\")\n\n const hub = getHub(opts.dir)\n const agentId = opts.agent\n if (!agentId) {\n console.log(chalk.red(\" --agent <id> is required\"))\n return\n }\n const store = hub.getAgentWiki(agentId)\n const n = parseInt(opts.n)\n\n // Gather recent task messages from .agentx/task-history/<agent>/<YYYY-MM-DD>/*.json\n const agentHistDir = rv(opts.history, agentId)\n if (!ex(agentHistDir)) {\n console.log(chalk.yellow(` no task-history at ${agentHistDir}`))\n return\n }\n type Task = { id: string; message: string; ts: string }\n const tasks: Task[] = []\n const days = rd(agentHistDir).sort().reverse() // newest day first\n for (const day of days) {\n const dayDir = jn(agentHistDir, day)\n let files: string[] = []\n try { files = rd(dayDir).filter(f => f.endsWith(\".json\")).sort().reverse() } catch { continue }\n for (const f of files) {\n if (tasks.length >= n) break\n try {\n const rec = JSON.parse(rf(jn(dayDir, f), \"utf-8\"))\n const msg = rec.message || rec.task?.message\n if (typeof msg === \"string\" && msg.trim().length > 10) {\n tasks.push({ id: rec.id || f.replace(\".json\", \"\"), message: msg.trim(), ts: rec.at || rec.timestamp || day })\n }\n } catch {}\n }\n if (tasks.length >= n) break\n }\n\n if (tasks.length === 0) {\n console.log(chalk.yellow(` no task messages found under ${agentHistDir}`))\n return\n }\n\n console.log()\n console.log(chalk.bold(` A/B harness — ${tasks.length} messages from ${agentId}`))\n console.log(chalk.dim(` OLD: findRelevant() BM25 over title+tags+content, top 3 truncated`))\n console.log(chalk.dim(` NEW: agenticQuery() catalog+wikilink walk (selector=${opts.selectorModel}, synth=${opts.synthModel})`))\n console.log()\n\n const lines: string[] = [\n `# Wiki A/B: ${agentId}`,\n \"\",\n `_Generated ${new Date().toISOString()} · ${tasks.length} messages sampled_`,\n \"\",\n \"For each message, the OLD BM25 retrieval (what Layer 10 used to preload) is shown alongside the NEW agentic query's selected articles + synthesized answer. Rate each pair on relevance 0–2 in the notes column.\",\n \"\",\n ]\n\n for (let i = 0; i < tasks.length; i++) {\n const t = tasks[i]\n process.stdout.write(chalk.dim(` [${i + 1}/${tasks.length}] querying... `))\n\n // OLD\n const old = store.findRelevant(t.message, agentId, 3)\n const oldTitles = old.map(a => `- **${a.meta.title}** [${a.meta.type || \"?\"}] (${a.path})`).join(\"\\n\") || \"_(none returned)_\"\n\n // NEW\n let newBlock: string\n try {\n const q = await agenticQuery(t.message, store, agentId, {\n selectorModel: opts.selectorModel,\n synthModel: opts.synthModel,\n })\n if (q.status !== \"ok\") {\n newBlock = `_(status: ${q.status}${q.error ? \" — \" + q.error : \"\"})_`\n } else {\n const cites = q.citations.map(c => `\\`${c.title}\\` [${c.type || \"?\"}]`).join(\", \")\n newBlock = `**Answer:**\\n\\n${q.answer}\\n\\n**Citations:** ${cites}`\n }\n } catch (e: any) {\n newBlock = `_(error: ${e.message})_`\n }\n console.log(chalk.dim(\"done\"))\n\n lines.push(\n `## ${i + 1}. ${t.id}`,\n \"\",\n `> ${t.message.replace(/\\n/g, \" \").slice(0, 400)}${t.message.length > 400 ? \"…\" : \"\"}`,\n \"\",\n \"### OLD — BM25 preload (top 3)\",\n \"\",\n oldTitles,\n \"\",\n \"### NEW — agentic query\",\n \"\",\n newBlock,\n \"\",\n \"| Path | Rating 0–2 | Notes |\",\n \"|---|---|---|\",\n \"| OLD | | |\",\n \"| NEW | | |\",\n \"\",\n )\n }\n\n const out = lines.join(\"\\n\")\n if (opts.out) {\n (await import(\"fs\")).writeFileSync(opts.out, out)\n console.log()\n console.log(chalk.green(` Wrote ${out.length} bytes to ${opts.out}`))\n } else {\n console.log()\n console.log(out)\n }\n })\n\n// agentx wiki interview — interactive write-side for the wiki.\n// Operator answers a short question bank per article type; an LLM\n// synthesizes a Farzapedia-shape article from the transcript. Accounts\n// for the \"absorb only captures what's already been said in channels\"\n// gap — this is where knowledge lives in your head.\nwiki\n .command(\"interview\")\n .description(\"interactive interview session — Q&A with an LLM synthesizer, produces one typed wiki article\")\n .option(\"--dir <path>\", \"wiki directory\")\n .option(\"--agent <id>\", \"which agent's wiki to write to (required)\")\n .option(\"--topic <text>\", \"what to interview about (e.g. 'MTGL deployment procedure')\")\n .option(\"--type <t>\", \"article type hint (person|project|place|concept|event|decision|pattern)\")\n .option(\"--model <m>\", \"synthesis model\", \"sonnet\")\n .option(\"--no-commit\", \"show the draft but don't write\")\n .option(\"--answers <path>\", \"non-interactive: one answer per line (same order as questions); last line = save|edit|scrap\")\n .action(async (opts) => {\n const readline = await import(\"node:readline/promises\")\n const { randomUUID } = await import(\"node:crypto\")\n const { WIKI_ARTICLE_TYPES } = await import(\"@/wiki/types\")\n\n // --answers: read all lines up front; feed them to each `ask()`.\n // Avoids readline/stdin interaction entirely for scripted runs.\n const scripted = opts.answers\n ? (readFileSync(opts.answers, \"utf-8\").split(/\\r?\\n/).filter(l => l.length > 0))\n : null\n let scriptCursor = 0\n\n if (!opts.agent) {\n console.log(chalk.red(\" --agent <id> is required. The article will be owned by this agent.\"))\n return\n }\n const hub = getHub(opts.dir)\n let store\n try { store = hub.getAgentWiki(opts.agent) } catch (e: any) {\n console.log(chalk.red(` can't open wiki for agent \"${opts.agent}\": ${e.message}`))\n return\n }\n\n const rl = scripted\n ? null\n : readline.createInterface({ input: process.stdin, output: process.stdout })\n const ask = async (prompt: string): Promise<string> => {\n if (scripted) {\n const answer = scripted[scriptCursor++] ?? \"\"\n process.stdout.write(prompt + chalk.dim(`[scripted] ${answer.slice(0, 80)}${answer.length > 80 ? \"…\" : \"\"}`) + \"\\n\")\n return answer.trim()\n }\n return (await rl!.question(prompt)).trim()\n }\n\n console.log()\n console.log(chalk.bold(\" Wiki Interview\"))\n console.log(chalk.dim(\" One article per session. Empty answer = skip field. /done = stop & synthesize. /abort = quit.\"))\n console.log()\n\n // Topic\n let topic = opts.topic || \"\"\n if (!topic) {\n topic = await ask(chalk.cyan(\" Topic? \") + chalk.dim(\"(a person, a procedure, a past event, …) \"))\n if (!topic || topic === \"/abort\") { rl?.close(); return }\n }\n\n // Type\n let type = (opts.type || \"\").toLowerCase()\n const validTypes = new Set(WIKI_ARTICLE_TYPES as readonly string[])\n if (!validTypes.has(type)) {\n console.log(chalk.dim(` Types: ${WIKI_ARTICLE_TYPES.join(\" | \")}`))\n const picked = await ask(chalk.cyan(\" Type? \"))\n if (picked === \"/abort\") { rl?.close(); return }\n if (!validTypes.has(picked)) {\n console.log(chalk.yellow(` \"${picked}\" isn't a valid type. Falling back to \"concept\".`))\n type = \"concept\"\n } else {\n type = picked\n }\n }\n\n // Question bank per type\n const QUESTIONS: Record<string, string[]> = {\n person: [\n \"Full name (and any aliases / Telegram handle / GitLab username)?\",\n \"Role or title?\",\n \"Which org or team are they part of (use the article title if you have one)?\",\n \"Key responsibilities in OUR work?\",\n \"Preferred channel to reach them (Telegram, email, in-person, …)?\",\n \"Who do they report to? (skip if none)\",\n \"Notable decisions, events, or patterns they're involved in?\",\n \"Anything quirky we should remember (timezone, working hours, style)?\",\n ],\n project: [\n \"One-line description — what is this project?\",\n \"Who owns it? (person article title)\",\n \"Tech stack or key tools involved?\",\n \"Current status (active / paused / archived)?\",\n \"Repo / URL / path on disk?\",\n \"Two or three key decisions made so far?\",\n \"Any open blockers, risks, or known issues?\",\n \"Related projects or patterns?\",\n ],\n place: [\n \"Kind — office / server / environment / domain / URL?\",\n \"Address — URL, IP, hostname, or physical location?\",\n \"Owner (person or team)?\",\n \"How to access it (SSH host, login, VPN, …)?\",\n \"What lives there (services, people, data)?\",\n \"Known quirks (timezone, uptime, access restrictions)?\",\n ],\n concept: [\n \"Define it in one sentence — what does this term mean in OUR work?\",\n \"Where did we first adopt it (origin story, date)?\",\n \"Two or three concrete examples from our team?\",\n \"What does it replace or extend (older concept, related concept)?\",\n \"Common misunderstandings to avoid?\",\n ],\n event: [\n \"Date (YYYY-MM-DD)?\",\n \"One-line summary — what happened?\",\n \"Who was involved?\",\n \"Timeline — key moments (start → resolution)?\",\n \"Impact — what broke, what got delivered, who was affected?\",\n \"Resolution / outcome?\",\n \"Follow-ups or lessons captured?\",\n ],\n decision: [\n \"Context — what was the situation forcing a choice?\",\n \"Options that were considered?\",\n \"Chosen option — and one-sentence why?\",\n \"Alternatives rejected — and one-sentence why not?\",\n \"Who decided, and when (date)?\",\n \"Is this reversible, and what would trigger a revisit?\",\n ],\n pattern: [\n \"Trigger — when should someone follow this pattern?\",\n \"Inputs required (what do you need before starting)?\",\n \"Steps in order — keep it tight, one line per step?\",\n \"Expected output — how do you know it worked?\",\n \"Common failure modes?\",\n \"Related patterns, decisions, or runbooks?\",\n ],\n }\n const questions = QUESTIONS[type] || QUESTIONS.concept\n\n // Ask each question\n console.log()\n console.log(chalk.bold(` Topic: ${chalk.cyan(topic)} · Type: ${chalk.magenta(type)}`))\n console.log(chalk.dim(` ${questions.length} questions. Skip with empty answer. /done to stop early.`))\n console.log()\n\n type QA = { q: string; a: string }\n const qas: QA[] = []\n let aborted = false\n for (let i = 0; i < questions.length; i++) {\n const q = questions[i]\n const a = await ask(` ${chalk.dim(`[${i + 1}/${questions.length}]`)} ${q}\\n ${chalk.green(\">\")} `)\n if (a === \"/abort\") { aborted = true; break }\n if (a === \"/done\") break\n if (a === \"/skip\") continue\n if (a) qas.push({ q, a })\n }\n\n // Always ask for anything extra\n if (!aborted) {\n const extra = await ask(`\\n ${chalk.dim(\"Anything else worth capturing?\")}\\n ${chalk.green(\">\")} `)\n if (extra && extra !== \"/abort\" && extra !== \"/done\") qas.push({ q: \"Anything else worth capturing?\", a: extra })\n }\n\n if (aborted || qas.length === 0) {\n console.log(chalk.yellow(\"\\n Nothing captured. Exiting.\"))\n rl?.close()\n return\n }\n\n // Build the catalog slice for wikilink grounding (first 40 titles max)\n const existingArticles = store.listArticles(opts.agent).slice(0, 40)\n const catalogLines = existingArticles\n .map(a => `- ${a.meta.title} [${a.meta.type || \"?\"}]`)\n .join(\"\\n\")\n\n const synthesisPrompt = [\n `You are compiling one Farzapedia-style wiki article from an operator interview transcript.`,\n ``,\n `**Topic:** ${topic}`,\n `**Type:** ${type}`,\n `**Owning agent:** ${opts.agent}`,\n ``,\n `## Transcript`,\n ...qas.map(x => `\\nQ: ${x.q}\\nA: ${x.a}`),\n ``,\n `## Existing articles (use [[Title]] wikilinks when referencing these)`,\n catalogLines || \"(none yet)\",\n ``,\n `## Output rules`,\n `- Output EXACTLY one markdown file: frontmatter (---) + body. No code fences, no preamble.`,\n `- Frontmatter fields in this exact order: title, type, related, tags, owner, access, created, last_updated, sources.`,\n ` - \\`title\\`: \"…\"`,\n ` - \\`type\\`: ${type}`,\n ` - \\`related\\`: [\"Article Title\", …] (titles that exist in the catalog above; drop if none)`,\n ` - \\`tags\\`: 2-4 specific tags, lowercase-kebab — no dates unless type=event`,\n ` - \\`owner\\`: ${opts.agent}`,\n ` - \\`access\\`: public (unless the content is sensitive)`,\n ` - \\`created\\`: ${new Date().toISOString().slice(0, 10)}`,\n ` - \\`last_updated\\`: ${new Date().toISOString().slice(0, 10)}`,\n ` - \\`sources\\`: [\"interview-${new Date().toISOString().slice(0, 10)}\"]`,\n `- Body: 20-80 lines, Wikipedia-style, organized by theme (not by question), synthesized (not verbatim Q&A).`,\n `- Use [[Title]] inline every time you reference something that has an article in the catalog.`,\n `- Do NOT invent facts. If the transcript didn't cover something, skip that sub-topic.`,\n ].join(\"\\n\")\n\n // Write prompt to tmp, run claude -p\n const tmpDir = resolve(store.baseDir, \"_tmp\")\n mkdirSync(tmpDir, { recursive: true })\n const promptPath = resolve(tmpDir, `interview-${randomUUID().slice(0, 8)}.txt`)\n writeFileSync(promptPath, synthesisPrompt)\n\n console.log()\n console.log(chalk.dim(` Synthesizing draft with ${opts.model}...`))\n\n let draft = \"\"\n try {\n const cmd = `cat '${promptPath}' | claude -p - --output-format json --max-turns 1 --model ${opts.model} --disallowedTools \"Bash Read Write Edit Glob Grep Agent WebSearch WebFetch NotebookEdit\"`\n const raw = execSync(cmd, { encoding: \"utf-8\", timeout: 180_000, maxBuffer: 4 * 1024 * 1024 })\n try {\n const envelope = JSON.parse(raw)\n draft = String(envelope.result || envelope.content || \"\")\n } catch {\n draft = raw\n }\n } catch (e: any) {\n console.log(chalk.red(` synthesis failed: ${e.message?.slice(0, 200)}`))\n rl?.close()\n return\n }\n\n // Strip any wrapping code fences / preamble\n draft = draft.trim()\n const fence = draft.match(/```(?:markdown|md)?\\s*\\n([\\s\\S]*?)\\n```\\s*$/)\n if (fence) draft = fence[1].trim()\n // If there's a preamble before the `---`, drop it\n const fmStart = draft.indexOf(\"---\")\n if (fmStart > 0) draft = draft.slice(fmStart)\n\n // Parse frontmatter to extract title + type\n const fmMatch = draft.match(/^---\\n([\\s\\S]*?)\\n---\\n([\\s\\S]*)$/)\n if (!fmMatch) {\n console.log(chalk.red(\" LLM output is not a valid frontmatter+body article:\"))\n console.log(draft.slice(0, 600))\n rl?.close()\n return\n }\n const fm: Record<string, string> = {}\n for (const line of fmMatch[1].split(\"\\n\")) {\n const m = line.match(/^(\\w+):\\s*(.+)$/)\n if (m) fm[m[1]] = m[2].trim().replace(/^\"(.*)\"$/, \"$1\")\n }\n const body = fmMatch[2]\n const title = fm.title || topic\n const slug = title.toLowerCase().replace(/[^a-z0-9]+/g, \"-\").replace(/^-+|-+$/g, \"\").slice(0, 60)\n // Use canonical per-type directory names. Most types pluralise with +s,\n // but \"person\" goes in \"people/\" (English irregular plural — and matches\n // what Farzapedia / our catalog groupings use everywhere else).\n const TYPE_DIR: Record<string, string> = {\n person: \"people\", project: \"projects\", place: \"places\",\n concept: \"concepts\", event: \"events\", decision: \"decisions\", pattern: \"patterns\",\n }\n const articlePath = `${TYPE_DIR[type] || type + \"s\"}/${slug}.md`\n\n console.log()\n console.log(chalk.bold(\" === Draft preview ===\"))\n console.log(chalk.dim(` Path: ${articlePath}`))\n console.log()\n console.log(draft)\n console.log()\n\n const choice = await ask(` ${chalk.green(\"save\")} / ${chalk.yellow(\"edit (opens $EDITOR)\")} / ${chalk.red(\"scrap\")} ? `)\n rl?.close()\n\n if (choice === \"scrap\" || choice === \"/abort\") {\n console.log(chalk.dim(\" Discarded.\"))\n return\n }\n if (!opts.commit) {\n console.log(chalk.dim(\" --no-commit: not writing.\"))\n console.log(chalk.dim(` Draft kept at ${promptPath} (prompt only; no article file)`))\n return\n }\n\n // Optional editor pass\n let finalContent = body\n let finalMeta: Record<string, any> = {\n title,\n type: fm.type || type,\n related: fm.related\n ? fm.related.replace(/^\\[|\\]$/g, \"\").split(\",\").map(s => s.trim().replace(/^\"(.*)\"$/, \"$1\")).filter(Boolean)\n : undefined,\n tags: fm.tags\n ? fm.tags.replace(/^\\[|\\]$/g, \"\").split(\",\").map(s => s.trim().replace(/^\"(.*)\"$/, \"$1\")).filter(Boolean)\n : [],\n owner: opts.agent,\n access: fm.access || \"public\",\n created: fm.created || new Date().toISOString().slice(0, 10),\n lastUpdated: fm.last_updated || new Date().toISOString().slice(0, 10),\n sources: [`interview-${new Date().toISOString().slice(0, 10)}`],\n }\n\n if (choice === \"edit\") {\n const editor = process.env.EDITOR || \"vi\"\n const editPath = resolve(tmpDir, `draft-${randomUUID().slice(0, 8)}.md`)\n writeFileSync(editPath, draft)\n try {\n execSync(`${editor} '${editPath}'`, { stdio: \"inherit\" })\n const edited = readFileSync(editPath, \"utf-8\")\n const m = edited.match(/^---\\n([\\s\\S]*?)\\n---\\n([\\s\\S]*)$/)\n if (m) {\n const ef: Record<string, string> = {}\n for (const line of m[1].split(\"\\n\")) {\n const mm = line.match(/^(\\w+):\\s*(.+)$/)\n if (mm) ef[mm[1]] = mm[2].trim().replace(/^\"(.*)\"$/, \"$1\")\n }\n finalContent = m[2]\n finalMeta = {\n ...finalMeta,\n title: ef.title || finalMeta.title,\n type: ef.type || finalMeta.type,\n access: ef.access || finalMeta.access,\n related: ef.related\n ? ef.related.replace(/^\\[|\\]$/g, \"\").split(\",\").map(s => s.trim().replace(/^\"(.*)\"$/, \"$1\")).filter(Boolean)\n : finalMeta.related,\n tags: ef.tags\n ? ef.tags.replace(/^\\[|\\]$/g, \"\").split(\",\").map(s => s.trim().replace(/^\"(.*)\"$/, \"$1\")).filter(Boolean)\n : finalMeta.tags,\n }\n }\n } catch (e: any) {\n console.log(chalk.red(` editor failed: ${e.message}`))\n return\n }\n }\n\n // Write via the store — type validation kicks in\n const written = store.writeArticle(articlePath, finalMeta as any, finalContent, opts.agent)\n if (!written) {\n console.log(chalk.red(\" write failed (permission?)\"))\n return\n }\n store.rebuildIndex()\n console.log(chalk.green(` ✓ ${articlePath} saved.`))\n\n // Suggest next topics from wikilinks in the body that don't yet exist\n const referenced = store.extractWikilinks(finalContent)\n const titleIdx = new Map<string, boolean>()\n for (const a of store.listArticles(opts.agent)) titleIdx.set(a.meta.title.toLowerCase(), true)\n const gaps = referenced.filter(r => !titleIdx.has(r.toLowerCase()))\n if (gaps.length) {\n console.log()\n console.log(chalk.bold(\" Gaps referenced but not yet covered:\"))\n for (const g of gaps.slice(0, 8)) {\n console.log(chalk.dim(` - ${g}`))\n }\n console.log(chalk.dim(` Run \\`agentx wiki interview --agent ${opts.agent} --topic \"<title>\"\\` for any of these.`))\n }\n })\n\n// agentx wiki quiz — reverse interview: operator asks, agent answers\n// via agenticQuery, operator grades with /ok /correct /add /link and the\n// cited article gets patched. Grows the wiki through dialogue instead\n// of structured extraction.\nwiki\n .command(\"quiz\")\n .description(\"reverse interview — ask the wiki questions and patch cited articles with corrections, additions, or links\")\n .option(\"--dir <path>\", \"wiki directory\")\n .option(\"--agent <id>\", \"which agent's wiki to quiz (required)\")\n .option(\"--selector-model <m>\", \"candidate-selection model\", \"haiku\")\n .option(\"--synth-model <m>\", \"answer synthesis model\", \"sonnet\")\n .option(\"--patch-model <m>\", \"article patch model\", \"sonnet\")\n .option(\"--rounds <n>\", \"stop after N rounds\", \"20\")\n .option(\"--script <path>\", \"non-interactive: question line + /verdict line per entry, entries separated by blank lines\")\n .option(\"--no-commit\", \"show proposed patches but don't write\")\n .option(\"--out <path>\", \"write a session transcript as markdown\")\n .action(async (opts) => {\n const readline = await import(\"node:readline/promises\")\n const { randomUUID } = await import(\"node:crypto\")\n const { agenticQuery } = await import(\"@/wiki/query\")\n\n if (!opts.agent) {\n console.log(chalk.red(\" --agent <id> is required.\"))\n return\n }\n const hub = getHub(opts.dir)\n let store\n try { store = hub.getAgentWiki(opts.agent) } catch (e: any) {\n console.log(chalk.red(` can't open wiki for agent \"${opts.agent}\": ${e.message}`))\n return\n }\n\n type Script = { q: string; verdict: string }[]\n let script: Script | null = null\n if (opts.script) {\n const raw = readFileSync(opts.script, \"utf-8\")\n const entries = raw.split(/\\n\\s*\\n/).map(e => e.trim()).filter(Boolean)\n script = []\n for (const entry of entries) {\n const lines = entry.split(/\\r?\\n/).filter(l => l.trim())\n if (lines.length < 2) continue\n const q = lines[0].replace(/^Q:\\s*/i, \"\").trim()\n const verdict = lines.slice(1).join(\" \").trim()\n if (q && verdict) script.push({ q, verdict })\n }\n }\n\n const rl = script\n ? null\n : readline.createInterface({ input: process.stdin, output: process.stdout })\n const ask = async (prompt: string): Promise<string> => {\n if (rl) return (await rl.question(prompt)).trim()\n return \"\"\n }\n\n const rounds = Math.min(parseInt(opts.rounds) || 20, script?.length ?? 999)\n const commit = opts.commit !== false\n\n console.log()\n console.log(chalk.bold(\" Wiki Quiz\"))\n console.log(chalk.dim(` Agent: ${opts.agent} · Rounds: ${rounds} · ${commit ? \"commit\" : \"dry-run\"} · ${script ? `scripted (${script.length})` : \"interactive\"}`))\n console.log(chalk.dim(\" Verdicts: /ok /correct <note> /add <note> /link <url> /skip /done\"))\n console.log()\n\n type Entry = { q: string; answer: string; citations: Array<{ title: string; path: string; type?: string }>; verdict: string; patched?: string }\n const transcript: Entry[] = []\n let applied = 0\n\n for (let i = 0; i < rounds; i++) {\n let q: string\n let verdict: string\n if (script) {\n const entry = script[i]\n if (!entry) break\n q = entry.q\n verdict = entry.verdict\n console.log(chalk.cyan(` [${i + 1}] Q: `) + q)\n } else {\n q = await ask(chalk.cyan(` [${i + 1}] Q: `))\n if (!q || q === \"/done\" || q === \"/abort\") break\n verdict = \"\"\n }\n\n process.stdout.write(chalk.dim(\" querying... \"))\n let result\n try {\n result = await agenticQuery(q, store, opts.agent, {\n selectorModel: opts.selectorModel,\n synthModel: opts.synthModel,\n })\n } catch (e: any) {\n console.log(chalk.red(`failed: ${e.message?.slice(0, 120)}`))\n continue\n }\n console.log(chalk.dim(\"done\"))\n\n if (result.status !== \"ok\") {\n console.log(chalk.yellow(` (status: ${result.status}${result.error ? \" — \" + result.error : \"\"})`))\n } else {\n const cites = result.citations.map(c => `${c.title} [${c.type || \"?\"}]`).join(\" · \")\n console.log()\n console.log(chalk.dim(\" A: \") + result.answer.replace(/\\n/g, \"\\n \"))\n console.log(chalk.dim(\" citations: \" + cites))\n }\n\n if (!script) {\n verdict = await ask(chalk.cyan(\" verdict > \"))\n }\n console.log(chalk.dim(\" verdict: \") + verdict)\n\n const entry: Entry = { q, answer: result.answer, citations: result.citations, verdict }\n\n const m = verdict.match(/^(\\/ok|\\/correct|\\/add|\\/link|\\/skip)(?:\\s+(.+))?$/i)\n if (!m) {\n console.log(chalk.yellow(\" (verdict not recognised — treating as /skip)\"))\n transcript.push(entry)\n continue\n }\n const action = m[1].toLowerCase()\n const note = (m[2] || \"\").trim()\n transcript.push(entry)\n\n if (action === \"/ok\" || action === \"/skip\") continue\n if (!note) {\n console.log(chalk.yellow(` ${action} without note — skipping.`))\n continue\n }\n\n const primary = result.citations[0]\n if (!primary) {\n console.log(chalk.yellow(\" no cited article to patch.\"))\n continue\n }\n\n const article = store.readArticle(primary.path)\n if (!article) {\n console.log(chalk.red(` can't read ${primary.path} to patch.`))\n continue\n }\n\n console.log(chalk.dim(` patching ${primary.title} (${primary.path})...`))\n const patchPrompt = buildQuizPatchPrompt(article.content, action, note, article.meta.title, article.meta.type)\n const tmpDir = resolve(store.baseDir, \"_tmp\")\n mkdirSync(tmpDir, { recursive: true })\n const promptPath = resolve(tmpDir, `quiz-patch-${randomUUID().slice(0, 8)}.txt`)\n writeFileSync(promptPath, patchPrompt)\n\n let patched = \"\"\n try {\n const cmd = `cat '${promptPath}' | claude -p - --output-format json --max-turns 1 --model ${opts.patchModel} --disallowedTools \"Bash Read Write Edit Glob Grep Agent WebSearch WebFetch NotebookEdit\"`\n const raw = execSync(cmd, { encoding: \"utf-8\", timeout: 120_000, maxBuffer: 4 * 1024 * 1024 })\n try {\n const envelope = JSON.parse(raw)\n patched = String(envelope.result || envelope.content || \"\")\n } catch { patched = raw }\n const fence = patched.trim().match(/```(?:markdown|md)?\\s*\\n([\\s\\S]*?)\\n```\\s*$/)\n if (fence) patched = fence[1].trim()\n patched = patched.trim()\n } catch (e: any) {\n console.log(chalk.red(` patch failed: ${e.message?.slice(0, 120)}`))\n continue\n }\n\n if (!patched || patched.length < 20) {\n console.log(chalk.yellow(\" patch returned nothing usable.\"))\n continue\n }\n\n const before = article.content.split(\"\\n\").length\n const after = patched.split(\"\\n\").length\n console.log(chalk.dim(` diff: ${before} → ${after} lines (${after - before >= 0 ? \"+\" : \"\"}${after - before})`))\n\n if (!commit) {\n console.log(chalk.dim(\" (--no-commit: patch not written)\"))\n entry.patched = primary.path + \" (dry)\"\n continue\n }\n\n const ok = store.writeArticle(primary.path, { ...article.meta, lastUpdated: new Date().toISOString().slice(0, 10) }, patched, opts.agent)\n if (!ok) {\n console.log(chalk.red(\" write failed (permission?)\"))\n continue\n }\n applied++\n entry.patched = primary.path\n console.log(chalk.green(` ✓ patched ${primary.path}`))\n }\n\n if (rl) rl.close()\n if (applied > 0 && commit) store.rebuildIndex()\n\n console.log()\n console.log(chalk.bold(` Session done: ${transcript.length} rounds, ${applied} patches applied.`))\n\n if (opts.out) {\n const lines: string[] = [\n `# Wiki Quiz — ${opts.agent}`,\n \"\",\n `_Generated ${new Date().toISOString()} · ${transcript.length} rounds · ${applied} patches_`,\n \"\",\n ]\n for (let i = 0; i < transcript.length; i++) {\n const e = transcript[i]\n lines.push(\n `## ${i + 1}. Q: ${e.q}`, \"\",\n `**A:** ${e.answer}`, \"\",\n `**Citations:** ${e.citations.map(c => `\\`${c.title}\\``).join(\", \") || \"_(none)_\"}`, \"\",\n `**Verdict:** \\`${e.verdict}\\`` + (e.patched ? ` → patched \\`${e.patched}\\`` : \"\"), \"\",\n )\n }\n writeFileSync(opts.out, lines.join(\"\\n\"))\n console.log(chalk.dim(` Transcript written to ${opts.out}`))\n }\n })\n\n// agentx wiki edit — direct $EDITOR on a known article.\n// Resolves <title-or-path> against the catalog, opens the file in\n// $EDITOR, rebuilds the catalog on exit. No LLM, no confirm step,\n// just the fastest path from \"I see a typo\" to \"it's fixed\".\nwiki\n .command(\"edit <agent> <titleOrPath>\")\n .description(\"open an article in $EDITOR (resolves by title or path), rebuild catalog on exit\")\n .option(\"--dir <path>\", \"wiki directory\")\n .option(\"--editor <cmd>\", \"override $EDITOR for this run\")\n .action((agentId, titleOrPath, opts) => {\n const hub = getHub(opts.dir)\n let store\n try { store = hub.getAgentWiki(agentId) } catch (e: any) {\n console.log(chalk.red(` can't open wiki for agent \"${agentId}\": ${e.message}`))\n return\n }\n\n const relPath = resolveArticlePath(store, titleOrPath, agentId)\n if (!relPath) {\n console.log(chalk.yellow(` no article matches \"${titleOrPath}\" in ${agentId}'s wiki.`))\n console.log(chalk.dim(` Tip: ${chalk.green(\"agentx wiki status\")} lists agents; ${chalk.green(`agentx wiki search \"term\" --agent ${agentId}`)} finds by content.`))\n return\n }\n\n const absPath = resolve(store.baseDir, relPath)\n const editor = opts.editor || process.env.EDITOR || \"vi\"\n console.log(chalk.dim(` opening ${relPath} in ${editor}...`))\n try {\n execSync(`${editor} '${absPath}'`, { stdio: \"inherit\" })\n } catch (e: any) {\n console.log(chalk.red(` editor exited with error: ${e.message?.slice(0, 150)}`))\n return\n }\n\n // Sync `related` from body wikilinks if the user added/removed any.\n // Read back the article, compare wikilinks, rewrite frontmatter if drift.\n const after = store.readArticle(relPath)\n if (after) {\n const seenLinks = new Set<string>()\n const bodyLinks = store.extractWikilinks(after.content).filter((w: string) => {\n if (seenLinks.has(w)) return false\n seenLinks.add(w); return true\n })\n const currentRelated = after.meta.related || []\n const drift = bodyLinks.some(b => !currentRelated.includes(b)) ||\n currentRelated.some(r => !bodyLinks.includes(r))\n if (drift) {\n store.writeArticle(relPath, {\n ...after.meta,\n related: bodyLinks.length ? bodyLinks : undefined,\n lastUpdated: new Date().toISOString().slice(0, 10),\n }, after.content, agentId)\n console.log(chalk.dim(` (synced frontmatter.related from body: ${bodyLinks.length} wikilink${bodyLinks.length === 1 ? \"\" : \"s\"})`))\n }\n }\n\n // Rebuild catalog so related/title changes propagate\n try {\n store.rebuildIndex()\n console.log(chalk.green(` ✓ ${relPath} saved. Catalog rebuilt.`))\n } catch (e: any) {\n console.log(chalk.yellow(` saved, but catalog rebuild failed: ${e.message?.slice(0, 100)}`))\n }\n })\n\n// agentx wiki patch — LLM-driven minimal edit from a free-form\n// instruction. \"quiz without the question\" — when you already know\n// what's wrong and just want the patch applied without hunting for\n// the specific line to change.\nwiki\n .command(\"patch <agent> <titleOrPath> <instruction>\")\n .description(\"LLM-patch an article from a free-form instruction; shows diff + confirms before writing\")\n .option(\"--dir <path>\", \"wiki directory\")\n .option(\"--patch-model <m>\", \"patch model\", \"sonnet\")\n .option(\"--yes\", \"skip confirmation and write immediately\")\n .option(\"--no-commit\", \"show the patched body but don't write\")\n .action(async (agentId, titleOrPath, instruction, opts) => {\n const readline = await import(\"node:readline/promises\")\n const { randomUUID } = await import(\"node:crypto\")\n const hub = getHub(opts.dir)\n let store\n try { store = hub.getAgentWiki(agentId) } catch (e: any) {\n console.log(chalk.red(` can't open wiki for agent \"${agentId}\": ${e.message}`))\n return\n }\n\n const relPath = resolveArticlePath(store, titleOrPath, agentId)\n if (!relPath) {\n console.log(chalk.yellow(` no article matches \"${titleOrPath}\" in ${agentId}'s wiki.`))\n return\n }\n const article = store.readArticle(relPath)\n if (!article) {\n console.log(chalk.red(` can't read ${relPath}.`))\n return\n }\n\n const prompt = buildWikiPatchPrompt(article.content, article.meta.title, article.meta.type, instruction)\n const tmpDir = resolve(store.baseDir, \"_tmp\")\n mkdirSync(tmpDir, { recursive: true })\n const promptPath = resolve(tmpDir, `patch-${randomUUID().slice(0, 8)}.txt`)\n writeFileSync(promptPath, prompt)\n\n console.log()\n console.log(chalk.dim(` Target: ${article.meta.title} (${relPath})`))\n console.log(chalk.dim(` Patching with ${opts.patchModel}...`))\n\n let patched = \"\"\n try {\n const cmd = `cat '${promptPath}' | claude -p - --output-format json --max-turns 1 --model ${opts.patchModel} --disallowedTools \"Bash Read Write Edit Glob Grep Agent WebSearch WebFetch NotebookEdit\"`\n const raw = execSync(cmd, { encoding: \"utf-8\", timeout: 120_000, maxBuffer: 4 * 1024 * 1024 })\n try {\n const envelope = JSON.parse(raw)\n patched = String(envelope.result || envelope.content || \"\")\n } catch { patched = raw }\n const fence = patched.trim().match(/```(?:markdown|md)?\\s*\\n([\\s\\S]*?)\\n```\\s*$/)\n if (fence) patched = fence[1].trim()\n patched = patched.trim()\n } catch (e: any) {\n console.log(chalk.red(` patch failed: ${e.message?.slice(0, 150)}`))\n return\n }\n\n if (!patched || patched.length < 20) {\n console.log(chalk.yellow(\" patch returned nothing usable.\"))\n return\n }\n\n const before = article.content.split(\"\\n\").length\n const after = patched.split(\"\\n\").length\n console.log()\n console.log(chalk.bold(\" === Patched preview ===\"))\n console.log(chalk.dim(` diff: ${before} → ${after} lines (${after - before >= 0 ? \"+\" : \"\"}${after - before})`))\n console.log()\n console.log(patched)\n console.log()\n\n if (!opts.commit) {\n console.log(chalk.dim(\" --no-commit: preview only, not written.\"))\n return\n }\n\n let go = !!opts.yes\n if (!go) {\n const rl = readline.createInterface({ input: process.stdin, output: process.stdout })\n const ans = (await rl.question(chalk.cyan(\" apply? [y/N] \"))).trim().toLowerCase()\n rl.close()\n go = ans === \"y\" || ans === \"yes\"\n }\n if (!go) {\n console.log(chalk.dim(\" aborted.\"))\n return\n }\n\n // Auto-sync `related` from body wikilinks — after an edit the body's\n // wikilinks are the source of truth, frontmatter.related should follow.\n // Dedupe preserving first-occurrence order.\n const seen = new Set<string>()\n const syncedRelated = store.extractWikilinks(patched).filter((w: string) => {\n if (seen.has(w)) return false\n seen.add(w); return true\n })\n const ok = store.writeArticle(relPath, {\n ...article.meta,\n related: syncedRelated.length ? syncedRelated : undefined,\n lastUpdated: new Date().toISOString().slice(0, 10),\n }, patched, agentId)\n if (!ok) {\n console.log(chalk.red(\" write failed (permission?)\"))\n return\n }\n store.rebuildIndex()\n const relDrift = (article.meta.related || []).filter(r => !syncedRelated.includes(r))\n if (relDrift.length) {\n console.log(chalk.dim(` (pruned stale related: ${relDrift.slice(0, 3).join(\", \")}${relDrift.length > 3 ? \", …\" : \"\"})`))\n }\n console.log(chalk.green(` ✓ ${relPath} patched.`))\n })\n\n/**\n * Resolve a user-provided \"title or path\" to a valid article path within\n * the given store. Matches by:\n * 1. Exact case-insensitive title\n * 2. If the arg looks like a path (has '/' or ends in '.md'), tries that\n * path against the store directly\n * 3. Slug-of-title match (case-insensitive)\n * Returns the relative path on success, null on no match.\n */\nfunction resolveArticlePath(store: any, titleOrPath: string, agentId: string): string | null {\n const arg = titleOrPath.trim()\n const articles = store.listArticles(agentId)\n\n // 1. Exact title match (case-insensitive)\n const lower = arg.toLowerCase()\n const byTitle = articles.find((a: any) => a.meta.title.toLowerCase() === lower)\n if (byTitle) return byTitle.path\n\n // 2. Path-like: try direct lookup\n if (arg.includes(\"/\") || arg.endsWith(\".md\")) {\n const normPath = arg.endsWith(\".md\") ? arg : `${arg}.md`\n const byPath = articles.find((a: any) => a.path === normPath || a.path === arg)\n if (byPath) return byPath.path\n }\n\n // 3. Slug match — both sides slugified, prefix or equality\n const argSlug = arg.toLowerCase().replace(/[^a-z0-9]+/g, \"-\").replace(/^-+|-+$/g, \"\")\n const bySlug = articles.find((a: any) => {\n const titleSlug = a.meta.title.toLowerCase().replace(/[^a-z0-9]+/g, \"-\").replace(/^-+|-+$/g, \"\")\n return titleSlug === argSlug || titleSlug.includes(argSlug) || a.path.toLowerCase().includes(argSlug)\n })\n if (bySlug) return bySlug.path\n\n return null\n}\n\nfunction buildWikiPatchPrompt(content: string, title: string, type: string | undefined, instruction: string): string {\n return [\n `You are editing a single wiki article to incorporate an operator instruction.`,\n ``,\n `## Article: \"${title}\" (type: ${type || \"untyped\"})`,\n ``,\n `<article-body>`,\n content,\n `</article-body>`,\n ``,\n `## Operator instruction`,\n instruction,\n ``,\n `## Rules`,\n `- Output ONLY the modified article body (content between the --- frontmatter markers).`,\n `- Do NOT output frontmatter (title, type, tags, etc.) — the serializer handles that.`,\n `- Do NOT wrap the output in code fences.`,\n `- Do NOT prepend any preamble like \"Here's the updated article:\".`,\n `- Preserve existing wikilinks, markdown formatting, and section structure unless the instruction requires changing them.`,\n `- Make the MINIMUM edit that satisfies the instruction — don't rewrite untouched sections.`,\n `- If the instruction is ambiguous or can't be applied, return the original body unchanged.`,\n ].join(\"\\n\")\n}\n\nfunction buildQuizPatchPrompt(content: string, action: string, note: string, title: string, type?: string): string {\n const instructions: Record<string, string> = {\n \"/correct\": `The operator says the article contains an error:\\n\\n ${note}\\n\\nEdit the article to correct ONLY this mistake. Do not rewrite untouched sections. Keep the existing prose style. If the correction invalidates a larger passage, revise the minimum that must change.`,\n \"/add\": `The operator wants to add this detail:\\n\\n ${note}\\n\\nIncorporate it into the most relevant existing section, or create a short new section if nothing fits. Keep the prose encyclopedic and under 100 additional words.`,\n \"/link\": `The operator wants to add this resource:\\n\\n ${note}\\n\\nAdd it as a Markdown link in the most relevant section, or append a \"## References\" section at the end if none exists. If it looks like a URL, use it as-is; otherwise treat it as a wikilink target and use [[${note}]].`,\n }\n\n return [\n `You are editing a single wiki article to incorporate operator feedback.`,\n ``,\n `## Article: \"${title}\" (type: ${type || \"untyped\"})`,\n ``,\n `<article-body>`,\n content,\n `</article-body>`,\n ``,\n `## Edit instruction`,\n instructions[action] || `Make a minimal edit per: ${note}`,\n ``,\n `## Rules`,\n `- Output ONLY the modified article body (content between the --- frontmatter markers).`,\n `- Do NOT output frontmatter (title, type, tags, etc.) — the serializer handles that.`,\n `- Do NOT wrap the output in code fences.`,\n `- Do NOT prepend any preamble like \"Here's the updated article:\".`,\n `- Preserve existing wikilinks, markdown formatting, and section structure unless the edit requires changing them.`,\n `- If no meaningful edit can be made from the operator's feedback, return the original body unchanged.`,\n ].join(\"\\n\")\n}\n\n// agentx wiki prune — Phase 3 cleanup before un-gating absorb.\n// Collapses legacy per-mode dirs (flat/, unified/) into canonical graph/.\n// Title-level dedup: for each title, the best copy wins (prefer typed,\n// then newer `last_updated`); losers are archived to `_versions/`.\nwiki\n .command(\"prune\")\n .description(\"collapse legacy flat/unified mode dirs into graph/ (dedup by title; losers archived)\")\n .option(\"--dir <path>\", \"wiki directory\")\n .option(\"--agent <id>\", \"prune only this agent's wiki\")\n .option(\"--commit\", \"execute moves + archives (default: dry-run)\")\n .action(async (opts) => {\n const hub = getHub(opts.dir)\n const agents = opts.agent ? [opts.agent] : hub.listAgents()\n const commit = !!opts.commit\n const wikiRoot = opts.dir ? resolve(opts.dir) : resolve(process.cwd(), \".agentx/wiki\")\n const CANONICAL = \"graph\"\n const LEGACY_MODES = [\"flat\", \"unified\"]\n\n console.log()\n console.log(chalk.bold(commit ? \" Pruning (commit)\" : \" Pruning (dry-run)\"))\n console.log(chalk.dim(` Canonical: ${CANONICAL}/ · Legacy to collapse: ${LEGACY_MODES.join(\"/, \")}/`))\n\n let totalLegacy = 0\n let totalPromote = 0\n let totalUpgrade = 0\n let totalArchive = 0\n\n for (const agentId of agents) {\n const agentRoot = resolve(wikiRoot, \"agents\", agentId)\n if (!existsSync(agentRoot)) continue\n\n const canonicalDir = resolve(agentRoot, CANONICAL)\n const legacyEntries = LEGACY_MODES\n .map(m => ({ mode: m, dir: resolve(agentRoot, m) }))\n .filter(e => existsSync(e.dir))\n\n if (legacyEntries.length === 0) continue\n\n // Build a title → {relPath, type, lastUpdated} index of the canonical dir.\n const canonIdx = new Map<string, { relPath: string; type?: string; lastUpdated: string }>()\n walkMd(canonicalDir, (abs) => {\n const rel = relative(canonicalDir, abs)\n if (rel.startsWith(\"_\") || rel.startsWith(\"raw/\") || rel.includes(\"_tmp/\")) return\n const parsed = parseWikiFrontmatter(readFileSync(abs, \"utf-8\"))\n if (!parsed?.meta.title) return\n canonIdx.set(parsed.meta.title.trim().toLowerCase(), {\n relPath: rel,\n type: parsed.meta.type,\n lastUpdated: parsed.meta.lastUpdated || \"\",\n })\n })\n\n // Enumerate legacy articles.\n type Legacy = {\n mode: string\n relPath: string\n absPath: string\n title: string\n type?: string\n lastUpdated: string\n }\n const legacy: Legacy[] = []\n for (const e of legacyEntries) {\n walkMd(e.dir, (abs) => {\n const rel = relative(e.dir, abs)\n if (rel.startsWith(\"_\") || rel.startsWith(\"raw/\") || rel.includes(\"_tmp/\")) return\n const parsed = parseWikiFrontmatter(readFileSync(abs, \"utf-8\"))\n if (!parsed?.meta.title) return\n legacy.push({\n mode: e.mode,\n relPath: rel,\n absPath: abs,\n title: parsed.meta.title.trim(),\n type: parsed.meta.type,\n lastUpdated: parsed.meta.lastUpdated || \"\",\n })\n })\n }\n totalLegacy += legacy.length\n\n if (legacy.length === 0) continue\n\n console.log()\n const modeStr = legacyEntries.map(e => e.mode).join(\"+\")\n console.log(chalk.bold(` ${chalk.cyan(agentId)}: ${legacy.length} legacy article(s) across ${modeStr}`))\n\n for (const la of legacy) {\n const key = la.title.toLowerCase()\n const existing = canonIdx.get(key)\n\n // Decide: promote (new), upgrade (beat canonical), or archive (lose to canonical)\n let action: \"promote\" | \"upgrade\" | \"archive\"\n if (!existing) action = \"promote\"\n else if (!existing.type && la.type) action = \"upgrade\"\n else if (!!existing.type === !!la.type && la.lastUpdated && existing.lastUpdated &&\n la.lastUpdated > existing.lastUpdated) action = \"upgrade\"\n else action = \"archive\"\n\n const typeTag = la.type ? chalk.magenta(`[${la.type}]`) : chalk.yellow(\"[untyped]\")\n const arrow = action === \"promote\" ? chalk.green(\"→ promote \")\n : action === \"upgrade\" ? chalk.cyan(\"⟳ upgrade \")\n : chalk.dim(\"✗ archive \")\n const where = la.relPath.length > 46 ? la.relPath.slice(0, 43) + \"...\" : la.relPath.padEnd(46)\n console.log(` ${arrow} ${typeTag} ${chalk.dim(la.mode + \"/\")}${where}`)\n if (action === \"upgrade\") console.log(chalk.dim(` (replaces ${existing!.relPath}, old version kept under _versions/)`))\n\n if (!commit) {\n if (action === \"promote\") totalPromote++\n else if (action === \"upgrade\") totalUpgrade++\n else totalArchive++\n continue\n }\n\n try {\n if (action === \"promote\") {\n const target = resolve(canonicalDir, la.relPath)\n if (existsSync(target)) {\n console.log(chalk.yellow(` ! target path already exists, archiving instead: ${la.relPath}`))\n archiveLegacy(agentRoot, la)\n totalArchive++\n } else {\n mkdirSync(dirname(target), { recursive: true })\n renameSync(la.absPath, target)\n canonIdx.set(key, { relPath: la.relPath, type: la.type, lastUpdated: la.lastUpdated })\n totalPromote++\n }\n } else if (action === \"upgrade\") {\n const target = resolve(canonicalDir, existing!.relPath)\n if (existsSync(target)) {\n const verDir = resolve(agentRoot, \"_versions\", existing!.relPath.replace(/\\.md$/, \"\"))\n mkdirSync(verDir, { recursive: true })\n const ts = new Date().toISOString().replace(/[:.]/g, \"-\")\n renameSync(target, resolve(verDir, `${ts}.md`))\n }\n mkdirSync(dirname(target), { recursive: true })\n renameSync(la.absPath, target)\n canonIdx.set(key, { relPath: existing!.relPath, type: la.type, lastUpdated: la.lastUpdated })\n totalUpgrade++\n } else {\n archiveLegacy(agentRoot, la)\n totalArchive++\n }\n } catch (e: any) {\n console.log(chalk.red(` ! ${action} failed: ${e.message?.slice(0, 120)}`))\n }\n }\n\n if (commit) {\n // Delete the now-empty legacy mode dirs (they will also contain obsolete\n // _index.md, _schema.md, log.md etc.; rmSync -f nukes the whole subtree).\n for (const e of legacyEntries) {\n try { rmSync(e.dir, { recursive: true, force: true }) } catch {}\n }\n // Rebuild the canonical catalog so _index.md reflects the merged corpus.\n try {\n hub.getAgentWiki(agentId).rebuildIndex()\n } catch (e: any) {\n console.log(chalk.dim(` (catalog rebuild skipped: ${e.message?.slice(0, 80)})`))\n }\n }\n }\n\n console.log()\n console.log(chalk.dim(` Legacy scanned: ${totalLegacy}`))\n if (commit) {\n console.log(chalk.green(` Promoted: ${totalPromote} · Upgraded canonical: ${totalUpgrade} · Archived: ${totalArchive}`))\n console.log(chalk.dim(\" Archived losers preserved under <agent>/_versions/. Legacy mode dirs deleted.\"))\n } else {\n console.log(chalk.dim(` Would: promote ${totalPromote} · upgrade ${totalUpgrade} · archive ${totalArchive}`))\n console.log(chalk.dim(\" Dry-run — add --commit to execute\"))\n }\n console.log()\n })\n\nfunction walkMd(dir: string, cb: (absPath: string) => void): void {\n if (!existsSync(dir)) return\n for (const entry of readdirSync(dir, { withFileTypes: true })) {\n const abs = resolve(dir, entry.name)\n if (entry.isDirectory()) walkMd(abs, cb)\n else if (entry.isFile() && entry.name.endsWith(\".md\")) cb(abs)\n }\n}\n\nfunction parseWikiFrontmatter(raw: string): { meta: Record<string, any> } | null {\n const fm = raw.match(/^---\\n([\\s\\S]*?)\\n---/)\n if (!fm) return null\n const meta: Record<string, any> = {}\n for (const line of fm[1].split(\"\\n\")) {\n const m = line.match(/^(\\w+):\\s*(.+)$/)\n if (!m) continue\n const key = m[1] === \"last_updated\" ? \"lastUpdated\" : m[1]\n meta[key] = m[2].trim().replace(/^\"(.*)\"$/, \"$1\")\n }\n return { meta }\n}\n\nfunction archiveLegacy(\n agentRoot: string,\n la: { mode: string; relPath: string; absPath: string },\n): void {\n const verDir = resolve(agentRoot, \"_versions\", `legacy-${la.mode}`, la.relPath.replace(/\\.md$/, \"\"))\n mkdirSync(verDir, { recursive: true })\n const ts = new Date().toISOString().replace(/[:.]/g, \"-\")\n renameSync(la.absPath, resolve(verDir, `${ts}.md`))\n}\n\n// agentx wiki migrate — Phase 2 of the Karpathy-alignment plan.\n// Backfills `type` + `related` on legacy articles so Phase 3's agentic\n// query has a corpus with a usable `_index.md` + wikilink graph.\nwiki\n .command(\"migrate\")\n .description(\"backfill type + related on legacy articles (one-shot)\")\n .option(\"--dir <path>\", \"wiki directory\")\n .option(\"--agent <id>\", \"migrate only this agent's articles\")\n .option(\"--commit\", \"write changes (default: dry-run, reports what would change)\")\n .option(\"--batch <n>\", \"articles per LLM call\", \"10\")\n .option(\"--max <n>\", \"cap articles this run (for spot-checks)\")\n .option(\"--model <m>\", \"classifier model\", \"sonnet\")\n .action(async (opts) => {\n const hub = getHub(opts.dir)\n const agents = opts.agent ? [opts.agent] : hub.listAgents()\n const batchSize = Math.max(1, parseInt(opts.batch) || 10)\n const maxArticles = opts.max ? parseInt(opts.max) : Infinity\n const commit = !!opts.commit\n\n console.log()\n console.log(chalk.bold(commit ? \" Migrating (commit)\" : \" Migrating (dry-run)\"))\n console.log(chalk.dim(` Batch size: ${batchSize} · Model: ${opts.model}`))\n console.log()\n\n let totalScanned = 0\n let totalNeeds = 0\n let totalApplied = 0\n\n for (const agentId of agents) {\n const agentWiki = hub.getAgentWiki(agentId)\n const articles = agentWiki.listArticles(agentId)\n const needs = articles.filter(a => !a.meta.type)\n totalScanned += articles.length\n totalNeeds += needs.length\n\n if (needs.length === 0) {\n console.log(` ${chalk.cyan(agentId)}: ${chalk.green(\"all typed\")} (${articles.length} articles)`)\n continue\n }\n\n const remaining = Math.max(0, maxArticles - totalApplied)\n const limit = Math.min(needs.length, remaining)\n if (limit === 0) {\n console.log(chalk.dim(` ${agentId}: skipped (--max reached)`))\n continue\n }\n\n console.log()\n console.log(chalk.bold(` ${chalk.cyan(agentId)}: ${limit}/${needs.length} untyped articles`))\n\n const baseDir = agentWiki[\"baseDir\"]\n const tmpDir = resolve(baseDir, \"_tmp\")\n mkdirSync(tmpDir, { recursive: true })\n\n for (let i = 0; i < limit; i += batchSize) {\n const batch = needs.slice(i, Math.min(i + batchSize, limit))\n const prompt = buildMigratePrompt(batch)\n const promptPath = resolve(tmpDir, \"migrate-prompt.txt\")\n writeFileSync(promptPath, prompt)\n\n let classifications: Array<{ path: string; type: string }>\n try {\n const cmd = `cat '${promptPath}' | claude -p - --output-format json --max-turns 1 --model ${opts.model} --disallowedTools \"Bash Read Write Edit Glob Grep Agent WebSearch WebFetch NotebookEdit\"`\n const rawOutput = execSync(cmd, { encoding: \"utf-8\", timeout: 120_000, maxBuffer: 4 * 1024 * 1024 })\n const envelope = JSON.parse(rawOutput)\n const responseText = String(envelope.result || envelope.content || \"\")\n const arrMatch = responseText.match(/\\[[\\s\\S]*\\]/)\n if (!arrMatch) throw new Error(\"no JSON array in classifier response\")\n classifications = JSON.parse(arrMatch[0])\n } catch (e: any) {\n console.log(chalk.red(` LLM classify failed: ${e.message?.slice(0, 150)}`))\n continue\n }\n\n for (const article of batch) {\n const c = classifications.find((x) => x.path === article.path)\n const norm = normalizeWikiType(c?.type)\n if (!c || !norm) {\n console.log(chalk.yellow(` ? ${article.path}: unclassified${c ? ` (got \"${c.type}\")` : \"\"}`))\n continue\n }\n const related = agentWiki.extractWikilinks(article.content)\n const newMeta = {\n ...article.meta,\n type: norm.type as any,\n related: related.length ? related : undefined,\n lastUpdated: new Date().toISOString().slice(0, 10),\n }\n const relStr = related.length ? chalk.dim(` → ${related.slice(0, 3).join(\", \")}${related.length > 3 ? \", …\" : \"\"}`) : \"\"\n const aliasNote = norm.alias ? chalk.dim(` (from \"${norm.alias}\")`) : \"\"\n console.log(` ${chalk.green(\"+\")} ${chalk.magenta(\"[\" + norm.type + \"]\")}${aliasNote} ${article.path}${relStr}`)\n\n if (commit) {\n agentWiki.writeArticle(article.path, newMeta, article.content, agentId)\n totalApplied++\n }\n }\n }\n\n if (commit) agentWiki.rebuildIndex()\n }\n\n console.log()\n console.log(chalk.dim(` Scanned ${totalScanned} articles; ${totalNeeds} needed migration`))\n if (commit) {\n console.log(chalk.green(` Applied ${totalApplied} patches.`))\n } else {\n console.log(chalk.dim(\" Dry-run — add --commit to write changes.\"))\n }\n console.log()\n })\n\n/**\n * Map the classifier's output to the 7-type enum. The LLM often volunteers\n * domain-specific types (issue, MR, runbook, agent…). Rather than reject\n * and re-run, map them to the nearest valid enum value. Caller gets back\n * {type, alias?} — alias is the raw LLM output when it wasn't an exact\n * match, for logging.\n */\nfunction normalizeWikiType(raw: string | undefined): { type: string; alias?: string } | null {\n if (!raw) return null\n const key = String(raw).trim().toLowerCase().replace(/^[\\s\"'`]+|[\\s\"'`]+$/g, \"\")\n if (!key) return null\n const ALIASES: Record<string, string> = {\n // Exact enum values\n person: \"person\", project: \"project\", place: \"place\", concept: \"concept\",\n event: \"event\", decision: \"decision\", pattern: \"pattern\",\n // Plurals\n people: \"person\", projects: \"project\", places: \"place\", concepts: \"concept\",\n events: \"event\", decisions: \"decision\", patterns: \"pattern\",\n // Domain variants → enum equivalents\n agent: \"project\", bot: \"project\", service: \"project\", product: \"project\",\n tool: \"project\", repo: \"project\", repository: \"project\", app: \"project\",\n application: \"project\", team: \"project\", organization: \"project\", company: \"project\",\n issue: \"event\", mr: \"event\", \"merge-request\": \"event\", \"merge_request\": \"event\",\n ticket: \"event\", incident: \"event\", deploy: \"event\", deployment: \"event\",\n launch: \"event\", release: \"event\",\n process: \"pattern\", procedure: \"pattern\", workflow: \"pattern\",\n runbook: \"pattern\", recipe: \"pattern\", template: \"pattern\", sop: \"pattern\",\n infrastructure: \"place\", infra: \"place\", server: \"place\", environment: \"place\",\n env: \"place\", location: \"place\", host: \"place\",\n decisionrecord: \"decision\", adr: \"decision\", \"decision-record\": \"decision\",\n }\n const mapped = ALIASES[key]\n if (!mapped) return null\n return mapped === key ? { type: mapped } : { type: mapped, alias: key }\n}\n\nfunction buildMigratePrompt(articles: Array<{ path: string; meta: { title: string; tags?: string[] }; content: string }>): string {\n const items = articles.map((a, i) => {\n const body = a.content.replace(/\\s+/g, \" \").slice(0, 400)\n const tags = (a.meta.tags || []).slice(0, 8).join(\", \")\n return `${i + 1}. path: \"${a.path}\"\\n title: \"${a.meta.title}\"\\n tags: [${tags}]\\n body: ${body}${a.content.length > 400 ? \"…\" : \"\"}`\n }).join(\"\\n\\n\")\n\n return `Classify each of these ${articles.length} wiki articles into EXACTLY ONE type from this closed set (no synonyms, no plurals, no new values):\n\n person | project | place | concept | event | decision | pattern\n\nWhat each type means:\n- person: an individual human (team member, stakeholder, contact)\n- project: a named initiative, repo, product, service, bot, agent, team, or org\n- place: a physical or logical location (office, server, environment, infrastructure)\n- concept: a recurring idea, philosophy, methodology, or thinking pattern\n- event: a specific dated thing that happened (incident, deploy, launch, GitLab issue, MR)\n- decision: a specific choice made and why (architecture decision, policy, ADR)\n- pattern: a reusable workflow, template, recipe, procedure, runbook, or SOP\n\nExplicit mappings (you WILL be tempted to volunteer these — don't; use the right-hand value):\n- \"agent\" / \"bot\" / \"service\" / \"repo\" / \"team\" → project\n- \"issue\" / \"MR\" / \"ticket\" / \"incident\" / \"deploy\" → event\n- \"process\" / \"procedure\" / \"runbook\" / \"workflow\" → pattern\n- \"infrastructure\" / \"server\" / \"environment\" → place\n- \"ADR\" / \"decision record\" → decision\n\nRules:\n- Return EXACTLY one type per article, by path, from the 7 allowed values above.\n- Do not invent new types. Do not return plurals. Do not return synonyms.\n- If the title is a person's name, it's person. If it's a repo/product/bot name, it's project. If it's dated + past tense, it's event.\n- If you genuinely cannot decide, pick \"concept\" as the fallback.\n- Output ONLY valid JSON, no markdown fencing, no prose.\n\nArticles:\n\n${items}\n\nOutput (JSON array, one entry per input article, same order):\n[\n {\"path\": \"path/to/article.md\", \"type\": \"project\"},\n ...\n]`\n}\n\n// agentx wiki entries\nwiki\n .command(\"entries\")\n .description(\"list raw entries\")\n .option(\"--dir <path>\", \"wiki directory\")\n .option(\"--agent <id>\", \"filter by agent\")\n .action((opts) => {\n const hub = getHub(opts.dir)\n const shared = hub.getSharedStore()\n let entries = shared.listEntries()\n\n if (opts.agent) {\n entries = entries.filter(e => e.agentId === opts.agent)\n }\n\n console.log()\n console.log(chalk.bold(` ${entries.length} raw entries`))\n console.log()\n\n for (const e of entries.slice(-20)) {\n console.log(` ${chalk.dim(e.date)} ${chalk.cyan(e.agentId)} via ${e.source}: ${e.content.slice(0, 80)}...`)\n }\n\n if (entries.length > 20) {\n console.log(chalk.dim(` ... showing last 20 of ${entries.length}`))\n }\n console.log()\n })\n\n// agentx wiki serve\nwiki\n .command(\"serve\")\n .description(\"start a local web server to browse agent wikis (local + mesh)\")\n .option(\"--dir <path>\", \"wiki directory\")\n .option(\"--mode <mode>\", \"graph (default, canonical) | unified | flat (legacy, back-compat)\", \"graph\")\n .option(\"--agent <id>\", \"serve only this agent's wiki\")\n .option(\"--port <n>\", \"port number\", \"4200\")\n .option(\"--peer <urls...>\", \"mesh peer URLs to federate\")\n .action(async (opts) => {\n const dir = opts.dir || resolve(process.cwd(), \".agentx/wiki\")\n const port = parseInt(opts.port)\n\n // Auto-discover peers from daemon config if not specified\n let peerUrls: string[] = opts.peer || []\n if (peerUrls.length === 0) {\n try {\n const { loadDaemonConfig } = await import(\"@/daemon/config\")\n const config = loadDaemonConfig()\n peerUrls = (config.mesh?.peers || []).map((p: any) => p.url)\n } catch { /* no config */ }\n }\n\n console.log()\n console.log(chalk.bold(\" AgentX Wiki Server\"))\n console.log()\n console.log(` ${chalk.green(\">\")} http://localhost:${port}`)\n if (opts.agent) {\n console.log(` Agent: ${chalk.cyan(opts.agent)}`)\n } else {\n console.log(` Mode: ${chalk.cyan(\"Hub\")} (all agents)`)\n }\n if (peerUrls.length > 0) {\n console.log(` Mesh: ${chalk.cyan(peerUrls.length + \" peer(s)\")} — ${peerUrls.join(\", \")}`)\n }\n console.log(chalk.dim(` Wiki: ${dir}`))\n console.log(chalk.dim(\" Press Ctrl+C to stop\"))\n console.log()\n\n startWikiServer(dir, port, opts.agent, peerUrls, opts.mode as WikiMode)\n })\n\n// agentx wiki query <question> — Phase 3 agentic query.\n// Walks _index.md → picks candidate articles → walks `related` wikilinks\n// → synthesizes an answer with citations. This is the Farzapedia-faithful\n// retrieval path; `wiki search` stays as the raw BM25 escape hatch.\nwiki\n .command(\"query <question>\")\n .description(\"agentic wiki query — walks the catalog + wikilink graph, synthesizes an answer\")\n .option(\"--dir <path>\", \"wiki directory\")\n .option(\"--agent <id>\", \"which agent's wiki to query (default: first one with a catalog)\")\n .option(\"--selector-model <m>\", \"candidate-selection model\", \"haiku\")\n .option(\"--synth-model <m>\", \"synthesis model\", \"sonnet\")\n .option(\"--max-candidates <n>\", \"candidates from selector\", \"3\")\n .option(\"--max-hops <n>\", \"wikilink hops from candidates\", \"2\")\n .option(\"--max-articles <n>\", \"cap on total articles walked\", \"8\")\n .option(\"--json\", \"emit full result as JSON (for A/B harnesses)\")\n .option(\"--trace\", \"print selector + walk trace\")\n .action(async (question, opts) => {\n const { agenticQuery } = await import(\"@/wiki/query\")\n const hub = getHub(opts.dir)\n const agents = opts.agent ? [opts.agent] : hub.listAgents()\n\n // Find the first agent that actually has a catalog.\n let chosen: string | null = null\n for (const id of agents) {\n const s = hub.getAgentWiki(id)\n const cat = resolve(s.baseDir, \"_index.md\")\n try {\n if ((await import(\"fs\")).existsSync(cat)) { chosen = id; break }\n } catch {}\n }\n if (!chosen) {\n console.log(chalk.yellow(\" No agent has a catalog yet. Run `agentx wiki status` or migrate first.\"))\n return\n }\n\n const store = hub.getAgentWiki(chosen)\n const result = await agenticQuery(question, store, chosen, {\n selectorModel: opts.selectorModel,\n synthModel: opts.synthModel,\n maxCandidates: parseInt(opts.maxCandidates),\n maxHops: parseInt(opts.maxHops),\n maxArticles: parseInt(opts.maxArticles),\n })\n\n if (opts.json) {\n console.log(JSON.stringify(result, null, 2))\n return\n }\n\n console.log()\n console.log(chalk.bold(` Q: ${question}`))\n console.log(chalk.dim(` agent: ${chosen} · status: ${result.status} · walked: ${result.walked.length}`))\n console.log()\n\n if (result.status !== \"ok\") {\n console.log(chalk.yellow(` (no answer) ${result.error || result.status}`))\n return\n }\n\n console.log(result.answer)\n console.log()\n if (result.citations.length) {\n console.log(chalk.dim(\" Citations:\"))\n for (const c of result.citations) {\n const type = c.type ? chalk.magenta(` [${c.type}]`) : \"\"\n console.log(chalk.dim(` - ${c.title}${type} (${c.path})`))\n }\n console.log()\n }\n\n if (opts.trace && result.trace) {\n console.log(chalk.dim(` selector: ${result.trace.selectorMs}ms synthesis: ${result.trace.synthesisMs}ms`))\n console.log(chalk.dim(` candidates: ${result.candidates.map(c => c.title).join(\" | \") || \"(none)\"}`))\n if (result.walked.length > result.candidates.length) {\n const follow = result.walked.filter(w => !result.candidates.some(c => c.path === w.path))\n console.log(chalk.dim(` followed: ${follow.map(w => `${w.title}@h${w.hop}`).join(\" | \")}`))\n }\n console.log()\n }\n })\n\n// agentx wiki search <query>\nwiki\n .command(\"search <query>\")\n .description(\"search wiki articles\")\n .option(\"--dir <path>\", \"wiki directory\")\n .option(\"--mode <mode>\", \"graph (default, canonical) | unified | flat (legacy, back-compat)\", \"graph\")\n .option(\"--agent <id>\", \"search specific agent's wiki\")\n .action((query, opts) => {\n const hub = getHub(opts.dir, opts.mode as WikiMode)\n const agents = opts.agent ? [opts.agent] : hub.listAgents()\n\n console.log()\n let found = 0\n\n for (const agentId of agents) {\n const store = hub.getAgentWiki(agentId)\n const results = store.findRelevant(query, undefined, 10)\n\n if (results.length > 0) {\n console.log(chalk.bold(` ${chalk.cyan(agentId)}:`))\n for (const r of results) {\n console.log(` ${r.meta.title} [${(r.meta.tags || []).slice(0, 3).join(\", \")}]`)\n console.log(chalk.dim(` ${r.path} — ${r.content.slice(0, 100)}...`))\n }\n found += results.length\n }\n }\n\n if (found === 0) console.log(chalk.dim(\" No matching articles\"))\n console.log()\n })\n\n// agentx wiki backfill-graphpath — populate graphPath on existing articles\n//\n// Reads each article's `sources[]`, looks the source entries up by id, computes\n// the graph fingerprint from each entry's (content, channel, sender), and if\n// the cache hits, picks the most-common path among the article's sources and\n// writes it as `graph_path:` in frontmatter. Without this, the wiki retrieval\n// score function multiplies the graph weight (0.6 by default) by 0 for every\n// pre-existing article — the graph half of the hybrid score is dead weight.\nwiki\n .command(\"backfill-graphpath\")\n .description(\"populate graphPath on existing articles by looking up source-entry classifications\")\n .option(\"--dir <path>\", \"wiki directory\")\n .option(\"--agent <id>\", \"backfill only this agent\")\n .option(\"--dry-run\", \"preview without writing\", false)\n .action((opts) => {\n const hub = getHub(opts.dir)\n const agents = opts.agent ? [opts.agent] : hub.listAgents()\n\n const baseDir = resolve(process.cwd(), \".agentx/graph\")\n if (!existsSync(baseDir)) {\n console.log(chalk.red(` No graph store at ${baseDir} — nothing to backfill against.`))\n return\n }\n const graphStore = new GraphStore({ baseDir })\n const idx = graphStore.loadIndex()\n const fpToPath = new Map<string, string[]>()\n for (const [fp, e] of Object.entries(idx.entries)) {\n fpToPath.set(fp, (e as any).path)\n }\n if (fpToPath.size === 0) {\n console.log(chalk.yellow(` Graph index is empty — nothing to look up.`))\n return\n }\n console.log(chalk.dim(` Loaded ${fpToPath.size} fingerprint -> path entries from .agentx/graph/index.json`))\n\n let totalArticles = 0\n let totalEligible = 0 // articles with empty graphPath that COULD be looked up\n let totalMatched = 0 // articles where at least one source matched\n let totalWritten = 0\n\n for (const agentId of agents) {\n const store = hub.getAgentWiki(agentId)\n const articles = store.listArticles(agentId)\n const sharedEntries = hub.getSharedStore().listEntries()\n const entriesById = new Map(sharedEntries.map((e) => [e.id, e]))\n\n let agentEligible = 0\n let agentMatched = 0\n let agentWritten = 0\n\n for (const article of articles) {\n totalArticles++\n if (article.meta.graphPath?.length) continue\n if (!article.meta.sources?.length) continue\n agentEligible++\n totalEligible++\n\n const counts = new Map<string, { path: string[]; n: number }>()\n for (const sid of article.meta.sources) {\n const entry = entriesById.get(sid)\n if (!entry) continue\n const sender = String((entry.meta as any)?.sender ?? \"\")\n const fp = graphStore.fingerprint({\n text: entry.content,\n channel: entry.source,\n sender,\n })\n const path = fpToPath.get(fp)\n if (!path?.length) continue\n const key = path.join(\"/\")\n const cur = counts.get(key)\n if (cur) cur.n++\n else counts.set(key, { path, n: 1 })\n }\n if (counts.size === 0) continue\n agentMatched++\n totalMatched++\n\n let best: { path: string[]; n: number } | undefined\n for (const v of counts.values()) if (!best || v.n > best.n) best = v\n if (!best) continue\n\n if (opts.dryRun) {\n continue\n }\n // Write through writeArticle so frontmatter renders consistently.\n store.writeArticle(article.path, {\n ...article.meta,\n graphPath: best.path,\n }, article.content, agentId)\n agentWritten++\n totalWritten++\n }\n\n console.log(` ${chalk.cyan(agentId)}: ${chalk.bold(articles.length)} articles · ${agentEligible} eligible · ${agentMatched} matched · ${chalk.green(agentWritten)} written`)\n }\n\n console.log()\n console.log(chalk.bold(` Total: ${totalArticles} articles, ${totalEligible} missing graphPath, ${totalMatched} matched (${Math.round((totalMatched / Math.max(1, totalEligible)) * 100)}%), ${totalWritten} written`))\n if (opts.dryRun) console.log(chalk.dim(` Dry-run — re-run without --dry-run to commit.`))\n console.log()\n })\n\n// agentx wiki sync — pull entries from mesh peers\nwiki\n .command(\"sync\")\n .description(\"pull raw entries from mesh peers into local wiki\")\n .option(\"--dir <path>\", \"wiki directory\")\n .option(\"--peer <url>\", \"sync from a specific peer URL (e.g., http://100.67.108.119:19900)\")\n .option(\"--dry-run\", \"show what would be synced without writing\")\n .action(async (opts) => {\n const hub = getHub(opts.dir)\n const shared = hub.getSharedStore()\n\n // Discover peers: from --peer flag, or from local daemon config\n let peerUrls: string[] = []\n\n if (opts.peer) {\n peerUrls = [opts.peer]\n } else {\n // Try to read mesh peers from local daemon\n try {\n const { loadDaemonConfig } = await import(\"@/daemon/config\")\n const config = loadDaemonConfig()\n peerUrls = (config.mesh?.peers || []).map((p: any) => p.url)\n } catch {\n console.log(chalk.red(\" No --peer specified and no daemon config found\"))\n console.log(chalk.dim(\" Usage: agentx wiki sync --peer http://100.67.108.119:19900\"))\n return\n }\n }\n\n if (peerUrls.length === 0) {\n console.log(chalk.dim(\" No mesh peers configured\"))\n return\n }\n\n // Get existing entry IDs to avoid duplicates\n const existingIds = new Set(shared.listEntries().map(e => e.id))\n\n let totalSynced = 0\n\n for (const peerUrl of peerUrls) {\n console.log()\n console.log(chalk.bold(` Syncing from ${peerUrl}...`))\n\n try {\n // Fetch entries from peer\n const res = await fetch(`${peerUrl}/wiki/entries`, { signal: AbortSignal.timeout(120000) })\n if (!res.ok) {\n console.log(chalk.red(` HTTP ${res.status}`))\n continue\n }\n\n const data = await res.json() as any\n const entries = data.entries || []\n const nodeId = data.nodeId || \"unknown\"\n\n console.log(chalk.dim(` Node: ${nodeId} — ${entries.length} entries`))\n\n let newCount = 0\n for (const entry of entries) {\n if (existingIds.has(entry.id)) continue\n\n if (!opts.dryRun) {\n shared.addEntry({\n id: entry.id,\n date: entry.date,\n agentId: entry.agentId,\n source: `${entry.source}@${nodeId}`, // Tag source with node\n sourceContext: entry.sourceContext,\n content: entry.content,\n })\n existingIds.add(entry.id)\n }\n newCount++\n }\n\n if (newCount > 0) {\n console.log(chalk.green(` ${newCount} new entries${opts.dryRun ? \" (dry run)\" : \" synced\"}`))\n } else {\n console.log(chalk.dim(\" Already up to date\"))\n }\n\n totalSynced += newCount\n\n // Also show remote agents summary\n try {\n const agentsRes = await fetch(`${peerUrl}/wiki/agents`, { signal: AbortSignal.timeout(5000) })\n if (agentsRes.ok) {\n const agentsData = await agentsRes.json() as any\n for (const agent of (agentsData.agents || [])) {\n if (agent.totalEntries > 0) {\n console.log(chalk.dim(` ${agent.agentId}: ${agent.totalEntries} entries, ${agent.totalArticles} articles`))\n }\n }\n }\n } catch { /* optional */ }\n\n } catch (e: any) {\n if (e.cause?.code === \"ECONNREFUSED\") {\n console.log(chalk.red(` Connection refused`))\n } else {\n console.log(chalk.red(` ${e.message}`))\n }\n }\n }\n\n console.log()\n if (totalSynced > 0 && !opts.dryRun) {\n console.log(chalk.green(` ${totalSynced} entries synced.`))\n } else if (totalSynced > 0) {\n console.log(chalk.dim(` ${totalSynced} entries would be synced (dry run)`))\n } else {\n console.log(chalk.dim(\" All peers up to date\"))\n }\n console.log()\n })\n\n// agentx wiki compare — deterministic comparison of all three modes\nwiki\n .command(\"compare\")\n .description(\"compare all wiki compilation modes for an agent\")\n .option(\"--dir <path>\", \"wiki directory\")\n .requiredOption(\"--agent <id>\", \"agent to compare\")\n .action((opts) => {\n const dir = opts.dir || resolve(process.cwd(), \".agentx/wiki\")\n const agentId = opts.agent\n const modes: WikiMode[] = [\"flat\", \"graph\", \"unified\"]\n\n // Collect stats per mode\n const stats = modes.map(mode => {\n const hub = new WikiHub(dir, undefined, mode)\n const wiki = hub.getAgentWiki(agentId)\n const index = wiki.rebuildIndex()\n const entries = hub.getAgentEntries(agentId)\n const unabsorbed = hub.getUnabsorbedEntries(agentId)\n\n const tags = new Set<string>()\n let totalTags = 0\n const sources = new Set<string>()\n for (const a of index.articles) {\n for (const t of (a.tags || [])) tags.add(t)\n totalTags += (a.tags?.length || 0)\n for (const s of (a.sources || [])) sources.add(s)\n }\n const dirs = new Set(index.articles.map(a => a.path.includes(\"/\") ? a.path.split(\"/\")[0] : \"/\"))\n\n return {\n mode,\n label: modeLabel(mode),\n articles: index.articles.length,\n entries: entries.length,\n unabsorbed: unabsorbed.length,\n uniqueTags: tags.size,\n avgTags: index.articles.length > 0 ? (totalTags / index.articles.length).toFixed(1) : \"0\",\n dirs: dirs.size,\n coverage: sources.size,\n articleList: index.articles,\n }\n })\n\n console.log()\n console.log(chalk.bold(` Wiki Compare: ${agentId}`))\n console.log(` Raw entries: ${stats[0].entries}`)\n console.log()\n\n // Table header\n const w = 22\n console.log(` ${\"\".padEnd(20)} ${stats.map(s => s.label.padEnd(w)).join(\" \")}`)\n console.log(` ${\"─\".repeat(20)} ${stats.map(() => \"─\".repeat(w)).join(\" \")}`)\n\n const rows: Array<[string, (s: typeof stats[0]) => string]> = [\n [\"Articles\", s => String(s.articles)],\n [\"Unabsorbed\", s => String(s.unabsorbed)],\n [\"Unique tags\", s => String(s.uniqueTags)],\n [\"Avg tags/article\", s => s.avgTags],\n [\"Directories\", s => String(s.dirs)],\n [\"Entry coverage\", s => `${s.coverage}/${s.entries}`],\n ]\n\n for (const [label, fn] of rows) {\n const vals = stats.map(s => fn(s).padEnd(w))\n console.log(` ${label.padEnd(20)} ${vals.join(\" \")}`)\n }\n\n console.log()\n\n // Best in each category\n const best = (key: \"uniqueTags\" | \"articles\" | \"coverage\", label: string) => {\n const max = Math.max(...stats.map(s => s[key] as number))\n const winners = stats.filter(s => (s[key] as number) === max).map(s => s.label)\n if (max > 0) console.log(chalk.dim(` Best ${label}: ${winners.join(\", \")} (${max})`))\n }\n best(\"uniqueTags\", \"tag richness\")\n best(\"articles\", \"article count\")\n best(\"coverage\", \"entry coverage\")\n\n console.log()\n })\n\n// ---------------------------------------------------------------------------\n// agentx wiki export / import — bulk tarball backup of .agentx/wiki/\n//\n// Closes the audit gap: no operator-facing way to back up wiki content\n// before a risky migration or move it between installs. Tarball is the\n// safest portable shape; we don't ship a sync tool yet (see `wiki migrate`\n// for in-place schema changes).\n\nwiki\n .command(\"export [output]\")\n .description(\"export the entire wiki tree to a .tar.gz\")\n .option(\"--dir <path>\", \"wiki directory to archive (default: .agentx/wiki)\")\n .option(\"--include-raw\", \"also include raw entries (.agentx/wiki/raw/) — bigger archive\")\n .action(async (output, opts) => {\n const wikiDir = opts.dir ? resolve(process.cwd(), opts.dir) : resolve(process.cwd(), \".agentx/wiki\")\n if (!existsSync(wikiDir)) {\n console.log(chalk.red(` Wiki dir not found: ${wikiDir}`))\n process.exit(1)\n }\n const date = new Date().toISOString().slice(0, 10)\n const out = output ? resolve(process.cwd(), output) : resolve(process.cwd(), `agentx-wiki-${date}.tar.gz`)\n const parent = resolve(wikiDir, \"..\")\n const base = wikiDir.split(\"/\").pop() || \"wiki\"\n const args = [\"-C\", parent, \"-czf\", out]\n if (!opts.includeRaw) args.push(\"--exclude=\" + base + \"/raw\")\n args.push(base)\n console.log(chalk.dim(` tar ${args.join(\" \")}`))\n const { spawnSync } = await import(\"child_process\")\n const r = spawnSync(\"tar\", args, { stdio: \"inherit\" })\n if (r.status !== 0) {\n console.log(chalk.red(` tar exited with ${r.status}`))\n process.exit(r.status || 1)\n }\n const { statSync } = await import(\"fs\")\n const size = existsSync(out) ? statSync(out).size : 0\n console.log()\n console.log(chalk.green(` ✓ wrote ${out} (${formatWikiBytes(size)})`))\n console.log(chalk.dim(` Restore on another node: agentx wiki import ${out}`))\n console.log()\n })\n\nwiki\n .command(\"import <archive>\")\n .description(\"restore a wiki archive (created with `agentx wiki export`)\")\n .option(\"--dir <path>\", \"where to restore (default: .agentx/wiki)\")\n .option(\"--force\", \"overwrite existing wiki without prompting\")\n .action(async (archive, opts) => {\n const archivePath = resolve(process.cwd(), archive)\n if (!existsSync(archivePath)) {\n console.log(chalk.red(` archive not found: ${archivePath}`))\n process.exit(1)\n }\n const target = opts.dir ? resolve(process.cwd(), opts.dir) : resolve(process.cwd(), \".agentx/wiki\")\n if (existsSync(target) && !opts.force) {\n console.log(chalk.yellow(` ${target} already exists.`))\n console.log(chalk.yellow(` Re-run with --force to overwrite (existing files where the archive has them; others stay).`))\n process.exit(1)\n }\n const parent = resolve(target, \"..\")\n const { mkdirSync } = await import(\"fs\")\n mkdirSync(parent, { recursive: true })\n const args = [\"-C\", parent, \"-xzf\", archivePath]\n console.log(chalk.dim(` tar ${args.join(\" \")}`))\n const { spawnSync } = await import(\"child_process\")\n const r = spawnSync(\"tar\", args, { stdio: \"inherit\" })\n if (r.status !== 0) {\n console.log(chalk.red(` tar exited with ${r.status}`))\n process.exit(r.status || 1)\n }\n console.log()\n console.log(chalk.green(` ✓ restored to ${target}`))\n console.log(chalk.dim(` Restart the daemon (or POST /reload) for the wiki hub to pick up the new content.`))\n console.log()\n })\n\nfunction formatWikiBytes(b: number): string {\n if (b < 1024) return b + \"B\"\n if (b < 1024 * 1024) return (b / 1024).toFixed(1) + \"K\"\n if (b < 1024 * 1024 * 1024) return (b / 1024 / 1024).toFixed(1) + \"M\"\n return (b / 1024 / 1024 / 1024).toFixed(2) + \"G\"\n}\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { resolve } from \"path\"\nimport { existsSync } from \"fs\"\nimport { GraphStore } from \"@/graph/store\"\nimport { hashPath, pathLabel } from \"@/graph/classifier\"\nimport { loadDaemonConfig } from \"@/daemon/config\"\n\n// --- agentx graph — intent knowledge graph operations ---\n//\n// v1 scope: just the review loop. Future: `graph status`, `graph nodes`,\n// `graph show <msgHash>`, `graph schema edit`. The admin panel surfaces\n// pending classifications; this CLI lets an operator (or a cron) invoke\n// the reviewer agent to triage them in batch.\n\nexport const graph = new Command()\n .name(\"graph\")\n .description(\"intent knowledge graph — review, inspect, manage\")\n\ngraph\n .command(\"review\")\n .description(\"triage pending classifications via the configured review agent (the agent uses `wiki query` for context before deciding)\")\n .option(\"--agent <id>\", \"override the review agent (defaults to graph.reviewAgent or graph.draftAgent)\")\n .option(\"--max <n>\", \"cap reviews this run\", \"20\")\n .option(\"--dry-run\", \"show the agent's decision but don't apply approvals/rejections\")\n .option(\"--daemon-url <url>\", \"daemon URL (default: http://localhost:18800)\")\n .action(async (opts) => {\n const config = loadDaemonConfig()\n if (!config.graph?.enabled) {\n console.log(chalk.yellow(\" graph.enabled is false — nothing to review\"))\n return\n }\n\n const agentId = opts.agent || config.graph.reviewAgent || config.graph.draftAgent\n if (!agentId) {\n console.log(chalk.red(\" no review agent. Set graph.reviewAgent in agentx.json or pass --agent <id>.\"))\n return\n }\n if (!config.agents?.[agentId]) {\n console.log(chalk.red(` agent \"${agentId}\" not in config`))\n return\n }\n const daemonUrl = (opts.daemonUrl || config.dashboard?.daemonUrl || \"http://localhost:18800\").replace(/\\/+$/, \"\")\n const cap = Math.max(1, parseInt(opts.max) || 20)\n\n const store = new GraphStore({ baseDir: resolve(process.cwd(), config.graph.baseDir) })\n const pending = store.listPendingClassifications(cap)\n if (pending.length === 0) {\n console.log(chalk.dim(\" no pending classifications — nothing to review\"))\n return\n }\n\n const schema = store.loadSchema()\n const nodes = store.loadNodes().nodes\n console.log()\n console.log(chalk.bold(` Graph review — ${pending.length} pending`))\n console.log(chalk.dim(` Reviewer: ${agentId} · daemon: ${daemonUrl} · ${opts.dryRun ? \"dry-run\" : \"commit\"}`))\n console.log()\n\n let approvedN = 0, rejectedN = 0, skippedN = 0, errorN = 0\n for (let i = 0; i < pending.length; i++) {\n const c = pending[i]\n const label = pathLabel(c.path, nodes) || c.path.join(\" › \")\n process.stdout.write(` [${i + 1}/${pending.length}] ${chalk.cyan(c.msgHash.slice(0, 8))} ${chalk.dim(label)} ... `)\n\n const prompt = buildReviewPrompt(c, schema, nodes)\n let decision: { decision?: string; reason?: string } | null = null\n try {\n decision = await askAgent(daemonUrl, agentId, prompt, config.dashboard?.token)\n } catch (e: any) {\n errorN++\n console.log(chalk.red(`ERR ${e.message?.slice(0, 80)}`))\n continue\n }\n if (!decision || !decision.decision) {\n errorN++\n console.log(chalk.red(\"ERR no decision\"))\n continue\n }\n const verdict = String(decision.decision).toLowerCase().trim()\n const reason = (decision.reason || \"\").toString().slice(0, 180)\n\n if (verdict === \"approve\") {\n console.log(chalk.green(`APPROVE`) + \" \" + chalk.dim(reason))\n if (!opts.dryRun) {\n try {\n commitApproved(store, c, schema, nodes, agentId)\n store.updateClassificationStatus(c.msgHash, {\n status: \"approved\",\n reviewer: agentId,\n reviewReason: reason,\n })\n approvedN++\n } catch (e: any) {\n console.log(chalk.yellow(` (commit failed, staying pending: ${e.message?.slice(0, 100)})`))\n errorN++\n }\n } else {\n approvedN++\n }\n } else if (verdict === \"reject\") {\n console.log(chalk.red(`REJECT`) + \" \" + chalk.dim(reason))\n if (!opts.dryRun) {\n store.updateClassificationStatus(c.msgHash, {\n status: \"rejected\",\n reviewer: agentId,\n reviewReason: reason,\n })\n }\n rejectedN++\n } else {\n console.log(chalk.yellow(`SKIP`) + \" \" + chalk.dim(reason || verdict))\n skippedN++\n }\n }\n\n console.log()\n const verb = opts.dryRun ? \"would\" : \"did\"\n console.log(chalk.dim(\n ` Summary: ${verb} approve ${approvedN}, ${verb} reject ${rejectedN}, ${skippedN} skipped, ${errorN} errors.`\n ))\n if (opts.dryRun && (approvedN > 0 || rejectedN > 0)) {\n console.log(chalk.dim(` Dry-run — omit --dry-run to apply.`))\n }\n console.log()\n })\n\n// --- graph migrate (Phase 2 of classifier-retire) ---\n// Bulk remap classifications.jsonl + index.json from v1 (scope/location/...)\n// to v2 (category/verb) via keyword heuristics. Idempotent. No LLM calls.\n\ngraph\n .command(\"migrate\")\n .description(\"remap past classifications from v1 (scope/location/org/unit/activity) to v2 (category/verb) via keyword heuristics. No LLM calls. Idempotent.\")\n .option(\"--dry-run\", \"report what would change, don't write\")\n .action(async (opts) => {\n const config = loadDaemonConfig()\n if (!config.graph) {\n console.log(chalk.yellow(\" graph block missing from agentx.json — nothing to migrate\"))\n return\n }\n const baseDir = resolve(process.cwd(), config.graph.baseDir)\n if (!existsSync(baseDir)) {\n console.log(chalk.yellow(` ${baseDir} does not exist — nothing to migrate`))\n return\n }\n const { migrateV2 } = await import(\"@/graph/migrate-v2\")\n const store = new GraphStore({ baseDir, log: () => undefined })\n const result = migrateV2(store, { dryRun: !!opts.dryRun, log: (...a) => console.log(chalk.dim(\" \"), ...a) })\n console.log()\n console.log(chalk.bold(\" Pattern hits:\"))\n const hits = Object.entries(result.patternHits).sort((a, b) => b[1] - a[1])\n if (hits.length === 0) console.log(chalk.dim(\" (none)\"))\n for (const [verb, count] of hits) console.log(` ${verb.padEnd(28)} ${count}`)\n console.log()\n if (opts.dryRun) {\n console.log(chalk.dim(` Dry-run — omit --dry-run to apply.`))\n } else {\n console.log(chalk.green(` Done. Backups: ${result.backups.length} file(s).`))\n }\n console.log()\n })\n\n// --- graph pull (cross-mesh sync) ---\n// v1: leader-follower — pull schema + nodes + approved classifications from\n// a peer's daemon. Conflicts skip silently; local always wins. Only approved\n// classifications come across — pending/rejected stay peer-local. Schema\n// divergence is reported but not reconciled (that's a harder design).\n\ngraph\n .command(\"pull\")\n .description(\"pull schema + nodes + approved classifications from a peer's graph\")\n .requiredOption(\"--from <url>\", \"peer daemon URL (e.g. http://clawd.noqta.tn:19900)\")\n .option(\"--token <t>\", \"bearer token for the peer (if it requires auth)\")\n .option(\"--limit <n>\", \"max approved classifications to pull\", \"500\")\n .option(\"--dry-run\", \"show what would change, don't write\")\n .action(async (opts) => {\n const config = loadDaemonConfig()\n if (!config.graph?.enabled) {\n console.log(chalk.yellow(\" graph.enabled is false on this node — nothing to sync INTO.\"))\n return\n }\n const peer = String(opts.from).replace(/\\/+$/, \"\")\n const limit = Math.max(1, parseInt(opts.limit) || 500)\n const headers: Record<string, string> = { Accept: \"application/json\" }\n if (opts.token) headers[\"Authorization\"] = `Bearer ${opts.token}`\n\n const store = new GraphStore({ baseDir: resolve(process.cwd(), config.graph.baseDir) })\n const localSchema = store.loadSchema()\n const localNodes = store.loadNodes().nodes\n const localIds = new Set(localNodes.map(n => n.id))\n\n // 1. Schema — warn on divergence. If local is fresh (no nodes committed),\n // adopt peer schema. Otherwise keep local + warn about axis drift.\n console.log()\n console.log(chalk.bold(` graph pull ← ${peer}`))\n let peerSchema: any, peerNodes: any[], peerClassifications: any[]\n try {\n const schemaRes = await fetch(`${peer}/graph/schema`, { headers })\n if (!schemaRes.ok) throw new Error(`schema HTTP ${schemaRes.status}`)\n const schemaData = await schemaRes.json() as any\n peerSchema = schemaData.schema\n\n const nodesRes = await fetch(`${peer}/graph/nodes`, { headers })\n if (!nodesRes.ok) throw new Error(`nodes HTTP ${nodesRes.status}`)\n peerNodes = ((await nodesRes.json() as any).nodes) || []\n\n const clRes = await fetch(`${peer}/graph/classifications?status=approved&limit=${limit}`, { headers })\n if (!clRes.ok) throw new Error(`classifications HTTP ${clRes.status}`)\n peerClassifications = ((await clRes.json() as any).classifications) || []\n } catch (e: any) {\n console.log(chalk.red(` fetch failed: ${e.message}`))\n return\n }\n\n const localLevels = localSchema.levels.map((l: any) => l.id).join(\",\")\n const peerLevels = peerSchema?.levels?.map((l: any) => l.id).join(\",\")\n const schemaMatches = localLevels === peerLevels\n if (!schemaMatches) {\n console.log(chalk.yellow(` ⚠ schema levels differ:`))\n console.log(chalk.dim(` local: ${localLevels}`))\n console.log(chalk.dim(` peer: ${peerLevels}`))\n if (localNodes.length === 0 && !opts.dryRun) {\n console.log(chalk.dim(` local is empty — adopting peer schema`))\n store.saveSchema(peerSchema)\n } else {\n console.log(chalk.yellow(` keeping local schema; node import may fail if levels disagree`))\n }\n } else {\n console.log(chalk.dim(` schema matches (${localSchema.levels.length} levels)`))\n }\n\n // 2. Nodes — import in topological order (level ascending) so parents\n // exist before children. Skip any id already present locally.\n const schemaForImport = schemaMatches ? localSchema : peerSchema\n const levelOrder = new Map<string, number>()\n schemaForImport.levels.forEach((l: any, i: number) => levelOrder.set(l.id, i))\n const sortedPeerNodes = [...peerNodes].sort(\n (a, b) => (levelOrder.get(a.level) ?? 99) - (levelOrder.get(b.level) ?? 99),\n )\n\n let nodesAdded = 0, nodesSkipped = 0, nodesFailed = 0\n for (const n of sortedPeerNodes) {\n if (localIds.has(n.id)) { nodesSkipped++; continue }\n if (opts.dryRun) { nodesAdded++; localIds.add(n.id); continue }\n try {\n store.addNode({\n ...n,\n createdBy: n.createdBy ? `${n.createdBy} (sync)` : `sync:${peer}`,\n })\n localIds.add(n.id)\n nodesAdded++\n } catch (e: any) {\n nodesFailed++\n console.log(chalk.yellow(` skip node ${n.id}: ${e.message?.slice(0, 100)}`))\n }\n }\n console.log(chalk.dim(` nodes: +${nodesAdded} added · ${nodesSkipped} already-present · ${nodesFailed} failed`))\n\n // 3. Approved classifications — populate fingerprint cache so recurring\n // similar messages here snap to the peer's approved path without\n // another LLM call. Skip any fingerprint already cached locally.\n let fpAdded = 0, fpSkipped = 0\n for (const c of peerClassifications) {\n if (!c.msgHash || !Array.isArray(c.path)) continue\n if (store.getFingerprint(c.msgHash)) { fpSkipped++; continue }\n if (opts.dryRun) { fpAdded++; continue }\n store.setFingerprint(c.msgHash, { path: c.path, leaf: c.leaf || {} })\n fpAdded++\n }\n console.log(chalk.dim(` fingerprints: +${fpAdded} cached · ${fpSkipped} already-present`))\n\n console.log()\n if (opts.dryRun) {\n console.log(chalk.dim(` Dry-run — omit --dry-run to apply.`))\n } else {\n console.log(chalk.green(` ✓ pulled from ${peer}`))\n }\n console.log()\n })\n\n// --- helpers ---\n\n/**\n * Build the review prompt for the agent. The agent sees the original message,\n * the proposed path + axes, a slice of the current catalog so it can sanity-\n * check names, and explicit instructions to use `wiki query` for institutional\n * context before deciding.\n */\nfunction buildReviewPrompt(\n c: any,\n schema: any,\n nodes: any[],\n): string {\n const existingByLevel: Record<string, string[]> = {}\n for (const n of nodes) {\n (existingByLevel[n.level] ||= []).push(`${n.id}${n.axes?.name ? ` (${n.axes.name})` : \"\"}`)\n }\n const levelsSummary = schema.levels\n .map((l: any) => ` ${l.id}: [${(existingByLevel[l.id] || []).slice(0, 10).join(\", \") || \"(none yet)\"}]`)\n .join(\"\\n\")\n\n const axesJson = JSON.stringify(c.proposedAxes || {}, null, 2)\n return [\n `You are reviewing a pending intent classification. Decide whether it is reasonable.`,\n ``,\n `--- MESSAGE (first 500 chars) ---`,\n (c.preview || \"\").slice(0, 500),\n `channel: ${c.channel || \"?\"} · sender: ${c.sender || \"?\"}`,\n ``,\n `--- PROPOSED PATH ---`,\n c.path.join(\" › \"),\n ``,\n `--- PROPOSED AXES (per new node) ---`,\n axesJson,\n ``,\n `--- CURRENT NODES BY LEVEL (first 10 per level) ---`,\n levelsSummary,\n ``,\n `--- YOUR JOB ---`,\n `Decide one of:`,\n ` approve — the path is right and the axes make sense for the message`,\n ` reject — the path is wrong (e.g. the message is NOT about the proposed org/topic, or the axes are bogus)`,\n ` skip — you can't confidently decide; leave it for a human`,\n ``,\n `BEFORE you decide, you MAY call \\`agentx wiki query\\` (via Bash) to check institutional context — e.g. \"is there an article for this project\" or \"who is this person\". This is optional; don't call it for obvious cases.`,\n ``,\n `Bias toward reject over approve when uncertain. A wrong approval pollutes the graph; a wrong rejection just keeps the entry pending.`,\n ``,\n `Return EXACTLY one JSON object on one line, no prose, no fences:`,\n ` {\"decision\":\"approve\"|\"reject\"|\"skip\",\"reason\":\"one sentence\"}`,\n ].join(\"\\n\")\n}\n\nasync function askAgent(\n daemonUrl: string,\n agentId: string,\n message: string,\n token?: string,\n): Promise<any> {\n const headers: Record<string, string> = { \"Content-Type\": \"application/json\" }\n if (token) headers[\"Authorization\"] = `Bearer ${token}`\n const ac = new AbortController()\n const timer = setTimeout(() => ac.abort(), 120_000) // 2 min — reviewer may call wiki query\n try {\n const r = await fetch(`${daemonUrl}/task`, {\n method: \"POST\",\n headers,\n body: JSON.stringify({\n agent: agentId,\n message,\n context: { channel: \"a2a\", sender: \"graph-review\" },\n }),\n signal: ac.signal,\n })\n if (!r.ok) throw new Error(`daemon /task HTTP ${r.status}`)\n const data: any = await r.json()\n if (data?.error) throw new Error(String(data.error))\n return extractJson((data?.content || \"\").toString())\n } finally {\n clearTimeout(timer)\n }\n}\n\n/** Commit any new nodes along the path + populate the fingerprint cache.\n * Delegates to store.commitNodesAlongPath which handles level inference\n * from axes (so paths that skip levels, like business→noqta when location\n * is absent, land at the right level) and refreshes nodes between adds. */\nfunction commitApproved(\n store: GraphStore,\n c: any,\n schema: any,\n _existing: any[], // unused — helper re-reads fresh each time\n createdBy: string,\n): void {\n store.commitNodesAlongPath(c.path, c.proposedAxes || {}, schema, createdBy)\n store.setFingerprint(c.msgHash, { path: c.path, leaf: c.leaf || {} })\n}\n\nfunction extractJson(text: string): any {\n if (!text) return null\n try { return JSON.parse(text) } catch {}\n const fenced = text.match(/```(?:json)?\\s*([\\s\\S]*?)```/)\n if (fenced) { try { return JSON.parse(fenced[1]) } catch {} }\n const start = text.indexOf(\"{\")\n if (start < 0) return null\n let depth = 0\n for (let i = start; i < text.length; i++) {\n if (text[i] === \"{\") depth++\n else if (text[i] === \"}\") {\n depth--\n if (depth === 0) { try { return JSON.parse(text.slice(start, i + 1)) } catch { return null } }\n }\n }\n return null\n}\n\n// Suppress unused-import warning — hashPath is exported via the types; we don't\n// need it in this file but keep the dependency explicit in case future\n// subcommands want to regenerate pathId for display.\nvoid hashPath\nvoid existsSync\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { ProcedureStore } from \"@/procedures\"\nimport { matchProcedures } from \"@/procedures/match\"\nimport { extractCommand, watchCommand } from \"./procedure-extract\"\n\n// --- agentx procedure — user-perspective SOPs, the front door to automation ---\n//\n// A procedure describes a recurring activity from the USER's point of view\n// (trigger, inputs, steps, expected outcome) — the system executing it is a\n// black box. Drafts come from `extract` (mined from real activity) or `add`\n// (hand-written); review with promote/reject; agents consume matches as\n// guidance. Executable DAG workflows are an optional later promotion.\n\nexport const procedure = new Command()\n .name(\"procedure\")\n .description(\"procedures (SOPs) — extract from activity, review drafts, match, schedule\")\n\nprocedure.addCommand(extractCommand)\nprocedure.addCommand(watchCommand)\n\nprocedure\n .command(\"list\")\n .description(\"list procedures with their trigger line\")\n .option(\"--drafts\", \"list unreviewed drafts instead\", false)\n .option(\"--all\", \"list active procedures and drafts\", false)\n .action((opts) => {\n const store = new ProcedureStore()\n const items = [\n ...(opts.drafts ? [] : store.list()),\n ...(opts.drafts || opts.all ? store.listDrafts() : []),\n ]\n if (!items.length) {\n console.log(chalk.dim(\n opts.drafts\n ? \" no procedure drafts. Mine some with: agentx procedure extract\"\n : \" no procedures yet. Try: agentx procedure extract · or: agentx procedure add\",\n ))\n return\n }\n console.log()\n for (const p of items) {\n const status = p.meta.status === \"active\" ? chalk.green(p.meta.status) : p.meta.status === \"draft\" ? chalk.yellow(p.meta.status) : chalk.dim(p.meta.status)\n console.log(` ${chalk.cyan(p.meta.id)} ${chalk.bold(p.meta.title)} ${status}`)\n console.log(` ${chalk.dim(\"trigger:\")} ${p.meta.trigger}`)\n if (p.meta.source) console.log(` ${chalk.dim(\"source:\")} ${chalk.dim(p.meta.source)}`)\n if (p.meta.kpis?.length) console.log(` ${chalk.dim(\"kpis:\")} ${p.meta.kpis.join(\", \")}`)\n }\n console.log()\n console.log(chalk.dim(` ${items.length} procedure${items.length === 1 ? \"\" : \"s\"}.`))\n })\n\nprocedure\n .command(\"add\")\n .description(\"add a new procedure (non-interactive; pass all fields as flags)\")\n .requiredOption(\"--id <id>\", \"procedure id (lower-kebab, e.g. deploy-clawd)\")\n .requiredOption(\"--title <t>\", \"human-readable title\")\n .requiredOption(\"--trigger <t>\", \"when this procedure applies (one sentence)\")\n .option(\"--input <i...>\", \"required input (repeatable)\", (v: string, prev: string[] = []) => [...prev, v])\n .option(\"--expected <t>\", \"expected output / success criterion\")\n .option(\"--kpi <k...>\", \"KPI (repeatable)\", (v: string, prev: string[] = []) => [...prev, v])\n .option(\"--owner <id>\", \"owning agent or person\")\n .option(\"--tag <t...>\", \"tag (repeatable)\", (v: string, prev: string[] = []) => [...prev, v])\n .option(\"--related <r...>\", \"related procedure id or wiki article title (repeatable)\", (v: string, prev: string[] = []) => [...prev, v])\n .option(\"--steps <md>\", \"markdown body — usually numbered steps\")\n .action((opts) => {\n const store = new ProcedureStore()\n const body = opts.steps\n ? String(opts.steps)\n : `## Steps\\n\\n1. (fill in)\\n\\n## Notes\\n\\n`\n try {\n const p = store.add({\n id: opts.id,\n title: opts.title,\n trigger: opts.trigger,\n inputs: opts.input || [],\n expected: opts.expected,\n kpis: opts.kpi || [],\n owner: opts.owner,\n tags: opts.tag || [],\n related: opts.related || [],\n } as any, body)\n console.log(chalk.green(` ✓ procedure added: ${p.meta.id}`))\n console.log(chalk.dim(` ${store.baseDir}/${p.path}`))\n } catch (e: any) {\n console.log(chalk.red(` add failed: ${e.message}`))\n process.exit(1)\n }\n })\n\nprocedure\n .command(\"show <id>\")\n .description(\"show a single procedure (active or draft)\")\n .action((id: string) => {\n const store = new ProcedureStore()\n const p = store.get(id) ?? store.getDraft(id)\n if (!p) {\n console.log(chalk.yellow(` no procedure matches \"${id}\". Try: agentx procedure list --all`))\n process.exit(1)\n }\n console.log()\n console.log(chalk.bold(` ${p!.meta.title}`) + chalk.dim(` (${p!.meta.id}, ${p!.meta.status})`))\n console.log(chalk.dim(` trigger: ${p!.meta.trigger}`))\n if (p!.meta.inputs?.length) console.log(chalk.dim(` inputs: ${p!.meta.inputs.join(\", \")}`))\n if (p!.meta.expected) console.log(chalk.dim(` expected: ${p!.meta.expected}`))\n if (p!.meta.kpis?.length) console.log(chalk.dim(` kpis: ${p!.meta.kpis.join(\", \")}`))\n if (p!.meta.owner) console.log(chalk.dim(` owner: ${p!.meta.owner}`))\n if (p!.meta.source) console.log(chalk.dim(` source: ${p!.meta.source}`))\n if (p!.meta.related?.length) console.log(chalk.dim(` related: ${p!.meta.related.join(\", \")}`))\n console.log()\n console.log(p!.body)\n console.log()\n })\n\nprocedure\n .command(\"promote <id>\")\n .description(\"promote a draft into the active procedure set\")\n .action((id: string) => {\n const store = new ProcedureStore()\n try {\n const p = store.promoteDraft(id)\n console.log(chalk.green(` ✓ promoted: ${p.meta.id}`))\n console.log(chalk.dim(` agents will now follow it when a task matches: \"${p.meta.trigger}\"`))\n } catch (e: any) {\n console.log(chalk.red(` ${e.message}`))\n process.exit(1)\n }\n })\n\nprocedure\n .command(\"reject <id>\")\n .description(\"reject a draft (kept under _drafts/_rejected/ so it is never re-mined)\")\n .action((id: string) => {\n const store = new ProcedureStore()\n try {\n store.rejectDraft(id)\n console.log(chalk.green(` ✓ rejected: ${id}`))\n } catch (e: any) {\n console.log(chalk.red(` ${e.message}`))\n process.exit(1)\n }\n })\n\nprocedure\n .command(\"deprecate <id>\")\n .description(\"retire an active procedure (kept, but never surfaced to agents)\")\n .action((id: string) => {\n const store = new ProcedureStore()\n try {\n store.deprecate(id)\n console.log(chalk.green(` ✓ deprecated: ${id}`))\n } catch (e: any) {\n console.log(chalk.red(` ${e.message}`))\n process.exit(1)\n }\n })\n\nprocedure\n .command(\"match <text>\")\n .description(\"find active procedures matching a task description\")\n .option(\"--limit <n>\", \"max matches\", \"3\")\n .option(\"--min-score <s>\", \"minimum score 0..1\", \"0.2\")\n .action((text: string, opts) => {\n const store = new ProcedureStore()\n const matches = matchProcedures(text, store.list(), {\n limit: Number(opts.limit) || 3,\n minScore: Number(opts.minScore) || 0.2,\n })\n if (!matches.length) {\n console.log(chalk.dim(\" no matching procedures\"))\n return\n }\n for (const m of matches) {\n console.log(` ${chalk.cyan(m.procedure.meta.id)} ${chalk.bold(m.score.toFixed(2))} ${chalk.dim(m.reasons.join(\", \"))}`)\n console.log(chalk.dim(` ${m.procedure.meta.trigger}`))\n }\n })\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { existsSync } from \"fs\"\nimport { resolve } from \"path\"\nimport Database from \"better-sqlite3\"\nimport { SessionStore } from \"@/agents/sessions\"\nimport { runExtraction, DEFAULT_MIN_OCCURRENCES, DEFAULT_MAX_CLUSTERS } from \"@/procedures/mine\"\nimport { applyConfigMutation, setAtPath } from \"@/daemon/config-mutator\"\n\n// --- agentx procedure extract / watch ---\n// extract: one mining pass (dry-run by default, like `wiki promote`).\n// watch: persist the cadence — a `crons.procedure-extract` entry that\n// shells this exact CLI, plus the `procedures.extraction` config\n// block the daemon's on-task watcher reads.\n\nfunction parseSince(input: string | undefined): number | undefined {\n if (!input) return undefined\n const m = /^(\\d+)\\s*([smhd])$/.exec(input.trim())\n if (m) {\n const n = Number(m[1])\n const unit = m[2]\n return Date.now() - n * (unit === \"s\" ? 1000 : unit === \"m\" ? 60_000 : unit === \"h\" ? 3600_000 : 86_400_000)\n }\n const n = Number(input)\n if (Number.isFinite(n) && n > 0) return n\n console.log(chalk.red(` Invalid --since \"${input}\". Use \"1h\", \"30m\", \"7d\", or an ms epoch.`))\n process.exit(1)\n}\n\nfunction openTraceDb(path: string): Database.Database {\n const dbPath = resolve(process.cwd(), path)\n if (!existsSync(dbPath)) {\n console.log(chalk.red(` No db at ${dbPath}`))\n process.exit(1)\n }\n return new Database(dbPath, { readonly: true })\n}\n\nexport const extractCommand = new Command()\n .name(\"extract\")\n .description(\"mine recurring user activity into procedure drafts (dry-run by default)\")\n .option(\"--path <path>\", \"SQLite db path\", \".agentx/db.sqlite\")\n .option(\"--since <duration>\", \"activity window, e.g. 24h, 7d, or ms epoch\", \"7d\")\n .option(\"--agent <id>\", \"only mine one agent's activity\")\n .option(\"--min-occurrences <n>\", \"recurrences before a pattern becomes a draft\", String(DEFAULT_MIN_OCCURRENCES))\n .option(\"--max <n>\", \"max clusters distilled per run\", String(DEFAULT_MAX_CLUSTERS))\n .option(\"--via <agentId>\", \"route the LLM call through a running agent — uses the agent's own session\")\n .option(\"--model <model>\", \"direct Anthropic API model — needs ANTHROPIC_API_KEY\")\n .option(\"--daemon <url>\", \"daemon API base URL for --via\", \"http://127.0.0.1:18800\")\n .option(\"--commit\", \"write drafts and persist recurrence counts\", false)\n .action(async (opts) => {\n if (opts.commit && !opts.via && !opts.model) {\n console.log(chalk.red(\" --commit needs an LLM: pass --via <agentId> or --model <model>\"))\n process.exit(1)\n }\n const db = openTraceDb(opts.path)\n const report = await runExtraction(db, {\n since: parseSince(opts.since),\n agentId: opts.agent,\n sessions: new SessionStore(process.cwd()),\n minOccurrences: Number(opts.minOccurrences) || DEFAULT_MIN_OCCURRENCES,\n max: Number(opts.max) || DEFAULT_MAX_CLUSTERS,\n commit: !!opts.commit,\n llm: { viaAgent: opts.via, model: opts.model, daemonUrl: opts.daemon, chatId: \"procedure-miner\" },\n log: (m) => console.log(chalk.dim(` ${m}`)),\n })\n\n console.log()\n console.log(` ${report.episodes} episode(s) → ${report.clusters} cluster(s), ${report.ready.length} at threshold`)\n for (const c of report.ready) {\n console.log(` ${chalk.cyan(c.key)} ${chalk.bold(`×${c.count}`)} ${chalk.dim(c.status)}`)\n if (c.sampleMessage) console.log(chalk.dim(` \"${c.sampleMessage.slice(0, 100)}\"`))\n }\n if (report.nearMisses.length) {\n console.log(chalk.dim(`\\n near-misses (same intent, different activity shape — tuning signal):`))\n for (const nm of report.nearMisses.slice(0, 5)) {\n console.log(chalk.dim(` ${nm.intent} → ${nm.keys.length} variants`))\n }\n }\n for (const d of report.drafted) {\n console.log(chalk.green(` ✓ draft written: ${d.id}`) + chalk.dim(` (${d.count} occurrences)`))\n }\n for (const s of report.skipped) {\n console.log(chalk.yellow(` skipped ${s.cluster}: ${s.reason}`))\n }\n for (const w of report.warnings) console.log(chalk.yellow(` ⚠ ${w}`))\n if (report.dryRun) {\n console.log(chalk.dim(\"\\n dry run only; pass --commit --via <agentId> to write drafts\"))\n } else if (report.drafted.length) {\n console.log(chalk.dim(\"\\n review with: agentx procedure list --drafts · then promote/reject <id>\"))\n }\n })\n\nconst CADENCE = {\n hourly: \"0 * * * *\",\n // 03:00 — after workflow-absorb (02:00) and memory-promote (02:30).\n daily: \"0 3 * * *\",\n} as const\n\nexport const watchCommand = new Command()\n .name(\"watch\")\n .description(\"set the extraction cadence: registers the cron + config the daemon runs on\")\n .option(\"--hourly\", \"extract every hour\")\n .option(\"--daily\", \"extract daily at 03:00\")\n .option(\"--cron <expr>\", \"custom 5-field cron expression\")\n .option(\"--on-task\", \"also count patterns live after each completed task\")\n .option(\"--off\", \"disable scheduled extraction\")\n .option(\"--via <agentId>\", \"agent that runs the extraction (LLM distillation goes through its session)\")\n .option(\"--min-occurrences <n>\", \"recurrences before a pattern becomes a draft\", String(DEFAULT_MIN_OCCURRENCES))\n .option(\"--timezone <tz>\", \"IANA timezone\", \"Africa/Tunis\")\n .option(\"-c, --config <path>\", \"path to agentx.json\")\n .option(\"--dry-run\", \"print what would be written without writing\")\n .action(async (opts) => {\n const schedule: string | undefined = opts.off\n ? undefined\n : opts.cron ?? (opts.hourly ? CADENCE.hourly : opts.daily ? CADENCE.daily : undefined)\n if (!opts.off && !schedule && !opts.onTask) {\n console.log(chalk.red(\" pick a cadence: --hourly, --daily, --cron <expr>, and/or --on-task (or --off)\"))\n process.exit(1)\n }\n if (!opts.off && !opts.via) {\n console.log(chalk.red(\" --via <agentId> is required: drafts are distilled through that agent's session\"))\n process.exit(1)\n }\n\n const minOccurrences = Number(opts.minOccurrences) || DEFAULT_MIN_OCCURRENCES\n const extraction = {\n enabled: !opts.off,\n onTaskCompletion: !opts.off && !!opts.onTask,\n minOccurrences,\n via: opts.off ? undefined : opts.via,\n }\n const prompt = [\n \"Run this shell command EXACTLY as written. Do NOT substitute, rewrite, shorten, or fall back to alternative commands. If it exits non-zero, report the verbatim exit code and stderr and STOP.\",\n \"\",\n `1) cd ${process.cwd()} && node dist/cli.js procedure extract --since 7d --max ${DEFAULT_MAX_CLUSTERS} --min-occurrences ${minOccurrences} --via ${opts.via} --commit`,\n \"\",\n \"Report a one-line summary of drafted/skipped counts.\",\n ].join(\"\\n\")\n\n const result = await applyConfigMutation(\n (c) => {\n setAtPath(c, \"procedures.extraction\", extraction)\n if (opts.off) {\n if ((c as any).crons?.[\"procedure-extract\"]) {\n setAtPath(c, \"crons.procedure-extract.enabled\", false)\n }\n } else if (schedule) {\n setAtPath(c, \"crons.procedure-extract\", {\n enabled: true,\n schedule,\n timezone: opts.timezone,\n agent: opts.via,\n prompt,\n timeout: 900,\n onError: \"log\",\n })\n }\n },\n { configPath: opts.config, dryRun: !!opts.dryRun },\n )\n if (!result.success) {\n console.log(chalk.red(` ✗ ${result.error}`))\n process.exit(1)\n }\n\n const verb = opts.dryRun ? \"would set\" : \"Set\"\n if (opts.off) {\n console.log(chalk.green(` ✓ ${verb} procedure extraction: off`))\n } else {\n console.log(chalk.green(` ✓ ${verb} procedure extraction cadence`))\n if (schedule) console.log(chalk.dim(` cron: ${schedule} (${opts.timezone}) via ${opts.via}`))\n if (opts.onTask) console.log(chalk.dim(` on-task counting: enabled`))\n console.log(chalk.dim(` threshold: ${minOccurrences} occurrences`))\n }\n console.log(chalk.yellow(\" ⚠ restart the daemon to activate — hot-reload does not pick up new config blocks\"))\n })\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { resolve, basename } from \"path\"\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\"\nimport Database from \"better-sqlite3\"\nimport { RunStore, WorkflowStore, lintWorkflow, workflowSchema, parseYamlWorkflow, renderWorkflowYaml, WorkflowYamlError } from \"@/workflows\"\nimport { TEMPLATES, readTemplate, type TemplateName } from \"@/workflows/templates\"\nimport { getTrace } from \"@/storage/traces\"\nimport {\n architectOrBuildDraft,\n buildDraftsFromClusters,\n buildDraftsFromClustersAsync,\n buildWorkflowDraftFromTrace,\n clusterWorkflowCandidates,\n getWorkflowDraft,\n isMeaningfulDraft,\n listWorkflowDrafts,\n loadSuccessfulTraces,\n promoteWorkflowDraft,\n rejectWorkflowDraft,\n validateWorkflowDraft,\n writeWorkflowDraft,\n} from \"@/workflows/absorb\"\n\n// --- agentx workflow — declarative state machines for channel events ---\n//\n// v1: list / show / validate / run-manual / runs / pause / resume / cancel\n// The engine itself runs inside the daemon; this CLI is the author tooling\n// (inspect YAML, validate, poke manual triggers, read run history).\n\nexport const workflow = new Command()\n .name(\"workflow\")\n .description(\"workflow definitions — list, show, validate, manage runs\")\n\nfunction durationToMs(input: string): number | null {\n const m = /^(\\d+)\\s*([smhd])$/.exec(input.trim())\n if (!m) return null\n const n = Number(m[1])\n const unit = m[2]\n return n * (unit === \"s\" ? 1000 : unit === \"m\" ? 60_000 : unit === \"h\" ? 3600_000 : 86_400_000)\n}\n\nfunction parseSince(input: string | undefined): number | undefined {\n if (!input) return undefined\n const ms = durationToMs(input)\n if (ms === null) {\n const n = Number(input)\n if (Number.isFinite(n) && n > 0) return n\n console.log(chalk.red(` Invalid --since \"${input}\". Use \"1h\", \"30m\", \"7d\", or an ms epoch.`))\n process.exit(1)\n }\n return Date.now() - ms\n}\n\nfunction openTraceDb(path = \".agentx/db.sqlite\"): Database.Database {\n const dbPath = resolve(process.cwd(), path)\n if (!existsSync(dbPath)) {\n console.log(chalk.red(` No db at ${dbPath}`))\n process.exit(1)\n }\n return new Database(dbPath, { readonly: true })\n}\n\nfunction printWorkflowDraft(workflow: unknown, format: \"yaml\" | \"json\"): void {\n if (format === \"json\") console.log(JSON.stringify(workflow, null, 2))\n else console.log(renderWorkflowYaml(workflow))\n}\n\nfunction traceSummary(records: any[]): { durationMs: number; totalTokens: number; models: string[]; status: string; result: string } {\n const models = Array.from(new Set(records.map((r) => r.model).filter(Boolean).map(String)))\n const durationMs = records.reduce((sum, r) => sum + (Number(r.durationMs) || 0), 0)\n const totalTokens = records.reduce((sum, r) => sum + (Number(r.totalTokens) || 0), 0)\n const last = records.at(-1)\n return {\n durationMs,\n totalTokens,\n models,\n status: records.some((r) => r.status === \"error\") ? \"error\" : (last?.status || \"ok\"),\n result: String(last?.outputSummary || last?.error || \"\").slice(0, 160),\n }\n}\n\nfunction printReplayComparison(original: ReturnType<typeof traceSummary>, replay: ReturnType<typeof traceSummary>): void {\n const deltaMs = replay.durationMs - original.durationMs\n const deltaTokens = replay.totalTokens - original.totalTokens\n console.log()\n console.log(chalk.bold(\" replay comparison\"))\n console.log(` original: ${original.status} ${original.totalTokens || 0}t ${original.durationMs || 0}ms model=${original.models.join(\",\") || \"—\"}`)\n console.log(` replay: ${replay.status} ${replay.totalTokens || 0}t ${replay.durationMs || 0}ms model=${replay.models.join(\",\") || \"—\"}`)\n console.log(` delta: ${deltaTokens >= 0 ? \"+\" : \"\"}${deltaTokens}t ${deltaMs >= 0 ? \"+\" : \"\"}${deltaMs}ms`)\n if (replay.result) console.log(` result: ${replay.result}`)\n}\n\nworkflow\n .command(\"list\")\n .description(\"list all workflows with their trigger + state count\")\n .action(() => {\n const store = new WorkflowStore()\n const items = store.list()\n if (!items.length) {\n console.log(chalk.dim(\" no workflows yet. Add one by writing .agentx/workflows/<id>.json\"))\n return\n }\n console.log()\n for (const wf of items) {\n const trigger = wf.nodes.find((n) => n.type.startsWith(\"trigger.\"))\n const cfg = (trigger?.config ?? {}) as { source?: string; filter?: { project?: string; repo?: string; chat?: string } }\n const filterParts = [cfg.filter?.project, cfg.filter?.repo, cfg.filter?.chat].filter(Boolean).join(\" / \")\n // `state` is the dispatch gate; `status` is review metadata (see\n // workflowSchema). Rendered unambiguously because the bare pair\n // \"state=… status=…\" kept getting misread as one lifecycle.\n const dispatch = wf.state === \"active\" ? chalk.green(\"dispatch: active\") : chalk.yellow(`dispatch: ${wf.state}`)\n console.log(` ${chalk.cyan(wf.id)} ${chalk.bold(wf.title)} ${chalk.dim(`v${wf.version} ·`)} ${dispatch} ${chalk.dim(`· review: ${wf.status}`)}`)\n console.log(` ${chalk.dim(\"trigger:\")} ${cfg.source ?? \"?\"}${filterParts ? ` ${chalk.dim(filterParts)}` : \"\"}`)\n console.log(` ${chalk.dim(\"nodes: \")} ${wf.nodes.length} (${wf.nodes.map((n) => n.type).join(\", \")})`)\n }\n console.log()\n console.log(chalk.dim(` ${items.length} workflow${items.length === 1 ? \"\" : \"s\"}.`))\n })\n\nworkflow\n .command(\"show <id>\")\n .description(\"show a single workflow's full definition\")\n .option(\"--format <fmt>\", \"output format: json (default) or yaml\", \"json\")\n .action((id: string, opts: { format: string }) => {\n const store = new WorkflowStore()\n const wf = store.get(id)\n if (!wf) {\n console.log(chalk.yellow(` no workflow matches \"${id}\". Try: agentx workflow list`))\n process.exit(1)\n }\n const fmt = opts.format.toLowerCase()\n if (fmt === \"yaml\" || fmt === \"yml\") {\n // Render the canonical (post-desugar) shape, not the original\n // YAML source — `flow:` sugar is a one-way authoring affordance,\n // not a round-trip format. The output validates clean when\n // copied back to a new file.\n console.log(renderWorkflowYaml(wf))\n } else if (fmt === \"json\") {\n console.log(JSON.stringify(wf, null, 2))\n } else {\n console.log(chalk.red(` unknown format \"${opts.format}\" — use json or yaml`))\n process.exit(1)\n }\n })\n\nworkflow\n .command(\"validate [file]\")\n .description(\"validate all workflows in .agentx/workflows (or a single file)\")\n .action((file?: string) => {\n if (file) {\n const path = resolve(process.cwd(), file)\n if (!existsSync(path)) {\n console.log(chalk.red(` file not found: ${path}`))\n process.exit(1)\n }\n try {\n const text = readFileSync(path, \"utf-8\")\n const isYaml = /\\.(ya?ml)$/i.test(file)\n // YAML files run through the desugar pass before Zod sees them.\n // JSON keeps its existing JSON.parse path.\n const raw = isYaml ? parseYamlWorkflow(text, { filePath: file }) : JSON.parse(text)\n const parsed = workflowSchema.safeParse(raw)\n if (!parsed.success) {\n console.log(chalk.red(` ✗ ${path}`))\n for (const i of parsed.error.issues) console.log(` ${i.path.join(\".\") || \"<root>\"}: ${i.message}`)\n process.exit(1)\n }\n const lintIssues = lintWorkflow(parsed.data)\n if (lintIssues.length) {\n console.log(chalk.yellow(` ! ${path} (lint)`))\n for (const l of lintIssues) console.log(` ${l}`)\n process.exit(1)\n }\n console.log(chalk.green(` ✓ ${parsed.data.id} — valid`))\n } catch (e: any) {\n // WorkflowYamlError already carries a friendly message with the\n // file path + line/col when js-yaml provided it; print as-is.\n const msg = e instanceof WorkflowYamlError ? e.message : `parse error: ${e?.message ?? e}`\n console.log(chalk.red(` ${msg}`))\n process.exit(1)\n }\n return\n }\n const store = new WorkflowStore()\n const results = store.validateAll()\n let ok = 0\n let bad = 0\n for (const r of results) {\n if (r.isValid) {\n console.log(chalk.green(` ✓ ${(r as any).workflow.id}`))\n ok++\n } else {\n const id = (r as any).workflow?.id || (r as any).id\n console.log(chalk.red(` ✗ ${id}`))\n for (const issue of r.issues) console.log(` ${issue}`)\n bad++\n }\n }\n console.log()\n console.log(chalk.dim(` ${ok} valid, ${bad} invalid.`))\n if (bad > 0) process.exit(1)\n })\n\nworkflow\n .command(\"init <id>\")\n .description(\"scaffold a new workflow YAML from a template (linear by default)\")\n .option(\"--template <name>\", `which template to use (${TEMPLATES.map((t) => t.name).join(\" | \")})`, \"linear\")\n .option(\"--agent <id>\", \"fill the agent placeholder with this agent id\", \"default\")\n .option(\"--reviewer <id>\", \"fill the reviewer placeholder for human-in-the-loop templates\", \"alice\")\n .option(\"--title <text>\", \"workflow title\", \"\")\n .option(\"--json\", \"scaffold as .json instead of .yaml\", false)\n .option(\"--force\", \"overwrite an existing workflow with the same id\", false)\n .action((id: string, opts) => {\n const tmplName = String(opts.template || \"linear\") as TemplateName\n if (!TEMPLATES.some((t) => t.name === tmplName)) {\n console.log(chalk.red(` unknown template \"${opts.template}\"`))\n console.log(chalk.dim(` available: ${TEMPLATES.map((t) => t.name).join(\", \")}`))\n process.exit(1)\n }\n if (!/^[a-z0-9][a-z0-9_-]*$/.test(id)) {\n console.log(chalk.red(` workflow id must be lower-kebab (got \"${id}\")`))\n process.exit(1)\n }\n const store = new WorkflowStore()\n if (!opts.force && store.get(id)) {\n console.log(chalk.red(` workflow \"${id}\" already exists. Use --force to overwrite or pick a new id.`))\n process.exit(1)\n }\n\n let body = readTemplate(tmplName)\n body = body\n .replace(/__ID__/g, id)\n .replace(/__TITLE__/g, opts.title ? String(opts.title) : `${tmplName} workflow ${id}`)\n .replace(/__AGENT__/g, String(opts.agent))\n .replace(/__REVIEWER__/g, String(opts.reviewer))\n\n // Validate the substituted text before writing — catches placeholder\n // typos and template drift before the operator opens it. Note: the\n // template may reference an agent that doesn't exist on this\n // install; lint flags unreachable nodes etc., not agent-existence,\n // so a \"valid\" workflow can still need editing before it runs.\n try {\n const raw = parseYamlWorkflow(body, { filePath: `${id}.yaml` })\n const parsed = workflowSchema.safeParse(raw)\n if (!parsed.success) {\n console.log(chalk.red(` template \"${tmplName}\" failed schema validation after substitution:`))\n for (const i of parsed.error.issues) console.log(` ${i.path.join(\".\") || \"<root>\"}: ${i.message}`)\n process.exit(1)\n }\n } catch (e: any) {\n console.log(chalk.red(` template parse failed: ${e?.message ?? e}`))\n process.exit(1)\n }\n\n const ext = opts.json ? \"json\" : \"yaml\"\n const dest = resolve(process.cwd(), \".agentx/workflows\", `${id}.${ext}`)\n if (opts.json) {\n // Round-trip through Zod so the JSON is canonical (sorted keys\n // become deterministic; stripped sugar; defaults filled).\n const raw = parseYamlWorkflow(body, { filePath: `${id}.yaml` })\n const parsed = workflowSchema.parse(raw)\n writeFileSync(dest, JSON.stringify(parsed, null, 2) + \"\\n\")\n } else {\n writeFileSync(dest, body)\n }\n\n console.log()\n console.log(chalk.green(` ✓ scaffolded ${dest}`))\n console.log(chalk.dim(` template: ${tmplName}`))\n console.log()\n console.log(chalk.dim(\" Next:\"))\n console.log(chalk.dim(` 1. edit ${dest}`))\n console.log(chalk.dim(` 2. agentx workflow validate ${dest}`))\n console.log(chalk.dim(` 3. agentx workflow run ${id} --watch`))\n console.log()\n })\n\nworkflow\n .command(\"templates\")\n .description(\"list the available workflow templates for `init`\")\n .action(() => {\n console.log()\n for (const t of TEMPLATES) {\n console.log(` ${chalk.cyan(t.name.padEnd(20))} ${chalk.bold(t.title)}`)\n console.log(` ${\" \".repeat(20)} ${chalk.dim(t.description)}`)\n }\n console.log()\n console.log(chalk.dim(` Use: agentx workflow init <id> --template <name>`))\n console.log()\n })\n\nworkflow\n .command(\"add <file>\")\n .description(\"import a YAML/JSON workflow file into .agentx/workflows and hot-reload\")\n .option(\"--daemon <url>\", \"daemon API base URL\", \"http://127.0.0.1:18800\")\n .option(\"--no-reload\", \"skip the POST /reload after writing\")\n .action(async (file: string, opts) => {\n const path = resolve(process.cwd(), file)\n if (!existsSync(path)) {\n console.log(chalk.red(` file not found: ${path}`))\n process.exit(1)\n }\n const text = readFileSync(path, \"utf-8\")\n const isYaml = /\\.(ya?ml)$/i.test(file)\n let raw: unknown\n try {\n raw = isYaml ? parseYamlWorkflow(text, { filePath: file }) : JSON.parse(text)\n } catch (e: any) {\n const msg = e instanceof WorkflowYamlError ? e.message : `parse error: ${e?.message ?? e}`\n console.log(chalk.red(` ${msg}`))\n process.exit(1)\n }\n const parsed = workflowSchema.safeParse(raw)\n if (!parsed.success) {\n console.log(chalk.red(` ✗ schema:`))\n for (const i of parsed.error.issues) console.log(` ${i.path.join(\".\") || \"<root>\"}: ${i.message}`)\n process.exit(1)\n }\n const lintIssues = lintWorkflow(parsed.data)\n if (lintIssues.length) {\n console.log(chalk.red(` ✗ lint:`))\n for (const l of lintIssues) console.log(` ${l}`)\n process.exit(1)\n }\n\n const store = new WorkflowStore()\n const ext = isYaml ? (basename(file).match(/\\.yml$/i) ? \"yml\" : \"yaml\") : \"json\"\n const dest = resolve(store.baseDir, `${parsed.data.id}.${ext}`)\n writeFileSync(dest, isYaml ? text : JSON.stringify(parsed.data, null, 2) + \"\\n\")\n console.log(chalk.green(` ✓ ${parsed.data.id} → ${dest}`))\n\n if (opts.reload === false) {\n console.log(chalk.dim(` --no-reload: skipped daemon hot-reload; restart manually if running.`))\n return\n }\n const url = `${String(opts.daemon).replace(/\\/$/, \"\")}/reload`\n try {\n const res = await fetch(url, { method: \"POST\" })\n if (res.ok) {\n console.log(chalk.dim(` ✓ daemon reloaded`))\n } else {\n console.log(chalk.dim(` daemon /reload returned ${res.status} — restart manually if needed`))\n }\n } catch {\n console.log(chalk.dim(` daemon not reachable at ${opts.daemon} — start it or restart to pick up the new workflow`))\n }\n })\n\nworkflow\n .command(\"runs [id]\")\n .description(\"list recent runs (optionally filtered to a single workflow)\")\n .option(\"--limit <n>\", \"max runs to show\", \"20\")\n .option(\"--node <id>\", \"home-node id for this daemon (defaults to WF_NODE_ID env or \\\"local\\\")\")\n .action((id: string | undefined, opts) => {\n const nodeId = opts.node || process.env.WF_NODE_ID || \"local\"\n const runs = new RunStore({ nodeId }).list({ workflowId: id, limit: Number(opts.limit) })\n if (!runs.length) {\n console.log(chalk.dim(` no runs yet${id ? ` for \"${id}\"` : \"\"}.`))\n return\n }\n console.log()\n for (const r of runs) {\n const last = r.history.at(-1)\n const nextLabel = r.pending[0] ?? (r.status === \"completed\" ? \"∅\" : \"—\")\n const stateColor = r.status === \"running\" ? chalk.cyan : r.status === \"failed\" ? chalk.red : chalk.green\n console.log(` ${chalk.dim(r.id.slice(0, 8))} ${chalk.bold(r.workflowId)} ${stateColor(nextLabel)} ${chalk.dim(r.status)}`)\n console.log(` ${chalk.dim(\"entity: \")} ${r.entityRef.backend}:${r.entityRef.id}`)\n console.log(` ${chalk.dim(\"home: \")} ${r.homeNode}`)\n console.log(` ${chalk.dim(\"updated: \")} ${r.updatedAt}`)\n if (last) console.log(` ${chalk.dim(\"last: \")} ${last.nodeId} (${last.status})`)\n }\n console.log()\n console.log(chalk.dim(` ${runs.length} run${runs.length === 1 ? \"\" : \"s\"}.`))\n })\n\nworkflow\n .command(\"draft-from-task <taskId>\")\n .description(\"generate a reviewable workflow draft from a successful task trace\")\n .option(\"--path <path>\", \"SQLite db path\", \".agentx/db.sqlite\")\n .option(\"--format <fmt>\", \"yaml (default) or json\", \"yaml\")\n .option(\"--commit\", \"write to .agentx/workflows/_drafts\", false)\n .option(\"--print\", \"print the generated draft\", false)\n .option(\"--allow-failed\", \"allow generating from non-ok traces\", false)\n .option(\"--model <model>\", \"direct Anthropic API path (e.g. claude-sonnet-4-6) — needs ANTHROPIC_API_KEY in daemon env\")\n .option(\"--via <agentId>\", \"route the LLM call through an agent (e.g. coo-agent) — uses the agent's own session, no raw API key needed\")\n .option(\"--daemon <url>\", \"daemon API base URL\", \"http://127.0.0.1:18800\")\n .action(async (taskId: string, opts) => {\n const db = openTraceDb(opts.path)\n const trace = getTrace(db, taskId)\n if (!trace) {\n console.log(chalk.red(` task trace not found: ${taskId}`))\n process.exit(1)\n }\n if (trace.task.status !== \"ok\" && !opts.allowFailed) {\n console.log(chalk.red(` task ${taskId} status=${trace.task.status}; pass --allow-failed to draft anyway`))\n process.exit(1)\n }\n const result = await architectOrBuildDraft(trace.task, trace.steps, {\n model: opts.model,\n viaAgent: opts.via,\n daemonUrl: opts.daemon,\n log: (m) => console.log(chalk.dim(` ${m}`)),\n })\n const workflow = result.workflow\n if (result.usedLlm) {\n console.log(chalk.dim(` ✦ LLM-architected via ${result.via || opts.model || opts.via}`))\n } else if (opts.model || opts.via) {\n console.log(chalk.yellow(` ⚠ LLM architect failed, used deterministic fallback`))\n }\n const issues = validateWorkflowDraft(workflow)\n if (issues.length) {\n console.log(chalk.red(` generated draft failed validation:`))\n for (const issue of issues) console.log(` ${issue}`)\n process.exit(1)\n }\n const format = String(opts.format).toLowerCase() === \"json\" ? \"json\" : \"yaml\"\n if (opts.commit) {\n const path = writeWorkflowDraft(workflow, { format })\n console.log(chalk.green(` ✓ draft written: ${path}`))\n }\n if (opts.print || !opts.commit) printWorkflowDraft(workflow, format)\n })\n\nworkflow\n .command(\"absorb\")\n .description(\"distill executable DAG drafts from traces (advanced — for user-facing pattern mining see `agentx procedure extract`)\")\n .option(\"--path <path>\", \"SQLite db path\", \".agentx/db.sqlite\")\n .option(\"--since <duration>\", \"trace window, e.g. 24h, 7d, or ms epoch\", \"24h\")\n .option(\"--agent <id>\", \"only absorb traces for one agent\")\n .option(\"--min-cluster-size <n>\", \"minimum similar traces per draft\", \"3\")\n .option(\"--min-message-length <n>\", \"minimum messagePreview chars to consider a trace (default 30)\", \"30\")\n .option(\"--max <n>\", \"maximum drafts to generate\", \"10\")\n .option(\"--dry-run\", \"preview candidates without writing\", false)\n .option(\"--commit\", \"write generated drafts\", false)\n .option(\"--model <model>\", \"direct Anthropic API architect (e.g. claude-sonnet-4-6) — needs ANTHROPIC_API_KEY\")\n .option(\"--via <agentId>\", \"route the LLM call through an agent (e.g. coo-agent) — uses the agent's own session\")\n .option(\"--daemon <url>\", \"daemon API base URL for --via\", \"http://127.0.0.1:18800\")\n .action(async (opts) => {\n const db = openTraceDb(opts.path)\n const traces = loadSuccessfulTraces(db, {\n since: parseSince(opts.since),\n agentId: opts.agent,\n limit: 1000,\n minMessageLength: Number(opts.minMessageLength) || 30,\n })\n if (traces.length === 0) {\n console.log(chalk.dim(\" no successful free-form traces found in window\"))\n return\n }\n const clusters = clusterWorkflowCandidates(traces, {\n minClusterSize: Number(opts.minClusterSize) || 3,\n max: Number(opts.max) || 10,\n })\n if (clusters.length === 0) {\n console.log(chalk.dim(` ${traces.length} trace(s), but no cluster met min size ${opts.minClusterSize}`))\n return\n }\n const drafts = await buildDraftsFromClustersAsync(db, clusters, {\n model: opts.model,\n viaAgent: opts.via,\n daemonUrl: opts.daemon,\n log: (m) => console.log(chalk.dim(` ${m}`)),\n })\n for (const draft of drafts) {\n const tag = draft.usedLlm ? chalk.magenta(\"✦ llm\") : chalk.dim(\"det.\")\n console.log(` ${chalk.cyan(draft.id)} ${chalk.bold(`${draft.sourceTaskIds.length} traces`)} confidence=${draft.confidence.toFixed(2)} ${tag}`)\n console.log(chalk.dim(` ${draft.reason}`))\n const issues = validateWorkflowDraft(draft.workflow)\n if (issues.length) {\n console.log(chalk.red(` validation failed: ${issues.join(\"; \")}`))\n continue\n }\n // Reject drafts with no actual work (e.g. trigger → end shapes from\n // notification-only traces). Operators can still hand-write minimal\n // workflows; this gates the auto-absorb path only.\n if (!isMeaningfulDraft(draft.workflow)) {\n console.log(chalk.yellow(` skipped: draft has no agent/action/branch step (${draft.workflow.nodes.length} nodes — likely a notification trace)`))\n continue\n }\n if (opts.commit && !opts.dryRun) {\n try {\n const path = writeWorkflowDraft(draft.workflow, { format: \"yaml\" })\n console.log(chalk.green(` written: ${path}`))\n } catch (e: any) {\n console.log(chalk.yellow(` skipped: ${e.message}`))\n }\n }\n }\n if (!opts.commit || opts.dryRun) console.log(chalk.dim(\" dry run only; pass --commit to write drafts\"))\n })\n\nworkflow\n .command(\"drafts\")\n .description(\"list workflow drafts pending review\")\n .option(\"--json\", \"emit JSON\", false)\n .action((opts) => {\n const drafts = listWorkflowDrafts()\n if (opts.json) {\n console.log(JSON.stringify(drafts.map((d) => ({ id: d.id, path: d.path, workflow: d.workflow })), null, 2))\n return\n }\n if (drafts.length === 0) {\n console.log(chalk.dim(\" no workflow drafts\"))\n return\n }\n for (const d of drafts) {\n const wf = d.workflow\n console.log(` ${chalk.cyan(d.id)} ${chalk.bold(wf.title)} ${chalk.dim(`status=${wf.status} state=${wf.state}`)}`)\n if (wf.sourceTaskIds.length) console.log(chalk.dim(` sources: ${wf.sourceTaskIds.slice(0, 5).join(\", \")}${wf.sourceTaskIds.length > 5 ? \"...\" : \"\"}`))\n if (wf.confidence != null) console.log(chalk.dim(` confidence: ${wf.confidence.toFixed(2)} path: ${d.path}`))\n }\n })\n\nworkflow\n .command(\"promote <draftId>\")\n .description(\"promote a workflow draft into the active workflow store\")\n .option(\"--replace\", \"replace an existing workflow file with the same id\", false)\n .option(\"--format <fmt>\", \"yaml (default) or json\", \"yaml\")\n .option(\"--daemon <url>\", \"daemon API base URL\", \"http://127.0.0.1:18800\")\n .action(async (draftId: string, opts) => {\n try {\n const format = String(opts.format).toLowerCase() === \"json\" ? \"json\" : \"yaml\"\n const result = promoteWorkflowDraft(draftId, { replace: !!opts.replace, format })\n console.log(chalk.green(` ✓ promoted ${draftId}`))\n console.log(chalk.dim(` ${result.from} -> ${result.to}`))\n try { await fetch(`${String(opts.daemon).replace(/\\/$/, \"\")}/reload`, { method: \"POST\" }) } catch { /* daemon optional */ }\n } catch (e: any) {\n console.log(chalk.red(` ${e.message}`))\n process.exit(1)\n }\n })\n\nworkflow\n .command(\"reject <draftId>\")\n .description(\"archive a workflow draft without activating it\")\n .action((draftId: string) => {\n try {\n const dest = rejectWorkflowDraft(draftId)\n console.log(chalk.green(` ✓ rejected ${draftId}`))\n console.log(chalk.dim(` archived: ${dest}`))\n } catch (e: any) {\n console.log(chalk.red(` ${e.message}`))\n process.exit(1)\n }\n })\n\nworkflow\n .command(\"replay-task <taskId>\")\n .description(\"replay a task through its generated workflow draft or an ad-hoc draft\")\n .option(\"--path <path>\", \"SQLite db path\", \".agentx/db.sqlite\")\n .option(\"--workflow <id>\", \"workflow or draft id to replay instead of auto-discovery\")\n .option(\"--input <json>\", \"override workflow trigger input\")\n .option(\"--agent <id>\", \"override agent id for generated draft agent nodes\")\n .option(\"--model <id>\", \"override model id for generated draft agent nodes\")\n .option(\"--timeout <minutes>\", \"override timeout hint in trigger input\")\n .option(\"--validate-only\", \"validate the replay workflow without running it\", false)\n .option(\"--dry-run\", \"print the replay workflow and input without running\", false)\n .option(\"--watch\", \"tail workflow traces while the replay runs\", false)\n .option(\"--daemon <url>\", \"daemon API base URL\", \"http://127.0.0.1:18800\")\n .action(async (taskId: string, opts) => {\n const db = openTraceDb(opts.path)\n const trace = getTrace(db, taskId)\n if (!trace) {\n console.log(chalk.red(` task trace not found: ${taskId}`))\n process.exit(1)\n }\n\n let workflowDef = opts.workflow ? getWorkflowDraft(opts.workflow)?.workflow : undefined\n if (!workflowDef && opts.workflow) {\n workflowDef = new WorkflowStore().get(opts.workflow) || undefined\n }\n if (!workflowDef) {\n workflowDef = listWorkflowDrafts().find((d) => d.workflow.sourceTaskIds.includes(taskId))?.workflow\n }\n if (!workflowDef) workflowDef = buildWorkflowDraftFromTrace(trace.task, trace.steps, { id: `_adhoc-replay-${taskId.toLowerCase().slice(0, 8)}` })\n\n if (opts.agent || opts.model) {\n workflowDef = workflowSchema.parse({\n ...workflowDef,\n nodes: workflowDef.nodes.map((n) => n.type === \"agent\"\n ? {\n ...n,\n config: {\n ...n.config,\n ...(opts.agent ? { agentId: String(opts.agent) } : {}),\n ...(opts.model ? { model: String(opts.model) } : {}),\n },\n }\n : n),\n })\n }\n\n const issues = validateWorkflowDraft(workflowDef)\n if (issues.length) {\n console.log(chalk.red(` replay workflow failed validation:`))\n for (const issue of issues) console.log(` ${issue}`)\n process.exit(1)\n }\n\n let payload: Record<string, unknown> = {\n input: {\n message: trace.task.messagePreview || \"\",\n taskId,\n originalAgentId: trace.task.agentId,\n timeoutMinutes: opts.timeout ? Number(opts.timeout) : undefined,\n },\n }\n if (opts.input) {\n try { payload = JSON.parse(opts.input) } catch { console.log(chalk.red(\" --input must be valid JSON\")); process.exit(1) }\n }\n\n if (opts.validateOnly || opts.dryRun) {\n printWorkflowDraft(workflowDef, \"yaml\")\n console.log(chalk.dim(\" input:\"))\n console.log(JSON.stringify(payload, null, 2))\n return\n }\n\n const store = new WorkflowStore()\n mkdirSync(store.baseDir, { recursive: true })\n const replayId = workflowDef.id.startsWith(\"_adhoc-\") ? workflowDef.id : `_adhoc-replay-${workflowDef.id}-${Date.now().toString(36)}`\n const replayWorkflow = workflowSchema.parse({ ...workflowDef, id: replayId, state: \"active\", status: \"review\" })\n const dest = resolve(store.baseDir, `${replayId}.yaml`)\n writeFileSync(dest, renderWorkflowYaml(replayWorkflow))\n const base = String(opts.daemon).replace(/\\/$/, \"\")\n try { await fetch(`${base}/reload`, { method: \"POST\" }) } catch { /* daemon may not support reload */ }\n const res = await fetch(`${base}/workflows/${encodeURIComponent(replayId)}/run`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ payload, force: true }),\n })\n if (!res.ok) {\n console.log(chalk.red(` replay failed (${res.status}): ${(await res.text()).slice(0, 300)}`))\n process.exit(1)\n }\n const body = await res.json() as { runId?: string }\n console.log(chalk.green(` ✓ replay started: ${body.runId || \"(unknown run)\"}`))\n console.log(chalk.dim(` workflow: ${replayId}`))\n const originalSummary = traceSummary(trace.steps)\n console.log(chalk.dim(` original: ${originalSummary.totalTokens || 0}t ${originalSummary.durationMs || 0}ms model=${originalSummary.models.join(\",\") || trace.task.model || \"—\"}`))\n if (body.runId) {\n const replayTraces = await tailTraces({ daemonUrl: base, runId: body.runId, quiet: !opts.watch })\n printReplayComparison(originalSummary, traceSummary(replayTraces))\n }\n })\n\nworkflow\n .command(\"run <id-or-file>\")\n .description(\"manually trigger a workflow by id, or load + register + run a YAML/JSON file\")\n .option(\"--input <json>\", \"JSON object merged into the trigger event payload\")\n .option(\"--force\", \"fire even if the trigger isn't `trigger.manual` (uses a synthesized event)\", false)\n .option(\"--watch\", \"tail per-step traces while the run executes\", false)\n .option(\"--daemon <url>\", \"daemon API base URL\", \"http://127.0.0.1:18800\")\n .action(async (idOrFile: string, opts) => {\n let payload: unknown = {}\n if (opts.input) {\n try { payload = JSON.parse(opts.input) } catch { console.log(chalk.red(` --input must be valid JSON`)); process.exit(1) }\n }\n\n // Two paths:\n // (1) `idOrFile` resolves to a real file → register-then-run it as a\n // one-shot. Useful for iterating on an unsaved YAML without\n // committing to .agentx/workflows/. The synthesized id collides\n // guard: prefix `_adhoc-` so we don't shadow stored workflows\n // unless the file's id already starts with that prefix.\n // (2) `idOrFile` is a workflow id → fire by id (existing behavior).\n let id = idOrFile\n const path = resolve(process.cwd(), idOrFile)\n const isFile = (idOrFile.includes(\"/\") || /\\.(ya?ml|json)$/i.test(idOrFile)) && existsSync(path)\n if (isFile) {\n const text = readFileSync(path, \"utf-8\")\n const isYaml = /\\.(ya?ml)$/i.test(idOrFile)\n let raw: unknown\n try {\n raw = isYaml ? parseYamlWorkflow(text, { filePath: idOrFile }) : JSON.parse(text)\n } catch (e: any) {\n const msg = e instanceof WorkflowYamlError ? e.message : `parse error: ${e?.message ?? e}`\n console.log(chalk.red(` ${msg}`))\n process.exit(1)\n }\n const parsed = workflowSchema.safeParse(raw)\n if (!parsed.success) {\n console.log(chalk.red(` ✗ schema:`))\n for (const i of parsed.error.issues) console.log(` ${i.path.join(\".\") || \"<root>\"}: ${i.message}`)\n process.exit(1)\n }\n const lintIssues = lintWorkflow(parsed.data)\n if (lintIssues.length) {\n console.log(chalk.red(` ✗ lint:`))\n for (const l of lintIssues) console.log(` ${l}`)\n process.exit(1)\n }\n // Write to the store under an _adhoc-prefixed id so the daemon's\n // fs.watch picks it up. We re-use the existing id when it already\n // starts with `_adhoc-` so repeated runs against the same file\n // don't accumulate copies.\n const store = new WorkflowStore()\n const adhocId = parsed.data.id.startsWith(\"_adhoc-\")\n ? parsed.data.id\n : `_adhoc-${parsed.data.id}-${Date.now().toString(36)}`\n const ext = isYaml ? \"yaml\" : \"json\"\n const dest = resolve(store.baseDir, `${adhocId}.${ext}`)\n const written = isYaml\n ? text.replace(new RegExp(`^id:\\\\s*${parsed.data.id}\\\\b`, \"m\"), `id: ${adhocId}`)\n : JSON.stringify({ ...parsed.data, id: adhocId }, null, 2) + \"\\n\"\n writeFileSync(dest, written)\n id = adhocId\n console.log(chalk.dim(` ad-hoc registered as \"${adhocId}\" → ${dest}`))\n // Hot-reload so the dispatcher knows about it before we POST.\n try { await fetch(`${String(opts.daemon).replace(/\\/$/, \"\")}/reload`, { method: \"POST\" }) } catch { /* daemon may not be running yet */ }\n }\n\n const url = `${String(opts.daemon).replace(/\\/$/, \"\")}/workflows/${encodeURIComponent(id)}/run`\n let runId: string | undefined\n try {\n const res = await fetch(url, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ payload, force: !!opts.force }),\n })\n if (!res.ok) {\n const text = await res.text()\n console.log(chalk.red(` run failed (${res.status}): ${text.slice(0, 300)}`))\n if (res.status === 409) console.log(chalk.dim(` hint: pass --force to fire non-manual workflows for testing`))\n process.exit(1)\n }\n const body = await res.json() as { runId?: string; source?: string; force?: boolean }\n runId = body.runId\n console.log(chalk.green(` ✓ run started: ${runId || \"(unknown id)\"}${body.force ? chalk.dim(` (forced, source=${body.source})`) : \"\"}`))\n } catch (e: any) {\n console.log(chalk.red(` request to daemon failed: ${e.message}`))\n process.exit(1)\n }\n\n if (opts.watch && runId) {\n await tailTraces({ daemonUrl: String(opts.daemon).replace(/\\/$/, \"\"), runId })\n }\n })\n\n/** Poll /traces?workflowRunId=<id> every 500ms until the run is no\n * longer \"running\", printing each new step row as it appears. The\n * trace store keys per node, so we only need to track which nodeIds\n * we've already printed. */\nasync function tailTraces(args: { daemonUrl: string; runId: string; quiet?: boolean }): Promise<any[]> {\n const seen = new Set<string>()\n const collected = new Map<string, any>()\n const startedAt = Date.now()\n // Hard cap so a stuck run doesn't pin the terminal forever.\n const maxMs = 15 * 60 * 1000\n\n while (Date.now() - startedAt < maxMs) {\n let traces: any[] = []\n try {\n const r = await fetch(`${args.daemonUrl}/traces?workflowRunId=${encodeURIComponent(args.runId)}&limit=200`)\n if (r.ok) {\n const body = await r.json() as { traces?: any[] }\n traces = body.traces || []\n }\n } catch { /* transient — try again next tick */ }\n\n for (const t of traces) {\n if (!t.taskId || seen.has(t.taskId)) continue\n seen.add(t.taskId)\n collected.set(t.taskId, t)\n if (args.quiet) continue\n const status = t.status || \"running\"\n const color = status === \"ok\" ? chalk.green : status === \"error\" ? chalk.red : chalk.cyan\n const tokens = t.totalTokens != null ? chalk.dim(`${t.totalTokens}t`) : \"\"\n const dur = t.durationMs != null ? chalk.dim(`${t.durationMs}ms`) : \"\"\n console.log(` ${color(status.padEnd(5))} ${chalk.bold(t.nodeId || t.label || \"(node)\")} ${tokens} ${dur}`)\n if (t.error) console.log(` ${chalk.red(String(t.error).slice(0, 200))}`)\n }\n\n // Look up the run's status to know when to stop. The run isn't in\n // /traces, so we read it from the run-store's HTTP surface.\n try {\n const r = await fetch(`${args.daemonUrl}/api/workflows/runs/${encodeURIComponent(args.runId)}`)\n if (r.ok) {\n const body = await r.json() as { run?: { status?: string } }\n const run = body.run\n if (run && run.status && run.status !== \"running\") {\n if (!args.quiet) {\n console.log()\n console.log(` ${chalk.dim(\"run finished:\")} ${run.status}`)\n console.log(chalk.dim(` full traces: ${args.daemonUrl}/traces?workflowRunId=${args.runId}`))\n }\n return Array.from(collected.values())\n }\n }\n } catch { /* try again next tick */ }\n\n await new Promise((r) => setTimeout(r, 500))\n }\n if (!args.quiet) console.log(chalk.yellow(` watch timed out after 15min. Run is still active — check /traces`))\n return Array.from(collected.values())\n}\n\nworkflow\n .command(\"trace <id>\")\n .description(\"pretty-print a task's execution trace (taskId or runId)\")\n .option(\"--daemon <url>\", \"daemon API base URL\", \"http://127.0.0.1:18800\")\n .option(\"--json\", \"raw JSON output\", false)\n .action(async (id: string, opts) => {\n const base = String(opts.daemon).replace(/\\/$/, \"\")\n\n // Try as a taskId first (single-step trace), then fall back to\n // workflowRunId (multi-step listing).\n try {\n const single = await fetch(`${base}/traces/${encodeURIComponent(id)}`)\n if (single.ok) {\n const rec = await single.json() as any\n if (opts.json) { console.log(JSON.stringify(rec, null, 2)); return }\n printTrace(rec)\n return\n }\n } catch { /* fall through to runId */ }\n\n let body: { traces?: any[] }\n try {\n const r = await fetch(`${base}/traces?workflowRunId=${encodeURIComponent(id)}&limit=200`)\n if (!r.ok) {\n console.log(chalk.red(` /traces returned ${r.status}`))\n process.exit(1)\n }\n body = await r.json() as { traces?: any[] }\n } catch (e: any) {\n console.log(chalk.red(` daemon request failed: ${e.message}`))\n process.exit(1)\n }\n const traces = body.traces || []\n if (traces.length === 0) {\n console.log(chalk.yellow(` no traces for \"${id}\"`))\n console.log(chalk.dim(` (sqlite must be opened — check 'agentx doctor' if the daemon logged 'sqlite: not opened')`))\n return\n }\n if (opts.json) { console.log(JSON.stringify(traces, null, 2)); return }\n console.log()\n console.log(chalk.bold(` ${traces.length} step${traces.length === 1 ? \"\" : \"s\"} for run ${id}:`))\n console.log()\n for (const t of traces) printTrace(t)\n })\n\nfunction printTrace(t: any): void {\n const status = t.status || \"ok\"\n const color = status === \"ok\" ? chalk.green : status === \"error\" ? chalk.red : chalk.cyan\n const tokens = t.totalTokens != null ? `${t.totalTokens}t` : \"—\"\n const dur = t.durationMs != null ? `${t.durationMs}ms` : \"—\"\n const model = t.model || \"—\"\n console.log(` ${color(status.padEnd(5))} ${chalk.bold(String(t.nodeId || t.label || \"(node)\"))}`)\n console.log(` ${chalk.dim(\"taskId:\")} ${t.taskId || \"—\"}`)\n console.log(` ${chalk.dim(\"model:\")} ${model}`)\n console.log(` ${chalk.dim(\"tokens:\")} ${tokens} ${chalk.dim(\"duration:\")} ${dur}`)\n if (t.error) console.log(` ${chalk.dim(\"error:\")} ${chalk.red(String(t.error).slice(0, 300))}`)\n console.log()\n}\n\nworkflow\n .command(\"pause <runId>\")\n .description(\"pause an active run\")\n .option(\"--node <id>\", \"home-node id\", )\n .action((runId: string, opts) => {\n const nodeId = opts.node || process.env.WF_NODE_ID || \"local\"\n const runs = new RunStore({ nodeId })\n const updated = runs.setStatus(runId, \"paused\")\n if (!updated) { console.log(chalk.yellow(` no such run: ${runId}`)); process.exit(1) }\n console.log(chalk.green(` ✓ paused ${runId}`))\n })\n\nworkflow\n .command(\"resume <runId>\")\n .description(\"resume a paused run\")\n .option(\"--node <id>\", \"home-node id\")\n .action((runId: string, opts) => {\n const nodeId = opts.node || process.env.WF_NODE_ID || \"local\"\n const runs = new RunStore({ nodeId })\n const updated = runs.setStatus(runId, \"running\")\n if (!updated) { console.log(chalk.yellow(` no such run: ${runId}`)); process.exit(1) }\n console.log(chalk.green(` ✓ resumed ${runId}`))\n })\n\nworkflow\n .command(\"cancel <runId>\")\n .description(\"cancel an active run\")\n .option(\"--node <id>\", \"home-node id\")\n .action((runId: string, opts) => {\n const nodeId = opts.node || process.env.WF_NODE_ID || \"local\"\n const runs = new RunStore({ nodeId })\n const updated = runs.setStatus(runId, \"canceled\")\n if (!updated) { console.log(chalk.yellow(` no such run: ${runId}`)); process.exit(1) }\n console.log(chalk.green(` ✓ canceled ${runId}`))\n })\n","// Workflow templates — bundled as string exports so they survive\n// tsup's tree-shaking. Each template is the raw YAML; the CLI loads\n// it, substitutes the placeholders (__ID__, __TITLE__, __AGENT__,\n// __REVIEWER__), and writes the result into .agentx/workflows/.\n//\n// Why inline as a TS module instead of copying the .yaml files into\n// dist/? Two reasons: (1) tsup doesn't copy non-code assets, and\n// adding a custom copy step risks drift between dev and prod; (2) the\n// templates are small enough that inlining costs ~5KB in the bundle\n// — well below the threshold worth a separate file pipeline.\n//\n// To edit: change the .yaml file in this directory, then re-run\n// `pnpm tsx scripts/sync-templates.ts` (or just paste the new\n// content into the matching export below). The .yaml files are the\n// source of truth; this index.ts is a hand-mirror.\n\nimport { readFileSync } from \"fs\"\nimport { resolve, dirname } from \"path\"\nimport { fileURLToPath } from \"url\"\n\nexport type TemplateName =\n | \"linear\"\n | \"branching\"\n | \"extract\"\n | \"retry\"\n\nexport interface TemplateMeta {\n name: TemplateName\n title: string\n description: string\n}\n\nexport const TEMPLATES: TemplateMeta[] = [\n { name: \"linear\", title: \"Linear\", description: \"Trigger → Agent → End. Smallest workflow that runs.\" },\n { name: \"branching\", title: \"Branching\", description: \"Classify, then route on the result via a branch node.\" },\n { name: \"extract\", title: \"Structured extraction\", description: \"Pull typed fields from free-form text via extract.structured.\" },\n { name: \"retry\", title: \"Retry + fallback\", description: \"Per-node retry policy with a branch fallback path.\" },\n]\n\n/** Read a template's raw YAML. Tries a small set of candidate paths\n * so the same code works in (a) dev, where templates sit next to\n * this .ts file, and (b) the bundled CLI, where tsup's onSuccess\n * hook copies them to `dist/workflows/templates/`. After bundling\n * the calling chunk may not live at dist/cli.js, so we fall back\n * to argv[1]-relative + a couple of common parent layouts before\n * giving up. */\nexport function readTemplate(name: TemplateName): string {\n const here = dirname(fileURLToPath(import.meta.url))\n const cliDir = process.argv[1] ? dirname(process.argv[1]) : \"\"\n const candidates = [\n resolve(here, `${name}.yaml`),\n resolve(here, \"workflows/templates\", `${name}.yaml`),\n resolve(here, \"..\", \"workflows/templates\", `${name}.yaml`),\n resolve(here, \"../..\", \"workflows/templates\", `${name}.yaml`),\n cliDir ? resolve(cliDir, \"workflows/templates\", `${name}.yaml`) : \"\",\n cliDir ? resolve(cliDir, \"..\", \"workflows/templates\", `${name}.yaml`) : \"\",\n ].filter(Boolean) as string[]\n for (const path of candidates) {\n try { return readFileSync(path, \"utf-8\") } catch { /* try next */ }\n }\n throw new Error(`workflow template \"${name}\" not found in any of:\\n ${candidates.join(\"\\n \")}`)\n}\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport prompts from \"prompts\"\nimport { readFileSync, existsSync } from \"fs\"\nimport { resolve } from \"path\"\nimport { applyConfigMutation } from \"@/daemon/config-mutator\"\n\n// --- agentx webhook — manage webhook entries from the CLI ---\n//\n// CLI parity with the dashboard's /admin → Webhooks tab. Mutates agentx.json\n// directly through applyConfigMutation, which validates with Zod and signals\n// the running daemon to hot-reload (no restart required).\n//\n// Subcommands:\n// list — print all webhook entries\n// add [id] — interactive add (or use flags)\n// remove <id> — delete a webhook entry\n// enable <id> — enable a webhook\n// disable <id> — disable a webhook\n// triggers set <id> <event> <workflow> — map event-type to workflow id\n// triggers remove <id> <event> — remove a trigger map entry\n// triggers default <id> <workflow> — set default workflow (no event match)\n\nconst VALID_SOURCES = [\"gitlab\", \"github\", \"sentry\", \"stripe\", \"vercel\", \"odoo\", \"hubspot\", \"discord\", \"slack\", \"custom\"] as const\ntype WebhookSource = (typeof VALID_SOURCES)[number]\n\nconst WIRED_SOURCES = new Set<WebhookSource>([\"gitlab\", \"github\", \"sentry\", \"stripe\", \"vercel\", \"odoo\", \"hubspot\"])\n\nconst SOURCE_HINTS: Record<WebhookSource, string> = {\n gitlab: \"GitLab → Settings → Webhooks (tick Push/Issue/Pipeline events)\",\n github: \"GitHub → Repo Settings → Webhooks\",\n sentry: \"Sentry → Project Settings → Alerts → Webhooks\",\n stripe: \"Stripe Dashboard → Developers → Webhooks\",\n vercel: \"Vercel → Project Settings → Webhooks\",\n odoo: \"Odoo → Settings → Technical → Automation → Webhooks (or your installed `webhook` module)\",\n hubspot: \"HubSpot → Settings → Integrations → Private Apps → Webhooks subscription\",\n discord: \"Discord channel → Integrations → Webhooks (inbound-only, no on:* events)\",\n slack: \"Slack Outgoing Webhooks / Events API (inbound-only, no on:* events)\",\n custom: \"Any service that POSTs JSON — Linear, Calendly, Notion, etc. (inbound-only)\",\n}\n\nfunction loadConfig(): any {\n const p = resolve(process.cwd(), \"agentx.json\")\n if (!existsSync(p)) throw new Error(\"No agentx.json found. Run: agentx init\")\n return JSON.parse(readFileSync(p, \"utf-8\"))\n}\n\nfunction statusBadge(w: any): string {\n if (!w.enabled) return chalk.dim(\"disabled\")\n const missingSecret = w.source !== \"custom\" && !w.secretEnv\n if (missingSecret) return chalk.yellow(\"⚠ no signing secret\")\n return chalk.green(\"✓ active\")\n}\n\nfunction printOneJson(w: any): void {\n console.log(JSON.stringify(w, null, 2))\n}\n\nfunction printOneHuman(w: any, daemonUrl?: string): void {\n const url = daemonUrl\n ? `${daemonUrl.replace(/\\/+$/, \"\")}/webhook/${encodeURIComponent(w.agentId)}/${encodeURIComponent(w.source)}`\n : `/webhook/${encodeURIComponent(w.agentId)}/${encodeURIComponent(w.source)}`\n const wired = WIRED_SOURCES.has(w.source) ? chalk.dim(\" · emits on:\" + w.source + \"-* hook events\") : \"\"\n console.log(` ${chalk.cyan(w.id)} ${statusBadge(w)}`)\n console.log(` ${chalk.dim(w.source)} → ${chalk.bold(w.agentId)}${wired}`)\n console.log(` POST ${chalk.dim(url)}`)\n if (w.secretEnv) console.log(` secret: ${chalk.dim(\"$\" + w.secretEnv)}`)\n if (w.description) console.log(` ${chalk.dim(w.description)}`)\n const triggers = w.triggers && typeof w.triggers === \"object\" ? w.triggers : {}\n const triggerKeys = Object.keys(triggers)\n if (triggerKeys.length) {\n console.log(` ${chalk.dim(\"triggers:\")}`)\n for (const k of triggerKeys) console.log(` ${k} → ${triggers[k]}`)\n }\n if (w.defaultWorkflow) {\n console.log(` ${chalk.dim(\"default workflow:\")} ${w.defaultWorkflow}`)\n }\n console.log()\n}\n\nexport const webhook = new Command()\n .name(\"webhook\")\n .description(\"manage webhook entries (gitlab, github, sentry, stripe, vercel, custom)\")\n\n// agentx webhook list\nwebhook\n .command(\"list\")\n .alias(\"ls\")\n .description(\"list webhook entries\")\n .option(\"--json\", \"emit JSON\")\n .action((opts) => {\n const cfg = loadConfig()\n const entries = Array.isArray(cfg.webhooks) ? cfg.webhooks : []\n if (opts.json) {\n console.log(JSON.stringify(entries, null, 2))\n return\n }\n if (!entries.length) {\n console.log(chalk.dim(\"\\n No webhooks registered. Add one with: agentx webhook add\\n\"))\n return\n }\n console.log()\n for (const w of entries) printOneHuman(w)\n })\n\n// agentx webhook add [id]\nwebhook\n .command(\"add [id]\")\n .description(\"register a new webhook entry\")\n .option(\"--source <source>\", `one of: ${VALID_SOURCES.join(\", \")}`)\n .option(\"--agent <agentId>\", \"agent that receives the webhook\")\n .option(\"--secret-env <name>\", \"env var holding the signing secret (recommended)\")\n .option(\"--description <text>\", \"free-text description\")\n .option(\"--node <peer>\", \"forward to a mesh peer (skips local agent check; validates against mesh.peers)\")\n .option(\"--no-prompt\", \"fail instead of prompting for missing values\")\n .action(async (idArg, opts) => {\n const cfg = loadConfig()\n const knownAgents = Object.keys(cfg.agents || {})\n const meshPeers: string[] = (cfg.mesh?.peers || []).map((p: any) => p.name).filter(Boolean)\n const node = String(opts.node || \"\").trim()\n if (!knownAgents.length && !node) throw new Error(\"No local agents configured. Add one with: agentx agent add — or use --node <peer> to forward to a mesh peer.\")\n\n let id = (idArg || \"\").trim()\n let source = String(opts.source || \"\").trim() as WebhookSource\n let agentId = String(opts.agent || \"\").trim()\n let secretEnv = String(opts.secretEnv || \"\").trim()\n let description = String(opts.description || \"\").trim()\n\n const interactive = opts.prompt !== false\n\n if (!id && interactive) {\n const r = await prompts({\n type: \"text\",\n name: \"id\",\n message: \"Webhook id (lowercase, e.g. mtgl-gitlab)\",\n validate: (v: string) => /^[a-z0-9][a-z0-9_-]*$/.test(v) || \"Use lowercase letters, digits, -, _\",\n })\n id = (r.id || \"\").trim()\n }\n if (!id) throw new Error(\"Webhook id is required.\")\n if (!/^[a-z0-9][a-z0-9_-]*$/.test(id)) throw new Error(\"Webhook id must be lowercase (letters, digits, -, _).\")\n\n if (!source && interactive) {\n const r = await prompts({\n type: \"select\",\n name: \"source\",\n message: \"Source\",\n choices: VALID_SOURCES.map((s) => ({\n title: `${s}${WIRED_SOURCES.has(s) ? \" ✓ wired\" : \"\"}`,\n value: s,\n description: SOURCE_HINTS[s],\n })),\n })\n source = r.source\n }\n if (!VALID_SOURCES.includes(source)) {\n throw new Error(`Source must be one of: ${VALID_SOURCES.join(\", \")}`)\n }\n\n if (!agentId && interactive) {\n // When --node is set, ask for a free-text agent id (the agent lives\n // on the remote peer; we don't have its definition locally).\n if (node) {\n const r = await prompts({\n type: \"text\",\n name: \"agentId\",\n message: `Agent on remote peer \"${node}\"`,\n })\n agentId = (r.agentId || \"\").trim()\n } else {\n const r = await prompts({\n type: \"select\",\n name: \"agentId\",\n message: \"Agent\",\n choices: knownAgents.map((a) => ({ title: a, value: a })),\n })\n agentId = r.agentId\n }\n }\n if (!agentId) throw new Error(\"Agent is required.\")\n if (node) {\n if (!meshPeers.includes(node)) {\n throw new Error(`Mesh peer \"${node}\" not found in mesh.peers. Add the peer first or omit --node.`)\n }\n } else if (!cfg.agents?.[agentId]) {\n throw new Error(`Unknown agent \"${agentId}\". Add it locally, or use --node <peer> to forward to a mesh peer.`)\n }\n\n if (!secretEnv && interactive && source !== \"custom\") {\n const r = await prompts({\n type: \"text\",\n name: \"secretEnv\",\n message: `Signing secret env-var (recommended for ${source})`,\n initial: `${source.toUpperCase()}_WEBHOOK_SECRET`,\n })\n secretEnv = (r.secretEnv || \"\").trim()\n }\n\n if (!description && interactive) {\n const r = await prompts({ type: \"text\", name: \"description\", message: \"Description (optional)\" })\n description = (r.description || \"\").trim()\n }\n\n const result = await applyConfigMutation((c: any) => {\n c.webhooks = Array.isArray(c.webhooks) ? c.webhooks : []\n if (c.webhooks.find((w: any) => w.id === id)) {\n throw new Error(`Webhook \"${id}\" already exists.`)\n }\n const entry: any = { id, source, agentId, enabled: true }\n if (secretEnv) entry.secretEnv = secretEnv\n if (description) entry.description = description\n if (node) entry.node = node\n c.webhooks.push(entry)\n })\n if (!result.success) throw new Error(result.error)\n\n console.log(chalk.green(`✓ added webhook \"${id}\" (${source} → ${agentId}${node ? ` @ ${node}` : \"\"})`))\n if (result.reloaded) console.log(chalk.dim(\" daemon hot-reloaded\"))\n if (!secretEnv && source !== \"custom\") {\n console.log(chalk.yellow(` ⚠ no signing secret set — payloads will be accepted unsigned. Add one with --secret-env`))\n }\n })\n\n// agentx webhook remove <id>\nwebhook\n .command(\"remove <id>\")\n .alias(\"rm\")\n .description(\"delete a webhook entry\")\n .option(\"--yes\", \"skip confirmation\")\n .action(async (id, opts) => {\n if (!opts.yes) {\n const r = await prompts({ type: \"confirm\", name: \"ok\", message: `Delete webhook \"${id}\"?`, initial: false })\n if (!r.ok) return\n }\n const result = await applyConfigMutation((c: any) => {\n const before = (c.webhooks || []).length\n c.webhooks = (c.webhooks || []).filter((w: any) => w.id !== id)\n if (c.webhooks.length === before) throw new Error(`Webhook \"${id}\" not found.`)\n })\n if (!result.success) throw new Error(result.error)\n console.log(chalk.green(`✓ removed webhook \"${id}\"`))\n })\n\n// agentx webhook enable <id> / disable <id>\nfunction toggleEnabled(enabled: boolean) {\n return async (id: string) => {\n const result = await applyConfigMutation((c: any) => {\n const w = (c.webhooks || []).find((x: any) => x.id === id)\n if (!w) throw new Error(`Webhook \"${id}\" not found.`)\n w.enabled = enabled\n })\n if (!result.success) throw new Error(result.error)\n console.log(chalk.green(`✓ ${enabled ? \"enabled\" : \"disabled\"} webhook \"${id}\"`))\n }\n}\n\nwebhook.command(\"enable <id>\").description(\"enable a webhook entry\").action(toggleEnabled(true))\nwebhook.command(\"disable <id>\").description(\"disable a webhook entry\").action(toggleEnabled(false))\n\n// agentx webhook triggers ...\nconst triggers = new Command()\n .name(\"triggers\")\n .description(\"manage event-type → workflow mappings on a webhook\")\n\ntriggers\n .command(\"set <id> <eventType> <workflowId>\")\n .description(\"map an event-type to a workflow id\")\n .action(async (id: string, eventType: string, workflowId: string) => {\n const result = await applyConfigMutation((c: any) => {\n const w = (c.webhooks || []).find((x: any) => x.id === id)\n if (!w) throw new Error(`Webhook \"${id}\" not found.`)\n w.triggers = w.triggers && typeof w.triggers === \"object\" ? w.triggers : {}\n w.triggers[eventType] = workflowId\n })\n if (!result.success) throw new Error(result.error)\n console.log(chalk.green(`✓ ${id}: ${eventType} → ${workflowId}`))\n })\n\ntriggers\n .command(\"remove <id> <eventType>\")\n .alias(\"rm\")\n .description(\"remove an event-type → workflow mapping\")\n .action(async (id: string, eventType: string) => {\n const result = await applyConfigMutation((c: any) => {\n const w = (c.webhooks || []).find((x: any) => x.id === id)\n if (!w) throw new Error(`Webhook \"${id}\" not found.`)\n if (w.triggers && typeof w.triggers === \"object\") delete w.triggers[eventType]\n })\n if (!result.success) throw new Error(result.error)\n console.log(chalk.green(`✓ removed trigger ${eventType} from \"${id}\"`))\n })\n\ntriggers\n .command(\"default <id> <workflowId>\")\n .description(\"set the default workflow when no event-type matches (use '-' to clear)\")\n .action(async (id: string, workflowId: string) => {\n const clear = workflowId === \"-\" || workflowId === \"\"\n const result = await applyConfigMutation((c: any) => {\n const w = (c.webhooks || []).find((x: any) => x.id === id)\n if (!w) throw new Error(`Webhook \"${id}\" not found.`)\n if (clear) delete w.defaultWorkflow\n else w.defaultWorkflow = workflowId\n })\n if (!result.success) throw new Error(result.error)\n console.log(chalk.green(`✓ ${id}: defaultWorkflow ${clear ? \"cleared\" : `→ ${workflowId}`}`))\n })\n\nwebhook.addCommand(triggers)\n\n// agentx webhook sources — list known sources with hints\nwebhook\n .command(\"sources\")\n .description(\"list known webhook source types\")\n .option(\"--json\", \"emit JSON\")\n .action((opts) => {\n const list = VALID_SOURCES.map((s) => ({\n source: s,\n wired: WIRED_SOURCES.has(s),\n hint: SOURCE_HINTS[s],\n }))\n if (opts.json) {\n console.log(JSON.stringify(list, null, 2))\n return\n }\n console.log()\n for (const item of list) {\n const tag = item.wired ? chalk.green(\"✓ wired\") : chalk.dim(\"inbound-only\")\n console.log(` ${chalk.cyan(item.source.padEnd(8))} ${tag} ${chalk.dim(item.hint)}`)\n }\n console.log()\n console.log(chalk.dim(\" Wired sources emit on:<source>-* hook events that workflows can subscribe to via trigger.hook.\"))\n console.log(chalk.dim(\" Use 'custom' for any service not in the list (Odoo, HubSpot, Linear, Calendly, etc.).\"))\n console.log()\n })\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { mutateAgentxConfig } from \"@/daemon/config-mutate\"\nimport { loadDaemonConfig } from \"@/daemon/config\"\n\n// --- agentx business — manage the business layer config ---\n//\n// Closes the second-pass parity gap: business.* in agentx.json had no\n// CLI surface and no dashboard UI, forcing operators to hand-edit\n// JSON for org-chart / project / contact-map changes — the same data\n// the activity-graph attribution and PM-gating rely on.\n//\n// Scope kept narrow on purpose:\n// show — read-only summary\n// orgchart — add / remove / list entries (agentId → { role, reportsTo, schedule })\n// project — add / remove / list (id, pm?, client?)\n// contact — add / remove / list (chatId/username → client/project)\n//\n// Out of scope for this round (use Advanced JSON tab in /admin or hand-\n// edit): workSource, roles, schedules beyond start/end, mainChannel.\n\nfunction mutate(mutator: (cfg: any) => string): void {\n const { summary, backupPath } = mutateAgentxConfig((cfg) => mutator(cfg))\n console.log(chalk.green(`\\n ✓ ${summary}`))\n if (backupPath) console.log(chalk.dim(` Backup: ${backupPath}`))\n console.log(chalk.dim(` Restart the daemon (or POST /reload) for the change to take effect.\\n`))\n}\n\nfunction readBusiness(): any {\n try {\n const cfg = loadDaemonConfig()\n return (cfg as any).business || {}\n } catch {\n return {}\n }\n}\n\nexport const business = new Command()\n .name(\"business\")\n .description(\"manage the business layer in agentx.json — orgChart, projects, contactMap\")\n\n// ---- show ----------------------------------------------------------------\n\nbusiness\n .command(\"show\")\n .description(\"print the current business config (orgChart, projects, contactMap)\")\n .option(\"--json\", \"machine-readable JSON\")\n .action((opts) => {\n const b = readBusiness()\n if (opts.json) { console.log(JSON.stringify(b, null, 2)); return }\n if (!b || !b.enabled) {\n console.log()\n console.log(chalk.yellow(\" business block not enabled (or missing).\"))\n console.log(chalk.dim(\" Add a `business` key to agentx.json to opt in.\"))\n console.log()\n return\n }\n const orgChart = b.orgChart || {}\n const projects = b.projects || []\n const contactMap = b.contactMap || []\n console.log()\n console.log(chalk.bold(\" Org chart\"))\n const orgEntries = Object.entries(orgChart) as Array<[string, any]>\n if (orgEntries.length === 0) console.log(chalk.dim(\" (empty)\"))\n else for (const [id, e] of orgEntries) {\n const reports = e.reportsTo ? chalk.dim(` → reports to ${e.reportsTo}`) : \"\"\n const sched = e.schedule ? chalk.dim(` · ${(e.schedule.days || []).join(\",\")} ${e.schedule.start}–${e.schedule.end}`) : \"\"\n console.log(` ${chalk.cyan(id)} ${e.role}${reports}${sched}`)\n }\n console.log()\n console.log(chalk.bold(` Projects (${projects.length})`))\n if (projects.length === 0) console.log(chalk.dim(\" (empty)\"))\n else for (const p of projects) {\n const pm = p.pm ? chalk.dim(` · pm=${p.pm}`) : \"\"\n const client = p.client ? chalk.dim(` · client=${p.client}`) : \"\"\n console.log(` ${chalk.cyan(p.id)}${pm}${client}`)\n }\n console.log()\n console.log(chalk.bold(` Contact map (${contactMap.length})`))\n if (contactMap.length === 0) console.log(chalk.dim(\" (empty)\"))\n else for (const c of contactMap) {\n const key = c.chatId ? `chatId=${c.chatId}` : c.username ? `username=${c.username}` : c.senderId ? `senderId=${c.senderId}` : \"?\"\n const ch = c.channel ? `${c.channel}/` : \"\"\n console.log(` ${chalk.cyan(ch + key)} → ${c.client}${c.project ? `/${c.project}` : \"\"}${c.displayName ? chalk.dim(` (${c.displayName})`) : \"\"}`)\n }\n console.log()\n })\n\n// ---- orgchart ------------------------------------------------------------\n\nconst orgchart = business\n .command(\"orgchart\")\n .description(\"manage business.orgChart — agentId → { role, reportsTo, schedule }\")\n\norgchart\n .command(\"list\")\n .description(\"list orgChart entries\")\n .option(\"--json\", \"JSON output\")\n .action((opts) => {\n const b = readBusiness()\n const entries = Object.entries(b.orgChart || {}) as Array<[string, any]>\n if (opts.json) { console.log(JSON.stringify(Object.fromEntries(entries), null, 2)); return }\n if (entries.length === 0) { console.log(chalk.dim(\" no entries\")); return }\n for (const [id, e] of entries) {\n console.log(` ${chalk.cyan(id)} ${e.role}${e.reportsTo ? chalk.dim(` → ${e.reportsTo}`) : \"\"}`)\n }\n })\n\norgchart\n .command(\"add <agentId>\")\n .description(\"add or update an orgChart entry for an agent\")\n .requiredOption(\"--role <role>\", \"role title (e.g. 'PM', 'Coder', 'DevOps')\")\n .option(\"--reports-to <agentId>\", \"manager's agentId\")\n .option(\"--start <hh:mm>\", \"schedule start\", \"09:00\")\n .option(\"--end <hh:mm>\", \"schedule end\", \"17:00\")\n .option(\"--days <csv>\", \"working days (mon,tue,wed,thu,fri)\", \"mon,tue,wed,thu,fri\")\n .option(\"--utilization <0..1>\", \"target utilization\", \"0.8\")\n .action((agentId: string, opts) => {\n const days = String(opts.days).split(\",\").map((s) => s.trim()).filter(Boolean) as Array<\"mon\" | \"tue\" | \"wed\" | \"thu\" | \"fri\" | \"sat\" | \"sun\">\n mutate((cfg) => {\n cfg.business = cfg.business || {}\n cfg.business.orgChart = cfg.business.orgChart || {}\n cfg.business.orgChart[agentId] = {\n role: opts.role,\n ...(opts.reportsTo ? { reportsTo: opts.reportsTo } : {}),\n schedule: { days, start: opts.start, end: opts.end },\n utilizationTarget: parseFloat(opts.utilization) || 0.8,\n }\n return `orgChart entry \"${agentId}\" upserted (role=${opts.role}${opts.reportsTo ? `, reports to ${opts.reportsTo}` : \"\"})`\n })\n })\n\norgchart\n .command(\"remove <agentId>\")\n .alias(\"rm\")\n .description(\"remove an orgChart entry\")\n .action((agentId: string) => {\n mutate((cfg) => {\n if (!cfg.business?.orgChart || !(agentId in cfg.business.orgChart)) {\n throw new Error(`no orgChart entry for \"${agentId}\"`)\n }\n delete cfg.business.orgChart[agentId]\n return `orgChart entry \"${agentId}\" removed`\n })\n })\n\n// ---- project -------------------------------------------------------------\n\nconst project = business\n .command(\"project\")\n .description(\"manage business.projects — id, pm, client\")\n\nproject\n .command(\"list\")\n .description(\"list projects\")\n .option(\"--json\", \"JSON output\")\n .action((opts) => {\n const b = readBusiness()\n const projects = b.projects || []\n if (opts.json) { console.log(JSON.stringify(projects, null, 2)); return }\n if (projects.length === 0) { console.log(chalk.dim(\" no projects\")); return }\n for (const p of projects) {\n console.log(` ${chalk.cyan(p.id)} ${p.pm ? `pm=${p.pm}` : \"\"} ${p.client ? `client=${p.client}` : \"\"}`.trimEnd())\n }\n })\n\nproject\n .command(\"add <id>\")\n .description(\"add or update a project entry\")\n .option(\"--pm <agentId>\", \"PM responsible for this project (drives PM gate)\")\n .option(\"--client <name>\", \"client this project belongs to (drives activity-graph attribution)\")\n .action((id: string, opts) => {\n mutate((cfg) => {\n cfg.business = cfg.business || {}\n cfg.business.projects = cfg.business.projects || []\n const idx = cfg.business.projects.findIndex((p: any) => p.id === id)\n const next = { id, ...(opts.pm ? { pm: opts.pm } : {}), ...(opts.client ? { client: opts.client } : {}) }\n if (idx >= 0) cfg.business.projects[idx] = { ...cfg.business.projects[idx], ...next }\n else cfg.business.projects.push(next)\n return idx >= 0 ? `project \"${id}\" updated` : `project \"${id}\" added`\n })\n })\n\nproject\n .command(\"remove <id>\")\n .alias(\"rm\")\n .description(\"remove a project entry\")\n .action((id: string) => {\n mutate((cfg) => {\n const list = cfg.business?.projects || []\n const before = list.length\n cfg.business.projects = list.filter((p: any) => p.id !== id)\n if (cfg.business.projects.length === before) throw new Error(`no project \"${id}\"`)\n return `project \"${id}\" removed`\n })\n })\n\n// ---- contact -------------------------------------------------------------\n\nconst contact = business\n .command(\"contact\")\n .description(\"manage business.contactMap — chatId/username/senderId → client/project\")\n\ncontact\n .command(\"list\")\n .description(\"list contact map entries\")\n .option(\"--json\", \"JSON output\")\n .action((opts) => {\n const b = readBusiness()\n const list = b.contactMap || []\n if (opts.json) { console.log(JSON.stringify(list, null, 2)); return }\n if (list.length === 0) { console.log(chalk.dim(\" no entries\")); return }\n for (const c of list) {\n const key = c.chatId ? `chatId=${c.chatId}` : c.username ? `username=${c.username}` : c.senderId ? `senderId=${c.senderId}` : \"?\"\n console.log(` ${c.channel ? c.channel + \"/\" : \"\"}${chalk.cyan(key)} → ${c.client}${c.project ? \"/\" + c.project : \"\"}`)\n }\n })\n\ncontact\n .command(\"add\")\n .description(\"add a contactMap entry\")\n .requiredOption(\"--client <name>\", \"client this contact belongs to\")\n .option(\"--channel <name>\", \"telegram | whatsapp | slack | discord\")\n .option(\"--chat-id <id>\", \"native chat id (e.g. -100…, JID)\")\n .option(\"--username <handle>\", \"sender username/handle\")\n .option(\"--sender-id <id>\", \"numeric sender id (when username is unstable)\")\n .option(\"--project <id>\", \"project this traffic should attribute to\")\n .option(\"--display-name <name>\", \"display-name override for the initiator pill\")\n .action((opts) => {\n if (!opts.chatId && !opts.username && !opts.senderId) {\n console.log(chalk.red(\" one of --chat-id / --username / --sender-id is required\"))\n process.exit(1)\n }\n mutate((cfg) => {\n cfg.business = cfg.business || {}\n cfg.business.contactMap = cfg.business.contactMap || []\n const entry: any = { client: opts.client }\n if (opts.channel) entry.channel = opts.channel\n if (opts.chatId) entry.chatId = opts.chatId\n if (opts.username) entry.username = opts.username\n if (opts.senderId) entry.senderId = opts.senderId\n if (opts.project) entry.project = opts.project\n if (opts.displayName) entry.displayName = opts.displayName\n cfg.business.contactMap.push(entry)\n const key = opts.chatId || opts.username || opts.senderId\n return `contact ${opts.channel ? opts.channel + \"/\" : \"\"}${key} → ${opts.client}${opts.project ? \"/\" + opts.project : \"\"} added`\n })\n })\n\ncontact\n .command(\"remove\")\n .alias(\"rm\")\n .description(\"remove a contactMap entry by matching field(s)\")\n .option(\"--channel <name>\")\n .option(\"--chat-id <id>\")\n .option(\"--username <handle>\")\n .option(\"--sender-id <id>\")\n .action((opts) => {\n mutate((cfg) => {\n const list = cfg.business?.contactMap || []\n const before = list.length\n cfg.business.contactMap = list.filter((c: any) => {\n if (opts.channel && c.channel !== opts.channel) return true\n if (opts.chatId && c.chatId !== opts.chatId) return true\n if (opts.username && c.username !== opts.username) return true\n if (opts.senderId && c.senderId !== opts.senderId) return true\n return false // matched all provided filters → drop\n })\n if (cfg.business.contactMap.length === before) throw new Error(\"no matching contact entry\")\n return `${before - cfg.business.contactMap.length} contact entry/entries removed`\n })\n })\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { DayPlanStore, parsePriorities, type PlanTier } from \"@/business/day-plan\"\nimport { loadDaemonConfig } from \"@/daemon/config\"\n\n// --- agentx plan: human-driven daily / weekly / monthly priorities ---\n//\n// Replaces the old mechanical standup-tick. The day-cycle reads\n// .agentx/plans/<date>.md (day → week → month fallback) every morning;\n// without a plan, the cycle posts a notification and dispatches no agent.\n// This CLI is the fast path for operators who'd rather type than open the\n// admin form. Markdown files are also editable directly on disk and via\n// the admin Plans tab — three surfaces, one source of truth.\n\nconst TIER_ALIAS: Record<string, PlanTier> = {\n today: \"day\", day: \"day\",\n week: \"week\", \"this-week\": \"week\",\n month: \"month\", \"this-month\": \"month\",\n}\n\nfunction resolveTier(label: string): PlanTier {\n const t = TIER_ALIAS[label.toLowerCase()]\n if (!t) throw new Error(`Unknown plan tier \"${label}\". Use: today | week | month.`)\n return t\n}\n\nfunction resolveStore(): DayPlanStore {\n const cfg = loadDaemonConfig()\n const dir = cfg.business?.standup?.plansDir || \".agentx/plans\"\n return new DayPlanStore(dir)\n}\n\nexport const plan = new Command()\n .name(\"plan\")\n .description(\"set / read / list day-week-month plans that drive the standup-tick\")\n\nplan\n .command(\"set <tier>\")\n .description(\"write a plan for today | week | month (priorities-as-bullets)\")\n .option(\"-p, --priority <text...>\", \"bullet line — repeat for multiple priorities\")\n .option(\"-m, --markdown <md>\", \"raw markdown body (overrides --priority)\")\n .option(\"-f, --file <path>\", \"read markdown from a file\")\n .action(async (tier: string, opts) => {\n const t = resolveTier(tier)\n const store = resolveStore()\n let body: string\n if (opts.file) {\n const { readFileSync } = await import(\"fs\")\n body = readFileSync(opts.file, \"utf-8\")\n } else if (opts.markdown) {\n body = opts.markdown\n } else if (opts.priority?.length) {\n body = (opts.priority as string[]).map((p) => `- ${p}`).join(\"\\n\")\n } else {\n console.error(chalk.red(\" Provide --priority, --markdown, or --file.\"))\n process.exit(1)\n }\n const result = store.write(t, body)\n console.log(chalk.green(` ✓ ${t} plan saved → ${result.path}`))\n const items = parsePriorities(body)\n if (items.length) {\n console.log(chalk.dim(` ${items.length} bullet${items.length === 1 ? \"\" : \"s\"}:`))\n for (const it of items) console.log(chalk.dim(` • ${it}`))\n }\n })\n\nplan\n .command(\"show [tier]\")\n .description(\"print the plan that the next standup will use (default: resolve day→week→month)\")\n .action(async (tier: string | undefined) => {\n const store = resolveStore()\n if (tier) {\n const t = resolveTier(tier)\n const r = store.read(t)\n if (!r) { console.log(chalk.dim(` No ${t} plan set.`)); return }\n printPlan(r.tier, r.date, r.content)\n return\n }\n const r = store.resolve()\n if (!r) {\n console.log(chalk.yellow(\" No plan set at any tier.\"))\n console.log(chalk.dim(\" The next standup-tick will post a 'no plan today' notice and dispatch no agent.\"))\n console.log(chalk.dim(\" Set one with: agentx plan set today --priority \\\"…\\\"\"))\n return\n }\n printPlan(r.tier, r.date, r.content)\n })\n\nplan\n .command(\"list\")\n .description(\"recent plans across all tiers\")\n .option(\"-n, --limit <n>\", \"max rows\", \"20\")\n .action(async (opts) => {\n const store = resolveStore()\n const rows = store.list(parseInt(opts.limit, 10) || 20)\n if (!rows.length) { console.log(chalk.dim(\" No plans yet.\")); return }\n for (const r of rows) {\n console.log(` ${chalk.cyan(r.tier.padEnd(5))} ${chalk.bold(r.date.padEnd(11))} ${chalk.dim(r.path)}`)\n }\n })\n\nplan\n .command(\"clear <tier>\")\n .description(\"remove the plan for today | week | month\")\n .action(async (tier: string) => {\n const t = resolveTier(tier)\n const store = resolveStore()\n const existing = store.read(t)\n if (!existing) { console.log(chalk.dim(` No ${t} plan to clear.`)); return }\n const { unlinkSync } = await import(\"fs\")\n unlinkSync(existing.path)\n console.log(chalk.green(` ✓ ${t} plan cleared (${existing.path})`))\n })\n\nfunction printPlan(tier: PlanTier, date: string, content: string): void {\n console.log(chalk.cyan(` ${tier} plan — ${date}`))\n console.log()\n for (const line of content.split(\"\\n\")) console.log(` ${line}`)\n console.log()\n const items = parsePriorities(content)\n if (items.length) console.log(chalk.dim(` ${items.length} bullet${items.length === 1 ? \"\" : \"s\"} extracted as priorities.`))\n}\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { mutateAgentxConfig } from \"@/daemon/config-mutate\"\nimport { loadDaemonConfig } from \"@/daemon/config\"\n\n// --- agentx notifications — manage where + when AgentX pings the operator ---\n//\n// Closes the audit gap: notifications.* in agentx.json had no CLI surface.\n// Operators tuning where task-error pings land or which event types are\n// surfaced were stuck hand-editing JSON.\n//\n// The whole notifications block is small: a destination (channel/chatId/\n// accountId), three event toggles (taskComplete / taskError / taskQueued),\n// and a longTaskThreshold.\n\nfunction readNotifications(): any {\n try { return (loadDaemonConfig() as any).notifications || {} } catch { return {} }\n}\n\nfunction mutate(mutator: (n: any) => string): void {\n const { summary, backupPath } = mutateAgentxConfig((cfg) => {\n cfg.notifications = cfg.notifications || {}\n return mutator(cfg.notifications)\n })\n console.log(chalk.green(`\\n ✓ ${summary}`))\n if (backupPath) console.log(chalk.dim(` Backup: ${backupPath}`))\n console.log(chalk.dim(` Restart the daemon (or POST /reload) for the change to take effect.\\n`))\n}\n\nexport const notifications = new Command()\n .name(\"notifications\")\n .description(\"manage notifications routing — destination, event toggles, long-task threshold\")\n\nnotifications\n .command(\"show\")\n .description(\"print current notifications config\")\n .option(\"--json\", \"JSON output\")\n .action((opts) => {\n const n = readNotifications()\n if (opts.json) { console.log(JSON.stringify(n, null, 2)); return }\n console.log()\n if (n.destination) {\n const acct = n.destination.accountId ? ` · account=${n.destination.accountId}` : \"\"\n console.log(` destination ${chalk.cyan(n.destination.channel + \":\" + n.destination.chatId)}${chalk.dim(acct)}`)\n } else {\n console.log(` destination ${chalk.dim(\"(unset — notifications go to the daemon log only)\")}`)\n }\n console.log(` longTaskThreshold ${n.longTaskThreshold ?? 30}s ${chalk.dim(\"(0 disables long-task pings)\")}`)\n const on = n.on || {}\n console.log(` on.taskComplete ${on.taskComplete === false ? chalk.dim(\"off\") : \"on\"}`)\n console.log(` on.taskError ${on.taskError === false ? chalk.dim(\"off\") : \"on\"}`)\n console.log(` on.taskQueued ${on.taskQueued ? \"on\" : chalk.dim(\"off\")}`)\n console.log()\n })\n\nnotifications\n .command(\"route\")\n .description(\"set the destination channel/chatId for notifications\")\n .requiredOption(\"--channel <name>\", \"telegram | whatsapp | slack | discord\")\n .requiredOption(\"--chat-id <id>\", \"native chat id (e.g. -100…, JID, channel id)\")\n .option(\"--account-id <id>\", \"channel account id when the channel is multi-account (telegram with multiple bots)\")\n .option(\"--clear\", \"clear the destination instead of setting it\")\n .action((opts) => {\n if (opts.clear) {\n mutate((n) => { delete n.destination; return \"notifications destination cleared\" })\n return\n }\n mutate((n) => {\n n.destination = {\n channel: opts.channel,\n chatId: opts.chatId,\n ...(opts.accountId ? { accountId: opts.accountId } : {}),\n }\n return `notifications destination → ${opts.channel}:${opts.chatId}${opts.accountId ? ` (account=${opts.accountId})` : \"\"}`\n })\n })\n\nnotifications\n .command(\"event <name> <state>\")\n .description(\"toggle an event: name in {taskComplete, taskError, taskQueued}; state in {on, off}\")\n .action((name: string, state: string) => {\n const known = [\"taskComplete\", \"taskError\", \"taskQueued\"]\n if (!known.includes(name)) {\n console.log(chalk.red(` unknown event \"${name}\". Pick from: ${known.join(\", \")}`))\n process.exit(1)\n }\n const onv = state.toLowerCase()\n if (![\"on\", \"off\", \"true\", \"false\", \"1\", \"0\"].includes(onv)) {\n console.log(chalk.red(` state must be on|off`))\n process.exit(1)\n }\n const enabled = onv === \"on\" || onv === \"true\" || onv === \"1\"\n mutate((n) => {\n n.on = n.on || {}\n n.on[name] = enabled\n return `notifications.on.${name} = ${enabled}`\n })\n })\n\nnotifications\n .command(\"threshold <seconds>\")\n .description(\"set the long-task threshold in seconds (0 disables long-task pings)\")\n .action((seconds: string) => {\n const n = parseInt(seconds, 10)\n if (!Number.isFinite(n) || n < 0) {\n console.log(chalk.red(\" threshold must be a non-negative integer\"))\n process.exit(1)\n }\n mutate((cfg) => {\n cfg.longTaskThreshold = n\n return `longTaskThreshold = ${n}s`\n })\n })\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { readdirSync, statSync, unlinkSync, rmSync, existsSync } from \"fs\"\nimport { resolve, join } from \"path\"\n\n// --- agentx retention — prune old session/drift files ---\n//\n// Closes the \"no operator-facing cleanup\" gap from the audit. Long-\n// lived daemons accumulate per-day session JSONs and drift snapshots;\n// neither gets pruned automatically. This subcommand walks each\n// allow-listed directory and removes files older than --days.\n\ninterface PruneTarget {\n /** Root path under .agentx/ to walk. */\n dir: string\n /** Description shown in the dry-run + summary output. */\n label: string\n /** When true, recurse into subdirs (sessions are flat; some workspaces nest). */\n recursive?: boolean\n}\n\nconst TARGETS: PruneTarget[] = [\n { dir: \".agentx/sessions\", label: \"Per-day session JSON\" },\n { dir: \".agentx/drift\", label: \"Drift snapshots\", recursive: true },\n { dir: \".agentx/router\", label: \"Router-decision logs\", recursive: true },\n { dir: \".agentx/patterns\", label: \"Self-improving pattern store\", recursive: true },\n]\n\nfunction walkFiles(dir: string, recursive: boolean): string[] {\n if (!existsSync(dir)) return []\n const out: string[] = []\n for (const entry of readdirSync(dir, { withFileTypes: true })) {\n const full = join(dir, entry.name)\n if (entry.isFile()) out.push(full)\n else if (entry.isDirectory() && recursive) out.push(...walkFiles(full, true))\n }\n return out\n}\n\nexport const retention = new Command()\n .name(\"retention\")\n .description(\"prune old workspace state (sessions, drift, router traces, pattern store)\")\n\nretention\n .command(\"show\", { isDefault: true })\n .description(\"show how much each retention target currently weighs\")\n .action(() => {\n console.log()\n let total = 0\n for (const t of TARGETS) {\n const root = resolve(process.cwd(), t.dir)\n const files = walkFiles(root, !!t.recursive)\n let bytes = 0\n let oldest: number | null = null\n for (const f of files) {\n try {\n const s = statSync(f)\n bytes += s.size\n if (oldest === null || s.mtimeMs < oldest) oldest = s.mtimeMs\n } catch { /* skip */ }\n }\n total += bytes\n const oldestAge = oldest !== null ? `${Math.round((Date.now() - oldest) / 86_400_000)}d` : \"—\"\n console.log(` ${chalk.cyan(t.dir.padEnd(22))} ${String(files.length).padStart(5)} files ${formatBytes(bytes).padStart(10)} oldest=${oldestAge}`)\n }\n console.log(chalk.dim(` ${\"\".padEnd(22)} ${\"\".padStart(5)} ${formatBytes(total).padStart(10)} total`))\n console.log()\n console.log(chalk.dim(\" Run `agentx retention prune --days 30` to delete files older than 30 days.\"))\n console.log()\n })\n\nretention\n .command(\"prune\")\n .description(\"delete files older than --days from each retention target\")\n .option(\"--days <n>\", \"max age in days; everything older is deleted\", \"30\")\n .option(\"--dry-run\", \"list candidates, don't delete\")\n .option(\"--target <name>\", \"limit to one target dir (e.g. .agentx/sessions)\")\n .action((opts) => {\n const days = parseInt(opts.days, 10)\n if (!Number.isFinite(days) || days < 1) {\n console.log(chalk.red(\" --days must be a positive integer\"))\n process.exit(1)\n }\n const cutoff = Date.now() - days * 86_400_000\n const filterTarget = opts.target as string | undefined\n let totalRemoved = 0\n let totalBytes = 0\n console.log()\n console.log(chalk.bold(` Pruning files older than ${days}d (${new Date(cutoff).toISOString().slice(0, 10)})${opts.dryRun ? chalk.yellow(\" — DRY RUN\") : \"\"}`))\n console.log()\n for (const t of TARGETS) {\n if (filterTarget && t.dir !== filterTarget) continue\n const root = resolve(process.cwd(), t.dir)\n const files = walkFiles(root, !!t.recursive)\n let removed = 0\n let bytes = 0\n for (const f of files) {\n try {\n const s = statSync(f)\n if (s.mtimeMs < cutoff) {\n bytes += s.size\n removed++\n if (!opts.dryRun) {\n try { unlinkSync(f) } catch { /* */ }\n }\n }\n } catch { /* skip */ }\n }\n // Best-effort cleanup of empty subdirs (recursive targets only).\n if (t.recursive && !opts.dryRun) {\n try { pruneEmptyDirs(root) } catch { /* */ }\n }\n const action = opts.dryRun ? \"would remove\" : \"removed\"\n console.log(` ${chalk.cyan(t.dir.padEnd(22))} ${action} ${String(removed).padStart(5)} files (${formatBytes(bytes)})`)\n totalRemoved += removed\n totalBytes += bytes\n }\n console.log()\n console.log(chalk.green(` ✓ ${opts.dryRun ? \"(dry-run)\" : \"\"} ${totalRemoved} files, ${formatBytes(totalBytes)} ${opts.dryRun ? \"would be reclaimed\" : \"reclaimed\"}`))\n console.log()\n })\n\nfunction pruneEmptyDirs(root: string): void {\n if (!existsSync(root)) return\n for (const entry of readdirSync(root, { withFileTypes: true })) {\n if (!entry.isDirectory()) continue\n const full = join(root, entry.name)\n pruneEmptyDirs(full)\n try {\n const remaining = readdirSync(full)\n if (remaining.length === 0) rmSync(full, { recursive: false })\n } catch { /* skip */ }\n }\n}\n\nfunction formatBytes(b: number): string {\n if (b < 1024) return b + \"B\"\n if (b < 1024 * 1024) return (b / 1024).toFixed(1) + \"K\"\n if (b < 1024 * 1024 * 1024) return (b / 1024 / 1024).toFixed(1) + \"M\"\n return (b / 1024 / 1024 / 1024).toFixed(2) + \"G\"\n}\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { ActionStore } from \"@/actions/store\"\nimport { runAction } from \"@/actions/runner\"\nimport { actionSchema, type Action } from \"@/actions/types\"\n\n// --- agentx actions — manage the action registry ---\n//\n// Closes the last outstanding parity audit gap: a registry of named,\n// parameterized invocations that workflows / CLI / dashboard can call\n// instead of hardcoding shell/http calls per use site.\n//\n// Two action kinds in v1:\n// shell — exec a command (cwd-aware, env-merge, template inputs)\n// http — fetch a URL with method/headers/body\n//\n// Storage: .agentx/actions/<id>.json (one file per action).\n\nexport const actions = new Command()\n .name(\"actions\")\n .description(\"manage the action registry — reusable shell/http invocations\")\n\nactions\n .command(\"list\")\n .description(\"list registered actions\")\n .option(\"--json\", \"JSON output\")\n .action((opts) => {\n const store = new ActionStore()\n const list = store.list()\n if (opts.json) { console.log(JSON.stringify(list, null, 2)); return }\n if (list.length === 0) {\n console.log()\n console.log(chalk.dim(\" No actions yet. Add one with `agentx actions add` or `agentx actions create`.\"))\n console.log()\n return\n }\n console.log()\n for (const a of list) {\n const inputs = a.inputs?.length ? chalk.dim(` (${a.inputs.length} input${a.inputs.length === 1 ? \"\" : \"s\"})`) : \"\"\n const target = a.kind === \"shell\" ? `shell: ${a.command.slice(0, 50)}` : `${a.method} ${a.url.slice(0, 50)}`\n console.log(` ${chalk.cyan(a.id.padEnd(24))} ${a.title}${inputs}`)\n console.log(` ${\" \".repeat(24)} ${chalk.dim(target)}`)\n }\n console.log()\n })\n\nactions\n .command(\"show <id>\")\n .description(\"show an action's full definition\")\n .option(\"--json\", \"JSON output\")\n .action((id: string, opts) => {\n const store = new ActionStore()\n const a = store.get(id)\n if (!a) { console.log(chalk.red(` no action \"${id}\"`)); process.exit(1) }\n if (opts.json) { console.log(JSON.stringify(a, null, 2)); return }\n console.log()\n console.log(chalk.bold(` ${a.title}`))\n if (a.description) console.log(chalk.dim(` ${a.description}`))\n console.log()\n console.log(` id ${a.id}`)\n console.log(` kind ${a.kind}`)\n console.log(` timeout ${a.timeoutMs}ms`)\n if (a.kind === \"shell\") {\n console.log(` command ${a.command}`)\n if (a.cwd) console.log(` cwd ${a.cwd}`)\n if (a.env) console.log(` env ${JSON.stringify(a.env)}`)\n } else {\n console.log(` ${a.method.padEnd(9)} ${a.url}`)\n if (a.headers) console.log(` headers ${JSON.stringify(a.headers)}`)\n if (a.body) console.log(` body ${a.body.slice(0, 200)}`)\n }\n if (a.inputs.length) {\n console.log()\n console.log(chalk.bold(\" Inputs:\"))\n for (const inp of a.inputs) {\n const req = inp.required ? chalk.red(\"*\") : \" \"\n const def = inp.defaultValue !== undefined ? chalk.dim(` default=${JSON.stringify(inp.defaultValue)}`) : \"\"\n const desc = inp.description ? chalk.dim(` — ${inp.description}`) : \"\"\n console.log(` ${req} ${chalk.cyan(inp.name)} (${inp.type})${def}${desc}`)\n }\n }\n console.log()\n })\n\nactions\n .command(\"add <id>\")\n .description(\"add (or replace) an action non-interactively\")\n .requiredOption(\"--title <text>\")\n .requiredOption(\"--kind <kind>\", \"shell | http\")\n .option(\"--description <text>\")\n .option(\"--command <text>\", \"[shell] templated shell command\")\n .option(\"--cwd <path>\", \"[shell] working directory\")\n .option(\"--url <url>\", \"[http] URL\")\n .option(\"--method <m>\", \"[http] GET|POST|PUT|PATCH|DELETE\", \"POST\")\n .option(\"--headers <json>\", \"[http] headers as JSON object\")\n .option(\"--body <text>\", \"[http] body template\")\n .option(\"--inputs <csv>\", \"comma-separated list of name:type[!] (e.g. amount:number!,note:string)\")\n .option(\"--timeout <ms>\", \"timeout in ms (default 30000)\", \"30000\")\n .action((id: string, opts) => {\n const inputs = parseInputsCsv(opts.inputs)\n const base: any = {\n id, title: opts.title, description: opts.description, inputs,\n timeoutMs: parseInt(opts.timeout, 10) || 30_000,\n kind: opts.kind,\n }\n if (opts.kind === \"shell\") {\n if (!opts.command) { console.log(chalk.red(\" --command required for kind=shell\")); process.exit(1) }\n base.command = opts.command\n if (opts.cwd) base.cwd = opts.cwd\n } else if (opts.kind === \"http\") {\n if (!opts.url) { console.log(chalk.red(\" --url required for kind=http\")); process.exit(1) }\n base.url = opts.url\n base.method = opts.method\n if (opts.headers) {\n try { base.headers = JSON.parse(opts.headers) }\n catch { console.log(chalk.red(\" --headers must be valid JSON\")); process.exit(1) }\n }\n if (opts.body) base.body = opts.body\n } else {\n console.log(chalk.red(\" --kind must be shell|http\"))\n process.exit(1)\n }\n const parsed = actionSchema.safeParse(base)\n if (!parsed.success) {\n console.log(chalk.red(\" validation failed:\"))\n for (const issue of parsed.error.issues) console.log(chalk.red(` ${issue.path.join(\".\")}: ${issue.message}`))\n process.exit(1)\n }\n const store = new ActionStore()\n const saved = store.save(parsed.data)\n console.log(chalk.green(`\\n ✓ action \"${saved.id}\" saved (${saved.kind}).`))\n console.log(chalk.dim(` Test: agentx actions run ${saved.id}\\n`))\n })\n\nactions\n .command(\"remove <id>\")\n .alias(\"rm\")\n .description(\"delete an action\")\n .action((id: string) => {\n const store = new ActionStore()\n if (!store.delete(id)) { console.log(chalk.red(` no action \"${id}\"`)); process.exit(1) }\n console.log(chalk.green(` ✓ action \"${id}\" removed`))\n })\n\nactions\n .command(\"run <id>\")\n .description(\"invoke an action and print its output\")\n .option(\"--input <kv...>\", \"input as key=value (repeat for each)\")\n .option(\"--json\", \"JSON output (full ActionRunResult)\")\n .action(async (id: string, opts) => {\n const store = new ActionStore()\n const action = store.get(id)\n if (!action) { console.log(chalk.red(` no action \"${id}\"`)); process.exit(1) }\n const inputs: Record<string, string> = {}\n for (const kv of (opts.input || []) as string[]) {\n const eq = kv.indexOf(\"=\")\n if (eq < 0) { console.log(chalk.red(` --input \"${kv}\" must be key=value`)); process.exit(1) }\n inputs[kv.slice(0, eq)] = kv.slice(eq + 1)\n }\n try {\n const result = await runAction(action as Action, inputs)\n if (opts.json) { console.log(JSON.stringify(result, null, 2)); return }\n console.log()\n console.log(` ${result.ok ? chalk.green(\"✓ ok\") : chalk.red(\"✗ failed\")} status=${result.status} ${result.durationMs}ms`)\n console.log()\n if (result.output) {\n console.log(chalk.dim(\" --- output ---\"))\n console.log(result.output)\n }\n if (result.errors) {\n console.log(chalk.dim(\" --- errors ---\"))\n console.log(chalk.red(result.errors))\n }\n console.log()\n if (!result.ok) process.exit(1)\n } catch (e: any) {\n console.log(chalk.red(` ${e.message}`))\n process.exit(1)\n }\n })\n\n// --- Typed built-in actions (separate registry from custom shell/http) ---\n//\n// Built-in actions are TypeScript modules under src/actions/builtin/ that\n// register at daemon boot. They expose strict input/output Zod schemas and\n// are the preferred way for agents to do typed work (HTTP, file I/O, RAG,\n// extract.structured, mesh.delegate). Operators don't author them — they\n// ship as part of the binary and appear at GET /api/actions/builtin.\n//\n// This subcommand exists so agents can invoke a built-in via Bash and\n// have the call land as a structured action step in /traces (vs an opaque\n// curl invocation). The CLI just POSTs to the daemon's existing endpoint.\n\nactions\n .command(\"builtin [name]\")\n .description(\"list registered built-in actions, or run one with --input\")\n .option(\"--input <json>\", \"JSON input matching the action's inputSchema\")\n .option(\"--daemon <url>\", \"daemon API base URL\", \"http://127.0.0.1:18800\")\n .option(\"--json\", \"raw JSON output (omit chrome)\")\n .option(\"--schema\", \"show the action's input/output schema instead of running it\")\n .action(async (name: string | undefined, opts) => {\n const base = String(opts.daemon).replace(/\\/+$/, \"\")\n\n // No name → list all built-ins.\n if (!name) {\n try {\n const res = await fetch(`${base}/api/actions/builtin`)\n if (!res.ok) {\n console.log(chalk.red(` list failed (${res.status}): ${(await res.text()).slice(0, 200)}`))\n process.exit(1)\n }\n const body = await res.json() as { actions?: Array<{ name: string; description?: string; timeoutMs?: number }> }\n const list = body.actions || []\n if (opts.json) { console.log(JSON.stringify(list, null, 2)); return }\n if (list.length === 0) {\n console.log(chalk.dim(\" No built-in actions registered. Daemon may not be running, or registerAllBuiltins() didn't fire at boot.\"))\n return\n }\n console.log()\n console.log(chalk.bold(\" Built-in typed actions\"))\n console.log(chalk.dim(\" Invoke: agentx actions builtin <name> --input '<json>'\"))\n console.log()\n for (const a of list) {\n const t = a.timeoutMs ? chalk.dim(` (timeout=${Math.round(a.timeoutMs / 1000)}s)`) : \"\"\n console.log(` ${chalk.cyan(a.name.padEnd(22))} ${a.description || \"\"}${t}`)\n }\n console.log()\n } catch (e: any) {\n console.log(chalk.red(` daemon unreachable: ${e.message || e}`))\n process.exit(1)\n }\n return\n }\n\n // --schema mode: print the input/output schema without running.\n if (opts.schema) {\n try {\n const res = await fetch(`${base}/api/actions/builtin`)\n const body = await res.json() as { actions?: Array<{ name: string; inputSchema?: unknown; outputSchema?: unknown; description?: string }> }\n const a = (body.actions || []).find((x) => x.name === name)\n if (!a) { console.log(chalk.red(` unknown action: ${name}`)); process.exit(1) }\n if (opts.json) { console.log(JSON.stringify(a, null, 2)); return }\n console.log()\n console.log(chalk.bold(` ${a.name}`))\n if (a.description) console.log(chalk.dim(` ${a.description}`))\n console.log()\n console.log(chalk.dim(\" --- input schema ---\"))\n console.log(JSON.stringify(a.inputSchema ?? {}, null, 2))\n if (a.outputSchema) {\n console.log()\n console.log(chalk.dim(\" --- output schema ---\"))\n console.log(JSON.stringify(a.outputSchema, null, 2))\n }\n console.log()\n } catch (e: any) {\n console.log(chalk.red(` schema fetch failed: ${e.message || e}`))\n process.exit(1)\n }\n return\n }\n\n // Run mode: POST to the daemon's typed-action endpoint with --input.\n let input: unknown = {}\n if (opts.input) {\n try { input = JSON.parse(opts.input) } catch (e: any) {\n console.log(chalk.red(` --input must be valid JSON: ${e.message}`))\n process.exit(1)\n }\n }\n try {\n const res = await fetch(`${base}/api/actions/builtin/${encodeURIComponent(name)}`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(input),\n })\n const body = await res.json().catch(() => ({}))\n if (!res.ok) {\n if (opts.json) { console.log(JSON.stringify(body, null, 2)); process.exit(1) }\n console.log(chalk.red(` action failed (${res.status}): ${(body as any).error || JSON.stringify(body).slice(0, 300)}`))\n process.exit(1)\n }\n if (opts.json) { console.log(JSON.stringify(body, null, 2)); return }\n // Default human-friendly output: print the structured result.\n console.log(JSON.stringify(body, null, 2))\n } catch (e: any) {\n console.log(chalk.red(` daemon unreachable: ${e.message || e}`))\n process.exit(1)\n }\n })\n\n/** Parse the --inputs CSV: name:type[!],name:type. `!` marks required. */\nfunction parseInputsCsv(csv: string | undefined): Action[\"inputs\"] {\n if (!csv) return []\n const out: Action[\"inputs\"] = []\n for (const part of csv.split(\",\").map((s) => s.trim()).filter(Boolean)) {\n const required = part.endsWith(\"!\")\n const clean = required ? part.slice(0, -1) : part\n const colon = clean.indexOf(\":\")\n const name = colon >= 0 ? clean.slice(0, colon) : clean\n const type = (colon >= 0 ? clean.slice(colon + 1) : \"string\") as \"string\" | \"number\" | \"boolean\"\n out.push({ name, type, required })\n }\n return out\n}\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { loadDaemonConfig } from \"@/daemon/config\"\n\n// --- agentx watch — one live operator console for the daemon ---\n//\n// Opens an SSE connection to the daemon's /events endpoint with optional\n// filters and prints one-line formatted entries. Meant for\n// agentx watch # everything\n// agentx watch --type run,task # just workflow runs + user tasks\n// agentx watch --workflow X # runs of a specific workflow\n// agentx watch --actor actor:alice\n//\n// Multi-daemon: pass --node <url> to point at a peer; otherwise uses the\n// local daemon URL from dashboard.daemonUrl or -c config.\n\nexport const watch = new Command()\n .name(\"watch\")\n .description(\"stream live daemon events — workflow runs, user tasks, signals, mesh health\")\n .option(\"-c, --config <path>\", \"daemon config file\")\n .option(\"-t, --type <kinds>\", \"comma-separated event kinds (run,task,signal,mesh,channel,status)\")\n .option(\"-w, --workflow <id>\", \"only events for this workflow id\")\n .option(\"-a, --actor <id>\", \"only task events involving this actor id\")\n .option(\"-r, --run <id>\", \"only events for this run id\")\n .option(\"--channel <name>\", \"only channel events on this channel (telegram/whatsapp/…)\")\n .option(\"--node <url>\", \"daemon URL (defaults to dashboard.daemonUrl from config)\")\n .option(\"--token <token>\", \"bearer token (defaults to dashboard.token from config)\")\n .action(async (opts) => {\n let baseUrl = typeof opts.node === \"string\" ? opts.node : \"\"\n let token = typeof opts.token === \"string\" ? opts.token : \"\"\n if (!baseUrl || !token) {\n try {\n const cfg = loadDaemonConfig(opts.config)\n if (!baseUrl) baseUrl = cfg.dashboard?.daemonUrl || \"\"\n if (!token) token = cfg.dashboard?.token || \"\"\n } catch {\n // No config — fall back to localhost:18800 and no auth.\n }\n }\n if (!baseUrl) baseUrl = \"http://localhost:18800\"\n\n const qs: string[] = []\n if (typeof opts.type === \"string\") qs.push(`type=${encodeURIComponent(opts.type)}`)\n if (typeof opts.workflow === \"string\") qs.push(`workflow=${encodeURIComponent(opts.workflow)}`)\n if (typeof opts.actor === \"string\") qs.push(`actor=${encodeURIComponent(opts.actor)}`)\n if (typeof opts.run === \"string\") qs.push(`run=${encodeURIComponent(opts.run)}`)\n if (typeof opts.channel === \"string\") qs.push(`channel=${encodeURIComponent(opts.channel)}`)\n const url = `${baseUrl.replace(/\\/+$/, \"\")}/events${qs.length ? `?${qs.join(\"&\")}` : \"\"}`\n\n console.log(chalk.dim(` connecting to ${url}`))\n\n const headers: Record<string, string> = { Accept: \"text/event-stream\" }\n if (token) headers[\"Authorization\"] = `Bearer ${token}`\n\n try {\n const res = await fetch(url, { headers })\n if (!res.ok || !res.body) {\n console.error(chalk.red(` connect failed: HTTP ${res.status}`))\n process.exit(1)\n }\n console.log(chalk.green(` connected — Ctrl-C to stop`))\n console.log(\"\")\n\n // Parse SSE frames: `event: <kind>\\ndata: <payload>\\n\\n`.\n const reader = res.body.getReader()\n const dec = new TextDecoder()\n let buf = \"\"\n while (true) {\n const { done, value } = await reader.read()\n if (done) break\n buf += dec.decode(value, { stream: true })\n let idx: number\n while ((idx = buf.indexOf(\"\\n\\n\")) >= 0) {\n const frame = buf.slice(0, idx)\n buf = buf.slice(idx + 2)\n printFrame(frame)\n }\n }\n } catch (e: any) {\n console.error(chalk.red(` disconnected: ${e.message || e}`))\n process.exit(1)\n }\n })\n\nfunction printFrame(frame: string): void {\n let event = \"message\"\n let data = \"\"\n for (const line of frame.split(\"\\n\")) {\n if (line.startsWith(\"event: \")) event = line.slice(7)\n else if (line.startsWith(\"data: \")) data = line.slice(6)\n }\n if (!data) return\n let payload: any = {}\n try { payload = JSON.parse(data) } catch { /* print raw */ console.log(`${event}: ${data}`); return }\n\n const ts = payload.at ? chalk.dim(new Date(payload.at).toLocaleTimeString()) : \"\"\n switch (event) {\n case \"run\": {\n const tag = chalk.cyan(payload.phase?.padEnd(9) ?? \"run\")\n const wf = chalk.bold(payload.workflowId ?? \"\")\n const runShort = chalk.dim((payload.runId ?? \"\").slice(0, 8))\n const node = payload.nodeId ? chalk.yellow(payload.nodeId) : \"\"\n const note = payload.note ? chalk.dim(`— ${payload.note}`) : \"\"\n console.log(`${ts} ${tag} ${wf} ${runShort} ${node} ${note}`)\n break\n }\n case \"task\": {\n const tag = chalk.magenta(`task.${payload.phase}`.padEnd(14))\n const wf = chalk.bold(payload.workflowId ?? \"\")\n const actors = Array.isArray(payload.assignedTo) ? payload.assignedTo.join(\",\") : \"\"\n const title = payload.title ? chalk.dim(`\"${payload.title}\"`) : \"\"\n console.log(`${ts} ${tag} ${wf} ${chalk.cyan(actors)} ${title}`)\n break\n }\n case \"signal\": {\n const tag = chalk.green(\"signal\".padEnd(9))\n const name = chalk.bold(payload.name)\n const scope = chalk.dim(`(${payload.scope})`)\n const wf = payload.workflowId ? chalk.dim(payload.workflowId) : \"\"\n console.log(`${ts} ${tag} ${name} ${scope} ${wf}`)\n break\n }\n case \"mesh\": {\n const tag = chalk.blue(\"mesh\".padEnd(9))\n const peer = chalk.bold(payload.peer)\n const health = payload.healthy ? chalk.green(\"✓ healthy\") : chalk.red(\"✗ lost\")\n console.log(`${ts} ${tag} ${peer} ${health} ${chalk.dim(payload.delta ?? \"\")}`)\n break\n }\n case \"channel\": {\n const tag = chalk.yellow(\"channel\".padEnd(9))\n const dir = payload.direction === \"in\" ? chalk.cyan(\"←\") : chalk.magenta(\"→\")\n const label = chalk.bold(`${payload.channel}:${payload.chatId ?? \"\"}`)\n const preview = payload.textPreview ? chalk.dim(payload.textPreview) : \"\"\n console.log(`${ts} ${tag} ${dir} ${label} ${preview}`)\n break\n }\n case \"status\": {\n console.log(chalk.dim(`${ts} status ${payload.node ?? \"\"} agents=${payload.agents ?? 0} active=${(payload.active ?? []).length} peers=${(payload.mesh ?? []).length}`))\n break\n }\n default:\n console.log(`${ts} ${event} ${JSON.stringify(payload)}`)\n }\n}\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { deprecationNotice, CHAT_SURFACE_DEPRECATION } from \"./deprecation\"\n\n// `agentx tui` — read-only mission-control view over the running daemon.\n//\n// Mounts an Ink app that polls /agents, /api/processes, /crons and\n// streams /events. Intentionally minimal in v0: no chat composer, no\n// kill/cancel; those land in v1 once the layout is settled.\n\nexport const tui = new Command()\n .name(\"tui\")\n .description(\"[deprecated — see agentx attach] interactive terminal mission control\")\n .option(\"-c, --config <path>\", \"daemon config file\")\n .option(\"--node <url>\", \"daemon URL (defaults to dashboard.daemonUrl from config)\")\n .option(\"--token <token>\", \"bearer token (defaults to dashboard.token from config)\")\n .option(\"--poll <ms>\", \"snapshot poll interval in ms\", \"3000\")\n .action(async (opts) => {\n deprecationNotice({ what: \"agentx tui\", ...CHAT_SURFACE_DEPRECATION })\n if (!process.stdout.isTTY) {\n console.error(chalk.red(\"agentx tui requires an interactive terminal\"))\n process.exit(1)\n }\n // Defer-load Ink + the app so non-TUI commands don't pay the React/Ink\n // import cost.\n const { resolveConn } = await import(\"@/tui/client\")\n const { App } = await import(\"@/tui/App\")\n const { render } = await import(\"ink\")\n const React = (await import(\"react\")).default\n\n const conn = resolveConn({ node: opts.node, token: opts.token, config: opts.config })\n const pollMs = Math.max(500, Number(opts.poll) || 3000)\n const instance = render(React.createElement(App, { conn, pollMs }))\n await instance.waitUntilExit()\n })\n","import chalk from \"chalk\"\n\n// --- Deprecation notices ---\n//\n// A surface is deprecated when the evidence says nobody uses it AND something\n// better exists. Both halves matter: dropping a capability because it is\n// unpopular is how tools get worse. Replacing one because it lost to a better\n// host is how they get simpler.\n//\n// See docs/architecture/surface-reduction.md for the fleet usage data behind\n// each entry here.\n//\n// The notice is a warning, never a block. The command still runs — an operator\n// mid-incident should never be stopped by a message about roadmaps.\n\nexport interface Deprecation {\n /** What is going away. */\n what: string\n /** Why, in one line an operator can evaluate. Cite evidence, not opinion. */\n why: string\n /** What to do instead, as a runnable command where possible. */\n instead: string\n /** Extra context worth one more line. */\n note?: string\n}\n\nexport function deprecationNotice(d: Deprecation): void {\n console.error()\n console.error(chalk.yellow(` ⚠ ${d.what} is deprecated.`))\n console.error(chalk.dim(` ${d.why}`))\n console.error()\n console.error(` Use ${chalk.cyan(d.instead)} instead.`)\n if (d.note) console.error(chalk.dim(` ${d.note}`))\n console.error()\n}\n\n/** `agentx chat` and `agentx tui` — the two terminal chat surfaces. Both went\n * unused on every node in the fleet after 2026-07-03. They lost to Claude\n * Code, and attach mode is the answer: rather than a third attempt at a chat\n * client, let the client people already prefer wear the agent identity. */\nexport const CHAT_SURFACE_DEPRECATION: Omit<Deprecation, \"what\"> = {\n why: \"No recorded use on any node since 2026-07-03.\",\n instead: \"agentx attach <agent>\",\n note: \"Wears the identity in the Claude Code session you already have open — see docs/reference/attach.md\",\n}\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { randomUUID } from \"crypto\"\nimport { createInterface } from \"node:readline/promises\"\nimport ora from \"ora\"\nimport { resolveConn, streamTask, fetchAgents, type AgentRow } from \"@/tui/client\"\nimport { deprecationNotice, CHAT_SURFACE_DEPRECATION } from \"./deprecation\"\n\n// `agentx chat @agent` — daemon-mediated REPL.\n//\n// Multi-turn conversation with a daemon-registered agent over POST /task.\n// We synthesize a stable (channel, chatId) per session so the daemon's\n// process registry keeps the agent's claude process warm across turns —\n// no cold spawn per message, no provider config duplicated in the CLI.\n//\n// Special commands at the prompt:\n// /exit, /quit leave the REPL\n// /clear start a fresh chatId (drops warm process)\n// /agent <id> switch the target agent for the next turn\n// /who print current target + chatId\n// /agents list registered agents\n\nexport const chat = new Command()\n .name(\"chat\")\n .description(\"[deprecated — see agentx attach] interactive chat with a daemon-registered agent\")\n .argument(\"[agent]\", \"agent id to talk to (with or without leading @)\")\n .option(\"-c, --config <path>\", \"daemon config file\")\n .option(\"--node <url>\", \"daemon URL (defaults to dashboard.daemonUrl from config)\")\n .option(\"--token <token>\", \"bearer token (defaults to dashboard.token from config)\")\n .option(\"--channel <name>\", \"logical channel name passed in context\", \"chat-cli\")\n .option(\"--chat-id <id>\", \"resume an existing chatId (otherwise a fresh one is generated)\")\n .action(async (agentArg: string | undefined, opts) => {\n deprecationNotice({ what: \"agentx chat\", ...CHAT_SURFACE_DEPRECATION })\n const conn = resolveConn({ node: opts.node, token: opts.token, config: opts.config })\n let agentId = (agentArg ?? \"\").replace(/^@/, \"\").trim()\n const channel: string = opts.channel\n let chatId: string = opts.chatId || `chat-cli:${randomUUID().slice(0, 12)}`\n\n // Confirm the daemon is reachable and the requested agent exists. We\n // pull the registry up front to give a useful error before the first\n // turn — and to default to the first available agent if none was given.\n let agents: AgentRow[] = []\n try {\n agents = await fetchAgents(conn)\n } catch (e: any) {\n console.error(chalk.red(` cannot reach daemon at ${conn.baseUrl}: ${e?.message || e}`))\n console.error(chalk.dim(` is the daemon running? try: agentx daemon status`))\n process.exit(1)\n }\n if (agents.length === 0) {\n console.error(chalk.red(\" no agents registered with the daemon\"))\n process.exit(1)\n }\n if (!agentId) {\n agentId = agents[0].id\n console.log(chalk.dim(` no agent given — defaulting to @${agentId}`))\n } else if (!agents.find((a) => a.id === agentId)) {\n console.error(chalk.red(` unknown agent: @${agentId}`))\n console.error(chalk.dim(` registered: ${agents.map((a) => `@${a.id}`).join(\", \")}`))\n process.exit(1)\n }\n\n // Interactive terminal → rich Ink REPL (streaming, markdown, tool\n // badges, history). Non-TTY (piped/scripted) → the plain streaming\n // fallback below, which stays scriptable.\n if (process.stdout.isTTY && process.stdin.isTTY) {\n const { render } = await import(\"ink\")\n const { ChatApp } = await import(\"@/tui/ChatApp\")\n const React = (await import(\"react\")).default\n // The Ink app is a full-height layout (welcome/empty-state lives inside\n // it), so no pre-render banner — that would push the layout off-screen.\n const instance = render(React.createElement(ChatApp, { conn, agentId, channel, chatId, agents }))\n await instance.waitUntilExit()\n return\n }\n\n printBanner(conn.baseUrl, agentId, chatId, channel)\n\n const rl = createInterface({ input: process.stdin, output: process.stdout })\n // Don't hard-exit mid-turn: if stdin closes (Ctrl-D / piped EOF) while a\n // reply is streaming, let the in-flight turn finish, then quit.\n let busy = false\n let closeRequested = false\n rl.on(\"close\", () => {\n if (busy) { closeRequested = true; return }\n console.log(chalk.dim(\"\\n bye\"))\n process.exit(0)\n })\n\n while (true) {\n let line: string\n try {\n line = (await rl.question(chalk.cyan(`you › `))).trim()\n } catch {\n // SIGINT during input — readline rejects.\n rl.close()\n return\n }\n if (!line) continue\n\n if (line === \"/exit\" || line === \"/quit\") { rl.close(); return }\n if (line === \"/who\") {\n console.log(chalk.dim(` @${agentId} chatId=${chatId} channel=${channel}`))\n continue\n }\n if (line === \"/clear\") {\n chatId = `chat-cli:${randomUUID().slice(0, 12)}`\n console.log(chalk.dim(` fresh chatId=${chatId} (warm process dropped)`))\n continue\n }\n if (line === \"/agents\") {\n try {\n const fresh = await fetchAgents(conn)\n for (const a of fresh) {\n const marker = a.id === agentId ? chalk.green(\"●\") : chalk.dim(\"○\")\n console.log(` ${marker} @${a.id} ${chalk.dim(a.tier)} ${a.model ?? \"\"}`)\n }\n } catch (e: any) {\n console.error(chalk.red(` failed to list agents: ${e?.message || e}`))\n }\n continue\n }\n if (line.startsWith(\"/agent \")) {\n const next = line.slice(\"/agent \".length).replace(/^@/, \"\").trim()\n if (!next) { console.log(chalk.red(\" usage: /agent <id>\")); continue }\n // Re-fetch to validate against the live registry.\n try {\n const fresh = await fetchAgents(conn)\n if (!fresh.find((a) => a.id === next)) {\n console.log(chalk.red(` unknown agent: @${next}`))\n continue\n }\n agentId = next\n console.log(chalk.dim(` now talking to @${agentId}`))\n } catch (e: any) {\n console.error(chalk.red(` failed to switch agent: ${e?.message || e}`))\n }\n continue\n }\n if (line.startsWith(\"/\")) {\n console.log(chalk.red(` unknown command: ${line.split(/\\s+/)[0]}`))\n console.log(chalk.dim(` available: /exit /quit /clear /agent <id> /who /agents`))\n continue\n }\n\n busy = true\n const spinner = ora({ text: `@${agentId}…`, color: \"cyan\" }).start()\n const startedAt = Date.now()\n const render = createStreamRenderer(agentId)\n try {\n const r = await streamTask(conn, agentId, line, {\n channel,\n chatId,\n onText: (t) => { spinner.stop(); render.text(t) },\n onThinking: () => { /* reasoning lane — kept quiet in the MVP */ },\n onTool: (tool) => { spinner.stop(); render.tool(tool) },\n })\n spinner.stop()\n const elapsed = Math.round((Date.now() - startedAt) / 100) / 10\n if (r.error) {\n render.finishError(r.error)\n } else {\n render.finish(elapsed, r.usage)\n }\n } catch (e: any) {\n spinner.stop()\n render.finishError(e?.message || String(e))\n } finally {\n busy = false\n }\n if (closeRequested) { console.log(chalk.dim(\" bye\")); return }\n }\n })\n\n/** Stateful renderer for one streamed reply. Streams text deltas with a\n * hanging 2-space indent and prints Claude-Code-style `● tool` badges as\n * the agent works — interleaving cleanly by tracking line position. */\nfunction createStreamRenderer(agentId: string) {\n let headerShown = false\n let atLineStart = true\n let anyText = false\n const seenTools = new Set<string>()\n\n const header = () => {\n if (headerShown) return\n process.stdout.write(`${chalk.green(`@${agentId}`)}\\n`)\n headerShown = true\n }\n\n return {\n /** Write a streamed text delta, indenting each new line by two spaces. */\n text(delta: string) {\n if (!delta) return\n header()\n anyText = true\n for (const ch of delta) {\n if (atLineStart && ch !== \"\\n\") { process.stdout.write(\" \"); atLineStart = false }\n process.stdout.write(ch)\n if (ch === \"\\n\") atLineStart = true\n }\n },\n /** Print a tool-call badge (once per tool invocation id). */\n tool(t: { status: \"start\" | \"result\"; id?: string; name?: string; error?: boolean; arg?: string }) {\n header()\n if (t.status === \"start\" && t.name) {\n const key = t.id || `${t.name}:${seenTools.size}`\n if (seenTools.has(key)) return\n seenTools.add(key)\n if (!atLineStart) { process.stdout.write(\"\\n\"); atLineStart = true }\n const arg = t.arg ? chalk.dim(`(${t.arg})`) : \"\"\n process.stdout.write(` ${chalk.green(\"●\")} ${chalk.bold(t.name)}${arg}\\n`)\n } else if (t.status === \"result\" && t.error) {\n if (!atLineStart) { process.stdout.write(\"\\n\"); atLineStart = true }\n process.stdout.write(` ${chalk.red(\"●\")} ${chalk.dim(`${t.name ?? \"tool\"} failed`)}\\n`)\n }\n },\n /** Close the turn: ensure a trailing newline + a dim timing/usage footer. */\n finish(elapsedS: number, usage?: Record<string, number>) {\n if (!headerShown) { process.stdout.write(`${chalk.green(`@${agentId}`)} ${chalk.dim(\"· (empty reply)\")}\\n\\n`); return }\n if (!atLineStart) process.stdout.write(\"\\n\")\n const out = usage?.outputTokens != null ? `, ${usage.outputTokens} tok` : \"\"\n process.stdout.write(chalk.dim(` · ${elapsedS}s${out}\\n\\n`))\n void anyText\n },\n finishError(msg: string) {\n if (headerShown && !atLineStart) process.stdout.write(\"\\n\")\n process.stdout.write(chalk.red(` ✗ ${msg}\\n\\n`))\n },\n }\n}\n\nfunction printBanner(baseUrl: string, agentId: string, chatId: string, channel: string) {\n console.log()\n console.log(chalk.bold(` agentx chat`))\n console.log(chalk.dim(` daemon: ${baseUrl} · channel: ${channel} · chatId: ${chatId}`))\n console.log(chalk.dim(` agent: @${agentId} · /exit to quit · /agent <id> to switch`))\n console.log()\n}\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { readFileSync } from \"fs\"\nimport { AgentMemory, type MemoryType } from \"@/agents/agent-memory\"\n\n// --- agentx memory — audit + edit an agent's structured memory ---\n//\n// Structured memory is Claude-Code-style:\n// user: who the user is, their role, preferences\n// feedback: rules the user gave me; what to do / avoid\n// project: facts about current work the code can't reveal\n// reference: pointers to external systems (linear, grafana, …)\n//\n// Each entry is a small markdown file with frontmatter. MEMORY.md is\n// auto-generated as the index and inlined into every task's system\n// prompt, so agents see everything they've learned on every turn.\n\nconst VALID_TYPES: MemoryType[] = [\"user\", \"feedback\", \"project\", \"reference\"]\n\nexport const memory = new Command()\n .name(\"memory\")\n .description(\"audit + edit agent-memory (per-agent experiential notes)\")\n\nmemory\n .command(\"add\")\n .description(\"add a memory for an agent\")\n .requiredOption(\"--agent <id>\", \"agent id\")\n .requiredOption(\"--type <type>\", \"one of: user, feedback, project, reference\")\n .requiredOption(\"--name <slug>\", \"short slug, unique per agent (e.g. deep-backend)\")\n .requiredOption(\"--description <line>\", \"one-line hook shown in MEMORY.md\")\n .option(\"--body <text>\", \"memory body (markdown); repeat --body or use --file\")\n .option(\"--file <path>\", \"read body from a file (use '-' for stdin)\")\n .action(async (opts: { agent: string; type: string; name: string; description: string; body?: string; file?: string }) => {\n if (!VALID_TYPES.includes(opts.type as MemoryType)) {\n console.error(chalk.red(` --type must be one of: ${VALID_TYPES.join(\", \")}`))\n process.exitCode = 1; return\n }\n let body = opts.body ?? \"\"\n if (opts.file) {\n if (opts.file === \"-\") {\n body = await readStdin()\n } else {\n try { body = readFileSync(opts.file, \"utf-8\") }\n catch (e: any) { console.error(chalk.red(` could not read --file: ${e.message}`)); process.exitCode = 1; return }\n }\n }\n if (!body.trim()) {\n console.error(chalk.red(\" memory body is required (use --body or --file)\"))\n process.exitCode = 1; return\n }\n const store = new AgentMemory()\n const rec = store.save({\n agentId: opts.agent,\n type: opts.type as MemoryType,\n name: opts.name,\n description: opts.description,\n body,\n })\n console.log(chalk.green(` ✓ memory \"${rec.name}\" saved (${rec.type}) for agent ${opts.agent}`))\n })\n\nmemory\n .command(\"list\")\n .description(\"list memories for an agent\")\n .requiredOption(\"--agent <id>\", \"agent id\")\n .option(\"--type <type>\", \"filter by memory type\")\n .action((opts: { agent: string; type?: string }) => {\n const store = new AgentMemory()\n let records = store.list(opts.agent)\n if (opts.type) {\n if (!VALID_TYPES.includes(opts.type as MemoryType)) {\n console.error(chalk.red(` --type must be one of: ${VALID_TYPES.join(\", \")}`))\n process.exitCode = 1; return\n }\n records = records.filter((r) => r.type === opts.type)\n }\n if (!records.length) {\n console.log(chalk.dim(` no memories for agent \"${opts.agent}\"${opts.type ? ` of type \"${opts.type}\"` : \"\"}`))\n return\n }\n console.log()\n let currentType: string | null = null\n for (const r of records) {\n if (r.type !== currentType) {\n console.log(chalk.bold(` ${r.type}`))\n currentType = r.type\n }\n console.log(` ${chalk.cyan(r.name.padEnd(28))} ${r.description}`)\n }\n console.log()\n console.log(chalk.dim(` ${records.length} memor${records.length === 1 ? \"y\" : \"ies\"} for ${opts.agent}`))\n })\n\nmemory\n .command(\"show\")\n .description(\"print the full body of a memory\")\n .requiredOption(\"--agent <id>\", \"agent id\")\n .argument(\"<name>\", \"memory name (slug)\")\n .action((name: string, opts: { agent: string }) => {\n const store = new AgentMemory()\n const rec = store.get(opts.agent, name)\n if (!rec) {\n console.error(chalk.red(` no memory \"${name}\" for agent \"${opts.agent}\"`))\n process.exitCode = 1; return\n }\n console.log(chalk.bold(`${rec.type}/${rec.name}`) + chalk.dim(` (${rec.description})`))\n console.log(chalk.dim(` updated ${rec.updatedAt}`))\n console.log()\n console.log(rec.body)\n })\n\nmemory\n .command(\"remove\")\n .alias(\"rm\")\n .description(\"remove a memory\")\n .requiredOption(\"--agent <id>\", \"agent id\")\n .argument(\"<name>\", \"memory name (slug)\")\n .action((name: string, opts: { agent: string }) => {\n const store = new AgentMemory()\n if (!store.remove(opts.agent, name)) {\n console.error(chalk.red(` no memory \"${name}\" for agent \"${opts.agent}\"`))\n process.exitCode = 1; return\n }\n console.log(chalk.green(` ✓ memory \"${name}\" removed`))\n })\n\nmemory\n .command(\"index\")\n .description(\"print the MEMORY.md index content an agent sees in its prompt\")\n .requiredOption(\"--agent <id>\", \"agent id\")\n .action((opts: { agent: string }) => {\n const store = new AgentMemory()\n const md = store.indexMarkdown(opts.agent)\n if (!md) {\n console.log(chalk.dim(` (no memories — MEMORY.md is empty for agent \"${opts.agent}\")`))\n return\n }\n console.log(md)\n })\n\nasync function readStdin(): Promise<string> {\n const chunks: Buffer[] = []\n for await (const chunk of process.stdin) chunks.push(chunk as Buffer)\n return Buffer.concat(chunks).toString(\"utf-8\")\n}\n","import { handleError } from \"@/utils/handle-error\"\nimport { logger } from \"@/utils/logger\"\nimport { startMcpServer } from \"@/mcp\"\nimport chalk from \"chalk\"\nimport { Command } from \"commander\"\nimport { resolve } from \"path\"\n\n// --- `agentx serve` — run as MCP server for AI editors ---\n\nexport const serve = new Command()\n .name(\"serve\")\n .description(\"run agentx as an MCP server for AI editors (Claude Code, Cursor, Windsurf, etc.)\")\n .option(\"--stdio\", \"use stdio transport (default)\", true)\n .option(\n \"-c, --cwd <cwd>\",\n \"working directory\",\n process.cwd()\n )\n .action(async (opts) => {\n try {\n process.chdir(resolve(opts.cwd))\n if (opts.stdio !== false) {\n // stdio mode — all logging goes to stderr, stdout is JSON-RPC\n await startMcpServer()\n } else {\n logger.error(\"Only stdio transport is currently supported.\")\n logger.info(\n `Usage: ${chalk.green(\"agentx serve --stdio\")} or configure in your MCP client.`\n )\n logger.break()\n logger.info(\"Add to Claude Code:\")\n logger.info(\n chalk.dim(\n ' claude mcp add agentx -- npx agentx serve --stdio'\n )\n )\n logger.break()\n logger.info(\"Add to Cursor/MCP config:\")\n logger.info(\n chalk.dim(\n JSON.stringify(\n {\n mcpServers: {\n agentx: {\n command: \"npx\",\n args: [\"agentx\", \"serve\", \"--stdio\"],\n },\n },\n },\n null,\n 2\n )\n )\n )\n }\n } catch (error) {\n handleError(error)\n }\n })\n","// --- agentx demo: the zero-key mesh walkthrough ---\n//\n// Boots three real daemons on loopback ports, pairs them into a real\n// A2A mesh (bearer-token verified), and plays a scripted scenario\n// through the genuine plumbing: /task dispatch on node A, a mesh hop\n// to node B via /send/agent, and a wrap-up turn — every step visible\n// in the /live dashboards and recorded in each node's intent ledger.\n//\n// Honesty contract: the ONLY fake thing is the model (a scripted\n// provider, src/agent/providers/demo.ts). Daemons, HTTP, mesh\n// discovery, auth, ledger rows: all real. The banner says so.\n\nimport { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { spawn, type ChildProcess } from \"child_process\"\nimport { mkdirSync, writeFileSync, rmSync, openSync, existsSync } from \"fs\"\nimport { resolve, join } from \"path\"\nimport { randomBytes } from \"crypto\"\n\ninterface NodeSpec {\n dir: string\n id: string\n name: string\n port: number\n agentId: string\n agentName: string\n persona: string\n script: object\n}\n\nconst KICKOFF = \"[demo] Customer reports checkout is broken and CI is red on demo/shop. Handle it.\"\nconst DELEGATION = \"CI is red on demo/shop — checkout.test.ts failing on Node 22. Diagnose, fix, and report back.\"\n\nfunction buildSpecs(root: string, basePort: number): NodeSpec[] {\n return [\n {\n dir: join(root, \"node-a\"),\n id: \"demo-laptop\",\n name: \"laptop-paris\",\n port: basePort,\n agentId: \"cx\",\n agentName: \"CX\",\n persona: \"You are CX, the customer-facing coordinator. You triage inbound issues and delegate technical work to @builder on the vps node.\",\n script: {\n steps: [\n {\n match: \"checkout is broken\",\n thinking: \"Checkout failure + red CI — this is a build problem, not a support question. @builder on vps-nyc owns demo/shop.\",\n reply:\n \"Checkout failure traced to the red pipeline on demo/shop. This needs a code fix — delegating to @builder on the vps-nyc node over the mesh. I'll report back on this thread.\",\n delayMs: 900,\n },\n {\n match: \"Builder reports\",\n thinking: \"Fix confirmed and pipeline green — close the loop with the customer.\",\n reply:\n \"Resolved ✅ — builder patched checkout.test.ts (Node 22 crypto import), MR !47 merged, pipeline green. Customer thread updated. Every hop of this run is in the ledger: `agentx ledger`.\",\n delayMs: 800,\n },\n ],\n fallback: {\n reply: \"Demo mode — I answer from a script. Try the scripted scenario, or run `agentx setup` to connect a real model.\",\n },\n },\n },\n {\n dir: join(root, \"node-b\"),\n id: \"demo-vps\",\n name: \"vps-nyc\",\n port: basePort + 1,\n agentId: \"builder\",\n agentName: \"Builder\",\n persona: \"You are Builder, the engineering agent on the vps node. You fix code, open MRs, and report results tersely.\",\n script: {\n steps: [\n {\n match: \"checkout\\\\.test\\\\.ts|CI is red\",\n thinking: \"Reproducing on Node 22… crypto.webcrypto import moved. Patching the test setup, rerunning the suite.\",\n reply:\n \"Fixed. checkout.test.ts assumed the legacy crypto.webcrypto import — patched for Node 22, suite green locally. Opened MR !47 on demo/shop; pipeline is green. Handing back to @cx.\",\n delayMs: 1400,\n chunkMs: 40,\n },\n ],\n fallback: { reply: \"Builder here (demo script). Send me a failing pipeline.\" },\n },\n },\n {\n dir: join(root, \"node-c\"),\n id: \"demo-pi\",\n name: \"pi-office\",\n port: basePort + 2,\n agentId: \"scout\",\n agentName: \"Scout\",\n persona: \"You are Scout, the monitoring agent on the office Raspberry Pi. You watch schedules and report status.\",\n script: {\n fallback: { reply: \"Scout here (demo script) — all monitors green on pi-office.\" },\n steps: [],\n },\n },\n ]\n}\n\nfunction writeNode(spec: NodeSpec, all: NodeSpec[], meshToken: string): void {\n const ws = join(spec.dir, \"workspaces\", spec.agentId)\n mkdirSync(ws, { recursive: true })\n writeFileSync(join(ws, \"CLAUDE.md\"), `# ${spec.agentName}\\n\\n${spec.persona}\\n`)\n writeFileSync(join(spec.dir, \"demo-script.json\"), JSON.stringify(spec.script, null, 2))\n\n const peers = all\n .filter((n) => n.id !== spec.id)\n .map((n) => ({ name: n.name, url: `http://127.0.0.1:${n.port}`, token: meshToken }))\n\n const config = {\n node: { id: spec.id, name: spec.name, bind: `127.0.0.1:${spec.port}`, defaultAgent: spec.agentId },\n // The dashboard block is read by the `agentx board serve` child the\n // demo starts for node A — it discovers the other nodes through the\n // daemon's /mesh directory, so one dashboard shows the whole mesh.\n dashboard: { enabled: true, port: spec.port + 10, bind: \"127.0.0.1\", daemonUrl: `http://127.0.0.1:${spec.port}` },\n providers: { demo: { apiKey: \"demo-mode\" } },\n agents: {\n [spec.agentId]: {\n name: spec.agentName,\n description: spec.persona,\n workspace: \"./workspaces/\" + spec.agentId,\n tier: \"orchestrator\",\n provider: \"demo\",\n mentions: [`@${spec.agentId}`, spec.agentId],\n maxConcurrent: 2,\n systemPrompt: spec.persona,\n },\n },\n mesh: { enabled: true, peers, discovery: \"static\", healthCheck: { interval: 3, timeout: 5 } },\n }\n writeFileSync(join(spec.dir, \"agentx.json\"), JSON.stringify(config, null, 2))\n}\n\nasync function waitFor(desc: string, fn: () => Promise<boolean>, timeoutMs: number): Promise<void> {\n const start = Date.now()\n while (Date.now() - start < timeoutMs) {\n try { if (await fn()) return } catch { /* not ready */ }\n await new Promise((r) => setTimeout(r, 500))\n }\n throw new Error(`Timed out waiting for ${desc} (${Math.round(timeoutMs / 1000)}s)`)\n}\n\nasync function post(port: number, path: string, body: object): Promise<any> {\n const res = await fetch(`http://127.0.0.1:${port}${path}`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n })\n const data: any = await res.json().catch(() => ({}))\n if (!res.ok || data.error) throw new Error(data.error || `${path} HTTP ${res.status}`)\n return data\n}\n\nfunction say(role: string, text: string, color: (s: string) => string): void {\n console.log()\n console.log(color(` ${role}`))\n console.log(` ${text.split(\"\\n\").join(\"\\n \")}`)\n}\n\nexport const demo = new Command()\n .name(\"demo\")\n .description(\"zero-key demo: three daemons, a real A2A mesh, a scripted scenario\")\n .option(\"--base-port <port>\", \"first of three consecutive loopback ports\", \"18921\")\n .option(\"--once\", \"play the scenario once and exit (default: keep daemons up until Ctrl-C)\")\n .option(\"--keep\", \"keep the .agentx-demo directory on exit\")\n .option(\"--no-open\", \"don't open the dashboard in a browser\")\n .action(async (opts) => {\n const basePort = parseInt(opts.basePort, 10)\n const root = resolve(process.cwd(), \".agentx-demo\")\n const specs = buildSpecs(root, basePort)\n const meshToken = randomBytes(24).toString(\"hex\")\n const children: ChildProcess[] = []\n\n const cli = process.argv[1]\n if (!cli || !existsSync(cli)) {\n console.error(chalk.red(\"Cannot resolve the agentx CLI entrypoint — run via the installed `agentx` binary.\"))\n process.exit(1)\n }\n\n if (existsSync(root)) rmSync(root, { recursive: true, force: true })\n for (const spec of specs) writeNode(spec, specs, meshToken)\n\n console.log()\n console.log(chalk.bold(\" agentx demo — one message, three machines (simulated on loopback)\"))\n console.log(chalk.yellow(\" Canned model responses. Real daemons, real A2A mesh, real ledger.\"))\n console.log(chalk.dim(\" Run `agentx setup` to wire real agents.\\n\"))\n\n let tearingDown = false\n const teardown = (code: number) => {\n if (tearingDown) return\n tearingDown = true\n for (const c of children) { try { c.kill(\"SIGTERM\") } catch { /* gone */ } }\n setTimeout(() => {\n if (!opts.keep) { try { rmSync(root, { recursive: true, force: true }) } catch { /* busy */ } }\n process.exit(code)\n }, 800)\n }\n process.on(\"SIGINT\", () => teardown(0))\n process.on(\"SIGTERM\", () => teardown(0))\n\n // Environment for the child daemons: demo script + shared mesh token.\n // Strip inherited model credentials so nothing real can be billed —\n // the demo must be able to say \"zero keys touched\" truthfully.\n const baseEnv = { ...process.env }\n delete baseEnv.ANTHROPIC_API_KEY\n delete baseEnv.ANTHROPIC_API_KEY_OLD\n delete baseEnv.OPENAI_API_KEY\n delete baseEnv.DEEPSEEK_API_KEY\n\n try {\n for (const spec of specs) {\n const logFd = openSync(join(spec.dir, \"daemon.log\"), \"a\")\n const child = spawn(process.execPath, [cli, \"daemon\", \"start\", \"-c\", join(spec.dir, \"agentx.json\")], {\n cwd: spec.dir,\n env: { ...baseEnv, MESH_TOKEN: meshToken, AGENTX_DEMO_SCRIPT: join(spec.dir, \"demo-script.json\") },\n stdio: [\"ignore\", logFd, logFd],\n })\n children.push(child)\n console.log(chalk.dim(` ▸ ${spec.name} starting on 127.0.0.1:${spec.port} (log: ${join(spec.dir, \"daemon.log\")})`))\n }\n\n for (const spec of specs) {\n await waitFor(`${spec.name} /health`, async () => {\n const r = await fetch(`http://127.0.0.1:${spec.port}/health`)\n return r.ok\n }, 30_000)\n }\n console.log(chalk.green(\" ✓ three daemons up\"))\n\n // One dashboard process, attached to laptop-paris — it discovers the\n // other two nodes over the mesh, so /live shows the whole fleet.\n const dashPort = specs[0].port + 10\n {\n const logFd = openSync(join(specs[0].dir, \"board.log\"), \"a\")\n const child = spawn(process.execPath, [cli, \"board\", \"serve\"], {\n cwd: specs[0].dir,\n env: { ...baseEnv, MESH_TOKEN: meshToken },\n stdio: [\"ignore\", logFd, logFd],\n })\n children.push(child)\n }\n await waitFor(\"dashboard /live\", async () => {\n const r = await fetch(`http://127.0.0.1:${dashPort}/live`)\n return r.ok\n }, 30_000)\n console.log(chalk.green(\" ✓ dashboard up\"))\n\n await waitFor(\"mesh discovery (laptop sees both peers)\", async () => {\n const r = await fetch(`http://127.0.0.1:${specs[0].port}/health`)\n const h: any = await r.json()\n const healthy = (h.mesh || []).filter((p: any) => p.healthy && p.skills?.length)\n return healthy.length >= 2\n }, 30_000)\n // Note: on loopback the daemon's mesh-auth gate exempts callers by\n // design, so don't claim token *verification* here — tokens are sent\n // and the gate is exercised only on non-loopback deployments.\n console.log(chalk.green(\" ✓ A2A mesh healthy — agent cards exchanged across three nodes\"))\n\n const liveUrl = `http://127.0.0.1:${dashPort}/live`\n console.log()\n console.log(` Dashboard: ${chalk.cyan(liveUrl)} (all three nodes via the mesh)`)\n console.log(chalk.dim(` Daemon APIs: ${specs.map((s) => `127.0.0.1:${s.port}`).join(\" · \")}`))\n\n if (opts.open !== false) {\n const opener = process.platform === \"darwin\" ? \"open\" : process.platform === \"win32\" ? \"start\" : \"xdg-open\"\n try { spawn(opener, [liveUrl], { stdio: \"ignore\", detached: true }).unref() } catch { /* headless */ }\n }\n\n const playScenario = async () => {\n console.log()\n console.log(chalk.bold(\" ── Scenario: red pipeline, cross-node fix ──\"))\n say(\"You → @cx (laptop-paris)\", KICKOFF, chalk.cyan)\n\n const s1 = await post(specs[0].port, \"/task\", { agent: \"cx\", message: KICKOFF })\n say(\"@cx (laptop-paris)\", s1.content || \"(no content)\", chalk.green)\n\n console.log()\n console.log(chalk.magenta(\" ⇄ mesh hop: laptop-paris → vps-nyc (A2A /task)\"))\n const s2 = await post(specs[0].port, \"/send/agent\", {\n agentId: \"builder\",\n senderAgentId: \"cx\",\n text: DELEGATION,\n })\n const builderReply = typeof s2.messageId === \"string\" ? s2.messageId : s2.content || \"(no reply)\"\n say(\"@builder (vps-nyc)\", builderReply, chalk.yellow)\n\n const s3 = await post(specs[0].port, \"/task\", {\n agent: \"cx\",\n message: `[demo] Builder reports: ${builderReply}`,\n })\n say(\"@cx (laptop-paris)\", s3.content || \"(no content)\", chalk.green)\n\n console.log()\n console.log(chalk.dim(` Inspect the run: ${liveUrl} · ledger rows on each node record every dispatch`))\n console.log(chalk.dim(` Worth your time? A star helps others find it: ${chalk.cyan(\"https://github.com/anis-marrouchi/agentx\")}`))\n }\n\n await playScenario()\n\n if (opts.once) {\n console.log()\n console.log(chalk.dim(\" --once: shutting down.\"))\n teardown(0)\n return\n }\n\n console.log()\n console.log(chalk.bold(\" Daemons stay up — browse the dashboards. Press Enter to replay, Ctrl-C to exit.\"))\n process.stdin.setEncoding(\"utf8\")\n process.stdin.on(\"data\", () => { playScenario().catch((e) => console.error(chalk.red(` Replay failed: ${e.message}`))) })\n process.stdin.resume()\n } catch (e: any) {\n console.error()\n console.error(chalk.red(` Demo failed: ${e.message}`))\n console.error(chalk.dim(` Node logs: ${specs.map((s) => join(s.dir, \"daemon.log\")).join(\", \")}`))\n teardown(1)\n }\n })\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { loadDaemonConfig } from \"@/daemon/config\"\n\n// --- agentx whatsapp: list & ingest WhatsApp data into the wiki ---\n//\n// Talks to the running daemon's HTTP API (same pattern as `agentx usage`).\n// The daemon owns the Baileys socket; the CLI is just a thin client that\n// renders the results. Keeps auth state on the daemon and avoids making\n// the CLI ship Baileys + pair-again.\n\nexport const whatsapp = new Command()\n .name(\"whatsapp\")\n .description(\"list WhatsApp chats/contacts and ingest them into the wiki as a data source\")\n\nwhatsapp\n .command(\"list-chats\")\n .description(\"list chats observed by the WhatsApp socket (cached, no live fetch)\")\n .option(\"--format <format>\", \"output format: table | json\", \"table\")\n .option(\"--group\", \"groups only\")\n .option(\"--dm\", \"DMs only\")\n .action(async (opts) => {\n try {\n const data = await getJSON(\"/whatsapp/chats\") as { chats?: Array<any> }\n let chats = data.chats ?? []\n if (opts.group) chats = chats.filter((c) => c.isGroup)\n if (opts.dm) chats = chats.filter((c) => !c.isGroup)\n if (opts.format === \"json\") {\n console.log(JSON.stringify(chats, null, 2))\n return\n }\n if (chats.length === 0) { console.log(chalk.dim(\" no chats cached yet\")); return }\n console.log()\n console.log(chalk.bold(` ${chats.length} chat${chats.length === 1 ? \"\" : \"s\"}`))\n console.log()\n for (const c of chats) {\n const kind = c.isGroup ? chalk.cyan(\"group\") : chalk.dim(\"dm\")\n const when = c.lastMessageAt ? new Date(c.lastMessageAt * 1000).toISOString().slice(0, 16).replace(\"T\", \" \") : \"—\"\n console.log(` ${kind} ${c.name.padEnd(30)} ${chalk.dim(c.jid.padEnd(40))} ${chalk.dim(when)}`)\n }\n console.log()\n } catch (e: any) {\n fail(e)\n }\n })\n\nwhatsapp\n .command(\"list-contacts\")\n .description(\"list contacts observed by the WhatsApp socket (cached, no live fetch)\")\n .option(\"--format <format>\", \"output format: table | json\", \"table\")\n .action(async (opts) => {\n try {\n const data = await getJSON(\"/whatsapp/contacts\") as { contacts?: Array<any> }\n const contacts = data.contacts ?? []\n if (opts.format === \"json\") {\n console.log(JSON.stringify(contacts, null, 2))\n return\n }\n if (contacts.length === 0) { console.log(chalk.dim(\" no contacts cached yet\")); return }\n console.log()\n console.log(chalk.bold(` ${contacts.length} contact${contacts.length === 1 ? \"\" : \"s\"}`))\n console.log()\n for (const c of contacts) {\n const name = (c.name || c.pushName || c.phone || c.jid).padEnd(30)\n const phone = c.phone ? `+${c.phone}`.padEnd(16) : \"—\".padEnd(16)\n console.log(` ${name} ${chalk.dim(phone)} ${chalk.dim(c.jid)}`)\n }\n console.log()\n } catch (e: any) {\n fail(e)\n }\n })\n\nwhatsapp\n .command(\"ingest-all\")\n .description(\"run a full ingest sweep against the configured allowlist (writes raw wiki entries)\")\n .option(\"--dry-run\", \"compute entries without writing them — review before enabling\")\n .option(\"--agent <id>\", \"owner agent for the entries (defaults to channels.whatsapp.defaultAgent)\")\n .option(\"--force\", \"bypass the channels.whatsapp.ingest.enabled guard\")\n .action(async (opts) => {\n try {\n const body: Record<string, unknown> = { dryRun: !!opts.dryRun, force: !!opts.force }\n if (opts.agent) body.agent = opts.agent\n const report = await postJSON(\"/whatsapp/ingest\", body)\n printReport(report, !!opts.dryRun)\n } catch (e: any) {\n fail(e)\n }\n })\n\nwhatsapp\n .command(\"ingest-contact <jid>\")\n .description(\"ingest one contact (skips scope allowlist for this JID only)\")\n .option(\"--dry-run\", \"compute entries without writing them\")\n .option(\"--agent <id>\", \"owner agent for the entries\")\n .action(async (jid, opts) => {\n try {\n const body: Record<string, unknown> = { dryRun: !!opts.dryRun, force: true, onlyJid: jid, onlyKind: \"contact\" }\n if (opts.agent) body.agent = opts.agent\n const report = await postJSON(\"/whatsapp/ingest\", body)\n printReport(report, !!opts.dryRun)\n } catch (e: any) {\n fail(e)\n }\n })\n\nwhatsapp\n .command(\"ingest-chat <jid>\")\n .description(\"ingest one chat (DM or group) including message window if `--messages` is set\")\n .option(\"--dry-run\", \"compute entries without writing them\")\n .option(\"--messages\", \"include the bounded message window for this chat (overrides config mode)\")\n .option(\"--agent <id>\", \"owner agent for the entries\")\n .action(async (jid, opts) => {\n try {\n const body: Record<string, unknown> = { dryRun: !!opts.dryRun, force: true, onlyJid: jid }\n if (opts.agent) body.agent = opts.agent\n if (opts.messages) body.forceMode = \"messages\"\n const report = await postJSON(\"/whatsapp/ingest\", body)\n printReport(report, !!opts.dryRun)\n } catch (e: any) {\n fail(e)\n }\n })\n\nwhatsapp\n .command(\"status\")\n .description(\"show WhatsApp channel + ingest status\")\n .action(async () => {\n try {\n const state = await getJSON(\"/whatsapp/state\")\n const chats = await getJSON(\"/whatsapp/chats\") as { chats?: any[] }\n const contacts = await getJSON(\"/whatsapp/contacts\") as { contacts?: any[] }\n console.log()\n console.log(chalk.bold(\" WhatsApp status\"))\n console.log()\n console.log(` connection: ${(state as any).connection || \"—\"}`)\n console.log(` cached chats: ${chats.chats?.length ?? 0}`)\n console.log(` cached contacts: ${contacts.contacts?.length ?? 0}`)\n console.log()\n } catch (e: any) {\n fail(e)\n }\n })\n\nfunction printReport(report: any, dryRun: boolean): void {\n console.log()\n console.log(chalk.bold(dryRun ? \" Ingest (dry-run)\" : \" Ingest report\"))\n console.log()\n console.log(` scanned: contacts=${report.scannedContacts}, groups=${report.scannedGroups}`)\n console.log(` wrote: contacts=${report.wroteContacts}, groups=${report.wroteGroups}, dm-windows=${report.wroteDmWindows}, group-windows=${report.wroteGroupWindows}`)\n if (report.skippedUnchanged) console.log(` skipped: ${report.skippedUnchanged} unchanged`)\n if (report.errors?.length) {\n console.log(chalk.yellow(` errors: ${report.errors.length}`))\n for (const err of report.errors.slice(0, 5)) {\n console.log(chalk.yellow(` - [${err.kind}] ${err.jid}: ${err.message}`))\n }\n }\n if (dryRun && report.dryRunEntries?.length) {\n console.log()\n console.log(chalk.dim(\" would-be entries:\"))\n for (const e of report.dryRunEntries.slice(0, 10)) {\n console.log(chalk.dim(` - ${e.id} (${e.source}, ${e.content.length} bytes)`))\n }\n if (report.dryRunEntries.length > 10) console.log(chalk.dim(` …and ${report.dryRunEntries.length - 10} more`))\n }\n console.log()\n}\n\nfunction daemonUrl(): string {\n try {\n const config = loadDaemonConfig()\n const [host, port] = config.node.bind.split(\":\")\n return `http://${host || \"127.0.0.1\"}:${port || \"19900\"}`\n } catch {\n return \"http://127.0.0.1:19900\"\n }\n}\n\nasync function getJSON(path: string): Promise<unknown> {\n const r = await fetch(`${daemonUrl()}${path}`, { signal: AbortSignal.timeout(10_000) })\n const data = await r.json().catch(() => ({}))\n if (!r.ok) throw new Error((data as any).error || `HTTP ${r.status}`)\n return data\n}\n\nasync function postJSON(path: string, body: unknown): Promise<any> {\n const r = await fetch(`${daemonUrl()}${path}`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n signal: AbortSignal.timeout(10 * 60_000),\n })\n const data = await r.json().catch(() => ({}))\n if (!r.ok) throw new Error((data as any).error || `HTTP ${r.status}`)\n return data\n}\n\nfunction fail(e: any): never {\n console.error(chalk.red(` ${e.message || e}`))\n process.exit(1)\n}\n","import { Command } from \"commander\"\nimport chalk from \"chalk\"\nimport { existsSync, mkdirSync, writeFileSync } from \"fs\"\nimport { join, resolve } from \"path\"\nimport { loadDaemonConfig } from \"@/daemon/config\"\nimport { agentXPluginManifestSchema, type AgentXPlugin } from \"@/plugins/types\"\n\n// `agentx plugin` — surface the plugin loader's view from outside the\n// daemon. `list` shows the configured packages; `doctor` actually\n// imports them and reports whether the manifest validates without\n// starting the daemon. Useful for operators to validate before\n// restarting and useful in CI to catch a broken plugin install.\n\nexport const plugin = new Command()\n .name(\"plugin\")\n .description(\"manage agentx plugins (Move B)\")\n\nplugin\n .command(\"list\", { isDefault: true })\n .description(\"list plugins configured in agentx.json\")\n .action(() => {\n try {\n const config = loadDaemonConfig()\n const names = config.plugins ?? []\n console.log()\n if (names.length === 0) {\n console.log(chalk.dim(\" No plugins configured.\"))\n console.log(chalk.dim(\" Add a plugin: edit agentx.json's `plugins: [\\\"your-package\\\"]` and pnpm install it.\"))\n console.log()\n return\n }\n console.log(chalk.bold(` Plugins configured: ${names.length}`))\n console.log()\n for (const n of names) {\n console.log(` ${chalk.cyan(n)}`)\n }\n console.log()\n console.log(chalk.dim(\" Run `agentx plugin doctor` to verify each plugin loads.\"))\n console.log()\n } catch (e: any) {\n console.log(chalk.red(` ${e.message}`))\n process.exitCode = 1\n }\n })\n\nplugin\n .command(\"init <name>\")\n .description(\"scaffold a new plugin package (npm-publishable, with manifest + setup hook)\")\n .option(\"--cwd <cwd>\", \"directory to create the package under\", process.cwd())\n .option(\"--description <text>\", \"short package description\")\n .option(\"--force\", \"overwrite an existing directory\")\n .action((name: string, opts) => {\n if (!/^(@[a-z0-9-]+\\/)?[a-z0-9][a-z0-9._-]*$/i.test(name)) {\n console.log(chalk.red(` invalid package name \"${name}\". Use lowercase letters, digits, hyphens; optional @scope/ prefix.`))\n process.exit(1)\n }\n const dirName = name.startsWith(\"@\") ? name.split(\"/\")[1] : name\n const target = resolve(opts.cwd, dirName)\n if (existsSync(target) && !opts.force) {\n console.log(chalk.red(` ${target} already exists. Use --force to overwrite.`))\n process.exit(1)\n }\n mkdirSync(target, { recursive: true })\n mkdirSync(join(target, \"src\"), { recursive: true })\n\n const description = opts.description || `AgentX plugin: ${name}`\n writeFileSync(join(target, \"package.json\"), packageJson(name, description))\n writeFileSync(join(target, \"tsconfig.json\"), tsconfig())\n writeFileSync(join(target, \"src/index.ts\"), pluginSource(name))\n writeFileSync(join(target, \"README.md\"), readme(name, description))\n writeFileSync(join(target, \".gitignore\"), gitignore())\n\n console.log()\n console.log(chalk.green(` ✓ scaffolded plugin at ${target}`))\n console.log()\n console.log(chalk.bold(\" Next steps:\"))\n console.log(chalk.dim(` cd ${dirName}`))\n console.log(chalk.dim(` pnpm install`))\n console.log(chalk.dim(` pnpm build`))\n console.log(chalk.dim(` pnpm link --global # for local testing`))\n console.log(chalk.dim(` # then in your agentx project:`))\n console.log(chalk.dim(` pnpm link --global ${name}`))\n console.log(chalk.dim(` agentx config set plugins[0] \"${name}\"`))\n console.log(chalk.dim(` agentx plugin doctor`))\n console.log()\n })\n\nplugin\n .command(\"doctor\")\n .description(\"dynamic-import each configured plugin and report status\")\n .action(async () => {\n try {\n const config = loadDaemonConfig()\n const names = config.plugins ?? []\n console.log()\n if (names.length === 0) {\n console.log(chalk.dim(\" No plugins configured. Nothing to check.\"))\n console.log()\n return\n }\n let bad = 0\n for (const name of names) {\n const status = await checkOne(name)\n if (status.kind === \"ok\") {\n console.log(` ${chalk.green(\"✓\")} ${chalk.cyan(name)} — ${status.manifestName} v${status.manifestVersion}`)\n } else {\n bad++\n console.log(` ${chalk.red(\"✗\")} ${chalk.cyan(name)} — ${status.reason}`)\n }\n }\n console.log()\n if (bad > 0) {\n console.log(chalk.red(` ${bad}/${names.length} plugin(s) failed`))\n process.exitCode = 1\n }\n } catch (e: any) {\n console.log(chalk.red(` ${e.message}`))\n process.exitCode = 1\n }\n })\n\ntype DoctorStatus =\n | { kind: \"ok\"; manifestName: string; manifestVersion: string }\n | { kind: \"fail\"; reason: string }\n\nasync function checkOne(packageName: string): Promise<DoctorStatus> {\n let mod: unknown\n try {\n mod = await import(packageName)\n } catch (e: any) {\n return { kind: \"fail\", reason: `import failed: ${e?.message ?? e}` }\n }\n\n const candidate = pickDefault(mod)\n if (!isPlugin(candidate)) {\n return { kind: \"fail\", reason: \"no default AgentXPlugin export (manifest/setup pair not found)\" }\n }\n const parsed = agentXPluginManifestSchema.safeParse(candidate.manifest)\n if (!parsed.success) {\n const issues = parsed.error.issues.map((i) => i.message).join(\"; \")\n return { kind: \"fail\", reason: `manifest invalid: ${issues}` }\n }\n return { kind: \"ok\", manifestName: parsed.data.name, manifestVersion: parsed.data.version }\n}\n\n// Same ESM/CJS interop logic the loader uses — duplicated here so the CLI\n// can run without the daemon's dependency tree. Two ~10-line functions\n// don't justify a shared module yet.\nfunction pickDefault(mod: unknown): unknown {\n if (mod == null) return mod\n if (typeof mod !== \"object\") return mod\n const m = mod as Record<string, unknown>\n if (m.default && typeof m.default === \"object\") {\n const d = m.default as Record<string, unknown>\n if (d.manifest && typeof d.setup === \"function\") return d\n if (d.default && typeof d.default === \"object\") {\n const dd = d.default as Record<string, unknown>\n if (dd.manifest && typeof dd.setup === \"function\") return dd\n }\n }\n if (m.manifest && typeof m.setup === \"function\") return m\n return m.default ?? m\n}\n\nfunction isPlugin(c: unknown): c is AgentXPlugin {\n return (\n !!c &&\n typeof c === \"object\" &&\n \"manifest\" in (c as object) &&\n \"setup\" in (c as object) &&\n typeof (c as { setup: unknown }).setup === \"function\"\n )\n}\n\n// --- Scaffolding templates for `agentx plugin init` ---\n\nfunction packageJson(name: string, description: string): string {\n return JSON.stringify({\n name,\n version: \"0.1.0\",\n description,\n main: \"dist/index.js\",\n types: \"dist/index.d.ts\",\n files: [\"dist\"],\n scripts: {\n build: \"tsc\",\n prepublishOnly: \"pnpm build\",\n },\n keywords: [\"agentx\", \"agentx-plugin\"],\n license: \"MIT\",\n devDependencies: {\n typescript: \"^5.4.0\",\n \"@types/node\": \"^20.0.0\",\n },\n }, null, 2) + \"\\n\"\n}\n\nfunction tsconfig(): string {\n return JSON.stringify({\n compilerOptions: {\n target: \"es2020\",\n module: \"commonjs\",\n lib: [\"es2020\"],\n declaration: true,\n outDir: \"dist\",\n strict: true,\n esModuleInterop: true,\n skipLibCheck: true,\n moduleResolution: \"node\",\n },\n include: [\"src/**/*.ts\"],\n }, null, 2) + \"\\n\"\n}\n\nfunction pluginSource(name: string): string {\n return `// ${name} — AgentX plugin\n//\n// A plugin's default export is { manifest, setup }. The daemon calls\n// setup(ctx) once at boot. ctx.on() subscribes to the bus; ctx.addChannel()\n// registers a custom channel adapter; ctx.log() namespaces output.\n\nconst plugin = {\n manifest: {\n name: ${JSON.stringify(name)},\n version: \"0.1.0\",\n // agentxRange: \"0.x\", // optional — gate against the daemon's major.minor\n },\n\n setup(ctx: any) {\n ctx.log(\"hello from\", ${JSON.stringify(name)})\n\n // Example: log every completed task.\n ctx.on(\"task:completed\", (payload: any) => {\n ctx.log(\"task done:\", payload.agentId, payload.durationMs + \"ms\")\n })\n\n // Example: register a no-op channel adapter.\n // ctx.addChannel({\n // name: \"my-channel\",\n // start: async () => {},\n // stop: async () => {},\n // send: async (out) => { ctx.log(\"send:\", out) },\n // })\n },\n\n // Optional — only needed for resources you own (timers, sockets).\n // Bus subscriptions are removed automatically.\n // teardown() {},\n}\n\nexport default plugin\n`\n}\n\nfunction readme(name: string, description: string): string {\n return `# ${name}\n\n${description}\n\n## Install\n\n\\`\\`\\`bash\npnpm install ${name}\n\\`\\`\\`\n\n## Use\n\nAdd to \\`agentx.json\\`:\n\n\\`\\`\\`json\n{\n \"plugins\": [\"${name}\"]\n}\n\\`\\`\\`\n\nThen verify the load:\n\n\\`\\`\\`bash\nagentx plugin doctor\n\\`\\`\\`\n\nRestart the daemon to activate.\n`\n}\n\nfunction gitignore(): string {\n return \"node_modules/\\ndist/\\n*.log\\n.env\\n\"\n}\n","import { Command, Option } from \"commander\"\nimport chalk from \"chalk\"\nimport { writeFileSync, mkdirSync, existsSync, readFileSync, appendFileSync } from \"fs\"\nimport { resolve, dirname } from \"path\"\nimport { homedir } from \"os\"\n\n// --- agentx completion: generate shell completion scripts ---\n//\n// Walks the commander tree built in src/program.ts and emits a static\n// completion script. Pattern modelled after the openclaw zsh completion:\n// - one `_agentx_<path>` function per (sub)command,\n// - root `_agentx_root_completion` dispatches on $line[1],\n// - `compdef _agentx_root_completion agentx` at the bottom.\n//\n// Regenerate + reinstall whenever a command or flag is added:\n// agentx completion --install\n//\n// Shipped with the global install so `npm i -g agentix-cli && agentx\n// completion --install` is the full setup path for end users.\n\nexport const completion = new Command()\n .name(\"completion\")\n .description(\"generate a shell completion script for agentx\")\n .option(\"-s, --shell <shell>\", \"shell to generate completion for: zsh|bash|fish\", \"zsh\")\n .option(\"-i, --install\", \"install the completion script to a default path for the shell\")\n .option(\"-o, --output <path>\", \"write the script to this path (overrides default install path)\")\n .option(\"-y, --yes\", \"skip confirmation prompts (non-interactive)\")\n .action(async (opts) => {\n const { buildProgram } = await import(\"@/program\")\n const program = await buildProgram()\n const shell = String(opts.shell || \"zsh\").toLowerCase()\n\n let script: string\n switch (shell) {\n case \"zsh\":\n script = generateZsh(program)\n break\n case \"bash\":\n script = generateBash(program)\n break\n case \"fish\":\n script = generateFish(program)\n break\n default:\n console.error(chalk.red(`unsupported shell: ${shell}`))\n console.error(chalk.dim(`supported: zsh, bash, fish`))\n process.exit(1)\n }\n\n // Plain print mode: stream to stdout so users can pipe/redirect.\n if (!opts.install && !opts.output) {\n process.stdout.write(script)\n return\n }\n\n const dest = opts.output ? resolve(String(opts.output)) : defaultInstallPath(shell)\n mkdirSync(dirname(dest), { recursive: true })\n writeFileSync(dest, script)\n\n console.log(chalk.green(`✓ Wrote ${shell} completion to:`))\n console.log(` ${dest}`)\n console.log()\n printShellHookInstructions(shell, dest, !!opts.yes)\n })\n\nfunction defaultInstallPath(shell: string): string {\n const home = homedir()\n switch (shell) {\n case \"zsh\":\n return resolve(home, \".zsh\", \"completions\", \"_agentx\")\n case \"bash\":\n return resolve(home, \".bash_completion.d\", \"agentx.bash\")\n case \"fish\":\n return resolve(home, \".config\", \"fish\", \"completions\", \"agentx.fish\")\n default:\n throw new Error(`unsupported shell: ${shell}`)\n }\n}\n\nfunction printShellHookInstructions(shell: string, dest: string, autoPatch: boolean): void {\n if (shell === \"zsh\") {\n const rc = resolve(homedir(), \".zshrc\")\n const fpathDir = dirname(dest)\n const fpathLine = `fpath=(${fpathDir} $fpath)`\n const compinitLine = `autoload -U compinit && compinit`\n const rcExisting = existsSync(rc) ? readFileSync(rc, \"utf-8\") : \"\"\n const needsFpath = !rcExisting.includes(fpathDir)\n const needsCompinit = !/autoload\\s+-U\\s+compinit/.test(rcExisting)\n\n if (!needsFpath && !needsCompinit) {\n console.log(chalk.dim(\"~/.zshrc already has fpath + compinit wired up. Run `exec zsh` to pick up the new script.\"))\n return\n }\n\n if (autoPatch && existsSync(rc)) {\n const block: string[] = [\"\", \"# agentx completion\"]\n if (needsFpath) block.push(fpathLine)\n if (needsCompinit) block.push(compinitLine)\n appendFileSync(rc, block.join(\"\\n\") + \"\\n\")\n console.log(chalk.green(`✓ Patched ~/.zshrc`))\n console.log(chalk.dim(\"Reload your shell: exec zsh\"))\n return\n }\n\n console.log(chalk.dim(\"Add this to ~/.zshrc if not already present:\"))\n if (needsFpath) console.log(chalk.cyan(` ${fpathLine}`))\n if (needsCompinit) console.log(chalk.cyan(` ${compinitLine}`))\n console.log()\n console.log(chalk.dim(\"Then reload: exec zsh\"))\n console.log(chalk.dim(\"Or rerun with --yes to auto-patch ~/.zshrc\"))\n return\n }\n\n if (shell === \"bash\") {\n const rc = resolve(homedir(), \".bashrc\")\n const sourceLine = `[ -f \"${dest}\" ] && source \"${dest}\"`\n const rcExisting = existsSync(rc) ? readFileSync(rc, \"utf-8\") : \"\"\n const already = rcExisting.includes(dest)\n\n if (already) {\n console.log(chalk.dim(\"~/.bashrc already sources this file. Start a new shell to pick it up.\"))\n return\n }\n\n if (autoPatch && existsSync(rc)) {\n appendFileSync(rc, `\\n# agentx completion\\n${sourceLine}\\n`)\n console.log(chalk.green(`✓ Patched ~/.bashrc`))\n console.log(chalk.dim(\"Reload your shell: exec bash\"))\n return\n }\n\n console.log(chalk.dim(\"Add this to ~/.bashrc:\"))\n console.log(chalk.cyan(` ${sourceLine}`))\n console.log()\n console.log(chalk.dim(\"Or rerun with --yes to auto-patch ~/.bashrc\"))\n return\n }\n\n if (shell === \"fish\") {\n console.log(chalk.dim(\"Fish auto-loads completions from this directory — start a new shell to pick it up.\"))\n return\n }\n}\n\n// ---------------------------------------------------------------------------\n// Commander tree helpers\n// ---------------------------------------------------------------------------\n\nfunction cmdName(cmd: Command): string {\n // commander stores the registered name on _name; fall back to .name()\n return (cmd as any)._name || cmd.name() || \"\"\n}\n\nfunction subcommandsOf(cmd: Command): Command[] {\n return cmd.commands.filter((c) => {\n const n = cmdName(c)\n if (!n) return false\n if (n === \"help\") return false\n // Hidden commands ARE completed on purpose.\n //\n // `hidden` exists to shorten `agentx --help` — 30 advanced commands are\n // registered but kept out of the default listing. Dropping them from\n // completion too would turn \"not advertised\" into \"hard to use\", which is\n // the opposite of the intent: someone who already knows `agentx ledger`\n // should still get its subcommands on Tab.\n return true\n })\n}\n\nfunction optionsOf(cmd: Command): Option[] {\n return (cmd.options as Option[]).filter((o) => !(o as any).hidden)\n}\n\n// ---------------------------------------------------------------------------\n// zsh generator\n// ---------------------------------------------------------------------------\n\nfunction generateZsh(program: Command): string {\n const out: string[] = []\n out.push(`#compdef agentx`)\n out.push(``)\n emitZshFn(program, [], out)\n out.push(`compdef _agentx_root_completion agentx`)\n out.push(``)\n return out.join(\"\\n\")\n}\n\nfunction zshFnName(path: string[]): string {\n if (path.length === 0) return `_agentx_root_completion`\n return `_agentx_${path.join(\"_\").replace(/[^a-z0-9_]/gi, \"_\")}`\n}\n\nfunction emitZshFn(cmd: Command, path: string[], out: string[]): void {\n const subs = subcommandsOf(cmd)\n const opts = optionsOf(cmd)\n const optLines = opts.map(zshOptionLine).filter((s): s is string => !!s)\n const name = zshFnName(path)\n\n out.push(`${name}() {`)\n out.push(` local -a commands`)\n out.push(` local -a options`)\n out.push(` `)\n\n // Nothing to complete: emit an empty-but-valid function.\n if (optLines.length === 0 && subs.length === 0) {\n out.push(` return 0`)\n out.push(`}`)\n out.push(``)\n return\n }\n\n const argLines: string[] = []\n for (const line of optLines) argLines.push(line)\n\n if (subs.length > 0) {\n const entries = subs.map(zshCommandEntry).join(\" \")\n argLines.push(` \"1: :_values 'command' ${entries}\"`)\n argLines.push(` \"*::arg:->args\"`)\n }\n\n out.push(` _arguments -C \\\\`)\n for (let i = 0; i < argLines.length; i++) {\n const last = i === argLines.length - 1\n out.push(`${argLines[i]}${last ? \"\" : \" \\\\\"}`)\n }\n\n if (subs.length > 0) {\n out.push(``)\n out.push(` case $state in`)\n out.push(` (args)`)\n out.push(` case $line[1] in`)\n for (const sub of subs) {\n const subFn = zshFnName([...path, cmdName(sub)])\n out.push(` (${cmdName(sub)}) ${subFn} ;;`)\n }\n out.push(` esac`)\n out.push(` ;;`)\n out.push(` esac`)\n }\n\n out.push(`}`)\n out.push(``)\n\n for (const sub of subs) {\n emitZshFn(sub, [...path, cmdName(sub)], out)\n }\n}\n\nfunction escapeZshDesc(s: string): string {\n return String(s || \"\")\n .replace(/\\r?\\n/g, \" \")\n .replace(/\"/g, '\\\\\"')\n .replace(/\\[/g, \"\\\\[\")\n .replace(/\\]/g, \"\\\\]\")\n}\n\nfunction escapeZshValue(s: string): string {\n return String(s || \"\")\n .replace(/\\r?\\n/g, \" \")\n .replace(/'/g, \"'\\\\''\")\n .replace(/\\[/g, \"\\\\[\")\n .replace(/\\]/g, \"\\\\]\")\n}\n\nfunction zshOptionLine(opt: Option): string | null {\n const short = opt.short || undefined\n const long = opt.long || undefined\n if (!short && !long) return null\n const desc = escapeZshDesc(opt.description || \"\")\n if (short && long) {\n return ` \"(${long} ${short})\"{${long},${short}}\"[${desc}]\"`\n }\n return ` \"${long || short}[${desc}]\"`\n}\n\nfunction zshCommandEntry(cmd: Command): string {\n const desc = escapeZshValue(cmd.description() || \"\")\n return `'${cmdName(cmd)}[${desc}]'`\n}\n\n// ---------------------------------------------------------------------------\n// bash generator (flat: root + first level)\n// ---------------------------------------------------------------------------\n\nfunction generateBash(program: Command): string {\n const tops = subcommandsOf(program)\n const lines: string[] = []\n lines.push(`# bash completion for agentx`)\n lines.push(`_agentx_complete() {`)\n lines.push(` local cur prev words cword`)\n lines.push(` COMPREPLY=()`)\n lines.push(` cur=\"\\${COMP_WORDS[COMP_CWORD]}\"`)\n lines.push(` prev=\"\\${COMP_WORDS[COMP_CWORD-1]}\"`)\n lines.push(``)\n lines.push(` local top=\"${tops.map(cmdName).join(\" \")}\"`)\n lines.push(``)\n lines.push(` if [[ $COMP_CWORD -eq 1 ]]; then`)\n lines.push(` COMPREPLY=( $(compgen -W \"$top\" -- \"$cur\") )`)\n lines.push(` return 0`)\n lines.push(` fi`)\n lines.push(``)\n lines.push(` local cmd=\"\\${COMP_WORDS[1]}\"`)\n lines.push(` local sub2=\"\\${COMP_WORDS[2]:-}\"`)\n lines.push(` case \"$cmd\" in`)\n for (const sub of tops) {\n const subsubs = subcommandsOf(sub).map(cmdName)\n const subOpts = collectBashFlags(sub)\n lines.push(` ${cmdName(sub)})`)\n if (subsubs.length > 0) {\n lines.push(` if [[ $COMP_CWORD -eq 2 ]]; then`)\n lines.push(` COMPREPLY=( $(compgen -W \"${subsubs.join(\" \")} ${subOpts}\" -- \"$cur\") )`)\n lines.push(` return 0`)\n lines.push(` fi`)\n lines.push(` case \"$sub2\" in`)\n for (const ss of subcommandsOf(sub)) {\n const ssOpts = collectBashFlags(ss)\n lines.push(` ${cmdName(ss)})`)\n lines.push(` COMPREPLY=( $(compgen -W \"${ssOpts}\" -- \"$cur\") )`)\n lines.push(` return 0`)\n lines.push(` ;;`)\n }\n lines.push(` esac`)\n } else {\n lines.push(` COMPREPLY=( $(compgen -W \"${subOpts}\" -- \"$cur\") )`)\n }\n lines.push(` ;;`)\n }\n lines.push(` esac`)\n lines.push(`}`)\n lines.push(``)\n lines.push(`complete -F _agentx_complete agentx`)\n lines.push(``)\n return lines.join(\"\\n\")\n}\n\nfunction collectBashFlags(cmd: Command): string {\n const flags: string[] = []\n for (const opt of optionsOf(cmd)) {\n if (opt.long) flags.push(opt.long)\n if (opt.short) flags.push(opt.short)\n }\n return flags.join(\" \")\n}\n\n// ---------------------------------------------------------------------------\n// fish generator\n// ---------------------------------------------------------------------------\n\nfunction generateFish(program: Command): string {\n const lines: string[] = []\n lines.push(`# fish completion for agentx`)\n lines.push(``)\n lines.push(`complete -c agentx -f`)\n lines.push(``)\n\n // Top-level subcommands: only when no subcommand entered.\n lines.push(`# top-level commands`)\n for (const sub of subcommandsOf(program)) {\n const desc = escapeFish(sub.description() || \"\")\n lines.push(`complete -c agentx -n \"__fish_use_subcommand\" -a \"${cmdName(sub)}\" -d \"${desc}\"`)\n }\n lines.push(``)\n\n // Root options (gated on no-subcommand to avoid polluting subcommand suggestions).\n for (const opt of optionsOf(program)) {\n const line = fishOptionLine(opt, [`__fish_use_subcommand`])\n if (line) lines.push(line)\n }\n lines.push(``)\n\n // Per-top-level: options + second-level subcommands.\n for (const sub of subcommandsOf(program)) {\n const name = cmdName(sub)\n lines.push(`# ${name}`)\n for (const opt of optionsOf(sub)) {\n const line = fishOptionLine(opt, [`__fish_seen_subcommand_from ${name}`])\n if (line) lines.push(line)\n }\n for (const subsub of subcommandsOf(sub)) {\n const desc = escapeFish(subsub.description() || \"\")\n lines.push(\n `complete -c agentx -n \"__fish_seen_subcommand_from ${name}; and not __fish_seen_subcommand_from ${subcommandsOf(sub).map(cmdName).join(\" \")}\" -a \"${cmdName(subsub)}\" -d \"${desc}\"`\n )\n for (const opt of optionsOf(subsub)) {\n const line = fishOptionLine(opt, [`__fish_seen_subcommand_from ${cmdName(subsub)}`])\n if (line) lines.push(line)\n }\n }\n lines.push(``)\n }\n return lines.join(\"\\n\")\n}\n\nfunction escapeFish(s: string): string {\n return String(s || \"\")\n .replace(/\\r?\\n/g, \" \")\n .replace(/\\\\/g, \"\\\\\\\\\")\n .replace(/\"/g, '\\\\\"')\n}\n\nfunction fishOptionLine(opt: Option, conditions: string[]): string | null {\n const shortRaw = opt.short ? opt.short.replace(/^-/, \"\") : \"\"\n const longRaw = opt.long ? opt.long.replace(/^--/, \"\") : \"\"\n if (!shortRaw && !longRaw) return null\n const desc = escapeFish(opt.description || \"\")\n const cond = conditions.map((c) => `-n \"${c}\"`).join(\" \")\n const parts: string[] = [`complete -c agentx`, cond]\n if (shortRaw) parts.push(`-s ${shortRaw}`)\n if (longRaw) parts.push(`-l ${longRaw}`)\n parts.push(`-d \"${desc}\"`)\n return parts.join(\" \")\n}\n"],"mappings":"yxCAAA,OAAS,WAAAA,OAAe,YCAxB,OAAS,WAAAC,OAAe,YAGxB,OAAOC,MAAW,QAClB,OAAS,cAAAC,GAAY,gBAAAC,OAAoB,KAWzC,eAAeC,GAAsBC,EAA+B,CAClE,GAAI,CACF,GAAM,CAAE,aAAAC,CAAa,EAAI,KAAM,QAAO,eAAe,EAG/CC,EAAMD,EAAa,KAAM,CAAC,KAAM,OAAOD,CAAG,EAAG,KAAM,UAAU,EAAG,CACpE,SAAU,QACV,QAAS,GACX,CAAC,EAAE,KAAK,EACR,OAAKE,EAEE,WAAW,KAAKA,CAAG,GAAK,yBAAyB,KAAKA,CAAG,EAF/C,EAGnB,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,IAAMC,EAAOC,GAAYF,CAAoB,EACzCG,GAAoBF,CAAI,GAAGG,GAAiB,MAAOH,CAAI,CAC7D,CAAC,EAMD,QAAWI,IAAO,CAChBC,GAAOC,GAAMC,GACbC,GAAQC,GACRC,GAAOC,GAASC,GAChBC,GACAC,GACAC,GACAC,GACAC,GAAOC,GAAWC,EACpB,EAAGvB,EAAQ,WAAWQ,CAAG,EAiBzB,QAAWA,KAAOgB,GAAUxB,EAAQ,WAAWQ,EAAK,CAAE,OAAQ,EAAK,CAAC,EAEpE,OAAAR,EAAQ,YAAY,QAAS,IAAM,CACjC,IAAMyB,EAAQD,GAAS,IAAKE,GAAMA,EAAE,KAAK,CAAC,EAAE,KAAK,EACjD,MAAO,CACL,GACA,aAAaD,EAAM,0EACnBE,GAAUF,EAAO,GAAI,IAAI,EACzB,EACF,EAAE,KAAK;AAAA,CAAI,CACb,CAAC,EAEMzB,CACT,CAGA,IAAMwB,GAAW,CAEfI,GAAMC,GAAOC,GAAWC,GAAWC,GAAYC,GAE/CC,GAAUC,GAASC,GAAOC,GAASC,GAAUC,GAE7CC,GAAWC,GAAUC,GAAYC,GAAOC,GAExCC,GAAMC,GAAUC,GAAWC,GAAMC,GAEjCC,GAEAC,GAASC,GAAWC,GAEpBC,GAAUC,GAEVC,GAAMC,EACR,EAGA,SAAS9B,GAAUF,EAAiBiC,EAAeC,EAAwB,CACzE,IAAMC,EAAkB,CAAC,EACrBC,EAAO,GACX,QAAWC,KAAKrC,EACVoC,GAASA,EAAK,OAASC,EAAE,OAAS,EAAKJ,IACzCE,EAAM,KAAKD,EAASE,CAAI,EACxBA,EAAO,IAETA,IAASA,EAAO,KAAO,IAAMC,EAE/B,OAAID,GAAMD,EAAM,KAAKD,EAASE,CAAI,EAC3BD,EAAM,KAAK;AAAA,CAAI,CACxB","names":["Command","Command","chalk","existsSync","readFileSync","isLikelyAgentxProcess","pid","execFileSync","cmd","daemon","Command","opts","spawn","openSync","writeFileSync","cli","args","logPath","logFd","e","child","ok","mkdirSync","resolve","lockDir","pidPath","oldPid","alive","loadDotenv","AgentXDaemon","path","text","raw","line","eq","key","val","unlinkSync","pidFiles","pidFile","r","execSync","config","loadDaemonConfig","host","port","url","data","formatDuration","a","active","errors","enabledCrons","icon","next","p","skills","warnings","validateWorkspaces","w","err","spawnProc","logFile","tail","res","reader","decoder","buffer","done","value","lines","time","msg","agent","messageParts","message","baseUrl","body","sshKey","remote","statSync","cliPath","ssh","seconds","Command","chalk","existsSync","readFileSync","writeFileSync","mkdirSync","hostname","resolve","init","opts","cwd","configPath","envPath","sessionsDir","examplePaths","example","p","claudeDir","Command","chalk","spawn","existsSync","dirname","resolve","fileURLToPath","setup","Command","opts","state","wizardState","port","resolveDashboardPort","url","chalk","probe","openBrowser","cli","resolveCliEntry","child","spawn","ok","loadDaemonConfig","candidate","resolve","dirname","fileURLToPath","existsSync","r","cmd","Command","chalk","token","Command","opts","store","TokenStore","scopes","s","days","secret","record","chalk","e","records","r","status","id","rec","Command","chalk","prompts","readFileSync","writeFileSync","existsSync","mkdirSync","cpSync","readdirSync","resolve","join","dirname","fileURLToPath","loadConfig","p","resolve","existsSync","readFileSync","saveConfig","config","applyConfigMutation","current","k","result","chalk","agent","Command","id","a","mentions","answers","prompts","v","ws","join","mkdirSync","agentDef","m","setupWorkspace","setup","args","wikiSkillSrc","wikiSkillDist","dirname","fileURLToPath","skillSrc","cpSync","opts","changes","s","n","integrations","agentId","list","enabled","statusBits","creds","meta","cfg","interactive","INTEGRATION_KINDS","kind","label","tokenEnv","auth","sessionDir","r","metadata","pair","rest","credentials","i","target","tk","tl","idx","removed","filtered","bad","issues","issue","channel","tg","name","acc","wa","route","dc","gl","agentIds","agentChoices","channelType","data","botHandle","agentMentions","e","routes","addMore","prev","cron","c","icon","mesh","peer","status","card","skillCmd","skillPath","srcPath","skillName","targets","destDir","skillsDir","skills","readdirSync","f","createHash","cwd","candidates","src","srcContent","srcHash","srcVersion","loadDaemonConfig","entries","newN","updatedN","unchangedN","skippedN","def","dstDir","dst","writeFileSync","dstContent","dstVersion","verb","loadLocalSkills","auditAll","loadReferences","loadRecipes","skillsRoots","refsRoot","references","recipes","results","summary","tag","reason","namespace","exampleRoot","exampleRecipe","targetRoot","targetRecipes","exampleFiles","copied","skipped","file","dest","rewritten","recipeDest","discoverFromSkills","renderDiscovery","filter","counts","files","writeRoot","targetDir","content","l","written","cards","b","hook","settingsPath","settings","entry","migrate","configPath","searchPaths","ocPath","oc","agents","bindings","bindMap","agentCount","axId","tgAccounts","tgCount","axAgentId","cronPath","cronData","cronCount","job","configCmd","warnings","validateWorkspaces","w","hasClaudeDir","hasClaudeMd","hasSettings","skillCount","checks","parseValue","raw","asString","formatValue","path","getAtPath","expandEnvVars","cfgPath","source","value","setAtPath","parsed","unsetAtPath","businessEnabled","projectsCount","configError","ledgerMode","pmGateRaw","pmGate","pmGateActive","ledgerValid","modeColor","pmStatus","Command","chalk","resolve","existsSync","db","Command","openReadOnly","cwd","path","resolve","existsSync","chalk","handle","openDb","emit","rows","asJson","cols","widths","c","fmt","cells","v","i","_","row","opts","where","params","sql","whereSql","t","e","Command","chalk","mkdtempSync","tmpdir","resolve","join","existsSync","Database","replay","target","events","decisions","resolutions","eventById","e","timeline","d","r","a","b","divergences","decisionsCount","entry","recorded","event","policy","buildPlaybackPolicy","eventInput","replayed","decideAndCommit","classifyDivergence","ledger","Command","openReadOnly","opts","root","resolve","path","existsSync","chalk","Database","e","emit","rows","asJson","cols","widths","c","fmt","cells","v","i","_","row","durationToMs","input","m","n","unit","parseSince","ms","db","since","sinceClause","sinceClauseDecisions","sinceClauseDivergences","eventsBySource","totalDecisions","decisionsByOutcome","totalDivergences","divergencesBySource","inFlight","where","params","whereSql","eventOrSubject","project","subject","idx","events","eventIds","placeholders","id","decisions","grouped","d","distinctAgents","dt","evDecisions","outcome","agent","reason","status","dur","sourceDb","eventWhere","eventParams","eventLimit","r","eventIdParams","resolutions","tmpDir","mkdtempSync","join","tmpdir","target","IntentLedger","result","replay","Command","chalk","resolve","existsSync","Database","trace","Command","openReadOnly","opts","root","resolve","path","existsSync","chalk","Database","e","durationToMs","input","m","n","unit","parseSince","ms","fmtAge","s","statusColor","db","traces","listTraces","t","status","dur","wf","tokens","taskId","rec","getTrace","printTrace","steps","wfPart","stepStatus","action","lines","l","message","base","body","startedAt","res","reply","durationMs","printBlock","same","text","max","shown","Command","chalk","existsSync","mkdirSync","writeFileSync","resolve","join","dirname","SEED_POLICY_YAML","SEED_PRODUCTION_YAML","SEED_CODER_AGENT_YAML","SEED_FILES","guard","Command","actionColor","a","chalk","rootOf","opts","resolve","guessInstallRoot","runCheckFromStdin","command","root","modeOverride","verdict","mode","ms","runGuard","printVerdict","v","col","rows","listDecisions","r","when","eff","base","join","GUARDRAILS_DIR","created","f","SEED_FILES","path","existsSync","mkdirSync","dirname","writeFileSync","res","e","p","loadPolicy","Command","chalk","existsSync","mkdirSync","readFileSync","writeFileSync","homedir","dirname","resolve","ATTACH_MARKER","GUARD_MARKER","hookCommand","route","port","query","entry","matcher","e","attachHookBlock","guardHookEntries","command","isOurs","marker","h","userSettingsPath","configuredDaemonPort","root","dir","cfg","bind","installAttachHooks","opts","path","withGuard","settings","before","hooks","events","event","desired","others","guardInstalled","changed","uninstallAttachHooks","kept","attachHooksInstalled","attach","Command","DEFAULT_URL","configuredDaemonPort","currentSessionId","explicit","api","url","path","body","res","text","json","daemonHint","msg","chalk","modeColor","m","printSession","s","mark","who","pending","here","DELIVERY_MODES","agent","opts","sessionId","isDeliveryMode","attachHooksInstalled","r","e","sessions","userSettingsPath","bound","idle","port","installAttachHooks","uninstallAttachHooks","Command","chalk","process_","Command","resolveDaemon","opts","baseUrl","token","cfg","loadDaemonConfig","authHeaders","contentType","h","fmtAge","ms","s","stateColor","chalk","res","e","procs","p","state","age","lastTurn","tokens","session","pending","agentId","channel","chatId","msg","body","Command","chalk","existsSync","rmSync","resolve","rag","Command","agentId","globs","opts","chalk","verbose","start","r","buildIndex","ms","root","resolve","existsSync","readdirSync","agents","d","a","info","indexInfo","query","k","hits","lexicalSearch","h","path","rmSync","Command","chalk","prompts","backlog","Command","loadCtx","configPath","config","loadDaemonConfig","ws","storePath","BacklogStore","fmtSource","s","chalk","fmtStatus","status","opts","store","items","i","it","assignee","id","agent","ctx","updated","usernames","resolveAssigneesForSource","result","syncBacklogItemToSource","a","gitlabReady","githubReady","source","choices","prompts","project","candidates","collectGitlabProjects","collectGithubProjects","p","search","issues","fetchGitlabIssues","fetchGithubIssues","projectId","existing","iss","sourceBacklogId","already","labels","selected","toAdd","src","hostnameFromGitlab","added","daemon","host","set","r","gl","params","res","arr","l","headers","url","q","githubMap","Command","chalk","existsSync","readFileSync","resolve","prompts","cronstrue","DAY_OF_WEEK","DEFAULT_TIMES","humanize","cron","extractTime","text","m","h","min","ampm","parseEnglishToCron","raw","n","time","dayKeywordTime","kw","t","resolvedTime","domMatch","tok","dom","dayTokens","dayWordsAlt","anchorRe","anchor","list","w","a","b","dow","v","slugifyScheduleId","phrase","agent","loadRawConfig","configPath","p","resolve","existsSync","chalk","readFileSync","parseOnError","flag","s","resolveNotifyTarget","cfg","dest","channel","chatId","accountId","prompts","parts","schedule","Command","when","opts","parsed","parseEnglishToCron","expanded","expandEnvVars","onErrorModes","notify","id","slugifyScheduleId","job","result","applyConfigMutation","c","setAtPath","verb","crons","entries","def","tag","human","enabled","getAtPath","unsetAtPath","words","r","Command","chalk","chalk","prompts","readFileSync","writeFileSync","existsSync","resolve","KV_RE","parseValue","raw","s","quoteIfNeeded","value","readDotEnv","path","abs","content","lines","m","serializeDotEnv","l","setDotEnv","key","idx","getDotEnv","key","path","readDotEnv","l","BOTFATHER_URL","getMe","token","res","j","pollFirstMessage","timeoutMs","deadline","offset","u","msg","connectTelegram","opts","chalk","openBrowser","prompts","spawn","opener","t","me","readFileSync","existsSync","resolve","cfgPath","raw","agents","agent","id","accounts","account","s","envVar","setDotEnv","result","applyConfigMutation","cfg","setAtPath","mentions","getAtPath","handle","capture","first","destResult","chalk","prompts","spawn","DEV_PORTAL","DEFAULT_PERMISSIONS","fetchMe","token","res","openInBrowser","url","opener","spawn","connectDiscord","opts","chalk","openBrowser","prompts","t","me","displayName","readFileSync","existsSync","resolve","cfgPath","raw","agents","agent","id","envVar","setDotEnv","result","applyConfigMutation","cfg","setAtPath","installUrl","openInstall","chalk","prompts","existsSync","mkdirSync","readdirSync","readFileSync","resolve","DEFAULT_SESSION_DIR","daemonRunning","pidFile","resolve","existsSync","pid","readFileSync","sessionExists","dir","readdirSync","f","pairSession","sessionDir","log","baileys","chalk","makeWASocket","useMultiFileAuthState","mkdirSync","state","saveCreds","version","silentLogger","sock","resolveP","deadline","u","qrcode","connectWhatsApp","opts","cont","prompts","cfgPath","raw","absSession","agents","agent","id","shouldPair","keep","s","result","applyConfigMutation","cfg","setAtPath","randomBytes","chalk","prompts","PROTOCOL","PATH_PREFIX","b64urlEncode","input","b64urlDecode","encodeInvite","payload","decodeInvite","link","raw","parsed","generateToken","randomBytes","resolveBindUrl","bind","host","port","nodeName","invite","opts","readFileSync","existsSync","resolve","cfgPath","chalk","token","getDotEnv","setDotEnv","url","entered","prompts","v","result","applyConfigMutation","cfg","setAtPath","join","e","existing","overwrite","peers","getAtPath","idx","p","peer","res","card","agents","connect","Command","opts","connectTelegram","connectDiscord","connectWhatsApp","mesh","invite","link","join","chalk","Command","chalk","usage","Command","config","loadDaemonConfig","host","port","data","chalk","fmt","n","agents","b","id","ag","total","avgMs","opts","execSync","existsSync","resolve","scriptPath","listSurfaceUse","kind","rows","buildProgram","program","seen","r","registered","walk","cmd","prefix","sub","name","unused","c","lastKind","count","days","Command","chalk","board","Command","opts","config","resolveServerConfig","startBoardDashboard","e","chalk","portOpt","bindOpt","cfg","loadDaemonConfig","b","src","id","mutateConfig","projects","s","x","changes","column","boardId","cols","c","map","columnId","col","before","mutator","summary","backupPath","mutateAgentxConfig","Command","chalk","resolve","relative","dirname","execSync","writeFileSync","mkdirSync","readFileSync","readdirSync","renameSync","rmSync","existsSync","getHub","dir","mode","WikiHub","modeLabel","wiki","Command","opts","hub","agents","totalEntries","chalk","agent","status","a","totalUnabsorbed","s","totalIssues","agentId","issues","issue","icon","maxEntries","graphStore","baseDir","GraphStore","fpToPath","idx","fp","e","lookupPath","entry","stamped","sender","pickGraphPath","sources","entries","counts","sid","path","key","cur","best","v","totalAbsorbed","totalWithPath","unabsorbed","agentWiki","existingIndex","worldview","entryTexts","prompt","buildAbsorbPrompt","tmpDir","promptPath","rawOutput","execErr","responseText","envelope","articles","gaps","objStart","arrStart","jsonStart","openChar","closeChar","depth","jsonEnd","i","jsonStr","parsed","parseErr","article","now","graphPath","typeTag","relStr","tagStr","gap","pct","sinceMs","parsePromoteSince","types","t","validTypes","badType","report","runPromotion","msg","cluster","c","corr","w","wmsg","err","input","m","n","unit","agenticQuery","rd","rf","ex","rv","jn","store","agentHistDir","tasks","days","day","dayDir","files","f","rec","lines","oldTitles","newBlock","q","cites","out","readline","randomUUID","WIKI_ARTICLE_TYPES","scripted","l","scriptCursor","rl","ask","answer","topic","type","picked","QUESTIONS","questions","qas","aborted","extra","catalogLines","synthesisPrompt","x","draft","cmd","raw","fence","fmStart","fmMatch","fm","line","body","title","slug","articlePath","choice","finalContent","finalMeta","editor","editPath","ef","mm","referenced","titleIdx","r","g","script","verdict","rounds","commit","transcript","applied","result","action","note","primary","patchPrompt","buildQuizPatchPrompt","patched","before","after","titleOrPath","relPath","resolveArticlePath","absPath","seenLinks","bodyLinks","currentRelated","b","instruction","buildWikiPatchPrompt","go","ans","seen","syncedRelated","relDrift","arg","lower","byTitle","normPath","byPath","argSlug","bySlug","titleSlug","content","instructions","wikiRoot","CANONICAL","LEGACY_MODES","totalLegacy","totalPromote","totalUpgrade","totalArchive","agentRoot","canonicalDir","legacyEntries","canonIdx","walkMd","abs","rel","parseWikiFrontmatter","legacy","modeStr","la","existing","arrow","where","target","archiveLegacy","verDir","ts","cb","meta","batchSize","maxArticles","totalScanned","totalNeeds","totalApplied","needs","remaining","limit","batch","buildMigratePrompt","classifications","arrMatch","norm","normalizeWikiType","related","newMeta","aliasNote","mapped","items","tags","port","peerUrls","loadDaemonConfig","p","startWikiServer","question","chosen","id","cat","follow","query","found","results","totalArticles","totalEligible","totalMatched","totalWritten","sharedEntries","entriesById","agentEligible","agentMatched","agentWritten","shared","existingIds","totalSynced","peerUrl","res","data","nodeId","newCount","agentsRes","agentsData","stats","index","totalTags","dirs","rows","label","fn","vals","max","winners","output","wikiDir","date","parent","base","args","spawnSync","statSync","size","formatWikiBytes","archive","archivePath","Command","chalk","resolve","existsSync","graph","Command","opts","config","loadDaemonConfig","chalk","agentId","daemonUrl","cap","store","GraphStore","resolve","pending","schema","nodes","approvedN","rejectedN","skippedN","errorN","i","c","label","pathLabel","prompt","buildReviewPrompt","decision","askAgent","e","verdict","reason","commitApproved","verb","baseDir","existsSync","migrateV2","result","hits","b","count","peer","limit","headers","localSchema","localNodes","localIds","n","peerSchema","peerNodes","peerClassifications","schemaRes","nodesRes","clRes","localLevels","l","peerLevels","schemaMatches","schemaForImport","levelOrder","sortedPeerNodes","a","nodesAdded","nodesSkipped","nodesFailed","fpAdded","fpSkipped","existingByLevel","levelsSummary","axesJson","message","token","ac","timer","r","data","extractJson","_existing","createdBy","text","fenced","start","depth","Command","chalk","Command","chalk","existsSync","resolve","Database","parseSince","input","m","unit","n","chalk","openTraceDb","path","dbPath","resolve","existsSync","Database","extractCommand","Command","DEFAULT_MIN_OCCURRENCES","DEFAULT_MAX_CLUSTERS","opts","db","report","runExtraction","SessionStore","c","nm","d","s","w","CADENCE","watchCommand","schedule","minOccurrences","extraction","prompt","result","applyConfigMutation","setAtPath","verb","procedure","Command","extractCommand","watchCommand","opts","store","ProcedureStore","items","chalk","p","status","v","prev","body","e","id","text","matches","matchProcedures","m","Command","chalk","resolve","basename","existsSync","mkdirSync","readFileSync","writeFileSync","Database","readFileSync","resolve","dirname","fileURLToPath","TEMPLATES","readTemplate","name","here","cliDir","candidates","path","workflow","Command","durationToMs","input","m","n","unit","parseSince","ms","chalk","openTraceDb","path","dbPath","resolve","existsSync","Database","printWorkflowDraft","format","renderWorkflowYaml","traceSummary","records","models","r","durationMs","sum","totalTokens","last","printReplayComparison","original","replay","deltaMs","deltaTokens","items","WorkflowStore","wf","cfg","filterParts","dispatch","id","opts","fmt","file","text","readFileSync","raw","parseYamlWorkflow","parsed","workflowSchema","i","lintIssues","lintWorkflow","e","msg","WorkflowYamlError","results","ok","bad","issue","TEMPLATES","t","tmplName","store","body","readTemplate","ext","dest","writeFileSync","isYaml","l","basename","url","res","nodeId","runs","RunStore","nextLabel","stateColor","taskId","db","trace","getTrace","result","architectOrBuildDraft","issues","validateWorkflowDraft","writeWorkflowDraft","traces","loadSuccessfulTraces","clusters","clusterWorkflowCandidates","drafts","buildDraftsFromClustersAsync","draft","tag","isMeaningfulDraft","listWorkflowDrafts","d","draftId","promoteWorkflowDraft","rejectWorkflowDraft","workflowDef","getWorkflowDraft","buildWorkflowDraftFromTrace","payload","mkdirSync","replayId","replayWorkflow","base","originalSummary","replayTraces","tailTraces","idOrFile","adhocId","written","runId","args","seen","collected","startedAt","maxMs","status","color","tokens","dur","run","single","rec","printTrace","model","Command","chalk","prompts","readFileSync","existsSync","resolve","VALID_SOURCES","WIRED_SOURCES","SOURCE_HINTS","loadConfig","p","resolve","existsSync","readFileSync","statusBadge","w","chalk","printOneHuman","w","daemonUrl","url","wired","WIRED_SOURCES","chalk","statusBadge","triggers","triggerKeys","k","webhook","Command","opts","cfg","loadConfig","entries","VALID_SOURCES","idArg","knownAgents","meshPeers","p","node","id","source","agentId","secretEnv","description","interactive","prompts","v","s","SOURCE_HINTS","a","result","applyConfigMutation","c","entry","before","toggleEnabled","enabled","x","eventType","workflowId","clear","list","item","tag","Command","chalk","mutate","mutator","summary","backupPath","mutateAgentxConfig","cfg","chalk","readBusiness","loadDaemonConfig","business","Command","opts","b","orgChart","projects","contactMap","orgEntries","id","e","reports","sched","p","pm","client","c","key","ch","orgchart","entries","agentId","days","s","project","idx","next","list","before","contact","entry","Command","chalk","TIER_ALIAS","resolveTier","label","t","resolveStore","dir","loadDaemonConfig","DayPlanStore","plan","Command","tier","opts","store","body","readFileSync","p","chalk","result","items","parsePriorities","it","r","printPlan","rows","existing","unlinkSync","date","content","line","Command","chalk","readNotifications","loadDaemonConfig","mutate","mutator","summary","backupPath","mutateAgentxConfig","cfg","chalk","notifications","Command","opts","n","acct","on","name","state","known","onv","enabled","seconds","Command","chalk","readdirSync","statSync","unlinkSync","rmSync","existsSync","resolve","join","TARGETS","walkFiles","dir","recursive","out","entry","full","retention","total","t","root","files","bytes","oldest","f","s","oldestAge","formatBytes","opts","days","cutoff","filterTarget","totalRemoved","totalBytes","removed","pruneEmptyDirs","action","b","Command","chalk","actions","Command","opts","list","ActionStore","chalk","a","inputs","target","id","inp","req","def","desc","parseInputsCsv","base","parsed","actionSchema","issue","saved","action","kv","eq","result","runAction","e","name","res","t","x","input","body","csv","out","part","s","required","clean","colon","type","Command","chalk","watch","Command","opts","baseUrl","token","cfg","loadDaemonConfig","qs","url","chalk","headers","res","reader","dec","buf","done","value","idx","frame","printFrame","e","event","data","line","payload","ts","tag","wf","runShort","node","note","actors","title","name","scope","peer","health","dir","label","preview","Command","chalk","chalk","deprecationNotice","d","CHAT_SURFACE_DEPRECATION","tui","Command","opts","deprecationNotice","CHAT_SURFACE_DEPRECATION","chalk","resolveConn","App","render","React","conn","pollMs","Command","chalk","randomUUID","createInterface","ora","chat","Command","agentArg","opts","deprecationNotice","CHAT_SURFACE_DEPRECATION","conn","resolveConn","agentId","channel","chatId","randomUUID","agents","fetchAgents","e","chalk","a","render","ChatApp","React","printBanner","rl","createInterface","busy","closeRequested","line","fresh","marker","next","spinner","ora","startedAt","createStreamRenderer","r","streamTask","t","tool","elapsed","headerShown","atLineStart","anyText","seenTools","header","delta","ch","key","arg","elapsedS","usage","out","msg","baseUrl","Command","chalk","readFileSync","VALID_TYPES","memory","Command","opts","chalk","body","readStdin","readFileSync","e","rec","AgentMemory","records","r","currentType","name","md","chunks","chunk","chalk","Command","resolve","serve","opts","startMcpServer","logger","error","handleError","Command","chalk","spawn","mkdirSync","writeFileSync","rmSync","openSync","existsSync","resolve","join","randomBytes","KICKOFF","DELEGATION","buildSpecs","root","basePort","writeNode","spec","all","meshToken","ws","peers","n","config","waitFor","desc","fn","timeoutMs","start","r","post","port","path","body","res","data","say","role","text","color","demo","opts","specs","children","cli","tearingDown","teardown","code","c","baseEnv","logFd","child","dashPort","p","liveUrl","s","opener","playScenario","s1","s2","builderReply","s3","e","Command","chalk","whatsapp","Command","opts","chats","getJSON","c","chalk","kind","when","e","fail","contacts","name","phone","body","report","postJSON","printReport","jid","state","dryRun","err","daemonUrl","config","loadDaemonConfig","host","port","path","r","data","Command","chalk","existsSync","mkdirSync","writeFileSync","join","resolve","plugin","Command","names","loadDaemonConfig","chalk","n","name","opts","dirName","target","resolve","existsSync","mkdirSync","join","description","writeFileSync","packageJson","tsconfig","pluginSource","readme","gitignore","bad","status","checkOne","packageName","mod","e","candidate","pickDefault","isPlugin","parsed","agentXPluginManifestSchema","m","d","dd","c","Command","chalk","writeFileSync","mkdirSync","existsSync","readFileSync","appendFileSync","resolve","dirname","homedir","completion","opts","buildProgram","program","shell","script","generateZsh","generateBash","generateFish","dest","defaultInstallPath","printShellHookInstructions","home","autoPatch","rc","fpathDir","fpathLine","compinitLine","rcExisting","needsFpath","needsCompinit","block","sourceLine","cmdName","cmd","subcommandsOf","c","n","optionsOf","out","emitZshFn","zshFnName","path","subs","optLines","zshOptionLine","s","name","argLines","line","entries","zshCommandEntry","i","last","sub","subFn","escapeZshDesc","escapeZshValue","opt","short","long","desc","tops","lines","subsubs","subOpts","collectBashFlags","ss","ssOpts","flags","escapeFish","fishOptionLine","subsub","conditions","shortRaw","longRaw","parts","buildProgram","packageInfo","getPackageInfo","program","Command","_thisCommand","actionCommand","path","commandPath","shouldRecordCommand","recordSurfaceUse","cmd","setup","init","connect","daemon","doctor","agent","channel","schedule","attach","guard","usage","serve","token","configCmd","completion","ADVANCED","names","c","wrapNames","wiki","graph","memory","procedure","references","rag","workflow","webhook","board","backlog","business","plan","ledger","trace","process_","watch","db","mesh","skillCmd","plugin","hook","actions","cron","migrate","retention","notifications","whatsapp","demo","chat","tui","width","indent","lines","line","n"]}