@augmentcode/auggie 0.37.0-prerelease.3 → 1.2.0-prerelease.202608251328
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/CHANGELOG.md +0 -0
- package/README.md +0 -42
- package/{augment.mjs → auggie-v2.mjs} +13380 -7524
- package/auggie-v2.mjs.d/extensions/ask-user/index.js +21 -0
- package/auggie-v2.mjs.d/extensions/manifest.json +20 -0
- package/auggie-v2.mjs.d/extensions/mcp/index.js +158 -0
- package/auggie-v2.mjs.d/extensions/migration/index.js +114 -0
- package/auggie-v2.mjs.d/extensions/otel/index.js +28 -0
- package/auggie-v2.mjs.d/photon_rs_bg.wasm +0 -0
- package/indexing-worker.mjs +288 -0
- package/package.json +29 -15
- package/vfs-prefetch-worker.mjs +38 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
var Nr=Object.create;var nn=Object.defineProperty;var Kr=Object.getOwnPropertyDescriptor;var Ur=Object.getOwnPropertyNames;var jr=Object.getPrototypeOf,$r=Object.prototype.hasOwnProperty;var x=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var h=(r,e)=>()=>{try{return e||r((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}};var Wr=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Ur(e))!$r.call(r,s)&&s!==t&&nn(r,s,{get:()=>e[s],enumerable:!(n=Kr(e,s))||n.enumerable});return r};var Gr=(r,e,t)=>(t=r!=null?Nr(jr(r)):{},Wr(e||!r||!r.__esModule?nn(t,"default",{value:r,enumerable:!0}):t,r));var dn=h(fn=>{"use strict";fn.supports=function(...e){let t=e.reduce((i,o)=>Object.assign(i,o),{}),n=t.implicitSnapshots||t.snapshots||!1,s=t.explicitSnapshots||!1;return Object.assign(t,{implicitSnapshots:n,explicitSnapshots:s,snapshots:n,has:t.has||!1,permanence:t.permanence||!1,seek:t.seek||!1,createIfMissing:t.createIfMissing||!1,errorIfExists:t.errorIfExists||!1,deferredOpen:t.deferredOpen||!1,streams:t.streams||!1,encodings:Object.assign({},t.encodings),events:Object.assign({},t.events),additionalMethods:Object.assign({},t.additionalMethods),signals:Object.assign({},t.signals)})}});var T=h((wo,yn)=>{"use strict";yn.exports=class extends Error{constructor(e,t){super(e||""),typeof t=="object"&&t!==null&&(t.code&&(this.code=String(t.code)),t.expected&&(this.expected=!0),t.transient&&(this.transient=!0),t.cause&&(this.cause=t.cause)),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}});var Qe=h((Eo,gn)=>{"use strict";var Je=null;gn.exports=function(){return Je===null&&(Je={textEncoder:new TextEncoder,textDecoder:new TextDecoder}),Je}});var tt=h(pn=>{"use strict";var Ze=T(),as=new Set(["buffer","view","utf8"]),et=class{constructor(e){if(this.encode=e.encode||this.encode,this.decode=e.decode||this.decode,this.name=e.name||this.name,this.format=e.format||this.format,typeof this.encode!="function")throw new TypeError("The 'encode' property must be a function");if(typeof this.decode!="function")throw new TypeError("The 'decode' property must be a function");if(this.encode=this.encode.bind(this),this.decode=this.decode.bind(this),typeof this.name!="string"||this.name==="")throw new TypeError("The 'name' property must be a string");if(typeof this.format!="string"||!as.has(this.format))throw new TypeError("The 'format' property must be one of 'buffer', 'view', 'utf8'");e.createViewTranscoder&&(this.createViewTranscoder=e.createViewTranscoder),e.createBufferTranscoder&&(this.createBufferTranscoder=e.createBufferTranscoder),e.createUTF8Transcoder&&(this.createUTF8Transcoder=e.createUTF8Transcoder)}get commonName(){return this.name.split("+")[0]}createBufferTranscoder(){throw new Ze(`Encoding '${this.name}' cannot be transcoded to 'buffer'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createViewTranscoder(){throw new Ze(`Encoding '${this.name}' cannot be transcoded to 'view'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createUTF8Transcoder(){throw new Ze(`Encoding '${this.name}' cannot be transcoded to 'utf8'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}};pn.Encoding=et});var it=h(be=>{"use strict";var{Buffer:rt}=x("buffer")||{},{Encoding:st}=tt(),cs=Qe(),Z=class extends st{constructor(e){super({...e,format:"buffer"})}createViewTranscoder(){return new ee({encode:this.encode,decode:e=>this.decode(rt.from(e.buffer,e.byteOffset,e.byteLength)),name:`${this.name}+view`})}createBufferTranscoder(){return this}},ee=class extends st{constructor(e){super({...e,format:"view"})}createBufferTranscoder(){return new Z({encode:e=>{let t=this.encode(e);return rt.from(t.buffer,t.byteOffset,t.byteLength)},decode:this.decode,name:`${this.name}+buffer`})}createViewTranscoder(){return this}},nt=class extends st{constructor(e){super({...e,format:"utf8"})}createBufferTranscoder(){return new Z({encode:e=>rt.from(this.encode(e),"utf8"),decode:e=>this.decode(e.toString("utf8")),name:`${this.name}+buffer`})}createViewTranscoder(){let{textEncoder:e,textDecoder:t}=cs();return new ee({encode:n=>e.encode(this.encode(n)),decode:n=>this.decode(t.decode(n)),name:`${this.name}+view`})}createUTF8Transcoder(){return this}};be.BufferFormat=Z;be.ViewFormat=ee;be.UTF8Format=nt});var bn=h(q=>{"use strict";var{Buffer:E}=x("buffer")||{Buffer:{isBuffer:()=>!1}},{textEncoder:wn,textDecoder:mn}=Qe()(),{BufferFormat:te,ViewFormat:ot,UTF8Format:En}=it(),_e=r=>r;q.utf8=new En({encode:function(r){return E.isBuffer(r)?r.toString("utf8"):ArrayBuffer.isView(r)?mn.decode(r):String(r)},decode:_e,name:"utf8",createViewTranscoder(){return new ot({encode:function(r){return ArrayBuffer.isView(r)?r:wn.encode(r)},decode:function(r){return mn.decode(r)},name:`${this.name}+view`})},createBufferTranscoder(){return new te({encode:function(r){return E.isBuffer(r)?r:ArrayBuffer.isView(r)?E.from(r.buffer,r.byteOffset,r.byteLength):E.from(String(r),"utf8")},decode:function(r){return r.toString("utf8")},name:`${this.name}+buffer`})}});q.json=new En({encode:JSON.stringify,decode:JSON.parse,name:"json"});q.buffer=new te({encode:function(r){return E.isBuffer(r)?r:ArrayBuffer.isView(r)?E.from(r.buffer,r.byteOffset,r.byteLength):E.from(String(r),"utf8")},decode:_e,name:"buffer",createViewTranscoder(){return new ot({encode:function(r){return ArrayBuffer.isView(r)?r:E.from(String(r),"utf8")},decode:function(r){return E.from(r.buffer,r.byteOffset,r.byteLength)},name:`${this.name}+view`})}});q.view=new ot({encode:function(r){return ArrayBuffer.isView(r)?r:wn.encode(r)},decode:_e,name:"view",createBufferTranscoder(){return new te({encode:function(r){return E.isBuffer(r)?r:ArrayBuffer.isView(r)?E.from(r.buffer,r.byteOffset,r.byteLength):E.from(String(r),"utf8")},decode:_e,name:`${this.name}+buffer`})}});q.hex=new te({encode:function(r){return E.isBuffer(r)?r:E.from(String(r),"hex")},decode:function(r){return r.toString("hex")},name:"hex"});q.base64=new te({encode:function(r){return E.isBuffer(r)?r:E.from(String(r),"base64")},decode:function(r){return r.toString("base64")},name:"base64"})});var kn=h(vn=>{"use strict";var _n=T(),ke=bn(),{Encoding:us}=tt(),{BufferFormat:ls,ViewFormat:hs,UTF8Format:fs}=it(),ne=Symbol("formats"),ve=Symbol("encodings"),ds=new Set(["buffer","view","utf8"]),at=class{constructor(e){if(Array.isArray(e)){if(!e.every(t=>ds.has(t)))throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}else throw new TypeError("The first argument 'formats' must be an array");this[ve]=new Map,this[ne]=new Set(e);for(let t in ke)try{this.encoding(t)}catch(n){if(n.code!=="LEVEL_ENCODING_NOT_SUPPORTED")throw n}}encodings(){return Array.from(new Set(this[ve].values()))}encoding(e){let t=this[ve].get(e);if(t===void 0){if(typeof e=="string"&&e!==""){if(t=ms[e],!t)throw new _n(`Encoding '${e}' is not found`,{code:"LEVEL_ENCODING_NOT_FOUND"})}else{if(typeof e!="object"||e===null)throw new TypeError("First argument 'encoding' must be a string or object");t=ys(e)}let{name:n,format:s}=t;if(!this[ne].has(s))if(this[ne].has("view"))t=t.createViewTranscoder();else if(this[ne].has("buffer"))t=t.createBufferTranscoder();else if(this[ne].has("utf8"))t=t.createUTF8Transcoder();else throw new _n(`Encoding '${n}' cannot be transcoded`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"});for(let i of[e,n,t.name,t.commonName])this[ve].set(i,t)}return t}};vn.Transcoder=at;function ys(r){if(r instanceof us)return r;let e="type"in r&&typeof r.type=="string"?r.type:void 0,t=r.name||e||`anonymous-${ws++}`;switch(gs(r)){case"view":return new hs({...r,name:t});case"utf8":return new fs({...r,name:t});case"buffer":return new ls({...r,name:t});default:throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}}function gs(r){return"format"in r&&r.format!==void 0?r.format:"buffer"in r&&typeof r.buffer=="boolean"?r.buffer?"buffer":"utf8":"code"in r&&Number.isInteger(r.code)?"view":"buffer"}var ps={binary:ke.buffer,"utf-8":ke.utf8},ms={...ke,...ps},ws=0});var xe=h((xo,Sn)=>{"use strict";var xn=Symbol("kErrors");Sn.exports=function(r){if(r=r.filter(Es),r.length!==0)return r.length===1?r[0]:new ut(r)};var ut=class extends Error{constructor(e){let t=new Set(e.map(bs).filter(Boolean)),n=Array.from(t).join("; ");super(n),Tn(this,"name","CombinedError"),Tn(this,xn,e),ct(this,"stack",()=>e.map(_s).join(`
|
|
2
|
+
|
|
3
|
+
`)),ct(this,"transient",()=>e.length>0&&e.every(vs)),ct(this,"expected",()=>e.length>0&&e.every(ks))}[Symbol.iterator](){return this[xn][Symbol.iterator]()}};function Tn(r,e,t){Object.defineProperty(r,e,{value:t})}function ct(r,e,t){Object.defineProperty(r,e,{get:t})}function Es(r){return r!=null}function bs(r){return r.message}function _s(r){return r.stack}function vs(r){return r.transient===!0}function ks(r){return r.expected===!0}});var V=h(H=>{"use strict";var xs=T(),An=new Set;H.getOptions=function(r,e){return typeof r=="object"&&r!==null?r:e!==void 0?e:{}};H.emptyOptions=Object.freeze({});H.noop=function(){};H.resolvedPromise=Promise.resolve();H.deprecate=function(r){if(!An.has(r)){An.add(r);let e=globalThis.console;typeof e<"u"&&typeof e.warn=="function"&&e.warn(new xs(r,{code:"LEVEL_LEGACY"}))}}});var ht=h(On=>{"use strict";var Ts=T(),lt=class extends Ts{constructor(e){super("Operation has been aborted",{code:"LEVEL_ABORTED",cause:e})}get name(){return"AbortError"}};On.AbortError=lt});var C=h(Se=>{"use strict";var re=T(),Ss=xe(),{getOptions:ft,emptyOptions:dt,noop:As}=V(),{AbortError:Os}=ht(),Te=Symbol("decodeOne"),ie=Symbol("decodeMany"),D=Symbol("keyEncoding"),B=Symbol("valueEncoding"),Y=class{#e=!1;#t=null;#n=null;#i=0;#a;#r;#o;#s;constructor(e,t){if(typeof e!="object"||e===null){let n=e===null?"null":typeof e;throw new TypeError(`The first argument must be an abstract-level database, received ${n}`)}if(typeof t!="object"||t===null)throw new TypeError("The second argument must be an options object");this[D]=t[D],this[B]=t[B],this.#r=Number.isInteger(t.limit)&&t.limit>=0?t.limit:1/0,this.#a=t.signal!=null?t.signal:null,this.#s=t.snapshot!=null?t.snapshot:null,this.#o=!1,this.db=e,this.db.attachResource(this)}get count(){return this.#i}get limit(){return this.#r}async next(){this.#u();try{if(this.#o||this.#i>=this.#r){this.#o=!0;return}let e=await this._next();if(e===void 0){this.#o=!0;return}try{e=this[Te](e)}catch(t){throw new se(t)}return this.#i++,e}finally{this.#c()}}async _next(){}async nextv(e,t){if(!Number.isInteger(e))throw new TypeError("The first argument 'size' must be an integer");t=ft(t,dt),e<1&&(e=1),this.#r<1/0&&(e=Math.min(e,this.#r-this.#i)),this.#u();try{if(this.#o||e<=0)return this.#o=!0,[];let n=await this._nextv(e,t);if(n.length===0)return this.#o=!0,n;try{this[ie](n)}catch(s){throw new se(s)}return this.#i+=n.length,n}finally{this.#c()}}async _nextv(e,t){let n=[];for(;n.length<e;){let s=await this._next(t);if(s!==void 0)n.push(s);else{this.#o=!0;break}}return n}async all(e){e=ft(e,dt),this.#u();try{if(this.#o||this.#i>=this.#r)return[];let t=await this._all(e);try{this[ie](t)}catch(n){throw new se(n)}return this.#i+=t.length,t}catch(t){this.#c(),await this.#f(t)}finally{this.#o=!0,this.#e&&(this.#c(),await this.close())}}async _all(e){let t=this.#i,n=[];for(;;){let s=this.#r<1/0?Math.min(1e3,this.#r-t):1e3;if(s<=0)return n;let i=await this._nextv(s,e);if(i.length===0)return n;n.push.apply(n,i),t+=i.length}}seek(e,t){if(t=ft(t,dt),this.#n===null){if(this.#e)throw new re("Iterator is busy: cannot call seek() until next() has completed",{code:"LEVEL_ITERATOR_BUSY"});{let n=this.db.keyEncoding(t.keyEncoding||this[D]),s=n.format;t.keyEncoding!==s&&(t={...t,keyEncoding:s});let i=this.db.prefixKey(n.encode(e),s,!1);this._seek(i,t),this.#o=!1}}}_seek(e,t){throw new re("Iterator does not implement seek()",{code:"LEVEL_NOT_SUPPORTED"})}async close(){return this.#n!==null?this.#n.catch(As):(this.#n=new Promise((e,t)=>{this.#t=()=>{this.#t=null,this.#h().then(e,t)}}),this.#e||this.#t(),this.#n)}async _close(){}async*[Symbol.asyncIterator](){try{let e;for(;(e=await this.next())!==void 0;)yield e}catch(e){await this.#f(e)}finally{await this.close()}}#u(){if(this.#n!==null)throw new re("Iterator is not open: cannot read after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"});if(this.#e)throw new re("Iterator is busy: cannot read until previous read has completed",{code:"LEVEL_ITERATOR_BUSY"});if(this.#a?.aborted)throw new Os;this.#s?.ref(),this.#e=!0}#c(){this.#e=!1,this.#t?.(),this.#s?.unref()}async#h(){await this._close(),this.db.detachResource(this)}async#f(e){try{await this.close()}catch(t){throw Ss([e,t])}throw e}};typeof Symbol.asyncDispose=="symbol"&&(Y.prototype[Symbol.asyncDispose]=async function(){return this.close()});var oe=class extends Y{#e;#t;constructor(e,t){super(e,t),this.#e=t.keys!==!1,this.#t=t.values!==!1}[Te](e){let t=e[0],n=e[1];return t!==void 0&&(e[0]=this.#e?this[D].decode(t):void 0),n!==void 0&&(e[1]=this.#t?this[B].decode(n):void 0),e}[ie](e){let t=this[D],n=this[B];for(let s of e){let i=s[0],o=s[1];i!==void 0&&(s[0]=this.#e?t.decode(i):void 0),o!==void 0&&(s[1]=this.#t?n.decode(o):void 0)}}},yt=class extends Y{[Te](e){return this[D].decode(e)}[ie](e){let t=this[D];for(let n=0;n<e.length;n++){let s=e[n];s!==void 0&&(e[n]=t.decode(s))}}},gt=class extends Y{[Te](e){return this[B].decode(e)}[ie](e){let t=this[B];for(let n=0;n<e.length;n++){let s=e[n];s!==void 0&&(e[n]=t.decode(s))}}},se=class extends re{constructor(e){super("Iterator could not decode data",{code:"LEVEL_DECODE_ERROR",cause:e})}};oe.keyEncoding=D;oe.valueEncoding=B;Se.AbstractIterator=oe;Se.AbstractKeyIterator=yt;Se.AbstractValueIterator=gt});var Ln=h(mt=>{"use strict";var{AbstractKeyIterator:Ls,AbstractValueIterator:Rs}=C(),N=Symbol("iterator"),pt=Symbol("handleOne"),Ae=Symbol("handleMany"),Oe=class extends Ls{constructor(e,t){super(e,t),this[N]=e.iterator({...t,keys:!0,values:!1})}[pt](e){return e[0]}[Ae](e){for(let t=0;t<e.length;t++)e[t]=e[t][0]}},Le=class extends Rs{constructor(e,t){super(e,t),this[N]=e.iterator({...t,keys:!1,values:!0})}[pt](e){return e[1]}[Ae](e){for(let t=0;t<e.length;t++)e[t]=e[t][1]}};for(let r of[Oe,Le])r.prototype._next=async function(){let e=await this[N].next();return e===void 0?e:this[pt](e)},r.prototype._nextv=async function(e,t){let n=await this[N].nextv(e,t);return this[Ae](n),n},r.prototype._all=async function(e){let t=await this[N].all(e);return this[Ae](t),t},r.prototype._seek=function(e,t){this[N].seek(e,t)},r.prototype._close=async function(){return this[N].close()};mt.DefaultKeyIterator=Oe;mt.DefaultValueIterator=Le});var Rn=h(Pe=>{"use strict";var{AbstractIterator:Is,AbstractKeyIterator:Vs,AbstractValueIterator:Ds}=C(),wt=T(),b=Symbol("nut"),De=Symbol("undefer"),Ce=Symbol("factory"),A=Symbol("signalOptions"),Re=class extends Is{constructor(e,t){super(e,t),this[b]=null,this[Ce]=()=>e.iterator(t),this[A]={signal:t.signal},this.db.defer(()=>this[De](),this[A])}},Ie=class extends Vs{constructor(e,t){super(e,t),this[b]=null,this[Ce]=()=>e.keys(t),this[A]={signal:t.signal},this.db.defer(()=>this[De](),this[A])}},Ve=class extends Ds{constructor(e,t){super(e,t),this[b]=null,this[Ce]=()=>e.values(t),this[A]={signal:t.signal},this.db.defer(()=>this[De](),this[A])}};for(let r of[Re,Ie,Ve])r.prototype[De]=function(){this.db.status==="open"&&(this[b]=this[Ce]())},r.prototype._next=async function(){if(this[b]!==null)return this[b].next();if(this.db.status==="opening")return this.db.deferAsync(()=>this._next(),this[A]);throw new wt("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})},r.prototype._nextv=async function(e,t){if(this[b]!==null)return this[b].nextv(e,t);if(this.db.status==="opening")return this.db.deferAsync(()=>this._nextv(e,t),this[A]);throw new wt("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})},r.prototype._all=async function(e){if(this[b]!==null)return this[b].all();if(this.db.status==="opening")return this.db.deferAsync(()=>this._all(e),this[A]);throw new wt("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})},r.prototype._seek=function(e,t){this[b]!==null?this[b]._seek(e,t):this.db.status==="opening"&&this.db.defer(()=>this._seek(e,t),this[A])},r.prototype._close=async function(){if(this[b]!==null)return this[b].close();if(this.db.status==="opening")return this.db.deferAsync(()=>this._close())};Pe.DeferredIterator=Re;Pe.DeferredKeyIterator=Ie;Pe.DeferredValueIterator=Ve});var Me=h(Et=>{"use strict";Et.prefixDescendantKey=function(r,e,t,n){for(;t!==null&&t!==n;)r=t.prefixKey(r,e,!0),t=t.parent;return r};Et.isDescendant=function(r,e){for(;;){if(r.parent==null)return!1;if(r.parent===e)return!0;r=r.parent}}});var _t=h(In=>{"use strict";var{prefixDescendantKey:Cs,isDescendant:Ps}=Me(),bt=class{#e;#t;#n;constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n}add(e){let t=e.type==="put",n=e.sublevel!=null,s=n?e.sublevel:this.#e;if(s._assertValidKey(e.key),e.keyEncoding=s.keyEncoding(e.keyEncoding),t)s._assertValidValue(e.value),e.valueEncoding=s.valueEncoding(e.valueEncoding);else if(e.type!=="del")throw new TypeError("A batch operation must have a type property that is 'put' or 'del'");let i=e.keyEncoding,o=i.encode(e.key),a=i.format,u=n&&!Ps(e.sublevel,this.#e)&&e.sublevel!==this.#e,l=n&&!u?Cs(o,a,s,this.#e):o;n&&!u&&(e.sublevel=null);let c=null;if(this.#n!==null&&!u&&(c={...e},c.encodedKey=l,n&&(c.key=l,c.keyEncoding=this.#e.keyEncoding(a)),this.#n.push(c)),e.key=u?l:this.#e.prefixKey(l,a,!0),e.keyEncoding=a,t){let d=e.valueEncoding,y=d.encode(e.value),g=d.format;e.value=y,e.valueEncoding=g,c!==null&&(c.encodedValue=y,n&&(c.value=y,c.valueEncoding=this.#e.valueEncoding(g)))}return this.#t.push(e),this}};In.PrewriteBatch=bt});var xt=h(Dn=>{"use strict";var Ms=xe(),Fe=T(),{getOptions:qe,emptyOptions:vt,noop:Fs}=V(),{prefixDescendantKey:Vn,isDescendant:qs}=Me(),{PrewriteBatch:Bs}=_t(),Be=Symbol("publicOperations"),ae=Symbol("privateOperations"),Ne=class{#e="open";#t=0;#n=null;#i;#a;#r;#o;#s;constructor(e,t){if(typeof e!="object"||e===null){let i=e===null?"null":typeof e;throw new TypeError(`The first argument must be an abstract-level database, received ${i}`)}let n=e.listenerCount("write")>0,s=!e.hooks.prewrite.noop;if(this.#i=n?[]:null,this.#s=qe(t,vt).add===!0,s){let i=new kt([],n?[]:null);this.#o=i,this.#r=new Bs(e,i[ae],i[Be]),this.#a=e.hooks.prewrite.run}else this.#o=null,this.#r=null,this.#a=null;this.db=e,this.db.attachResource(this)}get length(){return this.#o!==null?this.#t+this.#o.length:this.#t}put(e,t,n){this.#u(),n=qe(n,vt);let s=n.sublevel!=null,i=s?n.sublevel:this.db;i._assertValidKey(e),i._assertValidValue(t);let o={...n,type:"put",key:e,value:t,keyEncoding:i.keyEncoding(n.keyEncoding),valueEncoding:i.valueEncoding(n.valueEncoding)};if(this.#a!==null)try{this.#a(o,this.#r),o.keyEncoding=i.keyEncoding(o.keyEncoding),o.valueEncoding=i.valueEncoding(o.valueEncoding)}catch(m){throw new Fe("The prewrite hook failed on batch.put()",{code:"LEVEL_HOOK_ERROR",cause:m})}let a=o.keyEncoding,u=a.encode(o.key),l=a.format,c=s&&!qs(o.sublevel,this.db)&&o.sublevel!==this.db,d=s&&!c?Vn(u,l,i,this.db):u,y=o.valueEncoding,g=y.encode(o.value),k=y.format;if(s&&!c&&(o.sublevel=null),this.#i!==null&&!c){let m={...o};m.encodedKey=d,m.encodedValue=g,s&&(m.key=d,m.value=g,m.keyEncoding=this.db.keyEncoding(l),m.valueEncoding=this.db.valueEncoding(k)),this.#i.push(m)}return o.key=c?d:this.db.prefixKey(d,l,!0),o.value=g,o.keyEncoding=l,o.valueEncoding=k,this.#s?this._add(o):this._put(o.key,g,o),this.#t++,this}_put(e,t,n){}del(e,t){this.#u(),t=qe(t,vt);let n=t.sublevel!=null,s=n?t.sublevel:this.db;s._assertValidKey(e);let i={...t,type:"del",key:e,keyEncoding:s.keyEncoding(t.keyEncoding)};if(this.#a!==null)try{this.#a(i,this.#r),i.keyEncoding=s.keyEncoding(i.keyEncoding)}catch(c){throw new Fe("The prewrite hook failed on batch.del()",{code:"LEVEL_HOOK_ERROR",cause:c})}let o=i.keyEncoding,a=o.encode(i.key),u=o.format,l=n?Vn(a,u,s,this.db):a;if(n&&(i.sublevel=null),this.#i!==null){let c={...i};c.encodedKey=l,n&&(c.key=l,c.keyEncoding=this.db.keyEncoding(u)),this.#i.push(c)}return i.key=this.db.prefixKey(l,u,!0),i.keyEncoding=u,this.#s?this._add(i):this._del(i.key,i),this.#t++,this}_del(e,t){}_add(e){}clear(){return this.#u(),this._clear(),this.#i!==null&&(this.#i=[]),this.#o!==null&&this.#o.clear(),this.#t=0,this}_clear(){}async write(e){if(this.#u(),e=qe(e),this.#t===0)return this.close();{this.#e="writing";let t=this.#c();try{if(this.#o!==null){let n=this.#o[Be],s=this.#o[ae],i=this.#o.length;for(let o=0;o<i;o++){let a=s[o];this.#s?this._add(a):a.type==="put"?this._put(a.key,a.value,a):this._del(a.key,a)}n!==null&&i!==0&&(this.#i=this.#i.concat(n))}await this._write(e)}catch(n){t();try{await this.#n}catch(s){n=Ms([n,s])}throw n}return t(),this.#i!==null&&this.db.emit("write",this.#i),this.#n}}async _write(e){}async close(){return this.#n!==null?this.#n.catch(Fs):(this.#c()(),this.#n)}async _close(){}#u(){if(this.#e!=="open")throw new Fe("Batch is not open: cannot change operations after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});if(this.db.status!=="open")throw new Fe("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"})}#c(){let e;return this.#n=new Promise((t,n)=>{e=()=>{this.#h().then(t,n)}}),e}async#h(){this.#e="closing",await this._close(),this.db.detachResource(this)}};typeof Symbol.asyncDispose=="symbol"&&(Ne.prototype[Symbol.asyncDispose]=async function(){return this.close()});var kt=class{constructor(e,t){this[ae]=e,this[Be]=t}get length(){return this[ae].length}clear(){for(let e of[Be,ae]){let t=this[e];t!==null&&t.splice(0,t.length)}}};Dn.AbstractChainedBatch=Ne});var Pn=h(Cn=>{"use strict";var{AbstractChainedBatch:Ns}=xt(),Tt=class extends Ns{#e=[];constructor(e){super(e,{add:!0})}_add(e){this.#e.push(e)}_clear(){this.#e=[]}async _write(e){return this.db._batch(this.#e,e)}};Cn.DefaultChainedBatch=Tt});var qn=h(Fn=>{"use strict";var{noop:Ks}=V(),St=class{constructor(){this.postopen=new ce({async:!0}),this.prewrite=new ce({async:!1}),this.newsub=new ce({async:!1})}},ce=class{#e=new Set;#t;constructor(e){this.#t=e.async,this.noop=!0,this.run=this.#n()}add(e){Mn(e),this.#e.add(e),this.noop=!1,this.run=this.#n()}delete(e){Mn(e),this.#e.delete(e),this.noop=this.#e.size===0,this.run=this.#n()}#n(){if(this.noop)return Ks;if(this.#e.size===1){let[e]=this.#e;return e}else return this.#t?async function(t,...n){for(let s of t)await s(...n)}.bind(null,Array.from(this.#e)):function(t,...n){for(let s of t)s(...n)}.bind(null,Array.from(this.#e))}},Mn=function(r){if(typeof r!="function"){let e=r===null?"null":typeof r;throw new TypeError(`The first argument must be a function, received ${e}`)}};Fn.DatabaseHooks=St});var Nn=h(Bn=>{"use strict";var{deprecate:Us}=V();Bn.EventMonitor=class{constructor(e){this.write=!1;let t=s=>{s==="write"&&(this.write=!0),(s==="put"||s==="del"||s==="batch")&&Us(`The '${s}' event has been removed in favor of 'write'`)},n=s=>{s==="write"&&(this.write=e.listenerCount("write")>0)};e.on("newListener",t),e.on("removeListener",n)}}});var jn=h(Un=>{"use strict";var{getOptions:js,emptyOptions:$s}=V(),{AbortError:Kn}=ht(),Ke=class{constructor(e,t){this.fn=e,this.signal=t}},At=class{#e;#t;constructor(){this.#e=[],this.#t=new Set}add(e,t){t=js(t,$s);let n=t.signal;if(n==null){this.#e.push(new Ke(e,null));return}if(n.aborted){e(new Kn);return}this.#t.has(n)||(this.#t.add(n),n.addEventListener("abort",this.#n,{once:!0})),this.#e.push(new Ke(e,n))}drain(){let e=this.#e,t=this.#t;this.#e=[],this.#t=new Set;for(let n of t)n.removeEventListener("abort",this.#n);for(let n of e)n.fn.call(null)}#n=e=>{let t=e.target,n=new Kn,s=[];this.#e=this.#e.filter(function(i){return i.signal!==null&&i.signal===t?(s.push(i),!1):!0}),this.#t.delete(t);for(let i of s)i.fn.call(null,n)}};Un.DeferredQueue=At});var Wn=h((qo,$n)=>{"use strict";var Ws=Object.prototype.hasOwnProperty,Gs=new Set(["lt","lte","gt","gte"]);$n.exports=function(r,e){let t={};for(let n in r)Ws.call(r,n)&&(n==="keyEncoding"||n==="valueEncoding"||(Gs.has(n)?t[n]=e.encode(r[n]):t[n]=r[n]));return t.reverse=!!t.reverse,t.limit=Number.isInteger(t.limit)&&t.limit>=0?t.limit:-1,t}});var Gn=h(Ue=>{"use strict";var{AbstractIterator:Hs,AbstractKeyIterator:Ys,AbstractValueIterator:zs}=C(),Ot=class extends Hs{#e;#t;constructor(e,t,n,s){super(e,t),this.#e=n,this.#t=s}async _next(){let e=await this.#e.next();if(e!==void 0){let t=e[0];t!==void 0&&(e[0]=this.#t(t))}return e}async _nextv(e,t){let n=await this.#e.nextv(e,t),s=this.#t;for(let i of n){let o=i[0];o!==void 0&&(i[0]=s(o))}return n}async _all(e){let t=await this.#e.all(e),n=this.#t;for(let s of t){let i=s[0];i!==void 0&&(s[0]=n(i))}return t}_seek(e,t){this.#e.seek(e,t)}async _close(){return this.#e.close()}},Lt=class extends Ys{#e;#t;constructor(e,t,n,s){super(e,t),this.#e=n,this.#t=s}async _next(){let e=await this.#e.next();return e===void 0?e:this.#t(e)}async _nextv(e,t){let n=await this.#e.nextv(e,t),s=this.#t;for(let i=0;i<n.length;i++){let o=n[i];o!==void 0&&(n[i]=s(o))}return n}async _all(e){let t=await this.#e.all(e),n=this.#t;for(let s=0;s<t.length;s++){let i=t[s];i!==void 0&&(t[s]=n(i))}return t}_seek(e,t){this.#e.seek(e,t)}async _close(){return this.#e.close()}},Rt=class extends zs{#e;constructor(e,t,n){super(e,t),this.#e=n}async _next(){return this.#e.next()}async _nextv(e,t){return this.#e.nextv(e,t)}async _all(e){return this.#e.all(e)}_seek(e,t){this.#e.seek(e,t)}async _close(){return this.#e.close()}};Ue.AbstractSublevelIterator=Ot;Ue.AbstractSublevelKeyIterator=Lt;Ue.AbstractSublevelValueIterator=Rt});var zn=h((No,Yn)=>{"use strict";var Xs=T(),{Buffer:Vt}=x("buffer")||{},{AbstractSublevelIterator:Js,AbstractSublevelKeyIterator:Qs,AbstractSublevelValueIterator:Zs}=Gn(),P=Symbol("root"),Hn=new TextEncoder,ei={separator:"!"};Yn.exports=function({AbstractLevel:r}){class e extends r{#e;#t;#n;#i;#a;#r;#o;static defaults(n){return n==null?ei:n.separator?n:{...n,separator:"!"}}constructor(n,s,i){let{separator:o,manifest:a,...u}=e.defaults(i),l=[].concat(s).map(m=>ni(m,o)),c=o.charCodeAt(0)+1,d=n[P]||n;if(!l.every(m=>Hn.encode(m).every(F=>F>c&&F<127)))throw new Xs(`Sublevel name must use bytes > ${c} < 127`,{code:"LEVEL_INVALID_PREFIX"});super(ti(n,a),u);let y=l.map(m=>o+m+o).join(""),g=(n.prefix||"")+y,k=g.slice(0,-1)+String.fromCharCode(c);this[P]=d,this.#r=n,this.#n=l,this.#i=n.prefix?n.path().concat(l):l,this.#e=new ue(g),this.#a=new ue(k),this.#t=new ue(y),this.#o=new Dt}prefixKey(n,s,i){let o=i?this.#t:this.#e;if(s==="utf8")return o.utf8+n;if(n.byteLength===0)return o[s];if(s==="view"){let a=o.view,u=new Uint8Array(a.byteLength+n.byteLength);return u.set(a,0),u.set(n,a.byteLength),u}else{let a=o.buffer;return Vt.concat([a,n],a.byteLength+n.byteLength)}}#s(n,s){n.gte!==void 0?n.gte=this.prefixKey(n.gte,s,!1):n.gt!==void 0?n.gt=this.prefixKey(n.gt,s,!1):n.gte=this.#e[s],n.lte!==void 0?n.lte=this.prefixKey(n.lte,s,!1):n.lt!==void 0?n.lt=this.prefixKey(n.lt,s,!1):n.lte=this.#a[s]}get prefix(){return this.#e.utf8}get db(){return this[P]}get parent(){return this.#r}path(n=!1){return n?this.#n:this.#i}async _open(n){await this.#r.open({passive:!0}),this.#r.attachResource(this)}async _close(){this.#r.detachResource(this)}async _put(n,s,i){return this.#r.put(n,s,i)}async _get(n,s){return this.#r.get(n,s)}_getSync(n,s){return this.#r.getSync(n,s)}async _getMany(n,s){return this.#r.getMany(n,s)}async _has(n,s){return this.#r.has(n,s)}async _hasMany(n,s){return this.#r.hasMany(n,s)}async _del(n,s){return this.#r.del(n,s)}async _batch(n,s){return this.#r.batch(n,s)}async _clear(n){return this.#s(n,n.keyEncoding),this[P].clear(n)}_iterator(n){this.#s(n,n.keyEncoding);let s=this[P].iterator(n),i=this.#o.get(this.#e.utf8.length,n.keyEncoding);return new Js(this,n,s,i)}_keys(n){this.#s(n,n.keyEncoding);let s=this[P].keys(n),i=this.#o.get(this.#e.utf8.length,n.keyEncoding);return new Qs(this,n,s,i)}_values(n){this.#s(n,n.keyEncoding);let s=this[P].values(n);return new Zs(this,n,s)}_snapshot(n){return this[P].snapshot(n)}}return{AbstractSublevel:e}};var ti=function(r,e){return{...r.supports,createIfMissing:!1,errorIfExists:!1,events:{},additionalMethods:{},...e,encodings:{utf8:It(r,"utf8"),buffer:It(r,"buffer"),view:It(r,"view")}}},It=function(r,e){return r.supports.encodings[e]?r.keyEncoding(e).name===e:!1},ue=class{constructor(e){this.utf8=e,this.view=Hn.encode(e),this.buffer=Vt?Vt.from(this.view.buffer,0,this.view.byteLength):{}}},Dt=class{constructor(){this.cache=new Map}get(e,t){let n=this.cache.get(t);return n===void 0&&(t==="view"?n=function(s,i){return i.subarray(s)}.bind(null,e):n=function(s,i){return i.slice(s)}.bind(null,e),this.cache.set(t,n)),n}},ni=function(r,e){let t=0,n=r.length;for(;t<n&&r[t]===e;)t++;for(;n>t&&r[n-1]===e;)n--;return r.slice(t,n)}});var qt=h(Ft=>{"use strict";var{supports:ri}=dn(),{Transcoder:si}=kn(),{EventEmitter:ii}=x("events"),w=T(),Ct=xe(),{AbstractIterator:K}=C(),{DefaultKeyIterator:oi,DefaultValueIterator:ai}=Ln(),{DeferredIterator:ci,DeferredKeyIterator:ui,DeferredValueIterator:li}=Rn(),{DefaultChainedBatch:hi}=Pn(),{DatabaseHooks:fi}=qn(),{PrewriteBatch:di}=_t(),{EventMonitor:yi}=Nn(),{getOptions:O,noop:Pt,emptyOptions:gi,resolvedPromise:Xn}=V(),{prefixDescendantKey:pi,isDescendant:mi}=Me(),{DeferredQueue:wi}=jn(),je=Wn(),he=class extends ii{#e="opening";#t=!0;#n=null;#i=!1;#a;#r;#o;#s;#u;#c;#h;#f;constructor(e,t){if(super(),typeof e!="object"||e===null)throw new TypeError("The first argument 'manifest' must be an object");t=O(t);let{keyEncoding:n,valueEncoding:s,passive:i,...o}=t;this.#a=new Set,this.#r=new wi,this.#o=o;let a=e.snapshots!==!1&&e.implicitSnapshots!==!1;this.hooks=new fi,this.supports=ri(e,{deferredOpen:!0,seek:!0,implicitSnapshots:a,permanence:e.permanence!==!1,encodings:e.encodings||{},events:{...e.events,opening:!0,open:!0,closing:!0,closed:!0,write:!0,clear:!0}}),this.#f=new yi(this),this.#u=new si(Ei(this)),this.#c=this.#u.encoding(n||"utf8"),this.#h=this.#u.encoding(s||"utf8");for(let u of this.#u.encodings())this.supports.encodings[u.commonName]||(this.supports.encodings[u.commonName]=!0);this.#s={empty:gi,entry:Object.freeze({keyEncoding:this.#c.commonName,valueEncoding:this.#h.commonName}),entryFormat:Object.freeze({keyEncoding:this.#c.format,valueEncoding:this.#h.format}),key:Object.freeze({keyEncoding:this.#c.commonName}),keyFormat:Object.freeze({keyEncoding:this.#c.format}),owner:Object.freeze({owner:this})},queueMicrotask(()=>{this.#t&&this.open({passive:!1}).catch(Pt)})}get status(){return this.#e}get parent(){return null}keyEncoding(e){return this.#u.encoding(e??this.#c)}valueEncoding(e){return this.#u.encoding(e??this.#h)}async open(e){e={...this.#o,...O(e)},e.createIfMissing=e.createIfMissing!==!1,e.errorIfExists=!!e.errorIfExists;let t=this.hooks.postopen.noop?null:this.hooks.postopen.run,n=e.passive;for(n&&this.#t&&await void 0,this.#d();this.#n!==null;)await this.#n.catch(Pt);if(this.#d(),n){if(this.#e!=="open")throw new le}else if(this.#e==="closed"||this.#t){this.#t=!1,this.#n=Xn,this.#n=(async()=>{this.#e="opening";try{this.emit("opening"),await this._open(e)}catch(s){this.#e="closed",this.#r.drain();try{await this.#y()}catch(i){s=Ct([s,i])}throw new le(s)}if(this.#e="open",t!==null){let s;try{this.#i=!0,await t(e)}catch(i){s=Jn(i)}finally{this.#i=!1}if(s){this.#e="closing",this.#r.drain();try{await this.#y(),await this._close()}catch(i){this.#i=!0,s=Ct([s,i])}throw this.#e="closed",new w("The postopen hook failed on open()",{code:"LEVEL_HOOK_ERROR",cause:s})}}this.#r.drain(),this.emit("open")})();try{await this.#n}finally{this.#n=null}}else if(this.#e!=="open")throw new le}async _open(e){}async close(){for(this.#d();this.#n!==null;)await this.#n.catch(Pt);if(this.#d(),this.#e==="open"||this.#t){let e=this.#t;this.#t=!1,this.#n=Xn,this.#n=(async()=>{this.#e="closing",this.#r.drain();try{this.emit("closing"),await this.#y(),e||await this._close()}catch(t){throw this.#e="open",this.#r.drain(),new $e(t)}this.#e="closed",this.#r.drain(),this.emit("closed")})();try{await this.#n}finally{this.#n=null}}else if(this.#e!=="closed")throw new $e}async#y(){if(this.#a.size===0)return;let e=Array.from(this.#a),t=e.map(bi),n=await Promise.allSettled(t),s=[];for(let i=0;i<n.length;i++)n[i].status==="fulfilled"?this.#a.delete(e[i]):s.push(Jn(n[i].reason));if(s.length>0)throw Ct(s)}async _close(){}async get(e,t){if(t=O(t,this.#s.entry),this.#e==="opening")return this.deferAsync(()=>this.get(e,t));this.#l(),this._assertValidKey(e);let n=t.snapshot,s=this.keyEncoding(t.keyEncoding),i=this.valueEncoding(t.valueEncoding),o=s.format,a=i.format;t===this.#s.entry?t=this.#s.entryFormat:(t.keyEncoding!==o||t.valueEncoding!==a)&&(t={...t,keyEncoding:o,valueEncoding:a});let u=s.encode(e),l=this.prefixKey(u,o,!0);n?.ref();let c;try{c=await this._get(l,t)}finally{n?.unref()}try{return c===void 0?c:i.decode(c)}catch(d){throw new w("Could not decode value",{code:"LEVEL_DECODE_ERROR",cause:d})}}async _get(e,t){}getSync(e,t){if(this.status!=="open")throw new w("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});if(this._assertValidKey(e),t==null){let d=this.#c.encode(e),y=this.prefixKey(d,this.#c.format,!0),g=this._getSync(y,this.#s.entryFormat);try{return g!==void 0?this.#h.decode(g):void 0}catch(k){throw new w("Could not decode value",{code:"LEVEL_DECODE_ERROR",cause:k})}}let n=t.snapshot,s=this.keyEncoding(t.keyEncoding),i=this.valueEncoding(t.valueEncoding),o=s.format,a=i.format;(t.keyEncoding!==o||t.valueEncoding!==a)&&(t={...t,keyEncoding:o,valueEncoding:a});let u=s.encode(e),l=this.prefixKey(u,o,!0),c;n?.ref();try{c=this._getSync(l,t)}finally{n?.unref()}try{return c!==void 0?i.decode(c):void 0}catch(d){throw new w("Could not decode value",{code:"LEVEL_DECODE_ERROR",cause:d})}}_getSync(e,t){throw new w("Database does not support getSync()",{code:"LEVEL_NOT_SUPPORTED"})}async getMany(e,t){if(t=O(t,this.#s.entry),this.#e==="opening")return this.deferAsync(()=>this.getMany(e,t));if(this.#l(),!Array.isArray(e))throw new TypeError("The first argument 'keys' must be an array");if(e.length===0)return[];let n=t.snapshot,s=this.keyEncoding(t.keyEncoding),i=this.valueEncoding(t.valueEncoding),o=s.format,a=i.format;t===this.#s.entry?t=this.#s.entryFormat:(t.keyEncoding!==o||t.valueEncoding!==a)&&(t={...t,keyEncoding:o,valueEncoding:a});let u=new Array(e.length);for(let c=0;c<e.length;c++){let d=e[c];this._assertValidKey(d),u[c]=this.prefixKey(s.encode(d),o,!0)}n?.ref();let l;try{l=await this._getMany(u,t)}finally{n?.unref()}try{for(let c=0;c<l.length;c++)l[c]!==void 0&&(l[c]=i.decode(l[c]))}catch(c){throw new w(`Could not decode one or more of ${l.length} value(s)`,{code:"LEVEL_DECODE_ERROR",cause:c})}return l}async _getMany(e,t){return new Array(e.length).fill(void 0)}async has(e,t){if(t=O(t,this.#s.key),this.#e==="opening")return this.deferAsync(()=>this.has(e,t));this.#l(),this._assertValidKey(e);let n=t.snapshot,s=this.keyEncoding(t.keyEncoding),i=s.format;t===this.#s.key?t=this.#s.keyFormat:t.keyEncoding!==i&&(t={...t,keyEncoding:i});let o=s.encode(e),a=this.prefixKey(o,i,!0);n?.ref();try{return this._has(a,t)}finally{n?.unref()}}async _has(e,t){throw new w("Database does not support has()",{code:"LEVEL_NOT_SUPPORTED"})}async hasMany(e,t){if(t=O(t,this.#s.key),this.#e==="opening")return this.deferAsync(()=>this.hasMany(e,t));if(this.#l(),!Array.isArray(e))throw new TypeError("The first argument 'keys' must be an array");if(e.length===0)return[];let n=t.snapshot,s=this.keyEncoding(t.keyEncoding),i=s.format;t===this.#s.key?t=this.#s.keyFormat:t.keyEncoding!==i&&(t={...t,keyEncoding:i});let o=new Array(e.length);for(let a=0;a<e.length;a++){let u=e[a];this._assertValidKey(u),o[a]=this.prefixKey(s.encode(u),i,!0)}n?.ref();try{return this._hasMany(o,t)}finally{n?.unref()}}async _hasMany(e,t){throw new w("Database does not support hasMany()",{code:"LEVEL_NOT_SUPPORTED"})}async put(e,t,n){if(!this.hooks.prewrite.noop)return this.batch([{type:"put",key:e,value:t}],n);if(n=O(n,this.#s.entry),this.#e==="opening")return this.deferAsync(()=>this.put(e,t,n));this.#l(),this._assertValidKey(e),this._assertValidValue(t);let s=this.keyEncoding(n.keyEncoding),i=this.valueEncoding(n.valueEncoding),o=s.format,a=i.format,u=this.#f.write,l=n;n===this.#s.entry?n=this.#s.entryFormat:(n.keyEncoding!==o||n.valueEncoding!==a)&&(n={...n,keyEncoding:o,valueEncoding:a});let c=s.encode(e),d=this.prefixKey(c,o,!0),y=i.encode(t);if(await this._put(d,y,n),u){let g={...l,type:"put",key:e,value:t,keyEncoding:s,valueEncoding:i,encodedKey:c,encodedValue:y};this.emit("write",[g])}}async _put(e,t,n){}async del(e,t){if(!this.hooks.prewrite.noop)return this.batch([{type:"del",key:e}],t);if(t=O(t,this.#s.key),this.#e==="opening")return this.deferAsync(()=>this.del(e,t));this.#l(),this._assertValidKey(e);let n=this.keyEncoding(t.keyEncoding),s=n.format,i=this.#f.write,o=t;t===this.#s.key?t=this.#s.keyFormat:t.keyEncoding!==s&&(t={...t,keyEncoding:s});let a=n.encode(e),u=this.prefixKey(a,s,!0);if(await this._del(u,t),i){let l={...o,type:"del",key:e,keyEncoding:n,encodedKey:a};this.emit("write",[l])}}async _del(e,t){}batch(e,t){return arguments.length?(t=O(t,this.#s.empty),this.#g(e,t)):(this.#l(),this._chainedBatch())}async#g(e,t){if(this.#e==="opening")return this.deferAsync(()=>this.#g(e,t));if(this.#l(),!Array.isArray(e))throw new TypeError("The first argument 'operations' must be an array");if(e.length===0)return;let n=e.length,s=!this.hooks.prewrite.noop,i=this.#f.write,o=i?new Array(n):null,a=new Array(n),u=s?new di(this,a,o):null;for(let l=0;l<n;l++){let c={...t,...e[l]},d=c.type==="put",y=c.sublevel!=null,g=y?c.sublevel:this;if(g._assertValidKey(c.key),c.keyEncoding=g.keyEncoding(c.keyEncoding),d)g._assertValidValue(c.value),c.valueEncoding=g.valueEncoding(c.valueEncoding);else if(c.type!=="del")throw new TypeError("A batch operation must have a type property that is 'put' or 'del'");if(s)try{this.hooks.prewrite.run(c,u),c.keyEncoding=g.keyEncoding(c.keyEncoding),d&&(c.valueEncoding=g.valueEncoding(c.valueEncoding))}catch(we){throw new w("The prewrite hook failed on batch()",{code:"LEVEL_HOOK_ERROR",cause:we})}let k=c.keyEncoding,m=k.encode(c.key),F=k.format,z=y&&!mi(c.sublevel,this)&&c.sublevel!==this,me=y&&!z?pi(m,F,g,this):m;y&&!z&&(c.sublevel=null);let I=null;if(i&&!z&&(I={...c},I.encodedKey=me,y&&(I.key=me,I.keyEncoding=this.keyEncoding(F)),o[l]=I),c.key=z?me:this.prefixKey(me,F,!0),c.keyEncoding=F,d){let we=c.valueEncoding,ze=we.encode(c.value),tn=we.format;c.value=ze,c.valueEncoding=tn,i&&!z&&(I.encodedValue=ze,y&&(I.value=ze,I.valueEncoding=this.valueEncoding(tn)))}a[l]=c}await this._batch(a,t),i&&this.emit("write",o)}async _batch(e,t){}sublevel(e,t){let n=Mt.defaults(t),s=this._sublevel(e,n);if(!this.hooks.newsub.noop)try{this.hooks.newsub.run(s,n)}catch(i){throw new w("The newsub hook failed on sublevel()",{code:"LEVEL_HOOK_ERROR",cause:i})}return s}_sublevel(e,t){return new Mt(this,e,t)}prefixKey(e,t,n){return e}async clear(e){if(e=O(e,this.#s.empty),this.#e==="opening")return this.deferAsync(()=>this.clear(e));this.#l();let t=e,n=this.keyEncoding(e.keyEncoding),s=e.snapshot;if(e=je(e,n),e.keyEncoding=n.format,e.limit!==0){s?.ref();try{await this._clear(e)}finally{s?.unref()}this.emit("clear",t)}}async _clear(e){}iterator(e){let t=this.keyEncoding(e?.keyEncoding),n=this.valueEncoding(e?.valueEncoding);return e=je(e,t),e.keys=e.keys!==!1,e.values=e.values!==!1,e[K.keyEncoding]=t,e[K.valueEncoding]=n,e.keyEncoding=t.format,e.valueEncoding=n.format,this.#e==="opening"?new ci(this,e):(this.#l(),this._iterator(e))}_iterator(e){return new K(this,e)}keys(e){let t=this.keyEncoding(e?.keyEncoding),n=this.valueEncoding(e?.valueEncoding);return e=je(e,t),e[K.keyEncoding]=t,e[K.valueEncoding]=n,e.keyEncoding=t.format,e.valueEncoding=n.format,this.#e==="opening"?new ui(this,e):(this.#l(),this._keys(e))}_keys(e){return new oi(this,e)}values(e){let t=this.keyEncoding(e?.keyEncoding),n=this.valueEncoding(e?.valueEncoding);return e=je(e,t),e[K.keyEncoding]=t,e[K.valueEncoding]=n,e.keyEncoding=t.format,e.valueEncoding=n.format,this.#e==="opening"?new li(this,e):(this.#l(),this._values(e))}_values(e){return new ai(this,e)}snapshot(e){return this.#l(),typeof e!="object"||e===null?e=this.#s.owner:e.owner==null&&(e={...e,owner:this}),this._snapshot(e)}_snapshot(e){throw new w("Database does not support explicit snapshots",{code:"LEVEL_NOT_SUPPORTED"})}defer(e,t){if(typeof e!="function")throw new TypeError("The first argument must be a function");this.#r.add(function(n){n||e()},t)}deferAsync(e,t){if(typeof e!="function")throw new TypeError("The first argument must be a function");return new Promise((n,s)=>{this.#r.add(function(i){i?s(i):e().then(n,s)},t)})}attachResource(e){if(typeof e!="object"||e===null||typeof e.close!="function")throw new TypeError("The first argument must be a resource object");this.#a.add(e)}detachResource(e){this.#a.delete(e)}_chainedBatch(){return new hi(this)}_assertValidKey(e){if(e==null)throw new w("Key cannot be null or undefined",{code:"LEVEL_INVALID_KEY"})}_assertValidValue(e){if(e==null)throw new w("Value cannot be null or undefined",{code:"LEVEL_INVALID_VALUE"})}#l(){if(this.#e!=="open")throw new w("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"})}#d(){if(this.#i)throw new w("Database status is locked",{code:"LEVEL_STATUS_LOCKED"})}},{AbstractSublevel:Mt}=zn()({AbstractLevel:he});Ft.AbstractLevel=he;Ft.AbstractSublevel=Mt;typeof Symbol.asyncDispose=="symbol"&&(he.prototype[Symbol.asyncDispose]=async function(){return this.close()});var Ei=function(r){return Object.keys(r.supports.encodings).filter(e=>!!r.supports.encodings[e])},bi=function(r){return r.close()},Jn=function(r){if(r instanceof Error||Object.prototype.toString.call(r)==="[object Error]")return r;let t=`Promise rejection reason must be an Error, received ${r===null?"null":typeof r}`;return new TypeError(t)},le=class extends w{constructor(e){super("Database failed to open",{code:"LEVEL_DATABASE_NOT_OPEN",cause:e})}},$e=class extends w{constructor(e){super("Database failed to close",{code:"LEVEL_DATABASE_NOT_CLOSED",cause:e})}}});var Zn=h(Qn=>{"use strict";var _i=T(),{noop:vi}=V(),We=class{#e=!0;#t=0;#n=null;#i=null;#a;constructor(e){let t=e.owner;if(typeof t!="object"||t===null){let n=t===null?"null":typeof t;throw new TypeError(`Owner must be an abstract-level database, received ${n}`)}this.#a=t,this.#a.attachResource(this)}ref(){if(!this.#e)throw new _i("Snapshot is not open: cannot use snapshot after close()",{code:"LEVEL_SNAPSHOT_NOT_OPEN"});this.#t++}unref(){--this.#t===0&&this.#n?.()}async close(){return this.#i!==null?this.#i.catch(vi):(this.#e=!1,this.#i=new Promise((e,t)=>{this.#n=()=>{this.#n=null,ki(this,this.#a).then(e,t)}}),this.#t===0&&this.#n(),this.#i)}async _close(){}};typeof Symbol.asyncDispose=="symbol"&&(We.prototype[Symbol.asyncDispose]=async function(){return this.close()});var ki=async function(r,e){await r._close(),e.detachResource(r)};Qn.AbstractSnapshot=We});var Ge=h(M=>{"use strict";M.AbstractLevel=qt().AbstractLevel;M.AbstractSublevel=qt().AbstractSublevel;M.AbstractIterator=C().AbstractIterator;M.AbstractKeyIterator=C().AbstractKeyIterator;M.AbstractValueIterator=C().AbstractValueIterator;M.AbstractChainedBatch=xt().AbstractChainedBatch;M.AbstractSnapshot=Zn().AbstractSnapshot});var gr=h(($o,yr)=>{var rr=x("fs"),R=x("path"),sr=x("os"),ir=typeof __webpack_require__=="function"?__non_webpack_require__:x,xi=process.config&&process.config.variables||{},Ti=!!process.env.PREBUILDS_ONLY,er=process.versions.modules,Bt=Oi()?"electron":Ai()?"node-webkit":"node",Nt=process.env.npm_config_arch||sr.arch(),Kt=process.env.npm_config_platform||sr.platform(),or=process.env.LIBC||(Li(Kt)?"musl":"glibc"),Ut=process.env.ARM_VERSION||(Nt==="arm64"?"8":xi.arm_version)||"",ar=(process.versions.uv||"").split(".")[0];yr.exports=L;function L(r){return ir(L.resolve(r))}L.resolve=L.path=function(r){r=R.resolve(r||".");try{var e=ir(R.join(r,"package.json")).name.toUpperCase().replace(/-/g,"_");process.env[e+"_PREBUILD"]&&(r=process.env[e+"_PREBUILD"])}catch{}if(!Ti){var t=tr(R.join(r,"build/Release"),nr);if(t)return t;var n=tr(R.join(r,"build/Debug"),nr);if(n)return n}var s=a(r);if(s)return s;var i=a(R.dirname(process.execPath));if(i)return i;var o=["platform="+Kt,"arch="+Nt,"runtime="+Bt,"abi="+er,"uv="+ar,Ut?"armv="+Ut:"","libc="+or,"node="+process.versions.node,process.versions.electron?"electron="+process.versions.electron:"",typeof __webpack_require__=="function"?"webpack=true":""].filter(Boolean).join(" ");throw new Error("No native build was found for "+o+`
|
|
4
|
+
loaded from: `+r+`
|
|
5
|
+
`);function a(u){var l=jt(R.join(u,"prebuilds")).map(cr),c=l.filter(ur(Kt,Nt)).sort(lr)[0];if(c){var d=R.join(u,"prebuilds",c.name),y=jt(d).map(hr),g=y.filter(fr(Bt,er)),k=g.sort(dr(Bt))[0];if(k)return R.join(d,k.file)}}};function jt(r){try{return rr.readdirSync(r)}catch{return[]}}function tr(r,e){var t=jt(r).filter(e);return t[0]&&R.join(r,t[0])}function nr(r){return/\.node$/.test(r)}function cr(r){var e=r.split("-");if(e.length===2){var t=e[0],n=e[1].split("+");if(t&&n.length&&n.every(Boolean))return{name:r,platform:t,architectures:n}}}function ur(r,e){return function(t){return t==null||t.platform!==r?!1:t.architectures.includes(e)}}function lr(r,e){return r.architectures.length-e.architectures.length}function hr(r){var e=r.split("."),t=e.pop(),n={file:r,specificity:0};if(t==="node"){for(var s=0;s<e.length;s++){var i=e[s];if(i==="node"||i==="electron"||i==="node-webkit")n.runtime=i;else if(i==="napi")n.napi=!0;else if(i.slice(0,3)==="abi")n.abi=i.slice(3);else if(i.slice(0,2)==="uv")n.uv=i.slice(2);else if(i.slice(0,4)==="armv")n.armv=i.slice(4);else if(i==="glibc"||i==="musl")n.libc=i;else continue;n.specificity++}return n}}function fr(r,e){return function(t){return!(t==null||t.runtime&&t.runtime!==r&&!Si(t)||t.abi&&t.abi!==e&&!t.napi||t.uv&&t.uv!==ar||t.armv&&t.armv!==Ut||t.libc&&t.libc!==or)}}function Si(r){return r.runtime==="node"&&r.napi}function dr(r){return function(e,t){return e.runtime!==t.runtime?e.runtime===r?-1:1:e.abi!==t.abi?e.abi?-1:1:e.specificity!==t.specificity?e.specificity>t.specificity?-1:1:0}}function Ai(){return!!(process.versions&&process.versions.nw)}function Oi(){return process.versions&&process.versions.electron||process.env.ELECTRON_RUN_AS_NODE?!0:typeof window<"u"&&window.process&&window.process.type==="renderer"}function Li(r){return r==="linux"&&rr.existsSync("/etc/alpine-release")}L.parseTags=hr;L.matchTags=fr;L.compareTags=dr;L.parseTuple=cr;L.matchTuple=ur;L.compareTuples=lr});var pr=h((Go,Wt)=>{var $t=typeof __webpack_require__=="function"?__non_webpack_require__:x;typeof $t.addon=="function"?Wt.exports=$t.addon.bind($t):Wt.exports=gr()});var He=h((Yo,mr)=>{mr.exports=pr()(__dirname)});var Er=h(wr=>{"use strict";var{AbstractChainedBatch:Ri}=Ge(),fe=He(),de=Symbol("context"),Gt=class extends Ri{constructor(e,t){super(e),this[de]=fe.batch_init(t)}_put(e,t){fe.batch_put(this[de],e,t)}_del(e){fe.batch_del(this[de],e)}_clear(){fe.batch_clear(this[de])}async _write(e){return fe.batch_write(this[de],e)}async _close(){}};wr.ChainedBatch=Gt});var _r=h(br=>{"use strict";var{AbstractIterator:Ii}=Ge(),U=He(),j=Symbol("context"),v=Symbol("cache"),ye=Symbol("first"),_=Symbol("position"),ge=Symbol("state"),$=Symbol("signal"),pe=Symbol("abort"),Ht=[],Yt=1,zt=class extends Ii{constructor(e,t,n,s){super(e,n),this[ge]=new Uint8Array(1),this[j]=U.iterator_init(t,this[ge],n,s),this[ye]=!0,this[v]=Ht,this[_]=0,this[pe]=this[pe].bind(this),n.signal!=null?(this[$]=n.signal,this[$].addEventListener("abort",this[pe],{once:!0})):this[$]=null}_seek(e,t){this[ye]=!0,this[v]=Ht,this[ge][0]&=~Yt,this[_]=0,U.iterator_seek(this[j],e)}async _next(){if(this[_]<this[v].length)return this[v][this[_]++];if((this[ge][0]&Yt)===0&&(this[ye]?(this[ye]=!1,this[v]=await U.iterator_nextv(this[j],1),this[_]=0):(this[v]=await U.iterator_nextv(this[j],1e3),this[_]=0),this[_]<this[v].length))return this[v][this[_]++]}async _nextv(e,t){if(this[ye]=!1,this[_]<this[v].length){let n=Math.min(e,this[v].length-this[_]),s=this[v].slice(this[_],this[_]+n);return this[_]+=n,s}return(this[ge][0]&Yt)!==0?[]:U.iterator_nextv(this[j],e)}async _close(){this[v]=Ht,this[$]!==null&&(this[$].removeEventListener("abort",this[pe]),this[$]=null),U.iterator_close(this[j])}[pe](){this[$]=null,U.iterator_abort(this[j])}get cached(){return this[v].length-this[_]}};br.Iterator=zt});var Tr=h(xr=>{"use strict";var{AbstractLevel:Vi,AbstractSnapshot:Di}=Ge(),Xt=T(),Ci=x("fs/promises"),p=He(),{ChainedBatch:Pi}=Er(),{Iterator:Mi}=_r(),f=Symbol("context"),Ye=Symbol("location"),Jt=class extends Vi{#e=null;constructor(e,t){if(typeof e!="string"||e==="")throw new TypeError("The first argument 'location' must be a non-empty string");super({encodings:{buffer:!0,utf8:!0,view:!0},has:!0,createIfMissing:!0,errorIfExists:!0,explicitSnapshots:!0,getSync:!0,additionalMethods:{approximateSize:!0,compactRange:!0},signals:{iterators:!0}},t),this[Ye]=e,this[f]=p.db_init()}get location(){return this[Ye]}async _open(e){return e.createIfMissing&&await Ci.mkdir(this[Ye],{recursive:!0}),p.db_open(this[f],this[Ye],e)}async _close(){return p.db_close(this[f])}async _put(e,t,n){return p.db_put(this[f],e,t,n)}async _get(e,t){let n=0;return t.fillCache!==!1&&(n|=vr),t.valueEncoding!=="utf8"&&(n|=kr),t.keyEncoding!=="utf8"&&(n|=Fi,e.buffer.resizable&&(e=new Uint8Array(e))),p.db_get(this[f],n,e,t.snapshot?.[f])}_getSync(e,t){let n=0;if(t.fillCache!==!1&&(n|=vr),t.valueEncoding!=="utf8"&&(n|=kr),t.keyEncoding!=="utf8")return p.db_get_sync(this[f],n,e,t.snapshot?.[f]);{let s;return this.#e===null?s=this.#t(e):(s=this.#e.write(e),s===this.#e.byteLength&&(s=this.#t(e))),p.db_get_sync(this[f],n|qi,s,t.snapshot?.[f])}}#t(e){return this.#e=Buffer.allocUnsafe(Buffer.byteLength(e)+64),p.db_set_shared_buffer(this[f],this.#e),this.#e.write(e)}async _getMany(e,t){return p.db_get_many(this[f],e,t,t.snapshot?.[f])}async _has(e,t){return p.db_has(this[f],e,t.fillCache,t.snapshot?.[f])}async _hasMany(e,t){let n=e.length+32>>>5,s=new ArrayBuffer(n*4),i=new Uint32Array(s);await p.db_has_many(this[f],e,t.fillCache,t.snapshot?.[f],s);let o=new Array(e.length);for(let a=0;a<o.length;a++)o[a]=(i[a>>>5]&1<<(a&31))!==0;return o}async _del(e,t){return p.db_del(this[f],e,t)}async _clear(e){return p.db_clear(this[f],e,e.snapshot?.[f])}_chainedBatch(){return new Pi(this,this[f])}async _batch(e,t){return p.batch_do(this[f],e,t)}async approximateSize(e,t,n){if(arguments.length<2)throw new TypeError("The arguments 'start' and 'end' are required");if(typeof n!="object"&&(n=null),this.status==="opening")return this.deferAsync(()=>this.approximateSize(e,t,n));if(this.status!=="open")throw new Xt("Database is not open: cannot call approximateSize()",{code:"LEVEL_DATABASE_NOT_OPEN"});{let s=this.keyEncoding(n&&n.keyEncoding);return e=s.encode(e),t=s.encode(t),p.db_approximate_size(this[f],e,t)}}async compactRange(e,t,n){if(arguments.length<2)throw new TypeError("The arguments 'start' and 'end' are required");if(typeof n!="object"&&(n=null),this.status==="opening")return this.deferAsync(()=>this.compactRange(e,t,n));if(this.status!=="open")throw new Xt("Database is not open: cannot call compactRange()",{code:"LEVEL_DATABASE_NOT_OPEN"});{let s=this.keyEncoding(n&&n.keyEncoding);return e=s.encode(e),t=s.encode(t),p.db_compact_range(this[f],e,t)}}getProperty(e){if(typeof e!="string")throw new TypeError("The first argument 'property' must be a string");if(this.status!=="open")throw new Xt("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return p.db_get_property(this[f],e)}_iterator(e){return new Mi(this,this[f],e,e.snapshot?.[f])}_snapshot(e){return new Qt(this[f],e)}static async destroy(e){if(typeof e!="string"||e==="")throw new TypeError("The first argument 'location' must be a non-empty string");return p.destroy_db(e)}static async repair(e){if(typeof e!="string"||e==="")throw new TypeError("The first argument 'location' must be a non-empty string");return p.repair_db(e)}},Qt=class extends Di{constructor(e,t){super(t),this[f]=p.snapshot_init(e)}async _close(){p.snapshot_close(this[f])}};xr.ClassicLevel=Jt;var vr=1,Fi=2,kr=4,qi=8});var Ar=h(Sr=>{Sr.Level=Tr().ClassicLevel});var rn=`# IDE \u2192 Cosmos migration
|
|
6
|
+
|
|
7
|
+
You are the embedded migration agent. Your job is to migrate a developer's
|
|
8
|
+
local Augment IDE context into their Cosmos user-scope VFS so it is available to
|
|
9
|
+
their cloud agents. You do this by **reading** local context with the provided
|
|
10
|
+
tools and **writing** concise, summarised Markdown into the user VFS.
|
|
11
|
+
|
|
12
|
+
You have exactly three tools available. Use only these; do not attempt any other
|
|
13
|
+
file, network, or shell access.
|
|
14
|
+
|
|
15
|
+
- \`read_local_threads({ kvStoreDir })\` \u2014 reads the local conversation history
|
|
16
|
+
(the augment-kv-store LevelDB). Returns
|
|
17
|
+
\`{ ok, threads: [{ id, metadata, exchanges: [{ uuid, value }] }], threadCount }\`
|
|
18
|
+
on success, or \`{ ok: false, reason, error }\` on failure.
|
|
19
|
+
- \`read_local_config({ homeDir, workspaceDirs? })\` \u2014 scans local rules, skills,
|
|
20
|
+
MCP servers, plugin marketplaces, and user guidelines. Always returns
|
|
21
|
+
\`{ ok, config: { userGuidelines, rules[], skills[], marketplaces[], mcpServers[], readErrors[] } }\`.
|
|
22
|
+
Each \`rules\`/\`marketplaces\`/\`mcpServers\` entry and \`userGuidelines\` is
|
|
23
|
+
\`{ path, scope: "user" | "workspace", content }\`. Each \`skills\` entry is
|
|
24
|
+
\`{ dir, scope, root, files: [{ path, scope, content }] }\`.
|
|
25
|
+
- \`write_user_vfs({ files: [{ path, content, overwrite? }] })\` \u2014 commits UTF-8
|
|
26
|
+
text into the user VFS. Returns \`{ ok, committed[], newSeq?, skipped? }\` or
|
|
27
|
+
\`{ ok: false, reason, error }\`. By default each file is **skip-if-exists**
|
|
28
|
+
(idempotent); pass \`overwrite: true\` only when you deliberately want to
|
|
29
|
+
replace an existing file. A 4 MiB per-file cap truncates oversized content.
|
|
30
|
+
|
|
31
|
+
## The prime directive: summarise, never dump raw
|
|
32
|
+
|
|
33
|
+
You are a summariser, not a copier. **Never** write a raw thread transcript,
|
|
34
|
+
raw exchange JSON, or a raw LevelDB value into the VFS. For every thread you
|
|
35
|
+
produce a short, human-readable Markdown summary that captures what the
|
|
36
|
+
conversation was about and what was decided or built \u2014 not a verbatim replay.
|
|
37
|
+
A good thread summary is a handful of sentences plus a few bullet points, not
|
|
38
|
+
pages of transcript.
|
|
39
|
+
|
|
40
|
+
## Idempotency
|
|
41
|
+
|
|
42
|
+
This migration may be re-run. Every \`write_user_vfs\` call must rely on the
|
|
43
|
+
default **skip-if-exists** behaviour: do **not** pass \`overwrite: true\` unless
|
|
44
|
+
you have a specific reason to replace a file. A second run over an unchanged
|
|
45
|
+
local context must produce no new writes and must not corrupt or duplicate
|
|
46
|
+
anything already migrated. Treat the operation as safe to repeat.
|
|
47
|
+
|
|
48
|
+
## Step 1 \u2014 Read local context
|
|
49
|
+
|
|
50
|
+
1. Call \`read_local_threads\` with the \`kvStoreDir\` the host provides. If it
|
|
51
|
+
returns \`{ ok: false }\`, record that the thread history was unavailable and
|
|
52
|
+
continue with config migration \u2014 a missing store is not a fatal error.
|
|
53
|
+
2. Call \`read_local_config\` with the \`homeDir\` (and \`workspaceDirs\` if the host
|
|
54
|
+
provides them). This tool always succeeds; inspect \`config.readErrors\` for
|
|
55
|
+
any files it could not read and note them in the manifest.
|
|
56
|
+
|
|
57
|
+
## Step 2 \u2014 One Markdown summary per thread (v1: no clustering)
|
|
58
|
+
|
|
59
|
+
For **each** thread returned by \`read_local_threads\`, write **exactly one**
|
|
60
|
+
Markdown file. Do not cluster, merge, or split threads \u2014 one thread in, one
|
|
61
|
+
summary out.
|
|
62
|
+
|
|
63
|
+
- Path: \`.augment/migrated-context/threads/<thread-id>.md\` (use the thread's
|
|
64
|
+
\`id\` verbatim as the filename stem).
|
|
65
|
+
- Content: a concise summary. Start with a short title line, then 2\u20135 sentences
|
|
66
|
+
describing the topic and outcome of the conversation, then optionally a few
|
|
67
|
+
bullets for concrete decisions, files, or follow-ups. Derive this from the
|
|
68
|
+
thread's \`metadata\` and the ordered \`exchanges\`. Keep it tight; the reader
|
|
69
|
+
wants the gist, not the transcript.
|
|
70
|
+
|
|
71
|
+
If a thread has no meaningful content (empty or trivial), still write a
|
|
72
|
+
one-line summary noting it was empty rather than skipping it, so the index
|
|
73
|
+
stays complete.
|
|
74
|
+
|
|
75
|
+
## Step 3 \u2014 Migrate config into conventional user locations
|
|
76
|
+
|
|
77
|
+
Write the discovered config into the standard user \`.augment\` locations, each
|
|
78
|
+
via \`write_user_vfs\` with default skip-if-exists:
|
|
79
|
+
|
|
80
|
+
- **User guidelines** (\`config.userGuidelines\`): write its \`content\` to
|
|
81
|
+
\`.augment/user-guidelines.md\`.
|
|
82
|
+
- **Rules** (\`config.rules[]\`): write each rule's \`content\` to
|
|
83
|
+
\`.augment/rules/<basename>\` using the source file's basename.
|
|
84
|
+
- **Skills** (\`config.skills[]\`): for each skill, write each of its \`files\` to
|
|
85
|
+
\`.augment/skills/<skill-dir-basename>/<file-basename>\`, preserving the skill's
|
|
86
|
+
own directory grouping.
|
|
87
|
+
- **MCP servers** (\`config.mcpServers[]\`): merge/write the MCP server
|
|
88
|
+
definitions into the conventional user MCP config location under \`.augment/\`
|
|
89
|
+
(e.g. \`.augment/mcp.json\`). Preserve the original server definitions; if
|
|
90
|
+
multiple sources exist, combine them without dropping any.
|
|
91
|
+
- **Marketplaces** (\`config.marketplaces[]\`): write each to
|
|
92
|
+
\`.augment/plugins/marketplaces/<basename>\`.
|
|
93
|
+
|
|
94
|
+
Only migrate config surfaces that were actually found. Skip empty categories
|
|
95
|
+
silently.
|
|
96
|
+
|
|
97
|
+
## Step 4 \u2014 Write the index and manifest
|
|
98
|
+
|
|
99
|
+
Finally, write \`.augment/migrated-context/index.md\`. It must:
|
|
100
|
+
|
|
101
|
+
- Link to every per-thread summary under \`threads/\` (a Markdown list of links
|
|
102
|
+
using the thread ids).
|
|
103
|
+
- Include a short **manifest** section listing what was migrated: the thread
|
|
104
|
+
count, the config items migrated (counts per category), and any \`readErrors\`
|
|
105
|
+
or unavailable sources encountered, so a human can see the migration was
|
|
106
|
+
complete and where anything was skipped.
|
|
107
|
+
|
|
108
|
+
Write the index with default skip-if-exists like everything else. When you are
|
|
109
|
+
done, briefly report what you migrated (thread count and config categories) so
|
|
110
|
+
the outcome is visible in the event stream.
|
|
111
|
+
`;import{lstat as un,readdir as Hr,readFile as Yr,realpath as zr}from"node:fs/promises";import{join as S}from"node:path";import{defineTool as Xr}from"@augmentcode/auggie-v2";import{Type as X}from"@sinclair/typebox";var Jr="read_local_config",Q=".augment",Qr=".claude",Zr=".agents",es=S(Q,"user-guidelines.md"),ts=S(Q,"rules"),ns=S(Q,"plugins","marketplaces"),rs=["mcp-servers.json","mcp.json"],ss=[Q,Qr,Zr],sn=64,is=X.Object({homeDir:X.String({description:"The user's home directory to scan for user-scope config."}),workspaceDirs:X.Optional(X.Array(X.String(),{description:"Workspace directories to scan for workspace-scope config. May be empty."}))});function G(r){if(r instanceof Error){let e=r.code;return e?`${e}: ${r.message}`:r.message}return String(r)}function J(r){return r?.code==="ENOENT"}async function Xe(r,e,t){try{let n=await Yr(r,"utf-8");return{path:r,scope:e,content:n}}catch(n){return J(n)||t.push({path:r,error:G(n)}),null}}async function ln(r,e){try{return await Hr(r)}catch(t){return J(t)?[]:(e.push({path:r,error:G(t)}),[])}}async function Ee(r,e,t,n=new Set,s=0){let i=[];if(s>=sn)return t.push({path:r,error:`max directory depth (${sn}) exceeded; not descending further`}),i;try{let a=await zr(r);if(n.has(a))return t.push({path:r,error:`symlink cycle detected (already visited ${a}); skipping`}),i;n.add(a)}catch(a){J(a)||t.push({path:r,error:G(a)})}let o=await ln(r,t);for(let a of o){let u=S(r,a),l;try{l=await un(u)}catch(c){J(c)||t.push({path:u,error:G(c)});continue}if(l.isSymbolicLink())t.push({path:u,error:"symlink skipped (not following to avoid cycles)"});else if(l.isDirectory())i.push(...await Ee(u,e,t,n,s+1));else if(l.isFile()){let c=await Xe(u,e,t);c&&i.push(c)}}return i}function on(r,e,t){return Ee(S(r,ts),e,t)}async function an(r,e,t){let n=[];for(let s of ss){let i=S(r,s,"skills"),o=await ln(i,t);for(let a of o){let u=S(i,a),l;try{l=await un(u)}catch(c){J(c)||t.push({path:u,error:G(c)});continue}if(l.isSymbolicLink()){t.push({path:u,error:"symlink skipped (not following to avoid cycles)"});continue}l.isDirectory()&&n.push({dir:u,scope:e,root:s,files:await Ee(u,e,t)})}}return n}async function cn(r,e,t){let n=[];for(let s of rs){let i=await Xe(S(r,Q,s),e,t);i&&n.push(i)}return n}async function os(r,e){let t=[],n=await Xe(S(r,es),"user",t),s=await on(r,"user",t),i=await an(r,"user",t),o=await Ee(S(r,ns),"user",t),a=await cn(r,"user",t);for(let u of e)s.push(...await on(u,"workspace",t)),i.push(...await an(u,"workspace",t)),a.push(...await cn(u,"workspace",t));return{userGuidelines:n,rules:s,skills:i,marketplaces:o,mcpServers:a,readErrors:t}}function hn(r){r.registerTool(Xr({name:Jr,label:"Read Local Config",description:"Scan the local filesystem (no network) for the user's IDE agent config: user guidelines, user + workspace rules, skills across the .augment/.claude/.agents skill dirs, plugin marketplaces, and locally-defined MCP servers. Missing directories are treated as empty, not errors.",parameters:is,async execute(e,t,n,s,i){let{homeDir:o,workspaceDirs:a}=t,u;try{u=await os(o,a??[])}catch(c){u={userGuidelines:null,rules:[],skills:[],marketplaces:[],mcpServers:[],readErrors:[{path:o,error:G(c)}]}}return{content:[{type:"text",text:`Found ${u.rules.length} rule file(s), ${u.skills.length} skill(s), ${u.mcpServers.length} MCP config file(s), ${u.marketplaces.length} marketplace file(s)${u.userGuidelines?", and user guidelines":""}.`}],details:{ok:!0,config:u}}}}))}var Cr=Gr(Ar(),1);import{defineTool as Bi}from"@augmentcode/auggie-v2";import{Type as Or}from"@sinclair/typebox";var Ni="read_local_threads",Lr="metadata:",Rr="history:",Ir="exchange:",Ki=Or.Object({kvStoreDir:Or.String({description:"Absolute path to the host-provided augment-kv-store LevelDB directory."})});function Ui(r){return{content:[{type:"text",text:r}]}}function Zt(r){try{return JSON.parse(r)}catch{return r}}function ji(r){if(!Array.isArray(r))return[];let e=[];for(let t of r)typeof t=="string"?e.push(t):t&&typeof t=="object"&&typeof t.uuid=="string"&&e.push(t.uuid);return e}async function $i(r){let e=new Map,t=new Map,n=new Map;for await(let[o,a]of r.iterator()){if(o.startsWith(Lr)){e.set(o.slice(Lr.length),Zt(a));continue}if(o.startsWith(Rr)){t.set(o.slice(Rr.length),ji(Zt(a)));continue}if(o.startsWith(Ir)){let u=o.slice(Ir.length),l=u.lastIndexOf(":");if(l<=0)continue;let c=u.slice(0,l),d=u.slice(l+1),y=n.get(c)??[];y.push({uuid:d,value:Zt(a)}),n.set(c,y)}}let s=new Set([...e.keys(),...t.keys(),...n.keys()]),i=[];for(let o of s){let a=n.get(o)??[],u=t.get(o)??[];i.push({id:o,metadata:e.get(o)??null,exchanges:Wi(a,u)})}return i}function Wi(r,e){if(e.length===0)return r;let t=new Map(r.map(i=>[i.uuid,i])),n=[],s=new Set;for(let i of e){let o=t.get(i);o&&(n.push(o),s.add(i))}for(let i of r)s.has(i.uuid)||n.push(i);return n}async function Gi(r){if(typeof r!="string"||r.length===0)return{ok:!1,reason:"invalid_params",error:"kvStoreDir must be a non-empty path string."};let e;try{e=new Cr.Level(r,{createIfMissing:!1,errorIfExists:!1}),await e.open()}catch(t){return await Vr(e),{ok:!1,reason:"db_unavailable",error:`Could not open augment-kv-store at "${r}": ${Dr(t)}`}}try{let t=await $i(e);return{ok:!0,threads:t,threadCount:t.length}}catch(t){return{ok:!1,reason:"read_failed",error:`Failed reading threads from augment-kv-store: ${Dr(t)}`}}finally{await Vr(e)}}async function Vr(r){if(r)try{(r.status==="open"||r.status==="opening")&&await r.close()}catch{}}function Dr(r){if(r instanceof Error){let e=r.code;return e?`${e}: ${r.message}`:r.message}return String(r)}function Pr(r){r.registerTool(Bi({name:Ni,label:"Read Local Threads",description:"Read the host IDE's local conversation history from the augment-kv-store LevelDB (read-only). Returns structured threads reconstructed from the metadata/history/exchange keys. A locked or absent store is reported as an error result, not a crash.",parameters:Ki,async execute(e,t,n,s,i){let{kvStoreDir:o}=t,a=await Gi(o);return a.ok?{content:[{type:"text",text:`Read ${a.threadCount} thread(s) from the local augment-kv-store.`}],details:a}:{...Ui(a.error),details:a}}}))}import{defineTool as Hi,readAugmentCredentials as Yi}from"@augmentcode/auggie-v2";import{Type as W}from"@sinclair/typebox";var zi="write_user_vfs",Xi="/cloud-agents/vfs/commit-changes",Ji="user",Qi="migration-engine",Mr=4*1024*1024,Zi=-1,eo=0,to=W.Object({files:W.Array(W.Object({path:W.String({description:"VFS-relative path within the user filesystem."}),content:W.String({description:"UTF-8 text content to write."}),overwrite:W.Optional(W.Boolean({description:"true \u2192 overwrite (base_seq 0); false/omitted \u2192 skip-if-exists (base_seq -1, idempotent)."}))}),{description:"Files to commit into the user-scope VFS."})}),qr=new TextEncoder;function en(r){return qr.encode(r).length}function no(r){if(en(r)<=Mr)return{content:r,truncated:!1};let e=`
|
|
112
|
+
|
|
113
|
+
[migration: content truncated to fit the 4 MiB VFS limit]
|
|
114
|
+
`,t=Mr-en(e),n=Array.from(r),s=0,i=n.length;for(;s<i;){let o=Math.ceil((s+i)/2);en(n.slice(0,o).join(""))<=t?s=o:i=o-1}return{content:`${n.slice(0,s).join("")}${e}`,truncated:!0}}function ro(r){return`${r.replace(/\/+$/,"")}${Xi}`}function so(r){return{content:[{type:"text",text:r}]}}function Fr(r,e){return e.length===0?r:r.split(e).join("[redacted]")}async function io(r){if(!Array.isArray(r)||r.length===0)return{ok:!1,reason:"invalid_params",error:"files must be a non-empty array of {path, content}."};let e=await Yi();if(!e)return{ok:!1,reason:"no_credentials",error:"No Augment credentials available (session.json / AUGMENT_SESSION_AUTH). Cannot write to the user VFS."};let t=[],n=r.map(s=>{let{content:i,truncated:o}=no(s.content),a=qr.encode(i);return t.push({path:s.path,truncated:o,bytes:a.length}),{path:s.path,content:Array.from(a),deleted:!1,base_seq:s.overwrite?eo:Zi}});try{let s=await fetch(ro(e.apiUrl),{method:"POST",headers:{Authorization:`Bearer ${e.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify({filesystem_id:Ji,file_changes:n,modified_by:Qi})});if(!s.ok){let o=await oo(s);return{ok:!1,reason:"commit_failed",error:Fr(`commit-changes failed with HTTP ${s.status}${o?`: ${o}`:""}`,e.apiKey)}}let i=await ao(s);return{ok:!0,committed:t,newSeq:i?.new_seq,skipped:i?.skipped_files}}catch(s){let i=s instanceof Error?s.message:String(s);return{ok:!1,reason:"commit_failed",error:Fr(`commit-changes request failed: ${i}`,e.apiKey)}}}async function oo(r){try{return(await r.text()).slice(0,500)}catch{return""}}async function ao(r){try{return await r.json()}catch{return}}function Br(r){r.registerTool(Hi({name:zi,label:"Write User VFS",description:"Commit summarised migration output into the user's Cosmos user-scope VFS. Enforces a 4 MiB/file cap by truncating oversized content (never rejecting). Uses base_seq -1 (skip-if-exists, idempotent) unless overwrite:true is set (base_seq 0). Auth comes from the existing session credentials; no new auth surface.",parameters:to,async execute(e,t,n,s,i){let{files:o}=t,a=await io(o);if(a.ok){let u=a.committed.filter(c=>c.truncated).length,l=u>0?` (${u} truncated to the 4 MiB limit)`:"";return{content:[{type:"text",text:`Committed ${a.committed.length} file(s) to the user VFS${l}.`}],details:a}}return{...so(a.error),details:a}}}))}function ua(r){Pr(r),hn(r),Br(r)}function la(){return rn}export{ua as default,la as getMigrationPrompt};
|