sessiongraph 1.0.14 → 1.0.16

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 (41) hide show
  1. package/PRIVACY.md +15 -61
  2. package/README.md +35 -55
  3. package/bin/sessiongraph.mjs +14 -8
  4. package/dist/assets/index-C0jATzD9.css +1 -0
  5. package/dist/assets/{index-D4P4hbvc.js → index-CFlNwG9H.js} +1 -1
  6. package/dist/assets/index-D24Hz9MJ.js +180 -0
  7. package/dist/assets/{index-Kotmn42s.js → index-D7udGrT1.js} +1 -1
  8. package/dist/assets/{index-BLM-0yG6.js → index-U9QGDl1t.js} +1 -1
  9. package/dist/assets/katagami-sans-DMv8PCo8.woff2 +0 -0
  10. package/dist/assets/licenses/hugeicons.txt +21 -0
  11. package/dist/assets/licenses/katagami.txt +93 -0
  12. package/dist/assets/public-viewer-CyDoUT6s.css +1 -0
  13. package/dist/assets/public-viewer-iQBchlbq.js +24 -0
  14. package/dist/assets/scene-DmT4K5Nj.js +248 -0
  15. package/dist/assets/share-DrezE0sG.js +7 -0
  16. package/dist/assets/{three-D_1Qt16u.js → three-DDiuFd7k.js} +21 -21
  17. package/dist/assets/{worker-C10U_apJ.js → worker-B9mWJfQ6.js} +1 -1
  18. package/dist/index.html +2 -2
  19. package/dist-server/cli.mjs +50326 -17640
  20. package/dist-server/install-cli.mjs +204 -0
  21. package/dist-server/server.mjs +1089 -379
  22. package/docs/cli.md +293 -190
  23. package/docs/guide.md +16 -9
  24. package/docs/import-coverage.md +73 -5
  25. package/docs/performance.md +164 -0
  26. package/docs/releases.md +6 -0
  27. package/package.json +18 -10
  28. package/dist/assets/external-links-BmBkCsrt.js +0 -1
  29. package/dist/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
  30. package/dist/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
  31. package/dist/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
  32. package/dist/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
  33. package/dist/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
  34. package/dist/assets/index-B1kyvo41.js +0 -175
  35. package/dist/assets/index-Du0_nVjH.css +0 -1
  36. package/dist/assets/publishing-CEvQPkO1.css +0 -1
  37. package/dist/assets/publishing-D9CqkbeB.js +0 -23
  38. package/dist/assets/scene-CTHyYtma.js +0 -139
  39. package/dist/assets/share-Cw1E-ED9.js +0 -7
  40. package/docs/importer-comparison.md +0 -48
  41. package/docs/session-artifacts-audit.md +0 -176
@@ -1,2 +1,2 @@
1
- (function(){"use strict";const ve="ENTRIES",le="KEYS",he="VALUES";class K{constructor(e,t){const n=e._tree,o=Array.from(n.keys());this.set=e,this._type=t,this._path=o.length>0?[{node:n,keys:o}]:[]}next(){const e=this.dive();return this.backtrack(),e}dive(){if(this._path.length===0)return{done:!0,value:void 0};const{node:e,keys:t}=M(this._path);if(M(t)==="")return{done:!1,value:this.result()};const n=e.get(M(t));return this._path.push({node:n,keys:Array.from(n.keys())}),this.dive()}backtrack(){if(this._path.length===0)return;const e=M(this._path).keys;e.pop(),!(e.length>0)&&(this._path.pop(),this.backtrack())}key(){return this.set._prefix+this._path.map(({keys:e})=>M(e)).filter(e=>e!=="").join("")}value(){return M(this._path).node.get("")}result(){switch(this._type){case he:return this.value();case le:return this.key();default:return[this.key(),this.value()]}}[Symbol.iterator](){return this}}const M=s=>s[s.length-1],ke=(s,e,t)=>{const n=new Map;if(e===void 0)return n;const o=e.length+1,i=o+t,r=new Uint8Array(i*o).fill(t+1);for(let c=0;c<o;++c)r[c]=c;for(let c=1;c<i;++c)r[c*o]=c;return ue(s,e,t,n,r,1,o,""),n},ue=(s,e,t,n,o,i,r,c)=>{const a=i*r;e:for(const d of s.keys())if(d===""){const h=o[a-1];h<=t&&n.set(c,[s.get(d),h])}else{let h=i;for(let _=0;_<d.length;++_,++h){const m=d[_],l=r*h,f=l-r;let p=o[l];const u=Math.max(0,h-t-1),g=Math.min(r-1,h+t);for(let w=u;w<g;++w){const O=m!==e[w],V=o[f+w]+ +O,j=o[f+w+1]+1,x=o[l+w]+1,z=o[l+w+1]=Math.min(V,j,x);z<p&&(p=z)}if(p>t)continue e}ue(s.get(d),e,t,n,o,h,r,c+d)}};class I{constructor(e=new Map,t=""){this._size=void 0,this._tree=e,this._prefix=t}atPrefix(e){if(!e.startsWith(this._prefix))throw new Error("Mismatched prefix");const[t,n]=W(this._tree,e.slice(this._prefix.length));if(t===void 0){const[o,i]=Z(n);for(const r of o.keys())if(r!==""&&r.startsWith(i)){const c=new Map;return c.set(r.slice(i.length),o.get(r)),new I(c,e)}}return new I(t,e)}clear(){this._size=void 0,this._tree.clear()}delete(e){return this._size=void 0,ze(this._tree,e)}entries(){return new K(this,ve)}forEach(e){for(const[t,n]of this)e(t,n,this)}fuzzyGet(e,t){return ke(this._tree,e,t)}get(e){const t=H(this._tree,e);return t!==void 0?t.get(""):void 0}has(e){const t=H(this._tree,e);return t!==void 0&&t.has("")}keys(){return new K(this,le)}set(e,t){if(typeof e!="string")throw new Error("key must be a string");return this._size=void 0,X(this._tree,e).set("",t),this}get size(){if(this._size)return this._size;this._size=0;const e=this.entries();for(;!e.next().done;)this._size+=1;return this._size}update(e,t){if(typeof e!="string")throw new Error("key must be a string");this._size=void 0;const n=X(this._tree,e);return n.set("",t(n.get(""))),this}fetch(e,t){if(typeof e!="string")throw new Error("key must be a string");this._size=void 0;const n=X(this._tree,e);let o=n.get("");return o===void 0&&n.set("",o=t()),o}values(){return new K(this,he)}[Symbol.iterator](){return this.entries()}static from(e){const t=new I;for(const[n,o]of e)t.set(n,o);return t}static fromObject(e){return I.from(Object.entries(e))}}const W=(s,e,t=[])=>{if(e.length===0||s==null)return[s,t];for(const n of s.keys())if(n!==""&&e.startsWith(n))return t.push([s,n]),W(s.get(n),e.slice(n.length),t);return t.push([s,e]),W(void 0,"",t)},H=(s,e)=>{if(e.length===0||s==null)return s;for(const t of s.keys())if(t!==""&&e.startsWith(t))return H(s.get(t),e.slice(t.length))},X=(s,e)=>{const t=e.length;e:for(let n=0;s&&n<t;){for(const i of s.keys())if(i!==""&&e[n]===i[0]){const r=Math.min(t-n,i.length);let c=1;for(;c<r&&e[n+c]===i[c];)++c;const a=s.get(i);if(c===i.length)s=a;else{const d=new Map;d.set(i.slice(c),a),s.set(e.slice(n,n+c),d),s.delete(i),s=d}n+=c;continue e}const o=new Map;return s.set(e.slice(n),o),o}return s},ze=(s,e)=>{const[t,n]=W(s,e);if(t!==void 0){if(t.delete(""),t.size===0)fe(n);else if(t.size===1){const[o,i]=t.entries().next().value;me(n,o,i)}}},fe=s=>{if(s.length===0)return;const[e,t]=Z(s);if(e.delete(t),e.size===0)fe(s.slice(0,-1));else if(e.size===1){const[n,o]=e.entries().next().value;n!==""&&me(s.slice(0,-1),n,o)}},me=(s,e,t)=>{if(s.length===0)return;const[n,o]=Z(s);n.set(o+e,t),n.delete(o)},Z=s=>s[s.length-1],ee="or",pe="and",Me="and_not";class C{constructor(e){if(e?.fields==null)throw new Error('MiniSearch: option "fields" must be provided');const t=e.autoVacuum==null||e.autoVacuum===!0?oe:e.autoVacuum;this._options={...se,...e,autoVacuum:t,searchOptions:{...ge,...e.searchOptions||{}},autoSuggestOptions:{...Te,...e.autoSuggestOptions||{}}},this._index=new I,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldIds={},this._fieldLength=new Map,this._avgFieldLength=[],this._nextId=0,this._storedFields=new Map,this._dirtCount=0,this._currentVacuum=null,this._enqueuedVacuum=null,this._enqueuedVacuumConditions=ie,this.addFields(this._options.fields)}add(e){const{extractField:t,stringifyField:n,tokenize:o,processTerm:i,fields:r,idField:c}=this._options,a=t(e,c);if(a==null)throw new Error(`MiniSearch: document does not have ID field "${c}"`);if(this._idToShortId.has(a))throw new Error(`MiniSearch: duplicate ID ${a}`);const d=this.addDocumentId(a);this.saveStoredFields(d,e);for(const h of r){const _=t(e,h);if(_==null)continue;const m=o(n(_,h),h),l=this._fieldIds[h],f=new Set(m).size;this.addFieldLength(d,l,this._documentCount-1,f);for(const p of m){const u=i(p,h);if(Array.isArray(u))for(const g of u)this.addTerm(l,d,g);else u&&this.addTerm(l,d,u)}}}addAll(e){for(const t of e)this.add(t)}addAllAsync(e,t={}){const{chunkSize:n=10}=t,o={chunk:[],promise:Promise.resolve()},{chunk:i,promise:r}=e.reduce(({chunk:c,promise:a},d,h)=>(c.push(d),(h+1)%n===0?{chunk:[],promise:a.then(()=>new Promise(_=>setTimeout(_,0))).then(()=>this.addAll(c))}:{chunk:c,promise:a}),o);return r.then(()=>this.addAll(i))}remove(e){const{tokenize:t,processTerm:n,extractField:o,stringifyField:i,fields:r,idField:c}=this._options,a=o(e,c);if(a==null)throw new Error(`MiniSearch: document does not have ID field "${c}"`);const d=this._idToShortId.get(a);if(d==null)throw new Error(`MiniSearch: cannot remove document with ID ${a}: it is not in the index`);for(const h of r){const _=o(e,h);if(_==null)continue;const m=t(i(_,h),h),l=this._fieldIds[h],f=new Set(m).size;this.removeFieldLength(d,l,this._documentCount,f);for(const p of m){const u=n(p,h);if(Array.isArray(u))for(const g of u)this.removeTerm(l,d,g);else u&&this.removeTerm(l,d,u)}}this._storedFields.delete(d),this._documentIds.delete(d),this._idToShortId.delete(a),this._fieldLength.delete(d),this._documentCount-=1}removeAll(e){if(e)for(const t of e)this.remove(t);else{if(arguments.length>0)throw new Error("Expected documents to be present. Omit the argument to remove all documents.");this._index=new I,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldLength=new Map,this._avgFieldLength=[],this._storedFields=new Map,this._nextId=0}}discard(e){const t=this._idToShortId.get(e);if(t==null)throw new Error(`MiniSearch: cannot discard document with ID ${e}: it is not in the index`);this._idToShortId.delete(e),this._documentIds.delete(t),this._storedFields.delete(t),(this._fieldLength.get(t)||[]).forEach((n,o)=>{this.removeFieldLength(t,o,this._documentCount,n)}),this._fieldLength.delete(t),this._documentCount-=1,this._dirtCount+=1,this.maybeAutoVacuum()}maybeAutoVacuum(){if(this._options.autoVacuum===!1)return;const{minDirtFactor:e,minDirtCount:t,batchSize:n,batchWait:o}=this._options.autoVacuum;this.conditionalVacuum({batchSize:n,batchWait:o},{minDirtCount:t,minDirtFactor:e})}discardAll(e){const t=this._options.autoVacuum;try{this._options.autoVacuum=!1;for(const n of e)this.discard(n)}finally{this._options.autoVacuum=t}this.maybeAutoVacuum()}replace(e){const{idField:t,extractField:n}=this._options,o=n(e,t);this.discard(o),this.add(e)}vacuum(e={}){return this.conditionalVacuum(e)}conditionalVacuum(e,t){return this._currentVacuum?(this._enqueuedVacuumConditions=this._enqueuedVacuumConditions&&t,this._enqueuedVacuum!=null?this._enqueuedVacuum:(this._enqueuedVacuum=this._currentVacuum.then(()=>{const n=this._enqueuedVacuumConditions;return this._enqueuedVacuumConditions=ie,this.performVacuuming(e,n)}),this._enqueuedVacuum)):this.vacuumConditionsMet(t)===!1?Promise.resolve():(this._currentVacuum=this.performVacuuming(e),this._currentVacuum)}async performVacuuming(e,t){const n=this._dirtCount;if(this.vacuumConditionsMet(t)){const o=e.batchSize||ne.batchSize,i=e.batchWait||ne.batchWait;let r=1;for(const[c,a]of this._index){for(const[d,h]of a)for(const[_]of h)this._documentIds.has(_)||(h.size<=1?a.delete(d):h.delete(_));this._index.get(c).size===0&&this._index.delete(c),r%o===0&&await new Promise(d=>setTimeout(d,i)),r+=1}this._dirtCount-=n}await null,this._currentVacuum=this._enqueuedVacuum,this._enqueuedVacuum=null}vacuumConditionsMet(e){if(e==null)return!0;let{minDirtCount:t,minDirtFactor:n}=e;return t=t||oe.minDirtCount,n=n||oe.minDirtFactor,this.dirtCount>=t&&this.dirtFactor>=n}get isVacuuming(){return this._currentVacuum!=null}get dirtCount(){return this._dirtCount}get dirtFactor(){return this._dirtCount/(1+this._documentCount+this._dirtCount)}has(e){return this._idToShortId.has(e)}getStoredFields(e){const t=this._idToShortId.get(e);if(t!=null)return this._storedFields.get(t)}search(e,t={}){const{searchOptions:n}=this._options,o={...n,...t},i=this.executeQuery(e,t),r=[];for(const[c,{score:a,terms:d,match:h}]of i){const _=d.length||1,m={id:this._documentIds.get(c),score:a*_,terms:Object.keys(h),queryTerms:d,match:h};Object.assign(m,this._storedFields.get(c)),(o.filter==null||o.filter(m))&&r.push(m)}return e===C.wildcard&&o.boostDocument==null||r.sort(we),r}autoSuggest(e,t={}){t={...this._options.autoSuggestOptions,...t};const n=new Map;for(const{score:i,terms:r}of this.search(e,t)){const c=r.join(" "),a=n.get(c);a!=null?(a.score+=i,a.count+=1):n.set(c,{score:i,terms:r,count:1})}const o=[];for(const[i,{score:r,terms:c,count:a}]of n)o.push({suggestion:i,terms:c,score:r/a});return o.sort(we),o}get documentCount(){return this._documentCount}get termCount(){return this._index.size}static loadJSON(e,t){if(t==null)throw new Error("MiniSearch: loadJSON should be given the same options used when serializing the index");return this.loadJS(JSON.parse(e),t)}static async loadJSONAsync(e,t){if(t==null)throw new Error("MiniSearch: loadJSON should be given the same options used when serializing the index");return this.loadJSAsync(JSON.parse(e),t)}static getDefault(e){if(se.hasOwnProperty(e))return te(se,e);throw new Error(`MiniSearch: unknown option "${e}"`)}static loadJS(e,t){const{index:n,documentIds:o,fieldLength:i,storedFields:r,serializationVersion:c}=e,a=this.instantiateMiniSearch(e,t);a._documentIds=P(o),a._fieldLength=P(i),a._storedFields=P(r);for(const[d,h]of a._documentIds)a._idToShortId.set(h,d);for(const[d,h]of n){const _=new Map;for(const m of Object.keys(h)){let l=h[m];c===1&&(l=l.ds),_.set(parseInt(m,10),P(l))}a._index.set(d,_)}return a}static async loadJSAsync(e,t){const{index:n,documentIds:o,fieldLength:i,storedFields:r,serializationVersion:c}=e,a=this.instantiateMiniSearch(e,t);a._documentIds=await U(o),a._fieldLength=await U(i),a._storedFields=await U(r);for(const[h,_]of a._documentIds)a._idToShortId.set(_,h);let d=0;for(const[h,_]of n){const m=new Map;for(const l of Object.keys(_)){let f=_[l];c===1&&(f=f.ds),m.set(parseInt(l,10),await U(f))}++d%1e3===0&&await xe(0),a._index.set(h,m)}return a}static instantiateMiniSearch(e,t){const{documentCount:n,nextId:o,fieldIds:i,averageFieldLength:r,dirtCount:c,serializationVersion:a}=e;if(a!==1&&a!==2)throw new Error("MiniSearch: cannot deserialize an index created with an incompatible version");const d=new C(t);return d._documentCount=n,d._nextId=o,d._idToShortId=new Map,d._fieldIds=i,d._avgFieldLength=r,d._dirtCount=c||0,d._index=new I,d}executeQuery(e,t={}){if(e===C.wildcard)return this.executeWildcardQuery(t);if(typeof e!="string"){const m={...t,...e,queries:void 0},l=e.queries.map(f=>this.executeQuery(f,m));return this.combineResults(l,m.combineWith)}const{tokenize:n,processTerm:o,searchOptions:i}=this._options,r={tokenize:n,processTerm:o,...i,...t},{tokenize:c,processTerm:a}=r,_=c(e).flatMap(m=>a(m)).filter(m=>!!m).map(De(r)).map(m=>this.executeQuerySpec(m,r));return this.combineResults(_,r.combineWith)}executeQuerySpec(e,t){const n={...this._options.searchOptions,...t},o=(n.fields||this._options.fields).reduce((p,u)=>({...p,[u]:te(n.boost,u)||1}),{}),{boostDocument:i,weights:r,maxFuzzy:c,bm25:a}=n,{fuzzy:d,prefix:h}={...ge.weights,...r},_=this._index.get(e.term),m=this.termResults(e.term,e.term,1,e.termBoost,_,o,i,a);let l,f;if(e.prefix&&(l=this._index.atPrefix(e.term)),e.fuzzy){const p=e.fuzzy===!0?.2:e.fuzzy,u=p<1?Math.min(c,Math.round(e.term.length*p)):p;u&&(f=this._index.fuzzyGet(e.term,u))}if(l)for(const[p,u]of l){const g=p.length-e.term.length;if(!g)continue;f?.delete(p);const w=h*p.length/(p.length+.3*g);this.termResults(e.term,p,w,e.termBoost,u,o,i,a,m)}if(f)for(const p of f.keys()){const[u,g]=f.get(p);if(!g)continue;const w=d*p.length/(p.length+g);this.termResults(e.term,p,w,e.termBoost,u,o,i,a,m)}return m}executeWildcardQuery(e){const t=new Map,n={...this._options.searchOptions,...e};for(const[o,i]of this._documentIds){const r=n.boostDocument?n.boostDocument(i,"",this._storedFields.get(o)):1;t.set(o,{score:r,terms:[],match:{}})}return t}combineResults(e,t=ee){if(e.length===0)return new Map;const n=t.toLowerCase(),o=Ce[n];if(!o)throw new Error(`Invalid combination operator: ${t}`);return e.reduce(o)||new Map}toJSON(){const e=[];for(const[t,n]of this._index){const o={};for(const[i,r]of n)o[i]=Object.fromEntries(r);e.push([t,o])}return{documentCount:this._documentCount,nextId:this._nextId,documentIds:Object.fromEntries(this._documentIds),fieldIds:this._fieldIds,fieldLength:Object.fromEntries(this._fieldLength),averageFieldLength:this._avgFieldLength,storedFields:Object.fromEntries(this._storedFields),dirtCount:this._dirtCount,index:e,serializationVersion:2}}termResults(e,t,n,o,i,r,c,a,d=new Map){if(i==null)return d;for(const h of Object.keys(r)){const _=r[h],m=this._fieldIds[h],l=i.get(m);if(l==null)continue;let f=l.size;const p=this._avgFieldLength[m];for(const u of l.keys()){if(!this._documentIds.has(u)){this.removeTerm(m,u,t),f-=1;continue}const g=c?c(this._documentIds.get(u),t,this._storedFields.get(u)):1;if(!g)continue;const w=l.get(u),O=this._fieldLength.get(u)[m],V=Le(w,f,this._documentCount,O,p,a),j=n*o*_*g*V,x=d.get(u);if(x){x.score+=j,Ae(x.terms,e);const z=te(x.match,t);z?z.push(h):x.match[t]=[h]}else d.set(u,{score:j,terms:[e],match:{[t]:[h]}})}}return d}addTerm(e,t,n){const o=this._index.fetch(n,ye);let i=o.get(e);if(i==null)i=new Map,i.set(t,1),o.set(e,i);else{const r=i.get(t);i.set(t,(r||0)+1)}}removeTerm(e,t,n){if(!this._index.has(n)){this.warnDocumentChanged(t,e,n);return}const o=this._index.fetch(n,ye),i=o.get(e);i==null||i.get(t)==null?this.warnDocumentChanged(t,e,n):i.get(t)<=1?i.size<=1?o.delete(e):i.delete(t):i.set(t,i.get(t)-1),this._index.get(n).size===0&&this._index.delete(n)}warnDocumentChanged(e,t,n){for(const o of Object.keys(this._fieldIds))if(this._fieldIds[o]===t){this._options.logger("warn",`MiniSearch: document with ID ${this._documentIds.get(e)} has changed before removal: term "${n}" was not present in field "${o}". Removing a document after it has changed can corrupt the index!`,"version_conflict");return}}addDocumentId(e){const t=this._nextId;return this._idToShortId.set(e,t),this._documentIds.set(t,e),this._documentCount+=1,this._nextId+=1,t}addFields(e){for(let t=0;t<e.length;t++)this._fieldIds[e[t]]=t}addFieldLength(e,t,n,o){let i=this._fieldLength.get(e);i==null&&this._fieldLength.set(e,i=[]),i[t]=o;const c=(this._avgFieldLength[t]||0)*n+o;this._avgFieldLength[t]=c/(n+1)}removeFieldLength(e,t,n,o){if(n===1){this._avgFieldLength[t]=0;return}const i=this._avgFieldLength[t]*n-o;this._avgFieldLength[t]=i/(n-1)}saveStoredFields(e,t){const{storeFields:n,extractField:o}=this._options;if(n==null||n.length===0)return;let i=this._storedFields.get(e);i==null&&this._storedFields.set(e,i={});for(const r of n){const c=o(t,r);c!==void 0&&(i[r]=c)}}}C.wildcard=Symbol("*");const te=(s,e)=>Object.prototype.hasOwnProperty.call(s,e)?s[e]:void 0,Ce={[ee]:(s,e)=>{for(const t of e.keys()){const n=s.get(t);if(n==null)s.set(t,e.get(t));else{const{score:o,terms:i,match:r}=e.get(t);n.score=n.score+o,n.match=Object.assign(n.match,r),_e(n.terms,i)}}return s},[pe]:(s,e)=>{const t=new Map;for(const n of e.keys()){const o=s.get(n);if(o==null)continue;const{score:i,terms:r,match:c}=e.get(n);_e(o.terms,r),t.set(n,{score:o.score+i,terms:o.terms,match:Object.assign(o.match,c)})}return t},[Me]:(s,e)=>{for(const t of e.keys())s.delete(t);return s}},Ee={k:1.2,b:.7,d:.5},Le=(s,e,t,n,o,i)=>{const{k:r,b:c,d:a}=i;return Math.log(1+(t-e+.5)/(e+.5))*(a+s*(r+1)/(s+r*(1-c+c*n/o)))},De=s=>(e,t,n)=>{const o=typeof s.fuzzy=="function"?s.fuzzy(e,t,n):s.fuzzy||!1,i=typeof s.prefix=="function"?s.prefix(e,t,n):s.prefix===!0,r=typeof s.boostTerm=="function"?s.boostTerm(e,t,n):1;return{term:e,fuzzy:o,prefix:i,termBoost:r}},se={idField:"id",extractField:(s,e)=>s[e],stringifyField:(s,e)=>s.toString(),tokenize:s=>s.split(Oe),processTerm:s=>s.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(s,e)=>{typeof console?.[s]=="function"&&console[s](e)},autoVacuum:!0},ge={combineWith:ee,prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:.45,prefix:.375},bm25:Ee},Te={combineWith:pe,prefix:(s,e,t)=>e===t.length-1},ne={batchSize:1e3,batchWait:10},ie={minDirtFactor:.1,minDirtCount:20},oe={...ne,...ie},Ae=(s,e)=>{s.includes(e)||s.push(e)},_e=(s,e)=>{for(const t of e)s.includes(t)||s.push(t)},we=({score:s},{score:e})=>e-s,ye=()=>new Map,P=s=>{const e=new Map;for(const t of Object.keys(s))e.set(parseInt(t,10),s[t]);return e},U=async s=>{const e=new Map;let t=0;for(const n of Object.keys(s))e.set(parseInt(n,10),s[n]),++t%1e3===0&&await xe(0);return e},xe=s=>new Promise(e=>setTimeout(e,s)),Oe=/[\n\r\p{Z}\p{P}]+/u,F=24e6,J=48e3,Ve=2,E=s=>JSON.stringify([Ve,s.revision,s.updated,s.created,s.projectID,s.directory]);function je(s,e){if(!s||!e||s.id!==e.id||s.version!==E(e)||!Number.isInteger(s.pages)||s.pages<1||s.pages>8||!Number.isInteger(s.characters)||s.characters<0||s.characters>J||typeof s.partial!="boolean"||typeof s.complete!="boolean"||typeof s.capped!="boolean"||s.cursor!==void 0&&(typeof s.cursor!="string"||!/^\d{1,9}$/.test(s.cursor))||s.complete&&(s.partial||s.capped||s.cursor)||!s.complete&&!s.capped&&(!s.cursor||s.pages>=8)||!Array.isArray(s.fragments)||s.fragments.length>J)return!1;let t=0;for(const n of s.fragments){if(!n||!["You","Assistant","Tool","File"].includes(n.kind)||typeof n.text!="string"||n.text.length>2e3||!Number.isFinite(n.time))return!1;t+=n.text.length}return t===s.characters}const b=s=>s.normalize("NFKD").replace(new RegExp("\\p{M}","gu"),"").toLowerCase(),re=s=>b(s).match(/[\p{L}\p{N}]+/gu)||[],ce=s=>re(s).join(" ");function Ne(s){const e={text:"",terms:[],phrases:[],filters:[]},t=[];for(const n of s.slice(0,300).match(/(?:[^\s"]+|"[^"]*")+/g)||[]){const o=/^(source|project|dir|model|is|after|before|in):(.+)$/i.exec(n);if(o){const r=o[1].toLowerCase(),c=b(o[2].replace(/^"|"$/g,""));if(r==="in"){const a={title:["title"],files:["files"],messages:["body"],tools:["tools"]};e.fields=a[c],e.fields||(e.error="Use in:title, in:files, in:messages, or in:tools.")}else r==="is"&&!["fork","child","root","archived"].includes(c)?e.error="Use is:fork, is:child, is:root, or is:archived.":["after","before"].includes(r)&&(!/^\d{4}-\d{2}-\d{2}$/.test(c)||!Number.isFinite(Date.parse(c))||new Date(c).toISOString().slice(0,10)!==c)?e.error="Use a valid date in YYYY-MM-DD format.":e.filters.push([r,c]);continue}const i=n.replace(/^"|"$/g,"");n.startsWith('"')&&n.endsWith('"')&&e.phrases.push(ce(i)),t.push(i)}return e.text=t.join(" "),e.terms=re(e.text).slice(0,12),e.text=e.terms.join(" "),e}function $e(s,e,t=220){const n=b(s),o=e.reduce((r,c)=>{const a=n.indexOf(c);return a<0?r:Math.min(r,a)},1/0),i=Number.isFinite(o)?Math.max(0,o-55):0;return`${i?"…":""}${s.slice(i,i+t).replace(/\s+/g," ").trim()}${s.length>i+t?"…":""}`}class Re{index=new C({fields:["title","project","directory","model","sessionID","files","body","tools"],tokenize:re,processTerm:b,searchOptions:{combineWith:"AND",prefix:!0,boost:{title:12,files:5,project:3,directory:3,model:2,sessionID:12,body:1,tools:.6}}});entries=new Map;cache=new Map;scope=new Set;setData(e,t){const n=new Set(e.map(i=>i.id));for(const[i,r]of this.entries)n.has(i)||(this.index.remove(r.doc),this.entries.delete(i));const o=new Map(t.map(i=>[i.id,i.name]));for(const i of e){const r=this.entries.get(i.id),c=r&&E(r.session)===E(i),a={id:i.id,title:i.title,project:o.get(i.projectID)||"",directory:i.directory,model:i.model,sessionID:i.id,body:c?r.doc.body:"",files:c?r.doc.files:"",tools:c?r.doc.tools:""};if(c&&Object.keys(a).every(d=>r.doc[d]===a[d])){r.session=i;continue}this.entries.set(i.id,{session:i,doc:a,fragments:c?r.fragments:[]}),r&&this.index.remove(r.doc),this.index.add(a)}this.cache.clear()}setScope(e){this.scope=new Set(e),this.cache.clear()}content(e){return this.entries.get(e)?.fragments.slice()||[]}addContent(e,t){const n=this.entries.get(e);if(!n)return;n.fragments.push(...t);const o={...n.doc};for(const i of t){const r=i.kind==="File"?"files":i.kind==="Tool"?"tools":"body";o[r]+=`
1
+ (function(){"use strict";const ve="ENTRIES",le="KEYS",he="VALUES";class K{constructor(e,t){const n=e._tree,o=Array.from(n.keys());this.set=e,this._type=t,this._path=o.length>0?[{node:n,keys:o}]:[]}next(){const e=this.dive();return this.backtrack(),e}dive(){if(this._path.length===0)return{done:!0,value:void 0};const{node:e,keys:t}=M(this._path);if(M(t)==="")return{done:!1,value:this.result()};const n=e.get(M(t));return this._path.push({node:n,keys:Array.from(n.keys())}),this.dive()}backtrack(){if(this._path.length===0)return;const e=M(this._path).keys;e.pop(),!(e.length>0)&&(this._path.pop(),this.backtrack())}key(){return this.set._prefix+this._path.map(({keys:e})=>M(e)).filter(e=>e!=="").join("")}value(){return M(this._path).node.get("")}result(){switch(this._type){case he:return this.value();case le:return this.key();default:return[this.key(),this.value()]}}[Symbol.iterator](){return this}}const M=s=>s[s.length-1],ke=(s,e,t)=>{const n=new Map;if(e===void 0)return n;const o=e.length+1,i=o+t,r=new Uint8Array(i*o).fill(t+1);for(let c=0;c<o;++c)r[c]=c;for(let c=1;c<i;++c)r[c*o]=c;return ue(s,e,t,n,r,1,o,""),n},ue=(s,e,t,n,o,i,r,c)=>{const a=i*r;e:for(const d of s.keys())if(d===""){const h=o[a-1];h<=t&&n.set(c,[s.get(d),h])}else{let h=i;for(let _=0;_<d.length;++_,++h){const m=d[_],l=r*h,f=l-r;let p=o[l];const u=Math.max(0,h-t-1),g=Math.min(r-1,h+t);for(let w=u;w<g;++w){const O=m!==e[w],V=o[f+w]+ +O,j=o[f+w+1]+1,x=o[l+w]+1,z=o[l+w+1]=Math.min(V,j,x);z<p&&(p=z)}if(p>t)continue e}ue(s.get(d),e,t,n,o,h,r,c+d)}};class I{constructor(e=new Map,t=""){this._size=void 0,this._tree=e,this._prefix=t}atPrefix(e){if(!e.startsWith(this._prefix))throw new Error("Mismatched prefix");const[t,n]=W(this._tree,e.slice(this._prefix.length));if(t===void 0){const[o,i]=Z(n);for(const r of o.keys())if(r!==""&&r.startsWith(i)){const c=new Map;return c.set(r.slice(i.length),o.get(r)),new I(c,e)}}return new I(t,e)}clear(){this._size=void 0,this._tree.clear()}delete(e){return this._size=void 0,ze(this._tree,e)}entries(){return new K(this,ve)}forEach(e){for(const[t,n]of this)e(t,n,this)}fuzzyGet(e,t){return ke(this._tree,e,t)}get(e){const t=H(this._tree,e);return t!==void 0?t.get(""):void 0}has(e){const t=H(this._tree,e);return t!==void 0&&t.has("")}keys(){return new K(this,le)}set(e,t){if(typeof e!="string")throw new Error("key must be a string");return this._size=void 0,X(this._tree,e).set("",t),this}get size(){if(this._size)return this._size;this._size=0;const e=this.entries();for(;!e.next().done;)this._size+=1;return this._size}update(e,t){if(typeof e!="string")throw new Error("key must be a string");this._size=void 0;const n=X(this._tree,e);return n.set("",t(n.get(""))),this}fetch(e,t){if(typeof e!="string")throw new Error("key must be a string");this._size=void 0;const n=X(this._tree,e);let o=n.get("");return o===void 0&&n.set("",o=t()),o}values(){return new K(this,he)}[Symbol.iterator](){return this.entries()}static from(e){const t=new I;for(const[n,o]of e)t.set(n,o);return t}static fromObject(e){return I.from(Object.entries(e))}}const W=(s,e,t=[])=>{if(e.length===0||s==null)return[s,t];for(const n of s.keys())if(n!==""&&e.startsWith(n))return t.push([s,n]),W(s.get(n),e.slice(n.length),t);return t.push([s,e]),W(void 0,"",t)},H=(s,e)=>{if(e.length===0||s==null)return s;for(const t of s.keys())if(t!==""&&e.startsWith(t))return H(s.get(t),e.slice(t.length))},X=(s,e)=>{const t=e.length;e:for(let n=0;s&&n<t;){for(const i of s.keys())if(i!==""&&e[n]===i[0]){const r=Math.min(t-n,i.length);let c=1;for(;c<r&&e[n+c]===i[c];)++c;const a=s.get(i);if(c===i.length)s=a;else{const d=new Map;d.set(i.slice(c),a),s.set(e.slice(n,n+c),d),s.delete(i),s=d}n+=c;continue e}const o=new Map;return s.set(e.slice(n),o),o}return s},ze=(s,e)=>{const[t,n]=W(s,e);if(t!==void 0){if(t.delete(""),t.size===0)fe(n);else if(t.size===1){const[o,i]=t.entries().next().value;me(n,o,i)}}},fe=s=>{if(s.length===0)return;const[e,t]=Z(s);if(e.delete(t),e.size===0)fe(s.slice(0,-1));else if(e.size===1){const[n,o]=e.entries().next().value;n!==""&&me(s.slice(0,-1),n,o)}},me=(s,e,t)=>{if(s.length===0)return;const[n,o]=Z(s);n.set(o+e,t),n.delete(o)},Z=s=>s[s.length-1],ee="or",pe="and",Me="and_not";class C{constructor(e){if(e?.fields==null)throw new Error('MiniSearch: option "fields" must be provided');const t=e.autoVacuum==null||e.autoVacuum===!0?oe:e.autoVacuum;this._options={...se,...e,autoVacuum:t,searchOptions:{...ge,...e.searchOptions||{}},autoSuggestOptions:{...Te,...e.autoSuggestOptions||{}}},this._index=new I,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldIds={},this._fieldLength=new Map,this._avgFieldLength=[],this._nextId=0,this._storedFields=new Map,this._dirtCount=0,this._currentVacuum=null,this._enqueuedVacuum=null,this._enqueuedVacuumConditions=ie,this.addFields(this._options.fields)}add(e){const{extractField:t,stringifyField:n,tokenize:o,processTerm:i,fields:r,idField:c}=this._options,a=t(e,c);if(a==null)throw new Error(`MiniSearch: document does not have ID field "${c}"`);if(this._idToShortId.has(a))throw new Error(`MiniSearch: duplicate ID ${a}`);const d=this.addDocumentId(a);this.saveStoredFields(d,e);for(const h of r){const _=t(e,h);if(_==null)continue;const m=o(n(_,h),h),l=this._fieldIds[h],f=new Set(m).size;this.addFieldLength(d,l,this._documentCount-1,f);for(const p of m){const u=i(p,h);if(Array.isArray(u))for(const g of u)this.addTerm(l,d,g);else u&&this.addTerm(l,d,u)}}}addAll(e){for(const t of e)this.add(t)}addAllAsync(e,t={}){const{chunkSize:n=10}=t,o={chunk:[],promise:Promise.resolve()},{chunk:i,promise:r}=e.reduce(({chunk:c,promise:a},d,h)=>(c.push(d),(h+1)%n===0?{chunk:[],promise:a.then(()=>new Promise(_=>setTimeout(_,0))).then(()=>this.addAll(c))}:{chunk:c,promise:a}),o);return r.then(()=>this.addAll(i))}remove(e){const{tokenize:t,processTerm:n,extractField:o,stringifyField:i,fields:r,idField:c}=this._options,a=o(e,c);if(a==null)throw new Error(`MiniSearch: document does not have ID field "${c}"`);const d=this._idToShortId.get(a);if(d==null)throw new Error(`MiniSearch: cannot remove document with ID ${a}: it is not in the index`);for(const h of r){const _=o(e,h);if(_==null)continue;const m=t(i(_,h),h),l=this._fieldIds[h],f=new Set(m).size;this.removeFieldLength(d,l,this._documentCount,f);for(const p of m){const u=n(p,h);if(Array.isArray(u))for(const g of u)this.removeTerm(l,d,g);else u&&this.removeTerm(l,d,u)}}this._storedFields.delete(d),this._documentIds.delete(d),this._idToShortId.delete(a),this._fieldLength.delete(d),this._documentCount-=1}removeAll(e){if(e)for(const t of e)this.remove(t);else{if(arguments.length>0)throw new Error("Expected documents to be present. Omit the argument to remove all documents.");this._index=new I,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldLength=new Map,this._avgFieldLength=[],this._storedFields=new Map,this._nextId=0}}discard(e){const t=this._idToShortId.get(e);if(t==null)throw new Error(`MiniSearch: cannot discard document with ID ${e}: it is not in the index`);this._idToShortId.delete(e),this._documentIds.delete(t),this._storedFields.delete(t),(this._fieldLength.get(t)||[]).forEach((n,o)=>{this.removeFieldLength(t,o,this._documentCount,n)}),this._fieldLength.delete(t),this._documentCount-=1,this._dirtCount+=1,this.maybeAutoVacuum()}maybeAutoVacuum(){if(this._options.autoVacuum===!1)return;const{minDirtFactor:e,minDirtCount:t,batchSize:n,batchWait:o}=this._options.autoVacuum;this.conditionalVacuum({batchSize:n,batchWait:o},{minDirtCount:t,minDirtFactor:e})}discardAll(e){const t=this._options.autoVacuum;try{this._options.autoVacuum=!1;for(const n of e)this.discard(n)}finally{this._options.autoVacuum=t}this.maybeAutoVacuum()}replace(e){const{idField:t,extractField:n}=this._options,o=n(e,t);this.discard(o),this.add(e)}vacuum(e={}){return this.conditionalVacuum(e)}conditionalVacuum(e,t){return this._currentVacuum?(this._enqueuedVacuumConditions=this._enqueuedVacuumConditions&&t,this._enqueuedVacuum!=null?this._enqueuedVacuum:(this._enqueuedVacuum=this._currentVacuum.then(()=>{const n=this._enqueuedVacuumConditions;return this._enqueuedVacuumConditions=ie,this.performVacuuming(e,n)}),this._enqueuedVacuum)):this.vacuumConditionsMet(t)===!1?Promise.resolve():(this._currentVacuum=this.performVacuuming(e),this._currentVacuum)}async performVacuuming(e,t){const n=this._dirtCount;if(this.vacuumConditionsMet(t)){const o=e.batchSize||ne.batchSize,i=e.batchWait||ne.batchWait;let r=1;for(const[c,a]of this._index){for(const[d,h]of a)for(const[_]of h)this._documentIds.has(_)||(h.size<=1?a.delete(d):h.delete(_));this._index.get(c).size===0&&this._index.delete(c),r%o===0&&await new Promise(d=>setTimeout(d,i)),r+=1}this._dirtCount-=n}await null,this._currentVacuum=this._enqueuedVacuum,this._enqueuedVacuum=null}vacuumConditionsMet(e){if(e==null)return!0;let{minDirtCount:t,minDirtFactor:n}=e;return t=t||oe.minDirtCount,n=n||oe.minDirtFactor,this.dirtCount>=t&&this.dirtFactor>=n}get isVacuuming(){return this._currentVacuum!=null}get dirtCount(){return this._dirtCount}get dirtFactor(){return this._dirtCount/(1+this._documentCount+this._dirtCount)}has(e){return this._idToShortId.has(e)}getStoredFields(e){const t=this._idToShortId.get(e);if(t!=null)return this._storedFields.get(t)}search(e,t={}){const{searchOptions:n}=this._options,o={...n,...t},i=this.executeQuery(e,t),r=[];for(const[c,{score:a,terms:d,match:h}]of i){const _=d.length||1,m={id:this._documentIds.get(c),score:a*_,terms:Object.keys(h),queryTerms:d,match:h};Object.assign(m,this._storedFields.get(c)),(o.filter==null||o.filter(m))&&r.push(m)}return e===C.wildcard&&o.boostDocument==null||r.sort(we),r}autoSuggest(e,t={}){t={...this._options.autoSuggestOptions,...t};const n=new Map;for(const{score:i,terms:r}of this.search(e,t)){const c=r.join(" "),a=n.get(c);a!=null?(a.score+=i,a.count+=1):n.set(c,{score:i,terms:r,count:1})}const o=[];for(const[i,{score:r,terms:c,count:a}]of n)o.push({suggestion:i,terms:c,score:r/a});return o.sort(we),o}get documentCount(){return this._documentCount}get termCount(){return this._index.size}static loadJSON(e,t){if(t==null)throw new Error("MiniSearch: loadJSON should be given the same options used when serializing the index");return this.loadJS(JSON.parse(e),t)}static async loadJSONAsync(e,t){if(t==null)throw new Error("MiniSearch: loadJSON should be given the same options used when serializing the index");return this.loadJSAsync(JSON.parse(e),t)}static getDefault(e){if(se.hasOwnProperty(e))return te(se,e);throw new Error(`MiniSearch: unknown option "${e}"`)}static loadJS(e,t){const{index:n,documentIds:o,fieldLength:i,storedFields:r,serializationVersion:c}=e,a=this.instantiateMiniSearch(e,t);a._documentIds=P(o),a._fieldLength=P(i),a._storedFields=P(r);for(const[d,h]of a._documentIds)a._idToShortId.set(h,d);for(const[d,h]of n){const _=new Map;for(const m of Object.keys(h)){let l=h[m];c===1&&(l=l.ds),_.set(parseInt(m,10),P(l))}a._index.set(d,_)}return a}static async loadJSAsync(e,t){const{index:n,documentIds:o,fieldLength:i,storedFields:r,serializationVersion:c}=e,a=this.instantiateMiniSearch(e,t);a._documentIds=await U(o),a._fieldLength=await U(i),a._storedFields=await U(r);for(const[h,_]of a._documentIds)a._idToShortId.set(_,h);let d=0;for(const[h,_]of n){const m=new Map;for(const l of Object.keys(_)){let f=_[l];c===1&&(f=f.ds),m.set(parseInt(l,10),await U(f))}++d%1e3===0&&await xe(0),a._index.set(h,m)}return a}static instantiateMiniSearch(e,t){const{documentCount:n,nextId:o,fieldIds:i,averageFieldLength:r,dirtCount:c,serializationVersion:a}=e;if(a!==1&&a!==2)throw new Error("MiniSearch: cannot deserialize an index created with an incompatible version");const d=new C(t);return d._documentCount=n,d._nextId=o,d._idToShortId=new Map,d._fieldIds=i,d._avgFieldLength=r,d._dirtCount=c||0,d._index=new I,d}executeQuery(e,t={}){if(e===C.wildcard)return this.executeWildcardQuery(t);if(typeof e!="string"){const m={...t,...e,queries:void 0},l=e.queries.map(f=>this.executeQuery(f,m));return this.combineResults(l,m.combineWith)}const{tokenize:n,processTerm:o,searchOptions:i}=this._options,r={tokenize:n,processTerm:o,...i,...t},{tokenize:c,processTerm:a}=r,_=c(e).flatMap(m=>a(m)).filter(m=>!!m).map(De(r)).map(m=>this.executeQuerySpec(m,r));return this.combineResults(_,r.combineWith)}executeQuerySpec(e,t){const n={...this._options.searchOptions,...t},o=(n.fields||this._options.fields).reduce((p,u)=>({...p,[u]:te(n.boost,u)||1}),{}),{boostDocument:i,weights:r,maxFuzzy:c,bm25:a}=n,{fuzzy:d,prefix:h}={...ge.weights,...r},_=this._index.get(e.term),m=this.termResults(e.term,e.term,1,e.termBoost,_,o,i,a);let l,f;if(e.prefix&&(l=this._index.atPrefix(e.term)),e.fuzzy){const p=e.fuzzy===!0?.2:e.fuzzy,u=p<1?Math.min(c,Math.round(e.term.length*p)):p;u&&(f=this._index.fuzzyGet(e.term,u))}if(l)for(const[p,u]of l){const g=p.length-e.term.length;if(!g)continue;f?.delete(p);const w=h*p.length/(p.length+.3*g);this.termResults(e.term,p,w,e.termBoost,u,o,i,a,m)}if(f)for(const p of f.keys()){const[u,g]=f.get(p);if(!g)continue;const w=d*p.length/(p.length+g);this.termResults(e.term,p,w,e.termBoost,u,o,i,a,m)}return m}executeWildcardQuery(e){const t=new Map,n={...this._options.searchOptions,...e};for(const[o,i]of this._documentIds){const r=n.boostDocument?n.boostDocument(i,"",this._storedFields.get(o)):1;t.set(o,{score:r,terms:[],match:{}})}return t}combineResults(e,t=ee){if(e.length===0)return new Map;const n=t.toLowerCase(),o=Ce[n];if(!o)throw new Error(`Invalid combination operator: ${t}`);return e.reduce(o)||new Map}toJSON(){const e=[];for(const[t,n]of this._index){const o={};for(const[i,r]of n)o[i]=Object.fromEntries(r);e.push([t,o])}return{documentCount:this._documentCount,nextId:this._nextId,documentIds:Object.fromEntries(this._documentIds),fieldIds:this._fieldIds,fieldLength:Object.fromEntries(this._fieldLength),averageFieldLength:this._avgFieldLength,storedFields:Object.fromEntries(this._storedFields),dirtCount:this._dirtCount,index:e,serializationVersion:2}}termResults(e,t,n,o,i,r,c,a,d=new Map){if(i==null)return d;for(const h of Object.keys(r)){const _=r[h],m=this._fieldIds[h],l=i.get(m);if(l==null)continue;let f=l.size;const p=this._avgFieldLength[m];for(const u of l.keys()){if(!this._documentIds.has(u)){this.removeTerm(m,u,t),f-=1;continue}const g=c?c(this._documentIds.get(u),t,this._storedFields.get(u)):1;if(!g)continue;const w=l.get(u),O=this._fieldLength.get(u)[m],V=Le(w,f,this._documentCount,O,p,a),j=n*o*_*g*V,x=d.get(u);if(x){x.score+=j,Ae(x.terms,e);const z=te(x.match,t);z?z.push(h):x.match[t]=[h]}else d.set(u,{score:j,terms:[e],match:{[t]:[h]}})}}return d}addTerm(e,t,n){const o=this._index.fetch(n,ye);let i=o.get(e);if(i==null)i=new Map,i.set(t,1),o.set(e,i);else{const r=i.get(t);i.set(t,(r||0)+1)}}removeTerm(e,t,n){if(!this._index.has(n)){this.warnDocumentChanged(t,e,n);return}const o=this._index.fetch(n,ye),i=o.get(e);i==null||i.get(t)==null?this.warnDocumentChanged(t,e,n):i.get(t)<=1?i.size<=1?o.delete(e):i.delete(t):i.set(t,i.get(t)-1),this._index.get(n).size===0&&this._index.delete(n)}warnDocumentChanged(e,t,n){for(const o of Object.keys(this._fieldIds))if(this._fieldIds[o]===t){this._options.logger("warn",`MiniSearch: document with ID ${this._documentIds.get(e)} has changed before removal: term "${n}" was not present in field "${o}". Removing a document after it has changed can corrupt the index!`,"version_conflict");return}}addDocumentId(e){const t=this._nextId;return this._idToShortId.set(e,t),this._documentIds.set(t,e),this._documentCount+=1,this._nextId+=1,t}addFields(e){for(let t=0;t<e.length;t++)this._fieldIds[e[t]]=t}addFieldLength(e,t,n,o){let i=this._fieldLength.get(e);i==null&&this._fieldLength.set(e,i=[]),i[t]=o;const c=(this._avgFieldLength[t]||0)*n+o;this._avgFieldLength[t]=c/(n+1)}removeFieldLength(e,t,n,o){if(n===1){this._avgFieldLength[t]=0;return}const i=this._avgFieldLength[t]*n-o;this._avgFieldLength[t]=i/(n-1)}saveStoredFields(e,t){const{storeFields:n,extractField:o}=this._options;if(n==null||n.length===0)return;let i=this._storedFields.get(e);i==null&&this._storedFields.set(e,i={});for(const r of n){const c=o(t,r);c!==void 0&&(i[r]=c)}}}C.wildcard=Symbol("*");const te=(s,e)=>Object.prototype.hasOwnProperty.call(s,e)?s[e]:void 0,Ce={[ee]:(s,e)=>{for(const t of e.keys()){const n=s.get(t);if(n==null)s.set(t,e.get(t));else{const{score:o,terms:i,match:r}=e.get(t);n.score=n.score+o,n.match=Object.assign(n.match,r),_e(n.terms,i)}}return s},[pe]:(s,e)=>{const t=new Map;for(const n of e.keys()){const o=s.get(n);if(o==null)continue;const{score:i,terms:r,match:c}=e.get(n);_e(o.terms,r),t.set(n,{score:o.score+i,terms:o.terms,match:Object.assign(o.match,c)})}return t},[Me]:(s,e)=>{for(const t of e.keys())s.delete(t);return s}},Ee={k:1.2,b:.7,d:.5},Le=(s,e,t,n,o,i)=>{const{k:r,b:c,d:a}=i;return Math.log(1+(t-e+.5)/(e+.5))*(a+s*(r+1)/(s+r*(1-c+c*n/o)))},De=s=>(e,t,n)=>{const o=typeof s.fuzzy=="function"?s.fuzzy(e,t,n):s.fuzzy||!1,i=typeof s.prefix=="function"?s.prefix(e,t,n):s.prefix===!0,r=typeof s.boostTerm=="function"?s.boostTerm(e,t,n):1;return{term:e,fuzzy:o,prefix:i,termBoost:r}},se={idField:"id",extractField:(s,e)=>s[e],stringifyField:(s,e)=>s.toString(),tokenize:s=>s.split(Oe),processTerm:s=>s.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(s,e)=>{typeof console?.[s]=="function"&&console[s](e)},autoVacuum:!0},ge={combineWith:ee,prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:.45,prefix:.375},bm25:Ee},Te={combineWith:pe,prefix:(s,e,t)=>e===t.length-1},ne={batchSize:1e3,batchWait:10},ie={minDirtFactor:.1,minDirtCount:20},oe={...ne,...ie},Ae=(s,e)=>{s.includes(e)||s.push(e)},_e=(s,e)=>{for(const t of e)s.includes(t)||s.push(t)},we=({score:s},{score:e})=>e-s,ye=()=>new Map,P=s=>{const e=new Map;for(const t of Object.keys(s))e.set(parseInt(t,10),s[t]);return e},U=async s=>{const e=new Map;let t=0;for(const n of Object.keys(s))e.set(parseInt(n,10),s[n]),++t%1e3===0&&await xe(0);return e},xe=s=>new Promise(e=>setTimeout(e,s)),Oe=/[\n\r\p{Z}\p{P}]+/u,F=24e6,J=48e3,Ve=2,E=s=>JSON.stringify([Ve,s.importVersion,s.revision,s.updated,s.created,s.projectID,s.directory]);function je(s,e){if(!s||!e||s.id!==e.id||s.version!==E(e)||!Number.isInteger(s.pages)||s.pages<1||s.pages>8||!Number.isInteger(s.characters)||s.characters<0||s.characters>J||typeof s.partial!="boolean"||typeof s.complete!="boolean"||typeof s.capped!="boolean"||s.cursor!==void 0&&(typeof s.cursor!="string"||!/^\d{1,9}$/.test(s.cursor))||s.complete&&(s.partial||s.capped||s.cursor)||!s.complete&&!s.capped&&(!s.cursor||s.pages>=8)||!Array.isArray(s.fragments)||s.fragments.length>J)return!1;let t=0;for(const n of s.fragments){if(!n||!["You","Assistant","Tool","File"].includes(n.kind)||typeof n.text!="string"||n.text.length>2e3||!Number.isFinite(n.time))return!1;t+=n.text.length}return t===s.characters}const b=s=>s.normalize("NFKD").replace(new RegExp("\\p{M}","gu"),"").toLowerCase(),re=s=>b(s).match(/[\p{L}\p{N}]+/gu)||[],ce=s=>re(s).join(" ");function Ne(s){const e={text:"",terms:[],phrases:[],filters:[]},t=[];for(const n of s.slice(0,300).match(/(?:[^\s"]+|"[^"]*")+/g)||[]){const o=/^(source|project|dir|model|is|after|before|in):(.+)$/i.exec(n);if(o){const r=o[1].toLowerCase(),c=b(o[2].replace(/^"|"$/g,""));if(r==="in"){const a={title:["title"],files:["files"],messages:["body"],tools:["tools"]};e.fields=a[c],e.fields||(e.error="Use in:title, in:files, in:messages, or in:tools.")}else r==="is"&&!["fork","child","root","archived"].includes(c)?e.error="Use is:fork, is:child, is:root, or is:archived.":["after","before"].includes(r)&&(!/^\d{4}-\d{2}-\d{2}$/.test(c)||!Number.isFinite(Date.parse(c))||new Date(c).toISOString().slice(0,10)!==c)?e.error="Use a valid date in YYYY-MM-DD format.":e.filters.push([r,c]);continue}const i=n.replace(/^"|"$/g,"");n.startsWith('"')&&n.endsWith('"')&&e.phrases.push(ce(i)),t.push(i)}return e.text=t.join(" "),e.terms=re(e.text).slice(0,12),e.text=e.terms.join(" "),e}function $e(s,e,t=220){const n=b(s),o=e.reduce((r,c)=>{const a=n.indexOf(c);return a<0?r:Math.min(r,a)},1/0),i=Number.isFinite(o)?Math.max(0,o-55):0;return`${i?"…":""}${s.slice(i,i+t).replace(/\s+/g," ").trim()}${s.length>i+t?"…":""}`}class Re{index=new C({fields:["title","project","directory","model","sessionID","files","body","tools"],tokenize:re,processTerm:b,searchOptions:{combineWith:"AND",prefix:!0,boost:{title:12,files:5,project:3,directory:3,model:2,sessionID:12,body:1,tools:.6}}});entries=new Map;cache=new Map;scope=new Set;setData(e,t){const n=new Set(e.map(i=>i.id));for(const[i,r]of this.entries)n.has(i)||(this.index.remove(r.doc),this.entries.delete(i));const o=new Map(t.map(i=>[i.id,i.name]));for(const i of e){const r=this.entries.get(i.id),c=r&&E(r.session)===E(i),a={id:i.id,title:i.title,project:o.get(i.projectID)||"",directory:i.directory,model:i.model,sessionID:i.id,body:c?r.doc.body:"",files:c?r.doc.files:"",tools:c?r.doc.tools:""};if(c&&Object.keys(a).every(d=>r.doc[d]===a[d])){r.session=i;continue}this.entries.set(i.id,{session:i,doc:a,fragments:c?r.fragments:[]}),r&&this.index.remove(r.doc),this.index.add(a)}this.cache.clear()}setScope(e){this.scope=new Set(e),this.cache.clear()}content(e){return this.entries.get(e)?.fragments.slice()||[]}addContent(e,t){const n=this.entries.get(e);if(!n)return;n.fragments.push(...t);const o={...n.doc};for(const i of t){const r=i.kind==="File"?"files":i.kind==="Tool"?"tools":"body";o[r]+=`
2
2
  ${i.text}`}this.index.remove(n.doc),this.index.add(o),n.doc=o,this.cache.clear()}search(e,t=!1,n=80,o=0){const i=`${e}\0${t}\0${n}\0${o}`,r=this.cache.get(i);if(r)return r;const c=Ne(e);if(c.error)return{hits:[],total:0,error:c.error};const a=l=>{const{session:f,doc:p}=l;if(t&&!this.scope.has(f.id))return!1;for(const[u,g]of c.filters)if(u==="source"&&![f.source||"opencode",...(f.linkedSessionIDs||[]).map(w=>w.split(":")[0])].some(w=>b(w).includes(g))||u==="project"&&!b(p.project).includes(g)&&!b(f.projectID).includes(g)||u==="dir"&&!b(f.directory).includes(g)||u==="model"&&!b(f.model).includes(g)||u==="after"&&f.created<new Date(`${g}T00:00:00`).getTime()||u==="before"&&f.created>new Date(`${g}T23:59:59.999`).getTime()||u==="is"&&(g==="fork"&&!f.forkID||g==="child"&&(!f.parentID||f.forkID)||g==="root"&&(f.parentID||f.forkID)||g==="archived"&&!f.archived))return!1;if(c.phrases.length){const u=c.fields||["title","body","files","tools","project","directory","model"];if(!c.phrases.every(g=>u.some(w=>ce(p[w]).includes(g))))return!1}return!0},h=(c.terms.length?this.index.search(c.text,{fields:c.fields,fuzzy:l=>l.length<4?!1:l.length>7?2:1,filter:l=>a(this.entries.get(String(l.id)))}):[...this.entries.values()].filter(a).map(l=>({id:l.session.id,score:0,terms:[],match:{}}))).map(l=>{const f=this.entries.get(String(l.id)),p=ce(f.doc.title),u=new Set(Object.values(l.match).flat()),g=c.text?p.includes(c.text)&&(!c.fields||c.fields.includes("title"))?5:u.has("title")||u.has("sessionID")?4:u.has("files")?3:u.has("body")?2:1:0;return{match:l,entry:f,tier:g}}).sort((l,f)=>f.tier-l.tier||f.match.score-l.match.score||f.entry.session.updated-l.entry.session.updated||l.entry.session.id.localeCompare(f.entry.session.id)),m={hits:h.slice(o,o+Math.min(250,Math.max(1,n))).map(({match:l,entry:f,tier:p})=>{const u=l.terms.length?l.terms:c.terms,g=f.fragments.filter(x=>!c.fields||c.fields.includes(x.kind==="File"?"files":x.kind==="Tool"?"tools":"body"));let w,O=0;for(const x of g){const z=b(x.text),G=u.reduce((Je,qe)=>Je+Number(z.includes(qe)),0);if(G>O&&(w=x,O=G),G===u.length&&G>0)break}const V=new Set(Object.values(l.match).flat()),j=p>=4?V.has("sessionID")&&!V.has("title")?"Session ID":"Title":w?w.kind==="File"?"File":w.kind==="Tool"?"Tool":"Message":c.text?"Metadata":"Recent";return{id:f.session.id,score:l.score,source:j,excerpt:w?$e(w.text,u):"",terms:u}}),total:h.length};return this.cache.size>=30&&this.cache.delete(this.cache.keys().next().value),this.cache.set(i,m),m}}function We(s,e){let t=Math.max(0,e),n=!1;const o=[],i=[...s.fragments].sort((c,a)=>+(a.kind==="File"||a.kind==="You")-+(c.kind==="File"||c.kind==="You")),r=Math.max(160,Math.min(2e3,Math.floor(t/Math.max(1,i.length))));for(const c of i){if(t<=0){n=!0;break}const a=c.text.slice(0,Math.min(t,r));n||=a.length<c.text.length,o.push({...c,text:a}),t-=a.length}return{fragments:o,characters:Math.max(0,e)-t,partial:s.truncated||n}}class Pe{available=!0;epoch=0;async restore(e,t,n){const o=new Map(t.map(c=>[c.id,c]));let i,r=0;try{do{const c=await fetch(`/api/sessiongraph/index${i?`?after=${encodeURIComponent(i)}`:""}`);if(!c.ok)throw new Error("Index unavailable");const a=await c.json();this.epoch=a.epoch;for(const d of a.records)je(d,o.get(d.id))&&r+d.characters<=F&&(r+=d.characters,n(d));i=a.cursor}while(i);try{globalThis.indexedDB?.deleteDatabase("atlas-search")}catch{}}catch{this.available=!1}}async save(e){if(this.available)try{const t=await fetch("/api/sessiongraph/index",{method:"POST",headers:{"Content-Type":"application/json","X-SessionGraph-Action":"index"},body:JSON.stringify({record:e,epoch:this.epoch})});!t.ok&&t.status!==409&&(this.available=!1)}catch{this.available=!1}}async clear(){const e=await fetch("/api/sessiongraph/index",{method:"DELETE",headers:{"X-SessionGraph-Action":"index"}});if(this.available=e.ok,!e.ok)throw new Error("Could not clear saved index.")}}const v=new Re,q=new Pe,y=new Map,L=new Set;let D=!1,Q=0,S=0,k=0,B=!1,T,A,be=[],ae,Se=0;const Y=new Set,N=s=>postMessage(s);function $(){if(!A)return;const s=performance.now(),e=v.search(A.text,A.viewOnly,A.limit);be=e.hits.slice(0,12).map(t=>t.id),N({type:"results",request:A.request,...e,elapsed:performance.now()-s})}function R(){const s=[...y.values()];N({type:"status",status:{indexed:s.filter(e=>e.pages>0).length,complete:s.filter(e=>e.complete).length,total:y.size,characters:S,active:D&&Q>0,limited:S>=F||s.some(e=>e.partial||e.capped),failed:s.filter(e=>e.failed>0).length,restored:L.size,storage:B?T?.sourceID&&q.available?"local":"memory":"restoring"}})}function Ie(){ae||(ae=setTimeout(()=>{ae=void 0,$(),R()},200))}function Ue(){const s=t=>!!(t&&!t.inflight&&!t.complete&&!t.capped&&t.failed<1);for(const t of be){const n=y.get(t);if(s(n)&&n.pages<2)return n}let e;for(const t of y.values())s(t)&&(!e||t.pages<e.pages)&&(e=t);return e}function de(){if(!B||!D||S>=F){R();return}for(;Q<2;){const s=Ue();if(!s)break;s.inflight=!0,Q++;const e=k,t=new AbortController;Y.add(t),(async()=>{try{const n=new URLSearchParams({updated:String(s.session.updated)});s.cursor&&n.set("cursor",s.cursor);const o=await fetch(`/api/sessiongraph/session/${encodeURIComponent(s.session.id)}/content?${n}`,{signal:t.signal});if(!o.ok)throw new Error("Conversation unavailable");const i=await o.json();if(e!==k||t.signal.aborted)return;if(i.id!==s.session.id)throw new Error("Unexpected conversation");const r=Math.min(J,Math.floor(F/Math.max(1,y.size))),c=We(i,Math.min(r-s.characters,F-S));s.characters+=c.characters,S+=c.characters,v.addContent(s.session.id,c.fragments),s.pages++,s.partial||=c.partial,s.complete=!i.nextCursor&&!s.partial,s.capped=!s.complete&&(!i.nextCursor||s.characters>=r||s.pages>=8),s.cursor=i.nextCursor||void 0,Ie(),T?.sourceID&&await q.save({id:s.session.id,version:E(s.session),fragments:v.content(s.session.id),pages:s.pages,characters:s.characters,partial:s.partial,complete:s.complete,capped:s.capped,cursor:s.cursor})}catch{!t.signal.aborted&&e===k&&s.failed++}finally{s.inflight=!1,Y.delete(t),Q--,D?setTimeout(de,performance.now()-Se<150?150:35):R()}})()}R()}async function Fe(s,e=!1){const t=++k;B=!1,Y.forEach(r=>r.abort());const n=T?.sourceID===s.sourceID&&!e,o=n?new Map(y):new Map;n||(v.setData([],[]),L.clear()),T=s,y.clear(),S=0;for(const r of[...s.sessions].sort((c,a)=>a.updated-c.updated)){const c=o.get(r.id),a=c&&E(c.session)===E(r),d=a?{...c,session:r,inflight:!1}:{session:r,pages:0,characters:0,partial:!1,complete:!1,capped:!1,failed:0,inflight:!1};a||L.delete(r.id),y.set(r.id,d),S+=d.characters}for(const r of L)y.has(r)||L.delete(r);if(v.setData(s.sessions,s.projects),$(),R(),e&&await q.clear(),t!==k||(s.sourceID&&await q.restore(s.sourceID,s.sessions,r=>{if(t!==k)return;const c=y.get(r.id);!c||c.pages||S+r.characters>F||(v.addContent(r.id,r.fragments),Object.assign(c,{pages:r.pages,characters:r.characters,partial:r.partial,complete:r.complete,capped:r.capped,cursor:r.cursor}),S+=r.characters,L.add(r.id),Ie())}),t!==k))return;const i=Math.min(J,Math.floor(F/Math.max(1,y.size)));for(const r of y.values())!r.complete&&r.characters>=i&&(r.capped=!0);B=!0,$(),de()}self.onmessage=s=>{try{const e=s.data;e.type==="data"?Fe(e).catch(()=>N({type:"error",message:"Search index could not load. Reload to retry."})):e.type==="scope"?(v.setScope(e.ids),$()):e.type==="query"?(Se=performance.now(),A=e,$()):e.type==="clear-cache"?(D=!1,T&&Fe(T,!0).catch(()=>N({type:"error",message:"Search index could not reset. Reload to retry."}))):(D=e.enabled,D?y.forEach(t=>{t.failed=0}):Y.forEach(t=>t.abort()),de())}catch(e){N({type:"error",message:e instanceof Error?e.message:"Search unavailable"})}}})();
package/dist/index.html CHANGED
@@ -12,8 +12,8 @@
12
12
  <link rel="icon" sizes="any" href="/favicon.ico" />
13
13
  <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
14
14
  <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
15
- <script type="module" crossorigin src="/assets/index-B1kyvo41.js"></script>
16
- <link rel="stylesheet" crossorigin href="/assets/index-Du0_nVjH.css">
15
+ <script type="module" crossorigin src="/assets/index-D24Hz9MJ.js"></script>
16
+ <link rel="stylesheet" crossorigin href="/assets/index-C0jATzD9.css">
17
17
  </head>
18
18
  <body>
19
19
  <div id="app"></div>