@vibecontrols/agent 2026.1201.1 → 2026.1202.1

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 (71) hide show
  1. package/dist/{agent-config-xwvsmn6b.js → agent-config-mg5dvtm3.js} +1 -1
  2. package/dist/{agent-ready-tracker-7ebr09d9.js → agent-ready-tracker-b1dxkhrt.js} +1 -1
  3. package/dist/app-hvt8zawq.js +2 -0
  4. package/dist/autostart.cmd-4c0rekqt.js +2 -0
  5. package/dist/bootstrap-workspace-wsjzmm9n.js +2 -0
  6. package/dist/bootstrap.service-0m0rcq8d.js +2 -0
  7. package/dist/{bridge-client-9ax1cvj6.js → bridge-client-fcwk5tyk.js} +1 -1
  8. package/dist/{bridge-commands-hc1gvngq.js → bridge-commands-xagq5kq7.js} +1 -1
  9. package/dist/cli.js +1 -1
  10. package/dist/daemon-profile-0bvscqm2.js +2 -0
  11. package/dist/{finalize-retry-worker-c38km3mt.js → finalize-retry-worker-qe7zagk7.js} +1 -1
  12. package/dist/gateway-client-8gfze3jv.js +2 -0
  13. package/dist/{index-dr6rsnpk.js → index-2a1yq04v.js} +3 -3
  14. package/dist/{index-dgbe8jm8.js → index-2nq1tefj.js} +1 -1
  15. package/dist/{index-j99tkngg.js → index-30qr1qm3.js} +1 -1
  16. package/dist/{index-ednz6yz2.js → index-4qqsx04e.js} +1 -1
  17. package/dist/{index-twtvt4yt.js → index-5ygnxt32.js} +3 -3
  18. package/dist/{index-rhn7wy1p.js → index-6g3qhprq.js} +1 -1
  19. package/dist/{index-5tghd67e.js → index-6xd9k363.js} +6 -6
  20. package/dist/{index-j9jwwzq2.js → index-8y4fys3s.js} +7 -7
  21. package/dist/{index-yfk0pb00.js → index-ag2b7yeg.js} +1 -1
  22. package/dist/{index-bk17490n.js → index-c9q14161.js} +1 -1
  23. package/dist/{index-damc6cvc.js → index-djwa3tm3.js} +1 -1
  24. package/dist/{index-0rmmrrfh.js → index-ep20qw1j.js} +1 -1
  25. package/dist/{index-6nv5rdqh.js → index-fm1wjs3r.js} +1 -1
  26. package/dist/{index-12gb48hg.js → index-j9cg16we.js} +1 -1
  27. package/dist/{index-f5nmxa9e.js → index-jhgd7sva.js} +1 -1
  28. package/dist/{index-76vza24h.js → index-mrcjqvnf.js} +1 -1
  29. package/dist/{index-p7fbnfwd.js → index-n3kwtv6f.js} +2 -2
  30. package/dist/{index-e5jdx9c1.js → index-nqa1m94e.js} +2 -2
  31. package/dist/index-nxpw3anc.js +30 -0
  32. package/dist/{index-zcnfj1q4.js → index-prp5nvsa.js} +3 -3
  33. package/dist/{index-qzwbctkv.js → index-pw6aqemr.js} +4 -4
  34. package/dist/{index-4kf3nr14.js → index-r1v0yazw.js} +2 -2
  35. package/dist/{index-q4fht6h2.js → index-r2j1t657.js} +19 -19
  36. package/dist/{index-vhz1c474.js → index-tn2vyz8q.js} +1 -1
  37. package/dist/{index-br9bakfm.js → index-txchzvfc.js} +2 -2
  38. package/dist/{index-85jn7v8t.js → index-xertgyzn.js} +5 -5
  39. package/dist/{index-wxb9dgwq.js → index-zekdqp0t.js} +1 -1
  40. package/dist/{index-8jk4a62x.js → index-zfhmg1gz.js} +6 -6
  41. package/dist/{index-sjs32cgn.js → index-zngtj9re.js} +2 -2
  42. package/dist/index.js +2 -2
  43. package/dist/key.cmd-eevbsknq.js +2 -0
  44. package/dist/log-shipper-h7azf3f8.js +2 -0
  45. package/dist/{path-utils-qgkdkp5j.js → path-utils-3sgj48ta.js} +1 -1
  46. package/dist/plugin-system-e1a3ttpy.js +2 -0
  47. package/dist/prereqs-runner-etehmhk8.js +2 -0
  48. package/dist/profile-mount-rr5kr708.js +2 -0
  49. package/dist/register-core-7kb2k9g3.js +2 -0
  50. package/dist/secondary-profile-attach-2x3dsnn8.js +2 -0
  51. package/dist/subprocess-j0r8hvmc.js +2 -0
  52. package/dist/telemetry-fyced899.js +2 -0
  53. package/dist/tunnel-bootstrap-rm5k7qw4.js +2 -0
  54. package/package.json +1 -1
  55. package/dist/app-ntnpwedw.js +0 -2
  56. package/dist/autostart.cmd-mdyv35dn.js +0 -2
  57. package/dist/bootstrap-workspace-1pt0bwy6.js +0 -2
  58. package/dist/bootstrap.service-gehm65tt.js +0 -2
  59. package/dist/daemon-profile-fnhc7pcf.js +0 -2
  60. package/dist/gateway-client-3zp6kkav.js +0 -2
  61. package/dist/index-7wm4bqx5.js +0 -21
  62. package/dist/key.cmd-y415ngam.js +0 -2
  63. package/dist/log-shipper-02rqvtq8.js +0 -2
  64. package/dist/plugin-system-e690jr6e.js +0 -2
  65. package/dist/prereqs-runner-w7z2dwa6.js +0 -2
  66. package/dist/profile-mount-ga5z1vx9.js +0 -2
  67. package/dist/register-core-n1dy472f.js +0 -2
  68. package/dist/secondary-profile-attach-v7kxsk4z.js +0 -2
  69. package/dist/subprocess-p9bv9nqz.js +0 -2
  70. package/dist/telemetry-1d3t1mbf.js +0 -2
  71. package/dist/tunnel-bootstrap-m51w4d94.js +0 -2
@@ -1,21 +0,0 @@
1
- // @bun
2
- import{join as Ae}from"path";import{AsyncLocalStorage as Zt}from"async_hooks";import{mkdirSync as te}from"fs";import{join as et}from"path";import{appendFileSync as ct,existsSync as E,mkdirSync as ut,readFileSync as gt,readdirSync as ft,statSync as pt,unlinkSync as V}from"fs";import{join as y}from"path";var dt=30,ht=104857600,mt=/secret|password|token|key|email/i,K=/^audit-(\d{4}-\d{2}-\d{2})\.log$/;function H(t=new Date){let r=t.getUTCFullYear(),n=String(t.getUTCMonth()+1).padStart(2,"0"),i=String(t.getUTCDate()).padStart(2,"0");return`${r}-${n}-${i}`}function L(t){if(Array.isArray(t))return t.map(L);if(t&&typeof t==="object"){let r={};for(let[n,i]of Object.entries(t)){if(mt.test(n)){r[n]="[redacted]";continue}r[n]=L(i)}return r}return t}function yt(t,r){if(!r)return!0;if(r.includes("*"))return new RegExp(`^${r.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*")}$`).test(t);return t.includes(r)}class A{profile;auditDir;constructor(t,r){this.profile=t,this.auditDir=y(r,"audit")}ensureDir(){if(!E(this.auditDir))ut(this.auditDir,{recursive:!0});return this.auditDir}activeFilePath(){return y(this.ensureDir(),`audit-${H()}.log`)}emit(t,r,n={}){let i=L(n),o={timestamp:new Date().toISOString(),source:t,event:r,payload:{...i,profile:this.profile}};try{ct(this.activeFilePath(),`${JSON.stringify(o)}
3
- `,{mode:384})}catch{}}listLogFiles(){if(!E(this.auditDir))return[];return ft(this.auditDir).filter((t)=>K.test(t)).sort()}listEvents(t={}){let r=Math.max(1,Math.min(t.limit??200,5000)),n=t.since?Date.parse(t.since):null,i=t.event??"",o=this.listLogFiles(),s=[];for(let a=o.length-1;a>=0&&s.length<r;a--){let l=o[a],c;try{c=gt(y(this.auditDir,l),"utf8")}catch{continue}let u=c.split(`
4
- `);for(let g=u.length-1;g>=0&&s.length<r;g--){let d=u[g];if(!d)continue;let f;try{f=JSON.parse(d)}catch{continue}if(n!==null&&Number.isFinite(n)&&Date.parse(f.timestamp)<n)continue;if(!yt(f.event,i))continue;s.push(f)}}return s}runRetention(t=new Date){if(!E(this.auditDir))return;let r=t.getTime()-dt*24*60*60*1000,n=this.listLogFiles(),i=[];for(let a of n){let l=K.exec(a);if(!l)continue;let c=Date.parse(`${l[1]}T00:00:00Z`),u=y(this.auditDir,a);try{let g=pt(u);if(Number.isFinite(c)&&c<r){V(u);continue}i.push({name:a,size:g.size,mtime:g.mtimeMs})}catch{}}let o=i.reduce((a,l)=>a+l.size,0),s=`audit-${H(t)}.log`;i.sort((a,l)=>a.name.localeCompare(l.name));for(let a of i){if(o<=ht)break;if(a.name===s)continue;try{V(y(this.auditDir,a.name)),o-=a.size}catch{}}}__getAuditDirForTests(){return this.auditDir}}class P{profile;cryptoKey=null;apiKeyHash=null;constructor(t){this.profile=t}async load(t){if(t.byteLength!==32)throw Error(`KeyVault expects 32-byte key, got ${t.byteLength}`);let r=new Uint8Array(t);try{this.cryptoKey=await crypto.subtle.importKey("raw",r,{name:"AES-GCM"},!1,["encrypt","decrypt"])}finally{t.fill(0),r.fill(0)}}async bindApiKey(t){let r=new TextEncoder().encode(t);this.apiKeyHash=await crypto.subtle.digest("SHA-256",r),r.fill(0)}async match(t){if(!this.apiKeyHash)return!1;let r=new TextEncoder().encode(t),n=await crypto.subtle.digest("SHA-256",r);return r.fill(0),vt(this.apiKeyHash,n)}hasKey(){return this.cryptoKey!==null}getCryptoKey(){return this.cryptoKey}shutdown(){this.cryptoKey=null,this.apiKeyHash=null}}function vt(t,r){if(t.byteLength!==r.byteLength)return!1;let n=new Uint8Array(t),i=new Uint8Array(r),o=0;for(let s=0;s<n.length;s++)o|=(n[s]??0)^(i[s]??0);return o===0}import{existsSync as h,mkdirSync as Lt,statSync as At,copyFileSync as Pt,truncateSync as kt,renameSync as It,unlinkSync as Ct,createReadStream as _t}from"fs";import{join as Dt}from"path";import{EventEmitter as Ot}from"events";import{createInterface as Gt}from"readline";import{AsyncLocalStorage as St}from"async_hooks";var j=new St,Rt=/^[A-Za-z0-9._:-]{8,128}$/;function Ai(){let t=globalThis.crypto;if(t?.randomUUID)return t.randomUUID();let r=new Uint8Array(16);return t?.getRandomValues?.(r),[...r].map((n)=>n.toString(16).padStart(2,"0")).join("")}function Hi(t){let r=(i)=>{if(t instanceof Headers)return t.get(i)??void 0;return t[i]??t[i.toLowerCase()]??t[i.toUpperCase()]},n=r("x-request-id")??r("X-Request-Id");if(!n)return;return Rt.test(n)?n:void 0}function Vi(t){j.enterWith(t)}function Tt(){return j.getStore()?.requestId}function Et(){let t=process.env.VIBECONTROLS_LOG_SHIP_URL;if(!t)return null;return{url:t,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 Y=1000;class Q{config=null;queue=[];timer=null;inFlight=!1;dropped=0;init(){if(this.config)return;if(this.config=Et(),!this.config)return;if(this.timer=setInterval(()=>{this.flush()},this.config.intervalMs),this.timer&&typeof this.timer.unref==="function")this.timer.unref()}enqueue(t){if(!this.config)return;if(t.level==="debug"&&this.config.sampleRate<1&&Math.random()>this.config.sampleRate)return;if(this.queue.length>=Y)this.dropped+=1,this.queue.shift();this.queue.push(t)}async flush(){if(!this.config||this.inFlight||this.queue.length===0)return;this.inFlight=!0;let t=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:t,dropped:this.dropped}),signal:AbortSignal.timeout(5000)}),this.dropped=0}catch{this.queue=[...t,...this.queue].slice(0,Y)}finally{this.inFlight=!1}}stop(){if(this.timer)clearInterval(this.timer),this.timer=null;this.flush()}}var Yi=new Q;var Ut=10485760,W=7,Ft=60000,S={debug:0,info:1,warn:2,error:3},$t={debug:"\x1B[90m",info:"\x1B[36m",warn:"\x1B[33m",error:"\x1B[31m"},Nt="\x1B[0m";class k extends Ot{logDir;logFile;currentDay="";minLevel;isDaemon;emitOutput;prettyOutput;rotationTimer=null;constructor(t){super();this.setMaxListeners(100),this.logDir=t.logDir;let r=process.env.AGENT_LOG_FILE;this.logFile=r&&r.length>0?r:t.logFile??Dt(this.logDir,"default.log"),this.minLevel=process.env.LOG_LEVEL??"info",this.isDaemon=Boolean(process.env.AGENT_LOG_FILE);let n=process.env.VIBE_FOREGROUND==="1"||process.argv.some((i)=>i==="-f"||i==="--foreground");if(this.emitOutput=this.isDaemon||n||process.env.LOG_CONSOLE==="true"||!1,this.prettyOutput=this.emitOutput&&!this.isDaemon&&Boolean(process.stdout.isTTY),this.ensureLogDir(),this.currentDay=new Date().toISOString().split("T")[0]??"",this.isDaemon)this.rotationTimer=setInterval(()=>this.checkRotation(),Ft),this.rotationTimer.unref?.()}debug(t,r,n){this.log("debug",t,r,n)}info(t,r,n){this.log("info",t,r,n)}warn(t,r,n){this.log("warn",t,r,n)}error(t,r,n){this.log("error",t,r,n)}setLevel(t){this.minLevel=t}async readHistory(t){let{level:r,source:n,from:i,to:o,limit:s=200,offset:a=0}=t??{},l=[];if(!h(this.logFile))return l;return new Promise((c)=>{let u=Gt({input:_t(this.logFile,"utf8")}),g=0;u.on("line",(d)=>{if(l.length>=s){u.close();return}try{let f=JSON.parse(d);if(r&&S[f.level]<S[r])return;if(n&&!f.source.includes(n))return;if(i&&f.timestamp<i)return;if(o&&f.timestamp>o)return;if(g<a){g++;return}l.push(f)}catch{}}),u.on("close",()=>c(l)),u.on("error",()=>c(l))})}close(){if(this.rotationTimer)clearInterval(this.rotationTimer),this.rotationTimer=null}log(t,r,n,i){if(S[t]<S[this.minLevel])return;let o=Tt(),s=o!==void 0?{requestId:o,...i??{}}:i,a={timestamp:new Date().toISOString(),level:t,source:r,message:n,...s&&Object.keys(s).length>0?{metadata:s}:{}};if(this.emitOutput)if(this.prettyOutput){let l=$t[t],c=t.toUpperCase().padEnd(5),u=r?` [${r}]`:"",g=s&&Object.keys(s).length>0?` ${JSON.stringify(s)}`:"",d=a.timestamp.split("T")[1]?.slice(0,12)??a.timestamp;process.stdout.write(`${l}${d} ${c}${Nt}${u} ${n}${g}
5
- `)}else process.stdout.write(JSON.stringify(a)+`
6
- `);this.emit("log",a),Yi.enqueue(a)}checkRotation(){let t=new Date().toISOString().split("T")[0];if(this.currentDay&&this.currentDay!==t){this.rotate(),this.currentDay=t;return}this.currentDay=t;try{if(h(this.logFile)){if(At(this.logFile).size>=Ut)this.rotate()}}catch{}}rotate(){try{for(let t=W-1;t>=1;t--){let r=`${this.logFile}.${t}`,n=`${this.logFile}.${t+1}`;if(h(r)){if(t+1>W&&h(n))Ct(n);It(r,n)}}if(h(this.logFile))Pt(this.logFile,`${this.logFile}.1`),kt(this.logFile,0)}catch{}}ensureLogDir(){if(!h(this.logDir))Lt(this.logDir,{recursive:!0})}}var b=new Set(["localhost","127.0.0.1","0.0.0.0","::1","[::1]","host.docker.internal"]),qt=new Set(["4000","4001","4002","4003"]),Bt=new Set(["gw-global.local.burdenoff.com","gw-global-int.local.burdenoff.com","gw-wspace.local.burdenoff.com","gw-wspace-int.local.burdenoff.com"]),Mt=new Set(["graphql.burdenoff.com","graphqlworkspaces.burdenoff.com","alphagraphql.burdenoff.com","alphagraphqlworkspaces.burdenoff.com"]);function p(t){return t.toLowerCase().replace(/^\[|\]$/g,"")}function J(t){let r=p(t.hostname);if(!b.has(r))return!1;if(process.env.VIBECONTROLS_ALLOW_UNTRUSTED_GATEWAYS==="1")return!0;return qt.has(t.port)}function X(t){try{let r=new URL(t.trim());if(r.protocol!=="https:"&&r.protocol!=="http:")return!1;if(J(r))return!0;let n=p(r.hostname);if(Bt.has(n))return r.protocol==="https:";if(r.protocol!=="https:")return!1;return Mt.has(n)}catch{return!1}}function z(t,r){let n=t.trim();if(!X(n))throw Error(`${r} is not an allowed gateway URL. Use a trusted Burdenoff gateway, approved gw-*.local.burdenoff.com host, or localhost gateway ports 4000-4003.`);return n.replace(/\/+$/,"")}var _=new Set([".vibecontrols.com"]);function Jt(t){let r=t.trim().toLowerCase();if(!r)return;_.add(r.startsWith(".")?r:`.${r}`)}function Vt(t){try{let r=new URL(t.trim()),n=p(r.hostname);if(b.has(n))return r.protocol==="http:"||r.protocol==="https:";if(r.protocol!=="https:")return!1;for(let i of _)if(n.endsWith(i))return!0;return!1}catch{return!1}}function ci(t){if(!t)return null;let r=t.trim().replace(/\/+$/,"");return Vt(r)?r:null}function Wt(t){if(!t)return null;let r=ci(t);if(r)return r;let n=process.env.AGENT_TUNNEL_URL;if(n&&t.trim().replace(/\/+$/,"")===n.trim().replace(/\/+$/,""))return xt(t);return null}var zt=new Set([".trycloudflare.com"]);function Kt(t){try{let r=new URL(t.trim()),n=p(r.hostname);if(b.has(n))return r.protocol==="http:"||r.protocol==="https:";if(r.protocol!=="https:")return!1;for(let i of _)if(n.endsWith(i))return!0;for(let i of zt)if(n.endsWith(i))return!0;return!1}catch{return!1}}function Ir(t){if(!t)return null;let r=t.trim().replace(/\/+$/,"");return Kt(r)?r:null}function Ht(t){try{let r=new URL(t.trim()),n=p(r.hostname);if(b.has(n))return r.protocol==="http:"||r.protocol==="https:";return r.protocol==="https:"}catch{return!1}}function xt(t){if(!t)return null;let r=t.trim().replace(/\/+$/,"");return Ht(r)?r:null}function Zi(t,r){try{let n=new URL(t.trim());if(n.protocol!=="https:"&&!J(n))return!1;let i=p(n.hostname);for(let o of r){if(!o)continue;let s=new URL(o);if(i===p(s.hostname))return!0}return X(t)}catch{return!1}}var jt=/(?:\/(?:global|workspaces))?\/graphql$/i,Yt=1048576;function G(t){return t.trim().replace(/\/+$/,"").replace(jt,"")}function Z(t,r){return`${G(t)}/${r}/graphql`}function tt(t){return t instanceof Error?t.message:String(t)}async function Qt(t,r){let n=t.headers.get("content-length");if(n){let c=Number.parseInt(n,10);if(Number.isInteger(c)&&c>r)throw Error(`Gateway response is too large (${c} bytes)`)}if(!t.body)return"";let i=t.body.getReader(),o=[],s=0;try{while(!0){let{done:c,value:u}=await i.read();if(c)break;if(!u)continue;if(s+=u.byteLength,s>r)throw await i.cancel().catch(()=>{return}),Error(`Gateway response exceeds ${r} bytes`);o.push(u)}}finally{i.releaseLock()}let a=new Uint8Array(s),l=0;for(let c of o)a.set(c,l),l+=c.byteLength;return new TextDecoder().decode(a)}class ui{config=null;token=null;authInFlight=null;configGeneration=0;configure(t){let r=G(z(t.globalGatewayUrl,"globalGatewayUrl")),n=t.workspaceGatewayUrl?G(z(t.workspaceGatewayUrl,"workspaceGatewayUrl")):void 0,i=t.clientId.trim(),o=t.clientSecret.trim();if(!r)throw Error("globalGatewayUrl is required");if(!i)throw Error("clientId is required");if(!o)throw Error("clientSecret is required");this.configGeneration+=1,this.config={...t,globalGatewayUrl:r,workspaceGatewayUrl:n,clientId:i,clientSecret:o,scopes:t.scopes?.map((s)=>s.trim()).filter(Boolean),workspaceId:t.workspaceId?.trim()||void 0,organizationId:t.organizationId?.trim()||void 0},this.token=null,this.authInFlight=null,e().logger.info("gateway-client","Gateway client configured",{globalGatewayUrl:this.config.globalGatewayUrl,workspaceGatewayUrl:this.config.workspaceGatewayUrl,clientId:this.config.clientId})}isConfigured(){return this.config!==null}getConfig(){if(!this.config)return null;let{clientSecret:t,...r}=this.config;return r}async getAccessToken(){let{token:t,config:r}=await this.ensureToken();return{token:t,workspaceGatewayUrl:r.workspaceGatewayUrl??"",globalGatewayUrl:r.globalGatewayUrl??"",workspaceId:r.workspaceId??""}}async globalQuery(t,r){return this.executeQuery("global",t,r)}async workspaceQuery(t,r){return this.executeQuery("workspaces",t,r)}async lookupPeerAgent(t,r){if(!this.isConfigured())return null;try{let i=(await this.workspaceQuery(`query AgentNetworkLookup($targetAgentRecordId: ID!, $operation: String!) {
7
- vibecontrolsAgentNetworkLookup(targetAgentRecordId: $targetAgentRecordId, operation: $operation) {
8
- tunnelUrl
9
- peerApiKey
10
- }
11
- }`,{targetAgentRecordId:t,operation:r})).data?.vibecontrolsAgentNetworkLookup;if(!i)return null;return{tunnelUrl:i.tunnelUrl,apiKey:i.peerApiKey}}catch(n){return e().logger.warn("gateway-client","Peer agent lookup failed",{targetAgentRecordId:t,error:n instanceof Error?n.message:String(n)}),null}}async executeQuery(t,r,n){let{token:i,config:o}=await this.ensureToken(),s=t==="workspaces"?o.workspaceGatewayUrl??o.globalGatewayUrl:o.globalGatewayUrl,a=Z(s,t);e().logger.debug("gateway-client",`GraphQL ${t} request`,{url:a,queryLength:r.length});let l={"Content-Type":"application/json",Authorization:`Bearer ${i}`};if(o.workspaceId&&t==="workspaces")l["x-workspace-id"]=o.workspaceId;let c=Tt();if(c)l["X-Request-Id"]=c;let u=await this.postGraphQL(a,l,{query:r,variables:n});if(u.errors?.length)e().logger.warn("gateway-client","GraphQL errors",{supergraph:t,errors:u.errors.map((g)=>g.message)});return u}async ensureToken(){if(!this.config)throw Error("Gateway client not configured. Call configure() first.");let t=this.config,r=this.configGeneration;if(this.token&&this.token.expiresAt>Date.now()+60000)return{token:this.token.accessToken,config:t,generation:r};if(this.authInFlight?.generation===r){let i=await this.authInFlight.promise;if(r!==this.configGeneration||t!==this.config)return this.ensureToken();return{token:i,config:t,generation:r}}let n={generation:r,promise:this.authenticate(t,r)};this.authInFlight=n;try{let i=await n.promise;if(r!==this.configGeneration||t!==this.config)return this.ensureToken();return{token:i,config:t,generation:r}}finally{if(this.authInFlight===n)this.authInFlight=null}}async authenticate(t,r){e().logger.info("gateway-client","Authenticating with gateway",{clientId:t.clientId});let n=Z(t.globalGatewayUrl,"global"),i=await this.postGraphQL(n,{"Content-Type":"application/json"},{query:`
12
- mutation AuthenticateApp($input: AuthenticateAppInput!) {
13
- authenticateApp(input: $input) {
14
- accessToken
15
- tokenType
16
- expiresIn
17
- scopes
18
- }
19
- }
20
- `,variables:{input:{clientId:t.clientId,clientSecret:t.clientSecret,scopes:t.scopes??[]}}});if(i.errors?.length||!i.data?.authenticateApp){let a=i.errors?.[0]?.message??"Authentication failed";throw e().logger.error("gateway-client",`Authentication failed: ${a}`),Error(`Gateway authentication failed: ${a}`)}let o=i.data.authenticateApp,s={accessToken:o.accessToken,expiresAt:Date.now()+o.expiresIn*1000,scopes:o.scopes};if(r!==this.configGeneration||t!==this.config)throw Error("Gateway configuration changed during authentication");return this.token=s,e().logger.info("gateway-client","Authenticated successfully",{expiresIn:o.expiresIn,scopes:o.scopes}),s.accessToken}async postGraphQL(t,r,n){let i;try{i=await fetch(t,{method:"POST",headers:r,body:JSON.stringify(n),signal:AbortSignal.timeout(15000)})}catch(o){throw Error(`Could not reach gateway at ${t}: ${tt(o)}`,{cause:o})}try{let o=await Qt(i,Yt),s={};if(o)try{s=JSON.parse(o)}catch{let a=o.slice(0,240).replace(/\s+/g," ");throw Error(`Gateway returned a non-JSON response (${i.status} ${i.statusText}) from ${t}${a?`: ${a}`:""}`)}if(!i.ok){let a=s.errors?.[0]?.message??`${i.status} ${i.statusText}`;throw Error(`Gateway request failed at ${t}: ${a} (${i.status})`)}return s}catch(o){if(o instanceof Error)throw o;throw Error(`Failed to process gateway response from ${t}: ${tt(o)}`,{cause:o})}}}function D(){let t=B();if(t)return t.gatewayClient;return e().gatewayClient}var T=new Proxy({},{get(t,r,n){let i=D(),o=i[r];return typeof o==="function"?o.bind(i):o},set(t,r,n){let i=D();return i[r]=n,!0},has(t,r){return r in D()}});var re={maxFileDescriptors:4096,maxChildProcesses:256,maxMemoryMB:4096},U=new Zt;function wt(t){U.enterWith(t)}class F{name;dataDir;spawnOwnerKey;keyVault;audit;logger;budget;db=null;serviceRegistry=null;pluginManager=null;lifecycle=null;hostServices=null;tunnel={url:null,child:null,externalUrl:!1};_gatewayClient=null;state="awaiting-config";degradedReasons=[];listeners=new Set;lastFinalizeError=null;constructor(t){this.name=t.name,this.dataDir=t.dataDir,this.spawnOwnerKey=`profile/${t.name}`,this.budget=t.budget??re,te(this.dataDir,{recursive:!0}),this.keyVault=new P(t.name),this.audit=new A(t.name,t.dataDir),this.logger=new k({logDir:et(t.dataDir,"logs")})}run(t){return U.run(this,t)}get gatewayClient(){if(!this._gatewayClient)this._gatewayClient=new ui;return this._gatewayClient}attachServices(t){this.db=t.db,this.serviceRegistry=t.serviceRegistry,this.pluginManager=t.pluginManager,this.lifecycle=t.lifecycle,this.hostServices=t.hostServices}getBootState(){return this.state}setBootState(t){if(this.state===t)return;if(this.state=t,t!=="degraded")this.degradedReasons.length=0;for(let r of this.listeners)try{r(t)}catch{}}recordDegradedReason(t,r){if(this.degradedReasons.push({plugin:t,message:r}),this.state==="ready")this.setBootState("degraded");(async()=>{try{let{telemetryService:n}=await import("./telemetry-1d3t1mbf.js");n.emit("health.degraded",{reason_class:ie(r)})}catch{}})()}getDegradedReasons(){return this.degradedReasons.slice()}recordFinalizeError(t,r){this.lastFinalizeError={message:t,at:new Date().toISOString(),attempt:r}}clearFinalizeError(){this.lastFinalizeError=null}getLastFinalizeError(){return this.lastFinalizeError}onBootStateChange(t){return this.listeners.add(t),()=>this.listeners.delete(t)}async shutdown(){this.setBootState("shutting-down");try{let{unmountProfileRoutes:t}=await import("./profile-mount-ga5z1vx9.js");t(this.name)}catch{}try{if(this.pluginManager)await this.pluginManager.dispatchServerStop({reason:"shutdown"})}catch{}try{if(this.db)await this.db.close()}catch{}this.lifecycle=null,this.pluginManager=null,this.hostServices=null,this.serviceRegistry=null,this.db=null,this._gatewayClient=null,this.tunnel={url:null,child:null,externalUrl:!1},this.keyVault.shutdown(),this.listeners.clear()}subdir(t){return et(this.dataDir,t)}}function B(){return U.getStore()??null}function ie(t){let r=t.toLowerCase();if(r.includes("timeout"))return"timeout";if(r.includes("econn")||r.includes("network"))return"network";if(r.includes("permission")||r.includes("eacces"))return"permission";if(r.includes("not found")||r.includes("enoent"))return"not_found";if(r.includes("plugin"))return"plugin";return"other"}class q{profiles=new Map;create(t){if(this.profiles.has(t.name))throw Error(`profile already registered: ${t.name}`);let r=new F(t);return this.profiles.set(t.name,r),this.refreshProcessTitle(),r}refreshProcessTitle(){try{let r=[...this.profiles.keys()].sort().join(","),n=r.length>96?`${r.slice(0,93)}...`:r;process.title=`vibe-daemon[${n}]`}catch{}}get(t){return this.profiles.get(t)}list(){return[...this.profiles.values()]}names(){return[...this.profiles.keys()]}has(t){return this.profiles.has(t)}size(){return this.profiles.size}async destroy(t){let r=this.profiles.get(t);if(!r)return;await r.shutdown(),this.profiles.delete(t),this.refreshProcessTitle()}async destroyAll(){let t=[...this.profiles.keys()];for(let r of t)await this.destroy(r)}}import{isAbsolute as ve,join as w,relative as Se,resolve as M}from"path";import{existsSync as be,readFileSync as Te}from"fs";import{homedir as Re}from"os";import{existsSync as oe,mkdirSync as ae,readFileSync as le,renameSync as ce,writeFileSync as ue}from"fs";import{homedir as ge}from"os";import{dirname as fe,join as rt,resolve as pe}from"path";var m=new Map;async function he(t,r){let n=m.get(t)??Promise.resolve(),i,o=new Promise((s)=>{i=s});m.set(t,n.then(()=>o));try{return await n,await r()}finally{if(i(),m.get(t)===n.then(()=>o));queueMicrotask(()=>{let s=m.get(t);if(!s)return;Promise.race([s,new Promise((a)=>{a(void 0)})]).then(()=>{if(m.get(t)===s)m.delete(t)})})}}var de="agents-registry";async function ot(t){return he(de,t)}function me(){return pe(process.env.VIBECONTROLS_HOME??rt(ge(),".boff","vibecontrols"))}var nt=2,ye="default";function it(){return rt(me(),"agents.json")}function we(){let t=it();if(!oe(t))return null;try{let r=JSON.parse(le(t,"utf8"));if(r&&typeof r==="object"&&!Array.isArray(r)&&"instances"in r)return r;return null}catch{return null}}function x(){let t=we();if(!t)return{schemaVersion:nt,instances:[]};return t}function st(t){let r=it();ae(fe(r),{recursive:!0});let n=`${r}.${process.pid}.tmp`,i={...t,schemaVersion:nt};ue(n,`${JSON.stringify(i,null,2)}
21
- `,{encoding:"utf8",mode:384}),ce(n,r)}function bt(){return x().instances}function Ji(t){let r=x();st({...r,instances:t})}function Oe(){try{let r=x().defaultProfile;if(r&&typeof r==="string"&&r.length>0)return r}catch{}return ye}function Xt(t){if(!t||typeof t!=="string")throw Error("setDefaultProfile: name is required");let r=x();st({...r,defaultProfile:t})}var xe=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/,Ee=/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;function lt(t){if(!xe.test(t))throw Error("Invalid VIBECONTROLS_PROFILE. Use 1-128 characters: letters, numbers, dot, underscore, or dash.");return t}function R(){let t=process.env.VIBECONTROLS_PROFILE;if(t)return lt(t);let r=Oe();return lt(r)}function O(t){if(!Ee.test(t))throw Error("Agent name must use 1-64 characters: letters, numbers, dot, underscore, or dash.");return t}function li(t,r){let n=Se(M(t),M(r));return n===""||!!n&&!n.startsWith("..")&&!ve(n)}function I(){let t=C(),r=R();return w(t,"agents",r)}function ne(){return w(C(),"agents")}function ee(){return w(I(),"agent-db")}function C(){return M(process.env.VIBECONTROLS_HOME??w(Re(),".boff","vibecontrols"))}var Le="https://registry.npmjs.org/";function se(){if(process.env.VIBECONTROLS_REGISTRY)return process.env.VIBECONTROLS_REGISTRY;try{let t=w(I(),"config.json");if(be(t)){let r=JSON.parse(Te(t,"utf8"));if(r.registry)return r.registry}}catch{}return Le}var N=new q,v=null;function Pe(){if(v)return v;let t=R(),r=N.get(t);if(r)return v=r,r;return v=N.create({name:t,dataDir:I()}),v}function e(){return Pe()}function at(t){let r=O(t),n=N.get(r);if(n)return n;return N.create({name:r,dataDir:Ae(C(),"agents",r)})}export{Ai,Hi,Vi,Tt,Yi,z,Jt,ci,Wt,Ir,xt,Zi,ui,T,he,ot,bt,Ji,Oe,Xt,R,O,li,I,ne,ee,C,se,wt,B,N,e,at};
@@ -1,2 +0,0 @@
1
- // @bun
2
- import{Xi,Zr}from"./index-yfk0pb00.js";import"./index-v77bb0rm.js";import"./index-12gb48hg.js";import"./index-sq5j8bjn.js";import"./index-damc6cvc.js";import"./index-j99tkngg.js";import"./index-7wm4bqx5.js";export{Zr as register,Xi as resolveDefaultApiKey};
@@ -1,2 +0,0 @@
1
- // @bun
2
- import{Yi}from"./index-7wm4bqx5.js";export{Yi as logShipper};
@@ -1,2 +0,0 @@
1
- // @bun
2
- import{Lt,lr,fe,W}from"./index-8jk4a62x.js";import"./index-7wm4bqx5.js";export{Lt as PluginConfirmationRequiredError,W as PluginManager,lr as getPluginPackageRoot,fe as validatePluginPackageName};
@@ -1,2 +0,0 @@
1
- // @bun
2
- import{qt,Cr}from"./index-vhz1c474.js";import"./index-0rmmrrfh.js";import"./index-x4z055t8.js";import"./index-7wm4bqx5.js";export{Cr as readPrereqState,qt as runPluginPrereqs};
@@ -1,2 +0,0 @@
1
- // @bun
2
- import{_t,nn,$r}from"./index-p7fbnfwd.js";import"./index-qzwbctkv.js";import"./index-x4z055t8.js";import"./index-1t74r13z.js";import"./index-j99tkngg.js";import"./index-7wm4bqx5.js";export{$r as dispatchProfileRequest,_t as mountProfileRoutes,nn as unmountProfileRoutes};
@@ -1,2 +0,0 @@
1
- // @bun
2
- import{Mr}from"./index-q4fht6h2.js";import"./index-zcnfj1q4.js";import"./index-0rmmrrfh.js";import"./index-4kf3nr14.js";import"./index-dr6rsnpk.js";import"./index-twtvt4yt.js";import"./index-8jk4a62x.js";import"./index-wxb9dgwq.js";import"./index-cn4p1ks0.js";import"./index-qzwbctkv.js";import"./index-x4z055t8.js";import"./index-1t74r13z.js";import"./index-v77bb0rm.js";import"./index-12gb48hg.js";import"./index-sq5j8bjn.js";import"./index-damc6cvc.js";import"./index-j99tkngg.js";import"./index-7wm4bqx5.js";export{Mr as registerCoreCommands};
@@ -1,2 +0,0 @@
1
- // @bun
2
- import{hi}from"./index-5tghd67e.js";import"./index-br9bakfm.js";import"./index-8jk4a62x.js";import"./index-p7fbnfwd.js";import"./index-qzwbctkv.js";import"./index-x4z055t8.js";import"./index-1t74r13z.js";import"./index-j99tkngg.js";import"./index-7wm4bqx5.js";export{hi as attachSecondaryProfile};
@@ -1,2 +0,0 @@
1
- // @bun
2
- import{wr,qr,en}from"./index-ednz6yz2.js";import"./index-7wm4bqx5.js";export{en as killAllTracked,qr as listTrackedByOwner,wr as spawnTracked};
@@ -1,2 +0,0 @@
1
- // @bun
2
- import{Z}from"./index-wxb9dgwq.js";import"./index-cn4p1ks0.js";import"./index-7wm4bqx5.js";export{Z as telemetryService};
@@ -1,2 +0,0 @@
1
- // @bun
2
- import{or,Nr,rn,ar,lt}from"./index-dr6rsnpk.js";import"./index-wxb9dgwq.js";import"./index-cn4p1ks0.js";import"./index-7wm4bqx5.js";export{lt as getBootstrapTunnelUrl,or as sanitizeEnvSuffix,Nr as startBootstrapTunnel,ar as stopBootstrapTunnel,rn as tryHandoverBootstrapTunnel};