@vibecontrols/agent 2026.902.1 → 2026.1125.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.
- package/dist/agent-config-v9d7gcz0.js +2 -0
- package/dist/agent-ready-tracker-mewxehg9.js +2 -0
- package/dist/app-a95wetk5.js +2 -0
- package/dist/autostart.cmd-ahet7b1t.js +2 -0
- package/dist/bootstrap-workspace-3pb8qjsh.js +2 -0
- package/dist/bootstrap.service-9m7m1ksa.js +2 -0
- package/dist/bridge-client-xvqy3n15.js +2 -0
- package/dist/cli.js +2 -2
- package/dist/daemon-profile-sg8fp50z.js +2 -0
- package/dist/finalize-retry-handle-registry-z9mbbjmj.js +2 -0
- package/dist/finalize-retry-worker-az74f2qv.js +2 -0
- package/dist/gateway-client-ermpz52n.js +2 -0
- package/dist/getMachineId-bsd-4w1wmcjv.js +2 -0
- package/dist/getMachineId-darwin-kejwz8w5.js +3 -0
- package/dist/getMachineId-linux-mpm53wat.js +2 -0
- package/dist/getMachineId-unsupported-54seyw5v.js +2 -0
- package/dist/getMachineId-win-cva7ghz9.js +2 -0
- package/dist/highlights-3nz7pbkh.js +2 -0
- package/dist/highlights-6dgztt5d.js +2 -0
- package/dist/highlights-jq0g1547.js +2 -0
- package/dist/highlights-yc7cwzcr.js +2 -0
- package/dist/highlights-z2sw1kpq.js +2 -0
- package/dist/index-01fp85ft.js +171 -0
- package/dist/index-0gmhd3hs.js +4 -0
- package/dist/index-0qjbnyg4.js +21 -0
- package/dist/index-2r6cmxxz.js +9 -0
- package/dist/index-2vcxt38h.js +3 -0
- package/dist/index-4527yp1c.js +178 -0
- package/dist/index-4z1y39jt.js +3 -0
- package/dist/index-5021rk8n.js +3 -0
- package/dist/index-652f9scs.js +4 -0
- package/dist/index-75hk5q9s.js +13 -0
- package/dist/index-76m37yd8.js +22 -0
- package/dist/index-7f2k4g6q.js +8 -0
- package/dist/index-7gk1x74m.js +15 -0
- package/dist/index-7wben1jx.js +3 -0
- package/dist/index-8rbhm4g8.js +7 -0
- package/dist/index-9xrhb68w.js +14 -0
- package/dist/index-a0vx2zyx.js +3 -0
- package/dist/index-akk3rxnn.js +4 -0
- package/dist/index-b3v08awy.js +3 -0
- package/dist/index-byerrz46.js +3 -0
- package/dist/index-c4whjk5r.js +3 -0
- package/dist/index-cy97asyh.js +133 -0
- package/dist/index-d59kp6zr.js +3 -0
- package/dist/index-ec08v08h.js +116 -0
- package/dist/index-g08z6z5v.js +5 -0
- package/dist/index-gaztfvyz.js +158 -0
- package/dist/index-gnb8xw13.js +83 -0
- package/dist/index-haww9jpq.js +27 -0
- package/dist/index-hsrt2v87.js +2 -0
- package/dist/index-jmx5awkj.js +3 -0
- package/dist/index-jnxjjx2y.js +3 -0
- package/dist/index-kwhx023z.js +11 -0
- package/dist/index-mmx2kp76.js +16 -0
- package/dist/index-ne8q0a64.js +26 -0
- package/dist/index-nzfqdhsx.js +11 -0
- package/dist/index-qe3xpt41.js +3 -0
- package/dist/index-qfxwk38p.js +82 -0
- package/dist/index-ss5gez2p.js +2 -0
- package/dist/index-t5cfkz1e.js +4 -0
- package/dist/index-t6p4szqx.js +5 -0
- package/dist/index-tahaxp6n.js +3 -0
- package/dist/index-v16qz1fa.js +3 -0
- package/dist/index-v35k2y31.js +17 -0
- package/dist/index-vtsd74g0.js +9 -0
- package/dist/index-w0m3jm0s.js +408 -0
- package/dist/index-w4jqdhc2.js +5 -0
- package/dist/index-xtd0j8ve.js +3 -0
- package/dist/index-ywnfz6nm.js +3 -0
- package/dist/index.js +3 -3
- package/dist/injections-h25c1fmk.js +2 -0
- package/dist/interactive-vbz68zh5.js +2 -0
- package/dist/key.cmd-f6rjvjy8.js +2 -0
- package/dist/log-shipper-0erbwn0q.js +2 -0
- package/dist/path-utils-r4df8d3w.js +2 -0
- package/dist/plugin-system-zj50tg4k.js +2 -0
- package/dist/prereqs-runner-gca0bytz.js +2 -0
- package/dist/profile-mount-s4mc1x18.js +2 -0
- package/dist/prune-stale-shims-4nqtv0xt.js +2 -0
- package/dist/register-core-vng5hdga.js +2 -0
- package/dist/secondary-profile-attach-pyqqf4ny.js +2 -0
- package/dist/subprocess-4gg77skg.js +2 -0
- package/dist/telemetry-nmtywcba.js +2 -0
- package/dist/tree-sitter-javascript-rfadfcwb.js +2 -0
- package/dist/tree-sitter-markdown-gkyb2qez.js +2 -0
- package/dist/tree-sitter-markdown_inline-xzttqkvb.js +2 -0
- package/dist/tree-sitter-typescript-4z897028.js +2 -0
- package/dist/tree-sitter-zig-y6n7djp6.js +2 -0
- package/dist/tunnel-bootstrap-zwyzxrkt.js +2 -0
- package/package.json +10 -9
- package/dist/agent-config-5b0avmy6.js +0 -2
- package/dist/agent-ready-tracker-ez6r9djg.js +0 -2
- package/dist/app-mhms2gs0.js +0 -2
- package/dist/autostart.cmd-4zb9xhj0.js +0 -2
- package/dist/bootstrap-workspace-t5fyq07m.js +0 -2
- package/dist/bootstrap.service-nxhkrsf1.js +0 -2
- package/dist/bridge-client-bgkr7bcn.js +0 -2
- package/dist/daemon-profile-j2wt35x8.js +0 -2
- package/dist/esm-n9r8p5n2.js +0 -2
- package/dist/finalize-retry-handle-registry-fvm4gm8s.js +0 -2
- package/dist/finalize-retry-worker-wb8wj1yw.js +0 -2
- package/dist/gateway-client-6dqagbg4.js +0 -2
- package/dist/getMachineId-bsd-fgatzdd7.js +0 -2
- package/dist/getMachineId-darwin-gt8j2jw2.js +0 -3
- package/dist/getMachineId-linux-bcz4rr1x.js +0 -2
- package/dist/getMachineId-unsupported-079qwwb4.js +0 -2
- package/dist/getMachineId-win-2hk4e8bg.js +0 -2
- package/dist/highlights-0gfz787m.js +0 -2
- package/dist/highlights-86sbx76f.js +0 -2
- package/dist/highlights-n55f5jnk.js +0 -2
- package/dist/highlights-tbmszdr7.js +0 -2
- package/dist/highlights-wm2cs773.js +0 -2
- package/dist/index-06es0fmw.js +0 -10
- package/dist/index-0d4wfjbt.js +0 -171
- package/dist/index-29fmptfn.js +0 -13
- package/dist/index-2q2jadag.js +0 -11
- package/dist/index-2sn36kaj.js +0 -7
- package/dist/index-3p4n7nwg.js +0 -83
- package/dist/index-3tf12pw3.js +0 -3
- package/dist/index-54mmh1eb.js +0 -4
- package/dist/index-6jzsthh9.js +0 -3
- package/dist/index-7wejfjj9.js +0 -5
- package/dist/index-8q19ryt2.js +0 -28
- package/dist/index-8xh8m2z7.js +0 -8
- package/dist/index-98gr644s.js +0 -116
- package/dist/index-a8n6s2ae.js +0 -2
- package/dist/index-b16y8wyz.js +0 -15
- package/dist/index-bv1z3fxw.js +0 -3
- package/dist/index-cs78wq6y.js +0 -3
- package/dist/index-df19rrbe.js +0 -5
- package/dist/index-dx9hjdp4.js +0 -178
- package/dist/index-ea42kfvk.js +0 -5
- package/dist/index-ekr40gvh.js +0 -3
- package/dist/index-evnbrmdf.js +0 -4
- package/dist/index-f2asckf0.js +0 -26
- package/dist/index-ggxs7nwz.js +0 -3
- package/dist/index-gz5t0vvc.js +0 -4
- package/dist/index-hey6w5m0.js +0 -3
- package/dist/index-hp8jrj6j.js +0 -3
- package/dist/index-hrfkzecw.js +0 -3
- package/dist/index-hwpmdq5z.js +0 -4
- package/dist/index-hz5cy6vz.js +0 -11
- package/dist/index-jbxh0ffn.js +0 -407
- package/dist/index-js2r0men.js +0 -9
- package/dist/index-k3jkzj3k.js +0 -9
- package/dist/index-kteawn2b.js +0 -3
- package/dist/index-mbhq916m.js +0 -3
- package/dist/index-mxc61yr1.js +0 -3
- package/dist/index-qdbxvcwr.js +0 -17
- package/dist/index-qqq9qyy6.js +0 -21
- package/dist/index-rmh8pff5.js +0 -3
- package/dist/index-sspydg85.js +0 -15
- package/dist/index-tk81f249.js +0 -3
- package/dist/index-vjdg5qb2.js +0 -2
- package/dist/index-vkrf8kzp.js +0 -158
- package/dist/index-vnxqna70.js +0 -16
- package/dist/index-w7gctzhm.js +0 -83
- package/dist/index-wj5hx7gq.js +0 -4
- package/dist/index-x4eaagvr.js +0 -3
- package/dist/index-xjr60th0.js +0 -3
- package/dist/index-xtbppqnv.js +0 -3
- package/dist/index-y42xsgr6.js +0 -133
- package/dist/index-zr9rmjyp.js +0 -3
- package/dist/injections-2g0zh0bq.js +0 -2
- package/dist/interactive-08vyaapn.js +0 -2
- package/dist/key.cmd-642xcxb4.js +0 -2
- package/dist/log-shipper-9xfnjwr6.js +0 -2
- package/dist/path-utils-g449hqvm.js +0 -2
- package/dist/plugin-system-gpzcch00.js +0 -2
- package/dist/prereqs-runner-re9f51fp.js +0 -2
- package/dist/profile-mount-txvgkaz8.js +0 -2
- package/dist/prune-stale-shims-vs6a07tb.js +0 -2
- package/dist/register-core-ma4kse87.js +0 -2
- package/dist/secondary-profile-attach-m9x9e7py.js +0 -2
- package/dist/subprocess-zcgpccp1.js +0 -2
- package/dist/telemetry-k6em3vy2.js +0 -2
- package/dist/tree-sitter-javascript-qh90w7td.js +0 -2
- package/dist/tree-sitter-markdown-favzteb6.js +0 -2
- package/dist/tree-sitter-markdown_inline-x2726t9j.js +0 -2
- package/dist/tree-sitter-typescript-m7ep8z1h.js +0 -2
- package/dist/tree-sitter-zig-3vsxg5wh.js +0 -2
- package/dist/tunnel-bootstrap-y8dczezc.js +0 -2
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{I,C,e}from"./index-0qjbnyg4.js";import{existsSync as l,mkdirSync as a,readFileSync as p,appendFileSync as m,writeFileSync as u}from"fs";import{join as b,relative as y,resolve as c,isAbsolute as h}from"path";var o=".boff/",S=new Set([".boff",".boff/","/.boff","/.boff/"]);function Sr(){a(I(),{recursive:!0}),w()}function w(){let f=c(C()),i=c(process.cwd()),s=y(i,f);if(s.startsWith("..")||h(s))return;let t=b(i,".gitignore");if(!l(t)){u(t,`${o}
|
|
3
|
+
`,{mode:420}),e().logger.info("bootstrap",`Created .gitignore with ${o}`);return}let r=p(t,"utf8");if(r.split(/\r?\n/).some((g)=>{let n=g.trim();if(!n||n.startsWith("#"))return!1;return S.has(n)}))return;let d=r.length>0&&!r.endsWith(`
|
|
4
|
+
`);m(t,`${d?`
|
|
5
|
+
`:""}${o}
|
|
6
|
+
`),e().logger.info("bootstrap",`Appended ${o} to .gitignore`)}
|
|
7
|
+
export{Sr};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{x,Oe}from"./index-7wben1jx.js";import{P}from"./index-a0vx2zyx.js";function O(t){let e=Object.keys(t);if(e.length===0)return"";return e=e.sort(),JSON.stringify(e.map((r)=>[r,t[r]]))}function At(t){return`${t.name}:${t.version??""}:${t.schemaUrl??""}`}var Ne=class t extends Error{constructor(e){super(e);Object.setPrototypeOf(this,t.prototype)}};function T(t,e){let r,i=new Promise(function(s,o){r=setTimeout(function(){o(new Ne("Operation timed out."))},e)});return Promise.race([t,i]).then((n)=>(clearTimeout(r),n),(n)=>{throw clearTimeout(r),n})}function Mt(t,e){if(t.size!==e.size)return!1;for(let r of t)if(!e.has(r))return!1;return!0}function wt(t,e){let r=0,i=t.length-1,n=t.length;while(i>=r){let s=r+Math.trunc((i-r)/2);if(t[s]<e)r=s+1;else n=s,i=s-1}return n}function yt(t,e){return t.toLowerCase()===e.toLowerCase()}var Et=class{kind=0;createAccumulation(){}merge(t,e){}diff(t,e){}toMetricData(t,e,r,i){}};function xe(t){let e=t.map(()=>0);return e.push(0),{buckets:{boundaries:t,counts:e},sum:0,count:0,hasMinMax:!1,min:1/0,max:-1/0}}var Z=class{startTime;_boundaries;_recordMinMax;_current;constructor(t,e,r=!0,i=xe(e)){this.startTime=t,this._boundaries=e,this._recordMinMax=r,this._current=i}record(t){if(Number.isNaN(t))return;if(this._current.count+=1,this._current.sum+=t,this._recordMinMax)this._current.min=Math.min(t,this._current.min),this._current.max=Math.max(t,this._current.max),this._current.hasMinMax=!0;let e=wt(this._boundaries,t);this._current.buckets.counts[e]+=1}setStartTime(t){this.startTime=t}toPointValue(){return this._current}},Q=class{kind=3;_boundaries;_recordMinMax;constructor(t,e){this._boundaries=t,this._recordMinMax=e}createAccumulation(t){return new Z(t,this._boundaries,this._recordMinMax)}merge(t,e){let r=t.toPointValue(),i=e.toPointValue(),n=r.buckets.counts,s=i.buckets.counts,o=Array(n.length);for(let u=0;u<n.length;u++)o[u]=n[u]+s[u];let a=1/0,c=-1/0;if(this._recordMinMax){if(r.hasMinMax&&i.hasMinMax)a=Math.min(r.min,i.min),c=Math.max(r.max,i.max);else if(r.hasMinMax)a=r.min,c=r.max;else if(i.hasMinMax)a=i.min,c=i.max}return new Z(t.startTime,r.buckets.boundaries,this._recordMinMax,{buckets:{boundaries:r.buckets.boundaries,counts:o},count:r.count+i.count,sum:r.sum+i.sum,hasMinMax:this._recordMinMax&&(r.hasMinMax||i.hasMinMax),min:a,max:c})}diff(t,e){let r=t.toPointValue(),i=e.toPointValue(),n=r.buckets.counts,s=i.buckets.counts,o=Array(n.length);for(let a=0;a<n.length;a++)o[a]=s[a]-n[a];return new Z(e.startTime,r.buckets.boundaries,this._recordMinMax,{buckets:{boundaries:r.buckets.boundaries,counts:o},count:i.count-r.count,sum:i.sum-r.sum,hasMinMax:!1,min:1/0,max:-1/0})}toMetricData(t,e,r,i){return{descriptor:t,aggregationTemporality:e,dataPointType:0,dataPoints:r.map(([n,s])=>{let o=s.toPointValue(),a=t.type==="GAUGE"||t.type==="UP_DOWN_COUNTER"||t.type==="OBSERVABLE_GAUGE"||t.type==="OBSERVABLE_UP_DOWN_COUNTER";return{attributes:n,startTime:s.startTime,endTime:i,value:{min:o.hasMinMax?o.min:void 0,max:o.hasMinMax?o.max:void 0,sum:!a?o.sum:void 0,buckets:o.buckets,count:o.count}}})}}};var tt=class t{backing;indexBase;indexStart;indexEnd;constructor(e=new Ie,r=0,i=0,n=0){this.backing=e,this.indexBase=r,this.indexStart=i,this.indexEnd=n}get offset(){return this.indexStart}get length(){if(this.backing.length===0)return 0;if(this.indexEnd===this.indexStart&&this.at(0)===0)return 0;return this.indexEnd-this.indexStart+1}counts(){return Array.from({length:this.length},(e,r)=>this.at(r))}at(e){let r=this.indexBase-this.indexStart;if(e<r)e+=this.backing.length;return e-=r,this.backing.countAt(e)}incrementBucket(e,r){this.backing.increment(e,r)}decrementBucket(e,r){this.backing.decrement(e,r)}trim(){for(let e=0;e<this.length;e++)if(this.at(e)!==0){this.indexStart+=e;break}else if(e===this.length-1){this.indexStart=this.indexEnd=this.indexBase=0;return}for(let e=this.length-1;e>=0;e--)if(this.at(e)!==0){this.indexEnd-=this.length-e-1;break}this._rotate()}downscale(e){this._rotate();let r=1+this.indexEnd-this.indexStart,i=1<<e,n=0,s=0;for(let o=this.indexStart;o<=this.indexEnd;){let a=o%i;if(a<0)a+=i;for(let c=a;c<i&&n<r;c++)this._relocateBucket(s,n),n++,o++;s++}this.indexStart>>=e,this.indexEnd>>=e,this.indexBase=this.indexStart}clone(){return new t(this.backing.clone(),this.indexBase,this.indexStart,this.indexEnd)}_rotate(){let e=this.indexBase-this.indexStart;if(e===0)return;else if(e>0)this.backing.reverse(0,this.backing.length),this.backing.reverse(0,e),this.backing.reverse(e,this.backing.length);else this.backing.reverse(0,this.backing.length),this.backing.reverse(0,this.backing.length+e);this.indexBase=this.indexStart}_relocateBucket(e,r){if(e===r)return;this.incrementBucket(e,this.backing.emptyBucket(r))}},Ie=class t{_counts;constructor(e=[0]){this._counts=e}get length(){return this._counts.length}countAt(e){return this._counts[e]}growTo(e,r,i){let n=Array(e).fill(0);n.splice(i,this._counts.length-r,...this._counts.slice(r)),n.splice(0,r,...this._counts.slice(0,r)),this._counts=n}reverse(e,r){let i=Math.floor((e+r)/2)-e;for(let n=0;n<i;n++){let s=this._counts[e+n];this._counts[e+n]=this._counts[r-n-1],this._counts[r-n-1]=s}}emptyBucket(e){let r=this._counts[e];return this._counts[e]=0,r}increment(e,r){this._counts[e]+=r}decrement(e,r){if(this._counts[e]>=r)this._counts[e]-=r;else this._counts[e]=0}clone(){return new t([...this._counts])}};function v(t,e){if(t===0||t===Number.POSITIVE_INFINITY||t===Number.NEGATIVE_INFINITY||Number.isNaN(t))return t;return t*Math.pow(2,e)}function vt(t){return t--,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,t|=t>>16,t++,t}var _=class extends Error{};var L=-1022,k=1023,N=Math.pow(2,-1022),et=new DataView(new ArrayBuffer(8));function Nt(t){return et.setFloat64(0,t),{hi:et.getUint32(0),lo:et.getUint32(4)}}function U(t){let{hi:e}=Nt(t);return((e&2146435072)>>20)-1023}function D(t){let{hi:e,lo:r}=Nt(t);return(e&1048575)===0&&r===0}var xt=class{_shift;constructor(t){this._shift=-t}mapToIndex(t){if(t<N)return this._minNormalLowerBoundaryIndex();return U(t)+(D(t)?-1:0)>>this._shift}lowerBoundary(t){let e=this._minNormalLowerBoundaryIndex();if(t<e)throw new _(`underflow: ${t} is < minimum lower boundary: ${e}`);let r=this._maxNormalLowerBoundaryIndex();if(t>r)throw new _(`overflow: ${t} is > maximum lower boundary: ${r}`);return v(1,t<<this._shift)}get scale(){if(this._shift===0)return 0;return-this._shift}_minNormalLowerBoundaryIndex(){let t=L>>this._shift;if(this._shift<2)t--;return t}_maxNormalLowerBoundaryIndex(){return k>>this._shift}};var It=class{_scale;_scaleFactor;_inverseFactor;constructor(t){this._scale=t,this._scaleFactor=v(Math.LOG2E,t),this._inverseFactor=v(Math.LN2,-t)}mapToIndex(t){if(t<=N)return this._minNormalLowerBoundaryIndex()-1;if(D(t))return(U(t)<<this._scale)-1;let e=Math.floor(Math.log(t)*this._scaleFactor),r=this._maxNormalLowerBoundaryIndex();if(e>=r)return r;return e}lowerBoundary(t){let e=this._maxNormalLowerBoundaryIndex();if(t>=e){if(t===e)return 2*Math.exp((t-(1<<this._scale))/this._scaleFactor);throw new _(`overflow: ${t} is > maximum lower boundary: ${e}`)}let r=this._minNormalLowerBoundaryIndex();if(t<=r){if(t===r)return N;else if(t===r-1)return Math.exp((t+(1<<this._scale))/this._scaleFactor)/2;throw new _(`overflow: ${t} is < minimum lower boundary: ${r}`)}return Math.exp(t*this._inverseFactor)}get scale(){return this._scale}_minNormalLowerBoundaryIndex(){return L<<this._scale}_maxNormalLowerBoundaryIndex(){return(k+1<<this._scale)-1}};var Ct=-10,Rt=20,Ce=Array.from({length:31},(t,e)=>{if(e>10)return new It(e-10);return new xt(e-10)});function rt(t){if(t>Rt||t<Ct)throw new _(`expected scale >= ${Ct} && <= ${Rt}, got: ${t}`);return Ce[t+10]}var Ot=P(x(),1),B=class t{static combine(e,r){return new t(Math.min(e.low,r.low),Math.max(e.high,r.high))}low;high;constructor(e,r){this.low=e,this.high=r}},Re=20,Pe=160,it=2,Le=class t{startTime;_maxSize;_recordMinMax;_sum;_count;_zeroCount;_min;_max;_positive;_negative;_mapping;constructor(e,r=Pe,i=!0,n=0,s=0,o=0,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,u=new tt,E=new tt,J=rt(Re)){if(this.startTime=e,this._maxSize=r,this._recordMinMax=i,this._sum=n,this._count=s,this._zeroCount=o,this._min=a,this._max=c,this._positive=u,this._negative=E,this._mapping=J,this._maxSize<it)Ot.diag.warn(`Exponential Histogram Max Size set to ${this._maxSize}, changing to the minimum size of: ${it}`),this._maxSize=it}record(e){this.updateByIncrement(e,1)}setStartTime(e){this.startTime=e}toPointValue(){return{hasMinMax:this._recordMinMax,min:this.min,max:this.max,sum:this.sum,positive:{offset:this.positive.offset,bucketCounts:this.positive.counts()},negative:{offset:this.negative.offset,bucketCounts:this.negative.counts()},count:this.count,scale:this.scale,zeroCount:this.zeroCount}}get sum(){return this._sum}get min(){return this._min}get max(){return this._max}get count(){return this._count}get zeroCount(){return this._zeroCount}get scale(){if(this._count===this._zeroCount)return 0;return this._mapping.scale}get positive(){return this._positive}get negative(){return this._negative}updateByIncrement(e,r){if(!Number.isFinite(e))return;if(e>this._max)this._max=e;if(e<this._min)this._min=e;if(this._count+=r,e===0){this._zeroCount+=r;return}if(this._sum+=e*r,e>0)this._updateBuckets(this._positive,e,r);else this._updateBuckets(this._negative,-e,r)}merge(e){if(this._count===0)this._min=e.min,this._max=e.max;else if(e.count!==0){if(e.min<this.min)this._min=e.min;if(e.max>this.max)this._max=e.max}this.startTime=e.startTime,this._sum+=e.sum,this._count+=e.count,this._zeroCount+=e.zeroCount;let r=this._minScale(e);this._downscale(this.scale-r),this._mergeBuckets(this.positive,e,e.positive,r),this._mergeBuckets(this.negative,e,e.negative,r)}diff(e){this._min=1/0,this._max=-1/0,this._sum-=e.sum,this._count-=e.count,this._zeroCount-=e.zeroCount;let r=this._minScale(e);this._downscale(this.scale-r),this._diffBuckets(this.positive,e,e.positive,r),this._diffBuckets(this.negative,e,e.negative,r)}clone(){return new t(this.startTime,this._maxSize,this._recordMinMax,this._sum,this._count,this._zeroCount,this._min,this._max,this.positive.clone(),this.negative.clone(),this._mapping)}_updateBuckets(e,r,i){let n=this._mapping.mapToIndex(r),s=!1,o=0,a=0;if(e.length===0)e.indexStart=n,e.indexEnd=e.indexStart,e.indexBase=e.indexStart;else if(n<e.indexStart&&e.indexEnd-n>=this._maxSize)s=!0,a=n,o=e.indexEnd;else if(n>e.indexEnd&&n-e.indexStart>=this._maxSize)s=!0,a=e.indexStart,o=n;if(s){let c=this._changeScale(o,a);this._downscale(c),n=this._mapping.mapToIndex(r)}this._incrementIndexBy(e,n,i)}_incrementIndexBy(e,r,i){if(i===0)return;if(e.length===0)e.indexStart=e.indexEnd=e.indexBase=r;if(r<e.indexStart){let s=e.indexEnd-r;if(s>=e.backing.length)this._grow(e,s+1);e.indexStart=r}else if(r>e.indexEnd){let s=r-e.indexStart;if(s>=e.backing.length)this._grow(e,s+1);e.indexEnd=r}let n=r-e.indexBase;if(n<0)n+=e.backing.length;e.incrementBucket(n,i)}_grow(e,r){let i=e.backing.length,n=e.indexBase-e.indexStart,s=i-n,o=vt(r);if(o>this._maxSize)o=this._maxSize;let a=o-n;e.backing.growTo(o,s,a)}_changeScale(e,r){let i=0;while(e-r>=this._maxSize)e>>=1,r>>=1,i++;return i}_downscale(e){if(e===0)return;if(e<0)throw Error(`impossible change of scale: ${this.scale}`);let r=this._mapping.scale-e;this._positive.downscale(e),this._negative.downscale(e),this._mapping=rt(r)}_minScale(e){let r=Math.min(this.scale,e.scale),i=B.combine(this._highLowAtScale(this.positive,this.scale,r),this._highLowAtScale(e.positive,e.scale,r)),n=B.combine(this._highLowAtScale(this.negative,this.scale,r),this._highLowAtScale(e.negative,e.scale,r));return Math.min(r-this._changeScale(i.high,i.low),r-this._changeScale(n.high,n.low))}_highLowAtScale(e,r,i){if(e.length===0)return new B(0,-1);let n=r-i;return new B(e.indexStart>>n,e.indexEnd>>n)}_mergeBuckets(e,r,i,n){let s=i.offset,o=r.scale-n;for(let a=0;a<i.length;a++)this._incrementIndexBy(e,s+a>>o,i.at(a))}_diffBuckets(e,r,i,n){let s=i.offset,o=r.scale-n;for(let a=0;a<i.length;a++){let c=(s+a>>o)-e.indexBase;if(c<0)c+=e.backing.length;e.decrementBucket(c,i.at(a))}e.trim()}},Pt=class{kind=4;_maxSize;_recordMinMax;constructor(t,e){this._maxSize=t,this._recordMinMax=e}createAccumulation(t){return new Le(t,this._maxSize,this._recordMinMax)}merge(t,e){let r=e.clone();return r.merge(t),r}diff(t,e){let r=e.clone();return r.diff(t),r}toMetricData(t,e,r,i){return{descriptor:t,aggregationTemporality:e,dataPointType:1,dataPoints:r.map(([n,s])=>{let o=s.toPointValue(),a=t.type==="GAUGE"||t.type==="UP_DOWN_COUNTER"||t.type==="OBSERVABLE_GAUGE"||t.type==="OBSERVABLE_UP_DOWN_COUNTER";return{attributes:n,startTime:s.startTime,endTime:i,value:{min:o.hasMinMax?o.min:void 0,max:o.hasMinMax?o.max:void 0,sum:!a?o.sum:void 0,positive:{offset:o.positive.offset,bucketCounts:o.positive.bucketCounts},negative:{offset:o.negative.offset,bucketCounts:o.negative.bucketCounts},count:o.count,scale:o.scale,zeroCount:o.zeroCount}}})}}};function nt(t){if(Array.isArray(t))return ke(t);return Lt(typeof t)}function ke(t){let e;for(let r of t){if(r==null)continue;let i=typeof r;if(i===e)continue;if(!e){if(Lt(i)){e=i;continue}return!1}return!1}return!0}function Lt(t){switch(t){case"number":case"boolean":case"string":return!0}return!1}var Ue=Math.pow(10,6),V=Math.pow(10,9);function g(t){let e=t/1000;return[Math.trunc(e),Math.round(t%1000*Ue)]}function F(t){return kt(g(performance.timeOrigin),g(typeof t==="number"?t:performance.now()))}function st(t,e){let r=e[0]-t[0],i=e[1]-t[1];if(i<0)r-=1,i+=V;return[r,i]}function A(t){return t[0]*1e6+t[1]/1000}function ot(t){return t[0]+t[1]/V}function kt(t,e){let r=[t[0]+e[0],t[1]+e[1]];if(r[1]>=V)r[1]-=V,r[0]+=1;return r}var Ut="3.0.0";var Dt="process.runtime.name";var d=P(Oe(),1),M={[d.ATTR_TELEMETRY_SDK_NAME]:"opentelemetry",[Dt]:"node",[d.ATTR_TELEMETRY_SDK_LANGUAGE]:d.TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS,[d.ATTR_TELEMETRY_SDK_VERSION]:Ut};var at=class{startTime;_current;sampleTime;constructor(t,e=0,r=[0,0]){this.startTime=t,this._current=e,this.sampleTime=r}record(t){this._current=t,this.sampleTime=g(Date.now())}setStartTime(t){this.startTime=t}toPointValue(){return this._current}},Bt=class{kind=2;createAccumulation(t){return new at(t)}merge(t,e){let r=A(e.sampleTime)>=A(t.sampleTime)?e:t;return new at(t.startTime,r.toPointValue(),r.sampleTime)}diff(t,e){let r=A(e.sampleTime)>=A(t.sampleTime)?e:t;return new at(e.startTime,r.toPointValue(),r.sampleTime)}toMetricData(t,e,r,i){return{descriptor:t,aggregationTemporality:e,dataPointType:2,dataPoints:r.map(([n,s])=>({attributes:n,startTime:s.startTime,endTime:i,value:s.toPointValue()}))}}};var I=class{startTime;monotonic;_current;reset;constructor(t,e,r=0,i=!1){this.startTime=t,this.monotonic=e,this._current=r,this.reset=i}record(t){if(this.monotonic&&t<0)return;this._current+=t}setStartTime(t){this.startTime=t}toPointValue(){return this._current}},ct=class{kind=1;monotonic;constructor(t){this.monotonic=t}createAccumulation(t){return new I(t,this.monotonic)}merge(t,e){let r=t.toPointValue(),i=e.toPointValue();if(e.reset)return new I(e.startTime,this.monotonic,i,e.reset);return new I(t.startTime,this.monotonic,r+i)}diff(t,e){let r=t.toPointValue(),i=e.toPointValue();if(this.monotonic&&r>i)return new I(e.startTime,this.monotonic,i,!0);return new I(e.startTime,this.monotonic,i-r)}toMetricData(t,e,r,i){return{descriptor:t,aggregationTemporality:e,dataPointType:3,dataPoints:r.map(([n,s])=>({attributes:n,startTime:s.startTime,endTime:i,value:s.toPointValue()})),isMonotonic:this.monotonic}}};var Vt=P(x(),1),De=class t{static DEFAULT_INSTANCE=new Et;createAggregator(e){return t.DEFAULT_INSTANCE}},Be=class t{static MONOTONIC_INSTANCE=new ct(!0);static NON_MONOTONIC_INSTANCE=new ct(!1);createAggregator(e){switch(e.type){case"COUNTER":case"OBSERVABLE_COUNTER":case"HISTOGRAM":return t.MONOTONIC_INSTANCE;default:return t.NON_MONOTONIC_INSTANCE}}},Ve=class t{static DEFAULT_INSTANCE=new Bt;createAggregator(e){return t.DEFAULT_INSTANCE}},Fe=class t{static DEFAULT_INSTANCE=new Q([0,5,10,25,50,75,100,250,500,750,1000,2500,5000,7500,1e4],!0);createAggregator(e){return t.DEFAULT_INSTANCE}},ut=class{_boundaries;_recordMinMax;constructor(t,e=!0){if(t==null)throw Error("ExplicitBucketHistogramAggregation should be created with explicit boundaries, if a single bucket histogram is required, please pass an empty array");t=t.concat(),t=t.sort((n,s)=>n-s);let r=t.lastIndexOf(-1/0),i=t.indexOf(1/0);if(i===-1)i=void 0;this._boundaries=t.slice(r+1,i),this._recordMinMax=e}createAggregator(t){return new Q(this._boundaries,this._recordMinMax)}},lt=class{_maxSize;_recordMinMax;constructor(t=160,e=!0){this._maxSize=t,this._recordMinMax=e}createAggregator(t){return new Pt(this._maxSize,this._recordMinMax)}},Ge=class{_resolve(t){switch(t.type){case"COUNTER":case"UP_DOWN_COUNTER":case"OBSERVABLE_COUNTER":case"OBSERVABLE_UP_DOWN_COUNTER":return ht;case"GAUGE":case"OBSERVABLE_GAUGE":return gt;case"HISTOGRAM":if(t.advice.explicitBucketBoundaries)return new ut(t.advice.explicitBucketBoundaries);return _t}return Vt.diag.warn(`Unable to recognize instrument type: ${t.type}`),mt}createAggregator(t){return this._resolve(t).createAggregator(t)}},mt=new De,ht=new Be,gt=new Ve,_t=new Fe;new lt;var Ft=new Ge;function G(t){switch(t.type){case 0:return Ft;case 1:return mt;case 2:return ht;case 3:return gt;case 5:{let e=t;return new lt(e.options?.maxSize,e.options?.recordMinMax)}case 4:{let e=t;if(e.options==null)return _t;else return new ut(e.options?.boundaries,e.options?.recordMinMax)}default:throw Error("Unsupported Aggregation")}}var Gt=(t)=>({type:0}),$t=(t)=>1;var Ht="otel.component.name",zt="otel.component.type";var Wt="otel.sdk.metric_reader.collection.duration",Xt="error.type";var jt=new Map,dt=class{collectionDuration;standardAttrs;constructor(t,e){let r=jt.get(t)??0;jt.set(t,r+1),this.standardAttrs={[zt]:t,[Ht]:`${t}/${r}`},this.collectionDuration=e.createHistogram(Wt,{unit:"s",description:"The duration of the collect operation of the metric reader.",advice:{explicitBucketBoundaries:[]}})}recordCollection(t,e){let r=e?{...this.standardAttrs,[Xt]:e}:this.standardAttrs;this.collectionDuration.record(t,r)}};var Kt="3.0.0";var C=P(x(),1);var Yt=class{_shutdown=!1;_metricProducers;_sdkMetricProducer;_selfObsMetrics;_aggregationTemporalitySelector;_aggregationSelector;_cardinalitySelector;_otelComponentType;constructor(t){this._aggregationSelector=t?.aggregationSelector??Gt,this._aggregationTemporalitySelector=t?.aggregationTemporalitySelector??$t,this._metricProducers=t?.metricProducers??[],this._cardinalitySelector=t?.cardinalitySelector,this._otelComponentType=t?.otelComponentType??this.constructor.name,this._selfObsMetrics=new dt(this._otelComponentType,C.createNoopMeter())}setMetricProducer(t){if(this._sdkMetricProducer)throw Error("MetricReader can not be bound to a MeterProvider again.");this._sdkMetricProducer=t,this.onInitialized()}_setSelfObsMeterProvider(t){let e=t.getMeter("@opentelemetry/sdk-metrics",Kt);this._selfObsMetrics=new dt(this._otelComponentType,e)}selectAggregation(t){return this._aggregationSelector(t)}selectAggregationTemporality(t){return this._aggregationTemporalitySelector(t)}selectCardinalityLimit(t){return this._cardinalitySelector?this._cardinalitySelector(t):2000}onInitialized(){}async collect(t){if(this._sdkMetricProducer===void 0)throw Error("MetricReader is not bound to a MetricProducer");if(this._shutdown)throw Error("MetricReader is shutdown");let e=F(),[r,...i]=await Promise.all([this._sdkMetricProducer.collect({timeoutMillis:t?.timeoutMillis}),...this._metricProducers.map((a)=>a.collect({timeoutMillis:t?.timeoutMillis}))]),n=F(),s=r.errors.concat(i.flatMap((a)=>a.errors)),o=ot(st(e,n));return this._selfObsMetrics.recordCollection(o,s.length>0?s[0].name??"collect_error":void 0),{resourceMetrics:{resource:r.resourceMetrics.resource,scopeMetrics:r.resourceMetrics.scopeMetrics.concat(i.flatMap((a)=>a.resourceMetrics.scopeMetrics))},errors:s}}async shutdown(t){if(this._shutdown){C.diag.error("Cannot call shutdown twice.");return}if(t?.timeoutMillis==null)await this.onShutdown();else await T(this.onShutdown(),t.timeoutMillis);this._shutdown=!0}async forceFlush(t){if(this._shutdown){C.diag.warn("Cannot forceFlush on already shutdown MetricReader.");return}if(t?.timeoutMillis==null){await this.onForceFlush();return}await T(this.onForceFlush(),t.timeoutMillis)}};var qt=class{_registeredViews=[];addView(t){this._registeredViews.push(t)}findViews(t,e){return this._registeredViews.filter((r)=>this._matchInstrument(r.instrumentSelector,t)&&this._matchMeter(r.meterSelector,e))}_matchInstrument(t,e){return(t.getType()===void 0||e.type===t.getType())&&t.getNameFilter().match(e.name)&&t.getUnitFilter().match(e.unit)}_matchMeter(t,e){return t.getNameFilter().match(e.name)&&(e.version===void 0||t.getVersionFilter().match(e.version))&&(e.schemaUrl===void 0||t.getSchemaUrlFilter().match(e.schemaUrl))}};var H=P(x(),1);function h(t,e,r){if(!He(t))H.diag.warn(`Invalid metric name: "${t}". The metric name should be a ASCII string with a length no greater than 255 characters.`);return{name:t,type:e,description:r?.description??"",unit:r?.unit??"",valueType:r?.valueType??H.ValueType.DOUBLE,advice:r?.advice??{}}}function Jt(t,e){return{name:t.name??e.name,description:t.description??e.description,type:e.type,unit:e.unit,valueType:e.valueType,advice:e.advice}}function Zt(t,e){return yt(t.name,e.name)&&t.unit===e.unit&&t.type===e.type&&t.valueType===e.valueType}var $e=/^[a-z][a-z0-9_.\-/]{0,254}$/i;function He(t){return $e.test(t)}var S=P(x(),1),z=class{_writableMetricStorage;_descriptor;constructor(t,e){this._writableMetricStorage=t,this._descriptor=e}_record(t,e={},r){if(typeof t!=="number"){S.diag.warn(`non-number value provided to metric ${this._descriptor.name}: ${t}`);return}if(this._descriptor.valueType===S.ValueType.INT&&!Number.isInteger(t)){if(S.diag.warn(`INT value type cannot accept a floating-point value for ${this._descriptor.name}, ignoring the fractional digits.`),t=Math.trunc(t),!Number.isInteger(t))return}this._writableMetricStorage.record(t,e,r,Date.now())}},Qt=class extends z{add(t,e,r){this._record(t,e,r)}},te=class extends z{add(t,e,r){if(t<0){S.diag.warn(`negative value provided to counter ${this._descriptor.name}: ${t}`);return}this._record(t,e,r)}},ee=class extends z{record(t,e,r){this._record(t,e,r)}},re=class extends z{record(t,e,r){if(t<0){S.diag.warn(`negative value provided to histogram ${this._descriptor.name}: ${t}`);return}this._record(t,e,r)}},W=class{_metricStorages;_descriptor;_observableRegistry;constructor(t,e,r){this._descriptor=t,this._metricStorages=e,this._observableRegistry=r}addCallback(t){this._observableRegistry.addCallback(t,this)}removeCallback(t){this._observableRegistry.removeCallback(t,this)}},ie=class extends W{},ne=class extends W{},se=class extends W{};function R(t){return t instanceof W}var oe=class{_meterSharedState;constructor(t){this._meterSharedState=t}createGauge(t,e){let r=h(t,"GAUGE",e),i=this._meterSharedState.registerMetricStorage(r);return new ee(i,r)}createHistogram(t,e){let r=h(t,"HISTOGRAM",e),i=this._meterSharedState.registerMetricStorage(r);return new re(i,r)}createCounter(t,e){let r=h(t,"COUNTER",e),i=this._meterSharedState.registerMetricStorage(r);return new te(i,r)}createUpDownCounter(t,e){let r=h(t,"UP_DOWN_COUNTER",e),i=this._meterSharedState.registerMetricStorage(r);return new Qt(i,r)}createObservableGauge(t,e){let r=h(t,"OBSERVABLE_GAUGE",e),i=this._meterSharedState.registerAsyncMetricStorage(r);return new ne(r,i,this._meterSharedState.observableRegistry)}createObservableCounter(t,e){let r=h(t,"OBSERVABLE_COUNTER",e),i=this._meterSharedState.registerAsyncMetricStorage(r);return new ie(r,i,this._meterSharedState.observableRegistry)}createObservableUpDownCounter(t,e){let r=h(t,"OBSERVABLE_UP_DOWN_COUNTER",e),i=this._meterSharedState.registerAsyncMetricStorage(r);return new se(r,i,this._meterSharedState.observableRegistry)}addBatchObservableCallback(t,e){this._meterSharedState.observableRegistry.addBatchCallback(t,e)}removeBatchObservableCallback(t,e){this._meterSharedState.observableRegistry.removeBatchCallback(t,e)}};var X=class{_instrumentDescriptor;constructor(t){this._instrumentDescriptor=t}getInstrumentDescriptor(){return this._instrumentDescriptor}updateDescription(t){this._instrumentDescriptor=h(this._instrumentDescriptor.name,this._instrumentDescriptor.type,{description:t,valueType:this._instrumentDescriptor.valueType,unit:this._instrumentDescriptor.unit,advice:this._instrumentDescriptor.advice})}};var ze=class{_valueMap=new Map;_keyMap=new Map;_hash;constructor(t){this._hash=t}get(t,e){return e??=this._hash(t),this._valueMap.get(e)}getOrDefault(t,e){let r=this._hash(t);if(this._valueMap.has(r))return this._valueMap.get(r);let i=e();if(!this._keyMap.has(r))this._keyMap.set(r,t);return this._valueMap.set(r,i),i}set(t,e,r){if(r??=this._hash(t),!this._keyMap.has(r))this._keyMap.set(r,t);this._valueMap.set(r,e)}has(t,e){return e??=this._hash(t),this._valueMap.has(e)}*keys(){let t=this._keyMap.entries(),e=t.next();while(e.done!==!0)yield[e.value[1],e.value[0]],e=t.next()}*entries(){let t=this._valueMap.entries(),e=t.next();while(e.done!==!0)yield[this._keyMap.get(e.value[0]),e.value[1],e.value[0]],e=t.next()}get size(){return this._valueMap.size}},l=class extends ze{constructor(){super(O)}};var j=class{_activeCollectionStorage=new l;_cumulativeMemoStorage=new l;_cardinalityLimit;_overflowAttributes={"otel.metric.overflow":!0};_overflowHashCode;_aggregator;constructor(t,e){this._aggregator=t,this._cardinalityLimit=(e??2000)-1,this._overflowHashCode=O(this._overflowAttributes)}record(t,e,r){let i=this._activeCollectionStorage.get(e);if(!i){let n=g(r);if(this._activeCollectionStorage.size>=this._cardinalityLimit){this._activeCollectionStorage.getOrDefault(this._overflowAttributes,()=>this._aggregator.createAccumulation(n))?.record(t);return}i=this._aggregator.createAccumulation(n),this._activeCollectionStorage.set(e,i)}i?.record(t)}batchCumulate(t,e){for(let[r,i,n]of t.entries()){let s=r,o=n,a=this._aggregator.createAccumulation(e);a?.record(i);let c=a;if(this._cumulativeMemoStorage.has(s,o)){let u=this._cumulativeMemoStorage.get(s,o);c=this._aggregator.diff(u,a)}else if(this._cumulativeMemoStorage.size>=this._cardinalityLimit){if(s=this._overflowAttributes,o=this._overflowHashCode,this._cumulativeMemoStorage.has(s,o)){let u=this._cumulativeMemoStorage.get(s,o);c=this._aggregator.diff(u,a)}}if(this._activeCollectionStorage.has(s,o)){let u=this._activeCollectionStorage.get(s,o);c=this._aggregator.merge(u,c)}this._cumulativeMemoStorage.set(s,a,o),this._activeCollectionStorage.set(s,c,o)}}collect(){let t=this._activeCollectionStorage;return this._activeCollectionStorage=new l,t}};var K=class t{_aggregator;_unreportedAccumulations=new Map;_reportHistory=new Map;constructor(e,r){this._aggregator=e,r.forEach((i)=>{this._unreportedAccumulations.set(i,[])})}buildMetrics(e,r,i,n){this._stashAccumulations(i);let s=this._getMergedUnreportedAccumulations(e),o=s,a;if(this._reportHistory.has(e)){let u=this._reportHistory.get(e),E=u.collectionTime;if(a=u.aggregationTemporality,a===1)o=t.merge(u.accumulations,s,this._aggregator);else o=t.calibrateStartTime(u.accumulations,s,E)}else a=e.selectAggregationTemporality(r.type);this._reportHistory.set(e,{accumulations:o,collectionTime:n,aggregationTemporality:a});let c=We(o);if(c.length===0)return;return this._aggregator.toMetricData(r,a,c,n)}_stashAccumulations(e){let r=this._unreportedAccumulations.keys();for(let i of r){let n=this._unreportedAccumulations.get(i);if(n===void 0)n=[],this._unreportedAccumulations.set(i,n);n.push(e)}}_getMergedUnreportedAccumulations(e){let r=new l,i=this._unreportedAccumulations.get(e);if(this._unreportedAccumulations.set(e,[]),i===void 0)return r;for(let n of i)r=t.merge(r,n,this._aggregator);return r}static merge(e,r,i){let n=e,s=r.entries(),o=s.next();while(o.done!==!0){let[a,c,u]=o.value;if(e.has(a,u)){let E=e.get(a,u),J=i.merge(E,c);n.set(a,J,u)}else n.set(a,c,u);o=s.next()}return n}static calibrateStartTime(e,r,i){for(let[n,s]of e.keys())r.get(n,s)?.setStartTime(i);return r}};function We(t){return Array.from(t.entries())}var ae=class extends X{_aggregationCardinalityLimit;_deltaMetricStorage;_temporalMetricStorage;_attributesProcessor;constructor(t,e,r,i,n){super(t);this._aggregationCardinalityLimit=n,this._deltaMetricStorage=new j(e,this._aggregationCardinalityLimit),this._temporalMetricStorage=new K(e,i),this._attributesProcessor=r}record(t,e){if(this._attributesProcessor===void 0){this._deltaMetricStorage.batchCumulate(t,e);return}let r=new l;for(let[i,n]of t.entries())r.set(this._attributesProcessor.process(i),n);this._deltaMetricStorage.batchCumulate(r,e)}collect(t,e){let r=this._deltaMetricStorage.collect();return this._temporalMetricStorage.buildMetrics(t,this._instrumentDescriptor,r,e)}};function ft(t,e){let r="";if(t.unit!==e.unit)r+=` - Unit '${t.unit}' does not match '${e.unit}'
|
|
3
|
+
`;if(t.type!==e.type)r+=` - Type '${t.type}' does not match '${e.type}'
|
|
4
|
+
`;if(t.valueType!==e.valueType)r+=` - Value Type '${t.valueType}' does not match '${e.valueType}'
|
|
5
|
+
`;if(t.description!==e.description)r+=` - Description '${t.description}' does not match '${e.description}'
|
|
6
|
+
`;return r}function Xe(t,e){return` - use valueType '${t.valueType}' on instrument creation or use an instrument name other than '${e.name}'`}function je(t,e){return` - use unit '${t.unit}' on instrument creation or use an instrument name other than '${e.name}'`}function Ke(t,e){let r={name:e.name,type:e.type,unit:e.unit},i=JSON.stringify(r);return` - create a new view with a name other than '${t.name}' and InstrumentSelector '${i}'`}function Ye(t,e){let r={name:e.name,type:e.type,unit:e.unit},i=JSON.stringify(r);return` - create a new view with a name other than '${t.name}' and InstrumentSelector '${i}'
|
|
7
|
+
- OR - create a new view with the name ${t.name} and description '${t.description}' and InstrumentSelector ${i}
|
|
8
|
+
- OR - create a new view with the name ${e.name} and description '${t.description}' and InstrumentSelector ${i}`}function pt(t,e){if(t.valueType!==e.valueType)return Xe(t,e);if(t.unit!==e.unit)return je(t,e);if(t.type!==e.type)return Ke(t,e);if(t.description!==e.description)return Ye(t,e);return""}var St=P(x(),1),ce=class t{_sharedRegistry=new Map;_perCollectorRegistry=new Map;static create(){return new t}getStorages(e){let r=[];for(let n of this._sharedRegistry.values())r=r.concat(n);let i=this._perCollectorRegistry.get(e);if(i!=null)for(let n of i.values())r=r.concat(n);return r}register(e){this._registerStorage(e,this._sharedRegistry)}registerForCollector(e,r){let i=this._perCollectorRegistry.get(e);if(i==null)i=new Map,this._perCollectorRegistry.set(e,i);this._registerStorage(r,i)}findOrUpdateCompatibleStorage(e){let r=this._sharedRegistry.get(e.name);if(r===void 0)return null;return this._findOrUpdateCompatibleStorage(e,r)}findOrUpdateCompatibleCollectorStorage(e,r){let i=this._perCollectorRegistry.get(e);if(i===void 0)return null;let n=i.get(r.name);if(n===void 0)return null;return this._findOrUpdateCompatibleStorage(r,n)}_registerStorage(e,r){let i=e.getInstrumentDescriptor(),n=r.get(i.name);if(n===void 0){r.set(i.name,[e]);return}n.push(e)}_findOrUpdateCompatibleStorage(e,r){let i=null;for(let n of r){let s=n.getInstrumentDescriptor();if(Zt(s,e)){if(s.description!==e.description){if(e.description.length>s.description.length)n.updateDescription(e.description);St.diag.warn("A view or instrument with the name ",e.name,` has already been registered, but has a different description and is incompatible with another registered view.
|
|
9
|
+
`,`Details:
|
|
10
|
+
`,ft(s,e),`The longer description will be used.
|
|
11
|
+
To resolve the conflict:`,pt(s,e))}i=n}else St.diag.warn("A view or instrument with the name ",e.name,` has already been registered and is incompatible with another registered view.
|
|
12
|
+
`,`Details:
|
|
13
|
+
`,ft(s,e),`To resolve the conflict:
|
|
14
|
+
`,pt(s,e))}return i}};var ue=P(x(),1),le=class{_backingStorages;hasAttributeProcessor;constructor(t){this._backingStorages=t,this.hasAttributeProcessor=t.some((e)=>e.hasAttributeProcessor)}record(t,e,r,i){if(this.hasAttributeProcessor&&r===void 0)r=ue.context.active();let n=this._backingStorages;for(let s=0;s<n.length;s++)n[s].record(t,e,r,i)}};var f=P(x(),1),me=class{_buffer=new l;_instrumentName;_valueType;constructor(t,e){this._instrumentName=t,this._valueType=e}observe(t,e={}){if(typeof t!=="number"){f.diag.warn(`non-number value provided to metric ${this._instrumentName}: ${t}`);return}if(this._valueType===f.ValueType.INT&&!Number.isInteger(t)){if(f.diag.warn(`INT value type cannot accept a floating-point value for ${this._instrumentName}, ignoring the fractional digits.`),t=Math.trunc(t),!Number.isInteger(t))return}this._buffer.set(e,t)}},he=class{_buffer=new Map;observe(t,e,r={}){if(!R(t))return;let i=this._buffer.get(t);if(i==null)i=new l,this._buffer.set(t,i);if(typeof e!=="number"){f.diag.warn(`non-number value provided to metric ${t._descriptor.name}: ${e}`);return}if(t._descriptor.valueType===f.ValueType.INT&&!Number.isInteger(e)){if(f.diag.warn(`INT value type cannot accept a floating-point value for ${t._descriptor.name}, ignoring the fractional digits.`),e=Math.trunc(e),!Number.isInteger(e))return}i.set(r,e)}};var ge=P(x(),1),_e=class{_callbacks=[];_batchCallbacks=[];addCallback(t,e){if(this._findCallback(t,e)>=0)return;this._callbacks.push({callback:t,instrument:e})}removeCallback(t,e){let r=this._findCallback(t,e);if(r<0)return;this._callbacks.splice(r,1)}addBatchCallback(t,e){let r=new Set(e.filter(R));if(r.size===0){ge.diag.error("BatchObservableCallback is not associated with valid instruments",e);return}if(this._findBatchCallback(t,r)>=0)return;this._batchCallbacks.push({callback:t,instruments:r})}removeBatchCallback(t,e){let r=new Set(e.filter(R)),i=this._findBatchCallback(t,r);if(i<0)return;this._batchCallbacks.splice(i,1)}async observe(t,e){let r=this._observeCallbacks(t,e),i=this._observeBatchCallbacks(t,e);return(await Promise.allSettled([...r,...i])).filter((n)=>n.status==="rejected").map((n)=>n.reason)}_observeCallbacks(t,e){return this._callbacks.map(async({callback:r,instrument:i})=>{let n=new me(i._descriptor.name,i._descriptor.valueType),s=Promise.resolve(r(n));if(e!=null)s=T(s,e);await s,i._metricStorages.forEach((o)=>{o.record(n._buffer,t)})})}_observeBatchCallbacks(t,e){return this._batchCallbacks.map(async({callback:r,instruments:i})=>{let n=new he,s=Promise.resolve(r(n));if(e!=null)s=T(s,e);await s,i.forEach((o)=>{let a=n._buffer.get(o);if(a==null)return;o._metricStorages.forEach((c)=>{c.record(a,t)})})})}_findCallback(t,e){return this._callbacks.findIndex((r)=>r.callback===t&&r.instrument===e)}_findBatchCallback(t,e){return this._batchCallbacks.findIndex((r)=>r.callback===t&&Mt(r.instruments,e))}};var de=P(x(),1),fe=class extends X{_aggregationCardinalityLimit;_deltaMetricStorage;_temporalMetricStorage;_attributesProcessor;constructor(t,e,r,i,n){super(t);this._aggregationCardinalityLimit=n,this._deltaMetricStorage=new j(e,this._aggregationCardinalityLimit),this._temporalMetricStorage=new K(e,i),this._attributesProcessor=r,this.hasAttributeProcessor=r!==void 0}hasAttributeProcessor;record(t,e,r,i){if(this._attributesProcessor!==void 0)e=this._attributesProcessor.process(e,r??de.context.active());this._deltaMetricStorage.record(t,e,i)}collect(t,e){let r=this._deltaMetricStorage.collect();return this._temporalMetricStorage.buildMetrics(t,this._instrumentDescriptor,r,e)}};var pe=class{metricStorageRegistry=new ce;observableRegistry=new _e;meter;_meterProviderSharedState;_instrumentationScope;constructor(t,e){this.meter=new oe(this),this._meterProviderSharedState=t,this._instrumentationScope=e}registerMetricStorage(t){let e=this._registerMetricStorage(t,fe);if(e.length===1)return e[0];return new le(e)}registerAsyncMetricStorage(t){return this._registerMetricStorage(t,ae)}async collect(t,e,r){let i=await this.observableRegistry.observe(e,r?.timeoutMillis),n=this.metricStorageRegistry.getStorages(t);if(n.length===0)return null;let s=[];if(n.forEach((o)=>{let a=o.collect(t,e);if(a!=null)s.push(a)}),s.length===0)return{errors:i};return{scopeMetrics:{scope:this._instrumentationScope,metrics:s},errors:i}}_registerMetricStorage(t,e){let r=this._meterProviderSharedState.viewRegistry.findViews(t,this._instrumentationScope).map((i)=>{let n=Jt(i,t),s=this.metricStorageRegistry.findOrUpdateCompatibleStorage(n);if(s!=null)return s;let o=new e(n,i.aggregation.createAggregator(n),i.attributesProcessor,this._meterProviderSharedState.metricCollectors,i.aggregationCardinalityLimit);return this.metricStorageRegistry.register(o),o});if(r.length===0){let i=this._meterProviderSharedState.selectAggregations(t.type).map(([n,s])=>{let o=this.metricStorageRegistry.findOrUpdateCompatibleCollectorStorage(n,t);if(o!=null)return o;let a=s.createAggregator(t),c=n.selectCardinalityLimit(t.type),u=new e(t,a,void 0,[n],c);return this.metricStorageRegistry.registerForCollector(n,u),u});r=r.concat(i)}return r}};var Se=class{viewRegistry=new qt;metricCollectors=[];meterSharedStates=new Map;resource;constructor(t){this.resource=t}getMeterSharedState(t){let e=At(t),r=this.meterSharedStates.get(e);if(r==null)r=new pe(this,t),this.meterSharedStates.set(e,r);return r}selectAggregations(t){let e=[];for(let r of this.metricCollectors)e.push([r,G(r.selectAggregation(t))]);return e}};var be=class{_sharedState;_metricReader;constructor(t,e){this._sharedState=t,this._metricReader=e}async collect(t){let e=g(Date.now()),r=[],i=[],n=Array.from(this._sharedState.meterSharedStates.values()).map(async(s)=>{let o=await s.collect(this,e,t);if(o?.scopeMetrics!=null)r.push(o.scopeMetrics);if(o?.errors!=null)i.push(...o.errors)});return await Promise.all(n),{resourceMetrics:{resource:this._sharedState.resource,scopeMetrics:r},errors:i}}async forceFlush(t){await this._metricReader.forceFlush(t)}async shutdown(t){await this._metricReader.shutdown(t)}selectAggregationTemporality(t){return this._metricReader.selectAggregationTemporality(t)}selectAggregation(t){return this._metricReader.selectAggregation(t)}selectCardinalityLimit(t){return this._metricReader.selectCardinalityLimit?.(t)??2000}};var qe=/[\^$\\.+?()[\]{}|]/g,Y=class t{_matchAll;_regexp;constructor(e){if(e==="*")this._matchAll=!0,this._regexp=/.*/;else this._matchAll=!1,this._regexp=new RegExp(t.escapePattern(e))}match(e){if(this._matchAll)return!0;return this._regexp.test(e)}static escapePattern(e){return`^${e.replace(qe,"\\$&").replace("*",".*")}$`}static hasWildcard(e){return e.includes("*")}},w=class{_matchAll;_pattern;constructor(t){this._matchAll=t===void 0,this._pattern=t}match(t){if(this._matchAll)return!0;if(t===this._pattern)return!0;return!1}};var Je=class{process(t,e){return t}},Ze=class{_processors;constructor(t){this._processors=t}process(t,e){let r=t;for(let i of this._processors)r=i.process(r,e);return r}};function Te(){return Qe}function Ae(t){return new Ze(t)}var Qe=new Je;var Me=class{_nameFilter;_type;_unitFilter;constructor(t){this._nameFilter=new Y(t?.name??"*"),this._type=t?.type,this._unitFilter=new w(t?.unit)}getType(){return this._type}getNameFilter(){return this._nameFilter}getUnitFilter(){return this._unitFilter}};var we=class{_nameFilter;_versionFilter;_schemaUrlFilter;constructor(t){this._nameFilter=new w(t?.name),this._versionFilter=new w(t?.version),this._schemaUrlFilter=new w(t?.schemaUrl)}getNameFilter(){return this._nameFilter}getVersionFilter(){return this._versionFilter}getSchemaUrlFilter(){return this._schemaUrlFilter}};function tr(t){return t.instrumentName==null&&t.instrumentType==null&&t.instrumentUnit==null&&t.meterName==null&&t.meterVersion==null&&t.meterSchemaUrl==null}function er(t){if(tr(t))throw Error("Cannot create view with no selector arguments supplied");if(t.name!=null&&(t?.instrumentName==null||Y.hasWildcard(t.instrumentName)))throw Error("Views with a specified name must be declared with an instrument selector that selects at most one instrument per meter.")}var ye=class{name;description;aggregation;attributesProcessor;instrumentSelector;meterSelector;aggregationCardinalityLimit;constructor(t){if(er(t),t.attributesProcessors!=null)this.attributesProcessor=Ae(t.attributesProcessors);else this.attributesProcessor=Te();this.name=t.name,this.description=t.description,this.aggregation=G(t.aggregation??{type:0}),this.instrumentSelector=new Me({name:t.instrumentName,type:t.instrumentType,unit:t.instrumentUnit}),this.meterSelector=new we({name:t.meterName,version:t.meterVersion,schemaUrl:t.meterSchemaUrl}),this.aggregationCardinalityLimit=t.aggregationCardinalityLimit}};var b=P(x(),1);var y=(t)=>t!==null&&typeof t==="object"&&typeof t.then==="function";var p=P(x(),1);var m=P(Oe(),1);var q;function bt(){if(q===void 0)try{let t=globalThis.process.argv0;q=t?`unknown_service:${t}`:"unknown_service"}catch{q="unknown_service"}return q}var rr=class t{_rawAttributes;_asyncAttributesPending=!1;_schemaUrl;_memoizedAttributes;static FromAttributeList(e,r){let i=new t({},r);return i._rawAttributes=Ee(e),i._asyncAttributesPending=e.filter(([n,s])=>y(s)).length>0,i}constructor(e,r){let i=e.attributes??{};this._rawAttributes=Object.entries(i).map(([n,s])=>{if(y(s))this._asyncAttributesPending=!0;return[n,s]}),this._rawAttributes=Ee(this._rawAttributes),this._schemaUrl=ir(r?.schemaUrl)}get asyncAttributesPending(){return this._asyncAttributesPending}async waitForAsyncAttributes(){if(!this.asyncAttributesPending)return;for(let e=0;e<this._rawAttributes.length;e++){let[r,i]=this._rawAttributes[e];this._rawAttributes[e]=[r,y(i)?await i:i]}this._asyncAttributesPending=!1}get attributes(){if(this.asyncAttributesPending)p.diag.error("Accessing resource attributes before async attributes settled");if(this._memoizedAttributes)return this._memoizedAttributes;let e={};for(let[r,i]of this._rawAttributes){if(y(i)){p.diag.debug(`Unsettled resource attribute ${r} skipped`);continue}if(Object.hasOwn(e,r));else if(r.length===0)p.diag.warn("dropping invalid resource attribute key: <empty string>");else if(!nt(i))p.diag.warn(`dropping invalid resource attribute value for key "${r}"`);else e[r]=i}if(!this._asyncAttributesPending)this._memoizedAttributes=e;return e}getRawAttributes(){return this._rawAttributes}get schemaUrl(){return this._schemaUrl}merge(e){if(e==null)return this;let r=nr(this,e),i=r?{schemaUrl:r}:void 0;return t.FromAttributeList([...e.getRawAttributes(),...this.getRawAttributes()],i)}};function ve(t,e){return rr.FromAttributeList(Object.entries(t),e)}function Tt(){return ve({[m.ATTR_SERVICE_NAME]:bt(),[m.ATTR_TELEMETRY_SDK_LANGUAGE]:M[m.ATTR_TELEMETRY_SDK_LANGUAGE],[m.ATTR_TELEMETRY_SDK_NAME]:M[m.ATTR_TELEMETRY_SDK_NAME],[m.ATTR_TELEMETRY_SDK_VERSION]:M[m.ATTR_TELEMETRY_SDK_VERSION]})}function Ee(t){return t.map(([e,r])=>{if(y(r))return[e,r.then((i)=>i,(i)=>{p.diag.debug("promise rejection for resource attribute: %s - %s",e,i)})];return[e,r]})}function ir(t){if(typeof t==="string"||t===void 0)return t;p.diag.warn("Schema URL must be string or undefined, got %s. Schema URL will be ignored.",t)}function nr(t,e){let r=t?.schemaUrl,i=e?.schemaUrl,n=r===void 0||r==="",s=i===void 0||i==="";if(n)return i;if(s)return r;if(r===i)return r;p.diag.warn('Schema URL merge conflict: old resource has "%s", updating resource has "%s". Resulting resource will have undefined Schema URL.',r,i)}var sr=class{_sharedState;_shutdown=!1;constructor(t){if(this._sharedState=new Se(t?.resource??Tt()),t?.views!=null&&t.views.length>0)for(let e of t.views)this._sharedState.viewRegistry.addView(new ye(e));if(t?.readers!=null&&t.readers.length>0)for(let e of t.readers){let r=new be(this._sharedState,e);if(e.setMetricProducer(r),this._sharedState.metricCollectors.push(r),t.sdkMetricsEnabled&&e instanceof Yt)e._setSelfObsMeterProvider(this)}}getMeter(t,e="",r={}){if(this._shutdown)return b.diag.warn("A shutdown MeterProvider cannot provide a Meter"),b.createNoopMeter();if(typeof t!=="string"||t.length===0)b.diag.warn("Invalid MeterProvider instrumentation scope name, using empty string"),t="";return this._sharedState.getMeterSharedState({name:t,version:e,schemaUrl:r.schemaUrl}).meter}async shutdown(t){if(this._shutdown){b.diag.warn("shutdown may only be called once per MeterProvider");return}this._shutdown=!0,await Promise.all(this._sharedState.metricCollectors.map((e)=>e.shutdown(t)))}async forceFlush(t){if(this._shutdown){b.diag.warn("invalid attempt to force flush after MeterProvider shutdown");return}await Promise.all(this._sharedState.metricCollectors.map((e)=>e.forceFlush(t)))}};export{sr as MeterProvider};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var m=Object.create;var{getPrototypeOf:n,defineProperty:g,getOwnPropertyNames:o}=Object;var l=Object.prototype.hasOwnProperty;function p(b){return this[b]}var q,r,P=(b,c,d)=>{var h=b!=null&&typeof b==="object";if(h){var i=c?q??=new WeakMap:r??=new WeakMap,k=i.get(b);if(k)return k}d=b!=null?m(n(b)):{};let e=c||!b||!b.__esModule||!l.call(b,"default")?g(d,"default",{value:b,enumerable:!0}):d;if(b&&typeof b==="object"||typeof b==="function"){for(let f of o(b))if(!l.call(e,f))g(e,f,{get:p.bind(b,f),enumerable:!0})}if(h)i.set(b,e);return e};var a=(b,c)=>()=>(c||b((c={exports:{}}).exports,c),c.exports);var s=(b)=>b;function t(b,c){this[b]=s.bind(null,c)}var Hi=(b,c)=>{for(var d in c)g(b,d,{get:c[d],enumerable:!0,configurable:!0,set:t.bind(c,d)})};var j=import.meta.require;
|
|
3
|
+
export{P,a,Hi,j};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{homedir as y}from"os";import{isAbsolute as b,join as p}from"path";function g({command:t,args:s,platform:r=process.platform}){if(r==="win32")return["cmd","/c",t,...s];return["sh","-c",`${t} "$@"`,"--",...s]}function l(t,s){let r=y();if(t===void 0||t===null||t==="")return s??r;let e=t.trim();if(e==="")return s??r;if(e==="~")return r;if(e.startsWith("~/"))return p(r,e.slice(2));if(b(e))return e;return p(r,e)}function h(){try{return process.cwd()}catch{return}}async function pi(t,s,r=Bun.spawn){let e=g({command:t.command,args:s}),n=t.cwd&&t.cwd.trim()!==""?l(t.cwd):l(t.cwd,h()),d;try{d=r(e,{cwd:n,stdin:"inherit",stdout:"inherit",stderr:"inherit"})}catch(o){let u=o instanceof Error?o.message:String(o);return process.stderr.write(`vibe run: spawn failed in cwd=${n}: ${u}
|
|
3
|
+
`),{exitCode:127}}let i=await d.exited;return{exitCode:typeof i==="number"?i:1}}var f=1048576,R=60000;async function w(t){if(!t)return{text:"",truncated:!1};let s=t.getReader(),r=new TextDecoder,e=0,a=!1,n="";try{while(!0){let{done:d,value:i}=await s.read();if(d)break;if(a)continue;let o=f-e;if(i.byteLength<=o)n+=r.decode(i,{stream:!0}),e+=i.byteLength;else n+=r.decode(i.subarray(0,o),{stream:!0}),e=f,a=!0}n+=r.decode()}finally{s.releaseLock()}if(a)n+="...[truncated]";return{text:n,truncated:a}}async function mi(t,s){let r=g({command:t.command,args:s}),e=l(t.cwd),a=Date.now(),n;try{n=Bun.spawn(r,{cwd:e,stdin:"ignore",stdout:"pipe",stderr:"pipe"})}catch(c){let x=c instanceof Error?c.message:String(c);return{exit_code:127,stdout:"",stderr:`vibe alias: spawn failed in cwd=${e}: ${x}`,duration_ms:Date.now()-a,truncated:{stdout:!1,stderr:!1},timed_out:!1,cwd:e}}let d=!1,i=setTimeout(()=>{d=!0;try{n.kill()}catch{}},R),[o,u,m]=await Promise.all([w(n.stdout),w(n.stderr),n.exited]);return clearTimeout(i),{exit_code:typeof m==="number"?m:1,stdout:o.text,stderr:u.text,duration_ms:Date.now()-a,truncated:{stdout:o.truncated,stderr:u.truncated},timed_out:d,cwd:e}}
|
|
4
|
+
export{pi,mi};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var i=new Set(["static-api-key","plugin-state:external-config"]),o=["gateway-auth:"],s=[/(^|[-_:])secret($|[-_:])/i,/(^|[-_:])token($|[-_:])/i,/(^|[-_:])password($|[-_:])/i,/(^|[-_:])api[-_]?key($|[-_:])/i,/^static-api-key$/i,/^gateway-auth:/i,/^clientSecret$/i,/^plugin-state:external-config$/i],Ri="[redacted]";function Dt(t){return i.has(t)||o.some((n)=>t.startsWith(n))}function r(t){return s.some((n)=>n.test(t))}function xe(t,n){return r(t)&&n!==void 0?"[redacted]":n}function Fi(t){return Object.fromEntries(Object.entries(t).map(([n,e])=>[n,xe(n,e)]))}function L(t){if(Array.isArray(t))return t.map((n)=>L(n));if(!t||typeof t!=="object")return t;return Object.fromEntries(Object.entries(t).map(([n,e])=>[n,r(n)?"[redacted]":L(e)]))}
|
|
3
|
+
export{Ri,Dt,xe,Fi,L};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{R,C}from"./index-0qjbnyg4.js";import{J,w}from"./index-kwhx023z.js";import{existsSync as d,readFileSync as y}from"fs";import{join as T}from"path";var p="http://localhost:3005",h=new Set(["localhost","127.0.0.1","0.0.0.0","::1","[::1]"]);function A(r){return r.toLowerCase().replace(/^\[|\]$/g,"")}function Kt(r){try{let n=new URL(r);return h.has(A(n.hostname))}catch{return!1}}function u(r){let n=new URL(r.trim());if(n.protocol!=="http:"&&n.protocol!=="https:")throw Error("Agent URL must use http or https");if(n.username||n.password)throw Error("Agent URL must not include credentials");let t=n.toString().replace(/\/+$/,"");if(!Kt(t)&&process.env.VIBECONTROLS_ALLOW_REMOTE_AGENT_URL!=="1")throw Error("Refusing non-local agent URL. Set VIBECONTROLS_ALLOW_REMOTE_AGENT_URL=1 to target a remote/tunnel URL explicitly.");return t}function O(r){if(!Number.isInteger(r)||r<=0)return!1;try{return process.kill(r,0),!0}catch{return!1}}function _(){let r=T(C(),"agents.json");if(!d(r))return[];try{let n=JSON.parse(y(r,"utf-8"));return(Array.isArray(n)?n:n&&typeof n==="object"&&Array.isArray(n.instances)?n.instances:[]).filter((e)=>!!e&&typeof e==="object"&&typeof e.name==="string"&&typeof e.port==="number")}catch{return[]}}function E(r){let t=_().find((e)=>e.name===r);if(!t||!t.port)return null;if(typeof t.pid==="number"&&!O(t.pid))return null;return{url:`http://localhost:${t.port}`,port:t.port}}function f(r){let n=r?.agentUrl&&r.agentUrl!==p?r.agentUrl:void 0;if(n)return u(n);if(r?.profile){let t=E(r.profile);if(t)return t.url}if(process.env.AGENT_URL)return u(process.env.AGENT_URL);try{let t=m({}),e=E(t);if(e)return e.url}catch{}return u(p)}async function Re(r){let n=Kt(r);if(process.env.AGENT_API_KEY){if(n||process.env.VIBECONTROLS_SEND_API_KEY_TO_REMOTE==="1")return process.env.AGENT_API_KEY;throw Error("Refusing to send AGENT_API_KEY to a non-local agent URL. Set VIBECONTROLS_SEND_API_KEY_TO_REMOTE=1 only if you trust the target.")}if(!n)return;let t=R(),e=await J(`${t}:static-api-key`);if(e)return e;return w()["static-api-key"]}function m(r){if(r?.profile)return r.profile;if(process.env.VIBECONTROLS_PROFILE)return process.env.VIBECONTROLS_PROFILE;try{let n=T(C(),"agents.json");if(d(n)){let t=JSON.parse(y(n,"utf-8")),e=t&&typeof t==="object"&&!Array.isArray(t)?t.defaultProfile:void 0;if(typeof e==="string"&&e.length>0)return e}}catch{}return"default"}async function c(r,n,t={}){let e=await Re(r),s={...t.body?{"Content-Type":"application/json"}:{},...e?{"x-agent-api-key":e}:{},...t.headers??{}},o;try{o=await fetch(`${r}${n}`,{...t,headers:s})}catch(i){let g=i instanceof Error?i.message:String(i),l=/unable to connect|ECONNREFUSED|ENOTFOUND|EHOSTUNREACH|fetch failed/i.test(g);if(l&&Kt(r))throw Error(`Agent not reachable at ${r}. Is it running? Try 'vibe status' or 'vibe start'.`,{cause:i});if(l)throw Error(`Agent not reachable at ${r}. ${g}`,{cause:i});throw i}let a=await o.json().catch(()=>({}));return{ok:o.ok,status:o.status,data:a}}async function S(r,n){let{ok:t,status:e,data:s}=await c(r,n);if(!t){let o=s?.error||s?.message||`Agent returned ${e}`;throw Error(String(o))}return s}async function q(r,n,t){let{ok:e,status:s,data:o}=await c(r,n,{method:"POST",body:t!=null?JSON.stringify(t):void 0});if(!e){let a=o?.error||o?.message||`Agent returned ${s}`;throw Error(String(a))}return o}async function Ce(r,n,t){let{ok:e,status:s,data:o}=await c(r,n,{method:"PUT",body:t!=null?JSON.stringify(t):void 0});if(!e){let a=o?.error||o?.message||`Agent returned ${s}`;throw Error(String(a))}return o}async function Ae(r,n){let{ok:t,status:e,data:s}=await c(r,n,{method:"DELETE"});if(!t){let o=s?.error||s?.message||`Agent returned ${e}`;throw Error(String(o))}return s}
|
|
3
|
+
export{Kt,f,Re,m,S,q,Ce,Ae};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var h=new Set(["localhost","127.0.0.1","::1","[::1]"]),g=new Set(["127.0.0.1","::1"]),m=new Set(["same-origin","none"]),S=new Set(["https://vibecontrols.com","https://app.vibecontrols.com","https://alphaapp.vibecontrols.com","https://burdenoff.com","https://app.burdenoff.com","https://alphaapp.burdenoff.com"]);function w(e){let t=e.trim().toLowerCase().replace(/^\[|\]$/g,"");if(t.startsWith("::ffff:"))return t.slice(7);return t}function y(e){return g.has(w(e))}function c(e){let t=e.trim().toLowerCase().replace(/^\[|\]$/g,"");return h.has(t)}function a(e){if(!e||e.length>255)return null;for(let l=0;l<e.length;l++){let s=e.charCodeAt(l);if(s<=32||s===127)return null}if(/[/\\@?#,'"`]/.test(e))return null;let t=e.toLowerCase();if(t.startsWith("[")){let l=t.indexOf("]");if(l<=1)return null;let s=t.slice(1,l);if(!/^[0-9a-f:.]+$/.test(s))return null;let i=t.slice(l+1);if(i==="")return{host:`[${s}]`,hostname:s,port:""};if(!i.startsWith(":"))return null;let u=i.slice(1);if(!f(u))return null;return{host:`[${s}]:${u}`,hostname:s,port:u}}let n=t.indexOf(":");if(n===-1){if(!/^[a-z0-9.-]+$/.test(t)||t.startsWith(".")||t.endsWith("."))return null;return{host:t,hostname:t,port:""}}if(t.indexOf(":",n+1)!==-1)return null;let r=t.slice(0,n),o=t.slice(n+1);if(!r||!/^[a-z0-9.-]+$/.test(r)||r.startsWith(".")||r.endsWith("."))return null;if(!f(o))return null;return{host:`${r}:${o}`,hostname:r,port:o}}function f(e){if(!/^\d{1,5}$/.test(e))return!1;let t=Number(e);return Number.isInteger(t)&&t>=1&&t<=65535}function p(e){if(e.headers.has("host"))return a(e.headers.get("host")??"");try{return a(new URL(e.url).host)}catch{return null}}function O(e){return e.has("cf-connecting-ip")||e.has("x-forwarded-for")||e.has("x-real-ip")||e.has("forwarded")}function R(e){if(!e.has("sec-fetch-site"))return!1;let t=(e.get("sec-fetch-site")??"").trim().toLowerCase();return!m.has(t)}function Ge(e){return e.headers.has("origin")||e.headers.has("sec-fetch-site")}function b(e,t){if(!t)return;try{let n=new URL(t);if(n.protocol!=="https:"&&n.protocol!=="http:")return;let r=a(n.host);if(!r||r.hostname==="0.0.0.0")return;if(e.add(r.host),!r.port){let o=n.protocol==="https:"?"443":"80";e.add(`${r.host}:${o}`)}}catch{}}function Cr(e,t){let n=p(e);if(!n)return!1;if(n.hostname==="0.0.0.0")return!1;let r=new Set,{port:o}=t;if(Number.isInteger(o)&&o>0){if(r.add(`localhost:${o}`),r.add(`127.0.0.1:${o}`),r.add(`[::1]:${o}`),o===80||o===443)r.add("localhost"),r.add("127.0.0.1"),r.add("[::1]")}else if(o===0&&c(n.hostname))return!0;if(t.tunnelUrls)for(let s of t.tunnelUrls)b(r,s);let l=(process.env.VIBECONTROLS_ALLOWED_HOSTS??"").split(",").map((s)=>s.trim()).filter(Boolean);for(let s of[...t.allowedHosts??[],...l]){let i=a(s);if(i&&i.hostname!=="0.0.0.0")r.add(i.host)}return r.has(n.host)}function L(e){let t=new Set,n=process.env.VIBECONTROLS_DEV_CORS_PORTS??"",r=[...(e??[]).map((o)=>String(o).trim()),...n.split(",").map((o)=>o.trim())];for(let o of r)if(f(o))t.add(o);return t}function gi(e,t){let n;try{n=new URL(e)}catch{return!1}if(n.protocol!=="http:"&&n.protocol!=="https:")return!1;let r=n.hostname.toLowerCase().replace(/^\[|\]$/g,"");if(r==="0.0.0.0")return!1;let o=(t?.nodeEnv??"production")==="production";if(S.has(n.origin))return!0;let l=t?.configuredOrigins??[];for(let s of l){if(!s||s==="*")continue;try{let i=new URL(s);if(i.hostname.toLowerCase().replace(/^\[|\]$/g,"")==="0.0.0.0")continue;if(i.origin===n.origin){if(o&&c(r))return!1;return!0}}catch{}}if(o)return!1;if(r.endsWith(".local.burdenoff.com"))return!0;if(r==="localhost"||r==="127.0.0.1"){let s=L(t?.devPorts),i=n.port||(n.protocol==="https:"?"443":"80");return s.has(i)}return!1}function Be(e,t){let n=e.headers;if(O(n))return!1;if(R(n))return!1;let r=p(e);if(!r||!c(r.hostname))return!1;if(t?.port&&Number.isInteger(t.port)&&t.port>0&&r.port&&Number(r.port)!==t.port)return!1;if(n.has("origin")){let l=n.get("origin")??"";try{let s=new URL(l),i=a(s.host);if(!i||!c(i.hostname)||i.host!==r.host)return!1}catch{return!1}}let o=t?.requestIP(e)?.address;if(!o)return!1;return y(o)}function x(e){return`security:${e.toLowerCase()}`}function d(e){if(!e)return!1;let t=e.trim().toLowerCase();return t==="1"||t==="true"||t==="yes"}async function Pe(e,t,n,r){if(Be(e,n))return null;if(d(process.env[t]))return null;if(r?.getConfig)try{let o=await r.getConfig(x(t));if(d(o))return null}catch{}return`This operation is local-only by default. Set ${t}=1 to allow it over a tunnel, or toggle it from the agent's Security Settings.`}
|
|
3
|
+
export{Ge,Cr,gi,Be,Pe};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{I,ee}from"./index-0qjbnyg4.js";import{s,l,p,o,g,n,c}from"./index-7f2k4g6q.js";import{b}from"./index-w4jqdhc2.js";import{u}from"./index-t5cfkz1e.js";import{existsSync as L,mkdirSync as T,writeFileSync as U,unlinkSync as H,readFileSync as q}from"fs";import{join as v}from"path";import{homedir as A,platform as x}from"os";import{isAbsolute as J,resolve as K}from"path";function W(){return I()}function w(){return v(W(),"logs")}function B(){if(process.execPath&&process.execPath.includes("bun"))return process.execPath;let t=b().which("bun");if(t)return t;throw Error("Could not find bun binary. Ensure bun is installed and in PATH.")}function D(){return import.meta.dir.endsWith("/dist")||import.meta.dir.includes("/dist/")?v(import.meta.dir,"index.js"):v(import.meta.dir,"..","..","index.ts")}function R(t,e){if(/[\0\r\n]/.test(t))throw Error(`${e} contains invalid control characters`)}function C(t){if(!/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(t))throw Error("Agent name must use 1-64 characters: letters, numbers, dot, underscore, or dash.");return t}function Y(t){let e=parseInt(t,10);if(!Number.isInteger(e)||e<1||e>65535)throw Error("Port must be an integer between 1 and 65535");return e}function y(t){return R(t,"systemd value"),`"${t.replace(/\\/g,"\\\\").replace(/"/g,"\\\"")}"`}function tt(t){if(R(t,"systemd path"),!J(t))throw Error(`systemd path must be absolute, got: ${t}`);return t}function d(t){let e=String(t);return R(e,"plist value"),e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function V(t){let e=v(A(),".config","systemd","user");return T(e,{recursive:!0}),v(e,`vibecontrols-agent-${t}.service`)}function X(t){return`[Unit]
|
|
3
|
+
Description=VibeControls Agent (${t.name})
|
|
4
|
+
After=network.target
|
|
5
|
+
|
|
6
|
+
[Service]
|
|
7
|
+
Type=simple
|
|
8
|
+
ExecStart=${y(t.bunPath)} run ${y(t.entryPoint)}
|
|
9
|
+
Environment=${y(`PORT=${t.port}`)}
|
|
10
|
+
Environment=${y(`DB_PATH=${t.dbPath}`)}${t.host?`
|
|
11
|
+
Environment=${y(`HOST=${t.host}`)}`:""}
|
|
12
|
+
Environment=NODE_ENV=production${t.profile?`
|
|
13
|
+
Environment=${y(`VIBECONTROLS_PROFILE=${t.profile}`)}`:""}${t.profiles?`
|
|
14
|
+
Environment=${y(`VIBECONTROLS_PROFILES=${t.profiles}`)}`:""}${t.home?`
|
|
15
|
+
Environment=${y(`VIBECONTROLS_HOME=${t.home}`)}`:""}${t.isolatePlugins?`
|
|
16
|
+
Environment=${y(`VIBE_ISOLATE_PLUGINS=${t.isolatePlugins}`)}`:""}
|
|
17
|
+
Environment=${y(`AGENT_LOG_FILE=${t.logFile}`)}
|
|
18
|
+
Environment=${y(`HOME=${A()}`)}
|
|
19
|
+
Environment=${y(`PATH=${process.env.PATH??""}`)}
|
|
20
|
+
WorkingDirectory=${tt(A())}
|
|
21
|
+
Restart=always
|
|
22
|
+
RestartSec=5
|
|
23
|
+
StandardOutput=append:${t.logFile}
|
|
24
|
+
StandardError=append:${t.logFile}
|
|
25
|
+
|
|
26
|
+
[Install]
|
|
27
|
+
WantedBy=default.target
|
|
28
|
+
`}async function et(t,e,r,i={}){C(t),R(r,"dbPath");let a=B(),f=D(),h=v(w(),`${t}.log`),m=V(t),P=`vibecontrols-agent-${t}.service`;T(w(),{recursive:!0});let k=X({name:t,port:e,dbPath:r,bunPath:a,entryPoint:f,logFile:h,host:i.host,profile:i.profile,profiles:i.profiles,home:i.home,isolatePlugins:i.isolatePlugins});U(m,k),o(`Wrote systemd unit: ${m}`);let S=[["systemctl","--user","daemon-reload"],["systemctl","--user","enable",P],...i.skipStart?[]:[["systemctl","--user","start",P]]];for(let E of S){let O=Bun.spawnSync(E);if(O.exitCode!==0){let j=O.stderr.toString().trim();throw Error(`${E.join(" ")} failed (exit ${O.exitCode})${j?` \u2014 ${j}`:""}`)}}if(Bun.spawnSync(["loginctl","enable-linger",process.env.USER||""]).exitCode===0)o("Enabled user linger (service survives logout)");l(`Autostart installed for agent '${t}' on port ${e}`),n("Service",P),n("Unit file",m),n("Log file",h),c(),o(`Check status: systemctl --user status ${P}`)}async function nt(t){let e=`vibecontrols-agent-${t}.service`,r=V(t),i=[["systemctl","--user","stop",e],["systemctl","--user","disable",e]];for(let a of i)Bun.spawnSync(a);if(L(r))H(r),o(`Removed unit file: ${r}`);Bun.spawnSync(["systemctl","--user","daemon-reload"]),l(`Autostart removed for agent '${t}'`)}async function rt(t){let e=`vibecontrols-agent-${t}.service`,r=V(t);if(!L(r)){o(`Autostart is NOT configured for agent '${t}'`),n("Expected unit",r);return}g(`Autostart Status \u2014 ${t}`),n("Unit file",r),n("Service",e),c();let a=Bun.spawnSync(["systemctl","--user","status",e]).stdout.toString().trim();if(a)console.log(a);else o("Service status unavailable")}function F(t){let e=v(A(),"Library","LaunchAgents");return T(e,{recursive:!0}),v(e,`com.boff.vibecontrols.agent.${t}.plist`)}function z(t){return`<?xml version="1.0" encoding="UTF-8"?>
|
|
29
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
30
|
+
<plist version="1.0">
|
|
31
|
+
<dict>
|
|
32
|
+
<key>Label</key>
|
|
33
|
+
<string>com.boff.vibecontrols.agent.${d(t.name)}</string>
|
|
34
|
+
<key>ProgramArguments</key>
|
|
35
|
+
<array>
|
|
36
|
+
<string>${d(t.bunPath)}</string>
|
|
37
|
+
<string>run</string>
|
|
38
|
+
<string>${d(t.entryPoint)}</string>
|
|
39
|
+
</array>
|
|
40
|
+
<key>EnvironmentVariables</key>
|
|
41
|
+
<dict>
|
|
42
|
+
<key>PORT</key>
|
|
43
|
+
<string>${d(t.port)}</string>
|
|
44
|
+
<key>DB_PATH</key>
|
|
45
|
+
<string>${d(t.dbPath)}</string>${t.host?`
|
|
46
|
+
<key>HOST</key>
|
|
47
|
+
<string>${d(t.host)}</string>`:""}
|
|
48
|
+
<key>NODE_ENV</key>
|
|
49
|
+
<string>production</string>${t.profile?`
|
|
50
|
+
<key>VIBECONTROLS_PROFILE</key>
|
|
51
|
+
<string>${d(t.profile)}</string>`:""}${t.profiles?`
|
|
52
|
+
<key>VIBECONTROLS_PROFILES</key>
|
|
53
|
+
<string>${d(t.profiles)}</string>`:""}${t.home?`
|
|
54
|
+
<key>VIBECONTROLS_HOME</key>
|
|
55
|
+
<string>${d(t.home)}</string>`:""}${t.isolatePlugins?`
|
|
56
|
+
<key>VIBE_ISOLATE_PLUGINS</key>
|
|
57
|
+
<string>${d(t.isolatePlugins)}</string>`:""}
|
|
58
|
+
<key>AGENT_LOG_FILE</key>
|
|
59
|
+
<string>${d(t.logFile)}</string>
|
|
60
|
+
<key>HOME</key>
|
|
61
|
+
<string>${d(A())}</string>
|
|
62
|
+
<key>PATH</key>
|
|
63
|
+
<string>${d(process.env.PATH??"")}</string>
|
|
64
|
+
</dict>
|
|
65
|
+
<key>WorkingDirectory</key>
|
|
66
|
+
<string>${d(A())}</string>
|
|
67
|
+
<key>RunAtLoad</key>
|
|
68
|
+
<true/>
|
|
69
|
+
<key>KeepAlive</key>
|
|
70
|
+
<dict>
|
|
71
|
+
<key>SuccessfulExit</key>
|
|
72
|
+
<false/>
|
|
73
|
+
</dict>
|
|
74
|
+
<key>StandardOutPath</key>
|
|
75
|
+
<string>${d(t.logFile)}</string>
|
|
76
|
+
<key>StandardErrorPath</key>
|
|
77
|
+
<string>${d(t.logFile)}</string>
|
|
78
|
+
<key>ProcessType</key>
|
|
79
|
+
<string>Background</string>
|
|
80
|
+
</dict>
|
|
81
|
+
</plist>
|
|
82
|
+
`}async function st(t,e,r,i={}){C(t),R(r,"dbPath");let a=B(),f=D(),h=v(w(),`${t}.log`),m=F(t);T(w(),{recursive:!0});let P=z({name:t,port:e,dbPath:r,bunPath:a,entryPoint:f,logFile:h,host:i.host,profile:i.profile,profiles:i.profiles,home:i.home,isolatePlugins:i.isolatePlugins});if(U(m,P),o(`Wrote launchd plist: ${m}`),i.skipStart){l(`Autostart configured for agent '${t}' on port ${e}`),n("Plist",m),n("Log file",h);return}let k=Bun.spawnSync(["launchctl","load",m]);if(k.exitCode!==0){let S=k.stderr.toString().trim();p(`launchctl load failed: ${S}`),o("Trying bootstrap method...");let N=Bun.spawnSync(["id","-u"]).stdout.toString().trim(),E=Bun.spawnSync(["launchctl","bootstrap",`gui/${N}`,m]);if(E.exitCode!==0){let O=E.stderr.toString().trim();throw Error(`launchctl could not load ${m}: load failed${S?` \u2014 ${S}`:""}; bootstrap failed (exit ${E.exitCode})${O?` \u2014 ${O}`:""}`)}}l(`Autostart installed for agent '${t}' on port ${e}`),n("Plist",m),n("Log file",h)}async function it(t){let e=F(t),r=`com.boff.vibecontrols.agent.${t}`;Bun.spawnSync(["launchctl","unload",e]);let i=Bun.spawnSync(["id","-u"]).stdout.toString().trim();if(Bun.spawnSync(["launchctl","bootout",`gui/${i}/${r}`]),L(e))H(e),o(`Removed plist: ${e}`);l(`Autostart removed for agent '${t}'`)}async function ot(t){let e=F(t),r=`com.boff.vibecontrols.agent.${t}`;if(!L(e)){o(`Autostart is NOT configured for agent '${t}'`),n("Expected plist",e);return}g(`Autostart Status \u2014 ${t}`),n("Plist",e),n("Label",r),c();let f=Bun.spawnSync(["launchctl","list"]).stdout.toString().split(`
|
|
83
|
+
`).filter((h)=>h.includes("vibecontrols"));if(f.length>0)console.log(f.join(`
|
|
84
|
+
`));else o("Service not currently loaded")}function M(t){return`VibeControlsAgent_${t}`}function Q(t){return v(W(),`autostart-${t}.xml`)}function at(t){let e=[`<Variable><Name>VIBECONTROLS_PROFILE</Name><Value>${d(t.name)}</Value></Variable>`,`<Variable><Name>PORT</Name><Value>${d(t.port)}</Value></Variable>`,`<Variable><Name>VIBECONTROLS_HOME</Name><Value>${d(t.configDir)}</Value></Variable>`];if(t.dbPath)e.push(`<Variable><Name>DB_PATH</Name><Value>${d(t.dbPath)}</Value></Variable>`);let r=process.env.USERNAME??process.env.USER??"User";return`<?xml version="1.0" encoding="UTF-16"?>
|
|
85
|
+
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
|
|
86
|
+
<RegistrationInfo>
|
|
87
|
+
<Description>VibeControls Agent (${d(t.name)}) \u2014 auto-start on logon, restart on crash</Description>
|
|
88
|
+
</RegistrationInfo>
|
|
89
|
+
<Triggers>
|
|
90
|
+
<LogonTrigger>
|
|
91
|
+
<Enabled>true</Enabled>
|
|
92
|
+
<UserId>${d(r)}</UserId>
|
|
93
|
+
</LogonTrigger>
|
|
94
|
+
</Triggers>
|
|
95
|
+
<Principals>
|
|
96
|
+
<Principal id="Author">
|
|
97
|
+
<UserId>${d(r)}</UserId>
|
|
98
|
+
<LogonType>InteractiveToken</LogonType>
|
|
99
|
+
<RunLevel>LeastPrivilege</RunLevel>
|
|
100
|
+
</Principal>
|
|
101
|
+
</Principals>
|
|
102
|
+
<Settings>
|
|
103
|
+
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
|
|
104
|
+
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
|
|
105
|
+
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
|
|
106
|
+
<AllowHardTerminate>true</AllowHardTerminate>
|
|
107
|
+
<StartWhenAvailable>true</StartWhenAvailable>
|
|
108
|
+
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
|
|
109
|
+
<IdleSettings>
|
|
110
|
+
<StopOnIdleEnd>false</StopOnIdleEnd>
|
|
111
|
+
<RestartOnIdle>false</RestartOnIdle>
|
|
112
|
+
</IdleSettings>
|
|
113
|
+
<AllowStartOnDemand>true</AllowStartOnDemand>
|
|
114
|
+
<Enabled>true</Enabled>
|
|
115
|
+
<Hidden>true</Hidden>
|
|
116
|
+
<RunOnlyIfIdle>false</RunOnlyIfIdle>
|
|
117
|
+
<WakeToRun>false</WakeToRun>
|
|
118
|
+
<ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
|
|
119
|
+
<Priority>7</Priority>
|
|
120
|
+
<RestartOnFailure>
|
|
121
|
+
<Interval>PT1M</Interval>
|
|
122
|
+
<Count>3</Count>
|
|
123
|
+
</RestartOnFailure>
|
|
124
|
+
</Settings>
|
|
125
|
+
<Actions Context="Author">
|
|
126
|
+
<Exec>
|
|
127
|
+
<Command>${d(t.bunPath)}</Command>
|
|
128
|
+
<Arguments>${d(t.entryPoint)} start --foreground --port ${d(t.port)} --name ${d(t.name)}${t.host?` --host ${d(t.host)}`:""}</Arguments>
|
|
129
|
+
<WorkingDirectory>${d(t.configDir)}</WorkingDirectory>
|
|
130
|
+
</Exec>
|
|
131
|
+
</Actions>
|
|
132
|
+
</Task>`}async function lt(t,e,r,i={}){let a=M(t),f=Q(t),h=W(),m=w();T(h,{recursive:!0}),T(m,{recursive:!0});let P=B(),k=D(),S=at({name:t,port:e,host:i.host,dbPath:r,bunPath:P,entryPoint:k,configDir:h,logsDir:m}),N=Buffer.concat([Buffer.from([255,254]),Buffer.from(S,"utf16le")]);if(U(f,N),n("Task XML",f),Bun.spawnSync(["schtasks","/Create","/TN",a,"/XML",f,"/F"],{stdout:"inherit",stderr:"inherit"}).exitCode!==0)throw Error("schtasks /Create failed. Run from an elevated shell if your user lacks scheduler permission.");c(),l(`Autostart installed for agent '${t}' (Task: ${a})`),o("To start now without rebooting:"),o(` schtasks /Run /TN ${a}`)}async function ut(t){let e=M(t),r=Q(t),i=Bun.spawnSync(["schtasks","/Delete","/TN",e,"/F"],{stdout:"pipe",stderr:"pipe"});if(i.exitCode!==0)p(`schtasks /Delete returned non-zero (${i.exitCode}). Task may not have existed.`);else l(`Removed scheduled task ${e}`);if(L(r))try{H(r)}catch{}}async function ct(t){let e=M(t),r=Bun.spawnSync(["schtasks","/Query","/TN",e,"/V","/FO","LIST"],{stdout:"pipe",stderr:"pipe"});if(r.exitCode!==0){o(`Autostart is NOT configured for agent '${t}'`),n("Expected task",e);return}g(`Autostart Status \u2014 ${t}`),n("Task",e),c(),console.log(r.stdout.toString())}function G(t,e,r){if(!L(e))return!1;try{let i=r({bunPath:B(),entryPoint:D(),logFile:v(w(),`${t.name}.log`)});return q(e,"utf8")===i}catch{return!0}}function gt(t){try{let e=Bun.spawnSync(["systemctl","--user","is-enabled",`vibecontrols-agent-${t}.service`]);if(e.exitCode===0)return!0;let r=e.stdout.toString().trim();return!["disabled","masked","linked",""].includes(r)}catch{return!0}}var Z={linux:{label:"systemd",install:(t,e,r,i)=>et(t,e,r??"./agent-db",i),uninstall:nt,status:rt,isCurrent:(t)=>G(t,V(t.name),(e)=>X({...t,...e}))&>(t.name),autoConfigurable:!0},darwin:{label:"launchd",install:(t,e,r,i)=>st(t,e,r??"./agent-db",i),uninstall:it,status:ot,isCurrent:(t)=>G(t,F(t.name),(e)=>z({...t,...e})),autoConfigurable:!0},win32:{label:"Task Scheduler",install:lt,uninstall:ut,status:ct,isCurrent:()=>!0,autoConfigurable:!1}};function _(){let t=Z[x()];if(!t)throw Error(`Autostart is not supported on ${x()}. Supported: linux (systemd), darwin (launchd), win32 (Task Scheduler).`);return t}async function Zi(t){let e=process.env.VIBECONTROLS_PROFILES||void 0,r=process.env.VIBECONTROLS_HOME||void 0,i=process.env.VIBE_ISOLATE_PLUGINS||void 0;if(process.env.VIBE_NO_AUTOSTART==="1"||process.env.VIBE_AUTOSTART==="0")return{installed:!1,reason:"opted out via env"};let a=Z[x()];if(!a)return{installed:!1,reason:`unsupported platform ${x()}`};if(!a.autoConfigurable)return{installed:!1,reason:`${a.label} must be configured manually \u2014 run \`vibe autostart install\``};try{let f={name:t.name,port:t.port,dbPath:t.dbPath??"./agent-db",host:t.host,profile:t.profile,profiles:e,home:r,isolatePlugins:i};if(a.isCurrent(f))return{installed:!1,reason:"already configured"};return await a.install(t.name,t.port,t.dbPath,{skipStart:!0,host:t.host,profile:t.profile,profiles:e,home:r,isolatePlugins:i}),{installed:!0,serviceLabel:a.label}}catch(f){return{installed:!1,failed:!0,reason:f instanceof Error?f.message:String(f)}}}function qr(t){let e=t.command("autostart").description("Configure agent to auto-start on system boot");e.command("install").description("Generate and enable system service for auto-start on reboot").option("-n, --name <name>","Agent instance name","default").option("-p, --port <port>","Port to listen on","3005").option("--db-path <path>","Agent storage directory (absolute path; default: ~/.boff/vibecontrols/agents/<profile>/agent-db)").option("--json","Emit JSON").action(async function(r){let i={...t.opts(),...r};try{let a=_(),f=C(r.name),h=Y(r.port),m=r.dbPath??null,P=ee(),k=(()=>{if(!m)return P;if(J(m))return m;let S=K(P,"..",m);return p(`--db-path is relative; resolved to ${S}. Pass an absolute path to silence this warning.`),S})();if(!i.json)g("Installing Autostart"),n("Platform",`${x()} (${a.label})`),n("Agent",f),n("Port",String(h)),n("Database",k),c();await a.install(f,h,k),u(i,{ok:!0,enabled:!0,name:f,port:h})}catch(a){if(i.json)u(i,{ok:!1,error:String(a)}),process.exit(1);s(`Failed to install autostart: ${a}`),process.exit(1)}}),e.command("uninstall").description("Stop and remove the system service").option("-n, --name <name>","Agent instance name","default").option("--json","Emit JSON").action(async function(r){let i={...t.opts(),...r};try{let a=_(),f=C(r.name);if(!i.json)g("Removing Autostart");await a.uninstall(f),u(i,{ok:!0,enabled:!1,name:f})}catch(a){if(i.json)u(i,{ok:!1,error:String(a)}),process.exit(1);s(`Failed to uninstall autostart: ${a}`),process.exit(1)}}),e.command("status").description("Check if autostart is configured and running").option("-n, --name <name>","Agent instance name","default").action(async(r)=>{try{let i=_(),a=C(r.name);await i.status(a)}catch(i){s(`Failed to check autostart status: ${i}`),process.exit(1)}})}
|
|
133
|
+
export{Zi,qr};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{R}from"./index-0qjbnyg4.js";import{J,w,M,X}from"./index-kwhx023z.js";import{i,s,A,l,o,g,n,c,F}from"./index-7f2k4g6q.js";import{_,y,u}from"./index-t5cfkz1e.js";async function Vi(){if(process.env.AGENT_API_KEY)return process.env.AGENT_API_KEY;let a="default";try{a=R()}catch{}let d=await J(`${a}:static-api-key`);if(d)return d;return w()["static-api-key"]??null}var S=["read","mutate","plugin:install","plugin:remove","update","admin"];function K(a){if(a.length<=12)return"[redacted]";return`${a.slice(0,8)}...${a.slice(-4)}`}function I(){let a=new Uint8Array(32);return crypto.getRandomValues(a),`vcak_${Buffer.from(a).toString("base64url")}`}function N(){return crypto.randomUUID()}function b(a){if(!a)return;let d=/^(\d+)([smhdw]?)$/.exec(a.trim());if(!d)throw Error(`Invalid --expires-in: ${a} (use 30s, 12h, 7d, 4w; bare digits = days)`);let e=Number(d[1]),f=d[2]||"d",t=f==="s"?e*1000:f==="m"?e*60000:f==="h"?e*3600000:f==="w"?e*7*86400000:e*86400000;return new Date(Date.now()+t).toISOString()}function E(a){if(!a)return["read"];let d=a.split(",").map((e)=>e.trim()).filter(Boolean);for(let e of d)if(!S.includes(e))throw Error(`Unknown scope: ${e}. Allowed: ${S.join(", ")}`);return d}function jr(a){let d=a.command("key").description("Show or manage VibeControls agent API keys");d.command("show",{isDefault:!0}).description("Show the default agent API key").option("--show-secret","Print the full API key",!1).option("--json","Emit JSON").option("--plain","Force plain text output").action(async function(e){let f={...a.opts(),...e};try{await y({mode:_(f),fetchData:async()=>({apiKey:await Vi()??null}),plain:(t)=>{if(g("Agent API Key"),c(),!t.apiKey){s("No API key found in AGENT_API_KEY or local agent config.");return}if(n("API Key",i.bold(e.showSecret?t.apiKey:K(t.apiKey))),!e.showSecret)n("Full key",i.dim("hidden; rerun with --show-secret"));c()},json:(t)=>({apiKey:t.apiKey?e.showSecret?t.apiKey:"[redacted]":null})})}catch(t){s(`Failed to get API key: ${A(t)}`)}}),d.command("list").description("List all scoped API keys (default + minted)").option("--json","Emit JSON").option("--plain","Force plain text output").option("--show-secret","Include full key values in JSON output",!1).action(async function(e){let f={...a.opts(),...e};try{await y({mode:_(f),fetchData:()=>X(),plain:(t)=>{let r=[],m=t["static-api-key"];if(m)r.push({ID:"default",Name:"default",Scopes:"admin",Expires:"never",Key:K(m)});for(let p of t.apiKeys??[])r.push({ID:p.id??"(legacy)",Name:p.name,Scopes:p.scopes.join(","),Expires:p.expiresAt??"never",Key:K(p.key)});if(r.length===0){o("No keys configured.");return}g("Agent API Keys"),F(r)},json:(t)=>{let r=[],m=t["static-api-key"];if(m)r.push({id:"default",name:"default",scopes:["admin"],expiresAt:null,key:e.showSecret?m:"[redacted]"});for(let p of t.apiKeys??[])r.push({id:p.id??"(legacy)",name:p.name,scopes:p.scopes,expiresAt:p.expiresAt??null,key:e.showSecret?p.key:"[redacted]"});return r}})}catch(t){s(A(t))}}),d.command("add").description("Mint a new scoped API key").requiredOption("--name <name>","Display name (logs only)").option("--scope <scope>",`Comma-separated scope list (default: read). Allowed: ${S.join(",")}`,"read").option("--expires-in <duration>","TTL (e.g. 7d, 12h, 30m). Omit for no expiry.").option("--not-before <iso>","ISO timestamp before which the key is rejected.").option("--json","Emit JSON").action(function(e){let f={...a.opts(),...e};try{let t=E(e.scope),r=b(e.expiresIn),m=w(),p=N(),h=I(),k={id:p,name:e.name,key:h,scopes:t,expiresAt:r,notBefore:e.notBefore,createdAt:new Date().toISOString()},x=[...m.apiKeys??[],k];if(M({apiKeys:x}),u(f,{ok:!0,id:p,name:e.name,scopes:t,expiresAt:r??null,key:h}))return;if(l(`Minted key ${p}`),n("Name",e.name),n("Scopes",t.join(",")),r)n("Expires",r);if(e.notBefore)n("Not before",e.notBefore);c(),n("Key (save now)",i.bold(h))}catch(t){if(f.json){u(f,{ok:!1,error:A(t)});return}s(A(t))}}),d.command("revoke <id>").description("Revoke a scoped key by ID").option("--json","Emit JSON").action(function(e,f){let t={...a.opts(),...f};try{let r=w(),m=(r.apiKeys??[]).length,p=(r.apiKeys??[]).filter((h)=>h.id!==e);if(p.length===m){if(t.json){u(t,{ok:!1,error:`No key with id ${e}`});return}s(`No key with id ${e}`);return}if(M({apiKeys:p}),u(t,{ok:!0,id:e}))return;l(`Revoked key ${e}`)}catch(r){if(t.json){u(t,{ok:!1,error:A(r)});return}s(A(r))}}),d.command("rotate <id>").description("Rotate the secret of an existing scoped key (preserves scopes/expiry)").option("--json","Emit JSON").action(function(e,f){let t={...a.opts(),...f};try{let r=w();if(!(r.apiKeys??[]).find((k)=>k.id===e)){if(t.json){u(t,{ok:!1,error:`No key with id ${e}`});return}s(`No key with id ${e}`);return}let p=I(),h=(r.apiKeys??[]).map((k)=>k.id===e?{...k,key:p}:k);if(M({apiKeys:h}),u(t,{ok:!0,id:e,key:p}))return;l(`Rotated key ${e}`),n("New key (save now)",i.bold(p))}catch(r){if(t.json){u(t,{ok:!1,error:A(r)});return}s(A(r))}})}
|
|
3
|
+
export{Vi,jr};
|