sessiongraph 1.0.3 → 1.0.5

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 (59) hide show
  1. package/README.md +4 -1
  2. package/dist/assets/{index-ngj67_1P.js → index-3_I59bPI.js} +1 -1
  3. package/dist/assets/{index-DZ3QjOks.js → index-86i6pjnx.js} +1 -1
  4. package/dist/assets/{index-Ca1o8F2F.js → index-BEabiGl5.js} +16 -16
  5. package/dist/assets/{index-DmhroAg3.js → index-DxQk-77k.js} +1 -1
  6. package/dist/assets/{index-Oz3Ov7Mv.css → index-vX8x5oFC.css} +1 -1
  7. package/dist/assets/{scene-DpPyjrii.js → scene-CEalI0mr.js} +1 -1
  8. package/dist/assets/{share-BDMRLovI.js → share-BydK_UaB.js} +3 -3
  9. package/dist/assets/worker-DwqxiDWY.js +2 -0
  10. package/dist/index.html +2 -2
  11. package/dist/sources/LICENSE-OFL-1.1.txt +93 -0
  12. package/dist/sources/NOTICE.txt +22 -0
  13. package/dist/sources/amp.svg +1 -0
  14. package/dist/sources/antigravity.svg +1 -0
  15. package/dist/sources/aside.svg +1 -0
  16. package/dist/sources/augment.svg +1 -0
  17. package/dist/sources/cherry.svg +1 -0
  18. package/dist/sources/codebuddy.svg +1 -0
  19. package/dist/sources/codebuff.svg +1 -0
  20. package/dist/sources/commandcode.svg +1 -0
  21. package/dist/sources/crush.svg +1 -0
  22. package/dist/sources/deepseek.svg +1 -0
  23. package/dist/sources/devin.svg +1 -0
  24. package/dist/sources/droid.svg +1 -0
  25. package/dist/sources/freebuff.svg +1 -0
  26. package/dist/sources/fx.svg +1 -0
  27. package/dist/sources/gajae.svg +1 -0
  28. package/dist/sources/goose.svg +1 -0
  29. package/dist/sources/grok.svg +1 -0
  30. package/dist/sources/hermes.svg +1 -0
  31. package/dist/sources/hindsight.svg +1 -0
  32. package/dist/sources/jcode.svg +1 -0
  33. package/dist/sources/junie.svg +1 -0
  34. package/dist/sources/kimchi.svg +1 -0
  35. package/dist/sources/kimi.svg +1 -0
  36. package/dist/sources/kiro.svg +1 -0
  37. package/dist/sources/lmstudio.svg +1 -0
  38. package/dist/sources/mimo.svg +1 -0
  39. package/dist/sources/minimax.svg +1 -0
  40. package/dist/sources/mistral.svg +1 -0
  41. package/dist/sources/muse.svg +1 -0
  42. package/dist/sources/mux.svg +1 -0
  43. package/dist/sources/octofriend.svg +1 -0
  44. package/dist/sources/openclaw.svg +1 -0
  45. package/dist/sources/prime.svg +1 -0
  46. package/dist/sources/proma.svg +1 -0
  47. package/dist/sources/reasonix.svg +1 -0
  48. package/dist/sources/senpi.svg +1 -0
  49. package/dist/sources/t3.svg +1 -0
  50. package/dist/sources/trae.svg +1 -0
  51. package/dist/sources/unsloth.svg +1 -0
  52. package/dist/sources/warp.svg +1 -0
  53. package/dist/sources/zcode.svg +1 -0
  54. package/dist/sources/zed.svg +1 -0
  55. package/dist-server/server.mjs +425 -134
  56. package/docs/guide.md +3 -0
  57. package/docs/import-coverage.md +1 -1
  58. package/package.json +7 -7
  59. package/dist/assets/worker-YMPBjASm.js +0 -2
package/docs/guide.md CHANGED
@@ -86,6 +86,7 @@ Onboarding closes automatically after a successful import and library refresh. I
86
86
  | OpenCode | Official authenticated local service discovery and V2 GET API | Explicit forks and child IDs; authoritative snapshot paths where available. OpenCode must be running for an import, but not to browse saved data. Remote endpoints are rejected. |
87
87
  | Claude Code | SDK conversation-chain parsing with read-only local transcript discovery; legacy `~/.claude/transcripts/` envelopes | CLI and VS Code extension sessions, including IDE-prefixed prompts omitted by the SDK listing. Project transcripts take precedence over overlapping legacy exports. Preserves recorded message times and explicit subagent metadata. SDK-visible history can omit pre-compaction text. No inferred fork ancestry. File evidence requires a successful matching edit-tool result. |
88
88
  | Codex | Bounded streaming reads of active/archived JSONL, zstd/gzip archives, and suffixed rollout copies | Native session IDs deduplicate copies; active uncompressed rollouts take precedence. Explicit recorded fork/parent fields; completed file-change events. Mirrored event text is not imported twice. Store-only/cloud-only history and ordinary ChatGPT desktop/web chats are not imported. |
89
+ | T3 Code | Private read-only snapshot of the local server's `~/.t3/userdata/statev2.sqlite`; legacy `state.sqlite` fallback | T3 app threads retain their own titles, messages, ordered activity, recorded forks/children, and worktree paths. Strong recorded provider-thread IDs link overlapping Codex, Claude Code, and OpenCode imports; when the T3 conversation is complete, a uniquely linked provider session is shown through its T3 thread instead of appearing twice. Legacy V1 provides partial text history. Attachments and checkpoint file snapshots are omitted. |
89
90
  | Cursor | IDE JSONL transcripts, CLI/ACP stores, and legacy Composer `state.vscdb` databases in application `User/globalStorage` and `User/workspaceStorage` | Inline conversations, conversation maps, and separate bubble records preserve native creation dates. Modern representations take precedence while retaining Composer's original start date. Missing bubble times stay unknown. Older `.txt` transcripts, cloud-only and SDK-only history are excluded. |
90
91
  | Gemini CLI | `~/.gemini/tmp/*/chats/` JSON/JSONL; sandbox cache equivalent | Reconstructs append-only patches and rewinds. Explicit subagent directories form parent links. Workspace identity comes from `.project_root`; unknown directories stay unknown. |
91
92
  | Qwen Code | `~/.qwen/projects/*/chats/*.jsonl` | Recorded forks and parent sessions remain distinct. Tool results retain call IDs and recorded execution status. Daemon-only histories are excluded. |
@@ -98,6 +99,8 @@ Onboarding closes automatically after a successful import and library refresh. I
98
99
 
99
100
  Source roots respect `CLAUDE_CONFIG_DIR` and `CODEX_HOME`. `SESSIONGRAPH_SERVICE_FILE` selects a local OpenCode service registration. Adapters never read authentication files or execute source configuration, hooks, or agents. Source formats can evolve: unsupported history is disclosed rather than fabricated.
100
101
 
102
+ T3 Code discovery respects `T3CODE_HOME`. `SESSIONGRAPH_T3_CODE_HISTORY_DIR` can point to a T3 base directory, its `userdata` directory, or a specific SQLite file. T3 history on another machine must be imported by SessionGraph running on that machine or from an accessible local copy. The T3 source does not start its server or provider. When both T3 and a bound provider source are imported, the T3 thread is the visible conversation; provider sessions remain saved in SessionGraph's library. Source filters for a bound provider include its T3 threads. Opening a T3 thread in another harness uses a saved-context handoff; native T3 resume is not currently a launch destination.
103
+
101
104
  See [extended source coverage](import-coverage.md) for all additional harness locations, per-source overrides, the pinned Tokscale comparison, and explicit usage-only limitations. New sources are not selected automatically.
102
105
 
103
106
  Claude Code's local VS Code extension uses the same transcript directory as its CLI: `~/.claude/projects` (`%USERPROFILE%\.claude\projects` on Windows), or `projects` under `CLAUDE_CONFIG_DIR`. A separate CLI installation is not required for import. History in WSL, SSH hosts, or dev containers must be accessible in the environment running SessionGraph.
@@ -67,7 +67,7 @@ Every additional source accepts `SESSIONGRAPH_<SOURCE_ID_UPPERCASE_WITH_UNDERSCO
67
67
 
68
68
  Defaults also honor the implemented native home variables: `HERMES_HOME`, `OPENCLAW_STATE_DIR`, `FACTORY_HOME`, `KIMI_HOME`, `KIMI_CODE_HOME`, `GROK_HOME`, `JCODE_HOME`, `DSH_HOME`, `VIBE_HOME`, `MUX_ROOT`, `UNSLOTH_STUDIO_HOME`, `GOOSE_PATH_ROOT`, `CRUSH_GLOBAL_DATA`, `CODEBUFF_DATA_DIR`, `FREEBUFF_DATA_DIR`, Pi-family home/session overrides, `GEMINI_CLI_HOME`, `TOKSCALE_CONFIG_DIR`, and `TOKSCALE_HEADLESS_DIR`. Nothing reads or executes source configuration or credentials.
69
69
 
70
- File imports are bounded to 32 MB combined expanded data and 50,000 messages. SQLite imports query private DB/WAL copies (8 GB maximum per database or WAL), with 32 MB fields and 64 MB aggregate query output. Nested queries and expanded blobs share a 64 MB / 50,000-record session budget. Oversized or unsupported sessions retain previously saved history. Database revisions include WAL changes; source changes during copying/reading abort the read. At most two private copies are retained and cleaned on eviction/exit. Failed authoritative database representations block fallback to stale exports.
70
+ File imports are bounded to 32 MB combined expanded data and 50,000 messages. SQLite imports query private DB/WAL copies (8 GB maximum per database or WAL), with 32 MB fields and 64 MB aggregate query output. Nested queries and expanded blobs share a 64 MB / 50,000-record session budget. Oversized or unsupported sessions retain previously saved history. Database revisions include WAL changes; source changes during copying/reading abort the read. T3 Code pages stay on the verified discovery snapshot while its live server continues writing; later imports pick up newer revisions. At most two private copies are retained and cleaned on eviction/exit. Failed authoritative database representations block fallback to stale exports.
71
71
 
72
72
  Missing message timestamps remain unknown. Native dates place database sessions; undated database histories are skipped with a warning. File histories can fall back to file dates and disclose this. Unsupported message blocks, binary attachments, missing tools, and absent snapshots remain partial. Token counts are never estimated from text; usage aggregates are not converted into conversations. No new harness is enabled automatically, and continuing a session remains an explicit user action through supported launch destinations.
73
73
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sessiongraph",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -25,11 +25,11 @@
25
25
  "README.md"
26
26
  ],
27
27
  "optionalDependencies": {
28
- "sessiongraph-app-darwin-arm64": "1.0.3",
29
- "sessiongraph-app-darwin-x64": "1.0.3",
30
- "sessiongraph-app-linux-arm64": "1.0.3",
31
- "sessiongraph-app-linux-x64": "1.0.3",
32
- "sessiongraph-app-win32-x64": "1.0.3"
28
+ "sessiongraph-app-darwin-arm64": "1.0.5",
29
+ "sessiongraph-app-darwin-x64": "1.0.5",
30
+ "sessiongraph-app-linux-arm64": "1.0.5",
31
+ "sessiongraph-app-linux-x64": "1.0.5",
32
+ "sessiongraph-app-win32-x64": "1.0.5"
33
33
  },
34
34
  "type": "module",
35
35
  "engines": {
@@ -74,5 +74,5 @@
74
74
  "vite": "^7.2.0"
75
75
  },
76
76
  "packageManager": "pnpm@11.10.0",
77
- "sessionGraphCommit": "0bca44399a6460135ea5b86d158b01779fe2d0bb"
77
+ "sessionGraphCommit": "e89e8110cf9ad00ee96ec0a0b7df681b57343aa5"
78
78
  }
@@ -1,2 +0,0 @@
1
- (function(){"use strict";const Fe="ENTRIES",de="KEYS",le="VALUES";class G{constructor(e,t){const n=e._tree,r=Array.from(n.keys());this.set=e,this._type=t,this._path=r.length>0?[{node:n,keys:r}]:[]}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}=C(this._path);if(C(t)==="")return{done:!1,value:this.result()};const n=e.get(C(t));return this._path.push({node:n,keys:Array.from(n.keys())}),this.dive()}backtrack(){if(this._path.length===0)return;const e=C(this._path).keys;e.pop(),!(e.length>0)&&(this._path.pop(),this.backtrack())}key(){return this.set._prefix+this._path.map(({keys:e})=>C(e)).filter(e=>e!=="").join("")}value(){return C(this._path).node.get("")}result(){switch(this._type){case le:return this.value();case de:return this.key();default:return[this.key(),this.value()]}}[Symbol.iterator](){return this}}const C=s=>s[s.length-1],ve=(s,e,t)=>{const n=new Map;if(e===void 0)return n;const r=e.length+1,o=r+t,i=new Uint8Array(o*r).fill(t+1);for(let c=0;c<r;++c)i[c]=c;for(let c=1;c<o;++c)i[c*r]=c;return he(s,e,t,n,i,1,r,""),n},he=(s,e,t,n,r,o,i,c)=>{const a=o*i;e:for(const d of s.keys())if(d===""){const u=r[a-1];u<=t&&n.set(c,[s.get(d),u])}else{let u=o;for(let p=0;p<d.length;++p,++u){const l=d[p],h=i*u,g=h-i;let m=r[h];const f=Math.max(0,u-t-1),_=Math.min(i-1,u+t);for(let w=f;w<_;++w){const V=l!==e[w],R=r[g+w]+ +V,b=r[g+w+1]+1,F=r[h+w]+1,S=r[h+w+1]=Math.min(R,b,F);S<m&&(m=S)}if(m>t)continue e}he(s.get(d),e,t,n,r,u,i,c+d)}};class v{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[r,o]=X(n);for(const i of r.keys())if(i!==""&&i.startsWith(o)){const c=new Map;return c.set(i.slice(o.length),r.get(i)),new v(c,e)}}return new v(t,e)}clear(){this._size=void 0,this._tree.clear()}delete(e){return this._size=void 0,ze(this._tree,e)}entries(){return new G(this,Fe)}forEach(e){for(const[t,n]of this)e(t,n,this)}fuzzyGet(e,t){return ve(this._tree,e,t)}get(e){const t=K(this._tree,e);return t!==void 0?t.get(""):void 0}has(e){const t=K(this._tree,e);return t!==void 0&&t.has("")}keys(){return new G(this,de)}set(e,t){if(typeof e!="string")throw new Error("key must be a string");return this._size=void 0,H(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=H(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=H(this._tree,e);let r=n.get("");return r===void 0&&n.set("",r=t()),r}values(){return new G(this,le)}[Symbol.iterator](){return this.entries()}static from(e){const t=new v;for(const[n,r]of e)t.set(n,r);return t}static fromObject(e){return v.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)},K=(s,e)=>{if(e.length===0||s==null)return s;for(const t of s.keys())if(t!==""&&e.startsWith(t))return K(s.get(t),e.slice(t.length))},H=(s,e)=>{const t=e.length;e:for(let n=0;s&&n<t;){for(const o of s.keys())if(o!==""&&e[n]===o[0]){const i=Math.min(t-n,o.length);let c=1;for(;c<i&&e[n+c]===o[c];)++c;const a=s.get(o);if(c===o.length)s=a;else{const d=new Map;d.set(o.slice(c),a),s.set(e.slice(n,n+c),d),s.delete(o),s=d}n+=c;continue e}const r=new Map;return s.set(e.slice(n),r),r}return s},ze=(s,e)=>{const[t,n]=W(s,e);if(t!==void 0){if(t.delete(""),t.size===0)ue(n);else if(t.size===1){const[r,o]=t.entries().next().value;fe(n,r,o)}}},ue=s=>{if(s.length===0)return;const[e,t]=X(s);if(e.delete(t),e.size===0)ue(s.slice(0,-1));else if(e.size===1){const[n,r]=e.entries().next().value;n!==""&&fe(s.slice(0,-1),n,r)}},fe=(s,e,t)=>{if(s.length===0)return;const[n,r]=X(s);n.set(r+e,t),n.delete(r)},X=s=>s[s.length-1],Z="or",me="and",ke="and_not";class E{constructor(e){if(e?.fields==null)throw new Error('MiniSearch: option "fields" must be provided');const t=e.autoVacuum==null||e.autoVacuum===!0?ie:e.autoVacuum;this._options={...te,...e,autoVacuum:t,searchOptions:{...pe,...e.searchOptions||{}},autoSuggestOptions:{...De,...e.autoSuggestOptions||{}}},this._index=new v,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=ne,this.addFields(this._options.fields)}add(e){const{extractField:t,stringifyField:n,tokenize:r,processTerm:o,fields:i,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 u of i){const p=t(e,u);if(p==null)continue;const l=r(n(p,u),u),h=this._fieldIds[u],g=new Set(l).size;this.addFieldLength(d,h,this._documentCount-1,g);for(const m of l){const f=o(m,u);if(Array.isArray(f))for(const _ of f)this.addTerm(h,d,_);else f&&this.addTerm(h,d,f)}}}addAll(e){for(const t of e)this.add(t)}addAllAsync(e,t={}){const{chunkSize:n=10}=t,r={chunk:[],promise:Promise.resolve()},{chunk:o,promise:i}=e.reduce(({chunk:c,promise:a},d,u)=>(c.push(d),(u+1)%n===0?{chunk:[],promise:a.then(()=>new Promise(p=>setTimeout(p,0))).then(()=>this.addAll(c))}:{chunk:c,promise:a}),r);return i.then(()=>this.addAll(o))}remove(e){const{tokenize:t,processTerm:n,extractField:r,stringifyField:o,fields:i,idField:c}=this._options,a=r(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 u of i){const p=r(e,u);if(p==null)continue;const l=t(o(p,u),u),h=this._fieldIds[u],g=new Set(l).size;this.removeFieldLength(d,h,this._documentCount,g);for(const m of l){const f=n(m,u);if(Array.isArray(f))for(const _ of f)this.removeTerm(h,d,_);else f&&this.removeTerm(h,d,f)}}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 v,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,r)=>{this.removeFieldLength(t,r,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:r}=this._options.autoVacuum;this.conditionalVacuum({batchSize:n,batchWait:r},{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,r=n(e,t);this.discard(r),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=ne,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 r=e.batchSize||se.batchSize,o=e.batchWait||se.batchWait;let i=1;for(const[c,a]of this._index){for(const[d,u]of a)for(const[p]of u)this._documentIds.has(p)||(u.size<=1?a.delete(d):u.delete(p));this._index.get(c).size===0&&this._index.delete(c),i%r===0&&await new Promise(d=>setTimeout(d,o)),i+=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||ie.minDirtCount,n=n||ie.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,r={...n,...t},o=this.executeQuery(e,t),i=[];for(const[c,{score:a,terms:d,match:u}]of o){const p=d.length||1,l={id:this._documentIds.get(c),score:a*p,terms:Object.keys(u),queryTerms:d,match:u};Object.assign(l,this._storedFields.get(c)),(r.filter==null||r.filter(l))&&i.push(l)}return e===E.wildcard&&r.boostDocument==null||i.sort(_e),i}autoSuggest(e,t={}){t={...this._options.autoSuggestOptions,...t};const n=new Map;for(const{score:o,terms:i}of this.search(e,t)){const c=i.join(" "),a=n.get(c);a!=null?(a.score+=o,a.count+=1):n.set(c,{score:o,terms:i,count:1})}const r=[];for(const[o,{score:i,terms:c,count:a}]of n)r.push({suggestion:o,terms:c,score:i/a});return r.sort(_e),r}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(te.hasOwnProperty(e))return ee(te,e);throw new Error(`MiniSearch: unknown option "${e}"`)}static loadJS(e,t){const{index:n,documentIds:r,fieldLength:o,storedFields:i,serializationVersion:c}=e,a=this.instantiateMiniSearch(e,t);a._documentIds=P(r),a._fieldLength=P(o),a._storedFields=P(i);for(const[d,u]of a._documentIds)a._idToShortId.set(u,d);for(const[d,u]of n){const p=new Map;for(const l of Object.keys(u)){let h=u[l];c===1&&(h=h.ds),p.set(parseInt(l,10),P(h))}a._index.set(d,p)}return a}static async loadJSAsync(e,t){const{index:n,documentIds:r,fieldLength:o,storedFields:i,serializationVersion:c}=e,a=this.instantiateMiniSearch(e,t);a._documentIds=await U(r),a._fieldLength=await U(o),a._storedFields=await U(i);for(const[u,p]of a._documentIds)a._idToShortId.set(p,u);let d=0;for(const[u,p]of n){const l=new Map;for(const h of Object.keys(p)){let g=p[h];c===1&&(g=g.ds),l.set(parseInt(h,10),await U(g))}++d%1e3===0&&await ye(0),a._index.set(u,l)}return a}static instantiateMiniSearch(e,t){const{documentCount:n,nextId:r,fieldIds:o,averageFieldLength:i,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 E(t);return d._documentCount=n,d._nextId=r,d._idToShortId=new Map,d._fieldIds=o,d._avgFieldLength=i,d._dirtCount=c||0,d._index=new v,d}executeQuery(e,t={}){if(e===E.wildcard)return this.executeWildcardQuery(t);if(typeof e!="string"){const l={...t,...e,queries:void 0},h=e.queries.map(g=>this.executeQuery(g,l));return this.combineResults(h,l.combineWith)}const{tokenize:n,processTerm:r,searchOptions:o}=this._options,i={tokenize:n,processTerm:r,...o,...t},{tokenize:c,processTerm:a}=i,p=c(e).flatMap(l=>a(l)).filter(l=>!!l).map(Le(i)).map(l=>this.executeQuerySpec(l,i));return this.combineResults(p,i.combineWith)}executeQuerySpec(e,t){const n={...this._options.searchOptions,...t},r=(n.fields||this._options.fields).reduce((m,f)=>({...m,[f]:ee(n.boost,f)||1}),{}),{boostDocument:o,weights:i,maxFuzzy:c,bm25:a}=n,{fuzzy:d,prefix:u}={...pe.weights,...i},p=this._index.get(e.term),l=this.termResults(e.term,e.term,1,e.termBoost,p,r,o,a);let h,g;if(e.prefix&&(h=this._index.atPrefix(e.term)),e.fuzzy){const m=e.fuzzy===!0?.2:e.fuzzy,f=m<1?Math.min(c,Math.round(e.term.length*m)):m;f&&(g=this._index.fuzzyGet(e.term,f))}if(h)for(const[m,f]of h){const _=m.length-e.term.length;if(!_)continue;g?.delete(m);const w=u*m.length/(m.length+.3*_);this.termResults(e.term,m,w,e.termBoost,f,r,o,a,l)}if(g)for(const m of g.keys()){const[f,_]=g.get(m);if(!_)continue;const w=d*m.length/(m.length+_);this.termResults(e.term,m,w,e.termBoost,f,r,o,a,l)}return l}executeWildcardQuery(e){const t=new Map,n={...this._options.searchOptions,...e};for(const[r,o]of this._documentIds){const i=n.boostDocument?n.boostDocument(o,"",this._storedFields.get(r)):1;t.set(r,{score:i,terms:[],match:{}})}return t}combineResults(e,t=Z){if(e.length===0)return new Map;const n=t.toLowerCase(),r=Me[n];if(!r)throw new Error(`Invalid combination operator: ${t}`);return e.reduce(r)||new Map}toJSON(){const e=[];for(const[t,n]of this._index){const r={};for(const[o,i]of n)r[o]=Object.fromEntries(i);e.push([t,r])}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,r,o,i,c,a,d=new Map){if(o==null)return d;for(const u of Object.keys(i)){const p=i[u],l=this._fieldIds[u],h=o.get(l);if(h==null)continue;let g=h.size;const m=this._avgFieldLength[l];for(const f of h.keys()){if(!this._documentIds.has(f)){this.removeTerm(l,f,t),g-=1;continue}const _=c?c(this._documentIds.get(f),t,this._storedFields.get(f)):1;if(!_)continue;const w=h.get(f),V=this._fieldLength.get(f)[l],R=Ee(w,g,this._documentCount,V,m,a),b=n*r*p*_*R,F=d.get(f);if(F){F.score+=b,Te(F.terms,e);const S=ee(F.match,t);S?S.push(u):F.match[t]=[u]}else d.set(f,{score:b,terms:[e],match:{[t]:[u]}})}}return d}addTerm(e,t,n){const r=this._index.fetch(n,we);let o=r.get(e);if(o==null)o=new Map,o.set(t,1),r.set(e,o);else{const i=o.get(t);o.set(t,(i||0)+1)}}removeTerm(e,t,n){if(!this._index.has(n)){this.warnDocumentChanged(t,e,n);return}const r=this._index.fetch(n,we),o=r.get(e);o==null||o.get(t)==null?this.warnDocumentChanged(t,e,n):o.get(t)<=1?o.size<=1?r.delete(e):o.delete(t):o.set(t,o.get(t)-1),this._index.get(n).size===0&&this._index.delete(n)}warnDocumentChanged(e,t,n){for(const r of Object.keys(this._fieldIds))if(this._fieldIds[r]===t){this._options.logger("warn",`MiniSearch: document with ID ${this._documentIds.get(e)} has changed before removal: term "${n}" was not present in field "${r}". 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,r){let o=this._fieldLength.get(e);o==null&&this._fieldLength.set(e,o=[]),o[t]=r;const c=(this._avgFieldLength[t]||0)*n+r;this._avgFieldLength[t]=c/(n+1)}removeFieldLength(e,t,n,r){if(n===1){this._avgFieldLength[t]=0;return}const o=this._avgFieldLength[t]*n-r;this._avgFieldLength[t]=o/(n-1)}saveStoredFields(e,t){const{storeFields:n,extractField:r}=this._options;if(n==null||n.length===0)return;let o=this._storedFields.get(e);o==null&&this._storedFields.set(e,o={});for(const i of n){const c=r(t,i);c!==void 0&&(o[i]=c)}}}E.wildcard=Symbol("*");const ee=(s,e)=>Object.prototype.hasOwnProperty.call(s,e)?s[e]:void 0,Me={[Z]:(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:r,terms:o,match:i}=e.get(t);n.score=n.score+r,n.match=Object.assign(n.match,i),ge(n.terms,o)}}return s},[me]:(s,e)=>{const t=new Map;for(const n of e.keys()){const r=s.get(n);if(r==null)continue;const{score:o,terms:i,match:c}=e.get(n);ge(r.terms,i),t.set(n,{score:r.score+o,terms:r.terms,match:Object.assign(r.match,c)})}return t},[ke]:(s,e)=>{for(const t of e.keys())s.delete(t);return s}},Ce={k:1.2,b:.7,d:.5},Ee=(s,e,t,n,r,o)=>{const{k:i,b:c,d:a}=o;return Math.log(1+(t-e+.5)/(e+.5))*(a+s*(i+1)/(s+i*(1-c+c*n/r)))},Le=s=>(e,t,n)=>{const r=typeof s.fuzzy=="function"?s.fuzzy(e,t,n):s.fuzzy||!1,o=typeof s.prefix=="function"?s.prefix(e,t,n):s.prefix===!0,i=typeof s.boostTerm=="function"?s.boostTerm(e,t,n):1;return{term:e,fuzzy:r,prefix:o,termBoost:i}},te={idField:"id",extractField:(s,e)=>s[e],stringifyField:(s,e)=>s.toString(),tokenize:s=>s.split(Ae),processTerm:s=>s.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(s,e)=>{typeof console?.[s]=="function"&&console[s](e)},autoVacuum:!0},pe={combineWith:Z,prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:.45,prefix:.375},bm25:Ce},De={combineWith:me,prefix:(s,e,t)=>e===t.length-1},se={batchSize:1e3,batchWait:10},ne={minDirtFactor:.1,minDirtCount:20},ie={...se,...ne},Te=(s,e)=>{s.includes(e)||s.push(e)},ge=(s,e)=>{for(const t of e)s.includes(t)||s.push(t)},_e=({score:s},{score:e})=>e-s,we=()=>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 ye(0);return e},ye=s=>new Promise(e=>setTimeout(e,s)),Ae=/[\n\r\p{Z}\p{P}]+/u,z=24e6,J=48e3,Oe=2,L=s=>JSON.stringify([Oe,s.revision,s.updated,s.created,s.projectID,s.directory]);function Ve(s,e){if(!s||!e||s.id!==e.id||s.version!==L(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 x=s=>s.normalize("NFKD").replace(new RegExp("\\p{M}","gu"),"").toLowerCase(),oe=s=>x(s).match(/[\p{L}\p{N}]+/gu)||[],re=s=>oe(s).join(" ");function je(s){const e={text:"",terms:[],phrases:[],filters:[]},t=[];for(const n of s.slice(0,300).match(/(?:[^\s"]+|"[^"]*")+/g)||[]){const r=/^(source|project|dir|model|is|after|before|in):(.+)$/i.exec(n);if(r){const i=r[1].toLowerCase(),c=x(r[2].replace(/^"|"$/g,""));if(i==="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 i==="is"&&!["fork","child","root","archived"].includes(c)?e.error="Use is:fork, is:child, is:root, or is:archived.":["after","before"].includes(i)&&(!/^\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([i,c]);continue}const o=n.replace(/^"|"$/g,"");n.startsWith('"')&&n.endsWith('"')&&e.phrases.push(re(o)),t.push(o)}return e.text=t.join(" "),e.terms=oe(e.text).slice(0,12),e.text=e.terms.join(" "),e}function Ne(s,e,t=220){const n=x(s),r=e.reduce((i,c)=>{const a=n.indexOf(c);return a<0?i:Math.min(i,a)},1/0),o=Number.isFinite(r)?Math.max(0,r-55):0;return`${o?"…":""}${s.slice(o,o+t).replace(/\s+/g," ").trim()}${s.length>o+t?"…":""}`}class $e{index=new E({fields:["title","project","directory","model","sessionID","files","body","tools"],tokenize:oe,processTerm:x,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(o=>o.id));for(const[o,i]of this.entries)n.has(o)||(this.index.remove(i.doc),this.entries.delete(o));const r=new Map(t.map(o=>[o.id,o.name]));for(const o of e){const i=this.entries.get(o.id),c=i&&L(i.session)===L(o),a={id:o.id,title:o.title,project:r.get(o.projectID)||"",directory:o.directory,model:o.model,sessionID:o.id,body:c?i.doc.body:"",files:c?i.doc.files:"",tools:c?i.doc.tools:""};if(c&&Object.keys(a).every(d=>i.doc[d]===a[d])){i.session=o;continue}this.entries.set(o.id,{session:o,doc:a,fragments:c?i.fragments:[]}),i&&this.index.remove(i.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 r={...n.doc};for(const o of t){const i=o.kind==="File"?"files":o.kind==="Tool"?"tools":"body";r[i]+=`
2
- ${o.text}`}this.index.remove(n.doc),this.index.add(r),n.doc=r,this.cache.clear()}search(e,t=!1,n=80){const r=`${e}\0${t}\0${n}`,o=this.cache.get(r);if(o)return o;const i=je(e);if(i.error)return{hits:[],total:0,error:i.error};const c=l=>{const{session:h,doc:g}=l;if(t&&!this.scope.has(h.id))return!1;for(const[m,f]of i.filters)if(m==="source"&&!x(h.source||"opencode").includes(f)||m==="project"&&!x(g.project).includes(f)&&!x(h.projectID).includes(f)||m==="dir"&&!x(h.directory).includes(f)||m==="model"&&!x(h.model).includes(f)||m==="after"&&h.created<new Date(`${f}T00:00:00`).getTime()||m==="before"&&h.created>new Date(`${f}T23:59:59.999`).getTime()||m==="is"&&(f==="fork"&&!h.forkID||f==="child"&&(!h.parentID||h.forkID)||f==="root"&&(h.parentID||h.forkID)||f==="archived"&&!h.archived))return!1;if(i.phrases.length){const m=i.fields||["title","body","files","tools","project","directory","model"];if(!i.phrases.every(f=>m.some(_=>re(g[_]).includes(f))))return!1}return!0},d=(i.terms.length?this.index.search(i.text,{fields:i.fields,fuzzy:l=>l.length<4?!1:l.length>7?2:1,filter:l=>c(this.entries.get(String(l.id)))}):[...this.entries.values()].filter(c).map(l=>({id:l.session.id,score:0,terms:[],match:{}}))).map(l=>{const h=this.entries.get(String(l.id)),g=re(h.doc.title),m=new Set(Object.values(l.match).flat()),f=i.text?g.includes(i.text)&&(!i.fields||i.fields.includes("title"))?5:m.has("title")||m.has("sessionID")?4:m.has("files")?3:m.has("body")?2:1:0;return{match:l,entry:h,tier:f}}).sort((l,h)=>h.tier-l.tier||h.match.score-l.match.score||h.entry.session.updated-l.entry.session.updated||l.entry.session.id.localeCompare(h.entry.session.id)),p={hits:d.slice(0,Math.min(250,Math.max(1,n))).map(({match:l,entry:h,tier:g})=>{const m=l.terms.length?l.terms:i.terms,f=h.fragments.filter(b=>!i.fields||i.fields.includes(b.kind==="File"?"files":b.kind==="Tool"?"tools":"body"));let _,w=0;for(const b of f){const F=x(b.text),S=m.reduce((Pe,Ue)=>Pe+Number(F.includes(Ue)),0);if(S>w&&(_=b,w=S),S===m.length&&S>0)break}const V=new Set(Object.values(l.match).flat()),R=g>=4?V.has("sessionID")&&!V.has("title")?"Session ID":"Title":_?_.kind==="File"?"File":_.kind==="Tool"?"Tool":"Message":i.text?"Metadata":"Recent";return{id:h.session.id,score:l.score,source:R,excerpt:_?Ne(_.text,m):"",terms:m}}),total:d.length};return this.cache.size>=30&&this.cache.delete(this.cache.keys().next().value),this.cache.set(r,p),p}}class Re{available=!0;epoch=0;async restore(e,t,n){const r=new Map(t.map(c=>[c.id,c]));let o,i=0;try{do{const c=await fetch(`/api/sessiongraph/index${o?`?after=${encodeURIComponent(o)}`:""}`);if(!c.ok)throw new Error("Index unavailable");const a=await c.json();this.epoch=a.epoch;for(const d of a.records)Ve(d,r.get(d.id))&&i+d.characters<=z&&(i+=d.characters,n(d));o=a.cursor}while(o);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 k=new $e,q=new Re,y=new Map,D=new Set;let T=!1,Q=0,I=0,M=0,B=!1,A,O,xe=[],ce,be=0;const Y=new Set,j=s=>postMessage(s);function N(){if(!O)return;const s=performance.now(),e=k.search(O.text,O.viewOnly,O.limit);xe=e.hits.slice(0,12).map(t=>t.id),j({type:"results",request:O.request,...e,elapsed:performance.now()-s})}function $(){const s=[...y.values()];j({type:"status",status:{indexed:s.filter(e=>e.pages>0).length,complete:s.filter(e=>e.complete).length,total:y.size,characters:I,active:T&&Q>0,limited:I>=z||s.some(e=>e.partial||e.capped),failed:s.filter(e=>e.failed>0).length,restored:D.size,storage:B?A?.sourceID&&q.available?"local":"memory":"restoring"}})}function Se(){ce||(ce=setTimeout(()=>{ce=void 0,N(),$()},200))}function We(){const s=t=>!!(t&&!t.inflight&&!t.complete&&!t.capped&&t.failed<1);for(const t of xe){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 ae(){if(!B||!T||I>=z){$();return}for(;Q<2;){const s=We();if(!s)break;s.inflight=!0,Q++;const e=M,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 r=await fetch(`/api/sessiongraph/session/${encodeURIComponent(s.session.id)}/content?${n}`,{signal:t.signal});if(!r.ok)throw new Error("Conversation unavailable");const o=await r.json();if(e!==M||t.signal.aborted)return;if(o.id!==s.session.id)throw new Error("Unexpected conversation");const i=Math.min(J,Math.floor(z/Math.max(1,y.size)));let c=Math.min(i-s.characters,z-I);const a=[],d=[...o.fragments].sort((l,h)=>+(h.kind==="File"||h.kind==="You")-+(l.kind==="File"||l.kind==="You")),u=Math.max(160,Math.min(2e3,Math.floor(c/Math.max(1,d.length))));let p=!1;for(const l of d){if(c<=0){p=!0;break}const h=l.text.slice(0,Math.min(c,u));p||=h.length<l.text.length,a.push({...l,text:h}),c-=h.length,s.characters+=h.length,I+=h.length}k.addContent(s.session.id,a),s.pages++,s.partial||=o.truncated||p,s.complete=!o.nextCursor&&!s.partial,s.capped=!s.complete&&(!o.nextCursor||s.characters>=i||s.pages>=8),s.cursor=o.nextCursor||void 0,Se(),A?.sourceID&&await q.save({id:s.session.id,version:L(s.session),fragments:k.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===M&&s.failed++}finally{s.inflight=!1,Y.delete(t),Q--,T?setTimeout(ae,performance.now()-be<150?150:35):$()}})()}$()}async function Ie(s,e=!1){const t=++M;B=!1,Y.forEach(i=>i.abort());const n=A?.sourceID===s.sourceID&&!e,r=n?new Map(y):new Map;n||(k.setData([],[]),D.clear()),A=s,y.clear(),I=0;for(const i of[...s.sessions].sort((c,a)=>a.updated-c.updated)){const c=r.get(i.id),a=c&&L(c.session)===L(i),d=a?{...c,session:i,inflight:!1}:{session:i,pages:0,characters:0,partial:!1,complete:!1,capped:!1,failed:0,inflight:!1};a||D.delete(i.id),y.set(i.id,d),I+=d.characters}for(const i of D)y.has(i)||D.delete(i);if(k.setData(s.sessions,s.projects),N(),$(),e&&await q.clear(),t!==M||(s.sourceID&&await q.restore(s.sourceID,s.sessions,i=>{if(t!==M)return;const c=y.get(i.id);!c||c.pages||I+i.characters>z||(k.addContent(i.id,i.fragments),Object.assign(c,{pages:i.pages,characters:i.characters,partial:i.partial,complete:i.complete,capped:i.capped,cursor:i.cursor}),I+=i.characters,D.add(i.id),Se())}),t!==M))return;const o=Math.min(J,Math.floor(z/Math.max(1,y.size)));for(const i of y.values())!i.complete&&i.characters>=o&&(i.capped=!0);B=!0,N(),ae()}self.onmessage=s=>{try{const e=s.data;e.type==="data"?Ie(e).catch(()=>j({type:"error",message:"Search index could not load. Reload to retry."})):e.type==="scope"?(k.setScope(e.ids),N()):e.type==="query"?(be=performance.now(),O=e,N()):e.type==="clear-cache"?(T=!1,A&&Ie(A,!0).catch(()=>j({type:"error",message:"Search index could not reset. Reload to retry."}))):(T=e.enabled,T?y.forEach(t=>{t.failed=0}):Y.forEach(t=>t.abort()),ae())}catch(e){j({type:"error",message:e instanceof Error?e.message:"Search unavailable"})}}})();