dsh-memu-memory 1.2.4 → 1.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/AGENTS.md +3 -1
  2. package/README.md +9 -9
  3. package/README.zh.md +6 -6
  4. package/docs/binding-lifecycle.md +1 -1
  5. package/docs/env-and-commands.md +4 -1
  6. package/docs/host-adaptation.md +318 -0
  7. package/docs/host-api.md +29 -5
  8. package/docs/memory-semantics.md +45 -9
  9. package/docs/troubleshooting.md +27 -8
  10. package/lib/binding-diagnostics.js +2 -2
  11. package/lib/client.js +246 -56
  12. package/lib/consolidation-ledger.js +46 -1
  13. package/lib/consolidation-worker.js +1 -0
  14. package/lib/cycle.js +51 -17
  15. package/lib/embedding-catalog.js +14 -0
  16. package/lib/embedding-runtime.js +202 -25
  17. package/lib/global-graph.js +99 -1
  18. package/lib/index.js +8 -0
  19. package/lib/inject.js +71 -33
  20. package/lib/lexicon-scope.js +143 -0
  21. package/lib/lexicon.js +31 -4
  22. package/lib/local-vector-service.js +82 -6
  23. package/lib/memory.js +186 -12
  24. package/lib/memu.js +318 -3
  25. package/lib/private.js +310 -67
  26. package/lib/rpc.js +183 -23
  27. package/lib/salient-wake.js +38 -2
  28. package/lib/state.js +7 -5
  29. package/lib/tools.js +40 -17
  30. package/lib/vector-migration.js +13 -1
  31. package/lib/webui/graph-view.bundle.js +1 -1
  32. package/lib/webui/graph-view.js +4 -1
  33. package/package.json +1 -1
  34. package/tests/absorb-review.test.mjs +2 -1
  35. package/tests/backend-compensation.test.mjs +1 -1
  36. package/tests/browser.test.mjs +58 -1
  37. package/tests/client-render.test.mjs +39 -0
  38. package/tests/consolidation-fork.test.mjs +81 -6
  39. package/tests/cross-library-recall.test.mjs +113 -0
  40. package/tests/curator-absorb.test.mjs +2 -1
  41. package/tests/curator-clusters.test.mjs +2 -1
  42. package/tests/curator-commit.test.mjs +2 -1
  43. package/tests/curator-link.test.mjs +2 -1
  44. package/tests/curator-review-mode.test.mjs +2 -1
  45. package/tests/cycle.test.mjs +2 -2
  46. package/tests/embedding-runtime.test.mjs +53 -1
  47. package/tests/global-graph.test.mjs +90 -0
  48. package/tests/lexicon-scope.test.mjs +256 -0
  49. package/tests/lexicon-ui.test.mjs +23 -0
  50. package/tests/managed-memory.test.mjs +1 -1
  51. package/tests/recall-dedup.test.mjs +1 -1
  52. package/tests/salient-wake.test.mjs +28 -1
  53. package/tests/settings-plumbing.test.mjs +1 -0
  54. package/tests/stubs/dsh-schedule.js +35 -0
  55. package/tests/ui-defaults.test.mjs +1 -1
  56. package/tests/vector-migration.test.mjs +20 -0
  57. package/tests/webui-auth.test.mjs +28 -0
@@ -294,8 +294,20 @@ export function createVectorMigrator(options = {}) {
294
294
  const reason = typeof stepOptions.reason === 'string' ? stepOptions.reason : 'switch'
295
295
  const current = vectorState()
296
296
  const pending = current?.pending
297
- const resumable = !fresh && pending && pending.fingerprint === profile.fingerprint
297
+ let resumable = !fresh && pending && pending.fingerprint === profile.fingerprint
298
298
  && (pending.status === 'preparing' || pending.status === 'prepared' || pending.status === 'failed')
299
+ if (resumable) {
300
+ // Same fingerprint is not enough: the manifest digest covers the artifact
301
+ // list, and a catalog update (for example adding a download source) makes the
302
+ // old journal profile unverifiable. Resuming it would fail later in
303
+ // syncShadowImpl; discard it now and start a clean generation instead.
304
+ try {
305
+ assertProfileVerified(pending.profile)
306
+ } catch (error) {
307
+ log('discarding stale pending generation ' + pending.generation + ': ' + String(error?.code || error?.message || error))
308
+ resumable = false
309
+ }
310
+ }
299
311
  if (resumable) {
300
312
  // 续建:同一代际,只把新出现的库补进同一个 DB 集合(同一次原子切换里生效)
301
313
  const extended = updatePendingJournal(journal => {
@@ -1,2 +1,2 @@
1
1
  /* Generated by scripts/build-graph.mjs. Licenses: graph-LICENSE.txt */
2
- var DshMemuGraph=(()=>{var ht=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var xe=Object.prototype.hasOwnProperty;var pe=(t,e)=>{for(var n in e)ht(t,n,{get:e[n],enumerable:!0})},de=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of he(e))!xe.call(t,a)&&a!==n&&ht(t,a,{get:()=>e[a],enumerable:!(i=ce(e,a))||i.enumerable});return t};var ye=t=>de(ht({},"__esModule",{value:!0}),t);var De={};pe(De,{DEFAULT_OPTIONS:()=>Nt,createGraphView:()=>Te,createLayout:()=>ee,fitCamera:()=>ne,placeLabels:()=>re,zoomCamera:()=>At});function zt(t){let e=+this._x.call(null,t),n=+this._y.call(null,t);return It(this.cover(e,n),e,n,t)}function It(t,e,n,i){if(isNaN(e)||isNaN(n))return t;var a,f=t._root,s={data:i},o=t._x0,u=t._y0,l=t._x1,d=t._y1,y,m,h,v,r,c,p,g;if(!f)return t._root=s,t;for(;f.length;)if((r=e>=(y=(o+l)/2))?o=y:l=y,(c=n>=(m=(u+d)/2))?u=m:d=m,a=f,!(f=f[p=c<<1|r]))return a[p]=s,t;if(h=+t._x.call(null,f.data),v=+t._y.call(null,f.data),e===h&&n===v)return s.next=f,a?a[p]=s:t._root=s,t;do a=a?a[p]=new Array(4):t._root=new Array(4),(r=e>=(y=(o+l)/2))?o=y:l=y,(c=n>=(m=(u+d)/2))?u=m:d=m;while((p=c<<1|r)===(g=(v>=m)<<1|h>=y));return a[g]=f,a[p]=s,t}function St(t){var e,n,i=t.length,a,f,s=new Array(i),o=new Array(i),u=1/0,l=1/0,d=-1/0,y=-1/0;for(n=0;n<i;++n)isNaN(a=+this._x.call(null,e=t[n]))||isNaN(f=+this._y.call(null,e))||(s[n]=a,o[n]=f,a<u&&(u=a),a>d&&(d=a),f<l&&(l=f),f>y&&(y=f));if(u>d||l>y)return this;for(this.cover(u,l).cover(d,y),n=0;n<i;++n)It(this,s[n],o[n],t[n]);return this}function Tt(t,e){if(isNaN(t=+t)||isNaN(e=+e))return this;var n=this._x0,i=this._y0,a=this._x1,f=this._y1;if(isNaN(n))a=(n=Math.floor(t))+1,f=(i=Math.floor(e))+1;else{for(var s=a-n||1,o=this._root,u,l;n>t||t>=a||i>e||e>=f;)switch(l=(e<i)<<1|t<n,u=new Array(4),u[l]=o,o=u,s*=2,l){case 0:a=n+s,f=i+s;break;case 1:n=a-s,f=i+s;break;case 2:a=n+s,i=f-s;break;case 3:n=a-s,i=f-s;break}this._root&&this._root.length&&(this._root=o)}return this._x0=n,this._y0=i,this._x1=a,this._y1=f,this}function Dt(){var t=[];return this.visit(function(e){if(!e.length)do t.push(e.data);while(e=e.next)}),t}function Ct(t){return arguments.length?this.cover(+t[0][0],+t[0][1]).cover(+t[1][0],+t[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]}function E(t,e,n,i,a){this.node=t,this.x0=e,this.y0=n,this.x1=i,this.y1=a}function Pt(t,e,n){var i,a=this._x0,f=this._y0,s,o,u,l,d=this._x1,y=this._y1,m=[],h=this._root,v,r;for(h&&m.push(new E(h,a,f,d,y)),n==null?n=1/0:(a=t-n,f=e-n,d=t+n,y=e+n,n*=n);v=m.pop();)if(!(!(h=v.node)||(s=v.x0)>d||(o=v.y0)>y||(u=v.x1)<a||(l=v.y1)<f))if(h.length){var c=(s+u)/2,p=(o+l)/2;m.push(new E(h[3],c,p,u,l),new E(h[2],s,p,c,l),new E(h[1],c,o,u,p),new E(h[0],s,o,c,p)),(r=(e>=p)<<1|t>=c)&&(v=m[m.length-1],m[m.length-1]=m[m.length-1-r],m[m.length-1-r]=v)}else{var g=t-+this._x.call(null,h.data),b=e-+this._y.call(null,h.data),w=g*g+b*b;if(w<n){var N=Math.sqrt(n=w);a=t-N,f=e-N,d=t+N,y=e+N,i=h.data}}return i}function Et(t){if(isNaN(d=+this._x.call(null,t))||isNaN(y=+this._y.call(null,t)))return this;var e,n=this._root,i,a,f,s=this._x0,o=this._y0,u=this._x1,l=this._y1,d,y,m,h,v,r,c,p;if(!n)return this;if(n.length)for(;;){if((v=d>=(m=(s+u)/2))?s=m:u=m,(r=y>=(h=(o+l)/2))?o=h:l=h,e=n,!(n=n[c=r<<1|v]))return this;if(!n.length)break;(e[c+1&3]||e[c+2&3]||e[c+3&3])&&(i=e,p=c)}for(;n.data!==t;)if(a=n,!(n=n.next))return this;return(f=n.next)&&delete n.next,a?(f?a.next=f:delete a.next,this):e?(f?e[c]=f:delete e[c],(n=e[0]||e[1]||e[2]||e[3])&&n===(e[3]||e[2]||e[1]||e[0])&&!n.length&&(i?i[p]=n:this._root=n),this):(this._root=f,this)}function Ot(t){for(var e=0,n=t.length;e<n;++e)this.remove(t[e]);return this}function jt(){return this._root}function Rt(){var t=0;return this.visit(function(e){if(!e.length)do++t;while(e=e.next)}),t}function Ft(t){var e=[],n,i=this._root,a,f,s,o,u;for(i&&e.push(new E(i,this._x0,this._y0,this._x1,this._y1));n=e.pop();)if(!t(i=n.node,f=n.x0,s=n.y0,o=n.x1,u=n.y1)&&i.length){var l=(f+o)/2,d=(s+u)/2;(a=i[3])&&e.push(new E(a,l,d,o,u)),(a=i[2])&&e.push(new E(a,f,d,l,u)),(a=i[1])&&e.push(new E(a,l,s,o,d)),(a=i[0])&&e.push(new E(a,f,s,l,d))}return this}function Lt(t){var e=[],n=[],i;for(this._root&&e.push(new E(this._root,this._x0,this._y0,this._x1,this._y1));i=e.pop();){var a=i.node;if(a.length){var f,s=i.x0,o=i.y0,u=i.x1,l=i.y1,d=(s+u)/2,y=(o+l)/2;(f=a[0])&&e.push(new E(f,s,o,d,y)),(f=a[1])&&e.push(new E(f,d,o,u,y)),(f=a[2])&&e.push(new E(f,s,y,d,l)),(f=a[3])&&e.push(new E(f,d,y,u,l))}n.push(i)}for(;i=n.pop();)t(i.node,i.x0,i.y0,i.x1,i.y1);return this}function Bt(t){return t[0]}function Wt(t){return arguments.length?(this._x=t,this):this._x}function Yt(t){return t[1]}function Xt(t){return arguments.length?(this._y=t,this):this._y}function q(t,e,n){var i=new xt(e??Bt,n??Yt,NaN,NaN,NaN,NaN);return t==null?i:i.addAll(t)}function xt(t,e,n,i,a,f){this._x=t,this._y=e,this._x0=n,this._y0=i,this._x1=a,this._y1=f,this._root=void 0}function Ht(t){for(var e={data:t.data},n=e;t=t.next;)n=n.next={data:t.data};return e}var j=q.prototype=xt.prototype;j.copy=function(){var t=new xt(this._x,this._y,this._x0,this._y0,this._x1,this._y1),e=this._root,n,i;if(!e)return t;if(!e.length)return t._root=Ht(e),t;for(n=[{source:e,target:t._root=new Array(4)}];e=n.pop();)for(var a=0;a<4;++a)(i=e.source[a])&&(i.length?n.push({source:i,target:e.target[a]=new Array(4)}):e.target[a]=Ht(i));return t};j.add=zt;j.addAll=St;j.cover=Tt;j.data=Dt;j.extent=Ct;j.find=Pt;j.remove=Et;j.removeAll=Ot;j.root=jt;j.size=Rt;j.visit=Ft;j.visitAfter=Lt;j.x=Wt;j.y=Xt;function P(t){return function(){return t}}function Y(t){return(t()-.5)*1e-6}function me(t){return t.x+t.vx}function ge(t){return t.y+t.vy}function pt(t){var e,n,i,a=1,f=1;typeof t!="function"&&(t=P(t==null?1:+t));function s(){for(var l,d=e.length,y,m,h,v,r,c,p=0;p<f;++p)for(y=q(e,me,ge).visitAfter(o),l=0;l<d;++l)m=e[l],r=n[m.index],c=r*r,h=m.x+m.vx,v=m.y+m.vy,y.visit(g);function g(b,w,N,z,I){var T=b.data,O=b.r,D=r+O;if(T){if(T.index>m.index){var L=h-T.x-T.vx,B=v-T.y-T.vy,C=L*L+B*B;C<D*D&&(L===0&&(L=Y(i),C+=L*L),B===0&&(B=Y(i),C+=B*B),C=(D-(C=Math.sqrt(C)))/C*a,m.vx+=(L*=C)*(D=(O*=O)/(c+O)),m.vy+=(B*=C)*D,T.vx-=L*(D=1-D),T.vy-=B*D)}return}return w>h+D||z<h-D||N>v+D||I<v-D}}function o(l){if(l.data)return l.r=n[l.data.index];for(var d=l.r=0;d<4;++d)l[d]&&l[d].r>l.r&&(l.r=l[d].r)}function u(){if(e){var l,d=e.length,y;for(n=new Array(d),l=0;l<d;++l)y=e[l],n[y.index]=+t(y,l,e)}}return s.initialize=function(l,d){e=l,i=d,u()},s.iterations=function(l){return arguments.length?(f=+l,s):f},s.strength=function(l){return arguments.length?(a=+l,s):a},s.radius=function(l){return arguments.length?(t=typeof l=="function"?l:P(+l),u(),s):t},s}function we(t){return t.index}function Qt(t,e){var n=t.get(e);if(!n)throw new Error("node not found: "+e);return n}function dt(t){var e=we,n=y,i,a=P(30),f,s,o,u,l,d=1;t==null&&(t=[]);function y(c){return 1/Math.min(o[c.source.index],o[c.target.index])}function m(c){for(var p=0,g=t.length;p<d;++p)for(var b=0,w,N,z,I,T,O,D;b<g;++b)w=t[b],N=w.source,z=w.target,I=z.x+z.vx-N.x-N.vx||Y(l),T=z.y+z.vy-N.y-N.vy||Y(l),O=Math.sqrt(I*I+T*T),O=(O-f[b])/O*c*i[b],I*=O,T*=O,z.vx-=I*(D=u[b]),z.vy-=T*D,N.vx+=I*(D=1-D),N.vy+=T*D}function h(){if(s){var c,p=s.length,g=t.length,b=new Map(s.map((N,z)=>[e(N,z,s),N])),w;for(c=0,o=new Array(p);c<g;++c)w=t[c],w.index=c,typeof w.source!="object"&&(w.source=Qt(b,w.source)),typeof w.target!="object"&&(w.target=Qt(b,w.target)),o[w.source.index]=(o[w.source.index]||0)+1,o[w.target.index]=(o[w.target.index]||0)+1;for(c=0,u=new Array(g);c<g;++c)w=t[c],u[c]=o[w.source.index]/(o[w.source.index]+o[w.target.index]);i=new Array(g),v(),f=new Array(g),r()}}function v(){if(s)for(var c=0,p=t.length;c<p;++c)i[c]=+n(t[c],c,t)}function r(){if(s)for(var c=0,p=t.length;c<p;++c)f[c]=+a(t[c],c,t)}return m.initialize=function(c,p){s=c,l=p,h()},m.links=function(c){return arguments.length?(t=c,h(),m):t},m.id=function(c){return arguments.length?(e=c,m):e},m.iterations=function(c){return arguments.length?(d=+c,m):d},m.strength=function(c){return arguments.length?(n=typeof c=="function"?c:P(+c),v(),m):n},m.distance=function(c){return arguments.length?(a=typeof c=="function"?c:P(+c),r(),m):a},m}var ve={value:()=>{}};function Vt(){for(var t=0,e=arguments.length,n={},i;t<e;++t){if(!(i=arguments[t]+"")||i in n||/[\s.]/.test(i))throw new Error("illegal type: "+i);n[i]=[]}return new rt(n)}function rt(t){this._=t}function _e(t,e){return t.trim().split(/^|\s+/).map(function(n){var i="",a=n.indexOf(".");if(a>=0&&(i=n.slice(a+1),n=n.slice(0,a)),n&&!e.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:i}})}rt.prototype=Vt.prototype={constructor:rt,on:function(t,e){var n=this._,i=_e(t+"",n),a,f=-1,s=i.length;if(arguments.length<2){for(;++f<s;)if((a=(t=i[f]).type)&&(a=Me(n[a],t.name)))return a;return}if(e!=null&&typeof e!="function")throw new Error("invalid callback: "+e);for(;++f<s;)if(a=(t=i[f]).type)n[a]=Ut(n[a],t.name,e);else if(e==null)for(a in n)n[a]=Ut(n[a],t.name,null);return this},copy:function(){var t={},e=this._;for(var n in e)t[n]=e[n].slice();return new rt(t)},call:function(t,e){if((a=arguments.length-2)>0)for(var n=new Array(a),i=0,a,f;i<a;++i)n[i]=arguments[i+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(f=this._[t],i=0,a=f.length;i<a;++i)f[i].value.apply(e,n)},apply:function(t,e,n){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var i=this._[t],a=0,f=i.length;a<f;++a)i[a].value.apply(e,n)}};function Me(t,e){for(var n=0,i=t.length,a;n<i;++n)if((a=t[n]).name===e)return a.value}function Ut(t,e,n){for(var i=0,a=t.length;i<a;++i)if(t[i].name===e){t[i]=ve,t=t.slice(0,i).concat(t.slice(i+1));break}return n!=null&&t.push({name:e,value:n}),t}var yt=Vt;var J=0,Z=0,K=0,$t=1e3,it,tt,ot=0,$=0,at=0,et=typeof performance=="object"&&performance.now?performance:Date,Gt=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function wt(){return $||(Gt(be),$=et.now()+at)}function be(){$=0}function mt(){this._call=this._time=this._next=null}mt.prototype=st.prototype={constructor:mt,restart:function(t,e,n){if(typeof t!="function")throw new TypeError("callback is not a function");n=(n==null?wt():+n)+(e==null?0:+e),!this._next&&tt!==this&&(tt?tt._next=this:it=this,tt=this),this._call=t,this._time=n,gt()},stop:function(){this._call&&(this._call=null,this._time=1/0,gt())}};function st(t,e,n){var i=new mt;return i.restart(t,e,n),i}function Jt(){wt(),++J;for(var t=it,e;t;)(e=$-t._time)>=0&&t._call.call(void 0,e),t=t._next;--J}function qt(){$=(ot=et.now())+at,J=Z=0;try{Jt()}finally{J=0,Ne(),$=0}}function Ae(){var t=et.now(),e=t-ot;e>$t&&(at-=e,ot=t)}function Ne(){for(var t,e=it,n,i=1/0;e;)e._call?(i>e._time&&(i=e._time),t=e,e=e._next):(n=e._next,e._next=null,e=t?t._next=n:it=n);tt=t,gt(i)}function gt(t){if(!J){Z&&(Z=clearTimeout(Z));var e=t-$;e>24?(t<1/0&&(Z=setTimeout(qt,t-et.now()-at)),K&&(K=clearInterval(K))):(K||(ot=et.now(),K=setInterval(Ae,$t)),J=1,Gt(qt))}}function Kt(){let t=1;return()=>(t=(1664525*t+1013904223)%4294967296)/4294967296}function Zt(t){return t.x}function te(t){return t.y}var ke=10,ze=Math.PI*(3-Math.sqrt(5));function vt(t){var e,n=1,i=.001,a=1-Math.pow(i,1/300),f=0,s=.6,o=new Map,u=st(y),l=yt("tick","end"),d=Kt();t==null&&(t=[]);function y(){m(),l.call("tick",e),n<i&&(u.stop(),l.call("end",e))}function m(r){var c,p=t.length,g;r===void 0&&(r=1);for(var b=0;b<r;++b)for(n+=(f-n)*a,o.forEach(function(w){w(n)}),c=0;c<p;++c)g=t[c],g.fx==null?g.x+=g.vx*=s:(g.x=g.fx,g.vx=0),g.fy==null?g.y+=g.vy*=s:(g.y=g.fy,g.vy=0);return e}function h(){for(var r=0,c=t.length,p;r<c;++r){if(p=t[r],p.index=r,p.fx!=null&&(p.x=p.fx),p.fy!=null&&(p.y=p.fy),isNaN(p.x)||isNaN(p.y)){var g=ke*Math.sqrt(.5+r),b=r*ze;p.x=g*Math.cos(b),p.y=g*Math.sin(b)}(isNaN(p.vx)||isNaN(p.vy))&&(p.vx=p.vy=0)}}function v(r){return r.initialize&&r.initialize(t,d),r}return h(),e={tick:m,restart:function(){return u.restart(y),e},stop:function(){return u.stop(),e},nodes:function(r){return arguments.length?(t=r,h(),o.forEach(v),e):t},alpha:function(r){return arguments.length?(n=+r,e):n},alphaMin:function(r){return arguments.length?(i=+r,e):i},alphaDecay:function(r){return arguments.length?(a=+r,e):+a},alphaTarget:function(r){return arguments.length?(f=+r,e):f},velocityDecay:function(r){return arguments.length?(s=1-r,e):1-s},randomSource:function(r){return arguments.length?(d=r,o.forEach(v),e):d},force:function(r,c){return arguments.length>1?(c==null?o.delete(r):o.set(r,v(c)),e):o.get(r)},find:function(r,c,p){var g=0,b=t.length,w,N,z,I,T;for(p==null?p=1/0:p*=p,g=0;g<b;++g)I=t[g],w=r-I.x,N=c-I.y,z=w*w+N*N,z<p&&(T=I,p=z);return T},on:function(r,c){return arguments.length>1?(l.on(r,c),e):l.on(r)}}}function _t(){var t,e,n,i,a=P(-30),f,s=1,o=1/0,u=.81;function l(h){var v,r=t.length,c=q(t,Zt,te).visitAfter(y);for(i=h,v=0;v<r;++v)e=t[v],c.visit(m)}function d(){if(t){var h,v=t.length,r;for(f=new Array(v),h=0;h<v;++h)r=t[h],f[r.index]=+a(r,h,t)}}function y(h){var v=0,r,c,p=0,g,b,w;if(h.length){for(g=b=w=0;w<4;++w)(r=h[w])&&(c=Math.abs(r.value))&&(v+=r.value,p+=c,g+=c*r.x,b+=c*r.y);h.x=g/p,h.y=b/p}else{r=h,r.x=r.data.x,r.y=r.data.y;do v+=f[r.data.index];while(r=r.next)}h.value=v}function m(h,v,r,c){if(!h.value)return!0;var p=h.x-e.x,g=h.y-e.y,b=c-v,w=p*p+g*g;if(b*b/u<w)return w<o&&(p===0&&(p=Y(n),w+=p*p),g===0&&(g=Y(n),w+=g*g),w<s&&(w=Math.sqrt(s*w)),e.vx+=p*h.value*i/w,e.vy+=g*h.value*i/w),!0;if(h.length||w>=o)return;(h.data!==e||h.next)&&(p===0&&(p=Y(n),w+=p*p),g===0&&(g=Y(n),w+=g*g),w<s&&(w=Math.sqrt(s*w)));do h.data!==e&&(b=f[h.data.index]*i/w,e.vx+=p*b,e.vy+=g*b);while(h=h.next)}return l.initialize=function(h,v){t=h,n=v,d()},l.strength=function(h){return arguments.length?(a=typeof h=="function"?h:P(+h),d(),l):a},l.distanceMin=function(h){return arguments.length?(s=h*h,l):Math.sqrt(s)},l.distanceMax=function(h){return arguments.length?(o=h*h,l):Math.sqrt(o)},l.theta=function(h){return arguments.length?(u=h*h,l):Math.sqrt(u)},l}function Mt(t){var e=P(.1),n,i,a;typeof t!="function"&&(t=P(t==null?0:+t));function f(o){for(var u=0,l=n.length,d;u<l;++u)d=n[u],d.vx+=(a[u]-d.x)*i[u]*o}function s(){if(n){var o,u=n.length;for(i=new Array(u),a=new Array(u),o=0;o<u;++o)i[o]=isNaN(a[o]=+t(n[o],o,n))?0:+e(n[o],o,n)}}return f.initialize=function(o){n=o,s()},f.strength=function(o){return arguments.length?(e=typeof o=="function"?o:P(+o),s(),f):e},f.x=function(o){return arguments.length?(t=typeof o=="function"?o:P(+o),s(),f):t},f}function bt(t){var e=P(.1),n,i,a;typeof t!="function"&&(t=P(t==null?0:+t));function f(o){for(var u=0,l=n.length,d;u<l;++u)d=n[u],d.vy+=(a[u]-d.y)*i[u]*o}function s(){if(n){var o,u=n.length;for(i=new Array(u),a=new Array(u),o=0;o<u;++o)i[o]=isNaN(a[o]=+t(n[o],o,n))?0:+e(n[o],o,n)}}return f.initialize=function(o){n=o,s()},f.strength=function(o){return arguments.length?(e=typeof o=="function"?o:P(+o),s(),f):e},f.y=function(o){return arguments.length?(t=typeof o=="function"?o:P(+o),s(),f):t},f}var Ie=200,Q=(t,e,n)=>Math.max(e,Math.min(n,t)),Nt=Object.freeze({repulsion:120,distance:100,labels:!0,motion:!0});function ee(){let t=new Map,e=[],n=[],i="",a={...Nt},f=vt().stop().alphaDecay(.035).velocityDecay(.48).force("charge",_t().strength(-a.repulsion).distanceMax(1400)).force("collision",pt(o=>o.radius+12).iterations(2)).force("x",Mt(0).strength(.025)).force("y",bt(0).strength(.025));return{simulation:f,update:o=>{let u=[...new Map((o.nodes||[]).slice(0,Ie).map(r=>[r.id,r])).values()].sort((r,c)=>String(r.id).localeCompare(String(c.id))),l=new Set(u.map(r=>r.id)),d=(o.edges||[]).filter(r=>l.has(r.from)&&l.has(r.to)&&r.from!==r.to),y=JSON.stringify([u.map(r=>r.id),d.map(r=>[r.from,r.to]).sort()]),m=i!==y,h=new Map;for(let r of d)h.set(r.from,(h.get(r.from)||0)+1),h.set(r.to,(h.get(r.to)||0)+1);let v=u.filter(r=>!t.has(r.id));for(let r=0;r<v.length;r++){let c=v[r],p=d.filter(z=>z.from===c.id||z.to===c.id).map(z=>t.get(z.from===c.id?z.to:z.from)).filter(Boolean),g=r*2.399963229728653,b=p.length?32:24*Math.sqrt(r+.5),w=p.length?p.reduce((z,I)=>z+I.x,0)/p.length:0,N=p.length?p.reduce((z,I)=>z+I.y,0)/p.length:0;t.set(c.id,{id:c.id,x:w+Math.cos(g)*b,y:N+Math.sin(g)*b,vx:0,vy:0})}e=u.map(r=>Object.assign(t.get(r.id),r,{degree:h.get(r.id)||0,radius:4+Math.min(3,Math.log2(1+(h.get(r.id)||0)))+Q(Number(r.strength)||0,0,1)*2})),n=d.map(r=>({...r,source:t.get(r.from),target:t.get(r.to)})),m&&(f.nodes(e).force("link",dt(n).id(r=>r.id).distance(a.distance).strength(.18)),f.alpha(i?.25:1)),i=y;for(let r of t.keys())t.size>800&&!l.has(r)&&t.delete(r);return m},get nodes(){return e},get edges(){return n},configure(o){a={...a,...o},f.force("charge").strength(-a.repulsion),f.force("link")?.distance(a.distance),f.alpha(Math.max(.25,f.alpha()))},settle(o=200){f.tick(o)},dispose(){f.stop(),t.clear()}}}function ne(t,e,n){if(!t.length)return{x:e/2,y:n/2,k:1};let i=Math.min(...t.map(u=>u.x-u.radius)),a=Math.max(...t.map(u=>u.x+u.radius)),f=Math.min(...t.map(u=>u.y-u.radius)),s=Math.max(...t.map(u=>u.y+u.radius)),o=Q(Math.min(Math.max(32,e-100)/Math.max(120,a-i),Math.max(32,n-96)/Math.max(120,s-f)),.06,1.6);return{x:e/2-(i+a)*o/2,y:n/2-(f+s)*o/2,k:o}}function At(t,e,n){let i=Q(t.k*e,.06,5);return{k:i,x:n.x-(n.x-t.x)*i/t.k,y:n.y-(n.y-t.y)*i/t.k}}var Se=(t,e)=>t.x<e.x+e.width&&t.x+t.width>e.x&&t.y<e.y+e.height&&t.y+t.height>e.y;function re(t,e,n,i){let a=[...e],f=[];for(let s of t){let{x:o,y:u,radius:l,textWidth:d}=s,y=[{x:o-d/2,y:u+l+5},{x:o-d/2,y:u-l-21},{x:o+l+6,y:u-8},{x:o-l-d-6,y:u-8}];if(s.priority)for(let h of[28,48,72])y.push({x:o-d/2,y:u+l+h},{x:o-d/2,y:u-l-16-h},{x:o+l+h,y:u-8},{x:o-l-d-h,y:u-8});let m=y.map(h=>({...h,width:d,height:16})).find(h=>h.x>=5&&h.y>=5&&h.x+h.width<=n-5&&h.y+h.height<=i-5&&!a.some(v=>Se(h,v)));m&&(a.push({x:m.x-3,y:m.y-2,width:m.width+6,height:m.height+4}),f.push({...s,box:m}))}return f}function Te(t,{onFocus:e=()=>{},onZoom:n=()=>{},tooltip:i,reducedMotion:a=!1,emptyLabel:f=""}={}){let s=t.getContext("2d");if(!s)throw new Error("Canvas 2D is unavailable");let o=ee(),u=1,l=1,d=1,y={x:0,y:0,k:1},m={...Nt},h="",v=null,r=null,c=!1,p=!1,g=null,b=0,w=0,N=new Map,z=[],I=t.ownerDocument.defaultView,T=x=>({x:(x.x-y.x)/y.k,y:(x.y-y.y)/y.k}),O=x=>({x:x.x*y.k+y.x,y:x.y*y.k+y.y}),D=x=>Q(x.radius*Math.sqrt(y.k),2.5,22),L=x=>{let _=t.getBoundingClientRect();return{x:(x.clientX-_.left)*u/_.width,y:(x.clientY-_.top)*l/_.height}},B=x=>{let _=null,k=1/0;for(let A of o.nodes){let W=O(A),V=Math.hypot(W.x-x.x,W.y-x.y);V<=Math.max(10,D(A)+4)&&V<k&&(_=A,k=V)}return _},C=()=>{i&&(i.hidden=!0)},ie=(x,_)=>{v!==x&&(v=x,F()),t.style.cursor=r?"grabbing":x?"pointer":"grab",i&&(i.hidden=!x||!!r,!(!x||r)&&(i.textContent=String(x.title||x.id),i.style.left=`${Q(_.x+14,6,Math.max(6,u-Math.min(260,u-12)))}px`,i.style.top=`${(t.offsetTop||0)+Q(_.y+16,6,l-60)}px`))},oe=()=>{s.setTransform(d,0,0,d,0,0),s.clearRect(0,0,u,l);let x=I.getComputedStyle(t),_=x.color,k=x.getPropertyValue("--dsw-alias-bg-layer-1").trim()||"#ffffff",A=v?.id||h,W=new Set(A?[A]:[]);for(let S of o.edges)S.from===A&&W.add(S.to),S.to===A&&W.add(S.from);s.strokeStyle=_;for(let S of o.edges){let X=O(S.source),M=O(S.target),R=A&&(S.from===A||S.to===A);s.globalAlpha=R?.6:A?.055:.16,s.lineWidth=R?1.5:.8,s.beginPath(),s.moveTo(X.x,X.y),s.lineTo(M.x,M.y),s.stroke()}let V=o.nodes.map(S=>({node:S,...O(S),radius:D(S)})).filter(S=>S.x>=-30&&S.x<=u+30&&S.y>=-30&&S.y<=l+30);for(let S of V){let X=S.node,M=X.missing?"#92959c":X.kind!=="memory"?"#36a582":X.layer==="must_remember"?"#d97768":"#618fcd";s.globalAlpha=A&&!W.has(X.id)?.22:1,s.fillStyle=M,s.beginPath(),s.arc(S.x,S.y,S.radius,0,Math.PI*2),s.fill(),X.id===A&&(s.strokeStyle=M,s.lineWidth=1.5,s.beginPath(),s.arc(S.x,S.y,S.radius+4,0,Math.PI*2),s.stroke())}if(s.globalAlpha=1,m.labels){s.font="12px system-ui, sans-serif";let S=V.filter(M=>!A||W.has(M.node.id)).filter(M=>y.k>=.45||M.node.id===A||M.node.degree>=3||o.nodes.length<30).sort((M,R)=>+(R.node.id===A)-+(M.node.id===A)||R.node.degree-M.node.degree||String(M.node.id).localeCompare(String(R.node.id))).map(M=>{let R=String(M.node.title||M.node.id),H=R;for(;H.length>1&&s.measureText(H).width>Math.min(136,u-24);)H=H.slice(0,-1);return H!==R&&(H=H.slice(0,-2)+"..."),{...M,text:H,textWidth:s.measureText(H).width+4,priority:M.node.degree>=3||M.node.id===A}}),X=re(S,V.map(M=>({x:M.x-M.radius-2,y:M.y-M.radius-2,width:M.radius*2+4,height:M.radius*2+4})),u,l);s.textAlign="left",s.textBaseline="top";for(let M of X){let R={x:Q(M.x,M.box.x,M.box.x+M.box.width),y:Q(M.y,M.box.y,M.box.y+M.box.height)};Math.hypot(R.x-M.x,R.y-M.y)>M.radius+18&&(s.globalAlpha=.25,s.strokeStyle=_,s.lineWidth=.7,s.beginPath(),s.moveTo(M.x,M.y),s.lineTo(R.x,R.y),s.stroke()),s.fillStyle=k,s.globalAlpha=.88,s.fillRect(M.box.x-1,M.box.y,M.box.width+2,M.box.height),s.globalAlpha=M.node.id===A?1:.78,s.fillStyle=_,s.fillText(M.text,M.box.x+2,M.box.y+1)}s.globalAlpha=1}!o.nodes.length&&f&&(s.font="13px system-ui, sans-serif",s.textAlign="center",s.textBaseline="middle",s.fillStyle=_,s.globalAlpha=.55,s.fillText(f,u/2,l/2),s.globalAlpha=1)},ae=x=>{if(g=null,!p){if(m.motion&&!a&&o.simulation.alpha()>o.simulation.alphaMin()){for(w+=b?Math.min(64,x-b):17;w>=1e3/60;w-=1e3/60)o.simulation.tick();b=x,F()}else b=0,w=0;oe()}};function F(){!p&&g===null&&(g=I.requestAnimationFrame(ae))}let ft=()=>{n(y.k),F()},lt=()=>{y=ne(o.nodes,u,l),C(),ft()},nt=(x,_={x:u/2,y:l/2})=>{y=At(y,x,_),C(),ft()},ut=()=>{let x=t.getBoundingClientRect();if(!x.width||!x.height)return;let _=x.width,k=x.height;y.x+=(_-u)/2,y.y+=(k-l)/2,u=_,l=k,d=Math.min(2,I.devicePixelRatio||1),t.width=Math.round(u*d),t.height=Math.round(l*d),F()},G=()=>{r?.node&&(r.node.fx=null,r.node.fy=null,r.node.vx=0,r.node.vy=0)},se=()=>{G();let[x,_]=[...N.values()];r={type:"pinch",distance:Math.max(1,Math.hypot(_.x-x.x,_.y-x.y)),camera:{...y},center:{x:(x.x+_.x)/2,y:(x.y+_.y)/2},moved:!0}},fe=x=>{if(x.button!==0&&x.pointerType!=="touch")return;x.preventDefault(),t.focus({preventScroll:!0});let _=L(x);if(N.set(x.pointerId,_),t.setPointerCapture?.(x.pointerId),N.size>=2){se(),C();return}let k=B(_);r={type:k?"node":"pan",node:k,start:_,camera:{...y},moved:!1,offset:k?{x:k.x-T(_).x,y:k.y-T(_).y}:null},k&&(k.fx=k.x,k.fy=k.y,k.vx=0,k.vy=0),C(),t.style.cursor="grabbing"},le=x=>{let _=L(x);if(!N.has(x.pointerId)||!r){ie(B(_),_);return}if(N.set(x.pointerId,_),r.type==="pinch"){if(N.size<2)return;let[k,A]=[...N.values()],W={x:(k.x+A.x)/2,y:(k.y+A.y)/2};y=At(r.camera,Math.hypot(A.x-k.x,A.y-k.y)/r.distance,r.center),y.x+=W.x-r.center.x,y.y+=W.y-r.center.y,ft()}else{if(r.moved||(r.moved=Math.hypot(_.x-r.start.x,_.y-r.start.y)>5),!r.moved)return;if(r.node){let k=T(_),A=r.node;A.x=A.fx=k.x+r.offset.x,A.y=A.fy=k.y+r.offset.y,A.vx=0,A.vy=0,o.simulation.alpha(Math.max(.08,o.simulation.alpha()))}else y.x=r.camera.x+_.x-r.start.x,y.y=r.camera.y+_.y-r.start.y;F()}},ue=x=>{if(!N.has(x.pointerId))return;let _=x.type!=="pointerup",k=r?.node,A=!_&&!r?.moved&&r?.type!=="pinch";G(),N.delete(x.pointerId),r=null,N.size&&(r={type:"pan",start:[...N.values()][0],camera:{...y},moved:!0}),t.hasPointerCapture?.(x.pointerId)&&t.releasePointerCapture(x.pointerId),A&&e(k?.id||""),v=null,t.style.cursor="grab",C(),F()},U=(x,_,k,A)=>{x.addEventListener(_,k,A),z.push(()=>x.removeEventListener(_,k,A))};U(t,"pointerdown",fe),U(t,"pointermove",le);for(let x of["pointerup","pointercancel","lostpointercapture"])U(t,x,ue);U(t,"pointerleave",()=>{r||(v=null,C(),F())}),U(t,"wheel",x=>{x.preventDefault(),nt(Math.exp(-Q(x.deltaY,-160,160)*.0025),L(x))},{passive:!1}),U(t,"keydown",x=>{if(x.key==="+"||x.key==="=")nt(1.25);else if(x.key==="-")nt(.8);else if(x.key==="0"||x.key==="Home")lt();else if(x.key==="Escape")G(),r=null,N.clear(),e(""),C(),F();else if(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(x.key)){let _=x.shiftKey?90:30;y.x+=x.key==="ArrowLeft"?_:x.key==="ArrowRight"?-_:0,y.y+=x.key==="ArrowUp"?_:x.key==="ArrowDown"?-_:0,F()}else return;x.preventDefault()}),U(I,"blur",()=>{G(),r=null,N.clear(),v=null,C(),F()});let kt=I.ResizeObserver?new I.ResizeObserver(ut):null;kt?.observe(t),U(I,"resize",ut);let ct=I.MutationObserver?new I.MutationObserver(F):null;return ct?.observe(t.ownerDocument.documentElement,{attributes:!0,attributeFilter:["class","data-theme","style"]}),t.ownerDocument.body&&ct?.observe(t.ownerDocument.body,{attributes:!0,attributeFilter:["class","data-theme","style"]}),ut(),{update(x,_=""){r?.node&&!x.nodes.some(A=>A.id===r.node.id)&&(G(),r=null,N.clear());let k=o.update(x);h=_,v&&!o.nodes.includes(v)&&(v=null,C()),!c&&o.nodes.length?(o.settle(220),c=!0,lt()):k&&a&&o.settle(180),F()},configure(x){let _=x.repulsion!==void 0&&x.repulsion!==m.repulsion||x.distance!==void 0&&x.distance!==m.distance;m={...m,...x},_&&(o.configure(m),a&&o.settle(180)),F()},fit:lt,zoom:nt,dispose(){p=!0,G(),g!==null&&I.cancelAnimationFrame(g);for(let x of z)x();kt?.disconnect(),ct?.disconnect(),o.dispose(),C()}}}return ye(De);})();
2
+ var DshMemuGraph=(()=>{var ht=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var xe=Object.prototype.hasOwnProperty;var pe=(t,e)=>{for(var n in e)ht(t,n,{get:e[n],enumerable:!0})},de=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of he(e))!xe.call(t,a)&&a!==n&&ht(t,a,{get:()=>e[a],enumerable:!(i=ce(e,a))||i.enumerable});return t};var ye=t=>de(ht({},"__esModule",{value:!0}),t);var De={};pe(De,{DEFAULT_OPTIONS:()=>Nt,createGraphView:()=>Te,createLayout:()=>ee,fitCamera:()=>ne,placeLabels:()=>re,zoomCamera:()=>At});function zt(t){let e=+this._x.call(null,t),n=+this._y.call(null,t);return It(this.cover(e,n),e,n,t)}function It(t,e,n,i){if(isNaN(e)||isNaN(n))return t;var a,f=t._root,s={data:i},o=t._x0,u=t._y0,l=t._x1,d=t._y1,y,m,h,v,r,c,p,g;if(!f)return t._root=s,t;for(;f.length;)if((r=e>=(y=(o+l)/2))?o=y:l=y,(c=n>=(m=(u+d)/2))?u=m:d=m,a=f,!(f=f[p=c<<1|r]))return a[p]=s,t;if(h=+t._x.call(null,f.data),v=+t._y.call(null,f.data),e===h&&n===v)return s.next=f,a?a[p]=s:t._root=s,t;do a=a?a[p]=new Array(4):t._root=new Array(4),(r=e>=(y=(o+l)/2))?o=y:l=y,(c=n>=(m=(u+d)/2))?u=m:d=m;while((p=c<<1|r)===(g=(v>=m)<<1|h>=y));return a[g]=f,a[p]=s,t}function St(t){var e,n,i=t.length,a,f,s=new Array(i),o=new Array(i),u=1/0,l=1/0,d=-1/0,y=-1/0;for(n=0;n<i;++n)isNaN(a=+this._x.call(null,e=t[n]))||isNaN(f=+this._y.call(null,e))||(s[n]=a,o[n]=f,a<u&&(u=a),a>d&&(d=a),f<l&&(l=f),f>y&&(y=f));if(u>d||l>y)return this;for(this.cover(u,l).cover(d,y),n=0;n<i;++n)It(this,s[n],o[n],t[n]);return this}function Tt(t,e){if(isNaN(t=+t)||isNaN(e=+e))return this;var n=this._x0,i=this._y0,a=this._x1,f=this._y1;if(isNaN(n))a=(n=Math.floor(t))+1,f=(i=Math.floor(e))+1;else{for(var s=a-n||1,o=this._root,u,l;n>t||t>=a||i>e||e>=f;)switch(l=(e<i)<<1|t<n,u=new Array(4),u[l]=o,o=u,s*=2,l){case 0:a=n+s,f=i+s;break;case 1:n=a-s,f=i+s;break;case 2:a=n+s,i=f-s;break;case 3:n=a-s,i=f-s;break}this._root&&this._root.length&&(this._root=o)}return this._x0=n,this._y0=i,this._x1=a,this._y1=f,this}function Dt(){var t=[];return this.visit(function(e){if(!e.length)do t.push(e.data);while(e=e.next)}),t}function Ct(t){return arguments.length?this.cover(+t[0][0],+t[0][1]).cover(+t[1][0],+t[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]}function E(t,e,n,i,a){this.node=t,this.x0=e,this.y0=n,this.x1=i,this.y1=a}function Pt(t,e,n){var i,a=this._x0,f=this._y0,s,o,u,l,d=this._x1,y=this._y1,m=[],h=this._root,v,r;for(h&&m.push(new E(h,a,f,d,y)),n==null?n=1/0:(a=t-n,f=e-n,d=t+n,y=e+n,n*=n);v=m.pop();)if(!(!(h=v.node)||(s=v.x0)>d||(o=v.y0)>y||(u=v.x1)<a||(l=v.y1)<f))if(h.length){var c=(s+u)/2,p=(o+l)/2;m.push(new E(h[3],c,p,u,l),new E(h[2],s,p,c,l),new E(h[1],c,o,u,p),new E(h[0],s,o,c,p)),(r=(e>=p)<<1|t>=c)&&(v=m[m.length-1],m[m.length-1]=m[m.length-1-r],m[m.length-1-r]=v)}else{var g=t-+this._x.call(null,h.data),b=e-+this._y.call(null,h.data),w=g*g+b*b;if(w<n){var N=Math.sqrt(n=w);a=t-N,f=e-N,d=t+N,y=e+N,i=h.data}}return i}function Et(t){if(isNaN(d=+this._x.call(null,t))||isNaN(y=+this._y.call(null,t)))return this;var e,n=this._root,i,a,f,s=this._x0,o=this._y0,u=this._x1,l=this._y1,d,y,m,h,v,r,c,p;if(!n)return this;if(n.length)for(;;){if((v=d>=(m=(s+u)/2))?s=m:u=m,(r=y>=(h=(o+l)/2))?o=h:l=h,e=n,!(n=n[c=r<<1|v]))return this;if(!n.length)break;(e[c+1&3]||e[c+2&3]||e[c+3&3])&&(i=e,p=c)}for(;n.data!==t;)if(a=n,!(n=n.next))return this;return(f=n.next)&&delete n.next,a?(f?a.next=f:delete a.next,this):e?(f?e[c]=f:delete e[c],(n=e[0]||e[1]||e[2]||e[3])&&n===(e[3]||e[2]||e[1]||e[0])&&!n.length&&(i?i[p]=n:this._root=n),this):(this._root=f,this)}function Ot(t){for(var e=0,n=t.length;e<n;++e)this.remove(t[e]);return this}function jt(){return this._root}function Rt(){var t=0;return this.visit(function(e){if(!e.length)do++t;while(e=e.next)}),t}function Ft(t){var e=[],n,i=this._root,a,f,s,o,u;for(i&&e.push(new E(i,this._x0,this._y0,this._x1,this._y1));n=e.pop();)if(!t(i=n.node,f=n.x0,s=n.y0,o=n.x1,u=n.y1)&&i.length){var l=(f+o)/2,d=(s+u)/2;(a=i[3])&&e.push(new E(a,l,d,o,u)),(a=i[2])&&e.push(new E(a,f,d,l,u)),(a=i[1])&&e.push(new E(a,l,s,o,d)),(a=i[0])&&e.push(new E(a,f,s,l,d))}return this}function Lt(t){var e=[],n=[],i;for(this._root&&e.push(new E(this._root,this._x0,this._y0,this._x1,this._y1));i=e.pop();){var a=i.node;if(a.length){var f,s=i.x0,o=i.y0,u=i.x1,l=i.y1,d=(s+u)/2,y=(o+l)/2;(f=a[0])&&e.push(new E(f,s,o,d,y)),(f=a[1])&&e.push(new E(f,d,o,u,y)),(f=a[2])&&e.push(new E(f,s,y,d,l)),(f=a[3])&&e.push(new E(f,d,y,u,l))}n.push(i)}for(;i=n.pop();)t(i.node,i.x0,i.y0,i.x1,i.y1);return this}function Bt(t){return t[0]}function Wt(t){return arguments.length?(this._x=t,this):this._x}function Yt(t){return t[1]}function Xt(t){return arguments.length?(this._y=t,this):this._y}function q(t,e,n){var i=new xt(e??Bt,n??Yt,NaN,NaN,NaN,NaN);return t==null?i:i.addAll(t)}function xt(t,e,n,i,a,f){this._x=t,this._y=e,this._x0=n,this._y0=i,this._x1=a,this._y1=f,this._root=void 0}function Ht(t){for(var e={data:t.data},n=e;t=t.next;)n=n.next={data:t.data};return e}var j=q.prototype=xt.prototype;j.copy=function(){var t=new xt(this._x,this._y,this._x0,this._y0,this._x1,this._y1),e=this._root,n,i;if(!e)return t;if(!e.length)return t._root=Ht(e),t;for(n=[{source:e,target:t._root=new Array(4)}];e=n.pop();)for(var a=0;a<4;++a)(i=e.source[a])&&(i.length?n.push({source:i,target:e.target[a]=new Array(4)}):e.target[a]=Ht(i));return t};j.add=zt;j.addAll=St;j.cover=Tt;j.data=Dt;j.extent=Ct;j.find=Pt;j.remove=Et;j.removeAll=Ot;j.root=jt;j.size=Rt;j.visit=Ft;j.visitAfter=Lt;j.x=Wt;j.y=Xt;function P(t){return function(){return t}}function X(t){return(t()-.5)*1e-6}function me(t){return t.x+t.vx}function ge(t){return t.y+t.vy}function pt(t){var e,n,i,a=1,f=1;typeof t!="function"&&(t=P(t==null?1:+t));function s(){for(var l,d=e.length,y,m,h,v,r,c,p=0;p<f;++p)for(y=q(e,me,ge).visitAfter(o),l=0;l<d;++l)m=e[l],r=n[m.index],c=r*r,h=m.x+m.vx,v=m.y+m.vy,y.visit(g);function g(b,w,N,z,I){var T=b.data,O=b.r,D=r+O;if(T){if(T.index>m.index){var L=h-T.x-T.vx,B=v-T.y-T.vy,C=L*L+B*B;C<D*D&&(L===0&&(L=X(i),C+=L*L),B===0&&(B=X(i),C+=B*B),C=(D-(C=Math.sqrt(C)))/C*a,m.vx+=(L*=C)*(D=(O*=O)/(c+O)),m.vy+=(B*=C)*D,T.vx-=L*(D=1-D),T.vy-=B*D)}return}return w>h+D||z<h-D||N>v+D||I<v-D}}function o(l){if(l.data)return l.r=n[l.data.index];for(var d=l.r=0;d<4;++d)l[d]&&l[d].r>l.r&&(l.r=l[d].r)}function u(){if(e){var l,d=e.length,y;for(n=new Array(d),l=0;l<d;++l)y=e[l],n[y.index]=+t(y,l,e)}}return s.initialize=function(l,d){e=l,i=d,u()},s.iterations=function(l){return arguments.length?(f=+l,s):f},s.strength=function(l){return arguments.length?(a=+l,s):a},s.radius=function(l){return arguments.length?(t=typeof l=="function"?l:P(+l),u(),s):t},s}function we(t){return t.index}function Qt(t,e){var n=t.get(e);if(!n)throw new Error("node not found: "+e);return n}function dt(t){var e=we,n=y,i,a=P(30),f,s,o,u,l,d=1;t==null&&(t=[]);function y(c){return 1/Math.min(o[c.source.index],o[c.target.index])}function m(c){for(var p=0,g=t.length;p<d;++p)for(var b=0,w,N,z,I,T,O,D;b<g;++b)w=t[b],N=w.source,z=w.target,I=z.x+z.vx-N.x-N.vx||X(l),T=z.y+z.vy-N.y-N.vy||X(l),O=Math.sqrt(I*I+T*T),O=(O-f[b])/O*c*i[b],I*=O,T*=O,z.vx-=I*(D=u[b]),z.vy-=T*D,N.vx+=I*(D=1-D),N.vy+=T*D}function h(){if(s){var c,p=s.length,g=t.length,b=new Map(s.map((N,z)=>[e(N,z,s),N])),w;for(c=0,o=new Array(p);c<g;++c)w=t[c],w.index=c,typeof w.source!="object"&&(w.source=Qt(b,w.source)),typeof w.target!="object"&&(w.target=Qt(b,w.target)),o[w.source.index]=(o[w.source.index]||0)+1,o[w.target.index]=(o[w.target.index]||0)+1;for(c=0,u=new Array(g);c<g;++c)w=t[c],u[c]=o[w.source.index]/(o[w.source.index]+o[w.target.index]);i=new Array(g),v(),f=new Array(g),r()}}function v(){if(s)for(var c=0,p=t.length;c<p;++c)i[c]=+n(t[c],c,t)}function r(){if(s)for(var c=0,p=t.length;c<p;++c)f[c]=+a(t[c],c,t)}return m.initialize=function(c,p){s=c,l=p,h()},m.links=function(c){return arguments.length?(t=c,h(),m):t},m.id=function(c){return arguments.length?(e=c,m):e},m.iterations=function(c){return arguments.length?(d=+c,m):d},m.strength=function(c){return arguments.length?(n=typeof c=="function"?c:P(+c),v(),m):n},m.distance=function(c){return arguments.length?(a=typeof c=="function"?c:P(+c),r(),m):a},m}var ve={value:()=>{}};function Vt(){for(var t=0,e=arguments.length,n={},i;t<e;++t){if(!(i=arguments[t]+"")||i in n||/[\s.]/.test(i))throw new Error("illegal type: "+i);n[i]=[]}return new rt(n)}function rt(t){this._=t}function _e(t,e){return t.trim().split(/^|\s+/).map(function(n){var i="",a=n.indexOf(".");if(a>=0&&(i=n.slice(a+1),n=n.slice(0,a)),n&&!e.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:i}})}rt.prototype=Vt.prototype={constructor:rt,on:function(t,e){var n=this._,i=_e(t+"",n),a,f=-1,s=i.length;if(arguments.length<2){for(;++f<s;)if((a=(t=i[f]).type)&&(a=Me(n[a],t.name)))return a;return}if(e!=null&&typeof e!="function")throw new Error("invalid callback: "+e);for(;++f<s;)if(a=(t=i[f]).type)n[a]=Ut(n[a],t.name,e);else if(e==null)for(a in n)n[a]=Ut(n[a],t.name,null);return this},copy:function(){var t={},e=this._;for(var n in e)t[n]=e[n].slice();return new rt(t)},call:function(t,e){if((a=arguments.length-2)>0)for(var n=new Array(a),i=0,a,f;i<a;++i)n[i]=arguments[i+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(f=this._[t],i=0,a=f.length;i<a;++i)f[i].value.apply(e,n)},apply:function(t,e,n){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var i=this._[t],a=0,f=i.length;a<f;++a)i[a].value.apply(e,n)}};function Me(t,e){for(var n=0,i=t.length,a;n<i;++n)if((a=t[n]).name===e)return a.value}function Ut(t,e,n){for(var i=0,a=t.length;i<a;++i)if(t[i].name===e){t[i]=ve,t=t.slice(0,i).concat(t.slice(i+1));break}return n!=null&&t.push({name:e,value:n}),t}var yt=Vt;var J=0,Z=0,K=0,$t=1e3,it,tt,ot=0,$=0,at=0,et=typeof performance=="object"&&performance.now?performance:Date,Gt=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function wt(){return $||(Gt(be),$=et.now()+at)}function be(){$=0}function mt(){this._call=this._time=this._next=null}mt.prototype=st.prototype={constructor:mt,restart:function(t,e,n){if(typeof t!="function")throw new TypeError("callback is not a function");n=(n==null?wt():+n)+(e==null?0:+e),!this._next&&tt!==this&&(tt?tt._next=this:it=this,tt=this),this._call=t,this._time=n,gt()},stop:function(){this._call&&(this._call=null,this._time=1/0,gt())}};function st(t,e,n){var i=new mt;return i.restart(t,e,n),i}function Jt(){wt(),++J;for(var t=it,e;t;)(e=$-t._time)>=0&&t._call.call(void 0,e),t=t._next;--J}function qt(){$=(ot=et.now())+at,J=Z=0;try{Jt()}finally{J=0,Ne(),$=0}}function Ae(){var t=et.now(),e=t-ot;e>$t&&(at-=e,ot=t)}function Ne(){for(var t,e=it,n,i=1/0;e;)e._call?(i>e._time&&(i=e._time),t=e,e=e._next):(n=e._next,e._next=null,e=t?t._next=n:it=n);tt=t,gt(i)}function gt(t){if(!J){Z&&(Z=clearTimeout(Z));var e=t-$;e>24?(t<1/0&&(Z=setTimeout(qt,t-et.now()-at)),K&&(K=clearInterval(K))):(K||(ot=et.now(),K=setInterval(Ae,$t)),J=1,Gt(qt))}}function Kt(){let t=1;return()=>(t=(1664525*t+1013904223)%4294967296)/4294967296}function Zt(t){return t.x}function te(t){return t.y}var ke=10,ze=Math.PI*(3-Math.sqrt(5));function vt(t){var e,n=1,i=.001,a=1-Math.pow(i,1/300),f=0,s=.6,o=new Map,u=st(y),l=yt("tick","end"),d=Kt();t==null&&(t=[]);function y(){m(),l.call("tick",e),n<i&&(u.stop(),l.call("end",e))}function m(r){var c,p=t.length,g;r===void 0&&(r=1);for(var b=0;b<r;++b)for(n+=(f-n)*a,o.forEach(function(w){w(n)}),c=0;c<p;++c)g=t[c],g.fx==null?g.x+=g.vx*=s:(g.x=g.fx,g.vx=0),g.fy==null?g.y+=g.vy*=s:(g.y=g.fy,g.vy=0);return e}function h(){for(var r=0,c=t.length,p;r<c;++r){if(p=t[r],p.index=r,p.fx!=null&&(p.x=p.fx),p.fy!=null&&(p.y=p.fy),isNaN(p.x)||isNaN(p.y)){var g=ke*Math.sqrt(.5+r),b=r*ze;p.x=g*Math.cos(b),p.y=g*Math.sin(b)}(isNaN(p.vx)||isNaN(p.vy))&&(p.vx=p.vy=0)}}function v(r){return r.initialize&&r.initialize(t,d),r}return h(),e={tick:m,restart:function(){return u.restart(y),e},stop:function(){return u.stop(),e},nodes:function(r){return arguments.length?(t=r,h(),o.forEach(v),e):t},alpha:function(r){return arguments.length?(n=+r,e):n},alphaMin:function(r){return arguments.length?(i=+r,e):i},alphaDecay:function(r){return arguments.length?(a=+r,e):+a},alphaTarget:function(r){return arguments.length?(f=+r,e):f},velocityDecay:function(r){return arguments.length?(s=1-r,e):1-s},randomSource:function(r){return arguments.length?(d=r,o.forEach(v),e):d},force:function(r,c){return arguments.length>1?(c==null?o.delete(r):o.set(r,v(c)),e):o.get(r)},find:function(r,c,p){var g=0,b=t.length,w,N,z,I,T;for(p==null?p=1/0:p*=p,g=0;g<b;++g)I=t[g],w=r-I.x,N=c-I.y,z=w*w+N*N,z<p&&(T=I,p=z);return T},on:function(r,c){return arguments.length>1?(l.on(r,c),e):l.on(r)}}}function _t(){var t,e,n,i,a=P(-30),f,s=1,o=1/0,u=.81;function l(h){var v,r=t.length,c=q(t,Zt,te).visitAfter(y);for(i=h,v=0;v<r;++v)e=t[v],c.visit(m)}function d(){if(t){var h,v=t.length,r;for(f=new Array(v),h=0;h<v;++h)r=t[h],f[r.index]=+a(r,h,t)}}function y(h){var v=0,r,c,p=0,g,b,w;if(h.length){for(g=b=w=0;w<4;++w)(r=h[w])&&(c=Math.abs(r.value))&&(v+=r.value,p+=c,g+=c*r.x,b+=c*r.y);h.x=g/p,h.y=b/p}else{r=h,r.x=r.data.x,r.y=r.data.y;do v+=f[r.data.index];while(r=r.next)}h.value=v}function m(h,v,r,c){if(!h.value)return!0;var p=h.x-e.x,g=h.y-e.y,b=c-v,w=p*p+g*g;if(b*b/u<w)return w<o&&(p===0&&(p=X(n),w+=p*p),g===0&&(g=X(n),w+=g*g),w<s&&(w=Math.sqrt(s*w)),e.vx+=p*h.value*i/w,e.vy+=g*h.value*i/w),!0;if(h.length||w>=o)return;(h.data!==e||h.next)&&(p===0&&(p=X(n),w+=p*p),g===0&&(g=X(n),w+=g*g),w<s&&(w=Math.sqrt(s*w)));do h.data!==e&&(b=f[h.data.index]*i/w,e.vx+=p*b,e.vy+=g*b);while(h=h.next)}return l.initialize=function(h,v){t=h,n=v,d()},l.strength=function(h){return arguments.length?(a=typeof h=="function"?h:P(+h),d(),l):a},l.distanceMin=function(h){return arguments.length?(s=h*h,l):Math.sqrt(s)},l.distanceMax=function(h){return arguments.length?(o=h*h,l):Math.sqrt(o)},l.theta=function(h){return arguments.length?(u=h*h,l):Math.sqrt(u)},l}function Mt(t){var e=P(.1),n,i,a;typeof t!="function"&&(t=P(t==null?0:+t));function f(o){for(var u=0,l=n.length,d;u<l;++u)d=n[u],d.vx+=(a[u]-d.x)*i[u]*o}function s(){if(n){var o,u=n.length;for(i=new Array(u),a=new Array(u),o=0;o<u;++o)i[o]=isNaN(a[o]=+t(n[o],o,n))?0:+e(n[o],o,n)}}return f.initialize=function(o){n=o,s()},f.strength=function(o){return arguments.length?(e=typeof o=="function"?o:P(+o),s(),f):e},f.x=function(o){return arguments.length?(t=typeof o=="function"?o:P(+o),s(),f):t},f}function bt(t){var e=P(.1),n,i,a;typeof t!="function"&&(t=P(t==null?0:+t));function f(o){for(var u=0,l=n.length,d;u<l;++u)d=n[u],d.vy+=(a[u]-d.y)*i[u]*o}function s(){if(n){var o,u=n.length;for(i=new Array(u),a=new Array(u),o=0;o<u;++o)i[o]=isNaN(a[o]=+t(n[o],o,n))?0:+e(n[o],o,n)}}return f.initialize=function(o){n=o,s()},f.strength=function(o){return arguments.length?(e=typeof o=="function"?o:P(+o),s(),f):e},f.y=function(o){return arguments.length?(t=typeof o=="function"?o:P(+o),s(),f):t},f}var Ie=200,Q=(t,e,n)=>Math.max(e,Math.min(n,t)),Nt=Object.freeze({repulsion:120,distance:100,labels:!0,motion:!0});function ee(){let t=new Map,e=[],n=[],i="",a={...Nt},f=vt().stop().alphaDecay(.035).velocityDecay(.48).force("charge",_t().strength(-a.repulsion).distanceMax(1400)).force("collision",pt(o=>o.radius+12).iterations(2)).force("x",Mt(0).strength(.025)).force("y",bt(0).strength(.025));return{simulation:f,update:o=>{let u=[...new Map((o.nodes||[]).slice(0,Ie).map(r=>[r.id,r])).values()].sort((r,c)=>String(r.id).localeCompare(String(c.id))),l=new Set(u.map(r=>r.id)),d=(o.edges||[]).filter(r=>l.has(r.from)&&l.has(r.to)&&r.from!==r.to),y=JSON.stringify([u.map(r=>r.id),d.map(r=>[r.from,r.to]).sort()]),m=i!==y,h=new Map;for(let r of d)h.set(r.from,(h.get(r.from)||0)+1),h.set(r.to,(h.get(r.to)||0)+1);let v=u.filter(r=>!t.has(r.id));for(let r=0;r<v.length;r++){let c=v[r],p=d.filter(z=>z.from===c.id||z.to===c.id).map(z=>t.get(z.from===c.id?z.to:z.from)).filter(Boolean),g=r*2.399963229728653,b=p.length?32:24*Math.sqrt(r+.5),w=p.length?p.reduce((z,I)=>z+I.x,0)/p.length:0,N=p.length?p.reduce((z,I)=>z+I.y,0)/p.length:0;t.set(c.id,{id:c.id,x:w+Math.cos(g)*b,y:N+Math.sin(g)*b,vx:0,vy:0})}e=u.map(r=>Object.assign(t.get(r.id),r,{degree:h.get(r.id)||0,radius:4+Math.min(3,Math.log2(1+(h.get(r.id)||0)))+Q(Number(r.strength)||0,0,1)*2})),n=d.map(r=>({...r,source:t.get(r.from),target:t.get(r.to)})),m&&(f.nodes(e).force("link",dt(n).id(r=>r.id).distance(a.distance).strength(.18)),f.alpha(i?.25:1)),i=y;for(let r of t.keys())t.size>800&&!l.has(r)&&t.delete(r);return m},get nodes(){return e},get edges(){return n},configure(o){a={...a,...o},f.force("charge").strength(-a.repulsion),f.force("link")?.distance(a.distance),f.alpha(Math.max(.25,f.alpha()))},settle(o=200){f.tick(o)},dispose(){f.stop(),t.clear()}}}function ne(t,e,n){if(!t.length)return{x:e/2,y:n/2,k:1};let i=Math.min(...t.map(u=>u.x-u.radius)),a=Math.max(...t.map(u=>u.x+u.radius)),f=Math.min(...t.map(u=>u.y-u.radius)),s=Math.max(...t.map(u=>u.y+u.radius)),o=Q(Math.min(Math.max(32,e-100)/Math.max(120,a-i),Math.max(32,n-96)/Math.max(120,s-f)),.06,1.6);return{x:e/2-(i+a)*o/2,y:n/2-(f+s)*o/2,k:o}}function At(t,e,n){let i=Q(t.k*e,.06,5);return{k:i,x:n.x-(n.x-t.x)*i/t.k,y:n.y-(n.y-t.y)*i/t.k}}var Se=(t,e)=>t.x<e.x+e.width&&t.x+t.width>e.x&&t.y<e.y+e.height&&t.y+t.height>e.y;function re(t,e,n,i){let a=[...e],f=[];for(let s of t){let{x:o,y:u,radius:l,textWidth:d}=s,y=[{x:o-d/2,y:u+l+5},{x:o-d/2,y:u-l-21},{x:o+l+6,y:u-8},{x:o-l-d-6,y:u-8}];if(s.priority)for(let h of[28,48,72])y.push({x:o-d/2,y:u+l+h},{x:o-d/2,y:u-l-16-h},{x:o+l+h,y:u-8},{x:o-l-d-h,y:u-8});let m=y.map(h=>({...h,width:d,height:16})).find(h=>h.x>=5&&h.y>=5&&h.x+h.width<=n-5&&h.y+h.height<=i-5&&!a.some(v=>Se(h,v)));m&&(a.push({x:m.x-3,y:m.y-2,width:m.width+6,height:m.height+4}),f.push({...s,box:m}))}return f}function Te(t,{onFocus:e=()=>{},onZoom:n=()=>{},tooltip:i,reducedMotion:a=!1,emptyLabel:f=""}={}){let s=t.getContext("2d");if(!s)throw new Error("Canvas 2D is unavailable");let o=ee(),u=1,l=1,d=1,y={x:0,y:0,k:1},m={...Nt},h="",v=null,r=null,c=!1,p=!1,g=null,b=0,w=0,N=new Map,z=[],I=t.ownerDocument.defaultView,T=x=>({x:(x.x-y.x)/y.k,y:(x.y-y.y)/y.k}),O=x=>({x:x.x*y.k+y.x,y:x.y*y.k+y.y}),D=x=>Q(x.radius*Math.sqrt(y.k),2.5,22),L=x=>{let _=t.getBoundingClientRect();return{x:(x.clientX-_.left)*u/_.width,y:(x.clientY-_.top)*l/_.height}},B=x=>{let _=null,k=1/0;for(let A of o.nodes){let W=O(A),V=Math.hypot(W.x-x.x,W.y-x.y);V<=Math.max(10,D(A)+4)&&V<k&&(_=A,k=V)}return _},C=()=>{i&&(i.hidden=!0)},ie=(x,_)=>{v!==x&&(v=x,F()),t.style.cursor=r?"grabbing":x?"pointer":"grab",i&&(i.hidden=!x||!!r,!(!x||r)&&(i.textContent=String(x.title||x.id),i.style.left=`${Q(_.x+14,6,Math.max(6,u-Math.min(260,u-12)))}px`,i.style.top=`${(t.offsetTop||0)+Q(_.y+16,6,l-60)}px`))},oe=()=>{s.setTransform(d,0,0,d,0,0),s.clearRect(0,0,u,l);let x=I.getComputedStyle(t),_=x.color,k=x.getPropertyValue("--dsw-alias-bg-layer-1").trim()||"#ffffff",A=v?.id||h,W=new Set(A?[A]:[]);for(let S of o.edges)S.from===A&&W.add(S.to),S.to===A&&W.add(S.from);s.strokeStyle=_;for(let S of o.edges){let Y=O(S.source),M=O(S.target),R=A&&(S.from===A||S.to===A);s.globalAlpha=R?.6:A?.055:.16,s.lineWidth=R?1.5:.8,s.beginPath(),s.moveTo(Y.x,Y.y),s.lineTo(M.x,M.y),s.stroke()}let V=o.nodes.map(S=>({node:S,...O(S),radius:D(S)})).filter(S=>S.x>=-30&&S.x<=u+30&&S.y>=-30&&S.y<=l+30);for(let S of V){let Y=S.node,M=Y.missing?"#92959c":Y.kind==="global"?"#8b7bd8":Y.kind!=="memory"?"#36a582":Y.layer==="must_remember"?"#d97768":"#618fcd";s.globalAlpha=A&&!W.has(Y.id)?.22:1,s.fillStyle=M,s.beginPath(),s.arc(S.x,S.y,S.radius,0,Math.PI*2),s.fill(),Y.id===A&&(s.strokeStyle=M,s.lineWidth=1.5,s.beginPath(),s.arc(S.x,S.y,S.radius+4,0,Math.PI*2),s.stroke())}if(s.globalAlpha=1,m.labels){s.font="12px system-ui, sans-serif";let S=V.filter(M=>!A||W.has(M.node.id)).filter(M=>y.k>=.45||M.node.id===A||M.node.degree>=3||o.nodes.length<30).sort((M,R)=>+(R.node.id===A)-+(M.node.id===A)||R.node.degree-M.node.degree||String(M.node.id).localeCompare(String(R.node.id))).map(M=>{let R=String(M.node.title||M.node.id),H=R;for(;H.length>1&&s.measureText(H).width>Math.min(136,u-24);)H=H.slice(0,-1);return H!==R&&(H=H.slice(0,-2)+"..."),{...M,text:H,textWidth:s.measureText(H).width+4,priority:M.node.degree>=3||M.node.id===A}}),Y=re(S,V.map(M=>({x:M.x-M.radius-2,y:M.y-M.radius-2,width:M.radius*2+4,height:M.radius*2+4})),u,l);s.textAlign="left",s.textBaseline="top";for(let M of Y){let R={x:Q(M.x,M.box.x,M.box.x+M.box.width),y:Q(M.y,M.box.y,M.box.y+M.box.height)};Math.hypot(R.x-M.x,R.y-M.y)>M.radius+18&&(s.globalAlpha=.25,s.strokeStyle=_,s.lineWidth=.7,s.beginPath(),s.moveTo(M.x,M.y),s.lineTo(R.x,R.y),s.stroke()),s.fillStyle=k,s.globalAlpha=.88,s.fillRect(M.box.x-1,M.box.y,M.box.width+2,M.box.height),s.globalAlpha=M.node.id===A?1:.78,s.fillStyle=_,s.fillText(M.text,M.box.x+2,M.box.y+1)}s.globalAlpha=1}!o.nodes.length&&f&&(s.font="13px system-ui, sans-serif",s.textAlign="center",s.textBaseline="middle",s.fillStyle=_,s.globalAlpha=.55,s.fillText(f,u/2,l/2),s.globalAlpha=1)},ae=x=>{if(g=null,!p){if(m.motion&&!a&&o.simulation.alpha()>o.simulation.alphaMin()){for(w+=b?Math.min(64,x-b):17;w>=1e3/60;w-=1e3/60)o.simulation.tick();b=x,F()}else b=0,w=0;oe()}};function F(){!p&&g===null&&(g=I.requestAnimationFrame(ae))}let ft=()=>{n(y.k),F()},lt=()=>{y=ne(o.nodes,u,l),C(),ft()},nt=(x,_={x:u/2,y:l/2})=>{y=At(y,x,_),C(),ft()},ut=()=>{let x=t.getBoundingClientRect();if(!x.width||!x.height)return;let _=x.width,k=x.height;y.x+=(_-u)/2,y.y+=(k-l)/2,u=_,l=k,d=Math.min(2,I.devicePixelRatio||1),t.width=Math.round(u*d),t.height=Math.round(l*d),F()},G=()=>{r?.node&&(r.node.fx=null,r.node.fy=null,r.node.vx=0,r.node.vy=0)},se=()=>{G();let[x,_]=[...N.values()];r={type:"pinch",distance:Math.max(1,Math.hypot(_.x-x.x,_.y-x.y)),camera:{...y},center:{x:(x.x+_.x)/2,y:(x.y+_.y)/2},moved:!0}},fe=x=>{if(x.button!==0&&x.pointerType!=="touch")return;x.preventDefault(),t.focus({preventScroll:!0});let _=L(x);if(N.set(x.pointerId,_),t.setPointerCapture?.(x.pointerId),N.size>=2){se(),C();return}let k=B(_);r={type:k?"node":"pan",node:k,start:_,camera:{...y},moved:!1,offset:k?{x:k.x-T(_).x,y:k.y-T(_).y}:null},k&&(k.fx=k.x,k.fy=k.y,k.vx=0,k.vy=0),C(),t.style.cursor="grabbing"},le=x=>{let _=L(x);if(!N.has(x.pointerId)||!r){ie(B(_),_);return}if(N.set(x.pointerId,_),r.type==="pinch"){if(N.size<2)return;let[k,A]=[...N.values()],W={x:(k.x+A.x)/2,y:(k.y+A.y)/2};y=At(r.camera,Math.hypot(A.x-k.x,A.y-k.y)/r.distance,r.center),y.x+=W.x-r.center.x,y.y+=W.y-r.center.y,ft()}else{if(r.moved||(r.moved=Math.hypot(_.x-r.start.x,_.y-r.start.y)>5),!r.moved)return;if(r.node){let k=T(_),A=r.node;A.x=A.fx=k.x+r.offset.x,A.y=A.fy=k.y+r.offset.y,A.vx=0,A.vy=0,o.simulation.alpha(Math.max(.08,o.simulation.alpha()))}else y.x=r.camera.x+_.x-r.start.x,y.y=r.camera.y+_.y-r.start.y;F()}},ue=x=>{if(!N.has(x.pointerId))return;let _=x.type!=="pointerup",k=r?.node,A=!_&&!r?.moved&&r?.type!=="pinch";G(),N.delete(x.pointerId),r=null,N.size&&(r={type:"pan",start:[...N.values()][0],camera:{...y},moved:!0}),t.hasPointerCapture?.(x.pointerId)&&t.releasePointerCapture(x.pointerId),A&&e(k?.id||""),v=null,t.style.cursor="grab",C(),F()},U=(x,_,k,A)=>{x.addEventListener(_,k,A),z.push(()=>x.removeEventListener(_,k,A))};U(t,"pointerdown",fe),U(t,"pointermove",le);for(let x of["pointerup","pointercancel","lostpointercapture"])U(t,x,ue);U(t,"pointerleave",()=>{r||(v=null,C(),F())}),U(t,"wheel",x=>{x.preventDefault(),nt(Math.exp(-Q(x.deltaY,-160,160)*.0025),L(x))},{passive:!1}),U(t,"keydown",x=>{if(x.key==="+"||x.key==="=")nt(1.25);else if(x.key==="-")nt(.8);else if(x.key==="0"||x.key==="Home")lt();else if(x.key==="Escape")G(),r=null,N.clear(),e(""),C(),F();else if(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(x.key)){let _=x.shiftKey?90:30;y.x+=x.key==="ArrowLeft"?_:x.key==="ArrowRight"?-_:0,y.y+=x.key==="ArrowUp"?_:x.key==="ArrowDown"?-_:0,F()}else return;x.preventDefault()}),U(I,"blur",()=>{G(),r=null,N.clear(),v=null,C(),F()});let kt=I.ResizeObserver?new I.ResizeObserver(ut):null;kt?.observe(t),U(I,"resize",ut);let ct=I.MutationObserver?new I.MutationObserver(F):null;return ct?.observe(t.ownerDocument.documentElement,{attributes:!0,attributeFilter:["class","data-theme","style"]}),t.ownerDocument.body&&ct?.observe(t.ownerDocument.body,{attributes:!0,attributeFilter:["class","data-theme","style"]}),ut(),{update(x,_=""){r?.node&&!x.nodes.some(A=>A.id===r.node.id)&&(G(),r=null,N.clear());let k=o.update(x);h=_,v&&!o.nodes.includes(v)&&(v=null,C()),!c&&o.nodes.length?(o.settle(220),c=!0,lt()):k&&a&&o.settle(180),F()},configure(x){let _=x.repulsion!==void 0&&x.repulsion!==m.repulsion||x.distance!==void 0&&x.distance!==m.distance;m={...m,...x},_&&(o.configure(m),a&&o.settle(180)),F()},fit:lt,zoom:nt,dispose(){p=!0,G(),g!==null&&I.cancelAnimationFrame(g);for(let x of z)x();kt?.disconnect(),ct?.disconnect(),o.dispose(),C()}}}return ye(De);})();
@@ -169,7 +169,10 @@ export function createGraphView(canvas, { onFocus = () => {}, onZoom = () => {},
169
169
  .filter(p => p.x >= -30 && p.x <= width + 30 && p.y >= -30 && p.y <= height + 30)
170
170
  for (const p of visible) {
171
171
  const node = p.node
172
- const color = node.missing ? '#92959c' : node.kind !== 'memory' ? '#36a582' : node.layer === 'must_remember' ? '#d97768' : '#618fcd'
172
+ const color = node.missing ? '#92959c'
173
+ : node.kind === 'global' ? '#8b7bd8'
174
+ : node.kind !== 'memory' ? '#36a582'
175
+ : node.layer === 'must_remember' ? '#d97768' : '#618fcd'
173
176
  context.globalAlpha = active && !neighbors.has(node.id) ? .22 : 1
174
177
  context.fillStyle = color
175
178
  context.beginPath(); context.arc(p.x, p.y, p.radius, 0, Math.PI * 2); context.fill()
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-memu-memory",
3
3
  "icon": "./assets/icon.png",
4
- "version": "1.2.4",
4
+ "version": "1.2.6",
5
5
  "description": "面向长篇 RP 与陪伴对话的 DeepSeek Harness 记忆插件:三层记忆、逐轮召回、来源标注、关系图、图片附件与独立 WebUI。",
6
6
  "keywords": [
7
7
  "deepseek-harness",
@@ -48,7 +48,8 @@ globalThis.__curatorAbsorbReviewTest = {
48
48
 
49
49
  const memuSource = 'const bridge = globalThis.__curatorAbsorbReviewTest;'
50
50
  + 'export const commit = (args) => bridge.commit(args), forget = (args) => bridge.forget(args),'
51
- + 'retrieve = (args) => bridge.retrieve(args), listFiles = (args) => bridge.listFiles(args);'
51
+ + 'retrieve = (args) => bridge.retrieve(args), listFiles = (args) => bridge.listFiles(args),'
52
+ + 'closeMemuResident = () => 0, prewarmMemuResident = async () => false;'
52
53
  const hooks = registerHooks({
53
54
  resolve(specifier, context, nextResolve) {
54
55
  if (specifier === './memu.js') return { url: 'data:text/javascript,' + encodeURIComponent(memuSource), shortCircuit: true }
@@ -36,7 +36,7 @@ const backend = {
36
36
  }
37
37
 
38
38
  globalThis.__backendCompensationTest = backend
39
- const engineSource = 'const bridge = globalThis.__backendCompensationTest; export const commit = bridge.commit, retrieve = bridge.retrieve, forget = bridge.forget, listFiles = bridge.listFiles;'
39
+ const engineSource = 'const bridge = globalThis.__backendCompensationTest; export const commit = bridge.commit, retrieve = bridge.retrieve, forget = bridge.forget, listFiles = bridge.listFiles, closeMemuResident = () => 0, prewarmMemuResident = async () => false;'
40
40
  const hooks = registerHooks({
41
41
  resolve(specifier, context, nextResolve) {
42
42
  if (specifier === './memu.js') {
@@ -7,7 +7,7 @@ import path from 'node:path'
7
7
  const home = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-memu-memory-browser-'))
8
8
  process.env.DSH_MEMU_HOME = home
9
9
 
10
- const { createLibrary, ensureSession, loadPrivateIndex, savePrivateIndex, listLibraries, getSessionBinding } = await import('../lib/state.js')
10
+ const { createLibrary, ensureSession, loadPrivateIndex, savePrivateIndex, listLibraries, getSessionBinding, setSessionBinding, getLibrary, normalizeCwd } = await import('../lib/state.js')
11
11
  const { privateRemember, privateRecall, privateUpdate, privateArchive, globalList, globalRecall } = await import('../lib/memory.js')
12
12
  const { dispatch } = await import('../lib/rpc.js')
13
13
 
@@ -257,6 +257,63 @@ test('folder sessions use host titles and hide archived or deleted conversations
257
257
  assert.equal(out.sessions[0].title, '可见对话')
258
258
  })
259
259
 
260
+ test('turning private memory on backfills the folder library instead of leaving libraryId null', async () => {
261
+ const cwd = path.join(home, 'repair-scope')
262
+ setSessionBinding('repair-scope-session', {
263
+ scopeKey: cwd, useLibrary: false, useGlobal: true, libraryId: null,
264
+ domain: 'coding', domainOverride: 'rp',
265
+ })
266
+ const out = await dispatch({}, 'setSessionScope', { sessionId: 'repair-scope-session', useLibrary: true })
267
+ const binding = getSessionBinding('repair-scope-session')
268
+ assert.equal(binding.useLibrary, true)
269
+ assert.ok(binding.libraryId, 'enabling private memory must bind a library')
270
+ assert.equal(out.binding.libraryId, binding.libraryId)
271
+ assert.equal(getLibrary(binding.libraryId).scopeKey, normalizeCwd(cwd))
272
+ })
273
+
274
+ test('enabling a folder policy backfills conversations that already opted into private memory', async () => {
275
+ const cwd = path.join(home, 'repair-folder')
276
+ setSessionBinding('repair-folder-a', { scopeKey: cwd, useLibrary: true, useGlobal: true, libraryId: null, domain: 'coding', domainOverride: 'rp' })
277
+ setSessionBinding('repair-folder-b', { scopeKey: cwd, useLibrary: false, useGlobal: true, libraryId: null, domain: 'coding', domainOverride: 'rp' })
278
+ await dispatch({}, 'setFolderPolicy', { scopeKey: cwd, useLibrary: true })
279
+ const a = getSessionBinding('repair-folder-a')
280
+ assert.ok(a.libraryId, 'a private-enabled conversation must be bound')
281
+ assert.equal(getLibrary(a.libraryId).scopeKey, normalizeCwd(cwd))
282
+ const b = getSessionBinding('repair-folder-b')
283
+ assert.equal(b.libraryId, null, 'a conversation that opted out stays opted out')
284
+ assert.equal(b.useLibrary, false)
285
+ })
286
+
287
+ test('the global curation picker hides archived and deleted conversations too', async () => {
288
+ const cwd = path.join(home, 'browser-global-list')
289
+ const ctx = {
290
+ get(name) {
291
+ if (name === 'sessionQuery') {
292
+ return {
293
+ listSessions: async () => [
294
+ { header: { id: 'global-visible', cwd }, live: true, persisted: true },
295
+ { header: { id: 'global-archived', cwd }, live: false, persisted: true },
296
+ { header: { id: 'global-deleted', cwd }, live: false, persisted: true },
297
+ { header: { id: 'global-subagent', cwd, origin: 'subagent' }, live: false, persisted: true },
298
+ ],
299
+ readTitleSnapshots: async (ids) => ids.map((sessionId) => ({ sessionId, status: 'fulfilled', value: {} })),
300
+ }
301
+ }
302
+ if (name === 'workspaceRegistry') {
303
+ return {
304
+ archivedSessionIds: ['global-archived'],
305
+ // The deleted conversation's log still exists, but its workspace no
306
+ // longer claims it. listSessions() above still returns it.
307
+ list: () => [{ path: cwd, sessionIds: ['global-visible', 'global-archived'] }],
308
+ }
309
+ }
310
+ return null
311
+ },
312
+ }
313
+ const out = await dispatch(ctx, 'listSessions', { limit: 80 })
314
+ assert.deepEqual(out.sessions.map((s) => s.id), ['global-visible'])
315
+ })
316
+
260
317
  // ---- provenance in the browser, and the private review queue ----
261
318
 
262
319
  test('the browser shows where a memory came from, and lets it be corrected', async () => {
@@ -759,6 +759,45 @@ test('local vector settings render catalog controls and native download and migr
759
759
  assert.ok(!rpcCalls.some((call) => /downloadLocalVector|selectLocalVector|switchLocalVector/.test(call.endpoint)), 'rendering performed a model operation')
760
760
  })
761
761
 
762
+ test('runtime download shows MB/s, selectable sources and pause/stop controls', async (t) => {
763
+ const { tree, nodes, rpcCalls } = await renderVectorSettings(t, {
764
+ settings: { memoryBackend: 'api', vectorSource: 'local' },
765
+ localVector: {
766
+ ...VECTOR_CATALOG_FIXTURE,
767
+ runtime: {
768
+ status: 'downloading',
769
+ ready: false,
770
+ sources: [
771
+ { id: 'npmjs', label: 'npmjs' },
772
+ { id: 'npmmirror', label: 'npmmirror' },
773
+ ],
774
+ downloadSource: 'npmjs',
775
+ progress: {
776
+ bytes: 50 * 1048576,
777
+ totalBytes: 100 * 1048576,
778
+ speedBps: 2.5 * 1048576,
779
+ current: 'onnxruntime-node',
780
+ },
781
+ },
782
+ vector: {},
783
+ },
784
+ })
785
+ const text = treeText(tree)
786
+ for (const visible of ['managedVectorPause', 'managedVectorStop', 'managedVectorRuntimeSource', 'npmjs', 'npmmirror', '2.5 MB/s']) {
787
+ assert.ok(text.includes(visible), visible + ' did not render')
788
+ }
789
+ const progress = nodes.find((node) => node.type === 'progress' && node.props['aria-label'] === 'managedVectorProgress')
790
+ assert.ok(progress, 'runtime progress bar missing')
791
+ assert.equal(progress.props.value, 50 * 1048576)
792
+ assert.equal(progress.props.max, 100 * 1048576)
793
+ const pause = nodes.find((node) => node.type === 'button' && node.props.children === 'managedVectorPause')
794
+ const stop = nodes.find((node) => node.type === 'button' && node.props.children === 'managedVectorStop')
795
+ assert.ok(pause && stop, 'pause/stop buttons missing')
796
+ await pause.props.onClick()
797
+ await new Promise((resolve) => setTimeout(resolve, 0))
798
+ assert.ok(rpcCalls.some((call) => call.endpoint === 'installLocalVectorRuntime' && call.payload?.action === 'pause'))
799
+ })
800
+
762
801
  test('migration with unknown total renders indeterminate native progress', async (t) => {
763
802
  const { tree, nodes } = await renderVectorSettings(t, {
764
803
  settings: { memoryBackend: 'api', vectorSource: 'local' },
@@ -9,7 +9,7 @@ process.env.DSH_MEMU_HOME = home
9
9
 
10
10
  const state = await import('../lib/state.js')
11
11
  const activity = await import('../lib/activity-log.js')
12
- const { requestPrivateConsolidation, isConsolidating, consolidationWaitBudget, CONSOLIDATION_WAIT_POLICY } = await import('../lib/private.js')
12
+ const { requestPrivateConsolidation, isConsolidating, consolidationWaitBudget, CONSOLIDATION_WAIT_POLICY, CONSOLIDATION_WINDOW_EVENTS, compactSeedEvents, selectConsolidationWindow, selectTailTurnWindow } = await import('../lib/private.js')
13
13
 
14
14
  test.after(() => {
15
15
  try { fs.rmSync(home, { recursive: true, force: true }) } catch {}
@@ -100,9 +100,15 @@ function host({ live = false, whenIdle = null, parentOptions = { provider: 'test
100
100
  rec.forkFollowups.push({ child: spec.sessionId, message })
101
101
  if (emitTurnEnd) {
102
102
  if (turnReason?.kind === 'completed') {
103
- const throughSeq = 2 + extraEvents.length + padding
103
+ // The worker receipt must match the window the fork was seeded
104
+ // with, not the whole parent transcript.
105
+ const child = state.getSessionBinding(spec.sessionId)
106
+ const fromSeq = Number.isSafeInteger(child?.snapshotFromSeq) ? child.snapshotFromSeq : 0
107
+ const throughSeq = Number.isSafeInteger(child?.snapshotThroughSeq)
108
+ ? child.snapshotThroughSeq
109
+ : 2 + extraEvents.length + padding
104
110
  for (const handler of rec.sessionHandlers) {
105
- handler(childSession, { type: 'assistant/message', seq: 99, data: { message: { content: [{ type: 'text', text: receiptFence({ fromSeq: 0, throughSeq }, state.getSessionBinding(spec.sessionId)) }] } } })
111
+ handler(childSession, { type: 'assistant/message', seq: 99, data: { message: { content: [{ type: 'text', text: receiptFence({ fromSeq, throughSeq }, child) }] } } })
106
112
  }
107
113
  }
108
114
  for (const handler of rec.sessionHandlers) {
@@ -213,7 +219,7 @@ test('a closed session inherits the last request/header event', async () => {
213
219
  const result = await requestPrivateConsolidation(ctx, 'fork-closed')
214
220
  assert.equal(result.ok, true)
215
221
  const spec = ctx.rec.created[0]
216
- assert.equal(spec.inheritedEventCount, 5, 'the header events are part of the inherited log')
222
+ assert.equal(spec.inheritedEventCount, 3, 'only conversation events are seeded; request/header is noise')
217
223
  assert.deepEqual(spec.agentOptions, { provider: 'latest', model: 'latest-model', reasoningEffort: 'low', maxTokens: 4096 })
218
224
  })
219
225
 
@@ -349,9 +355,9 @@ test('a large transcript with nothing new since the cursor does not refork', asy
349
355
  const result = await requestPrivateConsolidation(ctx, 'fork-large-thin')
350
356
  assert.equal(result.ok, true)
351
357
  assert.equal(result.skipped, 'no-human-turn', 'the increment carries no human turn to consolidate')
352
- assert.equal(result.settled, false, 'nothing was consolidated, so the cursor must not move')
358
+ assert.equal(result.settled, true, 'a policy skip is terminal: the idle sweep stops re-reading the same greetings')
353
359
  assert.equal(ctx.rec.created.length, 0, 'no fork when the pending increment has no evidence')
354
- assert.equal(state.getSessionBinding('fork-large-thin').lastSleepSeq, 5905, 'the cursor must not advance')
360
+ assert.equal(state.getSessionBinding('fork-large-thin').lastSleepSeq, 5912, 'a terminal policy skip advances the coarse cursor so the same thin tail is not rescanned')
355
361
  })
356
362
 
357
363
  test('a large transcript that was never consolidated does fork, because the backlog is real', async () => {
@@ -365,6 +371,75 @@ test('a large transcript that was never consolidated does fork, because the back
365
371
  assert.equal(result.ok, true, 'the backlog bound lets this one through')
366
372
  assert.equal(ctx.rec.created.length, 1, 'a large unconsolidated backlog is worth exactly one fork')
367
373
  })
374
+ // ---------------------------------------------------------------- window & seed
375
+ test('the seed keeps conversation only, renumbers from zero, and strips replay/stream noise', () => {
376
+ const plugin = { seq: 0, type: 'user/message', data: { source: { kind: 'plugin:dsh-memu-memory', form: 'recall' }, content: [{ type: 'text', text: '旧召回' }] } }
377
+ const runtime = { seq: 1, type: 'user/message', data: { source: { kind: 'runtime-context', form: 'snapshot' }, content: [{ type: 'text', text: '运行时快照' }] } }
378
+ const header = { seq: 2, type: 'request/header', data: { header: {} } }
379
+ const user = { seq: 3, type: 'user/message', data: { source: { kind: 'user' }, content: [{ type: 'text', text: '记住:我不吃香菜' }] } }
380
+ const assistant = { seq: 4, type: 'assistant/message', data: {
381
+ message: {
382
+ source: { provider: 'p', model: 'm', replayState: { huge: 'x'.repeat(400) } },
383
+ content: [{ type: 'reasoning', text: '思考过程' }, { type: 'text', text: '好的' }, { type: 'tool-call', name: 'read', arguments: 'x'.repeat(2000) }],
384
+ },
385
+ stream: { blob: 'y'.repeat(400) },
386
+ } }
387
+ const repeated = 'R'.repeat(4000)
388
+ const tool1 = { seq: 5, type: 'tool/result', data: { message: { content: [{ type: 'text', text: repeated }] } } }
389
+ const tool2 = { seq: 6, type: 'tool/result', data: { message: { content: [{ type: 'text', text: repeated }] } } }
390
+ const catalog = {
391
+ type: 'user/message', seq: 0, time: 1, surfaceOp: 'append',
392
+ data: { role: 'user', source: { kind: 'plugin:dsh-memu-memory', form: 'notice' }, content: [{ type: 'text', text: '已有记忆目录' }] },
393
+ }
394
+ const seed = compactSeedEvents([plugin, runtime, header, user, assistant, tool1, tool2], catalog)
395
+ assert.deepEqual(seed.map(event => event.seq), [0, 1, 2, 3, 4], 'contiguous from zero, catalog at 0')
396
+ assert.match(seed[0].data.content[0].text, /已有记忆目录/)
397
+ assert.equal(seed[1].data.source.kind, 'user', 'only real user messages survive')
398
+ const msg = seed[2].data.message
399
+ assert.equal(msg.content.some(block => block.type === 'reasoning'), false, 'reasoning is not evidence')
400
+ assert.equal(msg.source.replayState, undefined, 'replay state duplicates the body')
401
+ assert.equal(seed[2].data.stream, undefined, 'the raw chunk log is not the message')
402
+ assert.match(msg.content.find(block => block.type === 'tool-call').arguments, /已截断/)
403
+ assert.match(seed[3].data.message.content[0].text, /已截断/)
404
+ assert.match(seed[4].data.message.content[0].text, /与前面相同的工具输出/, 'identical tool output is deduped')
405
+ })
406
+
407
+ test('a long tail is cut to one closed-turn window with a remainder', () => {
408
+ const events = Array.from({ length: CONSOLIDATION_WINDOW_EVENTS + 180 }, (_, seq) => ({ seq, type: 'todo/write', data: {} }))
409
+ const window = selectConsolidationWindow(events)
410
+ assert.equal(window.fromSeq, 0)
411
+ assert.ok(window.events.length <= CONSOLIDATION_WINDOW_EVENTS, 'the window stays bounded')
412
+ assert.ok(window.remaining > 0, 'the rest is left for the next sweep')
413
+ assert.ok(window.throughSeq < events.length - 1)
414
+ })
415
+
416
+ test('a manual re-check starts at a complete turn instead of mid-step', () => {
417
+ const events = [
418
+ { seq: 0, type: 'assistant/message', data: { message: { content: [{ type: 'text', text: '旧回答' }] } } },
419
+ { seq: 1, type: 'user/message', data: { source: { kind: 'user' }, content: [{ type: 'text', text: '最后一问' }] } },
420
+ { seq: 2, type: 'turn/start', data: { turn: 2 } },
421
+ { seq: 3, type: 'assistant/message', data: { message: { content: [{ type: 'text', text: '最后回答' }] } } },
422
+ { seq: 4, type: 'turn/end', data: { turn: 2, reason: { kind: 'completed' } } },
423
+ ]
424
+ const window = selectTailTurnWindow(events)
425
+ assert.equal(window.fromSeq, 1, 'the user message that opened the turn is included')
426
+ assert.equal(window.throughSeq, 4, 'the window ends on a closed turn')
427
+ })
428
+
429
+ test('the same failed snapshot stops re-forking after the failure cap', async () => {
430
+ state.ensureSession('fork-failcap', { cwd: path.join(home, 'proj-failcap'), agentPreset: 'coding' })
431
+ const ctx = host({ live: true, turnReason: { kind: 'error', error: { message: 'provider refused' } } })
432
+ const first = await requestPrivateConsolidation(ctx, 'fork-failcap', { force: true })
433
+ const second = await requestPrivateConsolidation(ctx, 'fork-failcap', { force: true })
434
+ assert.equal(first.ok, false)
435
+ assert.equal(second.ok, false)
436
+ assert.equal(ctx.rec.created.length, 2, 'two real attempts happen')
437
+ const third = await requestPrivateConsolidation(ctx, 'fork-failcap', { force: true })
438
+ assert.equal(third.ok, true)
439
+ assert.equal(third.skipped, 'snapshot-failed')
440
+ assert.equal(ctx.rec.created.length, 2, 'the third call does not pay for the same snapshot again')
441
+ })
442
+
368
443
  // ---------------------------------------------------------------- PTC 兼容
369
444
  // 现场(2026-10-31,yuike-ptc 会话):PTC 模式下 request/header 的工具表只有 run_code,
370
445
  // probe 曾据此判 unavailable(worker-tools-ptc-only),PTC 会话永远不被整理。宿主的
@@ -0,0 +1,113 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+ import fs from 'node:fs'
4
+ import os from 'node:os'
5
+ import path from 'node:path'
6
+
7
+ const home = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-memu-cross-library-'))
8
+ process.env.DSH_MEMU_HOME = home
9
+
10
+ const state = await import('../lib/state.js')
11
+ const { privateRecall, privateList } = await import('../lib/memory.js')
12
+
13
+ test.after(() => {
14
+ state.flushState()
15
+ try { fs.rmSync(home, { recursive: true, force: true }) } catch {}
16
+ })
17
+
18
+ const dir = (name) => path.join(home, name)
19
+ const execFor = (sessionId) => ({ agent: { session: { header: { id: sessionId } } } })
20
+
21
+ function seed(libraryId, id, entry = {}) {
22
+ const index = state.loadPrivateIndex(libraryId)
23
+ index.entries[id] = {
24
+ layer: 'long_term', title: id, content: `body of ${id}`, status: 'active',
25
+ createdAt: '2026-10-01T00:00:00.000Z', ...entry,
26
+ }
27
+ state.savePrivateIndex(libraryId, index)
28
+ }
29
+
30
+ function bind(sessionId, folder, libraryId, domain = 'coding') {
31
+ state.ensureSession(sessionId, { cwd: folder, libraryId })
32
+ state.setSessionBinding(sessionId, { domainOverride: domain })
33
+ }
34
+
35
+ function world() {
36
+ const current = state.ensureLibraryForCwd(dir('current'))
37
+ const other = state.ensureLibraryForCwd(dir('other'))
38
+ const rp = state.ensureLibraryForCwd(dir('rp'))
39
+ const off = state.ensureLibraryForCwd(dir('off'))
40
+ bind('cross-current', dir('current'), current.id, 'coding')
41
+ bind('cross-other', dir('other'), other.id, 'coding')
42
+ bind('cross-rp', dir('rp'), rp.id, 'rp')
43
+ bind('cross-off', dir('off'), off.id, 'coding')
44
+ state.setWorkspacePolicy(dir('off'), { useLibrary: false })
45
+ seed(current.id, 'mem-current', { title: '当前库的部署约定' })
46
+ seed(other.id, 'mem-other', { title: '另一个库的部署约定' })
47
+ seed(other.id, 'mem-secret', { title: '另一个库的部署秘密', visibility: 'secret' })
48
+ seed(rp.id, 'mem-rp', { title: '角色扮演里的部署约定' })
49
+ seed(off.id, 'mem-off', { title: '已关闭文件夹的部署约定' })
50
+ return { current, other, rp, off }
51
+ }
52
+
53
+ test('cross-library recall is opt-in and merges same-domain libraries only', async () => {
54
+ const libs = world()
55
+ const exec = execFor('cross-current')
56
+
57
+ state.updateSettings({ crossLibraryRecall: false })
58
+ const offResult = await privateRecall({ exec, query: '部署约定', topK: 10, relevanceThreshold: 0 })
59
+ assert.deepEqual(offResult.files.map((file) => file.name), ['mem-current'])
60
+
61
+ state.updateSettings({ crossLibraryRecall: true })
62
+ const onResult = await privateRecall({ exec, query: '部署约定', topK: 10, relevanceThreshold: 0 })
63
+ const names = onResult.files.map((file) => file.name).sort()
64
+ // Same-domain (coding) libraries only: the RP folder and the folder whose
65
+ // private switch is off never contribute, even with a matching query.
66
+ assert.deepEqual(names, ['mem-current', 'mem-other', 'mem-secret'])
67
+ assert.deepEqual(onResult.libraries.sort(), [libs.current.id, libs.other.id].sort())
68
+ const foreign = onResult.files.find((file) => file.name === 'mem-other')
69
+ assert.equal(foreign.libraryId, libs.other.id, 'foreign hits keep their owning library')
70
+ assert.equal(onResult.recallRoute, 'cross-library')
71
+ })
72
+
73
+ test('automatic recall keeps the secret exclusion across libraries', async () => {
74
+ world()
75
+ state.updateSettings({ crossLibraryRecall: true })
76
+ const result = await privateRecall({
77
+ exec: execFor('cross-current'), query: '部署约定', topK: 10,
78
+ relevanceThreshold: 0, purpose: 'automatic',
79
+ })
80
+ const names = result.files.map((file) => file.name).sort()
81
+ assert.deepEqual(names, ['mem-current', 'mem-other'])
82
+ assert.ok(!result.files.some((file) => file.entry?.visibility === 'secret'))
83
+ })
84
+
85
+ test('the sidebar list follows the same cross-library scope, while an explicit library stays single', async () => {
86
+ const libs = world()
87
+ state.updateSettings({ crossLibraryRecall: true })
88
+ const all = await privateList({ exec: execFor('cross-current') })
89
+ assert.deepEqual((all.libraries || []).map((library) => library.id).sort(), [libs.current.id, libs.other.id].sort())
90
+ assert.ok(all.files.some((file) => file.name === 'mem-other' && file.libraryId === libs.other.id))
91
+ assert.ok(!all.files.some((file) => file.name === 'mem-rp'), 'different domain is excluded')
92
+ assert.ok(!all.files.some((file) => file.name === 'mem-off'), 'folder with private memory off is excluded')
93
+
94
+ // An explicit libraryId is the browser's selector, not the session scope: it
95
+ // must show exactly that library even when the cross-library setting is on.
96
+ const explicit = await privateList({ exec: execFor('cross-current'), libraryId: libs.current.id })
97
+ assert.deepEqual(explicit.files.map((file) => file.name), ['mem-current'])
98
+ assert.equal(explicit.libraries, undefined)
99
+ })
100
+
101
+ test('the bound library is always included, while other libraries depend on a domain hint', async () => {
102
+ world()
103
+ state.updateSettings({ crossLibraryRecall: true })
104
+ // The bound library's own entries are never domain-filtered; only the extra
105
+ // libraries are. Switching this conversation to `mixed` must not hide its own
106
+ // memories, but it must stop pulling the coding-only library.
107
+ state.setSessionBinding('cross-current', { domainOverride: 'mixed' })
108
+ const result = await privateRecall({
109
+ exec: execFor('cross-current'), query: '当前库的部署约定', topK: 10, relevanceThreshold: 0,
110
+ })
111
+ assert.ok(result.files.some((file) => file.name === 'mem-current'))
112
+ assert.ok(!result.files.some((file) => file.name === 'mem-other'))
113
+ })
@@ -51,7 +51,8 @@ globalThis.__curatorAbsorbTest = {
51
51
 
52
52
  const memuSource = 'const bridge = globalThis.__curatorAbsorbTest;'
53
53
  + 'export const commit = (args) => bridge.commit(args), forget = (args) => bridge.forget(args),'
54
- + 'retrieve = (args) => bridge.retrieve(args), listFiles = (args) => bridge.listFiles(args);'
54
+ + 'retrieve = (args) => bridge.retrieve(args), listFiles = (args) => bridge.listFiles(args),'
55
+ + 'closeMemuResident = () => 0, prewarmMemuResident = async () => false;'
55
56
  const hooks = registerHooks({
56
57
  resolve(specifier, context, nextResolve) {
57
58
  if (specifier === './memu.js') return { url: 'data:text/javascript,' + encodeURIComponent(memuSource), shortCircuit: true }
@@ -24,7 +24,8 @@ globalThis.__curatorClusterTest = {
24
24
  }
25
25
  const memuSource = 'const bridge = globalThis.__curatorClusterTest;'
26
26
  + 'export const commit = (args) => bridge.commit(args), forget = (args) => bridge.forget(args),'
27
- + 'retrieve = (args) => bridge.retrieve(args), listFiles = (args) => bridge.listFiles(args);'
27
+ + 'retrieve = (args) => bridge.retrieve(args), listFiles = (args) => bridge.listFiles(args),'
28
+ + 'closeMemuResident = () => 0, prewarmMemuResident = async () => false;'
28
29
  const hooks = registerHooks({
29
30
  resolve(specifier, context, nextResolve) {
30
31
  if (specifier === './memu.js') return { url: 'data:text/javascript,' + encodeURIComponent(memuSource), shortCircuit: true }
@@ -50,7 +50,8 @@ const realStateUrl = new URL('../lib/state.js', import.meta.url).href
50
50
  const realMemuUrl = new URL('../lib/memu.js', import.meta.url).href
51
51
  const memuSource = 'const bridge = globalThis.__curatorCommitTest;'
52
52
  + 'export const commit = (args) => bridge.commit(args), forget = (args) => bridge.forget(args),'
53
- + 'retrieve = (args) => bridge.retrieve(args), listFiles = (args) => bridge.listFiles(args);'
53
+ + 'retrieve = (args) => bridge.retrieve(args), listFiles = (args) => bridge.listFiles(args),'
54
+ + 'closeMemuResident = () => 0, prewarmMemuResident = async () => false;'
54
55
  const stateSource = [
55
56
  `import * as real from ${JSON.stringify(realStateUrl)}`,
56
57
  'const hook = globalThis.__curatorIndexHook',
@@ -22,7 +22,8 @@ globalThis.__curatorLinkTest = {
22
22
  }
23
23
  const memuSource = 'const bridge = globalThis.__curatorLinkTest;'
24
24
  + 'export const commit = (args) => bridge.commit(args), forget = (args) => bridge.forget(args),'
25
- + 'retrieve = (args) => bridge.retrieve(args), listFiles = (args) => bridge.listFiles(args);'
25
+ + 'retrieve = (args) => bridge.retrieve(args), listFiles = (args) => bridge.listFiles(args),'
26
+ + 'closeMemuResident = () => 0, prewarmMemuResident = async () => false;'
26
27
  const hooks = registerHooks({
27
28
  resolve(specifier, context, nextResolve) {
28
29
  if (specifier === './memu.js') return { url: 'data:text/javascript,' + encodeURIComponent(memuSource), shortCircuit: true }
@@ -32,7 +32,8 @@ globalThis.__curatorReviewTest = {
32
32
 
33
33
  const memuSource = 'const bridge = globalThis.__curatorReviewTest;'
34
34
  + 'export const commit = (args) => bridge.commit(args), forget = (args) => bridge.forget(args),'
35
- + 'retrieve = (args) => bridge.retrieve(args), listFiles = (args) => bridge.listFiles(args);'
35
+ + 'retrieve = (args) => bridge.retrieve(args), listFiles = (args) => bridge.listFiles(args),'
36
+ + 'closeMemuResident = () => 0, prewarmMemuResident = async () => false;'
36
37
  const hooks = registerHooks({
37
38
  resolve(specifier, context, nextResolve) {
38
39
  if (specifier === './memu.js') return { url: 'data:text/javascript,' + encodeURIComponent(memuSource), shortCircuit: true }