@raytrace-cli/cli 0.14.3 → 0.15.1
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.
|
@@ -23,8 +23,8 @@ Error generating stack: `+e.message+`
|
|
|
23
23
|
+`).split(`
|
|
24
24
|
`));return[t,t.reduce((e,t)=>e.concat(...t),[])]}return[[],[]]},[e]);return(0,_.useEffect)(()=>{let n=t?.target??KN,c=t?.actInsideInputWithModifier??!0;if(e!==null){let e=e=>{if(i.current=e.ctrlKey||e.metaKey||e.shiftKey||e.altKey,(!i.current||i.current&&!c)&&Tj(e))return!1;let n=YN(e.code,s);if(a.current.add(e[n]),JN(o,a.current,!1)){let n=e.composedPath?.()?.[0]||e.target,a=n?.nodeName===`BUTTON`||n?.nodeName===`A`;t.preventDefault!==!1&&(i.current||!a)&&e.preventDefault(),r(!0)}},l=e=>{let t=YN(e.code,s);JN(o,a.current,!0)?(r(!1),a.current.clear()):a.current.delete(e[t]),e.key===`Meta`&&a.current.clear(),i.current=!1},u=()=>{a.current.clear(),r(!1)};return n?.addEventListener(`keydown`,e),n?.addEventListener(`keyup`,l),window.addEventListener(`blur`,u),window.addEventListener(`contextmenu`,u),()=>{n?.removeEventListener(`keydown`,e),n?.removeEventListener(`keyup`,l),window.removeEventListener(`blur`,u),window.removeEventListener(`contextmenu`,u)}}},[e,r]),n}function JN(e,t,n){return e.filter(e=>n||e.length===t.size).some(e=>e.every(e=>t.has(e)))}function YN(e,t){return t.includes(e)?`code`:`key`}var XN=()=>{let e=yN();return(0,_.useMemo)(()=>({zoomIn:async t=>{let{panZoom:n}=e.getState();return n?n.scaleBy(1.2,t):!1},zoomOut:async t=>{let{panZoom:n}=e.getState();return n?n.scaleBy(1/1.2,t):!1},zoomTo:async(t,n)=>{let{panZoom:r}=e.getState();return r?r.scaleTo(t,n):!1},getZoom:()=>e.getState().transform[2],setViewport:async(t,n)=>{let{transform:[r,i,a],panZoom:o}=e.getState();return o?(await o.setViewport({x:t.x??r,y:t.y??i,zoom:t.zoom??a},n),!0):!1},getViewport:()=>{let[t,n,r]=e.getState().transform;return{x:t,y:n,zoom:r}},setCenter:async(t,n,r)=>e.getState().setCenter(t,n,r),fitBounds:async(t,n)=>{let{width:r,height:i,minZoom:a,maxZoom:o,panZoom:s}=e.getState(),c=dj(t,r,i,a,o,n?.padding??.1);return s?(await s.setViewport(c,{duration:n?.duration,ease:n?.ease,interpolate:n?.interpolate}),!0):!1},screenToFlowPosition:(t,n={})=>{let{transform:r,snapGrid:i,snapToGrid:a,domNode:o}=e.getState();if(!o)return t;let{x:s,y:c}=o.getBoundingClientRect(),l={x:t.x-s,y:t.y-c},u=n.snapGrid??i;return oj(l,r,n.snapToGrid??a,u)},flowToScreenPosition:t=>{let{transform:n,domNode:r}=e.getState();if(!r)return t;let{x:i,y:a}=r.getBoundingClientRect(),o=sj(t,n);return{x:o.x+i,y:o.y+a}}}),[])};function ZN(e,t){let n=[],r=new Map,i=[];for(let t of e)if(t.type===`add`){i.push(t);continue}else if(t.type===`remove`||t.type===`replace`)r.set(t.id,[t]);else{let e=r.get(t.id);e?e.push(t):r.set(t.id,[t])}for(let e of t){let t=r.get(e.id);if(!t){n.push(e);continue}if(t[0].type===`remove`)continue;if(t[0].type===`replace`){n.push({...t[0].item});continue}let i={...e};for(let e of t)QN(e,i);n.push(i)}return i.length&&i.forEach(e=>{e.index===void 0?n.push({...e.item}):n.splice(e.index,0,{...e.item})}),n}function QN(e,t){switch(e.type){case`select`:t.selected=e.selected;break;case`position`:e.position!==void 0&&(t.position=e.position),e.dragging!==void 0&&(t.dragging=e.dragging);break;case`dimensions`:e.dimensions!==void 0&&(t.measured={...e.dimensions},e.setAttributes&&((e.setAttributes===!0||e.setAttributes===`width`)&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes===`height`)&&(t.height=e.dimensions.height))),typeof e.resizing==`boolean`&&(t.resizing=e.resizing)}}function $N(e,t){return ZN(e,t)}function eP(e,t){return ZN(e,t)}function tP(e,t){return{id:e,type:`select`,selected:t}}function nP(e,t=new Set,n=!1){let r=[];for(let[i,a]of e){let e=t.has(i);(a.selected!==void 0||e)&&a.selected!==e&&(n&&(a.selected=e),r.push(tP(a.id,e)))}return r}function rP({items:e=[],lookup:t}){let n=[],r=new Map(e.map(e=>[e.id,e]));for(let[r,i]of e.entries()){let e=t.get(i.id),a=e?.internals?.userNode??e;a!==void 0&&a!==i&&n.push({id:i.id,item:i,type:`replace`}),a===void 0&&n.push({item:i,type:`add`,index:r})}for(let[e]of t)r.get(e)===void 0&&n.push({id:e,type:`remove`});return n}function iP(e){return{id:e.id,type:`remove`}}var aP=ij(`React Flow`,`https://reactflow.dev/`);function oP(e,t,n={}){return Rj(e,t,{...n,onError:n.onError??aP})}var sP=e=>MA(e),cP=e=>jA(e);function lP(e){return(0,_.forwardRef)(e)}var uP=typeof window<`u`?_.useLayoutEffect:_.useEffect;function dP(e){let[t,n]=(0,_.useState)(BigInt(0)),[r]=(0,_.useState)(()=>fP(()=>n(e=>e+BigInt(1))));return uP(()=>{let t=r.get();t.length&&(e(t),r.reset())},[t]),r}function fP(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}var pP=(0,_.createContext)(null);function mP({children:e}){let t=yN(),n=dP((0,_.useCallback)(e=>{let{nodes:n=[],setNodes:r,hasDefaultNodes:i,onNodesChange:a,nodeLookup:o,fitViewQueued:s,onNodesChangeMiddlewareMap:c}=t.getState(),l=n;for(let t of e)l=typeof t==`function`?t(l):t;let u=rP({items:l,lookup:o});for(let e of c.values())u=e(u);i&&r(l),u.length>0?a?.(u):s&&window.requestAnimationFrame(()=>{let{fitViewQueued:e,nodes:n,setNodes:r}=t.getState();e&&r(n)})},[])),r=dP((0,_.useCallback)(e=>{let{edges:n=[],setEdges:r,hasDefaultEdges:i,onEdgesChange:a,edgeLookup:o}=t.getState(),s=n;for(let t of e)s=typeof t==`function`?t(s):t;i?r(s):a&&a(rP({items:s,lookup:o}))},[])),i=(0,_.useMemo)(()=>({nodeQueue:n,edgeQueue:r}),[]);return(0,G.jsx)(pP.Provider,{value:i,children:e})}function hP(){let e=(0,_.useContext)(pP);if(!e)throw Error(`useBatchContext must be used within a BatchProvider`);return e}var gP=e=>!!e.panZoom;function _P(){let e=XN(),t=yN(),n=hP(),r=vN(gP),i=(0,_.useMemo)(()=>{let e=e=>t.getState().nodeLookup.get(e),r=e=>{n.nodeQueue.push(e)},i=e=>{n.edgeQueue.push(e)},a=e=>{let{nodeLookup:n,nodeOrigin:r}=t.getState(),i=sP(e)?e:n.get(e.id),a=i.parentId?gj(i.position,i.measured,i.parentId,n,r):i.position;return ZA({...i,position:a,width:i.measured?.width??i.width,height:i.measured?.height??i.height})},o=(e,t,n={replace:!1})=>{r(r=>r.map(r=>{if(r.id===e){let e=typeof t==`function`?t(r):t;return n.replace&&sP(e)?e:{...r,...e}}return r}))},s=(e,t,n={replace:!1})=>{i(r=>r.map(r=>{if(r.id===e){let e=typeof t==`function`?t(r):t;return n.replace&&cP(e)?e:{...r,...e}}return r}))};return{getNodes:()=>t.getState().nodes.map(e=>({...e})),getNode:t=>e(t)?.internals.userNode,getInternalNode:e,getEdges:()=>{let{edges:e=[]}=t.getState();return e.map(e=>({...e}))},getEdge:e=>t.getState().edgeLookup.get(e),setNodes:r,setEdges:i,addNodes:e=>{let t=Array.isArray(e)?e:[e];n.nodeQueue.push(e=>[...e,...t])},addEdges:e=>{let t=Array.isArray(e)?e:[e];n.edgeQueue.push(e=>[...e,...t])},toObject:()=>{let{nodes:e=[],edges:n=[],transform:r}=t.getState(),[i,a,o]=r;return{nodes:e.map(e=>({...e})),edges:n.map(e=>({...e})),viewport:{x:i,y:a,zoom:o}}},deleteElements:async({nodes:e=[],edges:n=[]})=>{let{nodes:r,edges:i,onNodesDelete:a,onEdgesDelete:o,triggerNodeChanges:s,triggerEdgeChanges:c,onDelete:l,onBeforeDelete:u}=t.getState(),{nodes:d,edges:f}=await HA({nodesToRemove:e,edgesToRemove:n,nodes:r,edges:i,onBeforeDelete:u}),p=f.length>0,m=d.length>0;if(p){let e=f.map(iP);o?.(f),c(e)}if(m){let e=d.map(iP);a?.(d),s(e)}return(m||p)&&l?.({nodes:d,edges:f}),{deletedNodes:d,deletedEdges:f}},getIntersectingNodes:(e,n=!0,r)=>{let i=nj(e),o=i?e:a(e),s=r!==void 0;return o?(r||t.getState().nodes).filter(r=>{let a=t.getState().nodeLookup.get(r.id);if(a&&!i&&(r.id===e.id||!a.internals.positionAbsolute))return!1;let c=ZA(s?r:a),l=tj(c,o);return n&&l>0||l>=c.width*c.height||l>=o.width*o.height}):[]},isNodeIntersecting:(e,t,n=!0)=>{let r=nj(e)?e:a(e);if(!r)return!1;let i=tj(r,t);return n&&i>0||i>=t.width*t.height||i>=r.width*r.height},updateNode:o,updateNodeData:(e,t,n={replace:!1})=>{o(e,e=>{let r=typeof t==`function`?t(e):t;return n.replace?{...e,data:r}:{...e,data:{...e.data,...r}}},n)},updateEdge:s,updateEdgeData:(e,t,n={replace:!1})=>{s(e,e=>{let r=typeof t==`function`?t(e):t;return n.replace?{...e,data:r}:{...e,data:{...e.data,...r}}},n)},getNodesBounds:e=>{let{nodeLookup:n,nodeOrigin:r}=t.getState();return FA(e,{nodeLookup:n,nodeOrigin:r})},getHandleConnections:({type:e,id:n,nodeId:r})=>Array.from(t.getState().connectionLookup.get(`${r}-${e}${n?`-${n}`:``}`)?.values()??[]),getNodeConnections:({type:e,handleId:n,nodeId:r})=>Array.from(t.getState().connectionLookup.get(`${r}${e?n?`-${e}-${n}`:`-${e}`:``}`)?.values()??[]),fitView:async e=>{let r=t.getState().fitViewResolver??vj();return t.setState({fitViewQueued:!0,fitViewOptions:e,fitViewResolver:r}),n.nodeQueue.push(e=>[...e]),r.promise}}},[]);return(0,_.useMemo)(()=>({...i,...e,viewportInitialized:r}),[r])}var vP=e=>e.selected,yP=typeof window<`u`?window:void 0;function bP({deleteKeyCode:e,multiSelectionKeyCode:t}){let n=yN(),{deleteElements:r}=_P(),i=qN(e,{actInsideInputWithModifier:!1}),a=qN(t,{target:yP});(0,_.useEffect)(()=>{if(i){let{edges:e,nodes:t}=n.getState();r({nodes:t.filter(vP),edges:e.filter(vP)}),n.setState({nodesSelectionActive:!1})}},[i]),(0,_.useEffect)(()=>{n.setState({multiSelectionActive:a})},[a])}function xP(e){let t=yN();(0,_.useEffect)(()=>{let n=()=>{if(!e.current||!(e.current.checkVisibility?.()??!0))return!1;let n=Sj(e.current);(n.height===0||n.width===0)&&t.getState().onError?.(`004`,bA.error004()),t.setState({width:n.width||500,height:n.height||500})};if(e.current){n(),window.addEventListener(`resize`,n);let t=new ResizeObserver(()=>n());return t.observe(e.current),()=>{window.removeEventListener(`resize`,n),t&&e.current&&t.unobserve(e.current)}}},[])}var SP={position:`absolute`,width:`100%`,height:`100%`,top:0,left:0},CP=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function wP({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:r=!1,panActivationKeyPressed:i,panOnScrollSpeed:a=.5,panOnScrollMode:o=TA.Free,zoomOnDoubleClick:s=!0,panOnDrag:c=!0,defaultViewport:l,translateExtent:u,minZoom:d,maxZoom:f,zoomActivationKeyCode:p,preventScrolling:m=!0,children:h,noWheelClassName:g,noPanClassName:v,onViewportChange:y,isControlledViewport:b,paneClickDistance:x,selectionOnDrag:S}){let C=yN(),w=(0,_.useRef)(null),{userSelectionActive:T,lib:E,connectionInProgress:D}=vN(CP,mN),O=qN(p),k=(0,_.useRef)();xP(w);let A=(0,_.useCallback)(e=>{y?.({x:e[0],y:e[1],zoom:e[2]}),b||C.setState({transform:e})},[y,b]);return(0,_.useEffect)(()=>{if(w.current){k.current=qM({domNode:w.current,minZoom:d,maxZoom:f,translateExtent:u,viewport:l,onDraggingChange:e=>C.setState(t=>t.paneDragging===e?t:{paneDragging:e}),onPanZoomStart:(e,t)=>{let{onViewportChangeStart:n,onMoveStart:r}=C.getState();r?.(e,t),n?.(t)},onPanZoom:(e,t)=>{let{onViewportChange:n,onMove:r}=C.getState();r?.(e,t),n?.(t)},onPanZoomEnd:(e,t)=>{let{onViewportChangeEnd:n,onMoveEnd:r}=C.getState();r?.(e,t),n?.(t)}});let{x:e,y:t,zoom:n}=k.current.getViewport();return C.setState({panZoom:k.current,transform:[e,t,n],domNode:w.current.closest(`.react-flow`)}),()=>{k.current?.destroy()}}},[]),(0,_.useEffect)(()=>{k.current?.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:r,panActivationKeyPressed:i,panOnScrollSpeed:a,panOnScrollMode:o,zoomOnDoubleClick:s,panOnDrag:c,zoomActivationKeyPressed:O,preventScrolling:m,noPanClassName:v,userSelectionActive:T,noWheelClassName:g,lib:E,onTransformChange:A,connectionInProgress:D,selectionOnDrag:S,paneClickDistance:x})},[e,t,n,r,i,a,o,s,c,O,m,v,T,g,E,A,D,S,x]),(0,G.jsx)(`div`,{className:`react-flow__renderer`,ref:w,style:SP,children:h})}var TP=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function EP(){let{userSelectionActive:e,userSelectionRect:t}=vN(TP,mN);return e&&t?(0,G.jsx)(`div`,{className:`react-flow__selection react-flow__container`,style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}var DP=(e,t)=>n=>{n.target===t.current&&e?.(n)},OP=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging,panBy:e.panBy,autoPanSpeed:e.autoPanSpeed});function kP({isSelecting:e,selectionKeyPressed:t,selectionMode:n=EA.Full,panOnDrag:r,autoPanOnSelection:i,paneClickDistance:a,selectionOnDrag:o,onSelectionStart:s,onSelectionEnd:c,onPaneClick:l,onPaneContextMenu:u,onPaneScroll:d,onPaneMouseEnter:f,onPaneMouseMove:p,onPaneMouseLeave:m,children:h}){let g=(0,_.useRef)(0),v=yN(),{userSelectionActive:y,elementsSelectable:b,dragging:x,panBy:S,autoPanSpeed:C}=vN(OP,mN),w=b&&(e||y),T=(0,_.useRef)(null),E=(0,_.useRef)(),D=(0,_.useRef)(new Set),O=(0,_.useRef)(new Set),k=(0,_.useRef)(!1),A=(0,_.useRef)(!1),j=(0,_.useRef)({x:0,y:0}),M=(0,_.useRef)(!1),N=e=>{if(A.current||k.current||v.getState().connection.inProgress){A.current=!1,k.current=!1;return}l?.(e),v.getState().resetSelectedElements(),v.setState({nodesSelectionActive:!1})},P=e=>{if(Array.isArray(r)&&r?.includes(2)){e.preventDefault();return}u?.(e)},F=d?e=>d(e):void 0,I=e=>{A.current&&=(e.stopPropagation(),!1)},L=n=>{if(n.pointerType===`touch`&&r!==!1&&!t)return;let{domNode:i,transform:a}=v.getState();if(E.current=i?.getBoundingClientRect(),!E.current)return;let s=n.target===T.current;if(!s&&n.target.closest(`.nokey`)||!e||!(o&&s||t)||n.button!==0||!n.isPrimary)return;n.target?.setPointerCapture?.(n.pointerId),A.current=!1;let{x:c,y:l}=Dj(n.nativeEvent,E.current),u=oj({x:c,y:l},a);v.setState({userSelectionRect:{width:0,height:0,startX:u.x,startY:u.y,x:c,y:l}}),s||(n.stopPropagation(),n.preventDefault())};function R(e,t){let{userSelectionRect:r}=v.getState();if(!r)return;let{transform:i,nodeLookup:a,edgeLookup:o,connectionLookup:s,triggerNodeChanges:c,triggerEdgeChanges:l,defaultEdgeOptions:u}=v.getState(),d={x:r.startX,y:r.startY},{x:f,y:p}=sj(d,i),m={startX:d.x,startY:d.y,x:e<f?e:f,y:t<p?t:p,width:Math.abs(e-f),height:Math.abs(t-p)},h=D.current,g=O.current;D.current=new Set(LA(a,m,i,n===EA.Partial,!0).map(e=>e.id)),O.current=new Set;let _=u?.selectable??!0;for(let e of D.current){let t=s.get(e);if(t)for(let{edgeId:e}of t.values()){let t=o.get(e);t&&(t.selectable??_)&&O.current.add(e)}}_j(h,D.current)||c(nP(a,D.current,!0)),_j(g,O.current)||l(nP(o,O.current)),v.setState({userSelectionRect:m,userSelectionActive:!0,nodesSelectionActive:!1})}function z(){if(!i||!E.current)return;let[e,t]=qA(j.current,E.current,C);S({x:e,y:t}).then(e=>{if(!A.current||!e){g.current=requestAnimationFrame(z);return}let{x:t,y:n}=j.current;R(t,n),g.current=requestAnimationFrame(z)})}let B=()=>{cancelAnimationFrame(g.current),g.current=0,M.current=!1};(0,_.useEffect)(()=>()=>B(),[]);let V=e=>{let{userSelectionRect:n,transform:r,resetSelectedElements:i}=v.getState();if(!E.current||!n)return;let{x:o,y:c}=Dj(e.nativeEvent,E.current);j.current={x:o,y:c};let l=sj({x:n.startX,y:n.startY},r);if(!A.current){let n=t?0:a;if(Math.hypot(o-l.x,c-l.y)<=n)return;i(),s?.(e)}A.current=!0,M.current||=(z(),!0),R(o,c)},H=e=>{if(!w){e.target===T.current&&v.getState().connection.inProgress&&(k.current=!0);return}e.button===0&&(e.target?.releasePointerCapture?.(e.pointerId),!y&&e.target===T.current&&v.getState().userSelectionRect&&N?.(e),v.setState({userSelectionActive:!1,userSelectionRect:null}),A.current&&(c?.(e),v.setState({nodesSelectionActive:D.current.size>0})),B())},U=e=>{e.target?.releasePointerCapture?.(e.pointerId),B()},ee=r===!0||Array.isArray(r)&&r.includes(0);return(0,G.jsxs)(`div`,{className:Lw([`react-flow__pane`,{draggable:ee,dragging:x,selection:e}]),onClick:w?void 0:DP(N,T),onContextMenu:DP(P,T),onWheel:DP(F,T),onPointerEnter:w?void 0:f,onPointerMove:w?V:p,onPointerUp:H,onPointerCancel:w?U:void 0,onPointerDownCapture:w?L:void 0,onClickCapture:w?I:void 0,onPointerLeave:m,ref:T,style:SP,children:[h,(0,G.jsx)(EP,{})]})}function AP({id:e,store:t,unselect:n=!1,nodeRef:r}){let{addSelectedNodes:i,unselectNodesAndEdges:a,multiSelectionActive:o,nodeLookup:s,onError:c}=t.getState(),l=s.get(e);if(!l){c?.(`012`,bA.error012(e));return}t.setState({nodesSelectionActive:!1}),l.selected?(n||l.selected&&o)&&(a({nodes:[l],edges:[]}),requestAnimationFrame(()=>r?.current?.blur())):i([e])}function jP({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:i,isSelectable:a,nodeClickDistance:o}){let s=yN(),[c,l]=(0,_.useState)(!1),u=(0,_.useRef)();return(0,_.useEffect)(()=>{if(!t)return u.current=SM({getStoreItems:()=>s.getState(),onNodeMouseDown:t=>{AP({id:t,store:s,nodeRef:e})},onDragStart:()=>{l(!0)},onDragStop:()=>{l(!1)}}),()=>{u.current?.destroy(),u.current=void 0}},[t,s,e]),(0,_.useEffect)(()=>{!t&&e.current&&u.current&&u.current.update({noDragClassName:n,handleSelector:r,domNode:e.current,isSelectable:a,nodeId:i,nodeClickDistance:o})},[n,r,t,a,e,i,o]),c}var MP=e=>t=>t.selected&&(t.draggable||e&&t.draggable===void 0);function NP(){let e=yN();return(0,_.useCallback)(t=>{let{nodeExtent:n,snapToGrid:r,snapGrid:i,nodesDraggable:a,onError:o,updateNodePositions:s,nodeLookup:c,nodeOrigin:l}=e.getState(),u=new Map,d=MP(a),f=r?i[0]:5,p=r?i[1]:5,m=t.direction.x*f*t.factor,h=t.direction.y*p*t.factor;for(let[,e]of c){if(!d(e))continue;let t={x:e.internals.positionAbsolute.x+m,y:e.internals.positionAbsolute.y+h};r&&(t=aj(t,i));let{position:a,positionAbsolute:s}=VA({nodeId:e.id,nextPosition:t,nodeLookup:c,nodeExtent:n,nodeOrigin:l,onError:o});e.position=a,e.internals.positionAbsolute=s,u.set(e.id,e)}s(u)},[])}var PP=(0,_.createContext)(null),FP=PP.Provider;PP.Consumer;var IP=()=>(0,_.useContext)(PP),LP=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),RP=(0,_.createContext)(null);function zP({children:e}){let t=vN(LP,mN);return(0,G.jsx)(RP.Provider,{value:t,children:e})}function BP(){let e=(0,_.useContext)(RP);if(!e)throw Error(`useHandleConfig must be used within a HandleConfigProvider`);return e}var VP={connectingFrom:!1,connectingTo:!1,clickConnecting:!1,isPossibleEndHandle:!0,connectionInProcess:!1,clickConnectionInProcess:!1,valid:!1},HP=(e,t,n)=>r=>{let{connectionClickStartHandle:i,connectionMode:a,connection:o}=r,{fromHandle:s,toHandle:c,isValid:l}=o;if(!s&&!i)return VP;let u=c?.nodeId===e&&c?.id===t&&c?.type===n;return{connectingFrom:s?.nodeId===e&&s?.id===t&&s?.type===n,connectingTo:u,clickConnecting:i?.nodeId===e&&i?.id===t&&i?.type===n,isPossibleEndHandle:a===wA.Strict?s?.type!==n:e!==s?.nodeId||t!==s?.id,connectionInProcess:!!s,clickConnectionInProcess:!!i,valid:u&&l}};function UP({type:e=`source`,position:t=$.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:i=!0,isConnectableEnd:a=!0,id:o,onConnect:s,children:c,className:l,onMouseDown:u,onTouchStart:d,...f},p){let m=o||null,h=e===`target`,g=yN(),_=IP(),{connectOnClick:v,noPanClassName:y,rfId:b}=BP(),{connectingFrom:x,connectingTo:S,clickConnecting:C,isPossibleEndHandle:w,connectionInProcess:T,clickConnectionInProcess:E,valid:D}=vN(HP(_,m,e),mN);_||g.getState().onError?.(`010`,bA.error010());let O=e=>{let{defaultEdgeOptions:t,onConnect:n,hasDefaultEdges:r}=g.getState(),i={...t,...e};if(r){let{edges:e,setEdges:t,onError:n}=g.getState();t(oP(i,e,{onError:n}))}n?.(i),s?.(i)},k=e=>{if(!_)return;let t=Ej(e.nativeEvent);if(i&&(t&&e.button===0||!t)){let t=g.getState();MM.onPointerDown(e.nativeEvent,{handleDomNode:e.currentTarget,autoPanOnConnect:t.autoPanOnConnect,connectionMode:t.connectionMode,connectionRadius:t.connectionRadius,domNode:t.domNode,nodeLookup:t.nodeLookup,lib:t.lib,isTarget:h,handleId:m,nodeId:_,flowId:t.rfId,panBy:t.panBy,cancelConnection:t.cancelConnection,onConnectStart:t.onConnectStart,onConnectEnd:(...e)=>g.getState().onConnectEnd?.(...e),updateConnection:t.updateConnection,onConnect:O,isValidConnection:n||((...e)=>g.getState().isValidConnection?.(...e)??!0),getTransform:()=>g.getState().transform,getFromHandle:()=>g.getState().connection.fromHandle,autoPanSpeed:t.autoPanSpeed,dragThreshold:t.connectionDragThreshold})}t?u?.(e):d?.(e)};return(0,G.jsx)(`div`,{"data-handleid":m,"data-nodeid":_,"data-handlepos":t,"data-id":`${b}-${_}-${m}-${e}`,className:Lw([`react-flow__handle`,`react-flow__handle-${t}`,`nodrag`,y,l,{source:!h,target:h,connectable:r,connectablestart:i,connectableend:a,clickconnecting:C,connectingfrom:x,connectingto:S,valid:D,connectionindicator:r&&(!T||w)&&(T||E?a:i)}]),onMouseDown:k,onTouchStart:k,onClick:v?t=>{let{onClickConnectStart:r,onClickConnectEnd:a,connectionClickStartHandle:o,connectionMode:s,isValidConnection:c,lib:l,rfId:u,nodeLookup:d,connection:f}=g.getState();if(!_||!o&&!i)return;if(!o){r?.(t.nativeEvent,{nodeId:_,handleId:m,handleType:e}),g.setState({connectionClickStartHandle:{nodeId:_,type:e,id:m}});return}let p=Cj(t.target),h=n||c,{connection:v,isValid:y}=MM.isValid(t.nativeEvent,{handle:{nodeId:_,id:m,type:e},connectionMode:s,fromNodeId:o.nodeId,fromHandleId:o.id||null,fromType:o.type,isValidConnection:h,flowId:u,doc:p,lib:l,nodeLookup:d});y&&v&&O(v);let b=structuredClone(f);delete b.inProgress,b.toPosition=b.toHandle?b.toHandle.position:null,a?.(t,b),g.setState({connectionClickStartHandle:null})}:void 0,ref:p,...f,children:c})}var WP=(0,_.memo)(lP(UP));function GP({data:e,isConnectable:t,sourcePosition:n=$.Bottom}){return(0,G.jsxs)(G.Fragment,{children:[e?.label,(0,G.jsx)(WP,{type:`source`,position:n,isConnectable:t})]})}function KP({data:e,isConnectable:t,targetPosition:n=$.Top,sourcePosition:r=$.Bottom}){return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(WP,{type:`target`,position:n,isConnectable:t}),e?.label,(0,G.jsx)(WP,{type:`source`,position:r,isConnectable:t})]})}function qP(){return null}function JP({data:e,isConnectable:t,targetPosition:n=$.Top}){return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(WP,{type:`target`,position:n,isConnectable:t}),e?.label]})}var YP={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},XP={input:GP,default:KP,output:JP,group:qP};function ZP(e){return e.internals.handleBounds===void 0?{width:e.width??e.initialWidth??e.style?.width,height:e.height??e.initialHeight??e.style?.height}:{width:e.width??e.style?.width,height:e.height??e.style?.height}}var QP=e=>{let{width:t,height:n,x:r,y:i}=IA(e.nodeLookup,{filter:e=>!!e.selected});return{width:rj(t)?t:null,height:rj(n)?n:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${r}px,${i}px)`}};function $P({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){let r=yN(),{width:i,height:a,transformString:o,userSelectionActive:s}=vN(QP,mN),c=NP(),l=(0,_.useRef)(null);(0,_.useEffect)(()=>{n||l.current?.focus({preventScroll:!0})},[n]);let u=!s&&i!==null&&a!==null;if(jP({nodeRef:l,disabled:!u}),!u)return null;let d=e?t=>{e(t,r.getState().nodes.filter(e=>e.selected))}:void 0;return(0,G.jsx)(`div`,{className:Lw([`react-flow__nodesselection`,`react-flow__container`,t]),style:{transform:o},children:(0,G.jsx)(`div`,{ref:l,className:`react-flow__nodesselection-rect`,onContextMenu:d,tabIndex:n?void 0:-1,onKeyDown:n?void 0:e=>{Object.prototype.hasOwnProperty.call(YP,e.key)&&(e.preventDefault(),c({direction:YP[e.key],factor:e.shiftKey?4:1}))},style:{width:i,height:a}})})}var eF=typeof window<`u`?window:void 0,tF=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function nF({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:a,onPaneScroll:o,paneClickDistance:s,deleteKeyCode:c,selectionKeyCode:l,selectionOnDrag:u,selectionMode:d,onSelectionStart:f,onSelectionEnd:p,multiSelectionKeyCode:m,panActivationKeyCode:h,zoomActivationKeyCode:g,elementsSelectable:_,zoomOnScroll:v,zoomOnPinch:y,panOnScroll:b,panOnScrollSpeed:x,panOnScrollMode:S,zoomOnDoubleClick:C,panOnDrag:w,autoPanOnSelection:T,defaultViewport:E,translateExtent:D,minZoom:O,maxZoom:k,preventScrolling:A,onSelectionContextMenu:j,noWheelClassName:M,noPanClassName:N,disableKeyboardA11y:P,onViewportChange:F,isControlledViewport:I}){let{nodesSelectionActive:L,userSelectionActive:R}=vN(tF,mN),z=qN(l,{target:eF}),B=qN(h,{target:eF}),V=B||w,H=B||b,U=u&&V!==!0,ee=z||R||U;return bP({deleteKeyCode:c,multiSelectionKeyCode:m}),(0,G.jsx)(wP,{onPaneContextMenu:a,elementsSelectable:_,zoomOnScroll:v,zoomOnPinch:y,panOnScroll:H,panActivationKeyPressed:B,panOnScrollSpeed:x,panOnScrollMode:S,zoomOnDoubleClick:C,panOnDrag:!z&&V,defaultViewport:E,translateExtent:D,minZoom:O,maxZoom:k,zoomActivationKeyCode:g,preventScrolling:A,noWheelClassName:M,noPanClassName:N,onViewportChange:F,isControlledViewport:I,paneClickDistance:s,selectionOnDrag:U,children:(0,G.jsxs)(kP,{onSelectionStart:f,onSelectionEnd:p,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:a,onPaneScroll:o,panOnDrag:V,autoPanOnSelection:T,isSelecting:!!ee,selectionMode:d,selectionKeyPressed:z,paneClickDistance:s,selectionOnDrag:U,children:[e,L&&(0,G.jsx)($P,{onSelectionContextMenu:j,noPanClassName:N,disableKeyboardA11y:P})]})})}nF.displayName=`FlowRenderer`;var rF=(0,_.memo)(nF),iF=e=>t=>e?LA(t.nodeLookup,{x:0,y:0,width:t.width,height:t.height},t.transform,!0).map(e=>e.id):Array.from(t.nodeLookup.keys());function aF(e){return vN((0,_.useCallback)(iF(e),[e]),mN)}var oF=e=>e.updateNodeInternals;function sF(){let e=vN(oF),[t]=(0,_.useState)(()=>typeof ResizeObserver>`u`?null:new ResizeObserver(t=>{let n=new Map;t.forEach(e=>{let t=e.target.getAttribute(`data-id`);n.set(t,{id:t,nodeElement:e.target,force:!0})}),e(n)}));return(0,_.useEffect)(()=>()=>{t?.disconnect()},[t]),t}function cF({node:e,nodeType:t,hasDimensions:n,resizeObserver:r}){let i=yN(),a=(0,_.useRef)(null),o=(0,_.useRef)(null),s=(0,_.useRef)(e.sourcePosition),c=(0,_.useRef)(e.targetPosition),l=(0,_.useRef)(t),u=n&&!!e.internals.handleBounds;return(0,_.useEffect)(()=>{a.current&&!e.hidden&&(!u||o.current!==a.current)&&(o.current&&r?.unobserve(o.current),r?.observe(a.current),o.current=a.current)},[u,e.hidden]),(0,_.useEffect)(()=>()=>{o.current&&=(r?.unobserve(o.current),null)},[]),(0,_.useEffect)(()=>{if(a.current){let n=l.current!==t,r=s.current!==e.sourcePosition,o=c.current!==e.targetPosition;(n||r||o)&&(l.current=t,s.current=e.sourcePosition,c.current=e.targetPosition,i.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:a.current,force:!0}]])))}},[e.id,t,e.sourcePosition,e.targetPosition]),a}function lF({id:e,onClick:t,onMouseEnter:n,onMouseMove:r,onMouseLeave:i,onContextMenu:a,onDoubleClick:o,nodesDraggable:s,elementsSelectable:c,nodesConnectable:l,nodesFocusable:u,resizeObserver:d,noDragClassName:f,noPanClassName:p,disableKeyboardA11y:m,rfId:h,nodeTypes:g,nodeClickDistance:_,onError:v}){let{node:y,internals:b,isParent:x}=vN(t=>{let n=t.nodeLookup.get(e),r=t.parentLookup.has(e);return{node:n,internals:n.internals,isParent:r}},mN),S=y.type||`default`,C=g?.[S]||XP[S];C===void 0&&(v?.(`003`,bA.error003(S)),S=`default`,C=g?.default||XP.default);let w=!!(y.draggable||s&&y.draggable===void 0),T=!!(y.selectable||c&&y.selectable===void 0),E=!!(y.connectable||l&&y.connectable===void 0),D=!!(y.focusable||u&&y.focusable===void 0),O=yN(),k=hj(y),A=cF({node:y,nodeType:S,hasDimensions:k,resizeObserver:d}),j=jP({nodeRef:A,disabled:y.hidden||!w,noDragClassName:f,handleSelector:y.dragHandle,nodeId:e,isSelectable:T,nodeClickDistance:_}),M=NP();if(y.hidden)return null;let N=mj(y),P=ZP(y),F=T||w||t||n||r||i,I=n?e=>n(e,{...b.userNode}):void 0,L=r?e=>r(e,{...b.userNode}):void 0,R=i?e=>i(e,{...b.userNode}):void 0,z=a?e=>a(e,{...b.userNode}):void 0,B=o?e=>o(e,{...b.userNode}):void 0,V=n=>{let{selectNodesOnDrag:r,nodeDragThreshold:i}=O.getState();T&&(!r||!w||i>0)&&AP({id:e,store:O,nodeRef:A}),t&&t(n,{...b.userNode})},H=t=>{if(!(Tj(t.nativeEvent)||m)){if(SA.includes(t.key)&&T){let n=t.key===`Escape`;AP({id:e,store:O,unselect:n,nodeRef:A})}else if(w&&y.selected&&Object.prototype.hasOwnProperty.call(YP,t.key)){t.preventDefault();let{ariaLabelConfig:e}=O.getState();O.setState({ariaLiveMessage:e[`node.a11yDescription.ariaLiveMessage`]({direction:t.key.replace(`Arrow`,``).toLowerCase(),x:~~b.positionAbsolute.x,y:~~b.positionAbsolute.y})}),M({direction:YP[t.key],factor:t.shiftKey?4:1})}}},U=()=>{if(m||!A.current?.matches(`:focus-visible`))return;let{transform:t,width:n,height:r,autoPanOnNodeFocus:i,setCenter:a}=O.getState();i&&(LA(new Map([[e,y]]),{x:0,y:0,width:n,height:r},t,!0).length>0||a(y.position.x+N.width/2,y.position.y+N.height/2,{zoom:t[2]}))};return(0,G.jsx)(`div`,{className:Lw([`react-flow__node`,`react-flow__node-${S}`,{[p]:w},y.className,{selected:y.selected,selectable:T,parent:x,draggable:w,dragging:j}]),ref:A,style:{zIndex:b.z,transform:`translate(${b.positionAbsolute.x}px,${b.positionAbsolute.y}px)`,pointerEvents:F?`all`:`none`,visibility:k?`visible`:`hidden`,...y.style,...P},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:I,onMouseMove:L,onMouseLeave:R,onContextMenu:z,onClick:V,onDoubleClick:B,onKeyDown:D?H:void 0,tabIndex:D?0:void 0,onFocus:D?U:void 0,role:y.ariaRole??(D?`group`:void 0),"aria-roledescription":`node`,"aria-describedby":m?void 0:`${SN}-${h}`,"aria-label":y.ariaLabel,...y.domAttributes,children:(0,G.jsx)(FP,{value:e,children:(0,G.jsx)(C,{id:e,data:y.data,type:S,positionAbsoluteX:b.positionAbsolute.x,positionAbsoluteY:b.positionAbsolute.y,selected:y.selected??!1,selectable:T,draggable:w,deletable:y.deletable??!0,isConnectable:E,sourcePosition:y.sourcePosition,targetPosition:y.targetPosition,dragging:j,dragHandle:y.dragHandle,zIndex:b.z,parentId:y.parentId,...N})})})}var uF=(0,_.memo)(lF),dF=e=>({nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function fF(e){let{nodesConnectable:t,nodesFocusable:n,elementsSelectable:r,onError:i}=vN(dF,mN),a=aF(e.onlyRenderVisibleElements),o=sF();return(0,G.jsx)(`div`,{className:`react-flow__nodes`,style:SP,children:a.map(a=>(0,G.jsx)(uF,{id:a,nodeTypes:e.nodeTypes,nodeExtent:e.nodeExtent,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,resizeObserver:o,nodesDraggable:e.nodesDraggable??!0,nodesConnectable:t,nodesFocusable:n,elementsSelectable:r,nodeClickDistance:e.nodeClickDistance,onError:i},a))})}fF.displayName=`NodeRenderer`;var pF=(0,_.memo)(fF);function mF(e){return vN((0,_.useCallback)(t=>{if(!e)return t.edges.map(e=>e.id);let n=[];if(t.width&&t.height)for(let e of t.edges){let r=t.nodeLookup.get(e.source),i=t.nodeLookup.get(e.target);r&&i&&Fj({sourceNode:r,targetNode:i,width:t.width,height:t.height,transform:t.transform})&&n.push(e.id)}return n},[e]),mN)}var hF=({color:e=`none`,strokeWidth:t=1})=>{let n={strokeWidth:t,...e&&{stroke:e}};return(0,G.jsx)(`polyline`,{className:`arrow`,style:n,strokeLinecap:`round`,fill:`none`,strokeLinejoin:`round`,points:`-5,-4 0,0 -5,4`})},gF=({color:e=`none`,strokeWidth:t=1})=>{let n={strokeWidth:t,...e&&{stroke:e,fill:e}};return(0,G.jsx)(`polyline`,{className:`arrowclosed`,style:n,strokeLinecap:`round`,strokeLinejoin:`round`,points:`-5,-4 0,0 -5,4 -5,-4`})},_F={[kA.Arrow]:hF,[kA.ArrowClosed]:gF};function vF(e){let t=yN();return(0,_.useMemo)(()=>Object.prototype.hasOwnProperty.call(_F,e)?_F[e]:(t.getState().onError?.(`009`,bA.error009(e)),null),[e])}var yF=({id:e,type:t,color:n,width:r=12.5,height:i=12.5,markerUnits:a=`strokeWidth`,strokeWidth:o,orient:s=`auto-start-reverse`})=>{let c=vF(t);return c?(0,G.jsx)(`marker`,{className:`react-flow__arrowhead`,id:e,markerWidth:`${r}`,markerHeight:`${i}`,viewBox:`-10 -10 20 20`,markerUnits:a,orient:s,refX:`0`,refY:`0`,children:(0,G.jsx)(c,{color:n,strokeWidth:o})}):null},bF=({defaultColor:e,rfId:t})=>{let n=vN(e=>e.edges),r=vN(e=>e.defaultEdgeOptions),i=(0,_.useMemo)(()=>Qj(n,{id:t,defaultColor:e,defaultMarkerStart:r?.markerStart,defaultMarkerEnd:r?.markerEnd}),[n,r,t,e]);return i.length?(0,G.jsx)(`svg`,{className:`react-flow__marker`,"aria-hidden":`true`,children:(0,G.jsx)(`defs`,{children:i.map(e=>(0,G.jsx)(yF,{id:e.id,type:e.type,color:e.color,width:e.width,height:e.height,markerUnits:e.markerUnits,strokeWidth:e.strokeWidth,orient:e.orient},e.id))})}):null};bF.displayName=`MarkerDefinitions`;var xF=(0,_.memo)(bF);function SF({x:e,y:t,label:n,labelStyle:r,labelShowBg:i=!0,labelBgStyle:a,labelBgPadding:o=[2,4],labelBgBorderRadius:s=2,children:c,className:l,...u}){let[d,f]=(0,_.useState)({x:1,y:0,width:0,height:0}),p=Lw([`react-flow__edge-textwrapper`,l]),m=(0,_.useRef)(null);return(0,_.useEffect)(()=>{if(m.current){let e=m.current.getBBox();f({x:e.x,y:e.y,width:e.width,height:e.height})}},[n]),n?(0,G.jsxs)(`g`,{transform:`translate(${e-d.width/2} ${t-d.height/2})`,className:p,visibility:d.width?`visible`:`hidden`,...u,children:[i&&(0,G.jsx)(`rect`,{width:d.width+2*o[0],x:-o[0],y:-o[1],height:d.height+2*o[1],className:`react-flow__edge-textbg`,style:a,rx:s,ry:s}),(0,G.jsx)(`text`,{className:`react-flow__edge-text`,y:d.height/2,dy:`0.3em`,ref:m,style:r,children:n}),c]}):null}SF.displayName=`EdgeText`;var CF=(0,_.memo)(SF);function wF({path:e,labelX:t,labelY:n,label:r,labelStyle:i,labelShowBg:a,labelBgStyle:o,labelBgPadding:s,labelBgBorderRadius:c,interactionWidth:l=20,...u}){return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`path`,{...u,d:e,fill:`none`,className:Lw([`react-flow__edge-path`,u.className])}),l?(0,G.jsx)(`path`,{d:e,fill:`none`,strokeOpacity:0,strokeWidth:l,className:`react-flow__edge-interaction`}):null,r&&rj(t)&&rj(n)?(0,G.jsx)(CF,{x:t,y:n,label:r,labelStyle:i,labelShowBg:a,labelBgStyle:o,labelBgPadding:s,labelBgBorderRadius:c}):null]})}function TF({pos:e,x1:t,y1:n,x2:r,y2:i}){return e===$.Left||e===$.Right?[.5*(t+r),n]:[t,.5*(n+i)]}function EF({sourceX:e,sourceY:t,sourcePosition:n=$.Bottom,targetX:r,targetY:i,targetPosition:a=$.Top}){let[o,s]=TF({pos:n,x1:e,y1:t,x2:r,y2:i}),[c,l]=TF({pos:a,x1:r,y1:i,x2:e,y2:t}),[u,d,f,p]=kj({sourceX:e,sourceY:t,targetX:r,targetY:i,sourceControlX:o,sourceControlY:s,targetControlX:c,targetControlY:l});return[`M${e},${t} C${o},${s} ${c},${l} ${r},${i}`,u,d,f,p]}function DF(e){return(0,_.memo)(({id:t,sourceX:n,sourceY:r,targetX:i,targetY:a,sourcePosition:o,targetPosition:s,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:p,style:m,markerEnd:h,markerStart:g,interactionWidth:_})=>{let[v,y,b]=EF({sourceX:n,sourceY:r,sourcePosition:o,targetX:i,targetY:a,targetPosition:s}),x=e.isInternal?void 0:t;return(0,G.jsx)(wF,{id:x,path:v,labelX:y,labelY:b,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:p,style:m,markerEnd:h,markerStart:g,interactionWidth:_})})}var OF=DF({isInternal:!1}),kF=DF({isInternal:!0});OF.displayName=`SimpleBezierEdge`,kF.displayName=`SimpleBezierEdgeInternal`;function AF(e){return(0,_.memo)(({id:t,sourceX:n,sourceY:r,targetX:i,targetY:a,label:o,labelStyle:s,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:f,sourcePosition:p=$.Bottom,targetPosition:m=$.Top,markerEnd:h,markerStart:g,pathOptions:_,interactionWidth:v})=>{let[y,b,x]=Gj({sourceX:n,sourceY:r,sourcePosition:p,targetX:i,targetY:a,targetPosition:m,borderRadius:_?.borderRadius,offset:_?.offset,stepPosition:_?.stepPosition}),S=e.isInternal?void 0:t;return(0,G.jsx)(wF,{id:S,path:y,labelX:b,labelY:x,label:o,labelStyle:s,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:f,markerEnd:h,markerStart:g,interactionWidth:v})})}var jF=AF({isInternal:!1}),MF=AF({isInternal:!0});jF.displayName=`SmoothStepEdge`,MF.displayName=`SmoothStepEdgeInternal`;function NF(e){return(0,_.memo)(({id:t,...n})=>{let r=e.isInternal?void 0:t;return(0,G.jsx)(jF,{...n,id:r,pathOptions:(0,_.useMemo)(()=>({borderRadius:0,offset:n.pathOptions?.offset}),[n.pathOptions?.offset])})})}var PF=NF({isInternal:!1}),FF=NF({isInternal:!0});PF.displayName=`StepEdge`,FF.displayName=`StepEdgeInternal`;function IF(e){return(0,_.memo)(({id:t,sourceX:n,sourceY:r,targetX:i,targetY:a,label:o,labelStyle:s,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:f,markerEnd:p,markerStart:m,interactionWidth:h})=>{let[g,_,v]=zj({sourceX:n,sourceY:r,targetX:i,targetY:a}),y=e.isInternal?void 0:t;return(0,G.jsx)(wF,{id:y,path:g,labelX:_,labelY:v,label:o,labelStyle:s,labelShowBg:c,labelBgStyle:l,labelBgPadding:u,labelBgBorderRadius:d,style:f,markerEnd:p,markerStart:m,interactionWidth:h})})}var LF=IF({isInternal:!1}),RF=IF({isInternal:!0});LF.displayName=`StraightEdge`,RF.displayName=`StraightEdgeInternal`;function zF(e){return(0,_.memo)(({id:t,sourceX:n,sourceY:r,targetX:i,targetY:a,sourcePosition:o=$.Bottom,targetPosition:s=$.Top,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:p,style:m,markerEnd:h,markerStart:g,pathOptions:_,interactionWidth:v})=>{let[y,b,x]=Mj({sourceX:n,sourceY:r,sourcePosition:o,targetX:i,targetY:a,targetPosition:s,curvature:_?.curvature}),S=e.isInternal?void 0:t;return(0,G.jsx)(wF,{id:S,path:y,labelX:b,labelY:x,label:c,labelStyle:l,labelShowBg:u,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:p,style:m,markerEnd:h,markerStart:g,interactionWidth:v})})}var BF=zF({isInternal:!1}),VF=zF({isInternal:!0});BF.displayName=`BezierEdge`,VF.displayName=`BezierEdgeInternal`;var HF={default:VF,straight:RF,step:FF,smoothstep:MF,simplebezier:kF},UF={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null,zIndex:void 0},WF=(e,t,n)=>n===$.Left?e-t:n===$.Right?e+t:e,GF=(e,t,n)=>n===$.Top?e-t:n===$.Bottom?e+t:e,KF=`react-flow__edgeupdater`;function qF({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:i,onMouseEnter:a,onMouseOut:o,type:s}){return(0,G.jsx)(`circle`,{onMouseDown:i,onMouseEnter:a,onMouseOut:o,className:Lw([KF,`${KF}-${s}`]),cx:WF(t,r,e),cy:GF(n,r,e),r,stroke:`transparent`,fill:`transparent`})}function JF({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:r,sourceY:i,targetX:a,targetY:o,sourcePosition:s,targetPosition:c,onReconnect:l,onReconnectStart:u,onReconnectEnd:d,setReconnecting:f,setUpdateHover:p}){let m=yN(),h=(e,t)=>{if(e.button!==0)return;let{autoPanOnConnect:r,domNode:i,connectionMode:a,connectionRadius:o,lib:s,onConnectStart:c,cancelConnection:p,nodeLookup:h,rfId:g,panBy:_,updateConnection:v}=m.getState(),y=t.type===`target`;MM.onPointerDown(e.nativeEvent,{autoPanOnConnect:r,connectionMode:a,connectionRadius:o,domNode:i,handleId:t.id,nodeId:t.nodeId,nodeLookup:h,isTarget:y,edgeUpdaterType:t.type,lib:s,flowId:g,cancelConnection:p,panBy:_,isValidConnection:(...e)=>m.getState().isValidConnection?.(...e)??!0,onConnect:e=>l?.(n,e),onConnectStart:(r,i)=>{f(!0),u?.(e,n,t.type),c?.(r,i)},onConnectEnd:(...e)=>m.getState().onConnectEnd?.(...e),onReconnectEnd:(e,r)=>{f(!1),d?.(e,n,t.type,r)},updateConnection:v,getTransform:()=>m.getState().transform,getFromHandle:()=>m.getState().connection.fromHandle,dragThreshold:m.getState().connectionDragThreshold,handleDomNode:e.currentTarget})},g=e=>h(e,{nodeId:n.target,id:n.targetHandle??null,type:`target`}),_=e=>h(e,{nodeId:n.source,id:n.sourceHandle??null,type:`source`}),v=()=>p(!0),y=()=>p(!1);return(0,G.jsxs)(G.Fragment,{children:[(e===!0||e===`source`)&&(0,G.jsx)(qF,{position:s,centerX:r,centerY:i,radius:t,onMouseDown:g,onMouseEnter:v,onMouseOut:y,type:`source`}),(e===!0||e===`target`)&&(0,G.jsx)(qF,{position:c,centerX:a,centerY:o,radius:t,onMouseDown:_,onMouseEnter:v,onMouseOut:y,type:`target`})]})}function YF({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:r,onClick:i,onDoubleClick:a,onContextMenu:o,onMouseEnter:s,onMouseMove:c,onMouseLeave:l,reconnectRadius:u,onReconnect:d,onReconnectStart:f,onReconnectEnd:p,rfId:m,edgeTypes:h,noPanClassName:g,onError:v,disableKeyboardA11y:y}){let b=vN(t=>t.edgeLookup.get(e)),x=vN(e=>e.defaultEdgeOptions);b=x?{...x,...b}:b;let S=b.type||`default`,C=h?.[S]||HF[S];C===void 0&&(v?.(`011`,bA.error011(S)),S=`default`,C=h?.default||HF.default);let w=!!(b.focusable||t&&b.focusable===void 0),T=d!==void 0&&(b.reconnectable||n&&b.reconnectable===void 0),E=!!(b.selectable||r&&b.selectable===void 0),D=(0,_.useRef)(null),[O,k]=(0,_.useState)(!1),[A,j]=(0,_.useState)(!1),M=yN(),{zIndex:N=b.zIndex,sourceX:P,sourceY:F,targetX:I,targetY:L,sourcePosition:R,targetPosition:z}=vN((0,_.useCallback)(t=>{let n=t.nodeLookup.get(b.source),r=t.nodeLookup.get(b.target);if(!n||!r)return UF;let i=qj({id:e,sourceNode:n,targetNode:r,sourceHandle:b.sourceHandle||null,targetHandle:b.targetHandle||null,connectionMode:t.connectionMode,onError:v}),a=Pj({selected:b.selected,zIndex:b.zIndex,sourceNode:n,targetNode:r,elevateOnSelect:t.elevateEdgesOnSelect,zIndexMode:t.zIndexMode});return{...i||UF,zIndex:a}},[b.source,b.target,b.sourceHandle,b.targetHandle,b.selected,b.zIndex,v]),mN),B=(0,_.useMemo)(()=>b.markerStart?`url('#${Zj(b.markerStart,m)}')`:void 0,[b.markerStart,m]),V=(0,_.useMemo)(()=>b.markerEnd?`url('#${Zj(b.markerEnd,m)}')`:void 0,[b.markerEnd,m]);if(b.hidden||P===null||F===null||I===null||L===null)return null;let H=t=>{let{addSelectedEdges:n,unselectNodesAndEdges:r,multiSelectionActive:a}=M.getState();E&&(M.setState({nodesSelectionActive:!1}),b.selected&&a?(r({nodes:[],edges:[b]}),D.current?.blur()):n([e])),i&&i(t,b)},U=a?e=>{a(e,{...b})}:void 0,ee=o?e=>{o(e,{...b})}:void 0,W=s?e=>{s(e,{...b})}:void 0,te=c?e=>{c(e,{...b})}:void 0,ne=l?e=>{l(e,{...b})}:void 0;return(0,G.jsx)(`svg`,{style:{zIndex:N},children:(0,G.jsxs)(`g`,{className:Lw([`react-flow__edge`,`react-flow__edge-${S}`,b.className,g,{selected:b.selected,animated:b.animated,inactive:!E&&!i,updating:O,selectable:E}]),onClick:H,onDoubleClick:U,onContextMenu:ee,onMouseEnter:W,onMouseMove:te,onMouseLeave:ne,onKeyDown:w?t=>{if(!y&&SA.includes(t.key)&&E){let{unselectNodesAndEdges:n,addSelectedEdges:r}=M.getState();t.key===`Escape`?(D.current?.blur(),n({edges:[b]})):r([e])}}:void 0,tabIndex:w?0:void 0,role:b.ariaRole??(w?`group`:`img`),"aria-roledescription":`edge`,"data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":b.ariaLabel===null?void 0:b.ariaLabel||`Edge from ${b.source} to ${b.target}`,"aria-describedby":w?`${CN}-${m}`:void 0,ref:D,...b.domAttributes,children:[!A&&(0,G.jsx)(C,{id:e,source:b.source,target:b.target,type:b.type,selected:b.selected,animated:b.animated,selectable:E,deletable:b.deletable??!0,label:b.label,labelStyle:b.labelStyle,labelShowBg:b.labelShowBg,labelBgStyle:b.labelBgStyle,labelBgPadding:b.labelBgPadding,labelBgBorderRadius:b.labelBgBorderRadius,sourceX:P,sourceY:F,targetX:I,targetY:L,sourcePosition:R,targetPosition:z,data:b.data,style:b.style,sourceHandleId:b.sourceHandle,targetHandleId:b.targetHandle,markerStart:B,markerEnd:V,pathOptions:`pathOptions`in b?b.pathOptions:void 0,interactionWidth:b.interactionWidth}),T&&(0,G.jsx)(JF,{edge:b,isReconnectable:T,reconnectRadius:u,onReconnect:d,onReconnectStart:f,onReconnectEnd:p,sourceX:P,sourceY:F,targetX:I,targetY:L,sourcePosition:R,targetPosition:z,setUpdateHover:k,setReconnecting:j})]})})}var XF=(0,_.memo)(YF),ZF=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function QF({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:r,noPanClassName:i,onReconnect:a,onEdgeContextMenu:o,onEdgeMouseEnter:s,onEdgeMouseMove:c,onEdgeMouseLeave:l,onEdgeClick:u,reconnectRadius:d,onEdgeDoubleClick:f,onReconnectStart:p,onReconnectEnd:m,disableKeyboardA11y:h}){let{edgesFocusable:g,edgesReconnectable:_,elementsSelectable:v,onError:y}=vN(ZF,mN),b=mF(t);return(0,G.jsxs)(`div`,{className:`react-flow__edges`,children:[(0,G.jsx)(xF,{defaultColor:e,rfId:n}),b.map(e=>(0,G.jsx)(XF,{id:e,edgesFocusable:g,edgesReconnectable:_,elementsSelectable:v,noPanClassName:i,onReconnect:a,onContextMenu:o,onMouseEnter:s,onMouseMove:c,onMouseLeave:l,onClick:u,reconnectRadius:d,onDoubleClick:f,onReconnectStart:p,onReconnectEnd:m,rfId:n,onError:y,edgeTypes:r,disableKeyboardA11y:h},e))]})}QF.displayName=`EdgeRenderer`;var $F=(0,_.memo)(QF),eI=e=>`translate(${e[0]}px,${e[1]}px) scale(${e[2]})`;function tI({children:e}){let t=yN(),n=(0,_.useRef)(null),[r]=(0,_.useState)(()=>t.getState().transform);return uP(()=>{let e=null,r=()=>{let r=t.getState().transform;e&&r[0]===e[0]&&r[1]===e[1]&&r[2]===e[2]||(e=r,n.current&&(n.current.style.transform=eI(r)))};return r(),t.subscribe(r)},[t]),(0,G.jsx)(`div`,{ref:n,className:`react-flow__viewport xyflow__viewport react-flow__container`,style:{transform:eI(r)},children:e})}function nI(e){let t=_P(),n=(0,_.useRef)(!1);(0,_.useEffect)(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}var rI=e=>e.panZoom?.syncViewport;function iI(e){let t=vN(rI),n=yN();return(0,_.useEffect)(()=>{e&&(t?.(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function aI(e){return e.connection.inProgress?{...e.connection,to:oj(e.connection.to,e.transform)}:{...e.connection}}function oI(e){return e?t=>e(aI(t)):aI}function sI(e){return vN(oI(e),mN)}var cI=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function lI({containerStyle:e,style:t,type:n,component:r}){let{nodesConnectable:i,width:a,height:o,isValid:s,inProgress:c}=vN(cI,mN);return a&&i&&c?(0,G.jsx)(`svg`,{style:e,width:a,height:o,className:`react-flow__connectionline react-flow__container`,children:(0,G.jsx)(`g`,{className:Lw([`react-flow__connection`,bj(s)]),children:(0,G.jsx)(uI,{style:t,type:n,CustomComponent:r,isValid:s})})}):null}var uI=({style:e,type:t=OA.Bezier,CustomComponent:n,isValid:r})=>{let{inProgress:i,from:a,fromNode:o,fromHandle:s,fromPosition:c,to:l,toNode:u,toHandle:d,toPosition:f,pointer:p}=sI();if(!i)return;if(n)return(0,G.jsx)(n,{connectionLineType:t,connectionLineStyle:e,fromNode:o,fromHandle:s,fromX:a.x,fromY:a.y,toX:l.x,toY:l.y,fromPosition:c,toPosition:f,connectionStatus:bj(r),toNode:u,toHandle:d,pointer:p});let m=``,h={sourceX:a.x,sourceY:a.y,sourcePosition:c,targetX:l.x,targetY:l.y,targetPosition:f};switch(t){case OA.Bezier:[m]=Mj(h);break;case OA.SimpleBezier:[m]=EF(h);break;case OA.Step:[m]=Gj({...h,borderRadius:0});break;case OA.SmoothStep:[m]=Gj(h);break;default:[m]=zj(h)}return(0,G.jsx)(`path`,{d:m,fill:`none`,className:`react-flow__connection-path`,style:e})};uI.displayName=`ConnectionLine`;var dI={};function fI(e=dI){(0,_.useRef)(e),yN(),(0,_.useEffect)(()=>{},[e])}function pI(){yN(),(0,_.useRef)(!1),(0,_.useEffect)(()=>{},[])}function mI({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:r,onEdgeClick:i,onNodeDoubleClick:a,onEdgeDoubleClick:o,onNodeMouseEnter:s,onNodeMouseMove:c,onNodeMouseLeave:l,onNodeContextMenu:u,onSelectionContextMenu:d,onSelectionStart:f,onSelectionEnd:p,connectionLineType:m,connectionLineStyle:h,connectionLineComponent:g,connectionLineContainerStyle:_,selectionKeyCode:v,selectionOnDrag:y,selectionMode:b,multiSelectionKeyCode:x,panActivationKeyCode:S,zoomActivationKeyCode:C,deleteKeyCode:w,onlyRenderVisibleElements:T,elementsSelectable:E,defaultViewport:D,translateExtent:O,minZoom:k,maxZoom:A,preventScrolling:j,defaultMarkerColor:M,zoomOnScroll:N,zoomOnPinch:P,panOnScroll:F,panOnScrollSpeed:I,panOnScrollMode:L,zoomOnDoubleClick:R,panOnDrag:z,autoPanOnSelection:B,onPaneClick:V,onPaneMouseEnter:H,onPaneMouseMove:U,onPaneMouseLeave:ee,onPaneScroll:W,onPaneContextMenu:te,paneClickDistance:ne,nodeClickDistance:re,onEdgeContextMenu:ie,onEdgeMouseEnter:ae,onEdgeMouseMove:oe,onEdgeMouseLeave:se,reconnectRadius:ce,onReconnect:le,onReconnectStart:ue,onReconnectEnd:de,noDragClassName:fe,noWheelClassName:pe,noPanClassName:me,disableKeyboardA11y:he,nodeExtent:ge,rfId:_e,viewport:ve,onViewportChange:ye,nodesDraggable:be}){return fI(e),fI(t),pI(),nI(n),iI(ve),(0,G.jsx)(rF,{onPaneClick:V,onPaneMouseEnter:H,onPaneMouseMove:U,onPaneMouseLeave:ee,onPaneContextMenu:te,onPaneScroll:W,paneClickDistance:ne,deleteKeyCode:w,selectionKeyCode:v,selectionOnDrag:y,selectionMode:b,onSelectionStart:f,onSelectionEnd:p,multiSelectionKeyCode:x,panActivationKeyCode:S,zoomActivationKeyCode:C,elementsSelectable:E,zoomOnScroll:N,zoomOnPinch:P,zoomOnDoubleClick:R,panOnScroll:F,panOnScrollSpeed:I,panOnScrollMode:L,panOnDrag:z,autoPanOnSelection:B,defaultViewport:D,translateExtent:O,minZoom:k,maxZoom:A,onSelectionContextMenu:d,preventScrolling:j,noDragClassName:fe,noWheelClassName:pe,noPanClassName:me,disableKeyboardA11y:he,onViewportChange:ye,isControlledViewport:!!ve,children:(0,G.jsxs)(tI,{children:[(0,G.jsx)($F,{edgeTypes:t,onEdgeClick:i,onEdgeDoubleClick:o,onReconnect:le,onReconnectStart:ue,onReconnectEnd:de,onlyRenderVisibleElements:T,onEdgeContextMenu:ie,onEdgeMouseEnter:ae,onEdgeMouseMove:oe,onEdgeMouseLeave:se,reconnectRadius:ce,defaultMarkerColor:M,noPanClassName:me,disableKeyboardA11y:he,rfId:_e}),(0,G.jsx)(lI,{style:h,type:m,component:g,containerStyle:_}),(0,G.jsx)(`div`,{className:`react-flow__edgelabel-renderer`}),(0,G.jsx)(pF,{nodeTypes:e,onNodeClick:r,onNodeDoubleClick:a,onNodeMouseEnter:s,onNodeMouseMove:c,onNodeMouseLeave:l,onNodeContextMenu:u,nodeClickDistance:re,onlyRenderVisibleElements:T,noPanClassName:me,noDragClassName:fe,disableKeyboardA11y:he,nodeExtent:ge,rfId:_e,nodesDraggable:be}),(0,G.jsx)(`div`,{className:`react-flow__viewport-portal`})]})})}mI.displayName=`GraphView`;var hI=(0,_.memo)(mI),gI=ij(`React Flow`,`https://reactflow.dev/`),_I=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:i,height:a,fitView:o,fitViewOptions:s,minZoom:c=.5,maxZoom:l=2,nodeOrigin:u,nodeExtent:d,zIndexMode:f=`basic`}={})=>{let p=new Map,m=new Map,h=new Map,g=new Map,_=r??t??[],v=n??e??[],y=u??[0,0],b=d??xA;gM(h,g,_);let{nodesInitialized:x}=sM(v,p,m,{nodeOrigin:y,nodeExtent:b,zIndexMode:f}),S=[0,0,1];if(o&&i&&a){let{x:e,y:t,zoom:n}=dj(IA(p,{filter:e=>!(!e.width&&!e.initialWidth||!e.height&&!e.initialHeight)}),i,a,c,l,s?.padding??.1);S=[e,t,n]}return{rfId:`1`,width:i??0,height:a??0,transform:S,nodes:v,nodesInitialized:x,nodeLookup:p,parentLookup:m,edges:_,edgeLookup:g,connectionLookup:h,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:r!==void 0,panZoom:null,minZoom:c,maxZoom:l,translateExtent:xA,nodeExtent:b,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:wA.Strict,domNode:null,paneDragging:!1,noPanClassName:`nopan`,nodeOrigin:y,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:o??!1,fitViewOptions:s,fitViewResolver:null,connection:{...DA},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:``,autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:gI,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:`react`,debug:!1,ariaLabelConfig:CA,zIndexMode:f,defaultEdgeOptions:void 0,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map,onNodesDelete:void 0,onEdgesDelete:void 0,onDelete:void 0,onBeforeDelete:void 0,onViewportChangeStart:void 0,onViewportChange:void 0,onViewportChangeEnd:void 0,onNodeDragStart:void 0,onNodeDrag:void 0,onNodeDragStop:void 0,onSelectionDragStart:void 0,onSelectionDrag:void 0,onSelectionDragStop:void 0,onMoveStart:void 0,onMove:void 0,onMoveEnd:void 0,onConnect:void 0,onConnectStart:void 0,onConnectEnd:void 0,onClickConnectStart:void 0,onClickConnectEnd:void 0}},vI=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:i,height:a,fitView:o,fitViewOptions:s,minZoom:c,maxZoom:l,nodeOrigin:u,nodeExtent:d,zIndexMode:f})=>pN((p,m)=>{async function h(){let{nodeLookup:e,panZoom:t,fitViewOptions:n,fitViewResolver:r,width:i,height:a,minZoom:o,maxZoom:s}=m();t&&(await BA({nodes:e,width:i,height:a,panZoom:t,minZoom:o,maxZoom:s},n),r?.resolve(!0),p({fitViewResolver:null}))}return{..._I({nodes:e,edges:t,width:i,height:a,fitView:o,fitViewOptions:s,minZoom:c,maxZoom:l,nodeOrigin:u,nodeExtent:d,defaultNodes:n,defaultEdges:r,zIndexMode:f}),setNodes:e=>{let{nodeLookup:t,parentLookup:n,nodeOrigin:r,nodeExtent:i,elevateNodesOnSelect:a,fitViewQueued:o,zIndexMode:s,nodesSelectionActive:c}=m(),{nodesInitialized:l,hasSelectedNodes:u}=sM(e,t,n,{nodeOrigin:r,nodeExtent:i,elevateNodesOnSelect:a,checkEquality:!0,zIndexMode:s}),d=c&&u;o&&l?(h(),p({nodes:e,nodesInitialized:l,fitViewQueued:!1,fitViewOptions:void 0,nodesSelectionActive:d})):p({nodes:e,nodesInitialized:l,nodesSelectionActive:d})},setEdges:e=>{let{connectionLookup:t,edgeLookup:n}=m();gM(t,n,e),p({edges:e})},setDefaultNodesAndEdges:(e,t)=>{if(e){let{setNodes:t}=m();t(e),p({hasDefaultNodes:!0})}if(t){let{setEdges:e}=m();e(t),p({hasDefaultEdges:!0})}},updateNodeInternals:e=>{let{triggerNodeChanges:t,nodeLookup:n,parentLookup:r,domNode:i,nodeOrigin:a,nodeExtent:o,debug:s,fitViewQueued:c,zIndexMode:l}=m(),{changes:u,updatedInternals:d}=pM(e,n,r,i,a,o,l);d&&(iM(n,r,{nodeOrigin:a,nodeExtent:o,zIndexMode:l}),c?(h(),p({fitViewQueued:!1,fitViewOptions:void 0})):p({}),u?.length>0&&(s&&console.log(`React Flow: trigger node changes`,u),t?.(u)))},updateNodePositions:(e,t=!1)=>{let n=[],r=[],{nodeLookup:i,triggerNodeChanges:a,connection:o,updateConnection:s,onNodesChangeMiddlewareMap:c}=m();for(let[a,c]of e){let e=i.get(a),l=!!(e?.expandParent&&e?.parentId&&c?.position),u={id:a,type:`position`,position:l?{x:Math.max(0,c.position.x),y:Math.max(0,c.position.y)}:c.position,dragging:t};if(e&&o.inProgress&&o.fromNode.id===e.id){let t=Yj(e,o.fromHandle,$.Left,!0);s({...o,from:t})}l&&e.parentId&&n.push({id:a,parentId:e.parentId,rect:{...c.internals.positionAbsolute,width:c.measured.width??0,height:c.measured.height??0}}),r.push(u)}if(n.length>0){let{parentLookup:e,nodeOrigin:t}=m(),a=fM(n,i,e,t);r.push(...a)}for(let e of c.values())r=e(r);a(r)},triggerNodeChanges:e=>{let{onNodesChange:t,setNodes:n,nodes:r,hasDefaultNodes:i,debug:a}=m();e?.length&&(i&&n($N(e,r)),a&&console.log(`React Flow: trigger node changes`,e),t?.(e))},triggerEdgeChanges:e=>{let{onEdgesChange:t,setEdges:n,edges:r,hasDefaultEdges:i,debug:a}=m();e?.length&&(i&&n(eP(e,r)),a&&console.log(`React Flow: trigger edge changes`,e),t?.(e))},addSelectedNodes:e=>{let{multiSelectionActive:t,edgeLookup:n,nodeLookup:r,triggerNodeChanges:i,triggerEdgeChanges:a}=m();if(t){i(e.map(e=>tP(e,!0)));return}i(nP(r,new Set([...e]),!0)),a(nP(n))},addSelectedEdges:e=>{let{multiSelectionActive:t,edgeLookup:n,nodeLookup:r,triggerNodeChanges:i,triggerEdgeChanges:a}=m();if(t){a(e.map(e=>tP(e,!0)));return}a(nP(n,new Set([...e]))),i(nP(r,new Set,!0))},unselectNodesAndEdges:({nodes:e,edges:t}={})=>{let{edges:n,nodes:r,nodeLookup:i,triggerNodeChanges:a,triggerEdgeChanges:o}=m(),s=e||r,c=t||n,l=[];for(let e of s){if(!e.selected)continue;let t=i.get(e.id);t&&(t.selected=!1),l.push(tP(e.id,!1))}let u=[];for(let e of c)e.selected&&u.push(tP(e.id,!1));a(l),o(u)},setMinZoom:e=>{let{panZoom:t,maxZoom:n}=m();t?.setScaleExtent([e,n]),p({minZoom:e})},setMaxZoom:e=>{let{panZoom:t,minZoom:n}=m();t?.setScaleExtent([n,e]),p({maxZoom:e})},setTranslateExtent:e=>{m().panZoom?.setTranslateExtent(e),p({translateExtent:e})},resetSelectedElements:()=>{let{edges:e,nodes:t,triggerNodeChanges:n,triggerEdgeChanges:r,elementsSelectable:i}=m();if(!i)return;let a=t.reduce((e,t)=>t.selected?[...e,tP(t.id,!1)]:e,[]),o=e.reduce((e,t)=>t.selected?[...e,tP(t.id,!1)]:e,[]);n(a),r(o)},setNodeExtent:e=>{let{nodes:t,nodeLookup:n,parentLookup:r,nodeOrigin:i,elevateNodesOnSelect:a,nodeExtent:o,zIndexMode:s}=m();(e[0][0]!==o[0][0]||e[0][1]!==o[0][1]||e[1][0]!==o[1][0]||e[1][1]!==o[1][1])&&(sM(t,n,r,{nodeOrigin:i,nodeExtent:e,elevateNodesOnSelect:a,checkEquality:!1,zIndexMode:s}),p({nodeExtent:e}))},panBy:e=>{let{transform:t,width:n,height:r,panZoom:i,translateExtent:a}=m();return mM({delta:e,panZoom:i,transform:t,translateExtent:a,width:n,height:r})},setCenter:async(e,t,n)=>{let{width:r,height:i,maxZoom:a,panZoom:o}=m();if(!o)return!1;let s=n?.zoom===void 0?a:n.zoom;return await o.setViewport({x:r/2-e*s,y:i/2-t*s,zoom:s},{duration:n?.duration,ease:n?.ease,interpolate:n?.interpolate}),!0},cancelConnection:()=>{p({connection:{...DA}})},updateConnection:e=>{p({connection:e})},reset:()=>p({..._I()})}},Object.is);function yI({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:r,initialWidth:i,initialHeight:a,initialMinZoom:o,initialMaxZoom:s,initialFitViewOptions:c,fitView:l,nodeOrigin:u,nodeExtent:d,zIndexMode:f,children:p}){let[m]=(0,_.useState)(()=>vI({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,width:i,height:a,fitView:l,minZoom:o,maxZoom:s,fitViewOptions:c,nodeOrigin:u,nodeExtent:d,zIndexMode:f}));return(0,G.jsx)(gN,{value:m,children:(0,G.jsx)(mP,{children:(0,G.jsx)(zP,{children:p})})})}function bI({children:e,nodes:t,edges:n,defaultNodes:r,defaultEdges:i,width:a,height:o,fitView:s,fitViewOptions:c,minZoom:l,maxZoom:u,nodeOrigin:d,nodeExtent:f,zIndexMode:p}){return(0,_.useContext)(hN)?(0,G.jsx)(G.Fragment,{children:e}):(0,G.jsx)(yI,{initialNodes:t,initialEdges:n,defaultNodes:r,defaultEdges:i,initialWidth:a,initialHeight:o,fitView:s,initialFitViewOptions:c,initialMinZoom:l,initialMaxZoom:u,nodeOrigin:d,nodeExtent:f,zIndexMode:p,children:e})}var xI={width:`100%`,height:`100%`,overflow:`hidden`,position:`relative`,zIndex:0};function SI({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:i,nodeTypes:a,edgeTypes:o,onNodeClick:s,onEdgeClick:c,onInit:l,onMove:u,onMoveStart:d,onMoveEnd:f,onConnect:p,onConnectStart:m,onConnectEnd:h,onClickConnectStart:g,onClickConnectEnd:v,onNodeMouseEnter:y,onNodeMouseMove:b,onNodeMouseLeave:x,onNodeContextMenu:S,onNodeDoubleClick:C,onNodeDragStart:w,onNodeDrag:T,onNodeDragStop:E,onNodesDelete:D,onEdgesDelete:O,onDelete:k,onSelectionChange:A,onSelectionDragStart:j,onSelectionDrag:M,onSelectionDragStop:N,onSelectionContextMenu:P,onSelectionStart:F,onSelectionEnd:I,onBeforeDelete:L,connectionMode:R,connectionLineType:z=OA.Bezier,connectionLineStyle:B,connectionLineComponent:V,connectionLineContainerStyle:H,deleteKeyCode:U=`Backspace`,selectionKeyCode:ee=`Shift`,selectionOnDrag:W=!1,selectionMode:te=EA.Full,panActivationKeyCode:ne=`Space`,multiSelectionKeyCode:re=fj()?`Meta`:`Control`,zoomActivationKeyCode:ie=fj()?`Meta`:`Control`,snapToGrid:ae,snapGrid:oe,onlyRenderVisibleElements:se=!1,selectNodesOnDrag:ce,nodesDraggable:le,autoPanOnNodeFocus:ue,nodesConnectable:de,nodesFocusable:fe,nodeOrigin:pe=RN,edgesFocusable:me,edgesReconnectable:he,elementsSelectable:ge=!0,defaultViewport:_e=zN,minZoom:ve=.5,maxZoom:ye=2,translateExtent:be=xA,preventScrolling:xe=!0,nodeExtent:Se,defaultMarkerColor:Ce=`#b1b1b7`,zoomOnScroll:we=!0,zoomOnPinch:Te=!0,panOnScroll:Ee=!1,panOnScrollSpeed:De=.5,panOnScrollMode:Oe=TA.Free,zoomOnDoubleClick:ke=!0,panOnDrag:Ae=!0,onPaneClick:je,onPaneMouseEnter:Me,onPaneMouseMove:Ne,onPaneMouseLeave:Pe,onPaneScroll:Fe,onPaneContextMenu:Ie,paneClickDistance:Le=1,nodeClickDistance:Re=0,children:ze,onReconnect:Be,onReconnectStart:Ve,onReconnectEnd:He,onEdgeContextMenu:Ue,onEdgeDoubleClick:We,onEdgeMouseEnter:Ge,onEdgeMouseMove:Ke,onEdgeMouseLeave:qe,reconnectRadius:Je=10,onNodesChange:Ye,onEdgesChange:Xe,noDragClassName:Ze=`nodrag`,noWheelClassName:Qe=`nowheel`,noPanClassName:$e=`nopan`,fitView:et,fitViewOptions:tt,connectOnClick:nt,attributionPosition:rt,proOptions:it,defaultEdgeOptions:at,elevateNodesOnSelect:ot=!0,elevateEdgesOnSelect:st=!1,disableKeyboardA11y:ct=!1,autoPanOnConnect:lt,autoPanOnNodeDrag:ut,autoPanOnSelection:dt=!0,autoPanSpeed:ft,connectionRadius:pt,isValidConnection:mt,onError:ht,style:gt,id:_t,nodeDragThreshold:vt,connectionDragThreshold:yt,viewport:bt,onViewportChange:xt,width:St,height:Ct,colorMode:wt=`light`,debug:Tt,onScroll:Et,ariaLabelConfig:Dt,zIndexMode:Ot=`basic`,...kt},At){let jt=_t||`1`,Mt=GN(wt),Nt=(0,_.useCallback)(e=>{e.currentTarget.scrollTo({top:0,left:0,behavior:`instant`}),Et?.(e)},[Et]);return(0,G.jsx)(`div`,{"data-testid":`rf__wrapper`,...kt,onScroll:Nt,style:{...gt,...xI},ref:At,className:Lw([`react-flow`,i,Mt]),id:_t,role:`application`,children:(0,G.jsxs)(bI,{nodes:e,edges:t,width:St,height:Ct,fitView:et,fitViewOptions:tt,minZoom:ve,maxZoom:ye,nodeOrigin:pe,nodeExtent:Se,zIndexMode:Ot,children:[(0,G.jsx)(UN,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:p,onConnectStart:m,onConnectEnd:h,onClickConnectStart:g,onClickConnectEnd:v,nodesDraggable:le,autoPanOnNodeFocus:ue,nodesConnectable:de,nodesFocusable:fe,edgesFocusable:me,edgesReconnectable:he,elementsSelectable:ge,elevateNodesOnSelect:ot,elevateEdgesOnSelect:st,minZoom:ve,maxZoom:ye,nodeExtent:Se,onNodesChange:Ye,onEdgesChange:Xe,snapToGrid:ae,snapGrid:oe,connectionMode:R,translateExtent:be,connectOnClick:nt,defaultEdgeOptions:at,fitView:et,fitViewOptions:tt,onNodesDelete:D,onEdgesDelete:O,onDelete:k,onNodeDragStart:w,onNodeDrag:T,onNodeDragStop:E,onSelectionDrag:M,onSelectionDragStart:j,onSelectionDragStop:N,onMove:u,onMoveStart:d,onMoveEnd:f,noPanClassName:$e,nodeOrigin:pe,rfId:jt,autoPanOnConnect:lt,autoPanOnNodeDrag:ut,autoPanSpeed:ft,onError:ht,connectionRadius:pt,isValidConnection:mt,selectNodesOnDrag:ce,nodeDragThreshold:vt,connectionDragThreshold:yt,onBeforeDelete:L,debug:Tt,ariaLabelConfig:Dt,zIndexMode:Ot}),(0,G.jsx)(hI,{onInit:l,onNodeClick:s,onEdgeClick:c,onNodeMouseEnter:y,onNodeMouseMove:b,onNodeMouseLeave:x,onNodeContextMenu:S,onNodeDoubleClick:C,nodeTypes:a,edgeTypes:o,connectionLineType:z,connectionLineStyle:B,connectionLineComponent:V,connectionLineContainerStyle:H,selectionKeyCode:ee,selectionOnDrag:W,selectionMode:te,deleteKeyCode:U,multiSelectionKeyCode:re,panActivationKeyCode:ne,zoomActivationKeyCode:ie,onlyRenderVisibleElements:se,defaultViewport:_e,translateExtent:be,minZoom:ve,maxZoom:ye,preventScrolling:xe,zoomOnScroll:we,zoomOnPinch:Te,zoomOnDoubleClick:ke,panOnScroll:Ee,panOnScrollSpeed:De,panOnScrollMode:Oe,panOnDrag:Ae,autoPanOnSelection:dt,onPaneClick:je,onPaneMouseEnter:Me,onPaneMouseMove:Ne,onPaneMouseLeave:Pe,onPaneScroll:Fe,onPaneContextMenu:Ie,paneClickDistance:Le,nodeClickDistance:Re,onSelectionContextMenu:P,onSelectionStart:F,onSelectionEnd:I,onReconnect:Be,onReconnectStart:Ve,onReconnectEnd:He,onEdgeContextMenu:Ue,onEdgeDoubleClick:We,onEdgeMouseEnter:Ge,onEdgeMouseMove:Ke,onEdgeMouseLeave:qe,reconnectRadius:Je,defaultMarkerColor:Ce,noDragClassName:Ze,noWheelClassName:Qe,noPanClassName:$e,rfId:jt,disableKeyboardA11y:ct,nodeExtent:Se,viewport:bt,onViewportChange:xt,nodesDraggable:le}),(0,G.jsx)(LN,{onSelectionChange:A}),ze,(0,G.jsx)(jN,{proOptions:it,position:rt}),(0,G.jsx)(ON,{rfId:jt,disableKeyboardA11y:ct})]})})}var CI=lP(SI);bA.error014();function wI({dimensions:e,lineWidth:t,variant:n,className:r}){return(0,G.jsx)(`path`,{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:Lw([`react-flow__background-pattern`,n,r])})}function TI({radius:e,className:t}){return(0,G.jsx)(`circle`,{cx:e,cy:e,r:e,className:Lw([`react-flow__background-pattern`,`dots`,t])})}var EI;(function(e){e.Lines=`lines`,e.Dots=`dots`,e.Cross=`cross`})(EI||={});var DI={[EI.Dots]:1,[EI.Lines]:1,[EI.Cross]:6},OI=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function kI({id:e,variant:t=EI.Dots,gap:n=20,size:r,lineWidth:i=1,offset:a=0,color:o,bgColor:s,style:c,className:l,patternClassName:u}){let d=(0,_.useRef)(null),{transform:f,patternId:p}=vN(OI,mN),m=r||DI[t],h=t===EI.Dots,g=t===EI.Cross,v=Array.isArray(n)?n:[n,n],y=[v[0]*f[2]||1,v[1]*f[2]||1],b=m*f[2],x=Array.isArray(a)?a:[a,a],S=g?[b,b]:y,C=[x[0]*f[2]+S[0]/2,x[1]*f[2]+S[1]/2],w=`${p}${e||``}`;return(0,G.jsxs)(`svg`,{className:Lw([`react-flow__background`,l]),style:{...c,...SP,"--xy-background-color-props":s,"--xy-background-pattern-color-props":o},ref:d,"data-testid":`rf__background`,children:[(0,G.jsx)(`pattern`,{id:w,x:f[0]%y[0],y:f[1]%y[1],width:y[0],height:y[1],patternUnits:`userSpaceOnUse`,patternTransform:`translate(-${C[0]},-${C[1]})`,children:h?(0,G.jsx)(TI,{radius:b/2,className:u}):(0,G.jsx)(wI,{dimensions:S,lineWidth:i,variant:t,className:u})}),(0,G.jsx)(`rect`,{x:`0`,y:`0`,width:`100%`,height:`100%`,fill:`url(#${w})`})]})}kI.displayName=`Background`;var AI=(0,_.memo)(kI);function jI(){return(0,G.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 32 32`,children:(0,G.jsx)(`path`,{d:`M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z`})})}function MI(){return(0,G.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 32 5`,children:(0,G.jsx)(`path`,{d:`M0 0h32v4.2H0z`})})}function NI(){return(0,G.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 32 30`,children:(0,G.jsx)(`path`,{d:`M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z`})})}function PI(){return(0,G.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 25 32`,children:(0,G.jsx)(`path`,{d:`M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z`})})}function FI(){return(0,G.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 25 32`,children:(0,G.jsx)(`path`,{d:`M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z`})})}function II({children:e,className:t,...n}){return(0,G.jsx)(`button`,{type:`button`,className:Lw([`react-flow__controls-button`,t]),...n,children:e})}var LI=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function RI({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:i,onZoomIn:a,onZoomOut:o,onFitView:s,onInteractiveChange:c,className:l,children:u,position:d=`bottom-left`,orientation:f=`vertical`,"aria-label":p}){let m=yN(),{isInteractive:h,minZoomReached:g,maxZoomReached:_,ariaLabelConfig:v}=vN(LI,mN),{zoomIn:y,zoomOut:b,fitView:x}=_P();return(0,G.jsxs)(kN,{className:Lw([`react-flow__controls`,f===`horizontal`?`horizontal`:`vertical`,l]),position:d,style:e,"data-testid":`rf__controls`,"aria-label":p??v[`controls.ariaLabel`],children:[t&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(II,{onClick:()=>{y(),a?.()},className:`react-flow__controls-zoomin`,title:v[`controls.zoomIn.ariaLabel`],"aria-label":v[`controls.zoomIn.ariaLabel`],disabled:_,children:(0,G.jsx)(jI,{})}),(0,G.jsx)(II,{onClick:()=>{b(),o?.()},className:`react-flow__controls-zoomout`,title:v[`controls.zoomOut.ariaLabel`],"aria-label":v[`controls.zoomOut.ariaLabel`],disabled:g,children:(0,G.jsx)(MI,{})})]}),n&&(0,G.jsx)(II,{className:`react-flow__controls-fitview`,onClick:()=>{x(i),s?.()},title:v[`controls.fitView.ariaLabel`],"aria-label":v[`controls.fitView.ariaLabel`],children:(0,G.jsx)(NI,{})}),r&&(0,G.jsx)(II,{className:`react-flow__controls-interactive`,onClick:()=>{m.setState({nodesDraggable:!h,nodesConnectable:!h,elementsSelectable:!h}),c?.(!h)},title:v[`controls.interactive.ariaLabel`],"aria-label":v[`controls.interactive.ariaLabel`],children:h?(0,G.jsx)(FI,{}):(0,G.jsx)(PI,{})}),u]})}RI.displayName=`Controls`;var zI=(0,_.memo)(RI);function BI({id:e,x:t,y:n,width:r,height:i,style:a,color:o,strokeColor:s,strokeWidth:c,className:l,borderRadius:u,shapeRendering:d,selected:f,onClick:p}){let{background:m,backgroundColor:h}=a||{},g=o||m||h;return(0,G.jsx)(`rect`,{className:Lw([`react-flow__minimap-node`,{selected:f},l]),x:t,y:n,rx:u,ry:u,width:r,height:i,style:{fill:g,stroke:s,strokeWidth:c},shapeRendering:d,onClick:p?t=>p(t,e):void 0})}var VI=(0,_.memo)(BI),HI=e=>e.nodes.map(e=>e.id),UI=e=>e instanceof Function?e:()=>e;function WI({nodeStrokeColor:e,nodeColor:t,nodeClassName:n=``,nodeBorderRadius:r=5,nodeStrokeWidth:i,nodeComponent:a=VI,onClick:o}){let s=vN(HI,mN),c=UI(t),l=UI(e),u=UI(n),d=typeof window>`u`||window.chrome?`crispEdges`:`geometricPrecision`;return(0,G.jsx)(G.Fragment,{children:s.map(e=>(0,G.jsx)(KI,{id:e,nodeColorFunc:c,nodeStrokeColorFunc:l,nodeClassNameFunc:u,nodeBorderRadius:r,nodeStrokeWidth:i,NodeComponent:a,onClick:o,shapeRendering:d},e))})}function GI({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:r,nodeBorderRadius:i,nodeStrokeWidth:a,shapeRendering:o,NodeComponent:s,onClick:c}){let{node:l,x:u,y:d,width:f,height:p}=vN(t=>{let n=t.nodeLookup.get(e);if(!n)return{node:void 0,x:0,y:0,width:0,height:0};let r=n.internals.userNode,{x:i,y:a}=n.internals.positionAbsolute,{width:o,height:s}=mj(r);return{node:r,x:i,y:a,width:o,height:s}},mN);return!l||l.hidden||!hj(l)?null:(0,G.jsx)(s,{x:u,y:d,width:f,height:p,style:l.style,selected:!!l.selected,className:r(l),color:t(l),borderRadius:i,strokeColor:n(l),strokeWidth:a,shapeRendering:o,onClick:c,id:l.id})}var KI=(0,_.memo)(GI),qI=(0,_.memo)(WI),JI=200,YI=150,XI=e=>!e.hidden,ZI=e=>{let t={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]},n=!1;for(let t of e.nodeLookup.values())if(!t.hidden){n=!0;break}return{viewBB:t,boundingRect:n?$A(IA(e.nodeLookup,{filter:XI}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},QI=(e,t)=>e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height,$I=(e,t)=>QI(e.viewBB,t.viewBB)&&QI(e.boundingRect,t.boundingRect)&&e.rfId===t.rfId&&e.panZoom===t.panZoom&&e.translateExtent===t.translateExtent&&e.flowWidth===t.flowWidth&&e.flowHeight===t.flowHeight&&e.ariaLabelConfig===t.ariaLabelConfig,eL=`react-flow__minimap-desc`;function tL({style:e,className:t,nodeStrokeColor:n,nodeColor:r,nodeClassName:i=``,nodeBorderRadius:a=5,nodeStrokeWidth:o,nodeComponent:s,bgColor:c,maskColor:l,maskStrokeColor:u,maskStrokeWidth:d,position:f=`bottom-right`,onClick:p,onNodeClick:m,pannable:h=!1,zoomable:g=!1,ariaLabel:v,inversePan:y,zoomStep:b=1,offsetScale:x=5}){let S=yN(),C=(0,_.useRef)(null),{boundingRect:w,panZoom:T,viewBB:E,rfId:D,translateExtent:O,flowWidth:k,flowHeight:A,ariaLabelConfig:j}=vN(ZI,$I),M=e?.width??JI,N=e?.height??YI,P=w.width/M,F=w.height/N,I=Math.max(P,F),L=I*M,R=I*N,z=x*I,B=w.x-(L-w.width)/2-z,V=w.y-(R-w.height)/2-z,H=L+z*2,U=R+z*2,ee=`${eL}-${D}`,W=(0,_.useRef)(0),te=(0,_.useRef)();W.current=I,(0,_.useEffect)(()=>{let e=S.getState().panZoom;if(C.current&&e)return te.current=NM({domNode:C.current,panZoom:e,getTransform:()=>S.getState().transform,getViewScale:()=>W.current}),()=>{te.current?.destroy()}},[T]),(0,_.useEffect)(()=>{te.current?.update({translateExtent:O,width:k,height:A,inversePan:y,pannable:h,zoomStep:b,zoomable:g})},[h,g,y,b,O,k,A]);let ne=p?e=>{let[t,n]=te.current?.pointer(e)||[0,0];p(e,{x:t,y:n})}:void 0,re=(0,_.useCallback)((e,t)=>{let n=S.getState().nodeLookup.get(t).internals.userNode;m?.(e,n)},[m]),ie=m?re:void 0,ae=v??j[`minimap.ariaLabel`];return(0,G.jsx)(kN,{position:f,style:{...e,"--xy-minimap-background-color-props":typeof c==`string`?c:void 0,"--xy-minimap-mask-background-color-props":typeof l==`string`?l:void 0,"--xy-minimap-mask-stroke-color-props":typeof u==`string`?u:void 0,"--xy-minimap-mask-stroke-width-props":typeof d==`number`?d*I:void 0,"--xy-minimap-node-background-color-props":typeof r==`string`?r:void 0,"--xy-minimap-node-stroke-color-props":typeof n==`string`?n:void 0,"--xy-minimap-node-stroke-width-props":typeof o==`number`?o:void 0},className:Lw([`react-flow__minimap`,t]),"data-testid":`rf__minimap`,children:(0,G.jsxs)(`svg`,{width:M,height:N,viewBox:`${B} ${V} ${H} ${U}`,className:`react-flow__minimap-svg`,role:`img`,"aria-labelledby":ee,ref:C,onClick:ne,children:[ae&&(0,G.jsx)(`title`,{id:ee,children:ae}),(0,G.jsx)(qI,{onClick:ie,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:a,nodeClassName:i,nodeStrokeWidth:o,nodeComponent:s}),(0,G.jsx)(`path`,{className:`react-flow__minimap-mask`,d:`M${B-z},${V-z}h${H+z*2}v${U+z*2}h${-H-z*2}z
|
|
25
25
|
M${E.x},${E.y}h${E.width}v${E.height}h${-E.width}z`,fillRule:`evenodd`,pointerEvents:`none`})]})})}tL.displayName=`MiniMap`;var nL=(0,_.memo)(tL),rL=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,iL={[JM.Line]:`right`,[JM.Handle]:`bottom-right`};function aL({nodeId:e,position:t,variant:n=JM.Handle,className:r,style:i=void 0,children:a,color:o,minWidth:s=10,minHeight:c=10,maxWidth:l=Number.MAX_VALUE,maxHeight:u=Number.MAX_VALUE,keepAspectRatio:d=!1,resizeDirection:f,autoScale:p=!0,shouldResize:m,onResizeStart:h,onResize:g,onResizeEnd:v}){let y=IP(),b=typeof e==`string`?e:y,x=yN(),S=(0,_.useRef)(null),C=n===JM.Handle,w=vN((0,_.useCallback)(rL(C&&p),[C,p]),mN),T=(0,_.useRef)(null),E=t??iL[n];(0,_.useEffect)(()=>{if(S.current&&b)return T.current||=aN({domNode:S.current,nodeId:b,getStoreItems:()=>{let{nodeLookup:e,transform:t,snapGrid:n,snapToGrid:r,nodeOrigin:i,domNode:a}=x.getState();return{nodeLookup:e,transform:t,snapGrid:n,snapToGrid:r,nodeOrigin:i,paneDomNode:a}},onChange:(e,t)=>{let{triggerNodeChanges:n,nodeLookup:r,parentLookup:i,nodeOrigin:a}=x.getState(),o=[],s={x:e.x,y:e.y},c=r.get(b);if(c&&c.expandParent&&c.parentId){let t=c.origin??a,n=e.width??c.measured.width??0,l=e.height??c.measured.height??0,u=fM([{id:c.id,parentId:c.parentId,rect:{width:n,height:l,...gj({x:e.x??c.position.x,y:e.y??c.position.y},{width:n,height:l},c.parentId,r,t)}}],r,i,a);o.push(...u),s.x=e.x?Math.max(t[0]*n,e.x):void 0,s.y=e.y?Math.max(t[1]*l,e.y):void 0}if(s.x!==void 0&&s.y!==void 0){let e={id:b,type:`position`,position:{...s}};o.push(e)}if(e.width!==void 0&&e.height!==void 0){let t={id:b,type:`dimensions`,resizing:!0,setAttributes:f?f===`horizontal`?`width`:`height`:!0,dimensions:{width:e.width,height:e.height}};o.push(t)}for(let e of t){let t={...e,type:`position`};o.push(t)}n(o)},onEnd:({width:e,height:t})=>{let n={id:b,type:`dimensions`,resizing:!1,dimensions:{width:e,height:t}};x.getState().triggerNodeChanges([n])}}),T.current.update({controlPosition:E,boundaries:{minWidth:s,minHeight:c,maxWidth:l,maxHeight:u},keepAspectRatio:d,resizeDirection:f,onResizeStart:h,onResize:g,onResizeEnd:v,shouldResize:m}),()=>{T.current?.destroy()}},[E,s,c,l,u,d,h,g,v,m]);let D=E.split(`-`);return(0,G.jsx)(`div`,{className:Lw([`react-flow__resize-control`,`nodrag`,...D,n,r]),ref:S,style:{...i,scale:w,...o&&{[C?`backgroundColor`:`borderColor`]:o}},children:a})}(0,_.memo)(aL);var oL=3,sL=60,cL=140,lL=e=>e.replace(/\s+/g,` `).trim();function uL(e){let t=lL(e.description||e.proposed||e.name||`Tool call`);return t.length>sL?`${t.slice(0,59)}…`:t}function dL(e,t){if(t?.status===`ready`&&t.text)return t.text;if(e.length){let t=[...new Set(e.map(uL))],n=t.slice(0,oL),r=n.join(` · `)+(t.length>n.length?` · +${t.length-n.length} more`:``);return r.length>cL?`${r.slice(0,139)}…`:r}return t?.status===`loading`?`Summarizing…`:t?.status===`error`?`Summary unavailable.`:`No tool calls in this request.`}var fL=236,pL=300;function mL({data:e}){let t=e.failed===null?``:e.failed?`graph-node-fail`:`graph-node-ok`;return(0,G.jsxs)(`button`,{type:`button`,className:`graph-node ${t}`,onClick:e.onClick,children:[(0,G.jsx)(WP,{type:`target`,position:$.Left,style:{opacity:0}}),(0,G.jsx)(WP,{type:`source`,position:$.Right,style:{opacity:0}}),(0,G.jsxs)(`div`,{className:`graph-node-head`,children:[(0,G.jsxs)(`span`,{className:`graph-node-num`,children:[`Request #`,e.number]}),e.failed!==null&&(0,G.jsx)(`span`,{className:`graph-node-status ${e.failed?`fail`:`ok`}`,children:e.failed?`Failed`:`OK`})]}),(0,G.jsx)(`p`,{className:`graph-node-summary`,children:e.summaryText}),(0,G.jsxs)(`div`,{className:`graph-node-meta`,children:[(0,G.jsx)(`span`,{children:zC(e.cost,e.costEstimated)}),(0,G.jsx)(`span`,{children:BC(e.durationMs)}),e.totalCalls>0&&(0,G.jsxs)(`span`,{className:e.verifiedCount===e.totalCalls?`graph-node-verified-all`:`graph-node-verified-partial`,children:[e.verifiedCount,`/`,e.totalCalls,` verified`]})]})]})}var hL={request:mL};function gL({trace:e,blocks:t,summaries:n,onSelectStep:r}){let i=np(),{nodes:a,edges:o}=(0,_.useMemo)(()=>{let i=new Map((e.requests||[]).map(e=>[e.id,e])),a=new Map;for(let t of e.callVerifications||[]){let e=a.get(t.exchange_id)||[];e.push(t),a.set(t.exchange_id,e)}let o=t.map((e,t)=>{let o=i.get(e.exchangeId),s=n[e.exchangeId],c=a.get(e.exchangeId)||[],l=e.completion?ap(e.completion):null;return{id:e.exchangeId,type:`request`,position:{x:t*pL,y:0},data:{number:e.number,summaryText:dL(c,s),failed:l,cost:o?.cost??null,costEstimated:o?.costEstimated??!1,durationMs:o?.durationMs??null,verifiedCount:c.filter(e=>e.verified).length,totalCalls:c.length,onClick:()=>r(e.items[0]?.index??0)},style:{width:fL}}}),s=[];for(let e=0;e<t.length-1;e++){let n=t[e],r=t[e+1],i=a.get(n.exchangeId)||[],o=i.filter(e=>e.verified).length,c=i.length>0&&o===i.length,l=o>0&&o<i.length,u=i.length?`${o}/${i.length} verified`:void 0;s.push({id:`seq-${n.exchangeId}-${r.exchangeId}`,source:n.exchangeId,target:r.exchangeId,label:u,style:{stroke:c?`#3d7a5e`:l?`#8a7233`:i.length?`#7a3d45`:`var(--line)`},labelStyle:{fill:`var(--muted)`,fontSize:10},labelBgStyle:{fill:`var(--deep)`}})}return{nodes:o,edges:s}},[e,t,n,r]);return t.length?(0,G.jsx)(`div`,{className:`graph-canvas`,children:(0,G.jsxs)(CI,{nodes:a,edges:o,nodeTypes:hL,fitView:!0,proOptions:{hideAttribution:!0},colorMode:i,children:[(0,G.jsx)(AI,{color:i===`dark`?`#31362c`:`#d3dbcb`,gap:24}),(0,G.jsx)(zI,{showInteractive:!1}),(0,G.jsx)(nL,{pannable:!0,zoomable:!0,style:{background:`var(--deep)`},maskColor:i===`dark`?`rgba(17,19,21,0.75)`:`rgba(255,255,255,0.75)`,nodeColor:i===`dark`?`#31362c`:`#d3dbcb`})]})}):(0,G.jsx)(`div`,{className:`graph-empty`,children:`No model requests captured for this trace yet.`})}var _L=[``,`Minimal`,`Low`,`Moderate`,`High`,`Critical`],vL=[``,`Ignore`,`Routine`,`Watch`,`Review carefully`,`Lock down`],yL={"content-type":`application/json`,"x-raytace-experiment":`1`};async function bL(e,t){let n=await e.json().catch(()=>({}));if(!e.ok)throw Error(n.error||t);return n}var xL=async e=>bL(await x().fetch(`/raytace/sandboxes/${e}/files`,{cache:`no-store`}),`The initial scan could not be loaded.`),SL=async(e,t)=>bL(await x().fetch(`/raytace/sandboxes/${e}/files`,{method:`POST`,headers:yL,body:JSON.stringify({updates:t})}),`That change could not be saved.`),CL=async(e,t,n,r)=>bL(await x().fetch(`/raytace/sandboxes/${e}/activity${t||n?`?${t?`since=${Math.floor(t)}`:``}${t&&n?`&`:``}${n?`until=${Math.ceil(n)}`:``}`:``}`,{cache:`no-store`,signal:r}),`Sandbox activity could not be loaded.`),wL=async e=>bL(await x().fetch(`/raytace/alerts${e?`?sandbox=${e}`:``}`,{cache:`no-store`}),`Alerts could not be loaded.`);async function TL(){try{let e=await x().fetch(`/raytace/me`,{cache:`no-store`});if(!e.ok)return null;let t=await e.json();return typeof t.notify_email==`boolean`?t.notify_email:null}catch{return null}}var EL=async e=>bL(await x().fetch(`/raytace/me`,{method:`POST`,headers:yL,body:JSON.stringify({notify_email:e})}),`That setting could not be saved.`),DL=async e=>bL(await x().fetch(`/raytace/alerts/seen`,{method:`POST`,headers:yL,body:JSON.stringify({ids:e})}),`Alerts could not be marked seen.`),OL=new Map;function kL(e){let[t,n]=(0,_.useState)(new Map);return(0,_.useEffect)(()=>{if(!e)return;let t=!1;return OL.has(e)||OL.set(e,xL(e).then(e=>new Map(e.files.map(e=>[e.path,e])),()=>(OL.delete(e),new Map))),OL.get(e).then(e=>{t||n(e)}),()=>{t=!0}},[e]),t}var AL=e=>{OL.delete(e)},jL={read:`Read`,created:`Created`,changed:`Changed`,emptied:`Emptied`,appended:`Appended to`,deleted:`Deleted`,renamed:`Renamed`,permissions_changed:`Permissions changed`,attempted:`Refused`,opened_for_writing:`Opened for writing, not changed`},ML={read:`a read`,write:`a write`,delete:`a delete`,rename:`a rename`,permissions:`a permission change`},NL={confirmed:[`confirmed`,`The kernel saw the call, and the file shows its effect.`],attempted:[`refused`,`The kernel refused the call. Nothing changed.`],possible:[`possible`,`The file was opened for writing and is as it was.`],one_of:[`one of several`,`More than one process made such a call at that moment; this is the likeliest.`],unattributed:[`no call seen`,`The file changed on disk and the kernel reported no call for it: events may have been lost, or it was changed another way.`]},PL={connected:[`connected`,`The connection was made.`],attempted:[`attempted`,`The program did not wait for the result, so the call says only that it tried.`],refused_by_policy:[`refused by the firewall`,`A private address: the sandbox firewall rejects it, whatever the call returned.`],failed:[`failed`,`The connection was not made.`],listening:[`listening`,`The program accepts connections here. Nothing outside the sandbox network is routed to it.`]},FL=e=>new Date(e*1e3).toLocaleString(void 0,{day:`numeric`,month:`short`,hour:`numeric`,minute:`2-digit`,second:`2-digit`}),IL=e=>e>1?` ×${e.toLocaleString()}`:``,LL=e=>e?e.slice(0,8):null;function RL(e){let t=e.basis??{},n=LL(t.before?.sha256),r=LL(t.after?.sha256);return[t.syscall&&`Call: ${t.syscall}${t.errno?` (${t.errno})`:``}`,t.watcher?.length&&`Seen on disk: ${t.watcher.join(`, `)}`,n&&r&&n!==r&&`SHA-256 ${n}… → ${r}…`,t.path_from&&{argv:`The file is named in the program's own arguments.`,argv_folder:`A folder in the program's arguments holds the file.`,argv_text:`The file's name appears in the program's arguments.`}[t.path_from],t.candidates?.length&&`Also at that moment: ${t.candidates.map(e=>e.process??`pid ${e.pid}`).join(`, `)}`,t.note].filter(Boolean).join(`
|
|
26
|
-
`)}function zL({fact:e,step:t,onOpenCall:n}){return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`td`,{title:e.command??void 0,children:e.process??(0,G.jsx)(`span`,{className:`rt-muted`,children:`–`})}),(0,G.jsx)(`td`,{className:`rt-scan-open`,children:t&&(0,G.jsxs)(`button`,{type:`button`,className:`link-button`,onClick:()=>n(t.trace,t.call),children:[`Open the step `,(0,G.jsx)(P,{size:11})]})})]})}function BL({fact:e}){return(0,G.jsxs)(G.Fragment,{children:[Object.entries(e.outcomes).map(([e,t],n)=>(0,G.jsxs)(`span`,{title:PL[e]?.[1],className:e===`refused_by_policy`||e===`failed`?`exec-fail`:void 0,children:[n?` · `:``,PL[e]?.[0]??e,IL(t)]},e)),e.errno&&(0,G.jsxs)(`span`,{className:`rt-muted`,children:[` (`,e.errno,`)`]})]})}function VL({fact:e}){let[t,n]=(0,_.useState)(!1),r=t?e.packages:e.packages.slice(0,12);return(0,G.jsxs)(G.Fragment,{children:[r.map(e=>(0,G.jsxs)(`code`,{title:e.source,className:`rt-package`,children:[e.name,`@`,e.version]},`${e.name}@${e.version}`)),e.packages.length>r.length&&(0,G.jsxs)(`button`,{type:`button`,className:`link-button`,onClick:()=>n(!0),children:[`and `,(e.total-r.length).toLocaleString(),` more`]}),t&&e.total>e.packages.length&&(0,G.jsxs)(`span`,{className:`rt-muted`,children:[` and `,(e.total-e.packages.length).toLocaleString(),` not listed`]})]})}function HL({box:e,stepFor:t,onOpenCall:n}){let[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(null);if((0,_.useEffect)(()=>{i(null),o(null);let t=!1,n,r=async()=>{try{let n=await CL(e);t||(i(n),o(null))}catch(e){t||o(e instanceof Error?e.message:`Sandbox activity could not be loaded.`)}t||(n=setTimeout(r,1e4))};return r(),()=>{t=!0,clearTimeout(n)}},[e]),a&&!r)return(0,G.jsx)(`p`,{role:`alert`,className:`rt-problem`,children:a});if(!r)return(0,G.jsx)(rp,{label:`Loading sandbox activity…`});let s=new Set(r.network.map(e=>e.host).filter(Boolean)),c=r.lookups.filter(e=>!s.has(e.name)),l=!r.network.length&&!r.packages.length&&!r.files.length&&!r.lookups.length&&!r.bulk.length&&!r.identity.length,u=[...r.network,...r.files,...r.packages].some(e=>e.coverage===`gaps`);return l?(0,G.jsx)(`p`,{className:`rt-empty`,children:`Nothing recorded yet. The kernel layer of the sandbox reports every connection the agent makes, the packages it installs, and what happens to
|
|
27
|
-
`)}`,children:[` `,e.ip,(e.addresses?.length??1)>1?` and ${e.addresses.length-1} more`:``]}),e.coverage===`gaps`&&(0,G.jsx)(`span`,{className:`rt-flag`,title:`Events were lost about then.`,children:`gaps`})]}),(0,G.jsx)(`td`,{children:(0,G.jsx)(BL,{fact:e})}),(0,G.jsx)(zL,{fact:e,step:t(e.call_id),onOpenCall:n})]},e.id))})]})}):(0,G.jsx)(`p`,{className:`rt-empty`,children:`No connection left the sandbox.`}),c.length>0&&(0,G.jsxs)(`p`,{className:`rt-foot`,children:[`Looked up, with no connection seen: `,c.slice(0,40).map((e,t)=>(0,G.jsxs)(`span`,{title:e.failed?`The lookup failed: ${e.failed}`:e.addresses.join(`, `),children:[t?`, `:``,(0,G.jsx)(`code`,{children:e.name}),e.failed?` (${e.failed})`:``]},e.id)),c.length>40?` and ${c.length-40} more`:``,`.`]}),(0,G.jsx)(`div`,{className:`rt-list-head`,children:(0,G.jsx)(`span`,{children:`PACKAGES INSTALLED`})}),r.packages.length?(0,G.jsx)(`div`,{className:`rt-table-wrap`,children:(0,G.jsxs)(`table`,{className:`rt-table rt-scan`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{children:`When`}),(0,G.jsx)(`th`,{children:`Manager`}),(0,G.jsx)(`th`,{children:`Packages`}),(0,G.jsx)(`th`,{children:`Basis`}),(0,G.jsx)(`th`,{children:`Program`}),(0,G.jsx)(`th`,{children:`Step`})]})}),(0,G.jsx)(`tbody`,{children:r.packages.map(e=>(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`td`,{children:(0,G.jsx)(`time`,{children:FL(e.at)})}),(0,G.jsxs)(`td`,{children:[e.manager,` `,(0,G.jsxs)(`span`,{className:`rt-muted`,children:[`· `,e.total.toLocaleString()]})]}),(0,G.jsx)(`td`,{className:`rt-scan-why`,children:(0,G.jsx)(VL,{fact:e})}),(0,G.jsx)(`td`,{title:e.certainty===`corroborated`?`Read from the package manager's own records in the sandbox, and a package registry was reached about then.`:`Read from the package manager's own records in the sandbox, which the agent can write. No registry connection was seen with it.`,children:e.certainty===`corroborated`?`records, registry reached`:`records only`}),(0,G.jsx)(zL,{fact:e,step:t(e.call_id),onOpenCall:n})]},e.id))})]})}):(0,G.jsx)(`p`,{className:`rt-empty`,children:`No package manager left anything new.`}),(0,G.jsxs)(`div`,{className:`rt-list-head`,children:[(0,G.jsx)(`span`,{children:`FILES, AS THE KERNEL SAW THEM`}),(0,G.jsx)(`small`,{children:`files marked Report or Restrict, and new sensitive ones`})]}),r.files.length?(0,G.jsx)(`div`,{className:`rt-table-wrap`,children:(0,G.jsxs)(`table`,{className:`rt-table rt-scan`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{children:`When`}),(0,G.jsx)(`th`,{children:`File`}),(0,G.jsx)(`th`,{children:`What happened`}),(0,G.jsx)(`th`,{children:`How sure`}),(0,G.jsx)(`th`,{children:`Program`}),(0,G.jsx)(`th`,{children:`Step`})]})}),(0,G.jsx)(`tbody`,{children:r.files.map(e=>(0,G.jsxs)(`tr`,{className:e.effect===`attempted`?`rt-fact-refused`:void 0,title:RL(e),children:[(0,G.jsx)(`td`,{children:(0,G.jsx)(`time`,{children:FL(e.at)})}),(0,G.jsxs)(`td`,{children:[e.path?(0,G.jsx)(`code`,{children:e.path}):(0,G.jsx)(`span`,{className:`rt-muted`,title:`gVisor reports this call by number, without its path.`,children:`file not reported`}),e.guard&&(0,G.jsx)(`span`,{className:`rt-flag`,children:e.guard})]}),(0,G.jsxs)(`td`,{children:[jL[e.effect]??e.effect,e.effect===`attempted`&&e.intent?`: ${ML[e.intent]??e.intent}`:``,e.to?(0,G.jsxs)(G.Fragment,{children:[` to `,(0,G.jsx)(`code`,{children:e.to})]}):null,IL(e.count),e.basis?.errno&&(0,G.jsxs)(`span`,{className:`rt-muted`,children:[` (`,e.basis.errno,`)`]})]}),(0,G.jsx)(`td`,{title:NL[e.certainty]?.[1],children:NL[e.certainty]?.[0]??e.certainty}),(0,G.jsx)(zL,{fact:e,step:t(e.call_id),onOpenCall:n})]},e.id))})]})}):(0,G.jsx)(`p`,{className:`rt-empty`,children:`Nothing happened to a file marked Report or Restrict.`}),r.bulk.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`rt-list-head`,children:[(0,G.jsx)(`span`,{children:`BULK FILE ACCESS`}),(0,G.jsx)(`small`,{children:`counted, not kept`})]}),(0,G.jsx)(`ul`,{className:`rt-foot rt-bulk`,children:r.bulk.slice(0,20).map(e=>{let r=t(e.call_id);return(0,G.jsxs)(`li`,{children:[FL(e.at),`: `,e.process??`a step`,` opened `,e.opens.toLocaleString(),` files (`,Object.entries(e.folders).map(([e,t])=>`${t.toLocaleString()} under ${e}`).join(`, `),`)`,` `,r&&(0,G.jsxs)(`button`,{type:`button`,className:`link-button`,onClick:()=>n(r.trace,r.call),children:[`Open the step `,(0,G.jsx)(P,{size:11})]})]},e.id)})})]}),r.identity.length>0&&(0,G.jsxs)(`p`,{className:`rt-problem`,children:[`A program asked to change its user or group id: `,r.identity.map(e=>`${e.basis?.syscall??`setid`}(${e.ids.join(`, `)}) by ${e.process??`a process`}, ${e.effect===`changed`?`allowed`:`refused${e.basis?.errno?` (${e.basis.errno})`:``}`}`).join(`; `),`.`]}),(0,G.jsx)(`p`,{className:`rt-foot`,children:`Seen by the kernel layer of the sandbox and its host, not reported by the agent. An address is what a program connected to; the name beside it is the lookup that answered with it. HTTPS contents are not read. A file that was read is one opened for reading. A file not marked Report or Restrict is counted, not listed.`})]})}function UL(e){let t=new Map,n=new Map,r=(e,r)=>{if(e.call_id&&t.set(e.call_id,[...t.get(e.call_id)??[],r]),e.pid!=null){let t=`${e.pid}:${e.process_start_ns??``}`;n.set(t,[...n.get(t)??[],r])}};if(!e)return{byCall:t,byProcess:n};for(let t of e.network){let e=!!t.outcomes.refused_by_policy;r(t,{key:t.id,fail:e,text:`${e?`refused `:t.effect===`listen`?`listens on `:`→ `}${t.host??t.ip}:${t.port}${IL(t.count)}`,title:Object.entries(t.outcomes).map(([e,t])=>`${PL[e]?.[0]??e}${IL(t)}`).join(`, `)})}for(let t of e.packages)r(t,{key:t.id,text:`${t.manager}: ${t.total.toLocaleString()} package${t.total===1?``:`s`}`,title:t.packages.slice(0,20).map(e=>`${e.name}@${e.version}`).join(`, `)});for(let t of e.files)t.path&&r(t,{key:t.id,fail:t.effect===`attempted`,text:`${t.path.split(`/`).pop()} ${(jL[t.effect]??t.effect).toLowerCase()}`,title:`${t.path}\n${NL[t.certainty]?.[1]??``}\n${RL(t)}`});return{byCall:t,byProcess:n}}var WL=200,GL={untested:[`no test`,`No test file is named after this file.`],unreferenced:[`not imported`,`No other file imports this one, and nothing was found that starts it.`],large:[`large`,`Over 800 lines.`],created:[`new`,`Appeared after the initial scan, so it is scored by its path alone.`]},KL={watched_changed:`Watched file changed`,restricted_changed:`Restricted file changed`,new_sensitive:`Sensitive file created`,restricted_blocked:`Change to a restricted file blocked`,restricted_read:`Restricted file read`,restricted_named:`Restricted file named in a command`,watched_read:`Watched file read`,network_refused:`Connection to a private address refused`},qL={restricted_blocked:`The agent tried to change this file and was refused.`,restricted_named:`The command mentions this file. What it does is not known: it may only read it.`,network_refused:`The sandbox firewall rejects private addresses: the VM's own services and the cloud metadata server are there.`},JL={A:`added`,M:`edited`,D:`deleted`,R:`renamed`,T:`type changed`},YL={kernel:`Seen by the sandbox's kernel layer and its host: every program, whatever started it, and nothing the agent could write.`,hook:`Reported by the sandbox's Claude Code hook: the agent's own tool said so.`};function XL(e){let t=[];for(let n of e){let e=n.at??n.created,r=t.find(t=>t.path===n.path&&t.kind===n.kind&&!t.sources.includes(n.source)&&(t.call_id&&n.call_id?t.call_id===n.call_id:Math.abs((t.at??t.created)-e)<=20));if(!r){t.push({...n,ids:[n.id],sources:[n.source],tool:n.source===`hook`?n.tool:null,by:n.source===`kernel`?n.tool:null});continue}r.ids.push(n.id),r.sources.push(n.source),r.seen=r.seen&&n.seen,r.call_id??=n.call_id,n.source===`kernel`?r.by=n.tool:(r.tool=n.tool,r.status??=n.status,r.added??=n.added,r.removed??=n.removed,r.commit??=n.commit)}return t}var ZL=e=>new Date(typeof e==`number`?e*1e3:e).toLocaleString(void 0,{day:`numeric`,month:`short`,hour:`numeric`,minute:`2-digit`});function QL({level:e,title:t}){return(0,G.jsx)(`span`,{className:`rt-level level-${e}`,title:t??`Level ${e} of 5: ${_L[e]}`,children:e})}function $L({onSelect:e}){let[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(null);return(0,_.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await x().fetch(`/raytace/sandboxes`,{cache:`no-store`}),r=await t.json();if(!t.ok)throw Error(r.error||`Sandbox list unavailable`);e||n((r.sandboxes??[]).filter(e=>e.status!==`deleted`))}catch(t){e||i(t instanceof Error?t.message:`Sandbox list unavailable`)}})(),()=>{e=!0}},[]),r?(0,G.jsx)(`p`,{className:`rt-empty`,children:r}):t?t.length?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`rt-list-head`,children:(0,G.jsx)(`span`,{children:`CHOOSE A SANDBOX`})}),(0,G.jsx)(`ol`,{className:`rt-prompts`,children:t.map(t=>(0,G.jsx)(`li`,{className:`rt-prompt`,children:(0,G.jsxs)(`button`,{type:`button`,className:`rt-prompt-row`,onClick:()=>e(t.id),children:[(0,G.jsx)(`time`,{children:ZL(t.created)}),(0,G.jsx)(`strong`,{children:t.name}),(0,G.jsxs)(`small`,{children:[t.id.slice(0,12),`…`]})]})},t.id))})]}):(0,G.jsx)(`p`,{className:`rt-empty`,children:`No sandboxes yet. A project is scanned when its sandbox is created.`}):(0,G.jsx)(rp,{label:`Loading the initial scan…`})}function eR({box:e,traces:t,onSelect:n,onOpenCall:r,onAlertsSeen:i}){let[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(null),[d,f]=(0,_.useState)(`files`),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(``),[b,x]=(0,_.useState)(()=>new Set([5,4,3,2,1])),[S,C]=(0,_.useState)(WL),[w,T]=(0,_.useState)([]),[E,D]=(0,_.useState)(null);(0,_.useEffect)(()=>{let e=!1;return TL().then(t=>{e||D(t)}),()=>{e=!0}},[]),(0,_.useEffect)(()=>{if(o(null),c(null),u(null),C(WL),x(new Set([5,4,3,2,1])),!e)return;let t=!1;return xL(e).then(e=>{t||o(e)},e=>{t||c(e.message)}),()=>{t=!0}},[e]),(0,_.useEffect)(()=>{if(T([]),!e)return;let t=!1,n,r=async()=>{try{let n=await wL(e);t||T(n.alerts)}catch{}t||(n=setTimeout(r,1e4))};return r(),()=>{t=!0,clearTimeout(n)}},[e]);let O=(0,_.useCallback)(async(t,n)=>{u(null),o(e=>e&&{...e,files:e.files.map(e=>e.path===t.path?{...e,...n}:e)});try{let n=await SL(e,[t]),r=new Map(n.files.map(e=>[e.path,e]));o(e=>e&&{...e,guardrails:n.guardrails??e.guardrails,files:e.files.map(e=>r.get(e.path)??e)}),AL(e)}catch(t){u(t instanceof Error?t.message:`That change could not be saved.`),xL(e).then(o,()=>void 0)}},[e]),k=(0,_.useMemo)(()=>a?.files??[],[a]),A=(0,_.useMemo)(()=>{let e=[0,0,0,0,0,0],t=0,n=0;for(let r of k)e[r.level]+=1,r.restricted&&(t+=1),r.notify&&(n+=1);return{byLevel:e,restricted:t,notify:n}},[k]),j=(0,_.useMemo)(()=>{let e=v.trim().toLowerCase();return k.filter(t=>(p==null||t.level===p)&&(h!==`restricted`||t.restricted)&&(h!==`notify`||t.notify)&&(!e||t.path.toLowerCase().includes(e))).sort((e,t)=>t.level-e.level||(t.reach?.score??t.reach?.dependents??0)-(e.reach?.score??e.reach?.dependents??0)||(t.reach?.dependents??0)-(e.reach?.dependents??0)||e.path.localeCompare(t.path))},[k,p,h,v]),M=!!(v.trim()||p!=null||h),N=j.slice(0,S),L=[5,4,3,2,1].map(e=>({level:e,total:j.filter(t=>t.level===e).length,files:N.filter(t=>t.level===e),closed:!M&&b.has(e)})).filter(e=>e.total>0),R=e=>{let t=(e.hazard?.level??0)>=4,n=(e.reach?.level??0)>=4;return t&&n?`Sensitive · Widely used`:t?`Sensitive`:n?`Widely used`:null},z=(0,_.useMemo)(()=>new Set(a?.guardrails?.read_only??[]),[a]),H=w.filter(e=>!e.seen),U=(0,_.useMemo)(()=>XL(w),[w]),ee=n=>{if(!n)return null;let r=t.find(t=>t.sandboxId===e&&!t.forkId&&t.callVerifications?.some(e=>e.call_id===n));return r?{trace:r.id,call:n}:null},W=async e=>{D(e),u(null);try{await EL(e)}catch(t){D(!e),u(t instanceof Error?t.message:`That setting could not be saved.`)}},te=async e=>{T(t=>t.map(t=>e.includes(t.id)?{...t,seen:!0}:t));try{await DL(e)}catch{}i()},ne=a?.scan;return(0,G.jsxs)(`section`,{className:`rt-view`,children:[(0,G.jsxs)(`header`,{className:`rt-view-head`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`eyebrow`,children:`INITIAL SCAN`}),(0,G.jsx)(`h1`,{children:a?.name?`How risky each file of ${a.name} is to change`:`How risky each file is to change`})]}),e&&(0,G.jsx)(`div`,{className:`rt-actions`,children:(0,G.jsx)(`button`,{type:`button`,className:`rt-button`,onClick:()=>n(``),children:`Another sandbox`})})]}),!e&&(0,G.jsx)($L,{onSelect:n}),e&&s&&(0,G.jsx)(`p`,{role:`alert`,className:`verify-error`,children:s}),e&&!s&&!a&&(0,G.jsx)(rp,{label:`Loading the initial scan…`}),a&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`dl`,{className:`rt-stats`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Files`}),(0,G.jsx)(`dd`,{children:k.length.toLocaleString()})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Level`}),(0,G.jsx)(`dd`,{className:`rt-sev-counts`,children:[5,4,3,2,1].map(e=>(0,G.jsxs)(`button`,{type:`button`,"aria-pressed":p===e,className:`rt-level level-${e}${p===e?` rt-sev-on`:``}${p!=null&&p!==e?` rt-sev-off`:``}`,title:p===e?`Show every level`:`Show only level ${e} (${vL[e].toLowerCase()})`,onClick:()=>{m(t=>t===e?null:e),C(WL)},children:[e,` · `,A.byLevel[e]]},e))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Reported when changed`}),(0,G.jsx)(`dd`,{children:(0,G.jsxs)(`button`,{type:`button`,className:`rt-pick${h===`notify`?` on`:``}`,"aria-pressed":h===`notify`,onClick:()=>{g(e=>e===`notify`?null:`notify`),C(WL)},children:[(0,G.jsx)(I,{size:13}),` `,A.notify]})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Restricted`}),(0,G.jsx)(`dd`,{children:(0,G.jsxs)(`button`,{type:`button`,className:`rt-pick${h===`restricted`?` on`:``}`,"aria-pressed":h===`restricted`,onClick:()=>{g(e=>e===`restricted`?null:`restricted`),C(WL)},children:[(0,G.jsx)(se,{size:13}),` `,A.restricted]})})]})]}),(0,G.jsxs)(`div`,{className:`rt-tabs`,role:`tablist`,children:[(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":d===`files`,className:d===`files`?`on`:``,onClick:()=>f(`files`),children:`Files`}),(0,G.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":d===`alerts`,className:d===`alerts`?`on`:``,onClick:()=>f(`alerts`),children:[`Alerts`,H.length>0&&(0,G.jsx)(`span`,{className:`rt-count`,children:H.length})]}),(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":d===`activity`,className:d===`activity`?`on`:``,onClick:()=>f(`activity`),children:`Activity`})]}),l&&(0,G.jsx)(`p`,{role:`alert`,className:`rt-problem`,children:l}),d===`files`&&(0,G.jsxs)(G.Fragment,{children:[ne&&`error`in ne&&(0,G.jsxs)(`p`,{className:`rt-problem`,children:[ne.error,`. Files the agent changes are still scored by their path.`]}),!k.length&&!(ne&&`error`in ne)&&(0,G.jsx)(`p`,{className:`rt-empty`,children:`This sandbox was created before RayTrace scanned projects, so it has no scan.`}),k.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`input`,{className:`rt-search`,type:`search`,value:v,placeholder:`Filter by path`,"aria-label":`Filter files by path`,onChange:e=>{y(e.target.value),C(WL)}}),(0,G.jsx)(`div`,{className:`rt-table-wrap`,children:(0,G.jsxs)(`table`,{className:`rt-table rt-scan`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{children:`Level`}),(0,G.jsx)(`th`,{children:`File`}),(0,G.jsx)(`th`,{children:`Why`}),(0,G.jsx)(`th`,{title:`Report it when the agent changes this file`,children:`Report`}),(0,G.jsx)(`th`,{title:`The agent may not change this file`,children:`Restrict`})]})}),L.map(e=>(0,G.jsxs)(`tbody`,{children:[(0,G.jsx)(`tr`,{className:`rt-scan-group`,children:(0,G.jsx)(`td`,{colSpan:5,children:(0,G.jsxs)(`button`,{type:`button`,"aria-expanded":!e.closed,onClick:()=>x(t=>{let n=new Set(t);return n.has(e.level)?n.delete(e.level):n.add(e.level),n}),children:[e.closed?(0,G.jsx)(V,{size:13}):(0,G.jsx)(B,{size:13}),(0,G.jsx)(`span`,{className:`rt-level level-${e.level}`,children:e.level}),vL[e.level],(0,G.jsxs)(`span`,{className:`rt-muted`,children:[e.total.toLocaleString(),` file`,e.total===1?``:`s`]})]})})}),!e.closed&&e.files.map(e=>(0,G.jsxs)(`tr`,{children:[(0,G.jsxs)(`td`,{className:`rt-scan-level`,children:[(0,G.jsx)(`select`,{className:`rt-level level-${e.level}`,value:e.level,"aria-label":`Level of ${e.path}`,onChange:t=>{let n=Number(t.target.value);O({path:e.path,level:n===e.scanned_level?null:n},{level:n,edited:n!==e.scanned_level,...e.notify_set?{}:{notify:n>=4}})},children:[5,4,3,2,1].map(t=>(0,G.jsxs)(`option`,{value:t,children:[t,` `,vL[t],t===e.scanned_level?` (scanned)`:``]},t))}),e.edited&&(0,G.jsx)(`button`,{type:`button`,className:`rt-undo`,title:`Back to the scanned level, ${e.scanned_level}`,"aria-label":`Put ${e.path} back to its scanned level`,onClick:()=>void O({path:e.path,level:null},{level:e.scanned_level,edited:!1,...e.notify_set?{}:{notify:e.scanned_level>=4}}),children:(0,G.jsx)(he,{size:11})})]}),(0,G.jsx)(`td`,{children:(0,G.jsx)(`code`,{children:e.path})}),(0,G.jsxs)(`td`,{className:`rt-scan-why`,children:[e.reasons.join(` · `)||(0,G.jsx)(`span`,{className:`rt-muted`,children:`Nothing imports it, and its name marks nothing`}),R(e)&&(0,G.jsx)(`span`,{className:`rt-flag rt-driver`,title:`What put this file at its level: sensitivity of the code, weighted blast radius, or both`,children:R(e)}),e.flags.map(e=>(0,G.jsx)(`span`,{className:`rt-flag`,title:GL[e]?.[1],children:GL[e]?.[0]??e},e)),e.restricted&&(0,G.jsx)(`small`,{className:`rt-scan-lock`,children:z.has(e.path)?`Read-only in the sandbox, for every tool.`:`Claude Code edits are refused now. Read-only for every tool after the sandbox is next stopped and started.`})]}),(0,G.jsx)(`td`,{children:(0,G.jsx)(`input`,{type:`checkbox`,checked:e.notify,"aria-label":`Report changes to ${e.path}`,onChange:t=>void O({path:e.path,notify:t.target.checked},{notify:t.target.checked,notify_set:!0})})}),(0,G.jsx)(`td`,{children:(0,G.jsx)(`input`,{type:`checkbox`,checked:e.restricted,"aria-label":`Restrict ${e.path}`,onChange:t=>void O({path:e.path,restricted:t.target.checked},{restricted:t.target.checked})})})]},e.path))]},e.level))]})}),!j.length&&(0,G.jsx)(`p`,{className:`rt-empty`,children:`No files match.`}),j.length>S&&(0,G.jsxs)(`p`,{className:`rt-foot`,children:[(0,G.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>C(e=>e+WL),children:[`Show `,Math.min(WL,j.length-S),` more`]}),` `,S.toLocaleString(),` of `,j.length.toLocaleString(),` shown`]}),ne&&!(`error`in ne)&&(0,G.jsxs)(`p`,{className:`rt-foot`,children:[ne.version===`scan-v2`?`Level is the higher of weighted blast radius and sensitivity. Direct and startup dependents count most, then each extra hop decays; reach is banded by percentile in this project, while secret, destructive, credential, payment and deploy code can be sensitive at any reach.`:`Level is the higher of how much of the project imports a file and what kind of file it is.`,` `,ne.edges.toLocaleString(),` imports followed in JavaScript, TypeScript and Python; other files are scored by path. Secrets left out of the upload are scored when the agent creates them.`]})]})]}),d===`alerts`&&(0,G.jsxs)(G.Fragment,{children:[E!==null&&(0,G.jsxs)(`label`,{className:`rt-foot rt-email`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:E,onChange:e=>void W(e.target.checked)}),` Email me about alerts`,(0,G.jsx)(`span`,{className:`rt-muted`,children:` · batched, at most one message every 30 seconds per project`})]}),!w.length&&(0,G.jsx)(`p`,{className:`rt-empty`,children:`No alerts. One is raised when the agent changes, tries to change or reads a file marked Report or Restrict, creates a sensitive one, or tries to reach a private address.`}),w.length>0&&(0,G.jsxs)(G.Fragment,{children:[H.length>0&&(0,G.jsx)(`p`,{className:`rt-foot`,children:(0,G.jsx)(`button`,{type:`button`,className:`rt-button`,onClick:()=>void te(H.map(e=>e.id)),children:`Mark all seen`})}),(0,G.jsx)(`div`,{className:`rt-table-wrap`,children:(0,G.jsxs)(`table`,{className:`rt-table rt-scan`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{children:`When`}),(0,G.jsx)(`th`,{children:`Level`}),(0,G.jsx)(`th`,{children:`File or destination`}),(0,G.jsx)(`th`,{children:`What happened`}),(0,G.jsx)(`th`,{title:`Who saw it: the sandbox's kernel layer, or the agent's own tool through the sandbox's hook`,children:`Seen by`}),(0,G.jsx)(`th`,{title:`The agent's tool, and the program the kernel saw do it`,children:`Tool`}),(0,G.jsx)(`th`,{children:`Step`})]})}),(0,G.jsx)(`tbody`,{children:U.map(e=>{let t=ee(e.call_id);return(0,G.jsxs)(`tr`,{className:`${e.seen?`rt-seen`:``}${e.kind===`restricted_blocked`||e.kind===`network_refused`?` rt-alert-blocked`:``}`,children:[(0,G.jsx)(`td`,{children:(0,G.jsx)(`time`,{title:e.at?`Seen at ${new Date(e.at*1e3).toISOString()}`:void 0,children:ZL(e.at??e.created)})}),(0,G.jsx)(`td`,{children:(0,G.jsx)(QL,{level:e.level})}),(0,G.jsx)(`td`,{children:(0,G.jsx)(`code`,{children:e.path})}),(0,G.jsxs)(`td`,{title:qL[e.kind],children:[(e.kind===`restricted_blocked`||e.kind===`network_refused`)&&(0,G.jsx)(F,{size:12,"aria-hidden":`true`}),` `,KL[e.kind]??e.kind,e.status&&JL[e.status]?(0,G.jsxs)(`span`,{className:`rt-muted`,children:[` · `,JL[e.status]]}):null,e.added!=null&&(0,G.jsxs)(`span`,{className:`rt-muted`,children:[` · +`,e.added,` −`,e.removed??0]})]}),(0,G.jsx)(`td`,{children:[...e.sources].sort().reverse().map(e=>(0,G.jsx)(`span`,{className:`rt-flag rt-source-${e}`,title:YL[e],children:e},e))}),(0,G.jsx)(`td`,{children:e.tool||e.by?(0,G.jsxs)(G.Fragment,{children:[e.tool,e.tool&&e.by?` · `:``,e.by&&(0,G.jsx)(`span`,{title:`The program the kernel saw do it`,children:e.by})]}):(0,G.jsx)(`span`,{className:`rt-muted`,children:`–`})}),(0,G.jsx)(`td`,{className:`rt-scan-open`,children:t&&(0,G.jsxs)(`button`,{type:`button`,className:`link-button`,onClick:()=>{te(e.ids),r(t.trace,t.call)},children:[`Open the step `,(0,G.jsx)(P,{size:11})]})})]},e.id)})})]})})]})]}),d===`activity`&&(0,G.jsx)(HL,{box:e,stepFor:ee,onOpenCall:r})]})]})}function tR(e){let t=e.callVerifications??[],n=new Map,r=[],i=t.flatMap(e=>e.snapshot?[e.snapshot]:[]),a=new Set;t.forEach((e,t)=>{let i=e.snapshot;if(i){for(let e of i.too_big??[])a.add(e);i.changed&&i.changes.length&&r.push({call:e,number:t+1});for(let e of i.changes){let r=n.get(e.path)??{path:e.path,status:e.status,added:0,removed:0,calls:[]};r.status=e.status,e.added==null||r.added==null?(r.added=null,r.removed=null):(r.added+=e.added,r.removed=(r.removed??0)+(e.removed??0)),r.calls.includes(t+1)||r.calls.push(t+1),n.set(e.path,r)}}});let o=[...n.values()];return{files:o,steps:r,base:i.length?i[0].parent??`4b825dc642cb6eb9a060e54bf8d69288fbee4904`:null,final:i.at(-1)?.commit??null,hasSnapshots:i.length>0,tooBig:[...a],added:o.reduce((e,t)=>e+(t.added??0),0),removed:o.reduce((e,t)=>e+(t.removed??0),0)}}function nR(e){return/CalledProcessError|Command \[|docker|snapshot failed|exec:/i.test(e)?`The sandbox holding these snapshots could not be reached to read them. Check it under Sandboxes, then try again.`:e}var rR=(e,t)=>`raytrace-${e.id.slice(0,8)}${t?`-${t.split(`/`).at(-1)}`:``}.patch`,iR=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/;function aR(e){let t={hunks:[],additions:0,deletions:0,binary:!1},n=null,r=0,i=0,a=[],o=[],s=()=>{if(n){for(let e=0;e<Math.max(a.length,o.length);e+=1)n.rows.push({oldNo:a[e]?.no??null,oldText:a[e]?.text??null,newNo:o[e]?.no??null,newText:o[e]?.text??null});a=[],o=[]}},c=String(e??``).split(`
|
|
26
|
+
`)}function zL({fact:e,step:t,onOpenCall:n}){return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`td`,{title:e.command??void 0,children:e.process??(0,G.jsx)(`span`,{className:`rt-muted`,children:`–`})}),(0,G.jsx)(`td`,{className:`rt-scan-open`,children:t&&(0,G.jsxs)(`button`,{type:`button`,className:`link-button`,onClick:()=>n(t.trace,t.call),children:[`Open the step `,(0,G.jsx)(P,{size:11})]})})]})}function BL({fact:e}){return(0,G.jsxs)(G.Fragment,{children:[Object.entries(e.outcomes).map(([e,t],n)=>(0,G.jsxs)(`span`,{title:PL[e]?.[1],className:e===`refused_by_policy`||e===`failed`?`exec-fail`:void 0,children:[n?` · `:``,PL[e]?.[0]??e,IL(t)]},e)),e.errno&&(0,G.jsxs)(`span`,{className:`rt-muted`,children:[` (`,e.errno,`)`]})]})}function VL({fact:e}){let[t,n]=(0,_.useState)(!1),r=t?e.packages:e.packages.slice(0,12);return(0,G.jsxs)(G.Fragment,{children:[r.map(e=>(0,G.jsxs)(`code`,{title:e.source,className:`rt-package`,children:[e.name,`@`,e.version]},`${e.name}@${e.version}`)),e.packages.length>r.length&&(0,G.jsxs)(`button`,{type:`button`,className:`link-button`,onClick:()=>n(!0),children:[`and `,(e.total-r.length).toLocaleString(),` more`]}),t&&e.total>e.packages.length&&(0,G.jsxs)(`span`,{className:`rt-muted`,children:[` and `,(e.total-e.packages.length).toLocaleString(),` not listed`]})]})}function HL({box:e,stepFor:t,onOpenCall:n}){let[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(null);if((0,_.useEffect)(()=>{i(null),o(null);let t=!1,n,r=async()=>{try{let n=await CL(e);t||(i(n),o(null))}catch(e){t||o(e instanceof Error?e.message:`Sandbox activity could not be loaded.`)}t||(n=setTimeout(r,1e4))};return r(),()=>{t=!0,clearTimeout(n)}},[e]),a&&!r)return(0,G.jsx)(`p`,{role:`alert`,className:`rt-problem`,children:a});if(!r)return(0,G.jsx)(rp,{label:`Loading sandbox activity…`});let s=new Set(r.network.map(e=>e.host).filter(Boolean)),c=r.lookups.filter(e=>!s.has(e.name)),l=!r.network.length&&!r.packages.length&&!r.files.length&&!r.lookups.length&&!r.bulk.length&&!r.identity.length,u=[...r.network,...r.files,...r.packages].some(e=>e.coverage===`gaps`);return l?(0,G.jsx)(`p`,{className:`rt-empty`,children:`Nothing recorded yet. The kernel layer of the sandbox reports every connection the agent makes, the packages it installs, and what happens to the project's files. A sandbox started before this was turned on reports once it is stopped and started again.`}):(0,G.jsxs)(G.Fragment,{children:[u&&(0,G.jsxs)(`p`,{className:`rt-problem`,children:[`Some events were lost while these were recorded, so a row marked `,(0,G.jsx)(`em`,{children:`gaps`}),` may not be all that happened.`]}),(0,G.jsxs)(`div`,{className:`rt-list-head`,children:[(0,G.jsx)(`span`,{children:`NETWORK`}),(0,G.jsxs)(`small`,{children:[r.network.length,` destination`,r.network.length===1?``:`s`,r.more.includes(`network`)?`, newest shown`:``]})]}),r.network.length?(0,G.jsx)(`div`,{className:`rt-table-wrap`,children:(0,G.jsxs)(`table`,{className:`rt-table rt-scan`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{children:`Last`}),(0,G.jsx)(`th`,{children:`Destination`}),(0,G.jsx)(`th`,{children:`Result`}),(0,G.jsx)(`th`,{children:`Program`}),(0,G.jsx)(`th`,{children:`Step`})]})}),(0,G.jsx)(`tbody`,{children:r.network.map(e=>(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`td`,{children:(0,G.jsx)(`time`,{children:FL(e.at)})}),(0,G.jsxs)(`td`,{children:[(0,G.jsxs)(`code`,{children:[e.host??e.ip,`:`,e.port]}),e.host&&(0,G.jsxs)(`span`,{className:`rt-muted`,title:`The address${(e.addresses?.length??1)>1?`es`:``} the program connected to. The name is the lookup that answered with ${(e.addresses?.length??1)>1?`them`:`it`}.\n${(e.addresses??[e.ip]).join(`
|
|
27
|
+
`)}`,children:[` `,e.ip,(e.addresses?.length??1)>1?` and ${e.addresses.length-1} more`:``]}),e.coverage===`gaps`&&(0,G.jsx)(`span`,{className:`rt-flag`,title:`Events were lost about then.`,children:`gaps`})]}),(0,G.jsx)(`td`,{children:(0,G.jsx)(BL,{fact:e})}),(0,G.jsx)(zL,{fact:e,step:t(e.call_id),onOpenCall:n})]},e.id))})]})}):(0,G.jsx)(`p`,{className:`rt-empty`,children:`No connection left the sandbox.`}),c.length>0&&(0,G.jsxs)(`p`,{className:`rt-foot`,children:[`Looked up, with no connection seen: `,c.slice(0,40).map((e,t)=>(0,G.jsxs)(`span`,{title:e.failed?`The lookup failed: ${e.failed}`:e.addresses.join(`, `),children:[t?`, `:``,(0,G.jsx)(`code`,{children:e.name}),e.failed?` (${e.failed})`:``]},e.id)),c.length>40?` and ${c.length-40} more`:``,`.`]}),(0,G.jsx)(`div`,{className:`rt-list-head`,children:(0,G.jsx)(`span`,{children:`PACKAGES INSTALLED`})}),r.packages.length?(0,G.jsx)(`div`,{className:`rt-table-wrap`,children:(0,G.jsxs)(`table`,{className:`rt-table rt-scan`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{children:`When`}),(0,G.jsx)(`th`,{children:`Manager`}),(0,G.jsx)(`th`,{children:`Packages`}),(0,G.jsx)(`th`,{children:`Basis`}),(0,G.jsx)(`th`,{children:`Program`}),(0,G.jsx)(`th`,{children:`Step`})]})}),(0,G.jsx)(`tbody`,{children:r.packages.map(e=>(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`td`,{children:(0,G.jsx)(`time`,{children:FL(e.at)})}),(0,G.jsxs)(`td`,{children:[e.manager,` `,(0,G.jsxs)(`span`,{className:`rt-muted`,children:[`· `,e.total.toLocaleString()]})]}),(0,G.jsx)(`td`,{className:`rt-scan-why`,children:(0,G.jsx)(VL,{fact:e})}),(0,G.jsx)(`td`,{title:e.certainty===`corroborated`?`Read from the package manager's own records in the sandbox, and a package registry was reached about then.`:`Read from the package manager's own records in the sandbox, which the agent can write. No registry connection was seen with it.`,children:e.certainty===`corroborated`?`records, registry reached`:`records only`}),(0,G.jsx)(zL,{fact:e,step:t(e.call_id),onOpenCall:n})]},e.id))})]})}):(0,G.jsx)(`p`,{className:`rt-empty`,children:`No package manager left anything new.`}),(0,G.jsxs)(`div`,{className:`rt-list-head`,children:[(0,G.jsx)(`span`,{children:`FILES, AS THE KERNEL SAW THEM`}),(0,G.jsx)(`small`,{children:`every project file; reads only of sensitive, Report and Restrict files`})]}),r.files.length?(0,G.jsx)(`div`,{className:`rt-table-wrap`,children:(0,G.jsxs)(`table`,{className:`rt-table rt-scan`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{children:`When`}),(0,G.jsx)(`th`,{children:`File`}),(0,G.jsx)(`th`,{children:`What happened`}),(0,G.jsx)(`th`,{children:`How sure`}),(0,G.jsx)(`th`,{children:`Program`}),(0,G.jsx)(`th`,{children:`Step`})]})}),(0,G.jsx)(`tbody`,{children:r.files.map(e=>(0,G.jsxs)(`tr`,{className:e.effect===`attempted`?`rt-fact-refused`:void 0,title:RL(e),children:[(0,G.jsx)(`td`,{children:(0,G.jsx)(`time`,{children:FL(e.at)})}),(0,G.jsxs)(`td`,{children:[e.path?(0,G.jsx)(`code`,{children:e.path}):(0,G.jsx)(`span`,{className:`rt-muted`,title:`gVisor reports this call by number, without its path.`,children:`file not reported`}),e.guard&&e.guard!==`project`&&(0,G.jsx)(`span`,{className:`rt-flag`,children:e.guard})]}),(0,G.jsxs)(`td`,{children:[jL[e.effect]??e.effect,e.effect===`attempted`&&e.intent?`: ${ML[e.intent]??e.intent}`:``,e.to?(0,G.jsxs)(G.Fragment,{children:[` to `,(0,G.jsx)(`code`,{children:e.to})]}):null,IL(e.count),e.basis?.errno&&(0,G.jsxs)(`span`,{className:`rt-muted`,children:[` (`,e.basis.errno,`)`]})]}),(0,G.jsx)(`td`,{title:NL[e.certainty]?.[1],children:NL[e.certainty]?.[0]??e.certainty}),(0,G.jsx)(zL,{fact:e,step:t(e.call_id),onOpenCall:n})]},e.id))})]})}):(0,G.jsx)(`p`,{className:`rt-empty`,children:`Nothing happened to a project file.`}),r.bulk.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`rt-list-head`,children:[(0,G.jsx)(`span`,{children:`BULK FILE ACCESS`}),(0,G.jsx)(`small`,{children:`counted, not kept`})]}),(0,G.jsx)(`ul`,{className:`rt-foot rt-bulk`,children:r.bulk.slice(0,20).map(e=>{let r=t(e.call_id);return(0,G.jsxs)(`li`,{children:[FL(e.at),`: `,e.process??`a step`,` opened `,e.opens.toLocaleString(),` files (`,Object.entries(e.folders).map(([e,t])=>`${t.toLocaleString()} under ${e}`).join(`, `),`)`,` `,r&&(0,G.jsxs)(`button`,{type:`button`,className:`link-button`,onClick:()=>n(r.trace,r.call),children:[`Open the step `,(0,G.jsx)(P,{size:11})]})]},e.id)})})]}),r.identity.length>0&&(0,G.jsxs)(`p`,{className:`rt-problem`,children:[`A program asked to change its user or group id: `,r.identity.map(e=>`${e.basis?.syscall??`setid`}(${e.ids.join(`, `)}) by ${e.process??`a process`}, ${e.effect===`changed`?`allowed`:`refused${e.basis?.errno?` (${e.basis.errno})`:``}`}`).join(`; `),`.`]}),(0,G.jsx)(`p`,{className:`rt-foot`,children:`Seen by the kernel layer of the sandbox and its host, not reported by the agent. An address is what a program connected to; the name beside it is the lookup that answered with it. HTTPS contents are not read. A file that was read is one opened for reading. Reads of ordinary project files are counted, not listed, and so is everything under folders like node_modules.`})]})}function UL(e){let t=new Map,n=new Map,r=(e,r)=>{if(e.call_id&&t.set(e.call_id,[...t.get(e.call_id)??[],r]),e.pid!=null){let t=`${e.pid}:${e.process_start_ns??``}`;n.set(t,[...n.get(t)??[],r])}};if(!e)return{byCall:t,byProcess:n};for(let t of e.network){let e=!!t.outcomes.refused_by_policy;r(t,{key:t.id,fail:e,text:`${e?`refused `:t.effect===`listen`?`listens on `:`→ `}${t.host??t.ip}:${t.port}${IL(t.count)}`,title:Object.entries(t.outcomes).map(([e,t])=>`${PL[e]?.[0]??e}${IL(t)}`).join(`, `)})}for(let t of e.packages)r(t,{key:t.id,text:`${t.manager}: ${t.total.toLocaleString()} package${t.total===1?``:`s`}`,title:t.packages.slice(0,20).map(e=>`${e.name}@${e.version}`).join(`, `)});for(let t of e.files)t.path&&r(t,{key:t.id,fail:t.effect===`attempted`,text:`${t.path.split(`/`).pop()} ${(jL[t.effect]??t.effect).toLowerCase()}`,title:`${t.path}\n${NL[t.certainty]?.[1]??``}\n${RL(t)}`});return{byCall:t,byProcess:n}}var WL=200,GL={untested:[`no test`,`No test file is named after this file.`],unreferenced:[`not imported`,`No other file imports this one, and nothing was found that starts it.`],large:[`large`,`Over 800 lines.`],created:[`new`,`Appeared after the initial scan, so it is scored by its path alone.`]},KL={watched_changed:`Watched file changed`,restricted_changed:`Restricted file changed`,new_sensitive:`Sensitive file created`,restricted_blocked:`Change to a restricted file blocked`,restricted_read:`Restricted file read`,restricted_named:`Restricted file named in a command`,watched_read:`Watched file read`,network_refused:`Connection to a private address refused`},qL={restricted_blocked:`The agent tried to change this file and was refused.`,restricted_named:`The command mentions this file. What it does is not known: it may only read it.`,network_refused:`The sandbox firewall rejects private addresses: the VM's own services and the cloud metadata server are there.`},JL={A:`added`,M:`edited`,D:`deleted`,R:`renamed`,T:`type changed`},YL={kernel:`Seen by the sandbox's kernel layer and its host: every program, whatever started it, and nothing the agent could write.`,hook:`Reported by the sandbox's Claude Code hook: the agent's own tool said so.`};function XL(e){let t=[];for(let n of e){let e=n.at??n.created,r=t.find(t=>t.path===n.path&&t.kind===n.kind&&!t.sources.includes(n.source)&&(t.call_id&&n.call_id?t.call_id===n.call_id:Math.abs((t.at??t.created)-e)<=20));if(!r){t.push({...n,ids:[n.id],sources:[n.source],tool:n.source===`hook`?n.tool:null,by:n.source===`kernel`?n.tool:null});continue}r.ids.push(n.id),r.sources.push(n.source),r.seen=r.seen&&n.seen,r.call_id??=n.call_id,n.source===`kernel`?r.by=n.tool:(r.tool=n.tool,r.status??=n.status,r.added??=n.added,r.removed??=n.removed,r.commit??=n.commit)}return t}var ZL=e=>new Date(typeof e==`number`?e*1e3:e).toLocaleString(void 0,{day:`numeric`,month:`short`,hour:`numeric`,minute:`2-digit`});function QL({level:e,title:t}){return(0,G.jsx)(`span`,{className:`rt-level level-${e}`,title:t??`Level ${e} of 5: ${_L[e]}`,children:e})}function $L({onSelect:e}){let[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(null);return(0,_.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await x().fetch(`/raytace/sandboxes`,{cache:`no-store`}),r=await t.json();if(!t.ok)throw Error(r.error||`Sandbox list unavailable`);e||n((r.sandboxes??[]).filter(e=>e.status!==`deleted`))}catch(t){e||i(t instanceof Error?t.message:`Sandbox list unavailable`)}})(),()=>{e=!0}},[]),r?(0,G.jsx)(`p`,{className:`rt-empty`,children:r}):t?t.length?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`rt-list-head`,children:(0,G.jsx)(`span`,{children:`CHOOSE A SANDBOX`})}),(0,G.jsx)(`ol`,{className:`rt-prompts`,children:t.map(t=>(0,G.jsx)(`li`,{className:`rt-prompt`,children:(0,G.jsxs)(`button`,{type:`button`,className:`rt-prompt-row`,onClick:()=>e(t.id),children:[(0,G.jsx)(`time`,{children:ZL(t.created)}),(0,G.jsx)(`strong`,{children:t.name}),(0,G.jsxs)(`small`,{children:[t.id.slice(0,12),`…`]})]})},t.id))})]}):(0,G.jsx)(`p`,{className:`rt-empty`,children:`No sandboxes yet. A project is scanned when its sandbox is created.`}):(0,G.jsx)(rp,{label:`Loading the initial scan…`})}function eR({box:e,traces:t,onSelect:n,onOpenCall:r,onAlertsSeen:i}){let[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(null),[d,f]=(0,_.useState)(`files`),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(``),[b,x]=(0,_.useState)(()=>new Set([5,4,3,2,1])),[S,C]=(0,_.useState)(WL),[w,T]=(0,_.useState)([]),[E,D]=(0,_.useState)(null);(0,_.useEffect)(()=>{let e=!1;return TL().then(t=>{e||D(t)}),()=>{e=!0}},[]),(0,_.useEffect)(()=>{if(o(null),c(null),u(null),C(WL),x(new Set([5,4,3,2,1])),!e)return;let t=!1;return xL(e).then(e=>{t||o(e)},e=>{t||c(e.message)}),()=>{t=!0}},[e]),(0,_.useEffect)(()=>{if(T([]),!e)return;let t=!1,n,r=async()=>{try{let n=await wL(e);t||T(n.alerts)}catch{}t||(n=setTimeout(r,1e4))};return r(),()=>{t=!0,clearTimeout(n)}},[e]);let O=(0,_.useCallback)(async(t,n)=>{u(null),o(e=>e&&{...e,files:e.files.map(e=>e.path===t.path?{...e,...n}:e)});try{let n=await SL(e,[t]),r=new Map(n.files.map(e=>[e.path,e]));o(e=>e&&{...e,guardrails:n.guardrails??e.guardrails,files:e.files.map(e=>r.get(e.path)??e)}),AL(e)}catch(t){u(t instanceof Error?t.message:`That change could not be saved.`),xL(e).then(o,()=>void 0)}},[e]),k=(0,_.useMemo)(()=>a?.files??[],[a]),A=(0,_.useMemo)(()=>{let e=[0,0,0,0,0,0],t=0,n=0;for(let r of k)e[r.level]+=1,r.restricted&&(t+=1),r.notify&&(n+=1);return{byLevel:e,restricted:t,notify:n}},[k]),j=(0,_.useMemo)(()=>{let e=v.trim().toLowerCase();return k.filter(t=>(p==null||t.level===p)&&(h!==`restricted`||t.restricted)&&(h!==`notify`||t.notify)&&(!e||t.path.toLowerCase().includes(e))).sort((e,t)=>t.level-e.level||(t.reach?.score??t.reach?.dependents??0)-(e.reach?.score??e.reach?.dependents??0)||(t.reach?.dependents??0)-(e.reach?.dependents??0)||e.path.localeCompare(t.path))},[k,p,h,v]),M=!!(v.trim()||p!=null||h),N=j.slice(0,S),L=[5,4,3,2,1].map(e=>({level:e,total:j.filter(t=>t.level===e).length,files:N.filter(t=>t.level===e),closed:!M&&b.has(e)})).filter(e=>e.total>0),R=e=>{let t=(e.hazard?.level??0)>=4,n=(e.reach?.level??0)>=4;return t&&n?`Sensitive · Widely used`:t?`Sensitive`:n?`Widely used`:null},z=(0,_.useMemo)(()=>new Set(a?.guardrails?.read_only??[]),[a]),H=w.filter(e=>!e.seen),U=(0,_.useMemo)(()=>XL(w),[w]),ee=n=>{if(!n)return null;let r=t.find(t=>t.sandboxId===e&&!t.forkId&&t.callVerifications?.some(e=>e.call_id===n));return r?{trace:r.id,call:n}:null},W=async e=>{D(e),u(null);try{await EL(e)}catch(t){D(!e),u(t instanceof Error?t.message:`That setting could not be saved.`)}},te=async e=>{T(t=>t.map(t=>e.includes(t.id)?{...t,seen:!0}:t));try{await DL(e)}catch{}i()},ne=a?.scan;return(0,G.jsxs)(`section`,{className:`rt-view`,children:[(0,G.jsxs)(`header`,{className:`rt-view-head`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`eyebrow`,children:`INITIAL SCAN`}),(0,G.jsx)(`h1`,{children:a?.name?`How risky each file of ${a.name} is to change`:`How risky each file is to change`})]}),e&&(0,G.jsx)(`div`,{className:`rt-actions`,children:(0,G.jsx)(`button`,{type:`button`,className:`rt-button`,onClick:()=>n(``),children:`Another sandbox`})})]}),!e&&(0,G.jsx)($L,{onSelect:n}),e&&s&&(0,G.jsx)(`p`,{role:`alert`,className:`verify-error`,children:s}),e&&!s&&!a&&(0,G.jsx)(rp,{label:`Loading the initial scan…`}),a&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`dl`,{className:`rt-stats`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Files`}),(0,G.jsx)(`dd`,{children:k.length.toLocaleString()})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Level`}),(0,G.jsx)(`dd`,{className:`rt-sev-counts`,children:[5,4,3,2,1].map(e=>(0,G.jsxs)(`button`,{type:`button`,"aria-pressed":p===e,className:`rt-level level-${e}${p===e?` rt-sev-on`:``}${p!=null&&p!==e?` rt-sev-off`:``}`,title:p===e?`Show every level`:`Show only level ${e} (${vL[e].toLowerCase()})`,onClick:()=>{m(t=>t===e?null:e),C(WL)},children:[e,` · `,A.byLevel[e]]},e))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Reported when changed`}),(0,G.jsx)(`dd`,{children:(0,G.jsxs)(`button`,{type:`button`,className:`rt-pick${h===`notify`?` on`:``}`,"aria-pressed":h===`notify`,onClick:()=>{g(e=>e===`notify`?null:`notify`),C(WL)},children:[(0,G.jsx)(I,{size:13}),` `,A.notify]})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Restricted`}),(0,G.jsx)(`dd`,{children:(0,G.jsxs)(`button`,{type:`button`,className:`rt-pick${h===`restricted`?` on`:``}`,"aria-pressed":h===`restricted`,onClick:()=>{g(e=>e===`restricted`?null:`restricted`),C(WL)},children:[(0,G.jsx)(se,{size:13}),` `,A.restricted]})})]})]}),(0,G.jsxs)(`div`,{className:`rt-tabs`,role:`tablist`,children:[(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":d===`files`,className:d===`files`?`on`:``,onClick:()=>f(`files`),children:`Files`}),(0,G.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":d===`alerts`,className:d===`alerts`?`on`:``,onClick:()=>f(`alerts`),children:[`Alerts`,H.length>0&&(0,G.jsx)(`span`,{className:`rt-count`,children:H.length})]}),(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":d===`activity`,className:d===`activity`?`on`:``,onClick:()=>f(`activity`),children:`Activity`})]}),l&&(0,G.jsx)(`p`,{role:`alert`,className:`rt-problem`,children:l}),d===`files`&&(0,G.jsxs)(G.Fragment,{children:[ne&&`error`in ne&&(0,G.jsxs)(`p`,{className:`rt-problem`,children:[ne.error,`. Files the agent changes are still scored by their path.`]}),!k.length&&!(ne&&`error`in ne)&&(0,G.jsx)(`p`,{className:`rt-empty`,children:`This sandbox was created before RayTrace scanned projects, so it has no scan.`}),k.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`input`,{className:`rt-search`,type:`search`,value:v,placeholder:`Filter by path`,"aria-label":`Filter files by path`,onChange:e=>{y(e.target.value),C(WL)}}),(0,G.jsx)(`div`,{className:`rt-table-wrap`,children:(0,G.jsxs)(`table`,{className:`rt-table rt-scan`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{children:`Level`}),(0,G.jsx)(`th`,{children:`File`}),(0,G.jsx)(`th`,{children:`Why`}),(0,G.jsx)(`th`,{title:`Report it when the agent changes this file`,children:`Report`}),(0,G.jsx)(`th`,{title:`The agent may not change this file`,children:`Restrict`})]})}),L.map(e=>(0,G.jsxs)(`tbody`,{children:[(0,G.jsx)(`tr`,{className:`rt-scan-group`,children:(0,G.jsx)(`td`,{colSpan:5,children:(0,G.jsxs)(`button`,{type:`button`,"aria-expanded":!e.closed,onClick:()=>x(t=>{let n=new Set(t);return n.has(e.level)?n.delete(e.level):n.add(e.level),n}),children:[e.closed?(0,G.jsx)(V,{size:13}):(0,G.jsx)(B,{size:13}),(0,G.jsx)(`span`,{className:`rt-level level-${e.level}`,children:e.level}),vL[e.level],(0,G.jsxs)(`span`,{className:`rt-muted`,children:[e.total.toLocaleString(),` file`,e.total===1?``:`s`]})]})})}),!e.closed&&e.files.map(e=>(0,G.jsxs)(`tr`,{children:[(0,G.jsxs)(`td`,{className:`rt-scan-level`,children:[(0,G.jsx)(`select`,{className:`rt-level level-${e.level}`,value:e.level,"aria-label":`Level of ${e.path}`,onChange:t=>{let n=Number(t.target.value);O({path:e.path,level:n===e.scanned_level?null:n},{level:n,edited:n!==e.scanned_level,...e.notify_set?{}:{notify:n>=4}})},children:[5,4,3,2,1].map(t=>(0,G.jsxs)(`option`,{value:t,children:[t,` `,vL[t],t===e.scanned_level?` (scanned)`:``]},t))}),e.edited&&(0,G.jsx)(`button`,{type:`button`,className:`rt-undo`,title:`Back to the scanned level, ${e.scanned_level}`,"aria-label":`Put ${e.path} back to its scanned level`,onClick:()=>void O({path:e.path,level:null},{level:e.scanned_level,edited:!1,...e.notify_set?{}:{notify:e.scanned_level>=4}}),children:(0,G.jsx)(he,{size:11})})]}),(0,G.jsx)(`td`,{children:(0,G.jsx)(`code`,{children:e.path})}),(0,G.jsxs)(`td`,{className:`rt-scan-why`,children:[e.reasons.join(` · `)||(0,G.jsx)(`span`,{className:`rt-muted`,children:`Nothing imports it, and its name marks nothing`}),R(e)&&(0,G.jsx)(`span`,{className:`rt-flag rt-driver`,title:`What put this file at its level: sensitivity of the code, weighted blast radius, or both`,children:R(e)}),e.flags.map(e=>(0,G.jsx)(`span`,{className:`rt-flag`,title:GL[e]?.[1],children:GL[e]?.[0]??e},e)),e.restricted&&(0,G.jsx)(`small`,{className:`rt-scan-lock`,children:z.has(e.path)?`Read-only in the sandbox, for every tool.`:`Claude Code edits are refused now. Read-only for every tool after the sandbox is next stopped and started.`})]}),(0,G.jsx)(`td`,{children:(0,G.jsx)(`input`,{type:`checkbox`,checked:e.notify,"aria-label":`Report changes to ${e.path}`,onChange:t=>void O({path:e.path,notify:t.target.checked},{notify:t.target.checked,notify_set:!0})})}),(0,G.jsx)(`td`,{children:(0,G.jsx)(`input`,{type:`checkbox`,checked:e.restricted,"aria-label":`Restrict ${e.path}`,onChange:t=>void O({path:e.path,restricted:t.target.checked},{restricted:t.target.checked})})})]},e.path))]},e.level))]})}),!j.length&&(0,G.jsx)(`p`,{className:`rt-empty`,children:`No files match.`}),j.length>S&&(0,G.jsxs)(`p`,{className:`rt-foot`,children:[(0,G.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>C(e=>e+WL),children:[`Show `,Math.min(WL,j.length-S),` more`]}),` `,S.toLocaleString(),` of `,j.length.toLocaleString(),` shown`]}),ne&&!(`error`in ne)&&(0,G.jsxs)(`p`,{className:`rt-foot`,children:[ne.version===`scan-v2`?`Level is the higher of weighted blast radius and sensitivity. Direct and startup dependents count most, then each extra hop decays; reach is banded by percentile in this project, while secret, destructive, credential, payment and deploy code can be sensitive at any reach.`:`Level is the higher of how much of the project imports a file and what kind of file it is.`,` `,ne.edges.toLocaleString(),` imports followed in JavaScript, TypeScript and Python; other files are scored by path. Secrets left out of the upload are scored when the agent creates them.`]})]})]}),d===`alerts`&&(0,G.jsxs)(G.Fragment,{children:[E!==null&&(0,G.jsxs)(`label`,{className:`rt-foot rt-email`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:E,onChange:e=>void W(e.target.checked)}),` Email me about alerts`,(0,G.jsx)(`span`,{className:`rt-muted`,children:` · batched, at most one message every 30 seconds per project`})]}),!w.length&&(0,G.jsx)(`p`,{className:`rt-empty`,children:`No alerts. One is raised when the agent changes, tries to change or reads a file marked Report or Restrict, creates a sensitive one, or tries to reach a private address.`}),w.length>0&&(0,G.jsxs)(G.Fragment,{children:[H.length>0&&(0,G.jsx)(`p`,{className:`rt-foot`,children:(0,G.jsx)(`button`,{type:`button`,className:`rt-button`,onClick:()=>void te(H.map(e=>e.id)),children:`Mark all seen`})}),(0,G.jsx)(`div`,{className:`rt-table-wrap`,children:(0,G.jsxs)(`table`,{className:`rt-table rt-scan`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{children:`When`}),(0,G.jsx)(`th`,{children:`Level`}),(0,G.jsx)(`th`,{children:`File or destination`}),(0,G.jsx)(`th`,{children:`What happened`}),(0,G.jsx)(`th`,{title:`Who saw it: the sandbox's kernel layer, or the agent's own tool through the sandbox's hook`,children:`Seen by`}),(0,G.jsx)(`th`,{title:`The agent's tool, and the program the kernel saw do it`,children:`Tool`}),(0,G.jsx)(`th`,{children:`Step`})]})}),(0,G.jsx)(`tbody`,{children:U.map(e=>{let t=ee(e.call_id);return(0,G.jsxs)(`tr`,{className:`${e.seen?`rt-seen`:``}${e.kind===`restricted_blocked`||e.kind===`network_refused`?` rt-alert-blocked`:``}`,children:[(0,G.jsx)(`td`,{children:(0,G.jsx)(`time`,{title:e.at?`Seen at ${new Date(e.at*1e3).toISOString()}`:void 0,children:ZL(e.at??e.created)})}),(0,G.jsx)(`td`,{children:(0,G.jsx)(QL,{level:e.level})}),(0,G.jsx)(`td`,{children:(0,G.jsx)(`code`,{children:e.path})}),(0,G.jsxs)(`td`,{title:qL[e.kind],children:[(e.kind===`restricted_blocked`||e.kind===`network_refused`)&&(0,G.jsx)(F,{size:12,"aria-hidden":`true`}),` `,KL[e.kind]??e.kind,e.status&&JL[e.status]?(0,G.jsxs)(`span`,{className:`rt-muted`,children:[` · `,JL[e.status]]}):null,e.added!=null&&(0,G.jsxs)(`span`,{className:`rt-muted`,children:[` · +`,e.added,` −`,e.removed??0]})]}),(0,G.jsx)(`td`,{children:[...e.sources].sort().reverse().map(e=>(0,G.jsx)(`span`,{className:`rt-flag rt-source-${e}`,title:YL[e],children:e},e))}),(0,G.jsx)(`td`,{children:e.tool||e.by?(0,G.jsxs)(G.Fragment,{children:[e.tool,e.tool&&e.by?` · `:``,e.by&&(0,G.jsx)(`span`,{title:`The program the kernel saw do it`,children:e.by})]}):(0,G.jsx)(`span`,{className:`rt-muted`,children:`–`})}),(0,G.jsx)(`td`,{className:`rt-scan-open`,children:t&&(0,G.jsxs)(`button`,{type:`button`,className:`link-button`,onClick:()=>{te(e.ids),r(t.trace,t.call)},children:[`Open the step `,(0,G.jsx)(P,{size:11})]})})]},e.id)})})]})})]})]}),d===`activity`&&(0,G.jsx)(HL,{box:e,stepFor:ee,onOpenCall:r})]})]})}function tR(e){let t=e.callVerifications??[],n=new Map,r=[],i=t.flatMap(e=>e.snapshot?[e.snapshot]:[]),a=new Set;t.forEach((e,t)=>{let i=e.snapshot;if(i){for(let e of i.too_big??[])a.add(e);i.changed&&i.changes.length&&r.push({call:e,number:t+1});for(let e of i.changes){let r=n.get(e.path)??{path:e.path,status:e.status,added:0,removed:0,calls:[]};r.status=e.status,e.added==null||r.added==null?(r.added=null,r.removed=null):(r.added+=e.added,r.removed=(r.removed??0)+(e.removed??0)),r.calls.includes(t+1)||r.calls.push(t+1),n.set(e.path,r)}}});let o=[...n.values()];return{files:o,steps:r,base:i.length?i[0].parent??`4b825dc642cb6eb9a060e54bf8d69288fbee4904`:null,final:i.at(-1)?.commit??null,hasSnapshots:i.length>0,tooBig:[...a],added:o.reduce((e,t)=>e+(t.added??0),0),removed:o.reduce((e,t)=>e+(t.removed??0),0)}}function nR(e){return/CalledProcessError|Command \[|docker|snapshot failed|exec:/i.test(e)?`The sandbox holding these snapshots could not be reached to read them. Check it under Sandboxes, then try again.`:e}var rR=(e,t)=>`raytrace-${e.id.slice(0,8)}${t?`-${t.split(`/`).at(-1)}`:``}.patch`,iR=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/;function aR(e){let t={hunks:[],additions:0,deletions:0,binary:!1},n=null,r=0,i=0,a=[],o=[],s=()=>{if(n){for(let e=0;e<Math.max(a.length,o.length);e+=1)n.rows.push({oldNo:a[e]?.no??null,oldText:a[e]?.text??null,newNo:o[e]?.no??null,newText:o[e]?.text??null});a=[],o=[]}},c=String(e??``).split(`
|
|
28
28
|
`);return c.forEach((e,l)=>{if(/^Binary files .* differ$/.test(e)||e===`GIT binary patch`){t.binary=!0;return}let u=iR.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 oR=e=>/^[0-9a-f]{40}$/.test(e)||e.startsWith(`refs/forks/`);async function sR(e,t,n,r){if(!oR(t)||!oR(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(nR(o.error??`HTTP ${a.status}`));return{diff:o.diff??``,truncated:!!o.truncated}}function cR(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 lR=e=>e.startsWith(`+`)&&!e.startsWith(`+++`)?`add`:e.startsWith(`-`)&&!e.startsWith(`---`)?`del`:e.startsWith(`@@`)?`hunk`:``,uR=`raytace.diff-view`;function dR(){let[e,t]=(0,_.useState)(`split`);return(0,_.useEffect)(()=>{try{localStorage.getItem(uR)===`unified`&&t(`unified`)}catch{}},[]),[e,e=>{t(e);try{localStorage.setItem(uR,e)}catch{}}]}function fR({diff:e}){let t=(0,_.useMemo)(()=>aR(e),[e]),[n,r]=dR();return t.binary?(0,G.jsx)(`p`,{className:`rt-files-note`,children:`A binary file: it changed, but there are no lines to show.`}):t.hunks.length?(0,G.jsxs)(`div`,{className:`rt-diff-wrap`,children:[(0,G.jsxs)(`div`,{className:`rt-diff-bar`,children:[(0,G.jsxs)(`span`,{children:[(0,G.jsxs)(`b`,{className:`rt-diff-add-n`,children:[`+`,t.additions]}),` `,(0,G.jsxs)(`b`,{className:`rt-diff-del-n`,children:[`−`,t.deletions]})]}),(0,G.jsxs)(`span`,{className:`rt-diff-mode`,children:[(0,G.jsx)(`button`,{type:`button`,"aria-pressed":n===`split`,className:n===`split`?`on`:``,onClick:()=>r(`split`),children:`Split`}),(0,G.jsx)(`button`,{type:`button`,"aria-pressed":n===`unified`,className:n===`unified`?`on`:``,onClick:()=>r(`unified`),children:`Unified`})]})]}),n===`unified`?(0,G.jsx)(`pre`,{className:`rt-diff`,children:e.split(`
|
|
29
29
|
`).map((e,t)=>(0,G.jsxs)(`span`,{className:lR(e),children:[e,`
|
|
30
30
|
`]},t))}):(0,G.jsx)(`div`,{className:`rt-diff-scroll`,children:(0,G.jsxs)(`table`,{className:`rt-diff-split`,children:[(0,G.jsxs)(`colgroup`,{children:[(0,G.jsx)(`col`,{className:`rt-diff-ln-col`}),(0,G.jsx)(`col`,{}),(0,G.jsx)(`col`,{className:`rt-diff-ln-col`}),(0,G.jsx)(`col`,{})]}),(0,G.jsx)(`tbody`,{children:t.hunks.map((e,t)=>(0,G.jsxs)(_.Fragment,{children:[(0,G.jsx)(`tr`,{className:`rt-diff-hunk`,children:(0,G.jsx)(`td`,{colSpan:4,children:e.header})}),e.rows.map((e,t)=>e.note?(0,G.jsx)(`tr`,{className:`rt-diff-note-row`,children:(0,G.jsx)(`td`,{colSpan:4,children:e.note})},t):(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`td`,{className:`rt-diff-ln${e.oldText!=null&&e.oldText!==e.newText?` del`:``}`,children:e.oldNo??``}),(0,G.jsx)(`td`,{className:`rt-diff-code${e.oldText==null?` empty`:e.oldText===e.newText?``:` del`}`,children:e.oldText??``}),(0,G.jsx)(`td`,{className:`rt-diff-ln${e.newText!=null&&e.oldText!==e.newText?` add`:``}`,children:e.newNo??``}),(0,G.jsx)(`td`,{className:`rt-diff-code${e.newText==null?` empty`:e.oldText===e.newText?``:` add`}`,children:e.newText??``})]},t))]},t))})]})})]}):(0,G.jsx)(`pre`,{className:`rt-diff`,children:e||`(no difference)`})}function pR({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 sR(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,G.jsx)(`p`,{className:`rt-files-note`,children:o}):i?(0,G.jsxs)(G.Fragment,{children:[i.diff?(0,G.jsx)(fR,{diff:i.diff}):(0,G.jsx)(`pre`,{className:`rt-diff`,children:`(no difference)`}),i.truncated&&(0,G.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,G.jsx)(rp,{label:`Loading diff…`,compact:!0}):(0,G.jsx)(`p`,{className:`rt-files-note`,children:`No sandbox holds this snapshot, so there is no diff to load.`})}function mR(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 hR({snapshot:e,sandbox:t}){let n={A:`added`,M:`edited`,D:`deleted`,T:`type changed`},r=kL(t),[i,a]=(0,_.useState)(null);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`h4`,{children:[`Files changed `,(0,G.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,G.jsx)(`ul`,{className:`rt-files`,children:e.changes.map(o=>(0,G.jsxs)(_.Fragment,{children:[(0,G.jsxs)(`li`,{children:[(0,G.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,G.jsx)(V,{size:12,className:`rt-caret${i===o.path?` down`:``}`}),(0,G.jsx)(`span`,{className:`rt-file-status s-${o.status}`,children:n[o.status]??o.status}),(0,G.jsx)(`code`,{children:o.path})]}),(r.get(o.path)?.level??0)>=3&&(0,G.jsx)(QL,{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,G.jsx)(`span`,{className:`rt-flag`,title:`Its owner restricted this file: the agent was not meant to change it`,children:`restricted`}),(0,G.jsx)(`small`,{children:o.added==null?`binary`:`+${o.added} −${o.removed}`})]}),i===o.path&&(0,G.jsx)(`li`,{className:`rt-file-diff`,children:(0,G.jsx)(pR,{sandbox:t,from:e.parent??`4b825dc642cb6eb9a060e54bf8d69288fbee4904`,to:e.commit,path:o.path})})]},o.path))}):(0,G.jsx)(`p`,{className:`rt-files-note`,children:`No files changed.`}),e.too_big.length>0&&(0,G.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 gR(e,t){let n=wC(e,t);return n?JSON.stringify(n,null,2):``}var _R=`raytace.group-steps`;function vR(){let[e,t]=(0,_.useState)(!0);return(0,_.useEffect)(()=>{try{localStorage.getItem(_R)===`off`&&t(!1)}catch{}},[]),[e,e=>{t(e);try{localStorage.setItem(_R,e?`on`:`off`)}catch{}}]}function yR(e,t){let n=wC(e,t),r=[n?.file_path,n?.notebook_path].find(e=>typeof e==`string`&&e);return typeof r==`string`?r:null}var bR=(e,t)=>CC(e,t,dp(e.events,t.call_id),yR(e,t));function xR({name:e,section:t}){return(0,G.jsxs)(`th`,{children:[e,(0,G.jsx)(`a`,{className:`rt-th-help`,href:`${_C}#${t}`,target:`_blank`,rel:`noreferrer`,"aria-label":`What the ${e} labels mean (opens in a new tab)`,children:(0,G.jsx)(ie,{size:11})})]})}function SR({group:e,trace:t,open:n,onToggle:r}){let i=RC(e,t),a=e.calls.map(e=>bR(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=>cC(e.ended_at)-cC(e.started_at)).filter(Number.isFinite);return(0,G.jsxs)(`tr`,{className:`rt-row rt-group-row${n?` open`:``}`,onClick:r,children:[(0,G.jsxs)(`td`,{className:`rt-num`,children:[(0,G.jsx)(V,{size:12,className:`rt-caret`}),i.range.slice(1)]}),(0,G.jsxs)(`td`,{className:`rt-tool`,children:[i.kind,(0,G.jsxs)(`small`,{className:`rt-changed`,children:[e.calls.length,` steps`]})]}),(0,G.jsxs)(`td`,{className:`rt-cmd rt-group-label`,children:[i.label,i.flags.map(e=>(0,G.jsx)(`span`,{className:`rt-group-flag`,children:e},e))]}),(0,G.jsx)(`td`,{className:`rt-reported`,children:i.outcome}),(0,G.jsx)(`td`,{children:d||`—`}),(0,G.jsx)(`td`,{className:`rt-time`,children:f.length?lC(f.reduce((e,t)=>e+t,0)):`—`})]})}function CR({label:e,onOpen:t}){return!e.opens||!t?(0,G.jsx)(`span`,{className:`rt-ran ${e.tone}`,children:e.text}):(0,G.jsx)(`button`,{type:`button`,className:`rt-ran ${e.tone} rt-ran-link`,onClick:e=>{e.stopPropagation(),t()},children:e.text})}function wR({call:e}){let t=e.category?vC[e.category]:null;return!t||t.toLowerCase()===e.name.toLowerCase()?(0,G.jsx)(G.Fragment,{children:e.name}):(0,G.jsxs)(G.Fragment,{children:[t,(0,G.jsxs)(`span`,{className:`rt-tool-name`,children:[` · `,e.name]})]})}function TR({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=mR(e),m=sp(e.events),h=e.callVerifications??[],[g,v]=vR(),[y,b]=(0,_.useState)(()=>new Set),x=g?IC(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=fp(e).forkable&&!!o,O=fp(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`,zC(cp(j,`cost`),j.some(e=>e.costEstimated))],[`Time`,BC(lp(j))],[`Tokens in / out`,`${VC(cp(j,`input`))} / ${VC(cp(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,G.jsxs)(`section`,{className:`rt-view`,children:[(0,G.jsxs)(`header`,{className:`rt-view-head`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`eyebrow`,children:`TOOL CALLS`}),(0,G.jsx)(`h1`,{children:`How the agent got there`})]}),(0,G.jsxs)(`div`,{className:`rt-actions`,children:[(0,G.jsx)(Iw,{traces:t,currentId:e.id}),!s&&(0,G.jsxs)(`label`,{className:`rt-toggle`,title:`Fold runs of similar steps, such as repeated searches for the same thing, into one row`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:g,onChange:e=>v(e.target.checked)}),` Group similar steps`]}),(0,G.jsxs)(`button`,{type:`button`,className:`visualize-button ${s?`active`:``}`,onClick:()=>c(!s),children:[(0,G.jsx)(Ae,{size:14}),` `,s?`Back to list`:`Graph`]}),e.sandboxId&&r&&(0,G.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>r(),children:[`Sandbox evidence `,(0,G.jsx)(P,{size:14})]})]})]}),(0,G.jsx)(`dl`,{className:`rt-stats`,children:N.map(([e,t])=>(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:e}),(0,G.jsx)(`dd`,{children:t})]},e))}),s?(0,G.jsx)(gL,{trace:e,blocks:m,summaries:p,onSelectStep:()=>c(!1)}):(0,G.jsx)(`div`,{className:`rt-table-wrap`,children:(0,G.jsxs)(`table`,{className:`rt-table rt-calls`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{children:`#`}),(0,G.jsx)(xR,{name:`Tool`,section:`tool-categories`}),(0,G.jsx)(`th`,{children:`Command`}),(0,G.jsx)(`th`,{children:`Agent reported`}),(0,G.jsx)(xR,{name:`Sandbox`,section:`sandbox-labels`}),(0,G.jsx)(`th`,{children:`Ran for`})]})}),(0,G.jsx)(`tbody`,{children:m.map(t=>{let s=j.find(e=>e.id===t.exchangeId),c=p[t.exchangeId],d=t.completion?ap(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,G.jsxs)(_.Fragment,{children:[(0,G.jsx)(`tr`,{className:`rt-trip`,children:(0,G.jsxs)(`td`,{colSpan:6,children:[(0,G.jsxs)(`span`,{children:[`Round trip `,t.number]}),c?.status===`ready`&&(0,G.jsx)(`em`,{children:c.text}),(0,G.jsxs)(`small`,{children:[s?`${zC(s.cost,s.costEstimated)} · ${BC(s.durationMs)}`:``,d?` · failed`:``,g&&!m.length?` · answered`:``]})]})}),m.map(t=>{let s=dp(e.events,t.call_id),c=CC(e,t,s,yR(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=cC(t.started_at),h=cC(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,G.jsx)(SR,{group:v,trace:e,open:C(v),onToggle:()=>w(v)}):null;return v&&!C(v)?(0,G.jsx)(_.Fragment,{children:y},t.call_id):(0,G.jsxs)(_.Fragment,{children:[y,(0,G.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,G.jsxs)(`td`,{className:`rt-num`,children:[(0,G.jsx)(V,{size:12,className:`rt-caret`}),E.get(t.call_id)]}),(0,G.jsxs)(`td`,{className:`rt-tool`,children:[(0,G.jsx)(wR,{call:t}),t.snapshot?.changed&&(0,G.jsxs)(`small`,{className:`rt-changed`,title:`Files this call changed`,children:[t.snapshot.changes.length,` file`,t.snapshot.changes.length===1?``:`s`]})]}),(0,G.jsx)(`td`,{className:`rt-cmd`,children:t.description?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`rt-plain`,children:t.description}),(0,G.jsx)(`span`,{className:`rt-cmd-raw`,title:t.proposed??void 0,children:(0,G.jsx)(dC,{text:t.proposed||t.name})})]}):(0,G.jsx)(dC,{text:t.proposed||t.name})}),(0,G.jsx)(`td`,{className:`rt-reported ${s.state}`,children:s.state===`none`?`—`:s.state===`rejected`?`rejected`:s.code==null?s.state:`exit ${s.code}`}),(0,G.jsx)(`td`,{children:(0,G.jsx)(CR,{label:c,onOpen:d})}),(0,G.jsx)(`td`,{className:`rt-time`,children:Number.isFinite(m)&&Number.isFinite(h)?lC(h-m):`—`})]}),p&&(0,G.jsx)(`tr`,{className:`rt-expand`,children:(0,G.jsxs)(`td`,{colSpan:6,children:[(0,G.jsx)(`h4`,{children:`Arguments`}),(0,G.jsx)(`pre`,{children:gR(e,t)}),(0,G.jsx)(`h4`,{children:`Output the agent got back`}),(0,G.jsx)(`pre`,{children:s.output.trim()||`(no result captured)`}),t.snapshot&&(0,G.jsx)(`div`,{id:`files-${t.call_id}`,children:(0,G.jsx)(hR,{snapshot:t.snapshot,sandbox:e.sandboxId})}),(0,G.jsxs)(`div`,{className:`rt-actions`,children:[t.exec_id&&r&&(0,G.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>r(t.call_id),children:[`Show in sandbox `,(0,G.jsx)(P,{size:14})]}),i&&(0,G.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>i(g),children:[(0,G.jsx)(ae,{size:14}),` What it had in context`]}),O&&a&&(0,G.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>a(t.call_id),children:[(0,G.jsx)(R,{size:14}),` Why?`]}),D&&(0,G.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,G.jsx)(re,{size:14}),` Fork from here`]}),D&&A(t.exchange_id)&&(0,G.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,G.jsx)(re,{size:14}),` Rerun without this output`]})]})]})})]},t.call_id)})]},t.exchangeId)})})]})})]})}function ER(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 DR={likely:`likely`,possible:`possibly`,unclear:`unclear`};function OR({trace:e,onStep:t}){let{state:n,retry:r}=ER(e);if(n.status===`idle`)return null;let i=e.callVerifications??[],a=e=>e.steps.length>0&&(0,G.jsx)(`span`,{className:`rt-recap-steps`,children:e.steps.map(e=>t&&i[e-1]?(0,G.jsx)(`button`,{type:`button`,className:`rt-recap-step`,onClick:()=>t(i[e-1].call_id),title:`Open step ${e}`,children:e},e):(0,G.jsx)(`span`,{className:`rt-recap-step`,children:e},e))});return(0,G.jsxs)(`section`,{className:`rt-recap`,"aria-label":`Recap`,children:[(0,G.jsxs)(`header`,{children:[(0,G.jsx)(`span`,{className:`eyebrow`,children:`RECAP`}),n.status===`ready`&&(0,G.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,G.jsx)(rp,{label:`Reading the run…`,compact:!0}),n.status===`error`&&(0,G.jsxs)(`p`,{className:`rt-muted`,children:[n.message,` `,(0,G.jsxs)(`button`,{type:`button`,className:`link-button`,onClick:r,children:[(0,G.jsx)(ge,{size:11}),` Try again`]})]}),n.status===`ready`&&(0,G.jsxs)(G.Fragment,{children:[n.recap.headline&&(0,G.jsx)(`p`,{className:`rt-recap-headline`,children:n.recap.headline}),(0,G.jsx)(`h4`,{children:`What happened`}),(0,G.jsx)(`ol`,{className:`rt-recap-list`,children:n.recap.happened.map((e,t)=>(0,G.jsxs)(`li`,{children:[e.text,` `,a(e)]},t))}),n.recap.reasoning.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`h4`,{children:[`Probably why `,(0,G.jsx)(`small`,{children:`the observer's reading of the sequence, not a measurement`})]}),(0,G.jsx)(`ul`,{className:`rt-recap-list`,children:n.recap.reasoning.map((e,t)=>(0,G.jsxs)(`li`,{children:[(0,G.jsx)(`span`,{className:`rt-recap-sure s-${e.confidence??`possible`}`,children:DR[e.confidence??`possible`]}),` `,e.text,` `,a(e)]},t))})]}),n.recap.flags.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`h4`,{children:`Worth checking`}),(0,G.jsx)(`ul`,{className:`rt-recap-list rt-recap-flags`,children:n.recap.flags.map((e,t)=>(0,G.jsxs)(`li`,{children:[e.text,` `,a(e)]},t))})]})]})]})}var kR=e=>`${e.exchange_id}:${e.output_index}`,AR=e=>`${Math.round(e*100)}%`,jR=.02,MR={user:`Your request`,tool_result:`Earlier result`,agent:`Agent's earlier plan`,project:`Project instructions`,habit:`Routine step`,explore:`Exploring`};function NR(e){let[t,n]=(0,_.useState)({}),r=(0,_.useRef)(new Set),i=(0,_.useCallback)(async(e,t)=>{let i=kR(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(kR).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 PR(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[kR(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=RC(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:MR[u.kind].toLowerCase(),callId:null});break}}return o.length>1||o[0]?.callId?o:null}function FR({call:e,trace:t}){let n=dp(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,G.jsxs)(`div`,{className:`rt-cot-ran`,children:[(0,G.jsx)(`span`,{className:`workspace-label`,children:`WHAT ACTUALLY RAN`}),` `,r.join(` · `),i&&(0,G.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,G.jsxs)(`details`,{children:[(0,G.jsx)(`summary`,{children:`Files changed`}),(0,G.jsx)(hR,{snapshot:e.snapshot,sandbox:t.sandboxId})]})]})}function IR({attribution:e,number:t,onJump:n}){let r=e.ranked?e.causes.filter(e=>(e.probability??0)>=jR):e.causes;return(0,G.jsxs)(G.Fragment,{children:[e.ranked&&(0,G.jsx)(`div`,{className:`rt-cot-bar`,"aria-hidden":`true`,children:r.map(e=>(0,G.jsx)(`span`,{className:`k-${e.kind}`,style:{width:AR(e.probability??0)},title:`${AR(e.probability??0)} ${e.reason}`},e.key))}),!e.ranked&&(0,G.jsxs)(`p`,{className:`rt-cot-note`,children:[`Possible reasons, unranked`,e.unsure_reason?`: ${e.unsure_reason}`:`.`]}),(0,G.jsx)(`ol`,{className:`rt-cot-causes`,children:r.map(e=>{let r=e.source_call_id?t(e.source_call_id):null;return(0,G.jsxs)(`li`,{children:[e.probability==null?(0,G.jsx)(`span`,{"aria-hidden":`true`}):(0,G.jsx)(`strong`,{className:`rt-cot-pct`,children:AR(e.probability)}),(0,G.jsx)(`i`,{className:`rt-cot-dot k-${e.kind}`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{children:e.reason}),(0,G.jsxs)(`small`,{children:[MR[e.kind],r&&(0,G.jsxs)(G.Fragment,{children:[` · `,(0,G.jsxs)(`button`,{type:`button`,className:`link-button`,onClick:()=>n(e.source_call_id),children:[`step #`,r]})]})]}),e.quote&&(0,G.jsxs)(`details`,{children:[(0,G.jsx)(`summary`,{children:`Evidence`}),(0,G.jsx)(`blockquote`,{children:e.quote})]})]})]},e.key)})})]})}function LR({call:e,index:t,trace:n,states:r,chain:i,highlight:a,number:o,onJump:s}){let c=r[kR(e)],l=c?.status===`ready`?c.attribution:null;return(0,G.jsxs)(`li`,{id:`cot-${e.call_id}`,className:`rt-cot-step${a?` rt-focus`:``}`,children:[(0,G.jsxs)(`div`,{className:`rt-cot-head`,children:[(0,G.jsxs)(`span`,{className:`rt-cot-num`,children:[`#`,t+1]}),(0,G.jsx)(`strong`,{children:e.name}),(0,G.jsx)(dC,{text:e.proposed||e.name}),l?.purpose&&(0,G.jsx)(`span`,{className:`rt-chip`,title:l.purpose.label,children:l.purpose.choice.replace(`_`,` `)}),l?.unsure&&(0,G.jsx)(`span`,{className:`rt-cot-unsure`,title:l.unsure_reason??``,children:`Unsure`})]}),(0,G.jsx)(RR,{state:c,number:o,onJump:s}),i&&(0,G.jsxs)(`p`,{className:`rt-cot-chain`,children:[(0,G.jsx)(`span`,{className:`workspace-label`,children:`CHAIN`}),i.map((e,t)=>(0,G.jsxs)(`span`,{children:[e.callId?(0,G.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>s(e.callId),children:e.label}):e.label,` → `]},t)),(0,G.jsx)(`span`,{children:`this step`})]}),(0,G.jsx)(FR,{call:e,trace:n})]})}function RR({state:e,number:t,onJump:n}){if(!e||e.status===`loading`)return(0,G.jsx)(rp,{label:`Working out why…`,compact:!0});if(e.status===`error`)return(0,G.jsx)(`p`,{className:`rt-cot-note`,children:e.message});let{attribution:r}=e;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(IR,{attribution:r,number:t,onJump:n}),r.unsure&&r.unsure_reason&&(0,G.jsxs)(`p`,{className:`rt-cot-note`,children:[`Unsure: `,r.unsure_reason]})]})}function zR({trace:e,focusCall:t}){let n=fp(e),r=n.where===`sandbox`?e.callVerifications??[]:[],i=IC(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=NR(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,G.jsx)(`header`,{className:`rt-view-head`,children:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`eyebrow`,children:`CHAIN OF THOUGHT`}),(0,G.jsx)(`h1`,{children:`Why the agent did each step`}),(0,G.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,G.jsxs)(`section`,{className:`rt-view`,children:[h,(0,G.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,G.jsx)(`code`,{children:`raytrace sandbox create --local`}),`.`]})]});if(!r.length)return(0,G.jsxs)(`section`,{className:`rt-view`,children:[h,(0,G.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,G.jsx)(LR,{call:t,index:r.indexOf(t),trace:e,states:u,chain:PR(t,r,u,a,e),highlight:d===t.call_id,number:p,onJump:m},t.call_id);return(0,G.jsxs)(`section`,{className:`rt-view`,children:[h,(0,G.jsx)(OR,{trace:e,onStep:m}),(0,G.jsx)(`ol`,{className:`rt-cot-steps`,children:i.map(t=>{if(t.calls.length===1)return y(t.calls[0]);let n=RC(t,e),r=c(t),i=t.calls[0];return(0,G.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,G.jsxs)(`div`,{className:`rt-cot-head`,children:[(0,G.jsx)(`span`,{className:`rt-cot-num`,children:n.range}),(0,G.jsx)(`strong`,{children:n.label}),(0,G.jsxs)(`span`,{className:`rt-chip`,children:[t.calls.length,` steps`]}),n.flags.map(e=>(0,G.jsx)(`span`,{className:`rt-group-flag`,children:e},e))]}),(0,G.jsxs)(`p`,{className:`rt-cot-note`,children:[`Why it started (step #`,t.first,`):`]}),(0,G.jsx)(RR,{state:u[kR(i)],number:p,onJump:m}),n.repeated&&(0,G.jsxs)(`p`,{className:`rt-cot-note`,children:[n.repeated,` `,n.outcome[0].toUpperCase()+n.outcome.slice(1),`.`]}),(0,G.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,G.jsx)(`ol`,{className:`rt-cot-steps rt-cot-members`,children:t.calls.map(y)})]},t.id)})}),v&&(0,G.jsxs)(`p`,{className:`rt-foot`,children:[`Causes proposed and ranked by `,v,`. Each step is worked out once and saved.`]})]})}var BR=`/raytace`,VR=e=>[`queued`,`running`].includes(e.status),HR=e=>e===null?`Not measured`:`${Math.round(e*100)}%`;async function UR(e,t){let n=await fetch(`${BR}${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 WR(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 GR({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 UR(`/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 UR(`/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 UR(`/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(VR),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 B(){if(n){M(!0),E(``);try{let e=await UR(`/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 V(){if(n&&N&&R){A(!0),E(``);try{let e=await UR(`/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,G.jsxs)(`aside`,{className:`fork-panel lab decision-lab`,children:[(0,G.jsx)(`span`,{className:`eyebrow`,children:`COUNTERFACTUAL LAB`}),(0,G.jsx)(`h2`,{children:`Explore this decision`}),!n&&!D&&!T&&(0,G.jsx)(`p`,{children:`Select a proposed tool call or model answer in the sequence.`}),D&&(0,G.jsx)(rp,{label:`Loading the context before this step…`,compact:!0}),T&&(0,G.jsx)(`p`,{className:`experiment-error`,role:`alert`,children:T}),n&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`section`,{className:`step-focus`,children:[(0,G.jsx)(`small`,{children:`SELECTED STEP`}),(0,G.jsx)(`h3`,{children:e?.title}),(0,G.jsx)(`p`,{children:e?.detail})]}),(0,G.jsx)(`h3`,{children:`Possible explanations`}),(0,G.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,G.jsx)(`button`,{type:`button`,className:`run-button`,disabled:j||!o,onClick:B,children:j?`Generating explanations…`:`Generate explanations`}),(0,G.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,G.jsxs)(`li`,{className:e.evidence_id===u?`chosen`:``,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>z(e.evidence_id),children:[(0,G.jsx)(`span`,{children:t+1}),(0,G.jsx)(`strong`,{children:e.title})]}),(0,G.jsx)(`p`,{children:r?`Action repeated: ${HR(r.summary.baseline.rate)} original / ${HR(r.summary.intervention.rate)} edited`:`Action repeat rate: not measured`}),(0,G.jsxs)(`details`,{children:[(0,G.jsx)(`summary`,{children:`Supporting evidence`}),(0,G.jsx)(`p`,{children:e.explanation}),(0,G.jsx)(`blockquote`,{children:e.excerpt})]})]},e.evidence_id)})}),n.explanation_generated&&!n.hypotheses.length&&(0,G.jsx)(`p`,{children:`Insufficient evidence: no explanations with verifiable supporting quotes were returned.`}),(0,G.jsx)(`h3`,{children:`Edit and rerun`}),(0,G.jsx)(`label`,{htmlFor:`step-context`,children:`Context to change`}),(0,G.jsx)(bw,{id:`step-context`,className:`lab-select`,value:u,onChange:e=>z(e.target.value),children:n.evidence.map(e=>(0,G.jsxs)(xw,{value:e.id,children:[`#`,e.index+1,` · `,WR(e)]},e.id))}),(0,G.jsx)(`label`,{htmlFor:`edited-context`,children:`Edited context`}),(0,G.jsx)(`textarea`,{id:`edited-context`,value:f,onChange:e=>p(e.target.value),spellCheck:!1,rows:8}),(0,G.jsxs)(`div`,{className:`context-actions`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>p(N?.content??N?.preview??``),children:`Reset`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>p(``),children:`Withhold text`})]}),(0,G.jsx)(`small`,{children:`Only this context item changes. Other messages and tool history are retained.`}),(0,G.jsx)(`label`,{htmlFor:`step-model`,children:`Model`}),(0,G.jsxs)(bw,{id:`step-model`,className:`lab-select`,value:c,onChange:e=>l(e.target.value),children:[!i.some(e=>e.id===n.model)&&(0,G.jsx)(xw,{value:n.model,children:n.model}),i.map(e=>(0,G.jsxs)(xw,{value:e.id,children:[e.alias,` · `,e.id]},e.alias))]}),(0,G.jsx)(`label`,{htmlFor:`run-mode`,children:`Run mode`}),(0,G.jsxs)(bw,{id:`run-mode`,className:`lab-select`,value:m,onChange:e=>h(e.target.value),children:[(0,G.jsx)(xw,{value:`decision`,children:`Replay model decision`}),(0,G.jsx)(xw,{value:`execute`,disabled:!o,children:`Execute and continue`})]}),m===`decision`?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`label`,{htmlFor:`step-count`,children:`Runs per version`}),(0,G.jsx)(`input`,{id:`step-count`,type:`number`,min:2,max:20,step:1,value:g,onChange:e=>v(e.target.value)}),(0,G.jsx)(`p`,{children:R?`${I} original + ${I} edited = ${I*2} paid API calls maximum.`:`Enter a whole number from 2 to 20.`}),(0,G.jsxs)(`details`,{className:`raw-details`,children:[(0,G.jsx)(`summary`,{children:`How this is measured`}),(0,G.jsx)(`p`,{children:`Both use the selected model. Tools are not executed.`})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`label`,{htmlFor:`step-limit`,children:`Maximum model requests`}),(0,G.jsx)(`input`,{id:`step-limit`,type:`number`,min:1,max:20,step:1,value:y,onChange:e=>b(e.target.value)}),(0,G.jsxs)(`p`,{children:[`One continuation in a separate copy of current project files, up to `,R?L:`—`,` paid requests and 3 minutes.`]}),(0,G.jsxs)(`details`,{className:`raw-details`,children:[(0,G.jsx)(`summary`,{children:`How this is measured`}),(0,G.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,G.jsx)(`p`,{className:`scope-note`,children:n.replay_reason}),(0,G.jsx)(`button`,{className:`run-button`,type:`button`,disabled:k||!!P||!R||!N||!!n.replay_reason,onClick:V,children:k?`Starting…`:m===`decision`?`Compare responses`:`Execute in project copy`}),P&&(0,G.jsxs)(`div`,{className:`job-progress`,children:[(0,G.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,G.jsx)(`button`,{type:`button`,onClick:()=>UR(`/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,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`label`,{htmlFor:`step-run`,children:`Results for this action`}),(0,G.jsxs)(bw,{id:`step-run`,className:`lab-select`,value:C,onChange:e=>w(e.target.value),children:[(0,G.jsx)(xw,{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,G.jsxs)(xw,{value:e.id,children:[e.mode,` · `,e.model,` · `,e.status]},e.id))]})]})]}),F&&(0,G.jsxs)(`section`,{className:`trial-report`,children:[(0,G.jsx)(`h3`,{children:`Original vs rerun`}),(0,G.jsxs)(`p`,{children:[F.status,` · `,F.model]}),F.error&&(0,G.jsx)(`p`,{role:`alert`,className:`error-text`,children:F.error}),(0,G.jsxs)(`details`,{children:[(0,G.jsx)(`summary`,{children:`Original action`}),(0,G.jsx)(`pre`,{children:JSON.stringify(F.recorded,null,2)})]}),F.mode===`decision`?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`frequency-grid`,children:[[`Original context`,F.summary.baseline],[`Edited context`,F.summary.intervention]].map(([e,t])=>(0,G.jsxs)(`section`,{className:`frequency`,children:[(0,G.jsx)(`h4`,{children:e}),(0,G.jsx)(`strong`,{children:HR(t.rate)}),(0,G.jsxs)(`p`,{children:[t.hits,`/`,t.successful,` successful responses repeated the selected action`]}),t.interval&&(0,G.jsxs)(`small`,{children:[`95% interval: `,HR(t.interval[0]),`–`,HR(t.interval[1])]})]},e))}),(0,G.jsx)(`p`,{className:`lab-caption`,children:`These rates measure action repetition, not the probability an explanation is true.`}),(0,G.jsxs)(`details`,{className:`raw-details`,children:[(0,G.jsx)(`summary`,{children:`How this is measured`}),(0,G.jsx)(`p`,{children:`Small samples are uncertain. Answers require exact text matches.`})]}),(0,G.jsxs)(`p`,{children:[`Reported API cost: $`,F.cost.toFixed(4)]}),F.trials.map((e,t)=>(0,G.jsxs)(`details`,{children:[(0,G.jsxs)(`summary`,{children:[t+1,`. `,e.arm===`baseline`?`Original`:`Edited`,` · `,e.status===`succeeded`?e.matches?`same action`:`different response`:e.status]}),(0,G.jsx)(`pre`,{children:e.error||JSON.stringify(e.outcome,null,2)})]},t))]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{children:F.note}),F.workspace&&(0,G.jsxs)(`p`,{children:[`Files: `,(0,G.jsx)(`code`,{children:F.workspace})]}),(0,G.jsx)(`h4`,{children:`New execution sequence`}),F.events.map((e,t)=>(0,G.jsxs)(`details`,{children:[(0,G.jsxs)(`summary`,{children:[typeof e.type==`string`?e.type:`Event`,` `,String(e.item?.type||``)]}),(0,G.jsx)(`pre`,{children:JSON.stringify(e,null,2)})]},t))]})]})]})}var KR=e=>Math.round(e/4),qR=e=>e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e);async function JR(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 YR=(e,t=140)=>{let n=e.replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-1)}…`:n};function XR(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 ZR({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,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`li`,{className:`rt-file${i?` open`:``}`,children:(0,G.jsxs)(`button`,{type:`button`,className:`rt-file-row`,onClick:()=>a(!i),"aria-expanded":i,children:[(0,G.jsx)(`span`,{className:`rt-op rt-op-${e.op}`,children:e.op}),(0,G.jsx)(`code`,{className:`rt-file-path`,title:e.path,children:e.path}),(0,G.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,G.jsx)(`span`,{className:`rt-file-tokens`,title:`Estimated tokens this file added to the context window`,children:e.op===`wrote`?``:`~${qR(KR(e.chars))} tokens`}),(0,G.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,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(z,{size:12}),` used`]}):``})]})}),i&&(0,G.jsxs)(`li`,{className:`rt-file-detail`,children:[(0,G.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,G.jsx)(`code`,{children:YR(e.command,90)})]}),(0,G.jsxs)(`div`,{className:`rt-actions`,children:[e.op!==`wrote`&&(0,G.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:()=>void JR(t,e.context_index),children:[`Open what the model saw `,(0,G.jsx)(ee,{size:13})]}),r&&e.op!==`wrote`&&(0,G.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:r,title:`Open the Playground at the next step, with this output removed`,children:[(0,G.jsx)(re,{size:14}),` Rerun without this`]}),n&&e.op!==`wrote`&&(0,G.jsxs)(`button`,{type:`button`,className:`rt-button`,onClick:n,children:[(0,G.jsx)(te,{size:14}),` Test impact`]})]})]})]})}function QR({data:e}){let t=KR(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,G.jsxs)(`section`,{className:`rt-window`,"aria-label":`Context window`,children:[(0,G.jsxs)(`div`,{className:`rt-window-head`,children:[(0,G.jsxs)(`strong`,{children:[`Context window: ~`,qR(t),` tokens used`,o?` of ${qR(o)}`:``]}),(0,G.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,G.jsx)(`div`,{className:`rt-window-bar`,children:a.map(e=>(0,G.jsx)(`i`,{className:`rt-seg-${e.tone}`,style:{width:`${Math.max(.4,KR(e.chars)/s*100)}%`},title:`${e.label}: ~${qR(KR(e.chars))} tokens`},e.label))}),(0,G.jsx)(`div`,{className:`rt-window-legend`,children:a.map(e=>(0,G.jsxs)(`span`,{children:[(0,G.jsx)(`i`,{className:`rt-seg-${e.tone}`}),e.label,` ~`,qR(KR(e.chars))]},e.label))})]})}function $R({trace:e,stepKey:t,onStep:n,onRerunWithout:r}){let{data:i,error:a,summarizing:o}=XR(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=fp(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,G.jsxs)(`section`,{className:`rt-view`,children:[(0,G.jsx)(`header`,{className:`rt-view-head`,children:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`eyebrow`,children:`CONTEXT`}),(0,G.jsx)(`h1`,{children:`What the model was working from`}),(0,G.jsxs)(`p`,{className:`rt-muted rt-sub`,children:[YR(e.title,120),` · `,new Date(e.startedAt).toLocaleString(void 0,{day:`numeric`,month:`short`,hour:`numeric`,minute:`2-digit`})]})]})}),i&&(0,G.jsx)(QR,{data:i}),a&&(0,G.jsx)(`p`,{role:`alert`,className:`verify-error`,children:a}),!i&&!a&&(0,G.jsx)(rp,{label:`Loading the context…`}),i&&(0,G.jsxs)(`div`,{className:`rt-boxes`,children:[(0,G.jsxs)(`section`,{className:`rt-box`,children:[(0,G.jsxs)(`h2`,{children:[(0,G.jsx)(`span`,{children:`A`}),` You asked before`]}),i.earlierPrompts.length?(0,G.jsx)(`ol`,{className:`rt-box-list`,children:i.earlierPrompts.map((e,t)=>(0,G.jsx)(`li`,{children:i.summary?.prompts[t]??YR(e.text)},e.index))}):(0,G.jsx)(`p`,{className:`rt-muted`,children:`This was the first prompt in this conversation, so nothing you asked earlier was in context.`}),o&&(0,G.jsx)(`p`,{className:`rt-muted`,children:`Summarising…`})]}),(0,G.jsxs)(`section`,{className:`rt-box rt-box-wide`,children:[(0,G.jsxs)(`h2`,{children:[(0,G.jsx)(`span`,{children:`B`}),` The model brought`]}),(0,G.jsx)(`p`,{className:`rt-box-note`,children:E.length?i.summary?.answers||`${E.length} earlier answer${E.length===1?``:`s`}: ${YR(E.at(-1).text,120)}`:`No earlier answers: it started this conversation with your question.`}),w.length?(0,G.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,G.jsx)(ZR,{file:t,traceId:e.id,onRerun:C(t),onTest:b&&!y&&v(t)?()=>g(t):void 0},`${t.op}:${t.path}`))}):(0,G.jsx)(`p`,{className:`rt-muted`,children:`No file reads identified in what was captured.`}),T.length>0&&(0,G.jsxs)(`details`,{className:`rt-listed`,children:[(0,G.jsxs)(`summary`,{children:[`listed `,T.length,` location`,T.length===1?``:`s`]}),(0,G.jsx)(`ul`,{className:`rt-files`,children:T.map(t=>(0,G.jsx)(ZR,{file:t,traceId:e.id},`${t.op}:${t.path}`))})]}),(0,G.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,G.jsxs)(`section`,{className:`rt-box`,children:[(0,G.jsxs)(`h2`,{children:[(0,G.jsx)(`span`,{children:`C`}),` Internals`]}),(0,G.jsx)(`ul`,{className:`rt-internals`,children:i.internals.map(t=>(0,G.jsx)(`li`,{children:(0,G.jsxs)(`details`,{children:[(0,G.jsxs)(`summary`,{children:[(0,G.jsx)(`strong`,{children:t.kind}),(0,G.jsxs)(`span`,{children:[`~`,qR(KR(t.chars)),` tokens`]})]}),t.kind===`Environment`&&D?(0,G.jsx)(`dl`,{children:Object.entries(D).map(([e,t])=>(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:e.replace(/_/g,` `)}),(0,G.jsx)(`dd`,{children:t})]},e))}):t.names?(0,G.jsx)(`p`,{className:`rt-muted`,children:t.names.join(`, `)}):null,(0,G.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>void JR(e.id,t.context_index),children:`Open full text ↗`})]})},t.kind))}),!i.internals.some(e=>e.kind===`AGENTS.md`)&&(0,G.jsx)(`p`,{className:`rt-muted`,children:`No AGENTS.md was loaded.`})]})]}),b&&!y&&(0,G.jsxs)(`details`,{className:`rt-test`,ref:d,open:s,onToggle:e=>c(e.currentTarget.open),children:[(0,G.jsxs)(`summary`,{children:[(0,G.jsx)(te,{size:14}),` Test it: rerun a step with part of its context changed`]}),p.length?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`label`,{htmlFor:`lab-step`,className:`workspace-label`,children:`STEP`}),(0,G.jsx)(bw,{id:`lab-step`,className:`trace-picker`,value:h?m(h):``,onChange:e=>{u(null),n(e.target.value)},children:p.map(e=>(0,G.jsxs)(xw,{value:m(e),children:[e.title,` · `,e.detail.slice(0,80)]},m(e)))}),s&&h&&(0,G.jsx)(`div`,{className:`rt-lab-body`,children:(0,G.jsx)(GR,{selected:h,focusCallId:l},`${m(h)}:${l??``}`)})]}):(0,G.jsx)(`p`,{className:`rt-empty`,children:`This prompt proposed no tool calls, so there is no step to rerun.`})]})]})}function ez({size:e=16}){return(0,G.jsx)(`svg`,{width:e,height:e,viewBox:`0 0 16 16`,fill:`currentColor`,children:(0,G.jsx)(`path`,{d:`M6.766 11.328c-2.063-.25-3.516-1.734-3.516-3.656 0-.781.281-1.625.75-2.188-.203-.515-.172-1.609.063-2.062.625-.078 1.468.25 1.968.703.594-.187 1.219-.281 1.985-.281.765 0 1.39.094 1.953.265.484-.437 1.344-.765 1.969-.687.218.422.25 1.515.046 2.047.5.593.766 1.39.766 2.203 0 1.922-1.453 3.375-3.547 3.64.531.344.89 1.094.89 1.954v1.625c0 .468.391.734.86.547C13.781 14.359 16 11.53 16 8.03 16 3.61 12.406 0 7.984 0 3.563 0 0 3.61 0 8.031a7.88 7.88 0 0 0 5.172 7.422c.422.156.828-.125.828-.547v-1.25c-.219.094-.5.156-.75.156-1.031 0-1.64-.562-2.078-1.609-.172-.422-.36-.672-.719-.719-.187-.015-.25-.093-.25-.187 0-.188.313-.328.625-.328.453 0 .844.281 1.25.86.313.452.64.655 1.031.655s.641-.14 1-.5c.266-.265.47-.5.657-.656`})})}var tz={type:`spring`,stiffness:600,damping:28};function nz({first:e,second:t,active:n,sparkle:r=!1}){let i=Bf(),a=n?t:e;return(0,G.jsx)(`span`,{className:`rt-morph-icon${r?` sparkle`:``}`,"aria-hidden":`true`,children:(0,G.jsx)(Ed,{initial:!1,children:(0,G.jsxs)(Vf.span,{initial:{opacity:0,scale:i?1:.5,y:!i&&r?10:0},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:i?1:.5,y:!i&&r?-10:0},transition:i?{duration:0}:tz,children:[(0,G.jsx)(a,{size:16}),r&&n&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Vf.i,{className:`rt-star-spark one`,initial:{opacity:0,scale:0,rotate:-45},animate:{opacity:1,scale:1,rotate:0},transition:i?{duration:0}:{...tz,delay:.05},children:(0,G.jsx)(Ce,{size:8,fill:`currentColor`})}),(0,G.jsx)(Vf.i,{className:`rt-star-spark two`,initial:{opacity:0,scale:0,rotate:45},animate:{opacity:1,scale:1,rotate:0},transition:i?{duration:0}:{...tz,delay:.1},children:(0,G.jsx)(Ce,{size:5,fill:`currentColor`})})]})]},`${n}:${a.displayName}`)})})}function rz(){let[e,t]=(0,_.useState)(!1);return(0,G.jsxs)(`a`,{className:`rt-button rt-motion-button rt-github-star`,href:`https://github.com/Godcreatebugs/raytrace-cli`,target:`_blank`,rel:`noreferrer`,onMouseEnter:()=>t(!0),onMouseLeave:()=>t(!1),onFocus:()=>t(!0),onBlur:()=>t(!1),children:[(0,G.jsx)(nz,{first:ez,second:Ce,active:e,sparkle:!0}),(0,G.jsx)(`span`,{children:`Star on GitHub`})]})}function iz(){let e=np(),t=Bf(),n=`Switch to ${e===`light`?`dark`:`light`} theme`;return(0,G.jsx)(Vf.button,{type:`button`,className:`rt-motion-theme`,"aria-label":n,title:n,"aria-pressed":e===`dark`,onClick:()=>ep(e===`light`?`dark`:`light`),whileHover:t?void 0:{rotate:12,scale:1.08},whileTap:t?void 0:{scale:.9},children:(0,G.jsx)(nz,{first:ue,second:we,active:e===`dark`})})}function az({loaded:e,connected:t,offline:n}){let r=Bf(),i=e?t?`connected`:`offline`:`pending`;return(0,G.jsxs)(Vf.div,{className:`rt-network-status`,"data-state":i,role:`status`,"aria-live":`polite`,title:e?t?`Dashboard connected to the proxy`:`The dashboard cannot reach the proxy`:`Connecting to the local proxy`,whileHover:r?void 0:{scale:1.025},children:[(0,G.jsx)(nz,{first:ke,second:Oe,active:e&&!t}),(0,G.jsx)(`span`,{children:e?t?`Connected`:n:`Connecting…`})]})}function oz({children:e,className:t=``,...n}){return(0,G.jsxs)(`button`,{type:`button`,className:`rt-button rt-motion-button rt-delete-button ${t}`,...n,children:[(0,G.jsx)(`span`,{className:`rt-delete-icon`,"aria-hidden":`true`,children:(0,G.jsx)(Te,{size:16})}),e]})}function sz(){let e=Jf(),t=e?`Pause loading animation`:`Enable loading animation`;return(0,G.jsx)(`button`,{type:`button`,className:`rt-motion-theme rt-wave-motion-toggle`,"aria-label":t,title:t,"aria-pressed":e,onClick:()=>Yf(!e),children:(0,G.jsx)(De,{size:16,"aria-hidden":`true`})})}var cz=e=>{try{return Number(localStorage.getItem(e))||null}catch{return null}},lz=(e,t)=>{try{t==null?localStorage.removeItem(e):localStorage.setItem(e,String(t))}catch{}};function uz({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=cz(n);a&&e.current?.style.setProperty(t,`${Math.round(Math.min(i,Math.max(r,a)))}px`)},[e,t,n,r,i]),(0,G.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`),lz(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),lz(n,t)},onDoubleClick:()=>{s(null),lz(n,null)}})}var dz={"content-type":`application/json`,"x-raytace-experiment":`1`},fz=[`claude-opus-5-5`,`claude-sonnet-5`,`claude-haiku-4-5`,`claude-fable-5-1`],pz=`(output removed)`,mz=(e,t=120)=>{let n=e.replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-1)}…`:n},hz=e=>new Date(e).toLocaleString(void 0,{day:`numeric`,month:`short`,hour:`numeric`,minute:`2-digit`}),gz=e=>[`queued`,`creating`,`running`,`collecting`,`checking`].includes(e.status),_z={queued:`Waiting`,creating:`Starting sandbox`,running:`Running`,collecting:`Comparing`,checking:`Checking`,completed:`Done`,failed:`Failed`,interrupted:`Interrupted`,cancelled:`Cancelled`},vz=[1,3,5,10],yz=e=>e.check&&[`passed`,`failed`,`timed_out`].includes(e.check.status),bz=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},xz={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`},Sz=e=>e==null?``:e<1e4?`${(e/1e3).toFixed(1)} s`:`${Math.round(e/1e3)} s`;function Cz({check:e}){let t=e.status===`passed`||e.status===`failed`?`exit ${e.exit_code} · ${Sz(e.duration_ms)}`:e.status===`timed_out`?`stopped after ${Sz(e.duration_ms)}`:e.status===`skipped`?`the fork stopped before it got there`:``;return(0,G.jsxs)(`div`,{className:`pg-check c-${e.status}`,children:[(0,G.jsxs)(`p`,{children:[e.status===`passed`?(0,G.jsx)(z,{size:14}):e.status===`failed`||e.status===`timed_out`?(0,G.jsx)(Me,{size:14}):null,(0,G.jsx)(`strong`,{children:xz[e.status]}),(0,G.jsx)(`code`,{children:e.command}),t&&(0,G.jsx)(`small`,{children:t})]}),e.output&&(0,G.jsxs)(`details`,{children:[(0,G.jsx)(`summary`,{children:`Output`}),(0,G.jsx)(`pre`,{className:`pg-diff`,children:e.output})]})]})}function wz(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 Tz(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 Ez({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,G.jsx)(rp,{label:`Loading diff…`,compact:!0}):n.startsWith(`Could not load`)?(0,G.jsx)(`p`,{className:`pg-note`,children:n}):(0,G.jsx)(fR,{diff:n})}function Dz({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:dz})}finally{l(!1),i()}},m=gz(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,G.jsxs)(`article`,{className:`pg-run`,children:[(0,G.jsxs)(`header`,{className:`pg-run-head`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`pg-status s-${e.status}`,children:[_z[e.status],gz(e)&&e.progress.tool_calls?` · ${e.progress.tool_calls} tool call${e.progress.tool_calls===1?``:`s`}`:``]}),(0,G.jsx)(`strong`,{children:e.model}),(0,G.jsxs)(`small`,{children:[(e.attempts??1)>1&&`Run ${e.attempt} of ${e.attempts} · `,hz(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,G.jsxs)(`p`,{className:`pg-told`,children:[(0,G.jsx)(`b`,{children:`You told it:`}),` `,e.message]})]}),(0,G.jsxs)(`div`,{className:`rt-actions`,children:[r&&(0,G.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,G.jsx)(P,{size:13})]}),!e.deleted_at&&!gz(e)&&(0,G.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,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(de,{size:13}),` Unkeep`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(fe,{size:13}),` Keep`]})}),!e.deleted_at&&(0,G.jsx)(oz,{disabled:c,onClick:()=>p(`delete`),children:e.status===`queued`?`Cancel this run`:gz(e)?`Stop and delete`:`Delete sandbox`}),e.deleted_at&&e.status!==`cancelled`&&(0,G.jsx)(`span`,{className:`pg-note`,children:`Sandbox deleted · results kept`})]})]}),e.error&&(0,G.jsx)(`p`,{role:`alert`,className:`pg-error`,children:e.error}),e.check&&(0,G.jsx)(Cz,{check:e.check}),m&&(0,G.jsx)(`p`,{className:`pg-verdict${e.comparison?.same_files?` same`:``}`,children:m}),(0,G.jsxs)(`div`,{className:`pg-compare`,children:[(0,G.jsxs)(`section`,{children:[(0,G.jsx)(`h3`,{children:`Original, from this step`}),(0,G.jsxs)(`ol`,{className:`pg-steps`,children:[d.map(e=>(0,G.jsxs)(`li`,{children:[(0,G.jsx)(`b`,{children:e.name}),(0,G.jsx)(`code`,{children:mz(e.proposed??``,140)})]},e.call_id)),!d.length&&(0,G.jsx)(`li`,{className:`pg-note`,children:`Answered without another tool call.`})]}),t.answer&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`h4`,{children:`Answer`}),(0,G.jsx)(`p`,{className:`pg-answer`,children:t.answer})]})]}),(0,G.jsxs)(`section`,{children:[(0,G.jsx)(`h3`,{children:`Fork`}),(0,G.jsxs)(`ol`,{className:`pg-steps`,children:[e.events.filter(e=>e.kind===`tool`).map((e,t)=>(0,G.jsxs)(`li`,{children:[(0,G.jsx)(`b`,{children:e.name}),(0,G.jsx)(`code`,{children:mz(e.detail,140)})]},t)),gz(e)&&(0,G.jsx)(`li`,{className:`pg-note`,children:(0,G.jsx)(rp,{compact:!0,label: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…`})}),!gz(e)&&!e.events.some(e=>e.kind===`tool`)&&(0,G.jsx)(`li`,{className:`pg-note`,children:`Answered without another tool call.`})]}),e.result?.text&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`h4`,{children:`Answer`}),(0,G.jsx)(`p`,{className:`pg-answer`,children:e.result.text})]}),e.result&&(0,G.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,G.jsxs)(`section`,{className:`pg-files`,children:[(0,G.jsx)(`h3`,{children:`Files, original vs fork`}),f.length?(0,G.jsx)(`ul`,{children:f.map(t=>(0,G.jsxs)(_.Fragment,{children:[(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(o===t.path?null:t.path),"aria-expanded":o===t.path,children:[(0,G.jsx)(`span`,{className:`rt-file-status s-${t.status}`,children:{A:`only fork`,D:`only original`,M:`differs`}[t.status]??t.status}),(0,G.jsx)(`code`,{children:t.path}),(0,G.jsx)(`small`,{children:t.added==null?`binary`:`+${t.added} −${t.removed}`})]})}),o===t.path&&(0,G.jsx)(`li`,{children:(0,G.jsx)(Ez,{fork:e,path:t.path})})]},t.path))}):(0,G.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,G.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 Oz(e){let t=e.filter(e=>!gz(e)&&e.status!==`cancelled`),n=e.filter(yz),r=n.filter(e=>e.check?.status===`passed`).length,i=e=>bz(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(gz),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 kz(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 Az({change:e,base:t,onShow:n}){let r=Oz(e),i=Oz(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=kz(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,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{children:e}),(0,G.jsx)(`td`,{children:t(i)}),(0,G.jsx)(`td`,{children:t(r)})]}),c=(e,t)=>e==null?`—`:t(e);return(0,G.jsxs)(`section`,{className:`pg-baseline`,children:[(0,G.jsx)(`h3`,{children:`Against the step run unchanged`}),(0,G.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,G.jsxs)(`table`,{children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{scope:`col`,children:`Runs`}),(0,G.jsx)(`th`,{children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>n(t[0].id),children:[`Unchanged ×`,t.length]})}),(0,G.jsx)(`th`,{children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>n(e[0].id),children:[`Your change ×`,e.length]})})]})}),(0,G.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,Sz)),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,G.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 jz({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}=Oz(e);return(0,G.jsxs)(`section`,{className:`pg-batch`,children:[(0,G.jsxs)(`header`,{children:[(0,G.jsxs)(`div`,{className:`pg-batch-rate`,children:[l==null?(0,G.jsxs)(`strong`,{children:[o.length,`/`,e.length,` runs done`]}):(0,G.jsxs)(`strong`,{className:l===1?`good`:l===0?`bad`:`mixed`,children:[c,`/`,s.length,` passed`]}),(0,G.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,G.jsxs)(`dl`,{children:[d!=null&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Tool calls`}),(0,G.jsx)(`dd`,{children:Math.round(d)})]}),f!=null&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Time`}),(0,G.jsx)(`dd`,{children:Sz(f)})]}),u!=null&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Cost`}),(0,G.jsxs)(`dd`,{children:[`$`,u.toFixed(4)]})]}),p!=null&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Files differ`}),(0,G.jsx)(`dd`,{children:Math.round(p)})]}),o.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{children:`Same files`}),(0,G.jsxs)(`dd`,{children:[m,`/`,o.length]})]})]}),h&&(0,G.jsx)(oz,{disabled:i,onClick:async()=>{a(!0);try{await x().fetch(`/raytace/forks/${e[0].id}/stop-all`,{method:`POST`,headers:dz})}finally{a(!1),r()}},children:`Stop all runs`})]}),o.length>1&&(0,G.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,G.jsxs)(`table`,{className:`pg-batch-runs`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{children:`Run`}),(0,G.jsx)(`th`,{children:`Status`}),(0,G.jsx)(`th`,{children:`Check`}),(0,G.jsx)(`th`,{children:`Tool calls`}),(0,G.jsx)(`th`,{children:`Files differ`}),(0,G.jsx)(`th`,{children:`Time`}),(0,G.jsx)(`th`,{children:`Cost`})]})}),(0,G.jsx)(`tbody`,{children:e.map(e=>(0,G.jsxs)(`tr`,{className:e.id===t?`on`:``,onClick:()=>n(e.id),children:[(0,G.jsx)(`td`,{children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>n(e.id),"aria-pressed":e.id===t,children:[`#`,e.attempt??1]})}),(0,G.jsx)(`td`,{children:(0,G.jsx)(`span`,{className:`pg-status s-${e.status}`,children:_z[e.status]})}),(0,G.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,G.jsx)(`td`,{children:e.status===`queued`||e.status===`cancelled`?`—`:e.progress.tool_calls}),(0,G.jsx)(`td`,{children:e.comparison?e.comparison.changes.length:`—`}),(0,G.jsx)(`td`,{children:Sz(e.result?.duration_ms??null)||`—`}),(0,G.jsx)(`td`,{children:e.result?.cost_usd==null?`—`:`$${e.result.cost_usd.toFixed(4)}`})]},e.id))})]})]})}function Mz({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}=wz(c),f=fp(e),p=f.forkable&&t&&c.has(t)?t:null,m=p?o.findIndex(e=>e.id===p):-1,h=Tz(p),[g,v]=(0,_.useState)(()=>n?{[n]:{mode:`remove`,text:pz}}:{}),[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),[B,V]=(0,_.useState)(``),[H,U]=(0,_.useState)(null),ee=(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 W=e=>(h?.results??[]).filter(t=>{let n=e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return RegExp(`(^|[\\s'"=:(])(/workspace/)?${n}($|[\\s'";|&)<>])`).test(t.detail)}),te=new Map(S.flatMap(e=>W(e).map(t=>[t.call_id,e])));function ne(){let e=w.trim().replace(/^\/workspace\//,``).replace(/^\.\//,``);e&&!S.includes(e)&&C(t=>[...t,e]),T(``)}async function ie(){if(p){z(!0),V(``);try{let e=Object.fromEntries(Object.entries(g).map(([e,t])=>[e,t.text])),t=Object.fromEntries([...te.keys()].filter(t=>!(t in e)).map(e=>[e,pz])),n=await x().fetch(`/raytace/forks`,{method:`POST`,headers:dz,body:JSON.stringify({exchange_id:p,model:E||h?.model,minutes:O,message:y,check:oe,repeat:A,baseline:M&&me.length>0,exclude:S,results:{...t,...e}})}),r=await n.json();if(!n.ok)throw Error(r.error??`The fork could not start.`);U(r.id),await d()}catch(e){V(e instanceof Error?e.message:`The fork could not start.`)}finally{z(!1)}}}let ae=u.some(gz),oe=(P??u.find(e=>e.parent===h?.sandbox&&e.check)?.check?.command??``).trim(),se=[...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()],ce=se.find(e=>e.some(e=>e.id===H))??se[0]??null,le=se.filter(e=>e[0].unchanged&&e[0].model===h?.model&&(e[0].check?.command??``)===oe&&e.filter(e=>[`completed`,`failed`].includes(e.status)).length>=A).sort((e,t)=>t.length-e.length)[0]??null,ue=e=>e?.[0].baseline?se.find(t=>t[0].group===e[0].baseline)??null:null,de=ce?.find(e=>e.id===H)??ce?.find(e=>gz(e)&&e.status!==`queued`)??ce?.[0]??null,fe=E||h?.model||``,me=[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`,fe&&fe!==h?.model&&fe].filter(Boolean);return(0,G.jsxs)(`section`,{className:`rt-view`,children:[(0,G.jsx)(`header`,{className:`rt-view-head`,children:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`eyebrow`,children:`PLAYGROUND`}),(0,G.jsx)(`h1`,{children:`Rerun it from any step`}),(0,G.jsxs)(`p`,{className:`rt-muted rt-sub`,children:[mz(e.title,120),` · `,hz(e.startedAt)]})]})}),(0,G.jsxs)(`div`,{className:`pg-layout`,ref:ee,children:[(0,G.jsxs)(`nav`,{className:`pg-rounds`,"aria-label":`Steps`,children:[(0,G.jsx)(`h2`,{children:`1 · Pick a step`}),(0,G.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,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,className:e.id===p?`on`:``,onClick:()=>i(e.id),disabled:!f.forkable,children:[(0,G.jsxs)(`span`,{children:[`Round trip `,t+1,r?(0,G.jsxs)(`em`,{children:[r,` fork`,r===1?``:`s`]}):null]}),n.length?n.map(e=>(0,G.jsxs)(`code`,{children:[`#`,l.get(e.call_id),` `,e.name,` `,mz(e.proposed??``,60)]},e.call_id)):(0,G.jsx)(`small`,{children:`answered`})]})},e.id)})}),(0,G.jsx)(uz,{target:ee,variable:`--pg-steps`,storageKey:`raytace.playground-steps-width`,min:220,max:760,label:`Steps width`})]}),(0,G.jsxs)(`div`,{className:`pg-main`,children:[!f.forkable&&(0,G.jsxs)(`div`,{className:`pg-unforkable`,role:`note`,children:[(0,G.jsx)(`strong`,{children:f.where===`mac`?`This run can’t be forked`:f.where===`fork`?`This is a fork`:`Not forkable yet`}),(0,G.jsx)(`p`,{children:f.reason})]}),f.forkable&&!p&&(0,G.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,G.jsx)(rp,{label:`Checking whether this step can be forked…`}),p&&h&&!h.forkable&&(0,G.jsx)(`p`,{className:`pg-error`,children:h.reason}),p&&h?.forkable&&(0,G.jsxs)(`section`,{className:`pg-change`,children:[(0,G.jsxs)(`h2`,{children:[`2 · Change what it had `,(0,G.jsxs)(`small`,{children:[`then round trip `,m+1,` onward runs again, in its own sandbox`]})]}),(0,G.jsx)(`h3`,{children:`Message at this step`}),(0,G.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,G.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,G.jsx)(`h3`,{children:`Exclude files`}),(0,G.jsxs)(`form`,{className:`pg-file-pick`,onSubmit:e=>{e.preventDefault(),ne()},children:[(0,G.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,G.jsx)(`datalist`,{id:`pg-project-files`,children:I.slice(0,2e3).map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))}),(0,G.jsx)(`button`,{type:`submit`,className:`rt-button`,disabled:!w.trim(),children:`Exclude`})]}),S.length>0&&(0,G.jsx)(`ul`,{className:`pg-excluded`,children:S.map(e=>{let t=W(e),n=!I.length||I.includes(e);return(0,G.jsxs)(`li`,{children:[(0,G.jsx)(`code`,{children:e}),(0,G.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,G.jsx)(`button`,{type:`button`,"aria-label":`Stop excluding ${e}`,onClick:()=>C(t=>t.filter(t=>t!==e)),children:(0,G.jsx)(Me,{size:12})})]},e)})}),(0,G.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,G.jsxs)(`h3`,{children:[`Check `,(0,G.jsx)(`small`,{children:`how to tell whether it worked`})]}),(0,G.jsx)(`input`,{className:`pg-check-input`,value:P??oe,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,G.jsx)(`p`,{className:`pg-note`,children:oe?`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,G.jsxs)(`div`,{className:`pg-run-bar`,children:[(0,G.jsxs)(`label`,{children:[`Model `,(0,G.jsx)(`select`,{value:fe,onChange:e=>D(e.target.value),children:[...new Set([h.model,...fz].filter(Boolean))].map(e=>(0,G.jsxs)(`option`,{value:e,children:[e,e===h.model?` (original)`:``]},e))})]}),(0,G.jsxs)(`label`,{children:[`Runs `,(0,G.jsx)(`select`,{value:A,onChange:e=>j(Number(e.target.value)),children:vz.filter(e=>e<=(h.limits?.max_repeat??1/0)).map(e=>(0,G.jsx)(`option`,{value:e,children:e===1?`once`:`${e} times`},e))})]}),(0,G.jsxs)(`button`,{type:`button`,className:`pg-run-button`,onClick:ie,disabled:R||ae,children:[(0,G.jsx)(pe,{size:14}),` `,ae?`A fork is running`:R?`Starting…`:`${me.length?`Run fork · ${me.join(`, `)}`:`Run fork unchanged`}${A>1?` · ×${A}`:``}${M&&me.length&&!le?` + unchanged ×${A}`:``}`]})]}),me.length>0&&(0,G.jsxs)(`label`,{className:`pg-baseline-pick`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:M,onChange:e=>N(e.target.checked)}),le?(()=>{let e=Oz(le);return`Compare with the unchanged runs already done (×${le.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,G.jsxs)(`p`,{className:`pg-note`,children:[`Runs one after another, each from the same point`,oe?`, each graded by the check`:``,`. `,oe?``:`Without a check there is no pass rate, only how the runs compare. `,me.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,G.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.`}),R&&(0,G.jsx)(rp,{label:`Starting the fork…`,compact:!0}),B&&(0,G.jsx)(`p`,{role:`alert`,className:`pg-error`,children:B}),(0,G.jsxs)(`details`,{className:`pg-advanced`,open:!!n||void 0,children:[(0,G.jsx)(`summary`,{children:`Advanced`}),(0,G.jsx)(`h3`,{children:`Tool results it had seen`}),h.results?.length?(0,G.jsx)(`ul`,{className:`pg-results`,children:h.results.map(e=>{let t=g[e.call_id],n=!t&&te.has(e.call_id);return(0,G.jsxs)(`li`,{className:t?`edited ${t.mode}`:n?`edited remove`:``,children:[(0,G.jsxs)(`div`,{className:`pg-result-row`,children:[(0,G.jsxs)(`b`,{children:[`#`,l.get(e.call_id)??`?`,` `,e.name]}),(0,G.jsx)(`code`,{title:e.detail,children:mz(e.detail,90)}),(0,G.jsx)(`small`,{children:n?`removed with ${te.get(e.call_id)}`:`~${Math.round(e.chars/4).toLocaleString()} tokens`}),(0,G.jsx)(`span`,{className:`rt-actions`,children:t?(0,G.jsxs)(`button`,{type:`button`,className:`link-button`,onClick:()=>v(({[e.call_id]:t,...n})=>n),children:[(0,G.jsx)(Me,{size:12}),` Undo`]}):(0,G.jsxs)(G.Fragment,{children:[!n&&(0,G.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>v(t=>({...t,[e.call_id]:{mode:`remove`,text:pz}})),children:`Remove`}),!e.truncated&&(0,G.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>v(t=>({...t,[e.call_id]:{mode:`edit`,text:e.output}})),children:`Edit`})]})})]}),t&&(0,G.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,G.jsx)(`p`,{className:`pg-note`,children:`No tool results before this step: it comes straight after the prompt.`}),(0,G.jsxs)(`label`,{className:`pg-limit`,children:[`Safety limit `,(0,G.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,G.jsxs)(`option`,{value:e,children:[e,` min`]},e))}),(0,G.jsx)(`span`,{className:`pg-note`,children:`The fork ends when Claude Code finishes; this only stops one that runs away.`})]})]})]}),p&&(0,G.jsxs)(`section`,{className:`pg-runs`,children:[(0,G.jsxs)(`h2`,{children:[`3 · Runs `,se.length>1&&(0,G.jsxs)(`small`,{children:[se.length,` from this step`]})]}),se.length>1&&(0,G.jsx)(`div`,{className:`pg-run-tabs`,children:se.map((e,t)=>{let n=e.filter(yz),r=e.length>1?n.length?` · ${n.filter(e=>e.check?.status===`passed`).length}/${n.length} ✓`:``:yz(e[0])?` · ${e[0].check?.status===`passed`?`✓`:`✗`}`:``;return(0,G.jsxs)(`button`,{type:`button`,className:e===ce?`on`:``,onClick:()=>U(e[0].id),children:[(0,G.jsx)(re,{size:12}),` `,se.length-t,e[0].unchanged?` · unchanged`:``,e.length>1?` · ×${e.length}`:``,` · `,e.some(gz)?`Running`:_z[e[0].status],r,e.some(e=>e.keep)?` · kept`:``]},e[0].id)})}),ce&&ue(ce)&&(0,G.jsx)(Az,{change:ce,base:ue(ce),onShow:U}),ce&&ce.length>1&&(0,G.jsx)(jz,{runs:ce,shown:de?.id??null,onShow:U,onChanged:d}),de?(0,G.jsx)(Dz,{fork:de,trace:e,fromIndex:m,onChanged:d,onOpenTrace:a,forkTrace:r.filter(e=>e.forkId===de.id).at(0)??null},de.id):(0,G.jsx)(`p`,{className:`pg-note`,children:`No forks from this step yet.`})]})]})]})]})}function Nz({text:e,label:t=`Copy`,noun:n=`command`,variant:r=`copy`,title:i}){let[a,o]=(0,_.useState)(`idle`),[s,c]=(0,_.useState)(!1),l=(0,_.useRef)(void 0),u=(0,_.useRef)(0);(0,_.useEffect)(()=>(u.current+=1,o(`idle`),()=>{u.current+=1,clearTimeout(l.current)}),[e]);async function d(){let t=u.current;clearTimeout(l.current),o(`copying`);try{if(!navigator.clipboard)throw Error(`Clipboard unavailable`);if(await navigator.clipboard.writeText(typeof e==`function`?e():e),t!==u.current)return;o(`copied`),l.current=setTimeout(()=>o(`idle`),1800)}catch{t===u.current&&o(`error`)}}let f=r===`share`,p=a===`copied`?f?`Link copied`:`Copied`:a===`copying`?`Copying…`:a===`error`?`Retry copy`:t;return(0,G.jsxs)(`span`,{className:`rt-copy-control`,children:[(0,G.jsxs)(`button`,{type:`button`,className:`rt-button rt-motion-button rt-copy-button${f?` rt-share-button`:``}`,"data-state":a,disabled:a===`copying`,onClick:()=>void d(),"aria-label":a===`copied`?`${n} copied`:`${p} ${n}`,title:i,onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),onFocus:()=>c(!0),onBlur:()=>c(!1),children:[(0,G.jsx)(nz,{first:f?oe:H,second:a===`copied`?z:ye,active:a===`copied`||f&&s}),(0,G.jsx)(`span`,{children:p})]}),(0,G.jsx)(`span`,{className:a===`error`?`rt-copy-error`:`rt-sr-only`,role:`status`,children:a===`copied`?`${f?`Local dashboard link`:n[0].toUpperCase()+n.slice(1)} copied to clipboard.`:a===`error`?`Could not copy. Select the text and copy it manually, or retry.`:``})]})}function Pz({traceId:e}){let t=(0,_.useCallback)(()=>{let t=new URL(window.location.pathname,window.location.origin);return t.searchParams.set(`trace`,e),t.href},[e]);return(0,G.jsx)(Nz,{text:t,label:`Share`,noun:`prompt link`,variant:`share`,title:`Copy a link to this prompt. This local address works only on this computer; it does not publish your traces.`})}var Fz=53,Iz=[``,`Mon`,``,`Wed`,``,`Fri`,``];function Lz(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}`}var Rz=()=>()=>{},zz=()=>Lz(Date.now()),Bz=e=>e===0?0:e===1?1:e<=3?2:e<=6?3:4;function Vz({dates:e,selected:t,onSelect:n}){let r=(0,_.useSyncExternalStore)(Rz,zz,()=>null),i=new Map;for(let t of e)i.set(Lz(t),(i.get(Lz(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<Fz;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,G.jsxs)(`section`,{className:`rt-activity`,"aria-label":`Prompts per day`,children:[(0,G.jsxs)(`div`,{className:`rt-activity-head`,children:[(0,G.jsxs)(`strong`,{children:[l,` prompt`,l===1?``:`s`]}),(0,G.jsxs)(`span`,{children:[`on `,u,` day`,u===1?``:`s`,` in the last year`]})]}),r&&(0,G.jsx)(`div`,{className:`rt-activity-scroll`,children:(0,G.jsxs)(`div`,{className:`rt-activity-grid`,style:{gridTemplateColumns:`28px repeat(${Fz}, 12px)`},children:[(0,G.jsx)(`span`,{}),c.map((e,t)=>(0,G.jsx)(`span`,{className:`rt-activity-month`,children:e},t)),Iz.map((e,r)=>[(0,G.jsx)(`span`,{className:`rt-activity-day`,children:e},`label-${r}`),...s.map(e=>{let o=e[r];if(o>a)return(0,G.jsx)(`span`,{},Lz(o));let s=Lz(o),c=i.get(s)??0,l=`${c} prompt${c===1?``:`s`} · ${o.toLocaleDateString(void 0,{day:`numeric`,month:`short`,year:`numeric`})}`;return(0,G.jsx)(`button`,{type:`button`,title:l,"aria-label":l,"aria-pressed":t===s,disabled:!c,className:`rt-cell rt-cell-${Bz(c)}${t===s?` rt-cell-on`:``}`,onClick:()=>n(t===s?null:s)},s)})])]})}),(0,G.jsxs)(`div`,{className:`rt-activity-legend`,children:[`Less `,[0,1,2,3,4].map(e=>(0,G.jsx)(`i`,{className:`rt-cell rt-cell-${e}`},e)),` More`]})]})}var Hz=e=>e.split(`
|
|
@@ -6,7 +6,7 @@
|
|
|
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?v=raytrace-box-1" type="image/svg+xml" />
|
|
9
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
+
<script type="module" crossorigin src="/assets/index-BnYr54S5.js"></script>
|
|
10
10
|
<link rel="stylesheet" crossorigin href="/assets/index-B5ndFs_A.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body class="antialiased">
|
package/package.json
CHANGED
package/src/local-sandbox.mjs
CHANGED
|
@@ -108,7 +108,10 @@ export function vmStatus() {
|
|
|
108
108
|
|
|
109
109
|
function setupVersion() {
|
|
110
110
|
const hash = createHash('sha256');
|
|
111
|
-
|
|
111
|
+
// Files only: a __pycache__ left by running the tests there is no part of what is installed.
|
|
112
|
+
for (const entry of readdirSync(SOURCE, { withFileTypes: true }).sort((a, b) => (a.name < b.name ? -1 : 1))) {
|
|
113
|
+
if (entry.isFile()) hash.update(entry.name).update(readFileSync(join(SOURCE, entry.name)));
|
|
114
|
+
}
|
|
112
115
|
return hash.digest('hex').slice(0, 16);
|
|
113
116
|
}
|
|
114
117
|
|
package/worker/sandbox/engine.py
CHANGED
|
@@ -7,10 +7,11 @@ keeps what matters as a fact, counts the rest and stores no event at all.
|
|
|
7
7
|
|
|
8
8
|
What matters:
|
|
9
9
|
|
|
10
|
-
files
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
the
|
|
10
|
+
files every file of the project (outside node_modules and the
|
|
11
|
+
like): created, changed, emptied, appended, deleted, renamed,
|
|
12
|
+
or an attempt the kernel refused. A read is a fact as well for
|
|
13
|
+
a file the project's owner restricted or watches and one whose
|
|
14
|
+
path marks it sensitive (a .env, a key); other reads are counted
|
|
14
15
|
network every connection out of the sandbox, one fact for each
|
|
15
16
|
destination a step reached, and whether the firewall refuses it
|
|
16
17
|
packages what a package manager left installed once it had run
|
|
@@ -83,6 +84,7 @@ ERRNO = {**REFUSED, 2: 'ENOENT', 101: 'ENETUNREACH', 110: 'ETIMEDOUT', 111: 'ECO
|
|
|
83
84
|
EINPROGRESS = 115
|
|
84
85
|
MAX_HASHED = 5 * 1024 * 1024 # a larger file is compared by size, time and inode
|
|
85
86
|
HASH_LIMIT = 2000 # with more files than this to keep, none is hashed up front
|
|
87
|
+
PROJECT_LIMIT = 20_000 # a project with more files than this keeps facts of listed and sensitive files only
|
|
86
88
|
SENSITIVE_FROM = 4 # file_scan's level from which a new file's path alone is worth a fact
|
|
87
89
|
SETTLE = 0.3 # seconds between a change seen on disk and looking: gVisor's call may still be on its way
|
|
88
90
|
WRITER_LIFE = 900 # how long an open for writing may explain a later change
|
|
@@ -99,7 +101,11 @@ MAX_PACKAGES = 400
|
|
|
99
101
|
REJECTED = [ipaddress.ip_network(block) for block in network.REJECTED]
|
|
100
102
|
OWN_KINDS = frozenset(['open', 'connect', 'listen', 'setid'])
|
|
101
103
|
PROCESS_KINDS = frozenset(['exec_succeeded', 'clone', 'process_exit', 'collection_gap', 'collector_disconnected'])
|
|
102
|
-
|
|
104
|
+
# Claude Code runs a command as `bash -c "... eval '<command>'"`: the export follows a quote.
|
|
105
|
+
CALL_MARKER = re.compile(r'(?:^|[\s;\'"])export RAYTRACE_CALL_ID=([A-Za-z0-9_-]{1,128})(?=[\s;]|$)')
|
|
106
|
+
# RayTrace's own hook in the sandbox: after each tool call it runs git over the
|
|
107
|
+
# whole project to keep a snapshot. What it and its children do is not the agent's doing.
|
|
108
|
+
OWN_HOOK = '/opt/raytace-claude/hook.mjs'
|
|
103
109
|
SANDBOX_ID = re.compile(r'rt[pf]-[a-f0-9]{32}')
|
|
104
110
|
|
|
105
111
|
|
|
@@ -174,6 +180,20 @@ def names_inside(root, path):
|
|
|
174
180
|
os.close(fd)
|
|
175
181
|
|
|
176
182
|
|
|
183
|
+
def link_inside(root, path):
|
|
184
|
+
"""Whether a project path is a symbolic link (read, not followed)."""
|
|
185
|
+
try:
|
|
186
|
+
folder = open_inside(root, posixpath.dirname(path), directory=True)
|
|
187
|
+
except (OSError, ValueError):
|
|
188
|
+
return False
|
|
189
|
+
try:
|
|
190
|
+
return stat.S_ISLNK(os.stat(posixpath.basename(path), dir_fd=folder, follow_symlinks=False).st_mode)
|
|
191
|
+
except OSError:
|
|
192
|
+
return False
|
|
193
|
+
finally:
|
|
194
|
+
os.close(folder)
|
|
195
|
+
|
|
196
|
+
|
|
177
197
|
def change(before, after, events, flags):
|
|
178
198
|
"""What happened to a file between two photos, or None when nothing did."""
|
|
179
199
|
if after is None:
|
|
@@ -252,6 +272,7 @@ class Inotify:
|
|
|
252
272
|
"""The host kernel's file notifications, for the folders of the files
|
|
253
273
|
worth a fact. It names the file a delete or rename hit, which gVisor does not."""
|
|
254
274
|
CLOSE_WRITE, MODIFY, ATTRIB, CREATE, DELETE, MOVED_FROM, MOVED_TO = 0x8, 0x2, 0x4, 0x100, 0x200, 0x40, 0x80
|
|
275
|
+
ISDIR = 0x40000000
|
|
255
276
|
DELETE_SELF, MOVE_SELF, OVERFLOW, IGNORED, ONLYDIR = 0x400, 0x800, 0x4000, 0x8000, 0x01000000
|
|
256
277
|
WORDS = [(CLOSE_WRITE, 'close_write'), (MODIFY, 'modify'), (ATTRIB, 'attrib'), (CREATE, 'create'), (DELETE, 'delete'),
|
|
257
278
|
(MOVED_FROM, 'moved_from'), (MOVED_TO, 'moved_to')]
|
|
@@ -298,7 +319,8 @@ class Sandbox:
|
|
|
298
319
|
self.fork = False
|
|
299
320
|
self.mapped = self.guarded_at = None # the two files' times, as last read
|
|
300
321
|
self.restricted, self.watched, self.sensitive = set(), set(), set()
|
|
301
|
-
self.
|
|
322
|
+
self.project = False # every project file is kept, not only the listed and sensitive ones
|
|
323
|
+
self.guarded = {} # path -> restricted | watched | sensitive | project
|
|
302
324
|
self.hashing = True
|
|
303
325
|
self.photos = {} # path -> its last photo; None: it was not there
|
|
304
326
|
self.known = None # project paths that exist, to tell a new file from an old one
|
|
@@ -489,7 +511,9 @@ class Engine(threading.Thread):
|
|
|
489
511
|
for folder, folders, files in os.walk(workspace):
|
|
490
512
|
folders[:] = [name for name in folders if name not in SKIPPED]
|
|
491
513
|
inside = os.path.relpath(folder, workspace)
|
|
492
|
-
|
|
514
|
+
# Not links: a link is a name for another file, and that file is the one kept.
|
|
515
|
+
box.known.update(name if inside == '.' else inside + '/' + name for name in files
|
|
516
|
+
if not os.path.islink(os.path.join(folder, name)))
|
|
493
517
|
if len(box.known) > 200_000:
|
|
494
518
|
break
|
|
495
519
|
box.packages = installed(workspace, box.home)
|
|
@@ -508,12 +532,17 @@ class Engine(threading.Thread):
|
|
|
508
532
|
kept = {}
|
|
509
533
|
box.restricted = {path for path in kept.get('restricted') or [] if isinstance(path, str)}
|
|
510
534
|
box.watched = {path for path in kept.get('watched') or [] if isinstance(path, str)}
|
|
535
|
+
# Every project file, unless the lists say `"project": false` or there are too many to watch.
|
|
536
|
+
box.project = kept.get('project') is not False and box.known is not None and len(box.known) <= PROJECT_LIMIT
|
|
537
|
+
if box.project:
|
|
538
|
+
box.sensitive.update(path for path in box.known if file_scan.created_entry(path)['level'] >= SENSITIVE_FROM)
|
|
511
539
|
self.guard(box)
|
|
512
540
|
self.arm(box)
|
|
513
541
|
|
|
514
542
|
def guard(self, box):
|
|
515
543
|
"""The files to keep facts of, each with a first photo to compare later ones with."""
|
|
516
|
-
guarded = {path: '
|
|
544
|
+
guarded = {path: 'project' for path in box.known} if box.project else {}
|
|
545
|
+
guarded.update({path: 'sensitive' for path in box.sensitive})
|
|
517
546
|
guarded.update({path: 'watched' for path in box.watched})
|
|
518
547
|
guarded.update({path: 'restricted' for path in box.restricted})
|
|
519
548
|
box.hashing = len(guarded) <= HASH_LIMIT
|
|
@@ -540,6 +569,20 @@ class Engine(threading.Thread):
|
|
|
540
569
|
box.watches[folder] = watch
|
|
541
570
|
self.watched[watch] = (box, folder)
|
|
542
571
|
|
|
572
|
+
def cover(self, box, path, first=None):
|
|
573
|
+
"""A project file that appeared while the sandbox ran: kept from now
|
|
574
|
+
on. `first` is what it is compared with: None, it was not there."""
|
|
575
|
+
box.known.add(path)
|
|
576
|
+
box.guarded[path], box.photos[path] = 'project', first
|
|
577
|
+
folder = posixpath.dirname(path)
|
|
578
|
+
if self.inotify and folder not in box.watches:
|
|
579
|
+
try:
|
|
580
|
+
watch = self.inotify.add(box.workspace, folder)
|
|
581
|
+
except (OSError, ValueError):
|
|
582
|
+
return
|
|
583
|
+
box.watches[folder] = watch
|
|
584
|
+
self.watched[watch] = (box, folder)
|
|
585
|
+
|
|
543
586
|
def unwatch(self, box, folder):
|
|
544
587
|
watch = box.watches.pop(folder, None)
|
|
545
588
|
if watch is not None and self.watched.pop(watch, None):
|
|
@@ -565,7 +608,9 @@ class Engine(threading.Thread):
|
|
|
565
608
|
box.processes[pid] = {'start_ns': event.get('process_start_ns'), 'ppid': event.get('ppid'),
|
|
566
609
|
'name': posixpath.basename(event.get('executable') or (argv[0] if argv else '')) or event.get('process_name'),
|
|
567
610
|
'argv': [part[:400] for part in argv[:24]],
|
|
568
|
-
'call_id': marker or known.get('call_id') or parent.get('call_id')
|
|
611
|
+
'call_id': marker or known.get('call_id') or parent.get('call_id'),
|
|
612
|
+
'own': bool(known.get('own') or parent.get('own')
|
|
613
|
+
or (len(argv) > 1 and argv[1] == OWN_HOOK and posixpath.basename(argv[0]) == 'node'))}
|
|
569
614
|
if len(box.processes) > 20_000: # exits that never arrived: forget the oldest half
|
|
570
615
|
for stale in list(box.processes)[:10_000]:
|
|
571
616
|
del box.processes[stale]
|
|
@@ -596,7 +641,7 @@ class Engine(threading.Thread):
|
|
|
596
641
|
parent = box.processes.get(event.get('ppid')) or {}
|
|
597
642
|
return {'pid': pid, 'start_ns': known.get('start_ns') or event.get('process_start_ns'),
|
|
598
643
|
'name': known.get('name') or event.get('process_name') or None, 'argv': known.get('argv') or [],
|
|
599
|
-
'call_id': known.get('call_id') or parent.get('call_id')}
|
|
644
|
+
'call_id': known.get('call_id') or parent.get('call_id'), 'own': bool(known.get('own') or parent.get('own'))}
|
|
600
645
|
|
|
601
646
|
# ------------------------------------------------------------ facts
|
|
602
647
|
|
|
@@ -693,6 +738,9 @@ class Engine(threading.Thread):
|
|
|
693
738
|
self.guard(box)
|
|
694
739
|
self.arm(box)
|
|
695
740
|
guard = 'sensitive'
|
|
741
|
+
elif box.project and not link_inside(box.workspace, path):
|
|
742
|
+
self.cover(box, path)
|
|
743
|
+
guard = 'project'
|
|
696
744
|
if guard is None:
|
|
697
745
|
if writing and not errno and box.guarded:
|
|
698
746
|
box.aliases.append({'path': path, 'who': who, 'at_ns': at_ns, 'syscall': self.calls.get(event.get('sysno'), ('open', 'open'))[0]})
|
|
@@ -706,10 +754,16 @@ class Engine(threading.Thread):
|
|
|
706
754
|
'basis': {**basis, 'errno': REFUSED[errno]}}, at_ns)
|
|
707
755
|
return
|
|
708
756
|
if not writing:
|
|
757
|
+
# Reads of ordinary files are counted, as before: a test run reads hundreds.
|
|
758
|
+
# So is the snapshot hook reading every file after each tool call.
|
|
759
|
+
if guard == 'project' or who.get('own'):
|
|
760
|
+
return self.counted(box, who, top, at_ns)
|
|
709
761
|
self.fact(box, 'file', (path, 'read'), who, {'path': path, 'guard': guard, 'effect': 'read', 'certainty': 'confirmed',
|
|
710
762
|
'basis': {**basis, 'note': 'opened for reading; the bytes read are not captured'}}, at_ns)
|
|
711
763
|
return
|
|
712
764
|
now = self.clock()
|
|
765
|
+
if guard == 'project': # it may be a hard link to another kept file: see linked()
|
|
766
|
+
box.aliases.append({'path': path, 'who': who, 'at_ns': at_ns, 'syscall': call})
|
|
713
767
|
box.writers.setdefault(path, []).append({'who': who, 'at_ns': at_ns, 'flags': flags, 'syscall': call, 'credited': False, 'seen': now})
|
|
714
768
|
box.due[path] = min(box.due.get(path, now + 1), now + 1)
|
|
715
769
|
box.final[path] = now + 30
|
|
@@ -753,8 +807,9 @@ class Engine(threading.Thread):
|
|
|
753
807
|
if not at or path.startswith(at + '/'):
|
|
754
808
|
found.setdefault(path, 'argv_folder')
|
|
755
809
|
if not found:
|
|
810
|
+
# Not for ordinary project files: a short name is in any text.
|
|
756
811
|
text = ' '.join(who.get('argv') or [])
|
|
757
|
-
found = {path: 'argv_text' for path in box.guarded if path in text}
|
|
812
|
+
found = {path: 'argv_text' for path, guard in box.guarded.items() if guard != 'project' and path in text}
|
|
758
813
|
return sorted(found.items())[:5]
|
|
759
814
|
|
|
760
815
|
def actors(self, box, rule, at_ns, path):
|
|
@@ -762,7 +817,9 @@ class Engine(threading.Thread):
|
|
|
762
817
|
about when the watcher saw `path` change, likeliest first."""
|
|
763
818
|
found = {}
|
|
764
819
|
for call in box.raw:
|
|
765
|
-
|
|
820
|
+
# (Not the snapshot hook's git, which renames its own index beside every tool call.)
|
|
821
|
+
if (call['rule'] == rule and not call['errno'] and not call['who'].get('own')
|
|
822
|
+
and at_ns - RAW_WINDOW[0] <= call['at_ns'] <= at_ns + RAW_WINDOW[1]):
|
|
766
823
|
found.setdefault((call['who']['pid'], call['who']['start_ns']), call)
|
|
767
824
|
names = lambda call: any(posixpath.basename(path) == posixpath.basename(part) for part in call['who']['argv'])
|
|
768
825
|
ranked = sorted(found.values(), key=lambda call: (not names(call), abs(call['at_ns'] - at_ns)))
|
|
@@ -775,6 +832,10 @@ class Engine(threading.Thread):
|
|
|
775
832
|
events = self.inotify.read()
|
|
776
833
|
moved = {cookie: posixpath.join(self.watched[watch][1], name) for watch, mask, cookie, name in events
|
|
777
834
|
if mask & Inotify.MOVED_TO and watch in self.watched}
|
|
835
|
+
# Kept files that were renamed: the new name is the same file, not a new one.
|
|
836
|
+
renamed = {cookie: posixpath.join(self.watched[watch][1], name) for watch, mask, cookie, name in events
|
|
837
|
+
if mask & Inotify.MOVED_FROM and watch in self.watched
|
|
838
|
+
and posixpath.join(self.watched[watch][1], name) in self.watched[watch][0].guarded}
|
|
778
839
|
for watch, mask, cookie, name in events:
|
|
779
840
|
if mask & Inotify.OVERFLOW: # the kernel dropped notices: look at everything again
|
|
780
841
|
for box in self.boxes.values():
|
|
@@ -796,11 +857,40 @@ class Engine(threading.Thread):
|
|
|
796
857
|
self.noticed(box, path, [])
|
|
797
858
|
continue
|
|
798
859
|
path = posixpath.join(folder, name)
|
|
860
|
+
if path not in box.guarded and box.project and mask & (Inotify.CREATE | Inotify.MOVED_TO) and name not in SKIPPED:
|
|
861
|
+
self.appeared(box, path, bool(mask & Inotify.ISDIR), renamed.get(cookie))
|
|
799
862
|
if path in box.guarded:
|
|
800
863
|
self.noticed(box, path, [word for bit, word in Inotify.WORDS if mask & bit],
|
|
801
864
|
moved.get(cookie) if mask & Inotify.MOVED_FROM else None)
|
|
802
865
|
return len(events)
|
|
803
866
|
|
|
867
|
+
def appeared(self, box, path, folder, source=None):
|
|
868
|
+
"""A name the watcher saw arrive in a project that is kept whole, with
|
|
869
|
+
no open that created it: a file moved in, or a folder with its files.
|
|
870
|
+
`source` is the kept file it was renamed from, if it was one."""
|
|
871
|
+
renamed = source is not None
|
|
872
|
+
if not folder:
|
|
873
|
+
if len(box.guarded) < PROJECT_LIMIT:
|
|
874
|
+
# A kept file under its new name has its `renamed` fact already.
|
|
875
|
+
# Not one that was never looked at under its old name: a file
|
|
876
|
+
# written under a temporary name and moved here, as an agent's
|
|
877
|
+
# Write tool saves a new file. That is this file being created.
|
|
878
|
+
seen = renamed and box.photos.get(source) is not None
|
|
879
|
+
self.cover(box, path, photo(box.workspace, path, box.hashing) if seen else None)
|
|
880
|
+
return
|
|
881
|
+
folders = [path]
|
|
882
|
+
while folders and len(box.guarded) < PROJECT_LIMIT:
|
|
883
|
+
at = folders.pop()
|
|
884
|
+
for name in names_inside(box.workspace, at):
|
|
885
|
+
below = posixpath.join(at, name)
|
|
886
|
+
if name in SKIPPED or below in box.guarded:
|
|
887
|
+
continue
|
|
888
|
+
if photo(box.workspace, below, False) is not None:
|
|
889
|
+
self.cover(box, below)
|
|
890
|
+
self.noticed(box, below, ['moved_to' if renamed else 'create'])
|
|
891
|
+
else:
|
|
892
|
+
folders.append(below) # no folder, or an empty one, lists nothing
|
|
893
|
+
|
|
804
894
|
def noticed(self, box, path, words, moved_to=None):
|
|
805
895
|
"""The watcher saw something of a file: look at it once things settle."""
|
|
806
896
|
cause = box.causes.setdefault(path, {'events': set(), 'at_ns': time.time_ns()})
|
|
@@ -822,7 +912,8 @@ class Engine(threading.Thread):
|
|
|
822
912
|
writers = box.writers[path] = [writer for writer in box.writers.get(path, [])
|
|
823
913
|
if now - writer['seen'] < WRITER_LIFE and not writer.get('settled')]
|
|
824
914
|
before = box.photos.get(path)
|
|
825
|
-
|
|
915
|
+
# With too many files to hash up front, one that was seen to change is still hashed here.
|
|
916
|
+
after = photo(box.workspace, path, box.hashing or (box.project and bool(cause['events'] or writers)))
|
|
826
917
|
flags = 0
|
|
827
918
|
for writer in writers:
|
|
828
919
|
flags |= writer['flags']
|
|
@@ -870,7 +961,9 @@ class Engine(threading.Thread):
|
|
|
870
961
|
fact['basis']['after'] = after
|
|
871
962
|
if cause.get('to'):
|
|
872
963
|
fact['to'] = cause['to']
|
|
873
|
-
elif final:
|
|
964
|
+
elif final and not (guard == 'project' and before is None and after is None):
|
|
965
|
+
# (An ordinary file that came and went between two looks, as the
|
|
966
|
+
# temporary file of an editor's save does, is not worth a line.)
|
|
874
967
|
for writer in writers:
|
|
875
968
|
if not writer['credited']:
|
|
876
969
|
writer['credited'] = True
|
|
@@ -883,6 +976,11 @@ class Engine(threading.Thread):
|
|
|
883
976
|
writer['settled'] = True
|
|
884
977
|
if not writers:
|
|
885
978
|
box.writers.pop(path, None)
|
|
979
|
+
if guard == 'project' and after is None and (effect or final):
|
|
980
|
+
# Gone: nothing more to compare. It is kept again if it comes back.
|
|
981
|
+
box.guarded.pop(path, None)
|
|
982
|
+
box.photos.pop(path, None)
|
|
983
|
+
box.known.discard(path)
|
|
886
984
|
|
|
887
985
|
def linked(self, box, path, after, at_ns):
|
|
888
986
|
"""A recent open for writing of another name that is this file: a hard
|
|
@@ -211,5 +211,162 @@ class FailedExecs(unittest.TestCase):
|
|
|
211
211
|
self.assertNotIn('raw_packet_base64', json.loads(json.dumps(failed)))
|
|
212
212
|
|
|
213
213
|
|
|
214
|
+
|
|
215
|
+
class EveryProjectFile(unittest.TestCase):
|
|
216
|
+
"""A project kept whole: what happens to any of its files is a fact, not
|
|
217
|
+
only to the files on a list."""
|
|
218
|
+
SID = 'rtp-' + 'a' * 32
|
|
219
|
+
|
|
220
|
+
def setUp(self):
|
|
221
|
+
self.now = 1000.0
|
|
222
|
+
self.engine = engine.Engine(':memory:', arch='aarch64', watch=False, clock=lambda: self.now)
|
|
223
|
+
self.folder = tempfile.TemporaryDirectory()
|
|
224
|
+
self.state = tempfile.TemporaryDirectory()
|
|
225
|
+
self.addCleanup(self.folder.cleanup)
|
|
226
|
+
self.addCleanup(self.state.cleanup)
|
|
227
|
+
for name in ('CONTAINERS', 'GUARDRAILS', 'PROJECT_LIMIT'):
|
|
228
|
+
self.addCleanup(setattr, engine, name, getattr(engine, name))
|
|
229
|
+
engine.CONTAINERS = engine.GUARDRAILS = Path(self.state.name)
|
|
230
|
+
for name, text in (('src/app.js', 'one'), ('config/payment-keys.js', 'key'), ('node_modules/x/index.js', 'x')):
|
|
231
|
+
self.write(name, text)
|
|
232
|
+
(Path(self.state.name) / ('c' * 64 + '.json')).write_text(json.dumps({'id': self.SID, 'workspace': self.folder.name}))
|
|
233
|
+
self.box = engine.Sandbox('c' * 64)
|
|
234
|
+
self.box.processes[10] = {'start_ns': '10', 'ppid': 1, 'name': 'sed', 'argv': ['sed'], 'call_id': 'call_10'}
|
|
235
|
+
|
|
236
|
+
def write(self, name, text):
|
|
237
|
+
path = Path(self.folder.name) / name
|
|
238
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
239
|
+
path.write_text(text)
|
|
240
|
+
|
|
241
|
+
def opened(self, name, flags=engine.O_TRUNC | 1):
|
|
242
|
+
self.engine.opened(self.box, {'kind': 'open', 'pathname': '/workspace/' + name, 'flags': flags, 'errno': 0, 'pid': 10,
|
|
243
|
+
'ppid': 1, 'process_start_ns': '10', 'timestamp_ns': str(time.time_ns()), 'sysno': 56})
|
|
244
|
+
|
|
245
|
+
def looked(self, name, *words, final=False):
|
|
246
|
+
if words:
|
|
247
|
+
self.engine.noticed(self.box, name, list(words))
|
|
248
|
+
self.engine.look(self.box, name, final=final)
|
|
249
|
+
return [(fact['path'], fact['effect'], fact['guard'], fact['call_id']) for fact in self.engine.facts.values() if fact['kind'] == 'file']
|
|
250
|
+
|
|
251
|
+
def test_every_file_outside_the_skipped_folders_is_kept(self):
|
|
252
|
+
self.engine.refresh(self.box)
|
|
253
|
+
self.assertEqual(self.box.guarded, {'src/app.js': 'project', 'config/payment-keys.js': 'sensitive'})
|
|
254
|
+
|
|
255
|
+
def test_the_lists_can_turn_it_off_and_a_huge_project_is_not_kept_whole(self):
|
|
256
|
+
(Path(self.state.name) / (self.SID + '.json')).write_text(json.dumps({'restricted': [], 'watched': ['src/app.js'], 'project': False}))
|
|
257
|
+
self.engine.refresh(self.box)
|
|
258
|
+
self.assertEqual(self.box.guarded, {'src/app.js': 'watched'})
|
|
259
|
+
engine.PROJECT_LIMIT = 1
|
|
260
|
+
other = engine.Sandbox('c' * 64)
|
|
261
|
+
(Path(self.state.name) / (self.SID + '.json')).unlink()
|
|
262
|
+
self.engine.refresh(other)
|
|
263
|
+
self.assertEqual(other.guarded, {})
|
|
264
|
+
|
|
265
|
+
def test_an_edit_is_a_fact_and_a_read_is_counted(self):
|
|
266
|
+
self.engine.refresh(self.box)
|
|
267
|
+
self.opened('src/app.js', flags=0)
|
|
268
|
+
self.assertEqual(self.looked('src/app.js'), [])
|
|
269
|
+
self.opened('src/app.js')
|
|
270
|
+
self.write('src/app.js', 'two')
|
|
271
|
+
self.assertEqual(self.looked('src/app.js', 'modify', 'close_write'), [('src/app.js', 'changed', 'project', 'call_10')])
|
|
272
|
+
# A sensitive file that was there from the start: its read is a fact too.
|
|
273
|
+
self.opened('config/payment-keys.js', flags=0)
|
|
274
|
+
self.assertIn(('config/payment-keys.js', 'read', 'sensitive', 'call_10'), self.looked('config/payment-keys.js'))
|
|
275
|
+
|
|
276
|
+
def test_a_new_file_is_created_and_a_deleted_one_is_let_go(self):
|
|
277
|
+
self.engine.refresh(self.box)
|
|
278
|
+
self.opened('src/new.js', flags=engine.O_CREAT | 1)
|
|
279
|
+
self.write('src/new.js', 'new')
|
|
280
|
+
self.assertEqual(self.looked('src/new.js', 'create', 'close_write'), [('src/new.js', 'created', 'project', 'call_10')])
|
|
281
|
+
(Path(self.folder.name) / 'src/new.js').unlink()
|
|
282
|
+
self.assertIn(('src/new.js', 'deleted', 'project', None), self.looked('src/new.js', 'delete'))
|
|
283
|
+
self.assertNotIn('src/new.js', self.box.guarded)
|
|
284
|
+
self.assertNotIn('src/new.js', self.box.known)
|
|
285
|
+
|
|
286
|
+
def test_the_temporary_file_of_a_save_leaves_no_line(self):
|
|
287
|
+
self.engine.refresh(self.box)
|
|
288
|
+
self.opened('src/sedAbC', flags=engine.O_CREAT | 1)
|
|
289
|
+
self.write('src/sedAbC', 'two')
|
|
290
|
+
os.rename(Path(self.folder.name) / 'src/sedAbC', Path(self.folder.name) / 'src/app.js')
|
|
291
|
+
self.engine.numbered_call(self.box, {'kind': 'syscall_return', 'sysno': 38, 'errno': 0, 'pid': 10, 'ppid': 1,
|
|
292
|
+
'process_start_ns': '10', 'timestamp_ns': str(time.time_ns()), 'cwd': '/workspace'})
|
|
293
|
+
self.assertEqual(self.looked('src/app.js', 'moved_to'), [('src/app.js', 'changed', 'project', 'call_10')])
|
|
294
|
+
self.assertEqual(len(self.looked('src/sedAbC', 'moved_from', final=True)), 1)
|
|
295
|
+
self.assertNotIn('src/sedAbC', self.box.guarded)
|
|
296
|
+
|
|
297
|
+
def test_a_file_or_a_folder_moved_in_is_kept(self):
|
|
298
|
+
self.engine.refresh(self.box)
|
|
299
|
+
self.write('src/moved.js', 'm')
|
|
300
|
+
self.engine.appeared(self.box, 'src/moved.js', False)
|
|
301
|
+
self.assertEqual(self.looked('src/moved.js', 'moved_to'), [('src/moved.js', 'created', 'project', None)])
|
|
302
|
+
self.write('lib/deep/a.js', 'a')
|
|
303
|
+
self.write('lib/node_modules/b.js', 'b')
|
|
304
|
+
self.engine.appeared(self.box, 'lib', True)
|
|
305
|
+
self.assertEqual({path for path in self.box.guarded if path.startswith('lib/')}, {'lib/deep/a.js'})
|
|
306
|
+
# A kept file under a new name is the same file: no second line for it.
|
|
307
|
+
os.rename(Path(self.folder.name) / 'src/app.js', Path(self.folder.name) / 'src/main.js')
|
|
308
|
+
self.engine.appeared(self.box, 'src/main.js', False, 'src/app.js')
|
|
309
|
+
self.assertEqual([fact for fact in self.looked('src/main.js', 'moved_to') if fact[0] == 'src/main.js'], [])
|
|
310
|
+
|
|
311
|
+
RENAME = {'kind': 'syscall_return', 'sysno': 38, 'errno': 0, 'ppid': 1, 'cwd': '/workspace'}
|
|
312
|
+
|
|
313
|
+
def test_a_new_file_saved_under_a_temporary_name_is_created_by_the_mover(self):
|
|
314
|
+
"""How an agent's Write tool saves: it writes a temporary file and
|
|
315
|
+
renames it, while the snapshot hook's git renames its own index."""
|
|
316
|
+
self.engine.refresh(self.box)
|
|
317
|
+
self.engine.executed(self.box, {'pid': 30, 'ppid': 1, 'process_start_ns': '30', 'executable': '/usr/local/bin/node',
|
|
318
|
+
'argv': ['node', engine.OWN_HOOK]})
|
|
319
|
+
self.engine.executed(self.box, {'pid': 31, 'ppid': 30, 'process_start_ns': '31', 'executable': '/usr/bin/git', 'argv': ['git', 'add', '-A']})
|
|
320
|
+
self.opened('src/new.js.tmp.1', flags=engine.O_CREAT | 1)
|
|
321
|
+
self.write('src/new.js.tmp.1', 'new')
|
|
322
|
+
os.rename(Path(self.folder.name) / 'src/new.js.tmp.1', Path(self.folder.name) / 'src/new.js')
|
|
323
|
+
for pid in (31, 10):
|
|
324
|
+
self.engine.numbered_call(self.box, {**self.RENAME, 'pid': pid, 'process_start_ns': str(pid), 'timestamp_ns': str(time.time_ns())})
|
|
325
|
+
self.engine.appeared(self.box, 'src/new.js', False, 'src/new.js.tmp.1')
|
|
326
|
+
self.looked('src/new.js', 'moved_to')
|
|
327
|
+
(fact,) = self.engine.facts.values()
|
|
328
|
+
self.assertEqual((fact['path'], fact['effect'], fact['certainty'], fact['pid']), ('src/new.js', 'created', 'confirmed', 10))
|
|
329
|
+
|
|
330
|
+
def test_the_snapshot_hook_reading_every_file_is_counted_not_listed(self):
|
|
331
|
+
self.engine.refresh(self.box)
|
|
332
|
+
self.engine.executed(self.box, {'pid': 30, 'ppid': 1, 'process_start_ns': '30', 'executable': '/usr/local/bin/node',
|
|
333
|
+
'argv': ['node', engine.OWN_HOOK]})
|
|
334
|
+
self.engine.executed(self.box, {'pid': 31, 'ppid': 30, 'process_start_ns': '31', 'executable': '/usr/bin/git', 'argv': ['git', 'add', '-A']})
|
|
335
|
+
read = {'kind': 'open', 'pathname': '/workspace/config/payment-keys.js', 'flags': 0, 'errno': 0, 'ppid': 30,
|
|
336
|
+
'timestamp_ns': str(time.time_ns()), 'sysno': 56}
|
|
337
|
+
self.engine.opened(self.box, {**read, 'pid': 31, 'process_start_ns': '31'})
|
|
338
|
+
self.assertEqual([fact for fact in self.engine.facts.values() if fact['kind'] == 'file'], [])
|
|
339
|
+
# Anything else named like the hook is not it, and its read is a fact.
|
|
340
|
+
self.engine.executed(self.box, {'pid': 40, 'ppid': 1, 'process_start_ns': '40', 'executable': '/usr/local/bin/node',
|
|
341
|
+
'argv': ['node', '/tmp/hook.mjs']})
|
|
342
|
+
self.engine.opened(self.box, {**read, 'pid': 40, 'ppid': 1, 'process_start_ns': '40'})
|
|
343
|
+
self.assertEqual([fact['pid'] for fact in self.engine.facts.values() if fact['kind'] == 'file'], [40])
|
|
344
|
+
|
|
345
|
+
def test_the_shell_of_a_tool_call_carries_the_call_in_its_own_text(self):
|
|
346
|
+
"""Claude Code runs `bash -c "... eval '<command>'"`: a redirect is the shell's own write."""
|
|
347
|
+
self.engine.refresh(self.box)
|
|
348
|
+
self.engine.executed(self.box, {'pid': 50, 'ppid': 1, 'process_start_ns': '50', 'executable': '/bin/bash', 'argv': [
|
|
349
|
+
'/bin/bash', '-c', "source /home/node/snap.sh || true && eval 'export RAYTRACE_CALL_ID=toolu_01ABC\necho hi > src/app.js' < /dev/null"]})
|
|
350
|
+
self.assertEqual(self.box.processes[50]['call_id'], 'toolu_01ABC')
|
|
351
|
+
|
|
352
|
+
def test_a_write_through_a_link_is_still_the_writers(self):
|
|
353
|
+
os.symlink('app.js', Path(self.folder.name) / 'src/alias.js')
|
|
354
|
+
self.engine.refresh(self.box)
|
|
355
|
+
self.assertNotIn('src/alias.js', self.box.guarded)
|
|
356
|
+
self.opened('src/alias.js', flags=engine.O_CREAT | engine.O_TRUNC | 1)
|
|
357
|
+
self.assertNotIn('src/alias.js', self.box.guarded)
|
|
358
|
+
self.write('src/app.js', 'through the link')
|
|
359
|
+
self.looked('src/app.js', 'modify', 'close_write')
|
|
360
|
+
(fact,) = self.engine.facts.values()
|
|
361
|
+
self.assertEqual((fact['call_id'], fact['certainty'], fact['basis']['via']), ('call_10', 'confirmed', 'src/alias.js'))
|
|
362
|
+
self.engine.facts.clear()
|
|
363
|
+
os.link(Path(self.folder.name) / 'src/app.js', Path(self.folder.name) / 'src/hard.js')
|
|
364
|
+
self.opened('src/hard.js', flags=engine.O_CREAT | 1)
|
|
365
|
+
self.write('src/hard.js', 'through the hard link')
|
|
366
|
+
self.looked('src/app.js', 'modify', 'close_write')
|
|
367
|
+
(fact,) = [fact for fact in self.engine.facts.values() if fact['path'] == 'src/app.js']
|
|
368
|
+
self.assertEqual((fact['call_id'], fact['basis']['via']), ('call_10', 'src/hard.js'))
|
|
369
|
+
|
|
370
|
+
|
|
214
371
|
if __name__ == '__main__':
|
|
215
372
|
unittest.main()
|