@swestash/agent-lens 0.6.0 → 0.8.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/dist/agent-lens.js +535 -161
- package/dist/agent-lens.js.map +1 -1
- package/package.json +2 -2
- package/web/assets/{CopyButton-XWWtxa5T.js → CopyButton-CQA_09tY.js} +1 -1
- package/web/assets/Dashboard-CtAZNySe.js +69 -0
- package/web/assets/SecurityView-Dg0hnxA-.js +1 -0
- package/web/assets/SessionView-Ddk_CWjP.js +12 -0
- package/web/assets/{SkillView-BuWdX4As.js → SkillView-BfEFS2DU.js} +1 -1
- package/web/assets/{SkillsView-D8Wtsxi6.js → SkillsView-CG8HFyyk.js} +1 -1
- package/web/assets/{WorkflowView-Afsv_IWs.js → WorkflowView-B6_1UcYD.js} +1 -1
- package/web/assets/index-B9PbFrlb.js +68 -0
- package/web/assets/index-Dt08Kre7.css +1 -0
- package/web/assets/{index-T6SPgI6b.js → index-ksYuAXX3.js} +1 -1
- package/web/assets/{severity-DkldRG9Z.js → severity-CZIEtWx1.js} +1 -1
- package/web/index.html +2 -2
- package/web/assets/Dashboard-BQX66iZp.js +0 -69
- package/web/assets/SecurityView-C_CfNLoD.js +0 -1
- package/web/assets/SessionView-qPYTooYU.js +0 -12
- package/web/assets/index-BkDuOrzs.js +0 -68
- package/web/assets/index-CPyBa1Te.css +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as te,r as a,n as ie,d as N,p,j as e,F as ae,q as j,S as R,P as le,l as ne,L as re}from"./index-BkDuOrzs.js";import{S as ce,a as oe}from"./severity-DkldRG9Z.js";const E=50;function ge(){const[t,h]=te(),[i,l]=a.useState(null),[c,M]=a.useState({total:0,findings:[]}),[S,F]=a.useState([]),[H,V]=a.useState([]),[G,Q]=a.useState([]),[K,U]=a.useState(!0),[D,_]=a.useState(null),[f,I]=a.useState(!1),[w,q]=a.useState(1),[u,C]=a.useState(new Set),[T,J]=a.useState(0),{sort:r,toggle:P}=ie("severity","desc"),x=t.get("severity")??"",y=t.get("category")??"",b=t.get("rule")??"",L=t.get("session")??"",$=t.get("source")??"",A=t.get("project")??"",O=t.get("from")??"",W=t.get("to")??"",m=t.get("status")??"open",v=a.useMemo(()=>{const s=new URLSearchParams;for(const[n,d]of Object.entries({severity:x,category:y,rule:b,session:L,source:$,project:A,from:O,to:W,status:m}))d&&s.set(n,d);return s},[x,y,b,L,$,A,O,W,m]);a.useEffect(()=>{N("/sources").then(V).catch(()=>{}),N("/projects").then(Q).catch(()=>{})},[]),a.useEffect(()=>{N("/security/summary").then(l).catch(()=>{}),p||N("/security/mutes").then(F).catch(()=>{})},[T]),a.useEffect(()=>q(1),[v.toString(),r.key,r.dir]),a.useEffect(()=>C(new Set),[v.toString(),r.key,r.dir,w,T]),a.useEffect(()=>{U(!0),_(null);const s=new URLSearchParams(v);s.set("sort",r.key),s.set("dir",r.dir),s.set("limit",String(E)),s.set("offset",String((w-1)*E)),N("/security/findings?"+s.toString()).then(M).catch(n=>_(String(n))).finally(()=>U(!1))},[v,r.key,r.dir,w,T]);const o=a.useCallback(s=>{const n=new URLSearchParams(t);for(const[d,k]of Object.entries(s))k?n.set(d,k):n.delete(d);h(n)},[t,h]),g=a.useCallback(async s=>{I(!0),_(null);try{await s(),J(n=>n+1)}catch(n){_(String(n))}finally{I(!1)}},[]),X=a.useMemo(()=>new Map(((i==null?void 0:i.by_severity)??[]).map(s=>[s.severity,s.n])),[i]),B=a.useMemo(()=>((i==null?void 0:i.by_rule)??[]).filter(s=>!y||s.category===y),[i,y]),Y=Math.max(1,Math.ceil(c.total/E)),Z=[...v.keys()].some(s=>s!=="status")||m!=="open",z=c.findings.map(s=>s.id),ee=z.length>0&&z.every(s=>u.has(s)),se=s=>C(n=>{const d=new Set(n);return d.has(s)?d.delete(s):d.add(s),d});return e.jsxs("div",{children:[e.jsxs("div",{className:"detail-head",children:[e.jsx("h1",{children:"Security findings"}),e.jsxs("p",{className:"muted",style:{margin:"4px 0 0",maxWidth:760},children:["Risky operations the agent performed, flagged after the fact by deterministic rules over each tool call. Counts show ",e.jsx("strong",{children:"open"})," findings — mark benign ones safe or mute a noisy rule so a real one stands out. agent-lens is retrospective; it surfaces what ",e.jsx("em",{children:"happened"}),", it doesn't block."]})]}),p&&e.jsxs("div",{className:"demo-note",role:"note",children:["📦 This is a static demo over synthetic sessions. Browse the findings and reference below —"," ",e.jsx("strong",{children:"triage"})," (mark safe, mute rules) and live filtering run in the local app on your own data."]}),e.jsxs("div",{className:"kpi-row sev-kpis",role:"group","aria-label":"Open findings by severity",children:[e.jsxs("button",{type:"button",className:"kpi kpi-btn"+(x?"":" is-active"),onClick:()=>o({severity:""}),children:[e.jsx("div",{className:"kpi-label",children:"Open findings"}),e.jsx("div",{className:"kpi-value",children:(i==null?void 0:i.total)??"—"}),e.jsxs("div",{className:"kpi-sub",children:[(i==null?void 0:i.sessions_flagged)??0," sessions flagged"]})]}),ce.map(s=>e.jsxs("button",{type:"button",className:"kpi kpi-btn sev-kpi sev-"+s+(x===s?" is-active":""),onClick:()=>o({severity:x===s?"":s}),"aria-pressed":x===s,children:[e.jsx("div",{className:"kpi-label",children:s}),e.jsx("div",{className:"kpi-value",children:X.get(s)??0})]},s))]}),i&&(i.dismissed>0||i.muted>0)&&e.jsxs("div",{className:"triage-counts muted small",children:[e.jsxs("button",{type:"button",className:"linkish",onClick:()=>o({status:"dismissed",severity:""}),children:[i.dismissed," dismissed"]})," · ",e.jsxs("button",{type:"button",className:"linkish",onClick:()=>o({status:"muted",severity:""}),children:[i.muted," muted by rule"]})]}),e.jsxs("div",{className:"filters",children:[e.jsxs("select",{"aria-label":"Filter by status",value:m,onChange:s=>o({status:s.target.value}),children:[e.jsx("option",{value:"open",children:"open"}),e.jsx("option",{value:"dismissed",children:"dismissed"}),e.jsx("option",{value:"muted",children:"muted"}),e.jsx("option",{value:"all",children:"all"})]}),e.jsxs("select",{"aria-label":"Filter by category",value:y,onChange:s=>{const n=s.target.value,d=!b||B.some(k=>k.rule_id===b&&(!n||k.category===n));o({category:n,rule:d?b:""})},children:[e.jsx("option",{value:"",children:"all categories"}),((i==null?void 0:i.categories)??[]).map(s=>e.jsx("option",{value:s.key,children:s.title},s.key))]}),e.jsxs("select",{"aria-label":"Filter by rule",value:b,onChange:s=>o({rule:s.target.value}),children:[e.jsx("option",{value:"",children:"all rules"}),B.map(s=>e.jsxs("option",{value:s.rule_id,children:[s.rule_id," (",s.n,")"]},s.rule_id))]}),e.jsxs("select",{"aria-label":"Filter by source",value:$,onChange:s=>o({source:s.target.value}),children:[e.jsx("option",{value:"",children:"all sources"}),H.map(s=>e.jsx("option",{value:s.id,children:s.label},s.id))]}),e.jsx(ae,{ariaLabel:"Filter by project",searchPlaceholder:"Find project…",value:A,onChange:s=>o({project:s}),options:[{value:"",label:"all projects"},...G.map(s=>({value:s.id,label:s.path.replace(/^.*\//,"")}))]}),e.jsxs("label",{className:"ctl",children:["from ",e.jsx("input",{type:"date",value:O,onChange:s=>o({from:s.target.value})})]}),e.jsxs("label",{className:"ctl",children:["to ",e.jsx("input",{type:"date",value:W,onChange:s=>o({to:s.target.value})})]}),L&&e.jsxs("span",{className:"tag",style:{alignSelf:"center"},children:["session ",L.slice(0,8),"… ",e.jsx("button",{type:"button",className:"linkish",onClick:()=>o({session:""}),children:"✕"})]}),Z&&e.jsx("button",{type:"button",className:"ghost",onClick:()=>h(new URLSearchParams),children:"clear filters"})]}),!p&&(u.size>0||m==="open"&&c.total>0)&&e.jsxs("div",{className:"triage-bar",role:"group","aria-label":"Triage actions",children:[u.size>0&&m!=="dismissed"&&e.jsxs("button",{type:"button",disabled:f,onClick:()=>g(()=>j("/security/dismiss",{ids:[...u]})),children:["✓ Mark ",u.size," safe"]}),u.size>0&&m==="dismissed"&&e.jsxs("button",{type:"button",disabled:f,onClick:()=>g(()=>j("/security/reopen",{ids:[...u]})),children:["↩ Reopen ",u.size]}),u.size>0&&e.jsx("button",{type:"button",className:"ghost",onClick:()=>C(new Set),children:"clear selection"}),m==="open"&&c.total>0&&e.jsxs("button",{type:"button",className:"ghost",disabled:f,onClick:()=>{confirm(`Dismiss all ${c.total} open findings matching the current filter as safe?`)&&g(()=>j("/security/dismiss-matching",{filter:Object.fromEntries(v)}))},title:"Mark every open finding matching the current filter as safe",children:["Dismiss all ",c.total," matching"]})]}),D&&e.jsx("div",{className:"error",role:"alert",children:D}),K?e.jsx("div",{className:"muted pad",role:"status","aria-live":"polite",children:"Loading…"}):c.findings.length===0?e.jsx("div",{className:"muted pad",role:"status",children:i&&i.total===0&&m==="open"?"No open security findings — nothing risky is awaiting review.":"No findings match these filters."}):e.jsxs("table",{className:"sessions findings-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[!p&&e.jsx("th",{className:"check-col",children:e.jsx("input",{type:"checkbox","aria-label":"Select all on this page",checked:ee,onChange:s=>C(s.target.checked?new Set(z):new Set)})}),e.jsx(R,{label:"Severity",sortKey:"severity",active:r.key,dir:r.dir,onSort:P}),e.jsx("th",{children:"Finding"}),e.jsx(R,{label:"Category",sortKey:"category",active:r.key,dir:r.dir,onSort:P}),e.jsx("th",{children:"Evidence"}),e.jsx(R,{label:"When",sortKey:"time",active:r.key,dir:r.dir,onSort:P}),e.jsx(R,{label:"Session",sortKey:"session",active:r.key,dir:r.dir,onSort:P}),!p&&e.jsx("th",{children:"Actions"})]})}),e.jsx("tbody",{children:c.findings.map(s=>e.jsx(de,{f:s,selected:u.has(s.id),onToggle:()=>se(s.id),busy:f,onDismiss:()=>g(()=>j("/security/dismiss",{ids:[s.id]})),onReopen:()=>g(()=>j("/security/reopen",{ids:[s.id]})),onMute:()=>g(()=>j("/security/mute",{rule_id:s.rule_id,scope:"global"}))},s.id))})]}),!K&&c.total>E&&e.jsx(le,{page:w,pages:Y,total:c.total,unit:"findings",onPage:q}),!p&&S.length>0&&e.jsx(ue,{mutes:S,busy:f,onUnmute:s=>g(()=>j("/security/unmute",{rule_id:s.rule_id,scope:s.scope,scope_id:s.scope_id}))}),i&&i.categories.length>0&&e.jsx(he,{summary:i})]})}function de({f:t,selected:h,onToggle:i,busy:l,onDismiss:c,onReopen:M,onMute:S}){const F=`/session/${t.session_id}${t.event_uuid?`#ev-${t.event_uuid}`:""}`;return e.jsxs("tr",{className:t.dismissed?"is-dismissed":"",children:[!p&&e.jsx("td",{className:"check-col",children:e.jsx("input",{type:"checkbox","aria-label":"Select finding",checked:h,onChange:i})}),e.jsxs("td",{children:[e.jsx(oe,{severity:t.severity}),t.dismissed?e.jsx("span",{className:"tag",style:{marginLeft:4},title:t.dismiss_note??"",children:"safe"}):null]}),e.jsxs("td",{children:[e.jsx("div",{className:"finding-title",children:t.title??t.rule_id}),e.jsxs("div",{className:"muted small",children:[e.jsx("code",{children:t.rule_id}),t.framework_ref&&e.jsx("span",{className:"tag framework",style:{marginLeft:6},children:t.framework_ref})]})]}),e.jsx("td",{className:"small",children:t.category}),e.jsxs("td",{className:"finding-evidence-cell",children:[t.tool_name&&e.jsx("span",{className:"tag tool-tag",title:"Tool the finding fired on",children:t.tool_name}),e.jsx("code",{title:t.evidence??"",children:t.evidence})]}),e.jsx("td",{className:"small muted",title:t.started_at??"",children:ne(t.started_at??null)}),e.jsxs("td",{className:"small",children:[e.jsx(re,{to:F,className:"title",children:t.session_title||t.session_id.slice(0,12)}),t.is_sidechain?e.jsx("span",{className:"tag subagent",style:{marginLeft:6},children:"subagent"}):null,t.project_path&&e.jsx("div",{className:"muted path",children:t.project_path.replace(/^.*\//,"")})]}),!p&&e.jsxs("td",{className:"finding-actions small",children:[t.dismissed?e.jsx("button",{type:"button",className:"linkish",disabled:l,onClick:M,children:"reopen"}):e.jsx("button",{type:"button",className:"linkish",disabled:l,onClick:c,children:"safe"}),e.jsx("button",{type:"button",className:"linkish",disabled:l,onClick:S,title:`Mute rule ${t.rule_id} everywhere`,children:"mute rule"})]})]})}function ue({mutes:t,busy:h,onUnmute:i}){return e.jsxs("details",{className:"card muted-rules",children:[e.jsx("summary",{children:e.jsxs("span",{className:"sec-ref-title",children:["Muted rules (",t.length,")"]})}),e.jsx("ul",{className:"muted-rules-list",children:t.map(l=>e.jsxs("li",{children:[e.jsx("code",{children:l.rule_id}),e.jsxs("span",{className:"tag",style:{marginLeft:6},children:[l.scope,l.scope_id?`: ${l.scope_id}`:""]}),l.note&&e.jsx("span",{className:"muted small",style:{marginLeft:6},children:l.note}),e.jsx("button",{type:"button",className:"linkish",style:{marginLeft:8},disabled:h,onClick:()=>i(l),children:"unmute"})]},`${l.rule_id}:${l.scope}:${l.scope_id}`))})]})}function he({summary:t}){const h=new Map(t.by_category.map(i=>[i.category,i.n]));return e.jsxs("section",{className:"sec-reference",children:[e.jsx("h2",{children:"Risk categories"}),e.jsx("p",{className:"muted small",style:{marginTop:0},children:"What each category means and why it matters, anchored to OWASP Top 10 for Agentic Apps and MITRE ATLAS."}),e.jsx("div",{className:"sec-ref-grid",children:t.categories.map(i=>e.jsxs("details",{className:"card sec-ref",children:[e.jsxs("summary",{children:[e.jsx("span",{className:"sec-ref-title",children:i.title}),e.jsxs("a",{className:"tag framework",href:i.framework_url,target:"_blank",rel:"noreferrer",onClick:l=>l.stopPropagation(),children:[i.framework_ref," ↗"]}),e.jsxs("span",{className:"muted small",children:[h.get(i.key)??0," open"]})]}),e.jsxs("dl",{className:"sec-ref-body",children:[e.jsx("dt",{children:"What"}),e.jsx("dd",{children:i.what}),e.jsx("dt",{children:"Why it matters"}),e.jsx("dd",{children:i.why}),e.jsx("dt",{children:"What to do"}),e.jsx("dd",{children:i.remediation})]})]},i.key))})]})}export{ge as default};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import{i as cs,k as ds,r as m,d as us,j as s,L as y,h as H,t as ms,f as W,e as C,l as D,m as hs,s as Q}from"./index-BkDuOrzs.js";import{C as b,p as v}from"./CopyButton-XWWtxa5T.js";import{S as O,a as V}from"./severity-DkldRG9Z.js";import{M as ps,r as xs}from"./index-T6SPgI6b.js";const K=m.createContext("markdown"),Y=m.createContext(new Map),z=m.createContext(!1),G=m.createContext(null),X="agentlens.msgFormat";function fs(){try{return localStorage.getItem(X)==="raw"?"raw":"markdown"}catch{return"markdown"}}const Z="agentlens.hideTools";function js(){try{return localStorage.getItem(Z)==="1"}catch{return!1}}function gs({c:e}){var o;const[n,t]=m.useState(!1),l=m.useId(),a=(o=e.signals)==null?void 0:o.loc;return s.jsxs("div",{className:"classification",children:[s.jsx("span",{className:"tag cat cat-"+(e.category??"none"),children:e.category??"unclassified"}),e.complexity_band&&s.jsxs("span",{className:"tag complexity",children:[e.complexity_band," · ",e.complexity_score]}),a&&s.jsxs("span",{className:"muted small",children:["+",a.added,"/−",a.removed," LoC · ",a.files," files"]}),s.jsxs("button",{className:"ghost small","aria-expanded":n,"aria-controls":l,onClick:()=>t(i=>!i),children:["why ",n?"▾":"▸"]}),n&&(e.signals?s.jsx(ws,{id:l,s:e.signals,category:e.category}):s.jsx("div",{id:l,className:"muted small pad",children:"No signals recorded for this session."}))]})}const Ns={loc:"Lines changed",files:"Files touched",turns:"Turns",tokens:"Work tokens",duration:"Duration",subagents:"Subagents"},L=e=>`${Math.max(0,Math.min(1,e))*100}%`;function R({counts:e}){const n=Object.entries(e).sort((t,l)=>l[1]-t[1]);return n.length===0?s.jsx("span",{className:"muted",children:"—"}):s.jsx("span",{className:"sig-chips",children:n.map(([t,l])=>s.jsxs("span",{className:"sig-chip",children:[t," ",s.jsxs("span",{className:"muted",children:["×",l]})]},t))})}function ws({id:e,s:n,category:t}){const[l,a]=m.useState(!1),o=m.useId(),i=n.complexity_weights??{},r=n.complexity_subscores??{},c=Object.keys(i).map(d=>({key:d,weight:i[d],subscore:r[d]??0,pts:i[d]*(r[d]??0)*100})).sort((d,_)=>_.pts-d.pts),u=Math.max(...c.map(d=>d.pts),1e-4),p=Object.entries(n.category_scores??{}).map(([d,_])=>({k:d,v:_})).sort((d,_)=>_.v-d.v),j=Math.max(...p.map(d=>d.v),1e-4),x=p.filter(d=>d.v>.02||d.k===t),N=n.skills&&Object.keys(n.skills).length>0;return s.jsxs("div",{id:e,className:"signals-panel",children:[c.length>0&&s.jsxs("section",{className:"sig-section",children:[s.jsxs("h4",{className:"sig-h",children:["Complexity breakdown ",s.jsx("span",{className:"muted",children:"— what built the score"})]}),s.jsx("ul",{className:"sig-bars",children:c.map(d=>s.jsxs("li",{className:"sig-bar-row",children:[s.jsx("span",{className:"sig-bar-label",children:Ns[d.key]??d.key}),s.jsx("span",{className:"sig-bar","aria-hidden":"true",children:s.jsx("span",{className:"sig-bar-fill",style:{width:L(d.pts/u)}})}),s.jsxs("span",{className:"sig-bar-val",children:[d.pts.toFixed(1)," pts"]}),s.jsxs("span",{className:"sig-bar-sub muted",children:[Math.round(d.subscore*100),"% intensity · weight ",Math.round(d.weight*100),"%"]})]},d.key))})]}),x.length>0&&s.jsxs("section",{className:"sig-section",children:[s.jsxs("h4",{className:"sig-h",children:["Category scores ",s.jsxs("span",{className:"muted",children:["— why “",t,"” won"]})]}),s.jsx("ul",{className:"sig-bars",children:x.map(d=>s.jsxs("li",{className:"sig-bar-row"+(d.k===t?" is-win":""),children:[s.jsx("span",{className:"sig-bar-label",children:d.k}),s.jsx("span",{className:"sig-bar","aria-hidden":"true",children:s.jsx("span",{className:"sig-bar-fill",style:{width:L(d.v/j)}})}),s.jsx("span",{className:"sig-bar-val",children:d.v.toFixed(2)})]},d.k))})]}),s.jsxs("section",{className:"sig-section",children:[s.jsx("h4",{className:"sig-h",children:"Evidence"}),s.jsxs("dl",{className:"sig-grid",children:[n.tool_counts&&s.jsxs(s.Fragment,{children:[s.jsx("dt",{children:"Tools"}),s.jsx("dd",{children:s.jsx(R,{counts:n.tool_counts})})]}),N&&s.jsxs(s.Fragment,{children:[s.jsx("dt",{children:"Skills"}),s.jsx("dd",{children:s.jsx(R,{counts:n.skills})})]}),n.subagent_role&&s.jsxs(s.Fragment,{children:[s.jsx("dt",{children:"Subagent role"}),s.jsx("dd",{children:n.subagent_role})]}),n.files&&n.files.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs("dt",{children:["Files (",n.files.length,")"]}),s.jsx("dd",{className:"sig-files",children:n.files.join(", ")})]})]})]}),s.jsx("button",{className:"ghost small","aria-expanded":l,"aria-controls":o,onClick:()=>a(d=>!d),children:l?"Hide raw JSON ▴":"View raw JSON ▾"}),l&&s.jsx("pre",{id:o,className:"code signals",children:JSON.stringify(n,null,2)})]})}function _s({f:e}){var i;const[n,t]=m.useState(!1),l=m.useId(),a=((i=e.signals)==null?void 0:i.modifiers)??{},o=Object.keys(a).filter(r=>a[r]!==!1&&a[r]!=null&&a[r]!=="");return s.jsxs("div",{className:"finding sev-border-"+e.severity,children:[s.jsxs("button",{className:"finding-head","aria-expanded":n,"aria-controls":l,onClick:()=>t(r=>!r),children:[s.jsx(V,{severity:e.severity}),s.jsx("span",{className:"finding-title",children:e.title??e.rule_id}),e.framework_ref&&s.jsx("span",{className:"tag framework",children:e.framework_ref}),s.jsx("span",{className:"chev",children:n?"▾":"▸"})]}),n&&s.jsxs("div",{className:"finding-body",id:l,children:[e.evidence&&s.jsx("div",{className:"code-block",children:s.jsx("pre",{className:"code finding-evidence",children:e.evidence})}),s.jsxs("dl",{className:"sig-grid",children:[s.jsx("dt",{children:"Rule"}),s.jsx("dd",{children:s.jsx("code",{children:e.rule_id})}),s.jsx("dt",{children:"Category"}),s.jsx("dd",{children:e.category}),o.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("dt",{children:"Context"}),s.jsx("dd",{children:o.map(r=>s.jsxs("span",{className:"sig-chip",children:[r,a[r]!==!0?s.jsxs("span",{className:"muted",children:[" ",String(a[r])]}):null]},r))})]})]}),s.jsxs(y,{className:"subagent-link small",to:`/security?rule=${encodeURIComponent(e.rule_id)}`,children:["see all “",e.rule_id,"” findings →"]})]})]})}function ks({findings:e}){if(!e.length)return null;const n=[...e].sort((t,l)=>O.indexOf(t.severity)-O.indexOf(l.severity));return s.jsx("div",{className:"tool-findings",children:n.map(t=>s.jsx(_s,{f:t},t.id))})}function ys({findings:e,sessionId:n}){const t=new Map;for(const a of e)t.set(a.severity,(t.get(a.severity)??0)+1);const l=O.find(a=>t.has(a))??"info";return s.jsxs("div",{className:"security-banner sev-border-"+l,role:"status",children:[s.jsx("span",{className:"security-banner-icon","aria-hidden":"true",children:"🛡"}),s.jsxs("span",{className:"security-banner-text",children:[e.length," security ",e.length===1?"finding":"findings"," in this session"]}),s.jsx("span",{className:"security-banner-sevs",children:O.filter(a=>t.has(a)).map(a=>s.jsx(V,{severity:a,count:t.get(a)},a))}),s.jsx(y,{className:"subagent-link small",to:`/security?session=${encodeURIComponent(n)}`,children:"view on Security page →"})]})}function ss({t:e}){const[n,t]=m.useState(!1),[l,a]=m.useState(!1),o=m.useId(),i=e.skill_name?`Skill · ${e.skill_name}`:e.tool_name==="Workflow"&&e.workflow_name?`Workflow · ${e.workflow_name}`:e.agent_type?`${e.tool_name} → ${e.agent_type}`:e.tool_name;return s.jsxs("div",{className:"tool "+(e.status==="error"?"tool-err":""),children:[s.jsxs("button",{className:"tool-head","aria-expanded":n,"aria-controls":o,onClick:()=>t(r=>!r),children:[s.jsxs("span",{className:"tool-name",children:["🔧 ",i]}),e.status&&s.jsx("span",{className:"tool-status",children:e.status}),e.total_duration_ms?s.jsx("span",{className:"muted",children:C(e.total_duration_ms)}):null,s.jsx("span",{className:"chev",children:n?"▾":"▸"})]}),e.spawned_session_id&&s.jsx(y,{className:"subagent-link small",to:`/session/${e.spawned_session_id}`,children:"view subagent transcript →"}),e.workflow_run_id&&s.jsxs(y,{className:"subagent-link small",to:`/workflow/${e.workflow_run_id}`,children:["🔀 launched ",e.workflow_agent_count??0," agent",e.workflow_agent_count===1?"":"s"," · ",s.jsx("code",{children:e.workflow_run_id})," →"]}),e.skill_name&&s.jsxs(y,{className:"subagent-link small",to:`/skill/${encodeURIComponent(e.skill_name)}${e.skill_id?`?v=${e.skill_id}`:""}`,children:["📖 view skill",e.skill_id?" version":""," →"]}),n&&s.jsxs("div",{className:"tool-body",id:o,children:[e.input_json&&e.input_json!=="{}"&&s.jsxs("div",{className:"code-block",children:[s.jsx(b,{text:v(e.input_json),className:"copy-corner",title:"Copy tool input JSON"}),s.jsx("pre",{className:"code",children:v(e.input_json)})]}),e.result_summary&&s.jsx("div",{className:"result",children:e.result_summary}),e.full_result&&s.jsxs("div",{className:"full-result",children:[s.jsxs("button",{type:"button",className:"ghost small show-full","aria-expanded":l,onClick:()=>a(r=>!r),children:[l?"Hide":"Show"," full result (",(e.full_result.bytes/1024).toFixed(1)," KB)"]}),l&&s.jsxs("div",{className:"code-block",children:[s.jsx(b,{text:e.full_result.text,className:"copy-corner",title:"Copy full tool result"}),s.jsx("pre",{className:"code",children:e.full_result.text})]})]})]})]})}function es(e){if(!e)return null;try{const n=JSON.parse(e).plan;return typeof n=="string"&&n.trim()?n:null}catch{return null}}function vs({plan:e}){return s.jsxs("div",{className:"plan-card",children:[s.jsx("div",{className:"plan-card-head",children:"📋 Approved plan"}),s.jsx(as,{text:e})]})}function bs(e){if(!e)return[];try{const n=JSON.parse(e).questions;return Array.isArray(n)?n:[]}catch{return[]}}function Ss(e){if(!e)return{answers:{},annotations:{}};try{const n=JSON.parse(e);if(n&&typeof n=="object"&&n.answers)return{answers:n.answers,annotations:n.annotations??{}}}catch{}return{answers:{},annotations:{}}}function Cs({t:e}){const[n,t]=m.useState(!1),l=m.useId(),a=bs(e.input_json),{answers:o,annotations:i}=Ss(e.result_summary);return a.length===0?s.jsx(ss,{t:e}):s.jsxs("div",{className:"qa-card",children:[s.jsxs("div",{className:"qa-card-head",children:["🙋 Question",a.length===1?"":"s"," for the user"]}),a.map((r,c)=>{var _;const u=o[r.question],p=Array.isArray(u)?u:u!=null?[u]:[],j=new Set(p),x=new Set(r.options.map(w=>w.label)),N=p.filter(w=>!x.has(w)),d=(_=i[r.question])==null?void 0:_.notes;return s.jsxs("div",{className:"qa-q",children:[s.jsxs("div",{className:"qa-q-head",children:[r.header&&s.jsx("span",{className:"tag",children:r.header}),r.multiSelect&&s.jsx("span",{className:"muted small",children:"multi-select"})]}),s.jsx("div",{className:"qa-question",children:r.question}),s.jsxs("ul",{className:"qa-options",children:[r.options.map((w,S)=>{const f=j.has(w.label);return s.jsxs("li",{className:"qa-opt"+(f?" is-selected":""),children:[s.jsx("span",{className:"qa-mark","aria-hidden":"true",children:f?"☑":"☐"}),s.jsxs("span",{className:"qa-opt-body",children:[s.jsx("span",{className:"qa-opt-label",children:w.label}),w.description&&s.jsx("span",{className:"qa-opt-desc muted",children:w.description})]})]},S)}),N.map((w,S)=>s.jsxs("li",{className:"qa-opt is-selected",children:[s.jsx("span",{className:"qa-mark","aria-hidden":"true",children:"☑"}),s.jsxs("span",{className:"qa-opt-body",children:[s.jsx("span",{className:"qa-opt-label",children:w}),s.jsx("span",{className:"qa-opt-desc muted",children:"custom answer"})]})]},"c"+S))]}),d&&s.jsxs("div",{className:"qa-note",children:["📝 ",d]})]},c)}),s.jsxs("div",{className:"launch-actions",children:[s.jsx("button",{className:"ghost small","aria-expanded":n,"aria-controls":l,onClick:()=>t(r=>!r),children:n?"Hide raw JSON ▴":"View raw JSON ▾"}),s.jsx(b,{text:v(e.input_json??"{}")+(e.result_summary?`
|
|
2
|
-
|
|
3
|
-
`+v(e.result_summary):""),label:"JSON",title:"Copy raw question JSON"})]}),n&&s.jsxs("pre",{id:l,className:"code",children:[v(e.input_json??"{}"),e.result_summary?`
|
|
4
|
-
|
|
5
|
-
`+v(e.result_summary):""]})]})}function Is({t:e}){const n=e.workflow_name?`Workflow · ${e.workflow_name}`:"Workflow";return s.jsxs("div",{className:"tool launch-tool",children:[s.jsxs("div",{className:"launch-tool-head",children:[s.jsxs("span",{className:"tool-name",children:["🔀 ",n]}),e.status&&s.jsx("span",{className:"tool-status",children:e.status})]}),e.workflow_run_id&&s.jsxs(y,{className:"subagent-link small",to:`/workflow/${e.workflow_run_id}`,children:["🔀 launched ",e.workflow_agent_count??0," agent",e.workflow_agent_count===1?"":"s"," · ",s.jsx("code",{children:e.workflow_run_id})," →"]}),e.result_summary&&s.jsx("div",{className:"result",children:e.result_summary})]})}function Os(e){if(!e)return null;try{const n=JSON.parse(e);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 J(e,n,t){let l=n+2,a=!1;for(e[l]==="-"&&(a=!0,l++);e[l]===" "||e[l]===" ";)l++;let o="";(e[l]==="'"||e[l]==='"')&&(o=e[l],l++);let i="";if(o){for(;l<e.length&&e[l]!==o;)i+=e[l++];e[l]===o&&l++}else for(;l<e.length&&/[A-Za-z0-9_]/.test(e[l]);)i+=e[l++];return i&&t.push({delim:i,strip:a}),l-1}function Ts(e){const n=e.split(`
|
|
6
|
-
`),t=[];let l="NORMAL",a=0;const o=[];let i=!1;for(const r of n){if(o.length>0){t.push({text:r,cont:!0});const c=o[0];(c.strip?r.replace(/^\t+/,""):r).trimEnd()===c.delim&&o.shift();continue}t.push({text:r,cont:l!=="NORMAL"||a>0||i}),i=!1;for(let c=0;c<r.length;c++){const u=r[c];if(l==="SQUOTE"){u==="'"&&(l="NORMAL");continue}if(l==="DQUOTE"){u==="\\"?c++:u==='"'?l="NORMAL":u==="$"&&r[c+1]==="("?(a++,c++):u===")"?a>0&&a--:u==="<"&&r[c+1]==="<"&&r[c+2]!=="<"&&(c=J(r,c,o));continue}if(u==="\\")c++;else if(u==="'")l="SQUOTE";else if(u==='"')l="DQUOTE";else{if(u==="#"&&(c===0||/\s/.test(r[c-1])))break;u==="$"&&r[c+1]==="("?(a++,c++):u==="("?a++:u===")"?a>0&&a--:u==="<"&&r[c+1]==="<"&&r[c+2]!=="<"&&(c=J(r,c,o))}}if(l==="NORMAL"&&a===0&&o.length===0){const c=r.replace(/\s+$/,""),u=c.match(/\\+$/);(u&&u[0].length%2===1||/(&&|\|\||\|)$/.test(c))&&(i=!0)}}return t}function Es({t:e,bash:n}){const[t,l]=m.useState(!1),[a,o]=m.useState(!1),[i,r]=m.useState(!1),c=m.useId(),u=m.useId(),p=n.command.split(`
|
|
7
|
-
`)[0],j=Ts(n.command);return s.jsxs("div",{className:"tool "+(e.status==="error"?"tool-err":""),children:[s.jsxs("button",{className:"tool-head","aria-expanded":t,"aria-controls":c,onClick:()=>l(x=>!x),children:[s.jsx("span",{className:"tool-name",children:"🖥 Bash"}),n.description?s.jsxs("span",{className:"bash-desc",children:["# ",n.description]}):!t&&s.jsx("span",{className:"bash-preview",children:p}),e.status&&s.jsx("span",{className:"tool-status",children:e.status}),e.total_duration_ms?s.jsx("span",{className:"muted",children:C(e.total_duration_ms)}):null,s.jsx("span",{className:"chev",children:t?"▾":"▸"})]}),t&&s.jsxs("div",{className:"tool-body",id:c,children:[s.jsxs("div",{className:"shell code-block",children:[s.jsx(b,{text:n.command,className:"copy-corner",title:"Copy command"}),s.jsx("pre",{className:"shell-cmd",children:j.map((x,N)=>s.jsxs("span",{children:[s.jsx("span",{className:"shell-gutter"+(x.cont?" cont":""),"aria-hidden":"true",children:x.cont?" ":"$ "}),x.text,N<j.length-1?`
|
|
8
|
-
`:""]},N))})]}),(n.run_in_background||n.restart||n.timeout!=null)&&s.jsxs("div",{className:"bash-badges",children:[n.run_in_background&&s.jsx("span",{className:"bash-badge",children:"background"}),n.restart&&s.jsx("span",{className:"bash-badge",children:"restart"}),n.timeout!=null&&s.jsxs("span",{className:"bash-badge",children:["timeout ",Math.round(n.timeout/1e3),"s"]})]}),e.result_summary&&s.jsx("pre",{className:"shell-out",children:e.result_summary}),e.full_result&&s.jsxs("div",{className:"full-result",children:[s.jsxs("button",{type:"button",className:"ghost small show-full","aria-expanded":a,onClick:()=>o(x=>!x),children:[a?"Hide":"Show"," full result (",(e.full_result.bytes/1024).toFixed(1)," KB)"]}),a&&s.jsxs("div",{className:"code-block",children:[s.jsx(b,{text:e.full_result.text,className:"copy-corner",title:"Copy full tool result"}),s.jsx("pre",{className:"code",children:e.full_result.text})]})]}),s.jsxs("div",{className:"launch-actions",children:[s.jsx("button",{className:"ghost small","aria-expanded":i,"aria-controls":u,onClick:()=>r(x=>!x),children:i?"Hide raw JSON ▴":"View raw JSON ▾"}),s.jsx(b,{text:v(e.input_json??"{}"),label:"JSON",title:"Copy raw tool input JSON"})]}),i&&s.jsx("pre",{id:u,className:"code",children:v(e.input_json??"{}")})]})]})}function P(e,n){const t=e===""?[]:e.split(`
|
|
9
|
-
`),l=n===""?[]:n.split(`
|
|
10
|
-
`),a=t.length,o=l.length;if(a*o>25e4)return[...t.map(p=>({type:"del",text:p})),...l.map(p=>({type:"add",text:p}))];const i=Array.from({length:a+1},()=>new Array(o+1).fill(0));for(let p=a-1;p>=0;p--)for(let j=o-1;j>=0;j--)i[p][j]=t[p]===l[j]?i[p+1][j+1]+1:Math.max(i[p+1][j],i[p][j+1]);const r=[];let c=0,u=0;for(;c<a&&u<o;)t[c]===l[u]?(r.push({type:"ctx",text:t[c]}),c++,u++):i[c+1][u]>=i[c][u+1]?(r.push({type:"del",text:t[c]}),c++):(r.push({type:"add",text:l[u]}),u++);for(;c<a;)r.push({type:"del",text:t[c++]});for(;u<o;)r.push({type:"add",text:l[u++]});return r}function $s(e,n){if(!n)return null;try{const t=JSON.parse(n);if(!t||typeof t!="object"||typeof t.file_path!="string")return null;let l;if(e==="Write"){if(typeof t.content!="string")return null;l=[t.content===""?[]:t.content.split(`
|
|
11
|
-
`).map(i=>({type:"add",text:i}))]}else if(e==="MultiEdit"){if(!Array.isArray(t.edits)||(l=t.edits.filter(i=>{const r=i;return!!r&&typeof r.old_string=="string"&&typeof r.new_string=="string"}).map(i=>P(i.old_string,i.new_string)),l.length===0))return null}else{if(typeof t.old_string!="string"||typeof t.new_string!="string")return null;l=[P(t.old_string,t.new_string)]}let a=0,o=0;for(const i of l)for(const r of i)r.type==="add"?a++:r.type==="del"&&o++;return{file_path:t.file_path,kind:e,hunks:l,adds:a,dels:o}}catch{return null}}function Ms(e){const n=e.lastIndexOf("/");return n>=0?{dir:e.slice(0,n+1),base:e.slice(n+1)}:{dir:"",base:e}}const Fs={Edit:"✏️",MultiEdit:"✏️",Write:"📄"},E=400;function qs({t:e,edit:n}){const[t,l]=m.useState(!1),[a,o]=m.useState(!1),[i,r]=m.useState(!1),c=m.useId(),u=m.useId(),{dir:p,base:j}=Ms(n.file_path);return s.jsxs("div",{className:"tool "+(e.status==="error"?"tool-err":""),children:[s.jsxs("button",{className:"tool-head","aria-expanded":t,"aria-controls":c,onClick:()=>l(x=>!x),children:[s.jsxs("span",{className:"tool-name",children:[Fs[n.kind]??"✏️"," ",n.kind]}),s.jsxs("span",{className:"edit-path",children:[s.jsx("span",{className:"base",children:j}),p&&s.jsx("span",{className:"dir",children:p.replace(/\/$/,"")})]}),s.jsxs("span",{className:"diff-stat",children:[n.adds>0&&s.jsxs("span",{className:"add",children:["+",n.adds]}),n.dels>0&&s.jsxs("span",{className:"del",children:["−",n.dels]})]}),e.status&&s.jsx("span",{className:"tool-status",children:e.status}),e.total_duration_ms?s.jsx("span",{className:"muted",children:C(e.total_duration_ms)}):null,s.jsx("span",{className:"chev",children:t?"▾":"▸"})]}),t&&s.jsxs("div",{className:"tool-body",id:c,children:[n.hunks.map((x,N)=>s.jsxs("div",{className:"diff",children:[n.hunks.length>1&&s.jsxs("div",{className:"diff-hunk-sep",children:["edit ",N+1]}),x.slice(0,E).map((d,_)=>s.jsxs("div",{className:"diff-line "+d.type,children:[s.jsx("span",{className:"diff-sign","aria-hidden":"true",children:d.type==="add"?"+":d.type==="del"?"−":" "}),s.jsx("span",{className:"diff-text",children:d.text===""?" ":d.text})]},_)),x.length>E&&s.jsxs("div",{className:"diff-more",children:["… ",x.length-E," more lines — View raw JSON for the rest"]})]},N)),e.result_summary&&s.jsx("pre",{className:"shell-out",children:e.result_summary}),e.full_result&&s.jsxs("div",{className:"full-result",children:[s.jsxs("button",{type:"button",className:"ghost small show-full","aria-expanded":a,onClick:()=>o(x=>!x),children:[a?"Hide":"Show"," full result (",(e.full_result.bytes/1024).toFixed(1)," KB)"]}),a&&s.jsxs("div",{className:"code-block",children:[s.jsx(b,{text:e.full_result.text,className:"copy-corner",title:"Copy full tool result"}),s.jsx("pre",{className:"code",children:e.full_result.text})]})]}),s.jsxs("div",{className:"launch-actions",children:[s.jsx("button",{className:"ghost small","aria-expanded":i,"aria-controls":u,onClick:()=>r(x=>!x),children:i?"Hide raw JSON ▴":"View raw JSON ▾"}),s.jsx(b,{text:v(e.input_json??"{}"),label:"JSON",title:"Copy raw tool input JSON"})]}),i&&s.jsx("pre",{id:u,className:"code",children:v(e.input_json??"{}")})]})]})}function Bs({t:e,hideTools:n}){const t=e.findings??[],l=n&&t.length===0,a=As(e,l);return t.length===0?a:s.jsxs(s.Fragment,{children:[a,s.jsx(ks,{findings:t})]})}function As(e,n){if(e.tool_name==="ExitPlanMode"){const t=es(e.input_json);if(t)return s.jsx(vs,{plan:t})}if(e.tool_name==="AskUserQuestion")return s.jsx(Cs,{t:e});if(e.tool_name==="Workflow")return s.jsx(Is,{t:e});if(e.tool_name==="Bash"){const t=Os(e.input_json);if(t)return n?null:s.jsx(Es,{t:e,bash:t})}if(e.tool_name==="Edit"||e.tool_name==="MultiEdit"||e.tool_name==="Write"){const t=$s(e.tool_name,e.input_json);if(t)return n?null:s.jsx(qs,{t:e,edit:t})}return n?null:s.jsx(ss,{t:e})}function Ls(e,n){return e.findings&&e.findings.length||e.tool_name==="AskUserQuestion"||e.tool_name==="Workflow"||e.tool_name==="ExitPlanMode"&&es(e.input_json)?!0:!n}function ns(e){var l,a,o,i,r;const n=(a=(l=e.match(/<command-name>([^<]*)<\/command-name>/))==null?void 0:l[1])==null?void 0:a.trim();if(n){const c=((i=(o=e.match(/<command-args>([^<]*)<\/command-args>/))==null?void 0:o[1])==null?void 0:i.trim())??"";return{kind:"invocation",name:n.startsWith("/")?n:`/${n}`,args:c}}const t=(r=e.match(/<(?:local-command-stdout|command-output|local-command-stderr)>([\s\S]*?)<\/(?:local-command-stdout|command-output|local-command-stderr)>/))==null?void 0:r[1];return t!=null?{kind:"output",stdout:t.trim()}:/<local-command-caveat>/.test(e)?{kind:"caveat"}:null}function Rs({cmd:e}){return e.kind==="invocation"?s.jsxs("div",{className:"cmd",children:[s.jsxs("span",{className:"cmd-chip",title:"Slash command",children:["⌘ ",e.name]}),e.args&&s.jsx("code",{className:"cmd-args",children:e.args})]}):e.kind==="output"?s.jsx("div",{className:"cmd-out",children:e.stdout&&e.stdout!=="(no content)"?e.stdout:s.jsx("span",{className:"muted",children:"no output"})}):s.jsx("div",{className:"cmd-note muted small",children:"⌘ local command context"})}function ts(e){if(!/<task-notification>/.test(e))return null;const n=t=>{var l,a;return((a=(l=e.match(new RegExp(`<${t}>([\\s\\S]*?)</${t}>`)))==null?void 0:l[1])==null?void 0:a.trim())??null};return{taskId:n("task-id"),toolUseId:n("tool-use-id"),status:n("status"),summary:n("summary")}}function Js({n:e}){const n=m.useContext(Y),t=e.toolUseId?n.get(e.toolUseId):void 0,l=(e.status??"").toLowerCase();return s.jsxs("div",{className:"task-notif",children:[s.jsxs("div",{className:"task-notif-head",children:[s.jsx("span",{className:"task-notif-icon","aria-hidden":"true",children:"🔔"}),e.status&&s.jsx("span",{className:"tag task-status task-status-"+l,children:e.status}),e.taskId&&s.jsxs("code",{className:"task-notif-id",children:["task ",e.taskId]}),t&&s.jsx(y,{className:"subagent-link small",to:`/workflow/${t}`,children:"view workflow →"})]}),e.summary&&s.jsx("div",{className:"task-notif-summary",children:e.summary})]})}function U({text:e,id:n}){return m.useContext(K)==="raw"?s.jsx("div",{className:"text",id:n,children:e}):s.jsx("div",{className:"text md",id:n,children:s.jsx(ps,{remarkPlugins:[xs],components:Ps,children:e})})}const Ps={a:({node:e,...n})=>s.jsx("a",{...n,target:"_blank",rel:"noopener noreferrer"})};function as({text:e}){const n=e.length>1400||e.split(`
|
|
12
|
-
`).length>18,[t,l]=m.useState(!1),a=m.useId();return n?s.jsxs("div",{className:"text-wrap"+(t?"":" is-clamped"),children:[s.jsx(U,{text:e,id:a}),s.jsx("button",{className:"ghost small show-more","aria-expanded":t,"aria-controls":a,onClick:()=>l(o=>!o),children:t?"Show less ▴":"Show more ▾"})]}):s.jsx(U,{text:e})}function Us(e,n){const t=new Map(n.map(a=>[a.id,a])),l=[];for(const a of e){const o=a.turn_id??null,i=l[l.length-1];i&&i.turnId===o?i.events.push(a):l.push({turnId:o,turn:o?t.get(o)??null:null,events:[a]})}return l}function Hs(e){const n=ns(e);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=ts(e);return t?`🔔 task ${t.status??"notification"}`:e}function Ws({turn:e,events:n,open:t,onToggle:l}){const a=m.useId();return s.jsxs("section",{className:"turn"+(t?" is-open":""),children:[s.jsxs("button",{className:"turn-head","aria-expanded":t,"aria-controls":a,onClick:l,children:[s.jsx("span",{className:"chev turn-chev","aria-hidden":"true",children:t?"▾":"▸"}),s.jsxs("span",{className:"turn-no",children:["turn ",e.seq+1]}),e.prompt_preview?s.jsx("span",{className:"turn-preview",children:Hs(e.prompt_preview)}):null,s.jsxs("span",{className:"turn-stats muted",children:[n.length," msg",n.length===1?"":"s",e.duration_ms?" · "+C(e.duration_ms):""]})]}),s.jsx("div",{id:a,className:"turn-body",role:"region","aria-label":`turn ${e.seq+1} messages`,children:t&&n.map(o=>s.jsx(ls,{e:o},o.uuid))})]})}function ls({e}){const[n,t]=m.useState(!1),l=m.useId(),a=m.useContext(z),o=m.useContext(G),i=e.role||e.type,r=i==="user"?"👤":i==="assistant"?"🤖":"⚙️",c=e.toolCalls.filter(N=>Ls(N,a));if(!(e.text||e.thinking||c.length))return null;const p=e.text?ns(e.text):null,j=e.text&&!p?ts(e.text):null,x=e.text||e.thinking||"";return s.jsxs("div",{id:"ev-"+e.uuid,className:"event ev-"+i+(o===e.uuid?" ev-flagged":""),children:[s.jsxs("div",{className:"ev-meta",children:[s.jsxs("span",{className:"ev-who",children:[r," ",i]}),e.model&&s.jsx("span",{className:"tag",children:Q(e.model)}),e.is_sidechain?s.jsx("span",{className:"tag subagent",children:"subagent"}):null,s.jsx("span",{className:"muted ev-time",children:D(e.timestamp)}),x&&s.jsx(b,{text:x,className:"ev-copy copy-hover",title:"Copy message"})]}),e.thinking&&s.jsxs("div",{className:"thinking",children:[s.jsxs("button",{className:"thinking-toggle","aria-expanded":n,"aria-controls":l,onClick:()=>t(N=>!N),children:["🧠 thinking ",n?"▾":"▸"]}),n&&s.jsxs("div",{className:"code-block",children:[s.jsx(b,{text:e.thinking,className:"copy-corner",title:"Copy thinking"}),s.jsx("pre",{id:l,className:"thinking-body",children:e.thinking})]})]}),e.text&&(p?s.jsx(Rs,{cmd:p}):j?s.jsx(Js,{n:j}):s.jsx(as,{text:e.text})),c.map((N,d)=>s.jsx(Bs,{t:N,hideTools:a},d))]})}function $({c:e}){const n=e.agent_description||e.title||e.id.slice(0,12);return s.jsxs("li",{children:[s.jsx(y,{to:`/session/${e.id}`,children:n}),e.agent_type&&s.jsx("span",{className:"tag subagent meta-type",children:e.agent_type}),e.spawn_depth!=null&&e.spawn_depth>1&&s.jsxs("span",{className:"tag meta-depth",title:`nested ${e.spawn_depth} levels deep`,children:["↳",e.spawn_depth]}),s.jsxs("span",{className:"muted",children:[" ","· ",(e.models??"").split(",").filter(Boolean).map(Q).join(", ")," ·"," ",H(e.tokens)," tok · ",W(e.cost)]})]})}function Ds({d:e}){const n=e.workflow_runs??[],t=e.children.filter(a=>!a.workflow_run_id),l=n.length>0;return s.jsxs("div",{className:"subagents",children:[s.jsxs("h2",{children:["Spawned subagents (",e.children.length,")"]}),n.map(a=>{const o=e.children.filter(i=>i.workflow_run_id===a.run_id);return s.jsxs("details",{className:"wf-run",children:[s.jsxs("summary",{children:[s.jsxs(y,{className:"wf-run-name",to:`/workflow/${a.run_id}`,onClick:i=>i.stopPropagation(),children:["🔀 ",a.name||"workflow"," →"]}),a.status&&s.jsx("span",{className:"tag task-status task-status-"+a.status.toLowerCase(),children:a.status}),s.jsxs("span",{className:"muted small",children:[o.length," agent",o.length===1?"":"s",a.turn_seq!=null?` · turn ${a.turn_seq+1}`:""," · ",s.jsx("code",{children:a.run_id})]})]}),s.jsx("ul",{children:o.map(i=>s.jsx($,{c:i},i.id))})]},a.run_id)}),t.length>0&&(l?s.jsxs("details",{className:"wf-run",open:!0,children:[s.jsxs("summary",{children:[s.jsx("span",{className:"wf-run-name",children:"Task / Agent"}),s.jsxs("span",{className:"muted small",children:[t.length," subagent",t.length===1?"":"s"]})]}),s.jsx("ul",{children:t.map(a=>s.jsx($,{c:a},a.id))})]}):s.jsx("ul",{children:t.map(a=>s.jsx($,{c:a},a.id))}))]})}function zs(){const{id:e}=cs(),{hash:n}=ds(),[t,l]=m.useState(null),[a,o]=m.useState(null),[i,r]=m.useState(new Set),[c,u]=m.useState(fs),[p,j]=m.useState(js),x=h=>{u(h);try{localStorage.setItem(X,h)}catch{}},N=()=>j(h=>{const k=!h;try{localStorage.setItem(Z,k?"1":"0")}catch{}return k});m.useEffect(()=>{l(null),o(null),r(new Set),us("/sessions/"+e).then(l).catch(h=>o(String(h)))},[e]);const[d,_]=m.useState(null),w=m.useRef(null);m.useEffect(()=>{if(!t)return;const h=/^#ev-(.+)$/.exec(n);if(!h){w.current=null;return}if(w.current===n)return;const k=h[1],g=t.events.find(T=>T.uuid===k);if(g!=null&&g.turn_id&&i.has(g.turn_id)){const T=g.turn_id;r(os=>{const A=new Set(os);return A.delete(T),A});return}const B=document.getElementById("ev-"+k);if(!B)return;w.current=n,B.scrollIntoView({block:"center",behavior:"smooth"}),_(k);const is=window.setTimeout(()=>_(null),3e3);return()=>window.clearTimeout(is)},[t,n,i]);const S=m.useMemo(()=>{const h=new Map;for(const k of(t==null?void 0:t.events)??[])for(const g of k.toolCalls)g.tool_name==="Workflow"&&g.id&&g.workflow_run_id&&h.set(g.id,g.workflow_run_id);return h},[t]);if(a)return s.jsx("div",{className:"error",role:"alert",children:a});if(!t)return s.jsx("div",{className:"muted pad",role:"status","aria-live":"polite",children:"Loading…"});const f=t.session,M=t.events.filter(h=>h.text||h.thinking||h.toolCalls.length),F=Us(M,t.turns),I=F.filter(h=>h.turn).map(h=>h.turnId),q=I.some(h=>!i.has(h)),rs=h=>r(k=>{const g=new Set(k);return g.has(h)?g.delete(h):g.add(h),g});return s.jsxs("div",{className:"detail",children:[s.jsxs("div",{className:"detail-head",children:[s.jsx(y,{to:"/",className:"back",children:"← all sessions"}),s.jsx("h1",{children:f.title||f.id.slice(0,12)}),s.jsxs("div",{className:"detail-meta",children:[s.jsx("span",{children:s.jsx("b",{children:f.source_id})}),s.jsx("span",{className:"path",children:f.project_path}),f.is_sidechain?s.jsx("span",{className:"tag subagent",children:"subagent"}):null,t.parent&&s.jsxs("span",{className:"spawned-by",children:["↖ spawned by"," ",s.jsx(y,{to:`/session/${t.parent.id}`,children:t.parent.title||t.parent.id.slice(0,12)}),t.parent.turn_seq!=null?` · turn ${t.parent.turn_seq+1}`:""]}),s.jsxs("span",{children:[t.turns.length," turns"]}),s.jsxs("span",{children:[f.event_count," events"]}),s.jsxs("span",{title:ms(f.token_split),children:[H(f.tokens)," tok"]}),s.jsx("span",{title:"Estimated at API list prices (cache-aware)",children:W(f.cost)}),f.tool_call_count>0&&s.jsxs("span",{className:f.tool_failure_count>0?"tool-err-stat":"muted",title:"Tool calls that returned is_error, of "+f.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:[f.tool_failure_count," failed",f.tool_rejection_count>0?` · ${f.tool_rejection_count} declined/blocked`:"",` of ${f.tool_call_count} tool calls`]}),s.jsx("span",{children:C(f.duration_ms)}),s.jsx("span",{className:"muted",children:D(f.started_at)}),s.jsx("a",{className:"export",href:hs(f.id),children:"⬇ Export Markdown"})]}),t.classification&&s.jsx(gs,{c:t.classification}),t.findings&&t.findings.length>0&&s.jsx(ys,{findings:t.findings,sessionId:f.id})]}),t.children&&t.children.length>0&&s.jsx(Ds,{d:t}),s.jsxs("div",{className:"transcript-tools",children:[I.length>1&&s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"muted small",children:[I.length," turns"]}),s.jsx("button",{className:"ghost small",onClick:()=>r(q?new Set(I):new Set),children:q?"Collapse all":"Expand all"})]}),s.jsxs("button",{className:"ghost small"+(p?" is-active":""),"aria-pressed":p,onClick:N,title:"Hide Bash/Edit/Skill and other tool calls — show only assistant answers, plans and questions",children:[p?"☑ ":"☐ ","Hide tool messages"]}),s.jsxs("div",{className:"format-toggle",role:"group","aria-label":"Message format",children:[s.jsx("button",{className:"ghost small"+(c==="markdown"?" is-active":""),"aria-pressed":c==="markdown",onClick:()=>x("markdown"),children:"Markdown"}),s.jsx("button",{className:"ghost small"+(c==="raw"?" is-active":""),"aria-pressed":c==="raw",onClick:()=>x("raw"),children:"Raw"})]})]}),s.jsx(Y.Provider,{value:S,children:s.jsx(K.Provider,{value:c,children:s.jsx(z.Provider,{value:p,children:s.jsx(G.Provider,{value:d,children:s.jsxs("div",{className:"transcript",children:[M.length===0&&s.jsx("div",{className:"muted pad",role:"status",children:"This session has no rendered messages."}),F.map((h,k)=>h.turn?s.jsx(Ws,{turn:h.turn,events:h.events,open:!i.has(h.turnId),onToggle:()=>rs(h.turnId)},h.turnId):s.jsx("div",{className:"unturned",children:h.events.map(g=>s.jsx(ls,{e:g},g.uuid))},"unturned-"+k))]})})})})})]})}export{zs as default};
|