fleetlens 1.0.13 → 1.0.14

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 (69) hide show
  1. package/app/apps/web/.next/BUILD_ID +1 -1
  2. package/app/apps/web/.next/build-manifest.json +3 -3
  3. package/app/apps/web/.next/prerender-manifest.json +3 -3
  4. package/app/apps/web/.next/server/app/_global-error.html +1 -1
  5. package/app/apps/web/.next/server/app/_global-error.rsc +1 -1
  6. package/app/apps/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  7. package/app/apps/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  8. package/app/apps/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  9. package/app/apps/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  10. package/app/apps/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  11. package/app/apps/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  12. package/app/apps/web/.next/server/app/agent/page_client-reference-manifest.js +1 -1
  13. package/app/apps/web/.next/server/app/changelog/page_client-reference-manifest.js +1 -1
  14. package/app/apps/web/.next/server/app/day/[date]/page_client-reference-manifest.js +1 -1
  15. package/app/apps/web/.next/server/app/day/page_client-reference-manifest.js +1 -1
  16. package/app/apps/web/.next/server/app/digest/[date]/page_client-reference-manifest.js +1 -1
  17. package/app/apps/web/.next/server/app/digest/page_client-reference-manifest.js +1 -1
  18. package/app/apps/web/.next/server/app/insights/[key]/page_client-reference-manifest.js +1 -1
  19. package/app/apps/web/.next/server/app/insights/page_client-reference-manifest.js +1 -1
  20. package/app/apps/web/.next/server/app/page_client-reference-manifest.js +1 -1
  21. package/app/apps/web/.next/server/app/parallelism/page_client-reference-manifest.js +1 -1
  22. package/app/apps/web/.next/server/app/print/[key]/page_client-reference-manifest.js +1 -1
  23. package/app/apps/web/.next/server/app/projects/[slug]/page_client-reference-manifest.js +1 -1
  24. package/app/apps/web/.next/server/app/projects/page_client-reference-manifest.js +1 -1
  25. package/app/apps/web/.next/server/app/runs/page_client-reference-manifest.js +1 -1
  26. package/app/apps/web/.next/server/app/sessions/[id]/page_client-reference-manifest.js +1 -1
  27. package/app/apps/web/.next/server/app/sessions/page_client-reference-manifest.js +1 -1
  28. package/app/apps/web/.next/server/app/settings/page_client-reference-manifest.js +1 -1
  29. package/app/apps/web/.next/server/app/team/onboarding/page_client-reference-manifest.js +1 -1
  30. package/app/apps/web/.next/server/app/team/page_client-reference-manifest.js +1 -1
  31. package/app/apps/web/.next/server/app/usage/page_client-reference-manifest.js +1 -1
  32. package/app/apps/web/.next/server/chunks/[root-of-the-server]__02.51sr._.js +1 -1
  33. package/app/apps/web/.next/server/chunks/[root-of-the-server]__0zyh554._.js +1 -1
  34. package/app/apps/web/.next/server/chunks/packages_parser_dist_06d9se1._.js +1 -1
  35. package/app/apps/web/.next/server/chunks/packages_parser_dist_10ihc3~._.js +1 -1
  36. package/app/apps/web/.next/server/chunks/ssr/[root-of-the-server]__0s~wd1k._.js +1 -1
  37. package/app/apps/web/.next/server/chunks/ssr/_0k8yioi._.js +1 -1
  38. package/app/apps/web/.next/server/chunks/ssr/apps_web_0epqfet._.js +1 -1
  39. package/app/apps/web/.next/server/chunks/ssr/apps_web_components_0x014hn._.js +1 -1
  40. package/app/apps/web/.next/server/chunks/ssr/apps_web_lib_changelog_ts_0n7_p1d._.js +1 -1
  41. package/app/apps/web/.next/server/chunks/ssr/apps_web_lib_changelog_ts_0nb5_-s._.js +1 -1
  42. package/app/apps/web/.next/server/chunks/ssr/packages_parser_dist_0mx_509._.js +1 -1
  43. package/app/apps/web/.next/server/middleware-build-manifest.js +3 -3
  44. package/app/apps/web/.next/server/middleware-manifest.json +5 -5
  45. package/app/apps/web/.next/server/pages/500.html +1 -1
  46. package/app/apps/web/.next/server/server-reference-manifest.js +1 -1
  47. package/app/apps/web/.next/server/server-reference-manifest.json +1 -1
  48. package/app/apps/web/.next/static/chunks/00_9zw_tjem-o.js +14 -0
  49. package/app/apps/web/.next/static/chunks/{0r~~~j3kmv7s_.js → 08os0c_3cdpqn.js} +1 -1
  50. package/app/apps/web/.next/static/chunks/0f9bdjq4n1ykp.js +1 -0
  51. package/app/apps/web/app/usage/page.tsx +264 -1
  52. package/app/apps/web/lib/changelog-data.generated.ts +1 -1
  53. package/app/apps/web/lib/usage-data.ts +1 -1
  54. package/app/apps/web/lib/usage-display.test.ts +15 -0
  55. package/app/apps/web/lib/usage-display.ts +22 -3
  56. package/app/apps/web/package.json +1 -1
  57. package/app/apps/web/tsconfig.tsbuildinfo +1 -1
  58. package/dist/daemon-worker.js +358 -92
  59. package/dist/index.js +564 -155
  60. package/menubar/Fleetlens.app/Contents/Info.plist +2 -2
  61. package/menubar/Fleetlens.app/Contents/MacOS/FleetlensMenubar +0 -0
  62. package/menubar/Fleetlens.app/Contents/Resources/command-code.svg +4 -0
  63. package/menubar/Fleetlens.app/Contents/_CodeSignature/CodeResources +11 -0
  64. package/package.json +1 -1
  65. package/app/apps/web/.next/static/chunks/0lcq6isl3n79m.js +0 -1
  66. package/app/apps/web/.next/static/chunks/0livk1wjx5m4o.js +0 -14
  67. /package/app/apps/web/.next/static/{h9pB-Efqh5oayfi0_lGfY → FOCI6RnIt_wZ2j2ZEqW5_}/_buildManifest.js +0 -0
  68. /package/app/apps/web/.next/static/{h9pB-Efqh5oayfi0_lGfY → FOCI6RnIt_wZ2j2ZEqW5_}/_clientMiddlewareManifest.js +0 -0
  69. /package/app/apps/web/.next/static/{h9pB-Efqh5oayfi0_lGfY → FOCI6RnIt_wZ2j2ZEqW5_}/_ssgManifest.js +0 -0
@@ -1,3 +1,3 @@
1
- module.exports=[39587,t=>{"use strict";let e={kind:"claude-code",displayName:"Claude Code",shortLabel:"Claude",accentColor:"var(--af-accent)",iconChar:"✦"},i={kind:"codex",displayName:"Codex (OpenAI)",shortLabel:"Codex",accentColor:"rgb(16, 163, 127)",iconChar:"◆"},s={kind:"copilot",displayName:"GitHub Copilot CLI",shortLabel:"Copilot",accentColor:"rgb(137, 87, 229)",iconChar:"∞"},n={kind:"gemini",displayName:"Gemini CLI",shortLabel:"Gemini",accentColor:"rgb(124, 92, 246)",iconChar:"✺"},a={kind:"antigravity",displayName:"Antigravity",shortLabel:"Agy",accentColor:"rgb(236, 72, 153)",iconChar:"⏃"},o={kind:"cowork",displayName:"Cowork",shortLabel:"Cowork",accentColor:"rgb(217, 119, 87)",iconChar:"⌘"},r={kind:"grok",displayName:"Grok Build",shortLabel:"Grok",accentColor:"rgb(100, 116, 139)",iconChar:"◈"},l=[e,i,s,n,a,o,{kind:"zai",displayName:"Z.ai",shortLabel:"Z.ai",accentColor:"rgb(59, 130, 246)",iconChar:"Z"},r];l.map(t=>t.kind),t.s(["ANTIGRAVITY_METADATA",0,a,"CLAUDE_CODE_METADATA",0,e,"CODEX_METADATA",0,i,"COPILOT_METADATA",0,s,"COWORK_METADATA",0,o,"GEMINI_METADATA",0,n,"GROK_METADATA",0,r,"agentMetadata",0,l])},79357,t=>{"use strict";let e={input:0,output:0,cacheRead:0,cacheWrite:0},i=["/.claude/worktrees/","/.worktrees/","/claude/worktrees/"],s=/\/conductor\/workspaces\/[^/]+\/([^/]+)(?:\/|$)/;function n(t){for(let e of i){let i=t.lastIndexOf(e);if(i>=0)return{idx:i,marker:e}}return null}function a(t){let e=s.exec(t);if(!e)return null;let i=e[1],n=+!!e[0].endsWith("/");return{canonicalEndIdx:e.index+e[0].length-i.length-1-n,workspaceName:i}}let o="/.superset/worktrees/",r=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;function l(t){let e=t.indexOf(o);if(e<0)return null;let i=t.slice(e+o.length).split("/").filter(Boolean);if(0===i.length)return null;let s=r.test(i[0])?i[1]??i[0]:i[0];return{canonical:t.slice(0,e)+o+s,workspaceName:s}}function u(t){let e=t.replace(/\/{2,}/g,"/"),i=n(e);if(i)return e.slice(0,i.idx);let s=a(e);if(s)return e.slice(0,s.canonicalEndIdx);let o=l(e);return o?o.canonical:e}function c(t){let e=t.replace(/\/{2,}/g,"/"),i=n(e);if(i){let t=e.slice(i.idx+i.marker.length),s=t.indexOf("/");return s>=0?t.slice(0,s):t}let s=a(e);if(s)return s.workspaceName;let o=l(e);return o?o.workspaceName:null}function m(t){let e=u(t),i=e.replace(/\/+$/,"").split("/").filter(Boolean);return i[i.length-1]||e}function d(t){let i={sessionCount:t.length,totalDurationMs:0,totalAirTimeMs:0,totalTokens:{...e},totalToolCalls:0,totalTurns:0,avgTurnsPerSession:0,avgDurationMs:0,totalLinesAdded:0,totalLinesRemoved:0,totalFilesEdited:0};for(let e of t)i.totalDurationMs+=e.durationMs??0,i.totalAirTimeMs+=e.airTimeMs??e.durationMs??0,i.totalTokens.input+=e.totalUsage.input,i.totalTokens.output+=e.totalUsage.output,i.totalTokens.cacheRead+=e.totalUsage.cacheRead,i.totalTokens.cacheWrite+=e.totalUsage.cacheWrite,i.totalToolCalls+=e.toolCallCount??0,i.totalTurns+=e.turnCount??0,i.totalLinesAdded+=e.linesAdded??0,i.totalLinesRemoved+=e.linesRemoved??0,i.totalFilesEdited+=e.filesEdited??0;return t.length>0&&(i.avgTurnsPerSession=i.totalTurns/t.length,i.avgDurationMs=i.totalDurationMs/t.length),i}t.s(["canonicalProjectName",0,u,"computeBurstsFromSessions",0,function(t,e={}){let i=[];for(let e of t)e.activeSegments&&0!==e.activeSegments.length&&i.push({id:e.id,projectDir:e.projectDir,segments:e.activeSegments});return function(t,e){let i=e.minDurationMs??6e4,s=e.mergeGapMs??6e5,n=e.minActive??2,a=[];for(let e of t)for(let t of e.segments)t.endMs<=t.startMs||(a.push({ms:t.startMs,delta:1,sessionId:e.id}),a.push({ms:t.endMs,delta:-1,sessionId:e.id}));a.sort((t,e)=>t.ms-e.ms||e.delta-t.delta);let o=new Map,r=[],l=null;for(let t of a){if(1===t.delta)o.set(t.sessionId,(o.get(t.sessionId)??0)+1);else{let e=(o.get(t.sessionId)??0)-1;e<=0?o.delete(t.sessionId):o.set(t.sessionId,e)}let e=o.size;if(e>=n)if(l)for(let i of(l.endMs=t.ms,e>l.peak&&(l.peak=e),o.keys()))l.sessionIds.add(i);else l={startMs:t.ms,endMs:t.ms,peak:e,sessionIds:new Set(o.keys())};else l&&(l.endMs=t.ms,r.push(l),l=null)}l&&r.push(l);let u=r.filter(t=>t.endMs-t.startMs>=i),c=[];for(let t of u){let e=c[c.length-1];if(e&&t.startMs-e.endMs<=s)for(let i of(e.endMs=t.endMs,t.peak>e.peak&&(e.peak=t.peak),t.sessionIds))e.sessionIds.add(i);else c.push({startMs:t.startMs,endMs:t.endMs,peak:t.peak,sessionIds:new Set(t.sessionIds)})}let m=new Map;for(let e of t)m.set(e.id,e.projectDir);return c.map(t=>{let e=Array.from(new Set(Array.from(t.sessionIds).map(t=>m.get(t)).filter(t=>!!t)));return{startMs:t.startMs,endMs:t.endMs,peak:t.peak,sessionIds:Array.from(t.sessionIds),projectDirs:e,crossProject:e.length>1}})}(i,e)},"groupByProject",0,function(t){let e=new Map,i=function(t){let e=new Map;for(let i of t)i.repoName&&e.set(m(i.projectName),i.repoName);return t=>t.repoName??e.get(m(t.projectName))??m(t.projectName)}(t);for(let s of t){let t=i(s),n=e.get(t);n||(n={projectDir:t,projectName:t,sessions:[],rawProjectDirs:[],worktreeCount:0,metrics:d([]),perAgent:[],lastActiveMs:void 0},e.set(t,n)),n.sessions.push(s),n.rawProjectDirs.includes(s.projectDir)||n.rawProjectDirs.push(s.projectDir);let a=s.lastTimestamp?Date.parse(s.lastTimestamp):void 0;a&&(!n.lastActiveMs||a>n.lastActiveMs)&&(n.lastActiveMs=a)}for(let t of e.values()){t.metrics=d(t.sessions);let e=new Set;for(let i of t.sessions){let t=i.worktreeName??c(i.projectName)??(i.cwd?c(i.cwd):null);t&&e.add(t)}t.worktreeCount=e.size;let i=new Map;for(let e of t.sessions){let t=e.agent??"claude-code",s=i.get(t);s||(s={agent:t,sessions:0},i.set(t,s)),s.sessions+=1}t.perAgent=Array.from(i.values()).sort((t,e)=>e.sessions-t.sessions)}return Array.from(e.values()).sort((t,e)=>(e.lastActiveMs??0)-(t.lastActiveMs??0))},"projectKey",0,m,"toLocalDay",0,function(t){let e=new Date(t),i=e.getFullYear(),s=String(e.getMonth()+1).padStart(2,"0"),n=String(e.getDate()).padStart(2,"0");return`${i}-${s}-${n}`},"worktreeName",0,c])},36521,t=>{"use strict";let e=[/<system_instruction\b[^>]*>[\s\S]*?<\/system_instruction>\s*/gi],i=["<command-name>","<local-command-stdout>","<local-command-caveat>","<task-notification>","Base directory for this skill:","This session is being continued from a previous conversation","A session-scoped Stop hook is now active"];function s(t){if(!t)return t;let i=t;for(let t of e)i=i.replace(t,"");return i.trim()}t.s(["isFrameworkInjectedUserInput",0,function(t){if(!t)return!1;let e=s(t);if(!e)return!0;for(let t of i)if(e.startsWith(t))return!0;return!1},"stripFrameworkBoilerplate",0,s])},43427,20629,t=>{"use strict";let e;t.s(["agentSources",()=>ek,"appendUsageSnapshot",()=>eb,"cclensHome",()=>ew,"cclensPath",()=>eM,"getAnySession",()=>eN,"invalidateFile",()=>ev,"listAllSessions",()=>e_,"pruneUsageAgent",()=>ej],43427);var i=t.i(2157),s=t.i(60526),n=t.i(50227),a=t.i(39587),o=t.i(36521),r=t.i(79357);let l={input:0,output:0,cacheRead:0,cacheWrite:0};function u(t,e=200){let i=t.replace(/<[^>]+>/g,"").replace(/\s+/g," ").trim();return i.length>e?i.slice(0,e-1)+"…":i}let c=/^\s*<teammate-message\s+teammate_id="([^"]+)"[^>]*>([\s\S]*?)<\/teammate-message>/;function m(t){let e=t.match(c);if(!e)return;let i=e[1],s=e[2].trim(),n="message";if(s.startsWith("{"))try{let t=JSON.parse(s);"idle_notification"===t.type?n="idle-notification":"shutdown_request"===t.type?n="shutdown-request":"shutdown_approved"===t.type?n="shutdown-approved":"task_assignment"===t.type?n="task-assignment":"teammate_terminated"===t.type&&(n="teammate-terminated")}catch{}return{teammateId:i,body:s,kind:n}}function d(t){if(!t||"object"!=typeof t)return;let e=t=>"number"==typeof t?t:0;return{input:e(t.input_tokens),output:e(t.output_tokens),cacheRead:e(t.cache_read_input_tokens),cacheWrite:e(t.cache_creation_input_tokens)}}function p(t){let e,i,s,n,a,c,p,f,g,y,h,w=[];for(let e=0;e<t.length;e++){let i=function(t,e){if(!t||"object"!=typeof t)return null;let i=String(t.type??""),s=t.uuid,n=t.parentUuid??null,a=t.timestamp;if("assistant"===i){let o,r,l,c=t.message??{},m=c.content??[],p=d(c.usage),f=c.model,g=t.requestId,y=c.id,h=c.stop_reason,w=m[0],M="agent";return w?.type==="thinking"?(M="agent-thinking",o="[thinking] "+u(w.thinking,140)):w?.type==="tool_use"?(M="tool-call",r=w.name,l=w.id,o=`${w.name} `+u(JSON.stringify(w.input??{}),100)):o=w?.type==="text"?u(w.text,200):`<assistant:${w?.type??"empty"}>`,{index:e,uuid:s,parentUuid:n,timestamp:a,role:M,rawType:i,preview:o,blocks:m,usage:p,model:f,requestId:g,messageId:y,stopReason:h,toolName:r,toolUseId:l,raw:t}}if("user"===i){let r=(t.message??{}).content;if("string"==typeof r){let l=(0,o.stripFrameworkBoilerplate)(r),c=m(l);return{index:e,uuid:s,parentUuid:n,timestamp:a,role:"user",rawType:i,preview:u(l,200),blocks:l?[{type:"text",text:l}]:[],raw:t,teammateMessage:c}}if(Array.isArray(r)){let l=r[0];if(l?.type==="tool_result")return{index:e,uuid:s,parentUuid:n,timestamp:a,role:"tool-result",rawType:i,preview:u("string"==typeof l.content?l.content:JSON.stringify(l.content),200),blocks:r,toolUseId:l.tool_use_id,toolResult:t.toolUseResult,raw:t};let c=r.find(t=>t?.type==="text"),d=c?(0,o.stripFrameworkBoilerplate)(c.text):"",p=c?r.map(t=>t===c?{type:"text",text:d}:t):r,f=d?m(d):void 0;return{index:e,uuid:s,parentUuid:n,timestamp:a,role:"user",rawType:i,preview:d?u(d,200):u(JSON.stringify(r),200),blocks:p,raw:t,teammateMessage:f}}}if("attachment"===i){let o=t.attachment??{},r=String(o.type??"attachment"),l=`<attachment: ${r}>`;return"string"==typeof o.content&&o.content.length>0?l=`[${r}] `+u(o.content,140):Array.isArray(o.addedNames)&&(l=`[${r}] +${o.addedNames.length} names`),{index:e,uuid:s,parentUuid:n,timestamp:a,role:"system",rawType:i,preview:l,blocks:[{type:"text",text:JSON.stringify(o,null,2)}],attachmentType:r,raw:t}}return{index:e,uuid:s,parentUuid:n,timestamp:a,role:"meta",rawType:i||"unknown",preview:`${i}: ${u(JSON.stringify(t),140)}`,blocks:[{type:"text",text:JSON.stringify(t,null,2)}],raw:t}}(t[e],e);i&&w.push(i)}for(let t of w){if(!t.timestamp)continue;let s=Date.parse(t.timestamp);!Number.isNaN(s)&&((void 0===e||s<e)&&(e=s),(void 0===i||s>i)&&(i=s))}let M=void 0!==e?new Date(e).toISOString():void 0,v=void 0!==i?new Date(i).toISOString():void 0;for(let t of w){if(!t.timestamp)continue;let i=Date.parse(t.timestamp);Number.isNaN(i)||void 0!==e&&(t.tOffsetMs=Math.max(0,i-e))}let k=w.filter(t=>{let e;return t.timestamp&&("user"===(e=t.role)||"agent"===e||"agent-thinking"===e||"tool-call"===e||"tool-result"===e)}).map(t=>({e:t,ms:Date.parse(t.timestamp)})).filter(t=>!Number.isNaN(t.ms)).sort((t,e)=>t.ms-e.ms);for(let t=1;t<k.length;t++)k[t].e.gapMs=Math.max(0,k[t].ms-k[t-1].ms);let _=w.filter(t=>t.timestamp).map(t=>Date.parse(t.timestamp)).filter(t=>!Number.isNaN(t)).sort((t,e)=>t-e),N=[],T=0;if(_.length>0){let t=_[0],e=_[0];for(let i=1;i<_.length;i++){let s=_[i],n=s-e;n>18e4?(N.push({startMs:t,endMs:e}),t=s):n>0&&(T+=n),e=s}N.push({startMs:t,endMs:e})}let b=new Map,j=[];for(let t of w){if(!t.timestamp)continue;let e=Date.parse(t.timestamp);if(!Number.isNaN(e)){if("assistant"===t.rawType&&t.usage&&t.messageId){let i=b.get(t.messageId);i?(i.siblings.push(t),e<i.ms&&(i.rep=t,i.ms=e)):b.set(t.messageId,{rep:t,ms:e,siblings:[t]})}else if("system"===t.rawType){let i=t.raw;if(i?.subtype!=="compact_boundary")continue;let s=i.compactMetadata??{};j.push({ms:e,trigger:"manual"===s.trigger?"manual":"auto",preTokens:"number"==typeof s.preTokens?s.preTokens:0})}}}let I=[...b.values()].sort((t,e)=>t.ms-e.ms);j.sort((t,e)=>t.ms-e.ms);let C=0,x=0,S=(t,e)=>{for(let i of t.siblings)i.coldResume=e;C++,x+=e.writeTokens},A=new Set;for(let t of j){let e,i=I.find(e=>e.ms>t.ms&&(e.rep.usage?.cacheWrite??0)>=1e3);if(!i)continue;for(let i=I.length-1;i>=0;i--)if(I[i].ms<=t.ms){e=I[i].ms;break}let s=i.rep.usage,n=s.cacheWrite+s.cacheRead;S(i,{trigger:"compact",gapMs:void 0!==e?i.ms-e:0,writeTokens:s.cacheWrite,writeRatio:n>0?s.cacheWrite/n:0,compact:{trigger:t.trigger,preTokens:t.preTokens}}),A.add(i.rep.messageId)}for(let t=1;t<I.length;t++){let e=I[t-1],i=I[t];if(A.has(i.rep.messageId))continue;let s=i.rep.usage,n=s.cacheWrite+s.cacheRead,a=n>0?s.cacheWrite/n:0,o=i.ms-e.ms;o>3e5&&s.cacheWrite>=1e3&&a>=.3&&S(i,{trigger:"idle",gapMs:o,writeTokens:s.cacheWrite,writeRatio:a})}let P={...l},D=new Set,U="",R=!1,B=!1,z=0,F=0,O=0,$=0,W=new Set,E=new Map,L=void 0!==e?(0,r.toLocalDay)(e):void 0,J=t=>{let e;if(t){let i=Date.parse(t);Number.isNaN(i)||(e=(0,r.toLocalDay)(i))}if(!(e=e??L))return;let i=E.get(e);return i||(i={toolCalls:0,turns:0,tokens:{...l}},E.set(e,i)),i};for(let t of w){if("tool-call"===t.role){z++;let e=J(t.timestamp);e&&e.toolCalls++;let i=t.blocks.find(t=>t&&"tool_use"===t.type);if(i){let t=i.input??{};if("TeamCreate"===i.name&&(R=!0),"SendMessage"===i.name){let e="string"==typeof t.to?t.to:"";e&&"team-lead"!==e&&(B=!0)}let e="string"==typeof t.file_path?t.file_path:void 0;if("Edit"===i.name&&e){W.add(e);let i="string"==typeof t.old_string?t.old_string:"",s="string"==typeof t.new_string?t.new_string:"",n=i?i.split("\n").length:0,a=s?s.split("\n").length:0;O+=Math.max(0,a-n),$+=Math.max(0,n-a)}else if("Write"===i.name&&e){W.add(e);let i="string"==typeof t.content?t.content:"";O+=i?i.split("\n").length:0}}}if("user"===t.role){let e=function(t){let e=t?.content;if("string"==typeof e)return e;if(Array.isArray(e)){for(let t of e)if(t&&"object"==typeof t&&"text"===t.type&&"string"==typeof t.text)return t.text}return""}(t.raw?.message),i=(0,o.isFrameworkInjectedUserInput)(e),s=void 0!==t.teammateMessage&&!f;if(!i&&!s){g||(g=t.teammateMessage?t.teammateMessage.body:t.preview),F++;let e=J(t.timestamp);e&&e.turns++,h=t.preview}}"agent"===t.role&&(y=t.preview)}for(let e of t)if(e&&"object"==typeof e&&("string"!=typeof e.sessionId||U||(U=e.sessionId),"string"!=typeof e.cwd||n||(n=e.cwd),"string"!=typeof e.gitBranch||a||(a=e.gitBranch),"string"!=typeof e.entrypoint||c||(c=e.entrypoint),"string"!=typeof e.teamName||p||(p=e.teamName),"string"!=typeof e.agentName||f||(f=e.agentName),"assistant"===e.type)){let t=e.message;if(t){"string"!=typeof t.model||s||(s=t.model);let i="string"==typeof t.id?t.id:void 0;if(i&&D.has(i))continue;i&&D.add(i);let n=d(t.usage);if(n){P.input+=n.input,P.output+=n.output,P.cacheRead+=n.cacheRead,P.cacheWrite+=n.cacheWrite;let t=J("string"==typeof e.timestamp?e.timestamp:void 0);t&&(t.tokens.input+=n.input,t.tokens.output+=n.output,t.tokens.cacheRead+=n.cacheRead,t.tokens.cacheWrite+=n.cacheWrite)}}}return{events:w,meta:{sessionId:U,firstTimestamp:M,lastTimestamp:v,durationMs:void 0!==e&&void 0!==i?i-e:void 0,eventCount:w.length,model:s,cwd:n,gitBranch:a,entrypoint:c,totalUsage:P,status:"idle",firstUserPreview:g,lastUserPreview:h,lastAgentPreview:y,toolCallCount:z,turnCount:F,dailyBreakdown:Array.from(E.entries()).map(([t,e])=>({day:t,toolCalls:e.toolCalls,turns:e.turns,tokens:e.tokens})).sort((t,e)=>t.day.localeCompare(e.day)),airTimeMs:T,activeSegments:N,linesAdded:O,linesRemoved:$,filesEdited:W.size,coldResumeCount:C,cacheRebuildTokens:x,teamName:p,agentName:f,isTeamLead:void 0!==p&&void 0===f&&(R||B)}}}let f=/^(?:(?:https?|ssh|git):\/\/)?(?:[^@/]+@)?([^/:]+)[:/](.+?)(?:\.git)?\/?$/;function g(t){try{return(0,i.realpathSync)(t)}catch{return t}}function y(t){let e=g(t.replace(/\/{2,}/g,"/"));try{let t=function(t){let e;if(!t||!(0,n.isAbsolute)(t))return null;let a=(e=g((0,s.homedir)()),t===e||t.startsWith(`${e}/`)?e:void 0);for(let e=t.replace(/\/+$/,"")||t;;e=(0,n.dirname)(e)){if(e===a)return null;let t=function(t){let e=(0,n.join)(t,".git"),s=(0,i.statSync)(e,{throwIfNoEntry:!1});if(!s)return null;if(s.isDirectory())return{root:t,gitDir:e,commonDir:e};let a=function(t,e){let i=e.match(/^gitdir:\s*(.+)\s*$/m);if(!i)return;let s=i[1].trim();return(0,n.isAbsolute)(s)?s:(0,n.resolve)(t,s)}(t,(0,i.readFileSync)(e,"utf8"));return a?{root:t,gitDir:a,commonDir:function(t){let e=(0,n.join)(t,"commondir");if(!(0,i.existsSync)(e))return;let s=(0,i.readFileSync)(e,"utf8").trim();if(s)return(0,n.isAbsolute)(s)?s:(0,n.resolve)(t,s)}(a)}:{root:t}}(e);if(t)return t;if((0,n.dirname)(e)===e)return null}}(e);if(t){let s=g(function(t){if(t)return".git"===(0,n.basename)(t)?(0,n.dirname)(t):void 0}(t.commonDir)??t.root),a=g(t.root),o=s!==a?(0,r.worktreeName)(e)??(0,n.basename)(t.root):void 0,l={projectName:s};o&&(l.worktreeName=o);let u=function(t){let e=t.commonDir??t.gitDir;if(!e)return;let s=(0,n.join)(e,"config");if(!(0,i.existsSync)(s))return;let a=function(t){let e=!1;for(let i of t.split("\n")){let t=i.trim();if(t.startsWith("[")){e=/^\[remote\s+"origin"\]/.test(t);continue}if(!e)continue;let s=t.match(/^url\s*=\s*(.+)$/);if(s)return s[1].trim()}}((0,i.readFileSync)(s,"utf8"));return a?function(t){let e=t.match(f);if(!e)return;let i=e[1],s=e[2].split("/").filter(Boolean);if(s.length<2)return;let n=s[s.length-1],a=s.slice(0,-1).join("/");return{host:i,owner:a,name:n,url:t,webUrl:`https://${i}/${a}/${n}`}}(a):void 0}(t);return u&&(l.remote=u,l.repoName=u.name),l}}catch{}let a=(0,r.canonicalProjectName)(e),o=(0,r.worktreeName)(e)??void 0;return o?{projectName:a,worktreeName:o}:{projectName:a}}let h=n.default.join(s.default.homedir(),".claude","projects");function w(t){return t.startsWith("-")?"/"+t.slice(1).replace(/-/g,"/"):t}let M=n.default.join(s.default.homedir(),".cclens","runtime").replace(/[/.]/g,"-");async function v(t){let e=await i.promises.readFile(t,"utf8"),s=[];for(let t of e.split("\n")){let e=t.trim();if(e)try{s.push(JSON.parse(e))}catch{}}return s}function k(t){return t.replace(/\.jsonl$/i,"")}let _=new Map,N=new Map,T=new Map,b=null;function j(t){_.delete(t),N.delete(t),T.delete(t),b=null}async function I(t=h){let e;if(b&&b.root===t&&Date.now()-b.capturedAtMs<1e3)return b.files;try{e=await i.promises.readdir(t,{withFileTypes:!0})}catch{return[]}let s=e.filter(t=>t.isDirectory()&&t.name!==M).map(t=>t.name),a=(await Promise.all(s.map(async e=>{let s,a=n.default.join(t,e);try{s=await i.promises.readdir(a)}catch{return[]}let o=s.filter(t=>t.endsWith(".jsonl"));return(await Promise.all(o.map(async t=>{let s=n.default.join(a,t);try{let n=await i.promises.stat(s);return{projectDir:e,fileName:t,fullPath:s,mtimeMs:n.mtimeMs,sizeBytes:n.size}}catch{return null}}))).filter(t=>null!==t)}))).flat();return b={files:a,capturedAtMs:Date.now(),root:t},a}let C={input:0,output:0,cacheRead:0,cacheWrite:0};function x(t,e,i,s,n){for(let a of t){if(!a||"object"!=typeof a||"assistant"!==a.type)continue;let t=a.message;if(!t)continue;let o="string"==typeof t.id?t.id:void 0,l="string"==typeof a.requestId?a.requestId:void 0,u=null!=o&&null!=l?`${o}:${l}`:void 0;if(u&&e.has(u))continue;u&&e.add(u);let c=t.usage;if(c){let t=t=>"number"==typeof t?t:0,e=t(c.input_tokens),o=t(c.output_tokens),l=t(c.cache_read_input_tokens),u=t(c.cache_creation_input_tokens);if(i.input+=e,i.output+=o,i.cacheRead+=l,i.cacheWrite+=u,s){let t,i="string"==typeof a.timestamp?a.timestamp:void 0;if(i){let e=Date.parse(i);Number.isNaN(e)||(t=(0,r.toLocalDay)(e))}if(t=t??n){let i=s.get(t);i||(i={...C},s.set(t,i)),i.input+=e,i.output+=o,i.cacheRead+=l,i.cacheWrite+=u}}}}}async function S(t,e,s,a){let o,r={...C},l=new Set,u=new Map;x(t,l,r,u,a);let c=n.default.join(e,s,"subagents");try{o=await i.promises.readdir(c)}catch{return{usage:r,perDay:u}}let m=o.filter(t=>t.endsWith(".jsonl"));return 0===m.length||await Promise.all(m.map(async t=>{try{let e=await v(n.default.join(c,t));x(e,l,r,u,a)}catch{}})),{usage:r,perDay:u}}async function A(t,e){let s,a=n.default.join(t,e,"workflows");try{s=await i.promises.readdir(a)}catch{return{workflowCount:0,spawnedAgentCount:0,spans:[]}}let o=s.filter(t=>t.startsWith("wf_")&&t.endsWith(".json"));if(0===o.length)return{workflowCount:0,spawnedAgentCount:0,spans:[]};let r=0,l=[];return{workflowCount:(await Promise.all(o.map(async t=>{try{let e=JSON.parse(await i.promises.readFile(n.default.join(a,t),"utf8"));return"number"==typeof e.agentCount&&(r+=e.agentCount),"number"==typeof e.startTime&&"number"==typeof e.durationMs&&e.durationMs>0&&l.push({startMs:e.startTime,endMs:e.startTime+e.durationMs}),!0}catch{return!1}}))).filter(Boolean).length,spawnedAgentCount:r,spans:l}}async function P(t,e){let s;try{s=await i.promises.readdir(t,{withFileTypes:!0})}catch{return 0}return(await Promise.all(s.map(async s=>{let a=n.default.join(t,s.name);try{if(s.isDirectory())return e>0?await P(a,e-1):0;return(await i.promises.stat(a)).mtimeMs}catch{return 0}}))).reduce((t,e)=>Math.max(t,e),0)}async function D(t,e){let i=n.default.join(t,e),[s,a]=await Promise.all([P(n.default.join(i,"subagents"),2),P(n.default.join(i,"workflows"),0)]),o=Math.max(s,a);return o>0?o:void 0}async function U(t,e){let i=await D(n.default.dirname(e.fullPath),t.id),s=t.lastTimestamp?Date.parse(t.lastTimestamp):0,a=Math.max(Number.isFinite(s)?s:0,i??0);return a>0?{...t,lastActivityMs:a}:t}function R(t,e){if(0===e.length)return{};let i=[...t??[],...e].filter(t=>t.endMs>t.startMs).sort((t,e)=>t.startMs-e.startMs);if(0===i.length)return{};let s=[{...i[0]}];for(let t=1;t<i.length;t++){let e=i[t],n=s[s.length-1];e.startMs<=n.endMs?n.endMs=Math.max(n.endMs,e.endMs):s.push({...e})}let n=s.reduce((t,e)=>t+(e.endMs-e.startMs),0);return{activeSegments:s,airTimeMs:n}}async function B(t,e,i){let s=k(i.fileName),a=n.default.dirname(i.fullPath),o=t.firstTimestamp?(0,r.toLocalDay)(Date.parse(t.firstTimestamp)):void 0,{usage:l,perDay:u}=await S(e,a,s,o);t.totalUsage=l,t.dailyBreakdown=function(t,e,i){let s=new Map((t??[]).map(t=>[t.day,t])),n=[...new Set([...s.keys(),...e.keys()])].sort((t,e)=>t.localeCompare(e)).map(t=>({day:t,toolCalls:s.get(t)?.toolCalls??0,turns:s.get(t)?.turns??0,tokens:{...e.get(t)??C}}));if(n.length>0){let t=n.reduce((t,e)=>({input:t.input+e.tokens.input,output:t.output+e.tokens.output,cacheRead:t.cacheRead+e.tokens.cacheRead,cacheWrite:t.cacheWrite+e.tokens.cacheWrite}),{...C}),e=n[0].tokens;e.input+=i.input-t.input,e.output+=i.output-t.output,e.cacheRead+=i.cacheRead-t.cacheRead,e.cacheWrite+=i.cacheWrite-t.cacheWrite}return n}(t.dailyBreakdown,u,l)}async function z(t){let e=_.get(t.fullPath);if(e&&e.mtimeMs===t.mtimeMs&&e.sizeBytes===t.sizeBytes)return e.meta;try{let e=await v(t.fullPath),{meta:i}=p(e);await B(i,e,t);let s=k(t.fileName),a=n.default.dirname(t.fullPath),o=await A(a,s),r=i.cwd??w(t.projectDir),l=y(r),u={...i,id:s,filePath:t.fullPath,projectDir:t.projectDir,projectName:l.projectName,worktreeName:l.worktreeName,repoName:l.repoName,...o.workflowCount>0?{workflowCount:o.workflowCount,spawnedAgentCount:o.spawnedAgentCount}:{},...R(i.activeSegments,o.spans)};return _.set(t.fullPath,{meta:u,mtimeMs:t.mtimeMs,sizeBytes:t.sizeBytes}),u}catch{return null}}async function F(t){let e=N.get(t.fullPath);if(e&&e.mtimeMs===t.mtimeMs&&e.sizeBytes===t.sizeBytes)return e.detail;try{let e=await v(t.fullPath),{meta:i,events:s}=p(e),a=k(t.fileName);await B(i,e,t);let o=await A(n.default.dirname(t.fullPath),a),r=i.cwd??w(t.projectDir),l=y(r),u={...i,id:a,filePath:t.fullPath,projectDir:t.projectDir,projectName:l.projectName,worktreeName:l.worktreeName,repoName:l.repoName,events:s,...o.workflowCount>0?{workflowCount:o.workflowCount,spawnedAgentCount:o.spawnedAgentCount}:{},...R(i.activeSegments,o.spans)};N.set(t.fullPath,{detail:u,mtimeMs:t.mtimeMs,sizeBytes:t.sizeBytes});let c={...u};return delete c.events,_.set(t.fullPath,{meta:c,mtimeMs:t.mtimeMs,sizeBytes:t.sizeBytes}),u}catch{return null}}async function O(t={}){let{root:e=h,limit:i=500,projectDir:s}=t,n=await I(e);s&&(n=n.filter(t=>t.projectDir===s)),n.sort((t,e)=>e.mtimeMs-t.mtimeMs);let a=n.slice(0,i);return(await Promise.all(a.map(async t=>{let e=await z(t);return e?U(e,t):null}))).filter(t=>null!==t)}async function $(t,e={}){let{root:i=h}=e,s=(await I(i)).find(e=>k(e.fileName)===t);if(!s)return null;let a=await F(s);if(!a)return a;let o=a.firstTimestamp?Date.parse(a.firstTimestamp):void 0,r=n.default.join(n.default.dirname(s.fullPath),k(s.fileName),"subagents"),l=n.default.join(n.default.dirname(s.fullPath),k(s.fileName),"workflows"),[u,c]=await Promise.all([E(r,o,a.events),L(l,o,a.events)]),m=c.reduce((t,e)=>t+e.agentCount,0);return U({...a,subagents:u,workflows:c,...c.length>0?{workflowCount:c.length,spawnedAgentCount:m}:{}},s)}function W(t){let e,i,s,n,a,o={...C},r=new Set,l=0,u=0,c=0,m=new Map;for(let d of t){if(!d||"object"!=typeof d)continue;l++;let t="string"==typeof d.timestamp?Date.parse(d.timestamp):NaN;if(!Number.isNaN(t)&&((void 0===e||t<e)&&(e=t),(void 0===i||t>i)&&(i=t)),void 0===a&&"user"===d.type&&(null===d.parentUuid||void 0===d.parentUuid)){let t=d.message,e=t?.content;if("string"==typeof e)a=e;else if(Array.isArray(e)){let t=e.find(t=>t&&"object"==typeof t&&"text"===t.type);t?.text&&(a=t.text)}}if("assistant"===d.type){let t=d.message;if(!t)continue;n||"string"!=typeof t.model||(n=t.model);let e="string"==typeof t.id?t.id:void 0,i="string"==typeof d.requestId?d.requestId:void 0,a=null!=e&&null!=i?`${e}:${i}`:void 0,l=!a||!r.has(a);if(a&&l&&r.add(a),l){u++;let e=t.usage;if(e){let t=t=>"number"==typeof t?t:0;o.input+=t(e.input_tokens),o.output+=t(e.output_tokens),o.cacheRead+=t(e.cache_read_input_tokens),o.cacheWrite+=t(e.cache_creation_input_tokens)}}let p=t.content;if(Array.isArray(p))for(let t of p)t&&"object"==typeof t&&("text"===t.type&&"string"==typeof t.text?s=t.text:"tool_use"===t.type&&"string"==typeof t.name&&(c++,m.set(t.name,(m.get(t.name)??0)+1)))}}let d=Array.from(m.entries()).map(([t,e])=>({name:t,count:e})).sort((t,e)=>e.count-t.count);return{startMs:e,endMs:i,totalUsage:o,eventCount:l,finalPreview:void 0!==s?s.replace(/\s+/g," ").trim().slice(0,240):void 0,finalText:s,model:n,toolCalls:d,toolCallCount:c,assistantMessageCount:u,initialPrompt:a}}async function E(t,e,s){let a;try{a=await i.promises.readdir(t)}catch{return[]}let o=new Map,r=[];for(let t of s)if("tool-call"===t.role&&"Agent"===t.toolName)for(let e of t.blocks){if(e?.type!=="tool_use"||"Agent"!==e.name)continue;let i=e.input??{},s="string"==typeof i.description?i.description:void 0,n=t.timestamp?Date.parse(t.timestamp):void 0,a={toolUseId:e.id,parentUuid:t.uuid??"",runInBackground:!0===i.run_in_background,prompt:"string"==typeof i.prompt?i.prompt:void 0,tsMs:n};s&&o.set(s,a),void 0!==n&&r.push(a)}r.sort((t,e)=>(t.tsMs??0)-(e.tsMs??0));let l=a.filter(t=>t.startsWith("agent-")&&t.endsWith(".jsonl"));return(await Promise.all(l.map(async s=>{let a,l=s.replace(/^agent-/,"").replace(/\.jsonl$/,""),u=n.default.join(t,s),c=n.default.join(t,`agent-${l}.meta.json`),m={};try{let t=await i.promises.readFile(c,"utf8");m=JSON.parse(t)}catch{}try{a=await v(u)}catch{return null}let d=W(a),p=m.description&&m.description.trim().length>0?m.description:void 0,f=p?o.get(p):function(t){let e;if(void 0===t)return;let i=1/0;for(let s of r){if(void 0===s.tsMs)continue;let n=Math.abs(t-s.tsMs);n<i&&n<=2e3&&(e=s,i=n)}return e}(d.startMs),g=p??(d.initialPrompt?d.initialPrompt.replace(/\s+/g," ").trim().slice(0,80):"(no description)"),y=f?.prompt??d.initialPrompt,h=void 0!==e&&void 0!==d.startMs?Math.max(0,d.startMs-e):void 0,w=void 0!==e&&void 0!==d.endMs?Math.max(0,d.endMs-e):void 0,M=void 0!==d.startMs&&void 0!==d.endMs?d.endMs-d.startMs:void 0;return{agentId:l,agentType:m.agentType??"unknown",description:g,startMs:d.startMs,endMs:d.endMs,durationMs:M,startTOffsetMs:h,endTOffsetMs:w,eventCount:d.eventCount,totalUsage:d.totalUsage,parentUuid:f?.parentUuid,parentToolUseId:f?.toolUseId,runInBackground:f?.runInBackground,prompt:y,finalPreview:d.finalPreview,finalText:d.finalText,model:d.model,toolCalls:d.toolCalls,toolCallCount:d.toolCallCount,assistantMessageCount:d.assistantMessageCount}}))).filter(t=>null!==t).sort((t,e)=>(t.startMs??0)-(e.startMs??0))}async function L(t,e,s){let a;try{a=await i.promises.readdir(t)}catch{return[]}let o=a.filter(t=>t.startsWith("wf_")&&t.endsWith(".json"));if(0===o.length)return[];let r=[];for(let t of s){if("tool-call"!==t.role||"Workflow"!==t.toolName)continue;let e=t.timestamp?Date.parse(t.timestamp):NaN;if(!Number.isNaN(e))for(let i of t.blocks)i?.type==="tool_use"&&"Workflow"===i.name&&r.push({toolUseId:i.id,parentUuid:t.uuid??"",tsMs:e})}r.sort((t,e)=>t.tsMs-e.tsMs);let l=t=>"number"==typeof t?t:void 0,u=t=>"string"==typeof t&&t.length>0?t:void 0;return(await Promise.all(o.map(async s=>{let a;try{a=JSON.parse(await i.promises.readFile(n.default.join(t,s),"utf8"))}catch{return null}let o=u(a.runId)??s.replace(/\.json$/,""),c=l(a.startTime),m=l(a.durationMs),d=void 0!==c&&void 0!==m?c+m:void 0,p=void 0!==e&&void 0!==c?Math.max(0,c-e):void 0,f=void 0!==e&&void 0!==d?Math.max(0,d-e):void 0,g=Array.isArray(a.phases)?a.phases.filter(t=>!!t&&"object"==typeof t&&"string"==typeof t.title).map(t=>({title:t.title,detail:u(t.detail)})):[],y=Array.isArray(a.logs)?a.logs.filter(t=>"string"==typeof t):[],h=(t,e)=>{let i=u(t);return void 0===i?void 0:i.length>e?i.slice(0,e)+"…":i},w=(Array.isArray(a.workflowProgress)?a.workflowProgress:[]).filter(t=>!!t&&"object"==typeof t&&"workflow_agent"===t.type).map(t=>({index:l(t.index)??0,label:u(t.label)??"(agent)",phaseIndex:l(t.phaseIndex),phaseTitle:u(t.phaseTitle),agentId:u(t.agentId),model:u(t.model),state:u(t.state),startedAt:l(t.startedAt),durationMs:l(t.durationMs),tokens:l(t.tokens),toolCalls:l(t.toolCalls),lastToolSummary:h(t.lastToolSummary,200),promptPreview:h(t.promptPreview,600),resultPreview:h(t.resultPreview,600)})).sort((t,e)=>t.index-e.index),M=(t=>{let e,i;if(void 0===t||0===r.length)return;let s=1/0,n=1/0;for(let a of r){let o=Math.abs(t-a.tsMs);!(o>6e4)&&(o<n&&(i=a,n=o),a.tsMs<=t&&o<s&&(e=a,s=o))}return e??i})(c);return{runId:o,name:u(a.workflowName)??o,description:u(a.summary),status:u(a.status)??"unknown",agentCount:l(a.agentCount)??0,toolCallCount:l(a.totalToolCalls)??0,totalTokens:l(a.totalTokens)??0,durationMs:m,startMs:c,endMs:d,startTOffsetMs:p,endTOffsetMs:f,model:u(a.defaultModel),phases:g,logs:y,agents:w,parentToolUseId:M?.toolUseId,parentUuid:M?.parentUuid}}))).filter(t=>null!==t).sort((t,e)=>(t.startMs??0)-(e.startMs??0))}async function J(t,e,i,s={}){let a,o,r,l,u,c,{root:m=h}=s;if(!/^[\w.-]+$/.test(e)||!/^[\w.-]+$/.test(i))return null;let d=(await I(m)).find(e=>k(e.fileName)===t);if(!d)return null;let p=n.default.join(n.default.dirname(d.fullPath),t,"subagents","workflows",e,`agent-${i}.jsonl`);try{a=await v(p)}catch{return null}let f=new Set;for(let t of a){if(!t||"object"!=typeof t)continue;let e=t.message?.content;if(Array.isArray(e))for(let t of e)t&&"object"==typeof t&&"tool_result"===t.type&&!0===t.is_error&&"string"==typeof t.tool_use_id&&f.add(t.tool_use_id)}let g=[],y=new Map,w={...C},M=new Set,_=0,N=0;for(let t of a){if(!t||"object"!=typeof t)continue;N++;let e="string"==typeof t.timestamp?Date.parse(t.timestamp):NaN;if(!Number.isNaN(e)&&((void 0===u||e<u)&&(u=e),(void 0===c||e>c)&&(c=e)),void 0===o&&"user"===t.type&&(null===t.parentUuid||void 0===t.parentUuid)){let e=t.message?.content;if("string"==typeof e)o=e;else if(Array.isArray(e)){let t=e.find(t=>t&&"object"==typeof t&&"text"===t.type);t?.text&&(o=t.text)}}if("assistant"!==t.type)continue;let i=t.message;if(!i)continue;l||"string"!=typeof i.model||(l=i.model);let s="string"==typeof i.id?i.id:void 0,n="string"==typeof t.requestId?t.requestId:void 0,a=null!=s&&null!=n?`${s}:${n}`:void 0,m=!a||!M.has(a);if(a&&m&&M.add(a),m){_++;let t=i.usage;if(t){let e=t=>"number"==typeof t?t:0;w.input+=e(t.input_tokens),w.output+=e(t.output_tokens),w.cacheRead+=e(t.cache_read_input_tokens),w.cacheWrite+=e(t.cache_creation_input_tokens)}}let d=i.content;if(Array.isArray(d)){for(let t of d)if(t&&"object"==typeof t){if("text"===t.type&&"string"==typeof t.text)r=t.text;else if("tool_use"===t.type&&"string"==typeof t.name&&(y.set(t.name,(y.get(t.name)??0)+1),g.length<2e3)){let e=function(t){if(!t||"object"!=typeof t)return"";let e=e=>"string"==typeof t[e]?t[e]:void 0;return e("command")??e("file_path")??e("path")??e("pattern")??e("url")??e("description")??e("query")??e("prompt")??e("old_string")??JSON.stringify(t)}(t.input),i=e.replace(/\s+/g," ").trim().slice(0,160),s=e.length>4e3?e.slice(0,4e3)+"…":e;g.push({index:g.length+1,tool:t.name,preview:i,full:s.length>i.length||s.includes("\n")?s:void 0,isError:"string"==typeof t.id&&f.has(t.id)})}}}}return{agentId:i,prompt:o,finalText:r,steps:g,toolCalls:Array.from(y.entries()).map(([t,e])=>({name:t,count:e})).sort((t,e)=>e.count-t.count),toolCallCount:g.length,assistantMessageCount:_,eventCount:N,totalUsage:w,model:l,durationMs:void 0!==u&&void 0!==c?c-u:void 0}}let q={...a.CLAUDE_CODE_METADATA,defaultRoot:h,async listSessions(t){let e=await O(t);for(let t of e)t.agent||(t.agent="claude-code");return e},async getSession(t,e){let i=await $(t,e);return i&&!i.agent&&(i.agent="claude-code"),i}};t.s(["DEFAULT_ROOT",0,h,"claudeCodeSource",0,q,"getSession",0,$,"invalidateClaudeCodeFile",0,j,"listSessions",0,O,"loadWorkflowAgentDetail",0,J,"summarizeSubagentLines",0,W],20629);let G=n.default.join(s.default.homedir(),".codex","sessions"),H=/^rollout-(\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2})-([0-9a-f-]+)\.jsonl$/;async function K(t){return i.promises.readdir(t).catch(()=>[])}async function Y(t){let e=[];for(let s of(await K(t))){if(!/^\d{4}$/.test(s))continue;let a=n.default.join(t,s);for(let t of(await K(a))){if(!/^\d{2}$/.test(t))continue;let s=n.default.join(a,t);for(let t of(await K(s))){if(!/^\d{2}$/.test(t))continue;let a=n.default.join(s,t);for(let t of(await K(a))){let s=H.exec(t);if(!s)continue;let o=n.default.join(a,t),r=await i.promises.stat(o).catch(()=>null);r&&e.push({filePath:o,sessionId:s[2],mtimeMs:r.mtimeMs,sizeBytes:r.size})}}}}return e}async function Z(t){let e=await i.promises.readFile(t,"utf8"),s=[];for(let t of e.split("\n")){let e=t.trim();if(e)try{s.push(JSON.parse(e))}catch{}}return s}function Q(t){return t.replace(/\s+/g," ").trim().slice(0,200)}function V(t){let e;return((e=t.search(/<oai-mem-citation\b/i))>=0?t.slice(0,e):t).trim()}function X(t){for(let e of t.blocks)if(e?.type==="text"&&"string"==typeof e.text)return e.text;return t.preview??""}function tt(t){for(let e=t.length-1;e>=0;e--)if("agent"===t[e].role)return e;return -1}function te(t,e){let i=V(t),s=V(e);return!i&&!s||!!i&&!!s&&i===s}function ti(t,e){let i,s,n,a,r,l,u,c,m,d,p,f,g=[],h={input:0,output:0,cacheRead:0,cacheWrite:0},w=0,M=0,v=[],k=0;for(let t of e){if("object"!=typeof t||null===t)continue;let e="string"==typeof t.timestamp?t.timestamp:void 0;if(e){i||(i=e),s=e;let t=Date.parse(e);Number.isFinite(t)&&v.push(t)}let y="string"==typeof t.type?t.type:"",N=t.payload??{},T="string"==typeof N.type?N.type:"";if("session_meta"===y){"string"==typeof N.cwd&&(n=N.cwd),void 0===c&&"string"==typeof N.thread_source&&(c=N.thread_source),void 0===m&&"string"==typeof N.session_id&&(m=N.session_id),void 0===d&&"string"==typeof N.parent_thread_id&&(d=N.parent_thread_id),void 0===p&&"string"==typeof N.agent_nickname&&(p=N.agent_nickname),void 0===f&&"string"==typeof N.agent_path&&(f=N.agent_path);continue}if("turn_context"===y){"string"==typeof N.cwd&&(n=N.cwd),"string"==typeof N.model&&(a=N.model);continue}if("event_msg"===y&&"token_count"===T){let t=N.info??null,e=t?.total_token_usage??null;e&&(h.input=ts(e.input_tokens)??h.input,h.output=ts(e.output_tokens)??h.output,h.cacheRead=ts(e.cached_input_tokens)??h.cacheRead);continue}if("event_msg"===y&&"user_message"===T){let i="string"==typeof N.message?N.message:"",s=Q(i),n=(0,o.isFrameworkInjectedUserInput)(i);i&&!n&&(r||(r=s),l=s,M+=1),g.push({index:k++,timestamp:e,role:"user",rawType:"event_msg/user_message",preview:s,blocks:i?[{type:"text",text:i}]:[],raw:t});continue}if("event_msg"===y&&"agent_message"===T){let i="string"==typeof N.message?N.message:"",s=Q(i),n=tt(g);if(n>=0){let o=g[n];if("response_item/message"===o.rawType&&te(X(o),i)){g[n]={...o,timestamp:e??o.timestamp,rawType:"event_msg/agent_message",preview:s,blocks:i?[{type:"text",text:i}]:[],model:a,raw:t},i&&(u=s);continue}if("event_msg/agent_message"===o.rawType&&te(X(o),i))continue}i&&(u=s),g.push({index:k++,timestamp:e,role:"agent",rawType:"event_msg/agent_message",preview:s,blocks:i?[{type:"text",text:i}]:[],model:a,raw:t});continue}if("response_item"===y&&"reasoning"===T){let i=(N.summary??[]).map(t=>"string"==typeof t.text?t.text:"").join("\n").trim();g.push({index:k++,timestamp:e,role:"agent-thinking",rawType:"response_item/reasoning",preview:Q(i),blocks:i?[{type:"thinking",thinking:i}]:[],model:a,raw:t});continue}if("response_item"===y&&"message"===T&&"assistant"===N.role){let i=(N.content??[]).map(t=>"string"==typeof t.text?t.text:"").join("\n").trim(),s=tt(g);if(s>=0&&te(X(g[s]),i))continue;let n=Q(i);i&&(u=n),g.push({index:k++,timestamp:e,role:"agent",rawType:"response_item/message",preview:n,blocks:i?[{type:"text",text:i}]:[],model:a,raw:t});continue}if("response_item"===y&&"function_call"===T){var _;let i="string"==typeof N.name?N.name:"(unknown)",s="string"==typeof N.call_id?N.call_id:void 0,n="string"==typeof N.arguments?N.arguments:"",o=function(t){if(!t)return null;try{return JSON.parse(t)}catch{return t}}(n);w+=1,g.push({index:k++,timestamp:e,role:"tool-call",rawType:"response_item/function_call",preview:`${i}(${(_=n).length<=80?_:_.slice(0,79)+"…"})`,blocks:[{type:"tool_use",id:s??`codex-${k}`,name:i,input:o}],toolName:i,toolUseId:s,model:a,raw:t});continue}if("response_item"===y&&"function_call_output"===T){let i="string"==typeof N.call_id?N.call_id:void 0,s="string"==typeof N.output?N.output:"",n=/process exited with code [1-9]/i.test(s);g.push({index:k++,timestamp:e,role:"tool-result",rawType:"response_item/function_call_output",preview:Q(s),blocks:[{type:"tool_result",tool_use_id:i??"",content:s,is_error:n}],toolUseId:i,toolResult:s,raw:t});continue}g.push({index:k++,timestamp:e,role:"meta",rawType:T?`${y}/${T}`:y,preview:"",blocks:[],raw:t})}if(h.input>0||h.output>0){let e=-1;for(let t=g.length-1;t>=0;t--){let i=g[t].role;if("agent"===i||"agent-thinking"===i||"tool-call"===i){e=t;break}}if(e>=0){let i=g[e];i.messageId=`codex-${t.sessionId}-total`,i.usage={input:h.input,output:h.output,cacheRead:h.cacheRead,cacheWrite:0}}}let N=i?Date.parse(i):void 0;if(void 0!==N&&Number.isFinite(N)){let t;for(let e of g){if(!e.timestamp)continue;let i=Date.parse(e.timestamp);Number.isFinite(i)&&(e.tOffsetMs=Math.max(0,i-N),void 0!==t&&(e.gapMs=Math.max(0,i-t)),t=i)}}let T=function(t){if(0===t.length)return[];let e=[...t].sort((t,e)=>t-e),i=[],s=e[0],n=e[0];for(let t=1;t<e.length;t++)e[t]-n>18e4&&(i.push({startMs:s,endMs:n}),s=e[t]),n=e[t];return i.push({startMs:s,endMs:n}),i}(v),b=T.reduce((t,e)=>t+(e.endMs-e.startMs),0),j=i&&s?Date.parse(s)-Date.parse(i):void 0,I=n?y(n):void 0,C=I?.projectName??"(unknown)",x=n?n.replace(/^\//,"-").replace(/\//g,"-"):"(unknown)";return{meta:{agent:"codex",id:t.sessionId,filePath:t.filePath,projectName:C,worktreeName:I?.worktreeName,repoName:I?.repoName,projectDir:x,sessionId:t.sessionId,firstTimestamp:i,lastTimestamp:s,durationMs:j&&Number.isFinite(j)?j:void 0,eventCount:g.length,model:a,cwd:n,totalUsage:h,status:"idle",firstUserPreview:r,lastUserPreview:l,lastAgentPreview:u,toolCallCount:w,turnCount:M,airTimeMs:b,activeSegments:T},events:g,threadSource:c,rootSessionId:m,parentThreadId:d,agentNickname:p,agentPath:f}}function ts(t){return"number"==typeof t&&Number.isFinite(t)?t:void 0}let tn=new Map,ta=new Map;async function to(t){let e=await Y(t),i=[];for(let t of e){let e=tn.get(t.filePath);if(e&&e.mtimeMs===t.mtimeMs&&e.sizeBytes===t.sizeBytes){i.push({file:t,meta:e.meta,threadSource:e.threadSource,rootSessionId:e.rootSessionId,parentThreadId:e.parentThreadId,agentNickname:e.agentNickname,agentPath:e.agentPath});continue}try{let e=await Z(t.filePath),s=ti(t,e);tn.set(t.filePath,{meta:s.meta,mtimeMs:t.mtimeMs,sizeBytes:t.sizeBytes,threadSource:s.threadSource,rootSessionId:s.rootSessionId,parentThreadId:s.parentThreadId,agentNickname:s.agentNickname,agentPath:s.agentPath}),i.push({file:t,meta:s.meta,threadSource:s.threadSource,rootSessionId:s.rootSessionId,parentThreadId:s.parentThreadId,agentNickname:s.agentNickname,agentPath:s.agentPath})}catch{}}return i}async function tr(t={}){let e=t.root??G,i=await to(e),s=new Map;for(let t of i){if("subagent"!==t.threadSource||!t.rootSessionId)continue;let e=s.get(t.rootSessionId);e?e.push(t):s.set(t.rootSessionId,[t])}let n=[];for(let t of i){if("subagent"===t.threadSource)continue;let e=s.get(t.meta.id);if(!e||0===e.length){n.push(t.meta);continue}let i={...t.meta,spawnedAgentCount:e.length,totalUsage:{input:t.meta.totalUsage.input+e.reduce((t,e)=>t+e.meta.totalUsage.input,0),output:t.meta.totalUsage.output+e.reduce((t,e)=>t+e.meta.totalUsage.output,0),cacheRead:t.meta.totalUsage.cacheRead+e.reduce((t,e)=>t+e.meta.totalUsage.cacheRead,0),cacheWrite:t.meta.totalUsage.cacheWrite+e.reduce((t,e)=>t+e.meta.totalUsage.cacheWrite,0)},toolCallCount:(t.meta.toolCallCount??0)+e.reduce((t,e)=>t+(e.meta.toolCallCount??0),0)};for(let t of e)t.meta.lastTimestamp&&(!i.lastTimestamp||t.meta.lastTimestamp>i.lastTimestamp)&&(i.lastTimestamp=t.meta.lastTimestamp);n.push(i)}return(n.sort((t,e)=>(e.firstTimestamp??"").localeCompare(t.firstTimestamp??"")),void 0!==t.limit)?n.slice(0,t.limit):n}async function tl(t,e={}){let i=e.root??G,s=await to(i),n=s.find(e=>e.meta.id===t&&"subagent"!==e.threadSource);if(!n){let e=s.find(e=>e.meta.id===t);if(!e)return null;let i=ta.get(e.file.filePath);if(i&&i.mtimeMs===e.file.mtimeMs&&i.sizeBytes===e.file.sizeBytes)return i.detail;let n=await Z(e.file.filePath),{meta:a,events:o}=ti(e.file,n),r={...a,events:o};return ta.set(e.file.filePath,{detail:r,mtimeMs:e.file.mtimeMs,sizeBytes:e.file.sizeBytes}),r}let a=n.file,o=ta.get(a.filePath);if(o&&o.mtimeMs===a.mtimeMs&&o.sizeBytes===a.sizeBytes)return o.detail;let r=await Z(a.filePath),{meta:l,events:u}=ti(a,r),c=s.filter(e=>"subagent"===e.threadSource&&e.rootSessionId===t),m=l.firstTimestamp?Date.parse(l.firstTimestamp):void 0,d=c.map(t=>{let e,i,s,n,a;return i=(e=t.meta).firstTimestamp?Date.parse(e.firstTimestamp):void 0,s=e.lastTimestamp?Date.parse(e.lastTimestamp):void 0,n=void 0!==i&&Number.isFinite(i)?i:void 0,a=void 0!==s&&Number.isFinite(s)?s:void 0,{agentId:e.id,agentType:t.agentNickname??t.agentPath??"subagent",description:t.agentPath??t.agentNickname??e.id,startMs:n,endMs:a,durationMs:e.durationMs,startTOffsetMs:void 0!==m&&void 0!==n?Math.max(0,n-m):void 0,endTOffsetMs:void 0!==m&&void 0!==a?Math.max(0,a-m):void 0,eventCount:e.eventCount,totalUsage:e.totalUsage,model:e.model,toolCallCount:e.toolCallCount,finalPreview:e.lastAgentPreview}}).sort((t,e)=>(t.startMs??0)-(e.startMs??0)),p={...l,events:u,...d.length>0?{subagents:d,spawnedAgentCount:d.length}:{}};return ta.set(a.filePath,{detail:p,mtimeMs:a.mtimeMs,sizeBytes:a.sizeBytes}),p}let tu=n.default.join(s.default.homedir(),".copilot","session-state");function tc(t){return"object"==typeof t&&null!==t?t:void 0}function tm(t){return"string"==typeof t?t:void 0}function td(t){return"number"==typeof t&&Number.isFinite(t)?t:void 0}function tp(t){return("string"==typeof t?t:JSON.stringify(t??"")).replace(/\s+/g," ").trim().slice(0,200)}function tf(t,e){return td(tc(t?.[e])?.tokenCount)}async function tg(t){let e=await i.promises.readdir(t,{withFileTypes:!0}).catch(()=>[]),s=[];for(let a of e){if(!a.isDirectory())continue;let e=n.default.join(t,a.name,"events.jsonl"),o=await i.promises.stat(e).catch(()=>null);o?.isFile()&&s.push({filePath:e,sessionId:a.name,mtimeMs:o.mtimeMs,sizeBytes:o.size})}return s}async function ty(t){let e=await i.promises.readFile(t,"utf8"),s=[];for(let t of e.split("\n")){let e=t.trim();if(e)try{s.push(JSON.parse(e))}catch{}}return s}function th(t,e){var i;let s,n,a,r,l,u,c,m,d,p,f,g,h=e.map(tc).filter(t=>void 0!==t),w=new Set;for(let t of h){if("tool.execution_start"!==t.type)continue;let e=tm(tc(t.data)?.toolCallId);e&&w.add(e)}let M=[],v=[],k={input:0,output:0,cacheRead:0,cacheWrite:0},_=0,N=0,T=0,b=!1,j=0;function I(t){M.push({index:j++,...t})}for(let t of h){let e=tm(t.type)??"",i=tc(t.data)??{},y=tm(t.timestamp);if(y){let t=Date.parse(y);Number.isFinite(t)&&(v.push(t),s=void 0===s?t:Math.min(s,t),n=void 0===n?t:Math.max(n,t))}if("session.start"===e){let s=tc(i.context);a=tm(s?.cwd)??a,r=tm(s?.repository)??r,l=tm(s?.branch)??l,I({timestamp:y,role:"meta",rawType:e,preview:"Copilot session started",blocks:[],raw:t});continue}if("session.model_change"===e){let t=tm(i.newModel);t&&"auto"!==t&&(u=t)}else"session.auto_mode_resolved"===e?u=tm(i.chosenModel)??u:("assistant.turn_start"===e||"assistant.message"===e)&&(u=tm(i.model)??u);if("system.message"===e){I({timestamp:y,role:"system",rawType:e,preview:"Copilot system instructions",blocks:[],raw:t});continue}if("user.message"===e){let s=tm(i.content)??"",n=tp(s);s&&!(0,o.isFrameworkInjectedUserInput)(s)&&(c??=n,m=n,N+=1),I({timestamp:y,role:"user",rawType:e,preview:n,blocks:s?[{type:"text",text:s}]:[],raw:t});continue}if("assistant.message"===e){let s=tm(i.content)??"";if(T+=td(i.outputTokens)??0,s){let n=tp(s);d=n,I({timestamp:y,role:"agent",rawType:e,messageId:tm(i.messageId),preview:n,blocks:[{type:"text",text:s}],model:u,raw:t})}for(let e of Array.isArray(i.toolRequests)?i.toolRequests:[]){let i=tc(e);if(!i)continue;let s=tm(i.toolCallId);if(s&&w.has(s))continue;let n=tm(i.name)??"(unknown)",a=tc(i.arguments)??i.arguments??null;_+=1,I({timestamp:y,role:"tool-call",rawType:"assistant.message/tool_request",preview:`${n}(${tp(a).slice(0,80)})`,blocks:[{type:"tool_use",id:s??`copilot-${j}`,name:n,input:a}],toolName:n,toolUseId:s,model:u,raw:t})}continue}if("tool.execution_start"===e){let s=tm(i.toolCallId),n=tm(i.toolName)??"(unknown)",a=i.arguments??null;_+=1,I({timestamp:y,role:"tool-call",rawType:e,preview:`${n}(${tp(a).slice(0,80)})`,blocks:[{type:"tool_use",id:s??`copilot-${j}`,name:n,input:a}],toolName:n,toolUseId:s,model:tm(i.model)??u,raw:t});continue}if("tool.execution_complete"===e){let s=tm(i.toolCallId),n=tc(i.result),a=n&&"content"in n?n.content:i.result,o=!1!==i.success;I({timestamp:y,role:"tool-result",rawType:e,preview:tp(a),blocks:[{type:"tool_result",tool_use_id:s??"",content:a,is_error:!o}],toolUseId:s,toolResult:i.result,raw:t});continue}if("assistant.reasoning"===e){let s=tm(i.content)??"";I({timestamp:y,role:"agent-thinking",rawType:e,preview:tp(s),blocks:s?[{type:"thinking",thinking:s}]:[],model:u,raw:t});continue}if("session.shutdown"===e){b=!0,u=tm(i.currentModel)??u;let t=tc(i.tokenDetails);k.input=tf(t,"input")??k.input,k.output=tf(t,"output")??T,k.cacheRead=tf(t,"cache_read")??k.cacheRead,k.cacheWrite=tf(t,"cache_write")??k.cacheWrite;let e=tc(i.codeChanges);p=td(e?.linesAdded),f=td(e?.linesRemoved);let s=e?.filesModified;g=Array.isArray(s)?s.length:void 0}I({timestamp:y,role:"meta",rawType:e,preview:"",blocks:[],raw:t})}if(0===k.output&&(k.output=T),k.input||k.output||k.cacheRead||k.cacheWrite){let e=[...M].reverse().find(t=>"agent"===t.role||"agent-thinking"===t.role||"tool-call"===t.role);e&&(e.messageId=`copilot-${t.sessionId}-total`,e.usage={...k})}let C=void 0===s?void 0:new Date(s).toISOString(),x=void 0===n?void 0:new Date(n).toISOString();if(void 0!==s){let t;for(let e of M){if(!e.timestamp)continue;let i=Date.parse(e.timestamp);Number.isFinite(i)&&(e.tOffsetMs=Math.max(0,i-s),void 0!==t&&(e.gapMs=Math.max(0,i-t)),t=i)}}let S=function(t){let e=[...new Set(t)].sort((t,e)=>t-e);if(0===e.length)return[];let i=[],s=e[0],n=s;for(let t=1;t<e.length;t++){let a=e[t];a-n>18e4&&(i.push({startMs:s,endMs:n}),s=a),n=a}return i.push({startMs:s,endMs:n}),i}(v),A=S.reduce((t,e)=>t+e.endMs-e.startMs,0),P=a?y(a):void 0,D=P?.repoName??r?.split("/").filter(Boolean).at(-1);return{meta:{agent:"copilot",id:t.sessionId,filePath:t.filePath,projectName:P?.projectName??a??"(unknown)",worktreeName:P?.worktreeName,repoName:D,projectDir:(i=a)?i.replace(/^\//,"-").replace(/\//g,"-"):"(unknown)",sessionId:t.sessionId,firstTimestamp:C,lastTimestamp:x,lastActivityMs:t.mtimeMs,durationMs:void 0!==s&&void 0!==n?n-s:void 0,eventCount:M.length,model:u,cwd:a,gitBranch:l,totalUsage:k,status:b||Date.now()-t.mtimeMs>18e4?"idle":"running",firstUserPreview:c,lastUserPreview:m,lastAgentPreview:d,toolCallCount:_,turnCount:N,linesAdded:p,linesRemoved:f,filesEdited:g,airTimeMs:A,activeSegments:S},events:M}}let tw=new Map,tM=new Map;async function tv(t){let e=await tg(t),i=[];for(let t of e){let e=tw.get(t.filePath);if(e&&e.mtimeMs===t.mtimeMs&&e.sizeBytes===t.sizeBytes){i.push({file:t,meta:e.meta});continue}try{let e=await ty(t.filePath),{meta:s}=th(t,e);tw.set(t.filePath,{meta:s,mtimeMs:t.mtimeMs,sizeBytes:t.sizeBytes}),i.push({file:t,meta:s})}catch{}}return i}async function tk(t={}){let e=t.root??tu,i=(await tv(e)).map(t=>t.meta);return i.sort((t,e)=>(e.firstTimestamp??"").localeCompare(t.firstTimestamp??"")),void 0===t.limit?i:i.slice(0,t.limit)}async function t_(t,e={}){let i=e.root??tu,s=(await tv(i)).find(e=>e.meta.id===t);if(!s)return null;let n=tM.get(s.file.filePath);if(n&&n.mtimeMs===s.file.mtimeMs&&n.sizeBytes===s.file.sizeBytes)return n.detail;let a=await ty(s.file.filePath),{meta:o,events:r}=th(s.file,a),l={...o,events:r};return tM.set(s.file.filePath,{detail:l,mtimeMs:s.file.mtimeMs,sizeBytes:s.file.sizeBytes}),l}let tN=n.default.join(s.default.homedir(),".gemini","tmp"),tT=n.default.join(s.default.homedir(),".gemini","projects.json"),tb=/^session-.+\.(jsonl|json)$/;async function tj(t){return i.promises.readdir(t).catch(()=>[])}async function tI(t){let e=[];for(let s of(await tj(t))){let a=n.default.join(t,s,"chats");for(let t of(await tj(a))){if(!tb.test(t))continue;let o=n.default.join(a,t),r=await i.promises.stat(o).catch(()=>null);if(!r||!r.isFile())continue;let l=t.replace(/\.(jsonl|json)$/,"").split("-").pop()??t;e.push({filePath:o,slug:s,filenameId:l,format:t.endsWith(".jsonl")?"jsonl":"legacy-json",mtimeMs:r.mtimeMs,sizeBytes:r.size})}}return e}let tC=null;async function tx(){let t,e=await i.promises.stat(tT).catch(()=>null);if(!e)return new Map;if(tC&&tC.mtimeMs===e.mtimeMs)return tC.slugToCwd;let s=await i.promises.readFile(tT,"utf8").catch(()=>"");try{t=JSON.parse(s)}catch{t={}}let n=new Map;for(let[e,i]of Object.entries(t.projects??{}))"string"==typeof i&&n.set(i,e);return tC={mtimeMs:e.mtimeMs,slugToCwd:n},n}function tS(t){return!!t&&"object"==typeof t&&"string"==typeof t.id&&"string"==typeof t.type}async function tA(t){let e=await i.promises.readFile(t.filePath,"utf8");if("legacy-json"===t.format){let t;try{t=JSON.parse(e)}catch{return{meta:{},messages:[]}}return{meta:{sessionId:"string"==typeof t.sessionId?t.sessionId:void 0,projectHash:"string"==typeof t.projectHash?t.projectHash:void 0,startTime:"string"==typeof t.startTime?t.startTime:void 0,lastUpdated:"string"==typeof t.lastUpdated?t.lastUpdated:void 0,summary:"string"==typeof t.summary?t.summary:void 0},messages:(Array.isArray(t.messages)?t.messages:[]).filter(tS)}}let s={},n=new Map,a=[];for(let t of e.split("\n")){let e,i=t.trim();if(i){var o,r;try{e=JSON.parse(i)}catch{continue}if((o=e)&&"object"==typeof o&&"$rewindTo"in o){let t=e.$rewindTo,i=a.indexOf(t);if(i>=0){for(let t of a.slice(i))n.delete(t);a.length=i}continue}if((r=e)&&"object"==typeof r&&"$set"in r){Object.assign(s,e.$set);continue}if(tS(e)){n.has(e.id)||a.push(e.id),n.set(e.id,e);continue}if("object"==typeof e&&null!==e){let t=e;"string"!=typeof t.sessionId||s.sessionId||(s.sessionId=t.sessionId,"string"==typeof t.projectHash&&(s.projectHash=t.projectHash),"string"==typeof t.startTime&&(s.startTime=t.startTime),"string"==typeof t.lastUpdated&&(s.lastUpdated=t.lastUpdated),"string"==typeof t.summary&&(s.summary=t.summary))}}}let l=[];for(let t of a){let e=n.get(t);e&&l.push(e)}return{meta:s,messages:l}}function tP(t){return t.replace(/\s+/g," ").trim().slice(0,200)}function tD(t){if(!t)return"";if("string"==typeof t)return t;let e=Array.isArray(t)?t:[t],i=[];for(let t of e){if(!t||"object"!=typeof t)continue;if("string"==typeof t.text){i.push(t.text);continue}let e=t.functionResponse;if(e){let t=e.response;"string"==typeof t?i.push(t):t&&"object"==typeof t&&("string"==typeof t.output?i.push(t.output):"string"==typeof t.error?i.push(`error: ${t.error}`):i.push(JSON.stringify(t)))}}return i.join("\n")}async function tU(t){let e,i,s,n,a,r,{meta:l,messages:u}=await tA(t),c=(await tx()).get(t.slug),m=[],d={input:0,output:0,cacheRead:0,cacheWrite:0},p=0,f=0,g=[],h=0;function w(t){if(m.push(t),t.timestamp&&"meta"!==t.role){e||(e=t.timestamp),i=t.timestamp;let s=Date.parse(t.timestamp);Number.isFinite(s)&&g.push(s)}}for(let t of u){let e=t.timestamp;if("user"===t.type){let i=tD(t.displayContent??t.content),s=tP(i),r=(0,o.isFrameworkInjectedUserInput)(i);i&&!r&&(n||(n=s),a=s,f+=1),w({index:h++,timestamp:e,role:"user",rawType:"gemini/user",preview:s,blocks:i?[{type:"text",text:i}]:[],messageId:t.id,raw:t});continue}if("gemini"===t.type){let i;"string"==typeof t.model&&(s=t.model);let n=tD(t.content),a=tP(n);if(n&&(r=a),t.tokens){let e=t.tokens,s={input:e.input??0,output:e.output??0,cacheRead:e.cached??0,cacheWrite:0};i=s,d.input+=s.input,d.output+=s.output,d.cacheRead+=s.cacheRead}for(let i of t.thoughts??[]){let t=[i.subject,i.description].filter(Boolean).join(": ");t&&w({index:h++,timestamp:i.timestamp??e,role:"agent-thinking",rawType:"gemini/thought",preview:tP(t),blocks:[{type:"thinking",thinking:t}],model:s,raw:i})}for(let o of(n?w({index:h++,timestamp:e,role:"agent",rawType:"gemini/agent",preview:a,blocks:[{type:"text",text:n}],messageId:t.id,model:s,usage:i,raw:t}):i&&w({index:h++,timestamp:e,role:"agent",rawType:"gemini/agent",preview:"",blocks:[],messageId:t.id,model:s,usage:i,raw:t}),t.toolCalls??[])){p+=1;let t=o.args?JSON.stringify(o.args):"";w({index:h++,timestamp:o.timestamp??e,role:"tool-call",rawType:"gemini/tool_call",preview:`${o.name}(${t.length<=80?t:t.slice(0,79)+"…"})`,blocks:[{type:"tool_use",id:o.id,name:o.name,input:o.args??{}}],toolName:o.name,toolUseId:o.id,model:s,raw:o});let i=(o.status??"").toLowerCase();if("success"===i||"error"===i||"cancelled"===i){let t=tD(o.result);w({index:h++,timestamp:o.timestamp??e,role:"tool-result",rawType:"gemini/tool_result",preview:tP(t),blocks:[{type:"tool_result",tool_use_id:o.id,content:t,is_error:"error"===i||"cancelled"===i}],toolUseId:o.id,toolResult:t,raw:o})}}continue}if("info"===t.type||"warning"===t.type||"error"===t.type){let i=tD(t.content);w({index:h++,timestamp:e,role:"meta",rawType:`gemini/${t.type}`,preview:tP(i),blocks:i?[{type:"text",text:i}]:[],raw:t});continue}}let M=e?Date.parse(e):void 0;if(void 0!==M&&Number.isFinite(M)){let t;for(let e of m){if(!e.timestamp)continue;let i=Date.parse(e.timestamp);Number.isFinite(i)&&(e.tOffsetMs=Math.max(0,i-M),void 0!==t&&(e.gapMs=Math.max(0,i-t)),t=i)}}let v=function(t){if(0===t.length)return[];let e=[...t].sort((t,e)=>t-e),i=[],s=e[0],n=e[0];for(let t=1;t<e.length;t++)e[t]-n>18e4&&(i.push({startMs:s,endMs:n}),s=e[t]),n=e[t];return i.push({startMs:s,endMs:n}),i}(g),k=v.reduce((t,e)=>t+(e.endMs-e.startMs),0),_=e&&i?Date.parse(i)-Date.parse(e):void 0,N=l.sessionId??t.filenameId,T=c?y(c):void 0,b=T?.projectName??t.slug,j=c?c.replace(/^\//,"-").replace(/\//g,"-"):t.slug;return{meta:{agent:"gemini",id:N,filePath:t.filePath,projectName:b,worktreeName:T?.worktreeName,repoName:T?.repoName,projectDir:j,sessionId:N,firstTimestamp:e,lastTimestamp:i,durationMs:_&&Number.isFinite(_)?_:void 0,eventCount:m.length,model:s,cwd:c,totalUsage:d,status:"idle",firstUserPreview:n,lastUserPreview:a,lastAgentPreview:r,toolCallCount:p,turnCount:f,airTimeMs:k,activeSegments:v},events:m}}let tR=new Map,tB=new Map;async function tz(t={}){let e=t.root??tN,i=await tI(e),s=[];for(let t of i){let e=tR.get(t.filePath);if(e&&e.mtimeMs===t.mtimeMs&&e.sizeBytes===t.sizeBytes){s.push(e.meta);continue}try{let{meta:e}=await tU(t);tR.set(t.filePath,{meta:e,mtimeMs:t.mtimeMs,sizeBytes:t.sizeBytes}),s.push(e)}catch{}}return(s.sort((t,e)=>(e.firstTimestamp??"").localeCompare(t.firstTimestamp??"")),void 0!==t.limit)?s.slice(0,t.limit):s}async function tF(t,e={}){let i,s=e.root??tN,n=await tI(s);for(let e of n)if(e.filenameId===t||t.startsWith(e.filenameId)){i=e;break}if(!i)for(let e of n){let{meta:s}=await tU(e).catch(()=>({meta:{id:""}}));if(s.id===t){i=e;break}}if(!i)return null;let a=tB.get(i.filePath);if(a&&a.mtimeMs===i.mtimeMs&&a.sizeBytes===i.sizeBytes)return a.detail;let{meta:o,events:r}=await tU(i),l={...o,events:r};return tB.set(i.filePath,{detail:l,mtimeMs:i.mtimeMs,sizeBytes:i.sizeBytes}),l}let tO=n.default.join(s.default.homedir(),".gemini","antigravity-cli");async function t$(t){return i.promises.readdir(t).catch(()=>[])}let tW=null;async function tE(t){let e=n.default.join(t,"history.jsonl"),s=await i.promises.stat(e).catch(()=>null);if(!s)return new Map;if(tW&&tW.mtimeMs===s.mtimeMs)return tW.slugToCwd;let a=await i.promises.readFile(e,"utf8").catch(()=>""),o=new Map;for(let t of a.split("\n")){let e=t.trim();if(e)try{let t=JSON.parse(e);t.conversationId&&t.workspace&&o.set(t.conversationId,t.workspace)}catch{}}return tW={mtimeMs:s.mtimeMs,slugToCwd:o},o}async function tL(t){let e=await tE(t),s=[],a=n.default.join(t,"brain");for(let t of(await t$(a))){let o=n.default.join(a,t,".system_generated","logs","transcript.jsonl"),r=await i.promises.stat(o).catch(()=>null);r&&r.isFile()&&s.push({filePath:o,conversationId:t,cwd:e.get(t),mtimeMs:r.mtimeMs,sizeBytes:r.size})}return s}function tJ(t){return t.replace(/\s+/g," ").trim().slice(0,200)}async function tq(t){let e,s,n,a,r,l,u=await i.promises.readFile(t.filePath,"utf8"),c=[],m=0,d=0,p=[],f=0;function g(t){if(c.push(t),t.timestamp&&"meta"!==t.role){e||(e=t.timestamp),s=t.timestamp;let i=Date.parse(t.timestamp);Number.isFinite(i)&&p.push(i)}}let h=[],w=[],M=new Map;for(let t of u.split("\n")){let e=t.trim();if(e)try{let t=JSON.parse(e),i=t.step_index;"number"==typeof i?M.has(i)?w[M.get(i)]=t:(M.set(i,w.length),w.push(t)):w.push(t)}catch{}}for(let t of w){let e=t.created_at||t.timestamp;if("USER_INPUT"===t.type){if("string"==typeof t.content){let e=t.content.match(/Model Selection` from .*? to (.*?)\.\s*No need to/);if(e){let t=e[1].trim();n=t=t.replace(/\s*\(.*?\)\s*$/,"").trim()}else{let e=t.content.match(/Model Selection` from .*? to ([^\n]+)/);if(e){let t=e[1].trim();t.endsWith(".")&&(t=t.slice(0,-1).trim()),n=t=t.replace(/\s*\(.*?\)\s*$/,"").trim()}}}let i=t.content||"",s=i.match(/<USER_REQUEST>([\s\S]*?)<\/USER_REQUEST>/);s&&(i=s[1].trim());let l=tJ(i),u=(0,o.isFrameworkInjectedUserInput)(i);i&&!u&&(a||(a=l),r=l,d+=1),g({index:f++,timestamp:e,role:"user",rawType:"antigravity/user",preview:l,blocks:i?[{type:"text",text:i}]:[],messageId:t.step_index?.toString(),raw:t});continue}if("PLANNER_RESPONSE"===t.type){let i=t.thinking,s=t.content;if(i&&g({index:f++,timestamp:e,role:"agent-thinking",rawType:"antigravity/thought",preview:tJ(i),blocks:[{type:"thinking",thinking:i}],model:n,raw:t}),s){let i=tJ(s);l=i,g({index:f++,timestamp:e,role:"agent",rawType:"antigravity/agent",preview:i,blocks:[{type:"text",text:s}],messageId:t.step_index?.toString(),model:n,raw:t})}let a=t.tool_calls||[];for(let i=0;i<a.length;i++){let s=a[i];m+=1;let o=`tool-${t.step_index}-${i}`,r=s.args?JSON.stringify(s.args):"";h.push({id:o,name:s.name}),g({index:f++,timestamp:e,role:"tool-call",rawType:"antigravity/tool_call",preview:`${s.name}(${r.length<=80?r:r.slice(0,79)+"…"})`,blocks:[{type:"tool_use",id:o,name:s.name,input:s.args||{}}],toolName:s.name,toolUseId:o,model:n,raw:s})}continue}if("MODEL"===t.source&&"PLANNER_RESPONSE"!==t.type&&"ERROR_MESSAGE"!==t.type&&h.length>0){let i=h.shift(),s=i?i.id:`tool-${t.step_index}-unknown`,n="string"==typeof t.content?t.content:JSON.stringify(t.content||""),a="ERROR"===t.status||"FAILED"===t.status||"CANCELED"===t.status||!!t.error;g({index:f++,timestamp:e,role:"tool-result",rawType:"antigravity/tool_result",preview:tJ(n),blocks:[{type:"tool_result",tool_use_id:s,content:n,is_error:a}],toolUseId:s,toolResult:n,raw:t});continue}let i=t.content||t.error||"";g({index:f++,timestamp:e,role:"meta",rawType:`antigravity/${t.type?.toLowerCase()||"unknown"}`,preview:tJ(i),blocks:i?[{type:"text",text:i}]:[],raw:t})}let v=e?Date.parse(e):void 0;if(void 0!==v&&Number.isFinite(v)){let t;for(let e of c){if(!e.timestamp)continue;let i=Date.parse(e.timestamp);Number.isFinite(i)&&(e.tOffsetMs=Math.max(0,i-v),void 0!==t&&(e.gapMs=Math.max(0,i-t)),t=i)}}let k=function(t){if(0===t.length)return[];let e=[...t].sort((t,e)=>t-e),i=[],s=e[0],n=e[0];for(let t=1;t<e.length;t++)e[t]-n>18e4&&(i.push({startMs:s,endMs:n}),s=e[t]),n=e[t];return i.push({startMs:s,endMs:n}),i}(p),_=k.reduce((t,e)=>t+(e.endMs-e.startMs),0),N=e&&s?Date.parse(s)-Date.parse(e):void 0,T=t.conversationId,b=t.cwd,j=b?y(b):void 0,I=j?.projectName??t.conversationId,C=b?b.replace(/^\//,"-").replace(/\//g,"-"):t.conversationId;return{meta:{agent:"antigravity",id:T,filePath:t.filePath,projectName:I,worktreeName:j?.worktreeName,repoName:j?.repoName,projectDir:C,sessionId:T,firstTimestamp:e,lastTimestamp:s,durationMs:N&&Number.isFinite(N)?N:void 0,eventCount:c.length,model:n,cwd:b,totalUsage:{input:0,output:0,cacheRead:0,cacheWrite:0},status:"idle",firstUserPreview:a,lastUserPreview:r,lastAgentPreview:l,toolCallCount:m,turnCount:d,airTimeMs:_,activeSegments:k},events:c}}let tG=new Map,tH=new Map;async function tK(t={}){let e=t.root??tO,i=await tL(e),s=[];for(let t of i){let e=tG.get(t.filePath);if(e&&e.mtimeMs===t.mtimeMs&&e.sizeBytes===t.sizeBytes&&e.cwd===t.cwd){s.push(e.meta);continue}try{let{meta:e}=await tq(t);tG.set(t.filePath,{meta:e,mtimeMs:t.mtimeMs,sizeBytes:t.sizeBytes,cwd:t.cwd}),s.push(e)}catch{}}return(s.sort((t,e)=>(e.firstTimestamp??"").localeCompare(t.firstTimestamp??"")),void 0!==t.limit)?s.slice(0,t.limit):s}async function tY(t,e={}){let i,s=e.root??tO;for(let e of(await tL(s)))if(e.conversationId===t){i=e;break}if(!i)return null;let n=tH.get(i.filePath);if(n&&n.mtimeMs===i.mtimeMs&&n.sizeBytes===i.sizeBytes&&n.cwd===i.cwd)return n.detail;let{meta:a,events:o}=await tq(i),r={...a,events:o};return tH.set(i.filePath,{detail:r,mtimeMs:i.mtimeMs,sizeBytes:i.sizeBytes,cwd:i.cwd}),r}let tZ=(e=s.default.homedir(),n.default.join(e,".config","Claude","local-agent-mode-sessions")),tQ=/^local_[0-9a-f-]+$/;async function tV(t){return i.promises.readdir(t).catch(()=>[])}async function tX(t){let e=await i.promises.stat(t).catch(()=>null);return e?e.mtimeMs:0}async function t0(t){let e=[];for(let s of(await tV(t))){let a=n.default.join(t,s);for(let t of(await tV(a))){let s=n.default.join(a,t),o=await tX(n.default.join(s,"spaces.json"));for(let t of(await tV(s))){if(!tQ.test(t))continue;let a=n.default.join(s,t,"audit.jsonl"),r=await i.promises.stat(a).catch(()=>null);if(!r||!r.isFile()||0===r.size)continue;let l=n.default.join(s,`${t}.json`),u=await tX(l);e.push({sessionId:t,auditPath:a,metaPath:l,workspaceDir:s,auditMtimeMs:r.mtimeMs,auditSize:r.size,metaMtimeMs:u,spacesMtimeMs:o})}}}return e}let t1=new Map;async function t2(t){let e=n.default.join(t,"spaces.json"),s=await i.promises.stat(e).catch(()=>null);if(!s)return new Map;let a=t1.get(t);if(a&&a.mtimeMs===s.mtimeMs)return a.spaceIdToPath;let o=await i.promises.readFile(e,"utf8").catch(()=>""),r=new Map;try{for(let t of JSON.parse(o).spaces??[]){let e="string"==typeof t.id?t.id:void 0,i=(Array.isArray(t.folders)?t.folders:[])[0],s="string"==typeof i?.path?i.path:void 0;e&&s&&r.set(e,s)}}catch{}return t1.set(t,{mtimeMs:s.mtimeMs,spaceIdToPath:r}),r}async function t8(t){let e=await i.promises.readFile(t,"utf8").catch(()=>"");if(!e)return{};try{let t=JSON.parse(e);return{spaceId:"string"==typeof t.spaceId?t.spaceId:void 0,userSelectedFolders:Array.isArray(t.userSelectedFolders)?t.userSelectedFolders.filter(t=>"string"==typeof t):void 0,cwd:"string"==typeof t.cwd?t.cwd:void 0,model:"string"==typeof t.model?t.model:void 0,title:"string"==typeof t.title?t.title:void 0,createdAt:"number"==typeof t.createdAt?t.createdAt:void 0,lastActivityAt:"number"==typeof t.lastActivityAt?t.lastActivityAt:void 0}}catch{return{}}}async function t4(t){let e=await i.promises.readFile(t,"utf8"),s=[];for(let t of e.split("\n")){let e=t.trim();if(e)try{s.push(JSON.parse(e))}catch{}}return s}async function t3(t){let e,[i,s,n]=await Promise.all([t4(t.auditPath),t8(t.metaPath),t2(t.workspaceDir)]),a=(e=new Map,i.forEach((t,s)=>{if("string"!=typeof t.uuid)return;let n=e.get(t.uuid);void 0===n?e.set(t.uuid,s):void 0===i[n].timestamp&&void 0!==t.timestamp&&e.set(t.uuid,s)}),i.filter((t,i)=>"string"!=typeof t.uuid||e.get(t.uuid)===i)),{mainLines:o,subagentGroups:r}=function(t){let e=[],i=new Map;for(let s of t){let t=s.parent_tool_use_id;if("string"==typeof t){let e=i.get(t);e?e.push(s):i.set(t,[s])}else e.push(s)}return{mainLines:e,subagentGroups:i}}(a),{meta:l,events:u}=p(o),c=function(t,e,i){if(0===t.size)return[];let s=new Map;for(let i of e){let e=i.message?.content;if(Array.isArray(e)){for(let n of e)if(n&&"object"==typeof n){if("tool_use"===n.type&&"Agent"===n.name&&"string"==typeof n.id){let t=n.input??{},e=s.get(n.id)??{};"string"==typeof i.uuid&&(e.parentUuid=i.uuid),"string"==typeof t.description&&(e.description=t.description),"string"==typeof t.subagent_type&&(e.agentType=t.subagent_type),"string"==typeof t.prompt&&(e.prompt=t.prompt),s.set(n.id,e)}else if("tool_result"===n.type&&"string"==typeof n.tool_use_id&&t.has(n.tool_use_id)){let t=s.get(n.tool_use_id)??{};t.finalText=function(t){if("string"==typeof t)return t;if(Array.isArray(t)){let e=[];for(let i of t)if(i&&"object"==typeof i&&"text"===i.type){let t=i.text;"string"==typeof t&&e.push(t)}if(e.length)return e.join("\n")}}(n.content)??t.finalText,s.set(n.tool_use_id,t)}}}}let n=[];for(let[e,a]of t){let t=W(a),o=s.get(e)??{},r=o.finalText??t.finalText,l=r?r.replace(/\s+/g," ").trim().slice(0,240):t.finalPreview,u=void 0!==i&&void 0!==t.startMs?Math.max(0,t.startMs-i):void 0,c=void 0!==i&&void 0!==t.endMs?Math.max(0,t.endMs-i):void 0,m=void 0!==t.startMs&&void 0!==t.endMs?t.endMs-t.startMs:void 0;n.push({agentId:e,agentType:o.agentType??"unknown",description:o.description??(o.prompt?o.prompt.replace(/\s+/g," ").trim().slice(0,80):"(no description)"),startMs:t.startMs,endMs:t.endMs,durationMs:m,startTOffsetMs:u,endTOffsetMs:c,eventCount:t.eventCount,totalUsage:t.totalUsage,parentUuid:o.parentUuid,parentToolUseId:e,runInBackground:!1,finalPreview:l,finalText:r,prompt:o.prompt,model:t.model,toolCalls:t.toolCalls,toolCallCount:t.toolCallCount,assistantMessageCount:t.assistantMessageCount})}return n.sort((t,e)=>(t.startMs??0)-(e.startMs??0)),n}(r,a,l.firstTimestamp?Date.parse(l.firstTimestamp):void 0),{projectName:m,projectDir:d,cwd:f}=function(t,e){let i;if(t.spaceId&&(i=e.get(t.spaceId)),!i&&t.userSelectedFolders&&t.userSelectedFolders.length>0&&(i=t.userSelectedFolders[0]),!i)return{projectName:"cowork:unspaced",projectDir:"cowork-unspaced"};let s=y(i);return{projectName:s.projectName,worktreeName:s.worktreeName,projectDir:i.replace(/^\//,"-").replace(/\//g,"-"),cwd:i}}(s,n);return{meta:{...l,agent:"cowork",id:t.sessionId,sessionId:t.sessionId,filePath:t.auditPath,projectName:m,projectDir:d,cwd:f??l.cwd,model:l.model??s.model},events:u,subagents:c}}function t9(t){return{auditMtimeMs:t.auditMtimeMs,auditSize:t.auditSize,metaMtimeMs:t.metaMtimeMs,spacesMtimeMs:t.spacesMtimeMs}}function t7(t,e){return t.auditMtimeMs===e.auditMtimeMs&&t.auditSize===e.auditSize&&t.metaMtimeMs===e.metaMtimeMs&&t.spacesMtimeMs===e.spacesMtimeMs}let t6=new Map,t5=new Map;async function et(t={}){let e=t.root??tZ,i=await t0(e),s=[];for(let t of i){let e=t9(t),i=t6.get(t.auditPath);if(i&&t7(i.key,e)){s.push(i.meta);continue}try{let{meta:i}=await t3(t);t6.set(t.auditPath,{meta:i,key:e}),s.push(i)}catch{}}return(s.sort((t,e)=>(e.firstTimestamp??"").localeCompare(t.firstTimestamp??"")),void 0!==t.limit)?s.slice(0,t.limit):s}async function ee(t,e={}){let i=e.root??tZ,s=(await t0(i)).find(e=>e.sessionId===t);if(!s)return null;let n=t9(s),a=t5.get(s.auditPath);if(a&&t7(a.key,n))return a.detail;let{meta:o,events:r,subagents:l}=await t3(s),u={...o,events:r,...l.length?{subagents:l}:{}};return t5.set(s.auditPath,{detail:u,key:n}),u}function ei(){let t=process.env.GROK_HOME||n.default.join(s.default.homedir(),".grok");return n.default.join(t,"sessions")}let es=n.default.join(s.default.homedir(),".grok","sessions");async function en(t){return i.promises.readdir(t).catch(()=>[])}async function ea(t){let e=await i.promises.readFile(t,"utf8").catch(()=>null);if(null==e)return null;try{return JSON.parse(e)}catch{return null}}async function eo(t,e){let s=n.default.join(t,".cwd"),a=await i.promises.readFile(s,"utf8").catch(()=>null);if(a&&a.trim())return a.trim();try{return decodeURIComponent(e)}catch{return e}}async function er(t){let e=[];for(let s of(await en(t))){if("session_search.sqlite"===s||s.startsWith("."))continue;let a=n.default.join(t,s),o=await i.promises.stat(a).catch(()=>null);if(!o?.isDirectory())continue;let r=await eo(a,s);for(let t of(await en(a))){if("prompt_history.jsonl"===t||t.startsWith("."))continue;let o=n.default.join(a,t),l=n.default.join(o,"summary.json"),u=n.default.join(o,"updates.jsonl"),c=n.default.join(o,"signals.json"),[m,d,p]=await Promise.all([i.promises.stat(l).catch(()=>null),i.promises.stat(u).catch(()=>null),i.promises.stat(c).catch(()=>null)]);if(!m?.isFile())continue;let f=Math.max(m.mtimeMs,d?.mtimeMs??0),g=(d?.size??0)+m.size;e.push({dirPath:o,updatesPath:u,summaryPath:l,signalsPath:p?.isFile()?c:null,sessionId:t,groupName:s,decodedCwd:r,mtimeMs:f,sizeBytes:g})}}return e}function el(){return{input:0,output:0,cacheRead:0,cacheWrite:0}}function eu(t){return t.replace(/\s+/g," ").trim().slice(0,200)}function ec(t){return t?"string"==typeof t?t:"string"==typeof t.text?t.text:"":""}async function em(t){let e,s,n,a,r,[l,u,c]=await Promise.all([ea(t.summaryPath),t.signalsPath?ea(t.signalsPath):Promise.resolve(null),i.promises.readFile(t.updatesPath,"utf8").catch(()=>"")]),m=l?.info?.id??t.sessionId,d=l?.info?.cwd??t.decodedCwd,p=l?.current_model_id??u?.primaryModelId??u?.modelsUsed?.[0],f=[],g=el();u?.contextTokensUsed&&u.contextTokensUsed>0&&(g.input=u.contextTokensUsed);let h=0,w=0,M=[],v=0,k=new Set,_=0;function N(t){f.push(t),function(t,i){if(!t||"meta"===i)return;e||(e=t),s=t;let n=Date.parse(t);Number.isFinite(n)&&M.push(n)}(t.timestamp,t.role)}let T=null;function b(){if(!T)return;let t=T.texts.join(""),e=eu(t);if("user"===T.kind){let i=!t||(0,o.isFrameworkInjectedUserInput)(t);t&&!i&&(n||(n=e),a=e,w+=1),t&&N({index:v++,timestamp:T.firstTs,role:"user",rawType:"grok/user_message",preview:e,blocks:[{type:"text",text:t}],messageId:T.promptId,raw:1===T.raw.length?T.raw[0]:T.raw})}else"agent"===T.kind?(t&&(r=e),t&&N({index:v++,timestamp:T.firstTs,role:"agent",rawType:"grok/agent_message",preview:e,blocks:[{type:"text",text:t}],messageId:T.promptId,model:T.model??p,raw:1===T.raw.length?T.raw[0]:T.raw})):"thought"===T.kind&&t&&N({index:v++,timestamp:T.firstTs,role:"agent-thinking",rawType:"grok/agent_thought",preview:e,blocks:[{type:"thinking",thinking:t}],messageId:T.promptId,model:T.model??p,raw:1===T.raw.length?T.raw[0]:T.raw});T=null}function j(t,e,i,s,n,a){(e||"user"!==t)&&(T&&T.kind!==t&&b(),T||(T={kind:t,texts:[],firstTs:i,lastTs:i,model:n,promptId:s,raw:[]}),e&&T.texts.push(e),T.lastTs=i??T.lastTs,n&&(T.model=n),s&&(T.promptId=s),T.raw.push(a))}for(let t of c.split("\n")){let e,i=t.trim();if(!i)continue;try{e=JSON.parse(i)}catch{continue}let s=e.params?.update;if(!s||"object"!=typeof s)continue;let n=s.sessionUpdate;if(!n)continue;let a=function(t){let e=t.params?._meta,i=e&&"number"==typeof e.agentTimestampMs?e.agentTimestampMs:void 0;if(null!=i&&Number.isFinite(i))return new Date(i).toISOString();let s=t.timestamp;if("number"==typeof s&&Number.isFinite(s))return new Date(s>1e12?s:1e3*s).toISOString()}(e),o=e.params?._meta??{},r=s._meta??{},l="string"==typeof o.promptId&&o.promptId||"string"==typeof r.promptId&&r.promptId||void 0,u="string"==typeof r.modelId&&r.modelId||"string"==typeof o.modelId&&o.modelId||void 0;u&&(p=u);let c=o.totalTokens;if("number"==typeof c&&c>_&&(_=c),"user_message_chunk"===n){j("user",ec(s.content),a,l,u,e);continue}if("agent_message_chunk"===n){j("agent",ec(s.content),a,l,u,e);continue}if("agent_thought_chunk"===n){j("thought",ec(s.content),a,l,u,e);continue}if(b(),"tool_call"===n){let t="string"==typeof s.toolCallId?s.toolCallId:`grok-${v}`,i=function(t){let e=t._meta;if(e&&"object"==typeof e){let t=e["x.ai/tool"];if(t&&"object"==typeof t){let e=t.name;if("string"==typeof e&&e)return e}}return"string"==typeof t.title&&t.title?(!t.title.includes(" ")&&!t.title.includes("`"),t.title):"tool"}(s),n=s.rawInput??{},o=n?JSON.stringify(n):"";h+=1,N({index:v++,timestamp:a,role:"tool-call",rawType:"grok/tool_call",preview:`${i}(${o.length<=80?o:o.slice(0,79)+"…"})`,blocks:[{type:"tool_use",id:t,name:i,input:n}],toolName:i,toolUseId:t,model:p,raw:e});continue}if("tool_call_update"===n){let t=function(t){let e=t.status;return"string"==typeof e?e:e&&"object"==typeof e&&"string"==typeof e.status?e.status:void 0}(s);if("completed"!==t&&"failed"!==t&&"error"!==t&&"cancelled"!==t)continue;let i="string"==typeof s.toolCallId?s.toolCallId:"";if(i&&k.has(i))continue;i&&k.add(i);let n=function(t){let e=t.content;if(Array.isArray(e)){let t=[];for(let i of e){if(!i||"object"!=typeof i)continue;if("string"==typeof i.text&&i.text){t.push(i.text);continue}let e=i.content;"string"==typeof e&&e?t.push(e):e&&"object"==typeof e&&"string"==typeof e.text&&t.push(e.text)}if(t.length)return t.join("\n")}let i=t.rawOutput;if(null==i)return"";if("string"==typeof i)return i;if("object"==typeof i){if("string"==typeof i.output_for_prompt)return i.output_for_prompt;if("string"==typeof i.summary_for_prompt)return i.summary_for_prompt;if(i.Content&&"object"==typeof i.Content){let t=i.Content;if("string"==typeof t.content)return t.content}if(i.TodosUpdated&&"object"==typeof i.TodosUpdated){let t=i.TodosUpdated;if("string"==typeof t.summary_for_prompt)return t.summary_for_prompt}if(Array.isArray(i.stdout)||Array.isArray(i.output))try{return JSON.stringify({type:i.type,exit_code:i.exit_code,note:"binary/stdout omitted"})}catch{return""}try{return JSON.stringify(i)}catch{return""}}return String(i)}(s),o="failed"===t||"error"===t||"cancelled"===t;N({index:v++,timestamp:a,role:"tool-result",rawType:"grok/tool_result",preview:eu(n),blocks:[{type:"tool_result",tool_use_id:i,content:n,is_error:o||void 0}],toolUseId:i||void 0,toolResult:n,raw:e});continue}if("turn_completed"===n)continue}b(),0===g.input&&_>0&&(g.input=_),!e&&l?.created_at&&(e=l.created_at),s||(s=l?.last_active_at??l?.updated_at??e),u?.toolCallCount!=null&&u.toolCallCount>h&&(h=u.toolCallCount),u?.turnCount!=null&&u.turnCount>w&&(w=u.turnCount);let I=e?Date.parse(e):void 0;if(void 0!==I&&Number.isFinite(I)){let t;for(let e of f){if(!e.timestamp)continue;let i=Date.parse(e.timestamp);Number.isFinite(i)&&(e.tOffsetMs=Math.max(0,i-I),void 0!==t&&(e.gapMs=Math.max(0,i-t)),t=i)}}let C=function(t){if(0===t.length)return[];let e=[...t].sort((t,e)=>t-e),i=[],s=e[0],n=e[0];for(let t=1;t<e.length;t++){let a=e[t];a-n>18e4&&(i.push({startMs:s,endMs:n}),s=a),n=a}return i.push({startMs:s,endMs:n}),i}(M),x=C.reduce((t,e)=>t+(e.endMs-e.startMs),0),S=e&&s?Date.parse(s)-Date.parse(e):void 0,A=d?y(d):void 0,P=A?.projectName??d??t.decodedCwd,D=t.groupName||(d?encodeURIComponent(d):"(unknown)");if(!n){let t=l?.generated_title||l?.session_summary;t&&(n=eu(t))}let U=await ed(t.dirPath);return{meta:{agent:"grok",id:m,filePath:t.updatesPath,projectName:P,worktreeName:A?.worktreeName,repoName:A?.repoName,projectDir:D,sessionId:m,firstTimestamp:e,lastTimestamp:s,lastActivityMs:s?Date.parse(s):void 0,durationMs:S&&Number.isFinite(S)?S:void 0,eventCount:f.length,model:p,cwd:d,gitBranch:l?.head_branch,agentName:l?.agent_name,totalUsage:g,status:"idle",firstUserPreview:n,lastUserPreview:a,lastAgentPreview:r,toolCallCount:h,turnCount:w,linesAdded:u?.agentLinesAdded,linesRemoved:u?.agentLinesRemoved,airTimeMs:x,activeSegments:C,...U>0?{spawnedAgentCount:U}:{}},events:f,sessionKind:l?.session_kind}}async function ed(t){let e=n.default.join(t,"subagents"),s=await en(e),a=0;for(let t of s){let s=await i.promises.stat(n.default.join(e,t)).catch(()=>null);s?.isDirectory()&&(a+=1)}return a}async function ep(t,e){let i=n.default.join(t.dirPath,"subagents"),s=await en(i),a=n.default.dirname(t.dirPath),o=[];for(let t of s){let s=n.default.join(i,t,"meta.json"),r=await ea(s);if(!r)continue;let l=r.child_session_id??r.subagent_id??t,u=n.default.join(a,l),[c,m]=await Promise.all([ea(n.default.join(u,"summary.json")),ea(n.default.join(u,"signals.json"))]),d=c?.created_at?Date.parse(c.created_at):void 0,p=c?.last_active_at??c?.updated_at,f=p?Date.parse(p):void 0,g=void 0!==d&&Number.isFinite(d)?d:void 0,y=void 0!==f&&Number.isFinite(f)?f:void 0,h=el();m?.contextTokensUsed&&(h.input=m.contextTokensUsed),o.push({agentId:l,agentType:r.subagent_type??c?.agent_name??"subagent",description:r.description&&r.description.trim()||c?.generated_title||c?.session_summary||l,startMs:g,endMs:y,durationMs:void 0!==g&&void 0!==y?Math.max(0,y-g):void 0,startTOffsetMs:void 0!==e&&void 0!==g?Math.max(0,g-e):void 0,endTOffsetMs:void 0!==e&&void 0!==y?Math.max(0,y-e):void 0,eventCount:c?.num_messages??c?.num_chat_messages??0,totalUsage:h,prompt:"string"==typeof r.prompt?r.prompt:void 0,model:c?.current_model_id??m?.primaryModelId,toolCallCount:m?.toolCallCount})}return o.sort((t,e)=>(t.startMs??0)-(e.startMs??0)),o}let ef=new Map,eg=new Map;async function ey(t={}){let e=t.root??ei(),i=await er(e),s=[];for(let t of i){let e=await ea(t.summaryPath);if(e?.session_kind==="subagent")continue;let i=ef.get(t.dirPath);if(i&&i.mtimeMs===t.mtimeMs&&i.sizeBytes===t.sizeBytes){s.push(i.meta);continue}try{let{meta:e,sessionKind:i}=await em(t);if("subagent"===i)continue;ef.set(t.dirPath,{meta:e,mtimeMs:t.mtimeMs,sizeBytes:t.sizeBytes}),s.push(e)}catch{}}return(s.sort((t,e)=>(e.firstTimestamp??"").localeCompare(t.firstTimestamp??"")),void 0!==t.limit)?s.slice(0,t.limit):s}async function eh(t,e={}){let i=e.root??ei(),s=await er(i),n=s.find(e=>e.sessionId===t);if(!n){for(let e of s)try{let{meta:i,events:s}=await em(e);if(i.id===t){let t={...i,events:s};return eg.set(e.dirPath,{detail:t,mtimeMs:e.mtimeMs,sizeBytes:e.sizeBytes}),t}}catch{}return null}let a=eg.get(n.dirPath);if(a&&a.mtimeMs===n.mtimeMs&&a.sizeBytes===n.sizeBytes)return a.detail;let{meta:o,events:r}=await em(n),l=o.firstTimestamp?Date.parse(o.firstTimestamp):void 0,u=await ep(n,void 0!==l&&Number.isFinite(l)?l:void 0),c={...o,events:r,...u.length>0?{subagents:u,spawnedAgentCount:u.length}:{}};return eg.set(n.dirPath,{detail:c,mtimeMs:n.mtimeMs,sizeBytes:n.sizeBytes}),ef.set(n.dirPath,{meta:{...o,...u.length>0?{spawnedAgentCount:u.length}:{}},mtimeMs:n.mtimeMs,sizeBytes:n.sizeBytes}),c}function ew(){return process.env.CCLENS_HOME||n.default.join(s.default.homedir(),".cclens")}function eM(...t){return n.default.join(ew(),...t)}function ev(t){j(t)}let ek=[q,{...a.CODEX_METADATA,defaultRoot:G,listSessions:async t=>tr(t),getSession:async t=>tl(t)},{...a.COPILOT_METADATA,defaultRoot:tu,listSessions:async t=>tk(t),getSession:async(t,e)=>t_(t,e)},{...a.GEMINI_METADATA,defaultRoot:tN,listSessions:async t=>tz(t),getSession:async t=>tF(t)},{...a.ANTIGRAVITY_METADATA,defaultRoot:tO,listSessions:async t=>tK(t),getSession:async t=>tY(t)},{...a.COWORK_METADATA,defaultRoot:tZ,listSessions:async t=>et(t),getSession:async t=>ee(t)},{...a.GROK_METADATA,defaultRoot:es,listSessions:async t=>ey(t),getSession:async(t,e)=>eh(t,e)}];async function e_(t={}){let e=await Promise.all(ek.map(e=>e.listSessions(t))),i=[];for(let t of e)i.push(...t);return(i.sort((t,e)=>(e.firstTimestamp??"").localeCompare(t.firstTimestamp??"")),void 0!==t.limit)?i.slice(0,t.limit):i}async function eN(t){for(let e of ek){let i=await e.getSession(t);if(i)return i}return null}function eT(){return eM("usage.jsonl")}function eb(t){let e=eT();(0,i.mkdirSync)(n.default.dirname(e),{recursive:!0}),(0,i.appendFileSync)(e,JSON.stringify(t)+"\n","utf8")}function ej(t){let e=eT();if(!(0,i.existsSync)(e))return;let s=(0,i.readFileSync)(e,"utf8").split("\n").filter(e=>{if(!e.trim())return!1;try{return JSON.parse(e).agent!==t}catch{return!0}});(0,i.mkdirSync)(n.default.dirname(e),{recursive:!0}),(0,i.writeFileSync)(e,s.join("\n")+(s.length?"\n":""),"utf8")}}];
1
+ module.exports=[39587,t=>{"use strict";let e={kind:"claude-code",displayName:"Claude Code",shortLabel:"Claude",accentColor:"var(--af-accent)",iconChar:"✦"},i={kind:"codex",displayName:"Codex (OpenAI)",shortLabel:"Codex",accentColor:"rgb(16, 163, 127)",iconChar:"◆"},s={kind:"copilot",displayName:"GitHub Copilot CLI",shortLabel:"Copilot",accentColor:"rgb(137, 87, 229)",iconChar:"∞"},n={kind:"gemini",displayName:"Gemini CLI",shortLabel:"Gemini",accentColor:"rgb(124, 92, 246)",iconChar:"✺"},a={kind:"antigravity",displayName:"Antigravity",shortLabel:"Agy",accentColor:"rgb(236, 72, 153)",iconChar:"⏃"},o={kind:"cowork",displayName:"Cowork",shortLabel:"Cowork",accentColor:"rgb(217, 119, 87)",iconChar:"⌘"},r={kind:"grok",displayName:"Grok Build",shortLabel:"Grok",accentColor:"rgb(100, 116, 139)",iconChar:"◈"},l=[e,i,s,n,a,o,{kind:"zai",displayName:"Z.ai",shortLabel:"Z.ai",accentColor:"rgb(59, 130, 246)",iconChar:"Z"},r,{kind:"command-code",displayName:"Command Code",shortLabel:"Cmd",accentColor:"rgb(132, 204, 22)",iconChar:">"}];l.map(t=>t.kind),t.s(["ANTIGRAVITY_METADATA",0,a,"CLAUDE_CODE_METADATA",0,e,"CODEX_METADATA",0,i,"COPILOT_METADATA",0,s,"COWORK_METADATA",0,o,"GEMINI_METADATA",0,n,"GROK_METADATA",0,r,"agentMetadata",0,l])},79357,t=>{"use strict";let e={input:0,output:0,cacheRead:0,cacheWrite:0},i=["/.claude/worktrees/","/.worktrees/","/claude/worktrees/"],s=/\/conductor\/workspaces\/[^/]+\/([^/]+)(?:\/|$)/;function n(t){for(let e of i){let i=t.lastIndexOf(e);if(i>=0)return{idx:i,marker:e}}return null}function a(t){let e=s.exec(t);if(!e)return null;let i=e[1],n=+!!e[0].endsWith("/");return{canonicalEndIdx:e.index+e[0].length-i.length-1-n,workspaceName:i}}let o="/.superset/worktrees/",r=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;function l(t){let e=t.indexOf(o);if(e<0)return null;let i=t.slice(e+o.length).split("/").filter(Boolean);if(0===i.length)return null;let s=r.test(i[0])?i[1]??i[0]:i[0];return{canonical:t.slice(0,e)+o+s,workspaceName:s}}function u(t){let e=t.replace(/\/{2,}/g,"/"),i=n(e);if(i)return e.slice(0,i.idx);let s=a(e);if(s)return e.slice(0,s.canonicalEndIdx);let o=l(e);return o?o.canonical:e}function c(t){let e=t.replace(/\/{2,}/g,"/"),i=n(e);if(i){let t=e.slice(i.idx+i.marker.length),s=t.indexOf("/");return s>=0?t.slice(0,s):t}let s=a(e);if(s)return s.workspaceName;let o=l(e);return o?o.workspaceName:null}function m(t){let e=u(t),i=e.replace(/\/+$/,"").split("/").filter(Boolean);return i[i.length-1]||e}function d(t){let i={sessionCount:t.length,totalDurationMs:0,totalAirTimeMs:0,totalTokens:{...e},totalToolCalls:0,totalTurns:0,avgTurnsPerSession:0,avgDurationMs:0,totalLinesAdded:0,totalLinesRemoved:0,totalFilesEdited:0};for(let e of t)i.totalDurationMs+=e.durationMs??0,i.totalAirTimeMs+=e.airTimeMs??e.durationMs??0,i.totalTokens.input+=e.totalUsage.input,i.totalTokens.output+=e.totalUsage.output,i.totalTokens.cacheRead+=e.totalUsage.cacheRead,i.totalTokens.cacheWrite+=e.totalUsage.cacheWrite,i.totalToolCalls+=e.toolCallCount??0,i.totalTurns+=e.turnCount??0,i.totalLinesAdded+=e.linesAdded??0,i.totalLinesRemoved+=e.linesRemoved??0,i.totalFilesEdited+=e.filesEdited??0;return t.length>0&&(i.avgTurnsPerSession=i.totalTurns/t.length,i.avgDurationMs=i.totalDurationMs/t.length),i}t.s(["canonicalProjectName",0,u,"computeBurstsFromSessions",0,function(t,e={}){let i=[];for(let e of t)e.activeSegments&&0!==e.activeSegments.length&&i.push({id:e.id,projectDir:e.projectDir,segments:e.activeSegments});return function(t,e){let i=e.minDurationMs??6e4,s=e.mergeGapMs??6e5,n=e.minActive??2,a=[];for(let e of t)for(let t of e.segments)t.endMs<=t.startMs||(a.push({ms:t.startMs,delta:1,sessionId:e.id}),a.push({ms:t.endMs,delta:-1,sessionId:e.id}));a.sort((t,e)=>t.ms-e.ms||e.delta-t.delta);let o=new Map,r=[],l=null;for(let t of a){if(1===t.delta)o.set(t.sessionId,(o.get(t.sessionId)??0)+1);else{let e=(o.get(t.sessionId)??0)-1;e<=0?o.delete(t.sessionId):o.set(t.sessionId,e)}let e=o.size;if(e>=n)if(l)for(let i of(l.endMs=t.ms,e>l.peak&&(l.peak=e),o.keys()))l.sessionIds.add(i);else l={startMs:t.ms,endMs:t.ms,peak:e,sessionIds:new Set(o.keys())};else l&&(l.endMs=t.ms,r.push(l),l=null)}l&&r.push(l);let u=r.filter(t=>t.endMs-t.startMs>=i),c=[];for(let t of u){let e=c[c.length-1];if(e&&t.startMs-e.endMs<=s)for(let i of(e.endMs=t.endMs,t.peak>e.peak&&(e.peak=t.peak),t.sessionIds))e.sessionIds.add(i);else c.push({startMs:t.startMs,endMs:t.endMs,peak:t.peak,sessionIds:new Set(t.sessionIds)})}let m=new Map;for(let e of t)m.set(e.id,e.projectDir);return c.map(t=>{let e=Array.from(new Set(Array.from(t.sessionIds).map(t=>m.get(t)).filter(t=>!!t)));return{startMs:t.startMs,endMs:t.endMs,peak:t.peak,sessionIds:Array.from(t.sessionIds),projectDirs:e,crossProject:e.length>1}})}(i,e)},"groupByProject",0,function(t){let e=new Map,i=function(t){let e=new Map;for(let i of t)i.repoName&&e.set(m(i.projectName),i.repoName);return t=>t.repoName??e.get(m(t.projectName))??m(t.projectName)}(t);for(let s of t){let t=i(s),n=e.get(t);n||(n={projectDir:t,projectName:t,sessions:[],rawProjectDirs:[],worktreeCount:0,metrics:d([]),perAgent:[],lastActiveMs:void 0},e.set(t,n)),n.sessions.push(s),n.rawProjectDirs.includes(s.projectDir)||n.rawProjectDirs.push(s.projectDir);let a=s.lastTimestamp?Date.parse(s.lastTimestamp):void 0;a&&(!n.lastActiveMs||a>n.lastActiveMs)&&(n.lastActiveMs=a)}for(let t of e.values()){t.metrics=d(t.sessions);let e=new Set;for(let i of t.sessions){let t=i.worktreeName??c(i.projectName)??(i.cwd?c(i.cwd):null);t&&e.add(t)}t.worktreeCount=e.size;let i=new Map;for(let e of t.sessions){let t=e.agent??"claude-code",s=i.get(t);s||(s={agent:t,sessions:0},i.set(t,s)),s.sessions+=1}t.perAgent=Array.from(i.values()).sort((t,e)=>e.sessions-t.sessions)}return Array.from(e.values()).sort((t,e)=>(e.lastActiveMs??0)-(t.lastActiveMs??0))},"projectKey",0,m,"toLocalDay",0,function(t){let e=new Date(t),i=e.getFullYear(),s=String(e.getMonth()+1).padStart(2,"0"),n=String(e.getDate()).padStart(2,"0");return`${i}-${s}-${n}`},"worktreeName",0,c])},36521,t=>{"use strict";let e=[/<system_instruction\b[^>]*>[\s\S]*?<\/system_instruction>\s*/gi],i=["<command-name>","<local-command-stdout>","<local-command-caveat>","<task-notification>","Base directory for this skill:","This session is being continued from a previous conversation","A session-scoped Stop hook is now active"];function s(t){if(!t)return t;let i=t;for(let t of e)i=i.replace(t,"");return i.trim()}t.s(["isFrameworkInjectedUserInput",0,function(t){if(!t)return!1;let e=s(t);if(!e)return!0;for(let t of i)if(e.startsWith(t))return!0;return!1},"stripFrameworkBoilerplate",0,s])},43427,20629,t=>{"use strict";let e;t.s(["agentSources",()=>ek,"appendUsageSnapshot",()=>eb,"cclensHome",()=>ew,"cclensPath",()=>eM,"getAnySession",()=>eN,"invalidateFile",()=>ev,"listAllSessions",()=>e_,"pruneUsageAgent",()=>ej],43427);var i=t.i(2157),s=t.i(60526),n=t.i(50227),a=t.i(39587),o=t.i(36521),r=t.i(79357);let l={input:0,output:0,cacheRead:0,cacheWrite:0};function u(t,e=200){let i=t.replace(/<[^>]+>/g,"").replace(/\s+/g," ").trim();return i.length>e?i.slice(0,e-1)+"…":i}let c=/^\s*<teammate-message\s+teammate_id="([^"]+)"[^>]*>([\s\S]*?)<\/teammate-message>/;function m(t){let e=t.match(c);if(!e)return;let i=e[1],s=e[2].trim(),n="message";if(s.startsWith("{"))try{let t=JSON.parse(s);"idle_notification"===t.type?n="idle-notification":"shutdown_request"===t.type?n="shutdown-request":"shutdown_approved"===t.type?n="shutdown-approved":"task_assignment"===t.type?n="task-assignment":"teammate_terminated"===t.type&&(n="teammate-terminated")}catch{}return{teammateId:i,body:s,kind:n}}function d(t){if(!t||"object"!=typeof t)return;let e=t=>"number"==typeof t?t:0;return{input:e(t.input_tokens),output:e(t.output_tokens),cacheRead:e(t.cache_read_input_tokens),cacheWrite:e(t.cache_creation_input_tokens)}}function p(t){let e,i,s,n,a,c,p,f,g,y,h,w=[];for(let e=0;e<t.length;e++){let i=function(t,e){if(!t||"object"!=typeof t)return null;let i=String(t.type??""),s=t.uuid,n=t.parentUuid??null,a=t.timestamp;if("assistant"===i){let o,r,l,c=t.message??{},m=c.content??[],p=d(c.usage),f=c.model,g=t.requestId,y=c.id,h=c.stop_reason,w=m[0],M="agent";return w?.type==="thinking"?(M="agent-thinking",o="[thinking] "+u(w.thinking,140)):w?.type==="tool_use"?(M="tool-call",r=w.name,l=w.id,o=`${w.name} `+u(JSON.stringify(w.input??{}),100)):o=w?.type==="text"?u(w.text,200):`<assistant:${w?.type??"empty"}>`,{index:e,uuid:s,parentUuid:n,timestamp:a,role:M,rawType:i,preview:o,blocks:m,usage:p,model:f,requestId:g,messageId:y,stopReason:h,toolName:r,toolUseId:l,raw:t}}if("user"===i){let r=(t.message??{}).content;if("string"==typeof r){let l=(0,o.stripFrameworkBoilerplate)(r),c=m(l);return{index:e,uuid:s,parentUuid:n,timestamp:a,role:"user",rawType:i,preview:u(l,200),blocks:l?[{type:"text",text:l}]:[],raw:t,teammateMessage:c}}if(Array.isArray(r)){let l=r[0];if(l?.type==="tool_result")return{index:e,uuid:s,parentUuid:n,timestamp:a,role:"tool-result",rawType:i,preview:u("string"==typeof l.content?l.content:JSON.stringify(l.content),200),blocks:r,toolUseId:l.tool_use_id,toolResult:t.toolUseResult,raw:t};let c=r.find(t=>t?.type==="text"),d=c?(0,o.stripFrameworkBoilerplate)(c.text):"",p=c?r.map(t=>t===c?{type:"text",text:d}:t):r,f=d?m(d):void 0;return{index:e,uuid:s,parentUuid:n,timestamp:a,role:"user",rawType:i,preview:d?u(d,200):u(JSON.stringify(r),200),blocks:p,raw:t,teammateMessage:f}}}if("attachment"===i){let o=t.attachment??{},r=String(o.type??"attachment"),l=`<attachment: ${r}>`;return"string"==typeof o.content&&o.content.length>0?l=`[${r}] `+u(o.content,140):Array.isArray(o.addedNames)&&(l=`[${r}] +${o.addedNames.length} names`),{index:e,uuid:s,parentUuid:n,timestamp:a,role:"system",rawType:i,preview:l,blocks:[{type:"text",text:JSON.stringify(o,null,2)}],attachmentType:r,raw:t}}return{index:e,uuid:s,parentUuid:n,timestamp:a,role:"meta",rawType:i||"unknown",preview:`${i}: ${u(JSON.stringify(t),140)}`,blocks:[{type:"text",text:JSON.stringify(t,null,2)}],raw:t}}(t[e],e);i&&w.push(i)}for(let t of w){if(!t.timestamp)continue;let s=Date.parse(t.timestamp);!Number.isNaN(s)&&((void 0===e||s<e)&&(e=s),(void 0===i||s>i)&&(i=s))}let M=void 0!==e?new Date(e).toISOString():void 0,v=void 0!==i?new Date(i).toISOString():void 0;for(let t of w){if(!t.timestamp)continue;let i=Date.parse(t.timestamp);Number.isNaN(i)||void 0!==e&&(t.tOffsetMs=Math.max(0,i-e))}let k=w.filter(t=>{let e;return t.timestamp&&("user"===(e=t.role)||"agent"===e||"agent-thinking"===e||"tool-call"===e||"tool-result"===e)}).map(t=>({e:t,ms:Date.parse(t.timestamp)})).filter(t=>!Number.isNaN(t.ms)).sort((t,e)=>t.ms-e.ms);for(let t=1;t<k.length;t++)k[t].e.gapMs=Math.max(0,k[t].ms-k[t-1].ms);let _=w.filter(t=>t.timestamp).map(t=>Date.parse(t.timestamp)).filter(t=>!Number.isNaN(t)).sort((t,e)=>t-e),N=[],T=0;if(_.length>0){let t=_[0],e=_[0];for(let i=1;i<_.length;i++){let s=_[i],n=s-e;n>18e4?(N.push({startMs:t,endMs:e}),t=s):n>0&&(T+=n),e=s}N.push({startMs:t,endMs:e})}let b=new Map,j=[];for(let t of w){if(!t.timestamp)continue;let e=Date.parse(t.timestamp);if(!Number.isNaN(e)){if("assistant"===t.rawType&&t.usage&&t.messageId){let i=b.get(t.messageId);i?(i.siblings.push(t),e<i.ms&&(i.rep=t,i.ms=e)):b.set(t.messageId,{rep:t,ms:e,siblings:[t]})}else if("system"===t.rawType){let i=t.raw;if(i?.subtype!=="compact_boundary")continue;let s=i.compactMetadata??{};j.push({ms:e,trigger:"manual"===s.trigger?"manual":"auto",preTokens:"number"==typeof s.preTokens?s.preTokens:0})}}}let I=[...b.values()].sort((t,e)=>t.ms-e.ms);j.sort((t,e)=>t.ms-e.ms);let C=0,x=0,S=(t,e)=>{for(let i of t.siblings)i.coldResume=e;C++,x+=e.writeTokens},A=new Set;for(let t of j){let e,i=I.find(e=>e.ms>t.ms&&(e.rep.usage?.cacheWrite??0)>=1e3);if(!i)continue;for(let i=I.length-1;i>=0;i--)if(I[i].ms<=t.ms){e=I[i].ms;break}let s=i.rep.usage,n=s.cacheWrite+s.cacheRead;S(i,{trigger:"compact",gapMs:void 0!==e?i.ms-e:0,writeTokens:s.cacheWrite,writeRatio:n>0?s.cacheWrite/n:0,compact:{trigger:t.trigger,preTokens:t.preTokens}}),A.add(i.rep.messageId)}for(let t=1;t<I.length;t++){let e=I[t-1],i=I[t];if(A.has(i.rep.messageId))continue;let s=i.rep.usage,n=s.cacheWrite+s.cacheRead,a=n>0?s.cacheWrite/n:0,o=i.ms-e.ms;o>3e5&&s.cacheWrite>=1e3&&a>=.3&&S(i,{trigger:"idle",gapMs:o,writeTokens:s.cacheWrite,writeRatio:a})}let P={...l},D=new Set,U="",R=!1,B=!1,z=0,F=0,O=0,$=0,W=new Set,E=new Map,L=void 0!==e?(0,r.toLocalDay)(e):void 0,J=t=>{let e;if(t){let i=Date.parse(t);Number.isNaN(i)||(e=(0,r.toLocalDay)(i))}if(!(e=e??L))return;let i=E.get(e);return i||(i={toolCalls:0,turns:0,tokens:{...l}},E.set(e,i)),i};for(let t of w){if("tool-call"===t.role){z++;let e=J(t.timestamp);e&&e.toolCalls++;let i=t.blocks.find(t=>t&&"tool_use"===t.type);if(i){let t=i.input??{};if("TeamCreate"===i.name&&(R=!0),"SendMessage"===i.name){let e="string"==typeof t.to?t.to:"";e&&"team-lead"!==e&&(B=!0)}let e="string"==typeof t.file_path?t.file_path:void 0;if("Edit"===i.name&&e){W.add(e);let i="string"==typeof t.old_string?t.old_string:"",s="string"==typeof t.new_string?t.new_string:"",n=i?i.split("\n").length:0,a=s?s.split("\n").length:0;O+=Math.max(0,a-n),$+=Math.max(0,n-a)}else if("Write"===i.name&&e){W.add(e);let i="string"==typeof t.content?t.content:"";O+=i?i.split("\n").length:0}}}if("user"===t.role){let e=function(t){let e=t?.content;if("string"==typeof e)return e;if(Array.isArray(e)){for(let t of e)if(t&&"object"==typeof t&&"text"===t.type&&"string"==typeof t.text)return t.text}return""}(t.raw?.message),i=(0,o.isFrameworkInjectedUserInput)(e),s=void 0!==t.teammateMessage&&!f;if(!i&&!s){g||(g=t.teammateMessage?t.teammateMessage.body:t.preview),F++;let e=J(t.timestamp);e&&e.turns++,h=t.preview}}"agent"===t.role&&(y=t.preview)}for(let e of t)if(e&&"object"==typeof e&&("string"!=typeof e.sessionId||U||(U=e.sessionId),"string"!=typeof e.cwd||n||(n=e.cwd),"string"!=typeof e.gitBranch||a||(a=e.gitBranch),"string"!=typeof e.entrypoint||c||(c=e.entrypoint),"string"!=typeof e.teamName||p||(p=e.teamName),"string"!=typeof e.agentName||f||(f=e.agentName),"assistant"===e.type)){let t=e.message;if(t){"string"!=typeof t.model||s||(s=t.model);let i="string"==typeof t.id?t.id:void 0;if(i&&D.has(i))continue;i&&D.add(i);let n=d(t.usage);if(n){P.input+=n.input,P.output+=n.output,P.cacheRead+=n.cacheRead,P.cacheWrite+=n.cacheWrite;let t=J("string"==typeof e.timestamp?e.timestamp:void 0);t&&(t.tokens.input+=n.input,t.tokens.output+=n.output,t.tokens.cacheRead+=n.cacheRead,t.tokens.cacheWrite+=n.cacheWrite)}}}return{events:w,meta:{sessionId:U,firstTimestamp:M,lastTimestamp:v,durationMs:void 0!==e&&void 0!==i?i-e:void 0,eventCount:w.length,model:s,cwd:n,gitBranch:a,entrypoint:c,totalUsage:P,status:"idle",firstUserPreview:g,lastUserPreview:h,lastAgentPreview:y,toolCallCount:z,turnCount:F,dailyBreakdown:Array.from(E.entries()).map(([t,e])=>({day:t,toolCalls:e.toolCalls,turns:e.turns,tokens:e.tokens})).sort((t,e)=>t.day.localeCompare(e.day)),airTimeMs:T,activeSegments:N,linesAdded:O,linesRemoved:$,filesEdited:W.size,coldResumeCount:C,cacheRebuildTokens:x,teamName:p,agentName:f,isTeamLead:void 0!==p&&void 0===f&&(R||B)}}}let f=/^(?:(?:https?|ssh|git):\/\/)?(?:[^@/]+@)?([^/:]+)[:/](.+?)(?:\.git)?\/?$/;function g(t){try{return(0,i.realpathSync)(t)}catch{return t}}function y(t){let e=g(t.replace(/\/{2,}/g,"/"));try{let t=function(t){let e;if(!t||!(0,n.isAbsolute)(t))return null;let a=(e=g((0,s.homedir)()),t===e||t.startsWith(`${e}/`)?e:void 0);for(let e=t.replace(/\/+$/,"")||t;;e=(0,n.dirname)(e)){if(e===a)return null;let t=function(t){let e=(0,n.join)(t,".git"),s=(0,i.statSync)(e,{throwIfNoEntry:!1});if(!s)return null;if(s.isDirectory())return{root:t,gitDir:e,commonDir:e};let a=function(t,e){let i=e.match(/^gitdir:\s*(.+)\s*$/m);if(!i)return;let s=i[1].trim();return(0,n.isAbsolute)(s)?s:(0,n.resolve)(t,s)}(t,(0,i.readFileSync)(e,"utf8"));return a?{root:t,gitDir:a,commonDir:function(t){let e=(0,n.join)(t,"commondir");if(!(0,i.existsSync)(e))return;let s=(0,i.readFileSync)(e,"utf8").trim();if(s)return(0,n.isAbsolute)(s)?s:(0,n.resolve)(t,s)}(a)}:{root:t}}(e);if(t)return t;if((0,n.dirname)(e)===e)return null}}(e);if(t){let s=g(function(t){if(t)return".git"===(0,n.basename)(t)?(0,n.dirname)(t):void 0}(t.commonDir)??t.root),a=g(t.root),o=s!==a?(0,r.worktreeName)(e)??(0,n.basename)(t.root):void 0,l={projectName:s};o&&(l.worktreeName=o);let u=function(t){let e=t.commonDir??t.gitDir;if(!e)return;let s=(0,n.join)(e,"config");if(!(0,i.existsSync)(s))return;let a=function(t){let e=!1;for(let i of t.split("\n")){let t=i.trim();if(t.startsWith("[")){e=/^\[remote\s+"origin"\]/.test(t);continue}if(!e)continue;let s=t.match(/^url\s*=\s*(.+)$/);if(s)return s[1].trim()}}((0,i.readFileSync)(s,"utf8"));return a?function(t){let e=t.match(f);if(!e)return;let i=e[1],s=e[2].split("/").filter(Boolean);if(s.length<2)return;let n=s[s.length-1],a=s.slice(0,-1).join("/");return{host:i,owner:a,name:n,url:t,webUrl:`https://${i}/${a}/${n}`}}(a):void 0}(t);return u&&(l.remote=u,l.repoName=u.name),l}}catch{}let a=(0,r.canonicalProjectName)(e),o=(0,r.worktreeName)(e)??void 0;return o?{projectName:a,worktreeName:o}:{projectName:a}}let h=n.default.join(s.default.homedir(),".claude","projects");function w(t){return t.startsWith("-")?"/"+t.slice(1).replace(/-/g,"/"):t}let M=n.default.join(s.default.homedir(),".cclens","runtime").replace(/[/.]/g,"-");async function v(t){let e=await i.promises.readFile(t,"utf8"),s=[];for(let t of e.split("\n")){let e=t.trim();if(e)try{s.push(JSON.parse(e))}catch{}}return s}function k(t){return t.replace(/\.jsonl$/i,"")}let _=new Map,N=new Map,T=new Map,b=null;function j(t){_.delete(t),N.delete(t),T.delete(t),b=null}async function I(t=h){let e;if(b&&b.root===t&&Date.now()-b.capturedAtMs<1e3)return b.files;try{e=await i.promises.readdir(t,{withFileTypes:!0})}catch{return[]}let s=e.filter(t=>t.isDirectory()&&t.name!==M).map(t=>t.name),a=(await Promise.all(s.map(async e=>{let s,a=n.default.join(t,e);try{s=await i.promises.readdir(a)}catch{return[]}let o=s.filter(t=>t.endsWith(".jsonl"));return(await Promise.all(o.map(async t=>{let s=n.default.join(a,t);try{let n=await i.promises.stat(s);return{projectDir:e,fileName:t,fullPath:s,mtimeMs:n.mtimeMs,sizeBytes:n.size}}catch{return null}}))).filter(t=>null!==t)}))).flat();return b={files:a,capturedAtMs:Date.now(),root:t},a}let C={input:0,output:0,cacheRead:0,cacheWrite:0};function x(t,e,i,s,n){for(let a of t){if(!a||"object"!=typeof a||"assistant"!==a.type)continue;let t=a.message;if(!t)continue;let o="string"==typeof t.id?t.id:void 0,l="string"==typeof a.requestId?a.requestId:void 0,u=null!=o&&null!=l?`${o}:${l}`:void 0;if(u&&e.has(u))continue;u&&e.add(u);let c=t.usage;if(c){let t=t=>"number"==typeof t?t:0,e=t(c.input_tokens),o=t(c.output_tokens),l=t(c.cache_read_input_tokens),u=t(c.cache_creation_input_tokens);if(i.input+=e,i.output+=o,i.cacheRead+=l,i.cacheWrite+=u,s){let t,i="string"==typeof a.timestamp?a.timestamp:void 0;if(i){let e=Date.parse(i);Number.isNaN(e)||(t=(0,r.toLocalDay)(e))}if(t=t??n){let i=s.get(t);i||(i={...C},s.set(t,i)),i.input+=e,i.output+=o,i.cacheRead+=l,i.cacheWrite+=u}}}}}async function S(t,e,s,a){let o,r={...C},l=new Set,u=new Map;x(t,l,r,u,a);let c=n.default.join(e,s,"subagents");try{o=await i.promises.readdir(c)}catch{return{usage:r,perDay:u}}let m=o.filter(t=>t.endsWith(".jsonl"));return 0===m.length||await Promise.all(m.map(async t=>{try{let e=await v(n.default.join(c,t));x(e,l,r,u,a)}catch{}})),{usage:r,perDay:u}}async function A(t,e){let s,a=n.default.join(t,e,"workflows");try{s=await i.promises.readdir(a)}catch{return{workflowCount:0,spawnedAgentCount:0,spans:[]}}let o=s.filter(t=>t.startsWith("wf_")&&t.endsWith(".json"));if(0===o.length)return{workflowCount:0,spawnedAgentCount:0,spans:[]};let r=0,l=[];return{workflowCount:(await Promise.all(o.map(async t=>{try{let e=JSON.parse(await i.promises.readFile(n.default.join(a,t),"utf8"));return"number"==typeof e.agentCount&&(r+=e.agentCount),"number"==typeof e.startTime&&"number"==typeof e.durationMs&&e.durationMs>0&&l.push({startMs:e.startTime,endMs:e.startTime+e.durationMs}),!0}catch{return!1}}))).filter(Boolean).length,spawnedAgentCount:r,spans:l}}async function P(t,e){let s;try{s=await i.promises.readdir(t,{withFileTypes:!0})}catch{return 0}return(await Promise.all(s.map(async s=>{let a=n.default.join(t,s.name);try{if(s.isDirectory())return e>0?await P(a,e-1):0;return(await i.promises.stat(a)).mtimeMs}catch{return 0}}))).reduce((t,e)=>Math.max(t,e),0)}async function D(t,e){let i=n.default.join(t,e),[s,a]=await Promise.all([P(n.default.join(i,"subagents"),2),P(n.default.join(i,"workflows"),0)]),o=Math.max(s,a);return o>0?o:void 0}async function U(t,e){let i=await D(n.default.dirname(e.fullPath),t.id),s=t.lastTimestamp?Date.parse(t.lastTimestamp):0,a=Math.max(Number.isFinite(s)?s:0,i??0);return a>0?{...t,lastActivityMs:a}:t}function R(t,e){if(0===e.length)return{};let i=[...t??[],...e].filter(t=>t.endMs>t.startMs).sort((t,e)=>t.startMs-e.startMs);if(0===i.length)return{};let s=[{...i[0]}];for(let t=1;t<i.length;t++){let e=i[t],n=s[s.length-1];e.startMs<=n.endMs?n.endMs=Math.max(n.endMs,e.endMs):s.push({...e})}let n=s.reduce((t,e)=>t+(e.endMs-e.startMs),0);return{activeSegments:s,airTimeMs:n}}async function B(t,e,i){let s=k(i.fileName),a=n.default.dirname(i.fullPath),o=t.firstTimestamp?(0,r.toLocalDay)(Date.parse(t.firstTimestamp)):void 0,{usage:l,perDay:u}=await S(e,a,s,o);t.totalUsage=l,t.dailyBreakdown=function(t,e,i){let s=new Map((t??[]).map(t=>[t.day,t])),n=[...new Set([...s.keys(),...e.keys()])].sort((t,e)=>t.localeCompare(e)).map(t=>({day:t,toolCalls:s.get(t)?.toolCalls??0,turns:s.get(t)?.turns??0,tokens:{...e.get(t)??C}}));if(n.length>0){let t=n.reduce((t,e)=>({input:t.input+e.tokens.input,output:t.output+e.tokens.output,cacheRead:t.cacheRead+e.tokens.cacheRead,cacheWrite:t.cacheWrite+e.tokens.cacheWrite}),{...C}),e=n[0].tokens;e.input+=i.input-t.input,e.output+=i.output-t.output,e.cacheRead+=i.cacheRead-t.cacheRead,e.cacheWrite+=i.cacheWrite-t.cacheWrite}return n}(t.dailyBreakdown,u,l)}async function z(t){let e=_.get(t.fullPath);if(e&&e.mtimeMs===t.mtimeMs&&e.sizeBytes===t.sizeBytes)return e.meta;try{let e=await v(t.fullPath),{meta:i}=p(e);await B(i,e,t);let s=k(t.fileName),a=n.default.dirname(t.fullPath),o=await A(a,s),r=i.cwd??w(t.projectDir),l=y(r),u={...i,id:s,filePath:t.fullPath,projectDir:t.projectDir,projectName:l.projectName,worktreeName:l.worktreeName,repoName:l.repoName,...o.workflowCount>0?{workflowCount:o.workflowCount,spawnedAgentCount:o.spawnedAgentCount}:{},...R(i.activeSegments,o.spans)};return _.set(t.fullPath,{meta:u,mtimeMs:t.mtimeMs,sizeBytes:t.sizeBytes}),u}catch{return null}}async function F(t){let e=N.get(t.fullPath);if(e&&e.mtimeMs===t.mtimeMs&&e.sizeBytes===t.sizeBytes)return e.detail;try{let e=await v(t.fullPath),{meta:i,events:s}=p(e),a=k(t.fileName);await B(i,e,t);let o=await A(n.default.dirname(t.fullPath),a),r=i.cwd??w(t.projectDir),l=y(r),u={...i,id:a,filePath:t.fullPath,projectDir:t.projectDir,projectName:l.projectName,worktreeName:l.worktreeName,repoName:l.repoName,events:s,...o.workflowCount>0?{workflowCount:o.workflowCount,spawnedAgentCount:o.spawnedAgentCount}:{},...R(i.activeSegments,o.spans)};N.set(t.fullPath,{detail:u,mtimeMs:t.mtimeMs,sizeBytes:t.sizeBytes});let c={...u};return delete c.events,_.set(t.fullPath,{meta:c,mtimeMs:t.mtimeMs,sizeBytes:t.sizeBytes}),u}catch{return null}}async function O(t={}){let{root:e=h,limit:i=500,projectDir:s}=t,n=await I(e);s&&(n=n.filter(t=>t.projectDir===s)),n.sort((t,e)=>e.mtimeMs-t.mtimeMs);let a=n.slice(0,i);return(await Promise.all(a.map(async t=>{let e=await z(t);return e?U(e,t):null}))).filter(t=>null!==t)}async function $(t,e={}){let{root:i=h}=e,s=(await I(i)).find(e=>k(e.fileName)===t);if(!s)return null;let a=await F(s);if(!a)return a;let o=a.firstTimestamp?Date.parse(a.firstTimestamp):void 0,r=n.default.join(n.default.dirname(s.fullPath),k(s.fileName),"subagents"),l=n.default.join(n.default.dirname(s.fullPath),k(s.fileName),"workflows"),[u,c]=await Promise.all([E(r,o,a.events),L(l,o,a.events)]),m=c.reduce((t,e)=>t+e.agentCount,0);return U({...a,subagents:u,workflows:c,...c.length>0?{workflowCount:c.length,spawnedAgentCount:m}:{}},s)}function W(t){let e,i,s,n,a,o={...C},r=new Set,l=0,u=0,c=0,m=new Map;for(let d of t){if(!d||"object"!=typeof d)continue;l++;let t="string"==typeof d.timestamp?Date.parse(d.timestamp):NaN;if(!Number.isNaN(t)&&((void 0===e||t<e)&&(e=t),(void 0===i||t>i)&&(i=t)),void 0===a&&"user"===d.type&&(null===d.parentUuid||void 0===d.parentUuid)){let t=d.message,e=t?.content;if("string"==typeof e)a=e;else if(Array.isArray(e)){let t=e.find(t=>t&&"object"==typeof t&&"text"===t.type);t?.text&&(a=t.text)}}if("assistant"===d.type){let t=d.message;if(!t)continue;n||"string"!=typeof t.model||(n=t.model);let e="string"==typeof t.id?t.id:void 0,i="string"==typeof d.requestId?d.requestId:void 0,a=null!=e&&null!=i?`${e}:${i}`:void 0,l=!a||!r.has(a);if(a&&l&&r.add(a),l){u++;let e=t.usage;if(e){let t=t=>"number"==typeof t?t:0;o.input+=t(e.input_tokens),o.output+=t(e.output_tokens),o.cacheRead+=t(e.cache_read_input_tokens),o.cacheWrite+=t(e.cache_creation_input_tokens)}}let p=t.content;if(Array.isArray(p))for(let t of p)t&&"object"==typeof t&&("text"===t.type&&"string"==typeof t.text?s=t.text:"tool_use"===t.type&&"string"==typeof t.name&&(c++,m.set(t.name,(m.get(t.name)??0)+1)))}}let d=Array.from(m.entries()).map(([t,e])=>({name:t,count:e})).sort((t,e)=>e.count-t.count);return{startMs:e,endMs:i,totalUsage:o,eventCount:l,finalPreview:void 0!==s?s.replace(/\s+/g," ").trim().slice(0,240):void 0,finalText:s,model:n,toolCalls:d,toolCallCount:c,assistantMessageCount:u,initialPrompt:a}}async function E(t,e,s){let a;try{a=await i.promises.readdir(t)}catch{return[]}let o=new Map,r=[];for(let t of s)if("tool-call"===t.role&&"Agent"===t.toolName)for(let e of t.blocks){if(e?.type!=="tool_use"||"Agent"!==e.name)continue;let i=e.input??{},s="string"==typeof i.description?i.description:void 0,n=t.timestamp?Date.parse(t.timestamp):void 0,a={toolUseId:e.id,parentUuid:t.uuid??"",runInBackground:!0===i.run_in_background,prompt:"string"==typeof i.prompt?i.prompt:void 0,tsMs:n};s&&o.set(s,a),void 0!==n&&r.push(a)}r.sort((t,e)=>(t.tsMs??0)-(e.tsMs??0));let l=a.filter(t=>t.startsWith("agent-")&&t.endsWith(".jsonl"));return(await Promise.all(l.map(async s=>{let a,l=s.replace(/^agent-/,"").replace(/\.jsonl$/,""),u=n.default.join(t,s),c=n.default.join(t,`agent-${l}.meta.json`),m={};try{let t=await i.promises.readFile(c,"utf8");m=JSON.parse(t)}catch{}try{a=await v(u)}catch{return null}let d=W(a),p=m.description&&m.description.trim().length>0?m.description:void 0,f=p?o.get(p):function(t){let e;if(void 0===t)return;let i=1/0;for(let s of r){if(void 0===s.tsMs)continue;let n=Math.abs(t-s.tsMs);n<i&&n<=2e3&&(e=s,i=n)}return e}(d.startMs),g=p??(d.initialPrompt?d.initialPrompt.replace(/\s+/g," ").trim().slice(0,80):"(no description)"),y=f?.prompt??d.initialPrompt,h=void 0!==e&&void 0!==d.startMs?Math.max(0,d.startMs-e):void 0,w=void 0!==e&&void 0!==d.endMs?Math.max(0,d.endMs-e):void 0,M=void 0!==d.startMs&&void 0!==d.endMs?d.endMs-d.startMs:void 0;return{agentId:l,agentType:m.agentType??"unknown",description:g,startMs:d.startMs,endMs:d.endMs,durationMs:M,startTOffsetMs:h,endTOffsetMs:w,eventCount:d.eventCount,totalUsage:d.totalUsage,parentUuid:f?.parentUuid,parentToolUseId:f?.toolUseId,runInBackground:f?.runInBackground,prompt:y,finalPreview:d.finalPreview,finalText:d.finalText,model:d.model,toolCalls:d.toolCalls,toolCallCount:d.toolCallCount,assistantMessageCount:d.assistantMessageCount}}))).filter(t=>null!==t).sort((t,e)=>(t.startMs??0)-(e.startMs??0))}async function L(t,e,s){let a;try{a=await i.promises.readdir(t)}catch{return[]}let o=a.filter(t=>t.startsWith("wf_")&&t.endsWith(".json"));if(0===o.length)return[];let r=[];for(let t of s){if("tool-call"!==t.role||"Workflow"!==t.toolName)continue;let e=t.timestamp?Date.parse(t.timestamp):NaN;if(!Number.isNaN(e))for(let i of t.blocks)i?.type==="tool_use"&&"Workflow"===i.name&&r.push({toolUseId:i.id,parentUuid:t.uuid??"",tsMs:e})}r.sort((t,e)=>t.tsMs-e.tsMs);let l=t=>"number"==typeof t?t:void 0,u=t=>"string"==typeof t&&t.length>0?t:void 0;return(await Promise.all(o.map(async s=>{let a;try{a=JSON.parse(await i.promises.readFile(n.default.join(t,s),"utf8"))}catch{return null}let o=u(a.runId)??s.replace(/\.json$/,""),c=l(a.startTime),m=l(a.durationMs),d=void 0!==c&&void 0!==m?c+m:void 0,p=void 0!==e&&void 0!==c?Math.max(0,c-e):void 0,f=void 0!==e&&void 0!==d?Math.max(0,d-e):void 0,g=Array.isArray(a.phases)?a.phases.filter(t=>!!t&&"object"==typeof t&&"string"==typeof t.title).map(t=>({title:t.title,detail:u(t.detail)})):[],y=Array.isArray(a.logs)?a.logs.filter(t=>"string"==typeof t):[],h=(t,e)=>{let i=u(t);return void 0===i?void 0:i.length>e?i.slice(0,e)+"…":i},w=(Array.isArray(a.workflowProgress)?a.workflowProgress:[]).filter(t=>!!t&&"object"==typeof t&&"workflow_agent"===t.type).map(t=>({index:l(t.index)??0,label:u(t.label)??"(agent)",phaseIndex:l(t.phaseIndex),phaseTitle:u(t.phaseTitle),agentId:u(t.agentId),model:u(t.model),state:u(t.state),startedAt:l(t.startedAt),durationMs:l(t.durationMs),tokens:l(t.tokens),toolCalls:l(t.toolCalls),lastToolSummary:h(t.lastToolSummary,200),promptPreview:h(t.promptPreview,600),resultPreview:h(t.resultPreview,600)})).sort((t,e)=>t.index-e.index),M=(t=>{let e,i;if(void 0===t||0===r.length)return;let s=1/0,n=1/0;for(let a of r){let o=Math.abs(t-a.tsMs);!(o>6e4)&&(o<n&&(i=a,n=o),a.tsMs<=t&&o<s&&(e=a,s=o))}return e??i})(c);return{runId:o,name:u(a.workflowName)??o,description:u(a.summary),status:u(a.status)??"unknown",agentCount:l(a.agentCount)??0,toolCallCount:l(a.totalToolCalls)??0,totalTokens:l(a.totalTokens)??0,durationMs:m,startMs:c,endMs:d,startTOffsetMs:p,endTOffsetMs:f,model:u(a.defaultModel),phases:g,logs:y,agents:w,parentToolUseId:M?.toolUseId,parentUuid:M?.parentUuid}}))).filter(t=>null!==t).sort((t,e)=>(t.startMs??0)-(e.startMs??0))}async function J(t,e,i,s={}){let a,o,r,l,u,c,{root:m=h}=s;if(!/^[\w.-]+$/.test(e)||!/^[\w.-]+$/.test(i))return null;let d=(await I(m)).find(e=>k(e.fileName)===t);if(!d)return null;let p=n.default.join(n.default.dirname(d.fullPath),t,"subagents","workflows",e,`agent-${i}.jsonl`);try{a=await v(p)}catch{return null}let f=new Set;for(let t of a){if(!t||"object"!=typeof t)continue;let e=t.message?.content;if(Array.isArray(e))for(let t of e)t&&"object"==typeof t&&"tool_result"===t.type&&!0===t.is_error&&"string"==typeof t.tool_use_id&&f.add(t.tool_use_id)}let g=[],y=new Map,w={...C},M=new Set,_=0,N=0;for(let t of a){if(!t||"object"!=typeof t)continue;N++;let e="string"==typeof t.timestamp?Date.parse(t.timestamp):NaN;if(!Number.isNaN(e)&&((void 0===u||e<u)&&(u=e),(void 0===c||e>c)&&(c=e)),void 0===o&&"user"===t.type&&(null===t.parentUuid||void 0===t.parentUuid)){let e=t.message?.content;if("string"==typeof e)o=e;else if(Array.isArray(e)){let t=e.find(t=>t&&"object"==typeof t&&"text"===t.type);t?.text&&(o=t.text)}}if("assistant"!==t.type)continue;let i=t.message;if(!i)continue;l||"string"!=typeof i.model||(l=i.model);let s="string"==typeof i.id?i.id:void 0,n="string"==typeof t.requestId?t.requestId:void 0,a=null!=s&&null!=n?`${s}:${n}`:void 0,m=!a||!M.has(a);if(a&&m&&M.add(a),m){_++;let t=i.usage;if(t){let e=t=>"number"==typeof t?t:0;w.input+=e(t.input_tokens),w.output+=e(t.output_tokens),w.cacheRead+=e(t.cache_read_input_tokens),w.cacheWrite+=e(t.cache_creation_input_tokens)}}let d=i.content;if(Array.isArray(d)){for(let t of d)if(t&&"object"==typeof t){if("text"===t.type&&"string"==typeof t.text)r=t.text;else if("tool_use"===t.type&&"string"==typeof t.name&&(y.set(t.name,(y.get(t.name)??0)+1),g.length<2e3)){let e=function(t){if(!t||"object"!=typeof t)return"";let e=e=>"string"==typeof t[e]?t[e]:void 0;return e("command")??e("file_path")??e("path")??e("pattern")??e("url")??e("description")??e("query")??e("prompt")??e("old_string")??JSON.stringify(t)}(t.input),i=e.replace(/\s+/g," ").trim().slice(0,160),s=e.length>4e3?e.slice(0,4e3)+"…":e;g.push({index:g.length+1,tool:t.name,preview:i,full:s.length>i.length||s.includes("\n")?s:void 0,isError:"string"==typeof t.id&&f.has(t.id)})}}}}return{agentId:i,prompt:o,finalText:r,steps:g,toolCalls:Array.from(y.entries()).map(([t,e])=>({name:t,count:e})).sort((t,e)=>e.count-t.count),toolCallCount:g.length,assistantMessageCount:_,eventCount:N,totalUsage:w,model:l,durationMs:void 0!==u&&void 0!==c?c-u:void 0}}let q={...a.CLAUDE_CODE_METADATA,defaultRoot:h,async listSessions(t){let e=await O(t);for(let t of e)t.agent||(t.agent="claude-code");return e},async getSession(t,e){let i=await $(t,e);return i&&!i.agent&&(i.agent="claude-code"),i}};t.s(["DEFAULT_ROOT",0,h,"claudeCodeSource",0,q,"getSession",0,$,"invalidateClaudeCodeFile",0,j,"listSessions",0,O,"loadWorkflowAgentDetail",0,J,"summarizeSubagentLines",0,W],20629);let G=n.default.join(s.default.homedir(),".codex","sessions"),H=/^rollout-(\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2})-([0-9a-f-]+)\.jsonl$/;async function K(t){return i.promises.readdir(t).catch(()=>[])}async function Y(t){let e=[];for(let s of(await K(t))){if(!/^\d{4}$/.test(s))continue;let a=n.default.join(t,s);for(let t of(await K(a))){if(!/^\d{2}$/.test(t))continue;let s=n.default.join(a,t);for(let t of(await K(s))){if(!/^\d{2}$/.test(t))continue;let a=n.default.join(s,t);for(let t of(await K(a))){let s=H.exec(t);if(!s)continue;let o=n.default.join(a,t),r=await i.promises.stat(o).catch(()=>null);r&&e.push({filePath:o,sessionId:s[2],mtimeMs:r.mtimeMs,sizeBytes:r.size})}}}}return e}async function Z(t){let e=await i.promises.readFile(t,"utf8"),s=[];for(let t of e.split("\n")){let e=t.trim();if(e)try{s.push(JSON.parse(e))}catch{}}return s}function Q(t){return t.replace(/\s+/g," ").trim().slice(0,200)}function V(t){let e;return((e=t.search(/<oai-mem-citation\b/i))>=0?t.slice(0,e):t).trim()}function X(t){for(let e of t.blocks)if(e?.type==="text"&&"string"==typeof e.text)return e.text;return t.preview??""}function tt(t){for(let e=t.length-1;e>=0;e--)if("agent"===t[e].role)return e;return -1}function te(t,e){let i=V(t),s=V(e);return!i&&!s||!!i&&!!s&&i===s}function ti(t,e){let i,s,n,a,r,l,u,c,m,d,p,f,g=[],h={input:0,output:0,cacheRead:0,cacheWrite:0},w=0,M=0,v=[],k=0;for(let t of e){if("object"!=typeof t||null===t)continue;let e="string"==typeof t.timestamp?t.timestamp:void 0;if(e){i||(i=e),s=e;let t=Date.parse(e);Number.isFinite(t)&&v.push(t)}let y="string"==typeof t.type?t.type:"",N=t.payload??{},T="string"==typeof N.type?N.type:"";if("session_meta"===y){"string"==typeof N.cwd&&(n=N.cwd),void 0===c&&"string"==typeof N.thread_source&&(c=N.thread_source),void 0===m&&"string"==typeof N.session_id&&(m=N.session_id),void 0===d&&"string"==typeof N.parent_thread_id&&(d=N.parent_thread_id),void 0===p&&"string"==typeof N.agent_nickname&&(p=N.agent_nickname),void 0===f&&"string"==typeof N.agent_path&&(f=N.agent_path);continue}if("turn_context"===y){"string"==typeof N.cwd&&(n=N.cwd),"string"==typeof N.model&&(a=N.model);continue}if("event_msg"===y&&"token_count"===T){let t=N.info??null,e=t?.total_token_usage??null;e&&(h.input=ts(e.input_tokens)??h.input,h.output=ts(e.output_tokens)??h.output,h.cacheRead=ts(e.cached_input_tokens)??h.cacheRead);continue}if("event_msg"===y&&"user_message"===T){let i="string"==typeof N.message?N.message:"",s=Q(i),n=(0,o.isFrameworkInjectedUserInput)(i);i&&!n&&(r||(r=s),l=s,M+=1),g.push({index:k++,timestamp:e,role:"user",rawType:"event_msg/user_message",preview:s,blocks:i?[{type:"text",text:i}]:[],raw:t});continue}if("event_msg"===y&&"agent_message"===T){let i="string"==typeof N.message?N.message:"",s=Q(i),n=tt(g);if(n>=0){let o=g[n];if("response_item/message"===o.rawType&&te(X(o),i)){g[n]={...o,timestamp:e??o.timestamp,rawType:"event_msg/agent_message",preview:s,blocks:i?[{type:"text",text:i}]:[],model:a,raw:t},i&&(u=s);continue}if("event_msg/agent_message"===o.rawType&&te(X(o),i))continue}i&&(u=s),g.push({index:k++,timestamp:e,role:"agent",rawType:"event_msg/agent_message",preview:s,blocks:i?[{type:"text",text:i}]:[],model:a,raw:t});continue}if("response_item"===y&&"reasoning"===T){let i=(N.summary??[]).map(t=>"string"==typeof t.text?t.text:"").join("\n").trim();g.push({index:k++,timestamp:e,role:"agent-thinking",rawType:"response_item/reasoning",preview:Q(i),blocks:i?[{type:"thinking",thinking:i}]:[],model:a,raw:t});continue}if("response_item"===y&&"message"===T&&"assistant"===N.role){let i=(N.content??[]).map(t=>"string"==typeof t.text?t.text:"").join("\n").trim(),s=tt(g);if(s>=0&&te(X(g[s]),i))continue;let n=Q(i);i&&(u=n),g.push({index:k++,timestamp:e,role:"agent",rawType:"response_item/message",preview:n,blocks:i?[{type:"text",text:i}]:[],model:a,raw:t});continue}if("response_item"===y&&"function_call"===T){var _;let i="string"==typeof N.name?N.name:"(unknown)",s="string"==typeof N.call_id?N.call_id:void 0,n="string"==typeof N.arguments?N.arguments:"",o=function(t){if(!t)return null;try{return JSON.parse(t)}catch{return t}}(n);w+=1,g.push({index:k++,timestamp:e,role:"tool-call",rawType:"response_item/function_call",preview:`${i}(${(_=n).length<=80?_:_.slice(0,79)+"…"})`,blocks:[{type:"tool_use",id:s??`codex-${k}`,name:i,input:o}],toolName:i,toolUseId:s,model:a,raw:t});continue}if("response_item"===y&&"function_call_output"===T){let i="string"==typeof N.call_id?N.call_id:void 0,s="string"==typeof N.output?N.output:"",n=/process exited with code [1-9]/i.test(s);g.push({index:k++,timestamp:e,role:"tool-result",rawType:"response_item/function_call_output",preview:Q(s),blocks:[{type:"tool_result",tool_use_id:i??"",content:s,is_error:n}],toolUseId:i,toolResult:s,raw:t});continue}g.push({index:k++,timestamp:e,role:"meta",rawType:T?`${y}/${T}`:y,preview:"",blocks:[],raw:t})}if(h.input>0||h.output>0){let e=-1;for(let t=g.length-1;t>=0;t--){let i=g[t].role;if("agent"===i||"agent-thinking"===i||"tool-call"===i){e=t;break}}if(e>=0){let i=g[e];i.messageId=`codex-${t.sessionId}-total`,i.usage={input:h.input,output:h.output,cacheRead:h.cacheRead,cacheWrite:0}}}let N=i?Date.parse(i):void 0;if(void 0!==N&&Number.isFinite(N)){let t;for(let e of g){if(!e.timestamp)continue;let i=Date.parse(e.timestamp);Number.isFinite(i)&&(e.tOffsetMs=Math.max(0,i-N),void 0!==t&&(e.gapMs=Math.max(0,i-t)),t=i)}}let T=function(t){if(0===t.length)return[];let e=[...t].sort((t,e)=>t-e),i=[],s=e[0],n=e[0];for(let t=1;t<e.length;t++)e[t]-n>18e4&&(i.push({startMs:s,endMs:n}),s=e[t]),n=e[t];return i.push({startMs:s,endMs:n}),i}(v),b=T.reduce((t,e)=>t+(e.endMs-e.startMs),0),j=i&&s?Date.parse(s)-Date.parse(i):void 0,I=n?y(n):void 0,C=I?.projectName??"(unknown)",x=n?n.replace(/^\//,"-").replace(/\//g,"-"):"(unknown)";return{meta:{agent:"codex",id:t.sessionId,filePath:t.filePath,projectName:C,worktreeName:I?.worktreeName,repoName:I?.repoName,projectDir:x,sessionId:t.sessionId,firstTimestamp:i,lastTimestamp:s,durationMs:j&&Number.isFinite(j)?j:void 0,eventCount:g.length,model:a,cwd:n,totalUsage:h,status:"idle",firstUserPreview:r,lastUserPreview:l,lastAgentPreview:u,toolCallCount:w,turnCount:M,airTimeMs:b,activeSegments:T},events:g,threadSource:c,rootSessionId:m,parentThreadId:d,agentNickname:p,agentPath:f}}function ts(t){return"number"==typeof t&&Number.isFinite(t)?t:void 0}let tn=new Map,ta=new Map;async function to(t){let e=await Y(t),i=[];for(let t of e){let e=tn.get(t.filePath);if(e&&e.mtimeMs===t.mtimeMs&&e.sizeBytes===t.sizeBytes){i.push({file:t,meta:e.meta,threadSource:e.threadSource,rootSessionId:e.rootSessionId,parentThreadId:e.parentThreadId,agentNickname:e.agentNickname,agentPath:e.agentPath});continue}try{let e=await Z(t.filePath),s=ti(t,e);tn.set(t.filePath,{meta:s.meta,mtimeMs:t.mtimeMs,sizeBytes:t.sizeBytes,threadSource:s.threadSource,rootSessionId:s.rootSessionId,parentThreadId:s.parentThreadId,agentNickname:s.agentNickname,agentPath:s.agentPath}),i.push({file:t,meta:s.meta,threadSource:s.threadSource,rootSessionId:s.rootSessionId,parentThreadId:s.parentThreadId,agentNickname:s.agentNickname,agentPath:s.agentPath})}catch{}}return i}async function tr(t={}){let e=t.root??G,i=await to(e),s=new Map;for(let t of i){if("subagent"!==t.threadSource||!t.rootSessionId)continue;let e=s.get(t.rootSessionId);e?e.push(t):s.set(t.rootSessionId,[t])}let n=[];for(let t of i){if("subagent"===t.threadSource)continue;let e=s.get(t.meta.id);if(!e||0===e.length){n.push(t.meta);continue}let i={...t.meta,spawnedAgentCount:e.length,totalUsage:{input:t.meta.totalUsage.input+e.reduce((t,e)=>t+e.meta.totalUsage.input,0),output:t.meta.totalUsage.output+e.reduce((t,e)=>t+e.meta.totalUsage.output,0),cacheRead:t.meta.totalUsage.cacheRead+e.reduce((t,e)=>t+e.meta.totalUsage.cacheRead,0),cacheWrite:t.meta.totalUsage.cacheWrite+e.reduce((t,e)=>t+e.meta.totalUsage.cacheWrite,0)},toolCallCount:(t.meta.toolCallCount??0)+e.reduce((t,e)=>t+(e.meta.toolCallCount??0),0)};for(let t of e)t.meta.lastTimestamp&&(!i.lastTimestamp||t.meta.lastTimestamp>i.lastTimestamp)&&(i.lastTimestamp=t.meta.lastTimestamp);n.push(i)}return(n.sort((t,e)=>(e.firstTimestamp??"").localeCompare(t.firstTimestamp??"")),void 0!==t.limit)?n.slice(0,t.limit):n}async function tl(t,e={}){let i=e.root??G,s=await to(i),n=s.find(e=>e.meta.id===t&&"subagent"!==e.threadSource);if(!n){let e=s.find(e=>e.meta.id===t);if(!e)return null;let i=ta.get(e.file.filePath);if(i&&i.mtimeMs===e.file.mtimeMs&&i.sizeBytes===e.file.sizeBytes)return i.detail;let n=await Z(e.file.filePath),{meta:a,events:o}=ti(e.file,n),r={...a,events:o};return ta.set(e.file.filePath,{detail:r,mtimeMs:e.file.mtimeMs,sizeBytes:e.file.sizeBytes}),r}let a=n.file,o=ta.get(a.filePath);if(o&&o.mtimeMs===a.mtimeMs&&o.sizeBytes===a.sizeBytes)return o.detail;let r=await Z(a.filePath),{meta:l,events:u}=ti(a,r),c=s.filter(e=>"subagent"===e.threadSource&&e.rootSessionId===t),m=l.firstTimestamp?Date.parse(l.firstTimestamp):void 0,d=c.map(t=>{let e,i,s,n,a;return i=(e=t.meta).firstTimestamp?Date.parse(e.firstTimestamp):void 0,s=e.lastTimestamp?Date.parse(e.lastTimestamp):void 0,n=void 0!==i&&Number.isFinite(i)?i:void 0,a=void 0!==s&&Number.isFinite(s)?s:void 0,{agentId:e.id,agentType:t.agentNickname??t.agentPath??"subagent",description:t.agentPath??t.agentNickname??e.id,startMs:n,endMs:a,durationMs:e.durationMs,startTOffsetMs:void 0!==m&&void 0!==n?Math.max(0,n-m):void 0,endTOffsetMs:void 0!==m&&void 0!==a?Math.max(0,a-m):void 0,eventCount:e.eventCount,totalUsage:e.totalUsage,model:e.model,toolCallCount:e.toolCallCount,finalPreview:e.lastAgentPreview}}).sort((t,e)=>(t.startMs??0)-(e.startMs??0)),p={...l,events:u,...d.length>0?{subagents:d,spawnedAgentCount:d.length}:{}};return ta.set(a.filePath,{detail:p,mtimeMs:a.mtimeMs,sizeBytes:a.sizeBytes}),p}let tu=n.default.join(s.default.homedir(),".copilot","session-state");function tc(t){return"object"==typeof t&&null!==t?t:void 0}function tm(t){return"string"==typeof t?t:void 0}function td(t){return"number"==typeof t&&Number.isFinite(t)?t:void 0}function tp(t){return("string"==typeof t?t:JSON.stringify(t??"")).replace(/\s+/g," ").trim().slice(0,200)}function tf(t,e){return td(tc(t?.[e])?.tokenCount)}async function tg(t){let e=await i.promises.readdir(t,{withFileTypes:!0}).catch(()=>[]),s=[];for(let a of e){if(!a.isDirectory())continue;let e=n.default.join(t,a.name,"events.jsonl"),o=await i.promises.stat(e).catch(()=>null);o?.isFile()&&s.push({filePath:e,sessionId:a.name,mtimeMs:o.mtimeMs,sizeBytes:o.size})}return s}async function ty(t){let e=await i.promises.readFile(t,"utf8"),s=[];for(let t of e.split("\n")){let e=t.trim();if(e)try{s.push(JSON.parse(e))}catch{}}return s}function th(t,e){var i;let s,n,a,r,l,u,c,m,d,p,f,g,h=e.map(tc).filter(t=>void 0!==t),w=new Set;for(let t of h){if("tool.execution_start"!==t.type)continue;let e=tm(tc(t.data)?.toolCallId);e&&w.add(e)}let M=[],v=[],k={input:0,output:0,cacheRead:0,cacheWrite:0},_=0,N=0,T=0,b=!1,j=0;function I(t){M.push({index:j++,...t})}for(let t of h){let e=tm(t.type)??"",i=tc(t.data)??{},y=tm(t.timestamp);if(y){let t=Date.parse(y);Number.isFinite(t)&&(v.push(t),s=void 0===s?t:Math.min(s,t),n=void 0===n?t:Math.max(n,t))}if("session.start"===e){let s=tc(i.context);a=tm(s?.cwd)??a,r=tm(s?.repository)??r,l=tm(s?.branch)??l,I({timestamp:y,role:"meta",rawType:e,preview:"Copilot session started",blocks:[],raw:t});continue}if("session.model_change"===e){let t=tm(i.newModel);t&&"auto"!==t&&(u=t)}else"session.auto_mode_resolved"===e?u=tm(i.chosenModel)??u:("assistant.turn_start"===e||"assistant.message"===e)&&(u=tm(i.model)??u);if("system.message"===e){I({timestamp:y,role:"system",rawType:e,preview:"Copilot system instructions",blocks:[],raw:t});continue}if("user.message"===e){let s=tm(i.content)??"",n=tp(s);s&&!(0,o.isFrameworkInjectedUserInput)(s)&&(c??=n,m=n,N+=1),I({timestamp:y,role:"user",rawType:e,preview:n,blocks:s?[{type:"text",text:s}]:[],raw:t});continue}if("assistant.message"===e){let s=tm(i.content)??"";if(T+=td(i.outputTokens)??0,s){let n=tp(s);d=n,I({timestamp:y,role:"agent",rawType:e,messageId:tm(i.messageId),preview:n,blocks:[{type:"text",text:s}],model:u,raw:t})}for(let e of Array.isArray(i.toolRequests)?i.toolRequests:[]){let i=tc(e);if(!i)continue;let s=tm(i.toolCallId);if(s&&w.has(s))continue;let n=tm(i.name)??"(unknown)",a=tc(i.arguments)??i.arguments??null;_+=1,I({timestamp:y,role:"tool-call",rawType:"assistant.message/tool_request",preview:`${n}(${tp(a).slice(0,80)})`,blocks:[{type:"tool_use",id:s??`copilot-${j}`,name:n,input:a}],toolName:n,toolUseId:s,model:u,raw:t})}continue}if("tool.execution_start"===e){let s=tm(i.toolCallId),n=tm(i.toolName)??"(unknown)",a=i.arguments??null;_+=1,I({timestamp:y,role:"tool-call",rawType:e,preview:`${n}(${tp(a).slice(0,80)})`,blocks:[{type:"tool_use",id:s??`copilot-${j}`,name:n,input:a}],toolName:n,toolUseId:s,model:tm(i.model)??u,raw:t});continue}if("tool.execution_complete"===e){let s=tm(i.toolCallId),n=tc(i.result),a=n&&"content"in n?n.content:i.result,o=!1!==i.success;I({timestamp:y,role:"tool-result",rawType:e,preview:tp(a),blocks:[{type:"tool_result",tool_use_id:s??"",content:a,is_error:!o}],toolUseId:s,toolResult:i.result,raw:t});continue}if("assistant.reasoning"===e){let s=tm(i.content)??"";I({timestamp:y,role:"agent-thinking",rawType:e,preview:tp(s),blocks:s?[{type:"thinking",thinking:s}]:[],model:u,raw:t});continue}if("session.shutdown"===e){b=!0,u=tm(i.currentModel)??u;let t=tc(i.tokenDetails);k.input=tf(t,"input")??k.input,k.output=tf(t,"output")??T,k.cacheRead=tf(t,"cache_read")??k.cacheRead,k.cacheWrite=tf(t,"cache_write")??k.cacheWrite;let e=tc(i.codeChanges);p=td(e?.linesAdded),f=td(e?.linesRemoved);let s=e?.filesModified;g=Array.isArray(s)?s.length:void 0}I({timestamp:y,role:"meta",rawType:e,preview:"",blocks:[],raw:t})}if(0===k.output&&(k.output=T),k.input||k.output||k.cacheRead||k.cacheWrite){let e=[...M].reverse().find(t=>"agent"===t.role||"agent-thinking"===t.role||"tool-call"===t.role);e&&(e.messageId=`copilot-${t.sessionId}-total`,e.usage={...k})}let C=void 0===s?void 0:new Date(s).toISOString(),x=void 0===n?void 0:new Date(n).toISOString();if(void 0!==s){let t;for(let e of M){if(!e.timestamp)continue;let i=Date.parse(e.timestamp);Number.isFinite(i)&&(e.tOffsetMs=Math.max(0,i-s),void 0!==t&&(e.gapMs=Math.max(0,i-t)),t=i)}}let S=function(t){let e=[...new Set(t)].sort((t,e)=>t-e);if(0===e.length)return[];let i=[],s=e[0],n=s;for(let t=1;t<e.length;t++){let a=e[t];a-n>18e4&&(i.push({startMs:s,endMs:n}),s=a),n=a}return i.push({startMs:s,endMs:n}),i}(v),A=S.reduce((t,e)=>t+e.endMs-e.startMs,0),P=a?y(a):void 0,D=P?.repoName??r?.split("/").filter(Boolean).at(-1);return{meta:{agent:"copilot",id:t.sessionId,filePath:t.filePath,projectName:P?.projectName??a??"(unknown)",worktreeName:P?.worktreeName,repoName:D,projectDir:(i=a)?i.replace(/^\//,"-").replace(/\//g,"-"):"(unknown)",sessionId:t.sessionId,firstTimestamp:C,lastTimestamp:x,lastActivityMs:t.mtimeMs,durationMs:void 0!==s&&void 0!==n?n-s:void 0,eventCount:M.length,model:u,cwd:a,gitBranch:l,totalUsage:k,status:b||Date.now()-t.mtimeMs>18e4?"idle":"running",firstUserPreview:c,lastUserPreview:m,lastAgentPreview:d,toolCallCount:_,turnCount:N,linesAdded:p,linesRemoved:f,filesEdited:g,airTimeMs:A,activeSegments:S},events:M}}let tw=new Map,tM=new Map;async function tv(t){let e=await tg(t),i=[];for(let t of e){let e=tw.get(t.filePath);if(e&&e.mtimeMs===t.mtimeMs&&e.sizeBytes===t.sizeBytes){i.push({file:t,meta:e.meta});continue}try{let e=await ty(t.filePath),{meta:s}=th(t,e);tw.set(t.filePath,{meta:s,mtimeMs:t.mtimeMs,sizeBytes:t.sizeBytes}),i.push({file:t,meta:s})}catch{}}return i}async function tk(t={}){let e=t.root??tu,i=(await tv(e)).map(t=>t.meta);return i.sort((t,e)=>(e.firstTimestamp??"").localeCompare(t.firstTimestamp??"")),void 0===t.limit?i:i.slice(0,t.limit)}async function t_(t,e={}){let i=e.root??tu,s=(await tv(i)).find(e=>e.meta.id===t);if(!s)return null;let n=tM.get(s.file.filePath);if(n&&n.mtimeMs===s.file.mtimeMs&&n.sizeBytes===s.file.sizeBytes)return n.detail;let a=await ty(s.file.filePath),{meta:o,events:r}=th(s.file,a),l={...o,events:r};return tM.set(s.file.filePath,{detail:l,mtimeMs:s.file.mtimeMs,sizeBytes:s.file.sizeBytes}),l}let tN=n.default.join(s.default.homedir(),".gemini","tmp"),tT=n.default.join(s.default.homedir(),".gemini","projects.json"),tb=/^session-.+\.(jsonl|json)$/;async function tj(t){return i.promises.readdir(t).catch(()=>[])}async function tI(t){let e=[];for(let s of(await tj(t))){let a=n.default.join(t,s,"chats");for(let t of(await tj(a))){if(!tb.test(t))continue;let o=n.default.join(a,t),r=await i.promises.stat(o).catch(()=>null);if(!r||!r.isFile())continue;let l=t.replace(/\.(jsonl|json)$/,"").split("-").pop()??t;e.push({filePath:o,slug:s,filenameId:l,format:t.endsWith(".jsonl")?"jsonl":"legacy-json",mtimeMs:r.mtimeMs,sizeBytes:r.size})}}return e}let tC=null;async function tx(){let t,e=await i.promises.stat(tT).catch(()=>null);if(!e)return new Map;if(tC&&tC.mtimeMs===e.mtimeMs)return tC.slugToCwd;let s=await i.promises.readFile(tT,"utf8").catch(()=>"");try{t=JSON.parse(s)}catch{t={}}let n=new Map;for(let[e,i]of Object.entries(t.projects??{}))"string"==typeof i&&n.set(i,e);return tC={mtimeMs:e.mtimeMs,slugToCwd:n},n}function tS(t){return!!t&&"object"==typeof t&&"string"==typeof t.id&&"string"==typeof t.type}async function tA(t){let e=await i.promises.readFile(t.filePath,"utf8");if("legacy-json"===t.format){let t;try{t=JSON.parse(e)}catch{return{meta:{},messages:[]}}return{meta:{sessionId:"string"==typeof t.sessionId?t.sessionId:void 0,projectHash:"string"==typeof t.projectHash?t.projectHash:void 0,startTime:"string"==typeof t.startTime?t.startTime:void 0,lastUpdated:"string"==typeof t.lastUpdated?t.lastUpdated:void 0,summary:"string"==typeof t.summary?t.summary:void 0},messages:(Array.isArray(t.messages)?t.messages:[]).filter(tS)}}let s={},n=new Map,a=[];for(let t of e.split("\n")){let e,i=t.trim();if(i){var o,r;try{e=JSON.parse(i)}catch{continue}if((o=e)&&"object"==typeof o&&"$rewindTo"in o){let t=e.$rewindTo,i=a.indexOf(t);if(i>=0){for(let t of a.slice(i))n.delete(t);a.length=i}continue}if((r=e)&&"object"==typeof r&&"$set"in r){Object.assign(s,e.$set);continue}if(tS(e)){n.has(e.id)||a.push(e.id),n.set(e.id,e);continue}if("object"==typeof e&&null!==e){let t=e;"string"!=typeof t.sessionId||s.sessionId||(s.sessionId=t.sessionId,"string"==typeof t.projectHash&&(s.projectHash=t.projectHash),"string"==typeof t.startTime&&(s.startTime=t.startTime),"string"==typeof t.lastUpdated&&(s.lastUpdated=t.lastUpdated),"string"==typeof t.summary&&(s.summary=t.summary))}}}let l=[];for(let t of a){let e=n.get(t);e&&l.push(e)}return{meta:s,messages:l}}function tP(t){return t.replace(/\s+/g," ").trim().slice(0,200)}function tD(t){if(!t)return"";if("string"==typeof t)return t;let e=Array.isArray(t)?t:[t],i=[];for(let t of e){if(!t||"object"!=typeof t)continue;if("string"==typeof t.text){i.push(t.text);continue}let e=t.functionResponse;if(e){let t=e.response;"string"==typeof t?i.push(t):t&&"object"==typeof t&&("string"==typeof t.output?i.push(t.output):"string"==typeof t.error?i.push(`error: ${t.error}`):i.push(JSON.stringify(t)))}}return i.join("\n")}async function tU(t){let e,i,s,n,a,r,{meta:l,messages:u}=await tA(t),c=(await tx()).get(t.slug),m=[],d={input:0,output:0,cacheRead:0,cacheWrite:0},p=0,f=0,g=[],h=0;function w(t){if(m.push(t),t.timestamp&&"meta"!==t.role){e||(e=t.timestamp),i=t.timestamp;let s=Date.parse(t.timestamp);Number.isFinite(s)&&g.push(s)}}for(let t of u){let e=t.timestamp;if("user"===t.type){let i=tD(t.displayContent??t.content),s=tP(i),r=(0,o.isFrameworkInjectedUserInput)(i);i&&!r&&(n||(n=s),a=s,f+=1),w({index:h++,timestamp:e,role:"user",rawType:"gemini/user",preview:s,blocks:i?[{type:"text",text:i}]:[],messageId:t.id,raw:t});continue}if("gemini"===t.type){let i;"string"==typeof t.model&&(s=t.model);let n=tD(t.content),a=tP(n);if(n&&(r=a),t.tokens){let e=t.tokens,s={input:e.input??0,output:e.output??0,cacheRead:e.cached??0,cacheWrite:0};i=s,d.input+=s.input,d.output+=s.output,d.cacheRead+=s.cacheRead}for(let i of t.thoughts??[]){let t=[i.subject,i.description].filter(Boolean).join(": ");t&&w({index:h++,timestamp:i.timestamp??e,role:"agent-thinking",rawType:"gemini/thought",preview:tP(t),blocks:[{type:"thinking",thinking:t}],model:s,raw:i})}for(let o of(n?w({index:h++,timestamp:e,role:"agent",rawType:"gemini/agent",preview:a,blocks:[{type:"text",text:n}],messageId:t.id,model:s,usage:i,raw:t}):i&&w({index:h++,timestamp:e,role:"agent",rawType:"gemini/agent",preview:"",blocks:[],messageId:t.id,model:s,usage:i,raw:t}),t.toolCalls??[])){p+=1;let t=o.args?JSON.stringify(o.args):"";w({index:h++,timestamp:o.timestamp??e,role:"tool-call",rawType:"gemini/tool_call",preview:`${o.name}(${t.length<=80?t:t.slice(0,79)+"…"})`,blocks:[{type:"tool_use",id:o.id,name:o.name,input:o.args??{}}],toolName:o.name,toolUseId:o.id,model:s,raw:o});let i=(o.status??"").toLowerCase();if("success"===i||"error"===i||"cancelled"===i){let t=tD(o.result);w({index:h++,timestamp:o.timestamp??e,role:"tool-result",rawType:"gemini/tool_result",preview:tP(t),blocks:[{type:"tool_result",tool_use_id:o.id,content:t,is_error:"error"===i||"cancelled"===i}],toolUseId:o.id,toolResult:t,raw:o})}}continue}if("info"===t.type||"warning"===t.type||"error"===t.type){let i=tD(t.content);w({index:h++,timestamp:e,role:"meta",rawType:`gemini/${t.type}`,preview:tP(i),blocks:i?[{type:"text",text:i}]:[],raw:t});continue}}let M=e?Date.parse(e):void 0;if(void 0!==M&&Number.isFinite(M)){let t;for(let e of m){if(!e.timestamp)continue;let i=Date.parse(e.timestamp);Number.isFinite(i)&&(e.tOffsetMs=Math.max(0,i-M),void 0!==t&&(e.gapMs=Math.max(0,i-t)),t=i)}}let v=function(t){if(0===t.length)return[];let e=[...t].sort((t,e)=>t-e),i=[],s=e[0],n=e[0];for(let t=1;t<e.length;t++)e[t]-n>18e4&&(i.push({startMs:s,endMs:n}),s=e[t]),n=e[t];return i.push({startMs:s,endMs:n}),i}(g),k=v.reduce((t,e)=>t+(e.endMs-e.startMs),0),_=e&&i?Date.parse(i)-Date.parse(e):void 0,N=l.sessionId??t.filenameId,T=c?y(c):void 0,b=T?.projectName??t.slug,j=c?c.replace(/^\//,"-").replace(/\//g,"-"):t.slug;return{meta:{agent:"gemini",id:N,filePath:t.filePath,projectName:b,worktreeName:T?.worktreeName,repoName:T?.repoName,projectDir:j,sessionId:N,firstTimestamp:e,lastTimestamp:i,durationMs:_&&Number.isFinite(_)?_:void 0,eventCount:m.length,model:s,cwd:c,totalUsage:d,status:"idle",firstUserPreview:n,lastUserPreview:a,lastAgentPreview:r,toolCallCount:p,turnCount:f,airTimeMs:k,activeSegments:v},events:m}}let tR=new Map,tB=new Map;async function tz(t={}){let e=t.root??tN,i=await tI(e),s=[];for(let t of i){let e=tR.get(t.filePath);if(e&&e.mtimeMs===t.mtimeMs&&e.sizeBytes===t.sizeBytes){s.push(e.meta);continue}try{let{meta:e}=await tU(t);tR.set(t.filePath,{meta:e,mtimeMs:t.mtimeMs,sizeBytes:t.sizeBytes}),s.push(e)}catch{}}return(s.sort((t,e)=>(e.firstTimestamp??"").localeCompare(t.firstTimestamp??"")),void 0!==t.limit)?s.slice(0,t.limit):s}async function tF(t,e={}){let i,s=e.root??tN,n=await tI(s);for(let e of n)if(e.filenameId===t||t.startsWith(e.filenameId)){i=e;break}if(!i)for(let e of n){let{meta:s}=await tU(e).catch(()=>({meta:{id:""}}));if(s.id===t){i=e;break}}if(!i)return null;let a=tB.get(i.filePath);if(a&&a.mtimeMs===i.mtimeMs&&a.sizeBytes===i.sizeBytes)return a.detail;let{meta:o,events:r}=await tU(i),l={...o,events:r};return tB.set(i.filePath,{detail:l,mtimeMs:i.mtimeMs,sizeBytes:i.sizeBytes}),l}let tO=n.default.join(s.default.homedir(),".gemini","antigravity-cli");async function t$(t){return i.promises.readdir(t).catch(()=>[])}let tW=null;async function tE(t){let e=n.default.join(t,"history.jsonl"),s=await i.promises.stat(e).catch(()=>null);if(!s)return new Map;if(tW&&tW.mtimeMs===s.mtimeMs)return tW.slugToCwd;let a=await i.promises.readFile(e,"utf8").catch(()=>""),o=new Map;for(let t of a.split("\n")){let e=t.trim();if(e)try{let t=JSON.parse(e);t.conversationId&&t.workspace&&o.set(t.conversationId,t.workspace)}catch{}}return tW={mtimeMs:s.mtimeMs,slugToCwd:o},o}async function tL(t){let e=await tE(t),s=[],a=n.default.join(t,"brain");for(let t of(await t$(a))){let o=n.default.join(a,t,".system_generated","logs","transcript.jsonl"),r=await i.promises.stat(o).catch(()=>null);r&&r.isFile()&&s.push({filePath:o,conversationId:t,cwd:e.get(t),mtimeMs:r.mtimeMs,sizeBytes:r.size})}return s}function tJ(t){return t.replace(/\s+/g," ").trim().slice(0,200)}async function tq(t){let e,s,n,a,r,l,u=await i.promises.readFile(t.filePath,"utf8"),c=[],m=0,d=0,p=[],f=0;function g(t){if(c.push(t),t.timestamp&&"meta"!==t.role){e||(e=t.timestamp),s=t.timestamp;let i=Date.parse(t.timestamp);Number.isFinite(i)&&p.push(i)}}let h=[],w=[],M=new Map;for(let t of u.split("\n")){let e=t.trim();if(e)try{let t=JSON.parse(e),i=t.step_index;"number"==typeof i?M.has(i)?w[M.get(i)]=t:(M.set(i,w.length),w.push(t)):w.push(t)}catch{}}for(let t of w){let e=t.created_at||t.timestamp;if("USER_INPUT"===t.type){if("string"==typeof t.content){let e=t.content.match(/Model Selection` from .*? to (.*?)\.\s*No need to/);if(e){let t=e[1].trim();n=t=t.replace(/\s*\(.*?\)\s*$/,"").trim()}else{let e=t.content.match(/Model Selection` from .*? to ([^\n]+)/);if(e){let t=e[1].trim();t.endsWith(".")&&(t=t.slice(0,-1).trim()),n=t=t.replace(/\s*\(.*?\)\s*$/,"").trim()}}}let i=t.content||"",s=i.match(/<USER_REQUEST>([\s\S]*?)<\/USER_REQUEST>/);s&&(i=s[1].trim());let l=tJ(i),u=(0,o.isFrameworkInjectedUserInput)(i);i&&!u&&(a||(a=l),r=l,d+=1),g({index:f++,timestamp:e,role:"user",rawType:"antigravity/user",preview:l,blocks:i?[{type:"text",text:i}]:[],messageId:t.step_index?.toString(),raw:t});continue}if("PLANNER_RESPONSE"===t.type){let i=t.thinking,s=t.content;if(i&&g({index:f++,timestamp:e,role:"agent-thinking",rawType:"antigravity/thought",preview:tJ(i),blocks:[{type:"thinking",thinking:i}],model:n,raw:t}),s){let i=tJ(s);l=i,g({index:f++,timestamp:e,role:"agent",rawType:"antigravity/agent",preview:i,blocks:[{type:"text",text:s}],messageId:t.step_index?.toString(),model:n,raw:t})}let a=t.tool_calls||[];for(let i=0;i<a.length;i++){let s=a[i];m+=1;let o=`tool-${t.step_index}-${i}`,r=s.args?JSON.stringify(s.args):"";h.push({id:o,name:s.name}),g({index:f++,timestamp:e,role:"tool-call",rawType:"antigravity/tool_call",preview:`${s.name}(${r.length<=80?r:r.slice(0,79)+"…"})`,blocks:[{type:"tool_use",id:o,name:s.name,input:s.args||{}}],toolName:s.name,toolUseId:o,model:n,raw:s})}continue}if("MODEL"===t.source&&"PLANNER_RESPONSE"!==t.type&&"ERROR_MESSAGE"!==t.type&&h.length>0){let i=h.shift(),s=i?i.id:`tool-${t.step_index}-unknown`,n="string"==typeof t.content?t.content:JSON.stringify(t.content||""),a="ERROR"===t.status||"FAILED"===t.status||"CANCELED"===t.status||!!t.error;g({index:f++,timestamp:e,role:"tool-result",rawType:"antigravity/tool_result",preview:tJ(n),blocks:[{type:"tool_result",tool_use_id:s,content:n,is_error:a}],toolUseId:s,toolResult:n,raw:t});continue}let i=t.content||t.error||"";g({index:f++,timestamp:e,role:"meta",rawType:`antigravity/${t.type?.toLowerCase()||"unknown"}`,preview:tJ(i),blocks:i?[{type:"text",text:i}]:[],raw:t})}let v=e?Date.parse(e):void 0;if(void 0!==v&&Number.isFinite(v)){let t;for(let e of c){if(!e.timestamp)continue;let i=Date.parse(e.timestamp);Number.isFinite(i)&&(e.tOffsetMs=Math.max(0,i-v),void 0!==t&&(e.gapMs=Math.max(0,i-t)),t=i)}}let k=function(t){if(0===t.length)return[];let e=[...t].sort((t,e)=>t-e),i=[],s=e[0],n=e[0];for(let t=1;t<e.length;t++)e[t]-n>18e4&&(i.push({startMs:s,endMs:n}),s=e[t]),n=e[t];return i.push({startMs:s,endMs:n}),i}(p),_=k.reduce((t,e)=>t+(e.endMs-e.startMs),0),N=e&&s?Date.parse(s)-Date.parse(e):void 0,T=t.conversationId,b=t.cwd,j=b?y(b):void 0,I=j?.projectName??t.conversationId,C=b?b.replace(/^\//,"-").replace(/\//g,"-"):t.conversationId;return{meta:{agent:"antigravity",id:T,filePath:t.filePath,projectName:I,worktreeName:j?.worktreeName,repoName:j?.repoName,projectDir:C,sessionId:T,firstTimestamp:e,lastTimestamp:s,durationMs:N&&Number.isFinite(N)?N:void 0,eventCount:c.length,model:n,cwd:b,totalUsage:{input:0,output:0,cacheRead:0,cacheWrite:0},status:"idle",firstUserPreview:a,lastUserPreview:r,lastAgentPreview:l,toolCallCount:m,turnCount:d,airTimeMs:_,activeSegments:k},events:c}}let tG=new Map,tH=new Map;async function tK(t={}){let e=t.root??tO,i=await tL(e),s=[];for(let t of i){let e=tG.get(t.filePath);if(e&&e.mtimeMs===t.mtimeMs&&e.sizeBytes===t.sizeBytes&&e.cwd===t.cwd){s.push(e.meta);continue}try{let{meta:e}=await tq(t);tG.set(t.filePath,{meta:e,mtimeMs:t.mtimeMs,sizeBytes:t.sizeBytes,cwd:t.cwd}),s.push(e)}catch{}}return(s.sort((t,e)=>(e.firstTimestamp??"").localeCompare(t.firstTimestamp??"")),void 0!==t.limit)?s.slice(0,t.limit):s}async function tY(t,e={}){let i,s=e.root??tO;for(let e of(await tL(s)))if(e.conversationId===t){i=e;break}if(!i)return null;let n=tH.get(i.filePath);if(n&&n.mtimeMs===i.mtimeMs&&n.sizeBytes===i.sizeBytes&&n.cwd===i.cwd)return n.detail;let{meta:a,events:o}=await tq(i),r={...a,events:o};return tH.set(i.filePath,{detail:r,mtimeMs:i.mtimeMs,sizeBytes:i.sizeBytes,cwd:i.cwd}),r}let tZ=(e=s.default.homedir(),n.default.join(e,".config","Claude","local-agent-mode-sessions")),tQ=/^local_[0-9a-f-]+$/;async function tV(t){return i.promises.readdir(t).catch(()=>[])}async function tX(t){let e=await i.promises.stat(t).catch(()=>null);return e?e.mtimeMs:0}async function t0(t){let e=[];for(let s of(await tV(t))){let a=n.default.join(t,s);for(let t of(await tV(a))){let s=n.default.join(a,t),o=await tX(n.default.join(s,"spaces.json"));for(let t of(await tV(s))){if(!tQ.test(t))continue;let a=n.default.join(s,t,"audit.jsonl"),r=await i.promises.stat(a).catch(()=>null);if(!r||!r.isFile()||0===r.size)continue;let l=n.default.join(s,`${t}.json`),u=await tX(l);e.push({sessionId:t,auditPath:a,metaPath:l,workspaceDir:s,auditMtimeMs:r.mtimeMs,auditSize:r.size,metaMtimeMs:u,spacesMtimeMs:o})}}}return e}let t1=new Map;async function t2(t){let e=n.default.join(t,"spaces.json"),s=await i.promises.stat(e).catch(()=>null);if(!s)return new Map;let a=t1.get(t);if(a&&a.mtimeMs===s.mtimeMs)return a.spaceIdToPath;let o=await i.promises.readFile(e,"utf8").catch(()=>""),r=new Map;try{for(let t of JSON.parse(o).spaces??[]){let e="string"==typeof t.id?t.id:void 0,i=(Array.isArray(t.folders)?t.folders:[])[0],s="string"==typeof i?.path?i.path:void 0;e&&s&&r.set(e,s)}}catch{}return t1.set(t,{mtimeMs:s.mtimeMs,spaceIdToPath:r}),r}async function t8(t){let e=await i.promises.readFile(t,"utf8").catch(()=>"");if(!e)return{};try{let t=JSON.parse(e);return{spaceId:"string"==typeof t.spaceId?t.spaceId:void 0,userSelectedFolders:Array.isArray(t.userSelectedFolders)?t.userSelectedFolders.filter(t=>"string"==typeof t):void 0,cwd:"string"==typeof t.cwd?t.cwd:void 0,model:"string"==typeof t.model?t.model:void 0,title:"string"==typeof t.title?t.title:void 0,createdAt:"number"==typeof t.createdAt?t.createdAt:void 0,lastActivityAt:"number"==typeof t.lastActivityAt?t.lastActivityAt:void 0}}catch{return{}}}async function t4(t){let e=await i.promises.readFile(t,"utf8"),s=[];for(let t of e.split("\n")){let e=t.trim();if(e)try{s.push(JSON.parse(e))}catch{}}return s}async function t3(t){let e,[i,s,n]=await Promise.all([t4(t.auditPath),t8(t.metaPath),t2(t.workspaceDir)]),a=(e=new Map,i.forEach((t,s)=>{if("string"!=typeof t.uuid)return;let n=e.get(t.uuid);void 0===n?e.set(t.uuid,s):void 0===i[n].timestamp&&void 0!==t.timestamp&&e.set(t.uuid,s)}),i.filter((t,i)=>"string"!=typeof t.uuid||e.get(t.uuid)===i)),{mainLines:o,subagentGroups:r}=function(t){let e=[],i=new Map;for(let s of t){let t=s.parent_tool_use_id;if("string"==typeof t){let e=i.get(t);e?e.push(s):i.set(t,[s])}else e.push(s)}return{mainLines:e,subagentGroups:i}}(a),{meta:l,events:u}=p(o),c=function(t,e,i){if(0===t.size)return[];let s=new Map;for(let i of e){let e=i.message?.content;if(Array.isArray(e)){for(let n of e)if(n&&"object"==typeof n){if("tool_use"===n.type&&"Agent"===n.name&&"string"==typeof n.id){let t=n.input??{},e=s.get(n.id)??{};"string"==typeof i.uuid&&(e.parentUuid=i.uuid),"string"==typeof t.description&&(e.description=t.description),"string"==typeof t.subagent_type&&(e.agentType=t.subagent_type),"string"==typeof t.prompt&&(e.prompt=t.prompt),s.set(n.id,e)}else if("tool_result"===n.type&&"string"==typeof n.tool_use_id&&t.has(n.tool_use_id)){let t=s.get(n.tool_use_id)??{};t.finalText=function(t){if("string"==typeof t)return t;if(Array.isArray(t)){let e=[];for(let i of t)if(i&&"object"==typeof i&&"text"===i.type){let t=i.text;"string"==typeof t&&e.push(t)}if(e.length)return e.join("\n")}}(n.content)??t.finalText,s.set(n.tool_use_id,t)}}}}let n=[];for(let[e,a]of t){let t=W(a),o=s.get(e)??{},r=o.finalText??t.finalText,l=r?r.replace(/\s+/g," ").trim().slice(0,240):t.finalPreview,u=void 0!==i&&void 0!==t.startMs?Math.max(0,t.startMs-i):void 0,c=void 0!==i&&void 0!==t.endMs?Math.max(0,t.endMs-i):void 0,m=void 0!==t.startMs&&void 0!==t.endMs?t.endMs-t.startMs:void 0;n.push({agentId:e,agentType:o.agentType??"unknown",description:o.description??(o.prompt?o.prompt.replace(/\s+/g," ").trim().slice(0,80):"(no description)"),startMs:t.startMs,endMs:t.endMs,durationMs:m,startTOffsetMs:u,endTOffsetMs:c,eventCount:t.eventCount,totalUsage:t.totalUsage,parentUuid:o.parentUuid,parentToolUseId:e,runInBackground:!1,finalPreview:l,finalText:r,prompt:o.prompt,model:t.model,toolCalls:t.toolCalls,toolCallCount:t.toolCallCount,assistantMessageCount:t.assistantMessageCount})}return n.sort((t,e)=>(t.startMs??0)-(e.startMs??0)),n}(r,a,l.firstTimestamp?Date.parse(l.firstTimestamp):void 0),{projectName:m,projectDir:d,cwd:f}=function(t,e){let i;if(t.spaceId&&(i=e.get(t.spaceId)),!i&&t.userSelectedFolders&&t.userSelectedFolders.length>0&&(i=t.userSelectedFolders[0]),!i)return{projectName:"cowork:unspaced",projectDir:"cowork-unspaced"};let s=y(i);return{projectName:s.projectName,worktreeName:s.worktreeName,projectDir:i.replace(/^\//,"-").replace(/\//g,"-"),cwd:i}}(s,n);return{meta:{...l,agent:"cowork",id:t.sessionId,sessionId:t.sessionId,filePath:t.auditPath,projectName:m,projectDir:d,cwd:f??l.cwd,model:l.model??s.model},events:u,subagents:c}}function t9(t){return{auditMtimeMs:t.auditMtimeMs,auditSize:t.auditSize,metaMtimeMs:t.metaMtimeMs,spacesMtimeMs:t.spacesMtimeMs}}function t7(t,e){return t.auditMtimeMs===e.auditMtimeMs&&t.auditSize===e.auditSize&&t.metaMtimeMs===e.metaMtimeMs&&t.spacesMtimeMs===e.spacesMtimeMs}let t6=new Map,t5=new Map;async function et(t={}){let e=t.root??tZ,i=await t0(e),s=[];for(let t of i){let e=t9(t),i=t6.get(t.auditPath);if(i&&t7(i.key,e)){s.push(i.meta);continue}try{let{meta:i}=await t3(t);t6.set(t.auditPath,{meta:i,key:e}),s.push(i)}catch{}}return(s.sort((t,e)=>(e.firstTimestamp??"").localeCompare(t.firstTimestamp??"")),void 0!==t.limit)?s.slice(0,t.limit):s}async function ee(t,e={}){let i=e.root??tZ,s=(await t0(i)).find(e=>e.sessionId===t);if(!s)return null;let n=t9(s),a=t5.get(s.auditPath);if(a&&t7(a.key,n))return a.detail;let{meta:o,events:r,subagents:l}=await t3(s),u={...o,events:r,...l.length?{subagents:l}:{}};return t5.set(s.auditPath,{detail:u,key:n}),u}function ei(){let t=process.env.GROK_HOME||n.default.join(s.default.homedir(),".grok");return n.default.join(t,"sessions")}let es=n.default.join(s.default.homedir(),".grok","sessions");async function en(t){return i.promises.readdir(t).catch(()=>[])}async function ea(t){let e=await i.promises.readFile(t,"utf8").catch(()=>null);if(null==e)return null;try{return JSON.parse(e)}catch{return null}}async function eo(t,e){let s=n.default.join(t,".cwd"),a=await i.promises.readFile(s,"utf8").catch(()=>null);if(a&&a.trim())return a.trim();try{return decodeURIComponent(e)}catch{return e}}async function er(t){let e=[];for(let s of(await en(t))){if("session_search.sqlite"===s||s.startsWith("."))continue;let a=n.default.join(t,s),o=await i.promises.stat(a).catch(()=>null);if(!o?.isDirectory())continue;let r=await eo(a,s);for(let t of(await en(a))){if("prompt_history.jsonl"===t||t.startsWith("."))continue;let o=n.default.join(a,t),l=n.default.join(o,"summary.json"),u=n.default.join(o,"updates.jsonl"),c=n.default.join(o,"signals.json"),[m,d,p]=await Promise.all([i.promises.stat(l).catch(()=>null),i.promises.stat(u).catch(()=>null),i.promises.stat(c).catch(()=>null)]);if(!m?.isFile())continue;let f=Math.max(m.mtimeMs,d?.mtimeMs??0),g=(d?.size??0)+m.size;e.push({dirPath:o,updatesPath:u,summaryPath:l,signalsPath:p?.isFile()?c:null,sessionId:t,groupName:s,decodedCwd:r,mtimeMs:f,sizeBytes:g})}}return e}function el(){return{input:0,output:0,cacheRead:0,cacheWrite:0}}function eu(t){return t.replace(/\s+/g," ").trim().slice(0,200)}function ec(t){return t?"string"==typeof t?t:"string"==typeof t.text?t.text:"":""}async function em(t){let e,s,n,a,r,[l,u,c]=await Promise.all([ea(t.summaryPath),t.signalsPath?ea(t.signalsPath):Promise.resolve(null),i.promises.readFile(t.updatesPath,"utf8").catch(()=>"")]),m=l?.info?.id??t.sessionId,d=l?.info?.cwd??t.decodedCwd,p=l?.current_model_id??u?.primaryModelId??u?.modelsUsed?.[0],f=[],g=el();u?.contextTokensUsed&&u.contextTokensUsed>0&&(g.input=u.contextTokensUsed);let h=0,w=0,M=[],v=0,k=new Set,_=0;function N(t){f.push(t),function(t,i){if(!t||"meta"===i)return;e||(e=t),s=t;let n=Date.parse(t);Number.isFinite(n)&&M.push(n)}(t.timestamp,t.role)}let T=null;function b(){if(!T)return;let t=T.texts.join(""),e=eu(t);if("user"===T.kind){let i=!t||(0,o.isFrameworkInjectedUserInput)(t);t&&!i&&(n||(n=e),a=e,w+=1),t&&N({index:v++,timestamp:T.firstTs,role:"user",rawType:"grok/user_message",preview:e,blocks:[{type:"text",text:t}],messageId:T.promptId,raw:1===T.raw.length?T.raw[0]:T.raw})}else"agent"===T.kind?(t&&(r=e),t&&N({index:v++,timestamp:T.firstTs,role:"agent",rawType:"grok/agent_message",preview:e,blocks:[{type:"text",text:t}],messageId:T.promptId,model:T.model??p,raw:1===T.raw.length?T.raw[0]:T.raw})):"thought"===T.kind&&t&&N({index:v++,timestamp:T.firstTs,role:"agent-thinking",rawType:"grok/agent_thought",preview:e,blocks:[{type:"thinking",thinking:t}],messageId:T.promptId,model:T.model??p,raw:1===T.raw.length?T.raw[0]:T.raw});T=null}function j(t,e,i,s,n,a){(e||"user"!==t)&&(T&&T.kind!==t&&b(),T||(T={kind:t,texts:[],firstTs:i,lastTs:i,model:n,promptId:s,raw:[]}),e&&T.texts.push(e),T.lastTs=i??T.lastTs,n&&(T.model=n),s&&(T.promptId=s),T.raw.push(a))}for(let t of c.split("\n")){let e,i=t.trim();if(!i)continue;try{e=JSON.parse(i)}catch{continue}let s=e.params?.update;if(!s||"object"!=typeof s)continue;let n=s.sessionUpdate;if(!n)continue;let a=function(t){let e=t.params?._meta,i=e&&"number"==typeof e.agentTimestampMs?e.agentTimestampMs:void 0;if(null!=i&&Number.isFinite(i))return new Date(i).toISOString();let s=t.timestamp;if("number"==typeof s&&Number.isFinite(s))return new Date(s>1e12?s:1e3*s).toISOString()}(e),o=e.params?._meta??{},r=s._meta??{},l="string"==typeof o.promptId&&o.promptId||"string"==typeof r.promptId&&r.promptId||void 0,u="string"==typeof r.modelId&&r.modelId||"string"==typeof o.modelId&&o.modelId||void 0;u&&(p=u);let c=o.totalTokens;if("number"==typeof c&&c>_&&(_=c),"user_message_chunk"===n){j("user",ec(s.content),a,l,u,e);continue}if("agent_message_chunk"===n){j("agent",ec(s.content),a,l,u,e);continue}if("agent_thought_chunk"===n){j("thought",ec(s.content),a,l,u,e);continue}if(b(),"tool_call"===n){let t="string"==typeof s.toolCallId?s.toolCallId:`grok-${v}`,i=function(t){let e=t._meta;if(e&&"object"==typeof e){let t=e["x.ai/tool"];if(t&&"object"==typeof t){let e=t.name;if("string"==typeof e&&e)return e}}return"string"==typeof t.title&&t.title?(!t.title.includes(" ")&&!t.title.includes("`"),t.title):"tool"}(s),n=s.rawInput??{},o=n?JSON.stringify(n):"";h+=1,N({index:v++,timestamp:a,role:"tool-call",rawType:"grok/tool_call",preview:`${i}(${o.length<=80?o:o.slice(0,79)+"…"})`,blocks:[{type:"tool_use",id:t,name:i,input:n}],toolName:i,toolUseId:t,model:p,raw:e});continue}if("tool_call_update"===n){let t=function(t){let e=t.status;return"string"==typeof e?e:e&&"object"==typeof e&&"string"==typeof e.status?e.status:void 0}(s);if("completed"!==t&&"failed"!==t&&"error"!==t&&"cancelled"!==t)continue;let i="string"==typeof s.toolCallId?s.toolCallId:"";if(i&&k.has(i))continue;i&&k.add(i);let n=function(t){let e=t.content;if(Array.isArray(e)){let t=[];for(let i of e){if(!i||"object"!=typeof i)continue;if("string"==typeof i.text&&i.text){t.push(i.text);continue}let e=i.content;"string"==typeof e&&e?t.push(e):e&&"object"==typeof e&&"string"==typeof e.text&&t.push(e.text)}if(t.length)return t.join("\n")}let i=t.rawOutput;if(null==i)return"";if("string"==typeof i)return i;if("object"==typeof i){if("string"==typeof i.output_for_prompt)return i.output_for_prompt;if("string"==typeof i.summary_for_prompt)return i.summary_for_prompt;if(i.Content&&"object"==typeof i.Content){let t=i.Content;if("string"==typeof t.content)return t.content}if(i.TodosUpdated&&"object"==typeof i.TodosUpdated){let t=i.TodosUpdated;if("string"==typeof t.summary_for_prompt)return t.summary_for_prompt}if(Array.isArray(i.stdout)||Array.isArray(i.output))try{return JSON.stringify({type:i.type,exit_code:i.exit_code,note:"binary/stdout omitted"})}catch{return""}try{return JSON.stringify(i)}catch{return""}}return String(i)}(s),o="failed"===t||"error"===t||"cancelled"===t;N({index:v++,timestamp:a,role:"tool-result",rawType:"grok/tool_result",preview:eu(n),blocks:[{type:"tool_result",tool_use_id:i,content:n,is_error:o||void 0}],toolUseId:i||void 0,toolResult:n,raw:e});continue}if("turn_completed"===n)continue}b(),0===g.input&&_>0&&(g.input=_),!e&&l?.created_at&&(e=l.created_at),s||(s=l?.last_active_at??l?.updated_at??e),u?.toolCallCount!=null&&u.toolCallCount>h&&(h=u.toolCallCount),u?.turnCount!=null&&u.turnCount>w&&(w=u.turnCount);let I=e?Date.parse(e):void 0;if(void 0!==I&&Number.isFinite(I)){let t;for(let e of f){if(!e.timestamp)continue;let i=Date.parse(e.timestamp);Number.isFinite(i)&&(e.tOffsetMs=Math.max(0,i-I),void 0!==t&&(e.gapMs=Math.max(0,i-t)),t=i)}}let C=function(t){if(0===t.length)return[];let e=[...t].sort((t,e)=>t-e),i=[],s=e[0],n=e[0];for(let t=1;t<e.length;t++){let a=e[t];a-n>18e4&&(i.push({startMs:s,endMs:n}),s=a),n=a}return i.push({startMs:s,endMs:n}),i}(M),x=C.reduce((t,e)=>t+(e.endMs-e.startMs),0),S=e&&s?Date.parse(s)-Date.parse(e):void 0,A=d?y(d):void 0,P=A?.projectName??d??t.decodedCwd,D=t.groupName||(d?encodeURIComponent(d):"(unknown)");if(!n){let t=l?.generated_title||l?.session_summary;t&&(n=eu(t))}let U=await ed(t.dirPath);return{meta:{agent:"grok",id:m,filePath:t.updatesPath,projectName:P,worktreeName:A?.worktreeName,repoName:A?.repoName,projectDir:D,sessionId:m,firstTimestamp:e,lastTimestamp:s,lastActivityMs:s?Date.parse(s):void 0,durationMs:S&&Number.isFinite(S)?S:void 0,eventCount:f.length,model:p,cwd:d,gitBranch:l?.head_branch,agentName:l?.agent_name,totalUsage:g,status:"idle",firstUserPreview:n,lastUserPreview:a,lastAgentPreview:r,toolCallCount:h,turnCount:w,linesAdded:u?.agentLinesAdded,linesRemoved:u?.agentLinesRemoved,airTimeMs:x,activeSegments:C,...U>0?{spawnedAgentCount:U}:{}},events:f,sessionKind:l?.session_kind}}async function ed(t){let e=n.default.join(t,"subagents"),s=await en(e),a=0;for(let t of s){let s=await i.promises.stat(n.default.join(e,t)).catch(()=>null);s?.isDirectory()&&(a+=1)}return a}async function ep(t,e){let i=n.default.join(t.dirPath,"subagents"),s=await en(i),a=n.default.dirname(t.dirPath),o=[];for(let t of s){let s=n.default.join(i,t,"meta.json"),r=await ea(s);if(!r)continue;let l=r.child_session_id??r.subagent_id??t,u=n.default.join(a,l),[c,m]=await Promise.all([ea(n.default.join(u,"summary.json")),ea(n.default.join(u,"signals.json"))]),d=c?.created_at?Date.parse(c.created_at):void 0,p=c?.last_active_at??c?.updated_at,f=p?Date.parse(p):void 0,g=void 0!==d&&Number.isFinite(d)?d:void 0,y=void 0!==f&&Number.isFinite(f)?f:void 0,h=el();m?.contextTokensUsed&&(h.input=m.contextTokensUsed),o.push({agentId:l,agentType:r.subagent_type??c?.agent_name??"subagent",description:r.description&&r.description.trim()||c?.generated_title||c?.session_summary||l,startMs:g,endMs:y,durationMs:void 0!==g&&void 0!==y?Math.max(0,y-g):void 0,startTOffsetMs:void 0!==e&&void 0!==g?Math.max(0,g-e):void 0,endTOffsetMs:void 0!==e&&void 0!==y?Math.max(0,y-e):void 0,eventCount:c?.num_messages??c?.num_chat_messages??0,totalUsage:h,prompt:"string"==typeof r.prompt?r.prompt:void 0,model:c?.current_model_id??m?.primaryModelId,toolCallCount:m?.toolCallCount})}return o.sort((t,e)=>(t.startMs??0)-(e.startMs??0)),o}let ef=new Map,eg=new Map;async function ey(t={}){let e=t.root??ei(),i=await er(e),s=[];for(let t of i){let e=await ea(t.summaryPath);if(e?.session_kind==="subagent")continue;let i=ef.get(t.dirPath);if(i&&i.mtimeMs===t.mtimeMs&&i.sizeBytes===t.sizeBytes){s.push(i.meta);continue}try{let{meta:e,sessionKind:i}=await em(t);if("subagent"===i)continue;ef.set(t.dirPath,{meta:e,mtimeMs:t.mtimeMs,sizeBytes:t.sizeBytes}),s.push(e)}catch{}}return(s.sort((t,e)=>(e.firstTimestamp??"").localeCompare(t.firstTimestamp??"")),void 0!==t.limit)?s.slice(0,t.limit):s}async function eh(t,e={}){let i=e.root??ei(),s=await er(i),n=s.find(e=>e.sessionId===t);if(!n){for(let e of s)try{let{meta:i,events:s}=await em(e);if(i.id===t){let t={...i,events:s};return eg.set(e.dirPath,{detail:t,mtimeMs:e.mtimeMs,sizeBytes:e.sizeBytes}),t}}catch{}return null}let a=eg.get(n.dirPath);if(a&&a.mtimeMs===n.mtimeMs&&a.sizeBytes===n.sizeBytes)return a.detail;let{meta:o,events:r}=await em(n),l=o.firstTimestamp?Date.parse(o.firstTimestamp):void 0,u=await ep(n,void 0!==l&&Number.isFinite(l)?l:void 0),c={...o,events:r,...u.length>0?{subagents:u,spawnedAgentCount:u.length}:{}};return eg.set(n.dirPath,{detail:c,mtimeMs:n.mtimeMs,sizeBytes:n.sizeBytes}),ef.set(n.dirPath,{meta:{...o,...u.length>0?{spawnedAgentCount:u.length}:{}},mtimeMs:n.mtimeMs,sizeBytes:n.sizeBytes}),c}function ew(){return process.env.CCLENS_HOME||n.default.join(s.default.homedir(),".cclens")}function eM(...t){return n.default.join(ew(),...t)}function ev(t){j(t)}let ek=[q,{...a.CODEX_METADATA,defaultRoot:G,listSessions:async t=>tr(t),getSession:async t=>tl(t)},{...a.COPILOT_METADATA,defaultRoot:tu,listSessions:async t=>tk(t),getSession:async(t,e)=>t_(t,e)},{...a.GEMINI_METADATA,defaultRoot:tN,listSessions:async t=>tz(t),getSession:async t=>tF(t)},{...a.ANTIGRAVITY_METADATA,defaultRoot:tO,listSessions:async t=>tK(t),getSession:async t=>tY(t)},{...a.COWORK_METADATA,defaultRoot:tZ,listSessions:async t=>et(t),getSession:async t=>ee(t)},{...a.GROK_METADATA,defaultRoot:es,listSessions:async t=>ey(t),getSession:async(t,e)=>eh(t,e)}];async function e_(t={}){let e=await Promise.all(ek.map(e=>e.listSessions(t))),i=[];for(let t of e)i.push(...t);return(i.sort((t,e)=>(e.firstTimestamp??"").localeCompare(t.firstTimestamp??"")),void 0!==t.limit)?i.slice(0,t.limit):i}async function eN(t){for(let e of ek){let i=await e.getSession(t);if(i)return i}return null}function eT(){return eM("usage.jsonl")}function eb(t){let e=eT();(0,i.mkdirSync)(n.default.dirname(e),{recursive:!0}),(0,i.appendFileSync)(e,JSON.stringify(t)+"\n","utf8")}function ej(t){let e=eT();if(!(0,i.existsSync)(e))return;let s=(0,i.readFileSync)(e,"utf8").split("\n").filter(e=>{if(!e.trim())return!1;try{return JSON.parse(e).agent!==t}catch{return!0}});(0,i.mkdirSync)(n.default.dirname(e),{recursive:!0}),(0,i.writeFileSync)(e,s.join("\n")+(s.length?"\n":""),"utf8")}}];
2
2
 
3
3
  //# sourceMappingURL=packages_parser_dist_06d9se1._.js.map