this.me 3.1.7 β†’ 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 this.me neurons.me
3
+ Copyright (c) 2026 Jose Abella Eggleton (suiGn) - neurons.me
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -80,7 +80,7 @@ Runtime output (real):
80
80
  "home.kitchen.lights.avg": 60
81
81
  }
82
82
 
83
- last thoughts ->
83
+ last memory events ->
84
84
  [
85
85
  { path: "home.kitchen.lights.main.brightness", op: null, value: 80 },
86
86
  { path: "home.kitchen.lights.leds.brightness", op: null, value: 40 },
@@ -246,7 +246,7 @@ console.log(trace);
246
246
  For runtime snapshots/debug:
247
247
 
248
248
  ```ts
249
- me.inspect(); // thoughts + index + scopes
249
+ me.inspect(); // memory + index + scopes
250
250
  me.exportSnapshot(); // full portable state (Phase 7B)
251
251
  ```
252
252
 
@@ -274,7 +274,7 @@ The Kernel is physically incapable of executing arbitrary code. **It only resolv
274
274
 
275
275
  ###### π“‚€π“ˆ–π“‚€ ⟐ Your identity is Deterministic ⟐ π“‚€π“ˆ–π“‚€
276
276
 
277
- By exporting **"Thoughts"** or **"Snapshots"**, you can teleport your entire state between a **MacBook Air** in **Veracruz** and a high-end server in **London.**
277
+ By exporting **"Memory"** or **"Snapshots"**, you can teleport your entire state between a **MacBook Air** in **Veracruz** and a high-end server in **London.**
278
278
  The behavior is identical, bit-by-bit, because the logic is part of the state.
279
279
 
280
280
  ---
package/dist/me.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";function ye(f){return{__ptr:f}}function D(f){return!!f&&typeof f=="object"&&typeof f.__ptr=="string"&&f.__ptr.length>0}function me(f){return{__id:f}}function Xt(f){return!!f&&typeof f=="object"&&typeof f.__id=="string"&&f.__id.length>0}function be(f){return!!f&&typeof f=="object"&&typeof f.path=="string"&&typeof f.hash=="string"&&typeof f.timestamp=="number"}function I(f){return f.length===0?{scope:[],leaf:null}:{scope:f.slice(0,-1),leaf:f[f.length-1]}}function qt(f,r){if(r.length>f.length)return!1;for(let t=0;t<r.length;t++)if(f[t]!==r[t])return!1;return!0}function Zt(f){const r=f.trim().toLowerCase();if(r.length<3||r.length>63)throw new Error(`Invalid username length: ${r.length}. Expected 3..63 characters.`);if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$/.test(r))throw new Error(`Invalid username. Use only [a-z0-9-], and start/end with [a-z0-9]. Got: ${f}`);if(r.includes("--"))throw new Error(`Invalid username. "--" is not allowed. Got: ${f}`);return r}function K(f,r){return f[r]?.kind??null}function ke(f,r){if(f.length!==1||f[0]!=="+"||!Array.isArray(r)||r.length<2)return null;const n=String(r[0]??"").trim(),i=String(r[1]??"").trim();return!n||!i||n==="+"?null:{op:n,kind:i}}function Se(f,r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);return!i||K(f,i)!=="secret"||typeof t!="string"?null:{scopeKey:n.join(".")}}function Pe(f,r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);return!i||K(f,i)!=="noise"||typeof t!="string"?null:{scopeKey:n.join(".")}}function xe(f,r,t){if(r.length===0)return null;const{leaf:n}=I(r);if(!n||K(f,n)!=="pointer"||typeof t!="string")return null;const i=t.trim().replace(/^\./,"");return i?{targetPath:i}:null}function _e(f,r,t){if(r.length===1&&K(f,r[0])==="identity")return typeof t!="string"?null:{id:Zt(t),targetPath:[]};const{scope:n,leaf:i}=I(r);return!i||K(f,i)!=="identity"||typeof t!="string"?null:{id:Zt(t),targetPath:n}}function Be(f,r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);if(!i||K(f,i)!=="eval")return null;if(typeof t=="function")return{mode:"thunk",targetPath:n,thunk:t};if(Array.isArray(t)&&t.length>=2){const o=String(t[0]??"").trim(),s=String(t[1]??"").trim();return!o||!s?null:{mode:"assign",targetPath:n,name:o,expr:s}}return null}function Ae(f,r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);if(!i||K(f,i)!=="query")return null;let o=null,s;if(Array.isArray(t)&&t.length>0)Array.isArray(t[0])&&(t.length===1||typeof t[1]=="function")?(o=t[0],s=typeof t[1]=="function"?t[1]:void 0):o=t;else return null;if(!Array.isArray(o)||o.length===0)return null;const a=o.map(l=>String(l)).map(l=>l.trim()).filter(l=>l.length>0);return a.length===0?null:{targetPath:n,paths:a,fn:s}}function Ee(f,r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);if(!i||K(f,i)!=="remove")return null;if(t==null)return{targetPath:n};if(typeof t=="string"){const o=t.split(".").filter(Boolean);return{targetPath:[...n,...o]}}return null}var Fe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function we(f){return f&&f.__esModule&&Object.prototype.hasOwnProperty.call(f,"default")?f.default:f}var te={exports:{}};var fe;function Ne(){return fe||(fe=1,(function(f){(function(){var r="input is invalid type",t="finalize already called",n=typeof window=="object",i=n?window:{};i.JS_SHA3_NO_WINDOW&&(n=!1);var o=!n&&typeof self=="object",s=!i.JS_SHA3_NO_NODE_JS&&typeof process=="object"&&process.versions&&process.versions.node;s?i=Fe:o&&(i=self);for(var a=!i.JS_SHA3_NO_COMMON_JS&&!0&&f.exports,l=!i.JS_SHA3_NO_ARRAY_BUFFER&&typeof ArrayBuffer<"u",c="0123456789abcdef".split(""),d=[31,7936,2031616,520093696],v=[4,1024,262144,67108864],y=[1,256,65536,16777216],S=[6,1536,393216,100663296],p=[0,8,16,24],_=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],A=[224,256,384,512],B=[128,256],F=["hex","buffer","arrayBuffer","array","digest"],O={128:168,256:136},E=i.JS_SHA3_NO_NODE_JS||!Array.isArray?function(e){return Object.prototype.toString.call(e)==="[object Array]"}:Array.isArray,j=l&&(i.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)?function(e){return typeof e=="object"&&e.buffer&&e.buffer.constructor===ArrayBuffer}:ArrayBuffer.isView,T=function(e){var u=typeof e;if(u==="string")return[e,!0];if(u!=="object"||e===null)throw new Error(r);if(l&&e.constructor===ArrayBuffer)return[new Uint8Array(e),!1];if(!E(e)&&!j(e))throw new Error(r);return[e,!1]},W=function(e){return T(e)[0].length===0},Gt=function(e){for(var u=[],h=0;h<e.length;++h)u[h]=e[h];return u},ie=function(e,u,h){return function(g){return new N(e,u,e).update(g)[h]()}},oe=function(e,u,h){return function(g,m){return new N(e,u,m).update(g)[h]()}},se=function(e,u,h){return function(g,m,b,P){return z["cshake"+e].update(g,m,b,P)[h]()}},le=function(e,u,h){return function(g,m,b,P){return z["kmac"+e].update(g,m,b,P)[h]()}},J=function(e,u,h,g){for(var m=0;m<F.length;++m){var b=F[m];e[b]=u(h,g,b)}return e},ae=function(e,u){var h=ie(e,u,"hex");return h.create=function(){return new N(e,u,e)},h.update=function(g){return h.create().update(g)},J(h,ie,e,u)},de=function(e,u){var h=oe(e,u,"hex");return h.create=function(g){return new N(e,u,g)},h.update=function(g,m){return h.create(m).update(g)},J(h,oe,e,u)},ge=function(e,u){var h=O[e],g=se(e,u,"hex");return g.create=function(m,b,P){return W(b)&&W(P)?z["shake"+e].create(m):new N(e,u,m).bytepad([b,P],h)},g.update=function(m,b,P,k){return g.create(b,P,k).update(m)},J(g,se,e,u)},ve=function(e,u){var h=O[e],g=le(e,u,"hex");return g.create=function(m,b,P){return new Qt(e,u,b).bytepad(["KMAC",P],h).bytepad([m],h)},g.update=function(m,b,P,k){return g.create(m,P,k).update(b)},J(g,le,e,u)},ce=[{name:"keccak",padding:y,bits:A,createMethod:ae},{name:"sha3",padding:S,bits:A,createMethod:ae},{name:"shake",padding:d,bits:B,createMethod:de},{name:"cshake",padding:v,bits:B,createMethod:ge},{name:"kmac",padding:v,bits:B,createMethod:ve}],z={},V=[],M=0;M<ce.length;++M)for(var R=ce[M],q=R.bits,$=0;$<q.length;++$){var Yt=R.name+"_"+q[$];if(V.push(Yt),z[Yt]=R.createMethod(q[$],R.padding),R.name!=="sha3"){var ue=R.name+q[$];V.push(ue),z[ue]=z[Yt]}}function N(e,u,h){this.blocks=[],this.s=[],this.padding=u,this.outputBits=h,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(e<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=h>>5,this.extraBytes=(h&31)>>3;for(var g=0;g<50;++g)this.s[g]=0}N.prototype.update=function(e){if(this.finalized)throw new Error(t);var u=T(e);e=u[0];for(var h=u[1],g=this.blocks,m=this.byteCount,b=e.length,P=this.blockCount,k=0,C=this.s,x,w;k<b;){if(this.reset)for(this.reset=!1,g[0]=this.block,x=1;x<P+1;++x)g[x]=0;if(h)for(x=this.start;k<b&&x<m;++k)w=e.charCodeAt(k),w<128?g[x>>2]|=w<<p[x++&3]:w<2048?(g[x>>2]|=(192|w>>6)<<p[x++&3],g[x>>2]|=(128|w&63)<<p[x++&3]):w<55296||w>=57344?(g[x>>2]|=(224|w>>12)<<p[x++&3],g[x>>2]|=(128|w>>6&63)<<p[x++&3],g[x>>2]|=(128|w&63)<<p[x++&3]):(w=65536+((w&1023)<<10|e.charCodeAt(++k)&1023),g[x>>2]|=(240|w>>18)<<p[x++&3],g[x>>2]|=(128|w>>12&63)<<p[x++&3],g[x>>2]|=(128|w>>6&63)<<p[x++&3],g[x>>2]|=(128|w&63)<<p[x++&3]);else for(x=this.start;k<b&&x<m;++k)g[x>>2]|=e[k]<<p[x++&3];if(this.lastByteIndex=x,x>=m){for(this.start=x-m,this.block=g[P],x=0;x<P;++x)C[x]^=g[x];H(C),this.reset=!0}else this.start=x}return this},N.prototype.encode=function(e,u){var h=e&255,g=1,m=[h];for(e=e>>8,h=e&255;h>0;)m.unshift(h),e=e>>8,h=e&255,++g;return u?m.push(g):m.unshift(g),this.update(m),m.length},N.prototype.encodeString=function(e){var u=T(e);e=u[0];var h=u[1],g=0,m=e.length;if(h)for(var b=0;b<e.length;++b){var P=e.charCodeAt(b);P<128?g+=1:P<2048?g+=2:P<55296||P>=57344?g+=3:(P=65536+((P&1023)<<10|e.charCodeAt(++b)&1023),g+=4)}else g=m;return g+=this.encode(g*8),this.update(e),g},N.prototype.bytepad=function(e,u){for(var h=this.encode(u),g=0;g<e.length;++g)h+=this.encodeString(e[g]);var m=(u-h%u)%u,b=[];return b.length=m,this.update(b),this},N.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var e=this.blocks,u=this.lastByteIndex,h=this.blockCount,g=this.s;if(e[u>>2]|=this.padding[u&3],this.lastByteIndex===this.byteCount)for(e[0]=e[h],u=1;u<h+1;++u)e[u]=0;for(e[h-1]|=2147483648,u=0;u<h;++u)g[u]^=e[u];H(g)}},N.prototype.toString=N.prototype.hex=function(){this.finalize();for(var e=this.blockCount,u=this.s,h=this.outputBlocks,g=this.extraBytes,m=0,b=0,P="",k;b<h;){for(m=0;m<e&&b<h;++m,++b)k=u[m],P+=c[k>>4&15]+c[k&15]+c[k>>12&15]+c[k>>8&15]+c[k>>20&15]+c[k>>16&15]+c[k>>28&15]+c[k>>24&15];b%e===0&&(u=Gt(u),H(u),m=0)}return g&&(k=u[m],P+=c[k>>4&15]+c[k&15],g>1&&(P+=c[k>>12&15]+c[k>>8&15]),g>2&&(P+=c[k>>20&15]+c[k>>16&15])),P},N.prototype.arrayBuffer=function(){this.finalize();var e=this.blockCount,u=this.s,h=this.outputBlocks,g=this.extraBytes,m=0,b=0,P=this.outputBits>>3,k;g?k=new ArrayBuffer(h+1<<2):k=new ArrayBuffer(P);for(var C=new Uint32Array(k);b<h;){for(m=0;m<e&&b<h;++m,++b)C[b]=u[m];b%e===0&&(u=Gt(u),H(u))}return g&&(C[b]=u[m],k=k.slice(0,P)),k},N.prototype.buffer=N.prototype.arrayBuffer,N.prototype.digest=N.prototype.array=function(){this.finalize();for(var e=this.blockCount,u=this.s,h=this.outputBlocks,g=this.extraBytes,m=0,b=0,P=[],k,C;b<h;){for(m=0;m<e&&b<h;++m,++b)k=b<<2,C=u[m],P[k]=C&255,P[k+1]=C>>8&255,P[k+2]=C>>16&255,P[k+3]=C>>24&255;b%e===0&&(u=Gt(u),H(u))}return g&&(k=b<<2,C=u[m],P[k]=C&255,g>1&&(P[k+1]=C>>8&255),g>2&&(P[k+2]=C>>16&255)),P};function Qt(e,u,h){N.call(this,e,u,h)}Qt.prototype=new N,Qt.prototype.finalize=function(){return this.encode(this.outputBits,!0),N.prototype.finalize.call(this)};var H=function(e){var u,h,g,m,b,P,k,C,x,w,U,Z,G,Y,Q,X,tt,et,rt,nt,it,ot,st,lt,at,ct,ut,ft,ht,pt,dt,gt,vt,yt,mt,bt,kt,St,Pt,xt,_t,Bt,At,Et,Ft,wt,Nt,Ct,Ot,It,jt,Tt,zt,Mt,Kt,Dt,Rt,Wt,Vt,$t,Ht,Lt,Jt;for(g=0;g<48;g+=2)m=e[0]^e[10]^e[20]^e[30]^e[40],b=e[1]^e[11]^e[21]^e[31]^e[41],P=e[2]^e[12]^e[22]^e[32]^e[42],k=e[3]^e[13]^e[23]^e[33]^e[43],C=e[4]^e[14]^e[24]^e[34]^e[44],x=e[5]^e[15]^e[25]^e[35]^e[45],w=e[6]^e[16]^e[26]^e[36]^e[46],U=e[7]^e[17]^e[27]^e[37]^e[47],Z=e[8]^e[18]^e[28]^e[38]^e[48],G=e[9]^e[19]^e[29]^e[39]^e[49],u=Z^(P<<1|k>>>31),h=G^(k<<1|P>>>31),e[0]^=u,e[1]^=h,e[10]^=u,e[11]^=h,e[20]^=u,e[21]^=h,e[30]^=u,e[31]^=h,e[40]^=u,e[41]^=h,u=m^(C<<1|x>>>31),h=b^(x<<1|C>>>31),e[2]^=u,e[3]^=h,e[12]^=u,e[13]^=h,e[22]^=u,e[23]^=h,e[32]^=u,e[33]^=h,e[42]^=u,e[43]^=h,u=P^(w<<1|U>>>31),h=k^(U<<1|w>>>31),e[4]^=u,e[5]^=h,e[14]^=u,e[15]^=h,e[24]^=u,e[25]^=h,e[34]^=u,e[35]^=h,e[44]^=u,e[45]^=h,u=C^(Z<<1|G>>>31),h=x^(G<<1|Z>>>31),e[6]^=u,e[7]^=h,e[16]^=u,e[17]^=h,e[26]^=u,e[27]^=h,e[36]^=u,e[37]^=h,e[46]^=u,e[47]^=h,u=w^(m<<1|b>>>31),h=U^(b<<1|m>>>31),e[8]^=u,e[9]^=h,e[18]^=u,e[19]^=h,e[28]^=u,e[29]^=h,e[38]^=u,e[39]^=h,e[48]^=u,e[49]^=h,Y=e[0],Q=e[1],wt=e[11]<<4|e[10]>>>28,Nt=e[10]<<4|e[11]>>>28,ft=e[20]<<3|e[21]>>>29,ht=e[21]<<3|e[20]>>>29,$t=e[31]<<9|e[30]>>>23,Ht=e[30]<<9|e[31]>>>23,Bt=e[40]<<18|e[41]>>>14,At=e[41]<<18|e[40]>>>14,yt=e[2]<<1|e[3]>>>31,mt=e[3]<<1|e[2]>>>31,X=e[13]<<12|e[12]>>>20,tt=e[12]<<12|e[13]>>>20,Ct=e[22]<<10|e[23]>>>22,Ot=e[23]<<10|e[22]>>>22,pt=e[33]<<13|e[32]>>>19,dt=e[32]<<13|e[33]>>>19,Lt=e[42]<<2|e[43]>>>30,Jt=e[43]<<2|e[42]>>>30,Mt=e[5]<<30|e[4]>>>2,Kt=e[4]<<30|e[5]>>>2,bt=e[14]<<6|e[15]>>>26,kt=e[15]<<6|e[14]>>>26,et=e[25]<<11|e[24]>>>21,rt=e[24]<<11|e[25]>>>21,It=e[34]<<15|e[35]>>>17,jt=e[35]<<15|e[34]>>>17,gt=e[45]<<29|e[44]>>>3,vt=e[44]<<29|e[45]>>>3,lt=e[6]<<28|e[7]>>>4,at=e[7]<<28|e[6]>>>4,Dt=e[17]<<23|e[16]>>>9,Rt=e[16]<<23|e[17]>>>9,St=e[26]<<25|e[27]>>>7,Pt=e[27]<<25|e[26]>>>7,nt=e[36]<<21|e[37]>>>11,it=e[37]<<21|e[36]>>>11,Tt=e[47]<<24|e[46]>>>8,zt=e[46]<<24|e[47]>>>8,Et=e[8]<<27|e[9]>>>5,Ft=e[9]<<27|e[8]>>>5,ct=e[18]<<20|e[19]>>>12,ut=e[19]<<20|e[18]>>>12,Wt=e[29]<<7|e[28]>>>25,Vt=e[28]<<7|e[29]>>>25,xt=e[38]<<8|e[39]>>>24,_t=e[39]<<8|e[38]>>>24,ot=e[48]<<14|e[49]>>>18,st=e[49]<<14|e[48]>>>18,e[0]=Y^~X&et,e[1]=Q^~tt&rt,e[10]=lt^~ct&ft,e[11]=at^~ut&ht,e[20]=yt^~bt&St,e[21]=mt^~kt&Pt,e[30]=Et^~wt&Ct,e[31]=Ft^~Nt&Ot,e[40]=Mt^~Dt&Wt,e[41]=Kt^~Rt&Vt,e[2]=X^~et&nt,e[3]=tt^~rt&it,e[12]=ct^~ft&pt,e[13]=ut^~ht&dt,e[22]=bt^~St&xt,e[23]=kt^~Pt&_t,e[32]=wt^~Ct&It,e[33]=Nt^~Ot&jt,e[42]=Dt^~Wt&$t,e[43]=Rt^~Vt&Ht,e[4]=et^~nt&ot,e[5]=rt^~it&st,e[14]=ft^~pt&gt,e[15]=ht^~dt&vt,e[24]=St^~xt&Bt,e[25]=Pt^~_t&At,e[34]=Ct^~It&Tt,e[35]=Ot^~jt&zt,e[44]=Wt^~$t&Lt,e[45]=Vt^~Ht&Jt,e[6]=nt^~ot&Y,e[7]=it^~st&Q,e[16]=pt^~gt&lt,e[17]=dt^~vt&at,e[26]=xt^~Bt&yt,e[27]=_t^~At&mt,e[36]=It^~Tt&Et,e[37]=jt^~zt&Ft,e[46]=$t^~Lt&Mt,e[47]=Ht^~Jt&Kt,e[8]=ot^~Y&X,e[9]=st^~Q&tt,e[18]=gt^~lt&ct,e[19]=vt^~at&ut,e[28]=Bt^~yt&bt,e[29]=At^~mt&kt,e[38]=Tt^~Et&wt,e[39]=zt^~Ft&Nt,e[48]=Lt^~Mt&Dt,e[49]=Jt^~Kt&Rt,e[0]^=_[g],e[1]^=_[g+1]};if(a)f.exports=z;else for(M=0;M<V.length;++M)i[V[M]]=z[V[M]]})()})(te)),te.exports}var Ce=Ne();const Oe=we(Ce),{keccak256:pe}=Oe;function re(f){return new TextEncoder().encode(f)}function Ie(f){const r=f.startsWith("0x")?f.slice(2):f,t=new Uint8Array(r.length/2);for(let n=0;n<t.length;n++)t[n]=parseInt(r.substring(n*2,n*2+2),16);return t}function je(f){let r="";for(let t=0;t<f.length;t++)r+=f[t].toString(16).padStart(2,"0");return"0x"+r}function ee(f,r,t){const n=JSON.stringify(f),i=re(n),o=pe(r+":"+t.join(".")),s=re(o),a=new Uint8Array(i.length);for(let l=0;l<i.length;l++)a[l]=i[l]^s[l%s.length];return je(a)}function Ut(f,r,t){try{const n=Ie(f),i=pe(r+":"+t.join(".")),o=re(i),s=new Uint8Array(n.length);for(let l=0;l<n.length;l++)s[l]=n[l]^o[l%o.length];const a=new TextDecoder().decode(s);return JSON.parse(a)}catch{return null}}function Te(f){if(typeof f!="string"||!f.startsWith("0x"))return!1;const r=f.slice(2);return r.length<2||r.length%2!==0?!1:/^[0-9a-fA-F]+$/.test(r)}function ze(f){const r=[];let t="",n=0,i=null;for(let s=0;s<f.length;s++){const a=f[s];if(i){t+=a,a===i&&(i=null);continue}if(a==='"'||a==="'"){i=a,t+=a;continue}if(a==="["){n++,t+=a;continue}if(a==="]"){n=Math.max(0,n-1),t+=a;continue}if(a==="."&&n===0){const l=t.trim();l&&r.push(l),t="";continue}t+=a}const o=t.trim();return o&&r.push(o),r}function Me(f,r,t){if(r.length===0){if(t.length===1&&typeof t[0]=="string"){const d=t[0].trim(),v=d.startsWith("_")||d.startsWith("~")||d.startsWith("@"),y=d.includes("."),S=/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(d);if(y||v||S){const p=ze(d);return f.readPath(p)}}if(t.length===0)return f.createProxy([]);const l=f.normalizeArgs(t),c=f.postulate([],l);return c!==void 0?c:f.createProxy([])}const n=f.normalizeArgs(t),i=f.postulate(r,n),{scope:o,leaf:s}=f.splitPath(r),a=s?f.opKind(s):null;if(f.isThought(i)){const l=a?o:r;return f.createProxy(l)}return i!==void 0?i:f.createProxy(r)}function Ke(f,r,t={}){const{path:n,expression:i}=r,o=ke(n,i);if(o)return{kind:"return",value:{define:o}};const s=Se(f,n,i);if(s)return{kind:"commit",instructions:[{path:s.scopeKey?s.scopeKey.split(".").filter(Boolean):[],op:"secret",value:i}]};const a=Pe(f,n,i);if(a)return{kind:"commit",instructions:[{path:a.scopeKey?a.scopeKey.split(".").filter(Boolean):[],op:"noise",value:i}]};const l=xe(f,n,i);if(l){const{scope:S}=I(n);return{kind:"commit",instructions:[{path:S,op:"ptr",value:ye(l.targetPath)}]}}const c=_e(f,n,i);if(c)return{kind:"commit",instructions:[{path:c.targetPath,op:"id",value:me(c.id)}]};const d=Ee(f,n,i);if(d)return{kind:"commit",instructions:[{path:d.targetPath,op:"remove",value:"-"}]};const v=Be(f,n,i);if(v){if(v.mode==="assign")return{kind:"commit",instructions:[{path:[...v.targetPath,v.name],op:"derive",value:{kind:"expr",source:v.expr}}]};if(!t.evaluateThunk)throw new Error('Non-serializable derivation: "=" thunk requires `evaluateThunk` or serializable DNA.');const S=t.evaluateThunk(v.thunk);return v.targetPath.length===0?{kind:"return",value:S}:{kind:"commit",instructions:[{path:v.targetPath,op:"derive",value:S}]}}const y=Ae(f,n,i);if(y){if(!t.readPath)return{kind:"commit",instructions:[{path:y.targetPath,op:"query",value:{paths:y.paths}}]};const S=y.paths.map(_=>t.readPath(_.split(".").filter(Boolean))),p=y.fn?y.fn(...S):S;return y.targetPath.length===0?{kind:"return",value:p}:{kind:"commit",instructions:[{path:y.targetPath,op:"query",value:p}]}}return{kind:"commit",instructions:[{path:n,op:"set",value:i}]}}const he="+";function L(f){let r=2166136261;for(let t=0;t<f.length;t++)r^=f.charCodeAt(t),r=Math.imul(r,16777619);return("00000000"+(r>>>0).toString(16)).slice(-8)}class ne{constructor(r){this.localSecrets={},this.localNoises={},this.encryptedBranches={},this.index={},this._shortTermMemory=[],this.derivations={},this.refSubscribers={},this.unsafeEval=!1,this.operators={_:{kind:"secret"},"~":{kind:"noise"},__:{kind:"pointer"},"->":{kind:"pointer"},"@":{kind:"identity"},"=":{kind:"eval"},"?":{kind:"query"},"-":{kind:"remove"}},this.localSecrets={},this.localNoises={},this.encryptedBranches={},this.index={},this.operators={_:{kind:"secret"},"~":{kind:"noise"},__:{kind:"pointer"},"->":{kind:"pointer"},"@":{kind:"identity"},"=":{kind:"eval"},"?":{kind:"query"},"-":{kind:"remove"}},this._shortTermMemory=[],r!==void 0&&this.postulate([],r),this.rebuildIndex();const t=this.createProxy([]);return Object.setPrototypeOf(t,ne.prototype),Object.assign(t,this),t}get shortTermMemory(){return this._shortTermMemory}inspect(r){const t=r?.last;return{thoughts:typeof t=="number"&&Number.isFinite(t)&&t>0?this._shortTermMemory.slice(-Math.floor(t)):this._shortTermMemory.slice(),index:{...this.index},encryptedScopes:Object.keys(this.encryptedBranches),secretScopes:Object.keys(this.localSecrets),noiseScopes:Object.keys(this.localNoises)}}explain(r){const t=this.normalizeSelectorPath(String(r??"").split(".").filter(Boolean)),n=t.join("."),i=this.readPath(t),o=this.derivations[n];if(!o)return{path:n,value:i,derivation:null,meta:{dependsOn:[]}};const s=o.refs.map(a=>{const l=this.normalizeSelectorPath(a.path.split(".").filter(Boolean)),c=this.resolveBranchScope(l),d=!!(c&&c.length>0&&qt(l,c)),v=this.readPath(l);return{label:a.label,path:a.path,value:d?"●●●●":v,origin:d?"stealth":"public",masked:d}});return{path:n,value:i,derivation:{expression:o.expression,inputs:s},meta:{dependsOn:o.refs.map(a=>a.path),lastComputedAt:o.lastComputedAt}}}cloneValue(r){const t=globalThis.structuredClone;return typeof t=="function"?t(r):JSON.parse(JSON.stringify(r))}exportSnapshot(){return this.cloneValue({shortTermMemory:this._shortTermMemory,localSecrets:this.localSecrets,localNoises:this.localNoises,encryptedBranches:this.encryptedBranches,operators:this.operators})}importSnapshot(r){const t=this.cloneValue(r??{});this._shortTermMemory=Array.isArray(t.shortTermMemory)?t.shortTermMemory:[],this.localSecrets=t.localSecrets&&typeof t.localSecrets=="object"?t.localSecrets:{},this.localNoises=t.localNoises&&typeof t.localNoises=="object"?t.localNoises:{},this.encryptedBranches=t.encryptedBranches&&typeof t.encryptedBranches=="object"?t.encryptedBranches:{},this.derivations={},this.refSubscribers={};const n={_:{kind:"secret"},"~":{kind:"noise"},__:{kind:"pointer"},"->":{kind:"pointer"},"@":{kind:"identity"},"=":{kind:"eval"},"?":{kind:"query"},"-":{kind:"remove"}};this.operators=t.operators&&typeof t.operators=="object"?{...n,...t.operators}:n,this.rebuildIndex()}rehydrate(r){this.importSnapshot(r)}replayThoughts(r){this.localSecrets={},this.localNoises={},this.encryptedBranches={},this.index={},this._shortTermMemory=[],this.derivations={},this.refSubscribers={};for(const t of r||[]){const n=String(t.path||"").split(".").filter(Boolean);if(t.operator==="_"){this.postulate([...n,"_"],typeof t.expression=="string"?t.expression:"***");continue}if(t.operator==="~"){this.postulate([...n,"~"],typeof t.expression=="string"?t.expression:"***");continue}if(t.operator==="@"){const i=t.expression&&t.expression.__id||t.value&&t.value.__id||t.value;typeof i=="string"&&i.length>0&&this.postulate([...n,"@"],i);continue}if(t.operator==="__"||t.operator==="->"){const i=t.expression&&t.expression.__ptr||t.value&&t.value.__ptr||t.value;typeof i=="string"&&i.length>0&&this.postulate([...n,"__"],i);continue}if(t.operator==="-"){this.removeSubtree(n);continue}if(t.operator==="="||t.operator==="?"){this.postulate(n,t.value,t.operator);continue}this.postulate(n,t.expression,t.operator)}this.rebuildIndex()}isRemoveCall(r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);if(!i||this.opKind(i)!=="remove")return null;if(t==null)return{targetPath:n};if(typeof t=="string"){const o=t.split(".").filter(Boolean);return{targetPath:[...n,...o]}}return null}createProxy(r){const t=this,n=(...i)=>Me({createProxy:o=>t.createProxy(o),normalizeArgs:o=>t.normalizeArgs(o),readPath:o=>t.readPath(o),postulate:(o,s)=>t.postulate(o,s),opKind:o=>t.opKind(o),splitPath:I,isThought:be},r,i);return new Proxy(n,{get(i,o){if(typeof o=="symbol")return i[o];if(o in t){const a=t[o];return typeof a=="function"?a.bind(t):a}const s=[...r,String(o)];return t.createProxy(s)},apply(i,o,s){return Reflect.apply(i,void 0,s)}})}normalizeArgs(r){if(r.length!==0)return r.length===1?r[0]:r}opKind(r){return this.operators[r]?.kind??null}isSecretScopeCall(r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);return!i||this.opKind(i)!=="secret"||typeof t!="string"?null:{scopeKey:n.join(".")}}isNoiseScopeCall(r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);return!i||this.opKind(i)!=="noise"||typeof t!="string"?null:{scopeKey:n.join(".")}}isPointerCall(r,t){if(r.length===0)return null;const{leaf:n}=I(r);if(!n||this.opKind(n)!=="pointer"||typeof t!="string")return null;const i=t.trim().replace(/^\./,"");return i?{targetPath:i}:null}isIdentityCall(r,t){if(r.length===1&&this.opKind(r[0])==="identity")return typeof t!="string"?null:{id:Zt(t),targetPath:[]};const{scope:n,leaf:i}=I(r);return!i||this.opKind(i)!=="identity"||typeof t!="string"?null:{id:Zt(t),targetPath:n}}isEvalCall(r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);if(!i||this.opKind(i)!=="eval")return null;if(typeof t=="function")return{mode:"thunk",targetPath:n,thunk:t};if(Array.isArray(t)&&t.length>=2){const o=String(t[0]??"").trim(),s=String(t[1]??"").trim();return!o||!s?null:{mode:"assign",targetPath:n,name:o,expr:s}}return null}isQueryCall(r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);if(!i||this.opKind(i)!=="query")return null;let o=null,s;if(Array.isArray(t)&&t.length>0)Array.isArray(t[0])&&(t.length===1||typeof t[1]=="function")?(o=t[0],s=typeof t[1]=="function"?t[1]:void 0):o=t;else return null;if(!Array.isArray(o)||o.length===0)return null;const a=o.map(l=>String(l)).map(l=>l.trim()).filter(l=>l.length>0);return a.length===0?null:{targetPath:n,paths:a,fn:s}}isDefineOpCall(r,t){if(r.length!==1||r[0]!==he||!Array.isArray(t)||t.length<2)return null;const i=String(t[0]??"").trim(),o=String(t[1]??"").trim();return!i||!o||i===he?null:{op:i,kind:o}}getPrevThoughtHash(){return this._shortTermMemory[this._shortTermMemory.length-1]?.hash??""}extractExpressionRefs(r){const t=String(r??"").trim();if(!t)return[];const n=String.raw`[A-Za-z_][A-Za-z0-9_]*(?:\[(?:"[^"]*"|'[^']*'|[^\]]+)\])*`,i=new RegExp(String.raw`__ptr(?:\.${n})*|${n}(?:\.${n})*`,"g"),o=new Set(["true","false","null","undefined","NaN","Infinity"]),s=new Set,a=t.match(i)||[];for(const l of a)o.has(l)||s.add(l);return Array.from(s)}resolveRefPath(r,t){if(!r||r.startsWith("__ptr."))return null;const n=this.normalizeSelectorPath(r.split(".").filter(Boolean));if(n.length===0)return null;const i=this.normalizeSelectorPath([...t,...n]).join("."),o=this.normalizeSelectorPath(n).join(".");return r.includes(".")?o:i}unregisterDerivation(r){const t=this.derivations[r];if(t){for(const n of t.refs){const i=this.refSubscribers[n.path]||[];this.refSubscribers[n.path]=i.filter(o=>o!==r),this.refSubscribers[n.path].length===0&&delete this.refSubscribers[n.path]}delete this.derivations[r]}}registerDerivation(r,t,n){const i=r.join(".");this.unregisterDerivation(i);const o=this.extractExpressionRefs(n),s=[],a=new Set;for(const l of o){const c=this.resolveRefPath(l,t);if(!c||a.has(c))continue;a.add(c),s.push({label:l,path:c});const d=this.refSubscribers[c]||[];d.includes(i)||d.push(i),this.refSubscribers[c]=d}this.derivations[i]={expression:n,evalScope:[...t],refs:s,lastComputedAt:Date.now()}}recomputeTarget(r){const t=this.derivations[r];if(!t)return!1;const n=this.normalizeSelectorPath(r.split(".").filter(Boolean)),i=this.tryEvaluateAssignExpression(t.evalScope,t.expression);return this.postulate(n,i.ok?i.value:t.expression,"="),t.lastComputedAt=Date.now(),!0}invalidateFromPath(r){const t=this.normalizeSelectorPath(r).join(".");if(!t)return;const n=[t],i=new Set;for(;n.length>0;){const o=n.shift(),s=this.refSubscribers[o]||[];for(const a of s){if(i.has(a))continue;i.add(a),this.recomputeTarget(a)&&n.push(a)}}}clearDerivationsByPrefix(r){const t=r.join(".");for(const n of Object.keys(this.derivations))(t===""||n===t||n.startsWith(t+"."))&&this.unregisterDerivation(n)}commitThoughtOnly(r,t,n,i){const o=r.join("."),s=this.computeEffectiveSecret(r),a=this.getPrevThoughtHash(),l=JSON.stringify({path:o,operator:t,expression:n,value:i,effectiveSecret:s,prevHash:a}),c=L(l),d=Date.now(),v={path:o,operator:t,expression:n,value:i,effectiveSecret:s,hash:c,prevHash:a,timestamp:d};return this._shortTermMemory.push(v),this.rebuildIndex(),v}commitValueMapping(r,t,n=null){let i=t;const o=r.join("."),s=this.computeEffectiveSecret(r),a=this.resolveBranchScope(r);if(a&&a.length===0&&this.localSecrets[""]&&this.localSecrets[o],a&&a.length>0){const l=this.computeEffectiveSecret(a),c=r.slice(a.length),d=this.getBranchBlob(a);let v={};if(d&&l){const y=Ut(d,l,a);y&&typeof y=="object"&&(v=y)}if(c.length===0)(typeof v!="object"||v===null)&&(v={}),v.expression=t;else{let y=v;for(let S=0;S<c.length-1;S++){const p=c[S];(!y[p]||typeof y[p]!="object")&&(y[p]={}),y=y[p]}y[c[c.length-1]]=t}if(l){const y=ee(v,l,a);this.setBranchBlob(a,y)}i=t}else if(s){const l=n!=="="&&n!=="?";D(t)||Xt(t)||!l?i=t:i=ee(t,s,r)}else i=t;return this.commitThoughtOnly(r,n,t,i)}commitMapping(r,t=null){switch(r.op){case"set":return this.commitValueMapping(r.path,r.value,t);case"ptr":return this.commitValueMapping(r.path,r.value,"__");case"id":return this.commitValueMapping(r.path,r.value,"@");case"secret":{if(typeof r.value!="string")return;const n=r.path.join(".");return this.localSecrets[n]=r.value,this.commitThoughtOnly(r.path,"_","***","***")}default:return}}tryResolveEvalTokenValue(r,t){if(r.startsWith("__ptr.")){const s=this.getIndex(t);if(!D(s))return{ok:!1};const a=r.slice(6).split(".").filter(Boolean),l=[...s.__ptr.split(".").filter(Boolean),...a],c=this.readPath(l);return c==null?{ok:!1}:{ok:!0,value:c}}const n=r.split(".").filter(Boolean),i=[...t,...n];let o=this.readPath(i);return o==null&&(o=this.readPath(n)),o==null?{ok:!1}:{ok:!0,value:o}}tokenizeEvalExpression(r){const t=[],n=String.raw`[A-Za-z_][A-Za-z0-9_]*(?:\[(?:"[^"]*"|'[^']*'|[^\]]+)\])*`,i=new RegExp(String.raw`^(?:__ptr(?:\.${n})*|${n}(?:\.${n})*)`),o={true:!0,false:!1,null:null,undefined:void 0,NaN:NaN,Infinity:1/0},s=new Set([">=","<=","==","!=","&&","||"]),a=new Set(["+","-","*","/","%","<",">","!"]);let l=0;for(;l<r.length;){const c=r[l];if(/\s/.test(c)){l++;continue}if(c==="("){t.push({kind:"lparen"}),l++;continue}if(c===")"){t.push({kind:"rparen"}),l++;continue}const d=r.slice(l,l+2);if(s.has(d)){t.push({kind:"op",value:d}),l+=2;continue}if(a.has(c)){t.push({kind:"op",value:c}),l++;continue}if(/\d/.test(c)||c==="."&&/\d/.test(r[l+1]??"")){let y=l;for(;y<r.length&&/[0-9]/.test(r[y]);)y++;if(r[y]===".")for(y++;y<r.length&&/[0-9]/.test(r[y]);)y++;if(r[y]==="e"||r[y]==="E"){let p=y+1;(r[p]==="+"||r[p]==="-")&&p++;let _=!1;for(;p<r.length&&/[0-9]/.test(r[p]);)_=!0,p++;if(!_)return null;y=p}const S=Number(r.slice(l,y));if(!Number.isFinite(S))return null;t.push({kind:"literal",value:S}),l=y;continue}const v=r.slice(l).match(i);if(v&&v[0]){const y=v[0];Object.prototype.hasOwnProperty.call(o,y)?t.push({kind:"literal",value:o[y]}):t.push({kind:"identifier",value:y}),l+=y.length;continue}return null}return t}tryEvaluateAssignExpression(r,t){const n=String(t??"").trim();if(!n)return{ok:!1};if(!/^[A-Za-z0-9_\s+\-*/%().<>=!&|\[\]"']+$/.test(n))return{ok:!1};if(this.unsafeEval)return{ok:!1};const i=this.tokenizeEvalExpression(n);if(!i||i.length===0)return{ok:!1};const o={"u-":7,"!":7,"*":6,"/":6,"%":6,"+":5,"-":5,"<":4,"<=":4,">":4,">=":4,"==":3,"!=":3,"&&":2,"||":1},s=new Set(["u-","!"]),a=[],l=[];let c="start";for(const S of i){if(S.kind==="literal"||S.kind==="identifier"){a.push(S),c="value";continue}if(S.kind==="lparen"){l.push(S),c="lparen";continue}if(S.kind==="rparen"){let _=!1;for(;l.length>0;){const A=l.pop();if(A.kind==="lparen"){_=!0;break}a.push(A)}if(!_)return{ok:!1};c="rparen";continue}let p=S.value;if(p==="-"&&(c==="start"||c==="op"||c==="lparen"))p="u-";else{if(p==="!"&&(c==="value"||c==="rparen"))return{ok:!1};if(p!=="!"&&(c==="start"||c==="op"||c==="lparen"))return{ok:!1}}for(;l.length>0;){const _=l[l.length-1];if(_.kind!=="op")break;const A=o[_.value]??-1,B=o[p]??-1;if(B<0)return{ok:!1};if(!(s.has(p)?B<A:B<=A))break;a.push(l.pop())}l.push({kind:"op",value:p}),c="op"}if(c==="op"||c==="lparen"||c==="start")return{ok:!1};for(;l.length>0;){const S=l.pop();if(S.kind==="lparen")return{ok:!1};a.push(S)}const d=S=>{if(typeof S=="number"&&Number.isFinite(S))return S;if(typeof S=="string"){const p=Number(S);if(Number.isFinite(p))return p}return null},v=[];for(const S of a){if(S.kind==="literal"){v.push(S.value);continue}if(S.kind==="identifier"){const E=this.tryResolveEvalTokenValue(S.value,r);if(!E.ok)return{ok:!1};v.push(E.value);continue}const p=S.value;if(p==="u-"||p==="!"){if(v.length<1)return{ok:!1};const E=v.pop();if(p==="u-"){const j=d(E);if(j===null)return{ok:!1};v.push(-j)}else v.push(!E);continue}if(v.length<2)return{ok:!1};const _=v.pop(),A=v.pop();if(p==="&&"||p==="||"){v.push(p==="&&"?!!A&&!!_:!!A||!!_);continue}if(p==="=="||p==="!="){v.push(p==="=="?A==_:A!=_);continue}if(p==="<"||p==="<="||p===">"||p===">="){const E=d(A),j=d(_);if(E===null||j===null)return{ok:!1};p==="<"&&v.push(E<j),p==="<="&&v.push(E<=j),p===">"&&v.push(E>j),p===">="&&v.push(E>=j);continue}const B=d(A),F=d(_);if(B===null||F===null)return{ok:!1};let O;if(p==="+")O=B+F;else if(p==="-")O=B-F;else if(p==="*")O=B*F;else if(p==="/")O=B/F;else if(p==="%")O=B%F;else return{ok:!1};if(!Number.isFinite(O))return{ok:!1};v.push(O)}if(v.length!==1)return{ok:!1};const y=v[0];return typeof y=="number"&&Number.isFinite(y)?{ok:!0,value:y}:typeof y=="boolean"?{ok:!0,value:y}:{ok:!1}}postulate(r,t,n=null){let i=r;const o=this.isDefineOpCall(i,t);if(o){this.operators[o.op]={kind:o.kind};return}const{leaf:s}=I(i),a=s?this.opKind(s):null;if(a===null||a==="secret"||a==="pointer"||a==="identity"){const p=Ke(this.operators,{path:i,expression:t});if(p.kind==="commit"){const _=new Set(["set","secret","ptr","id"]);if(p.instructions.every(B=>_.has(B.op))){let B;const F=[];for(const O of p.instructions){const E=this.commitMapping(O,n);E&&(B=E,F.push(E.path.split(".").filter(Boolean)))}if(B){for(const O of F)this.invalidateFromPath(O);return B}}}}const c=this.isEvalCall(i,t);if(c){if(c.mode==="thunk"){const B=c.thunk();return c.targetPath.length===0?B:this.postulate(c.targetPath,B,"=")}if(this.pathContainsIterator(c.targetPath)){const B=this.collectIteratorIndices(c.targetPath);let F;for(const O of B){const E=this.normalizeSelectorPath(this.substituteIteratorInPath(c.targetPath,O)),j=this.normalizeSelectorPath([...E,c.name]),T=this.substituteIteratorInExpression(c.expr,O);this.registerDerivation(j,E,T);const W=this.tryEvaluateAssignExpression(E,T);F=this.postulate(j,W.ok?W.value:T,"=")}return F}if(this.pathContainsFilterSelector(c.targetPath)){const B=this.collectFilteredScopes(c.targetPath);let F;for(const O of B){const E=this.normalizeSelectorPath(O),j=this.normalizeSelectorPath([...E,c.name]);this.registerDerivation(j,E,c.expr);const T=this.tryEvaluateAssignExpression(E,c.expr);F=this.postulate(j,T.ok?T.value:c.expr,"=")}return F}const p=this.normalizeSelectorPath([...c.targetPath,c.name]),_=this.normalizeSelectorPath(c.targetPath);this.registerDerivation(p,_,c.expr);const A=this.tryEvaluateAssignExpression(_,c.expr);return A.ok?this.postulate(p,A.value,"="):this.postulate(p,c.expr,"=")}const d=this.isQueryCall(i,t);if(d){const p=d.paths.map(A=>this.readPath(A.split(".").filter(Boolean))),_=d.fn?d.fn(...p):p;return d.targetPath.length===0?_:this.postulate(d.targetPath,_,"?")}const v=this.isRemoveCall(i,t);if(v){this.removeSubtree(v.targetPath);return}const y=this.isNoiseScopeCall(i,t);if(y){this.localNoises[y.scopeKey]=t;const p=y.scopeKey?y.scopeKey.split(".").filter(Boolean):[];return this.commitThoughtOnly(p,"~","***","***")}const S=this.commitValueMapping(i,t,n);return this.invalidateFromPath(i),S}removeSubtree(r){this.clearDerivationsByPrefix(r);const t=r.join(".");for(const d of Object.keys(this.localSecrets)){if(t===""){delete this.localSecrets[d];continue}(d===t||d.startsWith(t+"."))&&delete this.localSecrets[d]}for(const d of Object.keys(this.localNoises)){if(t===""){delete this.localNoises[d];continue}(d===t||d.startsWith(t+"."))&&delete this.localNoises[d]}for(const d of Object.keys(this.encryptedBranches)){if(t===""){delete this.encryptedBranches[d];continue}if(d===t||d.startsWith(t+".")){delete this.encryptedBranches[d];continue}const v=d.split(".").filter(Boolean);if(!qt(r,v)||r.length<=v.length)continue;const y=this.computeEffectiveSecret(v);if(!y)continue;const S=this.getBranchBlob(v);if(!S)continue;const p=Ut(S,y,v);if(!p||typeof p!="object")continue;const _=r.slice(v.length);let A=p;for(let B=0;B<_.length-1;B++){const F=_[B];if(!A||typeof A!="object"||!(F in A)){A=null;break}A=A[F]}if(A&&typeof A=="object"){delete A[_[_.length-1]];const B=ee(p,y,v);this.setBranchBlob(v,B)}}const n=r.join("."),i=Date.now(),o=this.computeEffectiveSecret(r),s=this.getPrevThoughtHash(),a=JSON.stringify({path:n,operator:"-",expression:"-",value:"-",effectiveSecret:o,prevHash:s}),l=L(a),c={path:n,operator:"-",expression:"-",value:"-",effectiveSecret:o,hash:l,prevHash:s,timestamp:i};this._shortTermMemory.push(c),this.rebuildIndex()}computeEffectiveSecret(r){let t=null,n=null;this.localNoises[""]!==void 0&&(t="",n=this.localNoises[""]);for(let o=1;o<=r.length;o++){const s=r.slice(0,o).join(".");this.localNoises[s]!==void 0&&(t=s,n=this.localNoises[s])}let i="root";n?i=L("noise::"+n):this.localSecrets[""]&&(i=L(i+"::"+this.localSecrets[""])),t===null||t===""||t.split(".").filter(Boolean).length;for(let o=1;o<=r.length;o++){const s=r.slice(0,o).join(".");if(this.localSecrets[s]){if(t!==null&&t!==""){const a=t+".";if(!(s===t||s.startsWith(a)))continue}i=L(i+"::"+this.localSecrets[s])}}return i==="root"?"":i}rebuildIndex(){const r={},t=this._shortTermMemory.map((n,i)=>({t:n,i})).sort((n,i)=>n.t.timestamp!==i.t.timestamp?n.t.timestamp-i.t.timestamp:n.t.hash!==i.t.hash?n.t.hash<i.t.hash?-1:1:n.i-i.i).map(n=>n.t);for(const n of t){const i=n.path,o=i.split(".").filter(Boolean),s=this.resolveBranchScope(o),a=s&&s.length>0&&qt(o,s);if(n.operator==="-"){if(i===""){for(const c of Object.keys(r))delete r[c];continue}const l=i+".";for(const c of Object.keys(r))(c===i||c.startsWith(l))&&delete r[c];continue}a||(r[i]=n.value)}this.index=r}getIndex(r){return this.index[r.join(".")]}setIndex(r,t){this.index[r.join(".")]=t}resolveIndexPointerPath(r,t=8){let n=r;for(let i=0;i<t;i++){const o=this.getIndex(n);if(D(o)){n=o.__ptr.split(".").filter(Boolean);continue}let s=!1;for(let a=n.length-1;a>=0;a--){const l=n.slice(0,a),c=this.getIndex(l);if(!D(c))continue;const d=c.__ptr.split(".").filter(Boolean),v=n.slice(a);n=[...d,...v],s=!0;break}if(!s)return{path:n,raw:o}}return{path:n,raw:void 0}}setBranchBlob(r,t){const n=r.join(".");this.encryptedBranches[n]=t}getBranchBlob(r){const t=r.join(".");return this.encryptedBranches[t]}resolveBranchScope(r){let t=null;this.localSecrets[""]&&(t=[]);for(let n=1;n<=r.length;n++){const i=r.slice(0,n),o=i.join(".");this.localSecrets[o]&&(t=i)}return t}normalizeSelectorPath(r){const t=[];for(const n of r){const i=String(n).trim();if(!i)continue;const o=i.indexOf("[");if(o===-1){t.push(i);continue}const s=i.slice(0,o).trim(),a=i.slice(o);s&&t.push(s);const l=Array.from(a.matchAll(/\[([^\]]*)\]/g));if(l.map(d=>d[0]).join("")!==a){t.push(a);continue}for(const d of l){let v=(d[1]??"").trim();(v.startsWith('"')&&v.endsWith('"')||v.startsWith("'")&&v.endsWith("'"))&&(v=v.slice(1,-1)),v&&t.push(v)}}return t}pathContainsIterator(r){return r.some(t=>t.includes("[i]"))}substituteIteratorInPath(r,t){return r.map(n=>n.split("[i]").join(`[${t}]`))}substituteIteratorInExpression(r,t){return String(r??"").split("[i]").join(`[${t}]`)}collectIteratorIndices(r){const t=r.findIndex(o=>o.includes("[i]"));if(t===-1)return[];const n=[];for(let o=0;o<=t;o++){const s=r[o];if(o===t){const a=s.split("[i]").join("").trim();a&&n.push(a)}else n.push(s)}const i=new Set;for(const o of Object.keys(this.index)){const s=o.split(".").filter(Boolean);if(s.length<=n.length)continue;let a=!0;for(let l=0;l<n.length;l++)if(s[l]!==n[l]){a=!1;break}a&&i.add(s[n.length])}return Array.from(i).sort((o,s)=>{const a=Number(o),l=Number(s),c=Number.isFinite(a),d=Number.isFinite(l);return c&&d?a-l:c?-1:d?1:o.localeCompare(s)})}parseFilterExpression(r){const n=String(r??"").trim().match(/^(.+?)\s*(>=|<=|==|!=|>|<)\s*(.+)$/);if(!n)return null;const i=n[1].trim(),o=n[2],s=n[3].trim();return!i||!s?null:{left:i,op:o,right:s}}parseLogicalFilterExpression(r){const t=String(r??"").trim();if(!t)return null;const n=t.split(/\s*(&&|\|\|)\s*/).filter(s=>s.length>0);if(n.length===0)return null;const i=[],o=[];for(let s=0;s<n.length;s++)if(s%2===0){const a=this.parseFilterExpression(n[s]);if(!a)return null;i.push(a)}else{const a=n[s];if(a!=="&&"&&a!=="||")return null;o.push(a)}return i.length===0||o.length!==Math.max(0,i.length-1)?null:{clauses:i,ops:o}}compareValues(r,t,n){switch(t){case">":return r>n;case"<":return r<n;case">=":return r>=n;case"<=":return r<=n;case"==":return r==n;case"!=":return r!=n;default:return!1}}parseLiteralOrPath(r){const t=r.trim();if(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))return{kind:"literal",value:t.slice(1,-1)};if(t==="true")return{kind:"literal",value:!0};if(t==="false")return{kind:"literal",value:!1};if(t==="null")return{kind:"literal",value:null};const n=Number(t);return Number.isFinite(n)?{kind:"literal",value:n}:{kind:"path",parts:this.normalizeSelectorPath(t.split(".").filter(Boolean))}}resolveRelativeFirst(r,t){const n=this.readPath([...r,...t]);return n??this.readPath(t)}evaluateFilterClauseForScope(r,t){const n=this.normalizeSelectorPath(t.left.split(".").filter(Boolean)),i=this.resolveRelativeFirst(r,n);if(i==null)return!1;const o=this.parseLiteralOrPath(t.right),s=o.kind==="literal"?o.value:this.resolveRelativeFirst(r,o.parts);return s==null?!1:this.compareValues(i,t.op,s)}evaluateLogicalFilterForScope(r,t){const n=this.parseLogicalFilterExpression(t);if(!n)return!1;let i=this.evaluateFilterClauseForScope(r,n.clauses[0]);for(let o=1;o<n.clauses.length;o++){const s=this.evaluateFilterClauseForScope(r,n.clauses[o]);i=n.ops[o-1]==="&&"?i&&s:i||s}return i}collectChildrenForPrefix(r){const t=new Set;for(const n of Object.keys(this.index)){const i=n.split(".").filter(Boolean);if(i.length<=r.length)continue;let o=!0;for(let s=0;s<r.length;s++)if(i[s]!==r[s]){o=!1;break}o&&t.add(i[r.length])}return Array.from(t)}parseSelectorSegment(r){const t=String(r??"").trim(),n=t.indexOf("["),i=t.lastIndexOf("]");if(n<=0||i<=n||i!==t.length-1)return null;const o=t.slice(0,n).trim(),s=t.slice(n+1,i).trim();return!o||!s?null:{base:o,selector:s}}parseSelectorKeys(r){const t=r.trim();if(t.startsWith("[")&&t.endsWith("]")){const i=t.slice(1,-1).trim();return i?i.split(",").map(s=>s.trim()).filter(Boolean).map(s=>s.startsWith('"')&&s.endsWith('"')||s.startsWith("'")&&s.endsWith("'")?s.slice(1,-1):s):[]}const n=t.match(/^(-?\d+)\s*\.\.\s*(-?\d+)$/);if(n){const i=Number(n[1]),o=Number(n[2]);if(!Number.isFinite(i)||!Number.isFinite(o))return null;const s=i<=o?1:-1,a=[];if(Math.abs(o-i)>1e4)return null;for(let c=i;s>0?c<=o:c>=o;c+=s)a.push(String(c));return a}return null}parseTransformSelector(r){const n=r.trim().match(/^([A-Za-z_][A-Za-z0-9_]*)\s*=>\s*(.+)$/);if(!n)return null;const i=n[1].trim(),o=n[2].trim();return!i||!o?null:{varName:i,expr:o}}evaluateTransformPath(r){const t=r.findIndex(c=>{const d=this.parseSelectorSegment(c);return d?this.parseTransformSelector(d.selector)!==null:!1});if(t===-1)return;const n=this.parseSelectorSegment(r[t]);if(!n)return;const i=this.parseTransformSelector(n.selector);if(!i)return;const o=[...r.slice(0,t),n.base];if(r.slice(t+1).length>0)return;const a=this.collectChildrenForPrefix(o),l={};for(const c of a){const d=[...o,c],v=i.expr.replace(new RegExp(String.raw`\b${i.varName}\.`,"g"),""),y=this.tryEvaluateAssignExpression(d,v);y.ok&&(l[c]=y.value)}return l}evaluateSelectionPath(r){const t=r.findIndex(l=>this.parseSelectorSegment(l)!==null);if(t===-1)return;const n=this.parseSelectorSegment(r[t]);if(!n)return;const i=this.parseSelectorKeys(n.selector);if(i===null)return;const o=[...r.slice(0,t),n.base],s=r.slice(t+1),a={};for(const l of i){const c=[...o,l],d=s.length===0?this.buildPublicSubtree(c):this.readPath([...c,...s]);d!==void 0&&(a[l]=d)}return a}buildPublicSubtree(r){const t=r.join("."),n={};let i=!1;for(const[o,s]of Object.entries(this.index)){if(o===t)return s;if(!o.startsWith(t+"."))continue;const a=o.slice(t.length+1).split(".").filter(Boolean);let l=n;for(let c=0;c<a.length-1;c++){const d=a[c];(!l[d]||typeof l[d]!="object")&&(l[d]={}),l=l[d]}l[a[a.length-1]]=s,i=!0}return i?n:void 0}evaluateFilterPath(r){const t=r.findIndex(l=>this.parseLogicalFilterExpression(l)!==null);if(t===-1)return;const n=r[t],i=r.slice(0,t),o=r.slice(t+1);if(i.length===0)return;const s=this.collectChildrenForPrefix(i),a={};for(const l of s){const c=[...i,l];this.evaluateLogicalFilterForScope(c,n)&&(o.length===0?a[l]=this.buildPublicSubtree(c):a[l]=this.readPath([...c,...o]))}return a}pathContainsFilterSelector(r){return r.some(t=>{const n=this.parseSelectorSegment(t);return n?this.parseLogicalFilterExpression(n.selector)!==null:!1})}collectFilteredScopes(r){const t=r.findIndex(l=>{const c=this.parseSelectorSegment(l);return c?this.parseLogicalFilterExpression(c.selector)!==null:!1});if(t===-1)return[];const n=this.parseSelectorSegment(r[t]);if(!n)return[];const i=[...r.slice(0,t),n.base],o=r.slice(t+1),s=this.collectChildrenForPrefix(i),a=[];for(const l of s){const c=[...i,l];this.evaluateLogicalFilterForScope(c,n.selector)&&a.push([...c,...o])}return a}readPath(r){const t=this.evaluateTransformPath(r);if(t!==void 0)return t;const n=this.evaluateSelectionPath(r);if(n!==void 0)return n;r=this.normalizeSelectorPath(r);const i=this.evaluateFilterPath(r);if(i!==void 0)return i;const o=this.resolveBranchScope(r);if(o&&o.length>0&&qt(r,o)){if(r.length===o.length)return;const d=this.computeEffectiveSecret(o);if(!d)return null;const v=this.getBranchBlob(o);if(!v)return;const y=Ut(v,d,o);if(!y||typeof y!="object")return;const S=r.slice(o.length);let p=y;for(const _ of S){if(!p||typeof p!="object")return;p=p[_]}return D(p)?this.readPath(p.__ptr.split(".").filter(Boolean)):(Xt(p),p)}const s=this.getIndex(r);if(D(s))return s;const a=this.resolveIndexPointerPath(r),l=a.raw;if(l===void 0)return a.path.length===r.length&&a.path.every((v,y)=>v===r[y])?void 0:this.readPath(a.path);if(D(l))return this.readPath(l.__ptr.split(".").filter(Boolean));if(Xt(l)||!Te(l))return l;const c=this.computeEffectiveSecret(r);return c?Ut(l,c,r):null}}module.exports=ne;
1
+ "use strict";function ve(f){return{__ptr:f}}function D(f){return!!f&&typeof f=="object"&&typeof f.__ptr=="string"&&f.__ptr.length>0}function me(f){return{__id:f}}function Xt(f){return!!f&&typeof f=="object"&&typeof f.__id=="string"&&f.__id.length>0}function be(f){return!!f&&typeof f=="object"&&typeof f.path=="string"&&typeof f.hash=="string"&&typeof f.timestamp=="number"}function I(f){return f.length===0?{scope:[],leaf:null}:{scope:f.slice(0,-1),leaf:f[f.length-1]}}function qt(f,r){if(r.length>f.length)return!1;for(let t=0;t<r.length;t++)if(f[t]!==r[t])return!1;return!0}function Zt(f){const r=f.trim().toLowerCase();if(r.length<3||r.length>63)throw new Error(`Invalid username length: ${r.length}. Expected 3..63 characters.`);if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$/.test(r))throw new Error(`Invalid username. Use only [a-z0-9-], and start/end with [a-z0-9]. Got: ${f}`);if(r.includes("--"))throw new Error(`Invalid username. "--" is not allowed. Got: ${f}`);return r}function K(f,r){return f[r]?.kind??null}function ke(f,r){if(f.length!==1||f[0]!=="+"||!Array.isArray(r)||r.length<2)return null;const n=String(r[0]??"").trim(),i=String(r[1]??"").trim();return!n||!i||n==="+"?null:{op:n,kind:i}}function Se(f,r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);return!i||K(f,i)!=="secret"||typeof t!="string"?null:{scopeKey:n.join(".")}}function Pe(f,r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);return!i||K(f,i)!=="noise"||typeof t!="string"?null:{scopeKey:n.join(".")}}function xe(f,r,t){if(r.length===0)return null;const{leaf:n}=I(r);if(!n||K(f,n)!=="pointer"||typeof t!="string")return null;const i=t.trim().replace(/^\./,"");return i?{targetPath:i}:null}function _e(f,r,t){if(r.length===1&&K(f,r[0])==="identity")return typeof t!="string"?null:{id:Zt(t),targetPath:[]};const{scope:n,leaf:i}=I(r);return!i||K(f,i)!=="identity"||typeof t!="string"?null:{id:Zt(t),targetPath:n}}function Be(f,r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);if(!i||K(f,i)!=="eval")return null;if(typeof t=="function")return{mode:"thunk",targetPath:n,thunk:t};if(Array.isArray(t)&&t.length>=2){const o=String(t[0]??"").trim(),s=String(t[1]??"").trim();return!o||!s?null:{mode:"assign",targetPath:n,name:o,expr:s}}return null}function Ae(f,r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);if(!i||K(f,i)!=="query")return null;let o=null,s;if(Array.isArray(t)&&t.length>0)Array.isArray(t[0])&&(t.length===1||typeof t[1]=="function")?(o=t[0],s=typeof t[1]=="function"?t[1]:void 0):o=t;else return null;if(!Array.isArray(o)||o.length===0)return null;const a=o.map(l=>String(l)).map(l=>l.trim()).filter(l=>l.length>0);return a.length===0?null:{targetPath:n,paths:a,fn:s}}function Ee(f,r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);if(!i||K(f,i)!=="remove")return null;if(t==null)return{targetPath:n};if(typeof t=="string"){const o=t.split(".").filter(Boolean);return{targetPath:[...n,...o]}}return null}var Fe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function we(f){return f&&f.__esModule&&Object.prototype.hasOwnProperty.call(f,"default")?f.default:f}var te={exports:{}};var fe;function Ne(){return fe||(fe=1,(function(f){(function(){var r="input is invalid type",t="finalize already called",n=typeof window=="object",i=n?window:{};i.JS_SHA3_NO_WINDOW&&(n=!1);var o=!n&&typeof self=="object",s=!i.JS_SHA3_NO_NODE_JS&&typeof process=="object"&&process.versions&&process.versions.node;s?i=Fe:o&&(i=self);for(var a=!i.JS_SHA3_NO_COMMON_JS&&!0&&f.exports,l=!i.JS_SHA3_NO_ARRAY_BUFFER&&typeof ArrayBuffer<"u",c="0123456789abcdef".split(""),d=[31,7936,2031616,520093696],y=[4,1024,262144,67108864],v=[1,256,65536,16777216],S=[6,1536,393216,100663296],p=[0,8,16,24],_=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],A=[224,256,384,512],B=[128,256],F=["hex","buffer","arrayBuffer","array","digest"],O={128:168,256:136},E=i.JS_SHA3_NO_NODE_JS||!Array.isArray?function(e){return Object.prototype.toString.call(e)==="[object Array]"}:Array.isArray,T=l&&(i.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)?function(e){return typeof e=="object"&&e.buffer&&e.buffer.constructor===ArrayBuffer}:ArrayBuffer.isView,j=function(e){var u=typeof e;if(u==="string")return[e,!0];if(u!=="object"||e===null)throw new Error(r);if(l&&e.constructor===ArrayBuffer)return[new Uint8Array(e),!1];if(!E(e)&&!T(e))throw new Error(r);return[e,!1]},W=function(e){return j(e)[0].length===0},Gt=function(e){for(var u=[],h=0;h<e.length;++h)u[h]=e[h];return u},ie=function(e,u,h){return function(g){return new N(e,u,e).update(g)[h]()}},oe=function(e,u,h){return function(g,m){return new N(e,u,m).update(g)[h]()}},se=function(e,u,h){return function(g,m,b,P){return z["cshake"+e].update(g,m,b,P)[h]()}},le=function(e,u,h){return function(g,m,b,P){return z["kmac"+e].update(g,m,b,P)[h]()}},J=function(e,u,h,g){for(var m=0;m<F.length;++m){var b=F[m];e[b]=u(h,g,b)}return e},ae=function(e,u){var h=ie(e,u,"hex");return h.create=function(){return new N(e,u,e)},h.update=function(g){return h.create().update(g)},J(h,ie,e,u)},de=function(e,u){var h=oe(e,u,"hex");return h.create=function(g){return new N(e,u,g)},h.update=function(g,m){return h.create(m).update(g)},J(h,oe,e,u)},ge=function(e,u){var h=O[e],g=se(e,u,"hex");return g.create=function(m,b,P){return W(b)&&W(P)?z["shake"+e].create(m):new N(e,u,m).bytepad([b,P],h)},g.update=function(m,b,P,k){return g.create(b,P,k).update(m)},J(g,se,e,u)},ye=function(e,u){var h=O[e],g=le(e,u,"hex");return g.create=function(m,b,P){return new Qt(e,u,b).bytepad(["KMAC",P],h).bytepad([m],h)},g.update=function(m,b,P,k){return g.create(m,P,k).update(b)},J(g,le,e,u)},ce=[{name:"keccak",padding:v,bits:A,createMethod:ae},{name:"sha3",padding:S,bits:A,createMethod:ae},{name:"shake",padding:d,bits:B,createMethod:de},{name:"cshake",padding:y,bits:B,createMethod:ge},{name:"kmac",padding:y,bits:B,createMethod:ye}],z={},V=[],M=0;M<ce.length;++M)for(var R=ce[M],q=R.bits,$=0;$<q.length;++$){var Yt=R.name+"_"+q[$];if(V.push(Yt),z[Yt]=R.createMethod(q[$],R.padding),R.name!=="sha3"){var ue=R.name+q[$];V.push(ue),z[ue]=z[Yt]}}function N(e,u,h){this.blocks=[],this.s=[],this.padding=u,this.outputBits=h,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(e<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=h>>5,this.extraBytes=(h&31)>>3;for(var g=0;g<50;++g)this.s[g]=0}N.prototype.update=function(e){if(this.finalized)throw new Error(t);var u=j(e);e=u[0];for(var h=u[1],g=this.blocks,m=this.byteCount,b=e.length,P=this.blockCount,k=0,C=this.s,x,w;k<b;){if(this.reset)for(this.reset=!1,g[0]=this.block,x=1;x<P+1;++x)g[x]=0;if(h)for(x=this.start;k<b&&x<m;++k)w=e.charCodeAt(k),w<128?g[x>>2]|=w<<p[x++&3]:w<2048?(g[x>>2]|=(192|w>>6)<<p[x++&3],g[x>>2]|=(128|w&63)<<p[x++&3]):w<55296||w>=57344?(g[x>>2]|=(224|w>>12)<<p[x++&3],g[x>>2]|=(128|w>>6&63)<<p[x++&3],g[x>>2]|=(128|w&63)<<p[x++&3]):(w=65536+((w&1023)<<10|e.charCodeAt(++k)&1023),g[x>>2]|=(240|w>>18)<<p[x++&3],g[x>>2]|=(128|w>>12&63)<<p[x++&3],g[x>>2]|=(128|w>>6&63)<<p[x++&3],g[x>>2]|=(128|w&63)<<p[x++&3]);else for(x=this.start;k<b&&x<m;++k)g[x>>2]|=e[k]<<p[x++&3];if(this.lastByteIndex=x,x>=m){for(this.start=x-m,this.block=g[P],x=0;x<P;++x)C[x]^=g[x];H(C),this.reset=!0}else this.start=x}return this},N.prototype.encode=function(e,u){var h=e&255,g=1,m=[h];for(e=e>>8,h=e&255;h>0;)m.unshift(h),e=e>>8,h=e&255,++g;return u?m.push(g):m.unshift(g),this.update(m),m.length},N.prototype.encodeString=function(e){var u=j(e);e=u[0];var h=u[1],g=0,m=e.length;if(h)for(var b=0;b<e.length;++b){var P=e.charCodeAt(b);P<128?g+=1:P<2048?g+=2:P<55296||P>=57344?g+=3:(P=65536+((P&1023)<<10|e.charCodeAt(++b)&1023),g+=4)}else g=m;return g+=this.encode(g*8),this.update(e),g},N.prototype.bytepad=function(e,u){for(var h=this.encode(u),g=0;g<e.length;++g)h+=this.encodeString(e[g]);var m=(u-h%u)%u,b=[];return b.length=m,this.update(b),this},N.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var e=this.blocks,u=this.lastByteIndex,h=this.blockCount,g=this.s;if(e[u>>2]|=this.padding[u&3],this.lastByteIndex===this.byteCount)for(e[0]=e[h],u=1;u<h+1;++u)e[u]=0;for(e[h-1]|=2147483648,u=0;u<h;++u)g[u]^=e[u];H(g)}},N.prototype.toString=N.prototype.hex=function(){this.finalize();for(var e=this.blockCount,u=this.s,h=this.outputBlocks,g=this.extraBytes,m=0,b=0,P="",k;b<h;){for(m=0;m<e&&b<h;++m,++b)k=u[m],P+=c[k>>4&15]+c[k&15]+c[k>>12&15]+c[k>>8&15]+c[k>>20&15]+c[k>>16&15]+c[k>>28&15]+c[k>>24&15];b%e===0&&(u=Gt(u),H(u),m=0)}return g&&(k=u[m],P+=c[k>>4&15]+c[k&15],g>1&&(P+=c[k>>12&15]+c[k>>8&15]),g>2&&(P+=c[k>>20&15]+c[k>>16&15])),P},N.prototype.arrayBuffer=function(){this.finalize();var e=this.blockCount,u=this.s,h=this.outputBlocks,g=this.extraBytes,m=0,b=0,P=this.outputBits>>3,k;g?k=new ArrayBuffer(h+1<<2):k=new ArrayBuffer(P);for(var C=new Uint32Array(k);b<h;){for(m=0;m<e&&b<h;++m,++b)C[b]=u[m];b%e===0&&(u=Gt(u),H(u))}return g&&(C[b]=u[m],k=k.slice(0,P)),k},N.prototype.buffer=N.prototype.arrayBuffer,N.prototype.digest=N.prototype.array=function(){this.finalize();for(var e=this.blockCount,u=this.s,h=this.outputBlocks,g=this.extraBytes,m=0,b=0,P=[],k,C;b<h;){for(m=0;m<e&&b<h;++m,++b)k=b<<2,C=u[m],P[k]=C&255,P[k+1]=C>>8&255,P[k+2]=C>>16&255,P[k+3]=C>>24&255;b%e===0&&(u=Gt(u),H(u))}return g&&(k=b<<2,C=u[m],P[k]=C&255,g>1&&(P[k+1]=C>>8&255),g>2&&(P[k+2]=C>>16&255)),P};function Qt(e,u,h){N.call(this,e,u,h)}Qt.prototype=new N,Qt.prototype.finalize=function(){return this.encode(this.outputBits,!0),N.prototype.finalize.call(this)};var H=function(e){var u,h,g,m,b,P,k,C,x,w,U,Z,G,Y,Q,X,tt,et,rt,nt,it,ot,st,lt,at,ct,ut,ft,ht,pt,dt,gt,yt,vt,mt,bt,kt,St,Pt,xt,_t,Bt,At,Et,Ft,wt,Nt,Ct,Ot,It,Tt,jt,zt,Mt,Kt,Dt,Rt,Wt,Vt,$t,Ht,Lt,Jt;for(g=0;g<48;g+=2)m=e[0]^e[10]^e[20]^e[30]^e[40],b=e[1]^e[11]^e[21]^e[31]^e[41],P=e[2]^e[12]^e[22]^e[32]^e[42],k=e[3]^e[13]^e[23]^e[33]^e[43],C=e[4]^e[14]^e[24]^e[34]^e[44],x=e[5]^e[15]^e[25]^e[35]^e[45],w=e[6]^e[16]^e[26]^e[36]^e[46],U=e[7]^e[17]^e[27]^e[37]^e[47],Z=e[8]^e[18]^e[28]^e[38]^e[48],G=e[9]^e[19]^e[29]^e[39]^e[49],u=Z^(P<<1|k>>>31),h=G^(k<<1|P>>>31),e[0]^=u,e[1]^=h,e[10]^=u,e[11]^=h,e[20]^=u,e[21]^=h,e[30]^=u,e[31]^=h,e[40]^=u,e[41]^=h,u=m^(C<<1|x>>>31),h=b^(x<<1|C>>>31),e[2]^=u,e[3]^=h,e[12]^=u,e[13]^=h,e[22]^=u,e[23]^=h,e[32]^=u,e[33]^=h,e[42]^=u,e[43]^=h,u=P^(w<<1|U>>>31),h=k^(U<<1|w>>>31),e[4]^=u,e[5]^=h,e[14]^=u,e[15]^=h,e[24]^=u,e[25]^=h,e[34]^=u,e[35]^=h,e[44]^=u,e[45]^=h,u=C^(Z<<1|G>>>31),h=x^(G<<1|Z>>>31),e[6]^=u,e[7]^=h,e[16]^=u,e[17]^=h,e[26]^=u,e[27]^=h,e[36]^=u,e[37]^=h,e[46]^=u,e[47]^=h,u=w^(m<<1|b>>>31),h=U^(b<<1|m>>>31),e[8]^=u,e[9]^=h,e[18]^=u,e[19]^=h,e[28]^=u,e[29]^=h,e[38]^=u,e[39]^=h,e[48]^=u,e[49]^=h,Y=e[0],Q=e[1],wt=e[11]<<4|e[10]>>>28,Nt=e[10]<<4|e[11]>>>28,ft=e[20]<<3|e[21]>>>29,ht=e[21]<<3|e[20]>>>29,$t=e[31]<<9|e[30]>>>23,Ht=e[30]<<9|e[31]>>>23,Bt=e[40]<<18|e[41]>>>14,At=e[41]<<18|e[40]>>>14,vt=e[2]<<1|e[3]>>>31,mt=e[3]<<1|e[2]>>>31,X=e[13]<<12|e[12]>>>20,tt=e[12]<<12|e[13]>>>20,Ct=e[22]<<10|e[23]>>>22,Ot=e[23]<<10|e[22]>>>22,pt=e[33]<<13|e[32]>>>19,dt=e[32]<<13|e[33]>>>19,Lt=e[42]<<2|e[43]>>>30,Jt=e[43]<<2|e[42]>>>30,Mt=e[5]<<30|e[4]>>>2,Kt=e[4]<<30|e[5]>>>2,bt=e[14]<<6|e[15]>>>26,kt=e[15]<<6|e[14]>>>26,et=e[25]<<11|e[24]>>>21,rt=e[24]<<11|e[25]>>>21,It=e[34]<<15|e[35]>>>17,Tt=e[35]<<15|e[34]>>>17,gt=e[45]<<29|e[44]>>>3,yt=e[44]<<29|e[45]>>>3,lt=e[6]<<28|e[7]>>>4,at=e[7]<<28|e[6]>>>4,Dt=e[17]<<23|e[16]>>>9,Rt=e[16]<<23|e[17]>>>9,St=e[26]<<25|e[27]>>>7,Pt=e[27]<<25|e[26]>>>7,nt=e[36]<<21|e[37]>>>11,it=e[37]<<21|e[36]>>>11,jt=e[47]<<24|e[46]>>>8,zt=e[46]<<24|e[47]>>>8,Et=e[8]<<27|e[9]>>>5,Ft=e[9]<<27|e[8]>>>5,ct=e[18]<<20|e[19]>>>12,ut=e[19]<<20|e[18]>>>12,Wt=e[29]<<7|e[28]>>>25,Vt=e[28]<<7|e[29]>>>25,xt=e[38]<<8|e[39]>>>24,_t=e[39]<<8|e[38]>>>24,ot=e[48]<<14|e[49]>>>18,st=e[49]<<14|e[48]>>>18,e[0]=Y^~X&et,e[1]=Q^~tt&rt,e[10]=lt^~ct&ft,e[11]=at^~ut&ht,e[20]=vt^~bt&St,e[21]=mt^~kt&Pt,e[30]=Et^~wt&Ct,e[31]=Ft^~Nt&Ot,e[40]=Mt^~Dt&Wt,e[41]=Kt^~Rt&Vt,e[2]=X^~et&nt,e[3]=tt^~rt&it,e[12]=ct^~ft&pt,e[13]=ut^~ht&dt,e[22]=bt^~St&xt,e[23]=kt^~Pt&_t,e[32]=wt^~Ct&It,e[33]=Nt^~Ot&Tt,e[42]=Dt^~Wt&$t,e[43]=Rt^~Vt&Ht,e[4]=et^~nt&ot,e[5]=rt^~it&st,e[14]=ft^~pt&gt,e[15]=ht^~dt&yt,e[24]=St^~xt&Bt,e[25]=Pt^~_t&At,e[34]=Ct^~It&jt,e[35]=Ot^~Tt&zt,e[44]=Wt^~$t&Lt,e[45]=Vt^~Ht&Jt,e[6]=nt^~ot&Y,e[7]=it^~st&Q,e[16]=pt^~gt&lt,e[17]=dt^~yt&at,e[26]=xt^~Bt&vt,e[27]=_t^~At&mt,e[36]=It^~jt&Et,e[37]=Tt^~zt&Ft,e[46]=$t^~Lt&Mt,e[47]=Ht^~Jt&Kt,e[8]=ot^~Y&X,e[9]=st^~Q&tt,e[18]=gt^~lt&ct,e[19]=yt^~at&ut,e[28]=Bt^~vt&bt,e[29]=At^~mt&kt,e[38]=jt^~Et&wt,e[39]=zt^~Ft&Nt,e[48]=Lt^~Mt&Dt,e[49]=Jt^~Kt&Rt,e[0]^=_[g],e[1]^=_[g+1]};if(a)f.exports=z;else for(M=0;M<V.length;++M)i[V[M]]=z[V[M]]})()})(te)),te.exports}var Ce=Ne();const Oe=we(Ce),{keccak256:pe}=Oe;function re(f){return new TextEncoder().encode(f)}function Ie(f){const r=f.startsWith("0x")?f.slice(2):f,t=new Uint8Array(r.length/2);for(let n=0;n<t.length;n++)t[n]=parseInt(r.substring(n*2,n*2+2),16);return t}function Te(f){let r="";for(let t=0;t<f.length;t++)r+=f[t].toString(16).padStart(2,"0");return"0x"+r}function ee(f,r,t){const n=JSON.stringify(f),i=re(n),o=pe(r+":"+t.join(".")),s=re(o),a=new Uint8Array(i.length);for(let l=0;l<i.length;l++)a[l]=i[l]^s[l%s.length];return Te(a)}function Ut(f,r,t){try{const n=Ie(f),i=pe(r+":"+t.join(".")),o=re(i),s=new Uint8Array(n.length);for(let l=0;l<n.length;l++)s[l]=n[l]^o[l%o.length];const a=new TextDecoder().decode(s);return JSON.parse(a)}catch{return null}}function je(f){if(typeof f!="string"||!f.startsWith("0x"))return!1;const r=f.slice(2);return r.length<2||r.length%2!==0?!1:/^[0-9a-fA-F]+$/.test(r)}function ze(f){const r=[];let t="",n=0,i=null;for(let s=0;s<f.length;s++){const a=f[s];if(i){t+=a,a===i&&(i=null);continue}if(a==='"'||a==="'"){i=a,t+=a;continue}if(a==="["){n++,t+=a;continue}if(a==="]"){n=Math.max(0,n-1),t+=a;continue}if(a==="."&&n===0){const l=t.trim();l&&r.push(l),t="";continue}t+=a}const o=t.trim();return o&&r.push(o),r}function Me(f,r,t){if(r.length===0){if(t.length===1&&typeof t[0]=="string"){const d=t[0].trim(),y=d.startsWith("_")||d.startsWith("~")||d.startsWith("@"),v=d.includes("."),S=/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(d);if(v||y||S){const p=ze(d);return f.readPath(p)}}if(t.length===0)return f.createProxy([]);const l=f.normalizeArgs(t),c=f.postulate([],l);return c!==void 0?c:f.createProxy([])}const n=f.normalizeArgs(t),i=f.postulate(r,n),{scope:o,leaf:s}=f.splitPath(r),a=s?f.opKind(s):null;if(f.isThought(i)){const l=a?o:r;return f.createProxy(l)}return i!==void 0?i:f.createProxy(r)}function Ke(f,r,t={}){const{path:n,expression:i}=r,o=ke(n,i);if(o)return{kind:"return",value:{define:o}};const s=Se(f,n,i);if(s)return{kind:"commit",instructions:[{path:s.scopeKey?s.scopeKey.split(".").filter(Boolean):[],op:"secret",value:i}]};const a=Pe(f,n,i);if(a)return{kind:"commit",instructions:[{path:a.scopeKey?a.scopeKey.split(".").filter(Boolean):[],op:"noise",value:i}]};const l=xe(f,n,i);if(l){const{scope:S}=I(n);return{kind:"commit",instructions:[{path:S,op:"ptr",value:ve(l.targetPath)}]}}const c=_e(f,n,i);if(c)return{kind:"commit",instructions:[{path:c.targetPath,op:"id",value:me(c.id)}]};const d=Ee(f,n,i);if(d)return{kind:"commit",instructions:[{path:d.targetPath,op:"remove",value:"-"}]};const y=Be(f,n,i);if(y){if(y.mode==="assign")return{kind:"commit",instructions:[{path:[...y.targetPath,y.name],op:"derive",value:{kind:"expr",source:y.expr}}]};if(!t.evaluateThunk)throw new Error('Non-serializable derivation: "=" thunk requires `evaluateThunk` or serializable DNA.');const S=t.evaluateThunk(y.thunk);return y.targetPath.length===0?{kind:"return",value:S}:{kind:"commit",instructions:[{path:y.targetPath,op:"derive",value:S}]}}const v=Ae(f,n,i);if(v){if(!t.readPath)return{kind:"commit",instructions:[{path:v.targetPath,op:"query",value:{paths:v.paths}}]};const S=v.paths.map(_=>t.readPath(_.split(".").filter(Boolean))),p=v.fn?v.fn(...S):S;return v.targetPath.length===0?{kind:"return",value:p}:{kind:"commit",instructions:[{path:v.targetPath,op:"query",value:p}]}}return{kind:"commit",instructions:[{path:n,op:"set",value:i}]}}const he="+";function L(f){let r=2166136261;for(let t=0;t<f.length;t++)r^=f.charCodeAt(t),r=Math.imul(r,16777619);return("00000000"+(r>>>0).toString(16)).slice(-8)}class ne{constructor(r){this.localSecrets={},this.localNoises={},this.encryptedBranches={},this.index={},this._shortTermMemory=[],this.derivations={},this.refSubscribers={},this.unsafeEval=!1,this.operators={_:{kind:"secret"},"~":{kind:"noise"},__:{kind:"pointer"},"->":{kind:"pointer"},"@":{kind:"identity"},"=":{kind:"eval"},"?":{kind:"query"},"-":{kind:"remove"}},this.localSecrets={},this.localNoises={},this.encryptedBranches={},this.index={},this.operators={_:{kind:"secret"},"~":{kind:"noise"},__:{kind:"pointer"},"->":{kind:"pointer"},"@":{kind:"identity"},"=":{kind:"eval"},"?":{kind:"query"},"-":{kind:"remove"}},this._shortTermMemory=[],r!==void 0&&this.postulate([],r),this.rebuildIndex();const t=this.createProxy([]);return Object.setPrototypeOf(t,ne.prototype),Object.assign(t,this),t}get shortTermMemory(){return this._shortTermMemory}get memory(){return this._shortTermMemory}inspect(r){const t=r?.last,n=typeof t=="number"&&Number.isFinite(t)&&t>0?this._shortTermMemory.slice(-Math.floor(t)):this._shortTermMemory.slice();return{memory:n,thoughts:n,index:{...this.index},encryptedScopes:Object.keys(this.encryptedBranches),secretScopes:Object.keys(this.localSecrets),noiseScopes:Object.keys(this.localNoises)}}explain(r){const t=this.normalizeSelectorPath(String(r??"").split(".").filter(Boolean)),n=t.join("."),i=this.readPath(t),o=this.derivations[n];if(!o)return{path:n,value:i,derivation:null,meta:{dependsOn:[]}};const s=o.refs.map(a=>{const l=this.normalizeSelectorPath(a.path.split(".").filter(Boolean)),c=this.resolveBranchScope(l),d=!!(c&&c.length>0&&qt(l,c)),y=this.readPath(l);return{label:a.label,path:a.path,value:d?"●●●●":y,origin:d?"stealth":"public",masked:d}});return{path:n,value:i,derivation:{expression:o.expression,inputs:s},meta:{dependsOn:o.refs.map(a=>a.path),lastComputedAt:o.lastComputedAt}}}cloneValue(r){const t=globalThis.structuredClone;return typeof t=="function"?t(r):JSON.parse(JSON.stringify(r))}exportSnapshot(){return this.cloneValue({memory:this._shortTermMemory,shortTermMemory:this._shortTermMemory,localSecrets:this.localSecrets,localNoises:this.localNoises,encryptedBranches:this.encryptedBranches,operators:this.operators})}importSnapshot(r){const t=this.cloneValue(r??{});this._shortTermMemory=Array.isArray(t.memory)?t.memory:Array.isArray(t.shortTermMemory)?t.shortTermMemory:[],this.localSecrets=t.localSecrets&&typeof t.localSecrets=="object"?t.localSecrets:{},this.localNoises=t.localNoises&&typeof t.localNoises=="object"?t.localNoises:{},this.encryptedBranches=t.encryptedBranches&&typeof t.encryptedBranches=="object"?t.encryptedBranches:{},this.derivations={},this.refSubscribers={};const n={_:{kind:"secret"},"~":{kind:"noise"},__:{kind:"pointer"},"->":{kind:"pointer"},"@":{kind:"identity"},"=":{kind:"eval"},"?":{kind:"query"},"-":{kind:"remove"}};this.operators=t.operators&&typeof t.operators=="object"?{...n,...t.operators}:n,this.rebuildIndex()}rehydrate(r){this.importSnapshot(r)}replayThoughts(r){this.localSecrets={},this.localNoises={},this.encryptedBranches={},this.index={},this._shortTermMemory=[],this.derivations={},this.refSubscribers={};for(const t of r||[]){const n=String(t.path||"").split(".").filter(Boolean);if(t.operator==="_"){this.postulate([...n,"_"],typeof t.expression=="string"?t.expression:"***");continue}if(t.operator==="~"){this.postulate([...n,"~"],typeof t.expression=="string"?t.expression:"***");continue}if(t.operator==="@"){const i=t.expression&&t.expression.__id||t.value&&t.value.__id||t.value;typeof i=="string"&&i.length>0&&this.postulate([...n,"@"],i);continue}if(t.operator==="__"||t.operator==="->"){const i=t.expression&&t.expression.__ptr||t.value&&t.value.__ptr||t.value;typeof i=="string"&&i.length>0&&this.postulate([...n,"__"],i);continue}if(t.operator==="-"){this.removeSubtree(n);continue}if(t.operator==="="||t.operator==="?"){this.postulate(n,t.value,t.operator);continue}this.postulate(n,t.expression,t.operator)}this.rebuildIndex()}replayMemory(r){this.replayThoughts(r)}isRemoveCall(r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);if(!i||this.opKind(i)!=="remove")return null;if(t==null)return{targetPath:n};if(typeof t=="string"){const o=t.split(".").filter(Boolean);return{targetPath:[...n,...o]}}return null}createProxy(r){const t=this,n=(...i)=>Me({createProxy:o=>t.createProxy(o),normalizeArgs:o=>t.normalizeArgs(o),readPath:o=>t.readPath(o),postulate:(o,s)=>t.postulate(o,s),opKind:o=>t.opKind(o),splitPath:I,isThought:be},r,i);return new Proxy(n,{get(i,o){if(typeof o=="symbol")return i[o];if(o in t){const a=t[o];return typeof a=="function"?a.bind(t):a}const s=[...r,String(o)];return t.createProxy(s)},apply(i,o,s){return Reflect.apply(i,void 0,s)}})}normalizeArgs(r){if(r.length!==0)return r.length===1?r[0]:r}opKind(r){return this.operators[r]?.kind??null}isSecretScopeCall(r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);return!i||this.opKind(i)!=="secret"||typeof t!="string"?null:{scopeKey:n.join(".")}}isNoiseScopeCall(r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);return!i||this.opKind(i)!=="noise"||typeof t!="string"?null:{scopeKey:n.join(".")}}isPointerCall(r,t){if(r.length===0)return null;const{leaf:n}=I(r);if(!n||this.opKind(n)!=="pointer"||typeof t!="string")return null;const i=t.trim().replace(/^\./,"");return i?{targetPath:i}:null}isIdentityCall(r,t){if(r.length===1&&this.opKind(r[0])==="identity")return typeof t!="string"?null:{id:Zt(t),targetPath:[]};const{scope:n,leaf:i}=I(r);return!i||this.opKind(i)!=="identity"||typeof t!="string"?null:{id:Zt(t),targetPath:n}}isEvalCall(r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);if(!i||this.opKind(i)!=="eval")return null;if(typeof t=="function")return{mode:"thunk",targetPath:n,thunk:t};if(Array.isArray(t)&&t.length>=2){const o=String(t[0]??"").trim(),s=String(t[1]??"").trim();return!o||!s?null:{mode:"assign",targetPath:n,name:o,expr:s}}return null}isQueryCall(r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);if(!i||this.opKind(i)!=="query")return null;let o=null,s;if(Array.isArray(t)&&t.length>0)Array.isArray(t[0])&&(t.length===1||typeof t[1]=="function")?(o=t[0],s=typeof t[1]=="function"?t[1]:void 0):o=t;else return null;if(!Array.isArray(o)||o.length===0)return null;const a=o.map(l=>String(l)).map(l=>l.trim()).filter(l=>l.length>0);return a.length===0?null:{targetPath:n,paths:a,fn:s}}isDefineOpCall(r,t){if(r.length!==1||r[0]!==he||!Array.isArray(t)||t.length<2)return null;const i=String(t[0]??"").trim(),o=String(t[1]??"").trim();return!i||!o||i===he?null:{op:i,kind:o}}getPrevThoughtHash(){return this._shortTermMemory[this._shortTermMemory.length-1]?.hash??""}extractExpressionRefs(r){const t=String(r??"").trim();if(!t)return[];const n=String.raw`[A-Za-z_][A-Za-z0-9_]*(?:\[(?:"[^"]*"|'[^']*'|[^\]]+)\])*`,i=new RegExp(String.raw`__ptr(?:\.${n})*|${n}(?:\.${n})*`,"g"),o=new Set(["true","false","null","undefined","NaN","Infinity"]),s=new Set,a=t.match(i)||[];for(const l of a)o.has(l)||s.add(l);return Array.from(s)}resolveRefPath(r,t){if(!r||r.startsWith("__ptr."))return null;const n=this.normalizeSelectorPath(r.split(".").filter(Boolean));if(n.length===0)return null;const i=this.normalizeSelectorPath([...t,...n]).join("."),o=this.normalizeSelectorPath(n).join(".");return r.includes(".")?o:i}unregisterDerivation(r){const t=this.derivations[r];if(t){for(const n of t.refs){const i=this.refSubscribers[n.path]||[];this.refSubscribers[n.path]=i.filter(o=>o!==r),this.refSubscribers[n.path].length===0&&delete this.refSubscribers[n.path]}delete this.derivations[r]}}registerDerivation(r,t,n){const i=r.join(".");this.unregisterDerivation(i);const o=this.extractExpressionRefs(n),s=[],a=new Set;for(const l of o){const c=this.resolveRefPath(l,t);if(!c||a.has(c))continue;a.add(c),s.push({label:l,path:c});const d=this.refSubscribers[c]||[];d.includes(i)||d.push(i),this.refSubscribers[c]=d}this.derivations[i]={expression:n,evalScope:[...t],refs:s,lastComputedAt:Date.now()}}recomputeTarget(r){const t=this.derivations[r];if(!t)return!1;const n=this.normalizeSelectorPath(r.split(".").filter(Boolean)),i=this.tryEvaluateAssignExpression(t.evalScope,t.expression);return this.postulate(n,i.ok?i.value:t.expression,"="),t.lastComputedAt=Date.now(),!0}invalidateFromPath(r){const t=this.normalizeSelectorPath(r).join(".");if(!t)return;const n=[t],i=new Set;for(;n.length>0;){const o=n.shift(),s=this.refSubscribers[o]||[];for(const a of s){if(i.has(a))continue;i.add(a),this.recomputeTarget(a)&&n.push(a)}}}clearDerivationsByPrefix(r){const t=r.join(".");for(const n of Object.keys(this.derivations))(t===""||n===t||n.startsWith(t+"."))&&this.unregisterDerivation(n)}commitThoughtOnly(r,t,n,i){const o=r.join("."),s=this.computeEffectiveSecret(r),a=this.getPrevThoughtHash(),l=JSON.stringify({path:o,operator:t,expression:n,value:i,effectiveSecret:s,prevHash:a}),c=L(l),d=Date.now(),y={path:o,operator:t,expression:n,value:i,effectiveSecret:s,hash:c,prevHash:a,timestamp:d};return this._shortTermMemory.push(y),this.rebuildIndex(),y}commitValueMapping(r,t,n=null){let i=t;const o=r.join("."),s=this.computeEffectiveSecret(r),a=this.resolveBranchScope(r);if(a&&a.length===0&&this.localSecrets[""]&&this.localSecrets[o],a&&a.length>0){const l=this.computeEffectiveSecret(a),c=r.slice(a.length),d=this.getBranchBlob(a);let y={};if(d&&l){const v=Ut(d,l,a);v&&typeof v=="object"&&(y=v)}if(c.length===0)(typeof y!="object"||y===null)&&(y={}),y.expression=t;else{let v=y;for(let S=0;S<c.length-1;S++){const p=c[S];(!v[p]||typeof v[p]!="object")&&(v[p]={}),v=v[p]}v[c[c.length-1]]=t}if(l){const v=ee(y,l,a);this.setBranchBlob(a,v)}i=t}else if(s){const l=n!=="="&&n!=="?";D(t)||Xt(t)||!l?i=t:i=ee(t,s,r)}else i=t;return this.commitThoughtOnly(r,n,t,i)}commitMapping(r,t=null){switch(r.op){case"set":return this.commitValueMapping(r.path,r.value,t);case"ptr":return this.commitValueMapping(r.path,r.value,"__");case"id":return this.commitValueMapping(r.path,r.value,"@");case"secret":{if(typeof r.value!="string")return;const n=r.path.join(".");return this.localSecrets[n]=r.value,this.commitThoughtOnly(r.path,"_","***","***")}default:return}}tryResolveEvalTokenValue(r,t){if(r.startsWith("__ptr.")){const s=this.getIndex(t);if(!D(s))return{ok:!1};const a=r.slice(6).split(".").filter(Boolean),l=[...s.__ptr.split(".").filter(Boolean),...a],c=this.readPath(l);return c==null?{ok:!1}:{ok:!0,value:c}}const n=r.split(".").filter(Boolean),i=[...t,...n];let o=this.readPath(i);return o==null&&(o=this.readPath(n)),o==null?{ok:!1}:{ok:!0,value:o}}tokenizeEvalExpression(r){const t=[],n=String.raw`[A-Za-z_][A-Za-z0-9_]*(?:\[(?:"[^"]*"|'[^']*'|[^\]]+)\])*`,i=new RegExp(String.raw`^(?:__ptr(?:\.${n})*|${n}(?:\.${n})*)`),o={true:!0,false:!1,null:null,undefined:void 0,NaN:NaN,Infinity:1/0},s=new Set([">=","<=","==","!=","&&","||"]),a=new Set(["+","-","*","/","%","<",">","!"]);let l=0;for(;l<r.length;){const c=r[l];if(/\s/.test(c)){l++;continue}if(c==="("){t.push({kind:"lparen"}),l++;continue}if(c===")"){t.push({kind:"rparen"}),l++;continue}const d=r.slice(l,l+2);if(s.has(d)){t.push({kind:"op",value:d}),l+=2;continue}if(a.has(c)){t.push({kind:"op",value:c}),l++;continue}if(/\d/.test(c)||c==="."&&/\d/.test(r[l+1]??"")){let v=l;for(;v<r.length&&/[0-9]/.test(r[v]);)v++;if(r[v]===".")for(v++;v<r.length&&/[0-9]/.test(r[v]);)v++;if(r[v]==="e"||r[v]==="E"){let p=v+1;(r[p]==="+"||r[p]==="-")&&p++;let _=!1;for(;p<r.length&&/[0-9]/.test(r[p]);)_=!0,p++;if(!_)return null;v=p}const S=Number(r.slice(l,v));if(!Number.isFinite(S))return null;t.push({kind:"literal",value:S}),l=v;continue}const y=r.slice(l).match(i);if(y&&y[0]){const v=y[0];Object.prototype.hasOwnProperty.call(o,v)?t.push({kind:"literal",value:o[v]}):t.push({kind:"identifier",value:v}),l+=v.length;continue}return null}return t}tryEvaluateAssignExpression(r,t){const n=String(t??"").trim();if(!n)return{ok:!1};if(!/^[A-Za-z0-9_\s+\-*/%().<>=!&|\[\]"']+$/.test(n))return{ok:!1};if(this.unsafeEval)return{ok:!1};const i=this.tokenizeEvalExpression(n);if(!i||i.length===0)return{ok:!1};const o={"u-":7,"!":7,"*":6,"/":6,"%":6,"+":5,"-":5,"<":4,"<=":4,">":4,">=":4,"==":3,"!=":3,"&&":2,"||":1},s=new Set(["u-","!"]),a=[],l=[];let c="start";for(const S of i){if(S.kind==="literal"||S.kind==="identifier"){a.push(S),c="value";continue}if(S.kind==="lparen"){l.push(S),c="lparen";continue}if(S.kind==="rparen"){let _=!1;for(;l.length>0;){const A=l.pop();if(A.kind==="lparen"){_=!0;break}a.push(A)}if(!_)return{ok:!1};c="rparen";continue}let p=S.value;if(p==="-"&&(c==="start"||c==="op"||c==="lparen"))p="u-";else{if(p==="!"&&(c==="value"||c==="rparen"))return{ok:!1};if(p!=="!"&&(c==="start"||c==="op"||c==="lparen"))return{ok:!1}}for(;l.length>0;){const _=l[l.length-1];if(_.kind!=="op")break;const A=o[_.value]??-1,B=o[p]??-1;if(B<0)return{ok:!1};if(!(s.has(p)?B<A:B<=A))break;a.push(l.pop())}l.push({kind:"op",value:p}),c="op"}if(c==="op"||c==="lparen"||c==="start")return{ok:!1};for(;l.length>0;){const S=l.pop();if(S.kind==="lparen")return{ok:!1};a.push(S)}const d=S=>{if(typeof S=="number"&&Number.isFinite(S))return S;if(typeof S=="string"){const p=Number(S);if(Number.isFinite(p))return p}return null},y=[];for(const S of a){if(S.kind==="literal"){y.push(S.value);continue}if(S.kind==="identifier"){const E=this.tryResolveEvalTokenValue(S.value,r);if(!E.ok)return{ok:!1};y.push(E.value);continue}const p=S.value;if(p==="u-"||p==="!"){if(y.length<1)return{ok:!1};const E=y.pop();if(p==="u-"){const T=d(E);if(T===null)return{ok:!1};y.push(-T)}else y.push(!E);continue}if(y.length<2)return{ok:!1};const _=y.pop(),A=y.pop();if(p==="&&"||p==="||"){y.push(p==="&&"?!!A&&!!_:!!A||!!_);continue}if(p==="=="||p==="!="){y.push(p==="=="?A==_:A!=_);continue}if(p==="<"||p==="<="||p===">"||p===">="){const E=d(A),T=d(_);if(E===null||T===null)return{ok:!1};p==="<"&&y.push(E<T),p==="<="&&y.push(E<=T),p===">"&&y.push(E>T),p===">="&&y.push(E>=T);continue}const B=d(A),F=d(_);if(B===null||F===null)return{ok:!1};let O;if(p==="+")O=B+F;else if(p==="-")O=B-F;else if(p==="*")O=B*F;else if(p==="/")O=B/F;else if(p==="%")O=B%F;else return{ok:!1};if(!Number.isFinite(O))return{ok:!1};y.push(O)}if(y.length!==1)return{ok:!1};const v=y[0];return typeof v=="number"&&Number.isFinite(v)?{ok:!0,value:v}:typeof v=="boolean"?{ok:!0,value:v}:{ok:!1}}postulate(r,t,n=null){let i=r;const o=this.isDefineOpCall(i,t);if(o){this.operators[o.op]={kind:o.kind};return}const{leaf:s}=I(i),a=s?this.opKind(s):null;if(a===null||a==="secret"||a==="pointer"||a==="identity"){const p=Ke(this.operators,{path:i,expression:t});if(p.kind==="commit"){const _=new Set(["set","secret","ptr","id"]);if(p.instructions.every(B=>_.has(B.op))){let B;const F=[];for(const O of p.instructions){const E=this.commitMapping(O,n);E&&(B=E,F.push(E.path.split(".").filter(Boolean)))}if(B){for(const O of F)this.invalidateFromPath(O);return B}}}}const c=this.isEvalCall(i,t);if(c){if(c.mode==="thunk"){const B=c.thunk();return c.targetPath.length===0?B:this.postulate(c.targetPath,B,"=")}if(this.pathContainsIterator(c.targetPath)){const B=this.collectIteratorIndices(c.targetPath);let F;for(const O of B){const E=this.normalizeSelectorPath(this.substituteIteratorInPath(c.targetPath,O)),T=this.normalizeSelectorPath([...E,c.name]),j=this.substituteIteratorInExpression(c.expr,O);this.registerDerivation(T,E,j);const W=this.tryEvaluateAssignExpression(E,j);F=this.postulate(T,W.ok?W.value:j,"=")}return F}if(this.pathContainsFilterSelector(c.targetPath)){const B=this.collectFilteredScopes(c.targetPath);let F;for(const O of B){const E=this.normalizeSelectorPath(O),T=this.normalizeSelectorPath([...E,c.name]);this.registerDerivation(T,E,c.expr);const j=this.tryEvaluateAssignExpression(E,c.expr);F=this.postulate(T,j.ok?j.value:c.expr,"=")}return F}const p=this.normalizeSelectorPath([...c.targetPath,c.name]),_=this.normalizeSelectorPath(c.targetPath);this.registerDerivation(p,_,c.expr);const A=this.tryEvaluateAssignExpression(_,c.expr);return A.ok?this.postulate(p,A.value,"="):this.postulate(p,c.expr,"=")}const d=this.isQueryCall(i,t);if(d){const p=d.paths.map(A=>this.readPath(A.split(".").filter(Boolean))),_=d.fn?d.fn(...p):p;return d.targetPath.length===0?_:this.postulate(d.targetPath,_,"?")}const y=this.isRemoveCall(i,t);if(y){this.removeSubtree(y.targetPath);return}const v=this.isNoiseScopeCall(i,t);if(v){this.localNoises[v.scopeKey]=t;const p=v.scopeKey?v.scopeKey.split(".").filter(Boolean):[];return this.commitThoughtOnly(p,"~","***","***")}const S=this.commitValueMapping(i,t,n);return this.invalidateFromPath(i),S}removeSubtree(r){this.clearDerivationsByPrefix(r);const t=r.join(".");for(const d of Object.keys(this.localSecrets)){if(t===""){delete this.localSecrets[d];continue}(d===t||d.startsWith(t+"."))&&delete this.localSecrets[d]}for(const d of Object.keys(this.localNoises)){if(t===""){delete this.localNoises[d];continue}(d===t||d.startsWith(t+"."))&&delete this.localNoises[d]}for(const d of Object.keys(this.encryptedBranches)){if(t===""){delete this.encryptedBranches[d];continue}if(d===t||d.startsWith(t+".")){delete this.encryptedBranches[d];continue}const y=d.split(".").filter(Boolean);if(!qt(r,y)||r.length<=y.length)continue;const v=this.computeEffectiveSecret(y);if(!v)continue;const S=this.getBranchBlob(y);if(!S)continue;const p=Ut(S,v,y);if(!p||typeof p!="object")continue;const _=r.slice(y.length);let A=p;for(let B=0;B<_.length-1;B++){const F=_[B];if(!A||typeof A!="object"||!(F in A)){A=null;break}A=A[F]}if(A&&typeof A=="object"){delete A[_[_.length-1]];const B=ee(p,v,y);this.setBranchBlob(y,B)}}const n=r.join("."),i=Date.now(),o=this.computeEffectiveSecret(r),s=this.getPrevThoughtHash(),a=JSON.stringify({path:n,operator:"-",expression:"-",value:"-",effectiveSecret:o,prevHash:s}),l=L(a),c={path:n,operator:"-",expression:"-",value:"-",effectiveSecret:o,hash:l,prevHash:s,timestamp:i};this._shortTermMemory.push(c),this.rebuildIndex()}computeEffectiveSecret(r){let t=null,n=null;this.localNoises[""]!==void 0&&(t="",n=this.localNoises[""]);for(let o=1;o<=r.length;o++){const s=r.slice(0,o).join(".");this.localNoises[s]!==void 0&&(t=s,n=this.localNoises[s])}let i="root";n?i=L("noise::"+n):this.localSecrets[""]&&(i=L(i+"::"+this.localSecrets[""])),t===null||t===""||t.split(".").filter(Boolean).length;for(let o=1;o<=r.length;o++){const s=r.slice(0,o).join(".");if(this.localSecrets[s]){if(t!==null&&t!==""){const a=t+".";if(!(s===t||s.startsWith(a)))continue}i=L(i+"::"+this.localSecrets[s])}}return i==="root"?"":i}rebuildIndex(){const r={},t=this._shortTermMemory.map((n,i)=>({t:n,i})).sort((n,i)=>n.t.timestamp!==i.t.timestamp?n.t.timestamp-i.t.timestamp:n.t.hash!==i.t.hash?n.t.hash<i.t.hash?-1:1:n.i-i.i).map(n=>n.t);for(const n of t){const i=n.path,o=i.split(".").filter(Boolean),s=this.resolveBranchScope(o),a=s&&s.length>0&&qt(o,s);if(n.operator==="-"){if(i===""){for(const c of Object.keys(r))delete r[c];continue}const l=i+".";for(const c of Object.keys(r))(c===i||c.startsWith(l))&&delete r[c];continue}a||(r[i]=n.value)}this.index=r}getIndex(r){return this.index[r.join(".")]}setIndex(r,t){this.index[r.join(".")]=t}resolveIndexPointerPath(r,t=8){let n=r;for(let i=0;i<t;i++){const o=this.getIndex(n);if(D(o)){n=o.__ptr.split(".").filter(Boolean);continue}let s=!1;for(let a=n.length-1;a>=0;a--){const l=n.slice(0,a),c=this.getIndex(l);if(!D(c))continue;const d=c.__ptr.split(".").filter(Boolean),y=n.slice(a);n=[...d,...y],s=!0;break}if(!s)return{path:n,raw:o}}return{path:n,raw:void 0}}setBranchBlob(r,t){const n=r.join(".");this.encryptedBranches[n]=t}getBranchBlob(r){const t=r.join(".");return this.encryptedBranches[t]}resolveBranchScope(r){let t=null;this.localSecrets[""]&&(t=[]);for(let n=1;n<=r.length;n++){const i=r.slice(0,n),o=i.join(".");this.localSecrets[o]&&(t=i)}return t}normalizeSelectorPath(r){const t=[];for(const n of r){const i=String(n).trim();if(!i)continue;const o=i.indexOf("[");if(o===-1){t.push(i);continue}const s=i.slice(0,o).trim(),a=i.slice(o);s&&t.push(s);const l=Array.from(a.matchAll(/\[([^\]]*)\]/g));if(l.map(d=>d[0]).join("")!==a){t.push(a);continue}for(const d of l){let y=(d[1]??"").trim();(y.startsWith('"')&&y.endsWith('"')||y.startsWith("'")&&y.endsWith("'"))&&(y=y.slice(1,-1)),y&&t.push(y)}}return t}pathContainsIterator(r){return r.some(t=>t.includes("[i]"))}substituteIteratorInPath(r,t){return r.map(n=>n.split("[i]").join(`[${t}]`))}substituteIteratorInExpression(r,t){return String(r??"").split("[i]").join(`[${t}]`)}collectIteratorIndices(r){const t=r.findIndex(o=>o.includes("[i]"));if(t===-1)return[];const n=[];for(let o=0;o<=t;o++){const s=r[o];if(o===t){const a=s.split("[i]").join("").trim();a&&n.push(a)}else n.push(s)}const i=new Set;for(const o of Object.keys(this.index)){const s=o.split(".").filter(Boolean);if(s.length<=n.length)continue;let a=!0;for(let l=0;l<n.length;l++)if(s[l]!==n[l]){a=!1;break}a&&i.add(s[n.length])}return Array.from(i).sort((o,s)=>{const a=Number(o),l=Number(s),c=Number.isFinite(a),d=Number.isFinite(l);return c&&d?a-l:c?-1:d?1:o.localeCompare(s)})}parseFilterExpression(r){const n=String(r??"").trim().match(/^(.+?)\s*(>=|<=|==|!=|>|<)\s*(.+)$/);if(!n)return null;const i=n[1].trim(),o=n[2],s=n[3].trim();return!i||!s?null:{left:i,op:o,right:s}}parseLogicalFilterExpression(r){const t=String(r??"").trim();if(!t)return null;const n=t.split(/\s*(&&|\|\|)\s*/).filter(s=>s.length>0);if(n.length===0)return null;const i=[],o=[];for(let s=0;s<n.length;s++)if(s%2===0){const a=this.parseFilterExpression(n[s]);if(!a)return null;i.push(a)}else{const a=n[s];if(a!=="&&"&&a!=="||")return null;o.push(a)}return i.length===0||o.length!==Math.max(0,i.length-1)?null:{clauses:i,ops:o}}compareValues(r,t,n){switch(t){case">":return r>n;case"<":return r<n;case">=":return r>=n;case"<=":return r<=n;case"==":return r==n;case"!=":return r!=n;default:return!1}}parseLiteralOrPath(r){const t=r.trim();if(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))return{kind:"literal",value:t.slice(1,-1)};if(t==="true")return{kind:"literal",value:!0};if(t==="false")return{kind:"literal",value:!1};if(t==="null")return{kind:"literal",value:null};const n=Number(t);return Number.isFinite(n)?{kind:"literal",value:n}:{kind:"path",parts:this.normalizeSelectorPath(t.split(".").filter(Boolean))}}resolveRelativeFirst(r,t){const n=this.readPath([...r,...t]);return n??this.readPath(t)}evaluateFilterClauseForScope(r,t){const n=this.normalizeSelectorPath(t.left.split(".").filter(Boolean)),i=this.resolveRelativeFirst(r,n);if(i==null)return!1;const o=this.parseLiteralOrPath(t.right),s=o.kind==="literal"?o.value:this.resolveRelativeFirst(r,o.parts);return s==null?!1:this.compareValues(i,t.op,s)}evaluateLogicalFilterForScope(r,t){const n=this.parseLogicalFilterExpression(t);if(!n)return!1;let i=this.evaluateFilterClauseForScope(r,n.clauses[0]);for(let o=1;o<n.clauses.length;o++){const s=this.evaluateFilterClauseForScope(r,n.clauses[o]);i=n.ops[o-1]==="&&"?i&&s:i||s}return i}collectChildrenForPrefix(r){const t=new Set;for(const n of Object.keys(this.index)){const i=n.split(".").filter(Boolean);if(i.length<=r.length)continue;let o=!0;for(let s=0;s<r.length;s++)if(i[s]!==r[s]){o=!1;break}o&&t.add(i[r.length])}return Array.from(t)}parseSelectorSegment(r){const t=String(r??"").trim(),n=t.indexOf("["),i=t.lastIndexOf("]");if(n<=0||i<=n||i!==t.length-1)return null;const o=t.slice(0,n).trim(),s=t.slice(n+1,i).trim();return!o||!s?null:{base:o,selector:s}}parseSelectorKeys(r){const t=r.trim();if(t.startsWith("[")&&t.endsWith("]")){const i=t.slice(1,-1).trim();return i?i.split(",").map(s=>s.trim()).filter(Boolean).map(s=>s.startsWith('"')&&s.endsWith('"')||s.startsWith("'")&&s.endsWith("'")?s.slice(1,-1):s):[]}const n=t.match(/^(-?\d+)\s*\.\.\s*(-?\d+)$/);if(n){const i=Number(n[1]),o=Number(n[2]);if(!Number.isFinite(i)||!Number.isFinite(o))return null;const s=i<=o?1:-1,a=[];if(Math.abs(o-i)>1e4)return null;for(let c=i;s>0?c<=o:c>=o;c+=s)a.push(String(c));return a}return null}parseTransformSelector(r){const n=r.trim().match(/^([A-Za-z_][A-Za-z0-9_]*)\s*=>\s*(.+)$/);if(!n)return null;const i=n[1].trim(),o=n[2].trim();return!i||!o?null:{varName:i,expr:o}}evaluateTransformPath(r){const t=r.findIndex(c=>{const d=this.parseSelectorSegment(c);return d?this.parseTransformSelector(d.selector)!==null:!1});if(t===-1)return;const n=this.parseSelectorSegment(r[t]);if(!n)return;const i=this.parseTransformSelector(n.selector);if(!i)return;const o=[...r.slice(0,t),n.base];if(r.slice(t+1).length>0)return;const a=this.collectChildrenForPrefix(o),l={};for(const c of a){const d=[...o,c],y=i.expr.replace(new RegExp(String.raw`\b${i.varName}\.`,"g"),""),v=this.tryEvaluateAssignExpression(d,y);v.ok&&(l[c]=v.value)}return l}evaluateSelectionPath(r){const t=r.findIndex(l=>this.parseSelectorSegment(l)!==null);if(t===-1)return;const n=this.parseSelectorSegment(r[t]);if(!n)return;const i=this.parseSelectorKeys(n.selector);if(i===null)return;const o=[...r.slice(0,t),n.base],s=r.slice(t+1),a={};for(const l of i){const c=[...o,l],d=s.length===0?this.buildPublicSubtree(c):this.readPath([...c,...s]);d!==void 0&&(a[l]=d)}return a}buildPublicSubtree(r){const t=r.join("."),n={};let i=!1;for(const[o,s]of Object.entries(this.index)){if(o===t)return s;if(!o.startsWith(t+"."))continue;const a=o.slice(t.length+1).split(".").filter(Boolean);let l=n;for(let c=0;c<a.length-1;c++){const d=a[c];(!l[d]||typeof l[d]!="object")&&(l[d]={}),l=l[d]}l[a[a.length-1]]=s,i=!0}return i?n:void 0}evaluateFilterPath(r){const t=r.findIndex(l=>this.parseLogicalFilterExpression(l)!==null);if(t===-1)return;const n=r[t],i=r.slice(0,t),o=r.slice(t+1);if(i.length===0)return;const s=this.collectChildrenForPrefix(i),a={};for(const l of s){const c=[...i,l];this.evaluateLogicalFilterForScope(c,n)&&(o.length===0?a[l]=this.buildPublicSubtree(c):a[l]=this.readPath([...c,...o]))}return a}pathContainsFilterSelector(r){return r.some(t=>{const n=this.parseSelectorSegment(t);return n?this.parseLogicalFilterExpression(n.selector)!==null:!1})}collectFilteredScopes(r){const t=r.findIndex(l=>{const c=this.parseSelectorSegment(l);return c?this.parseLogicalFilterExpression(c.selector)!==null:!1});if(t===-1)return[];const n=this.parseSelectorSegment(r[t]);if(!n)return[];const i=[...r.slice(0,t),n.base],o=r.slice(t+1),s=this.collectChildrenForPrefix(i),a=[];for(const l of s){const c=[...i,l];this.evaluateLogicalFilterForScope(c,n.selector)&&a.push([...c,...o])}return a}readPath(r){const t=this.evaluateTransformPath(r);if(t!==void 0)return t;const n=this.evaluateSelectionPath(r);if(n!==void 0)return n;r=this.normalizeSelectorPath(r);const i=this.evaluateFilterPath(r);if(i!==void 0)return i;const o=this.resolveBranchScope(r);if(o&&o.length>0&&qt(r,o)){if(r.length===o.length)return;const d=this.computeEffectiveSecret(o);if(!d)return null;const y=this.getBranchBlob(o);if(!y)return;const v=Ut(y,d,o);if(!v||typeof v!="object")return;const S=r.slice(o.length);let p=v;for(const _ of S){if(!p||typeof p!="object")return;p=p[_]}return D(p)?this.readPath(p.__ptr.split(".").filter(Boolean)):(Xt(p),p)}const s=this.getIndex(r);if(D(s))return s;const a=this.resolveIndexPointerPath(r),l=a.raw;if(l===void 0)return a.path.length===r.length&&a.path.every((y,v)=>y===r[v])?void 0:this.readPath(a.path);if(D(l))return this.readPath(l.__ptr.split(".").filter(Boolean));if(Xt(l)||!je(l))return l;const c=this.computeEffectiveSecret(r);return c?Ut(l,c,r):null}}module.exports=ne;
package/dist/me.es.js CHANGED
@@ -1,4 +1,4 @@
1
- function ye(f) {
1
+ function ve(f) {
2
2
  return { __ptr: f };
3
3
  }
4
4
  function D(f) {
@@ -115,7 +115,7 @@ function Ne() {
115
115
  i.JS_SHA3_NO_WINDOW && (n = !1);
116
116
  var o = !n && typeof self == "object", s = !i.JS_SHA3_NO_NODE_JS && typeof process == "object" && process.versions && process.versions.node;
117
117
  s ? i = Fe : o && (i = self);
118
- for (var a = !i.JS_SHA3_NO_COMMON_JS && !0 && f.exports, l = !i.JS_SHA3_NO_ARRAY_BUFFER && typeof ArrayBuffer < "u", c = "0123456789abcdef".split(""), d = [31, 7936, 2031616, 520093696], v = [4, 1024, 262144, 67108864], y = [1, 256, 65536, 16777216], S = [6, 1536, 393216, 100663296], p = [0, 8, 16, 24], _ = [
118
+ for (var a = !i.JS_SHA3_NO_COMMON_JS && !0 && f.exports, l = !i.JS_SHA3_NO_ARRAY_BUFFER && typeof ArrayBuffer < "u", c = "0123456789abcdef".split(""), d = [31, 7936, 2031616, 520093696], y = [4, 1024, 262144, 67108864], v = [1, 256, 65536, 16777216], S = [6, 1536, 393216, 100663296], p = [0, 8, 16, 24], _ = [
119
119
  1,
120
120
  0,
121
121
  32898,
@@ -169,9 +169,9 @@ function Ne() {
169
169
  256: 136
170
170
  }, E = i.JS_SHA3_NO_NODE_JS || !Array.isArray ? function(e) {
171
171
  return Object.prototype.toString.call(e) === "[object Array]";
172
- } : Array.isArray, j = l && (i.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView) ? function(e) {
172
+ } : Array.isArray, T = l && (i.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView) ? function(e) {
173
173
  return typeof e == "object" && e.buffer && e.buffer.constructor === ArrayBuffer;
174
- } : ArrayBuffer.isView, T = function(e) {
174
+ } : ArrayBuffer.isView, j = function(e) {
175
175
  var u = typeof e;
176
176
  if (u === "string")
177
177
  return [e, !0];
@@ -179,11 +179,11 @@ function Ne() {
179
179
  throw new Error(r);
180
180
  if (l && e.constructor === ArrayBuffer)
181
181
  return [new Uint8Array(e), !1];
182
- if (!E(e) && !j(e))
182
+ if (!E(e) && !T(e))
183
183
  throw new Error(r);
184
184
  return [e, !1];
185
185
  }, W = function(e) {
186
- return T(e)[0].length === 0;
186
+ return j(e)[0].length === 0;
187
187
  }, Gt = function(e) {
188
188
  for (var u = [], h = 0; h < e.length; ++h)
189
189
  u[h] = e[h];
@@ -231,7 +231,7 @@ function Ne() {
231
231
  }, g.update = function(m, b, P, k) {
232
232
  return g.create(b, P, k).update(m);
233
233
  }, J(g, oe, e, u);
234
- }, ve = function(e, u) {
234
+ }, ye = function(e, u) {
235
235
  var h = O[e], g = se(e, u, "hex");
236
236
  return g.create = function(m, b, P) {
237
237
  return new Qt(e, u, b).bytepad(["KMAC", P], h).bytepad([m], h);
@@ -239,11 +239,11 @@ function Ne() {
239
239
  return g.create(m, P, k).update(b);
240
240
  }, J(g, se, e, u);
241
241
  }, ae = [
242
- { name: "keccak", padding: y, bits: A, createMethod: le },
242
+ { name: "keccak", padding: v, bits: A, createMethod: le },
243
243
  { name: "sha3", padding: S, bits: A, createMethod: le },
244
244
  { name: "shake", padding: d, bits: B, createMethod: de },
245
- { name: "cshake", padding: v, bits: B, createMethod: ge },
246
- { name: "kmac", padding: v, bits: B, createMethod: ve }
245
+ { name: "cshake", padding: y, bits: B, createMethod: ge },
246
+ { name: "kmac", padding: y, bits: B, createMethod: ye }
247
247
  ], z = {}, V = [], M = 0; M < ae.length; ++M)
248
248
  for (var R = ae[M], q = R.bits, $ = 0; $ < q.length; ++$) {
249
249
  var Yt = R.name + "_" + q[$];
@@ -260,7 +260,7 @@ function Ne() {
260
260
  N.prototype.update = function(e) {
261
261
  if (this.finalized)
262
262
  throw new Error(t);
263
- var u = T(e);
263
+ var u = j(e);
264
264
  e = u[0];
265
265
  for (var h = u[1], g = this.blocks, m = this.byteCount, b = e.length, P = this.blockCount, k = 0, C = this.s, x, w; k < b; ) {
266
266
  if (this.reset)
@@ -286,7 +286,7 @@ function Ne() {
286
286
  m.unshift(h), e = e >> 8, h = e & 255, ++g;
287
287
  return u ? m.push(g) : m.unshift(g), this.update(m), m.length;
288
288
  }, N.prototype.encodeString = function(e) {
289
- var u = T(e);
289
+ var u = j(e);
290
290
  e = u[0];
291
291
  var h = u[1], g = 0, m = e.length;
292
292
  if (h)
@@ -347,9 +347,9 @@ function Ne() {
347
347
  return this.encode(this.outputBits, !0), N.prototype.finalize.call(this);
348
348
  };
349
349
  var H = function(e) {
350
- var u, h, g, m, b, P, k, C, x, w, U, Z, G, Y, Q, X, tt, et, rt, nt, it, ot, st, lt, at, ct, ut, ft, ht, pt, dt, gt, vt, yt, mt, bt, kt, St, Pt, xt, _t, Bt, At, Et, Ft, wt, Nt, Ct, Ot, It, jt, Tt, zt, Mt, Kt, Dt, Rt, Wt, Vt, $t, Ht, Lt, Jt;
350
+ var u, h, g, m, b, P, k, C, x, w, U, Z, G, Y, Q, X, tt, et, rt, nt, it, ot, st, lt, at, ct, ut, ft, ht, pt, dt, gt, yt, vt, mt, bt, kt, St, Pt, xt, _t, Bt, At, Et, Ft, wt, Nt, Ct, Ot, It, Tt, jt, zt, Mt, Kt, Dt, Rt, Wt, Vt, $t, Ht, Lt, Jt;
351
351
  for (g = 0; g < 48; g += 2)
352
- m = e[0] ^ e[10] ^ e[20] ^ e[30] ^ e[40], b = e[1] ^ e[11] ^ e[21] ^ e[31] ^ e[41], P = e[2] ^ e[12] ^ e[22] ^ e[32] ^ e[42], k = e[3] ^ e[13] ^ e[23] ^ e[33] ^ e[43], C = e[4] ^ e[14] ^ e[24] ^ e[34] ^ e[44], x = e[5] ^ e[15] ^ e[25] ^ e[35] ^ e[45], w = e[6] ^ e[16] ^ e[26] ^ e[36] ^ e[46], U = e[7] ^ e[17] ^ e[27] ^ e[37] ^ e[47], Z = e[8] ^ e[18] ^ e[28] ^ e[38] ^ e[48], G = e[9] ^ e[19] ^ e[29] ^ e[39] ^ e[49], u = Z ^ (P << 1 | k >>> 31), h = G ^ (k << 1 | P >>> 31), e[0] ^= u, e[1] ^= h, e[10] ^= u, e[11] ^= h, e[20] ^= u, e[21] ^= h, e[30] ^= u, e[31] ^= h, e[40] ^= u, e[41] ^= h, u = m ^ (C << 1 | x >>> 31), h = b ^ (x << 1 | C >>> 31), e[2] ^= u, e[3] ^= h, e[12] ^= u, e[13] ^= h, e[22] ^= u, e[23] ^= h, e[32] ^= u, e[33] ^= h, e[42] ^= u, e[43] ^= h, u = P ^ (w << 1 | U >>> 31), h = k ^ (U << 1 | w >>> 31), e[4] ^= u, e[5] ^= h, e[14] ^= u, e[15] ^= h, e[24] ^= u, e[25] ^= h, e[34] ^= u, e[35] ^= h, e[44] ^= u, e[45] ^= h, u = C ^ (Z << 1 | G >>> 31), h = x ^ (G << 1 | Z >>> 31), e[6] ^= u, e[7] ^= h, e[16] ^= u, e[17] ^= h, e[26] ^= u, e[27] ^= h, e[36] ^= u, e[37] ^= h, e[46] ^= u, e[47] ^= h, u = w ^ (m << 1 | b >>> 31), h = U ^ (b << 1 | m >>> 31), e[8] ^= u, e[9] ^= h, e[18] ^= u, e[19] ^= h, e[28] ^= u, e[29] ^= h, e[38] ^= u, e[39] ^= h, e[48] ^= u, e[49] ^= h, Y = e[0], Q = e[1], wt = e[11] << 4 | e[10] >>> 28, Nt = e[10] << 4 | e[11] >>> 28, ft = e[20] << 3 | e[21] >>> 29, ht = e[21] << 3 | e[20] >>> 29, $t = e[31] << 9 | e[30] >>> 23, Ht = e[30] << 9 | e[31] >>> 23, Bt = e[40] << 18 | e[41] >>> 14, At = e[41] << 18 | e[40] >>> 14, yt = e[2] << 1 | e[3] >>> 31, mt = e[3] << 1 | e[2] >>> 31, X = e[13] << 12 | e[12] >>> 20, tt = e[12] << 12 | e[13] >>> 20, Ct = e[22] << 10 | e[23] >>> 22, Ot = e[23] << 10 | e[22] >>> 22, pt = e[33] << 13 | e[32] >>> 19, dt = e[32] << 13 | e[33] >>> 19, Lt = e[42] << 2 | e[43] >>> 30, Jt = e[43] << 2 | e[42] >>> 30, Mt = e[5] << 30 | e[4] >>> 2, Kt = e[4] << 30 | e[5] >>> 2, bt = e[14] << 6 | e[15] >>> 26, kt = e[15] << 6 | e[14] >>> 26, et = e[25] << 11 | e[24] >>> 21, rt = e[24] << 11 | e[25] >>> 21, It = e[34] << 15 | e[35] >>> 17, jt = e[35] << 15 | e[34] >>> 17, gt = e[45] << 29 | e[44] >>> 3, vt = e[44] << 29 | e[45] >>> 3, lt = e[6] << 28 | e[7] >>> 4, at = e[7] << 28 | e[6] >>> 4, Dt = e[17] << 23 | e[16] >>> 9, Rt = e[16] << 23 | e[17] >>> 9, St = e[26] << 25 | e[27] >>> 7, Pt = e[27] << 25 | e[26] >>> 7, nt = e[36] << 21 | e[37] >>> 11, it = e[37] << 21 | e[36] >>> 11, Tt = e[47] << 24 | e[46] >>> 8, zt = e[46] << 24 | e[47] >>> 8, Et = e[8] << 27 | e[9] >>> 5, Ft = e[9] << 27 | e[8] >>> 5, ct = e[18] << 20 | e[19] >>> 12, ut = e[19] << 20 | e[18] >>> 12, Wt = e[29] << 7 | e[28] >>> 25, Vt = e[28] << 7 | e[29] >>> 25, xt = e[38] << 8 | e[39] >>> 24, _t = e[39] << 8 | e[38] >>> 24, ot = e[48] << 14 | e[49] >>> 18, st = e[49] << 14 | e[48] >>> 18, e[0] = Y ^ ~X & et, e[1] = Q ^ ~tt & rt, e[10] = lt ^ ~ct & ft, e[11] = at ^ ~ut & ht, e[20] = yt ^ ~bt & St, e[21] = mt ^ ~kt & Pt, e[30] = Et ^ ~wt & Ct, e[31] = Ft ^ ~Nt & Ot, e[40] = Mt ^ ~Dt & Wt, e[41] = Kt ^ ~Rt & Vt, e[2] = X ^ ~et & nt, e[3] = tt ^ ~rt & it, e[12] = ct ^ ~ft & pt, e[13] = ut ^ ~ht & dt, e[22] = bt ^ ~St & xt, e[23] = kt ^ ~Pt & _t, e[32] = wt ^ ~Ct & It, e[33] = Nt ^ ~Ot & jt, e[42] = Dt ^ ~Wt & $t, e[43] = Rt ^ ~Vt & Ht, e[4] = et ^ ~nt & ot, e[5] = rt ^ ~it & st, e[14] = ft ^ ~pt & gt, e[15] = ht ^ ~dt & vt, e[24] = St ^ ~xt & Bt, e[25] = Pt ^ ~_t & At, e[34] = Ct ^ ~It & Tt, e[35] = Ot ^ ~jt & zt, e[44] = Wt ^ ~$t & Lt, e[45] = Vt ^ ~Ht & Jt, e[6] = nt ^ ~ot & Y, e[7] = it ^ ~st & Q, e[16] = pt ^ ~gt & lt, e[17] = dt ^ ~vt & at, e[26] = xt ^ ~Bt & yt, e[27] = _t ^ ~At & mt, e[36] = It ^ ~Tt & Et, e[37] = jt ^ ~zt & Ft, e[46] = $t ^ ~Lt & Mt, e[47] = Ht ^ ~Jt & Kt, e[8] = ot ^ ~Y & X, e[9] = st ^ ~Q & tt, e[18] = gt ^ ~lt & ct, e[19] = vt ^ ~at & ut, e[28] = Bt ^ ~yt & bt, e[29] = At ^ ~mt & kt, e[38] = Tt ^ ~Et & wt, e[39] = zt ^ ~Ft & Nt, e[48] = Lt ^ ~Mt & Dt, e[49] = Jt ^ ~Kt & Rt, e[0] ^= _[g], e[1] ^= _[g + 1];
352
+ m = e[0] ^ e[10] ^ e[20] ^ e[30] ^ e[40], b = e[1] ^ e[11] ^ e[21] ^ e[31] ^ e[41], P = e[2] ^ e[12] ^ e[22] ^ e[32] ^ e[42], k = e[3] ^ e[13] ^ e[23] ^ e[33] ^ e[43], C = e[4] ^ e[14] ^ e[24] ^ e[34] ^ e[44], x = e[5] ^ e[15] ^ e[25] ^ e[35] ^ e[45], w = e[6] ^ e[16] ^ e[26] ^ e[36] ^ e[46], U = e[7] ^ e[17] ^ e[27] ^ e[37] ^ e[47], Z = e[8] ^ e[18] ^ e[28] ^ e[38] ^ e[48], G = e[9] ^ e[19] ^ e[29] ^ e[39] ^ e[49], u = Z ^ (P << 1 | k >>> 31), h = G ^ (k << 1 | P >>> 31), e[0] ^= u, e[1] ^= h, e[10] ^= u, e[11] ^= h, e[20] ^= u, e[21] ^= h, e[30] ^= u, e[31] ^= h, e[40] ^= u, e[41] ^= h, u = m ^ (C << 1 | x >>> 31), h = b ^ (x << 1 | C >>> 31), e[2] ^= u, e[3] ^= h, e[12] ^= u, e[13] ^= h, e[22] ^= u, e[23] ^= h, e[32] ^= u, e[33] ^= h, e[42] ^= u, e[43] ^= h, u = P ^ (w << 1 | U >>> 31), h = k ^ (U << 1 | w >>> 31), e[4] ^= u, e[5] ^= h, e[14] ^= u, e[15] ^= h, e[24] ^= u, e[25] ^= h, e[34] ^= u, e[35] ^= h, e[44] ^= u, e[45] ^= h, u = C ^ (Z << 1 | G >>> 31), h = x ^ (G << 1 | Z >>> 31), e[6] ^= u, e[7] ^= h, e[16] ^= u, e[17] ^= h, e[26] ^= u, e[27] ^= h, e[36] ^= u, e[37] ^= h, e[46] ^= u, e[47] ^= h, u = w ^ (m << 1 | b >>> 31), h = U ^ (b << 1 | m >>> 31), e[8] ^= u, e[9] ^= h, e[18] ^= u, e[19] ^= h, e[28] ^= u, e[29] ^= h, e[38] ^= u, e[39] ^= h, e[48] ^= u, e[49] ^= h, Y = e[0], Q = e[1], wt = e[11] << 4 | e[10] >>> 28, Nt = e[10] << 4 | e[11] >>> 28, ft = e[20] << 3 | e[21] >>> 29, ht = e[21] << 3 | e[20] >>> 29, $t = e[31] << 9 | e[30] >>> 23, Ht = e[30] << 9 | e[31] >>> 23, Bt = e[40] << 18 | e[41] >>> 14, At = e[41] << 18 | e[40] >>> 14, vt = e[2] << 1 | e[3] >>> 31, mt = e[3] << 1 | e[2] >>> 31, X = e[13] << 12 | e[12] >>> 20, tt = e[12] << 12 | e[13] >>> 20, Ct = e[22] << 10 | e[23] >>> 22, Ot = e[23] << 10 | e[22] >>> 22, pt = e[33] << 13 | e[32] >>> 19, dt = e[32] << 13 | e[33] >>> 19, Lt = e[42] << 2 | e[43] >>> 30, Jt = e[43] << 2 | e[42] >>> 30, Mt = e[5] << 30 | e[4] >>> 2, Kt = e[4] << 30 | e[5] >>> 2, bt = e[14] << 6 | e[15] >>> 26, kt = e[15] << 6 | e[14] >>> 26, et = e[25] << 11 | e[24] >>> 21, rt = e[24] << 11 | e[25] >>> 21, It = e[34] << 15 | e[35] >>> 17, Tt = e[35] << 15 | e[34] >>> 17, gt = e[45] << 29 | e[44] >>> 3, yt = e[44] << 29 | e[45] >>> 3, lt = e[6] << 28 | e[7] >>> 4, at = e[7] << 28 | e[6] >>> 4, Dt = e[17] << 23 | e[16] >>> 9, Rt = e[16] << 23 | e[17] >>> 9, St = e[26] << 25 | e[27] >>> 7, Pt = e[27] << 25 | e[26] >>> 7, nt = e[36] << 21 | e[37] >>> 11, it = e[37] << 21 | e[36] >>> 11, jt = e[47] << 24 | e[46] >>> 8, zt = e[46] << 24 | e[47] >>> 8, Et = e[8] << 27 | e[9] >>> 5, Ft = e[9] << 27 | e[8] >>> 5, ct = e[18] << 20 | e[19] >>> 12, ut = e[19] << 20 | e[18] >>> 12, Wt = e[29] << 7 | e[28] >>> 25, Vt = e[28] << 7 | e[29] >>> 25, xt = e[38] << 8 | e[39] >>> 24, _t = e[39] << 8 | e[38] >>> 24, ot = e[48] << 14 | e[49] >>> 18, st = e[49] << 14 | e[48] >>> 18, e[0] = Y ^ ~X & et, e[1] = Q ^ ~tt & rt, e[10] = lt ^ ~ct & ft, e[11] = at ^ ~ut & ht, e[20] = vt ^ ~bt & St, e[21] = mt ^ ~kt & Pt, e[30] = Et ^ ~wt & Ct, e[31] = Ft ^ ~Nt & Ot, e[40] = Mt ^ ~Dt & Wt, e[41] = Kt ^ ~Rt & Vt, e[2] = X ^ ~et & nt, e[3] = tt ^ ~rt & it, e[12] = ct ^ ~ft & pt, e[13] = ut ^ ~ht & dt, e[22] = bt ^ ~St & xt, e[23] = kt ^ ~Pt & _t, e[32] = wt ^ ~Ct & It, e[33] = Nt ^ ~Ot & Tt, e[42] = Dt ^ ~Wt & $t, e[43] = Rt ^ ~Vt & Ht, e[4] = et ^ ~nt & ot, e[5] = rt ^ ~it & st, e[14] = ft ^ ~pt & gt, e[15] = ht ^ ~dt & yt, e[24] = St ^ ~xt & Bt, e[25] = Pt ^ ~_t & At, e[34] = Ct ^ ~It & jt, e[35] = Ot ^ ~Tt & zt, e[44] = Wt ^ ~$t & Lt, e[45] = Vt ^ ~Ht & Jt, e[6] = nt ^ ~ot & Y, e[7] = it ^ ~st & Q, e[16] = pt ^ ~gt & lt, e[17] = dt ^ ~yt & at, e[26] = xt ^ ~Bt & vt, e[27] = _t ^ ~At & mt, e[36] = It ^ ~jt & Et, e[37] = Tt ^ ~zt & Ft, e[46] = $t ^ ~Lt & Mt, e[47] = Ht ^ ~Jt & Kt, e[8] = ot ^ ~Y & X, e[9] = st ^ ~Q & tt, e[18] = gt ^ ~lt & ct, e[19] = yt ^ ~at & ut, e[28] = Bt ^ ~vt & bt, e[29] = At ^ ~mt & kt, e[38] = jt ^ ~Et & wt, e[39] = zt ^ ~Ft & Nt, e[48] = Lt ^ ~Mt & Dt, e[49] = Jt ^ ~Kt & Rt, e[0] ^= _[g], e[1] ^= _[g + 1];
353
353
  };
354
354
  if (a)
355
355
  f.exports = z;
@@ -370,7 +370,7 @@ function Ie(f) {
370
370
  t[n] = parseInt(r.substring(n * 2, n * 2 + 2), 16);
371
371
  return t;
372
372
  }
373
- function je(f) {
373
+ function Te(f) {
374
374
  let r = "";
375
375
  for (let t = 0; t < f.length; t++)
376
376
  r += f[t].toString(16).padStart(2, "0");
@@ -380,7 +380,7 @@ function ee(f, r, t) {
380
380
  const n = JSON.stringify(f), i = re(n), o = he(r + ":" + t.join(".")), s = re(o), a = new Uint8Array(i.length);
381
381
  for (let l = 0; l < i.length; l++)
382
382
  a[l] = i[l] ^ s[l % s.length];
383
- return je(a);
383
+ return Te(a);
384
384
  }
385
385
  function Ut(f, r, t) {
386
386
  try {
@@ -393,7 +393,7 @@ function Ut(f, r, t) {
393
393
  return null;
394
394
  }
395
395
  }
396
- function Te(f) {
396
+ function je(f) {
397
397
  if (typeof f != "string" || !f.startsWith("0x")) return !1;
398
398
  const r = f.slice(2);
399
399
  return r.length < 2 || r.length % 2 !== 0 ? !1 : /^[0-9a-fA-F]+$/.test(r);
@@ -432,8 +432,8 @@ function ze(f) {
432
432
  function Me(f, r, t) {
433
433
  if (r.length === 0) {
434
434
  if (t.length === 1 && typeof t[0] == "string") {
435
- const d = t[0].trim(), v = d.startsWith("_") || d.startsWith("~") || d.startsWith("@"), y = d.includes("."), S = /^[a-zA-Z][a-zA-Z0-9_-]*$/.test(d);
436
- if (y || v || S) {
435
+ const d = t[0].trim(), y = d.startsWith("_") || d.startsWith("~") || d.startsWith("@"), v = d.includes("."), S = /^[a-zA-Z][a-zA-Z0-9_-]*$/.test(d);
436
+ if (v || y || S) {
437
437
  const p = ze(d);
438
438
  return f.readPath(p);
439
439
  }
@@ -476,7 +476,7 @@ function Ke(f, r, t = {}) {
476
476
  const { scope: S } = I(n);
477
477
  return {
478
478
  kind: "commit",
479
- instructions: [{ path: S, op: "ptr", value: ye(l.targetPath) }]
479
+ instructions: [{ path: S, op: "ptr", value: ve(l.targetPath) }]
480
480
  };
481
481
  }
482
482
  const c = _e(f, n, i);
@@ -491,47 +491,47 @@ function Ke(f, r, t = {}) {
491
491
  kind: "commit",
492
492
  instructions: [{ path: d.targetPath, op: "remove", value: "-" }]
493
493
  };
494
- const v = Be(f, n, i);
495
- if (v) {
496
- if (v.mode === "assign")
494
+ const y = Be(f, n, i);
495
+ if (y) {
496
+ if (y.mode === "assign")
497
497
  return {
498
498
  kind: "commit",
499
499
  instructions: [
500
500
  {
501
- path: [...v.targetPath, v.name],
501
+ path: [...y.targetPath, y.name],
502
502
  op: "derive",
503
503
  value: {
504
504
  kind: "expr",
505
- source: v.expr
505
+ source: y.expr
506
506
  }
507
507
  }
508
508
  ]
509
509
  };
510
510
  if (!t.evaluateThunk)
511
511
  throw new Error('Non-serializable derivation: "=" thunk requires `evaluateThunk` or serializable DNA.');
512
- const S = t.evaluateThunk(v.thunk);
513
- return v.targetPath.length === 0 ? { kind: "return", value: S } : {
512
+ const S = t.evaluateThunk(y.thunk);
513
+ return y.targetPath.length === 0 ? { kind: "return", value: S } : {
514
514
  kind: "commit",
515
- instructions: [{ path: v.targetPath, op: "derive", value: S }]
515
+ instructions: [{ path: y.targetPath, op: "derive", value: S }]
516
516
  };
517
517
  }
518
- const y = Ae(f, n, i);
519
- if (y) {
518
+ const v = Ae(f, n, i);
519
+ if (v) {
520
520
  if (!t.readPath)
521
521
  return {
522
522
  kind: "commit",
523
523
  instructions: [
524
524
  {
525
- path: y.targetPath,
525
+ path: v.targetPath,
526
526
  op: "query",
527
- value: { paths: y.paths }
527
+ value: { paths: v.paths }
528
528
  }
529
529
  ]
530
530
  };
531
- const S = y.paths.map((_) => t.readPath(_.split(".").filter(Boolean))), p = y.fn ? y.fn(...S) : S;
532
- return y.targetPath.length === 0 ? { kind: "return", value: p } : {
531
+ const S = v.paths.map((_) => t.readPath(_.split(".").filter(Boolean))), p = v.fn ? v.fn(...S) : S;
532
+ return v.targetPath.length === 0 ? { kind: "return", value: p } : {
533
533
  kind: "commit",
534
- instructions: [{ path: y.targetPath, op: "query", value: p }]
534
+ instructions: [{ path: v.targetPath, op: "query", value: p }]
535
535
  };
536
536
  }
537
537
  return {
@@ -577,15 +577,22 @@ class pe {
577
577
  const t = this.createProxy([]);
578
578
  return Object.setPrototypeOf(t, pe.prototype), Object.assign(t, this), t;
579
579
  }
580
- // Legacy compatibility accessor. Prefer `inspect()` for debug tooling.
580
+ /**
581
+ * @deprecated Use `memory` or `inspect().memory`.
582
+ */
581
583
  get shortTermMemory() {
582
584
  return this._shortTermMemory;
583
585
  }
586
+ // Preferred memory accessor (alias of legacy shortTermMemory).
587
+ get memory() {
588
+ return this._shortTermMemory;
589
+ }
584
590
  // Explicit debug API (kept outside DSL semantics).
585
591
  inspect(r) {
586
- const t = r?.last;
592
+ const t = r?.last, n = typeof t == "number" && Number.isFinite(t) && t > 0 ? this._shortTermMemory.slice(-Math.floor(t)) : this._shortTermMemory.slice();
587
593
  return {
588
- thoughts: typeof t == "number" && Number.isFinite(t) && t > 0 ? this._shortTermMemory.slice(-Math.floor(t)) : this._shortTermMemory.slice(),
594
+ memory: n,
595
+ thoughts: n,
589
596
  index: { ...this.index },
590
597
  encryptedScopes: Object.keys(this.encryptedBranches),
591
598
  secretScopes: Object.keys(this.localSecrets),
@@ -602,11 +609,11 @@ class pe {
602
609
  meta: { dependsOn: [] }
603
610
  };
604
611
  const s = o.refs.map((a) => {
605
- const l = this.normalizeSelectorPath(a.path.split(".").filter(Boolean)), c = this.resolveBranchScope(l), d = !!(c && c.length > 0 && qt(l, c)), v = this.readPath(l);
612
+ const l = this.normalizeSelectorPath(a.path.split(".").filter(Boolean)), c = this.resolveBranchScope(l), d = !!(c && c.length > 0 && qt(l, c)), y = this.readPath(l);
606
613
  return {
607
614
  label: a.label,
608
615
  path: a.path,
609
- value: d ? "●●●●" : v,
616
+ value: d ? "●●●●" : y,
610
617
  origin: d ? "stealth" : "public",
611
618
  masked: d
612
619
  };
@@ -630,6 +637,7 @@ class pe {
630
637
  }
631
638
  exportSnapshot() {
632
639
  return this.cloneValue({
640
+ memory: this._shortTermMemory,
633
641
  shortTermMemory: this._shortTermMemory,
634
642
  localSecrets: this.localSecrets,
635
643
  localNoises: this.localNoises,
@@ -639,7 +647,7 @@ class pe {
639
647
  }
640
648
  importSnapshot(r) {
641
649
  const t = this.cloneValue(r ?? {});
642
- this._shortTermMemory = Array.isArray(t.shortTermMemory) ? t.shortTermMemory : [], this.localSecrets = t.localSecrets && typeof t.localSecrets == "object" ? t.localSecrets : {}, this.localNoises = t.localNoises && typeof t.localNoises == "object" ? t.localNoises : {}, this.encryptedBranches = t.encryptedBranches && typeof t.encryptedBranches == "object" ? t.encryptedBranches : {}, this.derivations = {}, this.refSubscribers = {};
650
+ this._shortTermMemory = Array.isArray(t.memory) ? t.memory : Array.isArray(t.shortTermMemory) ? t.shortTermMemory : [], this.localSecrets = t.localSecrets && typeof t.localSecrets == "object" ? t.localSecrets : {}, this.localNoises = t.localNoises && typeof t.localNoises == "object" ? t.localNoises : {}, this.encryptedBranches = t.encryptedBranches && typeof t.encryptedBranches == "object" ? t.encryptedBranches : {}, this.derivations = {}, this.refSubscribers = {};
643
651
  const n = {
644
652
  _: { kind: "secret" },
645
653
  "~": { kind: "noise" },
@@ -689,6 +697,9 @@ class pe {
689
697
  }
690
698
  this.rebuildIndex();
691
699
  }
700
+ replayMemory(r) {
701
+ this.replayThoughts(r);
702
+ }
692
703
  isRemoveCall(r, t) {
693
704
  if (r.length === 0) return null;
694
705
  const { scope: n, leaf: i } = I(r);
@@ -878,7 +889,7 @@ class pe {
878
889
  value: i,
879
890
  effectiveSecret: s,
880
891
  prevHash: a
881
- }), c = L(l), d = Date.now(), v = {
892
+ }), c = L(l), d = Date.now(), y = {
882
893
  path: o,
883
894
  operator: t,
884
895
  expression: n,
@@ -888,31 +899,31 @@ class pe {
888
899
  prevHash: a,
889
900
  timestamp: d
890
901
  };
891
- return this._shortTermMemory.push(v), this.rebuildIndex(), v;
902
+ return this._shortTermMemory.push(y), this.rebuildIndex(), y;
892
903
  }
893
904
  commitValueMapping(r, t, n = null) {
894
905
  let i = t;
895
906
  const o = r.join("."), s = this.computeEffectiveSecret(r), a = this.resolveBranchScope(r);
896
907
  if (a && a.length === 0 && this.localSecrets[""] && this.localSecrets[o], a && a.length > 0) {
897
908
  const l = this.computeEffectiveSecret(a), c = r.slice(a.length), d = this.getBranchBlob(a);
898
- let v = {};
909
+ let y = {};
899
910
  if (d && l) {
900
- const y = Ut(d, l, a);
901
- y && typeof y == "object" && (v = y);
911
+ const v = Ut(d, l, a);
912
+ v && typeof v == "object" && (y = v);
902
913
  }
903
914
  if (c.length === 0)
904
- (typeof v != "object" || v === null) && (v = {}), v.expression = t;
915
+ (typeof y != "object" || y === null) && (y = {}), y.expression = t;
905
916
  else {
906
- let y = v;
917
+ let v = y;
907
918
  for (let S = 0; S < c.length - 1; S++) {
908
919
  const p = c[S];
909
- (!y[p] || typeof y[p] != "object") && (y[p] = {}), y = y[p];
920
+ (!v[p] || typeof v[p] != "object") && (v[p] = {}), v = v[p];
910
921
  }
911
- y[c[c.length - 1]] = t;
922
+ v[c[c.length - 1]] = t;
912
923
  }
913
924
  if (l) {
914
- const y = ee(v, l, a);
915
- this.setBranchBlob(a, y);
925
+ const v = ee(y, l, a);
926
+ this.setBranchBlob(a, v);
916
927
  }
917
928
  i = t;
918
929
  } else if (s) {
@@ -984,28 +995,28 @@ class pe {
984
995
  continue;
985
996
  }
986
997
  if (/\d/.test(c) || c === "." && /\d/.test(r[l + 1] ?? "")) {
987
- let y = l;
988
- for (; y < r.length && /[0-9]/.test(r[y]); ) y++;
989
- if (r[y] === ".")
990
- for (y++; y < r.length && /[0-9]/.test(r[y]); ) y++;
991
- if (r[y] === "e" || r[y] === "E") {
992
- let p = y + 1;
998
+ let v = l;
999
+ for (; v < r.length && /[0-9]/.test(r[v]); ) v++;
1000
+ if (r[v] === ".")
1001
+ for (v++; v < r.length && /[0-9]/.test(r[v]); ) v++;
1002
+ if (r[v] === "e" || r[v] === "E") {
1003
+ let p = v + 1;
993
1004
  (r[p] === "+" || r[p] === "-") && p++;
994
1005
  let _ = !1;
995
1006
  for (; p < r.length && /[0-9]/.test(r[p]); )
996
1007
  _ = !0, p++;
997
1008
  if (!_) return null;
998
- y = p;
1009
+ v = p;
999
1010
  }
1000
- const S = Number(r.slice(l, y));
1011
+ const S = Number(r.slice(l, v));
1001
1012
  if (!Number.isFinite(S)) return null;
1002
- t.push({ kind: "literal", value: S }), l = y;
1013
+ t.push({ kind: "literal", value: S }), l = v;
1003
1014
  continue;
1004
1015
  }
1005
- const v = r.slice(l).match(i);
1006
- if (v && v[0]) {
1007
- const y = v[0];
1008
- Object.prototype.hasOwnProperty.call(o, y) ? t.push({ kind: "literal", value: o[y] }) : t.push({ kind: "identifier", value: y }), l += y.length;
1016
+ const y = r.slice(l).match(i);
1017
+ if (y && y[0]) {
1018
+ const v = y[0];
1019
+ Object.prototype.hasOwnProperty.call(o, v) ? t.push({ kind: "literal", value: o[v] }) : t.push({ kind: "identifier", value: v }), l += v.length;
1009
1020
  continue;
1010
1021
  }
1011
1022
  return null;
@@ -1092,44 +1103,44 @@ class pe {
1092
1103
  if (Number.isFinite(p)) return p;
1093
1104
  }
1094
1105
  return null;
1095
- }, v = [];
1106
+ }, y = [];
1096
1107
  for (const S of a) {
1097
1108
  if (S.kind === "literal") {
1098
- v.push(S.value);
1109
+ y.push(S.value);
1099
1110
  continue;
1100
1111
  }
1101
1112
  if (S.kind === "identifier") {
1102
1113
  const E = this.tryResolveEvalTokenValue(S.value, r);
1103
1114
  if (!E.ok) return { ok: !1 };
1104
- v.push(E.value);
1115
+ y.push(E.value);
1105
1116
  continue;
1106
1117
  }
1107
1118
  const p = S.value;
1108
1119
  if (p === "u-" || p === "!") {
1109
- if (v.length < 1) return { ok: !1 };
1110
- const E = v.pop();
1120
+ if (y.length < 1) return { ok: !1 };
1121
+ const E = y.pop();
1111
1122
  if (p === "u-") {
1112
- const j = d(E);
1113
- if (j === null) return { ok: !1 };
1114
- v.push(-j);
1123
+ const T = d(E);
1124
+ if (T === null) return { ok: !1 };
1125
+ y.push(-T);
1115
1126
  } else
1116
- v.push(!E);
1127
+ y.push(!E);
1117
1128
  continue;
1118
1129
  }
1119
- if (v.length < 2) return { ok: !1 };
1120
- const _ = v.pop(), A = v.pop();
1130
+ if (y.length < 2) return { ok: !1 };
1131
+ const _ = y.pop(), A = y.pop();
1121
1132
  if (p === "&&" || p === "||") {
1122
- v.push(p === "&&" ? !!A && !!_ : !!A || !!_);
1133
+ y.push(p === "&&" ? !!A && !!_ : !!A || !!_);
1123
1134
  continue;
1124
1135
  }
1125
1136
  if (p === "==" || p === "!=") {
1126
- v.push(p === "==" ? A == _ : A != _);
1137
+ y.push(p === "==" ? A == _ : A != _);
1127
1138
  continue;
1128
1139
  }
1129
1140
  if (p === "<" || p === "<=" || p === ">" || p === ">=") {
1130
- const E = d(A), j = d(_);
1131
- if (E === null || j === null) return { ok: !1 };
1132
- p === "<" && v.push(E < j), p === "<=" && v.push(E <= j), p === ">" && v.push(E > j), p === ">=" && v.push(E >= j);
1141
+ const E = d(A), T = d(_);
1142
+ if (E === null || T === null) return { ok: !1 };
1143
+ p === "<" && y.push(E < T), p === "<=" && y.push(E <= T), p === ">" && y.push(E > T), p === ">=" && y.push(E >= T);
1133
1144
  continue;
1134
1145
  }
1135
1146
  const B = d(A), F = d(_);
@@ -1142,11 +1153,11 @@ class pe {
1142
1153
  else if (p === "%") O = B % F;
1143
1154
  else return { ok: !1 };
1144
1155
  if (!Number.isFinite(O)) return { ok: !1 };
1145
- v.push(O);
1156
+ y.push(O);
1146
1157
  }
1147
- if (v.length !== 1) return { ok: !1 };
1148
- const y = v[0];
1149
- return typeof y == "number" && Number.isFinite(y) ? { ok: !0, value: y } : typeof y == "boolean" ? { ok: !0, value: y } : { ok: !1 };
1158
+ if (y.length !== 1) return { ok: !1 };
1159
+ const v = y[0];
1160
+ return typeof v == "number" && Number.isFinite(v) ? { ok: !0, value: v } : typeof v == "boolean" ? { ok: !0, value: v } : { ok: !1 };
1150
1161
  }
1151
1162
  // ---------------------------------------------------------
1152
1163
  // Postulate: semantic write at a given path
@@ -1187,10 +1198,10 @@ class pe {
1187
1198
  const B = this.collectIteratorIndices(c.targetPath);
1188
1199
  let F;
1189
1200
  for (const O of B) {
1190
- const E = this.normalizeSelectorPath(this.substituteIteratorInPath(c.targetPath, O)), j = this.normalizeSelectorPath([...E, c.name]), T = this.substituteIteratorInExpression(c.expr, O);
1191
- this.registerDerivation(j, E, T);
1192
- const W = this.tryEvaluateAssignExpression(E, T);
1193
- F = this.postulate(j, W.ok ? W.value : T, "=");
1201
+ const E = this.normalizeSelectorPath(this.substituteIteratorInPath(c.targetPath, O)), T = this.normalizeSelectorPath([...E, c.name]), j = this.substituteIteratorInExpression(c.expr, O);
1202
+ this.registerDerivation(T, E, j);
1203
+ const W = this.tryEvaluateAssignExpression(E, j);
1204
+ F = this.postulate(T, W.ok ? W.value : j, "=");
1194
1205
  }
1195
1206
  return F;
1196
1207
  }
@@ -1198,10 +1209,10 @@ class pe {
1198
1209
  const B = this.collectFilteredScopes(c.targetPath);
1199
1210
  let F;
1200
1211
  for (const O of B) {
1201
- const E = this.normalizeSelectorPath(O), j = this.normalizeSelectorPath([...E, c.name]);
1202
- this.registerDerivation(j, E, c.expr);
1203
- const T = this.tryEvaluateAssignExpression(E, c.expr);
1204
- F = this.postulate(j, T.ok ? T.value : c.expr, "=");
1212
+ const E = this.normalizeSelectorPath(O), T = this.normalizeSelectorPath([...E, c.name]);
1213
+ this.registerDerivation(T, E, c.expr);
1214
+ const j = this.tryEvaluateAssignExpression(E, c.expr);
1215
+ F = this.postulate(T, j.ok ? j.value : c.expr, "=");
1205
1216
  }
1206
1217
  return F;
1207
1218
  }
@@ -1215,15 +1226,15 @@ class pe {
1215
1226
  const p = d.paths.map((A) => this.readPath(A.split(".").filter(Boolean))), _ = d.fn ? d.fn(...p) : p;
1216
1227
  return d.targetPath.length === 0 ? _ : this.postulate(d.targetPath, _, "?");
1217
1228
  }
1218
- const v = this.isRemoveCall(i, t);
1219
- if (v) {
1220
- this.removeSubtree(v.targetPath);
1229
+ const y = this.isRemoveCall(i, t);
1230
+ if (y) {
1231
+ this.removeSubtree(y.targetPath);
1221
1232
  return;
1222
1233
  }
1223
- const y = this.isNoiseScopeCall(i, t);
1224
- if (y) {
1225
- this.localNoises[y.scopeKey] = t;
1226
- const p = y.scopeKey ? y.scopeKey.split(".").filter(Boolean) : [];
1234
+ const v = this.isNoiseScopeCall(i, t);
1235
+ if (v) {
1236
+ this.localNoises[v.scopeKey] = t;
1237
+ const p = v.scopeKey ? v.scopeKey.split(".").filter(Boolean) : [];
1227
1238
  return this.commitThoughtOnly(p, "~", "***", "***");
1228
1239
  }
1229
1240
  const S = this.commitValueMapping(i, t, n);
@@ -1255,15 +1266,15 @@ class pe {
1255
1266
  delete this.encryptedBranches[d];
1256
1267
  continue;
1257
1268
  }
1258
- const v = d.split(".").filter(Boolean);
1259
- if (!qt(r, v) || r.length <= v.length) continue;
1260
- const y = this.computeEffectiveSecret(v);
1261
- if (!y) continue;
1262
- const S = this.getBranchBlob(v);
1269
+ const y = d.split(".").filter(Boolean);
1270
+ if (!qt(r, y) || r.length <= y.length) continue;
1271
+ const v = this.computeEffectiveSecret(y);
1272
+ if (!v) continue;
1273
+ const S = this.getBranchBlob(y);
1263
1274
  if (!S) continue;
1264
- const p = Ut(S, y, v);
1275
+ const p = Ut(S, v, y);
1265
1276
  if (!p || typeof p != "object") continue;
1266
- const _ = r.slice(v.length);
1277
+ const _ = r.slice(y.length);
1267
1278
  let A = p;
1268
1279
  for (let B = 0; B < _.length - 1; B++) {
1269
1280
  const F = _[B];
@@ -1275,8 +1286,8 @@ class pe {
1275
1286
  }
1276
1287
  if (A && typeof A == "object") {
1277
1288
  delete A[_[_.length - 1]];
1278
- const B = ee(p, y, v);
1279
- this.setBranchBlob(v, B);
1289
+ const B = ee(p, v, y);
1290
+ this.setBranchBlob(y, B);
1280
1291
  }
1281
1292
  }
1282
1293
  const n = r.join("."), i = Date.now(), o = this.computeEffectiveSecret(r), s = this.getPrevThoughtHash(), a = JSON.stringify({
@@ -1361,8 +1372,8 @@ class pe {
1361
1372
  for (let a = n.length - 1; a >= 0; a--) {
1362
1373
  const l = n.slice(0, a), c = this.getIndex(l);
1363
1374
  if (!D(c)) continue;
1364
- const d = c.__ptr.split(".").filter(Boolean), v = n.slice(a);
1365
- n = [...d, ...v], s = !0;
1375
+ const d = c.__ptr.split(".").filter(Boolean), y = n.slice(a);
1376
+ n = [...d, ...y], s = !0;
1366
1377
  break;
1367
1378
  }
1368
1379
  if (!s)
@@ -1405,8 +1416,8 @@ class pe {
1405
1416
  continue;
1406
1417
  }
1407
1418
  for (const d of l) {
1408
- let v = (d[1] ?? "").trim();
1409
- (v.startsWith('"') && v.endsWith('"') || v.startsWith("'") && v.endsWith("'")) && (v = v.slice(1, -1)), v && t.push(v);
1419
+ let y = (d[1] ?? "").trim();
1420
+ (y.startsWith('"') && y.endsWith('"') || y.startsWith("'") && y.endsWith("'")) && (y = y.slice(1, -1)), y && t.push(y);
1410
1421
  }
1411
1422
  }
1412
1423
  return t;
@@ -1581,11 +1592,11 @@ class pe {
1581
1592
  if (r.slice(t + 1).length > 0) return;
1582
1593
  const a = this.collectChildrenForPrefix(o), l = {};
1583
1594
  for (const c of a) {
1584
- const d = [...o, c], v = i.expr.replace(
1595
+ const d = [...o, c], y = i.expr.replace(
1585
1596
  new RegExp(String.raw`\b${i.varName}\.`, "g"),
1586
1597
  ""
1587
- ), y = this.tryEvaluateAssignExpression(d, v);
1588
- y.ok && (l[c] = y.value);
1598
+ ), v = this.tryEvaluateAssignExpression(d, y);
1599
+ v.ok && (l[c] = v.value);
1589
1600
  }
1590
1601
  return l;
1591
1602
  }
@@ -1666,12 +1677,12 @@ class pe {
1666
1677
  if (r.length === o.length) return;
1667
1678
  const d = this.computeEffectiveSecret(o);
1668
1679
  if (!d) return null;
1669
- const v = this.getBranchBlob(o);
1670
- if (!v) return;
1671
- const y = Ut(v, d, o);
1672
- if (!y || typeof y != "object") return;
1680
+ const y = this.getBranchBlob(o);
1681
+ if (!y) return;
1682
+ const v = Ut(y, d, o);
1683
+ if (!v || typeof v != "object") return;
1673
1684
  const S = r.slice(o.length);
1674
- let p = y;
1685
+ let p = v;
1675
1686
  for (const _ of S) {
1676
1687
  if (!p || typeof p != "object") return;
1677
1688
  p = p[_];
@@ -1682,9 +1693,9 @@ class pe {
1682
1693
  if (D(s)) return s;
1683
1694
  const a = this.resolveIndexPointerPath(r), l = a.raw;
1684
1695
  if (l === void 0)
1685
- return a.path.length === r.length && a.path.every((v, y) => v === r[y]) ? void 0 : this.readPath(a.path);
1696
+ return a.path.length === r.length && a.path.every((y, v) => y === r[v]) ? void 0 : this.readPath(a.path);
1686
1697
  if (D(l)) return this.readPath(l.__ptr.split(".").filter(Boolean));
1687
- if (Xt(l) || !Te(l)) return l;
1698
+ if (Xt(l) || !je(l)) return l;
1688
1699
  const c = this.computeEffectiveSecret(r);
1689
1700
  return c ? Ut(l, c, r) : null;
1690
1701
  }
package/dist/me.umd.js CHANGED
@@ -1 +1 @@
1
- (function(q,W){typeof exports=="object"&&typeof module<"u"?module.exports=W():typeof define=="function"&&define.amd?define(W):(q=typeof globalThis<"u"?globalThis:q||self,q.Me=W())})(this,(function(){"use strict";function W(f){return{__ptr:f}}function D(f){return!!f&&typeof f=="object"&&typeof f.__ptr=="string"&&f.__ptr.length>0}function ye(f){return{__id:f}}function Qt(f){return!!f&&typeof f=="object"&&typeof f.__id=="string"&&f.__id.length>0}function ve(f){return!!f&&typeof f=="object"&&typeof f.path=="string"&&typeof f.hash=="string"&&typeof f.timestamp=="number"}function I(f){return f.length===0?{scope:[],leaf:null}:{scope:f.slice(0,-1),leaf:f[f.length-1]}}function U(f,r){if(r.length>f.length)return!1;for(let t=0;t<r.length;t++)if(f[t]!==r[t])return!1;return!0}function Z(f){const r=f.trim().toLowerCase();if(r.length<3||r.length>63)throw new Error(`Invalid username length: ${r.length}. Expected 3..63 characters.`);if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$/.test(r))throw new Error(`Invalid username. Use only [a-z0-9-], and start/end with [a-z0-9]. Got: ${f}`);if(r.includes("--"))throw new Error(`Invalid username. "--" is not allowed. Got: ${f}`);return r}function z(f,r){return f[r]?.kind??null}function me(f,r){if(f.length!==1||f[0]!=="+"||!Array.isArray(r)||r.length<2)return null;const n=String(r[0]??"").trim(),i=String(r[1]??"").trim();return!n||!i||n==="+"?null:{op:n,kind:i}}function be(f,r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);return!i||z(f,i)!=="secret"||typeof t!="string"?null:{scopeKey:n.join(".")}}function ke(f,r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);return!i||z(f,i)!=="noise"||typeof t!="string"?null:{scopeKey:n.join(".")}}function Se(f,r,t){if(r.length===0)return null;const{leaf:n}=I(r);if(!n||z(f,n)!=="pointer"||typeof t!="string")return null;const i=t.trim().replace(/^\./,"");return i?{targetPath:i}:null}function Pe(f,r,t){if(r.length===1&&z(f,r[0])==="identity")return typeof t!="string"?null:{id:Z(t),targetPath:[]};const{scope:n,leaf:i}=I(r);return!i||z(f,i)!=="identity"||typeof t!="string"?null:{id:Z(t),targetPath:n}}function xe(f,r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);if(!i||z(f,i)!=="eval")return null;if(typeof t=="function")return{mode:"thunk",targetPath:n,thunk:t};if(Array.isArray(t)&&t.length>=2){const o=String(t[0]??"").trim(),s=String(t[1]??"").trim();return!o||!s?null:{mode:"assign",targetPath:n,name:o,expr:s}}return null}function _e(f,r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);if(!i||z(f,i)!=="query")return null;let o=null,s;if(Array.isArray(t)&&t.length>0)Array.isArray(t[0])&&(t.length===1||typeof t[1]=="function")?(o=t[0],s=typeof t[1]=="function"?t[1]:void 0):o=t;else return null;if(!Array.isArray(o)||o.length===0)return null;const a=o.map(l=>String(l)).map(l=>l.trim()).filter(l=>l.length>0);return a.length===0?null:{targetPath:n,paths:a,fn:s}}function Be(f,r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);if(!i||z(f,i)!=="remove")return null;if(t==null)return{targetPath:n};if(typeof t=="string"){const o=t.split(".").filter(Boolean);return{targetPath:[...n,...o]}}return null}var Ae=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ee(f){return f&&f.__esModule&&Object.prototype.hasOwnProperty.call(f,"default")?f.default:f}var Xt={exports:{}};var se;function Fe(){return se||(se=1,(function(f){(function(){var r="input is invalid type",t="finalize already called",n=typeof window=="object",i=n?window:{};i.JS_SHA3_NO_WINDOW&&(n=!1);var o=!n&&typeof self=="object",s=!i.JS_SHA3_NO_NODE_JS&&typeof process=="object"&&process.versions&&process.versions.node;s?i=Ae:o&&(i=self);for(var a=!i.JS_SHA3_NO_COMMON_JS&&!0&&f.exports,l=!i.JS_SHA3_NO_ARRAY_BUFFER&&typeof ArrayBuffer<"u",c="0123456789abcdef".split(""),d=[31,7936,2031616,520093696],y=[4,1024,262144,67108864],v=[1,256,65536,16777216],S=[6,1536,393216,100663296],p=[0,8,16,24],_=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],A=[224,256,384,512],B=[128,256],F=["hex","buffer","arrayBuffer","array","digest"],O={128:168,256:136},E=i.JS_SHA3_NO_NODE_JS||!Array.isArray?function(e){return Object.prototype.toString.call(e)==="[object Array]"}:Array.isArray,T=l&&(i.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)?function(e){return typeof e=="object"&&e.buffer&&e.buffer.constructor===ArrayBuffer}:ArrayBuffer.isView,j=function(e){var u=typeof e;if(u==="string")return[e,!0];if(u!=="object"||e===null)throw new Error(r);if(l&&e.constructor===ArrayBuffer)return[new Uint8Array(e),!1];if(!E(e)&&!T(e))throw new Error(r);return[e,!1]},$=function(e){return j(e)[0].length===0},ne=function(e){for(var u=[],h=0;h<e.length;++h)u[h]=e[h];return u},ce=function(e,u,h){return function(g){return new N(e,u,e).update(g)[h]()}},ue=function(e,u,h){return function(g,m){return new N(e,u,m).update(g)[h]()}},fe=function(e,u,h){return function(g,m,b,P){return M["cshake"+e].update(g,m,b,P)[h]()}},he=function(e,u,h){return function(g,m,b,P){return M["kmac"+e].update(g,m,b,P)[h]()}},Y=function(e,u,h,g){for(var m=0;m<F.length;++m){var b=F[m];e[b]=u(h,g,b)}return e},pe=function(e,u){var h=ce(e,u,"hex");return h.create=function(){return new N(e,u,e)},h.update=function(g){return h.create().update(g)},Y(h,ce,e,u)},Me=function(e,u){var h=ue(e,u,"hex");return h.create=function(g){return new N(e,u,g)},h.update=function(g,m){return h.create(m).update(g)},Y(h,ue,e,u)},Ke=function(e,u){var h=O[e],g=fe(e,u,"hex");return g.create=function(m,b,P){return $(b)&&$(P)?M["shake"+e].create(m):new N(e,u,m).bytepad([b,P],h)},g.update=function(m,b,P,k){return g.create(b,P,k).update(m)},Y(g,fe,e,u)},De=function(e,u){var h=O[e],g=he(e,u,"hex");return g.create=function(m,b,P){return new oe(e,u,b).bytepad(["KMAC",P],h).bytepad([m],h)},g.update=function(m,b,P,k){return g.create(m,P,k).update(b)},Y(g,he,e,u)},de=[{name:"keccak",padding:v,bits:A,createMethod:pe},{name:"sha3",padding:S,bits:A,createMethod:pe},{name:"shake",padding:d,bits:B,createMethod:Me},{name:"cshake",padding:y,bits:B,createMethod:Ke},{name:"kmac",padding:y,bits:B,createMethod:De}],M={},H=[],K=0;K<de.length;++K)for(var R=de[K],Q=R.bits,L=0;L<Q.length;++L){var ie=R.name+"_"+Q[L];if(H.push(ie),M[ie]=R.createMethod(Q[L],R.padding),R.name!=="sha3"){var ge=R.name+Q[L];H.push(ge),M[ge]=M[ie]}}function N(e,u,h){this.blocks=[],this.s=[],this.padding=u,this.outputBits=h,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(e<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=h>>5,this.extraBytes=(h&31)>>3;for(var g=0;g<50;++g)this.s[g]=0}N.prototype.update=function(e){if(this.finalized)throw new Error(t);var u=j(e);e=u[0];for(var h=u[1],g=this.blocks,m=this.byteCount,b=e.length,P=this.blockCount,k=0,C=this.s,x,w;k<b;){if(this.reset)for(this.reset=!1,g[0]=this.block,x=1;x<P+1;++x)g[x]=0;if(h)for(x=this.start;k<b&&x<m;++k)w=e.charCodeAt(k),w<128?g[x>>2]|=w<<p[x++&3]:w<2048?(g[x>>2]|=(192|w>>6)<<p[x++&3],g[x>>2]|=(128|w&63)<<p[x++&3]):w<55296||w>=57344?(g[x>>2]|=(224|w>>12)<<p[x++&3],g[x>>2]|=(128|w>>6&63)<<p[x++&3],g[x>>2]|=(128|w&63)<<p[x++&3]):(w=65536+((w&1023)<<10|e.charCodeAt(++k)&1023),g[x>>2]|=(240|w>>18)<<p[x++&3],g[x>>2]|=(128|w>>12&63)<<p[x++&3],g[x>>2]|=(128|w>>6&63)<<p[x++&3],g[x>>2]|=(128|w&63)<<p[x++&3]);else for(x=this.start;k<b&&x<m;++k)g[x>>2]|=e[k]<<p[x++&3];if(this.lastByteIndex=x,x>=m){for(this.start=x-m,this.block=g[P],x=0;x<P;++x)C[x]^=g[x];J(C),this.reset=!0}else this.start=x}return this},N.prototype.encode=function(e,u){var h=e&255,g=1,m=[h];for(e=e>>8,h=e&255;h>0;)m.unshift(h),e=e>>8,h=e&255,++g;return u?m.push(g):m.unshift(g),this.update(m),m.length},N.prototype.encodeString=function(e){var u=j(e);e=u[0];var h=u[1],g=0,m=e.length;if(h)for(var b=0;b<e.length;++b){var P=e.charCodeAt(b);P<128?g+=1:P<2048?g+=2:P<55296||P>=57344?g+=3:(P=65536+((P&1023)<<10|e.charCodeAt(++b)&1023),g+=4)}else g=m;return g+=this.encode(g*8),this.update(e),g},N.prototype.bytepad=function(e,u){for(var h=this.encode(u),g=0;g<e.length;++g)h+=this.encodeString(e[g]);var m=(u-h%u)%u,b=[];return b.length=m,this.update(b),this},N.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var e=this.blocks,u=this.lastByteIndex,h=this.blockCount,g=this.s;if(e[u>>2]|=this.padding[u&3],this.lastByteIndex===this.byteCount)for(e[0]=e[h],u=1;u<h+1;++u)e[u]=0;for(e[h-1]|=2147483648,u=0;u<h;++u)g[u]^=e[u];J(g)}},N.prototype.toString=N.prototype.hex=function(){this.finalize();for(var e=this.blockCount,u=this.s,h=this.outputBlocks,g=this.extraBytes,m=0,b=0,P="",k;b<h;){for(m=0;m<e&&b<h;++m,++b)k=u[m],P+=c[k>>4&15]+c[k&15]+c[k>>12&15]+c[k>>8&15]+c[k>>20&15]+c[k>>16&15]+c[k>>28&15]+c[k>>24&15];b%e===0&&(u=ne(u),J(u),m=0)}return g&&(k=u[m],P+=c[k>>4&15]+c[k&15],g>1&&(P+=c[k>>12&15]+c[k>>8&15]),g>2&&(P+=c[k>>20&15]+c[k>>16&15])),P},N.prototype.arrayBuffer=function(){this.finalize();var e=this.blockCount,u=this.s,h=this.outputBlocks,g=this.extraBytes,m=0,b=0,P=this.outputBits>>3,k;g?k=new ArrayBuffer(h+1<<2):k=new ArrayBuffer(P);for(var C=new Uint32Array(k);b<h;){for(m=0;m<e&&b<h;++m,++b)C[b]=u[m];b%e===0&&(u=ne(u),J(u))}return g&&(C[b]=u[m],k=k.slice(0,P)),k},N.prototype.buffer=N.prototype.arrayBuffer,N.prototype.digest=N.prototype.array=function(){this.finalize();for(var e=this.blockCount,u=this.s,h=this.outputBlocks,g=this.extraBytes,m=0,b=0,P=[],k,C;b<h;){for(m=0;m<e&&b<h;++m,++b)k=b<<2,C=u[m],P[k]=C&255,P[k+1]=C>>8&255,P[k+2]=C>>16&255,P[k+3]=C>>24&255;b%e===0&&(u=ne(u),J(u))}return g&&(k=b<<2,C=u[m],P[k]=C&255,g>1&&(P[k+1]=C>>8&255),g>2&&(P[k+2]=C>>16&255)),P};function oe(e,u,h){N.call(this,e,u,h)}oe.prototype=new N,oe.prototype.finalize=function(){return this.encode(this.outputBits,!0),N.prototype.finalize.call(this)};var J=function(e){var u,h,g,m,b,P,k,C,x,w,X,tt,et,rt,nt,it,ot,st,lt,at,ct,ut,ft,ht,pt,dt,gt,yt,vt,mt,bt,kt,St,Pt,xt,_t,Bt,At,Et,Ft,wt,Nt,Ct,Ot,It,Tt,jt,zt,Mt,Kt,Dt,Rt,Wt,Vt,$t,Ht,Lt,Jt,qt,Ut,Zt,Gt,Yt;for(g=0;g<48;g+=2)m=e[0]^e[10]^e[20]^e[30]^e[40],b=e[1]^e[11]^e[21]^e[31]^e[41],P=e[2]^e[12]^e[22]^e[32]^e[42],k=e[3]^e[13]^e[23]^e[33]^e[43],C=e[4]^e[14]^e[24]^e[34]^e[44],x=e[5]^e[15]^e[25]^e[35]^e[45],w=e[6]^e[16]^e[26]^e[36]^e[46],X=e[7]^e[17]^e[27]^e[37]^e[47],tt=e[8]^e[18]^e[28]^e[38]^e[48],et=e[9]^e[19]^e[29]^e[39]^e[49],u=tt^(P<<1|k>>>31),h=et^(k<<1|P>>>31),e[0]^=u,e[1]^=h,e[10]^=u,e[11]^=h,e[20]^=u,e[21]^=h,e[30]^=u,e[31]^=h,e[40]^=u,e[41]^=h,u=m^(C<<1|x>>>31),h=b^(x<<1|C>>>31),e[2]^=u,e[3]^=h,e[12]^=u,e[13]^=h,e[22]^=u,e[23]^=h,e[32]^=u,e[33]^=h,e[42]^=u,e[43]^=h,u=P^(w<<1|X>>>31),h=k^(X<<1|w>>>31),e[4]^=u,e[5]^=h,e[14]^=u,e[15]^=h,e[24]^=u,e[25]^=h,e[34]^=u,e[35]^=h,e[44]^=u,e[45]^=h,u=C^(tt<<1|et>>>31),h=x^(et<<1|tt>>>31),e[6]^=u,e[7]^=h,e[16]^=u,e[17]^=h,e[26]^=u,e[27]^=h,e[36]^=u,e[37]^=h,e[46]^=u,e[47]^=h,u=w^(m<<1|b>>>31),h=X^(b<<1|m>>>31),e[8]^=u,e[9]^=h,e[18]^=u,e[19]^=h,e[28]^=u,e[29]^=h,e[38]^=u,e[39]^=h,e[48]^=u,e[49]^=h,rt=e[0],nt=e[1],Tt=e[11]<<4|e[10]>>>28,jt=e[10]<<4|e[11]>>>28,yt=e[20]<<3|e[21]>>>29,vt=e[21]<<3|e[20]>>>29,Ut=e[31]<<9|e[30]>>>23,Zt=e[30]<<9|e[31]>>>23,Nt=e[40]<<18|e[41]>>>14,Ct=e[41]<<18|e[40]>>>14,Pt=e[2]<<1|e[3]>>>31,xt=e[3]<<1|e[2]>>>31,it=e[13]<<12|e[12]>>>20,ot=e[12]<<12|e[13]>>>20,zt=e[22]<<10|e[23]>>>22,Mt=e[23]<<10|e[22]>>>22,mt=e[33]<<13|e[32]>>>19,bt=e[32]<<13|e[33]>>>19,Gt=e[42]<<2|e[43]>>>30,Yt=e[43]<<2|e[42]>>>30,Vt=e[5]<<30|e[4]>>>2,$t=e[4]<<30|e[5]>>>2,_t=e[14]<<6|e[15]>>>26,Bt=e[15]<<6|e[14]>>>26,st=e[25]<<11|e[24]>>>21,lt=e[24]<<11|e[25]>>>21,Kt=e[34]<<15|e[35]>>>17,Dt=e[35]<<15|e[34]>>>17,kt=e[45]<<29|e[44]>>>3,St=e[44]<<29|e[45]>>>3,ht=e[6]<<28|e[7]>>>4,pt=e[7]<<28|e[6]>>>4,Ht=e[17]<<23|e[16]>>>9,Lt=e[16]<<23|e[17]>>>9,At=e[26]<<25|e[27]>>>7,Et=e[27]<<25|e[26]>>>7,at=e[36]<<21|e[37]>>>11,ct=e[37]<<21|e[36]>>>11,Rt=e[47]<<24|e[46]>>>8,Wt=e[46]<<24|e[47]>>>8,Ot=e[8]<<27|e[9]>>>5,It=e[9]<<27|e[8]>>>5,dt=e[18]<<20|e[19]>>>12,gt=e[19]<<20|e[18]>>>12,Jt=e[29]<<7|e[28]>>>25,qt=e[28]<<7|e[29]>>>25,Ft=e[38]<<8|e[39]>>>24,wt=e[39]<<8|e[38]>>>24,ut=e[48]<<14|e[49]>>>18,ft=e[49]<<14|e[48]>>>18,e[0]=rt^~it&st,e[1]=nt^~ot&lt,e[10]=ht^~dt&yt,e[11]=pt^~gt&vt,e[20]=Pt^~_t&At,e[21]=xt^~Bt&Et,e[30]=Ot^~Tt&zt,e[31]=It^~jt&Mt,e[40]=Vt^~Ht&Jt,e[41]=$t^~Lt&qt,e[2]=it^~st&at,e[3]=ot^~lt&ct,e[12]=dt^~yt&mt,e[13]=gt^~vt&bt,e[22]=_t^~At&Ft,e[23]=Bt^~Et&wt,e[32]=Tt^~zt&Kt,e[33]=jt^~Mt&Dt,e[42]=Ht^~Jt&Ut,e[43]=Lt^~qt&Zt,e[4]=st^~at&ut,e[5]=lt^~ct&ft,e[14]=yt^~mt&kt,e[15]=vt^~bt&St,e[24]=At^~Ft&Nt,e[25]=Et^~wt&Ct,e[34]=zt^~Kt&Rt,e[35]=Mt^~Dt&Wt,e[44]=Jt^~Ut&Gt,e[45]=qt^~Zt&Yt,e[6]=at^~ut&rt,e[7]=ct^~ft&nt,e[16]=mt^~kt&ht,e[17]=bt^~St&pt,e[26]=Ft^~Nt&Pt,e[27]=wt^~Ct&xt,e[36]=Kt^~Rt&Ot,e[37]=Dt^~Wt&It,e[46]=Ut^~Gt&Vt,e[47]=Zt^~Yt&$t,e[8]=ut^~rt&it,e[9]=ft^~nt&ot,e[18]=kt^~ht&dt,e[19]=St^~pt&gt,e[28]=Nt^~Pt&_t,e[29]=Ct^~xt&Bt,e[38]=Rt^~Ot&Tt,e[39]=Wt^~It&jt,e[48]=Gt^~Vt&Ht,e[49]=Yt^~$t&Lt,e[0]^=_[g],e[1]^=_[g+1]};if(a)f.exports=M;else for(K=0;K<H.length;++K)i[H[K]]=M[H[K]]})()})(Xt)),Xt.exports}var we=Fe();const Ne=Ee(we),{keccak256:le}=Ne;function te(f){return new TextEncoder().encode(f)}function Ce(f){const r=f.startsWith("0x")?f.slice(2):f,t=new Uint8Array(r.length/2);for(let n=0;n<t.length;n++)t[n]=parseInt(r.substring(n*2,n*2+2),16);return t}function Oe(f){let r="";for(let t=0;t<f.length;t++)r+=f[t].toString(16).padStart(2,"0");return"0x"+r}function ee(f,r,t){const n=JSON.stringify(f),i=te(n),o=le(r+":"+t.join(".")),s=te(o),a=new Uint8Array(i.length);for(let l=0;l<i.length;l++)a[l]=i[l]^s[l%s.length];return Oe(a)}function G(f,r,t){try{const n=Ce(f),i=le(r+":"+t.join(".")),o=te(i),s=new Uint8Array(n.length);for(let l=0;l<n.length;l++)s[l]=n[l]^o[l%o.length];const a=new TextDecoder().decode(s);return JSON.parse(a)}catch{return null}}function Ie(f){if(typeof f!="string"||!f.startsWith("0x"))return!1;const r=f.slice(2);return r.length<2||r.length%2!==0?!1:/^[0-9a-fA-F]+$/.test(r)}function Te(f){const r=[];let t="",n=0,i=null;for(let s=0;s<f.length;s++){const a=f[s];if(i){t+=a,a===i&&(i=null);continue}if(a==='"'||a==="'"){i=a,t+=a;continue}if(a==="["){n++,t+=a;continue}if(a==="]"){n=Math.max(0,n-1),t+=a;continue}if(a==="."&&n===0){const l=t.trim();l&&r.push(l),t="";continue}t+=a}const o=t.trim();return o&&r.push(o),r}function je(f,r,t){if(r.length===0){if(t.length===1&&typeof t[0]=="string"){const d=t[0].trim(),y=d.startsWith("_")||d.startsWith("~")||d.startsWith("@"),v=d.includes("."),S=/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(d);if(v||y||S){const p=Te(d);return f.readPath(p)}}if(t.length===0)return f.createProxy([]);const l=f.normalizeArgs(t),c=f.postulate([],l);return c!==void 0?c:f.createProxy([])}const n=f.normalizeArgs(t),i=f.postulate(r,n),{scope:o,leaf:s}=f.splitPath(r),a=s?f.opKind(s):null;if(f.isThought(i)){const l=a?o:r;return f.createProxy(l)}return i!==void 0?i:f.createProxy(r)}function ze(f,r,t={}){const{path:n,expression:i}=r,o=me(n,i);if(o)return{kind:"return",value:{define:o}};const s=be(f,n,i);if(s)return{kind:"commit",instructions:[{path:s.scopeKey?s.scopeKey.split(".").filter(Boolean):[],op:"secret",value:i}]};const a=ke(f,n,i);if(a)return{kind:"commit",instructions:[{path:a.scopeKey?a.scopeKey.split(".").filter(Boolean):[],op:"noise",value:i}]};const l=Se(f,n,i);if(l){const{scope:S}=I(n);return{kind:"commit",instructions:[{path:S,op:"ptr",value:W(l.targetPath)}]}}const c=Pe(f,n,i);if(c)return{kind:"commit",instructions:[{path:c.targetPath,op:"id",value:ye(c.id)}]};const d=Be(f,n,i);if(d)return{kind:"commit",instructions:[{path:d.targetPath,op:"remove",value:"-"}]};const y=xe(f,n,i);if(y){if(y.mode==="assign")return{kind:"commit",instructions:[{path:[...y.targetPath,y.name],op:"derive",value:{kind:"expr",source:y.expr}}]};if(!t.evaluateThunk)throw new Error('Non-serializable derivation: "=" thunk requires `evaluateThunk` or serializable DNA.');const S=t.evaluateThunk(y.thunk);return y.targetPath.length===0?{kind:"return",value:S}:{kind:"commit",instructions:[{path:y.targetPath,op:"derive",value:S}]}}const v=_e(f,n,i);if(v){if(!t.readPath)return{kind:"commit",instructions:[{path:v.targetPath,op:"query",value:{paths:v.paths}}]};const S=v.paths.map(_=>t.readPath(_.split(".").filter(Boolean))),p=v.fn?v.fn(...S):S;return v.targetPath.length===0?{kind:"return",value:p}:{kind:"commit",instructions:[{path:v.targetPath,op:"query",value:p}]}}return{kind:"commit",instructions:[{path:n,op:"set",value:i}]}}const ae="+";function V(f){let r=2166136261;for(let t=0;t<f.length;t++)r^=f.charCodeAt(t),r=Math.imul(r,16777619);return("00000000"+(r>>>0).toString(16)).slice(-8)}class re{constructor(r){this.localSecrets={},this.localNoises={},this.encryptedBranches={},this.index={},this._shortTermMemory=[],this.derivations={},this.refSubscribers={},this.unsafeEval=!1,this.operators={_:{kind:"secret"},"~":{kind:"noise"},__:{kind:"pointer"},"->":{kind:"pointer"},"@":{kind:"identity"},"=":{kind:"eval"},"?":{kind:"query"},"-":{kind:"remove"}},this.localSecrets={},this.localNoises={},this.encryptedBranches={},this.index={},this.operators={_:{kind:"secret"},"~":{kind:"noise"},__:{kind:"pointer"},"->":{kind:"pointer"},"@":{kind:"identity"},"=":{kind:"eval"},"?":{kind:"query"},"-":{kind:"remove"}},this._shortTermMemory=[],r!==void 0&&this.postulate([],r),this.rebuildIndex();const t=this.createProxy([]);return Object.setPrototypeOf(t,re.prototype),Object.assign(t,this),t}get shortTermMemory(){return this._shortTermMemory}inspect(r){const t=r?.last;return{thoughts:typeof t=="number"&&Number.isFinite(t)&&t>0?this._shortTermMemory.slice(-Math.floor(t)):this._shortTermMemory.slice(),index:{...this.index},encryptedScopes:Object.keys(this.encryptedBranches),secretScopes:Object.keys(this.localSecrets),noiseScopes:Object.keys(this.localNoises)}}explain(r){const t=this.normalizeSelectorPath(String(r??"").split(".").filter(Boolean)),n=t.join("."),i=this.readPath(t),o=this.derivations[n];if(!o)return{path:n,value:i,derivation:null,meta:{dependsOn:[]}};const s=o.refs.map(a=>{const l=this.normalizeSelectorPath(a.path.split(".").filter(Boolean)),c=this.resolveBranchScope(l),d=!!(c&&c.length>0&&U(l,c)),y=this.readPath(l);return{label:a.label,path:a.path,value:d?"●●●●":y,origin:d?"stealth":"public",masked:d}});return{path:n,value:i,derivation:{expression:o.expression,inputs:s},meta:{dependsOn:o.refs.map(a=>a.path),lastComputedAt:o.lastComputedAt}}}cloneValue(r){const t=globalThis.structuredClone;return typeof t=="function"?t(r):JSON.parse(JSON.stringify(r))}exportSnapshot(){return this.cloneValue({shortTermMemory:this._shortTermMemory,localSecrets:this.localSecrets,localNoises:this.localNoises,encryptedBranches:this.encryptedBranches,operators:this.operators})}importSnapshot(r){const t=this.cloneValue(r??{});this._shortTermMemory=Array.isArray(t.shortTermMemory)?t.shortTermMemory:[],this.localSecrets=t.localSecrets&&typeof t.localSecrets=="object"?t.localSecrets:{},this.localNoises=t.localNoises&&typeof t.localNoises=="object"?t.localNoises:{},this.encryptedBranches=t.encryptedBranches&&typeof t.encryptedBranches=="object"?t.encryptedBranches:{},this.derivations={},this.refSubscribers={};const n={_:{kind:"secret"},"~":{kind:"noise"},__:{kind:"pointer"},"->":{kind:"pointer"},"@":{kind:"identity"},"=":{kind:"eval"},"?":{kind:"query"},"-":{kind:"remove"}};this.operators=t.operators&&typeof t.operators=="object"?{...n,...t.operators}:n,this.rebuildIndex()}rehydrate(r){this.importSnapshot(r)}replayThoughts(r){this.localSecrets={},this.localNoises={},this.encryptedBranches={},this.index={},this._shortTermMemory=[],this.derivations={},this.refSubscribers={};for(const t of r||[]){const n=String(t.path||"").split(".").filter(Boolean);if(t.operator==="_"){this.postulate([...n,"_"],typeof t.expression=="string"?t.expression:"***");continue}if(t.operator==="~"){this.postulate([...n,"~"],typeof t.expression=="string"?t.expression:"***");continue}if(t.operator==="@"){const i=t.expression&&t.expression.__id||t.value&&t.value.__id||t.value;typeof i=="string"&&i.length>0&&this.postulate([...n,"@"],i);continue}if(t.operator==="__"||t.operator==="->"){const i=t.expression&&t.expression.__ptr||t.value&&t.value.__ptr||t.value;typeof i=="string"&&i.length>0&&this.postulate([...n,"__"],i);continue}if(t.operator==="-"){this.removeSubtree(n);continue}if(t.operator==="="||t.operator==="?"){this.postulate(n,t.value,t.operator);continue}this.postulate(n,t.expression,t.operator)}this.rebuildIndex()}isRemoveCall(r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);if(!i||this.opKind(i)!=="remove")return null;if(t==null)return{targetPath:n};if(typeof t=="string"){const o=t.split(".").filter(Boolean);return{targetPath:[...n,...o]}}return null}createProxy(r){const t=this,n=(...i)=>je({createProxy:o=>t.createProxy(o),normalizeArgs:o=>t.normalizeArgs(o),readPath:o=>t.readPath(o),postulate:(o,s)=>t.postulate(o,s),opKind:o=>t.opKind(o),splitPath:I,isThought:ve},r,i);return new Proxy(n,{get(i,o){if(typeof o=="symbol")return i[o];if(o in t){const a=t[o];return typeof a=="function"?a.bind(t):a}const s=[...r,String(o)];return t.createProxy(s)},apply(i,o,s){return Reflect.apply(i,void 0,s)}})}normalizeArgs(r){if(r.length!==0)return r.length===1?r[0]:r}opKind(r){return this.operators[r]?.kind??null}isSecretScopeCall(r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);return!i||this.opKind(i)!=="secret"||typeof t!="string"?null:{scopeKey:n.join(".")}}isNoiseScopeCall(r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);return!i||this.opKind(i)!=="noise"||typeof t!="string"?null:{scopeKey:n.join(".")}}isPointerCall(r,t){if(r.length===0)return null;const{leaf:n}=I(r);if(!n||this.opKind(n)!=="pointer"||typeof t!="string")return null;const i=t.trim().replace(/^\./,"");return i?{targetPath:i}:null}isIdentityCall(r,t){if(r.length===1&&this.opKind(r[0])==="identity")return typeof t!="string"?null:{id:Z(t),targetPath:[]};const{scope:n,leaf:i}=I(r);return!i||this.opKind(i)!=="identity"||typeof t!="string"?null:{id:Z(t),targetPath:n}}isEvalCall(r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);if(!i||this.opKind(i)!=="eval")return null;if(typeof t=="function")return{mode:"thunk",targetPath:n,thunk:t};if(Array.isArray(t)&&t.length>=2){const o=String(t[0]??"").trim(),s=String(t[1]??"").trim();return!o||!s?null:{mode:"assign",targetPath:n,name:o,expr:s}}return null}isQueryCall(r,t){if(r.length===0)return null;const{scope:n,leaf:i}=I(r);if(!i||this.opKind(i)!=="query")return null;let o=null,s;if(Array.isArray(t)&&t.length>0)Array.isArray(t[0])&&(t.length===1||typeof t[1]=="function")?(o=t[0],s=typeof t[1]=="function"?t[1]:void 0):o=t;else return null;if(!Array.isArray(o)||o.length===0)return null;const a=o.map(l=>String(l)).map(l=>l.trim()).filter(l=>l.length>0);return a.length===0?null:{targetPath:n,paths:a,fn:s}}isDefineOpCall(r,t){if(r.length!==1||r[0]!==ae||!Array.isArray(t)||t.length<2)return null;const i=String(t[0]??"").trim(),o=String(t[1]??"").trim();return!i||!o||i===ae?null:{op:i,kind:o}}getPrevThoughtHash(){return this._shortTermMemory[this._shortTermMemory.length-1]?.hash??""}extractExpressionRefs(r){const t=String(r??"").trim();if(!t)return[];const n=String.raw`[A-Za-z_][A-Za-z0-9_]*(?:\[(?:"[^"]*"|'[^']*'|[^\]]+)\])*`,i=new RegExp(String.raw`__ptr(?:\.${n})*|${n}(?:\.${n})*`,"g"),o=new Set(["true","false","null","undefined","NaN","Infinity"]),s=new Set,a=t.match(i)||[];for(const l of a)o.has(l)||s.add(l);return Array.from(s)}resolveRefPath(r,t){if(!r||r.startsWith("__ptr."))return null;const n=this.normalizeSelectorPath(r.split(".").filter(Boolean));if(n.length===0)return null;const i=this.normalizeSelectorPath([...t,...n]).join("."),o=this.normalizeSelectorPath(n).join(".");return r.includes(".")?o:i}unregisterDerivation(r){const t=this.derivations[r];if(t){for(const n of t.refs){const i=this.refSubscribers[n.path]||[];this.refSubscribers[n.path]=i.filter(o=>o!==r),this.refSubscribers[n.path].length===0&&delete this.refSubscribers[n.path]}delete this.derivations[r]}}registerDerivation(r,t,n){const i=r.join(".");this.unregisterDerivation(i);const o=this.extractExpressionRefs(n),s=[],a=new Set;for(const l of o){const c=this.resolveRefPath(l,t);if(!c||a.has(c))continue;a.add(c),s.push({label:l,path:c});const d=this.refSubscribers[c]||[];d.includes(i)||d.push(i),this.refSubscribers[c]=d}this.derivations[i]={expression:n,evalScope:[...t],refs:s,lastComputedAt:Date.now()}}recomputeTarget(r){const t=this.derivations[r];if(!t)return!1;const n=this.normalizeSelectorPath(r.split(".").filter(Boolean)),i=this.tryEvaluateAssignExpression(t.evalScope,t.expression);return this.postulate(n,i.ok?i.value:t.expression,"="),t.lastComputedAt=Date.now(),!0}invalidateFromPath(r){const t=this.normalizeSelectorPath(r).join(".");if(!t)return;const n=[t],i=new Set;for(;n.length>0;){const o=n.shift(),s=this.refSubscribers[o]||[];for(const a of s){if(i.has(a))continue;i.add(a),this.recomputeTarget(a)&&n.push(a)}}}clearDerivationsByPrefix(r){const t=r.join(".");for(const n of Object.keys(this.derivations))(t===""||n===t||n.startsWith(t+"."))&&this.unregisterDerivation(n)}commitThoughtOnly(r,t,n,i){const o=r.join("."),s=this.computeEffectiveSecret(r),a=this.getPrevThoughtHash(),l=JSON.stringify({path:o,operator:t,expression:n,value:i,effectiveSecret:s,prevHash:a}),c=V(l),d=Date.now(),y={path:o,operator:t,expression:n,value:i,effectiveSecret:s,hash:c,prevHash:a,timestamp:d};return this._shortTermMemory.push(y),this.rebuildIndex(),y}commitValueMapping(r,t,n=null){let i=t;const o=r.join("."),s=this.computeEffectiveSecret(r),a=this.resolveBranchScope(r);if(a&&a.length===0&&this.localSecrets[""]&&this.localSecrets[o],a&&a.length>0){const l=this.computeEffectiveSecret(a),c=r.slice(a.length),d=this.getBranchBlob(a);let y={};if(d&&l){const v=G(d,l,a);v&&typeof v=="object"&&(y=v)}if(c.length===0)(typeof y!="object"||y===null)&&(y={}),y.expression=t;else{let v=y;for(let S=0;S<c.length-1;S++){const p=c[S];(!v[p]||typeof v[p]!="object")&&(v[p]={}),v=v[p]}v[c[c.length-1]]=t}if(l){const v=ee(y,l,a);this.setBranchBlob(a,v)}i=t}else if(s){const l=n!=="="&&n!=="?";D(t)||Qt(t)||!l?i=t:i=ee(t,s,r)}else i=t;return this.commitThoughtOnly(r,n,t,i)}commitMapping(r,t=null){switch(r.op){case"set":return this.commitValueMapping(r.path,r.value,t);case"ptr":return this.commitValueMapping(r.path,r.value,"__");case"id":return this.commitValueMapping(r.path,r.value,"@");case"secret":{if(typeof r.value!="string")return;const n=r.path.join(".");return this.localSecrets[n]=r.value,this.commitThoughtOnly(r.path,"_","***","***")}default:return}}tryResolveEvalTokenValue(r,t){if(r.startsWith("__ptr.")){const s=this.getIndex(t);if(!D(s))return{ok:!1};const a=r.slice(6).split(".").filter(Boolean),l=[...s.__ptr.split(".").filter(Boolean),...a],c=this.readPath(l);return c==null?{ok:!1}:{ok:!0,value:c}}const n=r.split(".").filter(Boolean),i=[...t,...n];let o=this.readPath(i);return o==null&&(o=this.readPath(n)),o==null?{ok:!1}:{ok:!0,value:o}}tokenizeEvalExpression(r){const t=[],n=String.raw`[A-Za-z_][A-Za-z0-9_]*(?:\[(?:"[^"]*"|'[^']*'|[^\]]+)\])*`,i=new RegExp(String.raw`^(?:__ptr(?:\.${n})*|${n}(?:\.${n})*)`),o={true:!0,false:!1,null:null,undefined:void 0,NaN:NaN,Infinity:1/0},s=new Set([">=","<=","==","!=","&&","||"]),a=new Set(["+","-","*","/","%","<",">","!"]);let l=0;for(;l<r.length;){const c=r[l];if(/\s/.test(c)){l++;continue}if(c==="("){t.push({kind:"lparen"}),l++;continue}if(c===")"){t.push({kind:"rparen"}),l++;continue}const d=r.slice(l,l+2);if(s.has(d)){t.push({kind:"op",value:d}),l+=2;continue}if(a.has(c)){t.push({kind:"op",value:c}),l++;continue}if(/\d/.test(c)||c==="."&&/\d/.test(r[l+1]??"")){let v=l;for(;v<r.length&&/[0-9]/.test(r[v]);)v++;if(r[v]===".")for(v++;v<r.length&&/[0-9]/.test(r[v]);)v++;if(r[v]==="e"||r[v]==="E"){let p=v+1;(r[p]==="+"||r[p]==="-")&&p++;let _=!1;for(;p<r.length&&/[0-9]/.test(r[p]);)_=!0,p++;if(!_)return null;v=p}const S=Number(r.slice(l,v));if(!Number.isFinite(S))return null;t.push({kind:"literal",value:S}),l=v;continue}const y=r.slice(l).match(i);if(y&&y[0]){const v=y[0];Object.prototype.hasOwnProperty.call(o,v)?t.push({kind:"literal",value:o[v]}):t.push({kind:"identifier",value:v}),l+=v.length;continue}return null}return t}tryEvaluateAssignExpression(r,t){const n=String(t??"").trim();if(!n)return{ok:!1};if(!/^[A-Za-z0-9_\s+\-*/%().<>=!&|\[\]"']+$/.test(n))return{ok:!1};if(this.unsafeEval)return{ok:!1};const i=this.tokenizeEvalExpression(n);if(!i||i.length===0)return{ok:!1};const o={"u-":7,"!":7,"*":6,"/":6,"%":6,"+":5,"-":5,"<":4,"<=":4,">":4,">=":4,"==":3,"!=":3,"&&":2,"||":1},s=new Set(["u-","!"]),a=[],l=[];let c="start";for(const S of i){if(S.kind==="literal"||S.kind==="identifier"){a.push(S),c="value";continue}if(S.kind==="lparen"){l.push(S),c="lparen";continue}if(S.kind==="rparen"){let _=!1;for(;l.length>0;){const A=l.pop();if(A.kind==="lparen"){_=!0;break}a.push(A)}if(!_)return{ok:!1};c="rparen";continue}let p=S.value;if(p==="-"&&(c==="start"||c==="op"||c==="lparen"))p="u-";else{if(p==="!"&&(c==="value"||c==="rparen"))return{ok:!1};if(p!=="!"&&(c==="start"||c==="op"||c==="lparen"))return{ok:!1}}for(;l.length>0;){const _=l[l.length-1];if(_.kind!=="op")break;const A=o[_.value]??-1,B=o[p]??-1;if(B<0)return{ok:!1};if(!(s.has(p)?B<A:B<=A))break;a.push(l.pop())}l.push({kind:"op",value:p}),c="op"}if(c==="op"||c==="lparen"||c==="start")return{ok:!1};for(;l.length>0;){const S=l.pop();if(S.kind==="lparen")return{ok:!1};a.push(S)}const d=S=>{if(typeof S=="number"&&Number.isFinite(S))return S;if(typeof S=="string"){const p=Number(S);if(Number.isFinite(p))return p}return null},y=[];for(const S of a){if(S.kind==="literal"){y.push(S.value);continue}if(S.kind==="identifier"){const E=this.tryResolveEvalTokenValue(S.value,r);if(!E.ok)return{ok:!1};y.push(E.value);continue}const p=S.value;if(p==="u-"||p==="!"){if(y.length<1)return{ok:!1};const E=y.pop();if(p==="u-"){const T=d(E);if(T===null)return{ok:!1};y.push(-T)}else y.push(!E);continue}if(y.length<2)return{ok:!1};const _=y.pop(),A=y.pop();if(p==="&&"||p==="||"){y.push(p==="&&"?!!A&&!!_:!!A||!!_);continue}if(p==="=="||p==="!="){y.push(p==="=="?A==_:A!=_);continue}if(p==="<"||p==="<="||p===">"||p===">="){const E=d(A),T=d(_);if(E===null||T===null)return{ok:!1};p==="<"&&y.push(E<T),p==="<="&&y.push(E<=T),p===">"&&y.push(E>T),p===">="&&y.push(E>=T);continue}const B=d(A),F=d(_);if(B===null||F===null)return{ok:!1};let O;if(p==="+")O=B+F;else if(p==="-")O=B-F;else if(p==="*")O=B*F;else if(p==="/")O=B/F;else if(p==="%")O=B%F;else return{ok:!1};if(!Number.isFinite(O))return{ok:!1};y.push(O)}if(y.length!==1)return{ok:!1};const v=y[0];return typeof v=="number"&&Number.isFinite(v)?{ok:!0,value:v}:typeof v=="boolean"?{ok:!0,value:v}:{ok:!1}}postulate(r,t,n=null){let i=r;const o=this.isDefineOpCall(i,t);if(o){this.operators[o.op]={kind:o.kind};return}const{leaf:s}=I(i),a=s?this.opKind(s):null;if(a===null||a==="secret"||a==="pointer"||a==="identity"){const p=ze(this.operators,{path:i,expression:t});if(p.kind==="commit"){const _=new Set(["set","secret","ptr","id"]);if(p.instructions.every(B=>_.has(B.op))){let B;const F=[];for(const O of p.instructions){const E=this.commitMapping(O,n);E&&(B=E,F.push(E.path.split(".").filter(Boolean)))}if(B){for(const O of F)this.invalidateFromPath(O);return B}}}}const c=this.isEvalCall(i,t);if(c){if(c.mode==="thunk"){const B=c.thunk();return c.targetPath.length===0?B:this.postulate(c.targetPath,B,"=")}if(this.pathContainsIterator(c.targetPath)){const B=this.collectIteratorIndices(c.targetPath);let F;for(const O of B){const E=this.normalizeSelectorPath(this.substituteIteratorInPath(c.targetPath,O)),T=this.normalizeSelectorPath([...E,c.name]),j=this.substituteIteratorInExpression(c.expr,O);this.registerDerivation(T,E,j);const $=this.tryEvaluateAssignExpression(E,j);F=this.postulate(T,$.ok?$.value:j,"=")}return F}if(this.pathContainsFilterSelector(c.targetPath)){const B=this.collectFilteredScopes(c.targetPath);let F;for(const O of B){const E=this.normalizeSelectorPath(O),T=this.normalizeSelectorPath([...E,c.name]);this.registerDerivation(T,E,c.expr);const j=this.tryEvaluateAssignExpression(E,c.expr);F=this.postulate(T,j.ok?j.value:c.expr,"=")}return F}const p=this.normalizeSelectorPath([...c.targetPath,c.name]),_=this.normalizeSelectorPath(c.targetPath);this.registerDerivation(p,_,c.expr);const A=this.tryEvaluateAssignExpression(_,c.expr);return A.ok?this.postulate(p,A.value,"="):this.postulate(p,c.expr,"=")}const d=this.isQueryCall(i,t);if(d){const p=d.paths.map(A=>this.readPath(A.split(".").filter(Boolean))),_=d.fn?d.fn(...p):p;return d.targetPath.length===0?_:this.postulate(d.targetPath,_,"?")}const y=this.isRemoveCall(i,t);if(y){this.removeSubtree(y.targetPath);return}const v=this.isNoiseScopeCall(i,t);if(v){this.localNoises[v.scopeKey]=t;const p=v.scopeKey?v.scopeKey.split(".").filter(Boolean):[];return this.commitThoughtOnly(p,"~","***","***")}const S=this.commitValueMapping(i,t,n);return this.invalidateFromPath(i),S}removeSubtree(r){this.clearDerivationsByPrefix(r);const t=r.join(".");for(const d of Object.keys(this.localSecrets)){if(t===""){delete this.localSecrets[d];continue}(d===t||d.startsWith(t+"."))&&delete this.localSecrets[d]}for(const d of Object.keys(this.localNoises)){if(t===""){delete this.localNoises[d];continue}(d===t||d.startsWith(t+"."))&&delete this.localNoises[d]}for(const d of Object.keys(this.encryptedBranches)){if(t===""){delete this.encryptedBranches[d];continue}if(d===t||d.startsWith(t+".")){delete this.encryptedBranches[d];continue}const y=d.split(".").filter(Boolean);if(!U(r,y)||r.length<=y.length)continue;const v=this.computeEffectiveSecret(y);if(!v)continue;const S=this.getBranchBlob(y);if(!S)continue;const p=G(S,v,y);if(!p||typeof p!="object")continue;const _=r.slice(y.length);let A=p;for(let B=0;B<_.length-1;B++){const F=_[B];if(!A||typeof A!="object"||!(F in A)){A=null;break}A=A[F]}if(A&&typeof A=="object"){delete A[_[_.length-1]];const B=ee(p,v,y);this.setBranchBlob(y,B)}}const n=r.join("."),i=Date.now(),o=this.computeEffectiveSecret(r),s=this.getPrevThoughtHash(),a=JSON.stringify({path:n,operator:"-",expression:"-",value:"-",effectiveSecret:o,prevHash:s}),l=V(a),c={path:n,operator:"-",expression:"-",value:"-",effectiveSecret:o,hash:l,prevHash:s,timestamp:i};this._shortTermMemory.push(c),this.rebuildIndex()}computeEffectiveSecret(r){let t=null,n=null;this.localNoises[""]!==void 0&&(t="",n=this.localNoises[""]);for(let o=1;o<=r.length;o++){const s=r.slice(0,o).join(".");this.localNoises[s]!==void 0&&(t=s,n=this.localNoises[s])}let i="root";n?i=V("noise::"+n):this.localSecrets[""]&&(i=V(i+"::"+this.localSecrets[""])),t===null||t===""||t.split(".").filter(Boolean).length;for(let o=1;o<=r.length;o++){const s=r.slice(0,o).join(".");if(this.localSecrets[s]){if(t!==null&&t!==""){const a=t+".";if(!(s===t||s.startsWith(a)))continue}i=V(i+"::"+this.localSecrets[s])}}return i==="root"?"":i}rebuildIndex(){const r={},t=this._shortTermMemory.map((n,i)=>({t:n,i})).sort((n,i)=>n.t.timestamp!==i.t.timestamp?n.t.timestamp-i.t.timestamp:n.t.hash!==i.t.hash?n.t.hash<i.t.hash?-1:1:n.i-i.i).map(n=>n.t);for(const n of t){const i=n.path,o=i.split(".").filter(Boolean),s=this.resolveBranchScope(o),a=s&&s.length>0&&U(o,s);if(n.operator==="-"){if(i===""){for(const c of Object.keys(r))delete r[c];continue}const l=i+".";for(const c of Object.keys(r))(c===i||c.startsWith(l))&&delete r[c];continue}a||(r[i]=n.value)}this.index=r}getIndex(r){return this.index[r.join(".")]}setIndex(r,t){this.index[r.join(".")]=t}resolveIndexPointerPath(r,t=8){let n=r;for(let i=0;i<t;i++){const o=this.getIndex(n);if(D(o)){n=o.__ptr.split(".").filter(Boolean);continue}let s=!1;for(let a=n.length-1;a>=0;a--){const l=n.slice(0,a),c=this.getIndex(l);if(!D(c))continue;const d=c.__ptr.split(".").filter(Boolean),y=n.slice(a);n=[...d,...y],s=!0;break}if(!s)return{path:n,raw:o}}return{path:n,raw:void 0}}setBranchBlob(r,t){const n=r.join(".");this.encryptedBranches[n]=t}getBranchBlob(r){const t=r.join(".");return this.encryptedBranches[t]}resolveBranchScope(r){let t=null;this.localSecrets[""]&&(t=[]);for(let n=1;n<=r.length;n++){const i=r.slice(0,n),o=i.join(".");this.localSecrets[o]&&(t=i)}return t}normalizeSelectorPath(r){const t=[];for(const n of r){const i=String(n).trim();if(!i)continue;const o=i.indexOf("[");if(o===-1){t.push(i);continue}const s=i.slice(0,o).trim(),a=i.slice(o);s&&t.push(s);const l=Array.from(a.matchAll(/\[([^\]]*)\]/g));if(l.map(d=>d[0]).join("")!==a){t.push(a);continue}for(const d of l){let y=(d[1]??"").trim();(y.startsWith('"')&&y.endsWith('"')||y.startsWith("'")&&y.endsWith("'"))&&(y=y.slice(1,-1)),y&&t.push(y)}}return t}pathContainsIterator(r){return r.some(t=>t.includes("[i]"))}substituteIteratorInPath(r,t){return r.map(n=>n.split("[i]").join(`[${t}]`))}substituteIteratorInExpression(r,t){return String(r??"").split("[i]").join(`[${t}]`)}collectIteratorIndices(r){const t=r.findIndex(o=>o.includes("[i]"));if(t===-1)return[];const n=[];for(let o=0;o<=t;o++){const s=r[o];if(o===t){const a=s.split("[i]").join("").trim();a&&n.push(a)}else n.push(s)}const i=new Set;for(const o of Object.keys(this.index)){const s=o.split(".").filter(Boolean);if(s.length<=n.length)continue;let a=!0;for(let l=0;l<n.length;l++)if(s[l]!==n[l]){a=!1;break}a&&i.add(s[n.length])}return Array.from(i).sort((o,s)=>{const a=Number(o),l=Number(s),c=Number.isFinite(a),d=Number.isFinite(l);return c&&d?a-l:c?-1:d?1:o.localeCompare(s)})}parseFilterExpression(r){const n=String(r??"").trim().match(/^(.+?)\s*(>=|<=|==|!=|>|<)\s*(.+)$/);if(!n)return null;const i=n[1].trim(),o=n[2],s=n[3].trim();return!i||!s?null:{left:i,op:o,right:s}}parseLogicalFilterExpression(r){const t=String(r??"").trim();if(!t)return null;const n=t.split(/\s*(&&|\|\|)\s*/).filter(s=>s.length>0);if(n.length===0)return null;const i=[],o=[];for(let s=0;s<n.length;s++)if(s%2===0){const a=this.parseFilterExpression(n[s]);if(!a)return null;i.push(a)}else{const a=n[s];if(a!=="&&"&&a!=="||")return null;o.push(a)}return i.length===0||o.length!==Math.max(0,i.length-1)?null:{clauses:i,ops:o}}compareValues(r,t,n){switch(t){case">":return r>n;case"<":return r<n;case">=":return r>=n;case"<=":return r<=n;case"==":return r==n;case"!=":return r!=n;default:return!1}}parseLiteralOrPath(r){const t=r.trim();if(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))return{kind:"literal",value:t.slice(1,-1)};if(t==="true")return{kind:"literal",value:!0};if(t==="false")return{kind:"literal",value:!1};if(t==="null")return{kind:"literal",value:null};const n=Number(t);return Number.isFinite(n)?{kind:"literal",value:n}:{kind:"path",parts:this.normalizeSelectorPath(t.split(".").filter(Boolean))}}resolveRelativeFirst(r,t){const n=this.readPath([...r,...t]);return n??this.readPath(t)}evaluateFilterClauseForScope(r,t){const n=this.normalizeSelectorPath(t.left.split(".").filter(Boolean)),i=this.resolveRelativeFirst(r,n);if(i==null)return!1;const o=this.parseLiteralOrPath(t.right),s=o.kind==="literal"?o.value:this.resolveRelativeFirst(r,o.parts);return s==null?!1:this.compareValues(i,t.op,s)}evaluateLogicalFilterForScope(r,t){const n=this.parseLogicalFilterExpression(t);if(!n)return!1;let i=this.evaluateFilterClauseForScope(r,n.clauses[0]);for(let o=1;o<n.clauses.length;o++){const s=this.evaluateFilterClauseForScope(r,n.clauses[o]);i=n.ops[o-1]==="&&"?i&&s:i||s}return i}collectChildrenForPrefix(r){const t=new Set;for(const n of Object.keys(this.index)){const i=n.split(".").filter(Boolean);if(i.length<=r.length)continue;let o=!0;for(let s=0;s<r.length;s++)if(i[s]!==r[s]){o=!1;break}o&&t.add(i[r.length])}return Array.from(t)}parseSelectorSegment(r){const t=String(r??"").trim(),n=t.indexOf("["),i=t.lastIndexOf("]");if(n<=0||i<=n||i!==t.length-1)return null;const o=t.slice(0,n).trim(),s=t.slice(n+1,i).trim();return!o||!s?null:{base:o,selector:s}}parseSelectorKeys(r){const t=r.trim();if(t.startsWith("[")&&t.endsWith("]")){const i=t.slice(1,-1).trim();return i?i.split(",").map(s=>s.trim()).filter(Boolean).map(s=>s.startsWith('"')&&s.endsWith('"')||s.startsWith("'")&&s.endsWith("'")?s.slice(1,-1):s):[]}const n=t.match(/^(-?\d+)\s*\.\.\s*(-?\d+)$/);if(n){const i=Number(n[1]),o=Number(n[2]);if(!Number.isFinite(i)||!Number.isFinite(o))return null;const s=i<=o?1:-1,a=[];if(Math.abs(o-i)>1e4)return null;for(let c=i;s>0?c<=o:c>=o;c+=s)a.push(String(c));return a}return null}parseTransformSelector(r){const n=r.trim().match(/^([A-Za-z_][A-Za-z0-9_]*)\s*=>\s*(.+)$/);if(!n)return null;const i=n[1].trim(),o=n[2].trim();return!i||!o?null:{varName:i,expr:o}}evaluateTransformPath(r){const t=r.findIndex(c=>{const d=this.parseSelectorSegment(c);return d?this.parseTransformSelector(d.selector)!==null:!1});if(t===-1)return;const n=this.parseSelectorSegment(r[t]);if(!n)return;const i=this.parseTransformSelector(n.selector);if(!i)return;const o=[...r.slice(0,t),n.base];if(r.slice(t+1).length>0)return;const a=this.collectChildrenForPrefix(o),l={};for(const c of a){const d=[...o,c],y=i.expr.replace(new RegExp(String.raw`\b${i.varName}\.`,"g"),""),v=this.tryEvaluateAssignExpression(d,y);v.ok&&(l[c]=v.value)}return l}evaluateSelectionPath(r){const t=r.findIndex(l=>this.parseSelectorSegment(l)!==null);if(t===-1)return;const n=this.parseSelectorSegment(r[t]);if(!n)return;const i=this.parseSelectorKeys(n.selector);if(i===null)return;const o=[...r.slice(0,t),n.base],s=r.slice(t+1),a={};for(const l of i){const c=[...o,l],d=s.length===0?this.buildPublicSubtree(c):this.readPath([...c,...s]);d!==void 0&&(a[l]=d)}return a}buildPublicSubtree(r){const t=r.join("."),n={};let i=!1;for(const[o,s]of Object.entries(this.index)){if(o===t)return s;if(!o.startsWith(t+"."))continue;const a=o.slice(t.length+1).split(".").filter(Boolean);let l=n;for(let c=0;c<a.length-1;c++){const d=a[c];(!l[d]||typeof l[d]!="object")&&(l[d]={}),l=l[d]}l[a[a.length-1]]=s,i=!0}return i?n:void 0}evaluateFilterPath(r){const t=r.findIndex(l=>this.parseLogicalFilterExpression(l)!==null);if(t===-1)return;const n=r[t],i=r.slice(0,t),o=r.slice(t+1);if(i.length===0)return;const s=this.collectChildrenForPrefix(i),a={};for(const l of s){const c=[...i,l];this.evaluateLogicalFilterForScope(c,n)&&(o.length===0?a[l]=this.buildPublicSubtree(c):a[l]=this.readPath([...c,...o]))}return a}pathContainsFilterSelector(r){return r.some(t=>{const n=this.parseSelectorSegment(t);return n?this.parseLogicalFilterExpression(n.selector)!==null:!1})}collectFilteredScopes(r){const t=r.findIndex(l=>{const c=this.parseSelectorSegment(l);return c?this.parseLogicalFilterExpression(c.selector)!==null:!1});if(t===-1)return[];const n=this.parseSelectorSegment(r[t]);if(!n)return[];const i=[...r.slice(0,t),n.base],o=r.slice(t+1),s=this.collectChildrenForPrefix(i),a=[];for(const l of s){const c=[...i,l];this.evaluateLogicalFilterForScope(c,n.selector)&&a.push([...c,...o])}return a}readPath(r){const t=this.evaluateTransformPath(r);if(t!==void 0)return t;const n=this.evaluateSelectionPath(r);if(n!==void 0)return n;r=this.normalizeSelectorPath(r);const i=this.evaluateFilterPath(r);if(i!==void 0)return i;const o=this.resolveBranchScope(r);if(o&&o.length>0&&U(r,o)){if(r.length===o.length)return;const d=this.computeEffectiveSecret(o);if(!d)return null;const y=this.getBranchBlob(o);if(!y)return;const v=G(y,d,o);if(!v||typeof v!="object")return;const S=r.slice(o.length);let p=v;for(const _ of S){if(!p||typeof p!="object")return;p=p[_]}return D(p)?this.readPath(p.__ptr.split(".").filter(Boolean)):(Qt(p),p)}const s=this.getIndex(r);if(D(s))return s;const a=this.resolveIndexPointerPath(r),l=a.raw;if(l===void 0)return a.path.length===r.length&&a.path.every((y,v)=>y===r[v])?void 0:this.readPath(a.path);if(D(l))return this.readPath(l.__ptr.split(".").filter(Boolean));if(Qt(l)||!Ie(l))return l;const c=this.computeEffectiveSecret(r);return c?G(l,c,r):null}}return re}));
1
+ (function(q,W){typeof exports=="object"&&typeof module<"u"?module.exports=W():typeof define=="function"&&define.amd?define(W):(q=typeof globalThis<"u"?globalThis:q||self,q.Me=W())})(this,(function(){"use strict";function W(f){return{__ptr:f}}function D(f){return!!f&&typeof f=="object"&&typeof f.__ptr=="string"&&f.__ptr.length>0}function ye(f){return{__id:f}}function Qt(f){return!!f&&typeof f=="object"&&typeof f.__id=="string"&&f.__id.length>0}function me(f){return!!f&&typeof f=="object"&&typeof f.path=="string"&&typeof f.hash=="string"&&typeof f.timestamp=="number"}function T(f){return f.length===0?{scope:[],leaf:null}:{scope:f.slice(0,-1),leaf:f[f.length-1]}}function U(f,r){if(r.length>f.length)return!1;for(let t=0;t<r.length;t++)if(f[t]!==r[t])return!1;return!0}function Z(f){const r=f.trim().toLowerCase();if(r.length<3||r.length>63)throw new Error(`Invalid username length: ${r.length}. Expected 3..63 characters.`);if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$/.test(r))throw new Error(`Invalid username. Use only [a-z0-9-], and start/end with [a-z0-9]. Got: ${f}`);if(r.includes("--"))throw new Error(`Invalid username. "--" is not allowed. Got: ${f}`);return r}function z(f,r){return f[r]?.kind??null}function ve(f,r){if(f.length!==1||f[0]!=="+"||!Array.isArray(r)||r.length<2)return null;const n=String(r[0]??"").trim(),i=String(r[1]??"").trim();return!n||!i||n==="+"?null:{op:n,kind:i}}function be(f,r,t){if(r.length===0)return null;const{scope:n,leaf:i}=T(r);return!i||z(f,i)!=="secret"||typeof t!="string"?null:{scopeKey:n.join(".")}}function ke(f,r,t){if(r.length===0)return null;const{scope:n,leaf:i}=T(r);return!i||z(f,i)!=="noise"||typeof t!="string"?null:{scopeKey:n.join(".")}}function Se(f,r,t){if(r.length===0)return null;const{leaf:n}=T(r);if(!n||z(f,n)!=="pointer"||typeof t!="string")return null;const i=t.trim().replace(/^\./,"");return i?{targetPath:i}:null}function Pe(f,r,t){if(r.length===1&&z(f,r[0])==="identity")return typeof t!="string"?null:{id:Z(t),targetPath:[]};const{scope:n,leaf:i}=T(r);return!i||z(f,i)!=="identity"||typeof t!="string"?null:{id:Z(t),targetPath:n}}function xe(f,r,t){if(r.length===0)return null;const{scope:n,leaf:i}=T(r);if(!i||z(f,i)!=="eval")return null;if(typeof t=="function")return{mode:"thunk",targetPath:n,thunk:t};if(Array.isArray(t)&&t.length>=2){const o=String(t[0]??"").trim(),s=String(t[1]??"").trim();return!o||!s?null:{mode:"assign",targetPath:n,name:o,expr:s}}return null}function _e(f,r,t){if(r.length===0)return null;const{scope:n,leaf:i}=T(r);if(!i||z(f,i)!=="query")return null;let o=null,s;if(Array.isArray(t)&&t.length>0)Array.isArray(t[0])&&(t.length===1||typeof t[1]=="function")?(o=t[0],s=typeof t[1]=="function"?t[1]:void 0):o=t;else return null;if(!Array.isArray(o)||o.length===0)return null;const a=o.map(l=>String(l)).map(l=>l.trim()).filter(l=>l.length>0);return a.length===0?null:{targetPath:n,paths:a,fn:s}}function Be(f,r,t){if(r.length===0)return null;const{scope:n,leaf:i}=T(r);if(!i||z(f,i)!=="remove")return null;if(t==null)return{targetPath:n};if(typeof t=="string"){const o=t.split(".").filter(Boolean);return{targetPath:[...n,...o]}}return null}var Ae=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ee(f){return f&&f.__esModule&&Object.prototype.hasOwnProperty.call(f,"default")?f.default:f}var Xt={exports:{}};var se;function Fe(){return se||(se=1,(function(f){(function(){var r="input is invalid type",t="finalize already called",n=typeof window=="object",i=n?window:{};i.JS_SHA3_NO_WINDOW&&(n=!1);var o=!n&&typeof self=="object",s=!i.JS_SHA3_NO_NODE_JS&&typeof process=="object"&&process.versions&&process.versions.node;s?i=Ae:o&&(i=self);for(var a=!i.JS_SHA3_NO_COMMON_JS&&!0&&f.exports,l=!i.JS_SHA3_NO_ARRAY_BUFFER&&typeof ArrayBuffer<"u",c="0123456789abcdef".split(""),d=[31,7936,2031616,520093696],y=[4,1024,262144,67108864],m=[1,256,65536,16777216],S=[6,1536,393216,100663296],p=[0,8,16,24],_=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],A=[224,256,384,512],B=[128,256],F=["hex","buffer","arrayBuffer","array","digest"],O={128:168,256:136},E=i.JS_SHA3_NO_NODE_JS||!Array.isArray?function(e){return Object.prototype.toString.call(e)==="[object Array]"}:Array.isArray,I=l&&(i.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)?function(e){return typeof e=="object"&&e.buffer&&e.buffer.constructor===ArrayBuffer}:ArrayBuffer.isView,j=function(e){var u=typeof e;if(u==="string")return[e,!0];if(u!=="object"||e===null)throw new Error(r);if(l&&e.constructor===ArrayBuffer)return[new Uint8Array(e),!1];if(!E(e)&&!I(e))throw new Error(r);return[e,!1]},$=function(e){return j(e)[0].length===0},ne=function(e){for(var u=[],h=0;h<e.length;++h)u[h]=e[h];return u},ce=function(e,u,h){return function(g){return new N(e,u,e).update(g)[h]()}},ue=function(e,u,h){return function(g,v){return new N(e,u,v).update(g)[h]()}},fe=function(e,u,h){return function(g,v,b,P){return M["cshake"+e].update(g,v,b,P)[h]()}},he=function(e,u,h){return function(g,v,b,P){return M["kmac"+e].update(g,v,b,P)[h]()}},Y=function(e,u,h,g){for(var v=0;v<F.length;++v){var b=F[v];e[b]=u(h,g,b)}return e},pe=function(e,u){var h=ce(e,u,"hex");return h.create=function(){return new N(e,u,e)},h.update=function(g){return h.create().update(g)},Y(h,ce,e,u)},Me=function(e,u){var h=ue(e,u,"hex");return h.create=function(g){return new N(e,u,g)},h.update=function(g,v){return h.create(v).update(g)},Y(h,ue,e,u)},Ke=function(e,u){var h=O[e],g=fe(e,u,"hex");return g.create=function(v,b,P){return $(b)&&$(P)?M["shake"+e].create(v):new N(e,u,v).bytepad([b,P],h)},g.update=function(v,b,P,k){return g.create(b,P,k).update(v)},Y(g,fe,e,u)},De=function(e,u){var h=O[e],g=he(e,u,"hex");return g.create=function(v,b,P){return new oe(e,u,b).bytepad(["KMAC",P],h).bytepad([v],h)},g.update=function(v,b,P,k){return g.create(v,P,k).update(b)},Y(g,he,e,u)},de=[{name:"keccak",padding:m,bits:A,createMethod:pe},{name:"sha3",padding:S,bits:A,createMethod:pe},{name:"shake",padding:d,bits:B,createMethod:Me},{name:"cshake",padding:y,bits:B,createMethod:Ke},{name:"kmac",padding:y,bits:B,createMethod:De}],M={},H=[],K=0;K<de.length;++K)for(var R=de[K],Q=R.bits,L=0;L<Q.length;++L){var ie=R.name+"_"+Q[L];if(H.push(ie),M[ie]=R.createMethod(Q[L],R.padding),R.name!=="sha3"){var ge=R.name+Q[L];H.push(ge),M[ge]=M[ie]}}function N(e,u,h){this.blocks=[],this.s=[],this.padding=u,this.outputBits=h,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(e<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=h>>5,this.extraBytes=(h&31)>>3;for(var g=0;g<50;++g)this.s[g]=0}N.prototype.update=function(e){if(this.finalized)throw new Error(t);var u=j(e);e=u[0];for(var h=u[1],g=this.blocks,v=this.byteCount,b=e.length,P=this.blockCount,k=0,C=this.s,x,w;k<b;){if(this.reset)for(this.reset=!1,g[0]=this.block,x=1;x<P+1;++x)g[x]=0;if(h)for(x=this.start;k<b&&x<v;++k)w=e.charCodeAt(k),w<128?g[x>>2]|=w<<p[x++&3]:w<2048?(g[x>>2]|=(192|w>>6)<<p[x++&3],g[x>>2]|=(128|w&63)<<p[x++&3]):w<55296||w>=57344?(g[x>>2]|=(224|w>>12)<<p[x++&3],g[x>>2]|=(128|w>>6&63)<<p[x++&3],g[x>>2]|=(128|w&63)<<p[x++&3]):(w=65536+((w&1023)<<10|e.charCodeAt(++k)&1023),g[x>>2]|=(240|w>>18)<<p[x++&3],g[x>>2]|=(128|w>>12&63)<<p[x++&3],g[x>>2]|=(128|w>>6&63)<<p[x++&3],g[x>>2]|=(128|w&63)<<p[x++&3]);else for(x=this.start;k<b&&x<v;++k)g[x>>2]|=e[k]<<p[x++&3];if(this.lastByteIndex=x,x>=v){for(this.start=x-v,this.block=g[P],x=0;x<P;++x)C[x]^=g[x];J(C),this.reset=!0}else this.start=x}return this},N.prototype.encode=function(e,u){var h=e&255,g=1,v=[h];for(e=e>>8,h=e&255;h>0;)v.unshift(h),e=e>>8,h=e&255,++g;return u?v.push(g):v.unshift(g),this.update(v),v.length},N.prototype.encodeString=function(e){var u=j(e);e=u[0];var h=u[1],g=0,v=e.length;if(h)for(var b=0;b<e.length;++b){var P=e.charCodeAt(b);P<128?g+=1:P<2048?g+=2:P<55296||P>=57344?g+=3:(P=65536+((P&1023)<<10|e.charCodeAt(++b)&1023),g+=4)}else g=v;return g+=this.encode(g*8),this.update(e),g},N.prototype.bytepad=function(e,u){for(var h=this.encode(u),g=0;g<e.length;++g)h+=this.encodeString(e[g]);var v=(u-h%u)%u,b=[];return b.length=v,this.update(b),this},N.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var e=this.blocks,u=this.lastByteIndex,h=this.blockCount,g=this.s;if(e[u>>2]|=this.padding[u&3],this.lastByteIndex===this.byteCount)for(e[0]=e[h],u=1;u<h+1;++u)e[u]=0;for(e[h-1]|=2147483648,u=0;u<h;++u)g[u]^=e[u];J(g)}},N.prototype.toString=N.prototype.hex=function(){this.finalize();for(var e=this.blockCount,u=this.s,h=this.outputBlocks,g=this.extraBytes,v=0,b=0,P="",k;b<h;){for(v=0;v<e&&b<h;++v,++b)k=u[v],P+=c[k>>4&15]+c[k&15]+c[k>>12&15]+c[k>>8&15]+c[k>>20&15]+c[k>>16&15]+c[k>>28&15]+c[k>>24&15];b%e===0&&(u=ne(u),J(u),v=0)}return g&&(k=u[v],P+=c[k>>4&15]+c[k&15],g>1&&(P+=c[k>>12&15]+c[k>>8&15]),g>2&&(P+=c[k>>20&15]+c[k>>16&15])),P},N.prototype.arrayBuffer=function(){this.finalize();var e=this.blockCount,u=this.s,h=this.outputBlocks,g=this.extraBytes,v=0,b=0,P=this.outputBits>>3,k;g?k=new ArrayBuffer(h+1<<2):k=new ArrayBuffer(P);for(var C=new Uint32Array(k);b<h;){for(v=0;v<e&&b<h;++v,++b)C[b]=u[v];b%e===0&&(u=ne(u),J(u))}return g&&(C[b]=u[v],k=k.slice(0,P)),k},N.prototype.buffer=N.prototype.arrayBuffer,N.prototype.digest=N.prototype.array=function(){this.finalize();for(var e=this.blockCount,u=this.s,h=this.outputBlocks,g=this.extraBytes,v=0,b=0,P=[],k,C;b<h;){for(v=0;v<e&&b<h;++v,++b)k=b<<2,C=u[v],P[k]=C&255,P[k+1]=C>>8&255,P[k+2]=C>>16&255,P[k+3]=C>>24&255;b%e===0&&(u=ne(u),J(u))}return g&&(k=b<<2,C=u[v],P[k]=C&255,g>1&&(P[k+1]=C>>8&255),g>2&&(P[k+2]=C>>16&255)),P};function oe(e,u,h){N.call(this,e,u,h)}oe.prototype=new N,oe.prototype.finalize=function(){return this.encode(this.outputBits,!0),N.prototype.finalize.call(this)};var J=function(e){var u,h,g,v,b,P,k,C,x,w,X,tt,et,rt,nt,it,ot,st,lt,at,ct,ut,ft,ht,pt,dt,gt,yt,mt,vt,bt,kt,St,Pt,xt,_t,Bt,At,Et,Ft,wt,Nt,Ct,Ot,Tt,It,jt,zt,Mt,Kt,Dt,Rt,Wt,Vt,$t,Ht,Lt,Jt,qt,Ut,Zt,Gt,Yt;for(g=0;g<48;g+=2)v=e[0]^e[10]^e[20]^e[30]^e[40],b=e[1]^e[11]^e[21]^e[31]^e[41],P=e[2]^e[12]^e[22]^e[32]^e[42],k=e[3]^e[13]^e[23]^e[33]^e[43],C=e[4]^e[14]^e[24]^e[34]^e[44],x=e[5]^e[15]^e[25]^e[35]^e[45],w=e[6]^e[16]^e[26]^e[36]^e[46],X=e[7]^e[17]^e[27]^e[37]^e[47],tt=e[8]^e[18]^e[28]^e[38]^e[48],et=e[9]^e[19]^e[29]^e[39]^e[49],u=tt^(P<<1|k>>>31),h=et^(k<<1|P>>>31),e[0]^=u,e[1]^=h,e[10]^=u,e[11]^=h,e[20]^=u,e[21]^=h,e[30]^=u,e[31]^=h,e[40]^=u,e[41]^=h,u=v^(C<<1|x>>>31),h=b^(x<<1|C>>>31),e[2]^=u,e[3]^=h,e[12]^=u,e[13]^=h,e[22]^=u,e[23]^=h,e[32]^=u,e[33]^=h,e[42]^=u,e[43]^=h,u=P^(w<<1|X>>>31),h=k^(X<<1|w>>>31),e[4]^=u,e[5]^=h,e[14]^=u,e[15]^=h,e[24]^=u,e[25]^=h,e[34]^=u,e[35]^=h,e[44]^=u,e[45]^=h,u=C^(tt<<1|et>>>31),h=x^(et<<1|tt>>>31),e[6]^=u,e[7]^=h,e[16]^=u,e[17]^=h,e[26]^=u,e[27]^=h,e[36]^=u,e[37]^=h,e[46]^=u,e[47]^=h,u=w^(v<<1|b>>>31),h=X^(b<<1|v>>>31),e[8]^=u,e[9]^=h,e[18]^=u,e[19]^=h,e[28]^=u,e[29]^=h,e[38]^=u,e[39]^=h,e[48]^=u,e[49]^=h,rt=e[0],nt=e[1],It=e[11]<<4|e[10]>>>28,jt=e[10]<<4|e[11]>>>28,yt=e[20]<<3|e[21]>>>29,mt=e[21]<<3|e[20]>>>29,Ut=e[31]<<9|e[30]>>>23,Zt=e[30]<<9|e[31]>>>23,Nt=e[40]<<18|e[41]>>>14,Ct=e[41]<<18|e[40]>>>14,Pt=e[2]<<1|e[3]>>>31,xt=e[3]<<1|e[2]>>>31,it=e[13]<<12|e[12]>>>20,ot=e[12]<<12|e[13]>>>20,zt=e[22]<<10|e[23]>>>22,Mt=e[23]<<10|e[22]>>>22,vt=e[33]<<13|e[32]>>>19,bt=e[32]<<13|e[33]>>>19,Gt=e[42]<<2|e[43]>>>30,Yt=e[43]<<2|e[42]>>>30,Vt=e[5]<<30|e[4]>>>2,$t=e[4]<<30|e[5]>>>2,_t=e[14]<<6|e[15]>>>26,Bt=e[15]<<6|e[14]>>>26,st=e[25]<<11|e[24]>>>21,lt=e[24]<<11|e[25]>>>21,Kt=e[34]<<15|e[35]>>>17,Dt=e[35]<<15|e[34]>>>17,kt=e[45]<<29|e[44]>>>3,St=e[44]<<29|e[45]>>>3,ht=e[6]<<28|e[7]>>>4,pt=e[7]<<28|e[6]>>>4,Ht=e[17]<<23|e[16]>>>9,Lt=e[16]<<23|e[17]>>>9,At=e[26]<<25|e[27]>>>7,Et=e[27]<<25|e[26]>>>7,at=e[36]<<21|e[37]>>>11,ct=e[37]<<21|e[36]>>>11,Rt=e[47]<<24|e[46]>>>8,Wt=e[46]<<24|e[47]>>>8,Ot=e[8]<<27|e[9]>>>5,Tt=e[9]<<27|e[8]>>>5,dt=e[18]<<20|e[19]>>>12,gt=e[19]<<20|e[18]>>>12,Jt=e[29]<<7|e[28]>>>25,qt=e[28]<<7|e[29]>>>25,Ft=e[38]<<8|e[39]>>>24,wt=e[39]<<8|e[38]>>>24,ut=e[48]<<14|e[49]>>>18,ft=e[49]<<14|e[48]>>>18,e[0]=rt^~it&st,e[1]=nt^~ot&lt,e[10]=ht^~dt&yt,e[11]=pt^~gt&mt,e[20]=Pt^~_t&At,e[21]=xt^~Bt&Et,e[30]=Ot^~It&zt,e[31]=Tt^~jt&Mt,e[40]=Vt^~Ht&Jt,e[41]=$t^~Lt&qt,e[2]=it^~st&at,e[3]=ot^~lt&ct,e[12]=dt^~yt&vt,e[13]=gt^~mt&bt,e[22]=_t^~At&Ft,e[23]=Bt^~Et&wt,e[32]=It^~zt&Kt,e[33]=jt^~Mt&Dt,e[42]=Ht^~Jt&Ut,e[43]=Lt^~qt&Zt,e[4]=st^~at&ut,e[5]=lt^~ct&ft,e[14]=yt^~vt&kt,e[15]=mt^~bt&St,e[24]=At^~Ft&Nt,e[25]=Et^~wt&Ct,e[34]=zt^~Kt&Rt,e[35]=Mt^~Dt&Wt,e[44]=Jt^~Ut&Gt,e[45]=qt^~Zt&Yt,e[6]=at^~ut&rt,e[7]=ct^~ft&nt,e[16]=vt^~kt&ht,e[17]=bt^~St&pt,e[26]=Ft^~Nt&Pt,e[27]=wt^~Ct&xt,e[36]=Kt^~Rt&Ot,e[37]=Dt^~Wt&Tt,e[46]=Ut^~Gt&Vt,e[47]=Zt^~Yt&$t,e[8]=ut^~rt&it,e[9]=ft^~nt&ot,e[18]=kt^~ht&dt,e[19]=St^~pt&gt,e[28]=Nt^~Pt&_t,e[29]=Ct^~xt&Bt,e[38]=Rt^~Ot&It,e[39]=Wt^~Tt&jt,e[48]=Gt^~Vt&Ht,e[49]=Yt^~$t&Lt,e[0]^=_[g],e[1]^=_[g+1]};if(a)f.exports=M;else for(K=0;K<H.length;++K)i[H[K]]=M[H[K]]})()})(Xt)),Xt.exports}var we=Fe();const Ne=Ee(we),{keccak256:le}=Ne;function te(f){return new TextEncoder().encode(f)}function Ce(f){const r=f.startsWith("0x")?f.slice(2):f,t=new Uint8Array(r.length/2);for(let n=0;n<t.length;n++)t[n]=parseInt(r.substring(n*2,n*2+2),16);return t}function Oe(f){let r="";for(let t=0;t<f.length;t++)r+=f[t].toString(16).padStart(2,"0");return"0x"+r}function ee(f,r,t){const n=JSON.stringify(f),i=te(n),o=le(r+":"+t.join(".")),s=te(o),a=new Uint8Array(i.length);for(let l=0;l<i.length;l++)a[l]=i[l]^s[l%s.length];return Oe(a)}function G(f,r,t){try{const n=Ce(f),i=le(r+":"+t.join(".")),o=te(i),s=new Uint8Array(n.length);for(let l=0;l<n.length;l++)s[l]=n[l]^o[l%o.length];const a=new TextDecoder().decode(s);return JSON.parse(a)}catch{return null}}function Te(f){if(typeof f!="string"||!f.startsWith("0x"))return!1;const r=f.slice(2);return r.length<2||r.length%2!==0?!1:/^[0-9a-fA-F]+$/.test(r)}function Ie(f){const r=[];let t="",n=0,i=null;for(let s=0;s<f.length;s++){const a=f[s];if(i){t+=a,a===i&&(i=null);continue}if(a==='"'||a==="'"){i=a,t+=a;continue}if(a==="["){n++,t+=a;continue}if(a==="]"){n=Math.max(0,n-1),t+=a;continue}if(a==="."&&n===0){const l=t.trim();l&&r.push(l),t="";continue}t+=a}const o=t.trim();return o&&r.push(o),r}function je(f,r,t){if(r.length===0){if(t.length===1&&typeof t[0]=="string"){const d=t[0].trim(),y=d.startsWith("_")||d.startsWith("~")||d.startsWith("@"),m=d.includes("."),S=/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(d);if(m||y||S){const p=Ie(d);return f.readPath(p)}}if(t.length===0)return f.createProxy([]);const l=f.normalizeArgs(t),c=f.postulate([],l);return c!==void 0?c:f.createProxy([])}const n=f.normalizeArgs(t),i=f.postulate(r,n),{scope:o,leaf:s}=f.splitPath(r),a=s?f.opKind(s):null;if(f.isThought(i)){const l=a?o:r;return f.createProxy(l)}return i!==void 0?i:f.createProxy(r)}function ze(f,r,t={}){const{path:n,expression:i}=r,o=ve(n,i);if(o)return{kind:"return",value:{define:o}};const s=be(f,n,i);if(s)return{kind:"commit",instructions:[{path:s.scopeKey?s.scopeKey.split(".").filter(Boolean):[],op:"secret",value:i}]};const a=ke(f,n,i);if(a)return{kind:"commit",instructions:[{path:a.scopeKey?a.scopeKey.split(".").filter(Boolean):[],op:"noise",value:i}]};const l=Se(f,n,i);if(l){const{scope:S}=T(n);return{kind:"commit",instructions:[{path:S,op:"ptr",value:W(l.targetPath)}]}}const c=Pe(f,n,i);if(c)return{kind:"commit",instructions:[{path:c.targetPath,op:"id",value:ye(c.id)}]};const d=Be(f,n,i);if(d)return{kind:"commit",instructions:[{path:d.targetPath,op:"remove",value:"-"}]};const y=xe(f,n,i);if(y){if(y.mode==="assign")return{kind:"commit",instructions:[{path:[...y.targetPath,y.name],op:"derive",value:{kind:"expr",source:y.expr}}]};if(!t.evaluateThunk)throw new Error('Non-serializable derivation: "=" thunk requires `evaluateThunk` or serializable DNA.');const S=t.evaluateThunk(y.thunk);return y.targetPath.length===0?{kind:"return",value:S}:{kind:"commit",instructions:[{path:y.targetPath,op:"derive",value:S}]}}const m=_e(f,n,i);if(m){if(!t.readPath)return{kind:"commit",instructions:[{path:m.targetPath,op:"query",value:{paths:m.paths}}]};const S=m.paths.map(_=>t.readPath(_.split(".").filter(Boolean))),p=m.fn?m.fn(...S):S;return m.targetPath.length===0?{kind:"return",value:p}:{kind:"commit",instructions:[{path:m.targetPath,op:"query",value:p}]}}return{kind:"commit",instructions:[{path:n,op:"set",value:i}]}}const ae="+";function V(f){let r=2166136261;for(let t=0;t<f.length;t++)r^=f.charCodeAt(t),r=Math.imul(r,16777619);return("00000000"+(r>>>0).toString(16)).slice(-8)}class re{constructor(r){this.localSecrets={},this.localNoises={},this.encryptedBranches={},this.index={},this._shortTermMemory=[],this.derivations={},this.refSubscribers={},this.unsafeEval=!1,this.operators={_:{kind:"secret"},"~":{kind:"noise"},__:{kind:"pointer"},"->":{kind:"pointer"},"@":{kind:"identity"},"=":{kind:"eval"},"?":{kind:"query"},"-":{kind:"remove"}},this.localSecrets={},this.localNoises={},this.encryptedBranches={},this.index={},this.operators={_:{kind:"secret"},"~":{kind:"noise"},__:{kind:"pointer"},"->":{kind:"pointer"},"@":{kind:"identity"},"=":{kind:"eval"},"?":{kind:"query"},"-":{kind:"remove"}},this._shortTermMemory=[],r!==void 0&&this.postulate([],r),this.rebuildIndex();const t=this.createProxy([]);return Object.setPrototypeOf(t,re.prototype),Object.assign(t,this),t}get shortTermMemory(){return this._shortTermMemory}get memory(){return this._shortTermMemory}inspect(r){const t=r?.last,n=typeof t=="number"&&Number.isFinite(t)&&t>0?this._shortTermMemory.slice(-Math.floor(t)):this._shortTermMemory.slice();return{memory:n,thoughts:n,index:{...this.index},encryptedScopes:Object.keys(this.encryptedBranches),secretScopes:Object.keys(this.localSecrets),noiseScopes:Object.keys(this.localNoises)}}explain(r){const t=this.normalizeSelectorPath(String(r??"").split(".").filter(Boolean)),n=t.join("."),i=this.readPath(t),o=this.derivations[n];if(!o)return{path:n,value:i,derivation:null,meta:{dependsOn:[]}};const s=o.refs.map(a=>{const l=this.normalizeSelectorPath(a.path.split(".").filter(Boolean)),c=this.resolveBranchScope(l),d=!!(c&&c.length>0&&U(l,c)),y=this.readPath(l);return{label:a.label,path:a.path,value:d?"●●●●":y,origin:d?"stealth":"public",masked:d}});return{path:n,value:i,derivation:{expression:o.expression,inputs:s},meta:{dependsOn:o.refs.map(a=>a.path),lastComputedAt:o.lastComputedAt}}}cloneValue(r){const t=globalThis.structuredClone;return typeof t=="function"?t(r):JSON.parse(JSON.stringify(r))}exportSnapshot(){return this.cloneValue({memory:this._shortTermMemory,shortTermMemory:this._shortTermMemory,localSecrets:this.localSecrets,localNoises:this.localNoises,encryptedBranches:this.encryptedBranches,operators:this.operators})}importSnapshot(r){const t=this.cloneValue(r??{});this._shortTermMemory=Array.isArray(t.memory)?t.memory:Array.isArray(t.shortTermMemory)?t.shortTermMemory:[],this.localSecrets=t.localSecrets&&typeof t.localSecrets=="object"?t.localSecrets:{},this.localNoises=t.localNoises&&typeof t.localNoises=="object"?t.localNoises:{},this.encryptedBranches=t.encryptedBranches&&typeof t.encryptedBranches=="object"?t.encryptedBranches:{},this.derivations={},this.refSubscribers={};const n={_:{kind:"secret"},"~":{kind:"noise"},__:{kind:"pointer"},"->":{kind:"pointer"},"@":{kind:"identity"},"=":{kind:"eval"},"?":{kind:"query"},"-":{kind:"remove"}};this.operators=t.operators&&typeof t.operators=="object"?{...n,...t.operators}:n,this.rebuildIndex()}rehydrate(r){this.importSnapshot(r)}replayThoughts(r){this.localSecrets={},this.localNoises={},this.encryptedBranches={},this.index={},this._shortTermMemory=[],this.derivations={},this.refSubscribers={};for(const t of r||[]){const n=String(t.path||"").split(".").filter(Boolean);if(t.operator==="_"){this.postulate([...n,"_"],typeof t.expression=="string"?t.expression:"***");continue}if(t.operator==="~"){this.postulate([...n,"~"],typeof t.expression=="string"?t.expression:"***");continue}if(t.operator==="@"){const i=t.expression&&t.expression.__id||t.value&&t.value.__id||t.value;typeof i=="string"&&i.length>0&&this.postulate([...n,"@"],i);continue}if(t.operator==="__"||t.operator==="->"){const i=t.expression&&t.expression.__ptr||t.value&&t.value.__ptr||t.value;typeof i=="string"&&i.length>0&&this.postulate([...n,"__"],i);continue}if(t.operator==="-"){this.removeSubtree(n);continue}if(t.operator==="="||t.operator==="?"){this.postulate(n,t.value,t.operator);continue}this.postulate(n,t.expression,t.operator)}this.rebuildIndex()}replayMemory(r){this.replayThoughts(r)}isRemoveCall(r,t){if(r.length===0)return null;const{scope:n,leaf:i}=T(r);if(!i||this.opKind(i)!=="remove")return null;if(t==null)return{targetPath:n};if(typeof t=="string"){const o=t.split(".").filter(Boolean);return{targetPath:[...n,...o]}}return null}createProxy(r){const t=this,n=(...i)=>je({createProxy:o=>t.createProxy(o),normalizeArgs:o=>t.normalizeArgs(o),readPath:o=>t.readPath(o),postulate:(o,s)=>t.postulate(o,s),opKind:o=>t.opKind(o),splitPath:T,isThought:me},r,i);return new Proxy(n,{get(i,o){if(typeof o=="symbol")return i[o];if(o in t){const a=t[o];return typeof a=="function"?a.bind(t):a}const s=[...r,String(o)];return t.createProxy(s)},apply(i,o,s){return Reflect.apply(i,void 0,s)}})}normalizeArgs(r){if(r.length!==0)return r.length===1?r[0]:r}opKind(r){return this.operators[r]?.kind??null}isSecretScopeCall(r,t){if(r.length===0)return null;const{scope:n,leaf:i}=T(r);return!i||this.opKind(i)!=="secret"||typeof t!="string"?null:{scopeKey:n.join(".")}}isNoiseScopeCall(r,t){if(r.length===0)return null;const{scope:n,leaf:i}=T(r);return!i||this.opKind(i)!=="noise"||typeof t!="string"?null:{scopeKey:n.join(".")}}isPointerCall(r,t){if(r.length===0)return null;const{leaf:n}=T(r);if(!n||this.opKind(n)!=="pointer"||typeof t!="string")return null;const i=t.trim().replace(/^\./,"");return i?{targetPath:i}:null}isIdentityCall(r,t){if(r.length===1&&this.opKind(r[0])==="identity")return typeof t!="string"?null:{id:Z(t),targetPath:[]};const{scope:n,leaf:i}=T(r);return!i||this.opKind(i)!=="identity"||typeof t!="string"?null:{id:Z(t),targetPath:n}}isEvalCall(r,t){if(r.length===0)return null;const{scope:n,leaf:i}=T(r);if(!i||this.opKind(i)!=="eval")return null;if(typeof t=="function")return{mode:"thunk",targetPath:n,thunk:t};if(Array.isArray(t)&&t.length>=2){const o=String(t[0]??"").trim(),s=String(t[1]??"").trim();return!o||!s?null:{mode:"assign",targetPath:n,name:o,expr:s}}return null}isQueryCall(r,t){if(r.length===0)return null;const{scope:n,leaf:i}=T(r);if(!i||this.opKind(i)!=="query")return null;let o=null,s;if(Array.isArray(t)&&t.length>0)Array.isArray(t[0])&&(t.length===1||typeof t[1]=="function")?(o=t[0],s=typeof t[1]=="function"?t[1]:void 0):o=t;else return null;if(!Array.isArray(o)||o.length===0)return null;const a=o.map(l=>String(l)).map(l=>l.trim()).filter(l=>l.length>0);return a.length===0?null:{targetPath:n,paths:a,fn:s}}isDefineOpCall(r,t){if(r.length!==1||r[0]!==ae||!Array.isArray(t)||t.length<2)return null;const i=String(t[0]??"").trim(),o=String(t[1]??"").trim();return!i||!o||i===ae?null:{op:i,kind:o}}getPrevThoughtHash(){return this._shortTermMemory[this._shortTermMemory.length-1]?.hash??""}extractExpressionRefs(r){const t=String(r??"").trim();if(!t)return[];const n=String.raw`[A-Za-z_][A-Za-z0-9_]*(?:\[(?:"[^"]*"|'[^']*'|[^\]]+)\])*`,i=new RegExp(String.raw`__ptr(?:\.${n})*|${n}(?:\.${n})*`,"g"),o=new Set(["true","false","null","undefined","NaN","Infinity"]),s=new Set,a=t.match(i)||[];for(const l of a)o.has(l)||s.add(l);return Array.from(s)}resolveRefPath(r,t){if(!r||r.startsWith("__ptr."))return null;const n=this.normalizeSelectorPath(r.split(".").filter(Boolean));if(n.length===0)return null;const i=this.normalizeSelectorPath([...t,...n]).join("."),o=this.normalizeSelectorPath(n).join(".");return r.includes(".")?o:i}unregisterDerivation(r){const t=this.derivations[r];if(t){for(const n of t.refs){const i=this.refSubscribers[n.path]||[];this.refSubscribers[n.path]=i.filter(o=>o!==r),this.refSubscribers[n.path].length===0&&delete this.refSubscribers[n.path]}delete this.derivations[r]}}registerDerivation(r,t,n){const i=r.join(".");this.unregisterDerivation(i);const o=this.extractExpressionRefs(n),s=[],a=new Set;for(const l of o){const c=this.resolveRefPath(l,t);if(!c||a.has(c))continue;a.add(c),s.push({label:l,path:c});const d=this.refSubscribers[c]||[];d.includes(i)||d.push(i),this.refSubscribers[c]=d}this.derivations[i]={expression:n,evalScope:[...t],refs:s,lastComputedAt:Date.now()}}recomputeTarget(r){const t=this.derivations[r];if(!t)return!1;const n=this.normalizeSelectorPath(r.split(".").filter(Boolean)),i=this.tryEvaluateAssignExpression(t.evalScope,t.expression);return this.postulate(n,i.ok?i.value:t.expression,"="),t.lastComputedAt=Date.now(),!0}invalidateFromPath(r){const t=this.normalizeSelectorPath(r).join(".");if(!t)return;const n=[t],i=new Set;for(;n.length>0;){const o=n.shift(),s=this.refSubscribers[o]||[];for(const a of s){if(i.has(a))continue;i.add(a),this.recomputeTarget(a)&&n.push(a)}}}clearDerivationsByPrefix(r){const t=r.join(".");for(const n of Object.keys(this.derivations))(t===""||n===t||n.startsWith(t+"."))&&this.unregisterDerivation(n)}commitThoughtOnly(r,t,n,i){const o=r.join("."),s=this.computeEffectiveSecret(r),a=this.getPrevThoughtHash(),l=JSON.stringify({path:o,operator:t,expression:n,value:i,effectiveSecret:s,prevHash:a}),c=V(l),d=Date.now(),y={path:o,operator:t,expression:n,value:i,effectiveSecret:s,hash:c,prevHash:a,timestamp:d};return this._shortTermMemory.push(y),this.rebuildIndex(),y}commitValueMapping(r,t,n=null){let i=t;const o=r.join("."),s=this.computeEffectiveSecret(r),a=this.resolveBranchScope(r);if(a&&a.length===0&&this.localSecrets[""]&&this.localSecrets[o],a&&a.length>0){const l=this.computeEffectiveSecret(a),c=r.slice(a.length),d=this.getBranchBlob(a);let y={};if(d&&l){const m=G(d,l,a);m&&typeof m=="object"&&(y=m)}if(c.length===0)(typeof y!="object"||y===null)&&(y={}),y.expression=t;else{let m=y;for(let S=0;S<c.length-1;S++){const p=c[S];(!m[p]||typeof m[p]!="object")&&(m[p]={}),m=m[p]}m[c[c.length-1]]=t}if(l){const m=ee(y,l,a);this.setBranchBlob(a,m)}i=t}else if(s){const l=n!=="="&&n!=="?";D(t)||Qt(t)||!l?i=t:i=ee(t,s,r)}else i=t;return this.commitThoughtOnly(r,n,t,i)}commitMapping(r,t=null){switch(r.op){case"set":return this.commitValueMapping(r.path,r.value,t);case"ptr":return this.commitValueMapping(r.path,r.value,"__");case"id":return this.commitValueMapping(r.path,r.value,"@");case"secret":{if(typeof r.value!="string")return;const n=r.path.join(".");return this.localSecrets[n]=r.value,this.commitThoughtOnly(r.path,"_","***","***")}default:return}}tryResolveEvalTokenValue(r,t){if(r.startsWith("__ptr.")){const s=this.getIndex(t);if(!D(s))return{ok:!1};const a=r.slice(6).split(".").filter(Boolean),l=[...s.__ptr.split(".").filter(Boolean),...a],c=this.readPath(l);return c==null?{ok:!1}:{ok:!0,value:c}}const n=r.split(".").filter(Boolean),i=[...t,...n];let o=this.readPath(i);return o==null&&(o=this.readPath(n)),o==null?{ok:!1}:{ok:!0,value:o}}tokenizeEvalExpression(r){const t=[],n=String.raw`[A-Za-z_][A-Za-z0-9_]*(?:\[(?:"[^"]*"|'[^']*'|[^\]]+)\])*`,i=new RegExp(String.raw`^(?:__ptr(?:\.${n})*|${n}(?:\.${n})*)`),o={true:!0,false:!1,null:null,undefined:void 0,NaN:NaN,Infinity:1/0},s=new Set([">=","<=","==","!=","&&","||"]),a=new Set(["+","-","*","/","%","<",">","!"]);let l=0;for(;l<r.length;){const c=r[l];if(/\s/.test(c)){l++;continue}if(c==="("){t.push({kind:"lparen"}),l++;continue}if(c===")"){t.push({kind:"rparen"}),l++;continue}const d=r.slice(l,l+2);if(s.has(d)){t.push({kind:"op",value:d}),l+=2;continue}if(a.has(c)){t.push({kind:"op",value:c}),l++;continue}if(/\d/.test(c)||c==="."&&/\d/.test(r[l+1]??"")){let m=l;for(;m<r.length&&/[0-9]/.test(r[m]);)m++;if(r[m]===".")for(m++;m<r.length&&/[0-9]/.test(r[m]);)m++;if(r[m]==="e"||r[m]==="E"){let p=m+1;(r[p]==="+"||r[p]==="-")&&p++;let _=!1;for(;p<r.length&&/[0-9]/.test(r[p]);)_=!0,p++;if(!_)return null;m=p}const S=Number(r.slice(l,m));if(!Number.isFinite(S))return null;t.push({kind:"literal",value:S}),l=m;continue}const y=r.slice(l).match(i);if(y&&y[0]){const m=y[0];Object.prototype.hasOwnProperty.call(o,m)?t.push({kind:"literal",value:o[m]}):t.push({kind:"identifier",value:m}),l+=m.length;continue}return null}return t}tryEvaluateAssignExpression(r,t){const n=String(t??"").trim();if(!n)return{ok:!1};if(!/^[A-Za-z0-9_\s+\-*/%().<>=!&|\[\]"']+$/.test(n))return{ok:!1};if(this.unsafeEval)return{ok:!1};const i=this.tokenizeEvalExpression(n);if(!i||i.length===0)return{ok:!1};const o={"u-":7,"!":7,"*":6,"/":6,"%":6,"+":5,"-":5,"<":4,"<=":4,">":4,">=":4,"==":3,"!=":3,"&&":2,"||":1},s=new Set(["u-","!"]),a=[],l=[];let c="start";for(const S of i){if(S.kind==="literal"||S.kind==="identifier"){a.push(S),c="value";continue}if(S.kind==="lparen"){l.push(S),c="lparen";continue}if(S.kind==="rparen"){let _=!1;for(;l.length>0;){const A=l.pop();if(A.kind==="lparen"){_=!0;break}a.push(A)}if(!_)return{ok:!1};c="rparen";continue}let p=S.value;if(p==="-"&&(c==="start"||c==="op"||c==="lparen"))p="u-";else{if(p==="!"&&(c==="value"||c==="rparen"))return{ok:!1};if(p!=="!"&&(c==="start"||c==="op"||c==="lparen"))return{ok:!1}}for(;l.length>0;){const _=l[l.length-1];if(_.kind!=="op")break;const A=o[_.value]??-1,B=o[p]??-1;if(B<0)return{ok:!1};if(!(s.has(p)?B<A:B<=A))break;a.push(l.pop())}l.push({kind:"op",value:p}),c="op"}if(c==="op"||c==="lparen"||c==="start")return{ok:!1};for(;l.length>0;){const S=l.pop();if(S.kind==="lparen")return{ok:!1};a.push(S)}const d=S=>{if(typeof S=="number"&&Number.isFinite(S))return S;if(typeof S=="string"){const p=Number(S);if(Number.isFinite(p))return p}return null},y=[];for(const S of a){if(S.kind==="literal"){y.push(S.value);continue}if(S.kind==="identifier"){const E=this.tryResolveEvalTokenValue(S.value,r);if(!E.ok)return{ok:!1};y.push(E.value);continue}const p=S.value;if(p==="u-"||p==="!"){if(y.length<1)return{ok:!1};const E=y.pop();if(p==="u-"){const I=d(E);if(I===null)return{ok:!1};y.push(-I)}else y.push(!E);continue}if(y.length<2)return{ok:!1};const _=y.pop(),A=y.pop();if(p==="&&"||p==="||"){y.push(p==="&&"?!!A&&!!_:!!A||!!_);continue}if(p==="=="||p==="!="){y.push(p==="=="?A==_:A!=_);continue}if(p==="<"||p==="<="||p===">"||p===">="){const E=d(A),I=d(_);if(E===null||I===null)return{ok:!1};p==="<"&&y.push(E<I),p==="<="&&y.push(E<=I),p===">"&&y.push(E>I),p===">="&&y.push(E>=I);continue}const B=d(A),F=d(_);if(B===null||F===null)return{ok:!1};let O;if(p==="+")O=B+F;else if(p==="-")O=B-F;else if(p==="*")O=B*F;else if(p==="/")O=B/F;else if(p==="%")O=B%F;else return{ok:!1};if(!Number.isFinite(O))return{ok:!1};y.push(O)}if(y.length!==1)return{ok:!1};const m=y[0];return typeof m=="number"&&Number.isFinite(m)?{ok:!0,value:m}:typeof m=="boolean"?{ok:!0,value:m}:{ok:!1}}postulate(r,t,n=null){let i=r;const o=this.isDefineOpCall(i,t);if(o){this.operators[o.op]={kind:o.kind};return}const{leaf:s}=T(i),a=s?this.opKind(s):null;if(a===null||a==="secret"||a==="pointer"||a==="identity"){const p=ze(this.operators,{path:i,expression:t});if(p.kind==="commit"){const _=new Set(["set","secret","ptr","id"]);if(p.instructions.every(B=>_.has(B.op))){let B;const F=[];for(const O of p.instructions){const E=this.commitMapping(O,n);E&&(B=E,F.push(E.path.split(".").filter(Boolean)))}if(B){for(const O of F)this.invalidateFromPath(O);return B}}}}const c=this.isEvalCall(i,t);if(c){if(c.mode==="thunk"){const B=c.thunk();return c.targetPath.length===0?B:this.postulate(c.targetPath,B,"=")}if(this.pathContainsIterator(c.targetPath)){const B=this.collectIteratorIndices(c.targetPath);let F;for(const O of B){const E=this.normalizeSelectorPath(this.substituteIteratorInPath(c.targetPath,O)),I=this.normalizeSelectorPath([...E,c.name]),j=this.substituteIteratorInExpression(c.expr,O);this.registerDerivation(I,E,j);const $=this.tryEvaluateAssignExpression(E,j);F=this.postulate(I,$.ok?$.value:j,"=")}return F}if(this.pathContainsFilterSelector(c.targetPath)){const B=this.collectFilteredScopes(c.targetPath);let F;for(const O of B){const E=this.normalizeSelectorPath(O),I=this.normalizeSelectorPath([...E,c.name]);this.registerDerivation(I,E,c.expr);const j=this.tryEvaluateAssignExpression(E,c.expr);F=this.postulate(I,j.ok?j.value:c.expr,"=")}return F}const p=this.normalizeSelectorPath([...c.targetPath,c.name]),_=this.normalizeSelectorPath(c.targetPath);this.registerDerivation(p,_,c.expr);const A=this.tryEvaluateAssignExpression(_,c.expr);return A.ok?this.postulate(p,A.value,"="):this.postulate(p,c.expr,"=")}const d=this.isQueryCall(i,t);if(d){const p=d.paths.map(A=>this.readPath(A.split(".").filter(Boolean))),_=d.fn?d.fn(...p):p;return d.targetPath.length===0?_:this.postulate(d.targetPath,_,"?")}const y=this.isRemoveCall(i,t);if(y){this.removeSubtree(y.targetPath);return}const m=this.isNoiseScopeCall(i,t);if(m){this.localNoises[m.scopeKey]=t;const p=m.scopeKey?m.scopeKey.split(".").filter(Boolean):[];return this.commitThoughtOnly(p,"~","***","***")}const S=this.commitValueMapping(i,t,n);return this.invalidateFromPath(i),S}removeSubtree(r){this.clearDerivationsByPrefix(r);const t=r.join(".");for(const d of Object.keys(this.localSecrets)){if(t===""){delete this.localSecrets[d];continue}(d===t||d.startsWith(t+"."))&&delete this.localSecrets[d]}for(const d of Object.keys(this.localNoises)){if(t===""){delete this.localNoises[d];continue}(d===t||d.startsWith(t+"."))&&delete this.localNoises[d]}for(const d of Object.keys(this.encryptedBranches)){if(t===""){delete this.encryptedBranches[d];continue}if(d===t||d.startsWith(t+".")){delete this.encryptedBranches[d];continue}const y=d.split(".").filter(Boolean);if(!U(r,y)||r.length<=y.length)continue;const m=this.computeEffectiveSecret(y);if(!m)continue;const S=this.getBranchBlob(y);if(!S)continue;const p=G(S,m,y);if(!p||typeof p!="object")continue;const _=r.slice(y.length);let A=p;for(let B=0;B<_.length-1;B++){const F=_[B];if(!A||typeof A!="object"||!(F in A)){A=null;break}A=A[F]}if(A&&typeof A=="object"){delete A[_[_.length-1]];const B=ee(p,m,y);this.setBranchBlob(y,B)}}const n=r.join("."),i=Date.now(),o=this.computeEffectiveSecret(r),s=this.getPrevThoughtHash(),a=JSON.stringify({path:n,operator:"-",expression:"-",value:"-",effectiveSecret:o,prevHash:s}),l=V(a),c={path:n,operator:"-",expression:"-",value:"-",effectiveSecret:o,hash:l,prevHash:s,timestamp:i};this._shortTermMemory.push(c),this.rebuildIndex()}computeEffectiveSecret(r){let t=null,n=null;this.localNoises[""]!==void 0&&(t="",n=this.localNoises[""]);for(let o=1;o<=r.length;o++){const s=r.slice(0,o).join(".");this.localNoises[s]!==void 0&&(t=s,n=this.localNoises[s])}let i="root";n?i=V("noise::"+n):this.localSecrets[""]&&(i=V(i+"::"+this.localSecrets[""])),t===null||t===""||t.split(".").filter(Boolean).length;for(let o=1;o<=r.length;o++){const s=r.slice(0,o).join(".");if(this.localSecrets[s]){if(t!==null&&t!==""){const a=t+".";if(!(s===t||s.startsWith(a)))continue}i=V(i+"::"+this.localSecrets[s])}}return i==="root"?"":i}rebuildIndex(){const r={},t=this._shortTermMemory.map((n,i)=>({t:n,i})).sort((n,i)=>n.t.timestamp!==i.t.timestamp?n.t.timestamp-i.t.timestamp:n.t.hash!==i.t.hash?n.t.hash<i.t.hash?-1:1:n.i-i.i).map(n=>n.t);for(const n of t){const i=n.path,o=i.split(".").filter(Boolean),s=this.resolveBranchScope(o),a=s&&s.length>0&&U(o,s);if(n.operator==="-"){if(i===""){for(const c of Object.keys(r))delete r[c];continue}const l=i+".";for(const c of Object.keys(r))(c===i||c.startsWith(l))&&delete r[c];continue}a||(r[i]=n.value)}this.index=r}getIndex(r){return this.index[r.join(".")]}setIndex(r,t){this.index[r.join(".")]=t}resolveIndexPointerPath(r,t=8){let n=r;for(let i=0;i<t;i++){const o=this.getIndex(n);if(D(o)){n=o.__ptr.split(".").filter(Boolean);continue}let s=!1;for(let a=n.length-1;a>=0;a--){const l=n.slice(0,a),c=this.getIndex(l);if(!D(c))continue;const d=c.__ptr.split(".").filter(Boolean),y=n.slice(a);n=[...d,...y],s=!0;break}if(!s)return{path:n,raw:o}}return{path:n,raw:void 0}}setBranchBlob(r,t){const n=r.join(".");this.encryptedBranches[n]=t}getBranchBlob(r){const t=r.join(".");return this.encryptedBranches[t]}resolveBranchScope(r){let t=null;this.localSecrets[""]&&(t=[]);for(let n=1;n<=r.length;n++){const i=r.slice(0,n),o=i.join(".");this.localSecrets[o]&&(t=i)}return t}normalizeSelectorPath(r){const t=[];for(const n of r){const i=String(n).trim();if(!i)continue;const o=i.indexOf("[");if(o===-1){t.push(i);continue}const s=i.slice(0,o).trim(),a=i.slice(o);s&&t.push(s);const l=Array.from(a.matchAll(/\[([^\]]*)\]/g));if(l.map(d=>d[0]).join("")!==a){t.push(a);continue}for(const d of l){let y=(d[1]??"").trim();(y.startsWith('"')&&y.endsWith('"')||y.startsWith("'")&&y.endsWith("'"))&&(y=y.slice(1,-1)),y&&t.push(y)}}return t}pathContainsIterator(r){return r.some(t=>t.includes("[i]"))}substituteIteratorInPath(r,t){return r.map(n=>n.split("[i]").join(`[${t}]`))}substituteIteratorInExpression(r,t){return String(r??"").split("[i]").join(`[${t}]`)}collectIteratorIndices(r){const t=r.findIndex(o=>o.includes("[i]"));if(t===-1)return[];const n=[];for(let o=0;o<=t;o++){const s=r[o];if(o===t){const a=s.split("[i]").join("").trim();a&&n.push(a)}else n.push(s)}const i=new Set;for(const o of Object.keys(this.index)){const s=o.split(".").filter(Boolean);if(s.length<=n.length)continue;let a=!0;for(let l=0;l<n.length;l++)if(s[l]!==n[l]){a=!1;break}a&&i.add(s[n.length])}return Array.from(i).sort((o,s)=>{const a=Number(o),l=Number(s),c=Number.isFinite(a),d=Number.isFinite(l);return c&&d?a-l:c?-1:d?1:o.localeCompare(s)})}parseFilterExpression(r){const n=String(r??"").trim().match(/^(.+?)\s*(>=|<=|==|!=|>|<)\s*(.+)$/);if(!n)return null;const i=n[1].trim(),o=n[2],s=n[3].trim();return!i||!s?null:{left:i,op:o,right:s}}parseLogicalFilterExpression(r){const t=String(r??"").trim();if(!t)return null;const n=t.split(/\s*(&&|\|\|)\s*/).filter(s=>s.length>0);if(n.length===0)return null;const i=[],o=[];for(let s=0;s<n.length;s++)if(s%2===0){const a=this.parseFilterExpression(n[s]);if(!a)return null;i.push(a)}else{const a=n[s];if(a!=="&&"&&a!=="||")return null;o.push(a)}return i.length===0||o.length!==Math.max(0,i.length-1)?null:{clauses:i,ops:o}}compareValues(r,t,n){switch(t){case">":return r>n;case"<":return r<n;case">=":return r>=n;case"<=":return r<=n;case"==":return r==n;case"!=":return r!=n;default:return!1}}parseLiteralOrPath(r){const t=r.trim();if(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'"))return{kind:"literal",value:t.slice(1,-1)};if(t==="true")return{kind:"literal",value:!0};if(t==="false")return{kind:"literal",value:!1};if(t==="null")return{kind:"literal",value:null};const n=Number(t);return Number.isFinite(n)?{kind:"literal",value:n}:{kind:"path",parts:this.normalizeSelectorPath(t.split(".").filter(Boolean))}}resolveRelativeFirst(r,t){const n=this.readPath([...r,...t]);return n??this.readPath(t)}evaluateFilterClauseForScope(r,t){const n=this.normalizeSelectorPath(t.left.split(".").filter(Boolean)),i=this.resolveRelativeFirst(r,n);if(i==null)return!1;const o=this.parseLiteralOrPath(t.right),s=o.kind==="literal"?o.value:this.resolveRelativeFirst(r,o.parts);return s==null?!1:this.compareValues(i,t.op,s)}evaluateLogicalFilterForScope(r,t){const n=this.parseLogicalFilterExpression(t);if(!n)return!1;let i=this.evaluateFilterClauseForScope(r,n.clauses[0]);for(let o=1;o<n.clauses.length;o++){const s=this.evaluateFilterClauseForScope(r,n.clauses[o]);i=n.ops[o-1]==="&&"?i&&s:i||s}return i}collectChildrenForPrefix(r){const t=new Set;for(const n of Object.keys(this.index)){const i=n.split(".").filter(Boolean);if(i.length<=r.length)continue;let o=!0;for(let s=0;s<r.length;s++)if(i[s]!==r[s]){o=!1;break}o&&t.add(i[r.length])}return Array.from(t)}parseSelectorSegment(r){const t=String(r??"").trim(),n=t.indexOf("["),i=t.lastIndexOf("]");if(n<=0||i<=n||i!==t.length-1)return null;const o=t.slice(0,n).trim(),s=t.slice(n+1,i).trim();return!o||!s?null:{base:o,selector:s}}parseSelectorKeys(r){const t=r.trim();if(t.startsWith("[")&&t.endsWith("]")){const i=t.slice(1,-1).trim();return i?i.split(",").map(s=>s.trim()).filter(Boolean).map(s=>s.startsWith('"')&&s.endsWith('"')||s.startsWith("'")&&s.endsWith("'")?s.slice(1,-1):s):[]}const n=t.match(/^(-?\d+)\s*\.\.\s*(-?\d+)$/);if(n){const i=Number(n[1]),o=Number(n[2]);if(!Number.isFinite(i)||!Number.isFinite(o))return null;const s=i<=o?1:-1,a=[];if(Math.abs(o-i)>1e4)return null;for(let c=i;s>0?c<=o:c>=o;c+=s)a.push(String(c));return a}return null}parseTransformSelector(r){const n=r.trim().match(/^([A-Za-z_][A-Za-z0-9_]*)\s*=>\s*(.+)$/);if(!n)return null;const i=n[1].trim(),o=n[2].trim();return!i||!o?null:{varName:i,expr:o}}evaluateTransformPath(r){const t=r.findIndex(c=>{const d=this.parseSelectorSegment(c);return d?this.parseTransformSelector(d.selector)!==null:!1});if(t===-1)return;const n=this.parseSelectorSegment(r[t]);if(!n)return;const i=this.parseTransformSelector(n.selector);if(!i)return;const o=[...r.slice(0,t),n.base];if(r.slice(t+1).length>0)return;const a=this.collectChildrenForPrefix(o),l={};for(const c of a){const d=[...o,c],y=i.expr.replace(new RegExp(String.raw`\b${i.varName}\.`,"g"),""),m=this.tryEvaluateAssignExpression(d,y);m.ok&&(l[c]=m.value)}return l}evaluateSelectionPath(r){const t=r.findIndex(l=>this.parseSelectorSegment(l)!==null);if(t===-1)return;const n=this.parseSelectorSegment(r[t]);if(!n)return;const i=this.parseSelectorKeys(n.selector);if(i===null)return;const o=[...r.slice(0,t),n.base],s=r.slice(t+1),a={};for(const l of i){const c=[...o,l],d=s.length===0?this.buildPublicSubtree(c):this.readPath([...c,...s]);d!==void 0&&(a[l]=d)}return a}buildPublicSubtree(r){const t=r.join("."),n={};let i=!1;for(const[o,s]of Object.entries(this.index)){if(o===t)return s;if(!o.startsWith(t+"."))continue;const a=o.slice(t.length+1).split(".").filter(Boolean);let l=n;for(let c=0;c<a.length-1;c++){const d=a[c];(!l[d]||typeof l[d]!="object")&&(l[d]={}),l=l[d]}l[a[a.length-1]]=s,i=!0}return i?n:void 0}evaluateFilterPath(r){const t=r.findIndex(l=>this.parseLogicalFilterExpression(l)!==null);if(t===-1)return;const n=r[t],i=r.slice(0,t),o=r.slice(t+1);if(i.length===0)return;const s=this.collectChildrenForPrefix(i),a={};for(const l of s){const c=[...i,l];this.evaluateLogicalFilterForScope(c,n)&&(o.length===0?a[l]=this.buildPublicSubtree(c):a[l]=this.readPath([...c,...o]))}return a}pathContainsFilterSelector(r){return r.some(t=>{const n=this.parseSelectorSegment(t);return n?this.parseLogicalFilterExpression(n.selector)!==null:!1})}collectFilteredScopes(r){const t=r.findIndex(l=>{const c=this.parseSelectorSegment(l);return c?this.parseLogicalFilterExpression(c.selector)!==null:!1});if(t===-1)return[];const n=this.parseSelectorSegment(r[t]);if(!n)return[];const i=[...r.slice(0,t),n.base],o=r.slice(t+1),s=this.collectChildrenForPrefix(i),a=[];for(const l of s){const c=[...i,l];this.evaluateLogicalFilterForScope(c,n.selector)&&a.push([...c,...o])}return a}readPath(r){const t=this.evaluateTransformPath(r);if(t!==void 0)return t;const n=this.evaluateSelectionPath(r);if(n!==void 0)return n;r=this.normalizeSelectorPath(r);const i=this.evaluateFilterPath(r);if(i!==void 0)return i;const o=this.resolveBranchScope(r);if(o&&o.length>0&&U(r,o)){if(r.length===o.length)return;const d=this.computeEffectiveSecret(o);if(!d)return null;const y=this.getBranchBlob(o);if(!y)return;const m=G(y,d,o);if(!m||typeof m!="object")return;const S=r.slice(o.length);let p=m;for(const _ of S){if(!p||typeof p!="object")return;p=p[_]}return D(p)?this.readPath(p.__ptr.split(".").filter(Boolean)):(Qt(p),p)}const s=this.getIndex(r);if(D(s))return s;const a=this.resolveIndexPointerPath(r),l=a.raw;if(l===void 0)return a.path.length===r.length&&a.path.every((y,m)=>y===r[m])?void 0:this.readPath(a.path);if(D(l))return this.readPath(l.__ptr.split(".").filter(Boolean));if(Qt(l)||!Te(l))return l;const c=this.computeEffectiveSecret(r);return c?G(l,c,r):null}}return re}));
package/dist/src/me.d.ts CHANGED
@@ -13,10 +13,16 @@ export declare class ME {
13
13
  private derivations;
14
14
  private refSubscribers;
15
15
  private readonly unsafeEval;
16
+ /**
17
+ * @deprecated Use `memory` or `inspect().memory`.
18
+ */
16
19
  get shortTermMemory(): Thought[];
20
+ get memory(): Thought[];
17
21
  inspect(opts?: {
18
22
  last?: number;
19
23
  }): {
24
+ memory: Thought[];
25
+ /** @deprecated Use memory */
20
26
  thoughts: Thought[];
21
27
  index: Record<string, any>;
22
28
  encryptedScopes: string[];
@@ -43,6 +49,8 @@ export declare class ME {
43
49
  };
44
50
  private cloneValue;
45
51
  exportSnapshot(): {
52
+ memory: Thought[];
53
+ /** @deprecated Use memory */
46
54
  shortTermMemory: Thought[];
47
55
  localSecrets: Record<string, string>;
48
56
  localNoises: Record<string, string>;
@@ -52,6 +60,8 @@ export declare class ME {
52
60
  }>;
53
61
  };
54
62
  importSnapshot(snapshot: {
63
+ memory?: Thought[];
64
+ /** @deprecated Use memory */
55
65
  shortTermMemory?: Thought[];
56
66
  localSecrets?: Record<string, string>;
57
67
  localNoises?: Record<string, string>;
@@ -61,6 +71,8 @@ export declare class ME {
61
71
  }>;
62
72
  }): void;
63
73
  rehydrate(snapshot: {
74
+ memory?: Thought[];
75
+ /** @deprecated Use memory */
64
76
  shortTermMemory?: Thought[];
65
77
  localSecrets?: Record<string, string>;
66
78
  localNoises?: Record<string, string>;
@@ -70,6 +82,7 @@ export declare class ME {
70
82
  }>;
71
83
  }): void;
72
84
  replayThoughts(thoughts: Thought[]): void;
85
+ replayMemory(memory: Thought[]): void;
73
86
  private operators;
74
87
  /**
75
88
  * Constructor base:
@@ -105,6 +105,10 @@ export interface OperatorKernel {
105
105
  localSecrets?: Record<string, string>;
106
106
  localNoises?: Record<string, string>;
107
107
  encryptedBranches?: Record<string, EncryptedBlob>;
108
+ memory?: Thought[];
109
+ /**
110
+ * @deprecated Use memory.
111
+ */
108
112
  shortTermMemory?: Thought[];
109
113
  rebuildIndex(): void;
110
114
  computeEffectiveSecret(path: SemanticPath): string;
@@ -123,7 +127,7 @@ export interface OperatorKernel {
123
127
  */
124
128
  readPath(path: SemanticPath): any;
125
129
  /**
126
- * Append a thought to shortTermMemory and rebuild index.
130
+ * Append an event to memory and rebuild index.
127
131
  * Operators that are β€œkernel-only” should avoid emitting thoughts.
128
132
  */
129
133
  commitThought?(t: Thought): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "this.me",
3
- "version": "3.1.7",
3
+ "version": "3.2.0",
4
4
  "type": "module",
5
5
  "main": "./dist/me.cjs",
6
6
  "module": "./dist/me.es.js",