sessiongraph-app-darwin-x64 1.0.11 → 1.0.12

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 (16) hide show
  1. package/package.json +2 -2
  2. package/payload/SessionGraph.app/Contents/Info.plist +2 -2
  3. package/payload/SessionGraph.app/Contents/MacOS/sessiongraph +0 -0
  4. package/payload/SessionGraph.app/Contents/Resources/resources/server.mjs +157 -53
  5. package/payload/SessionGraph.app/Contents/Resources/resources/web/assets/{external-links-CJk2OPKW.js → external-links-D0O8IeG0.js} +1 -1
  6. package/payload/SessionGraph.app/Contents/Resources/resources/web/assets/{index-JjTdnq9-.js → index-BS2Voifb.js} +1 -1
  7. package/payload/SessionGraph.app/Contents/Resources/resources/web/assets/{index-DPovJIlT.js → index-CIhs02tq.js} +5 -5
  8. package/payload/SessionGraph.app/Contents/Resources/resources/web/assets/{index-DhlS3ZId.js → index-GTrhxXlP.js} +1 -1
  9. package/payload/SessionGraph.app/Contents/Resources/resources/web/assets/{index-DOYyn-b_.js → index-Vq4WYmzW.js} +1 -1
  10. package/payload/SessionGraph.app/Contents/Resources/resources/web/assets/{publishing-CkVIjq_f.js → publishing-ofssf6d6.js} +1 -1
  11. package/payload/SessionGraph.app/Contents/Resources/resources/web/assets/{scene-BXs8B_Kk.js → scene-KCDTPCOD.js} +1 -1
  12. package/payload/SessionGraph.app/Contents/Resources/resources/web/assets/{share-jfOenMTA.js → share-DKeJCFAo.js} +3 -3
  13. package/payload/SessionGraph.app/Contents/Resources/resources/web/assets/worker-C10U_apJ.js +2 -0
  14. package/payload/SessionGraph.app/Contents/Resources/resources/web/index.html +1 -1
  15. package/payload/SessionGraph.app/Contents/_CodeSignature/CodeResources +44 -44
  16. package/payload/SessionGraph.app/Contents/Resources/resources/web/assets/worker-DwqxiDWY.js +0 -2
@@ -1 +1 @@
1
- import{n as i}from"./index-DPovJIlT.js";function r(e){if(e!==void 0){if(typeof e=="string")return e;if("ok"in e&&"cancel"in e)return{OkCancelCustom:[e.ok,e.cancel]};if("yes"in e&&"no"in e&&"cancel"in e)return{YesNoCancelCustom:[e.yes,e.no,e.cancel]};if("ok"in e)return{OkCustom:e.ok}}}async function f(e={}){return typeof e=="object"&&Object.freeze(e),await i("plugin:dialog|open",{options:e})}async function k(e={}){return typeof e=="object"&&Object.freeze(e),await i("plugin:dialog|save",{options:e})}async function l(e,a){return await i("plugin:dialog|message",{message:e,title:a?.title,kind:a?.kind,buttons:r(a?.buttons)})}async function s(e,a){const n=typeof a=="string"?{title:a}:a;return n&&!n.buttons&&n.okLabel&&(n.buttons={ok:n.okLabel}),l(e,n)}async function u(e,a){const n=typeof a=="string"?{title:a}:a,c=n?.okLabel||n?.cancelLabel,t=n?.okLabel??"Yes";return await l(e,{title:n?.title,kind:n?.kind,buttons:c?{ok:t,cancel:n.cancelLabel??"No"}:"YesNo"})===t}async function d(e,a){const n=typeof a=="string"?{title:a}:a,c=n?.okLabel||n?.cancelLabel,t=n?.okLabel??"Ok";return await l(e,{title:n?.title,kind:n?.kind,buttons:c?{ok:t,cancel:n.cancelLabel??"Cancel"}:"OkCancel"})===t}export{u as ask,d as confirm,s as message,f as open,k as save};
1
+ import{n as i}from"./index-CIhs02tq.js";function r(e){if(e!==void 0){if(typeof e=="string")return e;if("ok"in e&&"cancel"in e)return{OkCancelCustom:[e.ok,e.cancel]};if("yes"in e&&"no"in e&&"cancel"in e)return{YesNoCancelCustom:[e.yes,e.no,e.cancel]};if("ok"in e)return{OkCustom:e.ok}}}async function f(e={}){return typeof e=="object"&&Object.freeze(e),await i("plugin:dialog|open",{options:e})}async function k(e={}){return typeof e=="object"&&Object.freeze(e),await i("plugin:dialog|save",{options:e})}async function l(e,a){return await i("plugin:dialog|message",{message:e,title:a?.title,kind:a?.kind,buttons:r(a?.buttons)})}async function s(e,a){const n=typeof a=="string"?{title:a}:a;return n&&!n.buttons&&n.okLabel&&(n.buttons={ok:n.okLabel}),l(e,n)}async function u(e,a){const n=typeof a=="string"?{title:a}:a,c=n?.okLabel||n?.cancelLabel,t=n?.okLabel??"Yes";return await l(e,{title:n?.title,kind:n?.kind,buttons:c?{ok:t,cancel:n.cancelLabel??"No"}:"YesNo"})===t}async function d(e,a){const n=typeof a=="string"?{title:a}:a,c=n?.okLabel||n?.cancelLabel,t=n?.okLabel??"Ok";return await l(e,{title:n?.title,kind:n?.kind,buttons:c?{ok:t,cancel:n.cancelLabel??"Cancel"}:"OkCancel"})===t}export{u as ask,d as confirm,s as message,f as open,k as save};
@@ -1 +1 @@
1
- import{n as a,R as i,C as o}from"./index-DPovJIlT.js";class l extends i{constructor(e){super(e.rid),this.available=!0,this.currentVersion=e.currentVersion,this.version=e.version,this.date=e.date,this.body=e.body,this.rawJson=e.rawJson}async download(e,s){const d=new o;e&&(d.onmessage=e);const r=await a("plugin:updater|download",{onEvent:d,rid:this.rid,...s,headers:t(s?.headers)});await this.downloadedBytes?.close().catch(()=>{}),this.downloadedBytes=new i(r)}async install(e){if(!this.downloadedBytes)throw new Error("Update.install called before Update.download");await a("plugin:updater|install",{updateRid:this.rid,bytesRid:this.downloadedBytes.rid,...e}),this.downloadedBytes=void 0}async downloadAndInstall(e,s){const d=new o;e&&(d.onmessage=e),await a("plugin:updater|download_and_install",{onEvent:d,rid:this.rid,...s,headers:t(s?.headers)})}async close(){await this.downloadedBytes?.close(),await super.close()}}async function w(n){const e=await a("plugin:updater|check",{...n,headers:t(n?.headers)});return e?new l(e):null}function t(n){return n?Array.from(new Headers(n).entries()):void 0}export{l as Update,w as check};
1
+ import{n as a,R as i,C as o}from"./index-CIhs02tq.js";class l extends i{constructor(e){super(e.rid),this.available=!0,this.currentVersion=e.currentVersion,this.version=e.version,this.date=e.date,this.body=e.body,this.rawJson=e.rawJson}async download(e,s){const d=new o;e&&(d.onmessage=e);const r=await a("plugin:updater|download",{onEvent:d,rid:this.rid,...s,headers:t(s?.headers)});await this.downloadedBytes?.close().catch(()=>{}),this.downloadedBytes=new i(r)}async install(e){if(!this.downloadedBytes)throw new Error("Update.install called before Update.download");await a("plugin:updater|install",{updateRid:this.rid,bytesRid:this.downloadedBytes.rid,...e}),this.downloadedBytes=void 0}async downloadAndInstall(e,s){const d=new o;e&&(d.onmessage=e),await a("plugin:updater|download_and_install",{onEvent:d,rid:this.rid,...s,headers:t(s?.headers)})}async close(){await this.downloadedBytes?.close(),await super.close()}}async function w(n){const e=await a("plugin:updater|check",{...n,headers:t(n?.headers)});return e?new l(e):null}function t(n){return n?Array.from(new Headers(n).entries()):void 0}export{l as Update,w as check};
@@ -1,4 +1,4 @@
1
- import{h as pe,j as me,m as ge,D as be,a as ae,k as q,l as ie,t as he,P as fe,g as ye,c as we,i as V}from"./index-DPovJIlT.js";import{TimelineScene as ve}from"./scene-BXs8B_Kk.js";import{s as ke,e as Se,o as Ce}from"./external-links-CJk2OPKW.js";import"./three-D_1Qt16u.js";const xe=["svg",pe,[["path",{d:"M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"}],["path",{d:"M9 18c-4.51 2-5-2-7-2"}]]],Ae={tokens:"Token counts",timestamps:"Session timestamps",messageCounts:"Message counts",messageTimestamps:"Message timestamps",model:"Model used",harness:"Harness used"},Z={tokens:!0,timestamps:!0,messageCounts:!0,messageTimestamps:!0,model:!0,harness:!0};function oe(t){const r={...Z};if(ce(t))for(const n of Object.keys(r))typeof t[n]=="boolean"&&(r[n]=t[n]);return(!r.timestamps||!r.messageCounts)&&(r.messageTimestamps=!1),r}const re=1e4,Ee=2e6,Pe=1e5,Me="Always excluded: project and session names, messages, code, paths, source IDs, and costs. Anonymous groups and recorded branch links are included. Your GitHub username identifies this profile. Your published graph will appear in Explore graphs. Selected timestamps and usage will be public.",Te=/^(?:gpt-[3-6](?:\.[0-9])?(?:-(?:turbo|mini|nano|pro|codex|astra|instant|thinking|chat|latest|preview|[0-9]{4,8}))*|o[1-4](?:-(?:mini|pro|preview|[0-9]{4,8}))*|claude-(?:(?:sonnet|opus|haiku)-[3-5](?:[.-][0-9])?|[3-5](?:-[0-9])?-(?:sonnet|opus|haiku))(?:-(?:latest|thinking|[0-9]{8}))*|gemini-[1-4](?:\.[0-9])?-(?:pro|flash)(?:-(?:lite|preview|exp|latest|[0-9]{2,4}))*|deepseek-(?:chat|reasoner|v[3-4](?:\.[0-9])?|r1)|grok-[2-5](?:\.[0-9])?(?:-(?:fast|code|reasoning|non-reasoning|[0-9]))*|kimi-k[1-3](?:\.[0-9])?(?:-thinking)?|minimax-m[1-3](?:\.[0-9])?)$/i,Le=t=>{const r=t.split("/").at(-1)||"";return r.length<=100&&Te.test(r)?r.toLowerCase():null},ce=t=>!!t&&typeof t=="object"&&!Array.isArray(t),B=(t,r)=>ce(t)&&Object.keys(t).length===r.length&&r.every(n=>Object.hasOwn(t,n)),Y=(t,r=Number.MAX_SAFE_INTEGER)=>Number.isSafeInteger(t)&&t>=0&&t<=r,W=t=>Y(t,Date.UTC(2100,0,1)),z=t=>t===null||Y(t);function de(t){const r=()=>{throw new Error("Invalid anonymous graph. Reopen the publishing preview and try again.")};if(!B(t,["version","settings","sessions"])||t.version!==1||!Array.isArray(t.sessions)||!B(t.settings,Object.keys(Z))||Object.values(t.settings).some(f=>typeof f!="boolean"))return r();const n=t.settings;if(n.messageTimestamps&&(!n.timestamps||!n.messageCounts))return r();if(t.sessions.length<1||t.sessions.length>re)throw new Error(`Choose between 1 and ${re.toLocaleString("en")} sessions to publish.`);const e=["id","group","parent","fork",...n.timestamps?["timestamps"]:[],...n.tokens?["tokens"]:[],...n.messageCounts?["messages"]:[],...n.messageTimestamps?["messageTimes"]:[],...n.model?["model"]:[],...n.harness?["harness"]:[]];let m=0;for(let f=0;f<t.sessions.length;f++){const i=t.sessions[f];if(!B(i,e)||i.id!==f||!Y(i.group,t.sessions.length-1))return r();for(const p of["parent","fork"])if(i[p]!==null&&(!Y(i[p],t.sessions.length-1)||i[p]===f))return r();if(n.timestamps&&(!B(i.timestamps,["created","lastMessageAt"])||!W(i.timestamps.created)||i.timestamps.lastMessageAt!==null&&!W(i.timestamps.lastMessageAt))||n.tokens&&!z(i.tokens)||n.messageCounts&&(!B(i.messages,["count","untimed","partial"])||!z(i.messages.count)||!z(i.messages.untimed)||typeof i.messages.partial!="boolean")||n.messageTimestamps&&(!B(i.messageTimes,["values","limited"])||!Array.isArray(i.messageTimes.values)||i.messageTimes.values.length>2e3||typeof i.messageTimes.limited!="boolean"||i.messageTimes.values.some(p=>!W(p))||(m+=i.messageTimes.values.length,m>Pe))||n.model&&i.model!==null&&(typeof i.model!="string"||Le(i.model)!==i.model)||n.harness&&i.harness!==null&&(typeof i.harness!="string"||!me(i.harness)))return r()}const o=t.sessions,l=new Uint8Array(o.length);for(let f=0;f<o.length;f++){if(l[f])continue;const i=[[f,!1]];for(;i.length;){const[p,M]=i.pop();if(M){l[p]=2;continue}if(l[p]===1)return r();if(l[p]!==2){l[p]=1,i.push([p,!0]);for(const S of[o[p].parent,o[p].fork])S!==null&&i.push([S,!1])}}}if(new TextEncoder().encode(JSON.stringify(t)).length>Ee)throw new Error("This graph is too large. Choose a smaller date range.");return t}function le(t,r){const n=de(t),e=n.sessions.filter(l=>!r||r.has(l.id)).map(l=>({id:String(l.id),projectID:String(l.group),title:`Session ${l.id+1}`,directory:"",created:l.timestamps?.created??l.id*36e5,updated:l.timestamps?.created??l.id*36e5,tokens:l.tokens??null,cost:null,archived:!1,model:l.model??"",provider:"",agent:"",source:l.harness??void 0,activity:{firstMessageAt:null,lastMessageAt:l.timestamps?.lastMessageAt??null,userMessages:0,untimedUserMessages:0},...l.parent===null?{}:{parentID:String(l.parent)},...l.fork===null?{}:{forkID:String(l.fork)}})),m=[...new Set(n.sessions.map(l=>l.group))].map(l=>({id:String(l),name:`Group ${l+1}`,directory:"",worktrees:[]})),o=ge(e.map(l=>({...l,source:void 0})),m);for(const l of o.nodes)l.session.source=n.sessions[Number(l.session.id)].harness??void 0;return o}function $e(t){const r=t.settings.tokens?t.sessions.filter(e=>typeof e.tokens=="number"):[],n=r.reduce((e,m)=>e+m.tokens,0);return{sessionCount:t.sessions.length,tokenCount:r.length&&Number.isSafeInteger(n)?n:null,tokensPartial:r.length>0&&r.length<t.sessions.length}}function ue(t){const r=$e(t),n=[`${r.sessionCount.toLocaleString()} sessions`];if(t.settings.tokens&&n.push(r.tokenCount===null?"Tokens unavailable":`${r.tokenCount.toLocaleString()} recorded tokens${r.tokensPartial?" (partial coverage)":""}`),t.settings.messageCounts){const e=t.sessions.filter(m=>m.messages?.count!=null);n.push(e.length?`${e.reduce((m,o)=>m+o.messages.count,0).toLocaleString()} recorded messages${e.length<t.sessions.length||t.sessions.some(m=>m.messages?.partial)?" (partial history)":""}`:"Message counts unavailable")}return n.join(" · ")}const Q=t=>t==null?"Unknown":t.toLocaleString(),R=t=>t===null?"Unknown":new Date(t).toLocaleString();function Ie(t,r,n={}){const e=de(r);let m=le(e);t.classList.add("public-viewer"),t.classList.toggle("public-viewer-full",!!n.fullscreen),t.innerHTML=`
1
+ import{h as pe,j as me,m as ge,D as be,a as ae,k as q,l as ie,t as he,P as fe,g as ye,c as we,i as V}from"./index-CIhs02tq.js";import{TimelineScene as ve}from"./scene-KCDTPCOD.js";import{s as ke,e as Se,o as Ce}from"./external-links-D0O8IeG0.js";import"./three-D_1Qt16u.js";const xe=["svg",pe,[["path",{d:"M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"}],["path",{d:"M9 18c-4.51 2-5-2-7-2"}]]],Ae={tokens:"Token counts",timestamps:"Session timestamps",messageCounts:"Message counts",messageTimestamps:"Message timestamps",model:"Model used",harness:"Harness used"},Z={tokens:!0,timestamps:!0,messageCounts:!0,messageTimestamps:!0,model:!0,harness:!0};function oe(t){const r={...Z};if(ce(t))for(const n of Object.keys(r))typeof t[n]=="boolean"&&(r[n]=t[n]);return(!r.timestamps||!r.messageCounts)&&(r.messageTimestamps=!1),r}const re=1e4,Ee=2e6,Pe=1e5,Me="Always excluded: project and session names, messages, code, paths, source IDs, and costs. Anonymous groups and recorded branch links are included. Your GitHub username identifies this profile. Your published graph will appear in Explore graphs. Selected timestamps and usage will be public.",Te=/^(?:gpt-[3-6](?:\.[0-9])?(?:-(?:turbo|mini|nano|pro|codex|astra|instant|thinking|chat|latest|preview|[0-9]{4,8}))*|o[1-4](?:-(?:mini|pro|preview|[0-9]{4,8}))*|claude-(?:(?:sonnet|opus|haiku)-[3-5](?:[.-][0-9])?|[3-5](?:-[0-9])?-(?:sonnet|opus|haiku))(?:-(?:latest|thinking|[0-9]{8}))*|gemini-[1-4](?:\.[0-9])?-(?:pro|flash)(?:-(?:lite|preview|exp|latest|[0-9]{2,4}))*|deepseek-(?:chat|reasoner|v[3-4](?:\.[0-9])?|r1)|grok-[2-5](?:\.[0-9])?(?:-(?:fast|code|reasoning|non-reasoning|[0-9]))*|kimi-k[1-3](?:\.[0-9])?(?:-thinking)?|minimax-m[1-3](?:\.[0-9])?)$/i,Le=t=>{const r=t.split("/").at(-1)||"";return r.length<=100&&Te.test(r)?r.toLowerCase():null},ce=t=>!!t&&typeof t=="object"&&!Array.isArray(t),B=(t,r)=>ce(t)&&Object.keys(t).length===r.length&&r.every(n=>Object.hasOwn(t,n)),Y=(t,r=Number.MAX_SAFE_INTEGER)=>Number.isSafeInteger(t)&&t>=0&&t<=r,W=t=>Y(t,Date.UTC(2100,0,1)),z=t=>t===null||Y(t);function de(t){const r=()=>{throw new Error("Invalid anonymous graph. Reopen the publishing preview and try again.")};if(!B(t,["version","settings","sessions"])||t.version!==1||!Array.isArray(t.sessions)||!B(t.settings,Object.keys(Z))||Object.values(t.settings).some(f=>typeof f!="boolean"))return r();const n=t.settings;if(n.messageTimestamps&&(!n.timestamps||!n.messageCounts))return r();if(t.sessions.length<1||t.sessions.length>re)throw new Error(`Choose between 1 and ${re.toLocaleString("en")} sessions to publish.`);const e=["id","group","parent","fork",...n.timestamps?["timestamps"]:[],...n.tokens?["tokens"]:[],...n.messageCounts?["messages"]:[],...n.messageTimestamps?["messageTimes"]:[],...n.model?["model"]:[],...n.harness?["harness"]:[]];let m=0;for(let f=0;f<t.sessions.length;f++){const i=t.sessions[f];if(!B(i,e)||i.id!==f||!Y(i.group,t.sessions.length-1))return r();for(const p of["parent","fork"])if(i[p]!==null&&(!Y(i[p],t.sessions.length-1)||i[p]===f))return r();if(n.timestamps&&(!B(i.timestamps,["created","lastMessageAt"])||!W(i.timestamps.created)||i.timestamps.lastMessageAt!==null&&!W(i.timestamps.lastMessageAt))||n.tokens&&!z(i.tokens)||n.messageCounts&&(!B(i.messages,["count","untimed","partial"])||!z(i.messages.count)||!z(i.messages.untimed)||typeof i.messages.partial!="boolean")||n.messageTimestamps&&(!B(i.messageTimes,["values","limited"])||!Array.isArray(i.messageTimes.values)||i.messageTimes.values.length>2e3||typeof i.messageTimes.limited!="boolean"||i.messageTimes.values.some(p=>!W(p))||(m+=i.messageTimes.values.length,m>Pe))||n.model&&i.model!==null&&(typeof i.model!="string"||Le(i.model)!==i.model)||n.harness&&i.harness!==null&&(typeof i.harness!="string"||!me(i.harness)))return r()}const o=t.sessions,l=new Uint8Array(o.length);for(let f=0;f<o.length;f++){if(l[f])continue;const i=[[f,!1]];for(;i.length;){const[p,M]=i.pop();if(M){l[p]=2;continue}if(l[p]===1)return r();if(l[p]!==2){l[p]=1,i.push([p,!0]);for(const S of[o[p].parent,o[p].fork])S!==null&&i.push([S,!1])}}}if(new TextEncoder().encode(JSON.stringify(t)).length>Ee)throw new Error("This graph is too large. Choose a smaller date range.");return t}function le(t,r){const n=de(t),e=n.sessions.filter(l=>!r||r.has(l.id)).map(l=>({id:String(l.id),projectID:String(l.group),title:`Session ${l.id+1}`,directory:"",created:l.timestamps?.created??l.id*36e5,updated:l.timestamps?.created??l.id*36e5,tokens:l.tokens??null,cost:null,archived:!1,model:l.model??"",provider:"",agent:"",source:l.harness??void 0,activity:{firstMessageAt:null,lastMessageAt:l.timestamps?.lastMessageAt??null,userMessages:0,untimedUserMessages:0},...l.parent===null?{}:{parentID:String(l.parent)},...l.fork===null?{}:{forkID:String(l.fork)}})),m=[...new Set(n.sessions.map(l=>l.group))].map(l=>({id:String(l),name:`Group ${l+1}`,directory:"",worktrees:[]})),o=ge(e.map(l=>({...l,source:void 0})),m);for(const l of o.nodes)l.session.source=n.sessions[Number(l.session.id)].harness??void 0;return o}function $e(t){const r=t.settings.tokens?t.sessions.filter(e=>typeof e.tokens=="number"):[],n=r.reduce((e,m)=>e+m.tokens,0);return{sessionCount:t.sessions.length,tokenCount:r.length&&Number.isSafeInteger(n)?n:null,tokensPartial:r.length>0&&r.length<t.sessions.length}}function ue(t){const r=$e(t),n=[`${r.sessionCount.toLocaleString()} sessions`];if(t.settings.tokens&&n.push(r.tokenCount===null?"Tokens unavailable":`${r.tokenCount.toLocaleString()} recorded tokens${r.tokensPartial?" (partial coverage)":""}`),t.settings.messageCounts){const e=t.sessions.filter(m=>m.messages?.count!=null);n.push(e.length?`${e.reduce((m,o)=>m+o.messages.count,0).toLocaleString()} recorded messages${e.length<t.sessions.length||t.sessions.some(m=>m.messages?.partial)?" (partial history)":""}`:"Message counts unavailable")}return n.join(" · ")}const Q=t=>t==null?"Unknown":t.toLocaleString(),R=t=>t===null?"Unknown":new Date(t).toLocaleString();function Ie(t,r,n={}){const e=de(r);let m=le(e);t.classList.add("public-viewer"),t.classList.toggle("public-viewer-full",!!n.fullscreen),t.innerHTML=`
2
2
  <div class="public-canvas" aria-label="Interactive public session graph"></div>
3
3
  <div class="public-toolbar"><button type="button" data-sessions aria-expanded="true">☷ Sessions</button><span class="public-badge">Public snapshot</span></div>
4
4
  <nav class="public-view-controls" aria-label="Graph controls"><div class="public-view-switch"><button type="button" data-view="3d" aria-pressed="true">3D</button><button type="button" data-view="2d" aria-pressed="false">2D</button></div><button type="button" data-fit title="Fit view (F)">Fit view</button><button type="button" data-motion aria-pressed="true">Motion</button><button type="button" data-timeline aria-expanded="true">Timeline</button></nav>
@@ -1,4 +1,4 @@
1
- import{M as oe,C as L,S as ce,a as M,G,P as ae,I as ne,b as k,D as F,c as I,A as T,d as Y,e as N,B as D,F as S,f as re,g as H,W as ke,h as Pe,O as Se,i as Ae,H as Ce,E as Re,R as Fe,U as Ee,V as O,j as Ie,k as Te,l as ze,m as Be,n as Ue,o as V,p as Ge,q as g,r as De,s as ee,t as Oe,u as Le,v as j,w as te,x as ie,y as He,L as Ne,z as de,J as ue,K as Xe,N as _e}from"./three-D_1Qt16u.js";import{h as ge,o as R,c as Ve,D as $e,l as je,q as C,r as $,u as We,v as qe,w as Ye,x as se,y as fe}from"./index-DPovJIlT.js";const Ke=["svg",ge,[["path",{d:"M12 8V4H8"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2"}],["path",{d:"M2 14h2"}],["path",{d:"M20 14h2"}],["path",{d:"M15 13v2"}],["path",{d:"M9 13v2"}]]];const Qe=["svg",ge,[["circle",{cx:"12",cy:"8",r:"5"}],["path",{d:"M20 21a8 8 0 0 0-16 0"}]]],ye=`
1
+ import{M as oe,C as L,S as ce,a as M,G,P as ae,I as ne,b as k,D as F,c as I,A as T,d as Y,e as N,B as D,F as S,f as re,g as H,W as ke,h as Pe,O as Se,i as Ae,H as Ce,E as Re,R as Fe,U as Ee,V as O,j as Ie,k as Te,l as ze,m as Be,n as Ue,o as V,p as Ge,q as g,r as De,s as ee,t as Oe,u as Le,v as j,w as te,x as ie,y as He,L as Ne,z as de,J as ue,K as Xe,N as _e}from"./three-D_1Qt16u.js";import{h as ge,o as R,c as Ve,D as $e,l as je,q as C,r as $,u as We,v as qe,w as Ye,x as se,y as fe}from"./index-CIhs02tq.js";const Ke=["svg",ge,[["path",{d:"M12 8V4H8"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2"}],["path",{d:"M2 14h2"}],["path",{d:"M20 14h2"}],["path",{d:"M15 13v2"}],["path",{d:"M9 13v2"}]]];const Qe=["svg",ge,[["circle",{cx:"12",cy:"8",r:"5"}],["path",{d:"M20 21a8 8 0 0 0-16 0"}]]],ye=`
2
2
  attribute float nodeIndex;
3
3
  uniform float uSelected;
4
4
  uniform float uHovered;
@@ -1,6 +1,6 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-DhlS3ZId.js","assets/index-DPovJIlT.js","assets/index-cVgPCrFV.css","assets/index-JjTdnq9-.js"])))=>i.map(i=>d[i]);
2
- import{TimelineScene as V}from"./scene-BXs8B_Kk.js";import{i as U,_ as G,c as X,S as J,p as Y,a as Z,t as K,s as Q,b as H,d as ee,e as te,f as ae,g as oe}from"./index-DPovJIlT.js";import{s as re,o as se}from"./external-links-CJk2OPKW.js";import"./three-D_1Qt16u.js";const ne="#b0e9d6",ie="#dbe7e3",L=128,le=10,ce="M102 24 86 40H36a14 14 0 0 0 0 28h40a14 14 0 0 1 0 28H22",de=[[102,24],[36,40],[22,96]],ue=10;let O;function he(e,l,t,s,i=ne){O??=new Path2D(ce),e.save(),e.translate(l,t),e.scale(s/L,s/L),e.strokeStyle=e.fillStyle=i,e.lineWidth=le,e.lineCap=e.lineJoin="round",e.stroke(O);for(const[p,r]of de)e.beginPath(),e.arc(p,r,ue,0,Math.PI*2),e.fill();e.restore()}const pe="Cosmic Wobbly Disco Sneaky Bouncy Galactic Crispy Dizzy Fuzzy Noodle Groovy Sleepy Spicy Jolly Loopy Squishy Turbo Giggly Velvet Soggy Zippy Fluffy Moonwalking Wiggly Fizzy Snazzy Goofy Jazzy Tiny Chunky Dapper Wacky".split(" "),ye="Wombat Pickle Pancake Badger Potato Narwhal Noodle Goblin Otter Turnip Hamster Comet Dumpling Goose Biscuit Llama Muffin Squid Raccoon Toaster Waffle Penguin Yeti Pudding Walrus Taco Jellybean Platypus Sloth Cactus Donut Mongoose".split(" ");function fe(e,l=()=>crypto.getRandomValues(new Uint32Array(1))[0]/2**32){const t=pe.flatMap(s=>ye.map(i=>`${s} ${i}`));for(let s=t.length-1;s>0;s--){const i=Math.floor(l()*(s+1));[t[s],t[i]]=[t[i],t[s]]}return Array.from({length:e},(s,i)=>{const p=Math.floor(i/t.length);return`Project ${"Mega".repeat(p)}${t[i%t.length]}`})}function me(e){const l=fe(e.lanes.length),t=new Map(e.nodes.map((r,a)=>[r.session.id,`session-${a}`])),s=new Map(e.lanes.flatMap((r,a)=>r.nodes.map(o=>[o.session.id,`project-${a}`]))),i=e.nodes.map(r=>{const a=r.session,o={id:t.get(a.id),title:"Session",projectID:s.get(a.id),directory:"",created:a.created,updated:a.created,activity:a.activity&&{firstMessageAt:a.activity.firstMessageAt,lastMessageAt:a.activity.lastMessageAt,userMessages:a.activity.userMessages,untimedUserMessages:a.activity.untimedUserMessages},archived:!1,model:"",provider:"",agent:"",cost:null,source:a.source==="continue"?"continue":a.source==="opencode"||!a.source?"opencode":"unknown",tokens:a.tokens};return a.parentID&&t.has(a.parentID)&&(o.parentID=t.get(a.parentID)),a.forkID&&t.has(a.forkID)&&(o.forkID=t.get(a.forkID)),{session:o,position:[...r.position],startPosition:[...r.startPosition],color:r.color,radius:r.radius}}),p=new Map(i.map(r=>[r.session.id,r]));return{start:e.start,end:e.end,timeFrame:e.timeFrame&&{...e.timeFrame},nodes:i,edges:e.edges.map(r=>({from:t.get(r.from),to:t.get(r.to),kind:r.kind})),lanes:e.lanes.map((r,a)=>({key:`project-${a}`,label:l[a],color:r.color,kind:"directory",y:r.y,z:r.z,nodes:r.nodes.map(o=>p.get(t.get(o.session.id)))}))}}const $={mp4:{label:"MP4",description:"MP4 video",mime:"video/mp4",filename:"sessiongraph-playback.mp4"}},I=`My coding sessions, visualized with SessionGraph.
3
- https://github.com/arvindell/sessiongraph`,be=`https://x.com/intent/tweet?text=${encodeURIComponent(I)}`,z=e=>e instanceof Error&&e.name==="AbortError";async function ve(e,l,t){const{label:s,description:i,mime:p,filename:r}=$[t];try{if(U()){const[{save:a},{writeFile:o}]=await Promise.all([G(()=>import("./index-DhlS3ZId.js"),__vite__mapDeps([0,1,2])),G(()=>import("./index-JjTdnq9-.js"),__vite__mapDeps([3,1,2]))]),c=await a({title:`Save SessionGraph ${s}`,defaultPath:r,filters:[{name:i,extensions:[t]}]});if(!c)return"cancelled";await o(c,new Uint8Array(await e.arrayBuffer()))}else{const a=window.showSaveFilePicker;if(a){const c=await(await a.call(window,{suggestedName:r,types:[{description:i,accept:{[p]:[`.${t}`]}}]})).createWritable();try{await c.write(e),await c.close()}catch(d){throw await c.abort().catch(()=>{}),d}}else{const o=document.createElement("a");return o.href=l,o.download=r,document.body.append(o),o.click(),o.remove(),"downloaded"}}return"saved"}catch(a){if(z(a))return"cancelled";throw a}}const S=960,T=600,we=e=>Intl.NumberFormat("en",{notation:"compact",maximumFractionDigits:1}).format(e);function ge(e,l,t,s,i,p){const o=T-122,c=Math.max(1,...s);e.save(),he(e,24,14,28),e.fillStyle=ie,e.font='600 14px "Geist Variable", sans-serif',e.textAlign="left",e.textBaseline="middle",e.fillText("SessionGraph",58,28),e.restore();for(let h=0;h<s.length;h++){const f=Math.max(2,s[h]/c*22);e.fillStyle=h/s.length<=t?"#91bfae":"#253d39",e.fillRect(260+h/s.length*440,o-f,440/s.length-2,f)}e.fillStyle="#d6f4e8",e.fillRect(260+440*t,o-27,1,31);const d=l.start+(l.end-l.start)*t,k=i.at(d,t===1).tokens;e.textAlign="center",e.fillStyle="#a0baae",e.font='12px "IBM Plex Mono", monospace',e.fillText(oe(d,l.end-l.start),S/2,o+23),e.fillStyle="#e7f5ee",e.font='36px "Geist Variable", sans-serif',e.fillText(p(d,t===1).toLocaleString("en"),S/2-105,o+66),e.fillText(i.recorded?we(k):"—",S/2+105,o+66),e.font='12px "Geist Variable", sans-serif',e.fillStyle="#92b0a3",e.fillText("Sessions",S/2-105,o+87),e.fillText("Burnt tokens",S/2+105,o+87),e.textAlign="left"}async function Se(e,l,t,s){t.throwIfAborted();const{label:i,mime:p}=$.mp4,r=Y(e.nodes.map(y=>y.session)),a=Z(e.nodes.map(y=>y.session)),o=K(e.nodes.map(y=>Q(y.session)),e.start,e.end),c=document.createElement("div");c.className="share-render-host",c.setAttribute("aria-hidden","true"),c.style.cssText=`position:fixed;left:-12000px;top:0;width:${S}px;height:${T}px;pointer-events:none;visibility:hidden`,document.body.append(c);const d=document.createElement("canvas");d.width=S,d.height=T;const k=d.getContext("2d",{willReadFrequently:!0});let h,f;try{if(!k)throw new Error("Canvas export is unavailable.");h=new V(c,{onSelect(){},onHover(){},onPlaybackInterrupt(){},onEvent(){},onEventHover(){}},{manual:!0}),h.applyPreferences({...l,quality:"balanced",motion:"on",labels:!0,focusDimming:!1,trails:l.trails==="selected"?"all":l.trails}),h.setGraph(e,!0),h.prepareCapture(),await document.fonts.ready,t.throwIfAborted(),f=new Worker(new URL("/assets/mp4-worker-Dc_1QUwS.js",import.meta.url),{type:"module"});const y=(m,C=[])=>new Promise((A,b)=>{t.throwIfAborted();const v=()=>{clearTimeout(D),t.removeEventListener("abort",w),f.onmessage=null,f.onerror=null},w=()=>{v(),b(t.reason)},D=setTimeout(()=>{v(),b(new Error(`${i} encoding timed out. Please try again.`))},6e4);t.addEventListener("abort",w,{once:!0}),f.onmessage=M=>{v(),M.data.error?b(new Error(M.data.error)):A(M.data)},f.onerror=()=>{v(),b(new Error(`Could not start the ${i} encoder.`))},f.postMessage(m,C)});await y({init:!0,width:S,height:T});for(let m=0;m<H;m++){t.throwIfAborted();const C=ee(m);h.captureFrame(C,1/te,k,ae(m)),ge(k,e,C,o,r,a);const A=k.getImageData(0,0,S,T).data.buffer;await y({rgba:A,width:S,height:T},[A]),s((m+1)/H)}const _=await y({finish:!0});return new Blob([_.bytes],{type:p})}finally{f?.terminate(),h?.dispose(),c.remove()}}function De(e,l){const t=document.createElement("dialog");t.className="share-dialog",t.setAttribute("aria-labelledby","share-title"),t.innerHTML=`<p>Create a private MP4 video. Project and session names are hidden, and nothing is uploaded.</p>
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-GTrhxXlP.js","assets/index-CIhs02tq.js","assets/index-cVgPCrFV.css","assets/index-BS2Voifb.js"])))=>i.map(i=>d[i]);
2
+ import{TimelineScene as V}from"./scene-KCDTPCOD.js";import{i as U,_ as G,c as X,S as J,p as Y,a as Z,t as K,s as Q,b as H,d as ee,e as te,f as ae,g as oe}from"./index-CIhs02tq.js";import{s as re,o as se}from"./external-links-D0O8IeG0.js";import"./three-D_1Qt16u.js";const ne="#b0e9d6",ie="#dbe7e3",L=128,le=10,ce="M102 24 86 40H36a14 14 0 0 0 0 28h40a14 14 0 0 1 0 28H22",de=[[102,24],[36,40],[22,96]],ue=10;let O;function he(e,l,t,s,i=ne){O??=new Path2D(ce),e.save(),e.translate(l,t),e.scale(s/L,s/L),e.strokeStyle=e.fillStyle=i,e.lineWidth=le,e.lineCap=e.lineJoin="round",e.stroke(O);for(const[p,r]of de)e.beginPath(),e.arc(p,r,ue,0,Math.PI*2),e.fill();e.restore()}const pe="Cosmic Wobbly Disco Sneaky Bouncy Galactic Crispy Dizzy Fuzzy Noodle Groovy Sleepy Spicy Jolly Loopy Squishy Turbo Giggly Velvet Soggy Zippy Fluffy Moonwalking Wiggly Fizzy Snazzy Goofy Jazzy Tiny Chunky Dapper Wacky".split(" "),ye="Wombat Pickle Pancake Badger Potato Narwhal Noodle Goblin Otter Turnip Hamster Comet Dumpling Goose Biscuit Llama Muffin Squid Raccoon Toaster Waffle Penguin Yeti Pudding Walrus Taco Jellybean Platypus Sloth Cactus Donut Mongoose".split(" ");function fe(e,l=()=>crypto.getRandomValues(new Uint32Array(1))[0]/2**32){const t=pe.flatMap(s=>ye.map(i=>`${s} ${i}`));for(let s=t.length-1;s>0;s--){const i=Math.floor(l()*(s+1));[t[s],t[i]]=[t[i],t[s]]}return Array.from({length:e},(s,i)=>{const p=Math.floor(i/t.length);return`Project ${"Mega".repeat(p)}${t[i%t.length]}`})}function me(e){const l=fe(e.lanes.length),t=new Map(e.nodes.map((r,a)=>[r.session.id,`session-${a}`])),s=new Map(e.lanes.flatMap((r,a)=>r.nodes.map(o=>[o.session.id,`project-${a}`]))),i=e.nodes.map(r=>{const a=r.session,o={id:t.get(a.id),title:"Session",projectID:s.get(a.id),directory:"",created:a.created,updated:a.created,activity:a.activity&&{firstMessageAt:a.activity.firstMessageAt,lastMessageAt:a.activity.lastMessageAt,userMessages:a.activity.userMessages,untimedUserMessages:a.activity.untimedUserMessages},archived:!1,model:"",provider:"",agent:"",cost:null,source:a.source==="continue"?"continue":a.source==="opencode"||!a.source?"opencode":"unknown",tokens:a.tokens};return a.parentID&&t.has(a.parentID)&&(o.parentID=t.get(a.parentID)),a.forkID&&t.has(a.forkID)&&(o.forkID=t.get(a.forkID)),{session:o,position:[...r.position],startPosition:[...r.startPosition],color:r.color,radius:r.radius}}),p=new Map(i.map(r=>[r.session.id,r]));return{start:e.start,end:e.end,timeFrame:e.timeFrame&&{...e.timeFrame},nodes:i,edges:e.edges.map(r=>({from:t.get(r.from),to:t.get(r.to),kind:r.kind})),lanes:e.lanes.map((r,a)=>({key:`project-${a}`,label:l[a],color:r.color,kind:"directory",y:r.y,z:r.z,nodes:r.nodes.map(o=>p.get(t.get(o.session.id)))}))}}const $={mp4:{label:"MP4",description:"MP4 video",mime:"video/mp4",filename:"sessiongraph-playback.mp4"}},I=`My coding sessions, visualized with SessionGraph.
3
+ https://github.com/arvindell/sessiongraph`,be=`https://x.com/intent/tweet?text=${encodeURIComponent(I)}`,z=e=>e instanceof Error&&e.name==="AbortError";async function ve(e,l,t){const{label:s,description:i,mime:p,filename:r}=$[t];try{if(U()){const[{save:a},{writeFile:o}]=await Promise.all([G(()=>import("./index-GTrhxXlP.js"),__vite__mapDeps([0,1,2])),G(()=>import("./index-BS2Voifb.js"),__vite__mapDeps([3,1,2]))]),c=await a({title:`Save SessionGraph ${s}`,defaultPath:r,filters:[{name:i,extensions:[t]}]});if(!c)return"cancelled";await o(c,new Uint8Array(await e.arrayBuffer()))}else{const a=window.showSaveFilePicker;if(a){const c=await(await a.call(window,{suggestedName:r,types:[{description:i,accept:{[p]:[`.${t}`]}}]})).createWritable();try{await c.write(e),await c.close()}catch(d){throw await c.abort().catch(()=>{}),d}}else{const o=document.createElement("a");return o.href=l,o.download=r,document.body.append(o),o.click(),o.remove(),"downloaded"}}return"saved"}catch(a){if(z(a))return"cancelled";throw a}}const S=960,T=600,we=e=>Intl.NumberFormat("en",{notation:"compact",maximumFractionDigits:1}).format(e);function ge(e,l,t,s,i,p){const o=T-122,c=Math.max(1,...s);e.save(),he(e,24,14,28),e.fillStyle=ie,e.font='600 14px "Geist Variable", sans-serif',e.textAlign="left",e.textBaseline="middle",e.fillText("SessionGraph",58,28),e.restore();for(let h=0;h<s.length;h++){const f=Math.max(2,s[h]/c*22);e.fillStyle=h/s.length<=t?"#91bfae":"#253d39",e.fillRect(260+h/s.length*440,o-f,440/s.length-2,f)}e.fillStyle="#d6f4e8",e.fillRect(260+440*t,o-27,1,31);const d=l.start+(l.end-l.start)*t,k=i.at(d,t===1).tokens;e.textAlign="center",e.fillStyle="#a0baae",e.font='12px "IBM Plex Mono", monospace',e.fillText(oe(d,l.end-l.start),S/2,o+23),e.fillStyle="#e7f5ee",e.font='36px "Geist Variable", sans-serif',e.fillText(p(d,t===1).toLocaleString("en"),S/2-105,o+66),e.fillText(i.recorded?we(k):"—",S/2+105,o+66),e.font='12px "Geist Variable", sans-serif',e.fillStyle="#92b0a3",e.fillText("Sessions",S/2-105,o+87),e.fillText("Burnt tokens",S/2+105,o+87),e.textAlign="left"}async function Se(e,l,t,s){t.throwIfAborted();const{label:i,mime:p}=$.mp4,r=Y(e.nodes.map(y=>y.session)),a=Z(e.nodes.map(y=>y.session)),o=K(e.nodes.map(y=>Q(y.session)),e.start,e.end),c=document.createElement("div");c.className="share-render-host",c.setAttribute("aria-hidden","true"),c.style.cssText=`position:fixed;left:-12000px;top:0;width:${S}px;height:${T}px;pointer-events:none;visibility:hidden`,document.body.append(c);const d=document.createElement("canvas");d.width=S,d.height=T;const k=d.getContext("2d",{willReadFrequently:!0});let h,f;try{if(!k)throw new Error("Canvas export is unavailable.");h=new V(c,{onSelect(){},onHover(){},onPlaybackInterrupt(){},onEvent(){},onEventHover(){}},{manual:!0}),h.applyPreferences({...l,quality:"balanced",motion:"on",labels:!0,focusDimming:!1,trails:l.trails==="selected"?"all":l.trails}),h.setGraph(e,!0),h.prepareCapture(),await document.fonts.ready,t.throwIfAborted(),f=new Worker(new URL("/assets/mp4-worker-Dc_1QUwS.js",import.meta.url),{type:"module"});const y=(m,C=[])=>new Promise((A,b)=>{t.throwIfAborted();const v=()=>{clearTimeout(D),t.removeEventListener("abort",w),f.onmessage=null,f.onerror=null},w=()=>{v(),b(t.reason)},D=setTimeout(()=>{v(),b(new Error(`${i} encoding timed out. Please try again.`))},6e4);t.addEventListener("abort",w,{once:!0}),f.onmessage=M=>{v(),M.data.error?b(new Error(M.data.error)):A(M.data)},f.onerror=()=>{v(),b(new Error(`Could not start the ${i} encoder.`))},f.postMessage(m,C)});await y({init:!0,width:S,height:T});for(let m=0;m<H;m++){t.throwIfAborted();const C=ee(m);h.captureFrame(C,1/te,k,ae(m)),ge(k,e,C,o,r,a);const A=k.getImageData(0,0,S,T).data.buffer;await y({rgba:A,width:S,height:T},[A]),s((m+1)/H)}const _=await y({finish:!0});return new Blob([_.bytes],{type:p})}finally{f?.terminate(),h?.dispose(),c.remove()}}function De(e,l){const t=document.createElement("dialog");t.className="share-dialog",t.setAttribute("aria-labelledby","share-title"),t.innerHTML=`<p>Create a private MP4 video. Project and session names are hidden, and nothing is uploaded.</p>
4
4
  <div class="share-preview"><video aria-label="SessionGraph playback with hidden project and session names" muted loop playsinline controls hidden></video><div class="share-progress"><progress max="100" value="0" aria-label="Creating video"></progress><span role="status">Creating video… 0%</span></div></div>
5
5
  <p class="share-notice" role="status" hidden></p>
6
6
  <div class="share-actions"><button class="text-button share-close">Cancel</button><button class="secondary-button share-retry" hidden>Try again</button><a class="secondary-button share-x" target="_blank" rel="noopener noreferrer" hidden>Share in X</a><button class="secondary-button share-system" aria-label="Open share tray" aria-controls="playback-share-tray" aria-expanded="false" hidden>Share…</button><button class="primary-button share-save" hidden>Save MP4</button></div>
@@ -0,0 +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]+=`
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"})}}})();
@@ -12,7 +12,7 @@
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-DPovJIlT.js"></script>
15
+ <script type="module" crossorigin src="/assets/index-CIhs02tq.js"></script>
16
16
  <link rel="stylesheet" crossorigin href="/assets/index-cVgPCrFV.css">
17
17
  </head>
18
18
  <body>
@@ -18,15 +18,15 @@
18
18
  </data>
19
19
  <key>Resources/resources/server.mjs</key>
20
20
  <data>
21
- dLCavUnSBxWw1x4iyd+CmKPs79g=
21
+ MgN1AEw00F6uro8twjzD0AbZsfo=
22
22
  </data>
23
23
  <key>Resources/resources/web/apple-touch-icon.png</key>
24
24
  <data>
25
25
  7IrT+H6J4h1FxtVwSpZiqT0xzjI=
26
26
  </data>
27
- <key>Resources/resources/web/assets/external-links-CJk2OPKW.js</key>
27
+ <key>Resources/resources/web/assets/external-links-D0O8IeG0.js</key>
28
28
  <data>
29
- jEyWg9pJvGeU5RW5zQ26AUgBl2M=
29
+ qoq5g+btTH8wb4LU5G+LyQjxcr8=
30
30
  </data>
31
31
  <key>Resources/resources/web/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2</key>
32
32
  <data>
@@ -88,21 +88,21 @@
88
88
  <data>
89
89
  LdRX2sBB3T5WDAsZLCwBlsMYXPw=
90
90
  </data>
91
- <key>Resources/resources/web/assets/index-DOYyn-b_.js</key>
91
+ <key>Resources/resources/web/assets/index-BS2Voifb.js</key>
92
92
  <data>
93
- MwarVN51C0SSIE4i8iTvly4XIpc=
93
+ U9c9owi9e1cBBM801BBc80Usxt4=
94
94
  </data>
95
- <key>Resources/resources/web/assets/index-DPovJIlT.js</key>
95
+ <key>Resources/resources/web/assets/index-CIhs02tq.js</key>
96
96
  <data>
97
- HW9l9wX3GViTx2wIAfJniSh2CL8=
97
+ PxECxIMWc8PAb7biGosjGJEyIRY=
98
98
  </data>
99
- <key>Resources/resources/web/assets/index-DhlS3ZId.js</key>
99
+ <key>Resources/resources/web/assets/index-GTrhxXlP.js</key>
100
100
  <data>
101
- ZzR7CqspdYbmuLT5MUXlv5ii3lI=
101
+ WbASvcdvbtDo8VZztgCOvnSTKig=
102
102
  </data>
103
- <key>Resources/resources/web/assets/index-JjTdnq9-.js</key>
103
+ <key>Resources/resources/web/assets/index-Vq4WYmzW.js</key>
104
104
  <data>
105
- ydgcgJxsJ+sSiKCt95NunhCeysg=
105
+ 5ON5koaa0mgQDMsCSXjOQTeQ1+Q=
106
106
  </data>
107
107
  <key>Resources/resources/web/assets/index-cVgPCrFV.css</key>
108
108
  <data>
@@ -112,29 +112,29 @@
112
112
  <data>
113
113
  2/71pbsZ0DyFW7H+mzqWhzexMXI=
114
114
  </data>
115
- <key>Resources/resources/web/assets/publishing-CkVIjq_f.js</key>
116
- <data>
117
- I34GpqHzBf5zAGlP30htpkWNoFw=
118
- </data>
119
115
  <key>Resources/resources/web/assets/publishing-VJhUmdPH.css</key>
120
116
  <data>
121
117
  6fWzMO88QnTllqV2/V6JoSphpq8=
122
118
  </data>
123
- <key>Resources/resources/web/assets/scene-BXs8B_Kk.js</key>
119
+ <key>Resources/resources/web/assets/publishing-ofssf6d6.js</key>
120
+ <data>
121
+ K0riTJCU1FzCyGoGUDmTon961Js=
122
+ </data>
123
+ <key>Resources/resources/web/assets/scene-KCDTPCOD.js</key>
124
124
  <data>
125
- LMNX9Bs4c4b5hueocpCyUuL0gss=
125
+ 3hZJsK37DX0PXuhu35fdRSKkkOA=
126
126
  </data>
127
- <key>Resources/resources/web/assets/share-jfOenMTA.js</key>
127
+ <key>Resources/resources/web/assets/share-DKeJCFAo.js</key>
128
128
  <data>
129
- HFyzbGW7mdYpZOfCCnoBluoC1Sc=
129
+ zN+63CcQWEhrDXuDzGSR4bBUHtE=
130
130
  </data>
131
131
  <key>Resources/resources/web/assets/three-D_1Qt16u.js</key>
132
132
  <data>
133
133
  +vkqXmunTgaV0KGoBq/AEc36POU=
134
134
  </data>
135
- <key>Resources/resources/web/assets/worker-DwqxiDWY.js</key>
135
+ <key>Resources/resources/web/assets/worker-C10U_apJ.js</key>
136
136
  <data>
137
- mImryodKVT09sI0yWPkhy8RUFX4=
137
+ ldktmP7HUVpkPsH5F5Z1eTwGXsE=
138
138
  </data>
139
139
  <key>Resources/resources/web/brand/icon.svg</key>
140
140
  <data>
@@ -166,7 +166,7 @@
166
166
  </data>
167
167
  <key>Resources/resources/web/index.html</key>
168
168
  <data>
169
- 7GYxUsrJlijddy42QVLNPq7clAM=
169
+ v14oGu0PtIuPPMLXWYIiY2rtBlE=
170
170
  </data>
171
171
  <key>Resources/resources/web/sources/LICENSE-APACHE-2.0.txt</key>
172
172
  <data>
@@ -432,7 +432,7 @@
432
432
  <dict>
433
433
  <key>hash2</key>
434
434
  <data>
435
- mu2pgz4N3e7kk5aWigjjwM5VT7AYV7G5Y0sW4tnsmmk=
435
+ 52g3LHzvZPF3ovrGWt5g3hf39KxffiO5T8acadXiEPE=
436
436
  </data>
437
437
  </dict>
438
438
  <key>Resources/resources/web/apple-touch-icon.png</key>
@@ -442,11 +442,11 @@
442
442
  r0avunkAKv+j4kuQJ3Lk5pFwJ+ds28pxrEPQMyqVahc=
443
443
  </data>
444
444
  </dict>
445
- <key>Resources/resources/web/assets/external-links-CJk2OPKW.js</key>
445
+ <key>Resources/resources/web/assets/external-links-D0O8IeG0.js</key>
446
446
  <dict>
447
447
  <key>hash2</key>
448
448
  <data>
449
- BZZOuW7gccoHENF1x9CK4GBj+Cp7QUtoOpkP7y+c8hA=
449
+ rSd8xSPmILlRtX3INXUvifY7r7BcwHlpIvjXFl1Dn1k=
450
450
  </data>
451
451
  </dict>
452
452
  <key>Resources/resources/web/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2</key>
@@ -554,32 +554,32 @@
554
554
  vO1WHZkeP4HBUMCOcff6hJ/L/1I1YPYFkkXy7c4ZtgA=
555
555
  </data>
556
556
  </dict>
557
- <key>Resources/resources/web/assets/index-DOYyn-b_.js</key>
557
+ <key>Resources/resources/web/assets/index-BS2Voifb.js</key>
558
558
  <dict>
559
559
  <key>hash2</key>
560
560
  <data>
561
- aQO4VHltQltjC4yLWcOqrRIbRLI99lhiNJVOMhaWXrM=
561
+ PDwT4nYjawUSNl2EOADb2EV4grwgOl5LL6lyR+CpJUM=
562
562
  </data>
563
563
  </dict>
564
- <key>Resources/resources/web/assets/index-DPovJIlT.js</key>
564
+ <key>Resources/resources/web/assets/index-CIhs02tq.js</key>
565
565
  <dict>
566
566
  <key>hash2</key>
567
567
  <data>
568
- /kgfUhSr34iJXrowRhwoNFxUTXQMVsTKvxZNwaxLTqo=
568
+ GTar+BQRbPYvnjChPPqAc+hDe6kSOGAmHCCR1s1cmV8=
569
569
  </data>
570
570
  </dict>
571
- <key>Resources/resources/web/assets/index-DhlS3ZId.js</key>
571
+ <key>Resources/resources/web/assets/index-GTrhxXlP.js</key>
572
572
  <dict>
573
573
  <key>hash2</key>
574
574
  <data>
575
- 0bJQFyqo5UijLKyxIN31zAHVAcjzbqirjawAahYnv7s=
575
+ ErOpyjb47NmjXjakKx/+M8sQx4B3wOQu33Un1v2pOyM=
576
576
  </data>
577
577
  </dict>
578
- <key>Resources/resources/web/assets/index-JjTdnq9-.js</key>
578
+ <key>Resources/resources/web/assets/index-Vq4WYmzW.js</key>
579
579
  <dict>
580
580
  <key>hash2</key>
581
581
  <data>
582
- OeQ8citIU4tSKiNsGQsLITGsHHobkYJYajGEP6ZdMLk=
582
+ uu64IyfOXsSxbWpKOCclBBG7wIAj7rMLvQ308BGfRNI=
583
583
  </data>
584
584
  </dict>
585
585
  <key>Resources/resources/web/assets/index-cVgPCrFV.css</key>
@@ -596,32 +596,32 @@
596
596
  VaH6cQJD5lKhlsXhS1dVQylTIaiWiRK8K2VSicyCuzg=
597
597
  </data>
598
598
  </dict>
599
- <key>Resources/resources/web/assets/publishing-CkVIjq_f.js</key>
599
+ <key>Resources/resources/web/assets/publishing-VJhUmdPH.css</key>
600
600
  <dict>
601
601
  <key>hash2</key>
602
602
  <data>
603
- d3+2a7f5Zc0UqmJPT7SeUCNoeiqsDg/YCnSg7CnFtow=
603
+ qp+02zzJ3eDSRmM1QFKIs/gPNJJ1VudOM7MVpmEOywY=
604
604
  </data>
605
605
  </dict>
606
- <key>Resources/resources/web/assets/publishing-VJhUmdPH.css</key>
606
+ <key>Resources/resources/web/assets/publishing-ofssf6d6.js</key>
607
607
  <dict>
608
608
  <key>hash2</key>
609
609
  <data>
610
- qp+02zzJ3eDSRmM1QFKIs/gPNJJ1VudOM7MVpmEOywY=
610
+ tVY7Y0/v7Dla6cQ37EGGZLyUWhrbSHnaLEsIFN5T39E=
611
611
  </data>
612
612
  </dict>
613
- <key>Resources/resources/web/assets/scene-BXs8B_Kk.js</key>
613
+ <key>Resources/resources/web/assets/scene-KCDTPCOD.js</key>
614
614
  <dict>
615
615
  <key>hash2</key>
616
616
  <data>
617
- wupaNIsZ3ENfR6muy+XKsB8RjtLgCfsXqdibGdV3/yQ=
617
+ SPkzBgF/bgDrLG/J/AYxmbUgvAcdLvyuuCtvksVlBZA=
618
618
  </data>
619
619
  </dict>
620
- <key>Resources/resources/web/assets/share-jfOenMTA.js</key>
620
+ <key>Resources/resources/web/assets/share-DKeJCFAo.js</key>
621
621
  <dict>
622
622
  <key>hash2</key>
623
623
  <data>
624
- YhJZvV3OCey4ixKjg/ZkSqlDO1TEh6ud/IoTv8wcj/4=
624
+ o4nfZne4QFYjrTlJLPTf0ojZ6jK2phzyk1h7qLeONpU=
625
625
  </data>
626
626
  </dict>
627
627
  <key>Resources/resources/web/assets/three-D_1Qt16u.js</key>
@@ -631,11 +631,11 @@
631
631
  jmvag0RMTOx9k51cantgrINZ5EOs/TLx+2WZFlkv3u0=
632
632
  </data>
633
633
  </dict>
634
- <key>Resources/resources/web/assets/worker-DwqxiDWY.js</key>
634
+ <key>Resources/resources/web/assets/worker-C10U_apJ.js</key>
635
635
  <dict>
636
636
  <key>hash2</key>
637
637
  <data>
638
- EOfLd1vncqhtsbvSQsOKlub/6ifr9YRRXzi731FNbJs=
638
+ 7jdvgaFnpFEDygpRzMtaoKzULPDaexTvc1emS8Gz5Q0=
639
639
  </data>
640
640
  </dict>
641
641
  <key>Resources/resources/web/brand/icon.svg</key>
@@ -691,7 +691,7 @@
691
691
  <dict>
692
692
  <key>hash2</key>
693
693
  <data>
694
- UhiED2Ex/SM5AFK/YizjNSk/t9H2tVUQf1aLcAiFTdM=
694
+ DwVuBe7dVmDbe0uH8P92f8j8zp5diihy7RONtfjXioc=
695
695
  </data>
696
696
  </dict>
697
697
  <key>Resources/resources/web/sources/LICENSE-APACHE-2.0.txt</key>
@@ -1,2 +0,0 @@
1
- (function(){"use strict";const Fe="ENTRIES",de="KEYS",le="VALUES";class G{constructor(e,t){const i=e._tree,r=Array.from(i.keys());this.set=e,this._type=t,this._path=r.length>0?[{node:i,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 i=e.get(C(t));return this._path.push({node:i,keys:Array.from(i.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 i=new Map;if(e===void 0)return i;const r=e.length+1,o=r+t,n=new Uint8Array(o*r).fill(t+1);for(let c=0;c<r;++c)n[c]=c;for(let c=1;c<o;++c)n[c*r]=c;return he(s,e,t,i,n,1,r,""),i},he=(s,e,t,i,r,o,n,c)=>{const a=o*n;e:for(const d of s.keys())if(d===""){const u=r[a-1];u<=t&&i.set(c,[s.get(d),u])}else{let u=o;for(let p=0;p<d.length;++p,++u){const l=d[p],h=n*u,g=h-n;let m=r[h];const f=Math.max(0,u-t-1),_=Math.min(n-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,i,r,u,n,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,i]=W(this._tree,e.slice(this._prefix.length));if(t===void 0){const[r,o]=X(i);for(const n of r.keys())if(n!==""&&n.startsWith(o)){const c=new Map;return c.set(n.slice(o.length),r.get(n)),new v(c,e)}}return new v(t,e)}clear(){this._size=void 0,this._tree.clear()}delete(e){return this._size=void 0,ke(this._tree,e)}entries(){return new G(this,Fe)}forEach(e){for(const[t,i]of this)e(t,i,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 i=H(this._tree,e);return i.set("",t(i.get(""))),this}fetch(e,t){if(typeof e!="string")throw new Error("key must be a string");this._size=void 0;const i=H(this._tree,e);let r=i.get("");return r===void 0&&i.set("",r=t()),r}values(){return new G(this,le)}[Symbol.iterator](){return this.entries()}static from(e){const t=new v;for(const[i,r]of e)t.set(i,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 i of s.keys())if(i!==""&&e.startsWith(i))return t.push([s,i]),W(s.get(i),e.slice(i.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 i=0;s&&i<t;){for(const o of s.keys())if(o!==""&&e[i]===o[0]){const n=Math.min(t-i,o.length);let c=1;for(;c<n&&e[i+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(i,i+c),d),s.delete(o),s=d}i+=c;continue e}const r=new Map;return s.set(e.slice(i),r),r}return s},ke=(s,e)=>{const[t,i]=W(s,e);if(t!==void 0){if(t.delete(""),t.size===0)ue(i);else if(t.size===1){const[r,o]=t.entries().next().value;fe(i,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[i,r]=e.entries().next().value;i!==""&&fe(s.slice(0,-1),i,r)}},fe=(s,e,t)=>{if(s.length===0)return;const[i,r]=X(s);i.set(r+e,t),i.delete(r)},X=s=>s[s.length-1],Z="or",me="and",ze="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?ne: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=ie,this.addFields(this._options.fields)}add(e){const{extractField:t,stringifyField:i,tokenize:r,processTerm:o,fields:n,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 n){const p=t(e,u);if(p==null)continue;const l=r(i(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:i=10}=t,r={chunk:[],promise:Promise.resolve()},{chunk:o,promise:n}=e.reduce(({chunk:c,promise:a},d,u)=>(c.push(d),(u+1)%i===0?{chunk:[],promise:a.then(()=>new Promise(p=>setTimeout(p,0))).then(()=>this.addAll(c))}:{chunk:c,promise:a}),r);return n.then(()=>this.addAll(o))}remove(e){const{tokenize:t,processTerm:i,extractField:r,stringifyField:o,fields:n,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 n){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=i(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((i,r)=>{this.removeFieldLength(t,r,this._documentCount,i)}),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:i,batchWait:r}=this._options.autoVacuum;this.conditionalVacuum({batchSize:i,batchWait:r},{minDirtCount:t,minDirtFactor:e})}discardAll(e){const t=this._options.autoVacuum;try{this._options.autoVacuum=!1;for(const i of e)this.discard(i)}finally{this._options.autoVacuum=t}this.maybeAutoVacuum()}replace(e){const{idField:t,extractField:i}=this._options,r=i(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 i=this._enqueuedVacuumConditions;return this._enqueuedVacuumConditions=ie,this.performVacuuming(e,i)}),this._enqueuedVacuum)):this.vacuumConditionsMet(t)===!1?Promise.resolve():(this._currentVacuum=this.performVacuuming(e),this._currentVacuum)}async performVacuuming(e,t){const i=this._dirtCount;if(this.vacuumConditionsMet(t)){const r=e.batchSize||se.batchSize,o=e.batchWait||se.batchWait;let n=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),n%r===0&&await new Promise(d=>setTimeout(d,o)),n+=1}this._dirtCount-=i}await null,this._currentVacuum=this._enqueuedVacuum,this._enqueuedVacuum=null}vacuumConditionsMet(e){if(e==null)return!0;let{minDirtCount:t,minDirtFactor:i}=e;return t=t||ne.minDirtCount,i=i||ne.minDirtFactor,this.dirtCount>=t&&this.dirtFactor>=i}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:i}=this._options,r={...i,...t},o=this.executeQuery(e,t),n=[];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))&&n.push(l)}return e===E.wildcard&&r.boostDocument==null||n.sort(_e),n}autoSuggest(e,t={}){t={...this._options.autoSuggestOptions,...t};const i=new Map;for(const{score:o,terms:n}of this.search(e,t)){const c=n.join(" "),a=i.get(c);a!=null?(a.score+=o,a.count+=1):i.set(c,{score:o,terms:n,count:1})}const r=[];for(const[o,{score:n,terms:c,count:a}]of i)r.push({suggestion:o,terms:c,score:n/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:i,documentIds:r,fieldLength:o,storedFields:n,serializationVersion:c}=e,a=this.instantiateMiniSearch(e,t);a._documentIds=P(r),a._fieldLength=P(o),a._storedFields=P(n);for(const[d,u]of a._documentIds)a._idToShortId.set(u,d);for(const[d,u]of i){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:i,documentIds:r,fieldLength:o,storedFields:n,serializationVersion:c}=e,a=this.instantiateMiniSearch(e,t);a._documentIds=await U(r),a._fieldLength=await U(o),a._storedFields=await U(n);for(const[u,p]of a._documentIds)a._idToShortId.set(p,u);let d=0;for(const[u,p]of i){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:i,nextId:r,fieldIds:o,averageFieldLength:n,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=i,d._nextId=r,d._idToShortId=new Map,d._fieldIds=o,d._avgFieldLength=n,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:i,processTerm:r,searchOptions:o}=this._options,n={tokenize:i,processTerm:r,...o,...t},{tokenize:c,processTerm:a}=n,p=c(e).flatMap(l=>a(l)).filter(l=>!!l).map(Le(n)).map(l=>this.executeQuerySpec(l,n));return this.combineResults(p,n.combineWith)}executeQuerySpec(e,t){const i={...this._options.searchOptions,...t},r=(i.fields||this._options.fields).reduce((m,f)=>({...m,[f]:ee(i.boost,f)||1}),{}),{boostDocument:o,weights:n,maxFuzzy:c,bm25:a}=i,{fuzzy:d,prefix:u}={...pe.weights,...n},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,i={...this._options.searchOptions,...e};for(const[r,o]of this._documentIds){const n=i.boostDocument?i.boostDocument(o,"",this._storedFields.get(r)):1;t.set(r,{score:n,terms:[],match:{}})}return t}combineResults(e,t=Z){if(e.length===0)return new Map;const i=t.toLowerCase(),r=Me[i];if(!r)throw new Error(`Invalid combination operator: ${t}`);return e.reduce(r)||new Map}toJSON(){const e=[];for(const[t,i]of this._index){const r={};for(const[o,n]of i)r[o]=Object.fromEntries(n);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,i,r,o,n,c,a,d=new Map){if(o==null)return d;for(const u of Object.keys(n)){const p=n[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=i*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,i){const r=this._index.fetch(i,we);let o=r.get(e);if(o==null)o=new Map,o.set(t,1),r.set(e,o);else{const n=o.get(t);o.set(t,(n||0)+1)}}removeTerm(e,t,i){if(!this._index.has(i)){this.warnDocumentChanged(t,e,i);return}const r=this._index.fetch(i,we),o=r.get(e);o==null||o.get(t)==null?this.warnDocumentChanged(t,e,i):o.get(t)<=1?o.size<=1?r.delete(e):o.delete(t):o.set(t,o.get(t)-1),this._index.get(i).size===0&&this._index.delete(i)}warnDocumentChanged(e,t,i){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 "${i}" 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,i,r){let o=this._fieldLength.get(e);o==null&&this._fieldLength.set(e,o=[]),o[t]=r;const c=(this._avgFieldLength[t]||0)*i+r;this._avgFieldLength[t]=c/(i+1)}removeFieldLength(e,t,i,r){if(i===1){this._avgFieldLength[t]=0;return}const o=this._avgFieldLength[t]*i-r;this._avgFieldLength[t]=o/(i-1)}saveStoredFields(e,t){const{storeFields:i,extractField:r}=this._options;if(i==null||i.length===0)return;let o=this._storedFields.get(e);o==null&&this._storedFields.set(e,o={});for(const n of i){const c=r(t,n);c!==void 0&&(o[n]=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 i=s.get(t);if(i==null)s.set(t,e.get(t));else{const{score:r,terms:o,match:n}=e.get(t);i.score=i.score+r,i.match=Object.assign(i.match,n),ge(i.terms,o)}}return s},[me]:(s,e)=>{const t=new Map;for(const i of e.keys()){const r=s.get(i);if(r==null)continue;const{score:o,terms:n,match:c}=e.get(i);ge(r.terms,n),t.set(i,{score:r.score+o,terms:r.terms,match:Object.assign(r.match,c)})}return t},[ze]:(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,i,r,o)=>{const{k:n,b:c,d:a}=o;return Math.log(1+(t-e+.5)/(e+.5))*(a+s*(n+1)/(s+n*(1-c+c*i/r)))},Le=s=>(e,t,i)=>{const r=typeof s.fuzzy=="function"?s.fuzzy(e,t,i):s.fuzzy||!1,o=typeof s.prefix=="function"?s.prefix(e,t,i):s.prefix===!0,n=typeof s.boostTerm=="function"?s.boostTerm(e,t,i):1;return{term:e,fuzzy:r,prefix:o,termBoost:n}},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},ie={minDirtFactor:.1,minDirtCount:20},ne={...se,...ie},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 i of Object.keys(s))e.set(parseInt(i,10),s[i]),++t%1e3===0&&await ye(0);return e},ye=s=>new Promise(e=>setTimeout(e,s)),Ae=/[\n\r\p{Z}\p{P}]+/u,k=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 i of s.fragments){if(!i||!["You","Assistant","Tool","File"].includes(i.kind)||typeof i.text!="string"||i.text.length>2e3||!Number.isFinite(i.time))return!1;t+=i.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 i of s.slice(0,300).match(/(?:[^\s"]+|"[^"]*")+/g)||[]){const r=/^(source|project|dir|model|is|after|before|in):(.+)$/i.exec(i);if(r){const n=r[1].toLowerCase(),c=x(r[2].replace(/^"|"$/g,""));if(n==="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 n==="is"&&!["fork","child","root","archived"].includes(c)?e.error="Use is:fork, is:child, is:root, or is:archived.":["after","before"].includes(n)&&(!/^\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([n,c]);continue}const o=i.replace(/^"|"$/g,"");i.startsWith('"')&&i.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 i=x(s),r=e.reduce((n,c)=>{const a=i.indexOf(c);return a<0?n:Math.min(n,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 i=new Set(e.map(o=>o.id));for(const[o,n]of this.entries)i.has(o)||(this.index.remove(n.doc),this.entries.delete(o));const r=new Map(t.map(o=>[o.id,o.name]));for(const o of e){const n=this.entries.get(o.id),c=n&&L(n.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?n.doc.body:"",files:c?n.doc.files:"",tools:c?n.doc.tools:""};if(c&&Object.keys(a).every(d=>n.doc[d]===a[d])){n.session=o;continue}this.entries.set(o.id,{session:o,doc:a,fragments:c?n.fragments:[]}),n&&this.index.remove(n.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 i=this.entries.get(e);if(!i)return;i.fragments.push(...t);const r={...i.doc};for(const o of t){const n=o.kind==="File"?"files":o.kind==="Tool"?"tools":"body";r[n]+=`
2
- ${o.text}`}this.index.remove(i.doc),this.index.add(r),i.doc=r,this.cache.clear()}search(e,t=!1,i=80){const r=`${e}\0${t}\0${i}`,o=this.cache.get(r);if(o)return o;const n=je(e);if(n.error)return{hits:[],total:0,error:n.error};const c=l=>{const{session:h,doc:g}=l;if(t&&!this.scope.has(h.id))return!1;for(const[m,f]of n.filters)if(m==="source"&&![h.source||"opencode",...(h.linkedSessionIDs||[]).map(_=>_.split(":")[0])].some(_=>x(_).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(n.phrases.length){const m=n.fields||["title","body","files","tools","project","directory","model"];if(!n.phrases.every(f=>m.some(_=>re(g[_]).includes(f))))return!1}return!0},d=(n.terms.length?this.index.search(n.text,{fields:n.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=n.text?g.includes(n.text)&&(!n.fields||n.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,i))).map(({match:l,entry:h,tier:g})=>{const m=l.terms.length?l.terms:n.terms,f=h.fragments.filter(b=>!n.fields||n.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":n.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,i){const r=new Map(t.map(c=>[c.id,c]));let o,n=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))&&n+d.characters<=k&&(n+=d.characters,i(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 z=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=z.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>=k||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 i=y.get(t);if(s(i)&&i.pages<2)return i}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>=k){$();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 i=new URLSearchParams({updated:String(s.session.updated)});s.cursor&&i.set("cursor",s.cursor);const r=await fetch(`/api/sessiongraph/session/${encodeURIComponent(s.session.id)}/content?${i}`,{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 n=Math.min(J,Math.floor(k/Math.max(1,y.size)));let c=Math.min(n-s.characters,k-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}z.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>=n||s.pages>=8),s.cursor=o.nextCursor||void 0,Se(),A?.sourceID&&await q.save({id:s.session.id,version:L(s.session),fragments:z.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(n=>n.abort());const i=A?.sourceID===s.sourceID&&!e,r=i?new Map(y):new Map;i||(z.setData([],[]),D.clear()),A=s,y.clear(),I=0;for(const n of[...s.sessions].sort((c,a)=>a.updated-c.updated)){const c=r.get(n.id),a=c&&L(c.session)===L(n),d=a?{...c,session:n,inflight:!1}:{session:n,pages:0,characters:0,partial:!1,complete:!1,capped:!1,failed:0,inflight:!1};a||D.delete(n.id),y.set(n.id,d),I+=d.characters}for(const n of D)y.has(n)||D.delete(n);if(z.setData(s.sessions,s.projects),N(),$(),e&&await q.clear(),t!==M||(s.sourceID&&await q.restore(s.sourceID,s.sessions,n=>{if(t!==M)return;const c=y.get(n.id);!c||c.pages||I+n.characters>k||(z.addContent(n.id,n.fragments),Object.assign(c,{pages:n.pages,characters:n.characters,partial:n.partial,complete:n.complete,capped:n.capped,cursor:n.cursor}),I+=n.characters,D.add(n.id),Se())}),t!==M))return;const o=Math.min(J,Math.floor(k/Math.max(1,y.size)));for(const n of y.values())!n.complete&&n.characters>=o&&(n.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"?(z.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"})}}})();