@swestash/agent-lens 0.13.3 → 0.14.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.
@@ -1,15 +0,0 @@
1
- import{e as Os,j as e,q as A,r as d,L as y,f as Ms,t as Fs,b as $s,v as Rs,c as T,w as ts,s as qs,x as As,h as G,i as as,l as Ls,y as Bs,z as Ps,k as Us,E as Ds,o as Hs}from"./index-r-fSz0IT.js";import{S as O,a as ls,u as Js}from"./useResetOn-2tqWddId.js";import{A as L,C as S,p as v}from"./jsonish-mD--ddqP.js";import{M as Ws,r as Ks}from"./index-C2D0y2yH.js";function Vs({id:s}){const n=Os();return e.jsxs("details",{className:"export-menu col-customizer",ref:n,children:[e.jsx("summary",{className:"export",title:"Export this session as Markdown",children:"⬇ Export Markdown"}),e.jsxs("div",{className:"col-menu",role:"group","aria-label":"Export options",children:[e.jsxs("a",{href:A(s),download:!0,children:["Redacted ",e.jsx("span",{className:"muted small",children:"(secrets masked)"})]}),e.jsxs("a",{href:A(s,"structure"),download:!0,children:["Structure only ",e.jsx("span",{className:"muted small",children:"(scrubbed)"})]}),e.jsxs("a",{className:"export-verbatim",href:A(s,"off"),download:!0,children:["Verbatim ",e.jsx("span",{className:"muted small",children:"(unredacted)"})]})]})]})}function Qs({c:s}){var i;const[n,t]=d.useState(!1),a=d.useId(),l=(i=s.signals)==null?void 0:i.loc;return e.jsxs("div",{className:"classification",children:[e.jsx("span",{className:"tag cat cat-"+(s.category??"none"),children:s.category??"unclassified"}),s.complexity_band&&e.jsxs("span",{className:"tag complexity",children:[s.complexity_band," · ",s.complexity_score]}),l&&e.jsxs("span",{className:"muted small",children:["+",l.added,"/−",l.removed," LoC · ",l.files," files"]}),e.jsxs("button",{className:"ghost small","aria-expanded":n,"aria-controls":a,onClick:()=>t(r=>!r),children:["why ",n?"▾":"▸"]}),n&&(s.signals?e.jsx(Ys,{id:a,s:s.signals,category:s.category}):e.jsx("div",{id:a,className:"muted small pad",children:"No signals recorded for this session."}))]})}const zs={loc:"Lines changed",files:"Files touched",turns:"Turns",tokens:"Work tokens",duration:"Duration",subagents:"Subagents"},X=s=>`${Math.max(0,Math.min(1,s))*100}%`;function Z({counts:s}){const n=Object.entries(s).sort((t,a)=>a[1]-t[1]);return n.length===0?e.jsx("span",{className:"muted",children:"—"}):e.jsx("span",{className:"sig-chips",children:n.map(([t,a])=>e.jsxs("span",{className:"sig-chip",children:[t," ",e.jsxs("span",{className:"muted",children:["×",a]})]},t))})}function Ys({id:s,s:n,category:t}){const[a,l]=d.useState(!1),i=d.useId(),r=n.complexity_weights??{},o=n.complexity_subscores??{},c=Object.keys(r).map(m=>({key:m,weight:r[m],subscore:o[m]??0,pts:r[m]*(o[m]??0)*100})).sort((m,w)=>w.pts-m.pts),u=Math.max(...c.map(m=>m.pts),1e-4),h=Object.entries(n.category_scores??{}).map(([m,w])=>({k:m,v:w})).sort((m,w)=>w.v-m.v),f=Math.max(...h.map(m=>m.v),1e-4),x=h.filter(m=>m.v>.02||m.k===t),g=n.skills&&Object.keys(n.skills).length>0;return e.jsxs("div",{id:s,className:"signals-panel",children:[c.length>0&&e.jsxs("section",{className:"sig-section",children:[e.jsxs("h4",{className:"sig-h",children:["Complexity breakdown ",e.jsx("span",{className:"muted",children:"— what built the score"})]}),e.jsx("ul",{className:"sig-bars",children:c.map(m=>e.jsxs("li",{className:"sig-bar-row",children:[e.jsx("span",{className:"sig-bar-label",children:zs[m.key]??m.key}),e.jsx("span",{className:"sig-bar","aria-hidden":"true",children:e.jsx("span",{className:"sig-bar-fill",style:{width:X(m.pts/u)}})}),e.jsxs("span",{className:"sig-bar-val",children:[m.pts.toFixed(1)," pts"]}),e.jsxs("span",{className:"sig-bar-sub muted",children:[Math.round(m.subscore*100),"% intensity · weight ",Math.round(m.weight*100),"%"]})]},m.key))})]}),x.length>0&&e.jsxs("section",{className:"sig-section",children:[e.jsxs("h4",{className:"sig-h",children:["Category scores ",e.jsxs("span",{className:"muted",children:["— why “",t,"” won"]})]}),e.jsx("ul",{className:"sig-bars",children:x.map(m=>e.jsxs("li",{className:"sig-bar-row"+(m.k===t?" is-win":""),children:[e.jsx("span",{className:"sig-bar-label",children:m.k}),e.jsx("span",{className:"sig-bar","aria-hidden":"true",children:e.jsx("span",{className:"sig-bar-fill",style:{width:X(m.v/f)}})}),e.jsx("span",{className:"sig-bar-val",children:m.v.toFixed(2)})]},m.k))})]}),e.jsxs("section",{className:"sig-section",children:[e.jsx("h4",{className:"sig-h",children:"Evidence"}),e.jsxs("dl",{className:"sig-grid",children:[n.tool_counts&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Tools"}),e.jsx("dd",{children:e.jsx(Z,{counts:n.tool_counts})})]}),g&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Skills"}),e.jsx("dd",{children:e.jsx(Z,{counts:n.skills})})]}),n.subagent_role&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Subagent role"}),e.jsx("dd",{children:n.subagent_role})]}),n.files&&n.files.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("dt",{children:["Files (",n.files.length,")"]}),e.jsx("dd",{className:"sig-files",children:n.files.join(", ")})]})]})]}),e.jsx("button",{className:"ghost small","aria-expanded":a,"aria-controls":i,onClick:()=>l(m=>!m),children:a?"Hide raw JSON ▴":"View raw JSON ▾"}),a&&e.jsx("pre",{id:i,className:"code signals",children:JSON.stringify(n,null,2)})]})}function Gs({f:s}){var r;const[n,t]=d.useState(!1),a=d.useId(),l=((r=s.signals)==null?void 0:r.modifiers)??{},i=Object.keys(l).filter(o=>l[o]!==!1&&l[o]!=null&&l[o]!=="");return e.jsxs("div",{className:"finding sev-border-"+s.severity,children:[e.jsxs("button",{className:"finding-head","aria-expanded":n,"aria-controls":a,onClick:()=>t(o=>!o),children:[e.jsx(ls,{severity:s.severity}),e.jsx("span",{className:"finding-title",children:s.title??s.rule_id}),s.framework_ref&&e.jsx("span",{className:"tag framework",children:s.framework_ref}),e.jsx("span",{className:"chev",children:n?"▾":"▸"})]}),n&&e.jsxs("div",{className:"finding-body",id:a,children:[s.evidence&&e.jsx("div",{className:"code-block",children:e.jsx("pre",{className:"code finding-evidence",children:s.evidence})}),e.jsxs("dl",{className:"sig-grid",children:[e.jsx("dt",{children:"Rule"}),e.jsx("dd",{children:e.jsx("code",{children:s.rule_id})}),e.jsx("dt",{children:"Category"}),e.jsx("dd",{children:s.category}),i.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Context"}),e.jsx("dd",{children:i.map(o=>e.jsxs("span",{className:"sig-chip",children:[o,l[o]!==!0?e.jsxs("span",{className:"muted",children:[" ",String(l[o])]}):null]},o))})]})]}),e.jsxs(y,{className:"subagent-link small",to:`/security?rule=${encodeURIComponent(s.rule_id)}`,children:["see all “",s.rule_id,"” findings →"]})]})]})}function Xs({findings:s}){if(!s.length)return null;const n=[...s].sort((t,a)=>O.indexOf(t.severity)-O.indexOf(a.severity));return e.jsx("div",{className:"tool-findings",children:n.map(t=>e.jsx(Gs,{f:t},t.id))})}function Zs({findings:s,sessionId:n}){const t=new Map;for(const l of s)t.set(l.severity,(t.get(l.severity)??0)+1);const a=O.find(l=>t.has(l))??"info";return e.jsxs("div",{className:"security-banner sev-border-"+a,role:"status",children:[e.jsx("span",{className:"security-banner-icon","aria-hidden":"true",children:"🛡"}),e.jsxs("span",{className:"security-banner-text",children:[s.length," security ",s.length===1?"finding":"findings"," in this session"]}),e.jsx("span",{className:"security-banner-sevs",children:O.filter(l=>t.has(l)).map(l=>e.jsx(ls,{severity:l,count:t.get(l)},l))}),e.jsx(y,{className:"subagent-link small",to:`/security?session=${encodeURIComponent(n)}`,children:"view on Security page →"})]})}function se(s){const n={dirs:new Map,files:[]};for(const a of s){const l=a.display.startsWith("/"),i=(l?a.display.slice(1):a.display).split("/");l&&i.length>0&&(i[0]="/"+i[0]);let r=n;for(const o of i.slice(0,-1))r=r.dirs.get(o)??r.dirs.set(o,{dirs:new Map,files:[]}).get(o);r.files.push({name:i[i.length-1],path:a.path,list:a.list})}const t=a=>{for(const[l,i]of[...a.dirs.entries()])if(t(i),i.files.length===0&&i.dirs.size===1){const[r,o]=[...i.dirs.entries()][0];a.dirs.delete(l),a.dirs.set(l+"/"+r,o)}};return t(n),n}function rs({node:s,depth:n}){const t={paddingLeft:`${.4+n*1.1}rem`};return e.jsxs(e.Fragment,{children:[[...s.dirs.entries()].sort(([a],[l])=>a.localeCompare(l)).map(([a,l])=>e.jsxs(d.Fragment,{children:[e.jsx("tr",{children:e.jsx("td",{colSpan:3,style:t,children:e.jsxs("span",{className:"muted",children:["📁 ",a,"/"]})})}),e.jsx(rs,{node:l,depth:n+1})]},a)),[...s.files].sort((a,l)=>a.name.localeCompare(l.name)).map(a=>{const l=a.list.find(o=>o.event_uuid),i=a.list.reduce((o,c)=>o+(c.lines_added??0),0),r=a.list.reduce((o,c)=>o+(c.lines_removed??0),0);return e.jsxs("tr",{children:[e.jsx("td",{style:t,children:l!=null&&l.event_uuid?e.jsx("a",{href:`#ev-${l.event_uuid}`,className:"title",title:a.path+" — jump to the first change",children:a.name}):e.jsx("span",{title:a.path,children:a.name})}),e.jsxs("td",{className:"num",children:[a.list.length,"× ",e.jsxs("span",{className:"muted",children:["(+",i," −",r,")"]})]}),e.jsx("td",{children:e.jsx(y,{className:"subagent-link small",to:`/file?path=${encodeURIComponent(a.path)}`,children:"history →"})})]},a.path)})]})}function ee({changes:s,projectPath:n}){const t=new Map;for(const i of s)(t.get(i.file_path)??t.set(i.file_path,[]).get(i.file_path)).push(i);const a=i=>n&&i.startsWith(n.replace(/\/$/,"")+"/")?i.slice(n.replace(/\/$/,"").length+1):i,l=se([...t.entries()].map(([i,r])=>({display:a(i),path:i,list:r})));return e.jsxs("details",{className:"wf-run files-changed",children:[e.jsxs("summary",{children:["📄 ",t.size," ",t.size===1?"file":"files"," changed · ",s.length," ",s.length===1?"edit":"edits"]}),e.jsx("table",{className:"sessions",children:e.jsx("tbody",{children:e.jsx(rs,{node:l,depth:0})})})]})}function ne({d:s}){var t;const n=s.session;return e.jsxs("div",{className:"detail-head",children:[e.jsx(y,{to:"/",className:"back",children:"← all sessions"}),e.jsx("h1",{children:n.title||n.id.slice(0,12)}),e.jsxs("div",{className:"detail-meta",children:[e.jsx("span",{children:e.jsx("b",{children:n.source_id})}),e.jsx("span",{className:"path",children:n.project_path}),n.is_sidechain?e.jsx("span",{className:"tag subagent",children:"subagent"}):null,s.parent&&e.jsxs("span",{className:"spawned-by",children:["↖ spawned by"," ",e.jsx(y,{to:`/session/${s.parent.id}`,children:s.parent.title||s.parent.id.slice(0,12)}),s.parent.turn_seq!=null?` · turn ${s.parent.turn_seq+1}`:""]}),e.jsxs("span",{children:[s.turns.length," turns"]}),e.jsxs("span",{children:[n.event_count," events"]}),e.jsxs("span",{title:Fs(n.token_split),children:[Ms(n.tokens)," tok"]}),e.jsxs("span",{title:Rs(n.unpriced_models),children:[$s(n.cost),(t=n.unpriced_models)!=null&&t.length?e.jsx("span",{className:"warn-tag",children:" ⚠"}):null]}),n.tool_call_count>0&&e.jsxs("span",{className:n.tool_failure_count>0?"tool-err-stat":"muted",title:"Tool calls that returned is_error, of "+n.tool_call_count+". Failures = the agent's tool errored; declined/blocked = you rejected it or a guardrail blocked it (heuristic split from the result text — not an API-reported distinction).",children:[n.tool_failure_count," failed",n.tool_rejection_count>0?` · ${n.tool_rejection_count} declined/blocked`:"",` of ${n.tool_call_count} tool calls`]}),e.jsx("span",{children:T(n.duration_ms)}),e.jsx("span",{className:"muted",children:ts(n.started_at)}),e.jsx(Vs,{id:n.id})]}),s.classification&&e.jsx(Qs,{c:s.classification}),s.findings&&s.findings.length>0&&e.jsx(Zs,{findings:s.findings,sessionId:n.id}),s.file_changes&&s.file_changes.length>0&&e.jsx(ee,{changes:s.file_changes,projectPath:n.project_path??null})]})}function te({search:s,turnCount:n,anyOpen:t,onToggleAll:a,hideTools:l,onToggleHideTools:i,format:r,onChooseFormat:o}){return e.jsxs(e.Fragment,{children:[s,e.jsxs("div",{className:"transcript-tools",children:[n>1&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"muted small",children:[n," turns"]}),e.jsx("button",{className:"ghost small",onClick:a,children:t?"Collapse all":"Expand all"})]}),e.jsxs("button",{className:"ghost small"+(l?" is-active":""),"aria-pressed":l,onClick:i,title:"Hide Bash/Edit/Skill and other tool calls — show only assistant answers, plans and questions",children:[l?"☑ ":"☐ ","Hide tool messages"]}),e.jsxs("div",{className:"format-toggle",role:"group","aria-label":"Message format",children:[e.jsx("button",{className:"ghost small"+(r==="markdown"?" is-active":""),"aria-pressed":r==="markdown",onClick:()=>o("markdown"),children:"Markdown"}),e.jsx("button",{className:"ghost small"+(r==="raw"?" is-active":""),"aria-pressed":r==="raw",onClick:()=>o("raw"),children:"Raw"})]})]})]})}const M=2,ae={hits:[],byTurn:new Map,total:0};function is(s){var n;return[s.input_json,s.result_summary,(n=s.full_result)==null?void 0:n.text].filter(Boolean).join(`
2
- `)}function os(s){const n=[];s.text&&n.push(s.text),s.thinking&&n.push(s.thinking);for(const t of s.toolCalls)n.push(is(t));return n.join(`
3
- `).toLowerCase()}function le(s){return new Map(s.map(n=>[n.uuid,os(n)]))}function re(s,n){let t=0;for(let a=s.indexOf(n);a!==-1;a=s.indexOf(n,a+n.length))t++;return t}function ie(s,n,t){const a=t.trim().toLowerCase();if(a.length<M)return ae;const l=[],i=new Map;for(const r of s){const o=re(n.get(r.uuid)??os(r),a);o&&(l.push({uuid:r.uuid,turnId:r.turn_id??null,count:o}),r.turn_id&&i.set(r.turn_id,(i.get(r.turn_id)??0)+1))}return{hits:l,byTurn:i,total:l.length}}function oe(s,n){return U(is(s),n)}function U(s,n){const t=n.trim().toLowerCase();return!s||t.length<M?!1:s.toLowerCase().includes(t)}function cs(s,n,t){return a=>{if(a.key==="Escape"){a.preventDefault(),t();return}if(a.key==="Enter"){if(a.shiftKey){a.preventDefault(),s();return}a.target.tagName!=="BUTTON"&&(a.preventDefault(),n())}}}function ce({query:s,total:n,index:t,onPrev:a,onNext:l,onClear:i,onBackToBox:r}){return e.jsxs("div",{className:"search-nav",role:"group","aria-label":"Search matches",tabIndex:-1,onKeyDown:cs(a,l,i),children:[e.jsx("button",{type:"button",className:"ghost small sn-back","aria-label":"Back to the search box",onClick:r,children:"🔍"}),e.jsxs("span",{className:"sn-term",children:[e.jsx("span",{className:"sn-q",children:s}),e.jsxs("span",{className:"sn-pos",children:[t+1,"/",n]})]}),e.jsx("button",{type:"button",className:"ghost small","aria-label":"Previous match",onClick:a,children:"◂"}),e.jsx("button",{type:"button",className:"ghost small","aria-label":"Next match",onClick:l,children:"▸"}),e.jsx("button",{type:"button",className:"ghost small","aria-label":"Clear search",onClick:i,children:"✕"})]})}const de=150;function ue({query:s,onQuery:n,total:t,index:a,onPrev:l,onNext:i,inputRef:r}){const[o,c]=d.useState(s),u=d.useRef(0),h=d.useRef(null),[f,x]=d.useState(!0);d.useEffect(()=>{const N=h.current;if(!N||typeof IntersectionObserver>"u")return;const b=new IntersectionObserver(([F])=>x(F.isIntersecting));return b.observe(N),()=>b.disconnect()},[]);const g=d.useRef(s);g.current!==s&&(g.current=s,c(s)),d.useEffect(()=>()=>window.clearTimeout(u.current),[]);const m=N=>{c(N),window.clearTimeout(u.current),u.current=window.setTimeout(()=>n(N),de)},w=()=>{var N;window.clearTimeout(u.current),c(""),n(""),(N=r.current)==null||N.focus()},j=o.trim().length>=M;return e.jsxs(e.Fragment,{children:[e.jsxs("form",{ref:h,className:"transcript-search",role:"search",onSubmit:N=>N.preventDefault(),onKeyDown:cs(l,i,w),children:[e.jsx("span",{className:"ts-icon","aria-hidden":"true",children:"🔍"}),e.jsx("input",{ref:r,type:"search","aria-label":"Find in this session",placeholder:"Find in session…",value:o,onChange:N=>m(N.target.value)}),e.jsx("span",{className:"ts-count muted small",role:"status","aria-live":"polite",children:j?t===0?"No matches":`${a+1} of ${t} message${t===1?"":"s"}`:""}),e.jsx("button",{type:"button",className:"ghost small","aria-label":"Previous match",disabled:t===0,onClick:l,children:"◂"}),e.jsx("button",{type:"button",className:"ghost small","aria-label":"Next match",disabled:t===0,onClick:i,children:"▸"}),o&&e.jsx("button",{type:"button",className:"ghost small","aria-label":"Clear search",onClick:w,children:"✕"})]}),t>0&&!f&&e.jsx(ce,{query:s,total:t,index:a,onPrev:l,onNext:i,onClear:w,onBackToBox:()=>{var N;return(N=r.current)==null?void 0:N.focus()}})]})}function me({d:s}){const n=s.workflow_runs??[],t=s.children.filter(l=>!l.workflow_run_id),a=n.length>0;return e.jsxs("div",{className:"subagents",children:[e.jsxs("h2",{children:["Spawned subagents (",s.children.length,")"]}),n.map(l=>{const i=s.children.filter(r=>r.workflow_run_id===l.run_id);return e.jsxs("details",{className:"wf-run",children:[e.jsxs("summary",{children:[e.jsxs(y,{className:"wf-run-name",to:`/workflow/${l.run_id}`,onClick:r=>r.stopPropagation(),children:["🔀 ",l.name||"workflow"," →"]}),l.status&&e.jsx("span",{className:"tag task-status task-status-"+l.status.toLowerCase(),children:l.status}),e.jsxs("span",{className:"muted small",children:[i.length," agent",i.length===1?"":"s",l.turn_seq!=null?` · turn ${l.turn_seq+1}`:""," · ",e.jsx("code",{children:l.run_id})]})]}),e.jsx("ul",{children:i.map(r=>e.jsx(L,{a:r},r.id))})]},l.run_id)}),t.length>0&&(a?e.jsxs("details",{className:"wf-run",open:!0,children:[e.jsxs("summary",{children:[e.jsx("span",{className:"wf-run-name",children:"Task / Agent"}),e.jsxs("span",{className:"muted small",children:[t.length," subagent",t.length===1?"":"s"]})]}),e.jsx("ul",{children:t.map(l=>e.jsx(L,{a:l},l.id))})]}):e.jsx("ul",{children:t.map(l=>e.jsx(L,{a:l},l.id))}))]})}function ss(s,n){const t=s===""?[]:s.split(`
4
- `),a=n===""?[]:n.split(`
5
- `),l=t.length,i=a.length;if(l*i>25e4)return[...t.map(h=>({type:"del",text:h})),...a.map(h=>({type:"add",text:h}))];const r=Array.from({length:l+1},()=>new Array(i+1).fill(0));for(let h=l-1;h>=0;h--)for(let f=i-1;f>=0;f--)r[h][f]=t[h]===a[f]?r[h+1][f+1]+1:Math.max(r[h+1][f],r[h][f+1]);const o=[];let c=0,u=0;for(;c<l&&u<i;)t[c]===a[u]?(o.push({type:"ctx",text:t[c]}),c++,u++):r[c+1][u]>=r[c][u+1]?(o.push({type:"del",text:t[c]}),c++):(o.push({type:"add",text:a[u]}),u++);for(;c<l;)o.push({type:"del",text:t[c++]});for(;u<i;)o.push({type:"add",text:a[u++]});return o}function ds(s){if(!s)return null;try{const n=JSON.parse(s).plan;return typeof n=="string"&&n.trim()?n:null}catch{return null}}function he(s){if(!s)return[];try{const n=JSON.parse(s).questions;return Array.isArray(n)?n:[]}catch{return[]}}function pe(s){if(!s)return{answers:{},annotations:{}};try{const n=JSON.parse(s);if(n&&typeof n=="object"&&n.answers)return{answers:n.answers,annotations:n.annotations??{}}}catch{}return{answers:{},annotations:{}}}function xe(s){if(!s)return null;try{const n=JSON.parse(s);if(!n||typeof n!="object")return null;const t=typeof n.command=="string"?n.command:"";return t.trim()?{command:t,description:typeof n.description=="string"?n.description:void 0,timeout:typeof n.timeout=="number"?n.timeout:void 0,run_in_background:n.run_in_background===!0,restart:n.restart===!0}:null}catch{return null}}function fe(s,n){if(!n)return null;try{const t=JSON.parse(n);if(!t||typeof t!="object"||typeof t.file_path!="string")return null;let a;if(s==="Write"){if(typeof t.content!="string")return null;a=[t.content===""?[]:t.content.split(`
6
- `).map(r=>({type:"add",text:r}))]}else if(s==="MultiEdit"){if(!Array.isArray(t.edits)||(a=t.edits.filter(r=>{const o=r;return!!o&&typeof o.old_string=="string"&&typeof o.new_string=="string"}).map(r=>ss(r.old_string,r.new_string)),a.length===0))return null}else{if(typeof t.old_string!="string"||typeof t.new_string!="string")return null;a=[ss(t.old_string,t.new_string)]}let l=0,i=0;for(const r of a)for(const o of r)o.type==="add"?l++:o.type==="del"&&i++;return{file_path:t.file_path,kind:s,hunks:a,adds:l,dels:i}}catch{return null}}function je(s){const n=s.lastIndexOf("/");return n>=0?{dir:s.slice(0,n+1),base:s.slice(n+1)}:{dir:"",base:s}}function us(s){var a,l,i,r,o;const n=(l=(a=s.match(/<command-name>([^<]*)<\/command-name>/))==null?void 0:a[1])==null?void 0:l.trim();if(n){const c=((r=(i=s.match(/<command-args>([^<]*)<\/command-args>/))==null?void 0:i[1])==null?void 0:r.trim())??"";return{kind:"invocation",name:n.startsWith("/")?n:`/${n}`,args:c}}const t=(o=s.match(/<(?:local-command-stdout|command-output|local-command-stderr)>([\s\S]*?)<\/(?:local-command-stdout|command-output|local-command-stderr)>/))==null?void 0:o[1];return t!=null?{kind:"output",stdout:t.trim()}:/<local-command-caveat>/.test(s)?{kind:"caveat"}:null}function ms(s){if(!/<task-notification>/.test(s))return null;const n=t=>{var a,l;return((l=(a=s.match(new RegExp(`<${t}>([\\s\\S]*?)</${t}>`)))==null?void 0:a[1])==null?void 0:l.trim())??null};return{taskId:n("task-id"),toolUseId:n("tool-use-id"),status:n("status"),summary:n("summary")}}function ge(s){const n=us(s);if((n==null?void 0:n.kind)==="invocation")return`⌘ ${n.name}${n.args?" "+n.args:""}`;if((n==null?void 0:n.kind)==="output")return"⌘ command output";if((n==null?void 0:n.kind)==="caveat")return"⌘ local command";const t=ms(s);return t?`🔔 task ${t.status??"notification"}`:s}const hs=d.createContext("markdown"),ps=d.createContext(new Map),xs=d.createContext(!1),fs=d.createContext(null),D=d.createContext({query:"",activeUuid:null});function Ne({cmd:s}){return s.kind==="invocation"?e.jsxs("div",{className:"cmd",children:[e.jsxs("span",{className:"cmd-chip",title:"Slash command",children:["⌘ ",s.name]}),s.args&&e.jsx("code",{className:"cmd-args",children:s.args})]}):s.kind==="output"?e.jsx("div",{className:"cmd-out",children:s.stdout&&s.stdout!=="(no content)"?s.stdout:e.jsx("span",{className:"muted",children:"no output"})}):e.jsx("div",{className:"cmd-note muted small",children:"⌘ local command context"})}function we({n:s}){const n=d.useContext(ps),t=s.toolUseId?n.get(s.toolUseId):void 0,a=(s.status??"").toLowerCase();return e.jsxs("div",{className:"task-notif",children:[e.jsxs("div",{className:"task-notif-head",children:[e.jsx("span",{className:"task-notif-icon","aria-hidden":"true",children:"🔔"}),s.status&&e.jsx("span",{className:"tag task-status task-status-"+a,children:s.status}),s.taskId&&e.jsxs("code",{className:"task-notif-id",children:["task ",s.taskId]}),t&&e.jsx(y,{className:"subagent-link small",to:`/workflow/${t}`,children:"view workflow →"})]}),s.summary&&e.jsx("div",{className:"task-notif-summary",children:s.summary})]})}function es({text:s,id:n}){return d.useContext(hs)==="raw"?e.jsx("div",{className:"text",id:n,children:s}):e.jsx("div",{className:"text md",id:n,children:e.jsx(Ws,{remarkPlugins:[Ks],components:_e,children:s})})}const _e={a:({node:s,...n})=>e.jsx("a",{...n,target:"_blank",rel:"noopener noreferrer"})};function js({text:s,uuid:n}){const t=s.length>1400||s.split(`
7
- `).length>18,[a,l]=d.useState(!1),i=d.useContext(D),r=d.useId();if(!t)return e.jsx(es,{text:s});const o=a||!!n&&i.activeUuid===n&&U(s,i.query);return e.jsxs("div",{className:"text-wrap"+(o?"":" is-clamped"),children:[e.jsx(es,{text:s,id:r}),e.jsx("button",{className:"ghost small show-more","aria-expanded":o,"aria-controls":r,onClick:()=>l(!o),children:o?"Show less ▴":"Show more ▾"})]})}function gs({t:s}){const[n,t]=d.useState(!1),[a,l]=d.useState(!1),i=d.useId(),r=s.skill_name?`Skill · ${s.skill_name}`:s.tool_name==="Workflow"&&s.workflow_name?`Workflow · ${s.workflow_name}`:s.agent_type?`${s.tool_name} → ${s.agent_type}`:s.tool_name;return e.jsxs("div",{className:"tool "+(s.status==="error"?"tool-err":""),children:[e.jsxs("button",{className:"tool-head","aria-expanded":n,"aria-controls":i,onClick:()=>t(o=>!o),children:[e.jsxs("span",{className:"tool-name",children:["🔧 ",r]}),s.status&&e.jsx("span",{className:"tool-status",children:s.status}),s.total_duration_ms?e.jsx("span",{className:"muted",children:T(s.total_duration_ms)}):null,e.jsx("span",{className:"chev",children:n?"▾":"▸"})]}),s.spawned_session_id&&e.jsx(y,{className:"subagent-link small",to:`/session/${s.spawned_session_id}`,children:"view subagent transcript →"}),s.workflow_run_id&&e.jsxs(y,{className:"subagent-link small",to:`/workflow/${s.workflow_run_id}`,children:["🔀 launched ",s.workflow_agent_count??0," agent",s.workflow_agent_count===1?"":"s"," · ",e.jsx("code",{children:s.workflow_run_id})," →"]}),s.skill_name&&e.jsxs(y,{className:"subagent-link small",to:`/skill/${encodeURIComponent(s.skill_name)}${s.skill_id?`?v=${s.skill_id}`:""}`,children:["📖 view skill",s.skill_id?" version":""," →"]}),n&&e.jsxs("div",{className:"tool-body",id:i,children:[s.input_json&&s.input_json!=="{}"&&e.jsxs("div",{className:"code-block",children:[e.jsx(S,{text:v(s.input_json),className:"copy-corner",title:"Copy tool input JSON"}),e.jsx("pre",{className:"code",children:v(s.input_json)})]}),s.result_summary&&e.jsx("div",{className:"result",children:s.result_summary}),s.full_result&&e.jsxs("div",{className:"full-result",children:[e.jsxs("button",{type:"button",className:"ghost small show-full","aria-expanded":a,onClick:()=>l(o=>!o),children:[a?"Hide":"Show"," full result (",(s.full_result.bytes/1024).toFixed(1)," KB)"]}),a&&e.jsxs("div",{className:"code-block",children:[e.jsx(S,{text:s.full_result.text,className:"copy-corner",title:"Copy full tool result"}),e.jsx("pre",{className:"code",children:s.full_result.text})]})]})]})]})}function be({plan:s}){return e.jsxs("div",{className:"plan-card",children:[e.jsx("div",{className:"plan-card-head",children:"📋 Approved plan"}),e.jsx(js,{text:s})]})}function ke({t:s}){const[n,t]=d.useState(!1),a=d.useId(),l=he(s.input_json),{answers:i,annotations:r}=pe(s.result_summary);return l.length===0?e.jsx(gs,{t:s}):e.jsxs("div",{className:"qa-card",children:[e.jsxs("div",{className:"qa-card-head",children:["🙋 Question",l.length===1?"":"s"," for the user"]}),l.map((o,c)=>{var w;const u=i[o.question],h=Array.isArray(u)?u:u!=null?[u]:[],f=new Set(h),x=new Set(o.options.map(j=>j.label)),g=h.filter(j=>!x.has(j)),m=(w=r[o.question])==null?void 0:w.notes;return e.jsxs("div",{className:"qa-q",children:[e.jsxs("div",{className:"qa-q-head",children:[o.header&&e.jsx("span",{className:"tag",children:o.header}),o.multiSelect&&e.jsx("span",{className:"muted small",children:"multi-select"})]}),e.jsx("div",{className:"qa-question",children:o.question}),e.jsxs("ul",{className:"qa-options",children:[o.options.map((j,N)=>{const b=f.has(j.label);return e.jsxs("li",{className:"qa-opt"+(b?" is-selected":""),children:[e.jsx("span",{className:"qa-mark","aria-hidden":"true",children:b?"☑":"☐"}),e.jsxs("span",{className:"qa-opt-body",children:[e.jsx("span",{className:"qa-opt-label",children:j.label}),j.description&&e.jsx("span",{className:"qa-opt-desc muted",children:j.description})]})]},N)}),g.map((j,N)=>e.jsxs("li",{className:"qa-opt is-selected",children:[e.jsx("span",{className:"qa-mark","aria-hidden":"true",children:"☑"}),e.jsxs("span",{className:"qa-opt-body",children:[e.jsx("span",{className:"qa-opt-label",children:j}),e.jsx("span",{className:"qa-opt-desc muted",children:"custom answer"})]})]},"c"+N))]}),m&&e.jsxs("div",{className:"qa-note",children:["📝 ",m]})]},c)}),e.jsxs("div",{className:"launch-actions",children:[e.jsx("button",{className:"ghost small","aria-expanded":n,"aria-controls":a,onClick:()=>t(o=>!o),children:n?"Hide raw JSON ▴":"View raw JSON ▾"}),e.jsx(S,{text:v(s.input_json??"{}")+(s.result_summary?`
8
-
9
- `+v(s.result_summary):""),label:"JSON",title:"Copy raw question JSON"})]}),n&&e.jsxs("pre",{id:a,className:"code",children:[v(s.input_json??"{}"),s.result_summary?`
10
-
11
- `+v(s.result_summary):""]})]})}function ye({t:s}){const n=s.workflow_name?`Workflow · ${s.workflow_name}`:"Workflow";return e.jsxs("div",{className:"tool launch-tool",children:[e.jsxs("div",{className:"launch-tool-head",children:[e.jsxs("span",{className:"tool-name",children:["🔀 ",n]}),s.status&&e.jsx("span",{className:"tool-status",children:s.status})]}),s.workflow_run_id&&e.jsxs(y,{className:"subagent-link small",to:`/workflow/${s.workflow_run_id}`,children:["🔀 launched ",s.workflow_agent_count??0," agent",s.workflow_agent_count===1?"":"s"," · ",e.jsx("code",{children:s.workflow_run_id})," →"]}),s.result_summary&&e.jsx("div",{className:"result",children:s.result_summary})]})}function ns(s,n,t){let a=n+2,l=!1;for(s[a]==="-"&&(l=!0,a++);s[a]===" "||s[a]===" ";)a++;let i="";(s[a]==="'"||s[a]==='"')&&(i=s[a],a++);let r="";if(i){for(;a<s.length&&s[a]!==i;)r+=s[a++];s[a]===i&&a++}else for(;a<s.length&&/[A-Za-z0-9_]/.test(s[a]);)r+=s[a++];return r&&t.push({delim:r,strip:l}),a-1}function ve(s){const n=s.split(`
12
- `),t=[];let a="NORMAL",l=0;const i=[];let r=!1;for(const o of n){if(i.length>0){t.push({text:o,cont:!0});const c=i[0];(c.strip?o.replace(/^\t+/,""):o).trimEnd()===c.delim&&i.shift();continue}t.push({text:o,cont:a!=="NORMAL"||l>0||r}),r=!1;for(let c=0;c<o.length;c++){const u=o[c];if(a==="SQUOTE"){u==="'"&&(a="NORMAL");continue}if(a==="DQUOTE"){u==="\\"?c++:u==='"'?a="NORMAL":u==="$"&&o[c+1]==="("?(l++,c++):u===")"?l>0&&l--:u==="<"&&o[c+1]==="<"&&o[c+2]!=="<"&&o[c-1]!=="<"&&(c=ns(o,c,i));continue}if(u==="\\")c++;else if(u==="'")a="SQUOTE";else if(u==='"')a="DQUOTE";else{if(u==="#"&&(c===0||/\s/.test(o[c-1])))break;u==="$"&&o[c+1]==="("?(l++,c++):u==="("?l++:u===")"?l>0&&l--:u==="<"&&o[c+1]==="<"&&o[c+2]!=="<"&&o[c-1]!=="<"&&(c=ns(o,c,i))}}if(a==="NORMAL"&&l===0&&i.length===0){const c=o.replace(/\s+$/,""),u=c.match(/\\+$/);(u&&u[0].length%2===1||/(&&|\|\||\|)$/.test(c))&&(r=!0)}}return t}function Se({t:s,bash:n}){const[t,a]=d.useState(!1),[l,i]=d.useState(!1),[r,o]=d.useState(!1),c=d.useId(),u=d.useId(),h=n.command.split(`
13
- `)[0],f=ve(n.command);return e.jsxs("div",{className:"tool "+(s.status==="error"?"tool-err":""),children:[e.jsxs("button",{className:"tool-head","aria-expanded":t,"aria-controls":c,onClick:()=>a(x=>!x),children:[e.jsx("span",{className:"tool-name",children:"🖥 Bash"}),n.description?e.jsxs("span",{className:"bash-desc",children:["# ",n.description]}):!t&&e.jsx("span",{className:"bash-preview",children:h}),s.status&&e.jsx("span",{className:"tool-status",children:s.status}),s.total_duration_ms?e.jsx("span",{className:"muted",children:T(s.total_duration_ms)}):null,e.jsx("span",{className:"chev",children:t?"▾":"▸"})]}),t&&e.jsxs("div",{className:"tool-body",id:c,children:[e.jsxs("div",{className:"shell code-block",children:[e.jsx(S,{text:n.command,className:"copy-corner",title:"Copy command"}),e.jsx("pre",{className:"shell-cmd",children:f.map((x,g)=>e.jsxs("span",{children:[e.jsx("span",{className:"shell-gutter"+(x.cont?" cont":""),"aria-hidden":"true",children:x.cont?" ":"$ "}),x.text,g<f.length-1?`
14
- `:""]},g))})]}),(n.run_in_background||n.restart||n.timeout!=null)&&e.jsxs("div",{className:"bash-badges",children:[n.run_in_background&&e.jsx("span",{className:"bash-badge",children:"background"}),n.restart&&e.jsx("span",{className:"bash-badge",children:"restart"}),n.timeout!=null&&e.jsxs("span",{className:"bash-badge",children:["timeout ",Math.round(n.timeout/1e3),"s"]})]}),s.result_summary&&e.jsx("pre",{className:"shell-out",children:s.result_summary}),s.full_result&&e.jsxs("div",{className:"full-result",children:[e.jsxs("button",{type:"button",className:"ghost small show-full","aria-expanded":l,onClick:()=>i(x=>!x),children:[l?"Hide":"Show"," full result (",(s.full_result.bytes/1024).toFixed(1)," KB)"]}),l&&e.jsxs("div",{className:"code-block",children:[e.jsx(S,{text:s.full_result.text,className:"copy-corner",title:"Copy full tool result"}),e.jsx("pre",{className:"code",children:s.full_result.text})]})]}),e.jsxs("div",{className:"launch-actions",children:[e.jsx("button",{className:"ghost small","aria-expanded":r,"aria-controls":u,onClick:()=>o(x=>!x),children:r?"Hide raw JSON ▴":"View raw JSON ▾"}),e.jsx(S,{text:v(s.input_json??"{}"),label:"JSON",title:"Copy raw tool input JSON"})]}),r&&e.jsx("pre",{id:u,className:"code",children:v(s.input_json??"{}")})]})]})}const Ce={Edit:"✏️",MultiEdit:"✏️",Write:"📄"},B=400;function Te({t:s,edit:n}){const[t,a]=d.useState(!1),[l,i]=d.useState(!1),[r,o]=d.useState(!1),c=d.useId(),u=d.useId(),{dir:h,base:f}=je(n.file_path);return e.jsxs("div",{className:"tool "+(s.status==="error"?"tool-err":""),children:[e.jsxs("button",{className:"tool-head","aria-expanded":t,"aria-controls":c,onClick:()=>a(x=>!x),children:[e.jsxs("span",{className:"tool-name",children:[Ce[n.kind]??"✏️"," ",n.kind]}),e.jsxs("span",{className:"edit-path",children:[e.jsx("span",{className:"base",children:f}),h&&e.jsx("span",{className:"dir",children:h.replace(/\/$/,"")})]}),e.jsxs("span",{className:"diff-stat",children:[n.adds>0&&e.jsxs("span",{className:"add",children:["+",n.adds]}),n.dels>0&&e.jsxs("span",{className:"del",children:["−",n.dels]})]}),s.status&&e.jsx("span",{className:"tool-status",children:s.status}),s.total_duration_ms?e.jsx("span",{className:"muted",children:T(s.total_duration_ms)}):null,e.jsx("span",{className:"chev",children:t?"▾":"▸"})]}),t&&e.jsxs("div",{className:"tool-body",id:c,children:[n.hunks.map((x,g)=>e.jsxs("div",{className:"diff",children:[n.hunks.length>1&&e.jsxs("div",{className:"diff-hunk-sep",children:["edit ",g+1]}),x.slice(0,B).map((m,w)=>e.jsxs("div",{className:"diff-line "+m.type,children:[e.jsx("span",{className:"diff-sign","aria-hidden":"true",children:m.type==="add"?"+":m.type==="del"?"−":" "}),e.jsx("span",{className:"diff-text",children:m.text===""?" ":m.text})]},w)),x.length>B&&e.jsxs("div",{className:"diff-more",children:["… ",x.length-B," more lines — View raw JSON for the rest"]})]},g)),s.result_summary&&e.jsx("pre",{className:"shell-out",children:s.result_summary}),s.full_result&&e.jsxs("div",{className:"full-result",children:[e.jsxs("button",{type:"button",className:"ghost small show-full","aria-expanded":l,onClick:()=>i(x=>!x),children:[l?"Hide":"Show"," full result (",(s.full_result.bytes/1024).toFixed(1)," KB)"]}),l&&e.jsxs("div",{className:"code-block",children:[e.jsx(S,{text:s.full_result.text,className:"copy-corner",title:"Copy full tool result"}),e.jsx("pre",{className:"code",children:s.full_result.text})]})]}),e.jsxs("div",{className:"launch-actions",children:[e.jsx("button",{className:"ghost small","aria-expanded":r,"aria-controls":u,onClick:()=>o(x=>!x),children:r?"Hide raw JSON ▴":"View raw JSON ▾"}),e.jsx(S,{text:v(s.input_json??"{}"),label:"JSON",title:"Copy raw tool input JSON"})]}),r&&e.jsx("pre",{id:u,className:"code",children:v(s.input_json??"{}")})]})]})}function Ie({t:s,hideTools:n}){const t=s.findings??[],a=n&&t.length===0,l=Ee(s,a);return t.length===0?l:e.jsxs(e.Fragment,{children:[l,e.jsx(Xs,{findings:t})]})}function Ee(s,n){if(s.tool_name==="ExitPlanMode"){const t=ds(s.input_json);if(t)return e.jsx(be,{plan:t})}if(s.tool_name==="AskUserQuestion")return e.jsx(ke,{t:s});if(s.tool_name==="Workflow")return e.jsx(ye,{t:s});if(s.tool_name==="Bash"){const t=xe(s.input_json);if(t)return n?null:e.jsx(Se,{t:s,bash:t})}if(s.tool_name==="Edit"||s.tool_name==="MultiEdit"||s.tool_name==="Write"){const t=fe(s.tool_name,s.input_json);if(t)return n?null:e.jsx(Te,{t:s,edit:t})}return n?null:e.jsx(gs,{t:s})}function Oe(s,n){return s.findings&&s.findings.length||s.tool_name==="AskUserQuestion"||s.tool_name==="Workflow"||s.tool_name==="ExitPlanMode"&&ds(s.input_json)?!0:!n}function Ns({e:s}){const[n,t]=d.useState(!1),a=d.useId(),l=d.useContext(xs),i=d.useContext(fs),r=d.useContext(D),o=n||r.activeUuid===s.uuid&&U(s.thinking,r.query),c=s.role||s.type,u=c==="user"?"👤":c==="assistant"?"🤖":"⚙️",h=j=>r.activeUuid===s.uuid&&oe(j,r.query),f=s.toolCalls.filter(j=>Oe(j,l)||h(j));if(!(s.text||s.thinking||f.length))return null;const g=s.text?us(s.text):null,m=s.text&&!g?ms(s.text):null,w=s.text||s.thinking||"";return e.jsxs("div",{id:"ev-"+s.uuid,className:"event ev-"+c+(i===s.uuid?" ev-flagged":""),children:[e.jsxs("div",{className:"ev-meta",children:[e.jsxs("span",{className:"ev-who",children:[u," ",c]}),s.model&&e.jsx("span",{className:"tag",children:qs(s.model)}),s.is_sidechain?e.jsx("span",{className:"tag subagent",children:"subagent"}):null,e.jsx("span",{className:"muted ev-time",children:ts(s.timestamp)}),w&&e.jsx(S,{text:w,className:"ev-copy copy-hover",title:"Copy message"})]}),s.thinking&&e.jsxs("div",{className:"thinking",children:[e.jsxs("button",{className:"thinking-toggle","aria-expanded":o,"aria-controls":a,onClick:()=>t(!o),children:["🧠 thinking ",o?"▾":"▸"]}),o&&e.jsxs("div",{className:"code-block",children:[e.jsx(S,{text:s.thinking,className:"copy-corner",title:"Copy thinking"}),e.jsx("pre",{id:a,className:"thinking-body",children:s.thinking})]})]}),s.text&&(g?e.jsx(Ne,{cmd:g}):m?e.jsx(we,{n:m}):e.jsx(js,{text:s.text,uuid:s.uuid})),f.map((j,N)=>e.jsx(Ie,{t:j,hideTools:l&&!h(j)},N))]})}function Me({turn:s,events:n,matches:t=0,open:a,onToggle:l}){const i=d.useId();return e.jsxs("section",{className:"turn"+(a?" is-open":""),children:[e.jsxs("button",{className:"turn-head","aria-expanded":a,"aria-controls":i,onClick:l,children:[e.jsx("span",{className:"chev turn-chev","aria-hidden":"true",children:a?"▾":"▸"}),e.jsxs("span",{className:"turn-no",children:["turn ",s.seq+1]}),s.prompt_preview?e.jsx("span",{className:"turn-preview",children:ge(s.prompt_preview)}):null,t>0&&e.jsx("span",{className:"turn-matches",title:`${t} message${t===1?"":"s"} match the search`,children:t}),e.jsxs("span",{className:"turn-stats muted",children:[n.length," msg",n.length===1?"":"s",s.duration_ms?" · "+T(s.duration_ms):""]})]}),e.jsx("div",{id:i,className:"turn-body",role:"region","aria-label":`turn ${s.seq+1} messages`,children:a&&n.map(r=>e.jsx(Ns,{e:r},r.uuid))})]})}function Fe(s,n){const t=new Map(n.map(l=>[l.id,l])),a=[];for(const l of s){const i=l.turn_id??null,r=a[a.length-1];r&&r.turnId===i?r.events.push(l):a.push({turnId:i,turn:i?t.get(i)??null:null,events:[l]})}return a}function $e(s){const{data:n,error:t}=As("/sessions/"+s,{reset:!0}),a=d.useMemo(()=>{const l=new Map;for(const i of(n==null?void 0:n.events)??[])for(const r of i.toolCalls)r.tool_name==="Workflow"&&r.id&&r.workflow_run_id&&l.set(r.id,r.workflow_run_id);return l},[n]);return{d:n,error:t,wfMap:a}}const P="al-search";function Re(s,n){d.useEffect(()=>{const t=s.current,a=CSS==null?void 0:CSS.highlights,l=globalThis.Highlight;if(!t||!a||!l)return;const i=n.trim().toLowerCase();let r=0;const o=()=>{var f;if(r=0,a.delete(P),i.length<M)return;const u=[],h=document.createTreeWalker(t,NodeFilter.SHOW_TEXT);for(let x=h.nextNode();x;x=h.nextNode()){const g=(f=x.nodeValue)==null?void 0:f.toLowerCase();if(g)for(let m=g.indexOf(i);m!==-1;m=g.indexOf(i,m+i.length)){const w=new Range;w.setStart(x,m),w.setEnd(x,m+i.length),u.push(w)}}u.length&&a.set(P,new l(...u))};o();const c=new MutationObserver(()=>{r||(r=requestAnimationFrame(o))});return c.observe(t,{childList:!0,subtree:!0,characterData:!0}),()=>{c.disconnect(),r&&cancelAnimationFrame(r),a.delete(P)}},[s,n])}function qe(s,n,t,a,l){const[i,r]=d.useState(null);d.useEffect(()=>{var u;const c=n?(u=s==null?void 0:s.find(h=>h.uuid===n))==null?void 0:u.turn_id:null;c&&l(h=>{if(!h.has(c))return h;const f=new Set(h);return f.delete(c),f})},[s,n,t,l]);const o=d.useRef(null);return d.useEffect(()=>{if(!s||!n||!t){o.current=null;return}if(o.current===t)return;const c=document.getElementById("ev-"+n);if(!c)return;o.current=t,c.scrollIntoView({block:"center",behavior:"smooth"}),r(n);const u=window.setTimeout(()=>r(null),3e3);return()=>window.clearTimeout(u)},[s,n,t,a]),i}const H="msgFormat",J="hideTools";function ws(s){const n=Ls(s,null);if(n!=null)return n;try{return localStorage.getItem("agentlens."+s)}catch{return null}}const _s=s=>s==="raw"?"raw":"markdown",bs=s=>s===!0||s===1||s==="1";function Ae(){return _s(ws(H))}function Le(){return bs(ws(J))}function Be(s){as(H,s)}function Pe(s){as(J,s)}async function Ue(){const[s,n]=await Promise.all([G(H),G(J)]);return{...s!=null?{format:_s(s)}:{},...n!=null?{hideTools:bs(n)}:{}}}function Ke(){var z;const{id:s}=Bs(),{hash:n}=Ps(),{d:t,error:a,wfMap:l}=$e(s),[i,r]=d.useState(new Set),[o,c]=d.useState(Ae),[u,h]=d.useState(Le);d.useEffect(()=>r(new Set),[s]),d.useEffect(()=>{Ue().then(p=>{p.format!==void 0&&c(p.format),p.hideTools!==void 0&&h(p.hideTools)})},[]);const f=p=>{c(p),Be(p)},x=()=>h(p=>(Pe(!p),!p)),g=d.useMemo(()=>(t==null?void 0:t.events.filter(p=>p.text||p.thinking||p.toolCalls.length))??[],[t]),{get:m,set:w}=Us(),j=m("q"),N=d.useMemo(()=>le(g),[g]),b=d.useMemo(()=>ie(g,N,j),[g,N,j]),F=((z=/^#ev-(.+)$/.exec(n))==null?void 0:z[1])??null,[I,ks]=Js(n+`
15
- `+j,{idx:0,seq:0}),C=b.hits[I.idx]??null,ys=(C==null?void 0:C.uuid)??F,vs=C?`q:${j}:${I.idx}:${I.seq}`:n||null,Ss=qe(t==null?void 0:t.events,ys,vs,i,r),E=p=>{b.total&&ks(_=>({idx:(_.idx+p+b.total)%b.total,seq:_.seq+1}))},$=d.useRef({step:E,total:b.total});$.current={step:E,total:b.total};const W=d.useRef(null),K=d.useRef(null);Re(K,j),d.useEffect(()=>{const p=_=>{var Y;if(_.defaultPrevented||_.metaKey||_.ctrlKey||_.altKey)return;const k=_.target,Is=!!k&&(k.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(k.tagName));if(_.key==="/"&&!Is){_.preventDefault(),(Y=W.current)==null||Y.focus();return}const q=document.activeElement,Es=!q||q===document.body||q===document.documentElement;_.key==="Enter"&&Es&&$.current.total&&(_.preventDefault(),$.current.step(_.shiftKey?-1:1))};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[]);const Cs=d.useMemo(()=>({query:j,activeUuid:(C==null?void 0:C.uuid)??null}),[j,C]);if(a)return e.jsx(Ds,{error:a});if(!t)return e.jsx(Hs,{});const V=Fe(g,t.turns),R=V.filter(p=>p.turn).map(p=>p.turnId),Q=R.some(p=>!i.has(p)),Ts=p=>r(_=>{const k=new Set(_);return k.has(p)?k.delete(p):k.add(p),k});return e.jsxs("div",{className:"detail",children:[e.jsx(ne,{d:t}),t.children&&t.children.length>0&&e.jsx(me,{d:t}),e.jsx(te,{search:e.jsx(ue,{query:j,onQuery:p=>w({q:p}),total:b.total,index:I.idx,onPrev:()=>E(-1),onNext:()=>E(1),inputRef:W}),turnCount:R.length,anyOpen:Q,onToggleAll:()=>r(Q?new Set(R):new Set),hideTools:u,onToggleHideTools:x,format:o,onChooseFormat:f}),e.jsx(ps.Provider,{value:l,children:e.jsx(hs.Provider,{value:o,children:e.jsx(xs.Provider,{value:u,children:e.jsx(fs.Provider,{value:Ss,children:e.jsx(D.Provider,{value:Cs,children:e.jsxs("div",{className:"transcript",ref:K,children:[g.length===0&&e.jsx("div",{className:"muted pad",role:"status",children:"This session has no rendered messages."}),V.map((p,_)=>p.turn?e.jsx(Me,{turn:p.turn,events:p.events,matches:b.byTurn.get(p.turnId)??0,open:!i.has(p.turnId),onToggle:()=>Ts(p.turnId)},p.turnId):e.jsx("div",{className:"unturned",children:p.events.map(k=>e.jsx(Ns,{e:k},k.uuid))},"unturned-"+_))]})})})})})})]})}export{Ke as default};