@raytrace-cli/cli 0.7.0 → 0.9.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.
@@ -28,11 +28,11 @@ Error generating stack: `+e.message+`
28
28
  `);return c.forEach((e,l)=>{if(/^Binary files .* differ$/.test(e)||e===`GIT binary patch`){t.binary=!0;return}let u=TT.exec(e);if(u){s(),n={header:e.trim(),rows:[]},t.hunks.push(n),r=Number(u[1]),i=Number(u[2]);return}if(!n)return;if(e.startsWith(`\\`)){s(),n.rows.push({oldNo:null,oldText:null,newNo:null,newText:null,note:e.slice(1).trim()});return}if(e.startsWith(`-`)){a.push({no:r,text:e.slice(1)}),r+=1,t.deletions+=1;return}if(e.startsWith(`+`)){o.push({no:i,text:e.slice(1)}),i+=1,t.additions+=1;return}if(e===``&&l===c.length-1)return;s();let d=e.startsWith(` `)?e.slice(1):e;n.rows.push({oldNo:r,oldText:d,newNo:i,newText:d}),r+=1,i+=1}),s(),t}var DT=e=>/^[0-9a-f]{40}$/.test(e)||e.startsWith(`refs/forks/`);async function OT(e,t,n,r){if(!DT(t)||!DT(n))throw Error(`This snapshot cannot be diffed.`);let i=new URLSearchParams({commit:t,to:n,...r?{path:r}:{}}),a=await x().fetch(`/raytace/snapshots/${e}/diff?${i}`),o=await a.json().catch(()=>({}));if(!a.ok)throw Error(CT(o.error??`HTTP ${a.status}`));return{diff:o.diff??``,truncated:!!o.truncated}}function kT(e,t){let n=URL.createObjectURL(new Blob([t],{type:`text/plain;charset=utf-8`})),r=document.createElement(`a`);r.href=n,r.download=e,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}var AT=e=>e.startsWith(`+`)&&!e.startsWith(`+++`)?`add`:e.startsWith(`-`)&&!e.startsWith(`---`)?`del`:e.startsWith(`@@`)?`hunk`:``,jT=`raytace.diff-view`;function MT(){let[e,t]=(0,_.useState)(`split`);return(0,_.useEffect)(()=>{try{localStorage.getItem(jT)===`unified`&&t(`unified`)}catch{}},[]),[e,e=>{t(e);try{localStorage.setItem(jT,e)}catch{}}]}function NT({diff:e}){let t=(0,_.useMemo)(()=>ET(e),[e]),[n,r]=MT();return t.binary?(0,K.jsx)(`p`,{className:`rt-files-note`,children:`A binary file: it changed, but there are no lines to show.`}):t.hunks.length?(0,K.jsxs)(`div`,{className:`rt-diff-wrap`,children:[(0,K.jsxs)(`div`,{className:`rt-diff-bar`,children:[(0,K.jsxs)(`span`,{children:[(0,K.jsxs)(`b`,{className:`rt-diff-add-n`,children:[`+`,t.additions]}),` `,(0,K.jsxs)(`b`,{className:`rt-diff-del-n`,children:[`−`,t.deletions]})]}),(0,K.jsxs)(`span`,{className:`rt-diff-mode`,children:[(0,K.jsx)(`button`,{type:`button`,"aria-pressed":n===`split`,className:n===`split`?`on`:``,onClick:()=>r(`split`),children:`Split`}),(0,K.jsx)(`button`,{type:`button`,"aria-pressed":n===`unified`,className:n===`unified`?`on`:``,onClick:()=>r(`unified`),children:`Unified`})]})]}),n===`unified`?(0,K.jsx)(`pre`,{className:`rt-diff`,children:e.split(`
29
29
  `).map((e,t)=>(0,K.jsxs)(`span`,{className:AT(e),children:[e,`
30
30
  `]},t))}):(0,K.jsx)(`div`,{className:`rt-diff-scroll`,children:(0,K.jsxs)(`table`,{className:`rt-diff-split`,children:[(0,K.jsxs)(`colgroup`,{children:[(0,K.jsx)(`col`,{className:`rt-diff-ln-col`}),(0,K.jsx)(`col`,{}),(0,K.jsx)(`col`,{className:`rt-diff-ln-col`}),(0,K.jsx)(`col`,{})]}),(0,K.jsx)(`tbody`,{children:t.hunks.map((e,t)=>(0,K.jsxs)(_.Fragment,{children:[(0,K.jsx)(`tr`,{className:`rt-diff-hunk`,children:(0,K.jsx)(`td`,{colSpan:4,children:e.header})}),e.rows.map((e,t)=>e.note?(0,K.jsx)(`tr`,{className:`rt-diff-note-row`,children:(0,K.jsx)(`td`,{colSpan:4,children:e.note})},t):(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`td`,{className:`rt-diff-ln${e.oldText!=null&&e.oldText!==e.newText?` del`:``}`,children:e.oldNo??``}),(0,K.jsx)(`td`,{className:`rt-diff-code${e.oldText==null?` empty`:e.oldText===e.newText?``:` del`}`,children:e.oldText??``}),(0,K.jsx)(`td`,{className:`rt-diff-ln${e.newText!=null&&e.oldText!==e.newText?` add`:``}`,children:e.newNo??``}),(0,K.jsx)(`td`,{className:`rt-diff-code${e.newText==null?` empty`:e.oldText===e.newText?``:` add`}`,children:e.newText??``})]},t))]},t))})]})})]}):(0,K.jsx)(`pre`,{className:`rt-diff`,children:e||`(no difference)`})}function PT({sandbox:e,from:t,to:n,path:r}){let[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(``);return(0,_.useEffect)(()=>{if(!e)return;let i=!1;return OT(e,t,n,r).then(e=>{i||a(e)}).catch(e=>{i||s(`Could not load the diff: ${e.message}`)}),()=>{i=!0}},[e,t,n,r]),e?o?(0,K.jsx)(`p`,{className:`rt-files-note`,children:o}):i?(0,K.jsxs)(K.Fragment,{children:[i.diff?(0,K.jsx)(NT,{diff:i.diff}):(0,K.jsx)(`pre`,{className:`rt-diff`,children:`(no difference)`}),i.truncated&&(0,K.jsx)(`p`,{className:`rt-files-note`,children:`This diff is larger than the 500 KB the snapshot view returns, so it is cut off here — and a patch downloaded from it would be incomplete.`})]}):(0,K.jsx)(`p`,{className:`rt-files-note`,children:`Loading diff…`}):(0,K.jsx)(`p`,{className:`rt-files-note`,children:`No sandbox holds this snapshot, so there is no diff to load.`})}function FT(e){let[t,n]=(0,_.useState)({}),r=(0,_.useRef)(!1),i=(0,_.useCallback)(async e=>{n(t=>({...t,[e]:{status:`loading`}}));try{let t=await x().fetch(`/raytace/summaries/${e}`),i=t.ok?await t.json():null;if(r.current)return;if(i?.summary?.text){n(t=>({...t,[e]:{status:`ready`,text:i.summary.text}}));return}}catch{}for(let t=0,i=0;!r.current&&t<8&&i<3;t+=1){try{let t=await x().fetch(`/raytace/summaries`,{method:`POST`,headers:{"content-type":`application/json`,"x-raytace-experiment":`1`},body:JSON.stringify({exchange_id:e})});if(t.status===409){await new Promise(e=>setTimeout(e,400));continue}let i=await t.json();if(r.current)return;if(t.ok&&i.text){n(t=>({...t,[e]:{status:`ready`,text:i.text}}));return}}catch{if(r.current)return}i+=1,await new Promise(e=>setTimeout(e,600*i))}r.current||n(t=>({...t,[e]:{status:`error`}}))},[]),a=(e.requests??[]).map(e=>e.id).join(`,`);return(0,_.useEffect)(()=>{r.current=!1;let e=a&&x().summaries?a.split(`,`):[],t=0;return Promise.all(Array.from({length:4},async()=>{for(;!r.current&&t<e.length;){let n=e[t];t+=1,await i(n)}})),()=>{r.current=!0}},[a,i]),t}function IT({snapshot:e,sandbox:t}){let n={A:`added`,M:`edited`,D:`deleted`,T:`type changed`},r=Xw(t),[i,a]=(0,_.useState)(null);return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`h4`,{children:[`Files changed `,(0,K.jsxs)(`span`,{className:`rt-snap-id`,title:`Snapshot of the project folder after this call`,children:[`snapshot `,e.commit.slice(0,8)]})]}),e.changes.length?(0,K.jsx)(`ul`,{className:`rt-files`,children:e.changes.map(o=>(0,K.jsxs)(_.Fragment,{children:[(0,K.jsxs)(`li`,{children:[(0,K.jsxs)(`button`,{type:`button`,className:`rt-file-toggle`,"aria-expanded":i===o.path,title:i===o.path?`Hide what changed in this file`:`Show what changed in this file`,onClick:()=>a(i===o.path?null:o.path),children:[(0,K.jsx)(B,{size:12,className:`rt-caret${i===o.path?` down`:``}`}),(0,K.jsx)(`span`,{className:`rt-file-status s-${o.status}`,children:n[o.status]??o.status}),(0,K.jsx)(`code`,{children:o.path})]}),(r.get(o.path)?.level??0)>=3&&(0,K.jsx)(yT,{level:r.get(o.path).level,title:`Level ${r.get(o.path).level} of 5 in the initial scan: ${r.get(o.path).reasons.join(`; `)||`set by its owner`}`}),r.get(o.path)?.restricted&&(0,K.jsx)(`span`,{className:`rt-flag`,title:`Its owner restricted this file: the agent was not meant to change it`,children:`restricted`}),(0,K.jsx)(`small`,{children:o.added==null?`binary`:`+${o.added} −${o.removed}`})]}),i===o.path&&(0,K.jsx)(`li`,{className:`rt-file-diff`,children:(0,K.jsx)(PT,{sandbox:t,from:e.parent??`4b825dc642cb6eb9a060e54bf8d69288fbee4904`,to:e.commit,path:o.path})})]},o.path))}):(0,K.jsx)(`p`,{className:`rt-files-note`,children:`No files changed.`}),e.too_big.length>0&&(0,K.jsxs)(`p`,{className:`rt-files-note`,children:[`Too big to keep (over 5 MB), so the snapshot has their earlier version: `,e.too_big.join(`, `)]})]})}function LT(e,t){let n=Uu(e,t);return n?JSON.stringify(n,null,2):``}var RT=`raytace.group-steps`;function zT(){let[e,t]=(0,_.useState)(!0);return(0,_.useEffect)(()=>{try{localStorage.getItem(RT)===`off`&&t(!1)}catch{}},[]),[e,e=>{t(e);try{localStorage.setItem(RT,e?`on`:`off`)}catch{}}]}function BT(e,t){let n=Uu(e,t),r=[n?.file_path,n?.notebook_path].find(e=>typeof e==`string`&&e);return typeof r==`string`?r:null}var VT=(e,t)=>Hu(e,t,Ne(e.events,t.call_id),BT(e,t));function HT({name:e,section:t}){return(0,K.jsxs)(`th`,{children:[e,(0,K.jsx)(`a`,{className:`rt-th-help`,href:`${Iu}#${t}`,target:`_blank`,rel:`noreferrer`,"aria-label":`What the ${e} labels mean (opens in a new tab)`,children:(0,K.jsx)(ae,{size:11})})]})}function UT({group:e,trace:t,open:n,onToggle:r}){let i=rd(e,t),a=e.calls.map(e=>VT(t,e)),o=a.map(e=>e.id),s=(...e)=>o.filter(t=>e.includes(t)).length,c=s(`ran`,`differs`),l=c+s(`not_seen`,`rejected`),u=s(`file_changed`),d=[c?`${c} of ${l} ran`:``,s(`differs`)?`⚠ ${s(`differs`)} differ${s(`differs`)===1?`s`:``}`:``,u?`${u} file${u===1?``:`s`} changed`:``,s(`no_change`)?`✗ ${s(`no_change`)} no change`:``].filter(Boolean).join(` · `)||(new Set(o).size===1?a[0].text:``),f=e.calls.map(e=>Du(e.ended_at)-Du(e.started_at)).filter(Number.isFinite);return(0,K.jsxs)(`tr`,{className:`rt-row rt-group-row${n?` open`:``}`,onClick:r,children:[(0,K.jsxs)(`td`,{className:`rt-num`,children:[(0,K.jsx)(B,{size:12,className:`rt-caret`}),i.range.slice(1)]}),(0,K.jsxs)(`td`,{className:`rt-tool`,children:[i.kind,(0,K.jsxs)(`small`,{className:`rt-changed`,children:[e.calls.length,` steps`]})]}),(0,K.jsxs)(`td`,{className:`rt-cmd rt-group-label`,children:[i.label,i.flags.map(e=>(0,K.jsx)(`span`,{className:`rt-group-flag`,children:e},e))]}),(0,K.jsx)(`td`,{className:`rt-reported`,children:i.outcome}),(0,K.jsx)(`td`,{children:d||`—`}),(0,K.jsx)(`td`,{className:`rt-time`,children:f.length?Ou(f.reduce((e,t)=>e+t,0)):`—`})]})}function WT({label:e,onOpen:t}){return!e.opens||!t?(0,K.jsx)(`span`,{className:`rt-ran ${e.tone}`,children:e.text}):(0,K.jsx)(`button`,{type:`button`,className:`rt-ran ${e.tone} rt-ran-link`,onClick:e=>{e.stopPropagation(),t()},children:e.text})}function GT({call:e}){let t=e.category?Lu[e.category]:null;return!t||t.toLowerCase()===e.name.toLowerCase()?(0,K.jsx)(K.Fragment,{children:e.name}):(0,K.jsxs)(K.Fragment,{children:[t,(0,K.jsxs)(`span`,{className:`rt-tool-name`,children:[` · `,e.name]})]})}function KT({trace:e,traces:t,focusCall:n,onOpenSandbox:r,onOpenContext:i,onOpenThought:a,onOpenPlayground:o}){let[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(n),[d,f]=(0,_.useState)(null);(0,_.useEffect)(()=>{if(!d)return;let e=requestAnimationFrame(()=>{document.getElementById(`files-${d}`)?.scrollIntoView({block:`nearest`,behavior:`smooth`}),f(null)});return()=>cancelAnimationFrame(e)},[d]);let p=FT(e),m=ke(e.events),h=e.callVerifications??[],[g,v]=zT(),[y,b]=(0,_.useState)(()=>new Set),x=g?td(e,h):[],S=new Map(x.filter(e=>e.calls.length>1).flatMap(e=>e.calls.map(t=>[t.call_id,e]))),C=e=>y.has(e.id)!==e.calls.some(e=>e.call_id===n),w=e=>b(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n}),T=e=>{let t=S.get(e.call_id);return!(!t||C(t))},E=new Map(h.map((e,t)=>[e.call_id,t+1])),D=Pe(e).forkable&&!!o,O=Pe(e).where===`sandbox`,k=(e.requests??[]).map(e=>e.id),A=e=>k[k.indexOf(e)+1],j=e.requests??[],M=[...new Set(j.map(e=>e.model))],N=[[`Round trips`,String(j.length)],[`Tool calls`,String(h.length)],[`Cost`,id(Ae(j,`cost`),j.some(e=>e.costEstimated))],[`Time`,ad(je(j))],[`Tokens in / out`,`${od(Ae(j,`input`))} / ${od(Ae(j,`output`))}`],[M.length>1?`Models`:`Model`,M.join(`, `)||e.model]];return(0,_.useEffect)(()=>{if(!n)return;let e=requestAnimationFrame(()=>document.getElementById(`call-${n}`)?.scrollIntoView({block:`center`,behavior:`smooth`}));return()=>cancelAnimationFrame(e)},[n]),(0,K.jsxs)(`section`,{className:`rt-view`,children:[(0,K.jsxs)(`header`,{className:`rt-view-head`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`eyebrow`,children:`TOOL CALLS`}),(0,K.jsx)(`h1`,{children:`How the agent got there`})]}),(0,K.jsxs)(`div`,{className:`rt-actions`,children:[(0,K.jsx)(Xd,{traces:t,currentId:e.id}),!s&&(0,K.jsxs)(`label`,{className:`rt-toggle`,title:`Fold runs of similar steps, such as repeated searches for the same thing, into one row`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:g,onChange:e=>v(e.target.checked)}),` Group similar steps`]}),(0,K.jsxs)(`button`,{type:`button`,className:`visualize-button ${s?`active`:``}`,onClick:()=>c(!s),children:[(0,K.jsx)(Ce,{size:14}),` `,s?`Back to list`:`Graph`]}),e.sandboxId&&r&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>r(),children:[`Sandbox evidence `,(0,K.jsx)(P,{size:14})]})]})]}),(0,K.jsx)(`dl`,{className:`rt-stats`,children:N.map(([e,t])=>(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:e}),(0,K.jsx)(`dd`,{children:t})]},e))}),s?(0,K.jsx)(Lw,{trace:e,blocks:m,summaries:p,onSelectStep:()=>c(!1)}):(0,K.jsx)(`div`,{className:`rt-table-wrap`,children:(0,K.jsxs)(`table`,{className:`rt-table rt-calls`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{children:`#`}),(0,K.jsx)(HT,{name:`Tool`,section:`tool-categories`}),(0,K.jsx)(`th`,{children:`Command`}),(0,K.jsx)(`th`,{children:`Agent reported`}),(0,K.jsx)(HT,{name:`Sandbox`,section:`sandbox-labels`}),(0,K.jsx)(`th`,{children:`Ran for`})]})}),(0,K.jsx)(`tbody`,{children:m.map(t=>{let s=j.find(e=>e.id===t.exchangeId),c=p[t.exchangeId],d=t.completion?De(t.completion):null,m=h.filter(e=>e.exchange_id===t.exchangeId),g=t.items.some(({event:e})=>e.title===`Model answer`);return m.length&&m.every(e=>T(e)&&S.get(e.call_id).id!==e.call_id)?null:(0,K.jsxs)(_.Fragment,{children:[(0,K.jsx)(`tr`,{className:`rt-trip`,children:(0,K.jsxs)(`td`,{colSpan:6,children:[(0,K.jsxs)(`span`,{children:[`Round trip `,t.number]}),c?.status===`ready`&&(0,K.jsx)(`em`,{children:c.text}),(0,K.jsxs)(`small`,{children:[s?`${id(s.cost,s.costEstimated)} · ${ad(s.durationMs)}`:``,d?` · failed`:``,g&&!m.length?` · answered`:``]})]})}),m.map(t=>{let s=Ne(e.events,t.call_id),c=Hu(e,t,s,BT(e,t)),d=c.opens===`files`?()=>{u(t.call_id),f(t.call_id)}:r&&(()=>r(t.call_id)),p=l===t.call_id,m=Du(t.started_at),h=Du(t.ended_at),g={exchange_id:t.exchange_id,output_index:t.output_index,title:`#${E.get(t.call_id)} ${t.name}`,detail:t.proposed??t.name},v=S.get(t.call_id),y=v&&v.id===t.call_id?(0,K.jsx)(UT,{group:v,trace:e,open:C(v),onToggle:()=>w(v)}):null;return v&&!C(v)?(0,K.jsx)(_.Fragment,{children:y},t.call_id):(0,K.jsxs)(_.Fragment,{children:[y,(0,K.jsxs)(`tr`,{id:`call-${t.call_id}`,className:`rt-row${p?` open`:``}${n===t.call_id?` rt-focus`:``}${v?` rt-in-group`:``}`,onClick:()=>u(p?null:t.call_id),children:[(0,K.jsxs)(`td`,{className:`rt-num`,children:[(0,K.jsx)(B,{size:12,className:`rt-caret`}),E.get(t.call_id)]}),(0,K.jsxs)(`td`,{className:`rt-tool`,children:[(0,K.jsx)(GT,{call:t}),t.snapshot?.changed&&(0,K.jsxs)(`small`,{className:`rt-changed`,title:`Files this call changed`,children:[t.snapshot.changes.length,` file`,t.snapshot.changes.length===1?``:`s`]})]}),(0,K.jsx)(`td`,{className:`rt-cmd`,children:t.description?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{className:`rt-plain`,children:t.description}),(0,K.jsx)(`span`,{className:`rt-cmd-raw`,title:t.proposed??void 0,children:(0,K.jsx)(Au,{text:t.proposed||t.name})})]}):(0,K.jsx)(Au,{text:t.proposed||t.name})}),(0,K.jsx)(`td`,{className:`rt-reported ${s.state}`,children:s.state===`none`?`—`:s.state===`rejected`?`rejected`:s.code==null?s.state:`exit ${s.code}`}),(0,K.jsx)(`td`,{children:(0,K.jsx)(WT,{label:c,onOpen:d})}),(0,K.jsx)(`td`,{className:`rt-time`,children:Number.isFinite(m)&&Number.isFinite(h)?Ou(h-m):`—`})]}),p&&(0,K.jsx)(`tr`,{className:`rt-expand`,children:(0,K.jsxs)(`td`,{colSpan:6,children:[(0,K.jsx)(`h4`,{children:`Arguments`}),(0,K.jsx)(`pre`,{children:LT(e,t)}),(0,K.jsx)(`h4`,{children:`Output the agent got back`}),(0,K.jsx)(`pre`,{children:s.output.trim()||`(no result captured)`}),t.snapshot&&(0,K.jsx)(`div`,{id:`files-${t.call_id}`,children:(0,K.jsx)(IT,{snapshot:t.snapshot,sandbox:e.sandboxId})}),(0,K.jsxs)(`div`,{className:`rt-actions`,children:[t.exec_id&&r&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>r(t.call_id),children:[`Show in sandbox `,(0,K.jsx)(P,{size:14})]}),i&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>i(g),children:[(0,K.jsx)(oe,{size:14}),` What it had in context`]}),O&&a&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>a(t.call_id),children:[(0,K.jsx)(R,{size:14}),` Why?`]}),D&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,title:`Rerun from the model call that made this tool call`,onClick:()=>o?.(t.exchange_id),children:[(0,K.jsx)(ie,{size:14}),` Fork from here`]}),D&&A(t.exchange_id)&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,title:`Rerun the next step as if this call had returned nothing`,onClick:()=>o?.(A(t.exchange_id),t.call_id),children:[(0,K.jsx)(ie,{size:14}),` Rerun without this output`]})]})]})})]},t.call_id)})]},t.exchangeId)})})]})})]})}function qT(e){let[t,n]=(0,_.useState)({status:`idle`}),[r,i]=(0,_.useState)(0),a=e.callVerifications?.length??0,o=!!e.answer&&a>0;return(0,_.useEffect)(()=>{if(!o){n({status:`idle`});return}let t=!1,r=e=>{t||n(e)};return r({status:`loading`}),(async()=>{try{let t=await x().fetch(`/raytace/recap/${e.id}`),n=await t.json();if(t.ok&&n.recap)return r({status:`ready`,recap:n.recap});if(t.ok&&n.available===!1)return r({status:`idle`});let i=await x().fetch(`/raytace/recap`,{method:`POST`,headers:{"content-type":`application/json`,"x-raytace-experiment":`1`},body:JSON.stringify({trace_id:e.id})}),a=await i.json();r(i.ok?{status:`ready`,recap:a}:{status:`error`,message:a.error??`The recap could not be written.`})}catch{r({status:`error`,message:`The recap could not be loaded.`})}})(),()=>{t=!0}},[e.id,o,a,r]),{state:t,retry:()=>i(e=>e+1)}}var JT={likely:`likely`,possible:`possibly`,unclear:`unclear`};function YT({trace:e,onStep:t}){let{state:n,retry:r}=qT(e);if(n.status===`idle`)return null;let i=e.callVerifications??[],a=e=>e.steps.length>0&&(0,K.jsx)(`span`,{className:`rt-recap-steps`,children:e.steps.map(e=>t&&i[e-1]?(0,K.jsx)(`button`,{type:`button`,className:`rt-recap-step`,onClick:()=>t(i[e-1].call_id),title:`Open step ${e}`,children:e},e):(0,K.jsx)(`span`,{className:`rt-recap-step`,children:e},e))});return(0,K.jsxs)(`section`,{className:`rt-recap`,"aria-label":`Recap`,children:[(0,K.jsxs)(`header`,{children:[(0,K.jsx)(`span`,{className:`eyebrow`,children:`RECAP`}),n.status===`ready`&&(0,K.jsxs)(`small`,{children:[`Written by `,n.recap.model.split(`/`).pop(),` from `,n.recap.steps_read===n.recap.total_steps?`all ${n.recap.total_steps}`:`${n.recap.steps_read} of ${n.recap.total_steps}`,` steps`]})]}),n.status===`loading`&&(0,K.jsx)(`p`,{className:`rt-muted`,children:`Reading the run…`}),n.status===`error`&&(0,K.jsxs)(`p`,{className:`rt-muted`,children:[n.message,` `,(0,K.jsxs)(`button`,{type:`button`,className:`link-button`,onClick:r,children:[(0,K.jsx)(me,{size:11}),` Try again`]})]}),n.status===`ready`&&(0,K.jsxs)(K.Fragment,{children:[n.recap.headline&&(0,K.jsx)(`p`,{className:`rt-recap-headline`,children:n.recap.headline}),(0,K.jsx)(`h4`,{children:`What happened`}),(0,K.jsx)(`ol`,{className:`rt-recap-list`,children:n.recap.happened.map((e,t)=>(0,K.jsxs)(`li`,{children:[e.text,` `,a(e)]},t))}),n.recap.reasoning.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`h4`,{children:[`Probably why `,(0,K.jsx)(`small`,{children:`the observer's reading of the sequence, not a measurement`})]}),(0,K.jsx)(`ul`,{className:`rt-recap-list`,children:n.recap.reasoning.map((e,t)=>(0,K.jsxs)(`li`,{children:[(0,K.jsx)(`span`,{className:`rt-recap-sure s-${e.confidence??`possible`}`,children:JT[e.confidence??`possible`]}),` `,e.text,` `,a(e)]},t))})]}),n.recap.flags.length>0&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`h4`,{children:`Worth checking`}),(0,K.jsx)(`ul`,{className:`rt-recap-list rt-recap-flags`,children:n.recap.flags.map((e,t)=>(0,K.jsxs)(`li`,{children:[e.text,` `,a(e)]},t))})]})]})]})}var XT=e=>`${e.exchange_id}:${e.output_index}`,ZT=e=>`${Math.round(e*100)}%`,QT=.02,$T={user:`Your request`,tool_result:`Earlier result`,agent:`Agent's earlier plan`,project:`Project instructions`,habit:`Routine step`,explore:`Exploring`};function eE(e){let[t,n]=(0,_.useState)({}),r=(0,_.useRef)(new Set),i=(0,_.useCallback)(async(e,t)=>{let i=XT(e),a=e=>{e.status!==`loading`&&r.current.add(i),t()&&n(t=>({...t,[i]:e}))};a({status:`loading`});try{let t=await x().fetch(`/raytace/attribution/${encodeURIComponent(e.exchange_id)}/${e.output_index}`),n=await t.json();if(!t.ok){a({status:`error`,message:n.error??`Unavailable.`});return}if(n.attribution){a({status:`ready`,attribution:n.attribution});return}}catch{}for(let n=0,r=0;t()&&n<12&&r<3;n+=1){try{let t=await x().fetch(`/raytace/attribution`,{method:`POST`,headers:{"content-type":`application/json`,"x-raytace-experiment":`1`},body:JSON.stringify({exchange_id:e.exchange_id,output_index:e.output_index})});if(t.status===409){await new Promise(e=>setTimeout(e,700));continue}let n=await t.json();if(t.ok){a({status:`ready`,attribution:n});return}if(t.status<500){a({status:`error`,message:n.error??`Unavailable.`});return}}catch{if(!t())return}r+=1,await new Promise(e=>setTimeout(e,800*r))}t()&&a({status:`error`,message:`Could not work out this step. Reopen the view to retry.`})},[]),a=e.filter(e=>typeof e.output_index==`number`).map(XT).join(`,`);return(0,_.useEffect)(()=>{let e=!0,t=()=>e,n=(a?a.split(`,`):[]).filter(e=>!r.current.has(e)).map(e=>{let t=e.lastIndexOf(`:`);return{exchange_id:e.slice(0,t),output_index:Number(e.slice(t+1))}}),o=0;return Promise.all(Array.from({length:4},async()=>{for(;e&&o<n.length;){let e=n[o];o+=1,await i(e,t)}})),()=>{e=!1}},[a,i]),t}function tE(e,t,n,r,i){let a=new Map(t.map(e=>[e.call_id,e])),o=[],s=new Set,c=e;for(;c&&!s.has(c.call_id)&&o.length<8;){s.add(c.call_id);let l=n[XT(c)];if(l?.status!==`ready`||!l.attribution.ranked)break;let u=l.attribution.causes[0];if(!u)break;let d=u.source_call_id?a.get(u.source_call_id):void 0;if(u.kind===`tool_result`&&d){let n=r.get(d.call_id);if(n&&!n.calls.some(t=>t.call_id===e.call_id)){let e=rd(n,i);o.unshift({label:`${e.range} ${e.kind}`,callId:n.id}),c=n.calls[0]}else o.unshift({label:`#${t.indexOf(d)+1} ${d.name}`,callId:d.call_id}),c=d}else{o.unshift({label:$T[u.kind].toLowerCase(),callId:null});break}}return o.length>1||o[0]?.callId?o:null}function nE({call:e,trace:t}){let n=Ne(t.events,e.call_id),r=[];e.exec_id?(r.push(`The sandbox saw it run`),typeof e.exit_code==`number`&&r.push(`exit ${e.exit_code}`),e.descendant_count&&r.push(`${e.descendant_count} child process${e.descendant_count===1?``:`es`}`)):n.state===`rejected`?r.push(`Refused by the sandbox policy`):(e.kind?e.kind===`command`:e.name===`Bash`)?r.push(`No process was seen for it`):r.push(`Ran inside the agent, not as a separate process`),e.snapshot?.changed&&r.push(`${e.snapshot.changes.length} file${e.snapshot.changes.length===1?``:`s`} changed`);let i=e.reported_check&&e.reported_check!==`agrees`;return(0,K.jsxs)(`div`,{className:`rt-cot-ran`,children:[(0,K.jsx)(`span`,{className:`workspace-label`,children:`WHAT ACTUALLY RAN`}),` `,r.join(` · `),i&&(0,K.jsxs)(`p`,{className:`rt-cot-warn`,children:[`The agent was told something different from what the sandbox saw (`,e.reported_check===`exit_code_differs`?`exit code`:`duration`,` differs). Its next steps were based on what it was told.`]}),e.snapshot?.changed&&(0,K.jsxs)(`details`,{children:[(0,K.jsx)(`summary`,{children:`Files changed`}),(0,K.jsx)(IT,{snapshot:e.snapshot,sandbox:t.sandboxId})]})]})}function rE({attribution:e,number:t,onJump:n}){let r=e.ranked?e.causes.filter(e=>(e.probability??0)>=QT):e.causes;return(0,K.jsxs)(K.Fragment,{children:[e.ranked&&(0,K.jsx)(`div`,{className:`rt-cot-bar`,"aria-hidden":`true`,children:r.map(e=>(0,K.jsx)(`span`,{className:`k-${e.kind}`,style:{width:ZT(e.probability??0)},title:`${ZT(e.probability??0)} ${e.reason}`},e.key))}),!e.ranked&&(0,K.jsxs)(`p`,{className:`rt-cot-note`,children:[`Possible reasons, unranked`,e.unsure_reason?`: ${e.unsure_reason}`:`.`]}),(0,K.jsx)(`ol`,{className:`rt-cot-causes`,children:r.map(e=>{let r=e.source_call_id?t(e.source_call_id):null;return(0,K.jsxs)(`li`,{children:[e.probability==null?(0,K.jsx)(`span`,{"aria-hidden":`true`}):(0,K.jsx)(`strong`,{className:`rt-cot-pct`,children:ZT(e.probability)}),(0,K.jsx)(`i`,{className:`rt-cot-dot k-${e.kind}`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{children:e.reason}),(0,K.jsxs)(`small`,{children:[$T[e.kind],r&&(0,K.jsxs)(K.Fragment,{children:[` · `,(0,K.jsxs)(`button`,{type:`button`,className:`link-button`,onClick:()=>n(e.source_call_id),children:[`step #`,r]})]})]}),e.quote&&(0,K.jsxs)(`details`,{children:[(0,K.jsx)(`summary`,{children:`Evidence`}),(0,K.jsx)(`blockquote`,{children:e.quote})]})]})]},e.key)})})]})}function iE({call:e,index:t,trace:n,states:r,chain:i,highlight:a,number:o,onJump:s}){let c=r[XT(e)],l=c?.status===`ready`?c.attribution:null;return(0,K.jsxs)(`li`,{id:`cot-${e.call_id}`,className:`rt-cot-step${a?` rt-focus`:``}`,children:[(0,K.jsxs)(`div`,{className:`rt-cot-head`,children:[(0,K.jsxs)(`span`,{className:`rt-cot-num`,children:[`#`,t+1]}),(0,K.jsx)(`strong`,{children:e.name}),(0,K.jsx)(Au,{text:e.proposed||e.name}),l?.purpose&&(0,K.jsx)(`span`,{className:`rt-chip`,title:l.purpose.label,children:l.purpose.choice.replace(`_`,` `)}),l?.unsure&&(0,K.jsx)(`span`,{className:`rt-cot-unsure`,title:l.unsure_reason??``,children:`Unsure`})]}),(0,K.jsx)(aE,{state:c,number:o,onJump:s}),i&&(0,K.jsxs)(`p`,{className:`rt-cot-chain`,children:[(0,K.jsx)(`span`,{className:`workspace-label`,children:`CHAIN`}),i.map((e,t)=>(0,K.jsxs)(`span`,{children:[e.callId?(0,K.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>s(e.callId),children:e.label}):e.label,` → `]},t)),(0,K.jsx)(`span`,{children:`this step`})]}),(0,K.jsx)(nE,{call:e,trace:n})]})}function aE({state:e,number:t,onJump:n}){if(!e||e.status===`loading`)return(0,K.jsx)(`p`,{className:`rt-cot-note`,children:`Working out why…`});if(e.status===`error`)return(0,K.jsx)(`p`,{className:`rt-cot-note`,children:e.message});let{attribution:r}=e;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(rE,{attribution:r,number:t,onJump:n}),r.unsure&&r.unsure_reason&&(0,K.jsxs)(`p`,{className:`rt-cot-note`,children:[`Unsure: `,r.unsure_reason]})]})}function oE({trace:e,focusCall:t}){let n=Pe(e),r=n.where===`sandbox`?e.callVerifications??[]:[],i=td(e,r),a=new Map(i.filter(e=>e.calls.length>1).flatMap(e=>e.calls.map(t=>[t.call_id,e]))),[o,s]=(0,_.useState)(()=>new Set),c=e=>o.has(e.id)!==e.calls.some(e=>e.call_id===t),l=e=>s(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n}),u=eE(i.flatMap(e=>e.calls.length>1&&!c(e)?[e.calls[0]]:e.calls)),[d,f]=(0,_.useState)(t),p=e=>{let t=r.findIndex(t=>t.call_id===e);return t<0?null:t+1},m=e=>{let t=a.get(e);t&&!c(t)&&e!==t.id&&l(t),f(e),requestAnimationFrame(()=>(document.getElementById(`cot-${e}`)??(t?document.getElementById(`cot-group-${t.id}`):null))?.scrollIntoView({block:`center`,behavior:`smooth`}))};(0,_.useEffect)(()=>{if(!t)return;let e=requestAnimationFrame(()=>document.getElementById(`cot-${t}`)?.scrollIntoView({block:`center`,behavior:`smooth`}));return()=>cancelAnimationFrame(e)},[t]);let h=(0,K.jsx)(`header`,{className:`rt-view-head`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`eyebrow`,children:`CHAIN OF THOUGHT`}),(0,K.jsx)(`h1`,{children:`Why the agent did each step`}),(0,K.jsx)(`p`,{className:`rt-muted rt-cot-caption`,children:`Likely reasons inferred from what the agent could see. Not the model's private reasoning.`})]})});if(n.where!==`sandbox`)return(0,K.jsxs)(`section`,{className:`rt-view`,children:[h,(0,K.jsxs)(`p`,{className:`rt-empty`,children:[`Chain of thought is available for prompts run in the sandbox. Run Claude Code in a local sandbox: `,(0,K.jsx)(`code`,{children:`raytrace sandbox create --local`}),`.`]})]});if(!r.length)return(0,K.jsxs)(`section`,{className:`rt-view`,children:[h,(0,K.jsx)(`p`,{className:`rt-empty`,children:`This prompt made no tool calls.`})]});let g=Object.values(u).find(e=>e.status===`ready`),v=g?.status===`ready`?[g.attribution.proposer_model,g.attribution.jev_model].filter(Boolean).join(` + `):``,y=t=>(0,K.jsx)(iE,{call:t,index:r.indexOf(t),trace:e,states:u,chain:tE(t,r,u,a,e),highlight:d===t.call_id,number:p,onJump:m},t.call_id);return(0,K.jsxs)(`section`,{className:`rt-view`,children:[h,(0,K.jsx)(YT,{trace:e,onStep:m}),(0,K.jsx)(`ol`,{className:`rt-cot-steps`,children:i.map(t=>{if(t.calls.length===1)return y(t.calls[0]);let n=rd(t,e),r=c(t),i=t.calls[0];return(0,K.jsxs)(`li`,{id:`cot-group-${t.id}`,className:`rt-cot-step rt-cot-group${d&&t.calls.some(e=>e.call_id===d)&&!r?` rt-focus`:``}`,children:[(0,K.jsxs)(`div`,{className:`rt-cot-head`,children:[(0,K.jsx)(`span`,{className:`rt-cot-num`,children:n.range}),(0,K.jsx)(`strong`,{children:n.label}),(0,K.jsxs)(`span`,{className:`rt-chip`,children:[t.calls.length,` steps`]}),n.flags.map(e=>(0,K.jsx)(`span`,{className:`rt-group-flag`,children:e},e))]}),(0,K.jsxs)(`p`,{className:`rt-cot-note`,children:[`Why it started (step #`,t.first,`):`]}),(0,K.jsx)(aE,{state:u[XT(i)],number:p,onJump:m}),n.repeated&&(0,K.jsxs)(`p`,{className:`rt-cot-note`,children:[n.repeated,` `,n.outcome[0].toUpperCase()+n.outcome.slice(1),`.`]}),(0,K.jsx)(`button`,{type:`button`,className:`link-button rt-cot-expand`,onClick:()=>l(t),children:r?`Hide the steps`:`Show the ${t.calls.length} steps`}),r&&(0,K.jsx)(`ol`,{className:`rt-cot-steps rt-cot-members`,children:t.calls.map(y)})]},t.id)})}),v&&(0,K.jsxs)(`p`,{className:`rt-foot`,children:[`Causes proposed and ranked by `,v,`. Each step is worked out once and saved.`]})]})}var sE=`/raytace`,cE=e=>[`queued`,`running`].includes(e.status),lE=e=>e===null?`Not measured`:`${Math.round(e*100)}%`;async function uE(e,t){let n=await fetch(`${sE}${e}`,t===void 0?void 0:{method:`POST`,headers:{"content-type":`application/json`,"x-raytace-experiment":`1`},body:JSON.stringify(t)}),r=await n.json();if(!n.ok)throw Error(r.error||`Request failed (${n.status})`);return r}function dE(e){return e.preview.trim().startsWith(`<skills_instructions>`)?`Codex skill instructions`:e.preview.trim().startsWith(`<environment_context>`)?`Environment context`:e.action||`${e.kind} · ${e.preview.replace(/\s+/g,` `).slice(0,55)}`}function fE({selected:e,focusCallId:t=null}){let[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(``),[m,h]=(0,_.useState)(`decision`),[g,v]=(0,_.useState)(`3`),[y,b]=(0,_.useState)(`10`),[x,S]=(0,_.useState)([]),[C,w]=(0,_.useState)(``),[T,E]=(0,_.useState)(``),[D,O]=(0,_.useState)(!!e?.exchange_id&&e.output_index!==void 0),[k,A]=(0,_.useState)(!1),[j,M]=(0,_.useState)(!1);(0,_.useEffect)(()=>{let e=!1;return uE(`/models`).then(t=>{e||(a(t.models),s(t.execution_available))}).catch(t=>{e||E(t.message)}),()=>{e=!0}},[]),(0,_.useEffect)(()=>{let n=!1;if(e?.exchange_id&&e.output_index!==void 0)return uE(`/steps/${e.exchange_id}/${e.output_index}`).then(e=>{if(n)return;r(e),l(e.model);let i=t&&e.evidence.find(e=>e.call_id===t)||e.evidence.find(t=>t.id===e.hypotheses[0]?.evidence_id)||e.evidence[0];d(i?.id||``),p(i?.content??i?.preview??``)}).catch(e=>{n||E(e.message)}).finally(()=>{n||O(!1)}),()=>{n=!0}},[e?.exchange_id,e?.output_index,t]),(0,_.useEffect)(()=>{let e=!1,t,n=async()=>{try{let t=await uE(`/experiments`);e||S(t.experiments)}catch{}e||(t=setTimeout(n,1500))};return n(),()=>{e=!0,clearTimeout(t)}},[]);let N=n?.evidence.find(e=>e.id===u),P=x.find(cE),F=x.find(e=>e.id===C),I=Number(g),L=Number(y),R=m===`decision`?Number.isInteger(I)&&I>=2&&I<=20:Number.isInteger(L)&&L>=1&&L<=20;function z(e){let t=n?.evidence.find(t=>t.id===e);d(e),p(t?.content??t?.preview??``)}async function ee(){if(n){M(!0),E(``);try{let e=await uE(`/explanations`,{exchange_id:n.exchange_id,output_index:n.output_index});r({...n,hypotheses:e.hypotheses,explanation_generated:!0,explanation_model:e.model}),e.hypotheses[0]&&z(e.hypotheses[0].evidence_id)}catch(e){E(e instanceof Error?e.message:`Could not generate explanations.`)}finally{M(!1)}}}async function B(){if(n&&N&&R){A(!0),E(``);try{let e=await uE(`/step-runs`,{exchange_id:n.exchange_id,output_index:n.output_index,evidence_id:u,context:f,model:c,mode:m,repetitions:m===`decision`?I:2,max_requests:m===`execute`?L:1});S(t=>[e,...t]),w(e.id)}catch(e){E(e instanceof Error?e.message:`Could not start run.`)}finally{A(!1)}}}return(0,K.jsxs)(`aside`,{className:`fork-panel lab decision-lab`,children:[(0,K.jsx)(`span`,{className:`eyebrow`,children:`COUNTERFACTUAL LAB`}),(0,K.jsx)(`h2`,{children:`Explore this decision`}),!n&&!D&&!T&&(0,K.jsx)(`p`,{children:`Select a proposed tool call or model answer in the sequence.`}),D&&(0,K.jsx)(`output`,{children:`Loading the context before this step…`}),T&&(0,K.jsx)(`p`,{className:`experiment-error`,role:`alert`,children:T}),n&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`section`,{className:`step-focus`,children:[(0,K.jsx)(`small`,{children:`SELECTED STEP`}),(0,K.jsx)(`h3`,{children:e?.title}),(0,K.jsx)(`p`,{children:e?.detail})]}),(0,K.jsx)(`h3`,{children:`Possible explanations`}),(0,K.jsx)(`p`,{className:`lab-caption`,children:n.explanation_generated?`Generated by ${n.explanation_model} from earlier context. These are hypotheses, not private reasoning.`:`Generate a short explanation using ${n.explanation_model}. One additional paid API request; saved for this step.`}),!n.explanation_generated&&(0,K.jsx)(`button`,{type:`button`,className:`run-button`,disabled:j||!o,onClick:ee,children:j?`Generating explanations…`:`Generate explanations`}),(0,K.jsx)(`ol`,{className:`hypothesis-list`,children:n.hypotheses.map((e,t)=>{let r=x.find(t=>t.kind===`step`&&t.mode===`decision`&&t.exchange_id===n.exchange_id&&t.output_index===n.output_index&&t.evidence_id===e.evidence_id&&t.model===c&&t.status===`completed`);return(0,K.jsxs)(`li`,{className:e.evidence_id===u?`chosen`:``,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>z(e.evidence_id),children:[(0,K.jsx)(`span`,{children:t+1}),(0,K.jsx)(`strong`,{children:e.title})]}),(0,K.jsx)(`p`,{children:r?`Action repeated: ${lE(r.summary.baseline.rate)} original / ${lE(r.summary.intervention.rate)} edited`:`Action repeat rate: not measured`}),(0,K.jsxs)(`details`,{children:[(0,K.jsx)(`summary`,{children:`Supporting evidence`}),(0,K.jsx)(`p`,{children:e.explanation}),(0,K.jsx)(`blockquote`,{children:e.excerpt})]})]},e.evidence_id)})}),n.explanation_generated&&!n.hypotheses.length&&(0,K.jsx)(`p`,{children:`Insufficient evidence: no explanations with verifiable supporting quotes were returned.`}),(0,K.jsx)(`h3`,{children:`Edit and rerun`}),(0,K.jsx)(`label`,{htmlFor:`step-context`,children:`Context to change`}),(0,K.jsx)(zd,{id:`step-context`,className:`lab-select`,value:u,onChange:e=>z(e.target.value),children:n.evidence.map(e=>(0,K.jsxs)(Bd,{value:e.id,children:[`#`,e.index+1,` · `,dE(e)]},e.id))}),(0,K.jsx)(`label`,{htmlFor:`edited-context`,children:`Edited context`}),(0,K.jsx)(`textarea`,{id:`edited-context`,value:f,onChange:e=>p(e.target.value),spellCheck:!1,rows:8}),(0,K.jsxs)(`div`,{className:`context-actions`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>p(N?.content??N?.preview??``),children:`Reset`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>p(``),children:`Withhold text`})]}),(0,K.jsx)(`small`,{children:`Only this context item changes. Other messages and tool history are retained.`}),(0,K.jsx)(`label`,{htmlFor:`step-model`,children:`Model`}),(0,K.jsxs)(zd,{id:`step-model`,className:`lab-select`,value:c,onChange:e=>l(e.target.value),children:[!i.some(e=>e.id===n.model)&&(0,K.jsx)(Bd,{value:n.model,children:n.model}),i.map(e=>(0,K.jsxs)(Bd,{value:e.id,children:[e.alias,` · `,e.id]},e.alias))]}),(0,K.jsx)(`label`,{htmlFor:`run-mode`,children:`Run mode`}),(0,K.jsxs)(zd,{id:`run-mode`,className:`lab-select`,value:m,onChange:e=>h(e.target.value),children:[(0,K.jsx)(Bd,{value:`decision`,children:`Replay model decision`}),(0,K.jsx)(Bd,{value:`execute`,disabled:!o,children:`Execute and continue`})]}),m===`decision`?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`label`,{htmlFor:`step-count`,children:`Runs per version`}),(0,K.jsx)(`input`,{id:`step-count`,type:`number`,min:2,max:20,step:1,value:g,onChange:e=>v(e.target.value)}),(0,K.jsx)(`p`,{children:R?`${I} original + ${I} edited = ${I*2} paid API calls maximum.`:`Enter a whole number from 2 to 20.`}),(0,K.jsxs)(`details`,{className:`raw-details`,children:[(0,K.jsx)(`summary`,{children:`How this is measured`}),(0,K.jsx)(`p`,{children:`Both use the selected model. Tools are not executed.`})]})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`label`,{htmlFor:`step-limit`,children:`Maximum model requests`}),(0,K.jsx)(`input`,{id:`step-limit`,type:`number`,min:1,max:20,step:1,value:y,onChange:e=>b(e.target.value)}),(0,K.jsxs)(`p`,{children:[`One continuation in a separate copy of current project files, up to `,R?L:`—`,` paid requests and 3 minutes.`]}),(0,K.jsxs)(`details`,{className:`raw-details`,children:[(0,K.jsx)(`summary`,{children:`How this is measured`}),(0,K.jsx)(`p`,{children:`Tools can edit the copy; network access and approval-requiring actions are blocked. Dependencies are not copied. This reconstructs the task from edited context; it is not an exact historical session resume.`})]})]}),n.replay_reason&&(0,K.jsx)(`p`,{className:`scope-note`,children:n.replay_reason}),(0,K.jsx)(`button`,{className:`run-button`,type:`button`,disabled:k||!!P||!R||!N||!!n.replay_reason,onClick:B,children:k?`Starting…`:m===`decision`?`Compare responses`:`Execute in project copy`}),P&&(0,K.jsxs)(`div`,{className:`job-progress`,children:[(0,K.jsxs)(`p`,{children:[P.mode===`execute`?`${P.requests||0}/${P.max_requests} model requests`:`${P.trials?.length||0}/${P.max_requests} trials`,` · `,P.status]}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>uE(`/experiments/${P.id}/cancel`,{}).catch(e=>E(e.message)),children:`Cancel experiment`})]}),x.some(e=>e.kind===`step`&&e.exchange_id===n.exchange_id&&e.output_index===n.output_index)&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`label`,{htmlFor:`step-run`,children:`Results for this action`}),(0,K.jsxs)(zd,{id:`step-run`,className:`lab-select`,value:C,onChange:e=>w(e.target.value),children:[(0,K.jsx)(Bd,{value:``,children:`Choose an experiment`}),x.filter(e=>e.kind===`step`&&e.exchange_id===n.exchange_id&&e.output_index===n.output_index).map(e=>(0,K.jsxs)(Bd,{value:e.id,children:[e.mode,` · `,e.model,` · `,e.status]},e.id))]})]})]}),F&&(0,K.jsxs)(`section`,{className:`trial-report`,children:[(0,K.jsx)(`h3`,{children:`Original vs rerun`}),(0,K.jsxs)(`p`,{children:[F.status,` · `,F.model]}),F.error&&(0,K.jsx)(`p`,{role:`alert`,className:`error-text`,children:F.error}),(0,K.jsxs)(`details`,{children:[(0,K.jsx)(`summary`,{children:`Original action`}),(0,K.jsx)(`pre`,{children:JSON.stringify(F.recorded,null,2)})]}),F.mode===`decision`?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`frequency-grid`,children:[[`Original context`,F.summary.baseline],[`Edited context`,F.summary.intervention]].map(([e,t])=>(0,K.jsxs)(`section`,{className:`frequency`,children:[(0,K.jsx)(`h4`,{children:e}),(0,K.jsx)(`strong`,{children:lE(t.rate)}),(0,K.jsxs)(`p`,{children:[t.hits,`/`,t.successful,` successful responses repeated the selected action`]}),t.interval&&(0,K.jsxs)(`small`,{children:[`95% interval: `,lE(t.interval[0]),`–`,lE(t.interval[1])]})]},e))}),(0,K.jsx)(`p`,{className:`lab-caption`,children:`These rates measure action repetition, not the probability an explanation is true.`}),(0,K.jsxs)(`details`,{className:`raw-details`,children:[(0,K.jsx)(`summary`,{children:`How this is measured`}),(0,K.jsx)(`p`,{children:`Small samples are uncertain. Answers require exact text matches.`})]}),(0,K.jsxs)(`p`,{children:[`Reported API cost: $`,F.cost.toFixed(4)]}),F.trials.map((e,t)=>(0,K.jsxs)(`details`,{children:[(0,K.jsxs)(`summary`,{children:[t+1,`. `,e.arm===`baseline`?`Original`:`Edited`,` · `,e.status===`succeeded`?e.matches?`same action`:`different response`:e.status]}),(0,K.jsx)(`pre`,{children:e.error||JSON.stringify(e.outcome,null,2)})]},t))]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{children:F.note}),F.workspace&&(0,K.jsxs)(`p`,{children:[`Files: `,(0,K.jsx)(`code`,{children:F.workspace})]}),(0,K.jsx)(`h4`,{children:`New execution sequence`}),F.events.map((e,t)=>(0,K.jsxs)(`details`,{children:[(0,K.jsxs)(`summary`,{children:[typeof e.type==`string`?e.type:`Event`,` `,String(e.item?.type||``)]}),(0,K.jsx)(`pre`,{children:JSON.stringify(e,null,2)})]},t))]})]})]})}var pE=e=>Math.round(e/4),mE=e=>e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e);async function hE(e,t){let n=window.open(``,`_blank`);try{let r=await x().fetch(`/raytace/prompt-context/${e}/item/${t}`),i=URL.createObjectURL(new Blob([await r.text()],{type:`text/plain;charset=utf-8`}));n?n.location.replace(i):window.location.assign(i)}catch{n?.close()}}var gE=(e,t=140)=>{let n=e.replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-1)}…`:n};function _E(e){let[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(!1),s=(0,_.useRef)(!1);return(0,_.useEffect)(()=>{let t=!1;return x().fetch(`/raytace/prompt-context/${e}`).then(async e=>{let r=await e.json();if(e.status===404&&r.error===`Unknown local endpoint.`)throw Error(`The proxy is running an older version without this page. Restart it (raytrace stop && raytrace start) and reload.`);if(!e.ok)throw Error(r.error||`Context unavailable`);t||n(r)}).catch(e=>{t||i(e instanceof Error?e.message:`Context unavailable`)}),()=>{t=!0}},[e]),(0,_.useEffect)(()=>{if(!t||t.summary||!t.summary_needed||s.current)return;s.current=!0;let r=!1;return o(!0),x().fetch(`/raytace/prompt-context/summary`,{method:`POST`,headers:{"content-type":`application/json`,"x-raytace-experiment":`1`},body:JSON.stringify({trace_id:e})}).then(async e=>{let t=await e.json();e.ok&&!r&&n(e=>e&&{...e,summary:t})}).catch(()=>{}).finally(()=>{r||o(!1)}),()=>{r=!0}},[t,e]),{data:t,error:r,summarizing:a}}function vE({file:e,traceId:t,onTest:n,onRerun:r}){let[i,a]=(0,_.useState)(!1),o=e.op===`wrote`?`—`:`${e.lines} line${e.lines===1?``:`s`}`;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`li`,{className:`rt-file${i?` open`:``}`,children:(0,K.jsxs)(`button`,{type:`button`,className:`rt-file-row`,onClick:()=>a(!i),"aria-expanded":i,children:[(0,K.jsx)(`span`,{className:`rt-op rt-op-${e.op}`,children:e.op}),(0,K.jsx)(`code`,{className:`rt-file-path`,title:e.path,children:e.path}),(0,K.jsxs)(`span`,{className:`rt-file-size`,title:e.shared_output?`This output came from several commands chained together, so it cannot be split between them.`:void 0,children:[o,e.shared_output?`*`:``]}),(0,K.jsx)(`span`,{className:`rt-file-tokens`,title:`Estimated tokens this file added to the context window`,children:e.op===`wrote`?``:`~${mE(pE(e.chars))} tokens`}),(0,K.jsx)(`span`,{className:`rt-file-used`,title:e.used_later.length?`Words from this output appear later in what the model wrote: ${e.used_later.join(`, `)}. A hint, not proof it mattered.`:`Nothing from this output reappears later. A hint, not proof it did not matter.`,children:e.used_later.length?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(z,{size:12}),` used`]}):``})]})}),i&&(0,K.jsxs)(`li`,{className:`rt-file-detail`,children:[(0,K.jsxs)(`p`,{className:`rt-muted`,children:[e.when===`before`?`In context before your question`:`Read while answering this prompt`,e.reads>1?` · read ${e.reads} times`:``,` · `,e.via===`tool`?`named by the tool call`:`inferred from the command`,` `,(0,K.jsx)(`code`,{children:gE(e.command,90)})]}),(0,K.jsxs)(`div`,{className:`rt-actions`,children:[e.op!==`wrote`&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>void hE(t,e.context_index),children:[`Open what the model saw `,(0,K.jsx)(te,{size:13})]}),r&&e.op!==`wrote`&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:r,title:`Open the Playground at the next step, with this output removed`,children:[(0,K.jsx)(ie,{size:14}),` Rerun without this`]}),n&&e.op!==`wrote`&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:n,children:[(0,K.jsx)(ne,{size:14}),` Test impact`]})]})]})]})}function yE({data:e}){let t=pE(e.totals.chars),n=t=>e.internals.filter(e=>e.kind===t).reduce((e,t)=>e+t.chars,0),r=e.files.filter(e=>e.op!==`wrote`).reduce((e,t)=>e+t.chars,0),i=n(`System prompt`)+n(`Tools`)+r,a=[{label:`System prompt`,chars:n(`System prompt`),tone:1},{label:`Tool definitions`,chars:n(`Tools`),tone:2},{label:`File contents`,chars:r,tone:3},{label:`Conversation and other instructions`,chars:Math.max(0,e.totals.chars-i),tone:4}].filter(e=>e.chars>0),o=e.context_window,s=o||t||1;return(0,K.jsxs)(`section`,{className:`rt-window`,"aria-label":`Context window`,children:[(0,K.jsxs)(`div`,{className:`rt-window-head`,children:[(0,K.jsxs)(`strong`,{children:[`Context window: ~`,mE(t),` tokens used`,o?` of ${mE(o)}`:``]}),(0,K.jsx)(`span`,{children:o?`${(t/o*100).toFixed(1)}% full by the final answer · ${e.model}`:`by the final answer · window size for ${e.model} unknown`})]}),(0,K.jsx)(`div`,{className:`rt-window-bar`,children:a.map(e=>(0,K.jsx)(`i`,{className:`rt-seg-${e.tone}`,style:{width:`${Math.max(.4,pE(e.chars)/s*100)}%`},title:`${e.label}: ~${mE(pE(e.chars))} tokens`},e.label))}),(0,K.jsx)(`div`,{className:`rt-window-legend`,children:a.map(e=>(0,K.jsxs)(`span`,{children:[(0,K.jsx)(`i`,{className:`rt-seg-${e.tone}`}),e.label,` ~`,mE(pE(e.chars))]},e.label))})]})}function bE({trace:e,stepKey:t,onStep:n,onRerunWithout:r}){let{data:i,error:a,summarizing:o}=_E(e.id),[s,c]=(0,_.useState)(!1),[l,u]=(0,_.useState)(null),d=(0,_.useRef)(null),f=e.callVerifications??[],p=f.map((e,t)=>({call_id:e.call_id,exchange_id:e.exchange_id,output_index:e.output_index,title:`#${t+1} ${e.name}`,detail:e.proposed??e.name})),m=e=>`${e.exchange_id}:${e.output_index}`,h=p.find(e=>m(e)===t)??p[0];function g(e){let t=p.findIndex(t=>t.call_id===e.call_id),r=t>=0?p[t+1]:void 0;r&&(u(e.call_id),c(!0),n(m(r)),requestAnimationFrame(()=>d.current?.scrollIntoView({behavior:`smooth`,block:`start`})))}let v=e=>{let t=p.findIndex(t=>t.call_id===e.call_id);return t>=0&&t<p.length-1},y=Pe(e).forkable,b=x().reruns,S=(e.requests??[]).map(e=>e.id),C=e=>{let t=f.find(t=>t.call_id===e.call_id),n=t?S[S.indexOf(t.exchange_id)+1]:void 0;return r&&y&&n?()=>r(n,e.call_id):void 0},w=i?.files.filter(e=>e.op!==`listed`)??[],T=i?.files.filter(e=>e.op===`listed`)??[],E=i?.answers.filter(e=>e.when===`before`)??[],D=i?.internals.find(e=>e.kind===`Environment`)?.fields;return(0,K.jsxs)(`section`,{className:`rt-view`,children:[(0,K.jsx)(`header`,{className:`rt-view-head`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`eyebrow`,children:`CONTEXT`}),(0,K.jsx)(`h1`,{children:`What the model was working from`}),(0,K.jsxs)(`p`,{className:`rt-muted rt-sub`,children:[gE(e.title,120),` · `,new Date(e.startedAt).toLocaleString(void 0,{day:`numeric`,month:`short`,hour:`numeric`,minute:`2-digit`})]})]})}),i&&(0,K.jsx)(yE,{data:i}),a&&(0,K.jsx)(`p`,{role:`alert`,className:`verify-error`,children:a}),!i&&!a&&(0,K.jsx)(`p`,{className:`rt-empty`,children:`Loading the context…`}),i&&(0,K.jsxs)(`div`,{className:`rt-boxes`,children:[(0,K.jsxs)(`section`,{className:`rt-box`,children:[(0,K.jsxs)(`h2`,{children:[(0,K.jsx)(`span`,{children:`A`}),` You asked before`]}),i.earlierPrompts.length?(0,K.jsx)(`ol`,{className:`rt-box-list`,children:i.earlierPrompts.map((e,t)=>(0,K.jsx)(`li`,{children:i.summary?.prompts[t]??gE(e.text)},e.index))}):(0,K.jsx)(`p`,{className:`rt-muted`,children:`This was the first prompt in this conversation, so nothing you asked earlier was in context.`}),o&&(0,K.jsx)(`p`,{className:`rt-muted`,children:`Summarising…`})]}),(0,K.jsxs)(`section`,{className:`rt-box rt-box-wide`,children:[(0,K.jsxs)(`h2`,{children:[(0,K.jsx)(`span`,{children:`B`}),` The model brought`]}),(0,K.jsx)(`p`,{className:`rt-box-note`,children:E.length?i.summary?.answers||`${E.length} earlier answer${E.length===1?``:`s`}: ${gE(E.at(-1).text,120)}`:`No earlier answers: it started this conversation with your question.`}),w.length?(0,K.jsx)(`ul`,{className:`rt-files`,title:`From the agent's file tools and the commands it ran, not observed at the file level.`,children:w.map(t=>(0,K.jsx)(vE,{file:t,traceId:e.id,onRerun:C(t),onTest:b&&!y&&v(t)?()=>g(t):void 0},`${t.op}:${t.path}`))}):(0,K.jsx)(`p`,{className:`rt-muted`,children:`No file reads identified in what was captured.`}),T.length>0&&(0,K.jsxs)(`details`,{className:`rt-listed`,children:[(0,K.jsxs)(`summary`,{children:[`listed `,T.length,` location`,T.length===1?``:`s`]}),(0,K.jsx)(`ul`,{className:`rt-files`,children:T.map(t=>(0,K.jsx)(vE,{file:t,traceId:e.id},`${t.op}:${t.path}`))})]}),(0,K.jsxs)(`p`,{className:`rt-box-foot`,children:[`Tokens are estimates of what each file added to the context window. “used” means words from the file reappear in what the model wrote later. `,y?r?`Rerun without this opens the Playground with that output removed.`:``:b?`Test impact reruns the next step without it.`:``]})]}),(0,K.jsxs)(`section`,{className:`rt-box`,children:[(0,K.jsxs)(`h2`,{children:[(0,K.jsx)(`span`,{children:`C`}),` Internals`]}),(0,K.jsx)(`ul`,{className:`rt-internals`,children:i.internals.map(t=>(0,K.jsx)(`li`,{children:(0,K.jsxs)(`details`,{children:[(0,K.jsxs)(`summary`,{children:[(0,K.jsx)(`strong`,{children:t.kind}),(0,K.jsxs)(`span`,{children:[`~`,mE(pE(t.chars)),` tokens`]})]}),t.kind===`Environment`&&D?(0,K.jsx)(`dl`,{children:Object.entries(D).map(([e,t])=>(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:e.replace(/_/g,` `)}),(0,K.jsx)(`dd`,{children:t})]},e))}):t.names?(0,K.jsx)(`p`,{className:`rt-muted`,children:t.names.join(`, `)}):null,(0,K.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>void hE(e.id,t.context_index),children:`Open full text ↗`})]})},t.kind))}),!i.internals.some(e=>e.kind===`AGENTS.md`)&&(0,K.jsx)(`p`,{className:`rt-muted`,children:`No AGENTS.md was loaded.`})]})]}),b&&!y&&(0,K.jsxs)(`details`,{className:`rt-test`,ref:d,open:s,onToggle:e=>c(e.currentTarget.open),children:[(0,K.jsxs)(`summary`,{children:[(0,K.jsx)(ne,{size:14}),` Test it: rerun a step with part of its context changed`]}),p.length?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`label`,{htmlFor:`lab-step`,className:`workspace-label`,children:`STEP`}),(0,K.jsx)(zd,{id:`lab-step`,className:`trace-picker`,value:h?m(h):``,onChange:e=>{u(null),n(e.target.value)},children:p.map(e=>(0,K.jsxs)(Bd,{value:m(e),children:[e.title,` · `,e.detail.slice(0,80)]},m(e)))}),s&&h&&(0,K.jsx)(`div`,{className:`rt-lab-body`,children:(0,K.jsx)(fE,{selected:h,focusCallId:l},`${m(h)}:${l??``}`)})]}):(0,K.jsx)(`p`,{className:`rt-empty`,children:`This prompt proposed no tool calls, so there is no step to rerun.`})]})]})}var xE=e=>{try{return Number(localStorage.getItem(e))||null}catch{return null}},SE=(e,t)=>{try{t==null?localStorage.removeItem(e):localStorage.setItem(e,String(t))}catch{}};function CE({target:e,variable:t,storageKey:n,min:r,max:i,label:a}){let o=e=>Math.round(Math.min(i,Math.max(r,e))),s=n=>{n==null?e.current?.style.removeProperty(t):e.current?.style.setProperty(t,`${o(n)}px`)},c=e=>e.parentElement?.getBoundingClientRect().width??r;return(0,_.useEffect)(()=>{let a=xE(n);a&&e.current?.style.setProperty(t,`${Math.round(Math.min(i,Math.max(r,a)))}px`)},[e,t,n,r,i]),(0,K.jsx)(`button`,{type:`button`,"aria-label":`${a}: drag, or use the arrow keys, to resize`,className:`resize-handle`,title:`${a} · drag to resize, double-click to reset`,onPointerDown:e=>{let t=e.currentTarget,r=e.clientX,i=c(t);t.setPointerCapture(e.pointerId),document.body.classList.add(`resizing`);let a=e=>s(i+e.clientX-r),l=e=>{t.removeEventListener(`pointermove`,a),t.removeEventListener(`pointerup`,l),t.removeEventListener(`pointercancel`,l),document.body.classList.remove(`resizing`),SE(n,o(i+e.clientX-r))};t.addEventListener(`pointermove`,a),t.addEventListener(`pointerup`,l),t.addEventListener(`pointercancel`,l)},onKeyDown:e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;e.preventDefault();let t=o(c(e.currentTarget)+(e.key===`ArrowRight`?24:-24));s(t),SE(n,t)},onDoubleClick:()=>{s(null),SE(n,null)}})}var wE={"content-type":`application/json`,"x-raytace-experiment":`1`},TE=[`claude-opus-5-5`,`claude-sonnet-5`,`claude-haiku-4-5`,`claude-fable-5-1`],EE=`(output removed)`,DE=(e,t=120)=>{let n=e.replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-1)}…`:n},OE=e=>new Date(e).toLocaleString(void 0,{day:`numeric`,month:`short`,hour:`numeric`,minute:`2-digit`}),kE=e=>[`queued`,`creating`,`running`,`collecting`,`checking`].includes(e.status),AE={queued:`Waiting`,creating:`Starting sandbox`,running:`Running`,collecting:`Comparing`,checking:`Checking`,completed:`Done`,failed:`Failed`,interrupted:`Interrupted`,cancelled:`Cancelled`},jE=[1,3,5,10],ME=e=>e.check&&[`passed`,`failed`,`timed_out`].includes(e.check.status),NE=e=>{if(!e.length)return null;let t=[...e].sort((e,t)=>e-t),n=t.length>>1;return t.length%2?t[n]:(t[n-1]+t[n])/2},PE={pending:`Check waiting`,running:`Checking…`,passed:`Check passed`,failed:`Check failed`,timed_out:`Check timed out`,error:`Check could not run`,skipped:`Check not run`},FE=e=>e==null?``:e<1e4?`${(e/1e3).toFixed(1)} s`:`${Math.round(e/1e3)} s`;function IE({check:e}){let t=e.status===`passed`||e.status===`failed`?`exit ${e.exit_code} · ${FE(e.duration_ms)}`:e.status===`timed_out`?`stopped after ${FE(e.duration_ms)}`:e.status===`skipped`?`the fork stopped before it got there`:``;return(0,K.jsxs)(`div`,{className:`pg-check c-${e.status}`,children:[(0,K.jsxs)(`p`,{children:[e.status===`passed`?(0,K.jsx)(z,{size:14}):e.status===`failed`||e.status===`timed_out`?(0,K.jsx)(Te,{size:14}):null,(0,K.jsx)(`strong`,{children:PE[e.status]}),(0,K.jsx)(`code`,{children:e.command}),t&&(0,K.jsx)(`small`,{children:t})]}),e.output&&(0,K.jsxs)(`details`,{children:[(0,K.jsx)(`summary`,{children:`Output`}),(0,K.jsx)(`pre`,{className:`pg-diff`,children:e.output})]})]})}function LE(e){let[t,n]=(0,_.useState)([]),r=(0,_.useCallback)(async()=>{try{let e=await x().fetch(`/raytace/forks`);e.ok&&n((await e.json()).forks)}catch{}},[]);return(0,_.useEffect)(()=>{let e=!1,t,n=async()=>{await r(),e||(t=setTimeout(n,2500))};return n(),()=>{e=!0,clearTimeout(t)}},[r]),{forks:t.filter(t=>e.has(t.exchange_id)),refresh:r}}function RE(e){let[t,n]=(0,_.useState)(null);return(0,_.useEffect)(()=>{if(!e)return;let t=!1;return x().fetch(`/raytace/forks/preview/${e}`).then(async e=>{let r=await e.json();t||n(e.ok?r:{forkable:!1,reason:r.error??`Preview unavailable.`})}).catch(()=>{t||n({forkable:!1,reason:`RayTrace is not reachable.`})}),()=>{t=!0}},[e]),t}function zE({fork:e,path:t}){let[n,r]=(0,_.useState)(null);return(0,_.useEffect)(()=>{if(!e.comparison?.fork)return;let n=new URLSearchParams({commit:e.comparison.original,to:e.comparison.fork,path:t});x().fetch(`/raytace/snapshots/${e.parent}/diff?${n}`).then(async e=>{let t=await e.json();r(e.ok?t.diff||`(no difference)`:`Could not load the diff: ${t.error}`)}).catch(()=>r(`Could not load the diff.`))},[e,t]),n===null?(0,K.jsx)(`p`,{className:`pg-note`,children:`Loading diff…`}):n.startsWith(`Could not load`)?(0,K.jsx)(`p`,{className:`pg-note`,children:n}):(0,K.jsx)(NT,{diff:n})}function BE({fork:e,trace:t,fromIndex:n,forkTrace:r,onChanged:i,onOpenTrace:a}){let[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(!1),u=t.requests??[],d=(t.callVerifications??[]).filter(e=>u.findIndex(t=>t.id===e.exchange_id)>=n),f=e.comparison?.changes??[],p=async t=>{l(!0);try{await x().fetch(`/raytace/forks/${e.id}/${t}`,{method:`POST`,headers:wE})}finally{l(!1),i()}},m=kE(e)?null:e.status===`completed`?e.comparison?.same_files?`Same files as the original.`:`${f.length} file${f.length===1?``:`s`} differ from the original.`:null;return(0,K.jsxs)(`article`,{className:`pg-run`,children:[(0,K.jsxs)(`header`,{className:`pg-run-head`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`span`,{className:`pg-status s-${e.status}`,children:[AE[e.status],kE(e)&&e.progress.tool_calls?` · ${e.progress.tool_calls} tool call${e.progress.tool_calls===1?``:`s`}`:``]}),(0,K.jsx)(`strong`,{children:e.model}),(0,K.jsxs)(`small`,{children:[(e.attempts??1)>1&&`Run ${e.attempt} of ${e.attempts} · `,OE(e.created_at),(()=>{let t=e.edits.excluded??[],n=t.length?0:e.edits.results.length,r=[t.length&&`excluded ${t.join(`, `)}`,!t.length&&n&&`${n} tool result${n===1?``:`s`} edited`,e.edits.files.length&&`edited ${e.edits.files.join(`, `)}`].filter(Boolean);return r.length?` · ${r.join(` · `)}`:e.message?``:` · nothing changed`})()]}),e.message&&(0,K.jsxs)(`p`,{className:`pg-told`,children:[(0,K.jsx)(`b`,{children:`You told it:`}),` `,e.message]})]}),(0,K.jsxs)(`div`,{className:`rt-actions`,children:[r&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>a(r.id),title:`The fork's steps, commands and sandbox evidence, like any recorded run`,children:[`Fork's tool calls`,` `,(0,K.jsx)(P,{size:13})]}),!e.deleted_at&&!kE(e)&&(0,K.jsx)(`button`,{type:`button`,className:`rt-button`,disabled:c,onClick:()=>p(e.keep?`unkeep`:`keep`),title:e.keep?`Let it be deleted like any other fork`:`Keep this fork's sandbox instead of deleting it with the next run`,children:e.keep?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(ue,{size:13}),` Unkeep`]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(de,{size:13}),` Keep`]})}),!e.deleted_at&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,disabled:c,onClick:()=>p(`delete`),children:[(0,K.jsx)(be,{size:13}),e.status===`queued`?`Cancel this run`:kE(e)?`Stop and delete`:`Delete sandbox`]}),e.deleted_at&&e.status!==`cancelled`&&(0,K.jsx)(`span`,{className:`pg-note`,children:`Sandbox deleted · results kept`})]})]}),e.error&&(0,K.jsx)(`p`,{role:`alert`,className:`pg-error`,children:e.error}),e.check&&(0,K.jsx)(IE,{check:e.check}),m&&(0,K.jsx)(`p`,{className:`pg-verdict${e.comparison?.same_files?` same`:``}`,children:m}),(0,K.jsxs)(`div`,{className:`pg-compare`,children:[(0,K.jsxs)(`section`,{children:[(0,K.jsx)(`h3`,{children:`Original, from this step`}),(0,K.jsxs)(`ol`,{className:`pg-steps`,children:[d.map(e=>(0,K.jsxs)(`li`,{children:[(0,K.jsx)(`b`,{children:e.name}),(0,K.jsx)(`code`,{children:DE(e.proposed??``,140)})]},e.call_id)),!d.length&&(0,K.jsx)(`li`,{className:`pg-note`,children:`Answered without another tool call.`})]}),t.answer&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`h4`,{children:`Answer`}),(0,K.jsx)(`p`,{className:`pg-answer`,children:t.answer})]})]}),(0,K.jsxs)(`section`,{children:[(0,K.jsx)(`h3`,{children:`Fork`}),(0,K.jsxs)(`ol`,{className:`pg-steps`,children:[e.events.filter(e=>e.kind===`tool`).map((e,t)=>(0,K.jsxs)(`li`,{children:[(0,K.jsx)(`b`,{children:e.name}),(0,K.jsx)(`code`,{children:DE(e.detail,140)})]},t)),kE(e)&&(0,K.jsx)(`li`,{className:`pg-note pg-live`,children:e.status===`queued`?`Waiting for run ${(e.attempt??2)-1} to finish…`:e.status===`creating`?`Restoring the project and starting Claude Code…`:e.status===`collecting`?`Comparing files with the original…`:e.status===`checking`?`Running ${e.check?.command??`the check`}…`:`Working…`}),!kE(e)&&!e.events.some(e=>e.kind===`tool`)&&(0,K.jsx)(`li`,{className:`pg-note`,children:`Answered without another tool call.`})]}),e.result?.text&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`h4`,{children:`Answer`}),(0,K.jsx)(`p`,{className:`pg-answer`,children:e.result.text})]}),e.result&&(0,K.jsx)(`p`,{className:`pg-note`,children:[e.result.turns!=null&&`${e.result.turns} turns`,e.result.duration_ms!=null&&`${Math.round(e.result.duration_ms/1e3)} s`,e.result.cost_usd!=null&&`≈ $${e.result.cost_usd.toFixed(4)} at API prices`].filter(Boolean).join(` · `)})]})]}),e.comparison&&(0,K.jsxs)(`section`,{className:`pg-files`,children:[(0,K.jsx)(`h3`,{children:`Files, original vs fork`}),f.length?(0,K.jsx)(`ul`,{children:f.map(t=>(0,K.jsxs)(_.Fragment,{children:[(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>s(o===t.path?null:t.path),"aria-expanded":o===t.path,children:[(0,K.jsx)(`span`,{className:`rt-file-status s-${t.status}`,children:{A:`only fork`,D:`only original`,M:`differs`}[t.status]??t.status}),(0,K.jsx)(`code`,{children:t.path}),(0,K.jsx)(`small`,{children:t.added==null?`binary`:`+${t.added} −${t.removed}`})]})}),o===t.path&&(0,K.jsx)(`li`,{children:(0,K.jsx)(zE,{fork:e,path:t.path})})]},t.path))}):(0,K.jsx)(`p`,{className:`pg-note`,children:e.comparison.fork?`Every file is the same.`:`The fork took no snapshot, so there is nothing to compare.`}),(e.attempts??1)===1&&(0,K.jsx)(`p`,{className:`pg-note`,children:`Models do not answer the same way twice: even a fork with nothing changed can word things differently. Run it more than once before reading much into one difference.`})]})]})}function VE(e){let t=e.filter(e=>!kE(e)&&e.status!==`cancelled`),n=e.filter(ME),r=n.filter(e=>e.check?.status===`passed`).length,i=e=>NE(t.map(e).filter(e=>typeof e==`number`));return{finished:t,checked:n,passed:r,rate:n.length?r/n.length:null,live:e.some(kE),cost:i(e=>e.result?.cost_usd),calls:i(e=>e.progress.tool_calls),time:i(e=>e.result?.duration_ms),differ:i(e=>e.comparison?.changes.length),same:t.filter(e=>e.comparison?.same_files).length}}function HE(e,t,n,r){let i=(e,t)=>{let n=1;for(let r=1;r<=t;r+=1)n=n*(e-t+r)/r;return n},a=e+t,o=e+n,s=a+n+r,c=e=>i(o,e)*i(s-o,a-e)/i(s,a),l=c(e),u=0;for(let e=Math.max(0,a-(s-o));e<=Math.min(a,o);e+=1){let t=c(e);t<=l*(1+1e-7)&&(u+=t)}return Math.min(1,u)}function UE({change:e,base:t,onShow:n}){let r=VE(e),i=VE(t),a=e=>e.rate==null?`—`:`${e.passed}/${e.checked.length}`,o;if(r.rate==null||i.rate==null)o=e[0].check?`Waiting for both sides to be checked…`:`No check, so there is no pass rate to compare: only how the runs went.`;else{let e=HE(r.passed,r.checked.length-r.passed,i.passed,i.checked.length-i.passed),t=r.live||i.live?` so far`:``;o=r.rate===i.rate?`Both passed ${Math.round(r.rate*100)}% of the time${t}: no sign the change made a difference to the check.`:`Your change passed ${r.rate>i.rate?`more`:`less`} often${t}: ${a(r)} against ${a(i)} unchanged. `+(r.live||i.live?``:e<.05?`A gap this large is unlikely to be luck.`:`At this many runs that could still be luck; more runs would tell.`)}let s=(e,t)=>(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{children:e}),(0,K.jsx)(`td`,{children:t(i)}),(0,K.jsx)(`td`,{children:t(r)})]}),c=(e,t)=>e==null?`—`:t(e);return(0,K.jsxs)(`section`,{className:`pg-baseline`,children:[(0,K.jsx)(`h3`,{children:`Against the step run unchanged`}),(0,K.jsx)(`p`,{className:`pg-baseline-verdict${r.rate!=null&&i.rate!=null&&!r.live&&!i.live?r.rate>i.rate?` good`:r.rate<i.rate?` bad`:``:``}`,children:o}),(0,K.jsxs)(`table`,{children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{scope:`col`,children:`Runs`}),(0,K.jsx)(`th`,{children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>n(t[0].id),children:[`Unchanged ×`,t.length]})}),(0,K.jsx)(`th`,{children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>n(e[0].id),children:[`Your change ×`,e.length]})})]})}),(0,K.jsxs)(`tbody`,{children:[s(`Check passed`,a),s(`Tool calls`,e=>c(e.calls,e=>String(Math.round(e)))),s(`Time`,e=>c(e.time,FE)),s(`Cost`,e=>c(e.cost,e=>`$${e.toFixed(4)}`)),s(`Same files as original`,e=>e.finished.length?`${e.same}/${e.finished.length}`:`—`)]})]}),(0,K.jsxs)(`p`,{className:`pg-note`,children:[`Medians over finished runs. Both started from the same point with the same check`,e[0].model===t[0].model?``:`; unchanged uses the original model, ${t[0].model}`,`.`]})]})}function WE({runs:e,shown:t,onShow:n,onChanged:r}){let[i,a]=(0,_.useState)(!1),{finished:o,checked:s,passed:c,rate:l,cost:u,calls:d,time:f,differ:p,same:m,live:h}=VE(e);return(0,K.jsxs)(`section`,{className:`pg-batch`,children:[(0,K.jsxs)(`header`,{children:[(0,K.jsxs)(`div`,{className:`pg-batch-rate`,children:[l==null?(0,K.jsxs)(`strong`,{children:[o.length,`/`,e.length,` runs done`]}):(0,K.jsxs)(`strong`,{className:l===1?`good`:l===0?`bad`:`mixed`,children:[c,`/`,s.length,` passed`]}),(0,K.jsx)(`small`,{children:l==null?e[0].check?`waiting for the first check`:`no check set, so no pass rate`:`the check, over ${s.length} of ${e.length} runs`})]}),(0,K.jsxs)(`dl`,{children:[d!=null&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:`Tool calls`}),(0,K.jsx)(`dd`,{children:Math.round(d)})]}),f!=null&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:`Time`}),(0,K.jsx)(`dd`,{children:FE(f)})]}),u!=null&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:`Cost`}),(0,K.jsxs)(`dd`,{children:[`$`,u.toFixed(4)]})]}),p!=null&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:`Files differ`}),(0,K.jsx)(`dd`,{children:Math.round(p)})]}),o.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:`Same files`}),(0,K.jsxs)(`dd`,{children:[m,`/`,o.length]})]})]}),h&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,disabled:i,onClick:async()=>{a(!0);try{await x().fetch(`/raytace/forks/${e[0].id}/stop-all`,{method:`POST`,headers:wE})}finally{a(!1),r()}},children:[(0,K.jsx)(be,{size:13}),` Stop all runs`]})]}),o.length>1&&(0,K.jsxs)(`p`,{className:`pg-note`,children:[`Typical run (median)`,u==null?``:`; cost at API prices`,`.`,l!=null&&l>0&&l<1?` Passing some of the time means the outcome depends on luck, not just on what you changed.`:``]}),(0,K.jsxs)(`table`,{className:`pg-batch-runs`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{children:`Run`}),(0,K.jsx)(`th`,{children:`Status`}),(0,K.jsx)(`th`,{children:`Check`}),(0,K.jsx)(`th`,{children:`Tool calls`}),(0,K.jsx)(`th`,{children:`Files differ`}),(0,K.jsx)(`th`,{children:`Time`}),(0,K.jsx)(`th`,{children:`Cost`})]})}),(0,K.jsx)(`tbody`,{children:e.map(e=>(0,K.jsxs)(`tr`,{className:e.id===t?`on`:``,onClick:()=>n(e.id),children:[(0,K.jsx)(`td`,{children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>n(e.id),"aria-pressed":e.id===t,children:[`#`,e.attempt??1]})}),(0,K.jsx)(`td`,{children:(0,K.jsx)(`span`,{className:`pg-status s-${e.status}`,children:AE[e.status]})}),(0,K.jsx)(`td`,{className:e.check?`c-${e.check.status}`:``,children:e.check?e.check.status===`passed`?`✓ passed`:e.check.status===`failed`?`✗ exit ${e.check.exit_code}`:e.check.status===`timed_out`?`✗ timed out`:e.check.status===`error`?`could not run`:`—`:`—`}),(0,K.jsx)(`td`,{children:e.status===`queued`||e.status===`cancelled`?`—`:e.progress.tool_calls}),(0,K.jsx)(`td`,{children:e.comparison?e.comparison.changes.length:`—`}),(0,K.jsx)(`td`,{children:FE(e.result?.duration_ms??null)||`—`}),(0,K.jsx)(`td`,{children:e.result?.cost_usd==null?`—`:`$${e.result.cost_usd.toFixed(4)}`})]},e.id))})]})]})}function GE({trace:e,stepId:t,removeCall:n,forkTraces:r,onStep:i,onOpenTrace:a}){let o=(0,_.useMemo)(()=>e.requests??[],[e.requests]),s=(0,_.useMemo)(()=>e.callVerifications??[],[e.callVerifications]),c=(0,_.useMemo)(()=>new Set(o.map(e=>e.id)),[o]),l=new Map(s.map((e,t)=>[e.call_id,t+1])),{forks:u,refresh:d}=LE(c),f=Pe(e),p=f.forkable&&t&&c.has(t)?t:null,m=p?o.findIndex(e=>e.id===p):-1,h=RE(p),[g,v]=(0,_.useState)(()=>n?{[n]:{mode:`remove`,text:EE}}:{}),[y,b]=(0,_.useState)(``),[S,C]=(0,_.useState)([]),[w,T]=(0,_.useState)(``),[E,D]=(0,_.useState)(``),[O,k]=(0,_.useState)(10),[A,j]=(0,_.useState)(1),[M,N]=(0,_.useState)(!0),[P,F]=(0,_.useState)(null),[I,L]=(0,_.useState)([]),[R,z]=(0,_.useState)(!1),[ee,B]=(0,_.useState)(``),[V,H]=(0,_.useState)(null),te=(0,_.useRef)(null);(0,_.useEffect)(()=>{if(!h?.forkable||!h.sandbox||!h.start_snapshot)return;let e=!1;return x().fetch(`/raytace/snapshots/${h.sandbox}/files?commit=${h.start_snapshot}`).then(async t=>{let n=await t.json();!e&&t.ok&&L(n.files??[])}).catch(()=>{}),()=>{e=!0}},[h]);let U=e=>(h?.results??[]).filter(t=>{let n=e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return RegExp(`(^|[\\s'"=:(])(/workspace/)?${n}($|[\\s'";|&)<>])`).test(t.detail)}),ne=new Map(S.flatMap(e=>U(e).map(t=>[t.call_id,e])));function re(){let e=w.trim().replace(/^\/workspace\//,``).replace(/^\.\//,``);e&&!S.includes(e)&&C(t=>[...t,e]),T(``)}async function ae(){if(p){z(!0),B(``);try{let e=Object.fromEntries(Object.entries(g).map(([e,t])=>[e,t.text])),t=Object.fromEntries([...ne.keys()].filter(t=>!(t in e)).map(e=>[e,EE])),n=await x().fetch(`/raytace/forks`,{method:`POST`,headers:wE,body:JSON.stringify({exchange_id:p,model:E||h?.model,minutes:O,message:y,check:se,repeat:A,baseline:M&&he.length>0,exclude:S,results:{...t,...e}})}),r=await n.json();if(!n.ok)throw Error(r.error??`The fork could not start.`);H(r.id),await d()}catch(e){B(e instanceof Error?e.message:`The fork could not start.`)}finally{z(!1)}}}let oe=u.some(kE),se=(P??u.find(e=>e.parent===h?.sandbox&&e.check)?.check?.command??``).trim(),ce=[...u.filter(e=>e.exchange_id===p).reduce((e,t)=>{let n=t.group??t.id;return e.set(n,[...e.get(n)??[],t].sort((e,t)=>(e.attempt??1)-(t.attempt??1))),e},new Map).values()],le=ce.find(e=>e.some(e=>e.id===V))??ce[0]??null,ue=ce.filter(e=>e[0].unchanged&&e[0].model===h?.model&&(e[0].check?.command??``)===se&&e.filter(e=>[`completed`,`failed`].includes(e.status)).length>=A).sort((e,t)=>t.length-e.length)[0]??null,de=e=>e?.[0].baseline?ce.find(t=>t[0].group===e[0].baseline)??null:null,pe=le?.find(e=>e.id===V)??le?.find(e=>kE(e)&&e.status!==`queued`)??le?.[0]??null,me=E||h?.model||``,he=[y.trim()&&`a message`,S.length&&`${S.length} file${S.length===1?``:`s`} excluded`,Object.keys(g).length&&`${Object.keys(g).length} tool result${Object.keys(g).length===1?``:`s`} edited`,me&&me!==h?.model&&me].filter(Boolean);return(0,K.jsxs)(`section`,{className:`rt-view`,children:[(0,K.jsx)(`header`,{className:`rt-view-head`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`eyebrow`,children:`PLAYGROUND`}),(0,K.jsx)(`h1`,{children:`Rerun it from any step`}),(0,K.jsxs)(`p`,{className:`rt-muted rt-sub`,children:[DE(e.title,120),` · `,OE(e.startedAt)]})]})}),(0,K.jsxs)(`div`,{className:`pg-layout`,ref:te,children:[(0,K.jsxs)(`nav`,{className:`pg-rounds`,"aria-label":`Steps`,children:[(0,K.jsx)(`h2`,{children:`1 · Pick a step`}),(0,K.jsx)(`ol`,{children:o.map((e,t)=>{let n=s.filter(t=>t.exchange_id===e.id),r=u.filter(t=>t.exchange_id===e.id).length;return(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,className:e.id===p?`on`:``,onClick:()=>i(e.id),disabled:!f.forkable,children:[(0,K.jsxs)(`span`,{children:[`Round trip `,t+1,r?(0,K.jsxs)(`em`,{children:[r,` fork`,r===1?``:`s`]}):null]}),n.length?n.map(e=>(0,K.jsxs)(`code`,{children:[`#`,l.get(e.call_id),` `,e.name,` `,DE(e.proposed??``,60)]},e.call_id)):(0,K.jsx)(`small`,{children:`answered`})]})},e.id)})}),(0,K.jsx)(CE,{target:te,variable:`--pg-steps`,storageKey:`raytace.playground-steps-width`,min:220,max:760,label:`Steps width`})]}),(0,K.jsxs)(`div`,{className:`pg-main`,children:[!f.forkable&&(0,K.jsxs)(`div`,{className:`pg-unforkable`,role:`note`,children:[(0,K.jsx)(`strong`,{children:f.where===`mac`?`This run can’t be forked`:f.where===`fork`?`This is a fork`:`Not forkable yet`}),(0,K.jsx)(`p`,{children:f.reason})]}),f.forkable&&!p&&(0,K.jsx)(`p`,{className:`rt-empty`,children:`Pick the step to rerun from. Everything before it stays as it was; from it on, the model decides again.`}),p&&!h&&(0,K.jsx)(`p`,{className:`rt-empty`,children:`Checking whether this step can be forked…`}),p&&h&&!h.forkable&&(0,K.jsx)(`p`,{className:`pg-error`,children:h.reason}),p&&h?.forkable&&(0,K.jsxs)(`section`,{className:`pg-change`,children:[(0,K.jsxs)(`h2`,{children:[`2 · Change what it had `,(0,K.jsxs)(`small`,{children:[`then round trip `,m+1,` onward runs again, in its own sandbox`]})]}),(0,K.jsx)(`h3`,{children:`Message at this step`}),(0,K.jsx)(`textarea`,{className:`pg-message`,rows:3,value:y,maxLength:4e3,"aria-label":`Message the model gets at this step`,placeholder:`Optional. e.g. Don't use demo/package.json, read demo2/package.json instead.`,onChange:e=>b(e.target.value)}),(0,K.jsx)(`p`,{className:`pg-note`,children:y.trim()?`The fork resumes with this as your next message.`:`Empty: it resumes with only “${h.resume_prompt}”`}),(0,K.jsx)(`h3`,{children:`Exclude files`}),(0,K.jsxs)(`form`,{className:`pg-file-pick`,onSubmit:e=>{e.preventDefault(),re()},children:[(0,K.jsx)(`input`,{list:`pg-project-files`,value:w,placeholder:`path/to/file, as in the project`,"aria-label":`File to exclude`,onChange:e=>T(e.target.value)}),(0,K.jsx)(`datalist`,{id:`pg-project-files`,children:I.slice(0,2e3).map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))}),(0,K.jsx)(`button`,{type:`submit`,className:`rt-button`,disabled:!w.trim(),children:`Exclude`})]}),S.length>0&&(0,K.jsx)(`ul`,{className:`pg-excluded`,children:S.map(e=>{let t=U(e),n=!I.length||I.includes(e);return(0,K.jsxs)(`li`,{children:[(0,K.jsx)(`code`,{children:e}),(0,K.jsxs)(`span`,{children:[t.length?`output of ${t.map(e=>`#${l.get(e.call_id)??`?`}`).join(`, `)} removed · `:``,n?`not in the fork’s project`:`not in the project at this step`]}),(0,K.jsx)(`button`,{type:`button`,"aria-label":`Stop excluding ${e}`,onClick:()=>C(t=>t.filter(t=>t!==e)),children:(0,K.jsx)(Te,{size:12})})]},e)})}),(0,K.jsx)(`p`,{className:`pg-note`,children:`An excluded file is taken out of the fork’s copy of the project, and anything it had already read of it is removed from what it remembers, so it can’t just read it again.`}),(0,K.jsxs)(`h3`,{children:[`Check `,(0,K.jsx)(`small`,{children:`how to tell whether it worked`})]}),(0,K.jsx)(`input`,{className:`pg-check-input`,value:P??se,maxLength:2e3,spellCheck:!1,"aria-label":`Check command`,placeholder:`Optional. e.g. npm test, or: grep -q fetchUser src/api.ts`,onChange:e=>F(e.target.value)}),(0,K.jsx)(`p`,{className:`pg-note`,children:se?`Runs in the fork’s project folder once Claude Code finishes. Exit code 0 passes; anything else fails.`:`Empty: the fork is only compared file by file with the original.`}),(0,K.jsxs)(`div`,{className:`pg-run-bar`,children:[(0,K.jsxs)(`label`,{children:[`Model `,(0,K.jsx)(`select`,{value:me,onChange:e=>D(e.target.value),children:[...new Set([h.model,...TE].filter(Boolean))].map(e=>(0,K.jsxs)(`option`,{value:e,children:[e,e===h.model?` (original)`:``]},e))})]}),(0,K.jsxs)(`label`,{children:[`Runs `,(0,K.jsx)(`select`,{value:A,onChange:e=>j(Number(e.target.value)),children:jE.filter(e=>e<=(h.limits?.max_repeat??1/0)).map(e=>(0,K.jsx)(`option`,{value:e,children:e===1?`once`:`${e} times`},e))})]}),(0,K.jsxs)(`button`,{type:`button`,className:`pg-run-button`,onClick:ae,disabled:R||oe,children:[(0,K.jsx)(fe,{size:14}),` `,oe?`A fork is running`:R?`Starting…`:`${he.length?`Run fork · ${he.join(`, `)}`:`Run fork unchanged`}${A>1?` · ×${A}`:``}${M&&he.length&&!ue?` + unchanged ×${A}`:``}`]})]}),he.length>0&&(0,K.jsxs)(`label`,{className:`pg-baseline-pick`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:M,onChange:e=>N(e.target.checked)}),ue?(()=>{let e=VE(ue);return`Compare with the unchanged runs already done (×${ue.length}${e.rate==null?``:`, ${e.passed}/${e.checked.length} passed`})`})():`Also run it unchanged ×${A} to compare with, taking turns with your change`]}),A>1&&(0,K.jsxs)(`p`,{className:`pg-note`,children:[`Runs one after another, each from the same point`,se?`, each graded by the check`:``,`. `,se?``:`Without a check there is no pass rate, only how the runs compare. `,he.length&&M?``:`Tip: running it unchanged the same number of times shows how much it varies on its own.`]}),y.trim()&&S.length>0&&(0,K.jsx)(`p`,{className:`pg-note`,children:`This run both steers it and removes files: if it ends differently, you won’t know which of the two did it.`}),ee&&(0,K.jsx)(`p`,{role:`alert`,className:`pg-error`,children:ee}),(0,K.jsxs)(`details`,{className:`pg-advanced`,open:!!n||void 0,children:[(0,K.jsx)(`summary`,{children:`Advanced`}),(0,K.jsx)(`h3`,{children:`Tool results it had seen`}),h.results?.length?(0,K.jsx)(`ul`,{className:`pg-results`,children:h.results.map(e=>{let t=g[e.call_id],n=!t&&ne.has(e.call_id);return(0,K.jsxs)(`li`,{className:t?`edited ${t.mode}`:n?`edited remove`:``,children:[(0,K.jsxs)(`div`,{className:`pg-result-row`,children:[(0,K.jsxs)(`b`,{children:[`#`,l.get(e.call_id)??`?`,` `,e.name]}),(0,K.jsx)(`code`,{title:e.detail,children:DE(e.detail,90)}),(0,K.jsx)(`small`,{children:n?`removed with ${ne.get(e.call_id)}`:`~${Math.round(e.chars/4).toLocaleString()} tokens`}),(0,K.jsx)(`span`,{className:`rt-actions`,children:t?(0,K.jsxs)(`button`,{type:`button`,className:`link-button`,onClick:()=>v(({[e.call_id]:t,...n})=>n),children:[(0,K.jsx)(Te,{size:12}),` Undo`]}):(0,K.jsxs)(K.Fragment,{children:[!n&&(0,K.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>v(t=>({...t,[e.call_id]:{mode:`remove`,text:EE}})),children:`Remove`}),!e.truncated&&(0,K.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>v(t=>({...t,[e.call_id]:{mode:`edit`,text:e.output}})),children:`Edit`})]})})]}),t&&(0,K.jsx)(`textarea`,{"aria-label":`What ${e.name} returns in the fork`,value:t.text,rows:t.mode===`remove`?1:8,onChange:t=>{let n=t.target.value;v(t=>({...t,[e.call_id]:{...t[e.call_id],text:n}}))}})]},e.call_id)})}):(0,K.jsx)(`p`,{className:`pg-note`,children:`No tool results before this step: it comes straight after the prompt.`}),(0,K.jsxs)(`label`,{className:`pg-limit`,children:[`Safety limit `,(0,K.jsx)(`select`,{value:O,onChange:e=>k(Number(e.target.value)),children:[5,10,20,30].filter(e=>e<=(h.limits?.max_minutes??1/0)).map(e=>(0,K.jsxs)(`option`,{value:e,children:[e,` min`]},e))}),(0,K.jsx)(`span`,{className:`pg-note`,children:`The fork ends when Claude Code finishes; this only stops one that runs away.`})]})]})]}),p&&(0,K.jsxs)(`section`,{className:`pg-runs`,children:[(0,K.jsxs)(`h2`,{children:[`3 · Runs `,ce.length>1&&(0,K.jsxs)(`small`,{children:[ce.length,` from this step`]})]}),ce.length>1&&(0,K.jsx)(`div`,{className:`pg-run-tabs`,children:ce.map((e,t)=>{let n=e.filter(ME),r=e.length>1?n.length?` · ${n.filter(e=>e.check?.status===`passed`).length}/${n.length} ✓`:``:ME(e[0])?` · ${e[0].check?.status===`passed`?`✓`:`✗`}`:``;return(0,K.jsxs)(`button`,{type:`button`,className:e===le?`on`:``,onClick:()=>H(e[0].id),children:[(0,K.jsx)(ie,{size:12}),` `,ce.length-t,e[0].unchanged?` · unchanged`:``,e.length>1?` · ×${e.length}`:``,` · `,e.some(kE)?`Running`:AE[e[0].status],r,e.some(e=>e.keep)?` · kept`:``]},e[0].id)})}),le&&de(le)&&(0,K.jsx)(UE,{change:le,base:de(le),onShow:H}),le&&le.length>1&&(0,K.jsx)(WE,{runs:le,shown:pe?.id??null,onShow:H,onChanged:d}),pe?(0,K.jsx)(BE,{fork:pe,trace:e,fromIndex:m,onChanged:d,onOpenTrace:a,forkTrace:r.filter(e=>e.forkId===pe.id).at(0)??null},pe.id):(0,K.jsx)(`p`,{className:`pg-note`,children:`No forks from this step yet.`})]})]})]})]})}var KE=53,qE=[``,`Mon`,``,`Wed`,``,`Fri`,``];function JE(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}`}var YE=()=>()=>{},XE=()=>JE(Date.now()),ZE=e=>e===0?0:e===1?1:e<=3?2:e<=6?3:4;function QE({dates:e,selected:t,onSelect:n}){let r=(0,_.useSyncExternalStore)(YE,XE,()=>null),i=new Map;for(let t of e)i.set(JE(t),(i.get(JE(t))??0)+1);let a=new Date(`${r??`1970-01-01`}T00:00`),o=new Date(a);o.setDate(a.getDate()-a.getDay()-364);let s=[];for(let e=0;e<KE;e+=1){let t=[];for(let n=0;n<7;n+=1){let r=new Date(o);r.setDate(o.getDate()+e*7+n),t.push(r)}s.push(t)}let c=s.map((e,t)=>{let n=e.find(e=>e.getDate()===1);return n||t===0?(n??e[0]).toLocaleString(void 0,{month:`short`}):``}),l=e.length,u=[...i.keys()].length;return(0,K.jsxs)(`section`,{className:`rt-activity`,"aria-label":`Prompts per day`,children:[(0,K.jsxs)(`div`,{className:`rt-activity-head`,children:[(0,K.jsxs)(`strong`,{children:[l,` prompt`,l===1?``:`s`]}),(0,K.jsxs)(`span`,{children:[`on `,u,` day`,u===1?``:`s`,` in the last year`]})]}),r&&(0,K.jsx)(`div`,{className:`rt-activity-scroll`,children:(0,K.jsxs)(`div`,{className:`rt-activity-grid`,style:{gridTemplateColumns:`28px repeat(${KE}, 12px)`},children:[(0,K.jsx)(`span`,{}),c.map((e,t)=>(0,K.jsx)(`span`,{className:`rt-activity-month`,children:e},t)),qE.map((e,r)=>[(0,K.jsx)(`span`,{className:`rt-activity-day`,children:e},`label-${r}`),...s.map(e=>{let o=e[r];if(o>a)return(0,K.jsx)(`span`,{},JE(o));let s=JE(o),c=i.get(s)??0,l=`${c} prompt${c===1?``:`s`} · ${o.toLocaleDateString(void 0,{day:`numeric`,month:`short`,year:`numeric`})}`;return(0,K.jsx)(`button`,{type:`button`,title:l,"aria-label":l,"aria-pressed":t===s,disabled:!c,className:`rt-cell rt-cell-${ZE(c)}${t===s?` rt-cell-on`:``}`,onClick:()=>n(t===s?null:s)},s)})])]})}),(0,K.jsxs)(`div`,{className:`rt-activity-legend`,children:[`Less `,[0,1,2,3,4].map(e=>(0,K.jsx)(`i`,{className:`rt-cell rt-cell-${e}`},e)),` More`]})]})}var $E=e=>e.split(`
31
- `).find(e=>e.trim())?.trim()??`(empty prompt)`;function eD({traces:e,loaded:t=!0,selectedId:n,onSelect:r,onOpen:i,onOpenStep:a,canOpen:o=()=>!0}){let[s,c]=(0,_.useState)(null),l=e.filter(e=>!s||JE(e.startedAt)===s).sort((e,t)=>t.startedAt.localeCompare(e.startedAt));return(0,K.jsxs)(`section`,{className:`rt-view`,children:[(0,K.jsx)(`header`,{className:`rt-view-head`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`eyebrow`,children:`PROMPTS`}),(0,K.jsx)(`h1`,{children:`What you asked`})]})}),(0,K.jsx)(QE,{dates:e.map(e=>e.startedAt),selected:s,onSelect:c}),(0,K.jsxs)(`div`,{className:`rt-list-head`,children:[s?(0,K.jsxs)(`button`,{type:`button`,className:`rt-chip`,onClick:()=>c(null),children:[new Date(`${s}T00:00`).toLocaleDateString(void 0,{weekday:`short`,day:`numeric`,month:`short`}),` `,(0,K.jsx)(Te,{size:12})]}):(0,K.jsx)(`span`,{children:`Recent`}),(0,K.jsxs)(`small`,{children:[l.length,` prompt`,l.length===1?``:`s`]})]}),!l.length&&(0,K.jsx)(`p`,{className:`rt-empty`,children:t?`No prompts captured yet. Send a request through the proxy and it will appear here.`:`Loading…`}),(0,K.jsx)(`ol`,{className:`rt-prompts`,children:l.map(e=>{let t=e.id===n,s=Ae(e.requests,`cost`),c=e.callVerifications?.length??0,l=Pe(e);return(0,K.jsxs)(`li`,{className:t?`rt-prompt open`:`rt-prompt`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`rt-prompt-row`,"aria-expanded":t,onClick:()=>r(t?``:e.id),children:[(0,K.jsx)(`time`,{dateTime:e.startedAt,children:new Date(e.startedAt).toLocaleString(void 0,{day:`numeric`,month:`short`,hour:`numeric`,minute:`2-digit`})}),(0,K.jsxs)(`strong`,{children:[(0,K.jsx)(`span`,{className:`rt-where w-${l.where}`,title:l.forkable?`Ran in the sandbox: can be forked in the Playground`:l.reason??void 0,children:l.label}),$E(e.title)]}),(0,K.jsxs)(`small`,{children:[e.model,` · `,c,` tool call`,c===1?``:`s`,` · `,id(s,e.requests?.some(e=>e.costEstimated))]})]}),t&&(0,K.jsxs)(`div`,{className:`rt-prompt-detail`,children:[(0,K.jsx)(`h3`,{children:`Prompt`}),(0,K.jsx)(`p`,{className:`rt-text`,children:e.title}),(0,K.jsx)(`h3`,{children:`Answer`}),e.answer?(0,K.jsx)(`p`,{className:`rt-text`,children:e.answer}):(0,K.jsx)(`p`,{className:`rt-muted`,children:`No final answer was captured for this prompt.`}),(0,K.jsx)(YT,{trace:e,onStep:a&&(t=>a(e.id,t))}),(0,K.jsxs)(`div`,{className:`rt-actions`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>i(`calls`,e.id),children:[`Tool calls `,(0,K.jsx)(P,{size:14})]}),e.sandboxId&&o(`sandbox`)&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>i(`sandbox`,e.id),children:[`Sandbox evidence `,(0,K.jsx)(P,{size:14})]}),o(`context`)&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>i(`context`,e.id),children:[`Context `,(0,K.jsx)(P,{size:14})]})]})]})]},e.id)})})]})}var tD=[{id:`24h`,label:`Last 24h`,ms:864e5},{id:`7d`,label:`Last 7d`,ms:6048e5},{id:`30d`,label:`Last 30d`,ms:2592e6},{id:`all`,label:`All time`,ms:null}],nD=[`outcome:failed`,`reported:ok observed:failed`,`exit:127`,`http:>=400`,`failed | stats count by tool`,`failed | timechart count by model span=1d`],rD=[`#8a8f98`,`#b03a48`,`#13549b`,`#9e6514`,`#29996b`,`#5b4bc4`,`#33373d`,`#c06a2b`,`#777d87`];function iD(e){return e.split(/(\[[^\]]*\])/g).map((e,t)=>e.startsWith(`[`)&&e.endsWith(`]`)?(0,K.jsx)(`mark`,{children:e.slice(1,-1)},t):(0,K.jsx)(`span`,{children:e},t))}function aD(e,t,n){let r=RegExp(`(^|\\s)-?${t}:(\\S+)`,`g`);return`${e.replace(r,` `).replace(/\s+/g,` `).trim()} ${t}:${n}`.trim()}var oD=e=>new Date(e).toLocaleString(void 0,{day:`numeric`,month:`short`,hour:`numeric`,minute:`2-digit`}),sD=e=>new Date(e).toLocaleDateString(void 0,{day:`numeric`,month:`short`});function cD({rows:e,series:t,height:n=110,onBucket:r}){let i=Math.max(...e.map(e=>t.reduce((t,n)=>t+(e[n.key]??0),0)),1),a=702/Math.max(e.length,1),o=Math.max(Math.min(a-2,42),1),s=n-22;return(0,K.jsxs)(`svg`,{viewBox:`0 0 720 ${n}`,width:`100%`,height:n,"aria-label":`Events over time`,children:[(0,K.jsx)(`title`,{children:`Events over time`}),e.map((c,l)=>{let u=s,d=t.reduce((e,t)=>e+(c[t.key]??0),0);return(0,K.jsxs)(`g`,{onClick:r?()=>r(c.t):void 0,style:r?{cursor:`pointer`}:void 0,children:[(0,K.jsx)(`title`,{children:`${sD(c.t)} — ${d} events`}),t.map(e=>{let t=(c[e.key]??0)/i*s;return u-=t,t>0?(0,K.jsx)(`rect`,{x:18+l*a+(a-o)/2,y:u,width:o,height:t,fill:e.color},e.key):null}),(l===0||l===e.length-1||l===Math.floor(e.length/2))&&(0,K.jsx)(`text`,{x:18+l*a+a/2,y:n-4,textAnchor:`middle`,fontSize:`10`,fill:`currentColor`,opacity:`0.55`,children:sD(c.t)})]},l)})]})}function lD({initialQuery:e=``,onQuery:t,onOpenCall:n,onOpenTrace:r,onOpenSandbox:i}){let[a,o]=(0,_.useState)(e),[s,c]=(0,_.useState)(e),[l,u]=(0,_.useState)(`7d`),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(0),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)([]),[b,S]=(0,_.useState)(null),[C,w]=(0,_.useState)(!0),T=(0,_.useRef)(0),E=(0,_.useCallback)(()=>{if(l===`custom`&&d)return d;let e=tD.find(e=>e.id===l);return e?.ms?{from:Date.now()-e.ms,to:Date.now()}:{from:null,to:null}},[l,d]),D=(0,_.useCallback)(async(e=!1)=>{let t=++T.current;e||w(!0);let{from:n,to:r}=E(),i=new URLSearchParams({q:s,limit:`50`,offset:String(p)});n&&i.set(`from`,String(n)),r&&i.set(`to`,String(r));let a=new URLSearchParams({limit:`12`});n&&a.set(`from`,String(n)),r&&a.set(`to`,String(r));try{let[e,n]=await Promise.all([x().fetch(`/raytace/search?${i}`,{cache:`no-store`}),x().fetch(`/raytace/search/signatures?${a}`,{cache:`no-store`})]);if(t!==T.current)return;if(!e.ok)throw Error((await e.json().catch(()=>({}))).error??`Search returned ${e.status}`);g(await e.json()),n.ok&&y((await n.json()).signatures??[]),S(null)}catch(e){t===T.current&&S(e instanceof Error?e.message:`Search unavailable. Is the proxy running?`)}finally{t===T.current&&w(!1)}},[s,p,E]);(0,_.useEffect)(()=>{D()},[D]),(0,_.useEffect)(()=>{let e=setInterval(()=>void D(!0),15e3);return()=>clearInterval(e)},[D]);function O(e){o(e),c(e),m(0),t(e)}let k=h?.summary,A=(h?.histogram??[]).map(e=>({...e,other:Math.max(e.total-e.failed,0)})),j=A.length>1?A[1].t-A[0].t:864e5;return(0,K.jsxs)(`section`,{className:`rt-view rt-search-view`,children:[(0,K.jsx)(`header`,{className:`rt-view-head`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`eyebrow`,children:`SEARCH`}),(0,K.jsx)(`h1`,{children:`What the agents did`})]})}),(0,K.jsxs)(`form`,{className:`rt-search-bar`,onSubmit:e=>{e.preventDefault(),O(a)},children:[(0,K.jsx)(ge,{size:16}),(0,K.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),placeholder:`outcome:failed tool:Bash "permission denied" · try failed | stats count by tool`,"aria-label":`Search agent activity`,spellCheck:!1}),a&&(0,K.jsx)(`button`,{type:`button`,className:`rt-search-clear`,onClick:()=>O(``),"aria-label":`Clear search`,children:(0,K.jsx)(Te,{size:14})}),(0,K.jsxs)(`select`,{value:l,onChange:e=>{u(e.target.value),f(null),m(0)},"aria-label":`Time range`,children:[l===`custom`&&(0,K.jsx)(`option`,{value:`custom`,children:`Selected window`}),tD.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.label},e.id))]}),(0,K.jsx)(`button`,{type:`submit`,className:`rt-button primary`,children:`Search`})]}),(0,K.jsxs)(`div`,{className:`rt-search-quick`,children:[nD.map(e=>(0,K.jsx)(`button`,{type:`button`,className:`rt-chip`,onClick:()=>O(e),children:(0,K.jsx)(`code`,{children:e})},e)),l===`custom`&&d&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-chip`,onClick:()=>{u(`7d`),f(null)},children:[oD(new Date(d.from).toISOString()),` – `,oD(new Date(d.to).toISOString()),` `,(0,K.jsx)(Te,{size:12})]})]}),b&&(0,K.jsx)(`p`,{className:`rt-search-error`,children:b}),(h?.errors??[]).map(e=>(0,K.jsx)(`p`,{className:`rt-search-error`,children:e},e)),h?.error&&(0,K.jsx)(`p`,{className:`rt-search-error`,children:h.error}),h?.mode===`events`&&k&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`rt-search-summary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`strong`,{children:k.total}),(0,K.jsx)(`span`,{children:`events`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`strong`,{className:`rt-failed-text`,children:k.failed}),(0,K.jsx)(`span`,{children:`failed`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`strong`,{children:k.mismatched}),(0,K.jsx)(`span`,{children:`reported ≠ observed`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`strong`,{children:k.http_errors}),(0,K.jsx)(`span`,{children:`HTTP errors`})]}),(0,K.jsxs)(`small`,{children:[h.total,` match`,h.total===1?``:`es`,` the full query`]})]}),A.length>0&&(0,K.jsxs)(`div`,{className:`rt-search-chart`,children:[(0,K.jsx)(cD,{rows:A,height:110,series:[{key:`other`,color:`#c3c7cd`,label:`ok / unknown`},{key:`failed`,color:`#b03a48`,label:`failed`}],onBucket:e=>{f({from:e,to:e+j-1}),u(`custom`),m(0)}}),(0,K.jsx)(`small`,{children:`Grey ok/unknown, red failed. Click a bar to zoom to that window.`})]}),!s&&v.length>0&&(0,K.jsxs)(`div`,{className:`rt-search-clusters`,children:[(0,K.jsxs)(`div`,{className:`rt-list-head`,children:[(0,K.jsx)(`span`,{children:`TOP FAILURE CLUSTERS`}),(0,K.jsx)(`small`,{children:`repeat failures, grouped by signature`})]}),(0,K.jsx)(`ol`,{children:v.map(e=>(0,K.jsxs)(`li`,{children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>O(`signature:${e.signature}`),children:[(0,K.jsxs)(`strong`,{children:[`×`,e.count]}),(0,K.jsx)(`span`,{className:`rt-cluster-label`,children:e.label??e.signature}),(0,K.jsxs)(`small`,{children:[e.tools.join(`, `),e.exit_codes.length?` · exit ${e.exit_codes.join(`/`)}`:``,` · last `,oD(e.last)]})]}),e.sample_turn&&(0,K.jsxs)(`button`,{type:`button`,className:`link-button`,onClick:()=>e.sample_call?n(e.sample_turn,e.sample_call):r(e.sample_turn),children:[`latest example `,(0,K.jsx)(P,{size:11})]})]},e.signature))})]}),(0,K.jsxs)(`div`,{className:`rt-search-body`,children:[(0,K.jsx)(`aside`,{className:`rt-search-facets`,children:Object.entries(h.facets??{}).map(([e,t])=>t.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{children:e.replace(`_`,` `)}),t.map(t=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>O(aD(s,e===`tool`?`tool`:e,t.value)),children:[(0,K.jsx)(`span`,{children:t.value}),(0,K.jsx)(`small`,{children:t.count})]},t.value))]},e))}),(0,K.jsxs)(`div`,{className:`rt-search-results`,children:[(0,K.jsxs)(`div`,{className:`rt-list-head`,children:[(0,K.jsx)(`span`,{children:`EVENTS`}),(0,K.jsx)(`small`,{children:C?`Searching…`:`${h.hits?.length??0} shown`})]}),!C&&!(h.hits??[]).length&&(0,K.jsx)(`p`,{className:`rt-empty`,children:`Nothing matches. Missing evidence reads as unknown, never as success — try widening the time range.`}),(0,K.jsx)(`ol`,{children:(h.hits??[]).map(e=>(0,K.jsxs)(`li`,{className:`rt-hit outcome-${e.outcome}`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`rt-hit-main`,disabled:!e.turn_id,onClick:()=>{e.turn_id&&e.external_call_id?n(e.turn_id,e.external_call_id):e.turn_id&&r(e.turn_id)},children:[(0,K.jsx)(`time`,{dateTime:e.ts,children:oD(e.ts)}),(0,K.jsx)(`span`,{className:`rt-outcome outcome-${e.outcome}`,children:e.outcome}),(0,K.jsx)(`strong`,{children:e.kind===`turn`?`prompt`:e.kind===`proxy_error`?`proxy error`:`${e.tool_name??`tool`}${e.category?` · ${e.category}`:``}`}),(0,K.jsx)(`span`,{className:`rt-hit-text`,children:e.snippet?iD(e.snippet):e.command_text??e.prompt_excerpt??e.error_excerpt??``}),(0,K.jsxs)(`small`,{children:[e.model??``,e.exit_code==null?``:` · exit ${e.exit_code}`,e.http_status?` · HTTP ${e.http_status}`:``,e.kind===`call`?` · reported ${e.outcome_reported} · observed ${e.outcome_observed}`:``,e.reported_check&&e.reported_check!==`agrees`?` · ${e.reported_check.replaceAll(`_`,` `)}`:``,e.duration_ms==null?``:` · ${(e.duration_ms/1e3).toFixed(1)}s`]}),e.error_excerpt&&e.outcome===`failed`&&(0,K.jsx)(`span`,{className:`rt-hit-error`,children:e.signature_label??e.error_excerpt.split(`
31
+ `).find(e=>e.trim())?.trim()??`(empty prompt)`;function eD({traces:e,loaded:t=!0,box:n=``,onBox:r,selectedId:i,onSelect:a,onOpen:o,onOpenStep:s,canOpen:c=()=>!0}){let[l,u]=(0,_.useState)(null),d=n?e.filter(e=>e.sandboxId===n):e,f=d.filter(e=>!l||JE(e.startedAt)===l).sort((e,t)=>t.startedAt.localeCompare(e.startedAt));return(0,K.jsxs)(`section`,{className:`rt-view`,children:[(0,K.jsx)(`header`,{className:`rt-view-head`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`eyebrow`,children:`PROMPTS`}),(0,K.jsx)(`h1`,{children:`What you asked`})]})}),(0,K.jsx)(QE,{dates:d.map(e=>e.startedAt),selected:l,onSelect:u}),(0,K.jsxs)(`div`,{className:`rt-list-head`,children:[(0,K.jsxs)(`span`,{className:`rt-chips`,children:[n&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-chip`,title:`Show prompts from everywhere`,onClick:()=>r?.(``),children:[`Sandbox `,n,` `,(0,K.jsx)(Te,{size:12})]}),l?(0,K.jsxs)(`button`,{type:`button`,className:`rt-chip`,onClick:()=>u(null),children:[new Date(`${l}T00:00`).toLocaleDateString(void 0,{weekday:`short`,day:`numeric`,month:`short`}),` `,(0,K.jsx)(Te,{size:12})]}):!n&&(0,K.jsx)(`span`,{children:`Recent`})]}),(0,K.jsxs)(`small`,{children:[f.length,` prompt`,f.length===1?``:`s`]})]}),!f.length&&(0,K.jsx)(`p`,{className:`rt-empty`,children:t?n?`No prompts from this sandbox yet. Ask Claude Code something in it and it will appear here.`:`No prompts captured yet. Send a request through the proxy and it will appear here.`:`Loading…`}),(0,K.jsx)(`ol`,{className:`rt-prompts`,children:f.map(e=>{let t=e.id===i,n=Ae(e.requests,`cost`),r=e.callVerifications?.length??0,l=Pe(e);return(0,K.jsxs)(`li`,{className:t?`rt-prompt open`:`rt-prompt`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`rt-prompt-row`,"aria-expanded":t,onClick:()=>a(t?``:e.id),children:[(0,K.jsx)(`time`,{dateTime:e.startedAt,children:new Date(e.startedAt).toLocaleString(void 0,{day:`numeric`,month:`short`,hour:`numeric`,minute:`2-digit`})}),(0,K.jsxs)(`strong`,{children:[(0,K.jsx)(`span`,{className:`rt-where w-${l.where}`,title:l.forkable?`Ran in the sandbox: can be forked in the Playground`:l.reason??void 0,children:l.label}),$E(e.title)]}),(0,K.jsxs)(`small`,{children:[e.model,` · `,r,` tool call`,r===1?``:`s`,` · `,id(n,e.requests?.some(e=>e.costEstimated))]})]}),t&&(0,K.jsxs)(`div`,{className:`rt-prompt-detail`,children:[(0,K.jsx)(`h3`,{children:`Prompt`}),(0,K.jsx)(`p`,{className:`rt-text`,children:e.title}),(0,K.jsx)(`h3`,{children:`Answer`}),e.answer?(0,K.jsx)(`p`,{className:`rt-text`,children:e.answer}):(0,K.jsx)(`p`,{className:`rt-muted`,children:`No final answer was captured for this prompt.`}),(0,K.jsx)(YT,{trace:e,onStep:s&&(t=>s(e.id,t))}),(0,K.jsxs)(`div`,{className:`rt-actions`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>o(`calls`,e.id),children:[`Tool calls `,(0,K.jsx)(P,{size:14})]}),e.sandboxId&&c(`sandbox`)&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>o(`sandbox`,e.id),children:[`Sandbox evidence `,(0,K.jsx)(P,{size:14})]}),c(`context`)&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>o(`context`,e.id),children:[`Context `,(0,K.jsx)(P,{size:14})]})]})]})]},e.id)})})]})}var tD=[{id:`24h`,label:`Last 24h`,ms:864e5},{id:`7d`,label:`Last 7d`,ms:6048e5},{id:`30d`,label:`Last 30d`,ms:2592e6},{id:`all`,label:`All time`,ms:null}],nD=[`outcome:failed`,`reported:ok observed:failed`,`exit:127`,`http:>=400`,`failed | stats count by tool`,`failed | timechart count by model span=1d`],rD=[`#8a8f98`,`#b03a48`,`#13549b`,`#9e6514`,`#29996b`,`#5b4bc4`,`#33373d`,`#c06a2b`,`#777d87`];function iD(e){return e.split(/(\[[^\]]*\])/g).map((e,t)=>e.startsWith(`[`)&&e.endsWith(`]`)?(0,K.jsx)(`mark`,{children:e.slice(1,-1)},t):(0,K.jsx)(`span`,{children:e},t))}function aD(e,t,n){let r=RegExp(`(^|\\s)-?${t}:(\\S+)`,`g`);return`${e.replace(r,` `).replace(/\s+/g,` `).trim()} ${t}:${n}`.trim()}var oD=e=>new Date(e).toLocaleString(void 0,{day:`numeric`,month:`short`,hour:`numeric`,minute:`2-digit`}),sD=e=>new Date(e).toLocaleDateString(void 0,{day:`numeric`,month:`short`});function cD({rows:e,series:t,height:n=110,onBucket:r}){let i=Math.max(...e.map(e=>t.reduce((t,n)=>t+(e[n.key]??0),0)),1),a=702/Math.max(e.length,1),o=Math.max(Math.min(a-2,42),1),s=n-22;return(0,K.jsxs)(`svg`,{viewBox:`0 0 720 ${n}`,width:`100%`,height:n,"aria-label":`Events over time`,children:[(0,K.jsx)(`title`,{children:`Events over time`}),e.map((c,l)=>{let u=s,d=t.reduce((e,t)=>e+(c[t.key]??0),0);return(0,K.jsxs)(`g`,{onClick:r?()=>r(c.t):void 0,style:r?{cursor:`pointer`}:void 0,children:[(0,K.jsx)(`title`,{children:`${sD(c.t)} — ${d} events`}),t.map(e=>{let t=(c[e.key]??0)/i*s;return u-=t,t>0?(0,K.jsx)(`rect`,{x:18+l*a+(a-o)/2,y:u,width:o,height:t,fill:e.color},e.key):null}),(l===0||l===e.length-1||l===Math.floor(e.length/2))&&(0,K.jsx)(`text`,{x:18+l*a+a/2,y:n-4,textAnchor:`middle`,fontSize:`10`,fill:`currentColor`,opacity:`0.55`,children:sD(c.t)})]},l)})]})}function lD({initialQuery:e=``,onQuery:t,onOpenCall:n,onOpenTrace:r,onOpenSandbox:i}){let[a,o]=(0,_.useState)(e),[s,c]=(0,_.useState)(e),[l,u]=(0,_.useState)(`7d`),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(0),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)([]),[b,S]=(0,_.useState)(null),[C,w]=(0,_.useState)(!0),T=(0,_.useRef)(0),E=(0,_.useCallback)(()=>{if(l===`custom`&&d)return d;let e=tD.find(e=>e.id===l);return e?.ms?{from:Date.now()-e.ms,to:Date.now()}:{from:null,to:null}},[l,d]),D=(0,_.useCallback)(async(e=!1)=>{let t=++T.current;e||w(!0);let{from:n,to:r}=E(),i=new URLSearchParams({q:s,limit:`50`,offset:String(p)});n&&i.set(`from`,String(n)),r&&i.set(`to`,String(r));let a=new URLSearchParams({limit:`12`});n&&a.set(`from`,String(n)),r&&a.set(`to`,String(r));try{let[e,n]=await Promise.all([x().fetch(`/raytace/search?${i}`,{cache:`no-store`}),x().fetch(`/raytace/search/signatures?${a}`,{cache:`no-store`})]);if(t!==T.current)return;if(!e.ok)throw Error((await e.json().catch(()=>({}))).error??`Search returned ${e.status}`);g(await e.json()),n.ok&&y((await n.json()).signatures??[]),S(null)}catch(e){t===T.current&&S(e instanceof Error?e.message:`Search unavailable. Is the proxy running?`)}finally{t===T.current&&w(!1)}},[s,p,E]);(0,_.useEffect)(()=>{D()},[D]),(0,_.useEffect)(()=>{let e=setInterval(()=>void D(!0),15e3);return()=>clearInterval(e)},[D]);function O(e){o(e),c(e),m(0),t(e)}let k=h?.summary,A=(h?.histogram??[]).map(e=>({...e,other:Math.max(e.total-e.failed,0)})),j=A.length>1?A[1].t-A[0].t:864e5;return(0,K.jsxs)(`section`,{className:`rt-view rt-search-view`,children:[(0,K.jsx)(`header`,{className:`rt-view-head`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`eyebrow`,children:`SEARCH`}),(0,K.jsx)(`h1`,{children:`What the agents did`})]})}),(0,K.jsxs)(`form`,{className:`rt-search-bar`,onSubmit:e=>{e.preventDefault(),O(a)},children:[(0,K.jsx)(ge,{size:16}),(0,K.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),placeholder:`outcome:failed tool:Bash "permission denied" · try failed | stats count by tool`,"aria-label":`Search agent activity`,spellCheck:!1}),a&&(0,K.jsx)(`button`,{type:`button`,className:`rt-search-clear`,onClick:()=>O(``),"aria-label":`Clear search`,children:(0,K.jsx)(Te,{size:14})}),(0,K.jsxs)(`select`,{value:l,onChange:e=>{u(e.target.value),f(null),m(0)},"aria-label":`Time range`,children:[l===`custom`&&(0,K.jsx)(`option`,{value:`custom`,children:`Selected window`}),tD.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.label},e.id))]}),(0,K.jsx)(`button`,{type:`submit`,className:`rt-button primary`,children:`Search`})]}),(0,K.jsxs)(`div`,{className:`rt-search-quick`,children:[nD.map(e=>(0,K.jsx)(`button`,{type:`button`,className:`rt-chip`,onClick:()=>O(e),children:(0,K.jsx)(`code`,{children:e})},e)),l===`custom`&&d&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-chip`,onClick:()=>{u(`7d`),f(null)},children:[oD(new Date(d.from).toISOString()),` – `,oD(new Date(d.to).toISOString()),` `,(0,K.jsx)(Te,{size:12})]})]}),b&&(0,K.jsx)(`p`,{className:`rt-search-error`,children:b}),(h?.errors??[]).map(e=>(0,K.jsx)(`p`,{className:`rt-search-error`,children:e},e)),h?.error&&(0,K.jsx)(`p`,{className:`rt-search-error`,children:h.error}),h?.mode===`events`&&k&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`rt-search-summary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`strong`,{children:k.total}),(0,K.jsx)(`span`,{children:`events`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`strong`,{className:`rt-failed-text`,children:k.failed}),(0,K.jsx)(`span`,{children:`failed`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`strong`,{children:k.mismatched}),(0,K.jsx)(`span`,{children:`reported ≠ observed`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`strong`,{children:k.http_errors}),(0,K.jsx)(`span`,{children:`HTTP errors`})]}),(0,K.jsxs)(`small`,{children:[h.total,` match`,h.total===1?``:`es`,` the full query`]})]}),A.length>0&&(0,K.jsxs)(`div`,{className:`rt-search-chart`,children:[(0,K.jsx)(cD,{rows:A,height:110,series:[{key:`other`,color:`#c3c7cd`,label:`ok / unknown`},{key:`failed`,color:`#b03a48`,label:`failed`}],onBucket:e=>{f({from:e,to:e+j-1}),u(`custom`),m(0)}}),(0,K.jsx)(`small`,{children:`Grey ok/unknown, red failed. Click a bar to zoom to that window.`})]}),!s&&v.length>0&&(0,K.jsxs)(`div`,{className:`rt-search-clusters`,children:[(0,K.jsxs)(`div`,{className:`rt-list-head`,children:[(0,K.jsx)(`span`,{children:`TOP FAILURE CLUSTERS`}),(0,K.jsx)(`small`,{children:`repeat failures, grouped by signature`})]}),(0,K.jsx)(`ol`,{children:v.map(e=>(0,K.jsxs)(`li`,{children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>O(`signature:${e.signature}`),children:[(0,K.jsxs)(`strong`,{children:[`×`,e.count]}),(0,K.jsx)(`span`,{className:`rt-cluster-label`,children:e.label??e.signature}),(0,K.jsxs)(`small`,{children:[e.tools.join(`, `),e.exit_codes.length?` · exit ${e.exit_codes.join(`/`)}`:``,` · last `,oD(e.last)]})]}),e.sample_turn&&(0,K.jsxs)(`button`,{type:`button`,className:`link-button`,onClick:()=>e.sample_call?n(e.sample_turn,e.sample_call):r(e.sample_turn),children:[`latest example `,(0,K.jsx)(P,{size:11})]})]},e.signature))})]}),(0,K.jsxs)(`div`,{className:`rt-search-body`,children:[(0,K.jsx)(`aside`,{className:`rt-search-facets`,children:Object.entries(h.facets??{}).map(([e,t])=>t.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{children:e.replace(`_`,` `)}),t.map(t=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>O(aD(s,e===`tool`?`tool`:e,t.value)),children:[(0,K.jsx)(`span`,{children:t.value}),(0,K.jsx)(`small`,{children:t.count})]},t.value))]},e))}),(0,K.jsxs)(`div`,{className:`rt-search-results`,children:[(0,K.jsxs)(`div`,{className:`rt-list-head`,children:[(0,K.jsx)(`span`,{children:`EVENTS`}),(0,K.jsx)(`small`,{children:C?`Searching…`:`${h.hits?.length??0} shown`})]}),!C&&!(h.hits??[]).length&&(0,K.jsx)(`p`,{className:`rt-empty`,children:`Nothing matches. Missing evidence reads as unknown, never as success — try widening the time range.`}),(0,K.jsx)(`ol`,{children:(h.hits??[]).map(e=>(0,K.jsxs)(`li`,{className:`rt-hit outcome-${e.outcome}`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`rt-hit-main`,disabled:!e.turn_id,onClick:()=>{e.turn_id&&e.external_call_id?n(e.turn_id,e.external_call_id):e.turn_id&&r(e.turn_id)},children:[(0,K.jsx)(`time`,{dateTime:e.ts,children:oD(e.ts)}),(0,K.jsx)(`span`,{className:`rt-outcome outcome-${e.outcome}`,children:e.outcome}),(0,K.jsx)(`strong`,{children:e.kind===`turn`?`prompt`:e.kind===`proxy_error`?`proxy error`:`${e.tool_name??`tool`}${e.category?` · ${e.category}`:``}`}),(0,K.jsx)(`span`,{className:`rt-hit-text`,children:e.snippet?iD(e.snippet):e.command_text??e.prompt_excerpt??e.error_excerpt??``}),(0,K.jsxs)(`small`,{children:[e.model??``,e.exit_code==null?``:` · exit ${e.exit_code}`,e.http_status?` · HTTP ${e.http_status}`:``,e.kind===`call`?` · reported ${e.outcome_reported} · observed ${e.outcome_observed}`:``,e.reported_check&&e.reported_check!==`agrees`?` · ${e.reported_check.replaceAll(`_`,` `)}`:``,e.duration_ms==null?``:` · ${(e.duration_ms/1e3).toFixed(1)}s`]}),e.error_excerpt&&e.outcome===`failed`&&(0,K.jsx)(`span`,{className:`rt-hit-error`,children:e.signature_label??e.error_excerpt.split(`
32
32
  `)[0]})]}),i&&e.kind===`call`&&e.turn_id&&e.external_call_id&&(0,K.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>i(e.turn_id,e.external_call_id),children:`sandbox evidence`})]},e.id))}),(0,K.jsxs)(`div`,{className:`rt-search-pages`,children:[(0,K.jsx)(`button`,{type:`button`,className:`rt-button`,disabled:p===0,onClick:()=>m(Math.max(p-50,0)),children:`Newer`}),(0,K.jsx)(`button`,{type:`button`,className:`rt-button`,disabled:p+50>=(h.total??0),onClick:()=>m(p+50),children:`Older`})]})]})]})]}),h?.mode===`stats`&&(0,K.jsxs)(`div`,{className:`rt-search-stats`,children:[(0,K.jsx)(`div`,{className:`rt-list-head`,children:(0,K.jsxs)(`span`,{children:[h.agg===`avg_duration`?`AVG DURATION (MS)`:`COUNT`,h.by?` BY ${h.by.toUpperCase()}`:``]})}),(0,K.jsx)(`table`,{children:(0,K.jsx)(`tbody`,{children:(h.rows??[]).map((e,t)=>(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`td`,{children:String(e.key??`(none)`)}),(0,K.jsx)(`td`,{className:`rt-stat-bar`,"aria-label":String(e.value??e.count??``),children:(0,K.jsx)(`span`,{style:{width:`${Math.max(2,100*Number(e.value??e.count??0)/Math.max(...(h.rows??[]).map(e=>Number(e.value??e.count??0)),1))}%`}})}),(0,K.jsx)(`td`,{children:String(e.value??e.count??``)})]},t))})}),!(h.rows??[]).length&&(0,K.jsx)(`p`,{className:`rt-empty`,children:`No events match.`})]}),h?.mode===`timechart`&&(0,K.jsxs)(`div`,{className:`rt-search-chart`,children:[(0,K.jsx)(cD,{rows:h.rows??[],height:240,series:(h.series??[]).map((e,t)=>({key:e,label:e,color:rD[t%rD.length]}))}),(0,K.jsx)(`small`,{children:(h.series??[]).map((e,t)=>(0,K.jsxs)(`span`,{className:`rt-legend-item`,children:[(0,K.jsx)(`i`,{style:{background:rD[t%rD.length]}}),e,` `]},e))}),!(h.rows??[]).length&&(0,K.jsx)(`p`,{className:`rt-empty`,children:`No events match.`})]}),(0,K.jsxs)(`p`,{className:`rt-search-help`,children:[`Fields: `,(0,K.jsx)(`code`,{children:`outcome reported observed tool model category kind exit http file signature session after before`}),`. Pipes: `,(0,K.jsx)(`code`,{children:`| stats count by tool`}),`, `,(0,K.jsx)(`code`,{children:`| stats avg(duration) by model`}),`, `,(0,K.jsx)(`code`,{children:`| timechart count by outcome span=1d`}),`. Prefix `,(0,K.jsx)(`code`,{children:`-`}),` negates; trailing `,(0,K.jsx)(`code`,{children:`*`}),` is a prefix match.`]})]})}var uD={read:`Read`,search:`Search`,write:`Write`,edit:`Edit`,delete:`Delete / move`,run:`Run`,test:`Test`,build:`Build / install`,git:`Git`,web:`Web`,plan:`Plan`,delegate:`Delegate`,unsure:`Not sure`};function dD(e,t){let n=e.find(e=>{if(!e.title.startsWith(`Tool result:`))return!1;try{return JSON.parse(e.raw).call_id===t}catch{return!1}});if(!n)return{state:`none`,code:null,output:``};let r=``,i=!1,a=null;try{let e=JSON.parse(n.raw),t=e.output??e.content;r=typeof t==`string`?t:JSON.stringify(t??``),i=e.is_error===!0||e.status===`failed`;let o=typeof e.exit_code==`number`?e.exit_code:t&&typeof t==`object`&&typeof t.exit_code==`number`?t.exit_code:null;typeof o==`number`&&(a=o)}catch{}if(i)return{state:`failed`,code:a,output:r};if(a!==null)return{state:a===0?`ok`:`failed`,code:a,output:r};if(/Rejected\(/.test(r))return{state:`rejected`,code:null,output:r};let o=Number(r.match(/Process exited with code (\d+)/)?.[1]??NaN);return Number.isFinite(o)?{state:o===0?`ok`:`failed`,code:o,output:r}:{state:/failed/i.test(r.slice(0,80))?`failed`:`ok`,code:null,output:r}}var fD=(e,t)=>{let n=String(e??``).replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-1)}…`:n},pD=e=>e.split(`/`).filter(Boolean).at(-1)??e,mD={delete:45,git:40,write:35,edit:35,build:30,test:28,run:22,delegate:20,web:10,plan:8,read:5,search:5,unsure:8},hD=[[/\brm\s+-[a-z]*[rf]/,`Deletes files (rm -r/-f)`],[/\bsudo\b/,`Runs with elevated privileges (sudo)`],[/\b(curl|wget)\b[^|]*\|\s*(ba|z)?sh\b/,`Pipes a download straight into a shell`],[/\bgit\s+(push|reset\s+--hard|clean\s+-[a-z]*f|checkout\s+--\s)/,`Hard-to-undo git operation`],[/\b(drop\s+(table|database)|truncate\s+table|delete\s+from)\b/i,`Deletes stored data`],[/\bkill\s+-9\b|\bmkfs\b|\bdd\s+.*of=\/dev\//,`Can destroy processes or disks`],[/\b(npm|pnpm|yarn|pip|pip3|brew|apt(-get)?)\s+(install|add|i)\b/,`Installs or changes dependencies`],[/\bchmod\s+(-R\s+)?[0-7]{3,4}\b|\bchown\s+-R\b/,`Changes file permissions or ownership`]];function gD(e){return e.snapshot?.changed?(e.snapshot.changes??[]).map(e=>e.path):[]}function _D(e,t,n){let r=gD(t[n]).map(pD).filter(e=>e.length>=3);return r.length?t.slice(n+1).filter(e=>{let t=`${e.proposed??``} ${gD(e).join(` `)}`;return r.some(e=>t.includes(e))}).length:0}function vD(e,t,n,r=e.callVerifications??[]){let i=[],a=mD[t.category??`unsure`]??8;t.category&&i.push(`${uD[t.category]} step`);let o=t.proposed??``;for(let[e,t]of hD)e.test(o)&&(a+=30,i.push(t));let s=gD(t);s.length&&(a+=Math.min(30,s.length*10),i.push(`Changed ${s.length} file${s.length===1?``:`s`}: ${s.slice(0,3).map(pD).join(`, `)}${s.length>3?`, …`:``}`));let c=dD(e.events,t.call_id);c.state===`failed`&&(a+=25,i.push(`Failed as reported to the agent${c.code==null?``:` (exit ${c.code})`}`)),c.state===`rejected`&&(a+=25,i.push(`Refused by the sandbox policy`)),t.exit_code!=null&&t.exit_code!==0&&(a+=20,i.push(`Sandbox saw exit ${t.exit_code}`)),t.reported_check&&t.reported_check!==`agrees`&&(a+=25,i.push(`What the agent was told differs from what the sandbox saw`));let l=t.descendant_count??t.descendants?.length??0;l>1&&(a+=Math.min(15,l),i.push(`Ran ${l} processes underneath it`)),(c.state===`failed`||c.state===`rejected`)&&n+1<r.length&&(a+=12,i.push(`The run changed course after this step`));let u=_D(e,r,n);return u&&(a+=Math.min(18,u*6),i.push(`${u} later step${u===1?``:`s`} built on what it produced`)),n===r.length-1&&r.length>1&&(a+=5,i.push(`Last step before the final answer`)),{score:a,reasons:i}}var yD=e=>fD((e.proposed??e.name).split(`
33
33
  `).find(e=>e.trim())?.trim()??e.name,90);function bD(e){let t=e.callVerifications??[],n=t.map((n,r)=>({call:n,step:r+1,...vD(e,n,r,t),label:yD(n)}));if(!n.length)return[];let r=n.filter(e=>e.score>=28);return r.length>8&&(r=[...r].sort((e,t)=>t.score-e.score).slice(0,8)),r.length<3&&(r=[...n].sort((e,t)=>t.score-e.score).slice(0,Math.min(5,n.length))),r.sort((e,t)=>e.step-t.step)}function xD(e){let t=e.callVerifications??[];return t.length?t.map((n,r)=>({call:n,step:r+1,...vD(e,n,r,t),label:yD(n)})).sort((e,t)=>t.score-e.score||e.step-t.step)[0]:null}function SD(e,t){let n=e.callVerifications??[],r=n.findIndex(e=>e.call_id===t.call_id),i=r+1,a=[],o=e.events.filter(e=>e.title===`Model answer`&&e.exchange_id===t.exchange_id&&e.detail?.trim()).map(e=>e.detail).join(` `);o&&a.push({kind:`agent`,text:fD(o,300)});let s=r>0?n[r-1]:null,c=s?dD(e.events,s.call_id):null;s&&c&&(c.state!==`ok`||c.output.trim())&&a.push({kind:`result`,step:r,text:fD(c.output,260)||`Step #${r} ${c.state}`}),a.length||a.push({kind:`request`,text:fD(e.title,300)});let l=dD(e.events,t.call_id),u=[];t.exec_id||t.kernel_confirmed?u.push(`The sandbox saw it run${t.exit_code==null?``:` · exit ${t.exit_code}`}${(t.descendant_count??0)>0?` · ${t.descendant_count} child process${t.descendant_count===1?``:`es`}`:``}.`):t.snapshot?u.push(t.snapshot.changed?`The sandbox's snapshot after it shows ${t.snapshot.changes.length} file change${t.snapshot.changes.length===1?``:`s`}.`:`The sandbox's snapshot after it shows no file change.`):l.state===`rejected`?u.push(`The sandbox policy refused it; it never ran.`):e.sandboxId&&u.push(`The sandbox saw no process for this call. Missing evidence is not proof it did not run.`),l.state!==`none`&&u.push(`The agent was told: ${l.state}${l.code==null?``:` (exit ${l.code})`}${l.output.trim()?` — ${fD(l.output,180)}`:``}`),t.reported_check&&t.reported_check!==`agrees`&&u.push(`That report differs from what the sandbox observed — worth checking before trusting either.`),u.length||u.push(`No independent observation was recorded for this call.`);let d=gD(t),f=[];d.length&&f.push(`Changed ${d.map(e=>`\`${e}\``).join(`, `)}.`);let p=r>=0?_D(e,n,r):0;p&&f.push(`${p} later step${p===1?``:`s`} worked on what this produced, so later results depend on it.`);let m=r>=0?n[r+1]:void 0;m?f.push(`The next step (#${i+1}) was: ${yD(m)}.`):e.answer&&f.push(`After this, the agent answered: ${fD(e.answer,220)}`),f.length||f.push(`Nothing later in the record depends on it directly.`);let h=c&&(c.state===`failed`||c.state===`rejected`)?`Step #${r} had just ${c.state===`rejected`?`been refused`:`failed`} as the agent heard it, so this reads as a reaction to that result rather than a planned first move.`:o?`The agent said, just before proposing it: “${fD(o,180)}” That is its own account, not private reasoning.`:r<=0?`This follows directly from your request; the agent had seen nothing else yet.`:`Nothing the agent said at the time explains it beyond the sequence: it follows step #${r} and your original request.`;return{trigger:a,proposed:t.proposed??t.name,observed:u,consequence:f,why:h}}var CD={request:`Your request`,agent:`The agent said, just before`,result:`What the previous step returned`};function wD({trace:e,focusCall:t,onSelect:n,onOpenCall:r,onOpenThought:i,onOpenSandbox:a}){let o=e.callVerifications??[],s=bD(e),c=xD(e),[l,u]=(0,_.useState)(t);(0,_.useEffect)(()=>{t&&u(t)},[t]);let d=l&&o.some(e=>e.call_id===l)?l:c?.call.call_id??null,f=s.find(e=>e.call.call_id===d)??(c&&d===c.call.call_id?c:null)??s[0]??null,p=f?SD(e,f.call):null,m=(0,K.jsx)(`header`,{className:`rt-view-head`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`eyebrow`,children:`STORY`}),(0,K.jsx)(`h1`,{children:`What mattered in this run, and why`}),(0,K.jsx)(`p`,{className:`rt-muted rt-cot-caption`,children:`A timeline of the consequential steps only. Why a step happened is a reading of what the agent could see — not its private reasoning.`})]})});if(!o.length)return(0,K.jsxs)(`section`,{className:`rt-view`,children:[m,(0,K.jsx)(`p`,{className:`rt-empty`,children:`This prompt made no tool calls, so there is no story to rank. The final answer is the whole run.`})]});let h=e=>{u(e.call.call_id),n?.(e.call.call_id)},g=e=>c?.call.call_id===e.call.call_id;return(0,K.jsxs)(`section`,{className:`rt-view`,children:[m,(0,K.jsx)(YT,{trace:e,onStep:e=>{u(e),n?.(e)}}),(0,K.jsxs)(`div`,{className:`rt-story`,children:[(0,K.jsxs)(`aside`,{className:`rt-story-rail`,"aria-label":`Timeline of key moments`,children:[(0,K.jsx)(`h2`,{children:`Key moments`}),(0,K.jsxs)(`p`,{className:`rt-story-rail-note`,children:[s.length,` of `,o.length,` step`,o.length===1?``:`s`,` earned a place, ranked by files changed, failures, processes spawned, and what later steps built on.`]}),(0,K.jsx)(`ol`,{className:`rt-story-timeline`,children:s.map(e=>(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,"aria-label":`Step ${e.step}: ${e.label}`,className:`rt-story-node${f?.call.call_id===e.call.call_id?` active`:``}`,onClick:()=>h(e),children:[(0,K.jsx)(`span`,{className:`rt-story-dot`,"aria-hidden":!0}),(0,K.jsxs)(`span`,{className:`rt-story-node-body`,children:[(0,K.jsxs)(`span`,{className:`rt-story-node-head`,children:[(0,K.jsxs)(`span`,{className:`rt-cot-num`,children:[`#`,e.step]}),g(e)&&(0,K.jsxs)(`span`,{className:`rt-story-top`,children:[(0,K.jsx)(ye,{size:11}),` Most consequential`]}),(0,K.jsx)(`span`,{className:`rt-story-score`,title:`Consequence score, from the reasons listed for this step`,children:e.score})]}),(0,K.jsx)(`span`,{className:`rt-story-node-label`,children:e.label}),(0,K.jsx)(`span`,{className:`rt-story-node-why`,children:e.reasons[1]??e.reasons[0]??``})]})]})},e.call.call_id))}),(0,K.jsx)(`p`,{className:`rt-story-rail-note`,children:`Routine reads, searches and retries that changed nothing are in Tool calls, not here.`})]}),f&&p&&(0,K.jsxs)(`article`,{className:`rt-story-main`,"aria-label":`Story of step ${f.step}`,children:[g(f)?(0,K.jsxs)(`p`,{className:`rt-story-banner`,children:[(0,K.jsx)(ye,{size:13}),` The most consequential command of this run — the one later steps and the final answer most depend on.`]}):(0,K.jsxs)(`p`,{className:`rt-story-banner rt-story-banner-quiet`,children:[`Step #`,f.step,` of `,o.length,` · consequence score `,f.score]}),(0,K.jsxs)(`h2`,{className:`rt-story-title`,children:[`Step #`,f.step,`: `,f.label]}),(0,K.jsx)(`div`,{className:`rt-story-cmd`,children:(0,K.jsx)(Au,{text:p.proposed})}),(0,K.jsx)(`h3`,{children:`Why it did that`}),(0,K.jsx)(`p`,{className:`rt-story-why`,children:p.why}),(0,K.jsx)(`ul`,{className:`rt-story-list`,children:p.trigger.map((e,t)=>(0,K.jsxs)(`li`,{children:[(0,K.jsx)(`span`,{className:`rt-story-tag`,children:e.step?`${CD[e.kind]} (#${e.step})`:CD[e.kind]}),` `,e.text]},t))}),(0,K.jsx)(`h3`,{children:`What actually happened`}),(0,K.jsx)(`ul`,{className:`rt-story-list`,children:p.observed.map((e,t)=>(0,K.jsx)(`li`,{children:e},t))}),(0,K.jsx)(`h3`,{children:`Why it matters`}),(0,K.jsx)(`ul`,{className:`rt-story-list`,children:p.consequence.map((e,t)=>(0,K.jsx)(`li`,{children:e},t))}),(0,K.jsx)(`h3`,{children:`What earned its place`}),(0,K.jsx)(`div`,{className:`rt-chips`,children:f.reasons.map(e=>(0,K.jsx)(`span`,{className:`rt-chip rt-story-reason`,children:e},e))}),(0,K.jsxs)(`div`,{className:`rt-story-actions`,children:[r&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>r(f.call.call_id),children:[(0,K.jsx)(we,{size:12}),` Open in Tool calls`]}),i&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>i(f.call.call_id),children:[(0,K.jsx)(R,{size:12}),` Ranked causes`]}),a&&(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>a(f.call.call_id),children:[(0,K.jsx)(ve,{size:12}),` Sandbox evidence`]})]}),(0,K.jsx)(`p`,{className:`rt-foot`,children:`Ranked from recorded facts only — files changed, exit codes, processes the sandbox saw, disagreements between the agent's report and the sandbox, and what later steps reused. No model was asked to write this.`})]})]})]})}var TD={A:`added`,M:`edited`,D:`deleted`,T:`type changed`};function ED({trace:e,onOpenCall:t}){let n=ST(e),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(``),l=e.sandboxId,u=!!(l&&n.base&&n.final&&n.files.length);async function d(t){if(l&&n.base&&n.final){o(!0),c(``);try{let r=await OT(l,n.base,n.final,t);if(!r.diff){c(`That diff came back empty, so nothing was downloaded.`);return}kT(wT(e,t),r.diff),r.truncated&&c(`Downloaded, but the diff was larger than the 500 KB the snapshot view returns: this patch is incomplete.`)}catch(e){c(`Could not build the patch: ${e instanceof Error?e.message:String(e)}`)}finally{o(!1)}}}return(0,K.jsxs)(`section`,{className:`rt-view rt-changes`,children:[(0,K.jsxs)(`header`,{className:`rt-view-head`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`eyebrow`,children:`CHANGES`}),(0,K.jsx)(`h1`,{children:`What this prompt changed`})]}),(0,K.jsx)(`div`,{className:`rt-actions`,children:(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,disabled:!u||a,onClick:()=>void d(),title:u?`One patch file with every change this prompt made, to apply in your local copy`:`Needs a sandbox run whose file snapshots were recorded`,children:[(0,K.jsx)(H,{size:14}),` `,a?`Building patch…`:`Download patch`]})})]}),l?n.hasSnapshots?n.files.length?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`dl`,{className:`rt-stats`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:`Files changed`}),(0,K.jsx)(`dd`,{children:n.files.length})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:`Lines added`}),(0,K.jsxs)(`dd`,{children:[`+`,n.added]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:`Lines removed`}),(0,K.jsxs)(`dd`,{children:[`−`,n.removed]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:`Steps that changed files`}),(0,K.jsx)(`dd`,{children:n.steps.length})]})]}),s&&(0,K.jsx)(`p`,{role:`alert`,className:`verify-error`,children:s}),(0,K.jsx)(`h2`,{children:`Across the whole prompt`}),(0,K.jsx)(`ul`,{className:`rt-files`,children:n.files.map(e=>(0,K.jsxs)(_.Fragment,{children:[(0,K.jsxs)(`li`,{children:[(0,K.jsxs)(`button`,{type:`button`,className:`rt-file-toggle`,"aria-expanded":r===e.path,onClick:()=>i(r===e.path?null:e.path),children:[(0,K.jsx)(B,{size:12,className:`rt-caret${r===e.path?` down`:``}`}),(0,K.jsx)(`span`,{className:`rt-file-status s-${e.status}`,children:TD[e.status]??e.status}),(0,K.jsx)(`code`,{children:e.path})]}),(0,K.jsxs)(`small`,{children:[e.added==null?`binary`:`+${e.added} −${e.removed}`,` · step`,e.calls.length>1?`s`:``,` `,e.calls.map(e=>`#${e}`).join(`, `)]})]}),r===e.path&&n.base&&n.final&&(0,K.jsxs)(`li`,{className:`rt-file-diff`,children:[(0,K.jsx)(PT,{sandbox:l,from:n.base,to:n.final,path:e.path}),(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,disabled:a,onClick:()=>void d(e.path),children:[(0,K.jsx)(H,{size:13}),` `,`Download this file's patch`]})]})]},e.path))}),n.tooBig.length>0&&(0,K.jsxs)(`p`,{className:`rt-files-note`,children:[`Too big to snapshot (over 5 MB), so their changes are not in this list or the patch: `,n.tooBig.join(`, `)]}),(0,K.jsxs)(`div`,{className:`rt-changes-apply`,children:[(0,K.jsx)(`h2`,{children:`Take it into your local copy`}),(0,K.jsxs)(`p`,{children:[`Download the patch above, put it in your project folder, and check before applying:`,` `,(0,K.jsxs)(`code`,{children:[`git apply --check `,wT(e)]}),`, then `,(0,K.jsxs)(`code`,{children:[`git apply `,wT(e)]}),`. The patch is built from the sandbox's snapshots of this prompt only. It may not apply cleanly if your local copy has changed since the sandbox was created — review it like any other change.`]})]}),(0,K.jsxs)(`div`,{className:`rt-changes-steps`,children:[(0,K.jsx)(`h2`,{children:`Step by step`}),n.steps.map(({call:e,number:n})=>(0,K.jsxs)(`div`,{className:`rt-changes-step`,children:[(0,K.jsxs)(`p`,{className:`rt-files-note`,children:[`#`,n,` `,e.description??e.proposed??e.name,t&&(0,K.jsxs)(K.Fragment,{children:[` `,` `,(0,K.jsxs)(`button`,{type:`button`,className:`link-button`,onClick:()=>t(e.call_id),children:[`Open in Tool calls `,(0,K.jsx)(P,{size:12})]})]})]}),e.snapshot&&(0,K.jsx)(IT,{snapshot:e.snapshot,sandbox:l})]},e.call_id))]})]}):(0,K.jsx)(`p`,{className:`rt-empty`,children:`No file changed during this prompt. The snapshots taken after its steps show the project exactly as it started.`}):(0,K.jsx)(`p`,{className:`rt-empty`,children:`This run was recorded before file snapshots existed, so there is nothing to diff. Tool calls still shows what the agent reported.`}):(0,K.jsx)(`p`,{className:`rt-empty`,children:`This prompt did not run in a sandbox, so RayTrace holds no snapshot of the project folder to diff.`})]})}var DD=e=>[...e].sort((e,t)=>{let n=e.started_ns?BigInt(e.started_ns):null,r=t.started_ns?BigInt(t.started_ns):null;return n!=null&&r!=null&&n!==r?n<r?-1:1:e.event_id-t.event_id}),OD=e=>Pu({observed:!0,status:e.exit_code!=null||e.signal?void 0:`running`,exitCode:e.exit_code,signal:e.signal});function kD({trace:e,focusCall:t,onOpenCall:n}){let{since:r,until:i}=Me(e.requests),{data:a,error:o,raw:s,setRaw:c}=Tu(e.sandboxId,r,i),[l,u]=(0,_.useState)(new Set),[d,f]=(0,_.useState)(null);(0,_.useEffect)(()=>{if(f(null),!e.sandboxId)return;let t=!1,n,a=new AbortController,o=async()=>{try{let n=await Ww(e.sandboxId,r,i,a.signal);t||f(n)}catch{}!t&&!i&&(n=setTimeout(o,5e3))};return o(),()=>{t=!0,a.abort(),clearTimeout(n)}},[e.sandboxId,r,i]);let p=(0,_.useMemo)(()=>uT(d),[d]),m=new Set((d?.network??[]).filter(e=>e.effect===`connect`&&!e.outcomes.refused_by_policy).map(e=>`${e.host??e.ip}:${e.port}`)),h=a?.commands??[],g=a?.call_labels??{},v=e.callVerifications??[],y=new Map(v.map((e,t)=>[e.call_id,t+1])),b=new Set(h.map(e=>e.event_id)),x=new Map,S=[];for(let e of h){let t=e.parent_event_id;if(t==null||!b.has(t)){S.push(e);continue}x.set(t,[...x.get(t)??[],e])}let C=DD(S),w=C.map(OD),T=[0,1,2,3].map(e=>C.filter(t=>t.severity?.level===e).length),[E,D]=(0,_.useState)(null),O=E==null?C:C.filter(e=>e.severity?.level===E),k=e=>!!t&&e.attribution?.call_id===t,A=C.find(k),j=A?bu(A.pid,A.process_start_ns):null;(0,_.useEffect)(()=>{if(!j)return;let e=requestAnimationFrame(()=>document.getElementById(`proc-${j.replace(`:`,`-`)}`)?.scrollIntoView({block:`center`,behavior:`smooth`}));return()=>cancelAnimationFrame(e)},[j]);let M=e=>u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});function P(e,t){let r=DD(x.get(e.event_id)??[]),i=l.has(e.event_id),a=OD(e),o=ku(e.started_ns),s=ku(e.ended_ns),c=bu(e.pid,e.process_start_ns),u=e.attribution?.call_id??null,d=e.attribution?.parent_call_id??null,f=new Map;for(let e of[...t===0&&u?p.byCall.get(u)??[]:[],...c?p.byProcess.get(c)??[]:[]])f.set(e.key,e);return(0,K.jsxs)(_.Fragment,{children:[(0,K.jsxs)(`tr`,{id:c?`proc-${c.replace(`:`,`-`)}`:void 0,className:`rt-row${t?` rt-child`:``}${a.tone===`fail`?` failed`:``}${k(e)?` rt-focus`:``}`,onClick:r.length?()=>M(e.event_id):void 0,"aria-expanded":r.length?i:void 0,children:[(0,K.jsx)(`td`,{className:`rt-time`,children:Eu(o)}),(0,K.jsxs)(`td`,{className:`rt-cmd`,children:[(0,K.jsxs)(`span`,{className:`rt-cmd-line${r.length?` rt-parent`:``}`,style:{paddingLeft:`${t*22}px`},children:[r.length?(0,K.jsx)(B,{size:14,className:`rt-caret${i?` down`:``}`,"aria-hidden":`true`}):(0,K.jsx)(`span`,{className:`rt-caret-gap`}),(0,K.jsx)(`span`,{className:`rt-cmd-text`,title:e.command,children:e.description??(0,K.jsx)(Au,{text:e.command})}),e.description_source===`model`&&(0,K.jsx)(`span`,{className:`evidence-ai`,title:`Described by a model, not derived from the command text. Treat as a reading, not an observation.`,children:`~AI`})]}),e.description&&(0,K.jsx)(`span`,{className:`rt-cmd-raw`,style:{paddingLeft:`${t*22+20}px`},title:e.command,children:(0,K.jsx)(Au,{text:e.command})}),f.size>0&&(0,K.jsxs)(`span`,{className:`rt-chips`,style:{paddingLeft:`${t*22+20}px`},children:[[...f.values()].slice(0,8).map(e=>(0,K.jsx)(`span`,{className:`rt-flag${e.fail?` rt-fail`:``}`,title:e.title,children:e.text},e.key)),f.size>8&&(0,K.jsxs)(`span`,{className:`rt-flag`,title:[...f.values()].slice(8).map(e=>e.text).join(`
34
34
  `),children:[`+`,f.size-8]})]})]}),(0,K.jsx)(`td`,{className:`rt-pid`,children:e.pid}),(0,K.jsx)(`td`,{className:`exec-${a.tone}`,children:(0,K.jsx)(Fu,{outcome:a})}),(0,K.jsx)(`td`,{className:`rt-time`,children:Number.isFinite(o)&&Number.isFinite(s)?Ou(s-o):`—`}),(0,K.jsx)(`td`,{children:t===0?(0,K.jsx)(Cu,{severity:e.severity,flags:u?g[u]?.flags:void 0}):null}),(0,K.jsx)(`td`,{children:t>0?null:u?(0,K.jsxs)(`button`,{type:`button`,className:`link-button`,onClick:e=>{e.stopPropagation(),n(u)},children:[`#`,y.get(u)??`?`]}):d?(0,K.jsxs)(`span`,{className:`rt-muted`,children:[`under #`,y.get(d)??`?`]}):(0,K.jsx)(`span`,{className:`rt-muted`,title:`This process ran, but matched no proposed tool call.`,children:`no tool call`})})]}),i&&r.map(e=>P(e,t+1))]},e.event_id)}return(0,K.jsxs)(`section`,{className:`rt-view`,children:[(0,K.jsxs)(`header`,{className:`rt-view-head`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`eyebrow`,children:`SANDBOX EVIDENCE`}),(0,K.jsx)(`h1`,{children:`What actually ran`})]}),(0,K.jsx)(`div`,{className:`rt-actions`,children:(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>n(),children:[(0,K.jsx)(N,{size:14}),` Tool calls`]})})]}),e.sandboxId?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`dl`,{className:`rt-stats`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:`Commands`}),(0,K.jsx)(`dd`,{children:a?C.length:`—`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:`Succeeded`}),(0,K.jsx)(`dd`,{className:`exec-ok`,children:a?w.filter(e=>e.tone===`ok`).length:`—`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:`Failed`}),(0,K.jsx)(`dd`,{className:`exec-fail`,children:a?w.filter(e=>e.tone===`fail`).length:`—`})]}),(0,K.jsxs)(`div`,{title:[...m].join(`
35
- `)||void 0,children:[(0,K.jsx)(`dt`,{children:`Reached on the network`}),(0,K.jsx)(`dd`,{children:d?m.size:`—`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:`Severity`}),(0,K.jsx)(`dd`,{className:`rt-sev-counts`,children:[`none`,`low`,`high`,`severe`].map((e,t)=>(0,K.jsxs)(`button`,{type:`button`,"aria-pressed":E===t,className:`severity-badge severity-${t}${E===t?` rt-sev-on`:``}${E!=null&&E!==t?` rt-sev-off`:``}`,title:E===t?`Show every severity`:`Show only ${e} commands`,onClick:()=>D(e=>e===t?null:t),children:[T[t],` `,e]},e))})]})]}),o&&(0,K.jsx)(`p`,{role:`alert`,className:`verify-error`,children:o}),!a&&!o&&(0,K.jsx)(`p`,{className:`rt-empty`,children:`Loading…`}),a&&!s&&(0,K.jsxs)(K.Fragment,{children:[E!=null&&(0,K.jsxs)(`p`,{className:`rt-foot rt-filter-note`,children:[`Showing `,O.length,` of `,C.length,` commands with `,[`none`,`low`,`high`,`severe`][E],` severity.`,` `,(0,K.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>D(null),children:`Show all`})]}),C.length?O.length?(0,K.jsx)(`div`,{className:`rt-table-wrap`,children:(0,K.jsxs)(`table`,{className:`rt-table rt-sandbox`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{children:`Started`}),(0,K.jsx)(`th`,{children:`Command`}),(0,K.jsx)(`th`,{children:`pid`}),(0,K.jsx)(`th`,{children:`Result`}),(0,K.jsx)(`th`,{children:`Took`}),(0,K.jsx)(`th`,{children:`Severity`}),(0,K.jsx)(`th`,{children:`Tool call`})]})}),(0,K.jsx)(`tbody`,{children:O.map(e=>P(e,0))})]})}):(0,K.jsx)(`p`,{className:`rt-empty`,children:`No commands with this severity.`}):(0,K.jsx)(`p`,{className:`rt-empty`,children:`No commands were captured in the sandbox during this prompt. Missing evidence is not proof of non-execution.`}),(0,K.jsxs)(`p`,{className:`rt-foot`,children:[`Seen by the sandbox kernel layer, independent of what the agent reported. Collector gaps: `,a.gaps,`.`,` `,a.folded&&wu(a.folded)?`Folded, not shown as commands: ${wu(a.folded)}. `:``,(0,K.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>c(!0),children:`Show every raw event`})]})]}),a&&s&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`rt-foot`,children:(0,K.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>c(!1),children:`Back to commands`})}),(0,K.jsx)(`ul`,{className:`evidence-raw`,children:(a.events??[]).map(e=>(0,K.jsxs)(`li`,{children:[(0,K.jsx)(`code`,{children:e.kind===`exec_succeeded`?(e.argv??[]).join(` `):`${e.kind} exit=${e.exit_code??`unknown`}`}),(0,K.jsxs)(`small`,{children:[` pid `,e.pid,` · #`,e.event_id]})]},e.event_id))})]})]}):(0,K.jsx)(`p`,{className:`rt-empty`,children:`This prompt did not run in a sandbox, so there is no independent evidence of what ran.`})]})}var AD=1048576,jD={file:25*AD,total:200*AD,files:2e4,archive:100*AD},MD=new Set([`.git`,`.raytace`,`.raytrace`,`.ssh`,`.aws`,`.azure`,`.config`,`node_modules`,`.venv`,`__pycache__`,`.next`,`.vinext`,`dist`,`coverage`,`.wrangler`,`.DS_Store`]),ND=new Set([`.npmrc`,`.netrc`,`.pypirc`,`credentials`,`auth.json`,`id_rsa`,`id_ed25519`]),PD=/\.(pem|key|p12|pfx)$/i,FD=e=>e.startsWith(`.env`)||PD.test(e)||ND.has(e);function ID(e,t){let n=[];for(let r of e.split(/\r?\n/)){let e=r.replace(/(?<!\\)\s+$/,``);if(!e||e.startsWith(`#`))continue;let i=e.startsWith(`!`);i&&(e=e.slice(1)),e.startsWith(`\\`)&&(e=e.slice(1));let a=e.endsWith(`/`);if(a&&(e=e.slice(0,-1)),!e)continue;let o=e.includes(`/`);e.startsWith(`/`)&&(e=e.slice(1));let s=``;for(let t=0;t<e.length;t++){let n=e[t];if(n===`*`&&e[t+1]===`*`)e[t+2]===`/`?(s+=`(?:.*/)?`,t+=2):(s+=`.*`,t+=1);else if(n===`*`)s+=`[^/]*`;else if(n===`?`)s+=`[^/]`;else if(n===`[`){let n=e.indexOf(`]`,t+2);n<0?s+=`\\[`:(s+=`[${e.slice(t+1,n).replace(/^!/,`^`).replace(/\\/g,`\\\\`)}]`,t=n)}else s+=n.replace(/[.+^${}()|\\\]]/g,`\\$&`)}try{n.push({base:t,negate:i,dirOnly:a,match:RegExp(`^${o?``:`(?:.*/)?`}${s}$`)})}catch{}}return n}function LD(e,t,n){let r=!1;for(let i of e)(!i.dirOnly||n)&&(!i.base||t.startsWith(`${i.base}/`))&&i.match.test(i.base?t.slice(i.base.length+1):t)&&(r=!i.negate);return r}function RD(e,t){let n=t.split(`/`);for(let t=1;t<n.length;t++)if(LD(e,n.slice(0,t).join(`/`),!0))return!0;return LD(e,t,!1)}function zD(e,t,n,r){let i=[],a=0,o=[];for(let e of t.sort((e,t)=>e.path.localeCompare(t.path))){if(e.file.size>jD.file){o.push(`${e.path} (${(e.file.size/AD).toFixed(0)} MiB)`);continue}i.push(e),a+=e.file.size}return o.length&&r.push(`${o.length} file${o.length===1?` is`:`s are`} over ${jD.file/AD} MiB: ${o.slice(0,5).join(`, `)}${o.length>5?`, …`:``}. Add ${o.length===1?`it`:`them`} to .gitignore, or remove ${o.length===1?`it`:`them`}.`),i.length>jD.files&&r.push(`${i.length.toLocaleString()} files; a project may have at most ${jD.files.toLocaleString()}.`),a>jD.total&&r.push(`${(a/AD).toFixed(0)} MiB in all; a project may be at most ${jD.total/AD} MiB.`),!i.length&&!r.length&&r.push(`No files to upload in this folder.`),{name:e,files:i,total:a,skipped:n,problems:r}}var BD=e=>new Promise((t,n)=>{let r=e.createReader(),i=[],a=()=>r.readEntries(e=>{e.length?(i.push(...e),a()):t(i)},n);a()}),VD=e=>new Promise((t,n)=>e.file(t,n));function HD(e){return[...e.items].map(e=>e.webkitGetAsEntry?.()??null).filter(e=>e!==null)}async function UD(e){let t={ignored:0,excluded:0,secret:[]};if(e.length!==1||!e[0].isDirectory)return{name:``,files:[],total:0,skipped:t,problems:[`Drop one project folder (not files, and not several folders).`]};let n=e[0],r=[],i=[],a=async(e,n,i)=>{let o=await BD(e),s=o.find(e=>e.isFile&&e.name===`.gitignore`),c=s?[...i,...ID(await(await VD(s)).text(),n)]:i;for(let e of o){let i=n?`${n}/${e.name}`:e.name;if(MD.has(e.name)){t.excluded+=1;continue}if(LD(c,i,e.isDirectory)){t.ignored+=1;continue}if(e.isDirectory){await a(e,i,c);continue}if(FD(e.name)){t.secret.push(i);continue}r.length>jD.files*2||r.push({path:i,file:await VD(e)})}};try{await a(n,``,[])}catch{i.push(`Some of this folder could not be read.`)}return zD(n.name,r,t,i)}async function WD(e){let t={ignored:0,excluded:0,secret:[]},n=[...e].map(e=>{let[,...t]=(e.webkitRelativePath||e.name).split(`/`);return{path:t.join(`/`)||e.name,file:e}}),r=(e[0]?.webkitRelativePath||``).split(`/`)[0]||`project`,i=new Set,a=n.filter(e=>{let t=e.path.split(`/`),n=t.findIndex(e=>MD.has(e));return n<0||(i.add(t.slice(0,n+1).join(`/`)),!1)});t.excluded=i.size;let o=a.filter(e=>e.path.split(`/`).pop()===`.gitignore`).sort((e,t)=>e.path.split(`/`).length-t.path.split(`/`).length),s=[];for(let e of o)s.push(...ID(await e.file.text(),e.path.split(`/`).slice(0,-1).join(`/`)));let c=[];for(let e of a){if(RD(s,e.path)){t.ignored+=1;continue}if(FD(e.path.split(`/`).pop())){t.secret.push(e.path);continue}c.push(e)}return zD(r,c,t,[])}var GD=new TextEncoder;function KD(e,t,n,r,i){let a=new Uint8Array(512),o=(e,t)=>a.set(typeof e==`string`?GD.encode(e):e,t),s=(e,t)=>e.toString(8).padStart(t-1,`0`)+`\0`;o(e,0),o(s(420,8),100),o(s(1e3,8),108),o(s(1e3,8),116),o(s(n,12),124),o(s(Math.max(0,Math.floor(r)),12),136),o(` `,148),o(i,156),o(`ustar\x0000`,257),o(`node`,265),o(`node`,297),o(t,345);let c=0;for(let e of a)c+=e;return o(c.toString(8).padStart(6,`0`)+`\0 `,148),a}function qD(e,t,n){let r=GD.encode(e),i=r.length===e.length;if(i&&r.length<=100)return[KD(r,new Uint8Array,t,n,`0`)];if(i){for(let i=e.lastIndexOf(`/`);i>0;i=e.lastIndexOf(`/`,i-1))if(i<=155&&r.length-i-1<=100)return[KD(r.slice(i+1),r.slice(0,i),t,n,`0`)]}let a=` path=${e}\n`,o=GD.encode(a).length,s=o+String(o).length;String(s).length!==String(o).length&&(s=o+String(s).length);let c=GD.encode(`${s}${a}`),l=new Uint8Array(Math.ceil(c.length/512)*512);l.set(c);let u=GD.encode(e.replace(/[^\x20-\x7e]/g,`_`).slice(-100));return[KD(GD.encode(`PaxHeader`),new Uint8Array,c.length,n,`x`),l,KD(u,new Uint8Array,t,n,`0`)]}async function JD(e){let t=[];for(let{path:n,file:r}of e){t.push(...qD(n,r.size,r.lastModified/1e3),r);let e=r.size%512;e&&t.push(new Uint8Array(512-e))}t.push(new Uint8Array(1024));let n=await new Response(new Blob(t).stream().pipeThrough(new CompressionStream(`gzip`))).blob();if(n.size>jD.archive)throw Error(`The packed project is ${(n.size/AD).toFixed(0)} MiB; the most allowed is ${jD.archive/AD} MiB.`);return n}var YD=1048576,XD=e=>e<YD?`${Math.max(1,Math.round(e/1024))} KiB`:`${(e/YD).toFixed(1)} MiB`,ZD=e=>e.replace(/[^A-Za-z0-9._ -]/g,`-`).slice(0,100),QD=(e,t,n=`${t}s`)=>`${e.toLocaleString()} ${e===1?t:n}`;function $D({onCreated:e}){let[t,n]=(0,_.useState)({at:`idle`}),[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(!1),s=(0,_.useRef)(null),c=async e=>{n({at:`reading`});try{let t=await e;i(ZD(t.name)),n({at:`preview`,project:t})}catch{n({at:`failed`,message:`That folder could not be read.`})}},l=e=>{e.preventDefault(),o(!1),c(UD(HD(e.dataTransfer)))},u=async t=>{let i=x().createSandbox;if(i)try{n({at:`working`,step:`Packing ${QD(t.files.length,`file`)}…`});let a=await JD(t.files);n({at:`working`,step:`Uploading ${XD(a.size)} and starting the sandbox. This can take a minute…`});let o=await i(r.trim(),a),s=await o.json().catch(()=>({}));if(!o.ok||!s.id)throw Error(s.error||`The sandbox could not be created (HTTP ${o.status}).`);n({at:`idle`}),e(s.id)}catch(e){n({at:`failed`,project:t,message:e instanceof Error&&e.message!==`Failed to fetch`?e.message:`RayTrace could not be reached. Check your connection and try again.`})}},d=t.at===`preview`||t.at===`failed`?t.project:void 0,f=/^[A-Za-z0-9._ -]{1,100}$/.test(r.trim());return(0,K.jsxs)(`div`,{className:`rt-new-sandbox`,children:[(t.at===`idle`||t.at===`reading`||t.at===`failed`&&!d)&&(0,K.jsxs)(`div`,{className:a?`rt-drop over`:`rt-drop`,onDragOver:e=>{e.preventDefault(),o(!0)},onDragLeave:()=>o(!1),onDrop:l,children:[(0,K.jsx)(re,{size:20}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`strong`,{children:t.at===`reading`?`Reading the folder…`:`New sandbox: drop a project folder here`}),(0,K.jsxs)(`small`,{children:[`You will see what would be uploaded first. `,(0,K.jsx)(`code`,{children:`.env`}),` files, keys, `,(0,K.jsx)(`code`,{children:`node_modules`}),` and anything your `,(0,K.jsx)(`code`,{children:`.gitignore`}),` excludes stay on this machine. Up to `,jD.total/YD,` MiB, `,jD.file/YD,` MiB a file.`]}),t.at===`failed`&&(0,K.jsx)(`p`,{className:`rt-problem`,children:t.message})]}),(0,K.jsx)(`button`,{type:`button`,className:`rt-button`,disabled:t.at===`reading`,onClick:()=>s.current?.click(),children:`Choose folder`}),(0,K.jsx)(`input`,{ref:s,type:`file`,hidden:!0,multiple:!0,webkitdirectory:``,onChange:e=>{let t=e.target.files;t?.length&&c(WD(t)),e.target.value=``}})]}),d&&(0,K.jsxs)(`div`,{className:`rt-upload-preview`,children:[(0,K.jsxs)(`div`,{className:`rt-upload-head`,children:[(0,K.jsxs)(`label`,{children:[`Sandbox name`,(0,K.jsx)(`input`,{value:r,maxLength:100,onChange:e=>i(e.target.value)})]}),(0,K.jsx)(`button`,{type:`button`,className:`rt-icon-button`,"aria-label":`Cancel`,onClick:()=>n({at:`idle`}),children:(0,K.jsx)(Te,{size:15})})]}),(0,K.jsxs)(`dl`,{className:`rt-facts`,children:[(0,K.jsx)(`dt`,{children:`Will upload`}),(0,K.jsxs)(`dd`,{children:[QD(d.files.length,`file`),` · `,XD(d.total)]}),(0,K.jsx)(`dt`,{children:`Stays here`}),(0,K.jsxs)(`dd`,{children:[!d.skipped.ignored&&!d.skipped.excluded&&!d.skipped.secret.length&&`Nothing was left out.`,d.skipped.ignored>0&&(0,K.jsxs)(`span`,{children:[QD(d.skipped.ignored,`path`),` ignored by .gitignore. `]}),d.skipped.excluded>0&&(0,K.jsxs)(`span`,{children:[QD(d.skipped.excluded,`dependency or build folder`),` (node_modules, .git, dist…). `]}),d.skipped.secret.length>0&&(0,K.jsxs)(`span`,{children:[QD(d.skipped.secret.length,`credential file`),`: `,(0,K.jsxs)(`code`,{children:[d.skipped.secret.slice(0,6).join(`, `),d.skipped.secret.length>6?`, …`:``]})]})]}),(0,K.jsx)(`dt`,{children:`Files`}),(0,K.jsx)(`dd`,{className:`rt-upload-files`,children:(0,K.jsxs)(`code`,{children:[d.files.slice(0,12).map(e=>e.path).join(`
35
+ `)||void 0,children:[(0,K.jsx)(`dt`,{children:`Reached on the network`}),(0,K.jsx)(`dd`,{children:d?m.size:`—`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{children:`Severity`}),(0,K.jsx)(`dd`,{className:`rt-sev-counts`,children:[`none`,`low`,`high`,`severe`].map((e,t)=>(0,K.jsxs)(`button`,{type:`button`,"aria-pressed":E===t,className:`severity-badge severity-${t}${E===t?` rt-sev-on`:``}${E!=null&&E!==t?` rt-sev-off`:``}`,title:E===t?`Show every severity`:`Show only ${e} commands`,onClick:()=>D(e=>e===t?null:t),children:[T[t],` `,e]},e))})]})]}),o&&(0,K.jsx)(`p`,{role:`alert`,className:`verify-error`,children:o}),!a&&!o&&(0,K.jsx)(`p`,{className:`rt-empty`,children:`Loading…`}),a&&!s&&(0,K.jsxs)(K.Fragment,{children:[E!=null&&(0,K.jsxs)(`p`,{className:`rt-foot rt-filter-note`,children:[`Showing `,O.length,` of `,C.length,` commands with `,[`none`,`low`,`high`,`severe`][E],` severity.`,` `,(0,K.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>D(null),children:`Show all`})]}),C.length?O.length?(0,K.jsx)(`div`,{className:`rt-table-wrap`,children:(0,K.jsxs)(`table`,{className:`rt-table rt-sandbox`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{children:`Started`}),(0,K.jsx)(`th`,{children:`Command`}),(0,K.jsx)(`th`,{children:`pid`}),(0,K.jsx)(`th`,{children:`Result`}),(0,K.jsx)(`th`,{children:`Took`}),(0,K.jsx)(`th`,{children:`Severity`}),(0,K.jsx)(`th`,{children:`Tool call`})]})}),(0,K.jsx)(`tbody`,{children:O.map(e=>P(e,0))})]})}):(0,K.jsx)(`p`,{className:`rt-empty`,children:`No commands with this severity.`}):(0,K.jsx)(`p`,{className:`rt-empty`,children:`No commands were captured in the sandbox during this prompt. Missing evidence is not proof of non-execution.`}),(0,K.jsxs)(`p`,{className:`rt-foot`,children:[`Seen by the sandbox kernel layer, independent of what the agent reported. Collector gaps: `,a.gaps,`.`,` `,a.folded&&wu(a.folded)?`Folded, not shown as commands: ${wu(a.folded)}. `:``,(0,K.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>c(!0),children:`Show every raw event`})]})]}),a&&s&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`rt-foot`,children:(0,K.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>c(!1),children:`Back to commands`})}),(0,K.jsx)(`ul`,{className:`evidence-raw`,children:(a.events??[]).map(e=>(0,K.jsxs)(`li`,{children:[(0,K.jsx)(`code`,{children:e.kind===`exec_succeeded`?(e.argv??[]).join(` `):`${e.kind} exit=${e.exit_code??`unknown`}`}),(0,K.jsxs)(`small`,{children:[` pid `,e.pid,` · #`,e.event_id]})]},e.event_id))})]})]}):(0,K.jsx)(`p`,{className:`rt-empty`,children:`This prompt did not run in a sandbox, so there is no independent evidence of what ran.`})]})}var AD=1048576,jD={file:25*AD,total:200*AD,files:2e4,archive:100*AD},MD=new Set([`.git`,`.raytace`,`.raytrace`,`.ssh`,`.aws`,`.azure`,`.config`,`.claude`,`node_modules`,`.venv`,`__pycache__`,`.next`,`.vinext`,`dist`,`coverage`,`.wrangler`,`.DS_Store`]),ND=new Set([`.npmrc`,`.netrc`,`.pypirc`,`.htpasswd`,`.dockercfg`,`credentials`,`credentials.json`,`credentials.ini`,`auth.json`,`service-account.json`,`service_account.json`,`serviceAccountKey.json`,`client_secret.json`,`client_secrets.json`,`token.json`,`id_rsa`,`id_dsa`,`id_ecdsa`,`id_ed25519`,`id_ecdsa_sk`,`id_ed25519_sk`,`known_hosts`]),PD=/\.(pem|key|p12|pfx)$/i,FD=e=>{let t=e.toLowerCase();return t.startsWith(`.env`)||t.startsWith(`.secret`)||PD.test(e)||ND.has(t)};function ID(e,t){let n=[];for(let r of e.split(/\r?\n/)){let e=r.replace(/(?<!\\)\s+$/,``);if(!e||e.startsWith(`#`))continue;let i=e.startsWith(`!`);i&&(e=e.slice(1)),e.startsWith(`\\`)&&(e=e.slice(1));let a=e.endsWith(`/`);if(a&&(e=e.slice(0,-1)),!e)continue;let o=e.includes(`/`);e.startsWith(`/`)&&(e=e.slice(1));let s=``;for(let t=0;t<e.length;t++){let n=e[t];if(n===`*`&&e[t+1]===`*`)e[t+2]===`/`?(s+=`(?:.*/)?`,t+=2):(s+=`.*`,t+=1);else if(n===`*`)s+=`[^/]*`;else if(n===`?`)s+=`[^/]`;else if(n===`[`){let n=e.indexOf(`]`,t+2);n<0?s+=`\\[`:(s+=`[${e.slice(t+1,n).replace(/^!/,`^`).replace(/\\/g,`\\\\`)}]`,t=n)}else s+=n.replace(/[.+^${}()|\\\]]/g,`\\$&`)}try{n.push({base:t,negate:i,dirOnly:a,match:RegExp(`^${o?``:`(?:.*/)?`}${s}$`)})}catch{}}return n}function LD(e,t,n){let r=!1;for(let i of e)(!i.dirOnly||n)&&(!i.base||t.startsWith(`${i.base}/`))&&i.match.test(i.base?t.slice(i.base.length+1):t)&&(r=!i.negate);return r}function RD(e,t){let n=t.split(`/`);for(let t=1;t<n.length;t++)if(LD(e,n.slice(0,t).join(`/`),!0))return!0;return LD(e,t,!1)}function zD(e,t,n,r){let i=[],a=0,o=[];for(let e of t.sort((e,t)=>e.path.localeCompare(t.path))){if(e.file.size>jD.file){o.push(`${e.path} (${(e.file.size/AD).toFixed(0)} MiB)`);continue}i.push(e),a+=e.file.size}return o.length&&r.push(`${o.length} file${o.length===1?` is`:`s are`} over ${jD.file/AD} MiB: ${o.slice(0,5).join(`, `)}${o.length>5?`, …`:``}. Add ${o.length===1?`it`:`them`} to .gitignore, or remove ${o.length===1?`it`:`them`}.`),i.length>jD.files&&r.push(`${i.length.toLocaleString()} files; a project may have at most ${jD.files.toLocaleString()}.`),a>jD.total&&r.push(`${(a/AD).toFixed(0)} MiB in all; a project may be at most ${jD.total/AD} MiB.`),!i.length&&!r.length&&r.push(`No files to upload in this folder.`),{name:e,files:i,total:a,skipped:n,problems:r}}var BD=e=>new Promise((t,n)=>{let r=e.createReader(),i=[],a=()=>r.readEntries(e=>{e.length?(i.push(...e),a()):t(i)},n);a()}),VD=e=>new Promise((t,n)=>e.file(t,n));function HD(e){return[...e.items].map(e=>e.webkitGetAsEntry?.()??null).filter(e=>e!==null)}async function UD(e){let t={ignored:0,excluded:0,secret:[]};if(e.length!==1||!e[0].isDirectory)return{name:``,files:[],total:0,skipped:t,problems:[`Drop one project folder (not files, and not several folders).`]};let n=e[0],r=[],i=[],a=async(e,n,i)=>{let o=await BD(e),s=o.find(e=>e.isFile&&e.name===`.gitignore`),c=s?[...i,...ID(await(await VD(s)).text(),n)]:i;for(let e of o){let i=n?`${n}/${e.name}`:e.name;if(MD.has(e.name)){t.excluded+=1;continue}if(LD(c,i,e.isDirectory)){t.ignored+=1;continue}if(e.isDirectory){await a(e,i,c);continue}if(FD(e.name)){t.secret.push(i);continue}r.length>jD.files*2||r.push({path:i,file:await VD(e)})}};try{await a(n,``,[])}catch{i.push(`Some of this folder could not be read.`)}return zD(n.name,r,t,i)}async function WD(e){let t={ignored:0,excluded:0,secret:[]},n=[...e].map(e=>{let[,...t]=(e.webkitRelativePath||e.name).split(`/`);return{path:t.join(`/`)||e.name,file:e}}),r=(e[0]?.webkitRelativePath||``).split(`/`)[0]||`project`,i=new Set,a=n.filter(e=>{let t=e.path.split(`/`),n=t.findIndex(e=>MD.has(e));return n<0||(i.add(t.slice(0,n+1).join(`/`)),!1)});t.excluded=i.size;let o=a.filter(e=>e.path.split(`/`).pop()===`.gitignore`).sort((e,t)=>e.path.split(`/`).length-t.path.split(`/`).length),s=[];for(let e of o)s.push(...ID(await e.file.text(),e.path.split(`/`).slice(0,-1).join(`/`)));let c=[];for(let e of a){if(RD(s,e.path)){t.ignored+=1;continue}if(FD(e.path.split(`/`).pop())){t.secret.push(e.path);continue}c.push(e)}return zD(r,c,t,[])}var GD=new TextEncoder;function KD(e,t,n,r,i){let a=new Uint8Array(512),o=(e,t)=>a.set(typeof e==`string`?GD.encode(e):e,t),s=(e,t)=>e.toString(8).padStart(t-1,`0`)+`\0`;o(e,0),o(s(420,8),100),o(s(1e3,8),108),o(s(1e3,8),116),o(s(n,12),124),o(s(Math.max(0,Math.floor(r)),12),136),o(` `,148),o(i,156),o(`ustar\x0000`,257),o(`node`,265),o(`node`,297),o(t,345);let c=0;for(let e of a)c+=e;return o(c.toString(8).padStart(6,`0`)+`\0 `,148),a}function qD(e,t,n){let r=GD.encode(e),i=r.length===e.length;if(i&&r.length<=100)return[KD(r,new Uint8Array,t,n,`0`)];if(i){for(let i=e.lastIndexOf(`/`);i>0;i=e.lastIndexOf(`/`,i-1))if(i<=155&&r.length-i-1<=100)return[KD(r.slice(i+1),r.slice(0,i),t,n,`0`)]}let a=` path=${e}\n`,o=GD.encode(a).length,s=o+String(o).length;String(s).length!==String(o).length&&(s=o+String(s).length);let c=GD.encode(`${s}${a}`),l=new Uint8Array(Math.ceil(c.length/512)*512);l.set(c);let u=GD.encode(e.replace(/[^\x20-\x7e]/g,`_`).slice(-100));return[KD(GD.encode(`PaxHeader`),new Uint8Array,c.length,n,`x`),l,KD(u,new Uint8Array,t,n,`0`)]}async function JD(e){let t=[];for(let{path:n,file:r}of e){t.push(...qD(n,r.size,r.lastModified/1e3),r);let e=r.size%512;e&&t.push(new Uint8Array(512-e))}t.push(new Uint8Array(1024));let n=await new Response(new Blob(t).stream().pipeThrough(new CompressionStream(`gzip`))).blob();if(n.size>jD.archive)throw Error(`The packed project is ${(n.size/AD).toFixed(0)} MiB; the most allowed is ${jD.archive/AD} MiB.`);return n}var YD=1048576,XD=e=>e<YD?`${Math.max(1,Math.round(e/1024))} KiB`:`${(e/YD).toFixed(1)} MiB`,ZD=e=>e.replace(/[^A-Za-z0-9._ -]/g,`-`).slice(0,100),QD=(e,t,n=`${t}s`)=>`${e.toLocaleString()} ${e===1?t:n}`;function $D({onCreated:e}){let[t,n]=(0,_.useState)({at:`idle`}),[r,i]=(0,_.useState)(``),[a,o]=(0,_.useState)(!1),s=(0,_.useRef)(null),c=async e=>{n({at:`reading`});try{let t=await e;i(ZD(t.name)),n({at:`preview`,project:t})}catch{n({at:`failed`,message:`That folder could not be read.`})}},l=e=>{e.preventDefault(),o(!1),c(UD(HD(e.dataTransfer)))},u=async t=>{let i=x().createSandbox;if(i)try{n({at:`working`,step:`Packing ${QD(t.files.length,`file`)}…`});let a=await JD(t.files);n({at:`working`,step:`Uploading ${XD(a.size)} and starting the sandbox. This can take a minute…`});let o=await i(r.trim(),a),s=await o.json().catch(()=>({}));if(!o.ok||!s.id)throw Error(s.error||`The sandbox could not be created (HTTP ${o.status}).`);n({at:`idle`}),e(s.id)}catch(e){n({at:`failed`,project:t,message:e instanceof Error&&e.message!==`Failed to fetch`?e.message:`RayTrace could not be reached. Check your connection and try again.`})}},d=t.at===`preview`||t.at===`failed`?t.project:void 0,f=/^[A-Za-z0-9._ -]{1,100}$/.test(r.trim());return(0,K.jsxs)(`div`,{className:`rt-new-sandbox`,children:[(t.at===`idle`||t.at===`reading`||t.at===`failed`&&!d)&&(0,K.jsxs)(`div`,{className:a?`rt-drop over`:`rt-drop`,onDragOver:e=>{e.preventDefault(),o(!0)},onDragLeave:()=>o(!1),onDrop:l,children:[(0,K.jsx)(re,{size:20}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`strong`,{children:t.at===`reading`?`Reading the folder…`:`New sandbox: drop a project folder here`}),(0,K.jsxs)(`small`,{children:[`You will see what would be uploaded first. `,(0,K.jsx)(`code`,{children:`.env`}),` files, keys, `,(0,K.jsx)(`code`,{children:`node_modules`}),` and anything your `,(0,K.jsx)(`code`,{children:`.gitignore`}),` excludes stay on this machine. Up to `,jD.total/YD,` MiB, `,jD.file/YD,` MiB a file.`]}),t.at===`failed`&&(0,K.jsx)(`p`,{className:`rt-problem`,children:t.message})]}),(0,K.jsx)(`button`,{type:`button`,className:`rt-button`,disabled:t.at===`reading`,onClick:()=>s.current?.click(),children:`Choose folder`}),(0,K.jsx)(`input`,{ref:s,type:`file`,hidden:!0,multiple:!0,webkitdirectory:``,onChange:e=>{let t=e.target.files;t?.length&&c(WD(t)),e.target.value=``}})]}),d&&(0,K.jsxs)(`div`,{className:`rt-upload-preview`,children:[(0,K.jsxs)(`div`,{className:`rt-upload-head`,children:[(0,K.jsxs)(`label`,{children:[`Sandbox name`,(0,K.jsx)(`input`,{value:r,maxLength:100,onChange:e=>i(e.target.value)})]}),(0,K.jsx)(`button`,{type:`button`,className:`rt-icon-button`,"aria-label":`Cancel`,onClick:()=>n({at:`idle`}),children:(0,K.jsx)(Te,{size:15})})]}),(0,K.jsxs)(`dl`,{className:`rt-facts`,children:[(0,K.jsx)(`dt`,{children:`Will upload`}),(0,K.jsxs)(`dd`,{children:[QD(d.files.length,`file`),` · `,XD(d.total)]}),(0,K.jsx)(`dt`,{children:`Stays here`}),(0,K.jsxs)(`dd`,{children:[!d.skipped.ignored&&!d.skipped.excluded&&!d.skipped.secret.length&&`Nothing was left out.`,d.skipped.ignored>0&&(0,K.jsxs)(`span`,{children:[QD(d.skipped.ignored,`path`),` ignored by .gitignore. `]}),d.skipped.excluded>0&&(0,K.jsxs)(`span`,{children:[QD(d.skipped.excluded,`dependency or build folder`),` (node_modules, .git, dist…). `]}),d.skipped.secret.length>0&&(0,K.jsxs)(`span`,{children:[QD(d.skipped.secret.length,`credential file`),`: `,(0,K.jsxs)(`code`,{children:[d.skipped.secret.slice(0,6).join(`, `),d.skipped.secret.length>6?`, …`:``]})]})]}),(0,K.jsx)(`dt`,{children:`Files`}),(0,K.jsx)(`dd`,{className:`rt-upload-files`,children:(0,K.jsxs)(`code`,{children:[d.files.slice(0,12).map(e=>e.path).join(`
36
36
  `),d.files.length>12?`\n… and ${(d.files.length-12).toLocaleString()} more`:``]})})]}),d.problems.map(e=>(0,K.jsx)(`p`,{className:`rt-problem`,children:e},e)),t.at===`failed`&&(0,K.jsx)(`p`,{className:`rt-problem`,children:t.message}),(0,K.jsxs)(`div`,{className:`rt-actions`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`rt-button primary`,disabled:d.problems.length>0||!f,onClick:()=>void u(d),children:[(0,K.jsx)(xe,{size:13}),` Create sandbox`]}),(0,K.jsx)(`button`,{type:`button`,className:`rt-button`,onClick:()=>n({at:`idle`}),children:`Cancel`}),!f&&(0,K.jsx)(`small`,{className:`rt-muted`,children:`Name: letters, digits, spaces, and . _ - only.`})]})]}),t.at===`working`&&(0,K.jsx)(`p`,{className:`rt-upload-working`,children:t.step})]})}var eO=e=>e.split(`
37
37
  `).find(e=>e.trim())?.trim()??`(empty prompt)`,tO=e=>new Date(typeof e==`number`?e*1e3:e).toLocaleString(void 0,{day:`numeric`,month:`short`,hour:`numeric`,minute:`2-digit`}),nO=e=>e==null?`—`:`${(e/1048576).toFixed(e<1048576?2:1)} MiB`;function rO(e){return e===`lima`?{title:`Local VM`,detail:`Lima on this machine`}:{title:`Cloud VM ${e.split(`@`).pop()}`,detail:e}}function iO(e){return e.status===`deleted`?{label:`Destroyed`,tone:`deleted`}:e.on_host?e.status===`running`?{label:`Running`,tone:`running`}:e.status===`import_failed`?{label:`Failed to create`,tone:`deleted`}:{label:`Stopped`,tone:`stopped`}:{label:`Not connected`,tone:`unknown`}}function aO({traces:e,selectedId:t,onSelect:n,onOpenTrace:r,onOpenScan:i}){let[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)(``),[h,g]=(0,_.useState)(0),v=!!x().createSandbox;(0,_.useEffect)(()=>{let e=!1,t,n=async()=>{try{let t=await x().fetch(`/raytace/sandboxes`,{cache:`no-store`}),n=await t.json();if(!t.ok)throw Error(n.error||`Sandbox list unavailable`);e||(o(n.sandboxes??[]),c(null))}catch(t){e||c(t instanceof Error?t.message:`Proxy unavailable`)}e||(t=setTimeout(n,1e4))};return n(),()=>{e=!0,clearTimeout(t)}},[h]);let y=new Map;for(let t of e)t.sandboxId&&!t.forkId&&y.set(t.sandboxId,[...y.get(t.sandboxId)??[],t]);let b=[...new Set((a??[]).map(e=>e.host))].sort((e,t)=>{let n=e=>+!(a??[]).some(t=>t.host===e&&t.on_host);return n(e)-n(t)||e.localeCompare(t)}),S=e=>typeof e.created==`number`?e.created*1e3:Date.parse(e.created),C=e=>{navigator.clipboard?.writeText(e),u(e),setTimeout(()=>u(``),1500)},[w,T]=(0,_.useState)(null),E=async e=>{f(e.id),m(``);try{let t=await x().fetch(`/raytace/sandboxes/${e.id}`,{method:`DELETE`,headers:{"x-raytace-experiment":`1`}}),r=await t.json().catch(()=>({}));if(!t.ok)throw Error(r.error||`Destroy failed`);n(``),g(e=>e+1)}catch(e){m(e instanceof Error?e.message:`Destroy failed`)}finally{f(``),T(null)}};return(0,K.jsxs)(`section`,{className:`rt-view`,children:[(0,K.jsx)(`header`,{className:`rt-view-head`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`span`,{className:`eyebrow`,children:`SANDBOXES`}),(0,K.jsx)(`h1`,{children:`Where your agents ran`})]})}),v&&(0,K.jsx)($D,{onCreated:e=>{g(e=>e+1),(i??n)(e)}}),s&&(0,K.jsx)(`p`,{className:`rt-empty`,children:s}),p&&(0,K.jsx)(`p`,{className:`rt-empty`,children:p}),!s&&a===null&&(0,K.jsx)(`p`,{className:`rt-empty`,children:`Loading…`}),!s&&a?.length===0&&(0,K.jsxs)(`p`,{className:`rt-empty`,children:[`No sandboxes yet. `,v?`Drop a project folder above, or from`:`From`,` a Git repository: `,(0,K.jsx)(`code`,{children:`raytrace sandbox create`})]}),b.map(e=>{let o=rO(e),s=(a??[]).filter(t=>t.host===e).sort((e,t)=>Number(e.status===`deleted`)-Number(t.status===`deleted`)||S(t)-S(e)),c=s.some(e=>e.on_host);return(0,K.jsxs)(`div`,{className:`rt-host`,children:[(0,K.jsxs)(`div`,{className:`rt-list-head`,children:[(0,K.jsxs)(`span`,{className:`rt-host-title`,children:[(0,K.jsx)(_e,{size:13}),` `,o.title.toUpperCase()]}),(0,K.jsxs)(`small`,{children:[o.detail,` · `,c?`connected`:`not connected now`,` · `,s.length,` sandbox`,s.length===1?``:`es`]})]}),(0,K.jsx)(`ol`,{className:`rt-prompts`,children:s.map(e=>{let a=e.id===t,s=(y.get(e.id)??[]).sort((e,t)=>t.startedAt.localeCompare(e.startedAt)),c=iO(e),u=`raytrace connect ${e.host===`lima`&&e.name?e.name:e.id}`;return(0,K.jsxs)(`li`,{className:a?`rt-prompt open`:`rt-prompt`,children:[(0,K.jsxs)(`button`,{type:`button`,className:`rt-prompt-row`,"aria-expanded":a,onClick:()=>n(a?``:e.id),children:[(0,K.jsx)(`time`,{children:tO(e.created)}),(0,K.jsxs)(`strong`,{children:[(0,K.jsx)(`span`,{className:`rt-state s-${c.tone}`,children:c.label}),e.name]}),(0,K.jsxs)(`small`,{children:[s.length,` prompt`,s.length===1?``:`s`,` · `,e.id.slice(0,12),`…`]})]}),a&&(0,K.jsxs)(`div`,{className:`rt-prompt-detail`,children:[(0,K.jsxs)(`dl`,{className:`rt-facts`,children:[(0,K.jsx)(`dt`,{children:`Sandbox`}),(0,K.jsx)(`dd`,{children:(0,K.jsx)(`code`,{children:e.id})}),(0,K.jsx)(`dt`,{children:`Runs on`}),(0,K.jsxs)(`dd`,{children:[o.title,` `,(0,K.jsxs)(`span`,{className:`rt-muted`,children:[`(`,o.detail,`)`]})]}),(0,K.jsx)(`dt`,{children:`State`}),(0,K.jsxs)(`dd`,{children:[c.label,!e.on_host&&e.status!==`deleted`?(0,K.jsxs)(`span`,{className:`rt-muted`,children:[` — the manager is connected to another VM; last recorded: `,e.status]}):null]}),(0,K.jsx)(`dt`,{children:`Created`}),(0,K.jsxs)(`dd`,{children:[tO(e.created),e.deleted?(0,K.jsxs)(`span`,{className:`rt-muted`,children:[` · destroyed `,tO(e.deleted)]}):null]}),e.host!==`lima`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`dt`,{children:`Uploaded`}),(0,K.jsxs)(`dd`,{children:[nO(e.imported_bytes),e.skipped_count?(0,K.jsxs)(`span`,{className:`rt-muted`,children:[` · `,e.skipped_count,` file`,e.skipped_count===1?``:`s`,` left out`]}):null]})]}),(0,K.jsx)(`dt`,{children:`Recording`}),(0,K.jsx)(`dd`,{children:e.transcripts===!1?`Commands only (no Claude Code transcripts)`:`Commands and Claude Code transcripts`}),i&&e.scan?.by_level&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`dt`,{children:`Initial scan`}),(0,K.jsxs)(`dd`,{children:[e.scan.files,` files, `,(e.scan.by_level[4]??0)+(e.scan.by_level[5]??0),` at level 4 or 5`,` `,(0,K.jsxs)(`button`,{type:`button`,className:`link-button`,onClick:()=>i(e.id),children:[(0,K.jsx)(he,{size:11}),` Open the scan`]})]})]})]}),e.status!==`deleted`&&e.on_host&&(0,K.jsxs)(`div`,{className:`rt-shell-line`,children:[(0,K.jsx)(`code`,{children:u}),(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>C(u),children:[(0,K.jsx)(V,{size:13}),` `,l===u?`Copied`:`Copy`]})]}),e.host===`lima`&&(0,K.jsxs)(`div`,{className:`rt-shell-line`,children:[(0,K.jsxs)(`code`,{children:[`raytrace sandbox destroy `,e.name||e.id]}),(0,K.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>C(`raytrace sandbox destroy ${e.name||e.id}`),children:[(0,K.jsx)(V,{size:13}),` `,l===`raytrace sandbox destroy ${e.name||e.id}`?`Copied`:`Copy`]})]}),e.host===`lima`&&(0,K.jsxs)(`p`,{className:`rt-foot`,children:[`Run the first command in a terminal to open this sandbox, then start `,(0,K.jsx)(`code`,{children:`claude`}),` or `,(0,K.jsx)(`code`,{children:`codex`}),` there. The second deletes it, and asks whether to delete the logs recorded in it too.`]}),e.host!==`lima`&&e.status!==`deleted`&&e.on_host&&(0,K.jsxs)(`div`,{className:`rt-shell-line`,children:[(0,K.jsx)(`code`,{children:`Destroy this sandbox and stop anything running in it. Its recorded evidence stays.`}),(0,K.jsx)(`button`,{type:`button`,className:`rt-button`,disabled:d===e.id,onClick:()=>T(e),children:d===e.id?`Destroying…`:`Destroy`})]}),e.host!==`lima`&&e.status!==`deleted`&&e.on_host&&(0,K.jsxs)(`p`,{className:`rt-foot`,children:[`Run it in a terminal to open this sandbox, then start `,(0,K.jsx)(`code`,{children:`claude`}),` or `,(0,K.jsx)(`code`,{children:`codex`}),` there. Needs the RayTrace CLI, signed in as this account: `,(0,K.jsx)(`code`,{children:`npm install -g @raytrace-cli/cli@latest`}),`. On CLI 0.2 the command is `,(0,K.jsxs)(`code`,{children:[`raytrace sandbox shell `,e.id]}),`.`]}),(0,K.jsx)(`h3`,{children:`History`}),!s.length&&(0,K.jsx)(`p`,{className:`rt-muted`,children:`No prompts recorded in this sandbox yet.`}),s.length>0&&(0,K.jsx)(`ol`,{className:`rt-history`,children:s.map(e=>{let t=e.callVerifications??[],n=t.filter(e=>e.exec_id||(e.kind?e.kind===`command`:e.proposed!=null)),i=n.filter(e=>e.exec_id).length,a=t.filter(e=>e.kind===`file`&&!e.exec_id).length;return(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,onClick:()=>r(e.id),children:[(0,K.jsx)(`time`,{dateTime:e.startedAt,children:tO(e.startedAt)}),(0,K.jsx)(`span`,{children:eO(e.title)}),(0,K.jsxs)(`small`,{className:n.length&&i===n.length?`all`:``,children:[n.length?`${i} of ${n.length} command${n.length===1?``:`s`} observed in the sandbox`:`no commands`,a>0&&` · ${a} file operation${a===1?``:`s`}`]}),(0,K.jsx)(P,{size:13})]})},e.id)})})]})]},e.id)})})]},e)}),w&&(0,K.jsxs)(`dialog`,{open:!0,className:`rt-dialog`,"aria-labelledby":`rt-destroy-title`,onCancel:e=>{e.preventDefault(),d||T(null)},children:[(0,K.jsx)(`h2`,{id:`rt-destroy-title`,children:`Destroy this sandbox?`}),(0,K.jsxs)(`p`,{children:[`“`,w.name||w.id,`” stops and is deleted. Its recorded evidence stays.`]}),(0,K.jsxs)(`div`,{className:`rt-dialog-actions`,children:[(0,K.jsx)(`button`,{type:`button`,className:`rt-button`,autoFocus:!0,disabled:!!d,onClick:()=>T(null),children:`No`}),(0,K.jsx)(`button`,{type:`button`,className:`rt-button rt-danger`,disabled:!!d,onClick:()=>void E(w),children:d?`Destroying…`:`Yes, destroy`})]})]})]})}var oO=[`prompts`,`search`,`story`,`sandboxes`,`scan`,`calls`,`changes`,`sandbox`,`context`,`thought`,`playground`];function sO(e){let t=new URLSearchParams(typeof window>`u`?``:window.location.search),n=t.get(`view`),r=n===`lab`?`context`:n;return{view:r&&e.includes(r)?r:`prompts`,trace:t.get(`trace`)??``,call:t.get(`call`),step:t.get(`step`),box:t.get(`box`)??``,q:t.get(`q`)??``}}function cO(e){let t=new URLSearchParams;e.view!==`prompts`&&t.set(`view`,e.view),e.trace&&t.set(`trace`,e.trace),e.call&&t.set(`call`,e.call),e.step&&t.set(`step`,e.step),e.box&&t.set(`box`,e.box),e.view===`search`&&e.q&&t.set(`q`,e.q);let n=t.toString();window.history.pushState(null,``,n?`?${n}`:window.location.pathname)}var lO=e=>e.split(`
38
- `).find(e=>e.trim())?.trim()??``,uO=e=>`${e.exchange_id}:${e.output_index}`;function dO({views:e=oO,offline:t=`PROXY OFFLINE`,footer:n=null}){let r=t=>e.includes(t),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)({view:`prompts`,trace:``,call:null,step:null,box:``,q:``}),[f,p]=(0,_.useState)(``),m=(0,_.useRef)(null),h=Mw();(0,_.useEffect)(()=>{d(sO(e));let t=()=>d(sO(e));return window.addEventListener(`popstate`,t),()=>window.removeEventListener(`popstate`,t)},[e]);let g=(0,_.useCallback)(e=>{d(t=>{let n={...t,call:null,step:null,box:``,q:``,...e};return cO(n),n})},[]);(0,_.useEffect)(()=>{let e=!1,t,n=``,r=async()=>{try{let t=await x().fetch(`/raytace/traces?scope=history`,{cache:`no-store`,headers:n?{"if-none-match":n}:{}});if(t.status===304)e||s(!0);else{if(!t.ok)throw Error(`Proxy unavailable`);let r=await t.json();n=t.headers.get(`etag`)??``,e||(a(r.traces||[]),s(!0))}}catch{e||s(!1)}e||(l(!0),t=setTimeout(r,5e3))};return r(),()=>{e=!0,clearTimeout(t)}},[]);let[v,y]=(0,_.useState)(0),[b,S]=(0,_.useState)(0),C=e.includes(`scan`);(0,_.useEffect)(()=>{if(!C)return;let e=!1,t,n=async()=>{try{let t=await Gw();e||y(t.unseen)}catch{}e||(t=setTimeout(n,1e4))};return n(),()=>{e=!0,clearTimeout(t)}},[C,b]);let w=i.find(e=>e.id===u.trace),T=[{view:`prompts`,label:`Prompts`,icon:ce},{view:`search`,label:`Search`,icon:ge},{view:`story`,label:`Story`,icon:le},{view:`sandboxes`,label:`Sandboxes`,icon:L},{view:`scan`,label:`Initial scan`,icon:he},{view:`calls`,label:`Tool calls`,icon:we},{view:`changes`,label:`Changes`,icon:U},{view:`sandbox`,label:`Sandbox evidence`,icon:ve},{view:`context`,label:`Context`,icon:oe},{view:`thought`,label:`Chain of thought`,icon:R},{view:`playground`,label:`Playground`,icon:ie}].filter(e=>r(e.view));function E(){return!c&&u.trace?(0,K.jsx)(`section`,{className:`rt-view`,children:(0,K.jsx)(`p`,{className:`rt-empty`,children:`Loading…`})}):(0,K.jsx)(`section`,{className:`rt-view`,children:(0,K.jsxs)(`p`,{className:`rt-empty`,children:[c&&u.trace&&!w?`That prompt is no longer in the loaded history.`:`Choose a prompt first.`,` `,(0,K.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>g({view:`prompts`}),children:`Go to Prompts`})]})})}return(0,K.jsxs)(`main`,{className:`rt-shell`,ref:m,children:[(0,K.jsxs)(`aside`,{className:`nav rt-nav`,children:[(0,K.jsxs)(`div`,{className:`brand`,children:[(0,K.jsx)(Se,{size:22}),` RayTrace`]}),r(`search`)&&(0,K.jsxs)(`form`,{className:`rt-nav-search`,onSubmit:e=>{e.preventDefault(),g({view:`search`,q:f})},children:[(0,K.jsx)(ge,{size:13}),(0,K.jsx)(`input`,{value:f,onChange:e=>p(e.target.value),placeholder:`Search what agents did…`,"aria-label":`Search agent activity`,spellCheck:!1})]}),(0,K.jsx)(`nav`,{className:`nav-destinations`,children:T.map(({view:e,label:t,icon:n})=>(0,K.jsxs)(`button`,{type:`button`,className:`nav-item ${u.view===e?`active`:``}`,onClick:()=>g({view:e,trace:u.trace,...e===`scan`?{box:u.box||w?.sandboxId||``}:{}}),children:[(0,K.jsx)(n,{size:16}),` `,t,e===`scan`&&v>0&&(0,K.jsx)(`span`,{className:`rt-count`,title:`${v} unseen alert${v===1?``:`s`}`,children:v})]},e))}),w&&(0,K.jsxs)(`div`,{className:`rt-viewing`,children:[(0,K.jsx)(`span`,{className:`workspace-label`,children:`VIEWING`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>g({view:`prompts`,trace:w.id}),title:w.title,children:lO(w.title)}),(0,K.jsx)(`small`,{children:new Date(w.startedAt).toLocaleString(void 0,{day:`numeric`,month:`short`,hour:`numeric`,minute:`2-digit`})})]}),(0,K.jsxs)(`div`,{className:`nav-bottom`,children:[(0,K.jsxs)(`div`,{className:`nav-status`,children:[(0,K.jsxs)(`span`,{className:`status ${c?o?``:`offline`:`pending`}`,children:[(0,K.jsx)(`i`,{}),c?o?`CONNECTED`:t:`CONNECTING…`]}),(0,K.jsx)(`button`,{type:`button`,className:`theme-toggle`,onClick:()=>Aw(h===`light`?`dark`:`light`),"aria-pressed":h===`dark`,"aria-label":`Switch to ${h===`light`?`dark`:`light`} theme`,title:`Switch to ${h===`light`?`dark`:`light`} theme`,children:`◐`})]}),n]}),(0,K.jsx)(CE,{target:m,variable:`--nav-width`,storageKey:`raytace.nav-width`,min:180,max:480,label:`Navigation width`})]}),u.view===`prompts`&&r(`prompts`)&&(0,K.jsx)(eD,{traces:i.filter(e=>!e.forkId),loaded:c,selectedId:u.trace,onSelect:e=>g({view:`prompts`,trace:e}),onOpen:(e,t)=>g({view:e,trace:t}),onOpenStep:(e,t)=>g({view:`calls`,trace:e,call:t}),canOpen:r}),u.view===`search`&&r(`search`)&&(0,K.jsx)(lD,{initialQuery:u.q,onQuery:e=>g({view:`search`,trace:u.trace,q:e}),onOpenCall:(e,t)=>g({view:`calls`,trace:e,call:t}),onOpenTrace:e=>g({view:`prompts`,trace:e}),onOpenSandbox:r(`sandbox`)?(e,t)=>g({view:`sandbox`,trace:e,call:t}):void 0},u.q),u.view===`story`&&r(`story`)&&(w?(0,K.jsx)(wD,{trace:w,focusCall:u.call,onSelect:e=>g({view:`story`,trace:w.id,call:e}),onOpenCall:e=>g({view:`calls`,trace:w.id,call:e}),onOpenThought:r(`thought`)?e=>g({view:`thought`,trace:w.id,call:e}):void 0,onOpenSandbox:r(`sandbox`)?e=>g({view:`sandbox`,trace:w.id,call:e}):void 0},w.id):E()),u.view===`sandboxes`&&r(`sandboxes`)&&(0,K.jsx)(aO,{traces:i,selectedId:u.box,onSelect:e=>g({view:`sandboxes`,box:e}),onOpenTrace:e=>g({view:`calls`,trace:e}),onOpenScan:r(`scan`)?e=>g({view:`scan`,trace:u.trace,box:e}):void 0}),u.view===`scan`&&r(`scan`)&&(0,K.jsx)(xT,{box:u.box,traces:i,onSelect:e=>g({view:`scan`,trace:u.trace,box:e}),onOpenCall:(e,t)=>g({view:`calls`,trace:e,call:t}),onAlertsSeen:()=>S(e=>e+1)}),u.view===`calls`&&r(`calls`)&&(w?(0,K.jsx)(KT,{trace:w,traces:i,focusCall:u.call,onOpenSandbox:r(`sandbox`)?e=>g({view:`sandbox`,trace:w.id,call:e??null}):void 0,onOpenContext:r(`context`)?e=>g({view:`context`,trace:w.id,step:uO(e)}):void 0,onOpenThought:r(`thought`)?e=>g({view:`thought`,trace:w.id,call:e}):void 0,onOpenPlayground:r(`playground`)?(e,t)=>g({view:`playground`,trace:w.id,step:e,call:t??null}):void 0},w.id):E()),u.view===`changes`&&r(`changes`)&&(w?(0,K.jsx)(ED,{trace:w,onOpenCall:r(`calls`)?e=>g({view:`calls`,trace:w.id,call:e}):void 0},w.id):E()),u.view===`sandbox`&&r(`sandbox`)&&(w?(0,K.jsx)(kD,{trace:w,focusCall:u.call,onOpenCall:e=>g({view:`calls`,trace:w.id,call:e??null})},w.id):E()),u.view===`playground`&&r(`playground`)&&(w?(0,K.jsx)(GE,{trace:w,stepId:u.step,removeCall:u.call,forkTraces:i.filter(e=>e.forkId),onStep:e=>g({view:`playground`,trace:w.id,step:e}),onOpenTrace:e=>g({view:`calls`,trace:e})},`${w.id}:${u.step??``}`):E()),u.view===`context`&&r(`context`)&&(w?(0,K.jsx)(bE,{trace:w,stepKey:u.step,onStep:e=>g({view:`context`,trace:w.id,step:e}),onRerunWithout:r(`playground`)?(e,t)=>g({view:`playground`,trace:w.id,step:e,call:t}):void 0},w.id):E()),u.view===`thought`&&r(`thought`)&&(w?(0,K.jsx)(oE,{trace:w,focusCall:u.call},w.id):E())]})}var fO=[`prompts`,`search`,`story`,`sandboxes`,`calls`,`changes`,`sandbox`,`context`,`thought`,`playground`];S({fetch:(e,t)=>fetch(e,t)});var pO=4;function mO(){let[e,t]=(0,_.useState)(!1),[n,r]=(0,_.useState)(!1);return(0,_.useEffect)(()=>{fetch(`/raytace/version`).then(e=>e.ok?e.json():{api:0}).then(e=>t((Number(e.api)||0)<pO),()=>{}),fetch(`/raytace/models`).then(e=>r(e.status===401),()=>{})},[]),!e&&!n?null:(0,K.jsx)(`div`,{role:`alert`,style:{padding:`10px 16px`,background:`light-dark(#fff4d6,#3a2f12)`,color:`light-dark(#5c4300,#ffd97a)`,fontSize:13,borderBottom:`1px solid light-dark(#f0d48a,#5c4a1c)`},children:e?(0,K.jsxs)(K.Fragment,{children:[`An older RayTrace proxy is running, so parts of this page cannot load. Restart it: `,(0,K.jsx)(`code`,{children:`raytrace stop && raytrace start`})]}):(0,K.jsxs)(K.Fragment,{children:[`This browser is not signed in to RayTrace, so nothing can load. In a terminal, run: `,(0,K.jsx)(`code`,{children:`raytrace open`})]})})}(0,v.createRoot)(document.getElementById(`root`)).render((0,K.jsxs)(_.StrictMode,{children:[(0,K.jsx)(mO,{}),(0,K.jsx)(dO,{views:fO})]}));
38
+ `).find(e=>e.trim())?.trim()??``,uO=e=>`${e.exchange_id}:${e.output_index}`;function dO({views:e=oO,offline:t=`PROXY OFFLINE`,footer:n=null}){let r=t=>e.includes(t),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)({view:`prompts`,trace:``,call:null,step:null,box:``,q:``}),[f,p]=(0,_.useState)(``),m=(0,_.useRef)(null),h=Mw();(0,_.useEffect)(()=>{d(sO(e));let t=()=>d(sO(e));return window.addEventListener(`popstate`,t),()=>window.removeEventListener(`popstate`,t)},[e]);let g=(0,_.useCallback)(e=>{d(t=>{let n={...t,call:null,step:null,box:``,q:``,...e};return cO(n),n})},[]);(0,_.useEffect)(()=>{let e=!1,t,n=``,r=async()=>{try{let t=await x().fetch(`/raytace/traces?scope=history`,{cache:`no-store`,headers:n?{"if-none-match":n}:{}});if(t.status===304)e||s(!0);else{if(!t.ok)throw Error(`Proxy unavailable`);let r=await t.json();n=t.headers.get(`etag`)??``,e||(a(r.traces||[]),s(!0))}}catch{e||s(!1)}e||(l(!0),t=setTimeout(r,5e3))};return r(),()=>{e=!0,clearTimeout(t)}},[]);let[v,y]=(0,_.useState)(0),[b,S]=(0,_.useState)(0),C=e.includes(`scan`);(0,_.useEffect)(()=>{if(!C)return;let e=!1,t,n=async()=>{try{let t=await Gw();e||y(t.unseen)}catch{}e||(t=setTimeout(n,1e4))};return n(),()=>{e=!0,clearTimeout(t)}},[C,b]);let w=i.find(e=>e.id===u.trace),T=[{view:`prompts`,label:`Prompts`,icon:ce},{view:`search`,label:`Search`,icon:ge},{view:`story`,label:`Story`,icon:le},{view:`sandboxes`,label:`Sandboxes`,icon:L},{view:`scan`,label:`Initial scan`,icon:he},{view:`calls`,label:`Tool calls`,icon:we},{view:`changes`,label:`Changes`,icon:U},{view:`sandbox`,label:`Sandbox evidence`,icon:ve},{view:`context`,label:`Context`,icon:oe},{view:`thought`,label:`Chain of thought`,icon:R},{view:`playground`,label:`Playground`,icon:ie}].filter(e=>r(e.view));function E(){return!c&&u.trace?(0,K.jsx)(`section`,{className:`rt-view`,children:(0,K.jsx)(`p`,{className:`rt-empty`,children:`Loading…`})}):(0,K.jsx)(`section`,{className:`rt-view`,children:(0,K.jsxs)(`p`,{className:`rt-empty`,children:[c&&u.trace&&!w?`That prompt is no longer in the loaded history.`:`Choose a prompt first.`,` `,(0,K.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>g({view:`prompts`}),children:`Go to Prompts`})]})})}return(0,K.jsxs)(`main`,{className:`rt-shell`,ref:m,children:[(0,K.jsxs)(`aside`,{className:`nav rt-nav`,children:[(0,K.jsxs)(`div`,{className:`brand`,children:[(0,K.jsx)(Se,{size:22}),` RayTrace`]}),r(`search`)&&(0,K.jsxs)(`form`,{className:`rt-nav-search`,onSubmit:e=>{e.preventDefault(),g({view:`search`,q:f})},children:[(0,K.jsx)(ge,{size:13}),(0,K.jsx)(`input`,{value:f,onChange:e=>p(e.target.value),placeholder:`Search what agents did…`,"aria-label":`Search agent activity`,spellCheck:!1})]}),(0,K.jsx)(`nav`,{className:`nav-destinations`,children:T.map(({view:e,label:t,icon:n})=>(0,K.jsxs)(`button`,{type:`button`,className:`nav-item ${u.view===e?`active`:``}`,onClick:()=>g({view:e,trace:u.trace,...e===`scan`?{box:u.box||w?.sandboxId||``}:{}}),children:[(0,K.jsx)(n,{size:16}),` `,t,e===`scan`&&v>0&&(0,K.jsx)(`span`,{className:`rt-count`,title:`${v} unseen alert${v===1?``:`s`}`,children:v})]},e))}),w&&(0,K.jsxs)(`div`,{className:`rt-viewing`,children:[(0,K.jsx)(`span`,{className:`workspace-label`,children:`VIEWING`}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>g({view:`prompts`,trace:w.id}),title:w.title,children:lO(w.title)}),(0,K.jsx)(`small`,{children:new Date(w.startedAt).toLocaleString(void 0,{day:`numeric`,month:`short`,hour:`numeric`,minute:`2-digit`})})]}),(0,K.jsxs)(`div`,{className:`nav-bottom`,children:[(0,K.jsxs)(`div`,{className:`nav-status`,children:[(0,K.jsxs)(`span`,{className:`status ${c?o?``:`offline`:`pending`}`,children:[(0,K.jsx)(`i`,{}),c?o?`CONNECTED`:t:`CONNECTING…`]}),(0,K.jsx)(`button`,{type:`button`,className:`theme-toggle`,onClick:()=>Aw(h===`light`?`dark`:`light`),"aria-pressed":h===`dark`,"aria-label":`Switch to ${h===`light`?`dark`:`light`} theme`,title:`Switch to ${h===`light`?`dark`:`light`} theme`,children:`◐`})]}),n]}),(0,K.jsx)(CE,{target:m,variable:`--nav-width`,storageKey:`raytace.nav-width`,min:180,max:480,label:`Navigation width`})]}),u.view===`prompts`&&r(`prompts`)&&(0,K.jsx)(eD,{traces:i.filter(e=>!e.forkId),loaded:c,selectedId:u.trace,box:u.box,onBox:e=>g({view:`prompts`,box:e}),onSelect:e=>g({view:`prompts`,trace:e,box:u.box}),onOpen:(e,t)=>g({view:e,trace:t}),onOpenStep:(e,t)=>g({view:`calls`,trace:e,call:t}),canOpen:r}),u.view===`search`&&r(`search`)&&(0,K.jsx)(lD,{initialQuery:u.q,onQuery:e=>g({view:`search`,trace:u.trace,q:e}),onOpenCall:(e,t)=>g({view:`calls`,trace:e,call:t}),onOpenTrace:e=>g({view:`prompts`,trace:e}),onOpenSandbox:r(`sandbox`)?(e,t)=>g({view:`sandbox`,trace:e,call:t}):void 0},u.q),u.view===`story`&&r(`story`)&&(w?(0,K.jsx)(wD,{trace:w,focusCall:u.call,onSelect:e=>g({view:`story`,trace:w.id,call:e}),onOpenCall:e=>g({view:`calls`,trace:w.id,call:e}),onOpenThought:r(`thought`)?e=>g({view:`thought`,trace:w.id,call:e}):void 0,onOpenSandbox:r(`sandbox`)?e=>g({view:`sandbox`,trace:w.id,call:e}):void 0},w.id):E()),u.view===`sandboxes`&&r(`sandboxes`)&&(0,K.jsx)(aO,{traces:i,selectedId:u.box,onSelect:e=>g({view:`sandboxes`,box:e}),onOpenTrace:e=>g({view:`calls`,trace:e}),onOpenScan:r(`scan`)?e=>g({view:`scan`,trace:u.trace,box:e}):void 0}),u.view===`scan`&&r(`scan`)&&(0,K.jsx)(xT,{box:u.box,traces:i,onSelect:e=>g({view:`scan`,trace:u.trace,box:e}),onOpenCall:(e,t)=>g({view:`calls`,trace:e,call:t}),onAlertsSeen:()=>S(e=>e+1)}),u.view===`calls`&&r(`calls`)&&(w?(0,K.jsx)(KT,{trace:w,traces:i,focusCall:u.call,onOpenSandbox:r(`sandbox`)?e=>g({view:`sandbox`,trace:w.id,call:e??null}):void 0,onOpenContext:r(`context`)?e=>g({view:`context`,trace:w.id,step:uO(e)}):void 0,onOpenThought:r(`thought`)?e=>g({view:`thought`,trace:w.id,call:e}):void 0,onOpenPlayground:r(`playground`)?(e,t)=>g({view:`playground`,trace:w.id,step:e,call:t??null}):void 0},w.id):E()),u.view===`changes`&&r(`changes`)&&(w?(0,K.jsx)(ED,{trace:w,onOpenCall:r(`calls`)?e=>g({view:`calls`,trace:w.id,call:e}):void 0},w.id):E()),u.view===`sandbox`&&r(`sandbox`)&&(w?(0,K.jsx)(kD,{trace:w,focusCall:u.call,onOpenCall:e=>g({view:`calls`,trace:w.id,call:e??null})},w.id):E()),u.view===`playground`&&r(`playground`)&&(w?(0,K.jsx)(GE,{trace:w,stepId:u.step,removeCall:u.call,forkTraces:i.filter(e=>e.forkId),onStep:e=>g({view:`playground`,trace:w.id,step:e}),onOpenTrace:e=>g({view:`calls`,trace:e})},`${w.id}:${u.step??``}`):E()),u.view===`context`&&r(`context`)&&(w?(0,K.jsx)(bE,{trace:w,stepKey:u.step,onStep:e=>g({view:`context`,trace:w.id,step:e}),onRerunWithout:r(`playground`)?(e,t)=>g({view:`playground`,trace:w.id,step:e,call:t}):void 0},w.id):E()),u.view===`thought`&&r(`thought`)&&(w?(0,K.jsx)(oE,{trace:w,focusCall:u.call},w.id):E())]})}var fO=[`prompts`,`search`,`story`,`sandboxes`,`calls`,`changes`,`sandbox`,`context`,`thought`,`playground`];S({fetch:(e,t)=>fetch(e,t)});var pO=4;function mO(){let[e,t]=(0,_.useState)(!1),[n,r]=(0,_.useState)(!1);return(0,_.useEffect)(()=>{fetch(`/raytace/version`).then(e=>e.ok?e.json():{api:0}).then(e=>t((Number(e.api)||0)<pO),()=>{}),fetch(`/raytace/models`).then(e=>r(e.status===401),()=>{})},[]),!e&&!n?null:(0,K.jsx)(`div`,{role:`alert`,style:{padding:`10px 16px`,background:`light-dark(#fff4d6,#3a2f12)`,color:`light-dark(#5c4300,#ffd97a)`,fontSize:13,borderBottom:`1px solid light-dark(#f0d48a,#5c4a1c)`},children:e?(0,K.jsxs)(K.Fragment,{children:[`An older RayTrace proxy is running, so parts of this page cannot load. Restart it: `,(0,K.jsx)(`code`,{children:`raytrace stop && raytrace start`})]}):(0,K.jsxs)(K.Fragment,{children:[`This browser is not signed in to RayTrace, so nothing can load. In a terminal, run: `,(0,K.jsx)(`code`,{children:`raytrace open`})]})})}(0,v.createRoot)(document.getElementById(`root`)).render((0,K.jsxs)(_.StrictMode,{children:[(0,K.jsx)(mO,{}),(0,K.jsx)(dO,{views:fO})]}));
@@ -6,8 +6,8 @@
6
6
  <title>RayTrace — Agent trace forensics</title>
7
7
  <meta name="description" content="Evidence-backed traces and live counterfactual forks for coding agents." />
8
8
  <link rel="icon" href="/favicon.svg" type="image/svg+xml" />
9
- <script type="module" crossorigin src="/assets/index-Dc3LTk8b.js"></script>
10
- <link rel="stylesheet" crossorigin href="/assets/index-DtV3UdEB.css">
9
+ <script type="module" crossorigin src="/assets/index-TqrxOY-Y.js"></script>
10
+ <link rel="stylesheet" crossorigin href="/assets/index-H97VLD5l.css">
11
11
  </head>
12
12
  <body class="antialiased">
13
13
  <div id="root"></div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raytrace-cli/cli",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "See what your coding agent did: traces, tool calls, cost and step-by-step evidence for Claude Code and Codex.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/auth.mjs CHANGED
@@ -125,13 +125,16 @@ export async function accessToken() {
125
125
 
126
126
  // ------------------------------------------------------------- commands
127
127
 
128
- function openUrl(url) {
128
+ export function openUrl(url) {
129
129
  const [command, args] = process.platform === 'darwin' ? ['open', [url]]
130
130
  : process.platform === 'win32' ? ['cmd', ['/c', 'start', '', url]] : ['xdg-open', [url]];
131
131
  spawn(command, args, { stdio: 'ignore', detached: true }).on('error', () => {}).unref();
132
132
  }
133
133
 
134
- export async function login() {
134
+ /** Start WorkOS's device login. Returns the code and page to show at once;
135
+ * `done` settles when the code is approved (the session is then saved),
136
+ * declined, or expired. */
137
+ export async function startDeviceLogin() {
135
138
  const start = await workos('/authorize/device', { client_id: CLIENT_ID });
136
139
  if (start.status !== 200 || !start.data.device_code) {
137
140
  throw new Error(`WorkOS refused to start the sign-in: ${start.data.error_description || start.data.message || `HTTP ${start.status}`}`);
@@ -139,29 +142,34 @@ export async function login() {
139
142
  const { device_code, user_code, verification_uri, verification_uri_complete } = start.data;
140
143
  let interval = (start.data.interval || 5) * 1000;
141
144
  const deadline = Date.now() + (start.data.expires_in || 300) * 1000;
145
+ const done = (async () => {
146
+ while (Date.now() < deadline) {
147
+ await new Promise((resolve) => setTimeout(resolve, interval));
148
+ const { status, data } = await workos('/authenticate', {
149
+ grant_type: 'urn:ietf:params:oauth:grant-type:device_code', device_code, client_id: CLIENT_ID,
150
+ device_id: hostname().slice(0, 100),
151
+ });
152
+ if (status === 200 && data.access_token) return { email: data.user?.email, where: save(keep(data)) };
153
+ if (data.error === 'authorization_pending') continue;
154
+ if (data.error === 'slow_down') { interval += 5000; continue; }
155
+ if (data.error === 'access_denied') throw new Error('The sign-in was declined.');
156
+ if (data.error === 'expired_token') break;
157
+ throw new Error(`Sign-in failed: ${data.error_description || data.error || `HTTP ${status}`}`);
158
+ }
159
+ throw new Error('The code expired before it was approved. Run raytrace auth login again.');
160
+ })();
161
+ return { user_code, verification_uri, verification_uri_complete, done };
162
+ }
163
+
164
+ export async function login() {
165
+ const { user_code, verification_uri, verification_uri_complete, done } = await startDeviceLogin();
142
166
  say(`Your sign-in code: ${user_code}`);
143
167
  say(`Opening ${verification_uri}: sign in, or create your account, and approve the code`);
144
168
  say('(or open it yourself on any device).');
145
169
  openUrl(verification_uri_complete || verification_uri);
146
170
  say('Waiting for approval...');
147
- while (Date.now() < deadline) {
148
- await new Promise((resolve) => setTimeout(resolve, interval));
149
- const { status, data } = await workos('/authenticate', {
150
- grant_type: 'urn:ietf:params:oauth:grant-type:device_code', device_code, client_id: CLIENT_ID,
151
- device_id: hostname().slice(0, 100),
152
- });
153
- if (status === 200 && data.access_token) {
154
- const where = save(keep(data));
155
- say(`\nSigned in as ${data.user?.email}. Your sign-in is kept in ${where}.`);
156
- return;
157
- }
158
- if (data.error === 'authorization_pending') continue;
159
- if (data.error === 'slow_down') { interval += 5000; continue; }
160
- if (data.error === 'access_denied') throw new Error('The sign-in was declined.');
161
- if (data.error === 'expired_token') break;
162
- throw new Error(`Sign-in failed: ${data.error_description || data.error || `HTTP ${status}`}`);
163
- }
164
- throw new Error('The code expired before it was approved. Run raytrace auth login again.');
171
+ const { email, where } = await done;
172
+ say(`\nSigned in as ${email}. Your sign-in is kept in ${where}.`);
165
173
  }
166
174
 
167
175
  /** `raytrace auth login`: sign in, then say what comes next. */