@vibecontrols/agent 2026.602.2 → 2026.602.3

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 (116) hide show
  1. package/dist/{agent-config-85pskv43.js → agent-config-4ppenhqp.js} +1 -1
  2. package/dist/{agent-ready-tracker-zp6p8e6f.js → agent-ready-tracker-kgs7td6t.js} +1 -1
  3. package/dist/app-9j2t5geq.js +2 -0
  4. package/dist/bootstrap-workspace-qgs6d5f0.js +2 -0
  5. package/dist/bootstrap.service-vg72w8pa.js +2 -0
  6. package/dist/{bridge-client-341r9rry.js → bridge-client-1fxza4p7.js} +1 -1
  7. package/dist/cli.js +1 -1
  8. package/dist/daemon-profile-gwdcqx0q.js +2 -0
  9. package/dist/esm-6f3dfn6v.js +2 -0
  10. package/dist/{finalize-retry-handle-registry-vv241fsq.js → finalize-retry-handle-registry-xnm9kxry.js} +1 -1
  11. package/dist/{finalize-retry-worker-xp1nhv3c.js → finalize-retry-worker-dvykrzed.js} +1 -1
  12. package/dist/gateway-client-9kwnmk89.js +2 -0
  13. package/dist/{getMachineId-bsd-a56s0v8c.js → getMachineId-bsd-753751sw.js} +1 -1
  14. package/dist/{getMachineId-darwin-w9k0yw9r.js → getMachineId-darwin-na1pranq.js} +1 -1
  15. package/dist/{getMachineId-linux-anh31jbf.js → getMachineId-linux-dmn0ncdm.js} +1 -1
  16. package/dist/{getMachineId-unsupported-5hv3pwca.js → getMachineId-unsupported-yv77j894.js} +1 -1
  17. package/dist/{getMachineId-win-njb8tery.js → getMachineId-win-9hmyqmm0.js} +1 -1
  18. package/dist/highlights-00fcgwwq.js +2 -0
  19. package/dist/highlights-23bc8zge.js +2 -0
  20. package/dist/highlights-4mhb2pb0.js +2 -0
  21. package/dist/highlights-q7w64nwb.js +2 -0
  22. package/dist/highlights-xwdw5xay.js +2 -0
  23. package/dist/{index-678rwfc0.js → index-0924jp9m.js} +1 -1
  24. package/dist/{index-fzzwprvk.js → index-11grwjm1.js} +5 -5
  25. package/dist/index-1evqt03m.js +11 -0
  26. package/dist/{index-z5a4yxzz.js → index-1mppacnx.js} +3 -3
  27. package/dist/{index-jw1k4vbk.js → index-4qq083yd.js} +1 -1
  28. package/dist/{index-d5ysy1yn.js → index-5dysvvjv.js} +1 -1
  29. package/dist/{index-n7qyrdr1.js → index-5wpck4aw.js} +1 -1
  30. package/dist/{index-mtm8cfyt.js → index-8053zege.js} +2 -2
  31. package/dist/{index-5mw3eshk.js → index-8nqp3a4d.js} +1 -1
  32. package/dist/{index-2xs9cvjn.js → index-8sdrhr3q.js} +2 -2
  33. package/dist/{index-6mprnf7p.js → index-97mq40rr.js} +1 -1
  34. package/dist/{index-1hnw0rhc.js → index-9f52em7g.js} +29 -29
  35. package/dist/{index-0cn9bv8z.js → index-a4854mwz.js} +1 -1
  36. package/dist/{index-g8zv1gta.js → index-atp2ayra.js} +1 -1
  37. package/dist/{index-xjzmb1pn.js → index-b6x6a4xp.js} +2 -2
  38. package/dist/{index-yy1mm8zs.js → index-c7554sg7.js} +1 -1
  39. package/dist/{index-2gsarrbn.js → index-d1xjj001.js} +1 -1
  40. package/dist/{index-h8a8s8sn.js → index-ebwwtwwc.js} +1 -1
  41. package/dist/{index-8sm0nkh8.js → index-ep3zb271.js} +1 -1
  42. package/dist/index-gxgftnbh.js +26 -0
  43. package/dist/{index-g2raeeh4.js → index-h74va4wd.js} +2 -2
  44. package/dist/{index-v9fx5wab.js → index-hvjqgb97.js} +1 -1
  45. package/dist/{index-g3ap3xpr.js → index-jdh30t6c.js} +4 -4
  46. package/dist/{index-9bqd8veb.js → index-js1xn4sq.js} +3 -3
  47. package/dist/{index-x1h8r7pr.js → index-kt5zxp42.js} +1 -1
  48. package/dist/{index-ssjmzqcz.js → index-n6bdbgb9.js} +1 -1
  49. package/dist/{index-rdp5xq4r.js → index-nrsqzcfc.js} +1 -1
  50. package/dist/index-p23tet7a.js +2 -0
  51. package/dist/{index-04n4qgvd.js → index-pgew6sge.js} +3 -3
  52. package/dist/{index-1zw3kea7.js → index-qwtspxw8.js} +1 -1
  53. package/dist/index-rqq0k5fc.js +16 -0
  54. package/dist/{index-6jq17k9s.js → index-rv6h14n8.js} +1 -1
  55. package/dist/{index-qfz9fy56.js → index-rw9x93zb.js} +1 -1
  56. package/dist/{index-dm6yjmgq.js → index-rzpaqrhx.js} +2 -2
  57. package/dist/{index-vdahdt49.js → index-tgrt61qr.js} +1 -1
  58. package/dist/{index-ef95xr4z.js → index-thammzct.js} +2 -2
  59. package/dist/{index-tp4y9jde.js → index-wccxsz72.js} +1 -1
  60. package/dist/{index-scsjyj4m.js → index-x649afed.js} +2 -2
  61. package/dist/{index-8kvc8ttn.js → index-xrs52f2c.js} +1 -1
  62. package/dist/{index-yrgm89r8.js → index-ydc0tk17.js} +1 -1
  63. package/dist/{index-0248afsn.js → index-z5s398n0.js} +1 -1
  64. package/dist/index.js +2 -2
  65. package/dist/injections-x3xya90r.js +2 -0
  66. package/dist/interactive-qc1j66mq.js +2 -0
  67. package/dist/key.cmd-972133dv.js +2 -0
  68. package/dist/log-shipper-hjnn1d5p.js +2 -0
  69. package/dist/{path-utils-35re7qf9.js → path-utils-hxdyv2zn.js} +1 -1
  70. package/dist/{plugin-system-c916v9an.js → plugin-system-8hby8x1m.js} +1 -1
  71. package/dist/prereqs-runner-27x3j1md.js +2 -0
  72. package/dist/profile-mount-8dc9jwt5.js +2 -0
  73. package/dist/prune-stale-shims-23y0stm8.js +2 -0
  74. package/dist/register-core-qcj272qh.js +2 -0
  75. package/dist/secondary-profile-attach-xkvpmm08.js +2 -0
  76. package/dist/subprocess-1nna3d3x.js +2 -0
  77. package/dist/telemetry-8jfdyt51.js +2 -0
  78. package/dist/tree-sitter-javascript-q22gvtms.js +2 -0
  79. package/dist/tree-sitter-markdown-pntsjzm3.js +2 -0
  80. package/dist/tree-sitter-markdown_inline-g1wzqf7k.js +2 -0
  81. package/dist/tree-sitter-typescript-m9yfes10.js +2 -0
  82. package/dist/tree-sitter-zig-jmh62j90.js +2 -0
  83. package/dist/tunnel-bootstrap-5wgt9a1h.js +2 -0
  84. package/package.json +1 -1
  85. package/dist/app-y4yzq7yw.js +0 -2
  86. package/dist/bootstrap-workspace-zpm20zez.js +0 -2
  87. package/dist/bootstrap.service-pjmnpxha.js +0 -2
  88. package/dist/daemon-profile-vas1vf2t.js +0 -2
  89. package/dist/esm-9fpye77x.js +0 -2
  90. package/dist/gateway-client-43gzvj5s.js +0 -2
  91. package/dist/highlights-8d9mgr01.js +0 -2
  92. package/dist/highlights-jwvdxm9x.js +0 -2
  93. package/dist/highlights-qbx2vnme.js +0 -2
  94. package/dist/highlights-r3m83kn9.js +0 -2
  95. package/dist/highlights-s7mqapt6.js +0 -2
  96. package/dist/index-01qzsnwd.js +0 -16
  97. package/dist/index-hrdamx5j.js +0 -2
  98. package/dist/index-tmrbs96r.js +0 -11
  99. package/dist/index-z2yjbq9a.js +0 -26
  100. package/dist/injections-srewsjcz.js +0 -2
  101. package/dist/interactive-22ta89hc.js +0 -2
  102. package/dist/key.cmd-wgcq6kt8.js +0 -2
  103. package/dist/log-shipper-k24m8yw5.js +0 -2
  104. package/dist/prereqs-runner-ca4kt803.js +0 -2
  105. package/dist/profile-mount-npcknw6v.js +0 -2
  106. package/dist/prune-stale-shims-nkx9vq5m.js +0 -2
  107. package/dist/register-core-xhrk6ay5.js +0 -2
  108. package/dist/secondary-profile-attach-db5cr3e1.js +0 -2
  109. package/dist/subprocess-g9sk1ep9.js +0 -2
  110. package/dist/telemetry-tnq47dcs.js +0 -2
  111. package/dist/tree-sitter-javascript-3h25c6bs.js +0 -2
  112. package/dist/tree-sitter-markdown-3nemcjhe.js +0 -2
  113. package/dist/tree-sitter-markdown_inline-16ftwa53.js +0 -2
  114. package/dist/tree-sitter-typescript-f6mq6ze6.js +0 -2
  115. package/dist/tree-sitter-zig-s2trkm2d.js +0 -2
  116. package/dist/tunnel-bootstrap-2kg79ng8.js +0 -2
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{L as r1}from"./index-2gsarrbn.js";import{M as b2}from"./index-b5dhmybd.js";import{O as a$,P as B1}from"./index-e1bw1bwr.js";import{$ as U2,Q as r$,R as c$,S as s0,T as r0,U as e$,V as e0,W as $0,X as $1,Y as D$,Z as E$,_ as J2,ca as z0,da as I2,ea as _2,fa as K0,ga as U1,ha as I1,ia as _1,ja as L2,ka as W0}from"./index-g8zv1gta.js";import{la as J$,ma as X$,na as B$,oa as Q1,ta as w2}from"./index-qfz9fy56.js";import{va as p}from"./index-ssjmzqcz.js";import{Ca as X2}from"./index-4wgjx8bf.js";import{Ea as t1,Fa as k$,Ha as o$,Ma as t0,Oa as s1,Pa as g2,Wa as s$}from"./index-g3ap3xpr.js";import{Xa as l}from"./index-0ckffygp.js";import{Ya as d1,ab as a}from"./index-rc79x8fw.js";import{db as P2}from"./index-52cp759f.js";import{Ib as M2}from"./index-01qzsnwd.js";import{gc as t$,hc as T$,ic as f,jc as P,kc as B,lc as q0}from"./index-5mw3eshk.js";import{Bc as x$,Cc as W$,Dc as u$,nc as K,oc as E,pc as L,qc as C,rc as U,sc as j,tc as W,uc as T,vc as I,wc as J,xc as n,yc as G$}from"./index-z5a4yxzz.js";import{Ec as b0,Fc as r,Gc as v$}from"./index-ef95xr4z.js";import{Kc as w,Mc as A,Nc as y,Oc as m,Pc as L0,Qc as P$}from"./index-xjzmb1pn.js";import{Rc as Z2,Tc as A0,Uc as a1,Wc as G2,Xc as f0,Zc as y$,ad as F2,bd as f$,cd as P0,dd as T2,ed as V0,fd as R2,gd as j2,hd as E2,id as N2,kd as B0,ld as O1,nd as Y$,pd as U$,td as a0}from"./index-g2raeeh4.js";import{Nd as c0,zd as O0}from"./index-9bqd8veb.js";import{$d as V$,Xd as Y0,_d as Q$,ae as N$,be as Z$}from"./index-0cn9bv8z.js";import{he as $$}from"./index-yy1mm8zs.js";import{existsSync as o0}from"fs";import{join as p2}from"path";import{createServer as n2}from"net";function i2(Y,q="0.0.0.0"){return new Promise(($)=>{let Z=n2();Z.once("error",()=>$(!1)),Z.once("listening",()=>{Z.close(()=>$(!0))}),Z.listen({host:q,port:Y,exclusive:!0})})}async function p0(Y,q="0.0.0.0"){let $=Y;while(!await i2($,q))if($++,$>65535)throw Error(`No free port found starting from ${Y}`);return $}function Y1(Y){Y.command("start").description("Start a VibeControls agent instance").option("-p, --port <port>","Port to listen on. Default: 3005 for the 'default' profile, deterministic 3100-3399 for any other profile (FNV-1a hash) so multiple profiles run side-by-side without EADDRINUSE.").option("-n, --name <name>","Agent instance name","default").option("-f, --foreground","Run in foreground mode (default: daemon)",!1).option("--db-path <path>","Path to the agent storage directory").option("--profile <profile>","Profile name for isolated config (env: VIBECONTROLS_PROFILE)").option("--host <host>","Host to bind to","0.0.0.0").option("--skip-plugin-install","Skip automatic installation of default plugins",!1).option("--skip-plugin <name>","Skip a specific default plugin (repeatable). Accepts the short pluginName or the full package name.",(q,$=[])=>[...$,q],[]).option("--no-install-deps","Skip auto-installing missing tools (installed by their plugins on start by default)").option("-y, --yes","Skip the first-run install consent prompt. Equivalent to VIBE_AUTO_ACCEPT=1; useful for CI / Docker / nohup contexts.",!1).option("--client-id <id>","Gateway OAuth client ID (env: VIBE_CLIENT_ID)").option("--client-secret <secret>","Gateway OAuth client secret (env: VIBE_CLIENT_SECRET)").option("--global-gateway-url <url>","Global gateway URL (env: VIBE_GLOBAL_GATEWAY_URL)").option("--workspace-gateway-url <url>","Workspace gateway URL (env: VIBE_WORKSPACE_GATEWAY_URL)").option("--workspace-id <id>","Workspace ID for auto-report (env: VIBE_WORKSPACE_ID)").option("--isolate <plugins>","Comma-separated list of plugin names to force into worker_threads isolation (Phase 4 hostile-plugin mode). Sets VIBE_ISOLATE_PLUGINS in the daemon env.").option("--profiles <names>","Comma-separated list of profiles to host in this daemon (multi-profile boot). When unset, the daemon hosts a single profile resolved via --profile / VIBECONTROLS_PROFILE / 'default'. Sets VIBECONTROLS_PROFILES in the daemon env so app boot can spin up additional ProfileContexts via the in-process registry.").option("--strict-key-fetch","Refuse to boot if any profile's encryption-key fetch fails. Default lenient: a failed profile is marked degraded and the daemon stays up. Sets VIBE_STRICT_KEY_FETCH=1 in the daemon env.",!1).option("--json","Emit JSON").option("--plain","Plain text output (no interactive TUI). Implied for non-TTY / CI.").option("--abilities <list>","Comma-separated ability keys to install non-interactively (e.g. session,ai,gitops). Storage/tunnel/backup are always included.").option("--providers <list>","Comma-separated extra provider plugins to install beyond each meta's default (e.g. session-wezterm,ai-claude). Accepts short names or @vibecontrols/... packages. Persisted; manage later with `vibe capability`.").option("--wait-ready [seconds]","Block until the agent is fully ready (or fails). Polls /health/ready and renders phase transitions live. Without a value, defaults to 60s. Exits non-zero if the agent ends up degraded or times out. Useful for scripts/CI.").option("--no-wait","Skip the phase tracker entirely after spawning the daemon. Restores the old fire-and-print behavior \u2014 for users who want the previous quick-return UX.").action(async function(q){let $={...Y.opts(),...q};try{let x=function(h){if(h==="default")return 3005;let d=2166136261;for(let g=0;g<h.length;g++)d=Math.imul(d^h.charCodeAt(g),16777619);return 3100+Math.abs(d)%300},Z=new p,X=q.profile||process.env.VIBECONTROLS_PROFILE||"default";if(process.env.VIBECONTROLS_PROFILE=X,typeof q.isolate==="string"&&q.isolate.length>0)process.env.VIBE_ISOLATE_PLUGINS=q.isolate;if(typeof q.profiles==="string"&&q.profiles.length>0){let h=q.profiles.split(",").map((d)=>d.trim()).filter(Boolean);if(h.length>0){if(process.env.VIBECONTROLS_PROFILES=h.join(","),process.env.VIBECONTROLS_PROFILE=h[0],h.length>1)j(`--profiles received ${h.length} entries; daemon boots with '${h[0]}'. Remaining (${h.slice(1).join(", ")}) will be attached via /api/profiles after listen.`)}}if(q.strictKeyFetch===!0)process.env.VIBE_STRICT_KEY_FETCH="1";a0();let H=q.dbPath||N$(),Q=Z$(),z=!o0(H)&&!o0(p2(Q,"agents.json")),V=f($),_=V!=="json"&&V!=="plain"&&t$()&&q.yes!==!0,O=r$(Q),F;if(typeof $.abilities==="string"&&$.abilities.trim()!=="")F=e0($.abilities);else if(O!==null)F=O;else if(_)F=await e$();else F=$0();let D=typeof $.providers==="string"&&$.providers.trim()!=="",R=D?s0($.providers):c$(Q);if(O===null){let h=r0({installDeps:q.installDeps===!0,skipPluginInstall:q.skipPluginInstall===!0,skipPlugins:Array.isArray(q.skipPlugin)?q.skipPlugin:[]},F);if(z&&h.plugins.length>0)J(),W(`Installing ${h.plugins.length} plugin(s) for the selected abilities.`),J();$1(Q,h,F,process.env.VIBE_AGENT_VERSION,R)}else if(D)D$(Q,{providers:R,agentVersion:process.env.VIBE_AGENT_VERSION});if((z||D)&&R.length>0&&q.skipPluginInstall!==!0){W(`Installing ${R.length} selected provider plugin(s)...`);try{let{PluginManager:h}=await import("./plugin-system-c916v9an.js"),d=new h;for(let g of R)try{await d.install(g),U(`Installed provider ${g}`)}catch(k){j(`Could not install provider ${g}: ${k instanceof Error?k.message:String(k)}`)}}catch(h){j(`Provider install skipped: ${h instanceof Error?h.message:String(h)}`)}J()}if(z){W("First run detected \u2014 running setup..."),J();let h=Array.isArray(q.skipPlugin)?q.skipPlugin:[],d=q.skipPluginInstall?[]:o$(process.platform,F).filter((s)=>!h.includes(s.packageName)&&!h.includes(s.pluginName)).map((s)=>s.packageName),g=t0(d),K$=a$(g).filter((s)=>!s.installed);if(K$.length>0)if(j(`Missing tools: ${K$.map((s)=>s.name).join(", ")}`),q.installDeps)W("Their plugins will install them automatically on startup.");else W("Auto-install skipped (`--no-install-deps`) \u2014 install them yourself or drop the flag.");else U("All plugin tools present.");J()}if(!q.skipPluginInstall){let h=Array.isArray(q.skipPlugin)?q.skipPlugin:[],d=new s$;await d.loadCorePlugins(),await d.loadAll();let g=await d.ensureDefaultPlugins((k)=>{if(k.startsWith("No "))j(k);else if(k.startsWith("Installed "))U(k);else if(k.startsWith("Failed "))j(k);else W(k)},h,F);if(g.length>0)U(`Auto-installed ${g.length} default plugin${g.length>1?"s":""}.`),J()}let G=q.profile||process.env.VIBECONTROLS_PROFILE||q.name||"default",M=q.port?parseInt(q.port,10):x(G);if(isNaN(M)||M<1||M>65535)L("Invalid port number. Must be between 1 and 65535.");let N=await p0(M);if(N!==M)j(`Port ${M} is in use. Auto-selecting port ${K.bold(String(N))} instead.`),M=N;let S=q.host,q$=`http://${S==="0.0.0.0"?"localhost":S}:${M}`,o=q.clientId||process.env.VIBE_CLIENT_ID,v=q.clientSecret||process.env.VIBE_CLIENT_SECRET,u=q.globalGatewayUrl||process.env.VIBE_GLOBAL_GATEWAY_URL,c=q.workspaceGatewayUrl||process.env.VIBE_WORKSPACE_GATEWAY_URL,O$=q.workspaceId||process.env.VIBE_WORKSPACE_ID;if(o&&!v)L("--client-secret is required when --client-id is provided.");if(v&&!o)L("--client-id is required when --client-secret is provided.");if(o&&v){if(!u&&!process.env.VIBE_GLOBAL_GATEWAY_URL)L("--global-gateway-url is required when providing client credentials (none set in env).");if(process.env.VIBE_CLIENT_ID=o,process.env.VIBE_CLIENT_SECRET=v,u)process.env.VIBE_GLOBAL_GATEWAY_URL=u;let{writeAgentConfig:h}=await import("./agent-config-85pskv43.js");if(h({clientId:o,clientSecret:v,workspaceId:O$,globalGatewayUrl:u,workspaceGatewayUrl:c}),c)process.env.VIBE_WORKSPACE_GATEWAY_URL=c;if(O$)process.env.VIBE_WORKSPACE_ID=O$;U("Gateway credentials staged in env. Agent will authenticate and persist them on startup."),J()}else if(c||O$||u){if(j("Workspace options provided without --client-id / --client-secret \u2014 they will be staged in env but unused until credentials are configured."),c)process.env.VIBE_WORKSPACE_GATEWAY_URL=c;if(O$)process.env.VIBE_WORKSPACE_ID=O$;if(u)process.env.VIBE_GLOBAL_GATEWAY_URL=u;J()}if(q.foreground){if(!$.json)T("Starting agent in foreground"),I("Name",q.name),I("Port",String(M)),I("Host",S),I("Database",H),J();let{bootstrapWorkspace:h}=await import("./bootstrap-workspace-zpm20zez.js");h();let{createApp:d}=await import("./app-y4yzq7yw.js"),g=await d({port:M,host:S,dbPath:H});if(await g.start(),o&&v&&O$&&u&&c){let K$=await g.finalize({clientId:o,clientSecret:v,workspaceId:O$,globalGatewayUrl:u,workspaceGatewayUrl:c});if(!K$.ok)j(`Finalize failed \u2014 agent remains in awaiting-config state: ${K$.error}`)}if(B($,{ok:!0,name:q.name,port:M,host:S,pid:process.pid,url:q$}));else await u$(q$);let k=async()=>{await g.stop(),process.exit(0)};process.on("SIGTERM",k),process.on("SIGINT",k)}else{if(!$.json)T("Starting agent in daemon mode"),I("Name",q.name),I("Port",String(M)),I("Host",S),I("Database",H),J();if(q.installDeps===!1)process.env.VIBE_SKIP_PREREQ_INSTALL="1";await Z.startDaemon({port:M,name:q.name,daemon:!0,dbPath:H,host:S,profile:X});let d=(await Z.getStatus(q.name))?.port??M,k=`http://${S==="0.0.0.0"?"localhost":S}:${d}`,K$=q.waitReady,s=q.wait===!1,l0=K$!==void 0;if(s&&l0)j("--wait-ready is ignored because --no-wait was also passed.");let p$=!s&&l0,n0=!s&&(p$||!$.json),i0=(()=>{let C$=typeof K$==="string"?Number.parseInt(K$,10):NaN;if(Number.isInteger(C$)&&C$>0)return C$*1000;return p$?60000:25000})();if($.json){if(n0){let{trackAgentReady:C$}=await import("./agent-ready-tracker-zp6p8e6f.js"),e=await C$(k,{timeoutMs:i0,verbose:!1});if(p$&&(e.outcome==="degraded"||e.outcome==="timeout"))process.exitCode=1;B($,{ok:e.outcome==="ready"||e.outcome==="awaiting-config",name:q.name,port:d,host:S,url:k,abilities:[...F],outcome:e.outcome,bootState:e.bootState,degradedReasons:e.degradedReasons,summary:e.summary})}else B($,{ok:!0,name:q.name,port:d,host:S,url:k});return}if(await u$(k),n0){let{trackAgentReady:C$}=await import("./agent-ready-tracker-zp6p8e6f.js");J();let e=await C$(k,{timeoutMs:i0,verbose:!0});if(p$&&(e.outcome==="degraded"||e.outcome==="timeout"))process.exitCode=1}}}catch(Z){let X=Z instanceof Error?C(Z):String(Z);if($.json){B($,{ok:!1,error:X});return}L(`Failed to start agent: ${X}`)}})}function q1(Y){Y.command("stop").description("Stop a running VibeControls agent instance").option("-n, --name <name>","Agent instance name","default").option("--all","Stop all running agent instances",!1).option("--json","Emit JSON").action(async function(q){let $={...Y.opts(),...q};try{let Z=new p;if(q.all){let X=await Z.listInstances();if(!X||X.length===0){if(B($,{ok:!0,stopped:[]}))return;T("Stopping all agent instances"),J(),W(`${E.info} No running agent instances found.`);return}let H=[];if(!$.json)T("Stopping all agent instances"),J();for(let Q of X)try{if(await Z.stop(Q.name),H.push(Q.name),!$.json)U(`${E.success} Stopped ${K.bold(Q.name)}`)}catch{if(!$.json)L(`Failed to stop ${K.bold(Q.name)}`)}if(B($,{ok:!0,stopped:H,total:X.length}))return;J(),U(`${E.success} Stopped ${H.length}/${X.length} instance(s).`)}else{if(await Z.stop(q.name),B($,{ok:!0,name:q.name}))return;T(`Stopping agent: ${q.name}`),J(),U(`${E.success} Agent ${K.bold(q.name)} stopped.`)}}catch(Z){if($.json){B($,{ok:!1,error:C(Z)});return}L(`Failed to stop agent: ${C(Z)}`)}})}function Z1(Y){Y.command("restart").description("Restart a running VibeControls agent instance").option("-n, --name <name>","Agent instance name","default").option("-p, --port <port>","Port to listen on").option("--db-path <path>","Path to the agent storage directory").option("--json","Emit JSON").action(async function(q){let $={...Y.opts(),...q};try{let Z=new p;if(!$.json)T(`Restarting agent: ${q.name}`),J(),W(`${E.info} Stopping agent ${K.bold(q.name)}...`);let X=await Z.getStatus(q.name);try{if(await Z.stop(q.name),!$.json)U(`${E.success} Agent stopped.`)}catch{if(!$.json)W(`${E.info} Agent was not running.`)}let H=q.port??X?.port??3005,Q=typeof H==="number"?H:parseInt(H,10);if(isNaN(Q)||Q<1||Q>65535){if($.json){B($,{ok:!1,error:"Invalid port number"});return}L("Invalid port number. Must be between 1 and 65535.");return}let z={port:Q,name:q.name,daemon:!0,dbPath:q.dbPath??X?.config?.dbPath??N$(),host:X?.config?.host,profile:X?.config?.profile};if(!$.json)J(),W(`${E.info} Starting agent ${K.bold(q.name)}...`);await Z.startDaemon(z);let V=`http://localhost:${Q}`;if(B($,{ok:!0,name:q.name,port:Q,url:V}))return;J(),U(`${E.success} Agent ${K.bold(q.name)} restarted.`),J(),I("Port",String(Q)),I("Database",z.dbPath),J(),u$(V)}catch(Z){if($.json){B($,{ok:!1,error:C(Z)});return}L(`Failed to restart agent: ${C(Z)}`)}})}import{existsSync as o2,readFileSync as a2,unlinkSync as X1}from"fs";import{join as z1}from"path";function t2(Y){let q=z1(V$(),Y,"runtime.json");if(!o2(q))return null;try{let $=JSON.parse(a2(q,"utf8"));if(typeof $.pid!=="number")return null;return{...$,pid:$.pid,path:q}}catch{return null}}async function H1(Y){let q=t2(Y);if(!q)return null;if(!B$(q.pid)){try{X1(q.path)}catch{}return`agent pid=${q.pid} (${Y}) already gone (cleaned runtime.json).`}let $=l();if(!$.killProcessTree(q.pid,"SIGTERM"))return`failed to SIGTERM agent pid=${q.pid}.`;if(await new Promise((Z)=>setTimeout(Z,3000)),B$(q.pid))$.killProcessTree(q.pid,"SIGKILL");try{X1(q.path)}catch{}return`agent ${Y} pid=${q.pid}${q.port?` (port ${q.port})`:""} killed.`}async function s2(Y){let q=z1(V$(),Y),$=J$(q);if(!$)return null;if(!B$($.pid))return X$(q),`tunnel pid=${$.pid} already gone (cleaned state).`;let Z=l();if(!Z.killProcessTree($.pid,"SIGTERM"))return`failed to SIGTERM tunnel pid=${$.pid}.`;if(await new Promise((X)=>setTimeout(X,3000)),B$($.pid))Z.killProcessTree($.pid,"SIGKILL");return X$(q),`tunnel ${$.provider} pid=${$.pid} (${$.url??"no url"}) killed.`}function W1(Y){Y.command("kill").description("Force-kill an agent instance and its tunnel. Defaults to active profile.").option("-n, --name <name>","Agent instance name (alias of --profile, kept for back-compat)").option("--profile <name>","Kill a specific profile (overrides --name and VIBECONTROLS_PROFILE)").option("--all","Kill every agent instance and every profile's tunnel",!1).option("-y, --yes","Skip the confirmation prompt (for scripts/CI)",!1).option("--json","Emit JSON").action(async function(q){let $={...Y.opts(),...q},Z=q.all?"ALL agent instances + every profile's tunnel":`agent '${$.profile??$.name??"active profile"}'`;if(!await q0($,`Force-kill ${Z}? This sends SIGKILL (no graceful shutdown).`)){W("Aborted.");return}let X=[];try{let H=new p;if(q.all){if(!$.json)T("Force killing all agent instances + tunnels"),J();let _=await H.listInstances()??[],O=0,F=new Set;for(let G of _)try{if(await H.kill(G.name),!$.json)U(`${E.success} agent ${K.bold(G.name)} (pid=${G.pid||"?"}) killed.`);X.push(G.name),O++,F.add(G.name)}catch{if(!$.json)j(`${E.warning} could not kill agent ${G.name}.`)}try{let G=await import("fs"),x=V$(),M=G.existsSync(x)?G.readdirSync(x):[];for(let N of M){if(F.has(N))continue;let S=await H1(N);if(S)U(`${E.success} ${S}`),O++}}catch(G){j(`${E.warning} runtime.json sweep failed: ${G instanceof Error?C(G):String(G)}`)}let D=Q1({allProfiles:!0}),R=0;for(let G of D){if(!G.alive){X$(G.profileDir);continue}let x=l();if(x.killProcessTree(G.pid,"SIGTERM"),await new Promise((M)=>setTimeout(M,3000)),B$(G.pid))x.killProcessTree(G.pid,"SIGKILL");X$(G.profileDir),U(`${E.success} tunnel ${G.provider} pid=${G.pid} (${G.url??"no url"}, ${G.profileDir.split("/").pop()}) killed.`),R++}if(B($,{ok:!0,killed:X,tunnels:R}))return;J(),U(`${E.success} killed ${O} agent(s) and ${R} tunnel(s).`);return}let Q=q.profile||q.name||Y0();if(!$.json)T(`Force killing profile: ${Q}`),J();let z=await H.getStatus(Q);if(z){if(await H.kill(Q),X.push(Q),!$.json)U(`${E.success} agent ${K.bold(Q)} pid=${z.pid||"?"} killed.`)}else{let _=await H1(Q);if(_){if(X.push(Q),!$.json)U(`${E.success} ${_}`)}else if(!$.json)W(`${E.info} no running agent service for profile ${Q}.`)}let V=await s2(Q);if(V){if(!$.json)U(`${E.success} ${V}`)}else if(!$.json)W(`${E.info} no tunnel recorded for profile ${Q}.`);B($,{ok:!0,killed:X})}catch(H){if($.json){B($,{ok:!1,error:C(H)});return}L(`Failed to kill: ${C(H)}`)}})}function K1(Y){Y.command("list").alias("ls").description("List all VibeControls agent instances").option("--json","Emit JSON").option("--plain","Force plain text output").action(async function(q){try{let $={...Y.opts(),...q},Z=new p;await P({mode:f($),fetchData:()=>Z.listInstances(),plain:(X)=>{if(T("Agent Instances"),J(),!X||X.length===0){W(`${E.info} No agent instances found.`),W(`Run ${K.bold("vibe start")} to start an agent.`);return}let H=X.map((V)=>({Name:V.name,Status:x$(V.status),PID:V.pid||"-",Port:V.port||"-",Host:V.config?.host||"-",Database:V.config?.dbPath||"-",Started:V.startTime?G$(V.startTime):"-"}));n(H),J();let Q=X.filter((V)=>V.status==="running").length,z=X.length-Q;W(`${E.info} ${X.length} instance(s): ${K.green(String(Q))} running, ${K.dim(String(z))} stopped`)},interactive:async(X)=>{if(!X||X.length===0){T("Agent Instances"),J(),W(`${E.info} No agent instances found.`),W(`Run ${K.bold("vibe start")} to start an agent.`);return}let H=X.map((Q)=>{let z=[`${K.bold(Q.name)} ${x$(Q.status)}`,"",` PID: ${Q.pid??"-"}`,` Port: ${Q.port??"-"}`,` Host: ${Q.config?.host??"-"}`,` Database: ${Q.config?.dbPath??"-"}`,` Started: ${Q.startTime?G$(Q.startTime):"-"}`];return{id:Q.name,label:Q.name,hint:Q.status==="running"?"running":"stopped",detail:z.join(`
2
+ import{L as r1}from"./index-d1xjj001.js";import{M as b2}from"./index-b5dhmybd.js";import{O as a$,P as B1}from"./index-e1bw1bwr.js";import{$ as U2,Q as r$,R as c$,S as s0,T as r0,U as e$,V as e0,W as $0,X as $1,Y as D$,Z as E$,_ as J2,ca as z0,da as I2,ea as _2,fa as K0,ga as U1,ha as I1,ia as _1,ja as L2,ka as W0}from"./index-atp2ayra.js";import{la as J$,ma as X$,na as B$,oa as Q1,ta as w2}from"./index-rw9x93zb.js";import{va as p}from"./index-n6bdbgb9.js";import{Ca as X2}from"./index-4wgjx8bf.js";import{Ea as t1,Fa as k$,Ha as o$,Ma as t0,Oa as s1,Pa as g2,Wa as s$}from"./index-jdh30t6c.js";import{Xa as l}from"./index-0ckffygp.js";import{Ya as d1,ab as a}from"./index-rc79x8fw.js";import{db as P2}from"./index-52cp759f.js";import{Ib as M2}from"./index-rqq0k5fc.js";import{hc as t$,ic as T$,jc as f,kc as P,lc as B,mc as q0}from"./index-8nqp3a4d.js";import{Cc as x$,Dc as W$,Ec as u$,oc as K,pc as E,qc as L,rc as C,sc as U,tc as j,uc as W,vc as T,wc as I,xc as J,yc as n,zc as G$}from"./index-1mppacnx.js";import{Fc as b0,Gc as r,Hc as v$}from"./index-thammzct.js";import{Lc as w,Nc as A,Oc as y,Pc as m,Qc as L0,Rc as P$}from"./index-b6x6a4xp.js";import{Sc as Z2,Uc as A0,Vc as a1,Xc as G2,Yc as f0,_c as y$,bd as F2,cd as f$,dd as P0,ed as T2,fd as V0,gd as R2,hd as j2,id as E2,jd as N2,ld as B0,md as O1,od as Y$,qd as U$,ud as a0}from"./index-h74va4wd.js";import{Ad as O0,Od as c0}from"./index-js1xn4sq.js";import{$d as Q$,Yd as Y0,ae as V$,be as N$,ce as Z$}from"./index-a4854mwz.js";import{ie as $$}from"./index-c7554sg7.js";import{existsSync as o0}from"fs";import{join as p2}from"path";import{createServer as n2}from"net";function i2(Y,q="0.0.0.0"){return new Promise(($)=>{let Z=n2();Z.once("error",()=>$(!1)),Z.once("listening",()=>{Z.close(()=>$(!0))}),Z.listen({host:q,port:Y,exclusive:!0})})}async function p0(Y,q="0.0.0.0"){let $=Y;while(!await i2($,q))if($++,$>65535)throw Error(`No free port found starting from ${Y}`);return $}function Y1(Y){Y.command("start").description("Start a VibeControls agent instance").option("-p, --port <port>","Port to listen on. Default: 3005 for the 'default' profile, deterministic 3100-3399 for any other profile (FNV-1a hash) so multiple profiles run side-by-side without EADDRINUSE.").option("-n, --name <name>","Agent instance name","default").option("-f, --foreground","Run in foreground mode (default: daemon)",!1).option("--db-path <path>","Path to the agent storage directory").option("--profile <profile>","Profile name for isolated config (env: VIBECONTROLS_PROFILE)").option("--host <host>","Host to bind to","0.0.0.0").option("--skip-plugin-install","Skip automatic installation of default plugins",!1).option("--skip-plugin <name>","Skip a specific default plugin (repeatable). Accepts the short pluginName or the full package name.",(q,$=[])=>[...$,q],[]).option("--no-install-deps","Skip auto-installing missing tools (installed by their plugins on start by default)").option("-y, --yes","Skip the first-run install consent prompt. Equivalent to VIBE_AUTO_ACCEPT=1; useful for CI / Docker / nohup contexts.",!1).option("--client-id <id>","Gateway OAuth client ID (env: VIBE_CLIENT_ID)").option("--client-secret <secret>","Gateway OAuth client secret (env: VIBE_CLIENT_SECRET)").option("--global-gateway-url <url>","Global gateway URL (env: VIBE_GLOBAL_GATEWAY_URL)").option("--workspace-gateway-url <url>","Workspace gateway URL (env: VIBE_WORKSPACE_GATEWAY_URL)").option("--workspace-id <id>","Workspace ID for auto-report (env: VIBE_WORKSPACE_ID)").option("--isolate <plugins>","Comma-separated list of plugin names to force into worker_threads isolation (Phase 4 hostile-plugin mode). Sets VIBE_ISOLATE_PLUGINS in the daemon env.").option("--profiles <names>","Comma-separated list of profiles to host in this daemon (multi-profile boot). When unset, the daemon hosts a single profile resolved via --profile / VIBECONTROLS_PROFILE / 'default'. Sets VIBECONTROLS_PROFILES in the daemon env so app boot can spin up additional ProfileContexts via the in-process registry.").option("--strict-key-fetch","Refuse to boot if any profile's encryption-key fetch fails. Default lenient: a failed profile is marked degraded and the daemon stays up. Sets VIBE_STRICT_KEY_FETCH=1 in the daemon env.",!1).option("--json","Emit JSON").option("--plain","Plain text output (no interactive TUI). Implied for non-TTY / CI.").option("--abilities <list>","Comma-separated ability keys to install non-interactively (e.g. session,ai,gitops). Storage/tunnel/backup are always included.").option("--providers <list>","Comma-separated extra provider plugins to install beyond each meta's default (e.g. session-wezterm,ai-claude). Accepts short names or @vibecontrols/... packages. Persisted; manage later with `vibe capability`.").option("--wait-ready [seconds]","Block until the agent is fully ready (or fails). Polls /health/ready and renders phase transitions live. Without a value, defaults to 60s. Exits non-zero if the agent ends up degraded or times out. Useful for scripts/CI.").option("--no-wait","Skip the phase tracker entirely after spawning the daemon. Restores the old fire-and-print behavior \u2014 for users who want the previous quick-return UX.").action(async function(q){let $={...Y.opts(),...q};try{let x=function(h){if(h==="default")return 3005;let d=2166136261;for(let g=0;g<h.length;g++)d=Math.imul(d^h.charCodeAt(g),16777619);return 3100+Math.abs(d)%300},Z=new p,X=q.profile||process.env.VIBECONTROLS_PROFILE||"default";if(process.env.VIBECONTROLS_PROFILE=X,typeof q.isolate==="string"&&q.isolate.length>0)process.env.VIBE_ISOLATE_PLUGINS=q.isolate;if(typeof q.profiles==="string"&&q.profiles.length>0){let h=q.profiles.split(",").map((d)=>d.trim()).filter(Boolean);if(h.length>0){if(process.env.VIBECONTROLS_PROFILES=h.join(","),process.env.VIBECONTROLS_PROFILE=h[0],h.length>1)j(`--profiles received ${h.length} entries; daemon boots with '${h[0]}'. Remaining (${h.slice(1).join(", ")}) will be attached via /api/profiles after listen.`)}}if(q.strictKeyFetch===!0)process.env.VIBE_STRICT_KEY_FETCH="1";a0();let H=q.dbPath||N$(),Q=Z$(),z=!o0(H)&&!o0(p2(Q,"agents.json")),V=f($),_=V!=="json"&&V!=="plain"&&t$()&&q.yes!==!0,O=r$(Q),F;if(typeof $.abilities==="string"&&$.abilities.trim()!=="")F=e0($.abilities);else if(O!==null)F=O;else if(_)F=await e$();else F=$0();let D=typeof $.providers==="string"&&$.providers.trim()!=="",R=D?s0($.providers):c$(Q);if(O===null){let h=r0({installDeps:q.installDeps===!0,skipPluginInstall:q.skipPluginInstall===!0,skipPlugins:Array.isArray(q.skipPlugin)?q.skipPlugin:[]},F);if(z&&h.plugins.length>0)J(),W(`Installing ${h.plugins.length} plugin(s) for the selected abilities.`),J();$1(Q,h,F,process.env.VIBE_AGENT_VERSION,R)}else if(D)D$(Q,{providers:R,agentVersion:process.env.VIBE_AGENT_VERSION});if((z||D)&&R.length>0&&q.skipPluginInstall!==!0){W(`Installing ${R.length} selected provider plugin(s)...`);try{let{PluginManager:h}=await import("./plugin-system-8hby8x1m.js"),d=new h;for(let g of R)try{await d.install(g),U(`Installed provider ${g}`)}catch(k){j(`Could not install provider ${g}: ${k instanceof Error?k.message:String(k)}`)}}catch(h){j(`Provider install skipped: ${h instanceof Error?h.message:String(h)}`)}J()}if(z){W("First run detected \u2014 running setup..."),J();let h=Array.isArray(q.skipPlugin)?q.skipPlugin:[],d=q.skipPluginInstall?[]:o$(process.platform,F).filter((s)=>!h.includes(s.packageName)&&!h.includes(s.pluginName)).map((s)=>s.packageName),g=t0(d),K$=a$(g).filter((s)=>!s.installed);if(K$.length>0)if(j(`Missing tools: ${K$.map((s)=>s.name).join(", ")}`),q.installDeps)W("Their plugins will install them automatically on startup.");else W("Auto-install skipped (`--no-install-deps`) \u2014 install them yourself or drop the flag.");else U("All plugin tools present.");J()}if(!q.skipPluginInstall){let h=Array.isArray(q.skipPlugin)?q.skipPlugin:[],d=new s$;await d.loadCorePlugins(),await d.loadAll();let g=await d.ensureDefaultPlugins((k)=>{if(k.startsWith("No "))j(k);else if(k.startsWith("Installed "))U(k);else if(k.startsWith("Failed "))j(k);else W(k)},h,F);if(g.length>0)U(`Auto-installed ${g.length} default plugin${g.length>1?"s":""}.`),J()}let G=q.profile||process.env.VIBECONTROLS_PROFILE||q.name||"default",M=q.port?parseInt(q.port,10):x(G);if(isNaN(M)||M<1||M>65535)L("Invalid port number. Must be between 1 and 65535.");let N=await p0(M);if(N!==M)j(`Port ${M} is in use. Auto-selecting port ${K.bold(String(N))} instead.`),M=N;let S=q.host,q$=`http://${S==="0.0.0.0"?"localhost":S}:${M}`,o=q.clientId||process.env.VIBE_CLIENT_ID,v=q.clientSecret||process.env.VIBE_CLIENT_SECRET,u=q.globalGatewayUrl||process.env.VIBE_GLOBAL_GATEWAY_URL,c=q.workspaceGatewayUrl||process.env.VIBE_WORKSPACE_GATEWAY_URL,O$=q.workspaceId||process.env.VIBE_WORKSPACE_ID;if(o&&!v)L("--client-secret is required when --client-id is provided.");if(v&&!o)L("--client-id is required when --client-secret is provided.");if(o&&v){if(!u&&!process.env.VIBE_GLOBAL_GATEWAY_URL)L("--global-gateway-url is required when providing client credentials (none set in env).");if(process.env.VIBE_CLIENT_ID=o,process.env.VIBE_CLIENT_SECRET=v,u)process.env.VIBE_GLOBAL_GATEWAY_URL=u;let{writeAgentConfig:h}=await import("./agent-config-4ppenhqp.js");if(h({clientId:o,clientSecret:v,workspaceId:O$,globalGatewayUrl:u,workspaceGatewayUrl:c}),c)process.env.VIBE_WORKSPACE_GATEWAY_URL=c;if(O$)process.env.VIBE_WORKSPACE_ID=O$;U("Gateway credentials staged in env. Agent will authenticate and persist them on startup."),J()}else if(c||O$||u){if(j("Workspace options provided without --client-id / --client-secret \u2014 they will be staged in env but unused until credentials are configured."),c)process.env.VIBE_WORKSPACE_GATEWAY_URL=c;if(O$)process.env.VIBE_WORKSPACE_ID=O$;if(u)process.env.VIBE_GLOBAL_GATEWAY_URL=u;J()}if(q.foreground){if(!$.json)T("Starting agent in foreground"),I("Name",q.name),I("Port",String(M)),I("Host",S),I("Database",H),J();let{bootstrapWorkspace:h}=await import("./bootstrap-workspace-qgs6d5f0.js");h();let{createApp:d}=await import("./app-9j2t5geq.js"),g=await d({port:M,host:S,dbPath:H});if(await g.start(),o&&v&&O$&&u&&c){let K$=await g.finalize({clientId:o,clientSecret:v,workspaceId:O$,globalGatewayUrl:u,workspaceGatewayUrl:c});if(!K$.ok)j(`Finalize failed \u2014 agent remains in awaiting-config state: ${K$.error}`)}if(B($,{ok:!0,name:q.name,port:M,host:S,pid:process.pid,url:q$}));else await u$(q$);let k=async()=>{await g.stop(),process.exit(0)};process.on("SIGTERM",k),process.on("SIGINT",k)}else{if(!$.json)T("Starting agent in daemon mode"),I("Name",q.name),I("Port",String(M)),I("Host",S),I("Database",H),J();if(q.installDeps===!1)process.env.VIBE_SKIP_PREREQ_INSTALL="1";await Z.startDaemon({port:M,name:q.name,daemon:!0,dbPath:H,host:S,profile:X});let d=(await Z.getStatus(q.name))?.port??M,k=`http://${S==="0.0.0.0"?"localhost":S}:${d}`,K$=q.waitReady,s=q.wait===!1,l0=K$!==void 0;if(s&&l0)j("--wait-ready is ignored because --no-wait was also passed.");let p$=!s&&l0,n0=!s&&(p$||!$.json),i0=(()=>{let C$=typeof K$==="string"?Number.parseInt(K$,10):NaN;if(Number.isInteger(C$)&&C$>0)return C$*1000;return p$?60000:25000})();if($.json){if(n0){let{trackAgentReady:C$}=await import("./agent-ready-tracker-kgs7td6t.js"),e=await C$(k,{timeoutMs:i0,verbose:!1});if(p$&&(e.outcome==="degraded"||e.outcome==="timeout"))process.exitCode=1;B($,{ok:e.outcome==="ready"||e.outcome==="awaiting-config",name:q.name,port:d,host:S,url:k,abilities:[...F],outcome:e.outcome,bootState:e.bootState,degradedReasons:e.degradedReasons,summary:e.summary})}else B($,{ok:!0,name:q.name,port:d,host:S,url:k});return}if(await u$(k),n0){let{trackAgentReady:C$}=await import("./agent-ready-tracker-kgs7td6t.js");J();let e=await C$(k,{timeoutMs:i0,verbose:!0});if(p$&&(e.outcome==="degraded"||e.outcome==="timeout"))process.exitCode=1}}}catch(Z){let X=Z instanceof Error?C(Z):String(Z);if($.json){B($,{ok:!1,error:X});return}L(`Failed to start agent: ${X}`)}})}function q1(Y){Y.command("stop").description("Stop a running VibeControls agent instance").option("-n, --name <name>","Agent instance name","default").option("--all","Stop all running agent instances",!1).option("--json","Emit JSON").action(async function(q){let $={...Y.opts(),...q};try{let Z=new p;if(q.all){let X=await Z.listInstances();if(!X||X.length===0){if(B($,{ok:!0,stopped:[]}))return;T("Stopping all agent instances"),J(),W(`${E.info} No running agent instances found.`);return}let H=[];if(!$.json)T("Stopping all agent instances"),J();for(let Q of X)try{if(await Z.stop(Q.name),H.push(Q.name),!$.json)U(`${E.success} Stopped ${K.bold(Q.name)}`)}catch{if(!$.json)L(`Failed to stop ${K.bold(Q.name)}`)}if(B($,{ok:!0,stopped:H,total:X.length}))return;J(),U(`${E.success} Stopped ${H.length}/${X.length} instance(s).`)}else{if(await Z.stop(q.name),B($,{ok:!0,name:q.name}))return;T(`Stopping agent: ${q.name}`),J(),U(`${E.success} Agent ${K.bold(q.name)} stopped.`)}}catch(Z){if($.json){B($,{ok:!1,error:C(Z)});return}L(`Failed to stop agent: ${C(Z)}`)}})}function Z1(Y){Y.command("restart").description("Restart a running VibeControls agent instance").option("-n, --name <name>","Agent instance name","default").option("-p, --port <port>","Port to listen on").option("--db-path <path>","Path to the agent storage directory").option("--json","Emit JSON").action(async function(q){let $={...Y.opts(),...q};try{let Z=new p;if(!$.json)T(`Restarting agent: ${q.name}`),J(),W(`${E.info} Stopping agent ${K.bold(q.name)}...`);let X=await Z.getStatus(q.name);try{if(await Z.stop(q.name),!$.json)U(`${E.success} Agent stopped.`)}catch{if(!$.json)W(`${E.info} Agent was not running.`)}let H=q.port??X?.port??3005,Q=typeof H==="number"?H:parseInt(H,10);if(isNaN(Q)||Q<1||Q>65535){if($.json){B($,{ok:!1,error:"Invalid port number"});return}L("Invalid port number. Must be between 1 and 65535.");return}let z={port:Q,name:q.name,daemon:!0,dbPath:q.dbPath??X?.config?.dbPath??N$(),host:X?.config?.host,profile:X?.config?.profile};if(!$.json)J(),W(`${E.info} Starting agent ${K.bold(q.name)}...`);await Z.startDaemon(z);let V=`http://localhost:${Q}`;if(B($,{ok:!0,name:q.name,port:Q,url:V}))return;J(),U(`${E.success} Agent ${K.bold(q.name)} restarted.`),J(),I("Port",String(Q)),I("Database",z.dbPath),J(),u$(V)}catch(Z){if($.json){B($,{ok:!1,error:C(Z)});return}L(`Failed to restart agent: ${C(Z)}`)}})}import{existsSync as o2,readFileSync as a2,unlinkSync as X1}from"fs";import{join as z1}from"path";function t2(Y){let q=z1(V$(),Y,"runtime.json");if(!o2(q))return null;try{let $=JSON.parse(a2(q,"utf8"));if(typeof $.pid!=="number")return null;return{...$,pid:$.pid,path:q}}catch{return null}}async function H1(Y){let q=t2(Y);if(!q)return null;if(!B$(q.pid)){try{X1(q.path)}catch{}return`agent pid=${q.pid} (${Y}) already gone (cleaned runtime.json).`}let $=l();if(!$.killProcessTree(q.pid,"SIGTERM"))return`failed to SIGTERM agent pid=${q.pid}.`;if(await new Promise((Z)=>setTimeout(Z,3000)),B$(q.pid))$.killProcessTree(q.pid,"SIGKILL");try{X1(q.path)}catch{}return`agent ${Y} pid=${q.pid}${q.port?` (port ${q.port})`:""} killed.`}async function s2(Y){let q=z1(V$(),Y),$=J$(q);if(!$)return null;if(!B$($.pid))return X$(q),`tunnel pid=${$.pid} already gone (cleaned state).`;let Z=l();if(!Z.killProcessTree($.pid,"SIGTERM"))return`failed to SIGTERM tunnel pid=${$.pid}.`;if(await new Promise((X)=>setTimeout(X,3000)),B$($.pid))Z.killProcessTree($.pid,"SIGKILL");return X$(q),`tunnel ${$.provider} pid=${$.pid} (${$.url??"no url"}) killed.`}function W1(Y){Y.command("kill").description("Force-kill an agent instance and its tunnel. Defaults to active profile.").option("-n, --name <name>","Agent instance name (alias of --profile, kept for back-compat)").option("--profile <name>","Kill a specific profile (overrides --name and VIBECONTROLS_PROFILE)").option("--all","Kill every agent instance and every profile's tunnel",!1).option("-y, --yes","Skip the confirmation prompt (for scripts/CI)",!1).option("--json","Emit JSON").action(async function(q){let $={...Y.opts(),...q},Z=q.all?"ALL agent instances + every profile's tunnel":`agent '${$.profile??$.name??"active profile"}'`;if(!await q0($,`Force-kill ${Z}? This sends SIGKILL (no graceful shutdown).`)){W("Aborted.");return}let X=[];try{let H=new p;if(q.all){if(!$.json)T("Force killing all agent instances + tunnels"),J();let _=await H.listInstances()??[],O=0,F=new Set;for(let G of _)try{if(await H.kill(G.name),!$.json)U(`${E.success} agent ${K.bold(G.name)} (pid=${G.pid||"?"}) killed.`);X.push(G.name),O++,F.add(G.name)}catch{if(!$.json)j(`${E.warning} could not kill agent ${G.name}.`)}try{let G=await import("fs"),x=V$(),M=G.existsSync(x)?G.readdirSync(x):[];for(let N of M){if(F.has(N))continue;let S=await H1(N);if(S)U(`${E.success} ${S}`),O++}}catch(G){j(`${E.warning} runtime.json sweep failed: ${G instanceof Error?C(G):String(G)}`)}let D=Q1({allProfiles:!0}),R=0;for(let G of D){if(!G.alive){X$(G.profileDir);continue}let x=l();if(x.killProcessTree(G.pid,"SIGTERM"),await new Promise((M)=>setTimeout(M,3000)),B$(G.pid))x.killProcessTree(G.pid,"SIGKILL");X$(G.profileDir),U(`${E.success} tunnel ${G.provider} pid=${G.pid} (${G.url??"no url"}, ${G.profileDir.split("/").pop()}) killed.`),R++}if(B($,{ok:!0,killed:X,tunnels:R}))return;J(),U(`${E.success} killed ${O} agent(s) and ${R} tunnel(s).`);return}let Q=q.profile||q.name||Y0();if(!$.json)T(`Force killing profile: ${Q}`),J();let z=await H.getStatus(Q);if(z){if(await H.kill(Q),X.push(Q),!$.json)U(`${E.success} agent ${K.bold(Q)} pid=${z.pid||"?"} killed.`)}else{let _=await H1(Q);if(_){if(X.push(Q),!$.json)U(`${E.success} ${_}`)}else if(!$.json)W(`${E.info} no running agent service for profile ${Q}.`)}let V=await s2(Q);if(V){if(!$.json)U(`${E.success} ${V}`)}else if(!$.json)W(`${E.info} no tunnel recorded for profile ${Q}.`);B($,{ok:!0,killed:X})}catch(H){if($.json){B($,{ok:!1,error:C(H)});return}L(`Failed to kill: ${C(H)}`)}})}function K1(Y){Y.command("list").alias("ls").description("List all VibeControls agent instances").option("--json","Emit JSON").option("--plain","Force plain text output").action(async function(q){try{let $={...Y.opts(),...q},Z=new p;await P({mode:f($),fetchData:()=>Z.listInstances(),plain:(X)=>{if(T("Agent Instances"),J(),!X||X.length===0){W(`${E.info} No agent instances found.`),W(`Run ${K.bold("vibe start")} to start an agent.`);return}let H=X.map((V)=>({Name:V.name,Status:x$(V.status),PID:V.pid||"-",Port:V.port||"-",Host:V.config?.host||"-",Database:V.config?.dbPath||"-",Started:V.startTime?G$(V.startTime):"-"}));n(H),J();let Q=X.filter((V)=>V.status==="running").length,z=X.length-Q;W(`${E.info} ${X.length} instance(s): ${K.green(String(Q))} running, ${K.dim(String(z))} stopped`)},interactive:async(X)=>{if(!X||X.length===0){T("Agent Instances"),J(),W(`${E.info} No agent instances found.`),W(`Run ${K.bold("vibe start")} to start an agent.`);return}let H=X.map((Q)=>{let z=[`${K.bold(Q.name)} ${x$(Q.status)}`,"",` PID: ${Q.pid??"-"}`,` Port: ${Q.port??"-"}`,` Host: ${Q.config?.host??"-"}`,` Database: ${Q.config?.dbPath??"-"}`,` Started: ${Q.startTime?G$(Q.startTime):"-"}`];return{id:Q.name,label:Q.name,hint:Q.status==="running"?"running":"stopped",detail:z.join(`
3
3
  `)}});await r({title:`vibe list \u2014 ${X.length} instance(s)`,rows:H,footer:"\u2191/\u2193 navigate \xB7 q to quit"})},json:(X)=>X.map((H)=>({name:H.name,status:H.status,pid:H.pid??null,port:H.port??null,host:H.config?.host??null,database:H.config?.dbPath??null,startTime:H.startTime??null}))})}catch($){L(`Failed to list instances: ${$.message}`)}})}var V1=5000;function L1(Y){Y.command("logs").description("View logs for a VibeControls agent instance").option("-n, --name <name>","Agent instance name","default").option("-f, --follow","Follow log output",!1).option("--tail <lines>","Number of lines to show from the end","100").option("--json","Emit JSON (one object per line, banners suppressed)").option("--plain","Force plain text output").action(async function(q){try{let $={...Y.opts(),...q},Z=new p,X=parseInt($.tail??"100",10);if(isNaN(X)||X<1||X>V1){L(`Invalid tail value. Must be between 1 and ${V1}.`);return}let H=$.name??"default";if(!await Z.getStatus(H)){L(`Agent instance ${K.bold(H)} not found.`);return}if(!$.json){if($.follow)T(`Following logs: ${H}`),W(`${E.info} Press Ctrl+C to stop following.`);else T(`Logs: ${H}`);J()}await Z.showLogs(H,{follow:!!$.follow,tail:X})}catch($){L(`Failed to get logs: ${C($)}`)}})}function J1(Y){Y.command("setup").description("Install system dependencies and (optionally) write gateway auth config").option("--check","Only check dependencies without installing",!1).option("--client-id <id>","OAuth app client ID (for backend authentication)").option("--client-secret <secret>","OAuth app client secret").option("--workspace-id <id>","Workspace UUID this agent belongs to").option("--global-gateway-url <url>","Global public gateway URL (default: http://localhost:4000/global/graphql)").option("--workspace-gateway-url <url>","Workspace gateway URL (default: http://localhost:4001/workspaces/graphql)").option("--storage-adapter <name>","Named storage adapter (default: skalex, or custom:<path>)").option("--json","Emit JSON").action(async function(q){let $={...Y.opts(),...q},Z=[];try{if(!$.json)T("VibeControls Agent Setup");let X={};if(q.clientId)X.clientId=q.clientId;if(q.clientSecret)X.clientSecret=q.clientSecret;if(q.workspaceId)X.workspaceId=q.workspaceId;if(q.globalGatewayUrl)X.globalGatewayUrl=O0(q.globalGatewayUrl,"globalGatewayUrl");if(q.workspaceGatewayUrl)X.workspaceGatewayUrl=O0(q.workspaceGatewayUrl,"workspaceGatewayUrl");if(q.storageAdapter)X.storageAdapter=q.storageAdapter;if(Object.keys(X).length>0){let O=U$(X);if(Z.push(...Object.keys(X)),!$.json){U(`Agent config written to ${B0()}`),I("clientId",O.clientId?K.dim("(set)"):K.dim("(unset)")),I("clientSecret",O.clientSecret?K.dim("(set)"):K.dim("(unset)")),I("workspaceId",O.workspaceId??K.dim("(unset)"));let F=O1();if(I("globalGatewayUrl",O.globalGatewayUrl??F.globalGatewayUrl),I("workspaceGatewayUrl",O.workspaceGatewayUrl??F.workspaceGatewayUrl),O.storageAdapter)I("storageAdapter",O.storageAdapter);J()}}else{let O=Y$();if((O.clientId||O.clientSecret||O.workspaceId)&&!$.json)W(`Using existing agent config at ${B0()} (pass --client-id/--client-secret/--workspace-id to update).`),J()}if(!$.json)W("Checking dependencies..."),J();let H=a$(),Q=[],z=[];for(let O of H){if(O.installed)z.push(O.name);if(!$.json){let F=O.installed?E.success:E.error,D=O.version?K.dim(` (${O.version})`):"",R=O.required?"":K.dim(" [optional]");I(`${F} ${O.name}`,`${O.installed?K.green("installed"):K.red("missing")}${D}${R}`)}if(!O.installed)Q.push(O.name)}if(!$.json)J();if(Q.length===0){if(B($,{ok:!0,installed:z,configured:Z}))return;U("All dependencies are installed.");return}if(q.check){if($.json){B($,{ok:!1,installed:z,missing:Q,configured:Z});return}j(`Missing: ${Q.join(", ")}`),W(`Run ${K.bold("vibe setup")} to install them.`),process.exit(1)}if(!$.json)W(`Installing missing dependencies: ${Q.join(", ")}...`),J();let V=await B1(Q),_=Q.filter((O)=>!V.failed.includes(O));if(V.failed.length>0){if($.json){B($,{ok:!1,installed:[...z,..._],failed:V.failed,configured:Z});return}j(`${V.failed.length} tool(s) failed: ${V.failed.join(", ")}`),W("You may need to install manually or use sudo."),process.exit(1)}else{if(B($,{ok:!0,installed:[...z,..._],configured:Z}))return;U("All dependencies installed successfully.")}}catch(X){let H=X instanceof Error?C(X):String(X);if($.json){B($,{ok:!1,error:H});return}L(`Setup failed: ${H}`)}})}function r2(Y){let q=l();return q.which(Y)??`${Y}${q.executableSuffix}`}function C1(Y){Y.command("update").description("Check for and install VibeControls agent updates").option("--check","Only check for updates without installing",!1).option("--allow-incompatible","Override engines.bun compatibility check (use with care)",!1).option("--no-restart","Skip the post-install idle-aware restart of any running agent").option("-n, --name <name>","Agent profile name to restart after update","default").option("--version-target <version>","Install a specific version instead of the latest (e.g. 2026.601.21)").option("--json","Emit JSON").action(async function(q){let $={...Y.opts(),...q};try{if(!$.json)T("VibeControls Agent Update"),J(),W(`${E.info} Checking for updates...`),J();let Z=await I1();if(Z.error&&!Z.latest){if(B($,{ok:!1,current:Z.current,error:Z.error}))return;L(Z.error);return}if(!$.json)I("Package",K.bold(Z.name)),I("Registry",K.bold(Z.registry)),I("Current version",K.bold(Z.current)),I("Latest version",K.bold(Z.latest??"unknown")),J();if(q.check){if(B($,{ok:!0,current:Z.current,latest:Z.latest,upToDate:!Z.hasUpdate}))return;if(!Z.hasUpdate)U(`${E.success} You are running the latest version.`);else j(`${E.warning} A new version is available: ${K.green(Z.latest??"")}`),W(`${E.info} Run ${K.bold("vibe update")} to install the update.`);return}let X=q.versionTarget;if(!X&&!Z.hasUpdate){if(B($,{ok:!0,current:Z.current,latest:Z.latest,upToDate:!0}))return;U(`${E.success} You are running the latest version.`);return}if(!$.json)W(`${E.info} Updating to ${K.bold(X??Z.latest??"latest")}...`),J();let H=await _1({targetVersion:X,allowIncompatible:!!q.allowIncompatible,restart:q.restart!==!1,name:q.name,onLog:$.json?void 0:(Q)=>W(`${E.info} ${Q}`)});if(!H.ok){if(B($,{ok:!1,current:H.current,previous:H.previous,latest:H.latest,rolledBack:H.rolledBack,error:H.error}))return;L(H.error??"Update failed.");return}if(!$.json)switch(H.restart){case"restarted":U(`${E.success} Restarted agent ${K.bold(q.name)} on the new version.`);break;case"not-running":W(`${E.info} No running agent for profile ${K.bold(q.name)}; nothing to restart.`);break;case"still-busy":j(`${E.warning} Agent still serving requests \u2014 run ${K.bold("vibe restart")} when it's quiet.`);break;case"error":j(`${E.warning} Auto-restart failed: ${H.restartError}. Run ${K.bold("vibe restart")} manually.`);break}if(B($,{ok:!0,current:H.current,previous:H.previous,latest:H.latest,updated:H.updated,restart:H.restart,...H.restartError?{restartError:H.restartError}:{}}))return;if(J(),H.updated)U(`${E.success} Updated to ${K.bold(H.current)} (smoke: ${H.smoke?.step??"ok"}).`);else U(`${E.success} You are running the latest version.`);if(q.restart===!1)W(`${E.info} --no-restart set \u2014 restart running agents manually for the update to take effect.`)}catch(Z){let X=Z instanceof Error?C(Z):String(Z);if($.json){B($,{ok:!1,error:X});return}L(`Update failed: ${X}`)}}),Y.command("rollback").description("Roll the global agent install back to a specific version").argument("<version>","Target CalVer version (e.g. 2026.428.3)").action(async(q)=>{try{T("VibeControls Agent Rollback");let $=await U1();if(I("Package",K.bold($.name)),I("Current version",K.bold($.version)),I("Target version",K.bold(q)),J(),W(`${E.info} Rolling back\u2026`),Bun.spawnSync([r2("npm"),"install","-g",`${$.name}@${q}`,`--registry=${$.registry}`],{stdout:"inherit",stderr:"inherit"}).exitCode!==0){L("Rollback failed.");return}U(`${E.success} Rolled back to ${K.bold(q)}.`)}catch($){L(`Rollback failed: ${$ instanceof Error?C($):String($)}`)}})}import{existsSync as F$,mkdirSync as e2,writeFileSync as I0,unlinkSync as $6,readFileSync as J0}from"fs";import{join as L$}from"path";import{homedir as M$}from"os";var Y6=/^[A-Za-z0-9][A-Za-z0-9:_-]{0,63}$/,q6=/^--[A-Za-z0-9][A-Za-z0-9-]{0,63}$/;function R1(Y){return Y6.test(Y)?Y:null}function j1(Y){return Y.filter((q)=>R1(q))}function Z6(Y){return Y.filter((q)=>q6.test(q))}function w$(Y){return Y.commands.flatMap((q)=>{let $=R1(q.name());if(!$)return[];return[{name:$,description:q.description()||"",options:q.options.map((Z)=>({flags:Z.flags,description:Z.description||""})),subcommands:w$(q)}]})}function X6(Y){return j1(Y.map((q)=>q.name))}function H6(Y,q){let $=Y.find((X)=>X.name===q);if(!$)return[];let Z=[];for(let X of $.options){let H=X.flags.match(/--([\w-]+)/);if(H)Z.push(`--${H[1]}`)}return Z6(Z)}function E1(Y){let q=X6(Y),Z=Y.filter((H)=>H.subcommands.length>0).map((H)=>({name:H.name,subs:j1(H.subcommands.map((Q)=>Q.name))})).map((H)=>` ${H.name})
4
4
  COMPREPLY=($(compgen -W "${H.subs.join(" ")}" -- "\${cur}"))
5
5
  return 0
@@ -207,14 +207,14 @@ Version: ${Y.agent.version??"n/a"}`}),q.push({name:"System snapshot",ok:Y.syst
207
207
  `).filter(Boolean).length>0,message:`${Y.processes.split(`
208
208
  `).filter(Boolean).length} process(es)`,detail:Y.processes||"(none found)"}),q}function l1(Y){Y.command("diagnostics").alias("diag").description("Collect a redacted diagnostic dump for support").option("--agent-url <url>","Agent URL (default http://localhost:3005)","http://localhost:3005").option("--lines <n>","Tail this many log lines","1000").option("--out <path>","Write JSON dump to file").option("--json","Emit JSON to stdout").option("--plain","Force plain text output").action(async function(q){try{let $={...Y.opts(),...q},Z=w($),X=encodeURIComponent(A($)),H=Number.parseInt($.lines??"1000",10)||1000;await P({mode:f($),fetchData:async()=>{let[Q,z,V]=await Promise.all([S6(Z,X),h6(Z,X),v6(Z)]),_=Y$(),O=a(_),F=n$(Q$(),"logs"),R=["default.log","agent.log"].map((N)=>n$(F,N)).find((N)=>g1(N))??n$(F,"default.log"),G=y6(R,H),x={timestamp:new Date().toISOString(),agent:{version:z,agentUrl:Z},system:Q,health:V,config:O,processes:f6(),logFile:R,logsTail:G},M=P6(x);return{dump:x,probes:M}},plain:(Q)=>{T("VibeControls Agent Diagnostics"),J(),W("Collecting agent state\u2026");let z=$.out?$.out:n$(x6(n$(A6(),"vibe-diag-")),`vibe-diagnostics-${Date.now()}.json`);w6(z,JSON.stringify(Q.dump,null,2),"utf8"),I("Wrote",K.bold(z)),I("Log lines",String(Q.dump.logsTail.length)),I("Processes",String(Q.dump.processes.split(`
209
209
  `).filter(Boolean).length)),J(),U("Diagnostics complete. Attach the JSON to your support ticket.")},interactive:async(Q)=>{let z=Q.probes.map((_,O)=>({id:`${O}-${_.name}`,label:_.name,hint:_.ok?"ok":"fail",detail:[`${_.ok?K.green("\u2714 ok"):K.red("\u2718 fail")} ${K.bold(_.name)}`,"",_.message,..._.detail?["",_.detail]:[]].join(`
210
- `)})),V=Q.probes.filter((_)=>_.ok).length;await r({title:`Vibe Diagnostics \u2014 ${V}/${Q.probes.length} ok`,rows:z,footer:"\u2191/\u2193 navigate \xB7 q to quit"})},json:(Q)=>({checks:Q.probes.map((z)=>({name:z.name,ok:z.ok,message:z.message})),dump:Q.dump})})}catch($){L(`Diagnostics failed: ${$ instanceof Error?C($):String($)}`)}})}import{existsSync as h$,readFileSync as m6,readdirSync as g6,renameSync as l6,rmSync as S0,statSync as n6,writeFileSync as i6}from"fs";import{join as i}from"path";import{existsSync as j$,readdirSync as b6,rmSync as k6,statSync as u6}from"fs";import{dirname as H0,join as z$}from"path";var R$="@vibecontrols";function c6(){let q=l().npmGlobalBin();if(!q)return null;let $=z$(H0(q),"lib","node_modules");if(j$($))return $;let Z=z$(H0(q),"node_modules");if(j$(Z))return Z;let X=z$(H0(q),"..","node_modules");if(j$(X))return X;return null}function d6(){let Y=l(),q=Y.bunGlobalBin();if(q){let $=z$(H0(q),"node_modules");if(j$($))return $;let Z=z$(Y.homeDir,".bun","install","global","node_modules");if(j$(Z))return Z}return null}function n1(Y){let q=z$(Y,R$);if(!j$(q))return[];try{return b6(q).filter(($)=>{if($.startsWith("."))return!1;try{return u6(z$(q,$)).isDirectory()}catch{return!1}})}catch{return[]}}function i1(){let Y=[],q=d6();if(q)for(let Z of n1(q))Y.push({packageName:`${R$}/${Z}`,root:"bun",rootDir:z$(q,R$)});let $=c6();if($)for(let Z of n1($))Y.push({packageName:`${R$}/${Z}`,root:"npm",rootDir:z$($,R$)});return Y}function p1(Y,q){if(q.dryRun)return{packageName:Y.packageName,root:Y.root,ok:!0,via:"skip"};let $=l();if(Y.root==="bun"){let X=$.platform==="win32"?"bun.exe":"bun";try{if(Bun.spawnSync([X,"remove","-g",Y.packageName],{timeout:60000,stdout:"pipe",stderr:"pipe"}).exitCode===0)return{packageName:Y.packageName,root:Y.root,ok:!0,via:"bun"}}catch{}}else{let X=$.platform==="win32"?"npm.cmd":"npm";try{if(Bun.spawnSync([X,"uninstall","-g",Y.packageName],{timeout:120000,stdout:"pipe",stderr:"pipe"}).exitCode===0)return{packageName:Y.packageName,root:Y.root,ok:!0,via:"npm"}}catch{}}let Z=z$(Y.rootDir,Y.packageName.slice(R$.length+1));try{if(j$(Z))k6(Z,{recursive:!0,force:!0});return{packageName:Y.packageName,root:Y.root,ok:!0,via:"rm"}}catch(X){return{packageName:Y.packageName,root:Y.root,ok:!1,via:"rm",error:X instanceof Error?X.message:String(X)}}}var w0=`${R$}/agent`;function o1(Y){return Y===w0}var p6=new Set(["db","plugins-registry","logs","binaries","subprocs"]);function o6(Y){let q=new Set,$=[];if(!Y)return{keep:q,unknown:$};for(let Z of Y.split(",").map((X)=>X.trim()).filter(Boolean))if(p6.has(Z))q.add(Z);else $.push(Z);return{keep:q,unknown:$}}var a6=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;function t6(Y,q){if(!a6.test(q))return!1;let $=i(Y,q);try{return n6($).isDirectory()}catch{return!1}}function s6(){let Y=V$();if(!h$(Y))return[];return g6(Y).filter((q)=>t6(Y,q)).map((q)=>({profile:q,agentDir:i(Y,q)}))}function r6(){let Y=process.env.VIBECONTROLS_PROFILE||"default";return{profile:Y,agentDir:i(V$(),Y)}}function e6(Y){if(!Y)return[];return Y.split(",").map((q)=>q.trim()).filter(Boolean)}function $3(Y){let q=[],$=[],Z=[];for(let X of Y){let H=s1(X);if(!H){$.push(X);continue}let Q={packageName:H.packageName,pluginName:H.pluginName,isCore:!!H.isCore,raw:X};if(Q.isCore)Z.push(Q);else q.push(Q)}return{resolved:q,unknown:$,bundled:Z}}async function Y3(){return(await import("./subprocess-g9sk1ep9.js")).killAllTracked()}function q3(Y,q){let $=J$(Y);if(!$||typeof $.pid!=="number"||$.pid<=0)return{killed:0,skipped:0};let Z=l();if(!Z.isProcessAlive($.pid)){if(!q)X$(Y);return{killed:0,skipped:1}}if(q)return W(` would kill tunnel pid ${$.pid} (${$.provider}) from ${K.dim(Y)}`),{killed:1,skipped:0};let X=Z.killProcessTree($.pid,"SIGTERM");if(X&&Z.isProcessAlive($.pid))Z.killProcessTree($.pid,"SIGKILL");return X$(Y),{killed:X?1:0,skipped:X?0:1}}function e1(){return i(l().homeDir,".bun","install","global")}function $2(Y,q){let $=e1(),Z=i($,"package.json"),X=i($,"bun.lock");if(!h$(Z))return{droppedCount:0,manifestPath:Z,lockPath:X};let H=typeof Y==="function"?Y:(D)=>D===Y,Q;try{Q=m6(Z,"utf8")}catch{return{droppedCount:0,manifestPath:Z,lockPath:X}}let z;try{z=JSON.parse(Q)}catch{return{droppedCount:0,manifestPath:Z,lockPath:X}}if(!z.dependencies||typeof z.dependencies!=="object")return{droppedCount:0,manifestPath:Z,lockPath:X};let V=Object.keys(z.dependencies),_={};for(let D of V)if(!H(D))_[D]=z.dependencies[D];let O=V.length-Object.keys(_).length;if(O===0)return{droppedCount:0,manifestPath:Z,lockPath:X};if(q)return W(` would drop ${O} dep(s) from ${K.dim(Z)} and remove ${K.dim(X)}`),{droppedCount:O,manifestPath:Z,lockPath:X};z.dependencies=_;let F=`${Z}.${process.pid}.tmp`;if(i6(F,`${JSON.stringify(z,null,2)}
211
- `,{encoding:"utf8"}),l6(F,Z),h$(X))try{S0(X,{force:!0})}catch{}return{droppedCount:O,manifestPath:Z,lockPath:X}}async function _$(Y,q){if(!h$(Y))return;if(q){W(` would remove ${K.dim(Y)}`);return}try{S0(Y,{recursive:!0,force:!0})}catch($){j(`Failed to remove ${Y}: ${$ instanceof Error?C($):String($)}`)}}async function Z3(Y,q,$){if(q)return W(` would uninstall plugin ${K.bold(Y)}`),!0;if($)try{if((await fetch(`${$}/api/plugins/remove`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({packageName:Y})})).ok)return!0}catch{}try{let H=l(),Q=H.which("bun")??`bun${H.executableSuffix}`;if(Bun.spawnSync([Q,"remove","-g",Y],{timeout:60000,stdout:"pipe",stderr:"pipe"}).exitCode===0)return!0}catch{}let Z=i(e1(),"node_modules",Y),X=!1;try{if(h$(Z))S0(Z,{recursive:!0,force:!0}),X=!0}catch{}$2(Y,!1);try{let{pruneStaleBunBinShims:H}=await import("./prune-stale-shims-nkx9vq5m.js");H()}catch{}return X||!0}async function X3(Y,q){try{let $=await fetch(`${Y}/api/plugins/prereqs/uninstall`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({packageName:q})});if(!$.ok)return{ok:!1,pendingSudo:[]};let Z=await $.json();return{ok:!!Z.ok,pendingSudo:Z.pendingSudo??[]}}catch{return{ok:!1,pendingSudo:[]}}}async function H3(Y,q,$){try{let Z=await fetch(`${Y}/api/plugins/nuke`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(q?{packageName:q,dryRun:$}:{dryRun:$})});if(!Z.ok)return[];let X=await Z.json(),H=[];for(let Q of X.results??[]){if(Q.error){H.push(`${Q.plugin} (failed: ${Q.error})`);continue}for(let z of Q.reaped??[])H.push(`${Q.plugin}: ${z}`)}return H}catch{return[]}}async function Q3(Y,q){T(`Nuking agent: ${Y.profile}`),I("Path",Y.agentDir);let $=null;try{let X=(await q.serviceManager.listInstances()).find((H)=>H.name===Y.profile);if(X?.status==="running"){if($=`http://localhost:${X.config?.port??3005}`,(!q.keep.has("binaries")||!q.keep.has("subprocs"))&&(q.nukeAllPlugins||q.removePlugins.length>0)){let z=q.nukeAllPlugins?[void 0]:q.removePlugins.map((V)=>V.packageName);for(let V of z){let _=await H3($,V,q.dryRun);for(let O of _)if(q.dryRun)W(` would nuke \u2192 ${O}`);else U(`Plugin nuke \u2192 ${O}`)}}if(q.dryRun)W(` would stop running agent ${K.bold(Y.profile)}`);else try{await q.serviceManager.stop(Y.profile),U(`Stopped ${K.bold(Y.profile)}`)}catch(z){j(`Failed to stop ${Y.profile}: ${z}`)}}}catch{}if(!q.dryRun&&!q.keep.has("subprocs"))try{let{reaped:X}=await Y3();if(X>0)U(`Reaped ${X} tracked subprocess(es)`)}catch{}else if(q.keep.has("subprocs"))W(" keeping tracked subprocesses (--keep includes subprocs)");if(!q.keep.has("subprocs"))try{let{killed:X}=q3(Y.agentDir,q.dryRun);if(X>0&&!q.dryRun)U(`Killed persisted tunnel subprocess for ${Y.profile}`)}catch(X){j(`Failed to kill tunnel for ${Y.profile}: ${X instanceof Error?C(X):String(X)}`)}let Z=[];if(!q.keep.has("binaries")){let X=r1(Y.agentDir),H=new Map;for(let Q of X){let z=H.get(Q.pluginPackageName)??[];z.push(Q),H.set(Q.pluginPackageName,z)}if(H.size===0)W(" no agent-installed prerequisites tracked");else if(!$)j(` agent not running \u2014 cannot call prereqs/uninstall on ${H.size} plugin(s); rerun with the agent up to clean binaries`);else for(let[Q,z]of H){if(q.dryRun){W(` would call prereqs/uninstall on ${K.bold(Q)} (${z.length} item(s))`);continue}let V=await X3($,Q);if(V.ok)U(`Uninstalled prereqs for ${Q}`);else j(`Plugin ${Q} did not implement prereqs/uninstall`);for(let _ of V.pendingSudo)Z.push(_)}}else W(" keeping installed binaries (--keep includes binaries)");for(let X of q.removePlugins)if(await Z3(X.packageName,q.dryRun,$))U(`Removed plugin ${X.packageName}`);else j(`Failed to remove plugin ${X.packageName}`);if(q.nukeAllPlugins||!q.keep.has("plugins-registry"))await _$(i(Y.agentDir,"agent-plugins"),q.dryRun);else W(" keeping local agent-plugins store (--keep includes plugins-registry)");if(!q.keep.has("db"))await _$(i(Y.agentDir,"agent-db"),q.dryRun);else W(" keeping encrypted DB (--keep includes db)");if(!q.keep.has("plugins-registry"))await _$(i(Y.agentDir,"plugins.json"),q.dryRun),await _$(i(Y.agentDir,"prereqs-installed.json"),q.dryRun);else W(" keeping plugins.json + prereqs-installed.json (--keep includes plugins-registry)");if(!q.keep.has("logs"))await _$(i(Y.agentDir,"logs"),q.dryRun);else W(" keeping log files (--keep includes logs)");if(q.removeConfig)await _$(i(Y.agentDir,"config.json"),q.dryRun),U(`Removed config.json for ${Y.profile}`);return{pendingSudo:Z}}function Y2(Y){Y.command("nuke").description("Cleanly remove agent state, tracked binaries, and (optionally) plugins/config across one or all agents.").option("--remove-plugins <csv>","Comma-separated plugin names (short or full) to uninstall").option("--remove-config","Also delete config.json").option("--all","Apply to every agent under .boff/vibecontrols/agents/ and wipe all external provider plugins").option("--keep <csv>","Comma-separated list of things to preserve. Valid: db, plugins-registry, logs, binaries, subprocs").option("--dry-run","Print what would happen without doing it").option("-y, --yes","Skip the confirmation prompt").option("--json","Emit JSON").action(async function(q){let $={...Y.opts(),...q};try{let Z=q.all?s6():[r6()].filter((G)=>h$(G.agentDir));if(Z.length===0){W("Nothing to nuke \u2014 no agent state directories found.");return}let X=e6(q.removePlugins),{resolved:H,unknown:Q,bundled:z}=$3(X);if(Q.length>0){L(`Unknown plugin(s): ${Q.join(", ")} \u2014 try the full @vibecontrols/* package name`);return}if(z.length>0)for(let G of z)j(`Skipping ${K.bold(G.packageName)}: bundled with the agent (uninstall the agent itself with \`npm uninstall -g @vibecontrols/agent\`)`);let{keep:V,unknown:_}=o6(q.keep);if(_.length>0){L(`Unknown --keep value(s): ${_.join(", ")} \u2014 valid: db, plugins-registry, logs, binaries, subprocs`);return}if(T(q.dryRun?"Dry-run nuke":"Nuke"),W(`Agents: ${Z.map((G)=>G.profile).join(", ")}`),W(`Plugins: ${H.map((G)=>G.packageName).join(", ")||"(none)"}`),W(`Remove config: ${q.removeConfig?"yes":"no"}`),W(`Keep: ${V.size>0?[...V].sort().join(", "):"(nothing)"}`),W(`Wipe bun-global @vibecontrols/*: ${q.all?"yes":"no"}`),J(),!q.yes&&!q.dryRun){if(!await T$(K.bold("This will permanently delete the listed state. Continue?"))){W("Cancelled.");return}J()}let O=new p,F=[];for(let G of Z){let{pendingSudo:x}=await Q3(G,{serviceManager:O,removePlugins:H,nukeAllPlugins:!!q.all,removeConfig:!!q.removeConfig,keep:V,dryRun:!!q.dryRun});for(let M of x)F.push(M);J()}let D=[],R=null;if(q.all){try{if(q.dryRun){let N=await A0();R=N,W(` would clear ${N.count} secret(s) from ${N.backend}`)}else{let N=await A0(),S=!0;if(N.count>0&&!q.yes)S=await T$(K.bold(`About to remove ${N.count} secret(s) from ${N.backend}. Continue?`));if(S)if(R=await a1(),R.count>0)U(`Cleared ${R.count} secret(s) from ${R.backend}`);else W(" no secrets to clear");else W(" skipped clearing secrets (user declined)"),R={count:0,backend:"none",names:[]}}}catch(N){j(`Failed to clear secrets: ${N instanceof Error?C(N):String(N)}`)}let G=i1().filter((N)=>!o1(N.packageName));if(G.length===0)W(" no @vibecontrols/* packages found in bun-global / npm-global");else{W(` found ${G.length} @vibecontrols/* package(s) in global roots`);for(let N of G){let S=p1(N,{dryRun:!!q.dryRun});if(D.push(S),q.dryRun)W(` would uninstall ${K.bold(N.packageName)} (${N.root}-global)`);else if(S.ok)U(`Removed ${N.packageName} (${N.root}-global, via ${S.via})`);else j(`Failed to remove ${N.packageName} (${N.root}-global): ${S.error??"unknown"}`)}}let{droppedCount:x,manifestPath:M}=$2((N)=>N.startsWith("@vibecontrols/")&&N!==w0,!!q.dryRun);if(x>0&&!q.dryRun)U(`Dropped ${x} @vibecontrols/* dep(s) from ${M}`);await _$(i(Z$(),"agents.json"),!!q.dryRun),await _$(i(Z$(),".consent.json"),!!q.dryRun)}if(F.length>0){J(),j(`${F.length} command(s) require sudo to fully uninstall:`);for(let G of F)I(` ${G.name}`,G.command)}if(B($,{ok:!0,deleted:Z.map((G)=>G.profile),removedGlobalPackages:D,clearedSecrets:R,dryRun:!!q.dryRun}))return;if(q.all&&D.length>0&&!q.dryRun){let G=D.filter((x)=>x.ok).length;J(),W(`${E.info} Uninstalled ${G}/${D.length} global @vibecontrols/* package(s)`)}if(J(),U(q.dryRun?"Dry-run complete.":"Nuke complete."),q.all&&!q.dryRun)W(`${E.info} To remove the agent itself: ${K.bold("npm uninstall -g @vibecontrols/agent")} (or ${K.bold("bun remove -g @vibecontrols/agent")})`)}catch(Z){let X=Z instanceof Error?C(Z):String(Z);if($.json){B($,{ok:!1,error:X});return}L(X)}})}import{existsSync as z3}from"fs";import{platform as W3}from"os";var K3="http://localhost:3005";function q2(Y){if(Y==="pass")return K.green("\u2714 pass");if(Y==="warn")return K.yellow("\u26A0 warn");return K.red("\u2718 fail")}async function V3(Y){try{return await y(Y,"/health"),{name:"Agent HTTP reachable",grade:"pass",message:Y}}catch(q){return{name:"Agent HTTP reachable",grade:"fail",message:C(q),hint:"Run `vibe start` (or check `vibe status` if it should already be running)."}}}async function L3(){try{let Y="default";try{Y=Y0()}catch{}let q=await Z2(`${Y}:static-api-key`),$=Y$();if(!Boolean(q||$["static-api-key"]||process.env.AGENT_API_KEY))return{name:"Agent config / API key",grade:"warn",message:"No persistent API key set; agent will mint a fresh one each restart.",hint:"Run `vibe config --set static-api-key=true` to persist."};return{name:"Agent config / API key",grade:"pass",message:"config.json present, API key persisted"}}catch(Y){return{name:"Agent config / API key",grade:"fail",message:C(Y)}}}function O3(){let Y=Q$();if(!z3(Y))return{name:"Agent working directory",grade:"warn",message:`${Y} does not exist (will be created on first start)`};return{name:"Agent working directory",grade:"pass",message:Y}}async function B3(Y,q){try{if((await y(Y,`/api/profiles/${q}/agent/gateway-auth`))?.configured)return{name:"Gateway OAuth",grade:"pass",message:"configured"};return{name:"Gateway OAuth",grade:"warn",message:"not configured \u2014 agent works locally but won't sync with platform",hint:"Add the agent on the VibeControls platform and paste the credentials."}}catch{return{name:"Gateway OAuth",grade:"warn",message:"could not query agent for gateway-auth state"}}}async function J3(Y,q){try{let $=await y(Y,`/api/profiles/${q}/plugins`),Z=$?.plugins??$??[],X=Z.filter((H)=>H.status==="error"||H.status==="failed");if(X.length>0)return{name:"Plugin registry",grade:"fail",message:`${X.length} plugin(s) failed to load`,hint:X.map((H)=>H.name??H.packageName).join(", ")};return{name:"Plugin registry",grade:"pass",message:`${Z.length} plugin(s) loaded cleanly`}}catch{return{name:"Plugin registry",grade:"warn",message:"could not query agent for plugin list"}}}function U3(){let Y=W3();if(!["linux","darwin","win32"].includes(Y))return{name:"OS runtime",grade:"warn",message:`${Y} is not officially supported (linux, darwin, win32)`};let $=typeof Bun<"u"?Bun.version:null;if(!$)return{name:"OS runtime",grade:"warn",message:`${Y} / no Bun runtime detected`};return{name:"OS runtime",grade:"pass",message:`${Y} / Bun ${$}`}}function H2(Y){Y.command("doctor").description("Run a graded health check across the agent's subsystems").option("--agent-url <url>","Agent URL",K3).option("--profile <name>","Target a specific profile by name").option("--json","Emit machine-readable JSON instead of grading text").option("--plain","Force plain text output").action(async function(q){let $={...Y.opts(),...q},Z=w($),X=encodeURIComponent(A($)),H=[];if(await P({mode:f($),fetchData:async()=>{let Q=[];Q.push(U3()),Q.push(O3()),Q.push(await L3()),Q.push(await V3(Z)),Q.push(await B3(Z,X)),Q.push(await J3(Z,X));let z=X2();for(let V of z.getDoctorChecks())try{let _=await V.run();for(let O of _){let F=O.ok?"pass":O.grade??"fail";Q.push({name:O.name,grade:F,message:O.message,hint:O.hint})}}catch(_){Q.push({name:`${V.source}: doctor contributor`,grade:"warn",message:`contributor threw: ${_.message}`})}return H=Q,Q},plain:(Q)=>{T("Vibe Doctor"),J();for(let O of Q)if(console.log(`${q2(O.grade)} ${K.bold(O.name)}`),console.log(` ${O.message}`),O.hint)console.log(` ${K.dim("\u2192 "+O.hint)}`);J();let z=Q.filter((O)=>O.grade==="fail").length,V=Q.filter((O)=>O.grade==="warn").length,_=Q.filter((O)=>O.grade==="pass").length;if(W(`${_} pass, ${V} warn, ${z} fail`),z>0)L("Doctor found problems. See hints above."),process.exitCode=1;else if(V>0)W("Doctor finished with warnings.");else U("All checks pass.")},interactive:async(Q)=>{let z=Q.map((F,D)=>{let R=[`${q2(F.grade)} ${K.bold(F.name)}`,"",F.message];if(F.hint)R.push(""),R.push(K.dim("\u2192 "+F.hint));return{id:`${D}-${F.name}`,label:F.name,hint:F.grade==="pass"?"ok":F.grade,detail:R.join(`
210
+ `)})),V=Q.probes.filter((_)=>_.ok).length;await r({title:`Vibe Diagnostics \u2014 ${V}/${Q.probes.length} ok`,rows:z,footer:"\u2191/\u2193 navigate \xB7 q to quit"})},json:(Q)=>({checks:Q.probes.map((z)=>({name:z.name,ok:z.ok,message:z.message})),dump:Q.dump})})}catch($){L(`Diagnostics failed: ${$ instanceof Error?C($):String($)}`)}})}import{existsSync as h$,readFileSync as m6,readdirSync as g6,renameSync as l6,rmSync as S0,statSync as n6,writeFileSync as i6}from"fs";import{join as i}from"path";import{existsSync as j$,readdirSync as b6,rmSync as k6,statSync as u6}from"fs";import{dirname as H0,join as z$}from"path";var R$="@vibecontrols";function c6(){let q=l().npmGlobalBin();if(!q)return null;let $=z$(H0(q),"lib","node_modules");if(j$($))return $;let Z=z$(H0(q),"node_modules");if(j$(Z))return Z;let X=z$(H0(q),"..","node_modules");if(j$(X))return X;return null}function d6(){let Y=l(),q=Y.bunGlobalBin();if(q){let $=z$(H0(q),"node_modules");if(j$($))return $;let Z=z$(Y.homeDir,".bun","install","global","node_modules");if(j$(Z))return Z}return null}function n1(Y){let q=z$(Y,R$);if(!j$(q))return[];try{return b6(q).filter(($)=>{if($.startsWith("."))return!1;try{return u6(z$(q,$)).isDirectory()}catch{return!1}})}catch{return[]}}function i1(){let Y=[],q=d6();if(q)for(let Z of n1(q))Y.push({packageName:`${R$}/${Z}`,root:"bun",rootDir:z$(q,R$)});let $=c6();if($)for(let Z of n1($))Y.push({packageName:`${R$}/${Z}`,root:"npm",rootDir:z$($,R$)});return Y}function p1(Y,q){if(q.dryRun)return{packageName:Y.packageName,root:Y.root,ok:!0,via:"skip"};let $=l();if(Y.root==="bun"){let X=$.platform==="win32"?"bun.exe":"bun";try{if(Bun.spawnSync([X,"remove","-g",Y.packageName],{timeout:60000,stdout:"pipe",stderr:"pipe"}).exitCode===0)return{packageName:Y.packageName,root:Y.root,ok:!0,via:"bun"}}catch{}}else{let X=$.platform==="win32"?"npm.cmd":"npm";try{if(Bun.spawnSync([X,"uninstall","-g",Y.packageName],{timeout:120000,stdout:"pipe",stderr:"pipe"}).exitCode===0)return{packageName:Y.packageName,root:Y.root,ok:!0,via:"npm"}}catch{}}let Z=z$(Y.rootDir,Y.packageName.slice(R$.length+1));try{if(j$(Z))k6(Z,{recursive:!0,force:!0});return{packageName:Y.packageName,root:Y.root,ok:!0,via:"rm"}}catch(X){return{packageName:Y.packageName,root:Y.root,ok:!1,via:"rm",error:X instanceof Error?X.message:String(X)}}}var w0=`${R$}/agent`;function o1(Y){return Y===w0}var p6=new Set(["db","plugins-registry","logs","binaries","subprocs"]);function o6(Y){let q=new Set,$=[];if(!Y)return{keep:q,unknown:$};for(let Z of Y.split(",").map((X)=>X.trim()).filter(Boolean))if(p6.has(Z))q.add(Z);else $.push(Z);return{keep:q,unknown:$}}var a6=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;function t6(Y,q){if(!a6.test(q))return!1;let $=i(Y,q);try{return n6($).isDirectory()}catch{return!1}}function s6(){let Y=V$();if(!h$(Y))return[];return g6(Y).filter((q)=>t6(Y,q)).map((q)=>({profile:q,agentDir:i(Y,q)}))}function r6(){let Y=process.env.VIBECONTROLS_PROFILE||"default";return{profile:Y,agentDir:i(V$(),Y)}}function e6(Y){if(!Y)return[];return Y.split(",").map((q)=>q.trim()).filter(Boolean)}function $3(Y){let q=[],$=[],Z=[];for(let X of Y){let H=s1(X);if(!H){$.push(X);continue}let Q={packageName:H.packageName,pluginName:H.pluginName,isCore:!!H.isCore,raw:X};if(Q.isCore)Z.push(Q);else q.push(Q)}return{resolved:q,unknown:$,bundled:Z}}async function Y3(){return(await import("./subprocess-1nna3d3x.js")).killAllTracked()}function q3(Y,q){let $=J$(Y);if(!$||typeof $.pid!=="number"||$.pid<=0)return{killed:0,skipped:0};let Z=l();if(!Z.isProcessAlive($.pid)){if(!q)X$(Y);return{killed:0,skipped:1}}if(q)return W(` would kill tunnel pid ${$.pid} (${$.provider}) from ${K.dim(Y)}`),{killed:1,skipped:0};let X=Z.killProcessTree($.pid,"SIGTERM");if(X&&Z.isProcessAlive($.pid))Z.killProcessTree($.pid,"SIGKILL");return X$(Y),{killed:X?1:0,skipped:X?0:1}}function e1(){return i(l().homeDir,".bun","install","global")}function $2(Y,q){let $=e1(),Z=i($,"package.json"),X=i($,"bun.lock");if(!h$(Z))return{droppedCount:0,manifestPath:Z,lockPath:X};let H=typeof Y==="function"?Y:(D)=>D===Y,Q;try{Q=m6(Z,"utf8")}catch{return{droppedCount:0,manifestPath:Z,lockPath:X}}let z;try{z=JSON.parse(Q)}catch{return{droppedCount:0,manifestPath:Z,lockPath:X}}if(!z.dependencies||typeof z.dependencies!=="object")return{droppedCount:0,manifestPath:Z,lockPath:X};let V=Object.keys(z.dependencies),_={};for(let D of V)if(!H(D))_[D]=z.dependencies[D];let O=V.length-Object.keys(_).length;if(O===0)return{droppedCount:0,manifestPath:Z,lockPath:X};if(q)return W(` would drop ${O} dep(s) from ${K.dim(Z)} and remove ${K.dim(X)}`),{droppedCount:O,manifestPath:Z,lockPath:X};z.dependencies=_;let F=`${Z}.${process.pid}.tmp`;if(i6(F,`${JSON.stringify(z,null,2)}
211
+ `,{encoding:"utf8"}),l6(F,Z),h$(X))try{S0(X,{force:!0})}catch{}return{droppedCount:O,manifestPath:Z,lockPath:X}}async function _$(Y,q){if(!h$(Y))return;if(q){W(` would remove ${K.dim(Y)}`);return}try{S0(Y,{recursive:!0,force:!0})}catch($){j(`Failed to remove ${Y}: ${$ instanceof Error?C($):String($)}`)}}async function Z3(Y,q,$){if(q)return W(` would uninstall plugin ${K.bold(Y)}`),!0;if($)try{if((await fetch(`${$}/api/plugins/remove`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({packageName:Y})})).ok)return!0}catch{}try{let H=l(),Q=H.which("bun")??`bun${H.executableSuffix}`;if(Bun.spawnSync([Q,"remove","-g",Y],{timeout:60000,stdout:"pipe",stderr:"pipe"}).exitCode===0)return!0}catch{}let Z=i(e1(),"node_modules",Y),X=!1;try{if(h$(Z))S0(Z,{recursive:!0,force:!0}),X=!0}catch{}$2(Y,!1);try{let{pruneStaleBunBinShims:H}=await import("./prune-stale-shims-23y0stm8.js");H()}catch{}return X||!0}async function X3(Y,q){try{let $=await fetch(`${Y}/api/plugins/prereqs/uninstall`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({packageName:q})});if(!$.ok)return{ok:!1,pendingSudo:[]};let Z=await $.json();return{ok:!!Z.ok,pendingSudo:Z.pendingSudo??[]}}catch{return{ok:!1,pendingSudo:[]}}}async function H3(Y,q,$){try{let Z=await fetch(`${Y}/api/plugins/nuke`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(q?{packageName:q,dryRun:$}:{dryRun:$})});if(!Z.ok)return[];let X=await Z.json(),H=[];for(let Q of X.results??[]){if(Q.error){H.push(`${Q.plugin} (failed: ${Q.error})`);continue}for(let z of Q.reaped??[])H.push(`${Q.plugin}: ${z}`)}return H}catch{return[]}}async function Q3(Y,q){T(`Nuking agent: ${Y.profile}`),I("Path",Y.agentDir);let $=null;try{let X=(await q.serviceManager.listInstances()).find((H)=>H.name===Y.profile);if(X?.status==="running"){if($=`http://localhost:${X.config?.port??3005}`,(!q.keep.has("binaries")||!q.keep.has("subprocs"))&&(q.nukeAllPlugins||q.removePlugins.length>0)){let z=q.nukeAllPlugins?[void 0]:q.removePlugins.map((V)=>V.packageName);for(let V of z){let _=await H3($,V,q.dryRun);for(let O of _)if(q.dryRun)W(` would nuke \u2192 ${O}`);else U(`Plugin nuke \u2192 ${O}`)}}if(q.dryRun)W(` would stop running agent ${K.bold(Y.profile)}`);else try{await q.serviceManager.stop(Y.profile),U(`Stopped ${K.bold(Y.profile)}`)}catch(z){j(`Failed to stop ${Y.profile}: ${z}`)}}}catch{}if(!q.dryRun&&!q.keep.has("subprocs"))try{let{reaped:X}=await Y3();if(X>0)U(`Reaped ${X} tracked subprocess(es)`)}catch{}else if(q.keep.has("subprocs"))W(" keeping tracked subprocesses (--keep includes subprocs)");if(!q.keep.has("subprocs"))try{let{killed:X}=q3(Y.agentDir,q.dryRun);if(X>0&&!q.dryRun)U(`Killed persisted tunnel subprocess for ${Y.profile}`)}catch(X){j(`Failed to kill tunnel for ${Y.profile}: ${X instanceof Error?C(X):String(X)}`)}let Z=[];if(!q.keep.has("binaries")){let X=r1(Y.agentDir),H=new Map;for(let Q of X){let z=H.get(Q.pluginPackageName)??[];z.push(Q),H.set(Q.pluginPackageName,z)}if(H.size===0)W(" no agent-installed prerequisites tracked");else if(!$)j(` agent not running \u2014 cannot call prereqs/uninstall on ${H.size} plugin(s); rerun with the agent up to clean binaries`);else for(let[Q,z]of H){if(q.dryRun){W(` would call prereqs/uninstall on ${K.bold(Q)} (${z.length} item(s))`);continue}let V=await X3($,Q);if(V.ok)U(`Uninstalled prereqs for ${Q}`);else j(`Plugin ${Q} did not implement prereqs/uninstall`);for(let _ of V.pendingSudo)Z.push(_)}}else W(" keeping installed binaries (--keep includes binaries)");for(let X of q.removePlugins)if(await Z3(X.packageName,q.dryRun,$))U(`Removed plugin ${X.packageName}`);else j(`Failed to remove plugin ${X.packageName}`);if(q.nukeAllPlugins||!q.keep.has("plugins-registry"))await _$(i(Y.agentDir,"agent-plugins"),q.dryRun);else W(" keeping local agent-plugins store (--keep includes plugins-registry)");if(!q.keep.has("db"))await _$(i(Y.agentDir,"agent-db"),q.dryRun);else W(" keeping encrypted DB (--keep includes db)");if(!q.keep.has("plugins-registry"))await _$(i(Y.agentDir,"plugins.json"),q.dryRun),await _$(i(Y.agentDir,"prereqs-installed.json"),q.dryRun);else W(" keeping plugins.json + prereqs-installed.json (--keep includes plugins-registry)");if(!q.keep.has("logs"))await _$(i(Y.agentDir,"logs"),q.dryRun);else W(" keeping log files (--keep includes logs)");if(q.removeConfig)await _$(i(Y.agentDir,"config.json"),q.dryRun),U(`Removed config.json for ${Y.profile}`);return{pendingSudo:Z}}function Y2(Y){Y.command("nuke").description("Cleanly remove agent state, tracked binaries, and (optionally) plugins/config across one or all agents.").option("--remove-plugins <csv>","Comma-separated plugin names (short or full) to uninstall").option("--remove-config","Also delete config.json").option("--all","Apply to every agent under .boff/vibecontrols/agents/ and wipe all external provider plugins").option("--keep <csv>","Comma-separated list of things to preserve. Valid: db, plugins-registry, logs, binaries, subprocs").option("--dry-run","Print what would happen without doing it").option("-y, --yes","Skip the confirmation prompt").option("--json","Emit JSON").action(async function(q){let $={...Y.opts(),...q};try{let Z=q.all?s6():[r6()].filter((G)=>h$(G.agentDir));if(Z.length===0){W("Nothing to nuke \u2014 no agent state directories found.");return}let X=e6(q.removePlugins),{resolved:H,unknown:Q,bundled:z}=$3(X);if(Q.length>0){L(`Unknown plugin(s): ${Q.join(", ")} \u2014 try the full @vibecontrols/* package name`);return}if(z.length>0)for(let G of z)j(`Skipping ${K.bold(G.packageName)}: bundled with the agent (uninstall the agent itself with \`npm uninstall -g @vibecontrols/agent\`)`);let{keep:V,unknown:_}=o6(q.keep);if(_.length>0){L(`Unknown --keep value(s): ${_.join(", ")} \u2014 valid: db, plugins-registry, logs, binaries, subprocs`);return}if(T(q.dryRun?"Dry-run nuke":"Nuke"),W(`Agents: ${Z.map((G)=>G.profile).join(", ")}`),W(`Plugins: ${H.map((G)=>G.packageName).join(", ")||"(none)"}`),W(`Remove config: ${q.removeConfig?"yes":"no"}`),W(`Keep: ${V.size>0?[...V].sort().join(", "):"(nothing)"}`),W(`Wipe bun-global @vibecontrols/*: ${q.all?"yes":"no"}`),J(),!q.yes&&!q.dryRun){if(!await T$(K.bold("This will permanently delete the listed state. Continue?"))){W("Cancelled.");return}J()}let O=new p,F=[];for(let G of Z){let{pendingSudo:x}=await Q3(G,{serviceManager:O,removePlugins:H,nukeAllPlugins:!!q.all,removeConfig:!!q.removeConfig,keep:V,dryRun:!!q.dryRun});for(let M of x)F.push(M);J()}let D=[],R=null;if(q.all){try{if(q.dryRun){let N=await A0();R=N,W(` would clear ${N.count} secret(s) from ${N.backend}`)}else{let N=await A0(),S=!0;if(N.count>0&&!q.yes)S=await T$(K.bold(`About to remove ${N.count} secret(s) from ${N.backend}. Continue?`));if(S)if(R=await a1(),R.count>0)U(`Cleared ${R.count} secret(s) from ${R.backend}`);else W(" no secrets to clear");else W(" skipped clearing secrets (user declined)"),R={count:0,backend:"none",names:[]}}}catch(N){j(`Failed to clear secrets: ${N instanceof Error?C(N):String(N)}`)}let G=i1().filter((N)=>!o1(N.packageName));if(G.length===0)W(" no @vibecontrols/* packages found in bun-global / npm-global");else{W(` found ${G.length} @vibecontrols/* package(s) in global roots`);for(let N of G){let S=p1(N,{dryRun:!!q.dryRun});if(D.push(S),q.dryRun)W(` would uninstall ${K.bold(N.packageName)} (${N.root}-global)`);else if(S.ok)U(`Removed ${N.packageName} (${N.root}-global, via ${S.via})`);else j(`Failed to remove ${N.packageName} (${N.root}-global): ${S.error??"unknown"}`)}}let{droppedCount:x,manifestPath:M}=$2((N)=>N.startsWith("@vibecontrols/")&&N!==w0,!!q.dryRun);if(x>0&&!q.dryRun)U(`Dropped ${x} @vibecontrols/* dep(s) from ${M}`);await _$(i(Z$(),"agents.json"),!!q.dryRun),await _$(i(Z$(),".consent.json"),!!q.dryRun)}if(F.length>0){J(),j(`${F.length} command(s) require sudo to fully uninstall:`);for(let G of F)I(` ${G.name}`,G.command)}if(B($,{ok:!0,deleted:Z.map((G)=>G.profile),removedGlobalPackages:D,clearedSecrets:R,dryRun:!!q.dryRun}))return;if(q.all&&D.length>0&&!q.dryRun){let G=D.filter((x)=>x.ok).length;J(),W(`${E.info} Uninstalled ${G}/${D.length} global @vibecontrols/* package(s)`)}if(J(),U(q.dryRun?"Dry-run complete.":"Nuke complete."),q.all&&!q.dryRun)W(`${E.info} To remove the agent itself: ${K.bold("npm uninstall -g @vibecontrols/agent")} (or ${K.bold("bun remove -g @vibecontrols/agent")})`)}catch(Z){let X=Z instanceof Error?C(Z):String(Z);if($.json){B($,{ok:!1,error:X});return}L(X)}})}import{existsSync as z3}from"fs";import{platform as W3}from"os";var K3="http://localhost:3005";function q2(Y){if(Y==="pass")return K.green("\u2714 pass");if(Y==="warn")return K.yellow("\u26A0 warn");return K.red("\u2718 fail")}async function V3(Y){try{return await y(Y,"/health"),{name:"Agent HTTP reachable",grade:"pass",message:Y}}catch(q){return{name:"Agent HTTP reachable",grade:"fail",message:C(q),hint:"Run `vibe start` (or check `vibe status` if it should already be running)."}}}async function L3(){try{let Y="default";try{Y=Y0()}catch{}let q=await Z2(`${Y}:static-api-key`),$=Y$();if(!Boolean(q||$["static-api-key"]||process.env.AGENT_API_KEY))return{name:"Agent config / API key",grade:"warn",message:"No persistent API key set; agent will mint a fresh one each restart.",hint:"Run `vibe config --set static-api-key=true` to persist."};return{name:"Agent config / API key",grade:"pass",message:"config.json present, API key persisted"}}catch(Y){return{name:"Agent config / API key",grade:"fail",message:C(Y)}}}function O3(){let Y=Q$();if(!z3(Y))return{name:"Agent working directory",grade:"warn",message:`${Y} does not exist (will be created on first start)`};return{name:"Agent working directory",grade:"pass",message:Y}}async function B3(Y,q){try{if((await y(Y,`/api/profiles/${q}/agent/gateway-auth`))?.configured)return{name:"Gateway OAuth",grade:"pass",message:"configured"};return{name:"Gateway OAuth",grade:"warn",message:"not configured \u2014 agent works locally but won't sync with platform",hint:"Add the agent on the VibeControls platform and paste the credentials."}}catch{return{name:"Gateway OAuth",grade:"warn",message:"could not query agent for gateway-auth state"}}}async function J3(Y,q){try{let $=await y(Y,`/api/profiles/${q}/plugins`),Z=$?.plugins??$??[],X=Z.filter((H)=>H.status==="error"||H.status==="failed");if(X.length>0)return{name:"Plugin registry",grade:"fail",message:`${X.length} plugin(s) failed to load`,hint:X.map((H)=>H.name??H.packageName).join(", ")};return{name:"Plugin registry",grade:"pass",message:`${Z.length} plugin(s) loaded cleanly`}}catch{return{name:"Plugin registry",grade:"warn",message:"could not query agent for plugin list"}}}function U3(){let Y=W3();if(!["linux","darwin","win32"].includes(Y))return{name:"OS runtime",grade:"warn",message:`${Y} is not officially supported (linux, darwin, win32)`};let $=typeof Bun<"u"?Bun.version:null;if(!$)return{name:"OS runtime",grade:"warn",message:`${Y} / no Bun runtime detected`};return{name:"OS runtime",grade:"pass",message:`${Y} / Bun ${$}`}}function H2(Y){Y.command("doctor").description("Run a graded health check across the agent's subsystems").option("--agent-url <url>","Agent URL",K3).option("--profile <name>","Target a specific profile by name").option("--json","Emit machine-readable JSON instead of grading text").option("--plain","Force plain text output").action(async function(q){let $={...Y.opts(),...q},Z=w($),X=encodeURIComponent(A($)),H=[];if(await P({mode:f($),fetchData:async()=>{let Q=[];Q.push(U3()),Q.push(O3()),Q.push(await L3()),Q.push(await V3(Z)),Q.push(await B3(Z,X)),Q.push(await J3(Z,X));let z=X2();for(let V of z.getDoctorChecks())try{let _=await V.run();for(let O of _){let F=O.ok?"pass":O.grade??"fail";Q.push({name:O.name,grade:F,message:O.message,hint:O.hint})}}catch(_){Q.push({name:`${V.source}: doctor contributor`,grade:"warn",message:`contributor threw: ${_.message}`})}return H=Q,Q},plain:(Q)=>{T("Vibe Doctor"),J();for(let O of Q)if(console.log(`${q2(O.grade)} ${K.bold(O.name)}`),console.log(` ${O.message}`),O.hint)console.log(` ${K.dim("\u2192 "+O.hint)}`);J();let z=Q.filter((O)=>O.grade==="fail").length,V=Q.filter((O)=>O.grade==="warn").length,_=Q.filter((O)=>O.grade==="pass").length;if(W(`${_} pass, ${V} warn, ${z} fail`),z>0)L("Doctor found problems. See hints above."),process.exitCode=1;else if(V>0)W("Doctor finished with warnings.");else U("All checks pass.")},interactive:async(Q)=>{let z=Q.map((F,D)=>{let R=[`${q2(F.grade)} ${K.bold(F.name)}`,"",F.message];if(F.hint)R.push(""),R.push(K.dim("\u2192 "+F.hint));return{id:`${D}-${F.name}`,label:F.name,hint:F.grade==="pass"?"ok":F.grade,detail:R.join(`
212
212
  `)}}),V=Q.filter((F)=>F.grade==="fail").length,_=Q.filter((F)=>F.grade==="warn").length,O=Q.filter((F)=>F.grade==="pass").length;if(await r({title:`Vibe Doctor \u2014 ${O} pass, ${_} warn, ${V} fail`,rows:z,footer:"\u2191/\u2193 navigate \xB7 q to quit"}),V>0)process.exitCode=1},json:(Q)=>({checks:Q.map((z)=>({name:z.name,ok:z.grade==="pass",grade:z.grade,message:z.message,hint:z.hint??null}))})}),H.some((Q)=>Q.grade==="fail"))process.exitCode=1})}var I3="http://localhost:3005",h0=new Set(["debug","info","warn","error","silent"]);function Q2(Y){Y.command("log-level [level]").description("Show or update the running agent's log level").option("--agent-url <url>","Agent URL",I3).option("--profile <name>","Target a specific profile by name").option("--json","Emit JSON").option("--plain","Force plain text output").action(async function(q,$){try{let Z={...Y.opts(),...$},X=w(Z),H=encodeURIComponent(A(Z));if(!q){await P({mode:f(Z),fetchData:async()=>{return{level:(await y(X,`/api/profiles/${H}/agent/log-level`))?.level??"(unknown)"}},plain:(z)=>{T("Agent Log Level"),I("Current",z.level)},interactive:async(z)=>{await v$({title:"Agent Log Level",body:`Current: ${z.level}`,footer:"press q to exit"})}});return}let Q=q.toLowerCase();if(!h0.has(Q)){if(!B(Z,{ok:!1,error:`Invalid log level: ${q}`,valid:[...h0]}))L(`Invalid log level: ${q}. Use one of: ${[...h0].join(", ")}`);return}if(await m(X,`/api/profiles/${H}/agent/log-level`,{level:Q}),B(Z,{ok:!0,level:Q}))return;U(`Log level set to ${Q}`)}catch(Z){if(B({json:!!$.json},{ok:!1,error:C(Z)}))return;L(C(Z))}})}import{existsSync as z2,readdirSync as W2,statSync as K2,unlinkSync as _3}from"fs";import{join as v0}from"path";function C3(){let Y=V$();if(!z2(Y))return[];return W2(Y).map((q)=>v0(Y,q)).filter((q)=>K2(q).isDirectory())}function G3(Y,q,$){let Z=v0(Y,"logs");if(!z2(Z))return{count:0,bytes:0};let X=Date.now()-q*86400000,H=0,Q=0;for(let z of W2(Z)){let V=v0(Z,z),_=K2(V);if(!_.isFile())continue;if(_.mtimeMs>X)continue;if(H+=1,Q+=_.size,!$)try{_3(V)}catch{}}return{count:H,bytes:Q}}function F3(Y,q){let $=J$(Y);if(!$)return 0;if(B$($.pid))return 0;if(!q)X$(Y);return 1}function V2(Y){Y.command("gc").description("Garbage-collect stale agent state (tunnel files, old logs)").option("--keep-days <n>","Keep log files newer than N days","14").option("--dry-run","Show what would be removed without changing anything",!1).option("-y, --yes","Skip the confirmation prompt (for scripts/CI)",!1).option("--json","Emit JSON").action(async function(q){let $={...Y.opts(),...q};if(!q.dryRun&&!await q0($,"Remove stale agent state now?")){W("Aborted.");return}try{let Z=Number(q.keepDays);if(!Number.isFinite(Z)||Z<0){if($.json){B($,{ok:!1,error:`Invalid --keep-days: ${q.keepDays}`});return}L(`Invalid --keep-days: ${q.keepDays}`);return}let X=Boolean(q.dryRun);if(!$.json)T(X?"vibe gc (dry-run)":"vibe gc"),J();let H={staleTunnelStates:0,oldLogFiles:0,bytesFreed:0},Q=[];for(let z of C3()){let V=F3(z,X);H.staleTunnelStates+=V;let _=G3(z,Z,X);if(H.oldLogFiles+=_.count,H.bytesFreed+=_.bytes,V>0||_.count>0)Q.push(z)}if(B($,{ok:!0,removed:Q,staleTunnelStates:H.staleTunnelStates,oldLogFiles:H.oldLogFiles,freedBytes:H.bytesFreed,dryRun:X}))return;if(I("Stale tunnel state files",String(H.staleTunnelStates)),I("Old log files",String(H.oldLogFiles)),I("Bytes freed",`${(H.bytesFreed/1048576).toFixed(2)} MiB`),J(),X)W(K.dim("dry-run: no files were removed"));else U("gc complete")}catch(Z){if($.json){B($,{ok:!1,error:C(Z)});return}L(C(Z))}})}async function Q0(Y,q,$,Z){W(`\u2192 ${$}`);let X=await Y.run(q,{timeoutMs:Z});if(X.code!==0)throw j(X.stderr.slice(0,600)),Error(`${$} failed (exit ${X.code})`);return X.stdout}function O2(Y){Y.command("deploy <target>").description("Install + auto-configure the VibeControls agent on a remote target (defaults to SSH)").option("--version <version>","Pin a specific agent version (default: latest)").option("--registry <url>","npm registry (default: https://registry.npmjs.org/)").option("-i, --identity-file <path>","SSH identity file (override ssh_config)").option("--label <label>","Friendly name to record this peer under (default: target host)").option("--permissions <list>","Permissions to grant ourselves on the new peer (comma-separated)","tunnel:read,session:list,plugin:list,diagnostics:read").option("--expires-in <duration>","TTL for the minted peer key (default: no expiry)").option("--install-plugins <list>","Comma-separated plugin packages to also install on the remote agent").option("--autostart","Run `vibe autostart install` on the remote agent",!1).option("--no-bun","Skip Bun runtime install on the remote (default: best-effort)").option("--confirm","Required to proceed (no destructive ops; this is a sanity gate)").option("--json","Emit JSON").action(async function(q,$){let Z={...Y.opts(),...$};try{if(!$.confirm){L("Pass --confirm to proceed. `vibe deploy` runs npm install on the remote host.");return}let X=L2(q,{identityFile:$.identityFile});T(`vibe deploy \u2192 ${X.id}`),J(),W("Probing remote host\u2026");let H=await X.probe();if(I("Remote OS",H.os??"(unknown)"),I("Remote arch",H.arch??"(unknown)"),H.npm)I("Remote npm",H.npm);if(H.bun)I("Remote bun",H.bun);if(H.vibe)I("Remote vibe (existing)",H.vibe);if(J(),!H.bun){if($.bun===!1){L("Bun is required to run the agent but is not installed and --no-bun was passed. Install Bun manually, then re-run.");return}W("Installing Bun on remote\u2026");let M=await X.run(["sh","-c",`curl -fsSL https://bun.sh/install | bash && echo 'export PATH="$HOME/.bun/bin:$PATH"' >> ~/.bashrc`],{timeoutMs:300000});if(M.code!==0){j(M.stderr.slice(0,500)),L("Bun auto-install failed. Install Bun manually, then re-run.");return}let N=await X.run(["sh","-c","$HOME/.bun/bin/bun --version 2>/dev/null"],{timeoutMs:1e4});if(N.code===0&&N.stdout.trim())H.bun="$HOME/.bun/bin/bun",I("Remote bun (installed)",N.stdout.trim());else{L("Bun installer ran but the binary isn't reachable. Manual investigation needed.");return}}let Q=$.version??"latest",z=$.registry??"https://registry.npmjs.org/";if(!/^[A-Za-z0-9._@/^~>=<-]+$/.test(Q)){L(`Invalid agent version: ${Q}`);return}if(!/^https?:\/\/[A-Za-z0-9._~:/?#@!$&'()*+,;=%-]+$/.test(z)){L(`Invalid registry URL: ${z}`);return}await Q0(X,["sh","-c",`export PATH="$HOME/.bun/bin:$PATH"; npm_config_registry="${z}" bun install -g @vibecontrols/agent@${Q} --no-cache`],`Installing @vibecontrols/agent@${Q} via bun`,600000);let V='export PATH="$HOME/.bun/bin:$PATH"; ',_=await Q0(X,["sh","-c",`${V}vibe --version`],"Verifying remote vibe binary",15000);if(I("Remote agent version",_.trim()),$.autostart)await Q0(X,["sh","-c",`${V}vibe autostart install`],"Installing autostart unit",60000);if($.installPlugins)for(let M of $.installPlugins.split(",").map((N)=>N.trim()).filter(Boolean))await Q0(X,["sh","-c",`${V}vibe plugin install ${M}`],`Installing plugin ${M}`,300000);W("Starting remote agent in daemon mode\u2026"),await X.run(["sh","-c",`${V}vibe start`],{timeoutMs:60000}),W("Waiting for remote tunnel\u2026");let O=null,F=$.expiresIn?` --expires-in ${$.expiresIn}`:"",D=$.label??X.id,R=$.permissions??"tunnel:read";for(let M=0;M<15;M++){let N=await X.run(["sh","-c",`${V}vibe peer-bootstrap --label '${D.replace(/'/g,"")}' --scope ${R}${F} 2>/dev/null`],{timeoutMs:15000});if(N.code===0){let S=N.stdout,q$=S.indexOf("{"),o=S.lastIndexOf("}");if(q$>=0&&o>q$){let v=S.slice(q$,o+1);try{JSON.parse(v),O=v;break}catch{}}}await new Promise((S)=>setTimeout(S,2000))}if(!O){j("Could not run `vibe peer-bootstrap` on the remote. The agent is installed but not registered as a peer. Run `vibe network add ...` manually with the remote's API key + tunnel URL.");return}let G;try{G=JSON.parse(O)}catch(M){j(`Could not parse peer-bootstrap output: ${M.message}`);return}if(!G.tunnelUrl)j("Remote agent has no tunnel URL yet \u2014 it may still be coming up. Re-run `vibe network test <id>` later.");if(z0({id:G.id,label:D,tunnelUrl:G.tunnelUrl??"",apiKey:G.apiKey,permissions:G.permissions,addedAt:new Date().toISOString(),agentRecordId:G.agentRecordId??void 0,workspaceId:G.workspaceId??void 0,fingerprint:G.id}),B(Z,{ok:!0,host:q,version:_.trim(),peerId:G.id,tunnelUrl:G.tunnelUrl??null}))return;if(J(),U(`Deployed agent + registered peer ${G.id}`),I("Remote tunnel",G.tunnelUrl??"(pending)"),I("Permissions",G.permissions.join(",")),G.expiresAt)I("Key expires",G.expiresAt);J(),W(`${K.dim("Try it")}: ${K.bold(`vibe network test ${G.id.substring(0,8)}`)}`);let x=await W0(G.id,"/api/profiles/default/agent/identity",{operation:"post-deploy-probe"});if(x.ok)U("Peer probe succeeded.");else j(`Peer probe failed: ${x.status} ${x.error??""}. Tunnel may still be warming up.`)}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(C(X))}})}function B2(Y){let q=Y.split(",").map((Z)=>Z.trim()).filter(Boolean),$=K0(q);if($.length!==q.length)throw Error(`Invalid permission(s). Allowed: ${E$.join(",")}`);return $}function y0(Y){let{apiKey:q,...$}=Y;return a({...$,apiKey:"[REDACTED]"})}function C2(Y){let q=Y.command("network").description("Manage the mesh of peer agents this agent talks to");q.command("list").description("List configured peer agents").option("--json","Emit JSON").option("--plain","Force plain text output").action(async function($){try{let Z={...Y.opts(),...$};await P({mode:f(Z),fetchData:()=>J2(),plain:(X)=>{if(X.length===0){W("No peers configured. Add one via `vibe deploy <ssh-target>` or `vibe network add`.");return}T("Peer agents"),n(X.map((H)=>({ID:H.id.substring(0,8),Label:H.label,Tunnel:H.tunnelUrl,Permissions:H.permissions.join(","),Last_Reachable:H.lastReachable??"never"})))},interactive:async(X)=>{if(X.length===0){T("Peer agents"),J(),W("No peers configured. Add one via `vibe deploy <ssh-target>` or `vibe network add`.");return}let H=X.map((Q)=>{let z=[`${K.bold(Q.label)} ${Q.id.substring(0,8)}`,"",` Tunnel: ${Q.tunnelUrl}`,` Permissions: ${Q.permissions.join(",")}`,` Added: ${Q.addedAt}`,` Last reachable: ${Q.lastReachable??"never"}`,` Workspace: ${Q.workspaceId??"-"}`,` Agent record: ${Q.agentRecordId??"-"}`];return{id:Q.id,label:Q.label,hint:Q.lastReachable?"reachable":"never",detail:z.join(`
213
213
  `)}});await r({title:`vibe network \u2014 ${X.length} peer(s)`,rows:H})},json:(X)=>X.map(y0)})}catch(Z){L(Z.message)}}),q.command("add <id>").description("Manually add a peer (use deploy for the SSH-install flow)").requiredOption("--label <label>","Friendly name").requiredOption("--tunnel-url <url>","Peer's tunnel URL").requiredOption("--api-key <key>","Scoped API key the peer minted for us").option("--permissions <list>",`Comma-separated permissions (default: tunnel:read). Allowed: ${E$.join(",")}`,"tunnel:read").option("--agent-record-id <id>","Platform-side agent ID for backend rotation lookup").option("--workspace-id <id>","Platform-side workspace ID").option("--json","Emit JSON result").action(($,Z)=>{try{let X={...Y.opts(),...Z},H=B2(Z.permissions);if(z0({id:$,label:Z.label,tunnelUrl:Z.tunnelUrl,apiKey:Z.apiKey,permissions:H,addedAt:new Date().toISOString(),agentRecordId:Z.agentRecordId,workspaceId:Z.workspaceId}),B(X,{ok:!0,id:$,label:Z.label,permissions:H}))return;U(`Added peer ${$} (${Z.label})`)}catch(X){L(X.message)}}),q.command("remove <id>").description("Remove a peer record (does not revoke the key on the peer)").option("--json","Emit JSON result").action(($,Z)=>{let X={...Y.opts(),...Z},H=_2($);if(B(X,{ok:H,id:$}))return;if(H)U(`Removed peer ${$}`);else L(`No peer with id ${$}`)}),q.command("update <id>").description("Modify permissions or label of an existing peer").option("--label <label>","Update friendly name").option("--permissions <list>",`Comma-separated permissions. Allowed: ${E$.join(",")}`).option("--json","Emit JSON result").action(($,Z)=>{try{let X={...Y.opts(),...Z},H={};if(Z.label)H.label=Z.label;if(Z.permissions)H.permissions=B2(Z.permissions);let Q=I2($,H);if(!Q){if(B(X,{ok:!1,id:$,error:"not_found"}))return;L(`No peer with id ${$}`);return}if(B(X,{ok:!0,id:$,peer:y0(Q)}))return;U(`Updated peer ${$}`)}catch(X){L(X.message)}}),q.command("test <id>").description("Probe a peer (calls /api/agent/identity over its tunnel)").option("--json","Emit JSON").option("--plain","Force plain text output").action(async($,Z)=>{let X={...Y.opts(),...Z},H=U2($);if(!H){if(B(X,{ok:!1,id:$,error:"not_found"}))return;L(`No peer with id ${$}`);return}try{await P({mode:f(X),fetchData:async()=>({peer:H,result:await W0($,"/api/profiles/default/agent/identity",{operation:"network-test"})}),plain:({peer:Q,result:z})=>{if(T(`Probing peer ${Q.label} (${Q.id})`),J(),z.ok){if(U(`Peer is reachable${z.rotated?" (recovered via backend rotation lookup)":""}`),z.data)console.log(JSON.stringify(z.data,null,2))}else L(`Peer call failed (${z.status}): ${z.error??"(no detail)"}`)},interactive:async({peer:Q,result:z})=>{let V=[` Peer: ${Q.label} (${Q.id})`,` Tunnel: ${Q.tunnelUrl}`,` Status: ${z.ok?"reachable":`failed (${z.status})`}`,` Rotated: ${z.rotated?"yes":"no"}`,` Error: ${z.error??"-"}`,"",` Identity: ${z.data?JSON.stringify(z.data,null,2):"-"}`];await v$({title:`Probe ${Q.label}`,body:V.join(`
214
214
  `)})},json:({peer:Q,result:z})=>({peer:y0(Q),result:a({ok:z.ok,status:z.status,rotated:z.rotated??!1,error:z.error??null,data:z.data??null})})})}catch(Q){L(Q.message)}})}import{existsSync as T3}from"fs";function i$(Y){return T3(F2(Y))}function D2(Y){let q=Y.command("profile").description("Manage gateway-environment profiles");q.command("list").description("List all profiles and mark the active one").option("--json","Emit JSON").option("--plain","Force plain text output").action(async function($){try{let Z={...Y.opts(),...$},X=()=>{let H=f$(),z=T2().map((V)=>{let _=V0(V);return{name:V,active:V===H,globalGatewayUrl:_.globalGatewayUrl??null,workspaceGatewayUrl:_.workspaceGatewayUrl??null}});return{active:H,profiles:z}};await P({mode:f(Z),fetchData:X,plain:(H)=>{if(H.profiles.length===0){W("No profiles yet. Run 'vibe profile seed' to create the default profile.");return}T("Profiles"),n(H.profiles.map((Q)=>({Name:Q.name,Active:Q.active?K.green("\u25CF"):"","Global Gateway":Q.globalGatewayUrl??K.dim("(unset)"),"Workspace Gateway":Q.workspaceGatewayUrl??K.dim("(unset)")})))},interactive:async(H)=>{if(H.profiles.length===0){T("Profiles"),J(),W("No profiles yet. Run 'vibe profile seed' to create the default profile.");return}let Q=H.profiles.map((z)=>{let V=[`${K.bold(z.name)}${z.active?" "+K.green("\u25CF active"):""}`,"",` Global gateway: ${z.globalGatewayUrl??K.dim("(unset)")}`,` Workspace gateway: ${z.workspaceGatewayUrl??K.dim("(unset)")}`];return{id:z.name,label:z.name,hint:z.active?"active":"",detail:V.join(`
215
215
  `)}});await r({title:`vibe profile \u2014 ${H.profiles.length} profile(s)`,rows:Q,footer:"\u2191/\u2193 navigate \xB7 q to quit"})},json:(H)=>H})}catch(Z){L(Z.message)}}),q.command("current").description("Print the active profile name").option("--json","Emit JSON").option("--plain","Force plain text output").action(async function($){try{let Z={...Y.opts(),...$};await P({mode:f(Z),fetchData:()=>({active:f$()}),plain:(X)=>{console.log(X.active)},json:(X)=>X})}catch(Z){L(Z.message)}}),q.command("show [name]").description("Print a profile's config as JSON (apiKey + secrets redacted)").option("--json","Emit JSON").option("--plain","Force plain text output").action(async function($,Z){try{let X={...Y.opts(),...Z},H=$?y$($):f$();if(!i$(H)){L(`No profile named '${H}'. Try 'vibe profile list'.`);return}let Q=()=>({name:H,active:H===f$(),config:V0(H)});await P({mode:f(X),fetchData:Q,plain:(z)=>{T(`Profile: ${z.name}`),I("Active",z.active?"yes":"no"),J(),console.log(JSON.stringify(a(z.config),null,2))},interactive:async(z)=>{let V=[`Active: ${z.active?"yes":"no"}`,"",JSON.stringify(a(z.config),null,2)].join(`
216
216
  `);await v$({title:`Profile: ${z.name}`,body:V,footer:"q / Esc to quit"})},json:(z)=>({name:z.name,active:z.active,config:a(z.config)})})}catch(X){L(X.message)}}),q.command("create <name>").description("Create a new profile (blank, or copied from another)").option("--from <existing>","Copy gateway URLs + config from an existing profile").option("--use","After creating, set this profile as active",!1).option("--json","Emit JSON result").action(($,Z)=>{try{let X={...Y.opts(),...Z},H=y$($);if(i$(H)){L(`Profile '${H}' already exists.`);return}let Q;if(Z.from){let z=y$(Z.from);if(!i$(z)){L(`--from: profile '${z}' does not exist.`);return}let V=V0(z);delete V["static-api-key"],delete V.agentRecordId,delete V.apiKeys,Q=V}else if(H in G2)Q=E2(H);else if(H in f0){let z=f0[H];Q={schemaVersion:void 0,globalGatewayUrl:z.globalGatewayUrl,workspaceGatewayUrl:z.workspaceGatewayUrl}}else Q={};if(R2(H,Q),Z.use)P0(H);if(B(X,{ok:!0,action:"create",profile:H,from:Z.from??null,globalGatewayUrl:Q.globalGatewayUrl??null,workspaceGatewayUrl:Q.workspaceGatewayUrl??null,active:Z.use===!0}))return;if(U(`Profile '${H}' created.`),Q.globalGatewayUrl)I("Global gateway",Q.globalGatewayUrl);if(Q.workspaceGatewayUrl)I("Workspace gateway",Q.workspaceGatewayUrl);if(Z.use)W(`Active profile is now '${H}'.`);else J(),W(`Activate with: ${K.bold(`vibe profile use ${H}`)}`)}catch(X){L(X.message)}}),q.command("use <name>").description("Set the active profile pointer").option("--json","Emit JSON result").action(($,Z)=>{try{let X={...Y.opts(),...Z},H=y$($);if(!i$(H)){L(`No profile named '${H}'. Create it with 'vibe profile create ${H}' first.`);return}if(P0(H),B(X,{ok:!0,action:"use",profile:H}))return;U(`Active profile is now '${H}'.`)}catch(X){L(X.message)}}),q.command("delete <name>").description("Delete a profile (refuses if it is the active one)").option("--confirm","Required -- destructive",!1).option("--json","Emit JSON result").action(($,Z)=>{try{let X={...Y.opts(),...Z},H=y$($);if(!Z.confirm){L(`Pass --confirm to delete profile '${H}' (this removes its config + secrets).`);return}if(!i$(H)){L(`No profile named '${H}'.`);return}if(H===f$()){L(`Cannot delete the active profile '${H}'. Switch first: 'vibe profile use <other>'.`);return}let Q=j2(H);if(B(X,{ok:Q,action:"delete",profile:H}))return;if(Q)U(`Deleted profile '${H}'.`);else L(`Profile '${H}' could not be removed.`)}catch(X){L(X.message)}}),q.command("seed").description("Idempotently create local/alpha/prod profiles").option("--json","Emit JSON result").action(($)=>{try{let Z={...Y.opts(),...$},X=N2();if(B(Z,{ok:!0,action:"seed",created:X.created,activeWritten:X.activeWritten??null}))return;if(X.created.length>0)U(`Created profile(s): ${X.created.join(", ")}`);if(X.activeWritten)W(`Active profile set to '${X.activeWritten}'.`);if(X.created.length===0&&!X.activeWritten)W("Nothing to do -- profiles already initialized.")}catch(Z){L(Z.message)}})}function x2(Y){let q=Y.command("daemon-profile").description("Manage the running daemon's in-process ProfileRegistry (distinct from `vibe profile`, which manages gateway-environment profiles on disk).");q.command("list").description("List profiles known to the running daemon").option("--json","Emit JSON").option("--plain","Force plain text output").action(async function($){let Z={...Y.opts(),...$};try{await P({mode:f(Z),fetchData:()=>y(w(Z),"/api/profiles"),plain:(X)=>{if(T("Daemon Profiles"),J(),!X||X.length===0){W("No profiles attached.");return}let H=X.map((Q)=>({Name:Q.name,Default:Q.isDefault?"yes":"",Attached:Q.attached?"yes":"",BootState:Q.bootState??"-",Running:Q.isRunning?"yes":"",Port:Q.port??"-",PID:Q.pid??"-"}));n(H)}})}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(`Failed to list daemon profiles: ${C(X)}`)}}),q.command("create <name>").description("Create a new profile and attach it to the running daemon").option("--copy-from <source>","Copy config from an existing profile").option("--start","Spawn an out-of-process daemon for the new profile").option("--port <port>","Port for the spawned daemon (with --start)").option("--json","Emit JSON").action(async function($,Z){let X={...Y.opts(),...Z};try{let H={name:$};if(Z.copyFrom)H.copyFrom=Z.copyFrom;if(Z.start)H.start=!0;if(Z.port)H.port=parseInt(Z.port,10);let Q=await m(w(X),"/api/profiles",H);if(B(X,Q))return;if(U(`Profile '${$}' created.`),I("Default",Q.isDefault?"yes":"no"),I("Attached",Q.attached?"yes":"no"),Q.bootState)I("BootState",Q.bootState)}catch(H){if(X.json){B(X,{ok:!1,error:C(H)});return}L(`Failed to create profile: ${C(H)}`)}}),q.command("delete <name>").alias("rm").description("Delete a profile from the running daemon").option("--purge","Also remove the on-disk dataDir (destructive)").option("--json","Emit JSON").action(async function($,Z){let X={...Y.opts(),...Z};try{let H=Z.purge?`/api/profiles/${encodeURIComponent($)}?purge=true`:`/api/profiles/${encodeURIComponent($)}`,Q=await P$(w(X),H);if(B(X,Q))return;U(`Profile '${$}' deleted.`)}catch(H){if(X.json){B(X,{ok:!1,error:C(H)});return}L(`Failed to delete profile: ${C(H)}`)}}),q.command("start <name>").description("Ensure the profile is attached + running (idempotent)").option("--port <port>","Port for the spawned daemon").option("--json","Emit JSON").action(async function($,Z){let X={...Y.opts(),...Z};try{let H={};if(Z.port)H.port=parseInt(Z.port,10);let Q=await m(w(X),`/api/profiles/${encodeURIComponent($)}/start`,H);if(B(X,Q))return;if(U(`Profile '${$}' started.`),Q.bootState)I("BootState",Q.bootState);if(Q.port)I("Port",String(Q.port))}catch(H){if(X.json){B(X,{ok:!1,error:C(H)});return}L(`Failed to start profile: ${C(H)}`)}}),q.command("stop <name>").description("Stop the profile (detach from registry, preserve dataDir)").option("--json","Emit JSON").action(async function($,Z){let X={...Y.opts(),...Z};try{let H=await m(w(X),`/api/profiles/${encodeURIComponent($)}/stop`);if(B(X,H))return;U(`Profile '${$}' stopped.`)}catch(H){if(X.json){B(X,{ok:!1,error:C(H)});return}L(`Failed to stop profile: ${C(H)}`)}}),q.command("restart <name>").description("Stop then start the profile").option("--port <port>","Port for the spawned daemon").option("--json","Emit JSON").action(async function($,Z){let X={...Y.opts(),...Z};try{await m(w(X),`/api/profiles/${encodeURIComponent($)}/stop`);let H={};if(Z.port)H.port=parseInt(Z.port,10);let Q=await m(w(X),`/api/profiles/${encodeURIComponent($)}/start`,H);if(B(X,Q))return;if(U(`Profile '${$}' restarted.`),Q.bootState)I("BootState",Q.bootState)}catch(H){if(X.json){B(X,{ok:!1,error:C(H)});return}L(`Failed to restart profile: ${C(H)}`)}}),q.command("stats").description("Per-profile resource attribution (childPidCount, status, dataDir; CPU/heap reported at the process level)").option("--json","Emit JSON").option("--plain","Force plain text output").action(async function($){let Z={...Y.opts(),...$};try{await P({mode:f(Z),fetchData:()=>y(w(Z),"/api/profile-stats"),plain:(X)=>{if(T("Profile Stats"),J(),I("PID",String(X.process.pid)),I("Uptime (s)",String(Math.round(X.process.uptimeSeconds))),I("CPU user (ms)",String(Math.round(X.process.cpuUserMs))),I("CPU system (ms)",String(Math.round(X.process.cpuSystemMs))),I("Heap used (MB)",String(Math.round(X.process.heapUsedBytes/1048576))),J(),!X.profiles||X.profiles.length===0){W("No profiles attached.");return}n(X.profiles.map((H)=>({Name:H.name,Status:H.status,ChildPids:String(H.childPidCount),DataDir:H.dataDir})))}})}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(`Failed to fetch profile stats: ${C(X)}`)}})}import b$ from"os";function R3(){return crypto.randomUUID()}function j3(){let Y=new Uint8Array(32);return crypto.getRandomValues(Y),`vcak_${Buffer.from(Y).toString("base64url")}`}function E3(){let Y=new Bun.CryptoHasher("sha256");return Y.update(`${b$.hostname()}-${b$.platform()}-${b$.arch()}`),Y.digest("hex").substring(0,16)}function N3(Y){if(!Y)return;let q=/^(\d+)([smhdw]?)$/.exec(Y.trim());if(!q)throw Error(`Invalid --expires-in: ${Y}`);let $=Number(q[1]),Z=q[2]||"d",X=Z==="s"?$*1000:Z==="m"?$*60000:Z==="h"?$*3600000:Z==="w"?$*7*86400000:$*86400000;return new Date(Date.now()+X).toISOString()}function A2(Y){Y.command("peer-bootstrap").description("Mint a peer credential bundle (used by `vibe deploy` post-install handshake)").option("--label <label>","Friendly name for the caller (logged on this host)","peer").option("--scope <list>",`Comma-separated permissions for the minted key (default: tunnel:read). Allowed: ${E$.join(",")}`,"tunnel:read").option("--expires-in <duration>","TTL for the minted key (e.g. 7d, 12h). Omit for no expiry.").option("--emit-default-key","Include this agent's FULL default API key in the bundle. Only used by `vibe deploy` over the trusted SSH channel to onboard the new agent to the backend (fresh OAuth app). Never expose this output otherwise.",!1).option("--no-output","Don't print the JSON bundle (for testing)").option("--json","Emit JSON bundle (default behaviour, kept for parity)").action(async function(q){try{let $=q.scope.split(",").map((G)=>G.trim()).filter(Boolean),Z=K0($);if(Z.length===0)throw Error(`No valid permissions in --scope. Allowed: ${E$.join(",")}`);let X=N3(q.expiresIn),H=R3(),Q=j3(),z=Z.includes("mesh:forward")?["read","mesh:forward"]:["read"],_=[...Y$().apiKeys??[],{id:H,name:`peer:${q.label}`,key:Q,scopes:z,expiresAt:X,createdAt:new Date().toISOString()}];U$({apiKeys:_});let O=Y$(),F=await M2(),D={id:E3(),hostname:b$.hostname(),platform:b$.platform(),arch:b$.arch(),tunnelUrl:w2()||J$()?.url||null,apiKey:Q,keyId:H,permissions:Z,expiresAt:X??null,defaultApiKey:F.substring(0,8)+"****",...q.emitDefaultKey?{fullDefaultApiKey:F}:{},agentRecordId:O.agentRecordId??null,workspaceId:O.workspaceId??null};if(q.output===!1)return;console.log(`VIBE_BOOTSTRAP_JSON=${JSON.stringify(D)}`);let R={...Y.opts(),...q};if(B(R,D))return;console.log(JSON.stringify(D,null,2))}catch($){console.error(JSON.stringify({error:$ instanceof Error?C($):String($)})),process.exit(1)}})}var D3=[{title:"Lifecycle",commands:["start","stop","restart","kill","list","status"]},{title:"Setup",commands:["setup","autostart","deploy","update","completion"]},{title:"Profile",commands:["profile"]},{title:"Plugins",commands:["plugin"]},{title:"Network",commands:["tunnel","network","peer-bootstrap","gateway-auth","url"]},{title:"Data",commands:["export","import","file","project","session","task","bookmark","state","git","key","config"]},{title:"Diagnostics",commands:["doctor","diagnostics","health","info","system","log","logs","log-level","notify"]},{title:"Maintenance",commands:["gc","nuke"]},{title:"Help",commands:["help"]}];function k0(Y){let q=new Map;for(let $ of Y.commands){if($._hidden)continue;let Z=$.name();q.set(Z,{name:Z,description:$.description()||"",cmd:$})}return q}function x3(Y,q){let $=Y;for(let Z of q){let X=$.commands.find((H)=>H.name()===Z||H.aliases().includes(Z));if(!X)return null;$=X}return $}function u0(Y){let q=new Set,$=[];for(let X of D3)for(let H of X.commands){let Q=Y.get(H);if(!Q)continue;q.add(H),$.push({group:X.title,entry:Q})}let Z=[...Y.values()].filter((X)=>!q.has(X.name));for(let X of Z.sort((H,Q)=>H.name.localeCompare(Q.name)))$.push({group:"Other",entry:X});return $}function M3(Y,q=!1){let $=k0(Y),Z=u0($),X=Z.length>0?Math.max(...Z.map((V)=>V.entry.name.length)):0,H=[];H.push(""),H.push(`${K.bold("vibe")} ${K.dim("\u2014 VibeControls Agent CLI")}`),H.push(""),H.push(`Usage: ${K.bold("vibe")} <command> [options]`),H.push(` ${K.bold("vibe help")} <command>`);let Q="";for(let{group:V,entry:_}of Z){if(V!==Q)H.push(""),H.push(K.cyan(V)),Q=V;let O=" ".repeat(X-_.name.length+2);H.push(` ${K.bold(_.name)}${O}${_.description}`)}H.push(""),H.push(K.dim("Tip: pipe to a TTY to launch the interactive browser, or run `vibe help <command>` for full options.")),H.push("");let z=H.join(`
217
- `);return q?b0(z):z}function w3(Y){let q=k0(Y);return{commands:u0(q).map(({group:Z,entry:X})=>({name:X.name,description:X.description,group:Z}))}}function S2(Y,q=!1){process.stdout.write(M3(Y,q))}function h2(Y){process.stdout.write(Y.helpInformation())}async function A3(Y){let q;try{q=await import("./index-scsjyj4m.js")}catch{return!1}let{createCliRenderer:$,BoxRenderable:Z,TextRenderable:X,SelectRenderable:H,SelectRenderableEvents:Q}=q,z=k0(Y),V=u0(z);if(V.length===0)return!1;let _=await $({exitOnCtrlC:!0,targetFps:30}),O=[],F="";for(let v of V){if(v.group!==F)O.push({kind:"header",title:v.group}),F=v.group;O.push({kind:"cmd",entry:v.entry})}let D=O.map((v,u)=>v.kind==="header"?{name:`\u2500\u2500 ${v.title} \u2500\u2500`,description:"",value:u}:{name:v.entry.name,description:v.entry.description,value:u}),R=_.root.ctx,G=new Z(R,{width:"100%",height:"100%",flexDirection:"column",backgroundColor:"#0b0d12"}),x=new X(R,{content:" vibe \u2014 command browser \u2191/\u2193 navigate \xB7 Enter view \xB7 q quit",fg:"#8be9fd",height:1}),M=new Z(R,{width:"100%",flexGrow:1,flexDirection:"row"}),N=new H(R,{width:28,height:"100%",options:D,selectedIndex:O.findIndex((v)=>v.kind==="cmd"),showDescription:!1,backgroundColor:"#0b0d12",textColor:"#cdd6f4",focusedBackgroundColor:"#0b0d12",focusedTextColor:"#cdd6f4",selectedBackgroundColor:"#1f2335",selectedTextColor:"#a6e3a1",showScrollIndicator:!0,wrapSelection:!1}),S=new Z(R,{flexGrow:1,height:"100%",flexDirection:"column",paddingLeft:2,paddingRight:2,backgroundColor:"#11141c"}),q$=new X(R,{content:"",fg:"#cdd6f4"});S.add(q$),M.add(N),M.add(S),G.add(x),G.add(M),_.root.add(G),N.focus();let o=(v)=>{let u=O[v];if(!u)return;if(u.kind==="header"){q$.content=`
217
+ `);return q?b0(z):z}function w3(Y){let q=k0(Y);return{commands:u0(q).map(({group:Z,entry:X})=>({name:X.name,description:X.description,group:Z}))}}function S2(Y,q=!1){process.stdout.write(M3(Y,q))}function h2(Y){process.stdout.write(Y.helpInformation())}async function A3(Y){let q;try{q=await import("./index-x649afed.js")}catch{return!1}let{createCliRenderer:$,BoxRenderable:Z,TextRenderable:X,SelectRenderable:H,SelectRenderableEvents:Q}=q,z=k0(Y),V=u0(z);if(V.length===0)return!1;let _=await $({exitOnCtrlC:!0,targetFps:30}),O=[],F="";for(let v of V){if(v.group!==F)O.push({kind:"header",title:v.group}),F=v.group;O.push({kind:"cmd",entry:v.entry})}let D=O.map((v,u)=>v.kind==="header"?{name:`\u2500\u2500 ${v.title} \u2500\u2500`,description:"",value:u}:{name:v.entry.name,description:v.entry.description,value:u}),R=_.root.ctx,G=new Z(R,{width:"100%",height:"100%",flexDirection:"column",backgroundColor:"#0b0d12"}),x=new X(R,{content:" vibe \u2014 command browser \u2191/\u2193 navigate \xB7 Enter view \xB7 q quit",fg:"#8be9fd",height:1}),M=new Z(R,{width:"100%",flexGrow:1,flexDirection:"row"}),N=new H(R,{width:28,height:"100%",options:D,selectedIndex:O.findIndex((v)=>v.kind==="cmd"),showDescription:!1,backgroundColor:"#0b0d12",textColor:"#cdd6f4",focusedBackgroundColor:"#0b0d12",focusedTextColor:"#cdd6f4",selectedBackgroundColor:"#1f2335",selectedTextColor:"#a6e3a1",showScrollIndicator:!0,wrapSelection:!1}),S=new Z(R,{flexGrow:1,height:"100%",flexDirection:"column",paddingLeft:2,paddingRight:2,backgroundColor:"#11141c"}),q$=new X(R,{content:"",fg:"#cdd6f4"});S.add(q$),M.add(N),M.add(S),G.add(x),G.add(M),_.root.add(G),N.focus();let o=(v)=>{let u=O[v];if(!u)return;if(u.kind==="header"){q$.content=`
218
218
  ${u.title}
219
219
  `;return}let c=u.entry.cmd.helpInformation();q$.content=`
220
220
  ${c}
@@ -227,5 +227,5 @@ Enter: print this help and exit
227
227
  `);return}if(!Z.plain&&t$()){if(await A3(Y))return}S2(Y,!!Z.plain)}})}var S3="http://localhost:3005",h3=5000;function v3(Y,q,$){let Z=Number.parseInt(Y,10);if(!Number.isInteger(Z)||Z<1)return q;return Math.min(Z,$)}function y2(Y){Y.command("audit").description("View persistent audit log").command("list").description("List recent audit events").option("--since <iso>","Lower-bound ISO 8601 timestamp").option("--limit <n>","Maximum events to show","100").option("--event <pattern>","Filter by event name (supports * glob)").option("--agent-url <url>","Agent URL",S3).option("--json","Emit JSON (one object per line)").option("--plain","Force plain text output").action(async function($){try{let Z={...Y.opts(),...$},X=w(Z),H=encodeURIComponent(A(Z)),Q=new URLSearchParams;if(Q.set("limit",String(v3(String(Z.limit),100,h3))),Z.since)Q.set("since",String(Z.since));if(Z.event)Q.set("event",String(Z.event));let V=(await y(X,`/api/profiles/${H}/agent/audit?${Q.toString()}`)).events??[];if(Z.json){for(let _ of V)process.stdout.write(`${JSON.stringify(_)}
228
228
  `);return}if(V.length===0){W("No audit events found.");return}T("Audit events"),J();for(let _ of V){let O=_.timestamp?K.dim(G$(_.timestamp)):"",F=_.source?K.cyan(`[${_.source}]`):"",D=K.bold(_.event??"?"),R=_.payload?K.dim(JSON.stringify(_.payload)):"";console.log(` ${D} ${F} ${R} ${O}`)}}catch(Z){L(C(Z))}})}function f2(Y){let q=Y.command("alias").description("Manage per-profile aliases");q.command("list").description("List aliases for the current profile").option("--json","Emit JSON").option("--plain","Force plain text output").action(async function($){try{let Z={...Y.opts(),...$},X=w(Z),H=encodeURIComponent(A(Z));await P({mode:f(Z),fetchData:async()=>{return(await y(X,`/api/profiles/${H}/agent/aliases`)).aliases??[]},plain:(Q)=>{if(T("Aliases"),J(),!Q.length){W("No aliases defined.");return}let z=Q.map((V)=>({Name:V.name,Command:V.command.length>60?`${V.command.slice(0,57)}\u2026`:V.command,Description:V.description??"-",Updated:G$(V.updatedAt)}));n(z),J()}})}catch(Z){L(C(Z))}}),q.command("get <name>").description("Show an alias by name").option("--json","Emit JSON").action(async function($,Z){try{let X={...Y.opts(),...Z},H=w(X),Q=encodeURIComponent(A(X)),z=await y(H,`/api/profiles/${Q}/agent/aliases/${encodeURIComponent($)}`);if(X.json){process.stdout.write(`${JSON.stringify(z,null,2)}
229
229
  `);return}T(`Alias: ${z.name}`),J(),console.log(` ${K.bold("Command: ")} ${z.command}`),console.log(` ${K.bold("Description:")} ${z.description??"-"}`),console.log(` ${K.bold("Cwd: ")} ${z.cwd??"$HOME (default)"}`),console.log(` ${K.bold("Profile: ")} ${z.profile}`),console.log(` ${K.bold("Created: ")} ${z.createdAt}`),console.log(` ${K.bold("Updated: ")} ${z.updatedAt}`),J()}catch(X){L(C(X))}}),q.command("create <name>").description("Create a new alias").requiredOption("--command <cmd>","The shell command to run").option("--description <text>","Optional description").option("--cwd <dir>","Working directory the command runs in (supports ~, absolute, or relative-to-$HOME). Defaults to $HOME.").action(async function($,Z){try{let X={...Y.opts(),...Z},H=w(X),Q=encodeURIComponent(A(X)),z=await m(H,`/api/profiles/${Q}/agent/aliases`,{name:$,command:Z.command,description:Z.description,cwd:Z.cwd});U(`Created alias '${z.name}'`)}catch(X){L(C(X))}}),q.command("update <name>").description("Update an existing alias").option("--command <cmd>","Replacement shell command").option("--description <text>","Replacement description").option("--cwd <dir>","Replacement working directory. Pass an empty string to reset to $HOME.").action(async function($,Z){try{if(Z.command===void 0&&Z.description===void 0&&Z.cwd===void 0){L("Provide --command, --description, or --cwd to update.");return}let X={...Y.opts(),...Z},H=w(X),Q=encodeURIComponent(A(X)),z=await L0(H,`/api/profiles/${Q}/agent/aliases/${encodeURIComponent($)}`,{command:Z.command,description:Z.description,cwd:Z.cwd});U(`Updated alias '${z.name}'`)}catch(X){L(C(X))}}),q.command("delete <name>").description("Delete an alias").action(async function($,Z){try{let X={...Y.opts(),...Z},H=w(X),Q=encodeURIComponent(A(X));await P$(H,`/api/profiles/${Q}/agent/aliases/${encodeURIComponent($)}`),U(`Deleted alias '${$}'`)}catch(X){L(C(X))}})}function k2(Y){Y.command("run <name> [args...]").description("Run a stored alias by name").allowUnknownOption(!0).action(async function(q,$=[],Z){try{let X={...Y.opts(),...Z},H=w(X),Q=encodeURIComponent(A(X)),z;try{z=await y(H,`/api/profiles/${Q}/agent/aliases/${encodeURIComponent(q)}`)}catch{console.error(`alias '${q}' not found`),c0().audit.emit("agent","alias.executed",{exit_code:1}),process.exit(1)}let{exitCode:V}=await b2(z,$);c0().audit.emit("agent","alias.executed",{exit_code:V}),P2("alias.executed",{exit_code:V}),process.exit(V)}catch(X){L(C(X))}})}function u2(Y){Y.command("retry-config").description("Force the background finalize-retry worker to attempt finalize immediately. Use when the gateway came back online and you don't want to wait the current backoff.").option("--json","Emit JSON").action(async function(q){let $={...Y.opts(),...q};try{let Z=w($),X=await fetch(`${Z}/api/agent/retry-config`,{method:"POST"}),H;try{H=await X.json()}catch{if($.json)B($,{ok:!1,error:`agent returned non-JSON (HTTP ${X.status})`}),process.exit(1);L(`Agent returned non-JSON response (HTTP ${X.status}). The daemon may be on an older build without /api/agent/retry-config.`),process.exit(1);return}if($.json){if(B($,H),H.state!=="ready")process.exit(H.ok?0:3);return}if(X.status===409){T("Retry not available"),W(H.error??"No active finalize-retry worker."),process.exit(2);return}if(T("Force finalize retry"),I("Result",H.ok?K.green("ok"):K.red("failed")),H.state)I("Boot state",H.state);if(H.worker){if(I("Attempt",String(H.worker.attempt)),H.worker.nextAttemptAt)I("Next attempt",H.worker.nextAttemptAt)}if(J(),H.ok&&H.state==="ready")W(`${K.green("\u2713")} Agent finalized \u2014 state=ready.`),process.exit(0);else if(H.ok)W(`${K.yellow("\u26A0")} Attempt completed but agent is still in '${H.state}'. The worker will continue to retry in the background; check ${K.bold("vibe status")} for progress.`),process.exit(0);else j(`Retry failed: ${H.error??"unknown error"}. The worker will keep retrying on the configured backoff. View the full trace with ${K.bold("vibe logs --since 10m")}.`),process.exit(3)}catch(Z){let X=Z instanceof Error?C(Z):String(Z);if($.json){B($,{ok:!1,error:X}),process.exit(1);return}L(`Failed to reach agent: ${X}`),process.exit(1)}})}var t="http://localhost:3005";function y3(Y){return(Y||[]).map((q)=>({id:q.id??null,name:q.name??null,status:q.status??null,port:q.port??null,project:q.project??q.projectId??null}))}async function c2(Y,q,$,Z,X){await P({mode:f(X),fetchData:async()=>{return(await y(Y,q)).sessions||[]},plain:(H)=>{if(!H||H.length===0){W(Z);return}T($),n(H.map((Q)=>({ID:W$(Q.id||""),Name:Q.name||"-",Status:x$(Q.status||""),Port:Q.port??"-",Project:Q.project||Q.projectId||"-"})))},interactive:async(H)=>{if(!H||H.length===0){T($),W(Z);return}let Q=H.map((z)=>({id:String(z.id??""),label:z.name||W$(z.id||""),hint:z.status||"",detail:[`ID: ${z.id??"-"}`,`Name: ${z.name??"-"}`,`Status: ${x$(z.status||"")}`,`Port: ${z.port??"-"}`,`Project: ${z.project??z.projectId??"-"}`].join(`
230
- `)}));await r({title:`${$} \u2014 ${H.length} session(s)`,rows:Q})},json:(H)=>y3(H)})}function d2(Y){let q=Y.command("session").description("Manage terminal sessions");q.command("system").description("List system sessions (alias for `session list --system`)").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").option("--plain","Force plain text output").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z));await c2(X,`/api/profiles/${H}/sessions/system`,"System Sessions","No system sessions found.",Z)}catch(X){L(C(X))}}),q.command("list").description("List all sessions").option("--system","Show system sessions instead of user sessions").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").option("--plain","Force plain text output").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z)),Q=$.system?`/api/profiles/${H}/sessions/system`:`/api/profiles/${H}/sessions`;await c2(X,Q,"Sessions","No sessions found.",Z)}catch(X){L(C(X))}}),q.command("create").description("Create a new session").requiredOption("--name <name>","Session name").option("--project <id>","Project ID","default").option("--command <cmd>","Initial command to run").option("--cwd <dir>","Working directory").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z)),Q={sessionName:$.name,projectId:$.project};if($.command)Q.command=$.command;if($.cwd)Q.startDirectory=$.cwd;let z=await m(X,`/api/profiles/${H}/sessions/create`,Q),V=z?.session?.id||z?.id||z?.sessionId;if(B(Z,{ok:!0,id:V,name:$.name,project:$.project}))return;U(`Session created: ${W$(V)}`),I("Name",$.name),I("Project",$.project)}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(C(X))}}),q.command("kill").description("Kill a session").requiredOption("-i, --id <id>","Session ID").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z));if(await P$(X,`/api/profiles/${H}/sessions/${$.id}`),B(Z,{ok:!0,id:$.id}))return;U(`Session ${W$($.id)} killed.`)}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(C(X))}}),q.command("exec").description("Execute a command in a session").requiredOption("-i, --id <id>","Session ID").requiredOption("-c, --command <cmd>","Command to execute").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z)),Q=await m(X,`/api/profiles/${H}/sessions/${$.id}/command`,{command:$.command});if(B(Z,{ok:!0,id:$.id,output:Q?.output??null}))return;if(U("Command executed."),Q?.output)J(),console.log(Q.output)}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(C(X))}}),q.command("capture").description("Capture session terminal output").requiredOption("-i, --id <id>","Session ID").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").option("--plain","Force plain text output").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z));await P({mode:f(Z),fetchData:()=>y(X,`/api/profiles/${H}/sessions/${$.id}/capture`),plain:(Q)=>{if(Q?.content||Q?.output)console.log(Q.content||Q.output);else W("No capture data available.")},json:(Q)=>({id:$.id,content:Q?.content??Q?.output??null})})}catch(X){L(C(X))}}),q.command("keys").description("Send keys to a session").requiredOption("-i, --id <id>","Session ID").requiredOption("-k, --keys <keys>","Keys to send").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z));if(await m(X,`/api/profiles/${H}/sessions/${$.id}/keys`,{keys:$.keys}),B(Z,{ok:!0,id:$.id}))return;U("Keys sent.")}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(C(X))}}),q.command("interrupt").description("Send interrupt signal to a session").requiredOption("-i, --id <id>","Session ID").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z));if(await m(X,`/api/profiles/${H}/sessions/${$.id}/interrupt`,{}),B(Z,{ok:!0,id:$.id}))return;U(`Session ${W$($.id)} interrupted.`)}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(C(X))}}),q.command("rename").description("Rename a session").requiredOption("-i, --id <id>","Session ID").requiredOption("--name <name>","New session name").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z));if(await L0(X,`/api/profiles/${H}/sessions/${$.id}/rename`,{newName:$.name}),B(Z,{ok:!0,id:$.id,name:$.name}))return;U(`Session ${W$($.id)} renamed to "${$.name}".`)}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(C(X))}}),q.command("toggle-mouse").description("Toggle mouse support in a session").requiredOption("-i, --id <id>","Session ID").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z)),Q=await m(X,`/api/profiles/${H}/sessions/${$.id}/toggle-mouse`,{});if(B(Z,{ok:!0,id:$.id,mouseEnabled:!!Q?.mouseEnabled}))return;U(`Mouse support ${Q?.mouseEnabled?"enabled":"toggled"} for session ${W$($.id)}.`)}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(C(X))}}),q.command("terminal-start").description("Start terminal for a session").requiredOption("-i, --id <id>","Session ID").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z)),Q=await m(X,`/api/profiles/${H}/sessions/${$.id}/terminal`,{});if(B(Z,{ok:!0,id:$.id,port:Q?.port??null}))return;if(U(`Terminal started for session ${W$($.id)}.`),Q?.port)I("Port",Q.port)}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(C(X))}}),q.command("terminal-stop").description("Stop terminal for a session").requiredOption("-i, --id <id>","Session ID").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z));if(await m(X,`/api/profiles/${H}/sessions/${$.id}/terminal/stop`,{}),B(Z,{ok:!0,id:$.id}))return;U(`Terminal stopped for session ${W$($.id)}.`)}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(C(X))}}),q.command("health-check").description("Run health check on all sessions").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z)),Q=await y(X,`/api/profiles/${H}/sessions`),z=await m(X,`/api/profiles/${H}/sessions/health-check`,{sessionIds:(Q.sessions||[]).map((V)=>V.id)});if(B(Z,{ok:!0,healthy:z?.healthy??null,checked:z?.checked??null,fixed:z?.fixed??null}))return;if(U("Health check completed."),z?.healthy!==void 0)I("Healthy",z.healthy);if(z?.checked!==void 0)I("Checked",z.checked);if(z?.fixed!==void 0)I("Fixed",z.fixed)}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(C(X))}})}function m2(Y){Y.command("reuse-db").description("Point this agent at an EXISTING database (reuse data from another same-workspace agent)").option("--adapter <name>","Storage adapter to use (e.g. postgres, skalex). Defaults to the configured/default adapter.").option("--connection-string <conn>","Connection string for the adapter (e.g. postgres://user:pass@host/db)").option("--storage-options <json>","Raw adapter options as a JSON object (alternative/in addition to --connection-string)").option("--db-path <path>","Data directory the adapter should use (e.g. an existing Skalex agent-db dir)").option("-y, --yes","Skip the confirmation prompt").option("--json","Emit JSON").action(async function(q){let $={...Y.opts(),...q};try{let Z={};if(q.storageOptions){let Q;try{Q=JSON.parse(q.storageOptions)}catch{L("--storage-options must be valid JSON.");return}if(!Q||typeof Q!=="object"||Array.isArray(Q)){L("--storage-options must be a JSON object.");return}for(let[z,V]of Object.entries(Q))Z[z]=typeof V==="string"?V:JSON.stringify(V)}if(q.connectionString)Z.connectionString=String(q.connectionString);if(!q.adapter&&!q.dbPath&&Object.keys(Z).length===0){L("Nothing to set. Provide --adapter with --connection-string (or --storage-options), and/or --db-path.");return}if(!$.json){if(T("Reuse an existing database"),q.adapter)I("Adapter",K.bold(q.adapter));if(q.dbPath)I("Data path",K.bold(q.dbPath));if(Object.keys(Z).length>0)I("Options",K.dim(Object.keys(Z).join(", ")));J(),j(`${E.warning} Reuse is safe ONLY for a database from the SAME workspace \u2014 the encryption key is per-workspace, so a foreign DB won't decrypt (the agent will go degraded).`),j(`${E.warning} Two agents writing the same database concurrently can corrupt it. Keep this a single-writer setup unless your adapter is explicitly configured for shared writes.`),J()}if(!q.yes&&!$.json){if(!await T$(K.bold("Write this storage configuration to the agent config?"))){W("Cancelled.");return}}let X={};if(q.adapter)X.storageAdapter=String(q.adapter);if(Object.keys(Z).length>0)X.storageOptions=Z;if(q.dbPath)X.dbPath=String(q.dbPath);U$(X);let H=Y$();if(B($,{ok:!0,storageAdapter:H.storageAdapter??null,dbPath:H.dbPath??null,storageOptionKeys:Object.keys(H.storageOptions??{})}))return;U(`${E.success} Storage configuration written. Run ${K.bold("vibe restart")} so the agent connects to the existing database.`)}catch(Z){let X=Z instanceof Error?C(Z):String(Z);if($.json){B($,{ok:!1,error:X});return}L(`reuse-db failed: ${X}`)}})}function d0(Y){return new Set([...r$(Y)??$0()])}function m0(Y){return o$(process.platform,new Set(Y)).map((q)=>q.packageName)}async function g0(){let{PluginManager:Y}=await import("./plugin-system-c916v9an.js"),q=new Y;return{install:($)=>q.install($),remove:($)=>q.remove($)}}function l2(Y){let q=Y.command("capability").alias("cap").description("Select agent capabilities (abilities) + providers");q.command("list",{isDefault:!0}).description("List capabilities and whether each is enabled").option("--json","Emit JSON").action(($)=>{let Z={...Y.opts(),...$},X=Z$(),H=d0(X),Q=c$(X);if(B(Z,{abilities:k$.map((z)=>({key:z.key,label:z.label,mandatory:z.mandatory,enabled:z.mandatory||H.has(z.key)})),providers:Q}))return;if(T("Capabilities"),n(k$.map((z)=>({Key:z.key,Capability:z.label,Status:z.mandatory?"required":H.has(z.key)?"enabled":"disabled",Description:z.description}))),Q.length>0){J(),T("Extra providers");for(let z of Q)I("\u2022",z)}J(),W("Enable: vibe capability enable <key...> [--provider <pkg...>]"),W("Disable: vibe capability disable <key...>"),W("Re-run the interactive selector: vibe capability select")}),q.command("enable").description("Enable capabilities (installs their meta plugin) and/or extra providers").argument("[keys...]","Ability keys (e.g. gitops security)").option("--provider <pkg...>","Extra provider plugin(s) to install (short name or @vibecontrols/...)").option("--json","Emit JSON").action(async($,Z)=>{try{let X={...Y.opts(),...Z},H=Z$(),Q=new Set(k$.map((x)=>x.key)),z=($??[]).map((x)=>x.trim().toLowerCase()).filter((x)=>Q.has(x));for(let x of($??[]).filter((M)=>!Q.has(M.trim().toLowerCase())))j(`Unknown capability "${x}" \u2014 see \`vibe capability list\`.`);let _=(Array.isArray(Z.provider)?Z.provider:Z.provider?[Z.provider]:[]).map((x)=>g2(x)).filter((x)=>Boolean(x));if(z.length===0&&_.length===0){L("Provide at least one capability key or --provider <pkg>.");return}let O=d0(H);for(let x of z)O.add(x);let F=[...new Set([...m0(z),..._])],D=await g0(),R=[];for(let x of F)try{await D.install(x),R.push({package:x,ok:!0})}catch(M){R.push({package:x,ok:!1,error:C(M)})}let G=[...new Set([...c$(H),..._])];if(D$(H,{abilities:O,providers:G}),B(X,{ok:!0,action:"enable",abilities:[...O],providers:G,installed:R}))return;for(let x of R)if(x.ok)U(`Installed ${x.package}`);else j(`Failed to install ${x.package}: ${x.error}`);U("Capabilities updated. Restart the agent to load: vibe restart")}catch(X){L(C(X))}}),q.command("disable").description("Disable capabilities (removes their meta plugin)").argument("<keys...>","Ability keys").option("--json","Emit JSON").action(async($,Z)=>{try{let X={...Y.opts(),...Z},H=Z$(),Q=new Set(k$.map((R)=>R.key)),z=new Set(k$.filter((R)=>R.mandatory).map((R)=>R.key)),V=($??[]).map((R)=>R.trim().toLowerCase()).filter((R)=>Q.has(R));for(let R of V.filter((G)=>z.has(G)))j(`"${R}" is required and cannot be disabled.`);let _=V.filter((R)=>!z.has(R));if(_.length===0){L("Nothing to disable.");return}let O=d0(H);for(let R of _)O.delete(R);let F=await g0(),D=[];for(let R of m0(_))try{await F.remove(R),D.push({package:R,ok:!0})}catch(G){D.push({package:R,ok:!1,error:C(G)})}if(D$(H,{abilities:O}),B(X,{ok:!0,action:"disable",abilities:[...O],removed:D}))return;for(let R of D)if(R.ok)U(`Removed ${R.package}`);else j(`Failed to remove ${R.package}: ${R.error}`);U("Capabilities updated. Restart the agent to apply: vibe restart")}catch(X){L(C(X))}}),q.command("select").description("Re-run the interactive capability selector and apply it").option("--json","Emit JSON").action(async($)=>{try{let Z={...Y.opts(),...$},X=Z$(),H=await e$(),Q=await g0();for(let z of m0(H))try{await Q.install(z)}catch{}if(D$(X,{abilities:H}),B(Z,{ok:!0,action:"select",abilities:[...H]}))return;U(`Selection saved (${[...H].join(", ")||"none"}). Restart to apply: vibe restart`)}catch(Z){L(C(Z))}})}function _q(Y){Y1(Y),q1(Y),Z1(Y),W1(Y),K1(Y),L1(Y),J1(Y),C1(Y),A1(Y),h1(Y),b1(Y),m1(Y),l1(Y),Y2(Y),H2(Y),Q2(Y),V2(Y),O2(Y),C2(Y),D2(Y),x2(Y),A2(Y),v2(Y),y2(Y),f2(Y),k2(Y),u2(Y),d2(Y),m2(Y),l2(Y)}
230
+ `)}));await r({title:`${$} \u2014 ${H.length} session(s)`,rows:Q})},json:(H)=>y3(H)})}function d2(Y){let q=Y.command("session").description("Manage terminal sessions");q.command("system").description("List system sessions (alias for `session list --system`)").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").option("--plain","Force plain text output").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z));await c2(X,`/api/profiles/${H}/sessions/system`,"System Sessions","No system sessions found.",Z)}catch(X){L(C(X))}}),q.command("list").description("List all sessions").option("--system","Show system sessions instead of user sessions").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").option("--plain","Force plain text output").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z)),Q=$.system?`/api/profiles/${H}/sessions/system`:`/api/profiles/${H}/sessions`;await c2(X,Q,"Sessions","No sessions found.",Z)}catch(X){L(C(X))}}),q.command("create").description("Create a new session").requiredOption("--name <name>","Session name").option("--project <id>","Project ID","default").option("--command <cmd>","Initial command to run").option("--cwd <dir>","Working directory").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z)),Q={sessionName:$.name,projectId:$.project};if($.command)Q.command=$.command;if($.cwd)Q.startDirectory=$.cwd;let z=await m(X,`/api/profiles/${H}/sessions/create`,Q),V=z?.session?.id||z?.id||z?.sessionId;if(B(Z,{ok:!0,id:V,name:$.name,project:$.project}))return;U(`Session created: ${W$(V)}`),I("Name",$.name),I("Project",$.project)}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(C(X))}}),q.command("kill").description("Kill a session").requiredOption("-i, --id <id>","Session ID").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z));if(await P$(X,`/api/profiles/${H}/sessions/${$.id}`),B(Z,{ok:!0,id:$.id}))return;U(`Session ${W$($.id)} killed.`)}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(C(X))}}),q.command("exec").description("Execute a command in a session").requiredOption("-i, --id <id>","Session ID").requiredOption("-c, --command <cmd>","Command to execute").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z)),Q=await m(X,`/api/profiles/${H}/sessions/${$.id}/command`,{command:$.command});if(B(Z,{ok:!0,id:$.id,output:Q?.output??null}))return;if(U("Command executed."),Q?.output)J(),console.log(Q.output)}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(C(X))}}),q.command("capture").description("Capture session terminal output").requiredOption("-i, --id <id>","Session ID").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").option("--plain","Force plain text output").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z));await P({mode:f(Z),fetchData:()=>y(X,`/api/profiles/${H}/sessions/${$.id}/capture`),plain:(Q)=>{if(Q?.content||Q?.output)console.log(Q.content||Q.output);else W("No capture data available.")},json:(Q)=>({id:$.id,content:Q?.content??Q?.output??null})})}catch(X){L(C(X))}}),q.command("keys").description("Send keys to a session").requiredOption("-i, --id <id>","Session ID").requiredOption("-k, --keys <keys>","Keys to send").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z));if(await m(X,`/api/profiles/${H}/sessions/${$.id}/keys`,{keys:$.keys}),B(Z,{ok:!0,id:$.id}))return;U("Keys sent.")}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(C(X))}}),q.command("interrupt").description("Send interrupt signal to a session").requiredOption("-i, --id <id>","Session ID").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z));if(await m(X,`/api/profiles/${H}/sessions/${$.id}/interrupt`,{}),B(Z,{ok:!0,id:$.id}))return;U(`Session ${W$($.id)} interrupted.`)}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(C(X))}}),q.command("rename").description("Rename a session").requiredOption("-i, --id <id>","Session ID").requiredOption("--name <name>","New session name").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z));if(await L0(X,`/api/profiles/${H}/sessions/${$.id}/rename`,{newName:$.name}),B(Z,{ok:!0,id:$.id,name:$.name}))return;U(`Session ${W$($.id)} renamed to "${$.name}".`)}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(C(X))}}),q.command("toggle-mouse").description("Toggle mouse support in a session").requiredOption("-i, --id <id>","Session ID").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z)),Q=await m(X,`/api/profiles/${H}/sessions/${$.id}/toggle-mouse`,{});if(B(Z,{ok:!0,id:$.id,mouseEnabled:!!Q?.mouseEnabled}))return;U(`Mouse support ${Q?.mouseEnabled?"enabled":"toggled"} for session ${W$($.id)}.`)}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(C(X))}}),q.command("terminal-start").description("Start terminal for a session").requiredOption("-i, --id <id>","Session ID").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z)),Q=await m(X,`/api/profiles/${H}/sessions/${$.id}/terminal`,{});if(B(Z,{ok:!0,id:$.id,port:Q?.port??null}))return;if(U(`Terminal started for session ${W$($.id)}.`),Q?.port)I("Port",Q.port)}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(C(X))}}),q.command("terminal-stop").description("Stop terminal for a session").requiredOption("-i, --id <id>","Session ID").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z));if(await m(X,`/api/profiles/${H}/sessions/${$.id}/terminal/stop`,{}),B(Z,{ok:!0,id:$.id}))return;U(`Terminal stopped for session ${W$($.id)}.`)}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(C(X))}}),q.command("health-check").description("Run health check on all sessions").option("--agent-url <url>","Agent URL",t).option("--json","Emit JSON").action(async function($){let Z={...Y.opts(),...$};try{let X=w($),H=encodeURIComponent(A(Z)),Q=await y(X,`/api/profiles/${H}/sessions`),z=await m(X,`/api/profiles/${H}/sessions/health-check`,{sessionIds:(Q.sessions||[]).map((V)=>V.id)});if(B(Z,{ok:!0,healthy:z?.healthy??null,checked:z?.checked??null,fixed:z?.fixed??null}))return;if(U("Health check completed."),z?.healthy!==void 0)I("Healthy",z.healthy);if(z?.checked!==void 0)I("Checked",z.checked);if(z?.fixed!==void 0)I("Fixed",z.fixed)}catch(X){if(Z.json){B(Z,{ok:!1,error:C(X)});return}L(C(X))}})}function m2(Y){Y.command("reuse-db").description("Point this agent at an EXISTING database (reuse data from another same-workspace agent)").option("--adapter <name>","Storage adapter to use (e.g. postgres, skalex). Defaults to the configured/default adapter.").option("--connection-string <conn>","Connection string for the adapter (e.g. postgres://user:pass@host/db)").option("--storage-options <json>","Raw adapter options as a JSON object (alternative/in addition to --connection-string)").option("--db-path <path>","Data directory the adapter should use (e.g. an existing Skalex agent-db dir)").option("-y, --yes","Skip the confirmation prompt").option("--json","Emit JSON").action(async function(q){let $={...Y.opts(),...q};try{let Z={};if(q.storageOptions){let Q;try{Q=JSON.parse(q.storageOptions)}catch{L("--storage-options must be valid JSON.");return}if(!Q||typeof Q!=="object"||Array.isArray(Q)){L("--storage-options must be a JSON object.");return}for(let[z,V]of Object.entries(Q))Z[z]=typeof V==="string"?V:JSON.stringify(V)}if(q.connectionString)Z.connectionString=String(q.connectionString);if(!q.adapter&&!q.dbPath&&Object.keys(Z).length===0){L("Nothing to set. Provide --adapter with --connection-string (or --storage-options), and/or --db-path.");return}if(!$.json){if(T("Reuse an existing database"),q.adapter)I("Adapter",K.bold(q.adapter));if(q.dbPath)I("Data path",K.bold(q.dbPath));if(Object.keys(Z).length>0)I("Options",K.dim(Object.keys(Z).join(", ")));J(),j(`${E.warning} Reuse is safe ONLY for a database from the SAME workspace \u2014 the encryption key is per-workspace, so a foreign DB won't decrypt (the agent will go degraded).`),j(`${E.warning} Two agents writing the same database concurrently can corrupt it. Keep this a single-writer setup unless your adapter is explicitly configured for shared writes.`),J()}if(!q.yes&&!$.json){if(!await T$(K.bold("Write this storage configuration to the agent config?"))){W("Cancelled.");return}}let X={};if(q.adapter)X.storageAdapter=String(q.adapter);if(Object.keys(Z).length>0)X.storageOptions=Z;if(q.dbPath)X.dbPath=String(q.dbPath);U$(X);let H=Y$();if(B($,{ok:!0,storageAdapter:H.storageAdapter??null,dbPath:H.dbPath??null,storageOptionKeys:Object.keys(H.storageOptions??{})}))return;U(`${E.success} Storage configuration written. Run ${K.bold("vibe restart")} so the agent connects to the existing database.`)}catch(Z){let X=Z instanceof Error?C(Z):String(Z);if($.json){B($,{ok:!1,error:X});return}L(`reuse-db failed: ${X}`)}})}function d0(Y){return new Set([...r$(Y)??$0()])}function m0(Y){return o$(process.platform,new Set(Y)).map((q)=>q.packageName)}async function g0(){let{PluginManager:Y}=await import("./plugin-system-8hby8x1m.js"),q=new Y;return{install:($)=>q.install($),remove:($)=>q.remove($)}}function l2(Y){let q=Y.command("capability").alias("cap").description("Select agent capabilities (abilities) + providers");q.command("list",{isDefault:!0}).description("List capabilities and whether each is enabled").option("--json","Emit JSON").action(($)=>{let Z={...Y.opts(),...$},X=Z$(),H=d0(X),Q=c$(X);if(B(Z,{abilities:k$.map((z)=>({key:z.key,label:z.label,mandatory:z.mandatory,enabled:z.mandatory||H.has(z.key)})),providers:Q}))return;if(T("Capabilities"),n(k$.map((z)=>({Key:z.key,Capability:z.label,Status:z.mandatory?"required":H.has(z.key)?"enabled":"disabled",Description:z.description}))),Q.length>0){J(),T("Extra providers");for(let z of Q)I("\u2022",z)}J(),W("Enable: vibe capability enable <key...> [--provider <pkg...>]"),W("Disable: vibe capability disable <key...>"),W("Re-run the interactive selector: vibe capability select")}),q.command("enable").description("Enable capabilities (installs their meta plugin) and/or extra providers").argument("[keys...]","Ability keys (e.g. gitops security)").option("--provider <pkg...>","Extra provider plugin(s) to install (short name or @vibecontrols/...)").option("--json","Emit JSON").action(async($,Z)=>{try{let X={...Y.opts(),...Z},H=Z$(),Q=new Set(k$.map((x)=>x.key)),z=($??[]).map((x)=>x.trim().toLowerCase()).filter((x)=>Q.has(x));for(let x of($??[]).filter((M)=>!Q.has(M.trim().toLowerCase())))j(`Unknown capability "${x}" \u2014 see \`vibe capability list\`.`);let _=(Array.isArray(Z.provider)?Z.provider:Z.provider?[Z.provider]:[]).map((x)=>g2(x)).filter((x)=>Boolean(x));if(z.length===0&&_.length===0){L("Provide at least one capability key or --provider <pkg>.");return}let O=d0(H);for(let x of z)O.add(x);let F=[...new Set([...m0(z),..._])],D=await g0(),R=[];for(let x of F)try{await D.install(x),R.push({package:x,ok:!0})}catch(M){R.push({package:x,ok:!1,error:C(M)})}let G=[...new Set([...c$(H),..._])];if(D$(H,{abilities:O,providers:G}),B(X,{ok:!0,action:"enable",abilities:[...O],providers:G,installed:R}))return;for(let x of R)if(x.ok)U(`Installed ${x.package}`);else j(`Failed to install ${x.package}: ${x.error}`);U("Capabilities updated. Restart the agent to load: vibe restart")}catch(X){L(C(X))}}),q.command("disable").description("Disable capabilities (removes their meta plugin)").argument("<keys...>","Ability keys").option("--json","Emit JSON").action(async($,Z)=>{try{let X={...Y.opts(),...Z},H=Z$(),Q=new Set(k$.map((R)=>R.key)),z=new Set(k$.filter((R)=>R.mandatory).map((R)=>R.key)),V=($??[]).map((R)=>R.trim().toLowerCase()).filter((R)=>Q.has(R));for(let R of V.filter((G)=>z.has(G)))j(`"${R}" is required and cannot be disabled.`);let _=V.filter((R)=>!z.has(R));if(_.length===0){L("Nothing to disable.");return}let O=d0(H);for(let R of _)O.delete(R);let F=await g0(),D=[];for(let R of m0(_))try{await F.remove(R),D.push({package:R,ok:!0})}catch(G){D.push({package:R,ok:!1,error:C(G)})}if(D$(H,{abilities:O}),B(X,{ok:!0,action:"disable",abilities:[...O],removed:D}))return;for(let R of D)if(R.ok)U(`Removed ${R.package}`);else j(`Failed to remove ${R.package}: ${R.error}`);U("Capabilities updated. Restart the agent to apply: vibe restart")}catch(X){L(C(X))}}),q.command("select").description("Re-run the interactive capability selector and apply it").option("--json","Emit JSON").action(async($)=>{try{let Z={...Y.opts(),...$},X=Z$(),H=await e$(),Q=await g0();for(let z of m0(H))try{await Q.install(z)}catch{}if(D$(X,{abilities:H}),B(Z,{ok:!0,action:"select",abilities:[...H]}))return;U(`Selection saved (${[...H].join(", ")||"none"}). Restart to apply: vibe restart`)}catch(Z){L(C(Z))}})}function _q(Y){Y1(Y),q1(Y),Z1(Y),W1(Y),K1(Y),L1(Y),J1(Y),C1(Y),A1(Y),h1(Y),b1(Y),m1(Y),l1(Y),Y2(Y),H2(Y),Q2(Y),V2(Y),O2(Y),C2(Y),D2(Y),x2(Y),A2(Y),v2(Y),y2(Y),f2(Y),k2(Y),u2(Y),d2(Y),m2(Y),l2(Y)}
231
231
  export{M3 as I,_q as J};
@@ -0,0 +1,11 @@
1
+ // @bun
2
+ import{h as y,i as c}from"./index-cs78wq6y.js";import{A as p$,B as i$,y as l$}from"./index-9f52em7g.js";import{N as j$}from"./index-b5dhmybd.js";import{O as H$,P as K$}from"./index-e1bw1bwr.js";import{va as g}from"./index-n6bdbgb9.js";import"./index-wccxsz72.js";import{Ca as k$}from"./index-4wgjx8bf.js";import"./index-jdh30t6c.js";import"./index-0ckffygp.js";import{ab as v}from"./index-rc79x8fw.js";import{db as Y$}from"./index-52cp759f.js";import"./index-hvjqgb97.js";import{Jb as C$,Kb as D$,tb as X$,vb as L$}from"./index-rqq0k5fc.js";import"./index-5dysvvjv.js";import{Ub as F,Vb as p}from"./index-pgew6sge.js";import{Xb as g$}from"./index-rzpaqrhx.js";import"./index-8sdrhr3q.js";import{jc as x,kc as _,lc as c$}from"./index-8nqp3a4d.js";import{Ac as s,Bc as N,Cc as u,oc as V,pc as Z,qc as Y,rc as H,sc as A,uc as z,vc as X,wc as J,xc as Q,yc as h$,zc as k}from"./index-1mppacnx.js";import{Hc as K}from"./index-thammzct.js";import{Lc as T,Nc as b,Oc as M,Pc as y$}from"./index-b6x6a4xp.js";import{qd as T$}from"./index-h74va4wd.js";import{Id as z$,Ld as q$,Od as q}from"./index-js1xn4sq.js";import{$d as $$,Yd as J$,_d as a,ae as U$}from"./index-a4854mwz.js";import"./index-4qq083yd.js";import{ie as d}from"./index-c7554sg7.js";function t(f){let{name:W,onInit:w,onShutdown:U,onNuke:R,telemetryEventName:$,skipPlatforms:G}=f;return{onServerStart:async(I,O)=>{if(G&&G.includes(process.platform)){process.stderr.write(`[${W}] skipping init on unsupported platform '${process.platform}'
3
+ `);return}if(w)await w(O);if($)O.telemetry?.emit($,{plugin:W})},onServerStop:async(I)=>{if(U)await U(I)},onNuke:async(I,O)=>{if(R)return R(I,O)}}}var e=class{constructor(f,W){this.logger=f,this.source=W}logger;source;info(f,W){this.logger?.info?.(this.source,f,W)}warn(f,W){this.logger?.warn?.(this.source,f,W)}error(f,W){this.logger?.error?.(this.source,f,W)}debug(f,W){this.logger?.debug?.(this.source,f,W)}};import{existsSync as t$,rmSync as e$,statSync as a$}from"fs";import{resolve as $U}from"path";function R$(f=$$()){let W=[],w=$U(f),U=U$();if(!a(U,w))throw Error("Refusing to reset a path outside the agents directory");if(t$(w)&&a$(w).isDirectory())e$(w,{recursive:!0,force:!0}),W.push(w);return{removed:W,agentDir:w}}var S="alias",G$=/^[a-zA-Z0-9_-]{1,64}$/,w$=16384,f$=256,W$=1024,UU=new Set(["help","start","stop","restart","kill","list","status","setup","update","completion","autostart","export","import","diagnostics","nuke","doctor","log-level","gc","deploy","network","profile","peer-bootstrap","gateway-auth","info","key","system","url","health","notify","tunnel","session","git","config","log","plugin","ai","audit","alias","run"]);class D extends Error{code;constructor(f,W){super(W);this.code=f,this.name="AliasValidationError"}}class E extends Error{constructor(f){super(`alias '${f}' already exists`);this.name="AliasConflictError"}}class P extends Error{constructor(f){super(`alias '${f}' not found`);this.name="AliasNotFoundError"}}function RU(f){if(typeof f!=="string"||!G$.test(f))throw new D("invalid_name",`alias name must match ${G$} (got '${f}')`);if(UU.has(f))throw new D("reserved_name",`alias name '${f}' is reserved`)}function I$(f){if(typeof f!=="string"||f.length===0)throw new D("invalid_command","alias command must be a non-empty string");if(f.length>w$)throw new D("command_too_long",`alias command exceeds ${w$} bytes`)}function O$(f){if(f===void 0)return;if(typeof f!=="string")throw new D("invalid_description","alias description must be a string");if(f.length>f$)throw new D("description_too_long",`alias description exceeds ${f$} chars`)}function F$(f){if(f===void 0||f===null||f==="")return;if(typeof f!=="string")throw new D("invalid_cwd","alias cwd must be a string");if(f.length>W$)throw new D("cwd_too_long",`alias cwd exceeds ${W$} chars`);if(f.includes("\x00"))throw new D("invalid_cwd","alias cwd must not contain NUL bytes")}function GU(f){if(!f)return;try{return JSON.parse(f)}catch{return}}async function i(f){let W=await f.getAllPluginState(S),w=[];for(let U of W){let R=GU(U.value);if(R)w.push(R)}return w.sort((U,R)=>U.name.localeCompare(R.name)),w}async function n(f,W){return(await i(f)).find((U)=>U.name===W)}function V$(f){if(f===void 0||f===null)return null;let W=f.trim();return W===""?null:W}async function Q$(f,W){if(RU(W.name),I$(W.command),O$(W.description),F$(W.cwd),await n(f,W.name))throw new E(W.name);let U=new Date().toISOString(),R={id:crypto.randomUUID(),name:W.name,command:W.command,description:W.description,cwd:V$(W.cwd),profile:J$(),createdAt:U,updatedAt:U};return await f.setPluginState(S,R.id,JSON.stringify(R)),R}async function Z$(f,W,w){let U=await n(f,W);if(!U)throw new P(W);if(w.command!==void 0)I$(w.command);if(w.description!==void 0)O$(w.description);if(w.cwd!==void 0)F$(w.cwd);let R={...U,command:w.command??U.command,description:w.description!==void 0?w.description:U.description,cwd:w.cwd!==void 0?V$(w.cwd):U.cwd,updatedAt:new Date().toISOString()};return await f.setPluginState(S,R.id,JSON.stringify(R)),R}async function B$(f,W){let w=await n(f,W);if(!w)throw new P(W);await f.deletePluginState(S,w.id)}function m(){let f=q$()??q();return{dir:f.dataDir,scope:f.name}}function M$(f){let{serviceRegistry:W,db:w}=f;return new p().get("/api-key",()=>({apiKey:C$()})).post("/reset-key",async({body:U,set:R})=>{let $=U.apiKey;if(!$||typeof $!=="string")return R.status=400,{error:"Missing required field: apiKey"};try{return await D$($),await q().keyVault.bindApiKey($),q().logger.info("auth","Adopted backend-rotated agent API key via /reset-key"),{success:!0}}catch(G){return R.status=400,{error:"reset-key failed",message:G instanceof Error?G.message:String(G)}}},{body:F.Object({apiKey:F.String()})}).get("/audit",({query:U})=>{let R=U,$=R.limit?Math.min(5000,Math.max(1,Number.parseInt(R.limit,10)||100)):100,G=q().audit.listEvents({since:R.since,limit:$,event:R.event});return{events:G,count:G.length}},{query:F.Object({since:F.Optional(F.String()),limit:F.Optional(F.String()),event:F.Optional(F.String())})}).get("/setup/check",()=>{let U=H$();return{ready:U.filter(($)=>$.required).every(($)=>$.installed),dependencies:U}}).post("/setup/install",async({request:U,server:R,set:$})=>{let G=await c(U,"VIBECONTROLS_ALLOW_REMOTE_SETUP_INSTALL",R);if(G)return $.status=403,{error:"Forbidden",message:G};return await K$()}).get("/url",async()=>{let U=W.getProvider("tunnel"),R=U&&U.getActiveTunnelUrl?await U.getActiveTunnelUrl():null,$=`http://localhost:${process.env.PORT||3005}`;return{url:R||$,tunnelUrl:R,localUrl:$,source:R?"tunnel":"local"}}).get("/lifecycle/state",()=>{return{state:W.getService("agent","lifecycle")?.getState()??"running"}}).post("/lifecycle/stop",async({set:U})=>{let R=W.getService("agent","lifecycle");if(!R)return U.status=500,{error:"Lifecycle manager not initialized"};return await R.stop(),{state:"stopped"}}).post("/lifecycle/start",async({set:U})=>{let R=W.getService("agent","lifecycle");if(!R)return U.status=500,{error:"Lifecycle manager not initialized"};return await R.start(),{state:"running"}}).post("/lifecycle/kill",async({set:U})=>{let R=W.getService("agent","lifecycle");if(!R)return U.status=500,{error:"Lifecycle manager not initialized"};return setTimeout(()=>R.kill(),100),{state:"killing"}}).post("/log-level",async({body:U,request:R,server:$,set:G})=>{let I=await c(R,"VIBECONTROLS_ALLOW_REMOTE_LOG_LEVEL",$);if(I)return G.status=403,{error:"Forbidden",message:I};let O=String(U.level??"").toLowerCase();if(!["debug","info","warn","error"].includes(O))return G.status=400,{error:"Invalid level",message:"level must be debug | info | warn | error"};return q().logger.setLevel(O),q().logger.info("agent",`Log level set to ${O} via API`),{ok:!0,level:O}},{body:F.Object({level:F.String()})}).post("/reset",async({body:U,request:R,server:$,set:G})=>{if(!U.confirm)return G.status=400,{error:"Reset confirmation required",message:"Send { confirm: true } to reset local agent state."};let I=await c(R,"VIBECONTROLS_ALLOW_REMOTE_RESET",$);if(I)return G.status=403,{error:"Forbidden",message:I};let O=W.getService("agent","lifecycle");try{if(O)await O.prepareForReset()}catch(h){q().logger.warn("agent","prepareForReset failed during reset \u2014 proceeding to wipe anyway",{error:String(h)})}try{z$.configure({globalGatewayUrl:"",workspaceGatewayUrl:void 0,clientId:"",clientSecret:"",workspaceId:void 0})}catch{}await w.close();let{removed:B,agentDir:L}=R$();q().logger.info("agent","Reset wiped local agent state",{agentDir:L,removed:B});let C=new Uint8Array(32);crypto.getRandomValues(C);let j=`vcak_${Buffer.from(C).toString("base64url")}`;return T$({"static-api-key":j},m()),q().setBootState("awaiting-config"),G.status=200,{success:!0,state:"awaiting-config",...y(R,$)||process.env.VIBECONTROLS_RETURN_RESET_API_KEY==="1"?{newApiKey:j}:{},agentDir:L,removed:B}},{body:F.Object({confirm:F.Boolean()})}).post("/sessions/:sessionId/share",async({params:U,body:R,server:$,request:G,set:I})=>{if(!y(G,$)&&process.env.VIBECONTROLS_ALLOW_REMOTE_SESSION_SHARE!=="1")return I.status=403,{error:"Forbidden",message:"Session-share mint must come from a local request unless VIBECONTROLS_ALLOW_REMOTE_SESSION_SHARE=1."};if(!X$(U.sessionId))return I.status=400,{error:"BadRequest",message:"invalid sessionId"};let O=wU(R?.expiresIn)??1800000,B=crypto.randomUUID(),L=new Uint8Array(32);crypto.getRandomValues(L);let C=`vcak_${Buffer.from(L).toString("base64url")}`,j=new Date(Date.now()+O).toISOString(),r=[...(await import("./agent-config-4ppenhqp.js")).readAgentConfig({dir:m().dir}).apiKeys??[],{id:B,name:`session-share:${U.sessionId}:${R?.label??"viewer"}`,key:C,scopes:["read"],expiresAt:j,createdAt:new Date().toISOString()}];(await import("./agent-config-4ppenhqp.js")).writeAgentConfig({apiKeys:r},m());let h=W.getProvider("tunnel"),d$=(h&&h.getActiveTunnelUrl?await h.getActiveTunnelUrl():null)??`http://localhost:${process.env.PORT||3005}`,s$=L$({pathPrefixes:[`/terminal/${U.sessionId}`],methods:["GET"]},Math.min(600,Math.floor(O/1000))),r$=`${d$.replace(/\/$/,"")}/terminal/${encodeURIComponent(U.sessionId)}/#vt=${encodeURIComponent(s$.token)}`;return q().logger.info("session-share","Minted share credential",{sessionId:U.sessionId,keyId:B,expiresAt:j}),{ok:!0,keyId:B,apiKey:C,joinUrl:r$,sessionId:U.sessionId,expiresAt:j}},{params:F.Object({sessionId:F.String()}),body:F.Optional(F.Object({permissions:F.Optional(F.Array(F.String())),expiresIn:F.Optional(F.String()),label:F.Optional(F.String())}))}).get("/aliases",async()=>{return{aliases:await i(w)}}).get("/aliases/:name",async({params:U,set:R})=>{let $=await n(w,U.name);if(!$)return R.status=404,{error:"Alias not found"};return $},{params:F.Object({name:F.String()})}).post("/aliases",async({body:U,set:R})=>{try{let $=await Q$(w,U);return R.status=201,$}catch($){if($ instanceof E)return R.status=409,{error:"Alias already exists",message:$.message};if($ instanceof D)return R.status=400,{error:$.code,message:$.message};throw $}},{body:F.Object({name:F.String(),command:F.String(),description:F.Optional(F.String()),cwd:F.Optional(F.Union([F.String(),F.Null()]))})}).put("/aliases/:name",async({params:U,body:R,set:$})=>{try{return await Z$(w,U.name,R)}catch(G){if(G instanceof P)return $.status=404,{error:"Alias not found"};if(G instanceof D)return $.status=400,{error:G.code,message:G.message};throw G}},{params:F.Object({name:F.String()}),body:F.Object({command:F.Optional(F.String()),description:F.Optional(F.String()),cwd:F.Optional(F.Union([F.String(),F.Null()]))})}).delete("/aliases/:name",async({params:U,set:R})=>{try{return await B$(w,U.name),R.status=204,null}catch($){if($ instanceof P)return R.status=404,{error:"Alias not found"};throw $}},{params:F.Object({name:F.String()})}).post("/aliases/:name/execute",async({params:U,body:R,set:$})=>{let G=await n(w,U.name);if(!G)return $.status=404,{error:"Alias not found"};let I=R?.args??[],O=await j$(G,I);q().audit.emit("agent","alias.executed",{exit_code:O.exit_code});let B=Y$("alias.executed",{exit_code:O.exit_code});if(!B.ok)q().logger.debug("alias",`telemetry validate failed: ${B.reason}`);if(O.timed_out)$.status=408;return{exit_code:O.exit_code,stdout:O.stdout,stderr:O.stderr,duration_ms:O.duration_ms,truncated:O.truncated,cwd:O.cwd}},{params:F.Object({name:F.String()}),body:F.Optional(F.Object({args:F.Optional(F.Array(F.String()))}))}).post("/sessions/share/:keyId/revoke",async({params:U,server:R,request:$,set:G})=>{if(!y($,R)&&process.env.VIBECONTROLS_ALLOW_REMOTE_SESSION_SHARE!=="1")return G.status=403,{error:"Forbidden"};let I=await import("./agent-config-4ppenhqp.js"),O=m(),B=I.readAgentConfig({dir:O.dir}),L=(B.apiKeys??[]).length,C=(B.apiKeys??[]).filter((j)=>j.id!==U.keyId);if(C.length===L)return G.status=404,{error:"No such share key"};return I.writeAgentConfig({apiKeys:C},O),{ok:!0,revoked:U.keyId}},{params:F.Object({keyId:F.String()})})}function wU(f){if(!f)return null;let W=/^(\d+)([smhdw]?)$/.exec(f.trim());if(!W)return null;let w=Number(W[1]),U=W[2]||"m";return U==="s"?w*1000:U==="m"?w*60000:U==="h"?w*3600000:U==="d"?w*86400000:w*7*86400000}var fU="http://localhost:3005";function x$(f){f.command("health").description("Check health of a VibeControls agent instance").option("-n, --name <name>","Agent instance name").option("--agent-url <url>","Agent URL",fU).option("--json","Emit JSON").option("--plain","Force plain text output").action(async function(W){try{let w={...f.opts(),...W};await _({mode:x(w),fetchData:async()=>{if(w.name){let $=await new g().checkHealth(w.name);return{mode:"named",agentUrl:T(w),name:w.name,healthy:$.healthy,details:$.details??{}}}let U=T(w);try{let R=await M(U,"/health");return{mode:"url",agentUrl:U,healthy:!0,details:R}}catch(R){return{mode:"url",agentUrl:U,healthy:!1,details:{status:"unhealthy",...R instanceof Error?{error:H(R)}:{}}}}},plain:(U)=>{if(X("Agent Health"),Q(),U.mode==="named"){if(!U.healthy){Y(`Agent instance ${V.bold(U.name??"")} is not responding.`);return}let R=U.details;if(J("Instance",U.name??""),J("Status",u(R.status??"healthy")),R.uptime!==void 0)J("Uptime",`${R.uptime}s`);if(R.checks){Q(),z(`${Z.info} Health checks:`);for(let[$,G]of Object.entries(R.checks)){let I=G.status==="healthy"?Z.success:Z.error;J(` ${I} ${$}`,u(G.status))}}}else{if(J("URL",U.agentUrl),J("Status",u(U.details.status??"unhealthy")),U.details.version)J("Version",U.details.version);if(U.details.uptime!==void 0)J("Uptime",`${U.details.uptime}s`);if(U.details.timestamp)J("Timestamp",U.details.timestamp);if(U.details.checks){Q(),z(`${Z.info} Health checks:`);for(let[R,$]of Object.entries(U.details.checks)){let G=$.status==="healthy"?Z.success:Z.error;J(` ${G} ${R}`,u($.status))}}}if(Q(),U.healthy)A(`${Z.success} Agent is healthy.`)},interactive:async(U)=>{let R=[];if(U.mode==="named")R.push(`Instance: ${U.name??""}`);else R.push(`URL: ${U.agentUrl}`);if(R.push(`Status: ${u(U.details.status??(U.healthy?"healthy":"unhealthy"))}`),U.details.version)R.push(`Version: ${U.details.version}`);if(U.details.uptime!==void 0)R.push(`Uptime: ${U.details.uptime}s`);if(U.details.timestamp)R.push(`Time: ${U.details.timestamp}`);if(U.details.checks){R.push(""),R.push("Checks:");for(let[$,G]of Object.entries(U.details.checks))R.push(` ${$}: ${G.status}`)}await K({title:"Agent Health",body:R.join(`
4
+ `),footer:"press q to exit"})},json:(U)=>({mode:U.mode,agentUrl:U.agentUrl,name:U.name??null,healthy:U.healthy,details:U.details})})}catch(w){Y(`Health check failed: ${H(w)}`)}})}import{platform as WU,arch as JU,release as IU,hostname as OU,cpus as FU,totalmem as VU}from"os";var QU="http://localhost:3005";function _$(f){f.command("info").description("Show local and remote VibeControls agent information").option("--agent-url <url>","Agent URL",QU).option("--json","Emit JSON").option("--plain","Force plain text output").action(async function(W){try{let w={...f.opts(),...W},U=T(w),R=encodeURIComponent(b(w));await _({mode:x(w),fetchData:async()=>{let $={hostname:OU(),platform:WU(),arch:JU(),release:IU(),cpus:FU().length,totalMemory:VU(),nodeVersion:process.version,bunVersion:process.versions.bun};try{let G=await M(U,`/api/profiles/${R}/agent/version`);return{local:$,agentUrl:U,remote:G}}catch(G){return{local:$,agentUrl:U,remote:null,remoteError:G instanceof Error?H(G):String(G)}}},plain:($)=>{if(X("VibeControls Agent Info"),Q(),z(`${Z.info} Local System`),J("Hostname",$.local.hostname),J("Platform",`${$.local.platform} ${$.local.arch}`),J("OS Release",$.local.release),J("CPUs",String($.local.cpus)),J("Total Memory",N($.local.totalMemory)),J("Node.js",$.local.nodeVersion),$.local.bunVersion)J("Bun",$.local.bunVersion);if(Q(),z(`${Z.info} Remote Agent`),J("URL",$.agentUrl),$.remote){if(J("Version",V.bold($.remote.version)),$.remote.build)J("Build",$.remote.build);if($.remote.commit)J("Commit",$.remote.commit);if($.remote.nodeVersion)J("Node.js (remote)",$.remote.nodeVersion);if($.remote.bunVersion)J("Bun (remote)",$.remote.bunVersion)}else J("Status",V.dim("not reachable"));Q()},interactive:async($)=>{let G=[];if(G.push("Local System"),G.push(` Hostname: ${$.local.hostname}`),G.push(` Platform: ${$.local.platform} ${$.local.arch}`),G.push(` OS Release: ${$.local.release}`),G.push(` CPUs: ${$.local.cpus}`),G.push(` Total Memory: ${N($.local.totalMemory)}`),G.push(` Node.js: ${$.local.nodeVersion}`),$.local.bunVersion)G.push(` Bun: ${$.local.bunVersion}`);if(G.push(""),G.push("Remote Agent"),G.push(` URL: ${$.agentUrl}`),$.remote){if(G.push(` Version: ${$.remote.version}`),$.remote.build)G.push(` Build: ${$.remote.build}`);if($.remote.commit)G.push(` Commit: ${$.remote.commit}`);if($.remote.nodeVersion)G.push(` Node.js: ${$.remote.nodeVersion} (remote)`);if($.remote.bunVersion)G.push(` Bun: ${$.remote.bunVersion} (remote)`)}else G.push(" Status: not reachable");await K({title:"VibeControls Agent Info",body:G.join(`
5
+ `),footer:"press q to exit"})},json:($)=>({local:$.local,agentUrl:$.agentUrl,remote:$.remote,remoteError:$.remoteError??null})})}catch(w){Y(`Failed to get info: ${H(w)}`)}})}var ZU="http://localhost:3005";function b$(f){f.command("system").description("Show system information for a running VibeControls agent").option("--agent-url <url>","Agent URL",ZU).option("--json","Emit JSON").option("--plain","Force plain text output").action(async function(W){try{let w={...f.opts(),...W},U=T(w),R=encodeURIComponent(b(w));await _({mode:x(w),fetchData:()=>M(U,`/api/profiles/${R}/agent/system`),plain:($)=>{if(X("Agent System Information"),Q(),z(`${Z.info} Agent`),J("Version",V.bold($.agentVersion)),$.bunVersion)J("Bun",$.bunVersion);if($.environment)J("Environment",$.environment);J("Uptime",s($.uptime)),Q(),z(`${Z.info} Platform`),J("OS",`${$.platform} ${$.arch}`),J("Hostname",$.hostname),J("Release",$.release),Q(),z(`${Z.info} Resources`),J("CPUs",String($.cpus)),J("Total Memory",N($.totalMemory)),J("Free Memory",N($.freeMemory)),Q(),z(`${Z.info} Paths`),J("Home",$.homeDir),J("CWD",$.cwd),Q()},interactive:async($)=>{let G=["Agent",` Version: ${$.agentVersion}`,...$.bunVersion?[` Bun: ${$.bunVersion}`]:[],...$.environment?[` Environment: ${$.environment}`]:[],` Uptime: ${s($.uptime)}`,"","Platform",` OS: ${$.platform} ${$.arch}`,` Hostname: ${$.hostname}`,` Release: ${$.release}`,"","Resources",` CPUs: ${$.cpus}`,` Total Mem: ${N($.totalMemory)}`,` Free Mem: ${N($.freeMemory)}`,"","Paths",` Home: ${$.homeDir}`,` CWD: ${$.cwd}`];await K({title:"Agent System Information",body:G.join(`
6
+ `),footer:"press q to exit"})}})}catch(w){Y(`Failed to get system info: ${H(w)}`)}})}var BU="http://localhost:3005";async function u$(f){try{let W=await fetch(`${f}/health/ready`);if(W.status===200||W.status===503)return await W.json();return{healthy:!1,status:W.status}}catch{return{healthy:!1,error:"unreachable"}}}async function N$(f,W){try{let w=await fetch(`${f}/api/profiles/${W}/agent/api-key`);if(!w.ok)return null;return(await w.json()).apiKey??null}catch{return null}}async function zU(f,W){try{return await M(f,`/api/profiles/${W}/plugins`)}catch{return null}}function o(f){let W=f??{};if(W.error==="unreachable")return V.red("unreachable");if(typeof W.status==="number"&&W.status>=400)return V.red(`http ${W.status}`);let w=typeof W.status==="string"?W.status:"",U=typeof W.bootState==="string"?W.bootState:"";if(w==="ok"&&U==="ready")return V.green("ready");if(U==="awaiting-config")return V.yellow("awaiting-config");if(U==="initializing")return V.yellow("initializing");if(U==="degraded"||w==="degraded")return V.red(`degraded${U?` (${U})`:""}`);if(W.healthy===!1)return V.red("unhealthy");return V.green("healthy")}function YU(f){let w=(f??{}).lastFinalizeError;if(!w||typeof w!=="object")return null;let U=w;if(typeof U.message!=="string"||typeof U.at!=="string")return null;return{message:U.message,at:U.at,attempt:typeof U.attempt==="number"?U.attempt:void 0}}function P$(f){let W=f??{},w=typeof W.bootState==="string"?W.bootState:"";if(w!=="awaiting-config"&&w!=="degraded")return null;let U=[],R=YU(f);if(R)if(U.push(`${V.gray("\xB7")} Last error: ${V.red(R.message)}`),R.attempt!==void 0)U.push(`${V.gray("\xB7")} Background retry: attempt ${R.attempt}`);else U.push(`${V.gray("\xB7")} Last seen: ${R.at}`);if(w==="awaiting-config")U.push(`${V.gray("\xB7")} Force retry now: ${V.bold("vibe retry-config")}`);return U.push(`${V.gray("\xB7")} Full trace: ${V.bold("vibe logs --since 10m")}`),U.join(`
7
+ `)}async function TU(f,W){let w={agentUrl:W},U=f.jsonKey??f.title.toLowerCase(),R;try{R=await f.render(w)}catch(G){R=V.red(`error (${G.message})`)}let $=null;if(f.json)try{$=await f.json(w)}catch{$=null}return{title:f.title,jsonKey:U,text:R,json:$}}async function n$(f){let w=k$().getStatusSections();return Promise.all(w.map((U)=>TU(U,f)))}function S$(f){f.command("status").description("Show comprehensive status of VibeControls agent instance(s)").option("-n, --name <name>","Agent instance name").option("--agent-url <url>","Agent URL",BU).option("--profile <name>","Target a specific profile by name").option("--json","Emit JSON").option("--plain","Force plain text output").action(async function(W){try{let w={...f.opts(),...W},U=new g;await _({mode:x(w),fetchData:async()=>{if(w.name){let I=await U.getStatus(w.name);if(!I)return{kind:"instance",agentUrl:T(w),instance:null,contributed:[]};let O=I.status==="running"&&I.port?`http://localhost:${I.port}`:T(w);if(I.status!=="running")return{kind:"instance",agentUrl:O,instance:I,contributed:[]};let B=encodeURIComponent(b({profile:I.name})),[L,C,j,l]=await Promise.all([u$(O),N$(O,B),zU(O,B),n$(O)]);return{kind:"instance",agentUrl:O,instance:I,health:L,apiKey:C,plugins:j,contributed:l}}let R=await U.listInstances(),$=R.filter((I)=>I.status==="running"),G=await Promise.all($.map(async(I)=>{let O=`http://localhost:${I.port}`,B=encodeURIComponent(b({profile:I.name})),[L,C,j]=await Promise.all([u$(O),N$(O,B),n$(O)]);return{name:I.name,agentUrl:O,health:L,apiKey:C,contributed:j}}));return{kind:"overview",instances:R,perRunning:G}},plain:(R)=>{if(R.kind==="instance"){if(!R.instance){Y(`Agent instance ${V.bold(w.name??"")} not found.`);return}let G=R.instance;if(X(`Agent Status: ${G.name}`),J("Name",G.name),J("Status",u(G.status)),J("PID",G.pid?String(G.pid):V.dim("n/a")),J("Port",G.port?String(G.port):V.dim("n/a")),J("Host",G.config?.host||V.dim("n/a")),J("Database",G.config?.dbPath||V.dim("n/a")),G.startTime)J("Started",k(G.startTime));if(G.status==="running"){Q(),J("Health",o(R.health));let I=P$(R.health);if(I)Q(),console.log(I),Q();let O=R.health?.uptime;if(O)J("Uptime",String(O));if(J("API Key",R.apiKey??V.dim("(unavailable)")),R.plugins){let B=R.plugins.plugins??[],L=B.filter((C)=>C.isCore).length;J("Plugins",`${B.length} total (${L} core, ${B.length-L} external)`)}else J("Plugins",V.dim("(unable to fetch)"));for(let B of R.contributed){if(B.text===null)continue;J(B.title,B.text)}}Q();return}if(X("Agent Instances"),Q(),!R.instances||R.instances.length===0){z(`${Z.info} No agent instances found.`),z(`Run ${V.bold("vibe start")} to start an agent.`);return}let $=R.instances.map((G)=>({Name:G.name,Status:u(G.status),PID:G.pid||"-",Port:G.port||"-",Started:G.startTime?k(G.startTime):"-"}));h$($),Q();for(let G of R.perRunning){Q(),X(`Quick Status: ${G.name}`),J("Health",o(G.health));let I=P$(G.health);if(I)Q(),console.log(I),Q();J("API Key",G.apiKey??V.dim("(unavailable)"));for(let O of G.contributed){if(O.text===null)continue;J(O.title,O.text)}}Q(),z(`${Z.info} ${R.instances.length} instance(s) found. Use ${V.bold("vibe status -n <name>")} for full details.`)},interactive:async(R)=>{let $=[];if(R.kind==="instance"){if(!R.instance)$.push(`Agent instance "${w.name??""}" not found.`);else{let G=R.instance;if($.push(`Name: ${G.name}`),$.push(`Status: ${u(G.status)}`),$.push(`PID: ${G.pid??"n/a"}`),$.push(`Port: ${G.port??"n/a"}`),$.push(`Host: ${G.config?.host??"n/a"}`),$.push(`Database: ${G.config?.dbPath??"n/a"}`),G.startTime)$.push(`Started: ${k(G.startTime)}`);if(G.status==="running"){if($.push(""),$.push(`Health: ${o(R.health)}`),$.push(`API Key: ${R.apiKey??"(unavailable)"}`),R.plugins){let I=R.plugins.plugins??[],O=I.filter((B)=>B.isCore).length;$.push(`Plugins: ${I.length} (${O} core, ${I.length-O} external)`)}for(let I of R.contributed){if(I.text===null)continue;$.push(`${I.title.padEnd(9)} ${I.text}`)}}}await K({title:`vibe status${w.name?` \u2014 ${w.name}`:""}`,body:$.join(`
8
+ `),footer:"press q to exit"});return}if(!R.instances||R.instances.length===0)$.push("No agent instances found."),$.push("Run `vibe start` to start an agent.");else for(let G of R.instances){$.push(`${V.bold(G.name)} ${u(G.status)}`),$.push(` PID: ${G.pid??"-"}`),$.push(` Port: ${G.port??"-"}`),$.push(` Started: ${G.startTime?k(G.startTime):"-"}`);let I=R.perRunning.find((O)=>O.name===G.name);if(I){$.push(` Health: ${o(I.health)}`);for(let O of I.contributed){if(O.text===null)continue;$.push(` ${O.title.padEnd(9)} ${O.text}`)}}$.push("")}await K({title:`vibe status \u2014 ${R.instances.length} instance(s)`,body:$.join(`
9
+ `),footer:"press q to exit"})},json:(R)=>{let $=(G)=>Object.fromEntries(G.map((I)=>[I.jsonKey,I.json]));if(R.kind==="instance"){if(!R.instance)return{instance:null};let G={instance:{name:R.instance.name,status:R.instance.status,pid:R.instance.pid,port:R.instance.port,host:R.instance.config?.host,dbPath:R.instance.config?.dbPath,startTime:R.instance.startTime}};if(R.instance.status==="running")G.health=R.health??null,G.plugins=R.plugins??null,Object.assign(G,$(R.contributed));return G}return{instances:R.instances.map((G)=>({name:G.name,status:G.status,pid:G.pid,port:G.port,startTime:G.startTime})),perRunning:R.perRunning.map((G)=>({name:G.name,health:G.health??null,...$(G.contributed)}))}}})}catch(w){let U=w instanceof Error?H(w):String(w);Y(`Failed to get status: ${U}`)}})}var XU="http://localhost:3005";function E$(f){f.command("url").description("Show the active URL for a running VibeControls agent").option("--agent-url <url>","Agent URL",XU).option("--json","Emit JSON").option("--plain","Force plain text output").action(async(W)=>{try{let w={...f.opts(),...W},U=T(W),R=encodeURIComponent(b(w));await _({mode:x(w),fetchData:()=>M(U,`/api/profiles/${R}/agent/url`),plain:($)=>{if(X("Agent URL"),Q(),J("Active URL",V.bold($.url)),J("Local URL",$.localUrl),$.tunnelUrl)J("Tunnel URL",V.cyan($.tunnelUrl));if(J("Mode",$.isTunnel?`${Z.running} Tunnel active`:`${Z.info} Local only`),Q(),$.isTunnel)z(`${Z.info} Agent is accessible via tunnel at ${V.bold($.tunnelUrl)}`);else z(`${Z.info} Agent is running locally at ${V.bold($.localUrl)}`)},interactive:async($)=>{let G=[` Active URL: ${$.url}`,` Local URL: ${$.localUrl}`,` Tunnel URL: ${$.tunnelUrl??"-"}`,` Mode: ${$.isTunnel?"Tunnel active":"Local only"}`];await K({title:"Agent URL",body:G.join(`
10
+ `)})},json:($)=>v($)})}catch(w){Y(`Failed to get URL: ${w.message}`)}})}var m$="http://localhost:3005";function A$(f){let W=f.command("gateway-auth").description("Manage gateway authentication for VibeControls agent");W.command("configure").description("Configure gateway authentication credentials").requiredOption("--global-url <url>","Global gateway URL").requiredOption("--workspace-url <url>","Workspace gateway URL").requiredOption("--client-id <id>","OAuth client ID").requiredOption("--client-secret <secret>","OAuth client secret").option("--workspace-id <id>","Workspace ID for auto-report").option("--agent-record-id <id>","Existing backend agent record ID").option("--agent-url <url>","Agent URL",m$).option("--json","Emit JSON result").action(async(w)=>{try{let U={...f.opts(),...w},R=T(w),$=encodeURIComponent(b(U)),G=await y$(R,`/api/profiles/${$}/agent/gateway-auth`,{globalGatewayUrl:w.globalUrl,workspaceGatewayUrl:w.workspaceUrl,clientId:w.clientId,clientSecret:w.clientSecret,workspaceId:w.workspaceId,agentRecordId:w.agentRecordId});if(c$(U,{ok:!!G.success,message:G.message??null,globalGatewayUrl:w.globalUrl,workspaceGatewayUrl:w.workspaceUrl,clientId:w.clientId,workspaceId:w.workspaceId??null,agentRecordId:w.agentRecordId??null}))return;if(X("Configure Gateway Authentication"),Q(),z(`${Z.info} Sending gateway auth configuration...`),Q(),G.success){if(A(`${Z.success} Gateway authentication configured successfully.`),Q(),J("Global URL",w.globalUrl),J("Workspace URL",w.workspaceUrl),J("Client ID",w.clientId),J("Client Secret",V.dim("********")),w.workspaceId)J("Workspace ID",w.workspaceId);if(w.agentRecordId)J("Agent Record ID",w.agentRecordId)}else Y(G.message||"Failed to configure gateway authentication.");Q()}catch(U){Y(`Failed to configure gateway auth: ${U instanceof Error?H(U):String(U)}`)}}),W.command("status").description("Check gateway authentication status").option("--agent-url <url>","Agent URL",m$).option("--json","Emit JSON").option("--plain","Force plain text output").action(async(w)=>{try{let U={...f.opts(),...w},R=T(w),$=encodeURIComponent(b(U));await _({mode:x(U),fetchData:()=>M(R,`/api/profiles/${$}/agent/gateway-auth`),plain:(G)=>{if(X("Gateway Authentication Status"),Q(),J("Configured",G.configured?`${Z.success} ${V.green("Yes")}`:`${Z.error} ${V.red("No")}`),G.configured){if(J("Global URL",G.config?.globalGatewayUrl||V.dim("n/a")),J("Workspace URL",G.config?.workspaceGatewayUrl||V.dim("n/a")),J("Client ID",G.config?.clientId||V.dim("n/a")),G.config?.workspaceId)J("Workspace ID",G.config.workspaceId)}else Q(),z(`${Z.info} Run ${V.bold("vibe gateway-auth configure")} to set up gateway authentication.`);Q()},interactive:async(G)=>{let I=G.configured?[" Configured: yes",` Global URL: ${G.config?.globalGatewayUrl??"n/a"}`,` Workspace URL: ${G.config?.workspaceGatewayUrl??"n/a"}`,` Client ID: ${G.config?.clientId??"n/a"}`,` Workspace ID: ${G.config?.workspaceId??"-"}`]:[" Configured: no",""," Run `vibe gateway-auth configure` to set up."];await K({title:"Gateway Authentication Status",body:I.join(`
11
+ `)})},json:(G)=>v(G)})}catch(U){Y(`Failed to get gateway auth status: ${U instanceof Error?H(U):String(U)}`)}})}function o$(f,W){x$(f),_$(f),g$(f),b$(f),S$(f),E$(f),A$(f)}var v$="agent";function CR(f){let W=null,w=t({name:v$,onShutdown:()=>{p$(),l$()}});return{name:v$,version:"2.3.0",description:"Core agent identity, system info, setup, gateway authentication, and auto-report",capabilities:{storage:"rw",secrets:"rw",gateway:!0,broadcast:!0,audit:!0,telemetry:!0},tags:["backend","cli"],cliCommand:"agent",apiPrefix:"/api/agent",publicPaths:["/identity","/tunnel"],createRoutes:(U)=>{return W=U.db,M$(U)},onCliSetup:async(U,R)=>{o$(U,R)},onServerReady:async(U,R)=>{if(W){let $=U,G=(typeof $.decorator?.apiKey==="string"?$.decorator.apiKey:void 0)??(typeof $.store?.apiKey==="string"?$.store.apiKey:void 0)??"unknown",I=new e(R.logger,"agent-plugin");i$(W,R.serviceRegistry,G).catch((O)=>{I.warn(`Auto-report background task failed: ${O}`)})}},onServerStop:()=>w.onServerStop({})}}export{CR as createPlugin};
@@ -1,8 +1,8 @@
1
1
  // @bun
2
- import{he as A}from"./index-yy1mm8zs.js";var j=!process.env.NO_COLOR&&!!process.stdout.isTTY;function L(q){j=q}var C=(q,B)=>(F)=>j?`${q}${F}${B}`:F,z={bold:C("\x1B[1m","\x1B[22m"),dim:C("\x1B[2m","\x1B[22m"),italic:C("\x1B[3m","\x1B[23m"),underline:C("\x1B[4m","\x1B[24m"),red:C("\x1B[31m","\x1B[39m"),green:C("\x1B[32m","\x1B[39m"),yellow:C("\x1B[33m","\x1B[39m"),blue:C("\x1B[34m","\x1B[39m"),magenta:C("\x1B[35m","\x1B[39m"),cyan:C("\x1B[36m","\x1B[39m"),white:C("\x1B[37m","\x1B[39m"),gray:C("\x1B[90m","\x1B[39m"),brightRed:C("\x1B[91m","\x1B[39m"),brightGreen:C("\x1B[92m","\x1B[39m"),brightYellow:C("\x1B[93m","\x1B[39m"),brightBlue:C("\x1B[94m","\x1B[39m"),reset:"\x1B[0m"},Q={get success(){return z.green("\u2713")},get error(){return z.red("\u2717")},get warning(){return z.yellow("\u26A0")},get info(){return z.blue("\u25CF")},get running(){return z.green("\u25CF")},get stopped(){return z.red("\u25CB")},get pending(){return z.yellow("\u25CC")},get arrow(){return z.gray("\u2192")},get bullet(){return z.gray("\u2022")},get check(){return z.green("\u2714")}};function T(q){console.error(`${z.red("Error:")} ${q}`),process.exit(1)}function H(q){if(q instanceof Error)return q.message;if(typeof q==="string")return q;try{return JSON.stringify(q)}catch{return String(q)}}function M(q){console.log(` ${Q.success} ${q}`)}function f(q){console.log(` ${Q.warning} ${q}`)}function E(q){console.log(` ${Q.info} ${q}`)}function D(q){console.log(`
2
+ import{ie as A}from"./index-c7554sg7.js";var j=!process.env.NO_COLOR&&!!process.stdout.isTTY;function L(q){j=q}var C=(q,B)=>(F)=>j?`${q}${F}${B}`:F,z={bold:C("\x1B[1m","\x1B[22m"),dim:C("\x1B[2m","\x1B[22m"),italic:C("\x1B[3m","\x1B[23m"),underline:C("\x1B[4m","\x1B[24m"),red:C("\x1B[31m","\x1B[39m"),green:C("\x1B[32m","\x1B[39m"),yellow:C("\x1B[33m","\x1B[39m"),blue:C("\x1B[34m","\x1B[39m"),magenta:C("\x1B[35m","\x1B[39m"),cyan:C("\x1B[36m","\x1B[39m"),white:C("\x1B[37m","\x1B[39m"),gray:C("\x1B[90m","\x1B[39m"),brightRed:C("\x1B[91m","\x1B[39m"),brightGreen:C("\x1B[92m","\x1B[39m"),brightYellow:C("\x1B[93m","\x1B[39m"),brightBlue:C("\x1B[94m","\x1B[39m"),reset:"\x1B[0m"},Q={get success(){return z.green("\u2713")},get error(){return z.red("\u2717")},get warning(){return z.yellow("\u26A0")},get info(){return z.blue("\u25CF")},get running(){return z.green("\u25CF")},get stopped(){return z.red("\u25CB")},get pending(){return z.yellow("\u25CC")},get arrow(){return z.gray("\u2192")},get bullet(){return z.gray("\u2022")},get check(){return z.green("\u2714")}};function T(q){console.error(`${z.red("Error:")} ${q}`),process.exit(1)}function H(q){if(q instanceof Error)return q.message;if(typeof q==="string")return q;try{return JSON.stringify(q)}catch{return String(q)}}function M(q){console.log(` ${Q.success} ${q}`)}function f(q){console.log(` ${Q.warning} ${q}`)}function E(q){console.log(` ${Q.info} ${q}`)}function D(q){console.log(`
3
3
  ${z.bold(`\u2500\u2500 ${q} \u2500\u2500`)}
4
4
  `)}function X(q,B){let F=B===null||B===void 0?z.gray("(none)"):String(B);console.log(` ${z.bold(q.padEnd(14))} ${F}`)}function $(){console.log()}function S(q){if(q.length===0){console.log(" (none)");return}console.table(q)}function W(q){let B=Date.now()-new Date(q).getTime(),F=Math.floor(B/1000);if(F<0)return"just now";if(F<60)return`${F}s ago`;let J=Math.floor(F/60);if(J<60)return`${J}m ago`;let N=Math.floor(J/60);if(N<24)return`${N}h ago`;let P=Math.floor(N/24);if(P<30)return`${P}d ago`;return`${Math.floor(P/30)}mo ago`}function x(q){if(q<60)return`${Math.floor(q)}s`;let B=Math.floor(q/60),F=Math.floor(q%60);if(B<60)return`${B}m ${F}s`;let J=Math.floor(B/60),N=B%60;return`${J}h ${N}m`}function K(q){if(q<1024)return`${q} B`;if(q<1048576)return`${(q/1024).toFixed(1)} KB`;if(q<1073741824)return`${(q/1048576).toFixed(1)} MB`;return`${(q/1073741824).toFixed(1)} GB`}function h(q){switch(q){case"running":case"active":case"healthy":case"success":case"completed":return z.green(q);case"stopped":case"inactive":case"terminated":case"failed":return z.red(q);case"starting":case"stopping":case"pending":case"warning":return z.yellow(q);case"error":return z.red(q);default:return q}}function k(q,B=10){if(q.length<=B)return q;return q.substring(0,B)+"..."}async function v(q,B=15000){let F=Date.now(),J=!1;while(Date.now()-F<B){try{if((await fetch(`${q}/health`)).ok){J=!0;break}}catch{}await new Promise((G)=>setTimeout(G,500))}if(!J){console.log(`
5
5
  ${Q.warning} Agent not yet responding at ${q}. Check ${z.bold("vibe logs")} for details.
6
- `);return}let N=process.env.VIBECONTROLS_PROFILE||"default",P=`${q}/api/profiles/${encodeURIComponent(N)}/agent/tunnel`,R="(unavailable)";try{let{resolveDefaultApiKey:G}=await import("./key.cmd-wgcq6kt8.js"),I=await G();if(I)R=I}catch{}let Y=R&&R!=="(unavailable)"?{"x-agent-api-key":R}:{},O="(not running)",Z=!1;try{let G=await fetch(P,{headers:Y});if(G.ok){let I=await G.json();if(I.tunnelUrl)O=I.tunnelUrl;else if(I.status!=="inactive")Z=!0}}catch{}if(Z||O==="(not running)"){process.stdout.write(` ${Q.info} Provisioning tunnel (first run downloads the tunnel binary)\u2026`);let G=150000,I=Date.now();while(Date.now()-I<G){try{let V=await fetch(P,{headers:Y});if(V.ok){let _=await V.json();if(_.tunnelUrl){O=_.tunnelUrl;break}}}catch{}await new Promise((V)=>setTimeout(V,1500)),process.stdout.write(`\r ${Q.info} Provisioning tunnel (first run downloads the tunnel binary)\u2026 ${Math.round((Date.now()-I)/1000)}s`)}process.stdout.write(`
6
+ `);return}let N=process.env.VIBECONTROLS_PROFILE||"default",P=`${q}/api/profiles/${encodeURIComponent(N)}/agent/tunnel`,R="(unavailable)";try{let{resolveDefaultApiKey:G}=await import("./key.cmd-972133dv.js"),I=await G();if(I)R=I}catch{}let Y=R&&R!=="(unavailable)"?{"x-agent-api-key":R}:{},O="(not running)",Z=!1;try{let G=await fetch(P,{headers:Y});if(G.ok){let I=await G.json();if(I.tunnelUrl)O=I.tunnelUrl;else if(I.status!=="inactive")Z=!0}}catch{}if(Z||O==="(not running)"){process.stdout.write(` ${Q.info} Provisioning tunnel (first run downloads the tunnel binary)\u2026`);let G=150000,I=Date.now();while(Date.now()-I<G){try{let V=await fetch(P,{headers:Y});if(V.ok){let _=await V.json();if(_.tunnelUrl){O=_.tunnelUrl;break}}}catch{}await new Promise((V)=>setTimeout(V,1500)),process.stdout.write(`\r ${Q.info} Provisioning tunnel (first run downloads the tunnel binary)\u2026 ${Math.round((Date.now()-I)/1000)}s`)}process.stdout.write(`
7
7
  `)}if(D("Agent Connection Details"),X("Agent URL:",q),X("API Key:",R),X("Tunnel URL:",O==="(not running)"?z.yellow(O):z.green(O)),$(),console.log(" Copy the API Key and Tunnel URL into the VibeControls UI agent configuration."),O==="(not running)")console.log(` ${z.yellow("Tunnel still provisioning")} \u2014 the cloudflared download may still be running in the daemon.`),console.log(` Re-check shortly: ${z.bold("vibe url")}`),console.log(` Start it manually: ${z.bold(`vibe tunnel agent --start --agent-url ${q}`)}`),console.log(` If it never appears: ${z.bold("vibe logs --tail 80")} (look for 'tunnel-bootstrap' / 'install')`);$()}
8
- export{L as mc,z as nc,Q as oc,T as pc,H as qc,M as rc,f as sc,E as tc,D as uc,X as vc,$ as wc,S as xc,W as yc,x as zc,K as Ac,h as Bc,k as Cc,v as Dc};
8
+ export{L as nc,z as oc,Q as pc,T as qc,H as rc,M as sc,f as tc,E as uc,D as vc,X as wc,$ as xc,S as yc,W as zc,x as Ac,K as Bc,h as Cc,k as Dc,v as Ec};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
2
  function z(){let j=process.env.VIBECONTROLS_LOG_SHIP_URL;if(!j)return null;return{url:j,apiKey:process.env.VIBECONTROLS_LOG_SHIP_API_KEY,batchSize:Number.parseInt(process.env.VIBECONTROLS_LOG_SHIP_BATCH??"",10)||100,intervalMs:Number.parseInt(process.env.VIBECONTROLS_LOG_SHIP_INTERVAL_MS??"",10)||1e4,sampleRate:Number.parseFloat(process.env.VIBECONTROLS_LOG_SHIP_SAMPLE??"1")}}var k=1000;class s{config=null;queue=[];timer=null;inFlight=!1;dropped=0;init(){if(this.config)return;if(this.config=z(),!this.config)return;if(this.timer=setInterval(()=>{this.flush()},this.config.intervalMs),this.timer&&typeof this.timer.unref==="function")this.timer.unref()}enqueue(j){if(!this.config)return;if(j.level==="debug"&&this.config.sampleRate<1&&Math.random()>this.config.sampleRate)return;if(this.queue.length>=k)this.dropped+=1,this.queue.shift();this.queue.push(j)}async flush(){if(!this.config||this.inFlight||this.queue.length===0)return;this.inFlight=!0;let j=this.queue.splice(0,this.config.batchSize);try{await fetch(this.config.url,{method:"POST",headers:{"Content-Type":"application/json",...this.config.apiKey?{Authorization:`Bearer ${this.config.apiKey}`}:{}},body:JSON.stringify({entries:j,dropped:this.dropped}),signal:AbortSignal.timeout(5000)}),this.dropped=0}catch{this.queue=[...j,...this.queue].slice(0,k)}finally{this.inFlight=!1}}stop(){if(this.timer)clearInterval(this.timer),this.timer=null;this.flush()}}var B=new s;
3
- export{B as de};
3
+ export{B as ee};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
2
  import{randomBytes as G,timingSafeEqual as J}from"crypto";var M="x-vc-internal-auth",z=G(32).toString("hex");function U(){return z}function V(F){let j=F.get(M);if(!j)return!1;let w=Buffer.from(j),x=Buffer.from(z);return w.length===x.length&&J(w,x)}
3
- export{M as Qb,U as Rb,V as Sb};
3
+ export{M as Rb,U as Sb,V as Tb};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{Xa as N}from"./index-0ckffygp.js";import{Nd as Q}from"./index-9bqd8veb.js";var V=5000,H=new Map,X=1;function Y(b){return`${b}#${X++}`}function u(b){let z=Bun.spawn(b.cmd,{env:b.env,cwd:b.cwd,stdout:b.stdout??"pipe",stderr:b.stderr??"pipe",stdin:b.stdin??"pipe",...N().processGroupSpawnOpts()}),B={id:Y(b.owner),owner:b.owner,pid:z.pid??null,startedAt:new Date().toISOString(),proc:z,meta:b.meta};return H.set(B.id,B),z.exited.finally(()=>{H.delete(B.id)}),B}function v(){return[...H.values()]}function C(b){return[...H.values()].filter((z)=>z.owner===b)}async function Z(b,z){let B=N(),J=Date.now()+z;while(Date.now()<J){if(!B.isProcessAlive(b))return!0;await new Promise((U)=>setTimeout(U,100))}return!B.isProcessAlive(b)}async function T(b,z="SIGTERM"){let B=b.pid;if(B==null)return;let J=N();if(J.killProcessTree(B,z),await Z(B,V))return;J.killProcessTree(B,"SIGKILL")}async function D(b){let z=H.get(b);if(!z)return!1;return await T(z),H.delete(b),!0}async function F(){let b=[...H.values()];if(b.length===0)return{reaped:0};return Q().logger.info("subprocess",`Reaping ${b.length} tracked child process(es)`,{owners:[...new Set(b.map((z)=>z.owner))]}),await Promise.all(b.map((z)=>T(z))),H.clear(),{reaped:b.length}}
2
+ import{Xa as N}from"./index-0ckffygp.js";import{Od as Q}from"./index-js1xn4sq.js";var V=5000,H=new Map,X=1;function Y(b){return`${b}#${X++}`}function u(b){let z=Bun.spawn(b.cmd,{env:b.env,cwd:b.cwd,stdout:b.stdout??"pipe",stderr:b.stderr??"pipe",stdin:b.stdin??"pipe",...N().processGroupSpawnOpts()}),B={id:Y(b.owner),owner:b.owner,pid:z.pid??null,startedAt:new Date().toISOString(),proc:z,meta:b.meta};return H.set(B.id,B),z.exited.finally(()=>{H.delete(B.id)}),B}function v(){return[...H.values()]}function C(b){return[...H.values()].filter((z)=>z.owner===b)}async function Z(b,z){let B=N(),J=Date.now()+z;while(Date.now()<J){if(!B.isProcessAlive(b))return!0;await new Promise((U)=>setTimeout(U,100))}return!B.isProcessAlive(b)}async function T(b,z="SIGTERM"){let B=b.pid;if(B==null)return;let J=N();if(J.killProcessTree(B,z),await Z(B,V))return;J.killProcessTree(B,"SIGKILL")}async function D(b){let z=H.get(b);if(!z)return!1;return await T(z),H.delete(b),!0}async function F(){let b=[...H.values()];if(b.length===0)return{reaped:0};return Q().logger.info("subprocess",`Reaping ${b.length} tracked child process(es)`,{owners:[...new Set(b.map((z)=>z.owner))]}),await Promise.all(b.map((z)=>T(z))),H.clear(),{reaped:b.length}}
3
3
  export{u as o,v as p,C as q,D as r,F as s};