cogpit 2.0.0 → 2.1.0
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.
- package/README.md +4 -4
- package/dist/cli.js +18606 -14058
- package/dist/web/assets/CommandPaletteHost-C-ParO8t.js +1 -0
- package/dist/web/assets/ConfigBrowser-Co4eu81Z.js +1 -0
- package/dist/web/assets/{HighlightedEditor-BPmH8BvC.js → HighlightedEditor-j81AHVZZ.js} +2 -2
- package/dist/web/assets/{KeyboardShortcutsDialog-CTbXz40Z.js → KeyboardShortcutsDialog-CluzMowK.js} +1 -1
- package/dist/web/assets/{MobileFileChanges-C5VoKbje.js → MobileFileChanges-DiOncgtO.js} +1 -1
- package/dist/web/assets/{PreviewPanel-DoAf1W2k.js → PreviewPanel-i4Yn68yV.js} +1 -1
- package/dist/web/assets/{ProjectFilesPanel-v_O7Awnm.js → ProjectFilesPanel-DPLFARWn.js} +3 -3
- package/dist/web/assets/ProjectSwitcherModal-BUXfKNzX.js +1 -0
- package/dist/web/assets/{TerminalOutput-SImEU6_6.js → TerminalOutput-DLRMV4_Y.js} +1 -1
- package/dist/web/assets/{ThemeSelectorModal-rjVBMgWC.js → ThemeSelectorModal-Cmx9maEq.js} +1 -1
- package/dist/web/assets/{WorkflowsPanel-JVqgKAzY.js → WorkflowsPanel-Cgm_kbHR.js} +1 -1
- package/dist/web/assets/WorktreePanel-h3DRRXek.js +1 -0
- package/dist/web/assets/{index-C5VcQtkE.js → index-Cgnw8FK8.js} +1 -1
- package/dist/web/assets/{index-S7UMnH_y.js → index-DUI5EaV5.js} +4 -4
- package/dist/web/assets/index-DocqIkvS.js +144 -0
- package/dist/web/assets/index-cjmnKg1q.js +1 -0
- package/dist/web/assets/session-parser.worker-DTq2tkdd.js +29 -0
- package/dist/web/assets/{vendor-ui-BmLOQ5Or.js → vendor-ui-CIBbYCBQ.js} +151 -146
- package/dist/web/index.html +3 -3
- package/package.json +3 -2
- package/dist/web/assets/CommandPaletteHost-ChH6w0Bx.js +0 -1
- package/dist/web/assets/ConfigBrowser-CPCH7_25.js +0 -1
- package/dist/web/assets/ProjectSwitcherModal-CSZrCd3X.js +0 -1
- package/dist/web/assets/WorktreePanel-D94-oAau.js +0 -1
- package/dist/web/assets/index-C00ZsBZl.js +0 -1
- package/dist/web/assets/index-CNV6e3p0.js +0 -138
- package/dist/web/assets/session-parser.worker-BhyaigCR.js +0 -22
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as V,a as Qe,c as B,j as s}from"./vendor-react-gGw_S5I_.js";import{w as He,B as U,aH as We,aW as qe,A as _e,aI as Ke,be as Le,ae as ke,ad as ze,V as Te,bf as Xe,b4 as Je,b3 as Ze,b2 as et,bg as tt,bh as st,bi as nt,bj as it,U as ue,bk as lt,W as ot,ak as at,bl as rt,bm as ct,bn as dt,v as ut,af as ft,bo as mt,E as xt,y as ht,z as gt,G as pt,H as bt,ai as jt,p as wt,bp as vt,bq as Nt,q as yt}from"./index-DocqIkvS.js";import{E as It,ah as St,ao as Be,C as Fe,ap as Ie,a2 as qt,aq as _t,L as Ct,ar as Tt,as as kt,c as At,m as Et}from"./vendor-ui-CIBbYCBQ.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";const Rt=4e3;function Mt(){const[l,e]=V.useState([]),[t,n]=V.useState(!1),[i,r]=V.useState(null),o=V.useRef(!1);V.useEffect(()=>(o.current=!1,()=>{o.current=!0}),[]);const c=V.useCallback(async()=>{try{const m=await He("/api/mission-control");if(o.current)return;if(!m.ok)throw new Error(`Mission Control request failed (${m.status})`);const x=await m.json();if(o.current)return;e(Array.isArray(x.summaries)?x.summaries:[]),r(null)}catch(m){if(o.current)return;r(m instanceof Error?m.message:"Failed to load Mission Control")}finally{o.current||n(!1)}},[]);V.useEffect(()=>{n(!0);const m=()=>{(typeof document>"u"||document.visibilityState==="visible")&&c()},x=()=>{document.visibilityState==="visible"&&c()};m();const j=setInterval(m,Rt);return document.addEventListener("visibilitychange",x),()=>{clearInterval(j),document.removeEventListener("visibilitychange",x)}},[c]);const d=V.useMemo(()=>{const m=new Map;for(const x of l)m.set(x.sessionId,x);return m},[l]),g=V.useCallback(()=>{c()},[c]);return{summaries:d,loading:t,error:i,refresh:g}}const Ae="data-view-transition-kind",Lt="(prefers-reduced-motion: reduce)";let de=null,$e=null;function Dt(l,e,t){t===null?l.removeAttribute(e):l.setAttribute(e,t)}function Ft(l,e){const t={root:l,kind:e,previousKind:l.getAttribute(Ae)};return l.setAttribute(Ae,e),$e=t,t}function Se(l){$e===l&&(l.root.getAttribute(Ae)===l.kind&&Dt(l.root,Ae,l.previousKind),$e=null)}function $t(){const l=de;if(l){de=null;try{l.transition.skipTransition()}catch{Se(l.tag);return}Se(l.tag)}}function zt(){if(typeof window>"u"||typeof window.matchMedia!="function")return!1;try{return window.matchMedia(Lt).matches}catch{return!1}}function Ot(l,{kind:e}){$t();const t=typeof document>"u"?null:document,n=t==null?void 0:t.startViewTransition;if(!t||!(typeof n=="function")||zt())return l(),null;const r=Ft(t.documentElement,e);let o=!1,c=!1,d;const g=m=>{if(!o){o=!0;try{m?Qe.flushSync(l):l()}catch(x){throw c=!0,d=x,x}}};try{const m=n.call(t,()=>g(!0)),x={transition:m,tag:r};return de=x,m.ready.catch(()=>{}),m.updateCallbackDone.catch(()=>{}),m.finished.then(()=>{de===x&&(de=null),Se(r)},()=>{de===x&&(de=null),Se(r)}),m}catch{if(Se(r),c)throw d;return g(!1),null}}function Vt(l){const e={};for(const t of l)t.type==="boolean"?e[t.name]=t.defaultValue===!0:t.defaultValue!==void 0?e[t.name]=String(t.defaultValue):e[t.name]="";return e}function Ut(l,e){const t={};for(const n of l){const i=e[n.name];if(typeof i=="boolean"){t[n.name]=i;continue}i!==""&&(t[n.name]=n.type==="number"||n.type==="integer"?Number(i):i)}return t}function Yt(l,e){return l.every(t=>{if(!t.required)return!0;const n=e[t.name];return typeof n=="boolean"?!0:n===""?!1:t.type==="number"||t.type==="integer"?Number.isFinite(Number(n)):!0})}function Bt(l){const e=B.c(64),{request:t,responding:n,onAnswer:i}=l;let r;e[0]!==t.fields?(r=()=>Vt(t.fields),e[0]=t.fields,e[1]=r):r=e[1];const[o,c]=V.useState(r);let d;e[2]!==t.fields||e[3]!==o?(d=Yt(t.fields,o),e[2]=t.fields,e[3]=o,e[4]=d):d=e[4];const g=d,m=t.displayName||t.title||t.serverName;let x;e[5]===Symbol.for("react.memo_cache_sentinel")?(x=(_,I)=>{c(w=>({...w,[_]:I}))},e[5]=x):x=e[5];const j=x;let p;e[6]!==i||e[7]!==t.requestId?(p=()=>i(t.requestId,{action:"decline"}),e[6]=i,e[7]=t.requestId,e[8]=p):p=e[8];const u=p;if(t.mode==="url"&&t.url){const _=t.url;let I;e[9]!==t.message?(I=s.jsx("p",{className:"text-sm leading-relaxed text-foreground",children:t.message}),e[9]=t.message,e[10]=I):I=e[10];let w;e[11]!==_?(w=s.jsx("p",{className:"mt-1 truncate font-mono text-xs text-muted-foreground",title:_,children:_}),e[11]=_,e[12]=w):w=e[12];let S;e[13]!==i||e[14]!==t.requestId||e[15]!==_?(S=()=>{window.open(_,"_blank","noopener,noreferrer"),i(t.requestId,{action:"accept"})},e[13]=i,e[14]=t.requestId,e[15]=_,e[16]=S):S=e[16];let z;e[17]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(It,{"data-icon":"inline-end"}),e[17]=z):z=e[17];let L;e[18]!==n||e[19]!==S?(L=s.jsxs(U,{size:"sm",disabled:n,onClick:S,children:["Open link",z]}),e[18]=n,e[19]=S,e[20]=L):L=e[20];let k;e[21]!==u||e[22]!==n?(k=s.jsx(U,{variant:"ghost",size:"sm",disabled:n,onClick:u,children:"Decline"}),e[21]=u,e[22]=n,e[23]=k):k=e[23];let R;e[24]!==k||e[25]!==L?(R=s.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[L,k]}),e[24]=k,e[25]=L,e[26]=R):R=e[26];let F;return e[27]!==m||e[28]!==R||e[29]!==I||e[30]!==w?(F=s.jsxs(Ve,{server:m,children:[I,w,R]}),e[27]=m,e[28]=R,e[29]=I,e[30]=w,e[31]=F):F=e[31],F}let a;e[32]!==t.message?(a=s.jsx("p",{className:"text-sm leading-relaxed text-foreground",children:t.message}),e[32]=t.message,e[33]=a):a=e[33];let h;if(e[34]!==t.fields||e[35]!==t.requestId||e[36]!==n||e[37]!==o){let _;e[39]!==t.requestId||e[40]!==n||e[41]!==o?(_=I=>s.jsx(Pt,{id:`elicit-${t.requestId}-${I.name}`,field:I,value:o[I.name],disabled:n,onChange:w=>j(I.name,w)},I.name),e[39]=t.requestId,e[40]=n,e[41]=o,e[42]=_):_=e[42],h=t.fields.map(_),e[34]=t.fields,e[35]=t.requestId,e[36]=n,e[37]=o,e[38]=h}else h=e[38];let f;e[43]!==h?(f=s.jsx("div",{className:"mt-3 flex flex-col gap-3",children:h}),e[43]=h,e[44]=f):f=e[44];const y=n||!g;let v;e[45]!==i||e[46]!==t.fields||e[47]!==t.requestId||e[48]!==o?(v=()=>i(t.requestId,{action:"accept",content:Ut(t.fields,o)}),e[45]=i,e[46]=t.fields,e[47]=t.requestId,e[48]=o,e[49]=v):v=e[49];let q;e[50]!==y||e[51]!==v?(q=s.jsx(U,{size:"sm",disabled:y,onClick:v,children:"Send"}),e[50]=y,e[51]=v,e[52]=q):q=e[52];let T;e[53]!==u||e[54]!==n?(T=s.jsx(U,{variant:"ghost",size:"sm",disabled:n,onClick:u,children:"Decline"}),e[53]=u,e[54]=n,e[55]=T):T=e[55];let N;e[56]!==q||e[57]!==T?(N=s.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[q,T]}),e[56]=q,e[57]=T,e[58]=N):N=e[58];let b;return e[59]!==m||e[60]!==N||e[61]!==a||e[62]!==f?(b=s.jsxs(Ve,{server:m,children:[a,f,N]}),e[59]=m,e[60]=N,e[61]=a,e[62]=f,e[63]=b):b=e[63],b}function Pt(l){const e=B.c(55),{id:t,field:n,value:i,disabled:r,onChange:o}=l;if(n.type==="boolean"){const u=i===!0;let a;e[0]!==o?(a=v=>o(v===!0),e[0]=o,e[1]=a):a=e[1];let h;e[2]!==r||e[3]!==t||e[4]!==u||e[5]!==a?(h=s.jsx(Ke,{id:t,checked:u,disabled:r,onCheckedChange:a}),e[2]=r,e[3]=t,e[4]=u,e[5]=a,e[6]=h):h=e[6];let f;e[7]!==n?(f=s.jsx(De,{field:n}),e[7]=n,e[8]=f):f=e[8];let y;return e[9]!==t||e[10]!==h||e[11]!==f?(y=s.jsxs(Le,{htmlFor:t,className:"items-start gap-2 font-normal",children:[h,f]}),e[9]=t,e[10]=h,e[11]=f,e[12]=y):y=e[12],y}if(n.type==="enum"){let u;e[13]!==n?(u=s.jsx(De,{field:n}),e[13]=n,e[14]=u):u=e[14];let a;e[15]!==t||e[16]!==u?(a=s.jsx(Le,{htmlFor:t,children:u}),e[15]=t,e[16]=u,e[17]=a):a=e[17];let h;e[18]!==i?(h=typeof i=="string"&&i?[i]:[],e[18]=i,e[19]=h):h=e[19];let f;e[20]!==o?(f=b=>{b[0]&&o(b[0])},e[20]=o,e[21]=f):f=e[21];const y=n.label;let v;e[22]!==n.options?(v=n.options??[],e[22]=n.options,e[23]=v):v=e[23];let q;if(e[24]!==r||e[25]!==v){let b;e[27]!==r?(b=_=>s.jsx(ke,{value:_.value,disabled:r,className:"w-full justify-start px-3",children:_.label},_.value),e[27]=r,e[28]=b):b=e[28],q=v.map(b),e[24]=r,e[25]=v,e[26]=q}else q=e[26];let T;e[29]!==n.label||e[30]!==t||e[31]!==h||e[32]!==f||e[33]!==q?(T=s.jsx(ze,{id:t,value:h,onValueChange:f,orientation:"vertical",variant:"outline",size:"sm",className:"w-full items-stretch","aria-label":y,children:q}),e[29]=n.label,e[30]=t,e[31]=h,e[32]=f,e[33]=q,e[34]=T):T=e[34];let N;return e[35]!==a||e[36]!==T?(N=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[a,T]}),e[35]=a,e[36]=T,e[37]=N):N=e[37],N}let c;e[38]!==n?(c=s.jsx(De,{field:n}),e[38]=n,e[39]=c):c=e[39];let d;e[40]!==t||e[41]!==c?(d=s.jsx(Le,{htmlFor:t,children:c}),e[40]=t,e[41]=c,e[42]=d):d=e[42];const g=n.type==="string"?"text":"number",m=typeof i=="string"?i:"";let x;e[43]!==o?(x=u=>o(u.target.value),e[43]=o,e[44]=x):x=e[44];let j;e[45]!==r||e[46]!==n.label||e[47]!==t||e[48]!==g||e[49]!==m||e[50]!==x?(j=s.jsx(We,{id:t,"aria-label":n.label,type:g,value:m,disabled:r,onChange:x}),e[45]=r,e[46]=n.label,e[47]=t,e[48]=g,e[49]=m,e[50]=x,e[51]=j):j=e[51];let p;return e[52]!==d||e[53]!==j?(p=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[d,j]}),e[52]=d,e[53]=j,e[54]=p):p=e[54],p}function De(l){const e=B.c(8),{field:t}=l;let n;e[0]!==t.required?(n=t.required&&s.jsx("span",{className:"ml-0.5 text-warning",children:"*"}),e[0]=t.required,e[1]=n):n=e[1];let i;e[2]!==t.description?(i=t.description&&s.jsx("span",{className:"block text-xs font-normal text-muted-foreground",children:t.description}),e[2]=t.description,e[3]=i):i=e[3];let r;return e[4]!==t.label||e[5]!==n||e[6]!==i?(r=s.jsxs("span",{className:"min-w-0",children:[t.label,n,i]}),e[4]=t.label,e[5]=n,e[6]=i,e[7]=r):r=e[7],r}function Ve(l){const e=B.c(8),{server:t,children:n}=l;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(St,{className:"text-info"}),e[0]=i):i=e[0];let r;e[1]!==t?(r=s.jsxs(qe,{children:[t," needs input"]}),e[1]=t,e[2]=r):r=e[2];let o;e[3]!==n?(o=s.jsx("div",{className:"col-start-2 mt-1 min-w-0",children:n}),e[3]=n,e[4]=o):o=e[4];let c;return e[5]!==r||e[6]!==o?(c=s.jsxs(_e,{className:"border-info/40 bg-info/5",children:[i,r,o]}),e[5]=r,e[6]=o,e[7]=c):c=e[7],c}const Gt=["allow","allow_always","deny"],Qt=[{decision:"allow",label:"Allow",variant:"default"},{decision:"deny",label:"Deny",variant:"destructive"},{decision:"allow_always",label:"Always",variant:"outline"}];function Ht(l,e){return(l.availableDecisions??Gt).includes(e)}function Wt(l){const e=B.c(22),{request:t,queued:n,responding:i,onRespond:r}=l;let o;if(e[0]!==r||e[1]!==n||e[2]!==t||e[3]!==i){let c;e[5]!==t?(c=y=>Ht(t,y.decision),e[5]=t,e[6]=c):c=e[6];const d=Qt.filter(c),g=d.some(Kt);let m;e[7]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Be,{className:"text-warning"}),e[7]=m):m=e[7];const x=t.title||`Allow ${t.toolName}?`;let j;e[8]!==x?(j=s.jsx("span",{className:"min-w-0 flex-1 truncate",children:x}),e[8]=x,e[9]=j):j=e[9];let p;e[10]!==n?(p=n>0&&s.jsxs("span",{className:"shrink-0 font-mono text-xs text-warning",children:["+",n]}),e[10]=n,e[11]=p):p=e[11];let u;e[12]!==j||e[13]!==p?(u=s.jsxs(qe,{className:"flex min-w-0 items-center gap-2",children:[j,p]}),e[12]=j,e[13]=p,e[14]=u):u=e[14];let a;e[15]!==t.toolName?(a=s.jsx("span",{className:"shrink-0 font-mono text-xs text-muted-foreground",children:t.toolName}),e[15]=t.toolName,e[16]=a):a=e[16];let h;e[17]!==t.summary?(h=t.summary&&s.jsx("code",{className:"min-w-0 flex-1 truncate rounded bg-muted px-2 py-1 font-mono text-xs text-foreground",children:t.summary}),e[17]=t.summary,e[18]=h):h=e[18];let f;e[19]!==a||e[20]!==h?(f=s.jsxs("div",{className:"col-start-2 mt-2 flex min-w-0 items-center gap-2",children:[a,h]}),e[19]=a,e[20]=h,e[21]=f):f=e[21],o=s.jsxs(_e,{className:"border-warning/40 bg-warning/5",children:[m,u,f,g?s.jsx("div",{className:"col-start-2 mt-3 flex items-center gap-2",children:d.map(y=>{const{decision:v,label:q,variant:T}=y;return s.jsx(U,{size:"xs",variant:T,disabled:i,onClick:()=>r(t.requestId,v),children:q},v)})}):s.jsx("p",{className:"col-start-2 mt-2 text-xs text-warning",children:"Resolve this approval in its own provider"})]}),e[0]=r,e[1]=n,e[2]=t,e[3]=i,e[4]=o}else o=e[4];return o}function Kt(l){return l.decision!=="allow_always"}function Xt(l){return l.some(e=>e.options.length===0||e.options.some(t=>t.hasPreview))}function Jt(l){const e=B.c(63),{request:t,responding:n,gone:i,onAnswer:r,onOpenSession:o}=l,c=t.questions,[d,g]=V.useState(0);let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m={},e[0]=m):m=e[0];const x=V.useRef(m);let j;e[1]===Symbol.for("react.memo_cache_sentinel")?(j=new Set,e[1]=j):j=e[1];const[p,u]=V.useState(j);if(c.length===0)return null;if(Xt(c)){let E;e[2]!==c[0].question?(E=s.jsx("p",{className:"text-sm leading-relaxed text-foreground",children:c[0].question}),e[2]=c[0].question,e[3]=E):E=e[3];let C;e[4]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(Fe,{"data-icon":"inline-end"}),e[4]=C):C=e[4];let D;e[5]!==o?(D=s.jsxs(U,{variant:"outline",size:"sm",onClick:o,className:"mt-3",children:["Open full question",C]}),e[5]=o,e[6]=D):D=e[6];let O;return e[7]!==E||e[8]!==D?(O=s.jsxs(Ue,{children:[E,D]}),e[7]=E,e[8]=D,e[9]=O):O=e[9],O}const a=c[d];let h;e[10]!==a.question||e[11]!==d||e[12]!==r||e[13]!==c.length||e[14]!==t.toolUseId?(h=function(C){const D={...x.current,[a.question]:C};if(d+1<c.length){x.current=D,u(new Set),g(d+1);return}r(t.toolUseId,D)},e[10]=a.question,e[11]=d,e[12]=r,e[13]=c.length,e[14]=t.toolUseId,e[15]=h):h=e[15];const f=h;let y;e[16]!==a.header?(y=a.header&&s.jsx(Te,{variant:"outline",className:"border-info/40 text-info",children:a.header}),e[16]=a.header,e[17]=y):y=e[17];let v;e[18]!==d||e[19]!==c.length?(v=c.length>1&&s.jsxs("span",{className:"ml-auto shrink-0 font-mono text-xs text-muted-foreground",children:[d+1," of ",c.length]}),e[18]=d,e[19]=c.length,e[20]=v):v=e[20];let q;e[21]!==y||e[22]!==v?(q=s.jsxs("div",{className:"flex items-baseline gap-1.5",children:[y,v]}),e[21]=y,e[22]=v,e[23]=q):q=e[23];let T;e[24]!==a.question?(T=s.jsx("p",{className:"mt-2 line-clamp-3 text-sm leading-relaxed text-foreground",title:a.question,children:a.question}),e[24]=a.question,e[25]=T):T=e[25];let N;e[26]!==p?(N=[...p],e[26]=p,e[27]=N):N=e[27];let b;e[28]!==f||e[29]!==a.multiSelect?(b=E=>{a.multiSelect?u(new Set(E)):E[0]&&f(E[0])},e[28]=f,e[29]=a.multiSelect,e[30]=b):b=e[30];const _=a.multiSelect,I=a.question;let w;if(e[31]!==a.options||e[32]!==n){let E;e[34]!==n?(E=C=>s.jsx(Zt,{option:C,disabled:n},C.label),e[34]=n,e[35]=E):E=e[35],w=a.options.map(E),e[31]=a.options,e[32]=n,e[33]=w}else w=e[33];let S;e[36]!==a.multiSelect||e[37]!==a.question||e[38]!==w||e[39]!==N||e[40]!==b?(S=s.jsx(ze,{value:N,onValueChange:b,multiple:_,orientation:"vertical",variant:"outline",size:"sm",className:"mt-3 w-full items-stretch","aria-label":I,children:w}),e[36]=a.multiSelect,e[37]=a.question,e[38]=w,e[39]=N,e[40]=b,e[41]=S):S=e[41];let z;e[42]!==f||e[43]!==a.multiSelect||e[44]!==d||e[45]!==c.length||e[46]!==n||e[47]!==p?(z=a.multiSelect&&s.jsx(U,{size:"sm",disabled:n||p.size===0,onClick:()=>f(Xe(p)),children:d+1<c.length?"Next":"Send"}),e[42]=f,e[43]=a.multiSelect,e[44]=d,e[45]=c.length,e[46]=n,e[47]=p,e[48]=z):z=e[48];let L;e[49]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(Fe,{"data-icon":"inline-end"}),e[49]=L):L=e[49];let k;e[50]!==o?(k=s.jsxs(U,{variant:"ghost",size:"sm",onClick:o,className:"ml-auto text-muted-foreground",children:["Open session",L]}),e[50]=o,e[51]=k):k=e[51];let R;e[52]!==z||e[53]!==k?(R=s.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[z,k]}),e[52]=z,e[53]=k,e[54]=R):R=e[54];let F;e[55]!==i?(F=i&&s.jsx("p",{className:"mt-2 text-xs text-warning",children:"This question may already be answered. Open the session to check."}),e[55]=i,e[56]=F):F=e[56];let A;return e[57]!==S||e[58]!==R||e[59]!==F||e[60]!==q||e[61]!==T?(A=s.jsxs(Ue,{children:[q,T,S,R,F]}),e[57]=S,e[58]=R,e[59]=F,e[60]=q,e[61]=T,e[62]=A):A=e[62],A}function Zt(l){const e=B.c(17),{option:t,disabled:n}=l;let i;e[0]!==t.label?(i=s.jsx("span",{className:"min-w-0 flex-1 truncate text-left",children:t.label}),e[0]=t.label,e[1]=i):i=e[1];const r=i;if(!t.description){let m;return e[2]!==n||e[3]!==r||e[4]!==t.label?(m=s.jsx(ke,{value:t.label,disabled:n,className:"w-full justify-start px-3",children:r}),e[2]=n,e[3]=r,e[4]=t.label,e[5]=m):m=e[5],m}let o;e[6]!==n||e[7]!==t.label?(o=s.jsx(ke,{value:t.label,disabled:n,className:"w-full justify-start px-3"}),e[6]=n,e[7]=t.label,e[8]=o):o=e[8];let c;e[9]!==r||e[10]!==o?(c=s.jsx(Ze,{render:o,children:r}),e[9]=r,e[10]=o,e[11]=c):c=e[11];let d;e[12]!==t.description?(d=s.jsx(Je,{side:"right",className:"max-w-72 text-left",children:t.description}),e[12]=t.description,e[13]=d):d=e[13];let g;return e[14]!==c||e[15]!==d?(g=s.jsxs(et,{children:[c,d]}),e[14]=c,e[15]=d,e[16]=g):g=e[16],g}function Ue(l){const e=B.c(4),{children:t}=l;let n,i;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(Ie,{className:"text-info"}),i=s.jsx(qe,{children:"Answer to continue"}),e[0]=n,e[1]=i):(n=e[0],i=e[1]);let r;return e[2]!==t?(r=s.jsxs(_e,{className:"border-info/40 bg-info/5",children:[n,i,s.jsx("div",{className:"col-start-2 mt-1 min-w-0",children:t})]}),e[2]=t,e[3]=r):r=e[3],r}function es(l){const e=B.c(33),{request:t,responding:n,onChoose:i}=l;let r,o;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(Be,{className:"text-warning"}),o=s.jsx(qe,{children:"Claude declined this request"}),e[0]=r,e[1]=o):(r=e[0],o=e[1]);let c;e[2]!==t.originalModel?(c=s.jsxs("p",{className:"text-sm leading-relaxed text-foreground",children:[t.originalModel," would not answer. Retrying on a fallback model may work."]}),e[2]=t.originalModel,e[3]=c):c=e[3];let d;e[4]!==t.guidanceText?(d=t.guidanceText&&s.jsx("p",{className:"mt-1 text-sm leading-relaxed text-muted-foreground",children:t.guidanceText}),e[4]=t.guidanceText,e[5]=d):d=e[5];let g;e[6]!==i||e[7]!==t.requestId?(g=()=>i(t.requestId,"retry_fallback"),e[6]=i,e[7]=t.requestId,e[8]=g):g=e[8];let m;e[9]!==t.fallbackModel||e[10]!==n||e[11]!==g?(m=s.jsxs(U,{size:"sm",disabled:n,onClick:g,children:["Retry on ",t.fallbackModel]}),e[9]=t.fallbackModel,e[10]=n,e[11]=g,e[12]=m):m=e[12];let x;e[13]!==i||e[14]!==t.requestId?(x=()=>i(t.requestId,"edit_prompt"),e[13]=i,e[14]=t.requestId,e[15]=x):x=e[15];let j;e[16]!==n||e[17]!==x?(j=s.jsx(U,{variant:"outline",size:"sm",disabled:n,onClick:x,children:"Edit prompt"}),e[16]=n,e[17]=x,e[18]=j):j=e[18];let p;e[19]!==i||e[20]!==t.requestId?(p=()=>i(t.requestId,"cancelled"),e[19]=i,e[20]=t.requestId,e[21]=p):p=e[21];let u;e[22]!==n||e[23]!==p?(u=s.jsx(U,{variant:"ghost",size:"sm",disabled:n,className:"ml-auto text-muted-foreground",onClick:p,children:"Dismiss"}),e[22]=n,e[23]=p,e[24]=u):u=e[24];let a;e[25]!==u||e[26]!==m||e[27]!==j?(a=s.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[m,j,u]}),e[25]=u,e[26]=m,e[27]=j,e[28]=a):a=e[28];let h;return e[29]!==a||e[30]!==c||e[31]!==d?(h=s.jsxs(_e,{className:"border-warning/40 bg-warning/5",children:[r,o,s.jsxs("div",{className:"col-start-2 mt-1 min-w-0",children:[c,d,a]})]}),e[29]=a,e[30]=c,e[31]=d,e[32]=h):h=e[32],h}function Pe(l){return l==="awaiting_approval"||l==="awaiting_prompt"||l==="awaiting_question"||l==="awaiting_answer"}function Ee(l){return l==="done"||l==="failed"}const Ye={awaiting_approval:0,awaiting_prompt:1,awaiting_question:2,awaiting_answer:3,running:4,failed:5,done:6};function ts(l,e,t,n,i,r){return t?"awaiting_approval":n?"awaiting_prompt":i?"awaiting_question":r||l.agentStatus==="deferred"||l.agentStatus==="idle"&&e?"awaiting_answer":l.agentTerminalReason?"failed":e&&l.agentStatus&&nt.has(l.agentStatus)?"running":"done"}const ss=6;function ns({sessions:l,procBySession:e,summaries:t,permissionsBySession:n,questionsBySession:i,elicitationsBySession:r,dialogsBySession:o,awaitingPlan:c,newlyCompleted:d,finishedLimit:g=ss,now:m=Date.now()}){const x=[];for(const u of tt(l)){const a=n.get(u.sessionId)??[],h=i.get(u.sessionId)??[],f=r.get(u.sessionId)??[],y=o.get(u.sessionId)??[],v=c.has(u.sessionId),q=a.length+h.length+f.length+y.length+Number(v);u.teamName&&u.agentName&&q===0||x.push({session:u,state:ts(u,st(u,e,m),a.length>0,f.length>0||y.length>0,h.length>0,v),summary:t.get(u.sessionId)??null,permissions:a,questions:h,elicitations:f,dialogs:y})}const j=x.filter(u=>Ee(u.state)),p=[...j.filter(u=>d.has(u.session.sessionId)),...j.filter(u=>!d.has(u.session.sessionId))].slice(0,g);return[...x.filter(u=>!Ee(u.state)),...p].sort((u,a)=>Ye[u.state]-Ye[a.state])}function is(l,e){switch(e){case"running":return l.filter(t=>t.state==="running");case"needs-you":return l.filter(t=>Pe(t.state));case"finished":return l.filter(t=>Ee(t.state));default:return l}}function ls(l){const e={total:l.length,running:0,needsYou:0,finished:0,failed:0};for(const t of l)t.state==="running"&&e.running++,Pe(t.state)&&e.needsYou++,Ee(t.state)&&e.finished++,t.state==="failed"&&e.failed++;return e}function os(l){return l>=90?"text-destructive":l>=70?"text-warning":"text-muted-foreground"}const as={awaiting_approval:{label:"Waiting for approval",text:"text-warning",shell:"border-warning/40 bg-warning/5",icon:Ie},awaiting_prompt:{label:"Waiting for your input",text:"text-info",shell:"border-info/40 bg-info/5",icon:Ie},awaiting_question:{label:"Waiting for your answer",text:"text-info",shell:"border-info/40 bg-info/5",icon:Ie},awaiting_answer:{label:"Waiting for your answer",text:"text-warning",shell:"border-warning/40 bg-warning/5",icon:Ie},running:{label:"Running",text:"text-info",shell:"border-border",icon:null},done:{label:"Done",text:"text-success",shell:"border-border",icon:_t},failed:{label:"Failed",text:"text-destructive",shell:"border-destructive/40",icon:qt}};function rs(l){const e=B.c(3),{icon:t}=l;if(!t){let i;return e[0]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx("span",{className:"size-2 shrink-0 rounded-full bg-info"}),e[0]=i):i=e[0],i}let n;return e[1]!==t?(n=s.jsx(t,{className:"size-3.5 shrink-0"}),e[1]=t,e[2]=n):n=e[2],n}const cs=V.memo(function(e){const t=B.c(88),{card:n,customName:i,projectLabel:r,responding:o,goneQuestions:c,compact:d,onOpen:g,onRespond:m,onAnswerQuestion:x,onAnswerElicitation:j,onChooseDialog:p}=e,u=d===void 0?!1:d,{session:a,state:h,summary:f,permissions:y,questions:v,elicitations:q,dialogs:T}=n,N=as[h],b=y[0],_=v[0],I=q[0],w=T[0],S=!!(b||_||I||w);let z;t[0]!==i||t[1]!==a?(z=it(a,i),t[0]=i,t[1]=a,t[2]=z):z=t[2];const L=z,k=u&&"gap-1.5 py-2";let R;t[3]!==N.shell||t[4]!==k?(R=ue("motion-card motion-list-item group flex min-w-0 flex-col gap-2 rounded-lg border bg-card p-3 text-left transition-colors hover:border-foreground/20",N.shell,k),t[3]=N.shell,t[4]=k,t[5]=R):R=t[5];const F=`Open session ${L}`;let A;t[6]!==r?(A=s.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-xs text-muted-foreground",children:r}),t[6]=r,t[7]=A):A=t[7];let E;t[8]!==f?(E=(f==null?void 0:f.model)&&s.jsx("span",{className:"shrink-0 font-mono text-xs text-muted-foreground",children:lt(f.model)}),t[8]=f,t[9]=E):E=t[9];let C;t[10]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(Fe,{"data-icon":"inline-end",className:"shrink-0 text-transparent transition-colors group-hover:text-muted-foreground"}),t[10]=C):C=t[10];let D;t[11]!==A||t[12]!==E?(D=s.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[A,E,C]}),t[11]=A,t[12]=E,t[13]=D):D=t[13];const O=u?"truncate":"line-clamp-2";let se;t[14]!==O?(se=ue("text-sm font-medium leading-snug text-foreground",O),t[14]=O,t[15]=se):se=t[15];let P;t[16]!==se||t[17]!==L?(P=s.jsx("span",{className:se,children:L}),t[16]=se,t[17]=L,t[18]=P):P=t[18];let ne;t[19]!==g||t[20]!==P||t[21]!==F||t[22]!==D?(ne=s.jsxs(U,{variant:"ghost",onClick:g,className:"-m-1 h-auto min-w-0 flex-col items-stretch justify-start gap-1 whitespace-normal p-1 text-left","aria-label":F,children:[D,P]}),t[19]=g,t[20]=P,t[21]=F,t[22]=D,t[23]=ne):ne=t[23];let ie;t[24]!==N.text?(ie=ue("flex items-center gap-1.5 text-xs font-medium",N.text),t[24]=N.text,t[25]=ie):ie=t[25];let le;t[26]!==N.icon?(le=s.jsx(rs,{icon:N.icon}),t[26]=N.icon,t[27]=le):le=t[27];let te;t[28]!==N.label?(te=s.jsx("span",{className:"truncate",children:N.label}),t[28]=N.label,t[29]=te):te=t[29];const ce=a.lastActivityAt||a.lastModified;let G;t[30]!==ce?(G=ot(ce),t[30]=ce,t[31]=G):G=t[31];let oe;t[32]!==G?(oe=s.jsx("span",{className:"ml-auto shrink-0 font-mono text-xs font-normal text-muted-foreground",children:G}),t[32]=G,t[33]=oe):oe=t[33];let Q;t[34]!==ie||t[35]!==le||t[36]!==te||t[37]!==oe?(Q=s.jsxs("div",{className:ie,children:[le,te,oe]}),t[34]=ie,t[35]=le,t[36]=te,t[37]=oe,t[38]=Q):Q=t[38];let H;t[39]!==m||t[40]!==y.length||t[41]!==b||t[42]!==o||t[43]!==a.sessionId?(H=b&&s.jsx(Wt,{request:b,queued:y.length-1,responding:o.has(b.requestId),onRespond:(re,Y)=>m(a.sessionId,re,Y)}),t[39]=m,t[40]=y.length,t[41]=b,t[42]=o,t[43]=a.sessionId,t[44]=H):H=t[44];let W;t[45]!==w||t[46]!==p||t[47]!==b||t[48]!==o||t[49]!==a.sessionId?(W=!b&&w&&s.jsx(es,{request:w,responding:o.has(w.requestId),onChoose:(re,Y)=>p(a.sessionId,re,Y)},w.requestId),t[45]=w,t[46]=p,t[47]=b,t[48]=o,t[49]=a.sessionId,t[50]=W):W=t[50];let K;t[51]!==w||t[52]!==I||t[53]!==j||t[54]!==b||t[55]!==o||t[56]!==a.sessionId?(K=!b&&!w&&I&&s.jsx(Bt,{request:I,responding:o.has(I.requestId),onAnswer:(re,Y)=>j(a.sessionId,re,Y)},I.requestId),t[51]=w,t[52]=I,t[53]=j,t[54]=b,t[55]=o,t[56]=a.sessionId,t[57]=K):K=t[57];let X;t[58]!==w||t[59]!==I||t[60]!==c||t[61]!==x||t[62]!==g||t[63]!==_||t[64]!==b||t[65]!==o||t[66]!==a.sessionId?(X=!b&&!w&&!I&&_&&s.jsx(Jt,{request:_,responding:o.has(_.toolUseId),gone:c.has(_.toolUseId),onAnswer:(re,Y)=>x(a.sessionId,re,Y),onOpenSession:g},_.toolUseId),t[58]=w,t[59]=I,t[60]=c,t[61]=x,t[62]=g,t[63]=_,t[64]=b,t[65]=o,t[66]=a.sessionId,t[67]=X):X=t[67];let J;t[68]!==S||t[69]!==f?(J=!S&&(f==null?void 0:f.currentTool)&&s.jsx(ds,{tool:f.currentTool}),t[68]=S,t[69]=f,t[70]=J):J=t[70];let Z;t[71]!==S||t[72]!==u||t[73]!==f?(Z=!u&&!S&&(f==null?void 0:f.lastAssistantText)&&s.jsx("p",{className:"line-clamp-4 text-sm leading-relaxed text-muted-foreground",children:f.lastAssistantText}),t[71]=S,t[72]=u,t[73]=f,t[74]=Z):Z=t[74];let ee;t[75]!==f?(ee=f&&s.jsx(us,{summary:f}),t[75]=f,t[76]=ee):ee=t[76];let ae;return t[77]!==ne||t[78]!==Q||t[79]!==H||t[80]!==W||t[81]!==K||t[82]!==X||t[83]!==J||t[84]!==Z||t[85]!==ee||t[86]!==R?(ae=s.jsxs("div",{className:R,children:[ne,Q,H,W,K,X,J,Z,ee]}),t[77]=ne,t[78]=Q,t[79]=H,t[80]=W,t[81]=K,t[82]=X,t[83]=J,t[84]=Z,t[85]=ee,t[86]=R,t[87]=ae):ae=t[87],ae});function ds(l){const e=B.c(7),{tool:t}=l;let n;e[0]!==t.name?(n=s.jsx("span",{className:"shrink-0 font-mono text-xs text-muted-foreground",children:t.name}),e[0]=t.name,e[1]=n):n=e[1];let i;e[2]!==t.summary?(i=s.jsx("code",{className:"min-w-0 flex-1 truncate font-mono text-xs text-foreground/80",children:t.summary}),e[2]=t.summary,e[3]=i):i=e[3];let r;return e[4]!==n||e[5]!==i?(r=s.jsxs("div",{className:"flex min-w-0 items-center gap-2 rounded-md bg-muted/50 px-2.5 py-2",children:[n,i]}),e[4]=n,e[5]=i,e[6]=r):r=e[6],r}function us(l){const e=B.c(11),{summary:t}=l,n=t.filesTotal,i=t.context,r=n.count>0,o=i!==null&&i.used>0;if(!r&&!o)return null;let c;e[0]!==n.additions||e[1]!==n.count||e[2]!==n.deletions||e[3]!==r?(c=r&&s.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsxs("span",{className:"truncate",children:[n.count," file",n.count===1?"":"s"]}),s.jsx(at,{add:n.additions,del:n.deletions})]}),e[0]=n.additions,e[1]=n.count,e[2]=n.deletions,e[3]=r,e[4]=c):c=e[4];let d;e[5]!==i||e[6]!==o?(d=o&&s.jsxs("span",{className:ue("ml-auto shrink-0",os(i.percent)),children:["ctx ",i.percent,"%"]}),e[5]=i,e[6]=o,e[7]=d):d=e[7];let g;return e[8]!==c||e[9]!==d?(g=s.jsxs("div",{className:"mt-auto flex items-center gap-2 border-t pt-2 font-mono text-xs text-muted-foreground",children:[c,d]}),e[8]=c,e[9]=d,e[10]=g):g=e[10],g}const fs=8e3,ms=12,xs="Start Claude Code, Codex, or Copilot and every session shows up here",hs=[{id:"all",label:"All"},{id:"running",label:"Running"},{id:"needs-you",label:"Needs you"},{id:"finished",label:"Finished"}],gs=[{id:"grid",label:"Grid layout",Icon:Ct},{id:"list",label:"List layout",Icon:Tt}];function Ns(l){const e=B.c(118),{onSelectSession:t}=l,{sessions:n,procBySession:i,newlyCompleted:r,refresh:o}=rt(),{summaries:c,loading:d,error:g,refresh:m}=Mt(),{permissionsBySession:x,questionsBySession:j,elicitationsBySession:p,dialogsBySession:u,awaitingPlan:a,responding:h,respond:f,answerQuestion:y,answerElicitation:v,answerDialog:q,refresh:T}=ct();let N;e[0]===Symbol.for("react.memo_cache_sentinel")?(N=new Set,e[0]=N):N=e[0];const[b,_]=V.useState(N),{names:I}=dt(),{names:w}=ut(),[S,z]=V.useState("all");let L;e[1]===Symbol.for("react.memo_cache_sentinel")?(L=ft("mission-control-layout"),e[1]=L):L=e[1];const[k,R]=mt(L,"grid");let F;e[2]!==a||e[3]!==u||e[4]!==p||e[5]!==r||e[6]!==x||e[7]!==i||e[8]!==j||e[9]!==n||e[10]!==c?(F=ns({sessions:n,procBySession:i,summaries:c,permissionsBySession:x,questionsBySession:j,elicitationsBySession:p,dialogsBySession:u,awaitingPlan:a,newlyCompleted:r}),e[2]=a,e[3]=u,e[4]=p,e[5]=r,e[6]=x,e[7]=i,e[8]=j,e[9]=n,e[10]=c,e[11]=F):F=e[11];const A=F;let E;e[12]!==A?(E=ls(A),e[12]=A,e[13]=E):E=e[13];const C=E;let D;e[14]!==A||e[15]!==S?(D=is(A,S),e[14]=A,e[15]=S,e[16]=D):D=e[16];const O=D;let se;e[17]!==T||e[18]!==o||e[19]!==m?(se=()=>{o(),m(),T()},e[17]=T,e[18]=o,e[19]=m,e[20]=se):se=e[20];const P=se;let ne,ie;e[21]!==o?(ne=()=>{const $=setInterval(()=>{document.visibilityState==="visible"&&o()},fs);return()=>clearInterval($)},ie=[o],e[21]=o,e[22]=ne,e[23]=ie):(ne=e[22],ie=e[23]),V.useEffect(ne,ie);let le;e[24]!==y?(le=async($,M,Me)=>{(await y($,M,Me)).ok||_(Ge=>new Set(Ge).add(M))},e[24]=y,e[25]=le):le=e[25];const te=le;let ce;e[26]!==A.length?(ce=function(M){A.length<=ms?Ot(M,{kind:"fade"}):V.startTransition(M)},e[26]=A.length,e[27]=ce):ce=e[27];const G=ce;let oe;e[28]===Symbol.for("react.memo_cache_sentinel")?(oe=s.jsx("h2",{className:"truncate text-sm font-semibold",children:"Mission Control"}),e[28]=oe):oe=e[28];let Q;e[29]!==C.total?(Q=s.jsx(Te,{variant:"secondary",children:C.total}),e[29]=C.total,e[30]=Q):Q=e[30];let H;e[31]!==C.needsYou?(H=C.needsYou>0&&s.jsxs(Te,{variant:"outline",className:"border-warning/40 text-warning",children:[C.needsYou," need you"]}),e[31]=C.needsYou,e[32]=H):H=e[32];let W;e[33]!==C.failed?(W=C.failed>0&&s.jsxs(Te,{variant:"destructive",children:[C.failed," failed"]}),e[33]=C.failed,e[34]=W):W=e[34];let K;e[35]!==Q||e[36]!==H||e[37]!==W?(K=s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[oe,Q,H,W]}),e[35]=Q,e[36]=H,e[37]=W,e[38]=K):K=e[38];let X;e[39]!==S?(X=[S],e[39]=S,e[40]=X):X=e[40];let J;e[41]!==S||e[42]!==G?(J=$=>{const M=$.at(-1);M&&M!==S&&G(()=>z(M))},e[41]=S,e[42]=G,e[43]=J):J=e[43];let Z;e[44]!==C.needsYou?(Z=hs.map($=>s.jsxs(ke,{value:$.id,"aria-label":`Show ${$.label.toLowerCase()} sessions`,children:[$.label,$.id==="needs-you"&&C.needsYou>0&&s.jsx("span",{className:"font-mono text-warning",children:C.needsYou})]},$.id)),e[44]=C.needsYou,e[45]=Z):Z=e[45];let ee;e[46]!==X||e[47]!==J||e[48]!==Z?(ee=s.jsx(ze,{value:X,onValueChange:J,variant:"outline",size:"sm",spacing:0,"aria-label":"Filter sessions",children:Z}),e[46]=X,e[47]=J,e[48]=Z,e[49]=ee):ee=e[49];let ae;e[50]!==k||e[51]!==R||e[52]!==G?(ae=gs.map($=>{const{id:M,label:Me,Icon:Oe}=$;return s.jsx(U,{variant:"ghost",size:"icon-xs","aria-label":Me,"aria-pressed":k===M,onClick:()=>{M!==k&&G(()=>R(M))},className:ue(k===M&&"bg-accent text-accent-foreground"),children:s.jsx(Oe,{"data-icon":"inline-start"})},M)}),e[50]=k,e[51]=R,e[52]=G,e[53]=ae):ae=e[53];const re=d&&"animate-spin";let Y;e[54]!==re?(Y=ue(re),e[54]=re,e[55]=Y):Y=e[55];let fe;e[56]!==Y?(fe=s.jsx(At,{"data-icon":"inline-start",className:Y}),e[56]=Y,e[57]=fe):fe=e[57];let me;e[58]!==P||e[59]!==fe?(me=s.jsx(U,{variant:"ghost",size:"icon-xs","aria-label":"Refresh Mission Control",onClick:P,children:fe}),e[58]=P,e[59]=fe,e[60]=me):me=e[60];let xe;e[61]!==ae||e[62]!==me?(xe=s.jsxs("div",{className:"flex items-center gap-1",children:[ae,me]}),e[61]=ae,e[62]=me,e[63]=xe):xe=e[63];let he;e[64]!==ee||e[65]!==xe?(he=s.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[ee,xe]}),e[64]=ee,e[65]=xe,e[66]=he):he=e[66];let ge;e[67]!==K||e[68]!==he?(ge=s.jsxs("header",{className:"flex min-h-12 shrink-0 flex-wrap items-center gap-3 border-b px-4 py-2",children:[K,he]}),e[67]=K,e[68]=he,e[69]=ge):ge=e[69];let pe;e[70]!==g||e[71]!==P?(pe=g&&s.jsxs(_e,{variant:"destructive",className:"mb-4",children:[s.jsx(Et,{}),s.jsx(qe,{children:"Mission Control could not refresh"}),s.jsx(wt,{className:"truncate",children:g}),s.jsx(vt,{children:s.jsx(U,{variant:"outline",size:"xs",onClick:P,children:"Retry"})})]}),e[70]=g,e[71]=P,e[72]=pe):pe=e[72];let be;e[73]!==A.length||e[74]!==S||e[75]!==d||e[76]!==O.length?(be=O.length===0&&!d&&s.jsx(xt,{className:"min-h-64",children:s.jsxs(ht,{children:[s.jsx(gt,{variant:"icon",children:s.jsx(kt,{})}),s.jsx(pt,{children:A.length===0?"No live sessions":`Nothing matches "${S}"`}),s.jsx(bt,{children:A.length===0?xs:"Try a different filter."})]})}),e[73]=A.length,e[74]=S,e[75]=d,e[76]=O.length,e[77]=be):be=e[77];let je;e[78]!==A.length||e[79]!==d||e[80]!==O.length?(je=O.length===0&&d&&A.length===0&&s.jsxs("div",{className:"flex items-center justify-center gap-2 py-16 text-sm text-muted-foreground",children:[s.jsx(jt,{}),"Loading sessions…"]}),e[78]=A.length,e[79]=d,e[80]=O.length,e[81]=je):je=e[81];const Re=k==="grid"&&"md:grid-cols-2 2xl:grid-cols-3";let we;e[82]!==Re?(we=ue("grid grid-cols-1 gap-3",Re),e[82]=Re,e[83]=we):we=e[83];let ve;if(e[84]!==q||e[85]!==v||e[86]!==b||e[87]!==te||e[88]!==k||e[89]!==t||e[90]!==w||e[91]!==f||e[92]!==h||e[93]!==I||e[94]!==O){let $;e[96]!==q||e[97]!==v||e[98]!==b||e[99]!==te||e[100]!==k||e[101]!==t||e[102]!==w||e[103]!==f||e[104]!==h||e[105]!==I?($=M=>s.jsx(cs,{card:M,compact:k==="list",customName:I[M.session.sessionId],projectLabel:w[M.session.dirName]??Nt(M.session),responding:h,goneQuestions:b,onOpen:()=>t(M.session.dirName,M.session.fileName),onRespond:f,onAnswerQuestion:te,onAnswerElicitation:v,onChooseDialog:q},M.session.sessionId),e[96]=q,e[97]=v,e[98]=b,e[99]=te,e[100]=k,e[101]=t,e[102]=w,e[103]=f,e[104]=h,e[105]=I,e[106]=$):$=e[106],ve=O.map($),e[84]=q,e[85]=v,e[86]=b,e[87]=te,e[88]=k,e[89]=t,e[90]=w,e[91]=f,e[92]=h,e[93]=I,e[94]=O,e[95]=ve}else ve=e[95];let Ne;e[107]!==we||e[108]!==ve?(Ne=s.jsx("div",{className:we,children:ve}),e[107]=we,e[108]=ve,e[109]=Ne):Ne=e[109];let ye;e[110]!==pe||e[111]!==be||e[112]!==je||e[113]!==Ne?(ye=s.jsx(yt,{className:"flex-1",children:s.jsxs("div",{className:"p-4",children:[pe,be,je,Ne]})}),e[110]=pe,e[111]=be,e[112]=je,e[113]=Ne,e[114]=ye):ye=e[114];let Ce;return e[115]!==ge||e[116]!==ye?(Ce=s.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[ge,ye]}),e[115]=ge,e[116]=ye,e[117]=Ce):Ce=e[117],Ce}export{Ns as MissionControl};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
(function(){"use strict";const ct=["codex","copilot","claude"],ut="[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";function we(t,e){const n=new TextEncoder().encode(e);let s="";for(const i of n)s+=String.fromCharCode(i);const o=btoa(s).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");return`${t}${o}`}function Se(t,e){if(!e.startsWith(t))return null;try{const n=e.slice(t.length).replace(/-/g,"+").replace(/_/g,"/"),s=atob(n),o=Uint8Array.from(s,i=>i.charCodeAt(0));return new TextDecoder().decode(o)}catch{return null}}function Ct(t){return{owns:e=>typeof e=="string"&&e.startsWith(t),encode:e=>we(t,e),decode:e=>Se(t,e)}}function xt(t){const e=new RegExp(`(${ut})\\.jsonl$`,"i").exec(t);return e?e[1]:null}const At={urlId:t=>t.replace(/\.jsonl$/,""),fileNameFromUrlId:t=>t.endsWith(".jsonl")?t:`${t}.jsonl`};function It(t){return`'${t.replace(/'/g,"'\\''")}'`}function V(t,e){return e?[t,e]:[]}const Mt="codex__",wt="copilot__",Ee=new Set(["default","plan","acceptEdits","dontAsk","auto"]),Ne={kind:"claude",displayName:"Claude Code",binName:"claude",dirName:{owns:t=>typeof t=="string"&&!t.startsWith(Mt)&&!t.startsWith(wt),encode:t=>(t.replace(/[\\/]+$/,"")||t).replace(/[^a-zA-Z0-9]/g,"-"),decode:t=>{const e=/^([A-Za-z])--(.*)$/.exec(t);return e?`${e[1]}:\\${e[2].replace(/-/g,"\\")}`:"/"+t.replace(/^-/,"").replace(/-/g,"/")}},sessionFile:{name:t=>`${t}.jsonl`,sessionId:xt,...At},metadataFromHead:!0,resume:{command:t=>`claude --resume ${t}`,args:t=>["--resume",t]},launchArgs:{permissions:t=>t!=null&&t.mode?t.mode==="bypassPermissions"?["--dangerously-skip-permissions"]:[...Ee.has(t.mode)?["--permission-mode",t.mode]:[],...(t.allowedTools??[]).flatMap(e=>["--allowedTools",e]),...(t.disallowedTools??[]).flatMap(e=>["--disallowedTools",e])]:["--permission-mode","default"],model:t=>V("--model",t),effort:t=>V("--effort",t),fastTier:()=>[]},serviceTier:null,cli:{packageName:"@anthropic-ai/claude-code",homebrew:{name:"claude-code",cask:!1},wingetId:null,versionArgs:["--version"],selfUpdate:{args:["update"],matches:t=>t.endsWith("/.local/bin/claude")||t.endsWith("/.local/bin/claude.exe")||t.includes("/.local/share/claude/")},homeDirName:".claude",homeEnvVar:null,installMarker:"projects",homeIsDiscoverable:!1},config:{rootDirName:".claude",instructions:[{in:"scope",path:"CLAUDE.md",scopes:["global","project"]},{in:"root",path:"CLAUDE.md",label:".claude/CLAUDE.md",scopes:["project"]}],settings:[{in:"root",path:"settings.json",scopes:["global"]},{in:"root",path:"settings.local.json",scopes:["project"]}],skillsDir:"skills",agentsDir:"agents",commandsDir:"commands",themesDir:"themes",pluginsDir:"plugins"},contextWindow:{defaultLimit:1e6,limits:[{match:"claude-haiku-4-5",limit:2e5},{match:"claude-haiku-4-1",limit:2e5},{match:"claude-sonnet-4-5",limit:2e5},{match:"claude-opus-4-5",limit:2e5},{match:"claude-opus-4-1",limit:2e5}],compactBuffer:33e3,extendedContext:{marker:"[1m]",limit:1e6}},capabilities:{worktrees:!0,mcp:!0,slashCommands:!0,workflows:!0,agentTeams:!0,subagentTranscripts:!0,sharing:!0,goals:!0,undo:!0,redo:!0,nativeRewind:!1,fileCheckpoints:!0,reasoningEffort:!0,fastTier:!0,imageInput:!0,planMode:!0,midTurnSteering:!1,stopSession:!0,ultracode:!0,contextWindow:!0,externalProcesses:!1,modelFallbackNotices:!0,autoPermissionMode:"per-model",settingsApply:"live"}},St={appServerValue:"priority",cliConfigValue:"fast"},ve={kind:"codex",displayName:"Codex",binName:"codex",dirName:Ct(Mt),sessionFile:{name:(t,e=new Date)=>{const n=String(e.getFullYear()),s=String(e.getMonth()+1).padStart(2,"0"),o=String(e.getDate()).padStart(2,"0"),i=String(e.getHours()).padStart(2,"0"),l=String(e.getMinutes()).padStart(2,"0"),f=String(e.getSeconds()).padStart(2,"0");return`${n}/${s}/${o}/rollout-${n}-${s}-${o}T${i}-${l}-${f}-${t}.jsonl`},sessionId:xt,...At},metadataFromHead:!1,resume:{command:(t,e)=>e?`codex -C ${It(e)} resume ${t}`:`codex resume ${t}`,args:t=>["resume",t]},launchArgs:{permissions:t=>{const e=(t==null?void 0:t.mode)||"default";return e==="bypassPermissions"?["--dangerously-bypass-approvals-and-sandbox"]:["--sandbox",e==="plan"?"read-only":"workspace-write","-c",'approval_policy="never"']},model:t=>V("-m",t),effort:t=>t?["-c",`model_reasoning_effort=${JSON.stringify(t)}`]:[],fastTier:t=>t?["-c",`service_tier=${JSON.stringify(St.cliConfigValue)}`,"--enable","fast_mode"]:[]},serviceTier:St,cli:{packageName:"@openai/codex",homebrew:{name:"codex",cask:!1},wingetId:null,versionArgs:["--version"],selfUpdate:null,homeDirName:".codex",homeEnvVar:"CODEX_HOME",installMarker:"",homeIsDiscoverable:!0},config:{rootDirName:".codex",instructions:[{in:"scope",path:"AGENTS.md",scopes:["global","project"]}],settings:[{in:"root",path:"config.toml",scopes:["global","project"]}],skillsDir:"skills",agentsDir:"agents",commandsDir:"prompts",themesDir:null,pluginsDir:null},contextWindow:{defaultLimit:272e3,limits:[],compactBuffer:0,extendedContext:null},capabilities:{worktrees:!1,mcp:!1,slashCommands:!1,workflows:!1,agentTeams:!1,subagentTranscripts:!0,sharing:!1,goals:!0,undo:!0,redo:!0,nativeRewind:!1,fileCheckpoints:!1,reasoningEffort:!0,fastTier:!0,imageInput:!0,planMode:!0,midTurnSteering:!0,stopSession:!1,ultracode:!1,contextWindow:!1,externalProcesses:!1,modelFallbackNotices:!1,autoPermissionMode:"never",settingsApply:"next-turn"}},Be={kind:"copilot",displayName:"GitHub Copilot CLI",binName:"copilot",dirName:Ct(wt),sessionFile:{name:t=>`${t}/events.jsonl`,sessionId:t=>{const e=new RegExp(`^(${ut})/events\\.jsonl$`,"i").exec(t);return e?e[1]:null},urlId:t=>{const e=new RegExp(`^(${ut})/events\\.jsonl$`,"i").exec(t);return e?e[1]:t.replace(/\.jsonl$/,"")},fileNameFromUrlId:t=>t.endsWith(".jsonl")?t:`${t}/events.jsonl`},metadataFromHead:!0,resume:{command:(t,e)=>e?`copilot -C ${It(e)} --resume ${t}`:`copilot --resume ${t}`,args:t=>[`--resume=${t}`]},launchArgs:{permissions:t=>(t==null?void 0:t.mode)==="bypassPermissions"||(t==null?void 0:t.mode)==="auto"?["--allow-all"]:[],model:t=>V("--model",t),effort:t=>V("--reasoning-effort",t),fastTier:()=>[]},serviceTier:null,cli:{packageName:"@github/copilot",homebrew:{name:"copilot-cli",cask:!0},wingetId:"GitHub.Copilot",versionArgs:["--version"],selfUpdate:{args:["update"],matches:t=>t.endsWith("/.local/bin/copilot")||t==="/usr/local/bin/copilot"},homeDirName:".copilot",homeEnvVar:"COPILOT_HOME",installMarker:"session-state",homeIsDiscoverable:!0},config:{rootDirName:".copilot",instructions:[{in:"scope",path:"AGENTS.md",scopes:["global","project"]}],settings:[{in:"root",path:"config.json",scopes:["global"]}],skillsDir:"skills",agentsDir:null,commandsDir:null,themesDir:null,pluginsDir:null},contextWindow:{defaultLimit:2e5,limits:[],compactBuffer:0,extendedContext:null},capabilities:{worktrees:!1,mcp:!1,slashCommands:!1,workflows:!1,agentTeams:!1,subagentTranscripts:!1,sharing:!1,goals:!1,undo:!0,redo:!1,nativeRewind:!0,fileCheckpoints:!1,reasoningEffort:!1,fastTier:!1,imageInput:!1,planMode:!0,midTurnSteering:!0,stopSession:!0,ultracode:!1,contextWindow:!1,externalProcesses:!0,modelFallbackNotices:!1,autoPermissionMode:"always",settingsApply:"next-turn"}},Re=Object.freeze({claude:Ne,codex:ve,copilot:Be});function dt(t){return Re[t]}function pt(t){return t.type==="user"}function ft(t){return t.type==="assistant"}function Et(t){return t.type==="progress"}function Nt(t){return t.type==="system"}function vt(t){return t.type==="summary"}function Pe(t){return t.type==="queue-operation"}function Bt(t){return t.type==="attachment"}function Ue(t){return t.type==="user"&&t.isCompactSummary===!0}function Rt(t){return t.type==="system"&&t.subtype==="compact_boundary"}function Pt(t,e){let n=0;for(const s of t)e[s.name]=(e[s.name]??0)+1,s.isError&&n++;return n}function Ut(t,e){t.totalInputTokens+=e.input_tokens,t.totalOutputTokens+=e.output_tokens,t.totalCacheCreationTokens+=e.cache_creation_input_tokens??0,t.totalCacheReadTokens+=e.cache_read_input_tokens??0}function tt(t){return{totalInputTokens:0,totalOutputTokens:0,totalCacheCreationTokens:0,totalCacheReadTokens:0,toolCallCounts:{},errorCount:0,totalDurationMs:0,turnCount:t}}function et(t){const e=tt(t.length);for(const n of t){n.tokenUsage&&Ut(e,n.tokenUsage),n.durationMs&&(e.totalDurationMs+=n.durationMs),e.errorCount+=Pt(n.toolCalls,e.toolCallCounts);for(const s of n.subAgentActivity)e.errorCount+=Pt(s.toolCalls,e.toolCallCounts),s.tokenUsage&&Ut(e,s.tokenUsage)}return e}const $e=/<(agent-message|teammate-message)([^>]*)>([\s\S]*?)<\/\1>/g,Fe=[/\bteammate_id=(?:"([^"]*)"|'([^']*)')/,/\bfrom=(?:"([^"]*)"|'([^']*)')/];function De(t){for(const e of Fe){const n=t.match(e),s=(n==null?void 0:n[1])??(n==null?void 0:n[2]);if(s)return s}return null}function mt(t){let e=null,n=!1;const s=t.replace($e,(o,i,l,f)=>(n=!0,e===null&&(e=De(l)),f.trim()));return{sender:e,matched:n,body:n?s.trim():t}}function nt(t){return typeof t=="string"?t:t.filter(e=>e.type==="text").map(e=>e.text).join(`
|
|
2
|
+
`)}function $t(t){return t?typeof t=="string"?t:t.map(e=>e.type==="text"?e.text:"").filter(Boolean).join(`
|
|
3
|
+
`):""}function Ft(t){if(!(t!=null&&t.trim()))return!1;const e=t.trimStart();return e.startsWith("<")?!e.includes("<task-notification>")&&!e.startsWith("<system-reminder>")&&!e.startsWith("<local-command-"):!0}const Oe=/<task-notification>[\s\S]*?<\/task-notification>/g,je=/<[^>]*>/g;function We(t){var n;if(((n=t.origin)==null?void 0:n.kind)==="task-notification")return!0;const e=nt(t.message.content);return e.includes("<task-notification>")?e.replace(Oe,"").replace(je,"").trim()==="":!1}function Le(t){if(!Bt(t))return null;const e=t.attachment;if(!e||e.type!=="queued_command"||e.commandMode!=="prompt")return null;const n=e.prompt;if(n==null)return null;const s=typeof n=="string"?n:nt(n);if(!Ft(s))return null;const o=e.origin;if((o==null?void 0:o.kind)==="peer"){const l=o.name??o.from??null;if(l)return{raw:s,sender:l,body:o.body??mt(s).body}}if((o==null?void 0:o.kind)==="human")return{raw:s,sender:null,body:s};const i=mt(s);return{raw:s,sender:i.sender,body:i.body}}const qe=[["attributionAgent","agent"],["attributionSkill","skill"],["attributionPlugin","plugin"],["attributionMcpServer","mcpServer"],["attributionMcpTool","mcpTool"]];function ze(t,e){let n=t;for(const[s,o]of qe){const i=e[s];typeof i!="string"||!i||(n={...n,[o]:i})}return n}function Je(t,e){var s,o;if(!t)return{...e};const n=(((s=t.output_tokens_details)==null?void 0:s.thinking_tokens)??0)+(((o=e.output_tokens_details)==null?void 0:o.thinking_tokens)??0);return{input_tokens:t.input_tokens+e.input_tokens,output_tokens:t.output_tokens+e.output_tokens,cache_creation_input_tokens:(t.cache_creation_input_tokens??0)+(e.cache_creation_input_tokens??0),cache_read_input_tokens:(t.cache_read_input_tokens??0)+(e.cache_read_input_tokens??0),speed:e.speed??t.speed,...t.output_tokens_details||e.output_tokens_details?{output_tokens_details:{thinking_tokens:n}}:{}}}const Ke=/^This session is being continued from a previous conversation[\s\S]*?\n\nSummary:\s*\n/,Ve=/\n+(?:If you need specific details from before compaction|(?:Please c|C)ontinue the conversation from where it left off)[\s\S]*$/;function Qe(t){return nt(t).trim().replace(Ke,"").replace(Ve,"").trim()}function Ge(t){if(t)return{trigger:t.trigger,preTokens:t.preTokens,postTokens:t.postTokens}}function st(t,e){return{id:t.uuid??crypto.randomUUID(),userMessage:e,contentBlocks:[],thinking:[],assistantText:[],toolCalls:[],subAgentActivity:[],timestamp:t.timestamp??"",durationMs:null,tokenUsage:null,model:null}}function He(t){const e=[];let n=0;for(;n<t.length;){const s=t[n];if(s.kind==="tool_calls"){const o=s.toolCalls.findIndex(i=>i.name==="EnterPlanMode");if(o!==-1){const i=s.toolCalls[o],l=String(i.input.plan??""),f=s.timestamp,_=s.toolCalls.slice(0,o);_.length>0&&e.push({kind:"tool_calls",toolCalls:_,timestamp:s.timestamp});const T=[],b=s.toolCalls.slice(o+1),h=b.findIndex(k=>k.name==="ExitPlanMode");if(h!==-1){T.push(...b.slice(0,h));const k=b[h],p=k.input.path?String(k.input.path):void 0;let N="pending";k.result!==null&&(N=k.isError?"rejected":"approved"),e.push({kind:"plan_mode",plan:l,planFilePath:p,status:N,toolCalls:T,timestamp:f});const S=b.slice(h+1);S.length>0&&e.push({kind:"tool_calls",toolCalls:S,timestamp:s.timestamp}),n++;continue}else{T.push(...b);let k,p,N="pending",S=n+1;const w=[];for(;S<t.length;){const B=t[S];if(B.kind==="tool_calls"){const P=B.toolCalls.findIndex($=>$.name==="ExitPlanMode");if(P!==-1){T.push(...B.toolCalls.slice(0,P)),k=B.toolCalls[P],p=k.input.path?String(k.input.path):void 0,k.result!==null&&(N=k.isError?"rejected":"approved");const $=B.toolCalls.slice(P+1);e.push({kind:"plan_mode",plan:l,planFilePath:p,status:N,toolCalls:T,timestamp:f}),e.push(...w),$.length>0&&e.push({kind:"tool_calls",toolCalls:$,timestamp:B.timestamp}),n=S+1;break}else T.push(...B.toolCalls),S++}else if(B.kind==="hook_event"||B.kind==="text"||B.kind==="queued_prompt"||B.kind==="agent_message")w.push(B),S++;else break}k||(e.push({kind:"plan_mode",plan:l,planFilePath:void 0,status:"pending",toolCalls:T,timestamp:f}),e.push(...w),n=S);continue}}}e.push(s),n++}return e}function Xe(t){return t.contentBlocks.some(e=>e.kind==="agent_message")?{...t,contentBlocks:t.contentBlocks.map(e=>{if(e.kind!=="agent_message")return e;const{reply:n,...s}=e;return s})}:t}function Dt(t){var s;const e=t.map(Xe),n=new Map;for(const o of e)for(const i of o.contentBlocks){if(i.kind==="agent_message"){const l=n.get(i.sender);l?l.push(i):n.set(i.sender,[i]);continue}if(i.kind==="tool_calls")for(const l of i.toolCalls){if(l.name!=="SendMessage")continue;const f=l.input.to;if(typeof f!="string"||!f)continue;const _=(s=n.get(f))==null?void 0:s.shift();if(!_)continue;const T=l.input.summary;_.reply={summary:typeof T=="string"?T:"",timestamp:l.timestamp||i.timestamp||""}}}return e}function Ze(t){const e=[];let n=!1;for(let s=0;s<t.length;s++){const o=t[s];if(vt(o)||Rt(o)){n=!1;continue}if(pt(o)&&!o.isMeta){const i=o.message.content;if(n&&Array.isArray(i)&&i.some(f=>f.type==="tool_result"))continue;e.push(s),n=!0;continue}ft(o)&&!n&&(e.push(s),n=!0)}return e}function Ot(t){var F,I;const e=[],n=[];let s=null,o=0,i=null,l=null;function f(a){l&&(a.compactionSummary=l.summary,a.compactionMeta=l.meta,l=null)}let _=null;const T=new Map,b=new Set,h=new Map,k=new Map,p=new Set,N=new Map,S=[],w=new Map;function B(a,c){let g=w.get(a);g||(g=new Map,w.set(a,g)),g.set(c,(g.get(c)??0)+1)}function P(a,c){const g=w.get(a),d=g==null?void 0:g.get(c);return!g||!d?!1:(d===1?g.delete(c):g.set(c,d-1),!0)}function $(){for(const a of S)a.turn.contentBlocks.push(a.sender?{kind:"agent_message",sender:a.sender,body:a.body,timestamp:a.timestamp}:{kind:"queued_prompt",content:a.content,timestamp:a.timestamp});S.length=0}function O(a){if(!i)return;const c=h.get(a);if(!c||c.length===0)return;i.subAgentActivity.push(...c),h.delete(a);const g=p.has(a)?"background_agent":"sub_agent",d=k.get(a);if(d)d.messages.push(...c);else{const r={kind:g,messages:[...c]};i.contentBlocks.push(r),k.set(a,r)}}function j(){if(i){for(const a of i.toolCalls)O(a.id);for(const[a]of h)O(a);for(const a of i.contentBlocks)if(a.kind==="hook_event")for(const c of a.events){if(!(c.eventName==="PostToolUse"||c.eventName.startsWith("PostToolUse:"))||!c.toolUseId)continue;const d=i.toolCalls.find(r=>r.id===c.toolUseId);d&&(c.updatedToolOutput&&(d.outputReplacedByHook=!0),c.durationMs!==void 0&&(d.hookDurationMs=(d.hookDurationMs??0)+c.durationMs))}i.contentBlocks=He(i.contentBlocks),e.push(i),s!==null&&n.push(s),s=null,i=null,k.clear()}}for(o=0;o<t.length;o++){const a=t[o];if(vt(a)){j(),l={summary:a.summary};continue}if(Rt(a)){j(),l={meta:Ge(a.compactMetadata)};continue}if(Ue(a)){j(),s=o,i=st(a,null),i.compactionSummary=Qe(a.message.content),i.compactionMeta=l==null?void 0:l.meta,l=null;continue}if(Nt(a)&&a.subtype==="away_summary"&&a.content){_={content:a.content,timestamp:a.timestamp};continue}if(Pe(a)){if(i&&a.operation==="enqueue"&&Ft(a.content)){const c=mt(a.content);S.push({turn:i,content:a.content,timestamp:a.timestamp,sender:c.sender,body:c.body}),B(i,a.content)}continue}if(Bt(a)){const c=Le(a);i&&c!==null&&!P(i,c.raw)&&S.push({turn:i,content:c.raw,timestamp:((F=a.attachment)==null?void 0:F.timestamp)??a.timestamp,sender:c.sender,body:c.body});continue}if(S.length>0){const c=pt(a)&&!a.isMeta?a.message.content:null;if(typeof c=="string"){const g=S.findIndex(d=>d.content===c);if(g>=0){const[d]=S.splice(g,1);P(d.turn,d.content)}}$()}if(pt(a)&&!a.isMeta){const c=a.message.content;if(typeof c!="string"&&Array.isArray(c)&&c.some(d=>d.type==="tool_result")&&i){for(const r of c)if(r.type==="tool_result"){const y=T.get(r.tool_use_id);y&&(y.turn.toolCalls[y.index].result=$t(r.content),y.turn.toolCalls[y.index].isError=r.is_error===!0,T.delete(r.tool_use_id))}const d=a.toolUseResult;if(d!=null&&d.agentId){const r=((I=c.find(M=>M.type==="tool_result"))==null?void 0:I.tool_use_id)??"",y=N.get(r),u=p.has(r),C=[];if(Array.isArray(d.content))for(const M of d.content)M.type==="text"&&C.push(M.text);const m={agentId:d.agentId,parentToolUseId:r||void 0,agentName:(y==null?void 0:y.name)??null,subagentType:(y==null?void 0:y.subagentType)??null,type:"assistant",content:d.content,toolCalls:[],thinking:[],text:C,timestamp:a.timestamp??"",tokenUsage:d.usage?{input_tokens:d.usage.input_tokens??0,output_tokens:d.usage.output_tokens??0,cache_creation_input_tokens:d.usage.cache_creation_input_tokens??0,cache_read_input_tokens:d.usage.cache_read_input_tokens??0}:null,model:null,isBackground:u,prompt:d.prompt,status:d.status,durationMs:d.totalDurationMs,toolUseCount:d.totalToolUseCount};if(!k.get(r)){i.subAgentActivity.push(m);const E={kind:u?"background_agent":"sub_agent",messages:[m]};i.contentBlocks.push(E),k.set(r,E)}}continue}if(We(a)){const g={kind:"task_notification",content:nt(c),timestamp:a.timestamp};if(i){i.contentBlocks.push(g);continue}s=o,i=st(a,null),i.contentBlocks.push(g),f(i);continue}j(),s=o,i=st(a,a.message.content),f(i),_&&(i.contentBlocks.push({kind:"recap",content:_.content,timestamp:_.timestamp}),_=null);continue}if(ft(a)){let c=function(){u.length>0&&(C.contentBlocks.push({kind:"tool_calls",toolCalls:[...u],timestamp:r}),u.length=0)},g=function(){if(y.length>0){const m=C.contentBlocks[C.contentBlocks.length-1];m&&m.kind==="thinking"?m.blocks.push(...y):C.contentBlocks.push({kind:"thinking",blocks:[...y],timestamp:r}),y.length=0}};i||(s=o,i=st(a,null),f(i)),i.model=a.message.model,a.effort&&(i.effort=a.effort),i.attribution=ze(i.attribution,a);const d=a.message.id;b.has(d)||(b.add(d),i.tokenUsage=Je(i.tokenUsage,a.message.usage));const r=a.timestamp??"",y=[],u=[],C=i;for(const m of a.message.content)if(m.type==="thinking"){c();const x=m;if(!x.thinking)continue;i.thinking.push(x),y.push(x)}else if(m.type==="text"){c(),g();const x=/<thinking>([\s\S]*?)<\/thinking>/g;let M=m.text,E;for(;(E=x.exec(m.text))!==null;){const v=E[1].trim();if(v){const R={type:"thinking",thinking:v,signature:""};i.thinking.push(R),i.contentBlocks.push({kind:"thinking",blocks:[R],timestamp:r})}M=M.replace(E[0],"")}if(M=M.trim(),M){i.assistantText.push(M);const v=i.contentBlocks[i.contentBlocks.length-1];v&&v.kind==="text"?v.text.push(M):i.contentBlocks.push({kind:"text",text:[M],timestamp:r})}}else if(m.type==="tool_use"){g();const x={id:m.id,name:m.name,input:m.input,result:null,isError:!1,timestamp:a.timestamp??""},M=i.toolCalls.length;if(i.toolCalls.push(x),u.push(x),T.set(m.id,{turn:i,index:M}),m.name==="Task"||m.name==="Agent"){const E=m.input;E.run_in_background===!0&&p.add(m.id),N.set(m.id,{name:E.name??null,subagentType:E.subagent_type??null})}}g(),c();continue}if(Et(a)&&a.data.type==="agent_progress"){const c=a.data,g=a.parentToolUseID??"";let d=null;if(c.message.type==="assistant"){const m=c.message.message,x=m.id,M=m.usage;M&&x&&!b.has(x)&&(b.add(x),d={input_tokens:M.input_tokens??0,output_tokens:M.output_tokens??0,cache_creation_input_tokens:M.cache_creation_input_tokens??0,cache_read_input_tokens:M.cache_read_input_tokens??0})}const r=c.message.type==="assistant"?c.message.message.model??null:null,y=N.get(g),u={agentId:c.agentId,parentToolUseId:g||void 0,agentName:(y==null?void 0:y.name)??null,subagentType:(y==null?void 0:y.subagentType)??null,type:c.message.type,content:c.message.message.content,toolCalls:[],thinking:[],text:[],timestamp:c.message.timestamp??a.timestamp??"",tokenUsage:d,model:r,isBackground:p.has(g)};if(c.message.type==="assistant"){const m=c.message.message.content;if(Array.isArray(m))for(const x of m)x.type==="thinking"?u.thinking.push(x.thinking):x.type==="text"?u.text.push(x.text):x.type==="tool_use"&&u.toolCalls.push({id:x.id,name:x.name,input:x.input,result:null,isError:!1,timestamp:c.message.timestamp??a.timestamp??""})}else if(c.message.type==="user"){const m=c.message.message.content;if(Array.isArray(m)){for(const x of m)if(x.type==="tool_result"){const M=h.get(g);if(M)for(const E of M){const v=E.toolCalls.find(R=>R.id===x.tool_use_id);v&&(v.result=$t(x.content),v.isError=x.is_error===!0)}}}}let C=h.get(g);C||(C=[],h.set(g,C)),C.push(u),i&&O(g);continue}if(Et(a)&&a.data.type==="hook_progress"){const c=a.data,g=String(c.hook_event_name??c.hookEvent??"unknown"),d=c.hookSpecificOutput,r={eventName:g,source:c.source!==void 0?String(c.source):void 0,toolName:c.tool_name!==void 0?String(c.tool_name):void 0,toolUseId:c.tool_use_id!==void 0?String(c.tool_use_id):void 0,command:c.command!==void 0?String(c.command):void 0,output:c.output!==void 0?String(c.output):void 0,stderr:c.stderr!==void 0?String(c.stderr):void 0,exitCode:c.exit_code!==void 0?Number(c.exit_code):void 0,decision:c.decision!==void 0?String(c.decision):void 0,durationMs:c.duration_ms!==void 0?Number(c.duration_ms):void 0,updatedToolOutput:(d==null?void 0:d.updatedToolOutput)!==void 0?String(d.updatedToolOutput):void 0,sessionTitle:(d==null?void 0:d.sessionTitle)!==void 0?String(d.sessionTitle):void 0,worktreePath:(d==null?void 0:d.worktreePath)!==void 0?String(d.worktreePath):void 0,timestamp:a.timestamp??""};if(i){const y=i.contentBlocks[i.contentBlocks.length-1];y&&y.kind==="hook_event"?y.events.push(r):i.contentBlocks.push({kind:"hook_event",events:[r],timestamp:a.timestamp})}continue}if(Nt(a)&&a.subtype==="turn_duration"&&i){a.durationMs!==void 0&&a.durationMs!==null&&(i.durationMs=(i.durationMs??0)+a.durationMs);continue}}return $(),j(),{turns:Dt(e),turnStartIndices:n}}function jt(t){return Ot(t).turns}function Wt(){return!0}function Lt(t){const e=[];for(const n of t){const s=n.trim();if(s)try{e.push(JSON.parse(s))}catch{}}return e}function qt(t){return Lt(t.split(`
|
|
4
|
+
`))}function zt(t){const e={sessionId:"",version:"",gitBranch:"",cwd:"",slug:"",name:"",model:"",branchedFrom:void 0};for(const n of t)if(n.sessionId&&!e.sessionId&&(e.sessionId=n.sessionId),n.version&&!e.version&&(e.version=n.version),n.gitBranch&&!e.gitBranch&&(e.gitBranch=n.gitBranch),n.cwd&&!e.cwd&&(e.cwd=n.cwd),n.slug&&!e.slug&&(e.slug=n.slug),n.name&&!e.name&&(e.name=n.name),n.branchedFrom&&!e.branchedFrom&&(e.branchedFrom=n.branchedFrom),ft(n)&&n.message.model&&!e.model&&(e.model=n.message.model),e.sessionId&&e.version&&e.gitBranch&&e.cwd&&e.model)break;return e}function Ye(t){return zt(Lt(t))}function tn(t,e){const n=qt(t),s=zt(n),o=jt(n),i=e!=null&&e.skipStats?tt(o.length):et(o);return{...s,turns:o,stats:i,rawMessages:e!=null&&e.skipStats?[]:n,agentKind:"claude"}}function en(t,e){const n=qt(e);if(n.length===0)return t;const s=t.rawMessages,o=[...s,...n],i=Ze(s),l=Math.max(0,t.turns.length-i.length);let f=Math.max(0,i.length-1);const _=new Set;for(const N of n)if(N.type==="progress"){const S=N.parentToolUseID;S&&_.add(S)}if(_.size>0)for(let N=f-1;N>=0;N--){const S=t.turns[l+N];if(S!=null&&S.toolCalls.some(w=>_.has(w.id))){f=N;break}}const T=i[f]??s.length,b=t.turns.slice(0,l+f),h=jt(o.slice(T)),k=Dt([...b,...h]),p=et(k);return{sessionId:t.sessionId,version:t.version,gitBranch:t.gitBranch,cwd:t.cwd,slug:t.slug,name:t.name,model:t.model||k.length>0&&k[k.length-1].model||"",turns:k,stats:p,rawMessages:o,branchedFrom:t.branchedFrom,agentKind:t.agentKind}}const Jt="<task-notification>",nn=/<task-id>([^<]+)<\/task-id>/g,sn=/<tool-use-id>([^<]+)<\/tool-use-id>/g;function W(t){return typeof t=="object"&&t!==null}function on(t){const e=W(t.message)?t.message:null,n=e==null?void 0:e.content;return typeof n=="string"?[n]:Array.isArray(n)?n.filter(s=>W(s)&&typeof s.text=="string").map(s=>s.text):[]}function rn(t){const e=[],n=new Set,s=new Set,o=new Set;function i(l,f){if(l.includes(Jt)){for(const _ of l.matchAll(nn))n.add(_[1]),f==null||f.add(_[1]);for(const _ of l.matchAll(sn))n.add(_[1]),f==null||f.add(_[1])}}for(const l of t){if(l.type==="user"){const f=W(l.toolUseResult)?l.toolUseResult:null;if((f==null?void 0:f.status)==="async_launched"){const _=W(l.message)?l.message:null,b=(Array.isArray(_==null?void 0:_.content)?_.content:[]).filter(p=>W(p)&&p.type==="tool_result").map(p=>p.tool_use_id),h=[f.agentId,f.taskId,...b].filter(p=>typeof p=="string"&&p.length>0),k=[f.description,f.workflowName,f.summary].find(p=>typeof p=="string"&&p.length>0)??"";h.length>0&&e.push({ids:h,description:k})}for(const _ of on(l))i(_,o);continue}if(l.type==="assistant"){const f=W(l.message)?l.message:null,_=Array.isArray(f==null?void 0:f.content)?f.content:[];for(const T of _){if(!W(T)||T.type!=="tool_use"||T.name!=="TaskStop")continue;const b=W(T.input)?T.input:null,h=(b==null?void 0:b.task_id)??(b==null?void 0:b.shell_id);typeof h=="string"&&n.add(h)}continue}if(l.type==="attachment"){const f=W(l.attachment)?l.attachment:null;typeof(f==null?void 0:f.prompt)=="string"&&i(f.prompt,o);continue}if(l.type==="queue-operation"&&typeof l.content=="string"){const f=l.operation;i(l.content,f==="enqueue"?s:o)}}return{pendingDescriptions:e.filter(l=>!l.ids.some(f=>n.has(f))).map(l=>l.description),undeliveredNotifications:[...s].filter(l=>!o.has(l)).length}}function an(t,e){return{status:"awaiting_agents",pendingQueue:e,pendingAgents:t.length,pendingAgentDescriptions:t.filter(n=>n.length>0)}}function ln(t){var l,f;let e=0,n=null,s=!1;function o(_,T){const b={status:_,pendingQueue:Math.max(0,e)};return T&&(b.toolName=T),b}function i(){return n??(n=rn(t))}for(let _=t.length-1;_>=0;_--){const T=t[_];if(T.type!=="queue-operation"){if(T.type==="progress"){const b=T.data;if((b==null?void 0:b.type)==="hook_progress"&&(b.decision??((l=b.hookSpecificOutput)==null?void 0:l.permissionDecision))==="defer")return o("deferred");break}break}}for(let _=t.length-1;_>=0;_--){const T=t[_];if(T.type==="queue-operation"){if(typeof T.content=="string"&&T.content.includes(Jt))continue;const b=T.operation;b==="enqueue"?e++:(b==="dequeue"||b==="remove")&&e--;continue}if(T.type==="attachment"){const b=W(T.attachment)?T.attachment:null;(b==null?void 0:b.commandMode)==="task-notification"&&(s=!0);continue}if(T.type==="assistant"){const b=T.message,h=b==null?void 0:b.stop_reason;if(h==="end_turn"){const k=i();if(s||k.undeliveredNotifications>0)return o("processing");if(k.pendingDescriptions.length>0)return an(k.pendingDescriptions,Math.max(0,e));let p=!1;for(let N=_-1;N>=0;N--){const S=t[N];if(S.type==="user"&&!S.isMeta){p=!0;break}}return o(p?"completed":"idle")}if(h==="tool_use"){const k=b==null?void 0:b.content,p=(f=k==null?void 0:k.findLast)==null?void 0:f.call(k,N=>N.type==="tool_use");return o("tool_use",p==null?void 0:p.name)}return o("thinking")}if(T.type==="user"){if(T.isMeta)continue;return o("processing")}if(T.type==="system"&&T.subtype==="terminal_reason"){const b=T.reason;if(b)return{status:"completed",terminalReason:b,pendingQueue:Math.max(0,e)};continue}T.type!=="summary"&&T.type==="system"&&T.subtype}return{status:"idle"}}function cn(t){return Ot(t).turnStartIndices}function Kt(t,e,n){if(!e)return;t.assistantText.push(e);const s=t.contentBlocks[t.contentBlocks.length-1];if((s==null?void 0:s.kind)==="text"){s.text.push(e);return}t.contentBlocks.push({kind:"text",text:[e],timestamp:n})}const Vt={0:"\0",b:"\b",f:"\f",n:`
|
|
5
|
+
`,r:"\r",t:" ",v:"\v"};function Qt(t,e){const n=t[e];if(n!=='"'&&n!=="'"&&n!=="`")return null;let s="",o=e+1;for(;o<t.length;){const i=t[o];if(i===n)return{endIndex:o+1,value:s};if(i!=="\\"){s+=i,o++;continue}if(o++,o>=t.length)return null;const l=t[o];if(l in Vt){s+=Vt[l],o++;continue}if(l===`
|
|
6
|
+
`){o++;continue}if(l==="\r"){o+=t[o+1]===`
|
|
7
|
+
`?2:1;continue}if(l==="x"&&/^[0-9a-fA-F]{2}$/.test(t.slice(o+1,o+3))){s+=String.fromCharCode(Number.parseInt(t.slice(o+1,o+3),16)),o+=3;continue}if(l==="u"){const f=t.slice(o+1).match(/^\{([0-9a-fA-F]+)\}/);if(f){const T=Number.parseInt(f[1],16);if(Number.isFinite(T)&&T<=1114111){s+=String.fromCodePoint(T),o+=f[0].length+1;continue}}const _=t.slice(o+1,o+5);if(/^[0-9a-fA-F]{4}$/.test(_)){s+=String.fromCharCode(Number.parseInt(_,16)),o+=5;continue}}s+=l,o++}return null}function Gt(t){return t.includes("*** Begin Patch")&&t.includes("*** End Patch")}function un(t){if(!t.includes("apply_patch")||!t.includes("*** Begin Patch"))return[];const e=new Map;for(let l=0;l<t.length;l++){const f=Qt(t,l);if(f){if(Gt(f.value)){const _=t.slice(0,l).match(/(?:^|[;\n])\s*(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*$/);_&&e.set(_[1],f.value)}l=f.endIndex-1}}const n=[],s=new Set,o=/\btools\s*\.\s*apply_patch\s*\(/g;let i;for(;(i=o.exec(t))!==null;){let l=i.index+i[0].length;for(;/\s/.test(t[l]??"");)l++;const f=Qt(t,l),_=f?null:t.slice(l).match(/^([A-Za-z_$][\w$]*)/),T=(f==null?void 0:f.value)??(_?e.get(_[1]):void 0);!T||!Gt(T)||s.has(T)||(s.add(T),n.push(T))}return n}function Ht(t,e){if(!e||t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t))return t;const n=e.replace(/[\\/]+$/,""),s=t.replace(/^\.[\\/]/,"");return/^[A-Za-z]:[\\/]/.test(e)?`${n}\\${s.replace(/\//g,"\\")}`:`${n}/${s}`}function Xt(t,e,n,s=""){var _,T;const o=[],i=/^\*\*\*\s+(Update File|Add File|Delete File):\s*(.+)$/gm,l=[];let f;for(;(f=i.exec(t))!==null;)l.push({action:f[1],filePath:f[2].trim(),headerIdx:f.index,startIdx:f.index+f[0].length});for(let b=0;b<l.length;b++){const h=l[b],k=b+1<l.length?l[b+1].headerIdx:t.length,p=t.slice(h.startIdx,k),N=(T=(_=p.match(/^\*\*\*\s+Move to:\s*(.+)$/m))==null?void 0:_[1])==null?void 0:T.trim(),S=Ht(h.filePath,s),w=Ht(N||h.filePath,s),B=p.split(/^@@.*$/m).filter(j=>j.trim()),P=[],$=[];for(const j of B)for(const F of j.split(`
|
|
8
|
+
`))F.startsWith("-")?P.push(F.slice(1)):F.startsWith("+")?$.push(F.slice(1)):F.startsWith(" ")&&(P.push(F.slice(1)),$.push(F.slice(1)));const O=l.length>1?`${e}:file-${b}`:e;h.action==="Add File"?o.push({id:O,name:"Write",input:{file_path:w,content:$.join(`
|
|
9
|
+
`)},result:null,isError:!1,timestamp:n}):h.action==="Delete File"?o.push({id:O,name:"Edit",input:{file_path:w,old_string:P.join(`
|
|
10
|
+
`),new_string:""},result:null,isError:!1,timestamp:n}):o.push({id:O,name:"Edit",input:{file_path:w,...N?{old_path:S}:{},old_string:P.join(`
|
|
11
|
+
`),new_string:$.join(`
|
|
12
|
+
`)},result:null,isError:!1,timestamp:n})}return o}function dn(t,e,n,s,o=""){return t==="apply_patch"?Xt(e,n,s,o):un(e).flatMap((i,l)=>Xt(i,`${n}:patch-${l}`,s,o))}function pn(t,e,n){var f;if(!e||!/(?:apply[_ ]patch|invalid patch|invalid context|failed to (?:apply|find)|could not apply)/i.test(t))return new Set;const s=new Map;for(const _ of n){const T=(f=_.id.match(/:patch-(\d+)(?::file-\d+)?$/))==null?void 0:f[1];if(T===void 0)continue;const b=Number(T),h=s.get(b)??[];h.push(_),s.set(b,h)}if(s.size===0)return new Set(n.map(_=>_.id));const o=t.toLowerCase().replaceAll("\\","/"),i=new Set;for(const[_,T]of s)T.some(b=>{const h=String(b.input.file_path??"").toLowerCase().replaceAll("\\","/");if(!h)return!1;const p=h.split("/").filter(Boolean).slice(-2).join("/");return o.includes(h)||p.includes("/")&&o.includes(p)})&&i.add(_);for(const _ of o.matchAll(/\bpatch\s*(?:#|-)?\s*(\d+)\b/g)){const T=Number(_[1]);s.has(T)&&i.add(T)}i.size===0&&i.add(Math.max(...s.keys()));const l=Math.min(...i);for(const _ of s.keys())_>=l&&i.add(_);return new Set([...i].flatMap(_=>{var T;return((T=s.get(_))==null?void 0:T.map(b=>b.id))??[]}))}function gt(t){return typeof t=="object"&&t!==null}const fn=new Map([["spawn_agent","spawn_agent"],["spawnAgent","spawn_agent"],["wait_agent","wait_agent"],["waitAgent","wait_agent"],["send_message","send_message"],["sendMessage","send_message"],["followup_task","followup_task"],["followupTask","followup_task"],["list_agents","list_agents"],["listAgents","list_agents"],["interrupt_agent","interrupt_agent"],["interruptAgent","interrupt_agent"]]);function Q(t){const e=t.split(/(?:__|[.:/])+/).filter(Boolean).at(-1)??t;return fn.get(e)??t}function ht(t){if(!t)return!1;const e=t.match(/Process exited with code (\d+)/);if(e)return e[1]!=="0";const n=t.replace(/\b0\s+(?:fail(?:ed|ures?)?|errors?)\b/gi,"").replace(/\bno\s+(?:failures?|errors?)\b/gi,"");return/\b(error|failed|exception)\b/i.test(n)}function mn(t){return{todos:(Array.isArray(t.plan)?t.plan:[]).filter(s=>gt(s)).map(s=>({content:typeof s.step=="string"?s.step:"",status:typeof s.status=="string"?s.status:"pending",activeForm:typeof s.step=="string"?s.step:""}))}}function gn(t){return typeof t=="string"?t:Array.isArray(t)?t.filter(e=>gt(e)&&typeof e.text=="string").map(e=>e.text).join(""):""}function Zt(t){const e=gn(t);if(!e)return{text:"",isError:!1};try{const n=JSON.parse(e),s=typeof n.output=="string"?n.output:e,o=gt(n.metadata)?n.metadata:null,i=o?o.exit_code!==0&&o.exit_code!==void 0:ht(s);return{text:s,isError:i}}catch{return{text:e,isError:ht(e)}}}const hn=["# AGENTS.md instructions for ","<recommended_plugins>","<environment_context>","<permissions instructions>","<collaboration_mode>","<skills_instructions>"];function _n(t){var e,n;return((n=(e=globalThis.crypto)==null?void 0:e.randomUUID)==null?void 0:n.call(e))??`${t}-${Math.random().toString(36).slice(2,10)}`}function _t(t){try{return JSON.parse(t)}catch{return null}}function U(t){return typeof t=="object"&&t!==null}function J(t){return!t||typeof t.type!="string"?!1:t.type==="session_meta"||t.type==="turn_context"||t.type==="event_msg"||t.type==="response_item"||t.type==="inter_agent_communication_metadata"||t.type==="compacted"||t.type==="world_state"}function ot(t,e){const n=t==null?void 0:t.content;return Array.isArray(n)?n.filter(s=>U(s)&&s.type===e&&typeof s.text=="string").map(s=>s.text).join(`
|
|
13
|
+
`).trim():""}const yn=/^data:(image\/(?:png|jpeg|gif|webp));base64,(.+)$/is,kn=/^data:(audio\/(?:wav|x-wav|mpeg|mp4|webm|ogg));base64,(.+)$/is;function Yt(t){if(typeof t!="string")return null;const e=yn.exec(t);return!(e!=null&&e[1])||!e[2]?null:{type:"image",source:{type:"base64",media_type:e[1].toLowerCase(),data:e[2]}}}function te(t){if(typeof t!="string")return null;const e=kn.exec(t);return!(e!=null&&e[1])||!e[2]?null:{type:"audio",source:{type:"base64",media_type:e[1].toLowerCase(),data:e[2]}}}function Tn(t){return Array.isArray(t.images)?t.images.map(Yt).filter(e=>e!==null):[]}function bn(t){return Array.isArray(t.audio)?t.audio.map(te).filter(e=>e!==null):[]}function ee(t){return Array.isArray(t.content)?t.content.filter(e=>U(e)&&e.type==="input_image").map(e=>Yt(e.image_url)).filter(e=>e!==null):[]}function ne(t){return Array.isArray(t.content)?t.content.filter(e=>U(e)&&e.type==="input_audio").map(e=>te(e.audio_url)).filter(e=>e!==null):[]}function se(t,e,n=[],s=[],o=[]){const i=[...s.map(f=>`
|
|
14
|
+
`),...o.map(f=>`
|
|
15
|
+
[audio attachment](<${f}>)`)].join(""),l=t+i;return e.length===0&&n.length===0?l:[...e,...n,...l?[{type:"text",text:l}]:[]]}function Cn(t){var l,f;const e=ot(t,"input_text");if(!e)return{messageType:null,text:""};const n=e.match(/\r?\nPayload:\s*(?:\r?\n|$)/);if(!e.startsWith("Message Type:")||!n||n.index===void 0)return{messageType:null,text:e.trim()};const o=((f=(l=e.slice(0,n.index).match(/^Message Type:\s*([^\r\n]+)/))==null?void 0:l[1])==null?void 0:f.trim().toUpperCase())??null,i=e.slice(n.index+n[0].length).trim();return{messageType:o,text:i}}function G(t){return t.split(/[\\/]/).filter(Boolean).at(-1)??null}function xn(t){if(typeof t!="string")return"";const e=t.trim();return/^gAAAAA[A-Za-z0-9_-]+$/.test(e)?"":e}function yt(t){const e=t.trim();return!e||hn.some(n=>e.startsWith(n))?"":e}function An(t,e){return t?{input_tokens:t.input_tokens+e.input_tokens,output_tokens:t.output_tokens+e.output_tokens,cache_creation_input_tokens:(t.cache_creation_input_tokens??0)+(e.cache_creation_input_tokens??0),cache_read_input_tokens:(t.cache_read_input_tokens??0)+(e.cache_read_input_tokens??0)}:{...e}}function In(t){if(!U(t))return null;const e=typeof t.input_tokens=="number"?t.input_tokens:0,n=typeof t.output_tokens=="number"?t.output_tokens:0,s=typeof t.cache_write_input_tokens=="number"?t.cache_write_input_tokens:typeof t.cache_creation_input_tokens=="number"?t.cache_creation_input_tokens:0,o=typeof t.cached_input_tokens=="number"?Math.max(0,t.cached_input_tokens):null,i=o??(typeof t.cache_read_input_tokens=="number"?t.cache_read_input_tokens:0),l=o===null?e:Math.max(0,e-o);return l===0&&n===0&&s===0&&i===0?null:{input_tokens:l,output_tokens:n,cache_creation_input_tokens:s,cache_read_input_tokens:i}}function Mn(t,e,n){if(!e)return;const s={type:"thinking",thinking:e,signature:""};t.thinking.push(s);const o=t.contentBlocks[t.contentBlocks.length-1];if(o&&o.kind==="thinking"){o.blocks.push(s);return}t.contentBlocks.push({kind:"thinking",blocks:[s],timestamp:n})}function K(t,e,n){t.toolCalls.push(e);const s=t.contentBlocks[t.contentBlocks.length-1];if(s&&s.kind==="tool_calls"&&s.timestamp===n){s.toolCalls.push(e);return}t.contentBlocks.push({kind:"tool_calls",toolCalls:[e],timestamp:n})}function wn(t,e,n){if(!e||!(e.userMessage!==null||e.assistantText.length>0||e.toolCalls.length>0||e.thinking.length>0||e.subAgentActivity.length>0))return null;if(e.timestamp&&n){const o=new Date(e.timestamp).getTime(),i=new Date(n).getTime();Number.isFinite(o)&&Number.isFinite(i)&&i>=o&&(e.durationMs=i-o)}return t.push(e),null}function oe(t){if(typeof t!="string"||!t.trim())return{};try{const e=JSON.parse(t);return U(e)?e:{value:e}}catch{return{raw:t}}}function H(t){if(typeof t=="string")return t;try{return JSON.stringify(t)}catch{return String(t??"")}}function ie(...t){return t.find(e=>typeof e=="string")}function Sn(t){return t.startsWith("exec-")}function En(t){if(!U(t))return{text:H(t),isError:!1};if("Err"in t)return{text:H(t.Err),isError:!0};const e=U(t.Ok)?t.Ok:null;if(!e)return{text:H(t),isError:!1};const n=Zt(e.content);return{text:n.text||(e.structuredContent!==void 0?H(e.structuredContent):H(e)),isError:e.isError===!0||n.isError}}function Nn(t,e,n){return{id:t?`${t}@${e}`:_n("codex-turn"),userMessage:null,contentBlocks:[],thinking:[],assistantText:[],toolCalls:[],subAgentActivity:[],timestamp:e,durationMs:null,tokenUsage:null,model:n}}function re(t){return t.type==="event_msg"&&U(t.payload)&&t.payload.type==="user_message"&&typeof t.payload.message=="string"?yt(t.payload.message):t.type==="response_item"&&U(t.payload)&&t.payload.type==="message"&&t.payload.role==="user"?yt(ot(t.payload,"input_text")):""}function vn(t,e){if(t.type==="session_meta"||t.type==="event_msg"&&(e==null?void 0:e.type)==="task_started")return!1;if(t.type==="response_item"&&(e==null?void 0:e.type)==="message"){if(e.role==="developer"||e.role==="system")return!1;if(e.role==="user")return re(t)!==""||ee(e).length>0||ne(e).length>0}return!0}function ae(t){let e="",n="",s="",o="",i="",l,f="",_="",T="",b="",h=0,k=!1,p=null,N="/root",S="";for(const w of t){if(!U(w.payload))continue;if(w.type==="session_meta"){if(e||(e=typeof w.payload.id=="string"?w.payload.id:""),n||(n=typeof w.payload.cli_version=="string"?w.payload.cli_version:""),o||(o=typeof w.payload.cwd=="string"?w.payload.cwd:""),!l&&U(w.payload.branchedFrom)){const O=typeof w.payload.branchedFrom.sessionId=="string"?w.payload.branchedFrom.sessionId:"";O&&(l={sessionId:O,turnIndex:typeof w.payload.branchedFrom.turnIndex=="number"?w.payload.branchedFrom.turnIndex:null})}const P=U(w.payload.source)?w.payload.source:null;if(P&&U(P.subagent)){k=!0;const O=U(P.subagent.thread_spawn)?P.subagent.thread_spawn:null;O&&typeof O.agent_path=="string"&&(N=O.agent_path)}typeof w.payload.forked_from_id=="string"&&w.payload.forked_from_id&&(p=w.payload.forked_from_id);const $=U(w.payload.git)?w.payload.git:null;s||(s=$&&typeof $.branch=="string"?$.branch:"")}w.type==="turn_context"&&(i||(i=typeof w.payload.model=="string"?w.payload.model:""),o||(o=typeof w.payload.cwd=="string"?w.payload.cwd:""));const B=re(w);B&&B!==S&&(f||(f=B),_=B,S=B,h++,T||(T=w.timestamp??""),b=w.timestamp??b)}return b===""&&(b=T),{sessionId:e,version:n,gitBranch:s,cwd:o,model:i,slug:"",name:"",branchedFrom:l,firstUserMessage:f,lastUserMessage:_,timestamp:T,lastTimestamp:b,turnCount:h,isSubagent:k,parentSessionId:p,agentPath:N}}function Bn(t){for(const e of t.split(`
|
|
16
|
+
`)){const n=e.trim();if(n)return J(_t(n))}return!1}function Rn(t){return J(t[0]??null)}function Pn(t){const e=t.map(_t).filter(J);return ae(e)}function le(t,e){const n=ae(t.filter(J)),s=[],o=new Map,i=new Map,l=new Map,f=new Map,_=new Map,T=new Map,b=new Map,h=new Map;function k(g,d,r,y={}){const u=_.get(g);let C=h.get(g);if(!C){const x={agentId:g,parentToolUseId:(u==null?void 0:u.parentToolCallId)||void 0,agentName:(u==null?void 0:u.nickname)??(u!=null&&u.agentPath?G(u.agentPath):null),subagentType:(u==null?void 0:u.agentType)??null,type:"assistant",content:null,toolCalls:[],thinking:[],text:[],timestamp:(u==null?void 0:u.timestamp)??r,tokenUsage:null,model:(u==null?void 0:u.model)??null,isBackground:!1,prompt:(u==null?void 0:u.message)||void 0,status:y.status??"running"};d.subAgentActivity.push(x);const M=d.contentBlocks[d.contentBlocks.length-1];(M==null?void 0:M.kind)==="sub_agent"?M.messages.push(x):d.contentBlocks.push({kind:"sub_agent",messages:[x],timestamp:r}),C={message:x,turn:d},h.set(g,C)}const m=C.message;if(u&&(m.parentToolUseId=u.parentToolCallId||m.parentToolUseId,m.agentName=u.nickname??(u.agentPath?G(u.agentPath):m.agentName),m.subagentType=u.agentType,m.model=u.model,m.prompt=u.message||m.prompt),y.text&&!m.text.includes(y.text)&&(m.text.push(y.text),m.content=m.text.join(`
|
|
17
|
+
|
|
18
|
+
`)),y.status){const x=new Set(["completed","failed","interrupted"]);if(y.status==="running"&&m.status&&x.has(m.status)||(m.status=y.status),x.has(y.status)&&m.timestamp&&r){const M=new Date(m.timestamp).getTime(),E=new Date(r).getTime();Number.isFinite(M)&&Number.isFinite(E)&&E>=M&&(m.durationMs=E-M)}}return m}let p=null,N=null,S=n.model||null,w="",B=null,P=!1;const $=[];let O=0,j=null,F=null;function I(g){const d=s.length,r=wn(s,g,w);return s.length>d&&F!==null&&$.push(F),F=null,r}function a(g,d,r){const y=Nn(g,d,r);return F=j??O,j=null,P||(y.isFragment=!0),B&&(y.compactionSummary=B,B=null),y}function c(g,d,r,y,u){const C=i.get(d);if(C){C.input={...C.input,...r},C.result=y,C.isError=y==="failed";return}const m={id:d,name:"WebSearch",input:r,result:y,isError:y==="failed",timestamp:u};i.set(d,m),K(g,m,u)}for(let g=0;g<t.length;g++){const d=t[g];if(!J(d))continue;O=g;const r=U(d.payload)?d.payload:void 0,y=d.timestamp??"";if(d.type==="compacted"){p=I(p),B="Conversation compacted",w=y;continue}if(d.type!=="world_state"){if(d.type==="turn_context"){p=I(p),j=g,N=typeof(r==null?void 0:r.turn_id)=="string"?r.turn_id:null,S=typeof(r==null?void 0:r.model)=="string"?r.model:S,w=y,P=!0;continue}if(d.type==="event_msg"&&(r==null?void 0:r.type)==="user_message"&&typeof r.message=="string"){p&&(p.assistantText.length>0||p.toolCalls.length>0||p.thinking.length>0)&&(p=I(p)),P=!0,p??(p=a(N,y,S));const u=(Array.isArray(r.local_images)?r.local_images:[]).filter(m=>typeof m=="string"&&m.length>0),C=(Array.isArray(r.local_audio)?r.local_audio:[]).filter(m=>typeof m=="string"&&m.length>0);p.userMessage=se(r.message,Tn(r),bn(r),u,C),p.isFragment=!1,p.timestamp=p.timestamp||y,w=y;continue}if(!(!p&&!vn(d,r))){if(p??(p=a(N,y,S)),!p.model&&S&&(p.model=S),p.timestamp||(p.timestamp=y),y&&(w=y),d.type==="event_msg"&&(r==null?void 0:r.type)==="token_count"){const u=U(r.info)?r.info:null,C=u?In(u.last_token_usage):null;C&&(p.tokenUsage=An(p.tokenUsage,C));continue}if(d.type==="event_msg"&&(r==null?void 0:r.type)==="web_search_end"&&typeof r.call_id=="string"){const u={};typeof r.query=="string"&&r.query&&(u.query=r.query),U(r.action)&&(u.action=r.action),c(p,r.call_id,u,"completed",y);continue}if(d.type==="event_msg"&&(r==null?void 0:r.type)==="mcp_tool_call_end"&&typeof r.call_id=="string"&&U(r.invocation)){const u=r.invocation,C=typeof u.server=="string"?u.server:"mcp",m=typeof u.tool=="string"?u.tool:"tool",x=U(u.arguments)?u.arguments:{},M=En(r.result),E=o.get(r.call_id);E?(E.result=M.text,E.isError=M.isError,o.delete(r.call_id)):Sn(r.call_id)||K(p,{id:r.call_id,name:`mcp__${C}__${m}`,input:x,result:M.text,isError:M.isError,timestamp:y},y);continue}if(d.type==="event_msg"&&(r==null?void 0:r.type)==="sub_agent_activity"&&typeof r.agent_thread_id=="string"&&typeof r.agent_path=="string"){const u=r.agent_thread_id,C=typeof r.event_id=="string"?r.event_id:"",m=typeof r.kind=="string"?r.kind:"started",x=C?f.get(C):void 0,M=T.get(r.agent_path),E=_.get(u)??(M?_.get(M):void 0);if(m!=="started"&&!E&&!x)continue;if(M&&M!==u&&!h.has(u)){const L=h.get(M);L&&(L.message.agentId=u,h.delete(M),h.set(u,L)),_.delete(M)}const v={agentId:u,nickname:(E==null?void 0:E.nickname)??G(r.agent_path)??(x==null?void 0:x.taskName)??null,agentPath:r.agent_path,message:(E==null?void 0:E.message)??(x==null?void 0:x.message)??"",model:(E==null?void 0:E.model)??(x==null?void 0:x.model)??null,agentType:(E==null?void 0:E.agentType)??(x==null?void 0:x.agentType)??null,timestamp:(E==null?void 0:E.timestamp)??(y||(x==null?void 0:x.timestamp)||""),parentToolCallId:(E==null?void 0:E.parentToolCallId)??C};_.set(u,v),T.set(r.agent_path,u),C&&(m==="started"||x)&&b.set(C,u),k(u,p,y,{status:m==="interrupted"?"interrupted":"running"});continue}if(!(d.type!=="response_item"||!r)){if(r.type==="reasoning"){const u=Array.isArray(r.summary)?r.summary.filter(C=>typeof C=="string").join(`
|
|
19
|
+
`):"";Mn(p,u.trim(),y);continue}if(r.type==="message"&&r.role==="assistant"){Kt(p,ot(r,"output_text"),y);continue}if(r.type==="message"&&r.role==="user"&&p.userMessage===null){const u=yt(ot(r,"input_text")),C=ee(r),m=ne(r);(u||C.length>0||m.length>0)&&(p.userMessage=se(u,C,m),p.isFragment=!1,P=!0);continue}if(r.type==="web_search_call"&&typeof r.id=="string"){const u={};U(r.action)&&(u.action=r.action);const C=typeof r.status=="string"?r.status:"completed";c(p,r.id,u,C,y);continue}if(r.type==="tool_search_call"){const u=ie(r.call_id,r.id)??"";if(u){const C={id:u,name:"ToolSearch",input:U(r.arguments)?r.arguments:{},result:null,isError:!1,timestamp:y};o.set(u,C),K(p,C,y)}continue}if(r.type==="tool_search_output"&&typeof r.call_id=="string"){const u=o.get(r.call_id);if(u){const C=Array.isArray(r.tools)?r.tools:[],m=C.filter(U).map(E=>ie(E.name)??"").filter(Boolean),x=m.length>0?m.length:C.length,M=`Found ${x} tool${x===1?"":"s"}`;u.result=m.length>0?`${M}: ${m.join(", ")}`:M,u.isError=r.status==="failed",o.delete(r.call_id)}continue}if(r.type==="agent_message"&&typeof r.author=="string"){const u=r.author,C=typeof r.recipient=="string"?r.recipient:null,m=Cn(r);if(m.messageType==="NEW_TASK")continue;const x=T.get(u),M=u.startsWith(`${n.agentPath}/`)&&(C===null||C===n.agentPath);if(!x&&!M)continue;const E=x??u;x||(_.set(E,{agentId:E,nickname:G(u),agentPath:u,message:"",model:null,agentType:null,timestamp:y,parentToolCallId:""}),T.set(u,E));let v;m.messageType==="FINAL_ANSWER"?v="completed":m.messageType==="ERROR"||m.messageType==="FAILED"?v="failed":m.messageType==="INTERRUPTED"?v="interrupted":m.messageType==="MESSAGE"&&(v="running"),k(E,p,y,{status:v,text:m.text||void 0});continue}if(r.type==="function_call"&&typeof r.call_id=="string"){const u=typeof r.name=="string"?r.name:"tool",C=Q(u),m=oe(r.arguments);let x=C,M=m;C==="exec_command"?x="Bash":C==="update_plan"&&(x="TodoWrite",M=mn(m)),C==="spawn_agent"&&f.set(r.call_id,{callId:r.call_id,message:xn(m.message),taskName:typeof m.task_name=="string"?m.task_name:null,model:typeof m.model=="string"?m.model:null,agentType:typeof m.agent_type=="string"?m.agent_type:null,timestamp:y});const E={id:r.call_id,name:x,input:M,result:null,isError:!1,timestamp:y};o.set(E.id,E),K(p,E,y);continue}if(r.type==="function_call_output"&&typeof r.call_id=="string"){const u=o.get(r.call_id);if(!u)continue;const C=typeof r.output=="string"?r.output:null;if(u.result=C,u.isError=ht(C),o.delete(r.call_id),u.name==="spawn_agent"&&C)try{const m=JSON.parse(C),x=typeof m.agent_id=="string"?m.agent_id:b.get(u.id)??"",M=typeof m.task_name=="string"?m.task_name:null,E=typeof m.nickname=="string"?m.nickname:M?G(M):null;if(x){const v=f.get(u.id),R=_.get(x),L={agentId:x,nickname:E??(R==null?void 0:R.nickname)??(v==null?void 0:v.taskName)??null,agentPath:M??(R==null?void 0:R.agentPath)??null,message:(R==null?void 0:R.message)??(v==null?void 0:v.message)??"",model:(R==null?void 0:R.model)??(v==null?void 0:v.model)??null,agentType:(R==null?void 0:R.agentType)??(v==null?void 0:v.agentType)??null,timestamp:(R==null?void 0:R.timestamp)??(v==null?void 0:v.timestamp)??y,parentToolCallId:(R==null?void 0:R.parentToolCallId)??u.id};_.set(x,L),b.set(u.id,x),L.agentPath&&T.set(L.agentPath,x),k(x,p,y,{status:"running"})}}catch{}if(u.name==="wait_agent"&&C&&p)try{const m=JSON.parse(C),x=U(m.status)?m.status:{};for(const[M,E]of Object.entries(x)){const v=U(E)?E:{},R=typeof v.completed=="string"?v.completed:"",L=typeof v.failed=="string"?v.failed:typeof v.error=="string"?v.error:"",Me=typeof v.interrupted=="string"?v.interrupted:"",gs=R?"completed":L?"failed":Me?"interrupted":typeof v.status=="string"?v.status:"running";_.has(M)||_.set(M,{agentId:M,nickname:null,agentPath:null,message:"",model:null,agentType:null,timestamp:y,parentToolCallId:""}),k(M,p,y,{status:gs,text:R||L||Me||void 0})}}catch{}continue}if(r.type==="custom_tool_call"&&typeof r.call_id=="string"){const u=typeof r.name=="string"?r.name:"tool",C=typeof r.input=="string"?r.input:"",m=r.call_id,x=C?dn(u,C,m,y,n.cwd):[];if(u!=="apply_patch"){const M={id:m,name:u==="exec_command"?"Bash":u,input:oe(C),result:null,isError:!1,timestamp:y};o.set(M.id,M),K(p,M,y)}for(const M of x)o.set(M.id,M),K(p,M,y);x.length>0&&l.set(m,{calls:x,direct:u==="apply_patch"});continue}if(r.type==="custom_tool_call_output"&&typeof r.call_id=="string"){const u=r.call_id,{text:C,isError:m}=Zt(r.output),x=l.get(u);if(x){const E=x.direct&&m?new Set(x.calls.map(v=>v.id)):pn(C,m,x.calls);for(const v of x.calls){const R=o.get(v.id);R&&(R.result=C,R.isError=E.has(R.id),o.delete(R.id))}l.delete(u)}const M=o.get(u);M&&(M.result=C,M.isError=m,o.delete(u));continue}}}}}return I(p),{turnStartIndices:$,sessionId:n.sessionId,version:n.version,gitBranch:n.gitBranch,cwd:n.cwd,slug:n.slug,name:"",model:n.model,turns:s,stats:e!=null&&e.skipStats?tt(s.length):et(s),rawMessages:e!=null&&e.skipStats?[]:t,branchedFrom:n.branchedFrom,agentKind:"codex"}}function ce(t,e){const n=t.split(`
|
|
20
|
+
`).map(i=>i.trim()).filter(Boolean).map(_t).filter(J),{turnStartIndices:s,...o}=le(n,e);return o}function Un(t,e){const n=t.rawMessages.map(s=>JSON.stringify(s)).join(`
|
|
21
|
+
`);return ce(n?`${n}
|
|
22
|
+
${e}`:e)}const $n=new Set(["FINAL_ANSWER","ERROR","FAILED","INTERRUPTED"]);function Fn(t){const e=t.content;return Array.isArray(e)?e.filter(n=>U(n)&&n.type==="input_text"&&typeof n.text=="string").map(n=>n.text).join(`
|
|
23
|
+
`):""}function it(t){if(typeof t!="string")return null;try{const e=JSON.parse(t);return U(e)?e:null}catch{return null}}function Dn(t){var _,T;const e=new Map,n=new Set,s=new Map,o=new Map,i=new Set,l=new Map;function f(b,h){n.has(b)||e.set(b,e.get(b)||h)}for(const b of t){const h=U(b.payload)?b.payload:null;if(h){if(b.type==="event_msg"&&h.type==="sub_agent_activity"&&typeof h.agent_thread_id=="string"&&typeof h.agent_path=="string"){const k=h.agent_thread_id,p=typeof h.kind=="string"?h.kind:"started",N=typeof h.event_id=="string"?h.event_id:"",S=s.get(h.agent_path),w=e.has(k)||n.has(k)||S!==void 0||o.has(N);if(p!=="started"&&!w)continue;S&&S!==k&&(e.has(S)&&(f(k,e.get(S)??""),e.delete(S)),n.has(S)&&n.add(k)),s.set(h.agent_path,k),p==="interrupted"?(n.add(k),e.delete(k)):f(k,o.get(N)??"");continue}if(b.type==="response_item"){if(h.type==="function_call"&&typeof h.call_id=="string"){const k=Q(typeof h.name=="string"?h.name:"");if(k==="spawn_agent"){const p=it(h.arguments);o.set(h.call_id,typeof(p==null?void 0:p.task_name)=="string"?p.task_name:"")}else if(k==="wait_agent")i.add(h.call_id);else if(k==="interrupt_agent"){const p=it(h.arguments),N=[p==null?void 0:p.agent_id,...Array.isArray(p==null?void 0:p.agent_ids)?p.agent_ids:[]].filter(S=>typeof S=="string");l.set(h.call_id,N)}continue}if(h.type==="function_call_output"&&typeof h.call_id=="string"){const k=h.call_id;if(o.has(k)){const p=it(h.output),N=typeof(p==null?void 0:p.agent_id)=="string"?p.agent_id:"";if(N){f(N,o.get(k)??"");const S=typeof(p==null?void 0:p.task_name)=="string"?p.task_name:"";S&&!s.has(S)&&s.set(S,N)}}else if(i.has(k)){const p=it(h.output),N=U(p==null?void 0:p.status)?p.status:{};for(const[S,w]of Object.entries(N)){const B=U(w)?w:{},P=typeof B.status=="string"?B.status:"";(typeof B.completed=="string"||typeof B.failed=="string"||typeof B.error=="string"||typeof B.interrupted=="string"||P==="completed"||P==="failed"||P==="interrupted")&&(n.add(S),e.delete(S))}}else if(l.has(k))for(const p of l.get(k)??[])n.add(p),e.delete(p);continue}if(h.type==="agent_message"&&typeof h.author=="string"){const p=((T=(_=Fn(h).match(/^Message Type:\s*([^\r\n]+)/))==null?void 0:_[1])==null?void 0:T.trim().toUpperCase())??"";if(!$n.has(p))continue;const N=s.get(h.author)??h.author;n.add(N),e.delete(N)}}}}return[...e.entries()].filter(([b])=>!n.has(b)).map(([,b])=>b)}function On(t){for(let e=t.length-1;e>=0;e--){const n=t[e];if(n.type==="event_msg"){const s=n.payload;switch(s==null?void 0:s.type){case"task_complete":{const o=Dn(t);return o.length>0?{status:"awaiting_agents",pendingQueue:0,pendingAgents:o.length,pendingAgentDescriptions:o.filter(i=>i.length>0)}:{status:"completed"}}case"task_started":return{status:"processing"};case"agent_message":return{status:"thinking"};case"token_count":continue}}if(n.type==="response_item"){const s=n.payload;if(!s)continue;if(s.type==="function_call")return{status:"tool_use",toolName:s.name?Q(s.name):s.name};if(s.type==="message"){if(s.role==="assistant")return{status:"thinking"};if(s.role==="user")return{status:"processing"}}}}return{status:"idle"}}function jn(t){return le(t,{skipStats:!0}).turnStartIndices}const Wn=/^(?:assistant|auto_mode|auto_mode_switch|background_tasks|canvas|command|custom|elicitation|exit_plan_mode|extensions|external_tool|factory|hook|managed_settings|mcp|model|pending_messages|permission|sampling|session|skill|subagent|system|tool|ui|user_input)\./;function D(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function ue(t){return typeof t.agentId!="string"||t.agentId.length===0}function de(t){return!D(t)||typeof t.type!="string"||!D(t.data)?!1:t.type==="abort"||t.type==="binary_asset"||t.type==="user.message"||Wn.test(t.type)}function pe(t){try{const e=JSON.parse(t);return de(e)?e:null}catch{return null}}function Ln(t){return t.split(`
|
|
24
|
+
`).map(e=>e.trim()).filter(Boolean).map(pe).filter(e=>e!==null)}function A(...t){return t.find(e=>typeof e=="string")??""}function q(t){return typeof t=="number"&&Number.isFinite(t)?t:0}function X(t){return typeof t.timestamp=="string"?t.timestamp:""}function z(t,e){var n,s;return typeof t.id=="string"&&t.id?t.id:((s=(n=globalThis.crypto)==null?void 0:n.randomUUID)==null?void 0:s.call(n))??`${e}-${Math.random().toString(36).slice(2,10)}`}function fe(t){const e=z(t,"copilot-turn"),n=A(t.data.turnId);return n?`${n}@${e}`:e}function kt(t,e){if(!D(t))return;const n=A(t.cwd),s=A(t.branch);n&&(e.cwd=n),s&&(e.gitBranch=s)}function me(t){const e={sessionId:"",version:"",gitBranch:"",cwd:"",model:"",slug:"",name:"",firstUserMessage:"",lastUserMessage:"",timestamp:"",lastTimestamp:"",turnCount:0,isSubagent:!1,parentSessionId:null};for(const n of t){if(!ue(n))continue;const{data:s}=n,o=X(n);if(o&&(e.lastTimestamp=o),n.type==="session.start"){e.sessionId||(e.sessionId=A(s.sessionId)),e.version||(e.version=A(s.copilotVersion)||(typeof s.version=="number"?String(s.version):A(s.version))),kt(s.context,e),e.model=A(s.selectedModel)||e.model;continue}if(n.type==="session.resume"){kt(s.context,e),e.model=A(s.selectedModel)||e.model;continue}if(n.type==="session.context_changed"){kt(s,e);continue}if(n.type==="session.auto_mode_resolved"){e.model=A(s.chosenModel)||e.model;continue}if(n.type==="session.model_change"){e.model=A(s.newModel)||e.model;continue}if(n.type==="session.title_changed"){e.name=A(s.title)||e.name;continue}if(n.type==="session.shutdown"){e.model=A(s.currentModel)||e.model;continue}if((n.type==="assistant.turn_start"||n.type==="assistant.turn_end"||n.type==="assistant.message"||n.type==="assistant.usage"||n.type==="tool.execution_start"||n.type==="tool.execution_complete")&&(e.model=A(s.model)||e.model),n.type!=="user.message")continue;e.turnCount++,e.timestamp||(e.timestamp=o);const i=A(s.content).trim();i&&(e.firstUserMessage||(e.firstUserMessage=i),e.lastUserMessage=i)}return e.lastTimestamp||(e.lastTimestamp=e.timestamp),e}function qn(t){for(const e of t.split(`
|
|
25
|
+
`)){const n=e.trim();if(n)try{const s=JSON.parse(n);if(de(s))return!0}catch{}}return!1}function zn(t){var e;return os((e=t[0])==null?void 0:e.type)}function Jn(t){const e=t.map(n=>pe(n.trim())).filter(n=>n!==null);return me(e)}function Tt(t){if(typeof t=="string")return t;if(t===void 0)return"";try{return JSON.stringify(t)}catch{return String(t)}}function ge(t){return typeof t=="string"?t:Array.isArray(t)?t.flatMap(e=>{const n=typeof e=="string"?e:D(e)?A(e.text,e.content):"";return n?[n]:[]}).join(`
|
|
26
|
+
`):""}function Kn(t){const e=new Map;for(const n of t){if(n.type!=="session.binary_asset"&&n.type!=="binary_asset")continue;const s=A(n.data.assetId),o=A(n.data.data),i=A(n.data.mimeType);s&&o&&i&&e.set(s,{data:o,mimeType:i})}return e}function Vn(t,e){if(!D(t))return null;const n=e.get(A(t.assetId)),s=A(t.mimeType,n==null?void 0:n.mimeType).toLowerCase(),o=A(t.data,n==null?void 0:n.data);return!s.startsWith("image/")||!o?null:{type:"image",source:{type:"base64",media_type:s,data:o}}}function he(t,e){if(!Array.isArray(t))return[];const n=[],s=new Set;for(const o of t){const i=Vn(o,e);if(!i)continue;const l=`${i.source.media_type}:${i.source.data}`;s.has(l)||(s.add(l),n.push(i))}return n}function Qn(t,e){const n=A(t.content),s=he(t.attachments,e);return s.length===0?n:[...s,...n?[{type:"text",text:n}]:[]]}function Gn(t,e){return D(t.result)?he([...Array.isArray(t.result.contents)?t.result.contents:[],...Array.isArray(t.result.binaryResultsForLlm)?t.result.binaryResultsForLlm:[]],e):[]}function rt(t,e){var o,i;if(!t)return{...e};const n=((o=t.output_tokens_details)==null?void 0:o.thinking_tokens)??0,s=((i=e.output_tokens_details)==null?void 0:i.thinking_tokens)??0;return{input_tokens:t.input_tokens+e.input_tokens,output_tokens:t.output_tokens+e.output_tokens,cache_creation_input_tokens:(t.cache_creation_input_tokens??0)+(e.cache_creation_input_tokens??0),cache_read_input_tokens:(t.cache_read_input_tokens??0)+(e.cache_read_input_tokens??0),...n||s?{output_tokens_details:{thinking_tokens:n+s}}:{}}}function bt(t,e=!1){const n=q(t.cacheWriteTokens),s=q(t.cacheReadTokens),o=q(t.inputTokens),i={input_tokens:e?Math.max(0,o-n-s):o,output_tokens:q(t.outputTokens),cache_creation_input_tokens:n,cache_read_input_tokens:s},l=q(t.reasoningTokens);return l&&(i.output_tokens_details={thinking_tokens:l}),i.input_tokens===0&&i.output_tokens===0&&i.cache_creation_input_tokens===0&&i.cache_read_input_tokens===0&&l===0?null:i}function Hn(t){if(!D(t.modelMetrics))return null;let e=null;for(const n of Object.values(t.modelMetrics)){if(!D(n)||!D(n.usage))continue;const s=bt(n.usage,!0);s&&(e=rt(e,s))}return e}function Xn(t){if(typeof t=="string")return{label:t};if(!D(t))return null;const e=A(t.label,t.title,t.value,t.name);if(!e)return null;const n=A(t.description);return n?{label:e,description:n}:{label:e}}function Zn(t){return Array.isArray(t)?t.map(Xn).filter(e=>e!==null):[]}function Yn(t){if(!D(t))return null;const e=A(t.question,t.prompt,t.text,t.message);if(!e)return null;const n=A(t.header,t.title),s=typeof t.multiSelect=="boolean"?t.multiSelect:typeof t.multi_select=="boolean"?t.multi_select:void 0;return{question:e,...n?{header:n}:{},options:Zn(t.options??t.choices),...s===void 0?{}:{multiSelect:s}}}function ts(t){const n=(Array.isArray(t.questions)?t.questions:[t]).map(Yn).filter(s=>s!==null);return n.length>0?{...t,questions:n}:t}function Z(t){switch(t.toLowerCase().replace(/-/g,"_")){case"ask_user":return"AskUserQuestion";case"bash":case"powershell":case"shell":return"Bash";case"create":return"Write";case"edit":return"Edit";default:return t}}function at(t,e){const n=D(e)?e:e===void 0?{}:{value:e};return t==="AskUserQuestion"?ts(n):t==="Edit"?{...n,file_path:A(n.file_path,n.path),old_string:A(n.old_string,n.old_str),new_string:A(n.new_string,n.new_str)}:t==="Write"?{...n,file_path:A(n.file_path,n.path),content:A(n.content,n.file_text)}:t==="Bash"&&typeof n.command!="string"&&typeof n.cmd=="string"?{...n,command:n.cmd}:n}function es(t){const e=t.error;if(typeof e=="string")return e;if(D(e)){const s=A(e.message,e.code);if(s)return s}const n=t.result;if(typeof n=="string")return n;if(!D(n))return n===void 0?"":Tt(n);if(typeof n.detailedContent=="string")return n.detailedContent;if(typeof n.content=="string")return n.content;if(Array.isArray(n.contents)){const s=n.contents.flatMap(o=>{const i=typeof o=="string"?o:D(o)?A(o.text,o.content,o.output):"";return i?[i]:[]}).join(`
|
|
27
|
+
`);if(s)return s}return n.structuredContent!==void 0?Tt(n.structuredContent):Tt(n)}function _e(t,e,n,s){if(!e||t.thinking.some(l=>l.thinking===e))return;const o={type:"thinking",thinking:e,signature:s};t.thinking.push(o);const i=t.contentBlocks[t.contentBlocks.length-1];if((i==null?void 0:i.kind)==="thinking"){i.blocks.push(o);return}t.contentBlocks.push({kind:"thinking",blocks:[o],timestamp:n})}function lt(t,e,n){t.toolCalls.push(e);const s=t.contentBlocks[t.contentBlocks.length-1];if((s==null?void 0:s.kind)==="tool_calls"){s.toolCalls.push(e);return}t.contentBlocks.push({kind:"tool_calls",toolCalls:[e],timestamp:n})}function Y(t,e,n,s){return{id:t,name:e,input:n,result:null,isError:!1,timestamp:s}}function ye(t,e,n){if(!Array.isArray(t))return[];const s=[];for(const o of t){if(!D(o))continue;const i=A(o.toolCallId),l=A(o.name);if(!i||!l||n(i))continue;const f=Z(l);s.push(Y(i,f,at(f,o.arguments),e))}return s}function ke(t,e,n,s){t.name=e,t.input=at(e,n),t.timestamp=s||t.timestamp}function Te(t,e,n){t.result=es(e);const s=Gn(e,n);s.length>0&&(t.resultImages=s),t.isError=e.success===!1||e.error!==void 0&&e.error!==null}function be(t,e,n,s,o,i){return{id:t,userMessage:n,contentBlocks:[],thinking:[],assistantText:[],toolCalls:[],subAgentActivity:[],timestamp:e,durationMs:null,tokenUsage:null,model:s,...o?{effort:o}:{},...i?{isFragment:!0}:{}}}function ns(t){return t.userMessage!==null||t.assistantText.length>0||t.thinking.length>0||t.toolCalls.length>0||t.subAgentActivity.length>0}function Ce(t,e){const n=Ln(t),s=me(n),o=Kn(n),i=[],l=new Map,f=new Map,_=new Map,T=new WeakMap,b=new WeakMap;let h=null,k=null,p,N=!1,S=!1,w=null;function B(I,a){a&&T.set(I,a)}function P(I){return h||(h=be(fe(I),X(I),null,k,p,!0)),h}function $(){h&&(ns(h)&&i.push(h),h=null)}function O(I){var C;const a=typeof I.agentId=="string"?I.agentId:"";if(!a)return null;const c=f.get(a);if(c)return c.message;const g=I.data,d=A(g.toolCallId),r=d?((C=l.get(d))==null?void 0:C.turn)??h:h;if(!r)return null;const y=A(g.executionMode),u={agentId:a,...d?{parentToolUseId:d}:{},agentName:A(g.agentDisplayName,g.agentName)||null,subagentType:A(g.agentType,g.agentName)||null,type:"assistant",content:null,toolCalls:[],thinking:[],text:[],timestamp:X(I),tokenUsage:null,model:A(g.model)||null,isBackground:y==="background",...A(g.description)?{prompt:A(g.description)}:{},status:"running"};return r.subAgentActivity.push(u),r.contentBlocks.push({kind:u.isBackground?"background_agent":"sub_agent",messages:[u],timestamp:u.timestamp}),f.set(a,{message:u,turn:r}),u}function j(I){if(ue(I))return!1;const a=O(I);if(!a)return!0;const{data:c}=I,g=X(I);if(I.type==="subagent.started"||I.type==="subagent.configured")return a.parentToolUseId||(a.parentToolUseId=A(c.toolCallId)||void 0),a.agentName=A(c.agentDisplayName,c.agentName)||a.agentName,a.subagentType=A(c.agentType,c.agentName)||a.subagentType,a.model=A(c.model)||a.model,a.prompt||(a.prompt=A(c.description)||void 0),a.isBackground||(a.isBackground=A(c.executionMode)==="background"),a.status="running",!0;if(I.type==="subagent.completed"||I.type==="subagent.failed"){a.agentName=A(c.agentDisplayName,c.agentName)||a.agentName,a.subagentType=A(c.agentType,c.agentName)||a.subagentType,a.model=A(c.model)||a.model,a.durationMs=q(c.durationMs)||a.durationMs,a.toolUseCount=q(c.totalToolCalls)||a.toolUseCount,a.status=I.type==="subagent.completed"?"completed":"failed";const d=A(c.error,c.message);return d&&!a.text.includes(d)&&a.text.push(d),!0}if(I.type==="user.message")return a.prompt||(a.prompt=A(c.content)||void 0),!0;if(I.type==="assistant.reasoning"){const d=A(c.content);return d&&!a.thinking.includes(d)&&a.thinking.push(d),!0}if(I.type==="assistant.message"){a.model=A(c.model)||a.model;const d=A(c.reasoningText);d&&!a.thinking.includes(d)&&a.thinking.push(d);const r=ge(c.content);r&&!a.text.includes(r)&&a.text.push(r);for(const y of ye(c.toolRequests,g,u=>_.has(u)))a.toolCalls.push(y),_.set(y.id,{call:y,message:a});return!0}if(I.type==="assistant.usage"){a.model=A(c.model)||a.model;const d=bt(c);return d&&(a.tokenUsage=rt(a.tokenUsage,d)),!0}if(I.type==="tool.execution_start"){const d=A(c.toolCallId)||z(I,"copilot-agent-tool"),r=A(c.toolName)||"Tool",y=Z(r),u=_.get(d);if(u)ke(u.call,y,c.arguments,g);else{const C=Y(d,y,at(y,c.arguments),g);a.toolCalls.push(C),_.set(d,{call:C,message:a})}return!0}if(I.type==="tool.execution_complete"){const d=A(c.toolCallId)||z(I,"copilot-agent-tool");let r=_.get(d);if(!r){const y=A(c.toolName)||"Tool",u=Z(y),C=Y(d,u,{},g);a.toolCalls.push(C),r={call:C,message:a}}return Te(r.call,c,o),_.delete(d),!0}return!0}for(const I of n){if(j(I))continue;const{data:a}=I,c=X(I);if(I.type==="session.start"||I.type==="session.resume"){k=A(a.selectedModel)||k,p=A(a.reasoningEffort)||p;continue}if(I.type==="session.auto_mode_resolved"){k=A(a.chosenModel)||k,h&&(h.model=k);continue}if(I.type==="session.model_change"){k=A(a.newModel)||k;const g=a.reasoningEffort;typeof g=="string"&&(p=g),h&&(h.model=k,p&&(h.effort=p));continue}if(I.type==="session.shutdown"){k=A(a.currentModel)||k,h&&!h.model&&(h.model=k),w=Hn(a)??w;const g=q(a.totalApiDurationMs);h&&!S&&g&&b.set(h,g);continue}if(I.type==="user.message"){$(),h=be(fe(I),c,Qn(a,o),k,p,!1),B(h,c);continue}if(I.type==="assistant.turn_start"){k=A(a.model)||k;const g=P(I);g.model=k,p&&(g.effort=p),B(g,c);continue}if(I.type==="assistant.reasoning"){const g=P(I);_e(g,A(a.content),c,A(a.reasoningId)||z(I,"copilot-thinking")),B(g,c);continue}if(I.type==="assistant.message"){k=A(a.model)||k;const g=P(I);g.model=k,p&&(g.effort=p),_e(g,A(a.reasoningText),c,z(I,"copilot-thinking")),Kt(g,ge(a.content),c);for(const d of ye(a.toolRequests,c,r=>l.has(r)))lt(g,d,c),l.set(d.id,{call:d,turn:g});B(g,c);continue}if(I.type==="assistant.usage"){k=A(a.model)||k,p=A(a.reasoningEffort)||p;const g=bt(a),d=q(a.duration);g&&(N=!0),d&&(S=!0);const r=P(I);r.model=k,p&&(r.effort=p),g&&(r.tokenUsage=rt(r.tokenUsage,g)),d&&b.set(r,(b.get(r)??0)+d),B(r,c);continue}if(I.type==="tool.execution_start"){k=A(a.model)||k;const g=P(I);g.model=k;const d=A(a.toolCallId)||z(I,"copilot-tool"),r=A(a.toolName)||"Tool",y=Z(r),u=l.get(d);if(u)ke(u.call,y,a.arguments,c);else{const C=Y(d,y,at(y,a.arguments),c);lt(g,C,c),l.set(d,{call:C,turn:g})}B(g,c);continue}if(I.type==="tool.execution_complete"){k=A(a.model)||k;const g=A(a.toolCallId)||z(I,"copilot-tool");let d=l.get(g);if(!d){const r=P(I),y=A(a.toolName)||"Tool",u=Z(y),C=Y(g,u,{},c);lt(r,C,c),d={call:C,turn:r}}Te(d.call,a,o),l.delete(g),B(d.turn,c);continue}if(I.type==="session.error"){const g=P(I),r={errorType:A(a.errorType)||"unknown"};typeof a.statusCode=="number"&&(r.statusCode=a.statusCode),typeof a.errorCode=="string"&&(r.errorCode=a.errorCode),lt(g,{id:z(I,"copilot-error"),name:"Error",input:r,result:A(a.message)||"Copilot session error",isError:!0,timestamp:c},c),B(g,c);continue}(I.type==="assistant.turn_end"||I.type==="assistant.idle"||I.type==="session.idle")&&h&&B(h,c)}if($(),!N&&w&&i.length===1&&(i[0].tokenUsage=rt(i[0].tokenUsage,w)),s.model)for(const I of i)I.model||(I.model=s.model);for(const I of i){const a=T.get(I),c=Date.parse(I.timestamp),g=a?Date.parse(a):Number.NaN;if(Number.isFinite(c)&&Number.isFinite(g)&&g>=c)I.durationMs=g-c;else{const d=b.get(I)??0;d&&(I.durationMs=d)}}const F=e!=null&&e.skipStats?tt(i.length):et(i);return!(e!=null&&e.skipStats)&&!N&&w&&i.length>1&&(F.totalInputTokens=w.input_tokens,F.totalOutputTokens=w.output_tokens,F.totalCacheCreationTokens=w.cache_creation_input_tokens??0,F.totalCacheReadTokens=w.cache_read_input_tokens??0),{sessionId:s.sessionId,version:s.version,gitBranch:s.gitBranch,cwd:s.cwd,slug:s.slug,name:s.name,model:s.model,turns:i,stats:F,rawMessages:e!=null&&e.skipStats?[]:n,agentKind:"copilot"}}function ss(t,e){const n=t.rawMessages.map(s=>JSON.stringify(s)).join(`
|
|
28
|
+
`);return Ce(n?`${n}
|
|
29
|
+
${e}`:e)}function os(t){return typeof t=="string"&&(t==="abort"||t==="binary_asset"||t==="user.message"||t.startsWith("assistant.")||t.startsWith("permission.")||t.startsWith("session.")||t.startsWith("subagent.")||t.startsWith("tool.")||t.startsWith("user_input."))}function is(t){const e=new Map;for(const o of t){const i=typeof o.agentId=="string"?o.agentId:"";if(!i&&(o.type==="abort"||o.type==="session.shutdown"||o.type==="session.error")){e.clear();continue}if(!i||!o.type.startsWith("subagent."))continue;const l=D(o.data)?o.data:{};if(o.type==="subagent.completed"||o.type==="subagent.failed"){e.delete(i);continue}if(o.type==="subagent.started"||o.type==="subagent.configured"){const f=[l.agentDisplayName,l.description,l.agentName].find(_=>typeof _=="string")??"";e.set(i,f||e.get(i)||"")}}if(e.size>0){const o=[...e.values()];return{status:"awaiting_agents",pendingQueue:0,pendingAgents:o.length,pendingAgentDescriptions:o.filter(i=>i.length>0)}}let n=!1;const s=new Set;for(let o=t.length-1;o>=0;o--){const i=t[o];if(typeof i.agentId=="string"&&i.agentId)continue;const l=D(i.data)?i.data:{};switch(i.type){case"abort":case"session.shutdown":return{status:"completed"};case"assistant.turn_end":{for(let f=o-1;f>=0;f--){const _=t[f];if(typeof _.agentId=="string"&&_.agentId)continue;if(_.type==="user.message")break;if(_.type==="abort")return{status:"completed"};if(_.type!=="assistant.message")continue;const T=D(_.data)?_.data:{};return Array.isArray(T.toolRequests)&&T.toolRequests.length>0?{status:"processing"}:{status:"completed"}}return{status:"processing"}}case"session.error":return{status:"completed",terminalReason:typeof l.message=="string"?l.message:"Copilot session error"};case"assistant.idle":case"session.idle":return{status:n?"completed":"idle"};case"permission.completed":{const f=typeof l.requestId=="string"?l.requestId:"";f&&s.add(f);continue}case"permission.requested":{const f=typeof l.requestId=="string"?l.requestId:"";if(f&&s.has(f))continue;return{status:"deferred"}}case"user_input.requested":return{status:"tool_use",toolName:"AskUserQuestion"};case"tool.execution_start":return s.size>0?{status:"thinking"}:{status:"tool_use",toolName:typeof l.toolName=="string"?Q(l.toolName):typeof l.name=="string"?Q(l.name):void 0};case"tool.execution_complete":return{status:"thinking"};case"assistant.turn_start":return{status:"processing"};case"assistant.message":case"assistant.message_delta":case"assistant.reasoning":case"assistant.reasoning_delta":return{status:"thinking"};case"user.message":return n=!0,{status:"processing"};case"session.start":case"session.resume":return{status:n?"processing":"idle"}}}return{status:"idle"}}function rs(t){const e=[];for(let n=0;n<t.length;n++){const s=t[n];if(s.type!=="user.message"||typeof s.agentId=="string")continue;const o=s.data;!o||typeof o!="object"||Array.isArray(o)||typeof s.id!="string"||!s.id||e.push(n)}return e}const xe=ct[ct.length-1],as={kind:"codex",descriptor:dt("codex"),detectsText:Bn,detectsRecords:Rn,parse:ce,append:Un,metadataFromLines:Pn,status:On,turnBoundaries:jn},ls={kind:"copilot",descriptor:dt("copilot"),detectsText:qn,detectsRecords:zn,parse:Ce,append:ss,metadataFromLines:Jn,status:is,turnBoundaries:rs},cs={kind:"claude",descriptor:dt("claude"),detectsText:Wt,detectsRecords:Wt,parse:tn,append:en,metadataFromLines:Ye,status:ln,turnBoundaries:cn},us=Object.freeze({claude:cs,codex:as,copilot:ls});function ds(t){function e(n){for(const s of ct){const o=t[s];if(n(o))return o}return t[xe]}return{formatFor:n=>t[n],formatForText:n=>e(s=>s.detectsText(n)),formatForRecords:n=>e(s=>s.detectsRecords(n))}}const Ae=ds(us);function Ie(t){return Ae.formatForText(t)}function ps(t){return Ae.formatForRecords(t)}function fs(t,e){return Ie(t).parse(t,e)}function ms(t,e){const n=ps(t.rawMessages);return(n.kind===xe?Ie(e):n).append(t,e)}self.onmessage=t=>{const e=t.data;try{let n;e.type==="parse"?n=fs(e.text):n=ms(e.existing,e.newText),self.postMessage({type:"result",id:e.id,session:n})}catch(n){self.postMessage({type:"error",id:e.id,error:n instanceof Error?n.message:String(n)})}}})();
|