@openrig/cli 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/daemon/assets/guidance/{using-openrig.md → openrig-start.md} +1 -1
- package/daemon/dist/adapters/claude-code-adapter.d.ts.map +1 -1
- package/daemon/dist/adapters/claude-code-adapter.js +4 -24
- package/daemon/dist/adapters/claude-code-adapter.js.map +1 -1
- package/daemon/dist/adapters/codex-runtime-adapter.d.ts.map +1 -1
- package/daemon/dist/adapters/codex-runtime-adapter.js +4 -22
- package/daemon/dist/adapters/codex-runtime-adapter.js.map +1 -1
- package/daemon/dist/domain/bootstrap-orchestrator.d.ts +2 -0
- package/daemon/dist/domain/bootstrap-orchestrator.d.ts.map +1 -1
- package/daemon/dist/domain/bootstrap-orchestrator.js +22 -4
- package/daemon/dist/domain/bootstrap-orchestrator.js.map +1 -1
- package/daemon/dist/domain/cwd-resolution.d.ts +5 -0
- package/daemon/dist/domain/cwd-resolution.d.ts.map +1 -0
- package/daemon/dist/domain/cwd-resolution.js +29 -0
- package/daemon/dist/domain/cwd-resolution.js.map +1 -0
- package/daemon/dist/domain/managed-blocks.d.ts +18 -0
- package/daemon/dist/domain/managed-blocks.d.ts.map +1 -0
- package/daemon/dist/domain/managed-blocks.js +61 -0
- package/daemon/dist/domain/managed-blocks.js.map +1 -0
- package/daemon/dist/domain/profile-resolver.d.ts +2 -0
- package/daemon/dist/domain/profile-resolver.d.ts.map +1 -1
- package/daemon/dist/domain/profile-resolver.js +6 -1
- package/daemon/dist/domain/profile-resolver.js.map +1 -1
- package/daemon/dist/domain/rig-teardown.d.ts +2 -0
- package/daemon/dist/domain/rig-teardown.d.ts.map +1 -1
- package/daemon/dist/domain/rig-teardown.js +35 -0
- package/daemon/dist/domain/rig-teardown.js.map +1 -1
- package/daemon/dist/domain/rigspec-instantiator.d.ts +4 -1
- package/daemon/dist/domain/rigspec-instantiator.d.ts.map +1 -1
- package/daemon/dist/domain/rigspec-instantiator.js +33 -12
- package/daemon/dist/domain/rigspec-instantiator.js.map +1 -1
- package/daemon/dist/domain/rigspec-preflight.d.ts +1 -0
- package/daemon/dist/domain/rigspec-preflight.d.ts.map +1 -1
- package/daemon/dist/domain/rigspec-preflight.js +12 -0
- package/daemon/dist/domain/rigspec-preflight.js.map +1 -1
- package/daemon/dist/routes/bootstrap.js +12 -2
- package/daemon/dist/routes/bootstrap.js.map +1 -1
- package/daemon/dist/routes/up.js +11 -2
- package/daemon/dist/routes/up.js.map +1 -1
- package/dist/commands/bootstrap.d.ts.map +1 -1
- package/dist/commands/bootstrap.js +7 -1
- package/dist/commands/bootstrap.js.map +1 -1
- package/dist/commands/up.d.ts.map +1 -1
- package/dist/commands/up.js +11 -3
- package/dist/commands/up.js.map +1 -1
- package/package.json +1 -1
- package/ui/dist/assets/{index-CrjgHtlk.js → index-VA_A8dpm.js} +1 -1
- package/ui/dist/index.html +1 -1
|
@@ -219,6 +219,6 @@ edges: []`}),u.jsx("button",{"data-testid":"add-pod-submit",disabled:$.isPending
|
|
|
219
219
|
+`).split(`
|
|
220
220
|
`)),v=h.reduce((g,y)=>g.concat(...y),[]);return[h,v]}return[[],[]]},[e]);return j.useEffect(()=>{const m=(t==null?void 0:t.target)??hS,h=(t==null?void 0:t.actInsideInputWithModifier)??!0;if(e!==null){const v=b=>{var N,C;if(i.current=b.ctrlKey||b.metaKey||b.shiftKey||b.altKey,(!i.current||i.current&&!h)&&Tj(b))return!1;const w=pS(b.code,f);if(l.current.add(b[w]),mS(d,l.current,!1)){const T=((C=(N=b.composedPath)==null?void 0:N.call(b))==null?void 0:C[0])||b.target,_=(T==null?void 0:T.nodeName)==="BUTTON"||(T==null?void 0:T.nodeName)==="A";t.preventDefault!==!1&&(i.current||!_)&&b.preventDefault(),r(!0)}},g=b=>{const S=pS(b.code,f);mS(d,l.current,!0)?(r(!1),l.current.clear()):l.current.delete(b[S]),b.key==="Meta"&&l.current.clear(),i.current=!1},y=()=>{l.current.clear(),r(!1)};return m==null||m.addEventListener("keydown",v),m==null||m.addEventListener("keyup",g),window.addEventListener("blur",y),window.addEventListener("contextmenu",y),()=>{m==null||m.removeEventListener("keydown",v),m==null||m.removeEventListener("keyup",g),window.removeEventListener("blur",y),window.removeEventListener("contextmenu",y)}}},[e,r]),s}function mS(e,t,s){return e.filter(r=>s||r.length===t.size).some(r=>r.every(i=>t.has(i)))}function pS(e,t){return t.includes(e)?"code":"key"}const Ez=()=>{const e=ot();return j.useMemo(()=>({zoomIn:t=>{const{panZoom:s}=e.getState();return s?s.scaleBy(1.2,{duration:t==null?void 0:t.duration}):Promise.resolve(!1)},zoomOut:t=>{const{panZoom:s}=e.getState();return s?s.scaleBy(1/1.2,{duration:t==null?void 0:t.duration}):Promise.resolve(!1)},zoomTo:(t,s)=>{const{panZoom:r}=e.getState();return r?r.scaleTo(t,{duration:s==null?void 0:s.duration}):Promise.resolve(!1)},getZoom:()=>e.getState().transform[2],setViewport:async(t,s)=>{const{transform:[r,i,l],panZoom:d}=e.getState();return d?(await d.setViewport({x:t.x??r,y:t.y??i,zoom:t.zoom??l},s),Promise.resolve(!0)):Promise.resolve(!1)},getViewport:()=>{const[t,s,r]=e.getState().transform;return{x:t,y:s,zoom:r}},setCenter:async(t,s,r)=>e.getState().setCenter(t,s,r),fitBounds:async(t,s)=>{const{width:r,height:i,minZoom:l,maxZoom:d,panZoom:f}=e.getState(),m=n0(t,r,i,l,d,(s==null?void 0:s.padding)??.1);return f?(await f.setViewport(m,{duration:s==null?void 0:s.duration,ease:s==null?void 0:s.ease,interpolate:s==null?void 0:s.interpolate}),Promise.resolve(!0)):Promise.resolve(!1)},screenToFlowPosition:(t,s={})=>{const{transform:r,snapGrid:i,snapToGrid:l,domNode:d}=e.getState();if(!d)return t;const{x:f,y:m}=d.getBoundingClientRect(),h={x:t.x-f,y:t.y-m},v=s.snapGrid??i,g=s.snapToGrid??l;return Nc(h,r,g,v)},flowToScreenPosition:t=>{const{transform:s,domNode:r}=e.getState();if(!r)return t;const{x:i,y:l}=r.getBoundingClientRect(),d=tf(t,s);return{x:d.x+i,y:d.y+l}}}),[])};function Zj(e,t){const s=[],r=new Map,i=[];for(const l of e)if(l.type==="add"){i.push(l);continue}else if(l.type==="remove"||l.type==="replace")r.set(l.id,[l]);else{const d=r.get(l.id);d?d.push(l):r.set(l.id,[l])}for(const l of t){const d=r.get(l.id);if(!d){s.push(l);continue}if(d[0].type==="remove")continue;if(d[0].type==="replace"){s.push({...d[0].item});continue}const f={...l};for(const m of d)Cz(m,f);s.push(f)}return i.length&&i.forEach(l=>{l.index!==void 0?s.splice(l.index,0,{...l.item}):s.push({...l.item})}),s}function Cz(e,t){switch(e.type){case"select":{t.selected=e.selected;break}case"position":{typeof e.position<"u"&&(t.position=e.position),typeof e.dragging<"u"&&(t.dragging=e.dragging);break}case"dimensions":{typeof e.dimensions<"u"&&(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);break}}}function _z(e,t){return Zj(e,t)}function Rz(e,t){return Zj(e,t)}function Rr(e,t){return{id:e,type:"select",selected:t}}function Ji(e,t=new Set,s=!1){const r=[];for(const[i,l]of e){const d=t.has(i);!(l.selected===void 0&&!d)&&l.selected!==d&&(s&&(l.selected=d),r.push(Rr(l.id,d)))}return r}function gS({items:e=[],lookup:t}){var i;const s=[],r=new Map(e.map(l=>[l.id,l]));for(const[l,d]of e.entries()){const f=t.get(d.id),m=((i=f==null?void 0:f.internals)==null?void 0:i.userNode)??f;m!==void 0&&m!==d&&s.push({id:d.id,item:d,type:"replace"}),m===void 0&&s.push({item:d,type:"add",index:l})}for(const[l]of t)r.get(l)===void 0&&s.push({id:l,type:"remove"});return s}function xS(e){return{id:e.id,type:"remove"}}const yS=e=>nL(e),Tz=e=>Sj(e);function Wj(e){return j.forwardRef(e)}const Az=typeof window<"u"?j.useLayoutEffect:j.useEffect;function vS(e){const[t,s]=j.useState(BigInt(0)),[r]=j.useState(()=>Mz(()=>s(i=>i+BigInt(1))));return Az(()=>{const i=r.get();i.length&&(e(i),r.reset())},[t]),r}function Mz(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:s=>{t.push(s),e()}}}const Jj=j.createContext(null);function kz({children:e}){const t=ot(),s=j.useCallback(f=>{const{nodes:m=[],setNodes:h,hasDefaultNodes:v,onNodesChange:g,nodeLookup:y,fitViewQueued:b,onNodesChangeMiddlewareMap:S}=t.getState();let w=m;for(const C of f)w=typeof C=="function"?C(w):C;let N=gS({items:w,lookup:y});for(const C of S.values())N=C(N);v&&h(w),N.length>0?g==null||g(N):b&&window.requestAnimationFrame(()=>{const{fitViewQueued:C,nodes:T,setNodes:_}=t.getState();C&&_(T)})},[]),r=vS(s),i=j.useCallback(f=>{const{edges:m=[],setEdges:h,hasDefaultEdges:v,onEdgesChange:g,edgeLookup:y}=t.getState();let b=m;for(const S of f)b=typeof S=="function"?S(b):S;v?h(b):g&&g(gS({items:b,lookup:y}))},[]),l=vS(i),d=j.useMemo(()=>({nodeQueue:r,edgeQueue:l}),[]);return u.jsx(Jj.Provider,{value:d,children:e})}function Oz(){const e=j.useContext(Jj);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const Dz=e=>!!e.panZoom;function c0(){const e=Ez(),t=ot(),s=Oz(),r=Ve(Dz),i=j.useMemo(()=>{const l=g=>t.getState().nodeLookup.get(g),d=g=>{s.nodeQueue.push(g)},f=g=>{s.edgeQueue.push(g)},m=g=>{var C,T;const{nodeLookup:y,nodeOrigin:b}=t.getState(),S=yS(g)?g:y.get(g.id),w=S.parentId?_j(S.position,S.measured,S.parentId,y,b):S.position,N={...S,position:w,width:((C=S.measured)==null?void 0:C.width)??S.width,height:((T=S.measured)==null?void 0:T.height)??S.height};return wo(N)},h=(g,y,b={replace:!1})=>{d(S=>S.map(w=>{if(w.id===g){const N=typeof y=="function"?y(w):y;return b.replace&&yS(N)?N:{...w,...N}}return w}))},v=(g,y,b={replace:!1})=>{f(S=>S.map(w=>{if(w.id===g){const N=typeof y=="function"?y(w):y;return b.replace&&Tz(N)?N:{...w,...N}}return w}))};return{getNodes:()=>t.getState().nodes.map(g=>({...g})),getNode:g=>{var y;return(y=l(g))==null?void 0:y.internals.userNode},getInternalNode:l,getEdges:()=>{const{edges:g=[]}=t.getState();return g.map(y=>({...y}))},getEdge:g=>t.getState().edgeLookup.get(g),setNodes:d,setEdges:f,addNodes:g=>{const y=Array.isArray(g)?g:[g];s.nodeQueue.push(b=>[...b,...y])},addEdges:g=>{const y=Array.isArray(g)?g:[g];s.edgeQueue.push(b=>[...b,...y])},toObject:()=>{const{nodes:g=[],edges:y=[],transform:b}=t.getState(),[S,w,N]=b;return{nodes:g.map(C=>({...C})),edges:y.map(C=>({...C})),viewport:{x:S,y:w,zoom:N}}},deleteElements:async({nodes:g=[],edges:y=[]})=>{const{nodes:b,edges:S,onNodesDelete:w,onEdgesDelete:N,triggerNodeChanges:C,triggerEdgeChanges:T,onDelete:_,onBeforeDelete:R}=t.getState(),{nodes:O,edges:B}=await oL({nodesToRemove:g,edgesToRemove:y,nodes:b,edges:S,onBeforeDelete:R}),L=B.length>0,M=O.length>0;if(L){const I=B.map(xS);N==null||N(B),T(I)}if(M){const I=O.map(xS);w==null||w(O),C(I)}return(M||L)&&(_==null||_({nodes:O,edges:B})),{deletedNodes:O,deletedEdges:B}},getIntersectingNodes:(g,y=!0,b)=>{const S=K1(g),w=S?g:m(g),N=b!==void 0;return w?(b||t.getState().nodes).filter(C=>{const T=t.getState().nodeLookup.get(C.id);if(T&&!S&&(C.id===g.id||!T.internals.positionAbsolute))return!1;const _=wo(N?C:T),R=ic(_,w);return y&&R>0||R>=_.width*_.height||R>=w.width*w.height}):[]},isNodeIntersecting:(g,y,b=!0)=>{const w=K1(g)?g:m(g);if(!w)return!1;const N=ic(w,y);return b&&N>0||N>=y.width*y.height||N>=w.width*w.height},updateNode:h,updateNodeData:(g,y,b={replace:!1})=>{h(g,S=>{const w=typeof y=="function"?y(S):y;return b.replace?{...S,data:w}:{...S,data:{...S.data,...w}}},b)},updateEdge:v,updateEdgeData:(g,y,b={replace:!1})=>{v(g,S=>{const w=typeof y=="function"?y(S):y;return b.replace?{...S,data:w}:{...S,data:{...S.data,...w}}},b)},getNodesBounds:g=>{const{nodeLookup:y,nodeOrigin:b}=t.getState();return sL(g,{nodeLookup:y,nodeOrigin:b})},getHandleConnections:({type:g,id:y,nodeId:b})=>{var S;return Array.from(((S=t.getState().connectionLookup.get(`${b}-${g}${y?`-${y}`:""}`))==null?void 0:S.values())??[])},getNodeConnections:({type:g,handleId:y,nodeId:b})=>{var S;return Array.from(((S=t.getState().connectionLookup.get(`${b}${g?y?`-${g}-${y}`:`-${g}`:""}`))==null?void 0:S.values())??[])},fitView:async g=>{const y=t.getState().fitViewResolver??dL();return t.setState({fitViewQueued:!0,fitViewOptions:g,fitViewResolver:y}),s.nodeQueue.push(b=>[...b]),y.promise}}},[]);return j.useMemo(()=>({...i,...e,viewportInitialized:r}),[r])}const bS=e=>e.selected,Lz=typeof window<"u"?window:void 0;function zz({deleteKeyCode:e,multiSelectionKeyCode:t}){const s=ot(),{deleteElements:r}=c0(),i=lc(e,{actInsideInputWithModifier:!1}),l=lc(t,{target:Lz});j.useEffect(()=>{if(i){const{edges:d,nodes:f}=s.getState();r({nodes:f.filter(bS),edges:d.filter(bS)}),s.setState({nodesSelectionActive:!1})}},[i]),j.useEffect(()=>{s.setState({multiSelectionActive:l})},[l])}function Pz(e){const t=ot();j.useEffect(()=>{const s=()=>{var i,l,d,f;if(!e.current||!(((l=(i=e.current).checkVisibility)==null?void 0:l.call(i))??!0))return!1;const r=s0(e.current);(r.height===0||r.width===0)&&((f=(d=t.getState()).onError)==null||f.call(d,"004",hs.error004())),t.setState({width:r.width||500,height:r.height||500})};if(e.current){s(),window.addEventListener("resize",s);const r=new ResizeObserver(()=>s());return r.observe(e.current),()=>{window.removeEventListener("resize",s),r&&e.current&&r.unobserve(e.current)}}},[])}const Ef={position:"absolute",width:"100%",height:"100%",top:0,left:0},Iz=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function Bz({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:s=!0,panOnScroll:r=!1,panOnScrollSpeed:i=.5,panOnScrollMode:l=Fr.Free,zoomOnDoubleClick:d=!0,panOnDrag:f=!0,defaultViewport:m,translateExtent:h,minZoom:v,maxZoom:g,zoomActivationKeyCode:y,preventScrolling:b=!0,children:S,noWheelClassName:w,noPanClassName:N,onViewportChange:C,isControlledViewport:T,paneClickDistance:_,selectionOnDrag:R}){const O=ot(),B=j.useRef(null),{userSelectionActive:L,lib:M,connectionInProgress:I}=Ve(Iz,it),H=lc(y),D=j.useRef();Pz(B);const Y=j.useCallback(K=>{C==null||C({x:K[0],y:K[1],zoom:K[2]}),T||O.setState({transform:K})},[C,T]);return j.useEffect(()=>{if(B.current){D.current=KL({domNode:B.current,minZoom:v,maxZoom:g,translateExtent:h,viewport:m,onDraggingChange:A=>O.setState($=>$.paneDragging===A?$:{paneDragging:A}),onPanZoomStart:(A,$)=>{const{onViewportChangeStart:z,onMoveStart:G}=O.getState();G==null||G(A,$),z==null||z($)},onPanZoom:(A,$)=>{const{onViewportChange:z,onMove:G}=O.getState();G==null||G(A,$),z==null||z($)},onPanZoomEnd:(A,$)=>{const{onViewportChangeEnd:z,onMoveEnd:G}=O.getState();G==null||G(A,$),z==null||z($)}});const{x:K,y:U,zoom:q}=D.current.getViewport();return O.setState({panZoom:D.current,transform:[K,U,q],domNode:B.current.closest(".react-flow")}),()=>{var A;(A=D.current)==null||A.destroy()}}},[]),j.useEffect(()=>{var K;(K=D.current)==null||K.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:s,panOnScroll:r,panOnScrollSpeed:i,panOnScrollMode:l,zoomOnDoubleClick:d,panOnDrag:f,zoomActivationKeyPressed:H,preventScrolling:b,noPanClassName:N,userSelectionActive:L,noWheelClassName:w,lib:M,onTransformChange:Y,connectionInProgress:I,selectionOnDrag:R,paneClickDistance:_})},[e,t,s,r,i,l,d,f,H,b,N,L,w,M,Y,I,R,_]),u.jsx("div",{className:"react-flow__renderer",ref:B,style:Ef,children:S})}const Hz=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function Uz(){const{userSelectionActive:e,userSelectionRect:t}=Ve(Hz,it);return e&&t?u.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}const Ap=(e,t)=>s=>{s.target===t.current&&(e==null||e(s))},$z=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function qz({isSelecting:e,selectionKeyPressed:t,selectionMode:s=ac.Full,panOnDrag:r,paneClickDistance:i,selectionOnDrag:l,onSelectionStart:d,onSelectionEnd:f,onPaneClick:m,onPaneContextMenu:h,onPaneScroll:v,onPaneMouseEnter:g,onPaneMouseMove:y,onPaneMouseLeave:b,children:S}){const w=ot(),{userSelectionActive:N,elementsSelectable:C,dragging:T,connectionInProgress:_}=Ve($z,it),R=C&&(e||N),O=j.useRef(null),B=j.useRef(),L=j.useRef(new Set),M=j.useRef(new Set),I=j.useRef(!1),H=z=>{if(I.current||_){I.current=!1;return}m==null||m(z),w.getState().resetSelectedElements(),w.setState({nodesSelectionActive:!1})},D=z=>{if(Array.isArray(r)&&(r!=null&&r.includes(2))){z.preventDefault();return}h==null||h(z)},Y=v?z=>v(z):void 0,K=z=>{I.current&&(z.stopPropagation(),I.current=!1)},U=z=>{var oe,ce;const{domNode:G}=w.getState();if(B.current=G==null?void 0:G.getBoundingClientRect(),!B.current)return;const V=z.target===O.current;if(!V&&!!z.target.closest(".nokey")||!e||!(l&&V||t)||z.button!==0||!z.isPrimary)return;(ce=(oe=z.target)==null?void 0:oe.setPointerCapture)==null||ce.call(oe,z.pointerId),I.current=!1;const{x:ee,y:se}=Gn(z.nativeEvent,B.current);w.setState({userSelectionRect:{width:0,height:0,startX:ee,startY:se,x:ee,y:se}}),V||(z.stopPropagation(),z.preventDefault())},q=z=>{const{userSelectionRect:G,transform:V,nodeLookup:P,edgeLookup:Q,connectionLookup:ee,triggerNodeChanges:se,triggerEdgeChanges:oe,defaultEdgeOptions:ce,resetSelectedElements:fe}=w.getState();if(!B.current||!G)return;const{x:ue,y:he}=Gn(z.nativeEvent,B.current),{startX:Ce,startY:Se}=G;if(!I.current){const Re=t?0:i;if(Math.hypot(ue-Ce,he-Se)<=Re)return;fe(),d==null||d(z)}I.current=!0;const ye={startX:Ce,startY:Se,x:ue<Ce?ue:Ce,y:he<Se?he:Se,width:Math.abs(ue-Ce),height:Math.abs(he-Se)},ve=L.current,de=M.current;L.current=new Set(t0(P,ye,V,s===ac.Partial,!0).map(Re=>Re.id)),M.current=new Set;const Ae=(ce==null?void 0:ce.selectable)??!0;for(const Re of L.current){const Be=ee.get(Re);if(Be)for(const{edgeId:St}of Be.values()){const dt=Q.get(St);dt&&(dt.selectable??Ae)&&M.current.add(St)}}if(!F1(ve,L.current)){const Re=Ji(P,L.current,!0);se(Re)}if(!F1(de,M.current)){const Re=Ji(Q,M.current);oe(Re)}w.setState({userSelectionRect:ye,userSelectionActive:!0,nodesSelectionActive:!1})},A=z=>{var G,V;z.button===0&&((V=(G=z.target)==null?void 0:G.releasePointerCapture)==null||V.call(G,z.pointerId),!N&&z.target===O.current&&w.getState().userSelectionRect&&(H==null||H(z)),w.setState({userSelectionActive:!1,userSelectionRect:null}),I.current&&(f==null||f(z),w.setState({nodesSelectionActive:L.current.size>0})))},$=r===!0||Array.isArray(r)&&r.includes(0);return u.jsxs("div",{className:bt(["react-flow__pane",{draggable:$,dragging:T,selection:e}]),onClick:R?void 0:Ap(H,O),onContextMenu:Ap(D,O),onWheel:Ap(Y,O),onPointerEnter:R?void 0:g,onPointerMove:R?q:y,onPointerUp:R?A:void 0,onPointerDownCapture:R?U:void 0,onClickCapture:R?K:void 0,onPointerLeave:b,ref:O,style:Ef,children:[S,u.jsx(Uz,{})]})}function gg({id:e,store:t,unselect:s=!1,nodeRef:r}){const{addSelectedNodes:i,unselectNodesAndEdges:l,multiSelectionActive:d,nodeLookup:f,onError:m}=t.getState(),h=f.get(e);if(!h){m==null||m("012",hs.error012(e));return}t.setState({nodesSelectionActive:!1}),h.selected?(s||h.selected&&d)&&(l({nodes:[h],edges:[]}),requestAnimationFrame(()=>{var v;return(v=r==null?void 0:r.current)==null?void 0:v.blur()})):i([e])}function eE({nodeRef:e,disabled:t=!1,noDragClassName:s,handleSelector:r,nodeId:i,isSelectable:l,nodeClickDistance:d}){const f=ot(),[m,h]=j.useState(!1),v=j.useRef();return j.useEffect(()=>{v.current=DL({getStoreItems:()=>f.getState(),onNodeMouseDown:g=>{gg({id:g,store:f,nodeRef:e})},onDragStart:()=>{h(!0)},onDragStop:()=>{h(!1)}})},[]),j.useEffect(()=>{if(!(t||!e.current||!v.current))return v.current.update({noDragClassName:s,handleSelector:r,domNode:e.current,isSelectable:l,nodeId:i,nodeClickDistance:d}),()=>{var g;(g=v.current)==null||g.destroy()}},[s,r,t,l,e,i,d]),m}const Vz=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function tE(){const e=ot();return j.useCallback(s=>{const{nodeExtent:r,snapToGrid:i,snapGrid:l,nodesDraggable:d,onError:f,updateNodePositions:m,nodeLookup:h,nodeOrigin:v}=e.getState(),g=new Map,y=Vz(d),b=i?l[0]:5,S=i?l[1]:5,w=s.direction.x*b*s.factor,N=s.direction.y*S*s.factor;for(const[,C]of h){if(!y(C))continue;let T={x:C.internals.positionAbsolute.x+w,y:C.internals.positionAbsolute.y+N};i&&(T=wc(T,l));const{position:_,positionAbsolute:R}=wj({nodeId:C.id,nextPosition:T,nodeLookup:h,nodeExtent:r,nodeOrigin:v,onError:f});C.position=_,C.internals.positionAbsolute=R,g.set(C.id,C)}m(g)},[])}const u0=j.createContext(null),Gz=u0.Provider;u0.Consumer;const nE=()=>j.useContext(u0),Yz=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),Qz=(e,t,s)=>r=>{const{connectionClickStartHandle:i,connectionMode:l,connection:d}=r,{fromHandle:f,toHandle:m,isValid:h}=d,v=(m==null?void 0:m.nodeId)===e&&(m==null?void 0:m.id)===t&&(m==null?void 0:m.type)===s;return{connectingFrom:(f==null?void 0:f.nodeId)===e&&(f==null?void 0:f.id)===t&&(f==null?void 0:f.type)===s,connectingTo:v,clickConnecting:(i==null?void 0:i.nodeId)===e&&(i==null?void 0:i.id)===t&&(i==null?void 0:i.type)===s,isPossibleEndHandle:l===bo.Strict?(f==null?void 0:f.type)!==s:e!==(f==null?void 0:f.nodeId)||t!==(f==null?void 0:f.id),connectionInProcess:!!f,clickConnectionInProcess:!!i,valid:v&&h}};function Kz({type:e="source",position:t=we.Top,isValidConnection:s,isConnectable:r=!0,isConnectableStart:i=!0,isConnectableEnd:l=!0,id:d,onConnect:f,children:m,className:h,onMouseDown:v,onTouchStart:g,...y},b){var q,A;const S=d||null,w=e==="target",N=ot(),C=nE(),{connectOnClick:T,noPanClassName:_,rfId:R}=Ve(Yz,it),{connectingFrom:O,connectingTo:B,clickConnecting:L,isPossibleEndHandle:M,connectionInProcess:I,clickConnectionInProcess:H,valid:D}=Ve(Qz(C,S,e),it);C||(A=(q=N.getState()).onError)==null||A.call(q,"010",hs.error010());const Y=$=>{const{defaultEdgeOptions:z,onConnect:G,hasDefaultEdges:V}=N.getState(),P={...z,...$};if(V){const{edges:Q,setEdges:ee}=N.getState();ee(yL(P,Q))}G==null||G(P),f==null||f(P)},K=$=>{if(!C)return;const z=Aj($.nativeEvent);if(i&&(z&&$.button===0||!z)){const G=N.getState();pg.onPointerDown($.nativeEvent,{handleDomNode:$.currentTarget,autoPanOnConnect:G.autoPanOnConnect,connectionMode:G.connectionMode,connectionRadius:G.connectionRadius,domNode:G.domNode,nodeLookup:G.nodeLookup,lib:G.lib,isTarget:w,handleId:S,nodeId:C,flowId:G.rfId,panBy:G.panBy,cancelConnection:G.cancelConnection,onConnectStart:G.onConnectStart,onConnectEnd:(...V)=>{var P,Q;return(Q=(P=N.getState()).onConnectEnd)==null?void 0:Q.call(P,...V)},updateConnection:G.updateConnection,onConnect:Y,isValidConnection:s||((...V)=>{var P,Q;return((Q=(P=N.getState()).isValidConnection)==null?void 0:Q.call(P,...V))??!0}),getTransform:()=>N.getState().transform,getFromHandle:()=>N.getState().connection.fromHandle,autoPanSpeed:G.autoPanSpeed,dragThreshold:G.connectionDragThreshold})}z?v==null||v($):g==null||g($)},U=$=>{const{onClickConnectStart:z,onClickConnectEnd:G,connectionClickStartHandle:V,connectionMode:P,isValidConnection:Q,lib:ee,rfId:se,nodeLookup:oe,connection:ce}=N.getState();if(!C||!V&&!i)return;if(!V){z==null||z($.nativeEvent,{nodeId:C,handleId:S,handleType:e}),N.setState({connectionClickStartHandle:{nodeId:C,type:e,id:S}});return}const fe=Rj($.target),ue=s||Q,{connection:he,isValid:Ce}=pg.isValid($.nativeEvent,{handle:{nodeId:C,id:S,type:e},connectionMode:P,fromNodeId:V.nodeId,fromHandleId:V.id||null,fromType:V.type,isValidConnection:ue,flowId:se,doc:fe,lib:ee,nodeLookup:oe});Ce&&he&&Y(he);const Se=structuredClone(ce);delete Se.inProgress,Se.toPosition=Se.toHandle?Se.toHandle.position:null,G==null||G($,Se),N.setState({connectionClickStartHandle:null})};return u.jsx("div",{"data-handleid":S,"data-nodeid":C,"data-handlepos":t,"data-id":`${R}-${C}-${S}-${e}`,className:bt(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",_,h,{source:!w,target:w,connectable:r,connectablestart:i,connectableend:l,clickconnecting:L,connectingfrom:O,connectingto:B,valid:D,connectionindicator:r&&(!I||M)&&(I||H?l:i)}]),onMouseDown:K,onTouchStart:K,onClick:T?U:void 0,ref:b,...y,children:m})}const Wa=j.memo(Wj(Kz));function Fz({data:e,isConnectable:t,sourcePosition:s=we.Bottom}){return u.jsxs(u.Fragment,{children:[e==null?void 0:e.label,u.jsx(Wa,{type:"source",position:s,isConnectable:t})]})}function Xz({data:e,isConnectable:t,targetPosition:s=we.Top,sourcePosition:r=we.Bottom}){return u.jsxs(u.Fragment,{children:[u.jsx(Wa,{type:"target",position:s,isConnectable:t}),e==null?void 0:e.label,u.jsx(Wa,{type:"source",position:r,isConnectable:t})]})}function Zz(){return null}function Wz({data:e,isConnectable:t,targetPosition:s=we.Top}){return u.jsxs(u.Fragment,{children:[u.jsx(Wa,{type:"target",position:s,isConnectable:t}),e==null?void 0:e.label]})}const nf={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},SS={input:Fz,default:Xz,output:Wz,group:Zz};function Jz(e){var t,s,r,i;return e.internals.handleBounds===void 0?{width:e.width??e.initialWidth??((t=e.style)==null?void 0:t.width),height:e.height??e.initialHeight??((s=e.style)==null?void 0:s.height)}:{width:e.width??((r=e.style)==null?void 0:r.width),height:e.height??((i=e.style)==null?void 0:i.height)}}const e8=e=>{const{width:t,height:s,x:r,y:i}=Sc(e.nodeLookup,{filter:l=>!!l.selected});return{width:Vn(t)?t:null,height:Vn(s)?s:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${r}px,${i}px)`}};function t8({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:s}){const r=ot(),{width:i,height:l,transformString:d,userSelectionActive:f}=Ve(e8,it),m=tE(),h=j.useRef(null);j.useEffect(()=>{var b;s||(b=h.current)==null||b.focus({preventScroll:!0})},[s]);const v=!f&&i!==null&&l!==null;if(eE({nodeRef:h,disabled:!v}),!v)return null;const g=e?b=>{const S=r.getState().nodes.filter(w=>w.selected);e(b,S)}:void 0,y=b=>{Object.prototype.hasOwnProperty.call(nf,b.key)&&(b.preventDefault(),m({direction:nf[b.key],factor:b.shiftKey?4:1}))};return u.jsx("div",{className:bt(["react-flow__nodesselection","react-flow__container",t]),style:{transform:d},children:u.jsx("div",{ref:h,className:"react-flow__nodesselection-rect",onContextMenu:g,tabIndex:s?void 0:-1,onKeyDown:s?void 0:y,style:{width:i,height:l}})})}const wS=typeof window<"u"?window:void 0,n8=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function sE({children:e,onPaneClick:t,onPaneMouseEnter:s,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:l,onPaneScroll:d,paneClickDistance:f,deleteKeyCode:m,selectionKeyCode:h,selectionOnDrag:v,selectionMode:g,onSelectionStart:y,onSelectionEnd:b,multiSelectionKeyCode:S,panActivationKeyCode:w,zoomActivationKeyCode:N,elementsSelectable:C,zoomOnScroll:T,zoomOnPinch:_,panOnScroll:R,panOnScrollSpeed:O,panOnScrollMode:B,zoomOnDoubleClick:L,panOnDrag:M,defaultViewport:I,translateExtent:H,minZoom:D,maxZoom:Y,preventScrolling:K,onSelectionContextMenu:U,noWheelClassName:q,noPanClassName:A,disableKeyboardA11y:$,onViewportChange:z,isControlledViewport:G}){const{nodesSelectionActive:V,userSelectionActive:P}=Ve(n8,it),Q=lc(h,{target:wS}),ee=lc(w,{target:wS}),se=ee||M,oe=ee||R,ce=v&&se!==!0,fe=Q||P||ce;return zz({deleteKeyCode:m,multiSelectionKeyCode:S}),u.jsx(Bz,{onPaneContextMenu:l,elementsSelectable:C,zoomOnScroll:T,zoomOnPinch:_,panOnScroll:oe,panOnScrollSpeed:O,panOnScrollMode:B,zoomOnDoubleClick:L,panOnDrag:!Q&&se,defaultViewport:I,translateExtent:H,minZoom:D,maxZoom:Y,zoomActivationKeyCode:N,preventScrolling:K,noWheelClassName:q,noPanClassName:A,onViewportChange:z,isControlledViewport:G,paneClickDistance:f,selectionOnDrag:ce,children:u.jsxs(qz,{onSelectionStart:y,onSelectionEnd:b,onPaneClick:t,onPaneMouseEnter:s,onPaneMouseMove:r,onPaneMouseLeave:i,onPaneContextMenu:l,onPaneScroll:d,panOnDrag:se,isSelecting:!!fe,selectionMode:g,selectionKeyPressed:Q,paneClickDistance:f,selectionOnDrag:ce,children:[e,V&&u.jsx(t8,{onSelectionContextMenu:U,noPanClassName:A,disableKeyboardA11y:$})]})})}sE.displayName="FlowRenderer";const s8=j.memo(sE),a8=e=>t=>e?t0(t.nodeLookup,{x:0,y:0,width:t.width,height:t.height},t.transform,!0).map(s=>s.id):Array.from(t.nodeLookup.keys());function r8(e){return Ve(j.useCallback(a8(e),[e]),it)}const i8=e=>e.updateNodeInternals;function o8(){const e=Ve(i8),[t]=j.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(s=>{const r=new Map;s.forEach(i=>{const l=i.target.getAttribute("data-id");r.set(l,{id:l,nodeElement:i.target,force:!0})}),e(r)}));return j.useEffect(()=>()=>{t==null||t.disconnect()},[t]),t}function l8({node:e,nodeType:t,hasDimensions:s,resizeObserver:r}){const i=ot(),l=j.useRef(null),d=j.useRef(null),f=j.useRef(e.sourcePosition),m=j.useRef(e.targetPosition),h=j.useRef(t),v=s&&!!e.internals.handleBounds;return j.useEffect(()=>{l.current&&!e.hidden&&(!v||d.current!==l.current)&&(d.current&&(r==null||r.unobserve(d.current)),r==null||r.observe(l.current),d.current=l.current)},[v,e.hidden]),j.useEffect(()=>()=>{d.current&&(r==null||r.unobserve(d.current),d.current=null)},[]),j.useEffect(()=>{if(l.current){const g=h.current!==t,y=f.current!==e.sourcePosition,b=m.current!==e.targetPosition;(g||y||b)&&(h.current=t,f.current=e.sourcePosition,m.current=e.targetPosition,i.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:l.current,force:!0}]])))}},[e.id,t,e.sourcePosition,e.targetPosition]),l}function c8({id:e,onClick:t,onMouseEnter:s,onMouseMove:r,onMouseLeave:i,onContextMenu:l,onDoubleClick:d,nodesDraggable:f,elementsSelectable:m,nodesConnectable:h,nodesFocusable:v,resizeObserver:g,noDragClassName:y,noPanClassName:b,disableKeyboardA11y:S,rfId:w,nodeTypes:N,nodeClickDistance:C,onError:T}){const{node:_,internals:R,isParent:O}=Ve(ue=>{const he=ue.nodeLookup.get(e),Ce=ue.parentLookup.has(e);return{node:he,internals:he.internals,isParent:Ce}},it);let B=_.type||"default",L=(N==null?void 0:N[B])||SS[B];L===void 0&&(T==null||T("003",hs.error003(B)),B="default",L=(N==null?void 0:N.default)||SS.default);const M=!!(_.draggable||f&&typeof _.draggable>"u"),I=!!(_.selectable||m&&typeof _.selectable>"u"),H=!!(_.connectable||h&&typeof _.connectable>"u"),D=!!(_.focusable||v&&typeof _.focusable>"u"),Y=ot(),K=Cj(_),U=l8({node:_,nodeType:B,hasDimensions:K,resizeObserver:g}),q=eE({nodeRef:U,disabled:_.hidden||!M,noDragClassName:y,handleSelector:_.dragHandle,nodeId:e,isSelectable:I,nodeClickDistance:C}),A=tE();if(_.hidden)return null;const $=Zs(_),z=Jz(_),G=I||M||t||s||r||i,V=s?ue=>s(ue,{...R.userNode}):void 0,P=r?ue=>r(ue,{...R.userNode}):void 0,Q=i?ue=>i(ue,{...R.userNode}):void 0,ee=l?ue=>l(ue,{...R.userNode}):void 0,se=d?ue=>d(ue,{...R.userNode}):void 0,oe=ue=>{const{selectNodesOnDrag:he,nodeDragThreshold:Ce}=Y.getState();I&&(!he||!M||Ce>0)&&gg({id:e,store:Y,nodeRef:U}),t&&t(ue,{...R.userNode})},ce=ue=>{if(!(Tj(ue.nativeEvent)||S)){if(xj.includes(ue.key)&&I){const he=ue.key==="Escape";gg({id:e,store:Y,unselect:he,nodeRef:U})}else if(M&&_.selected&&Object.prototype.hasOwnProperty.call(nf,ue.key)){ue.preventDefault();const{ariaLabelConfig:he}=Y.getState();Y.setState({ariaLiveMessage:he["node.a11yDescription.ariaLiveMessage"]({direction:ue.key.replace("Arrow","").toLowerCase(),x:~~R.positionAbsolute.x,y:~~R.positionAbsolute.y})}),A({direction:nf[ue.key],factor:ue.shiftKey?4:1})}}},fe=()=>{var de;if(S||!((de=U.current)!=null&&de.matches(":focus-visible")))return;const{transform:ue,width:he,height:Ce,autoPanOnNodeFocus:Se,setCenter:ye}=Y.getState();if(!Se)return;t0(new Map([[e,_]]),{x:0,y:0,width:he,height:Ce},ue,!0).length>0||ye(_.position.x+$.width/2,_.position.y+$.height/2,{zoom:ue[2]})};return u.jsx("div",{className:bt(["react-flow__node",`react-flow__node-${B}`,{[b]:M},_.className,{selected:_.selected,selectable:I,parent:O,draggable:M,dragging:q}]),ref:U,style:{zIndex:R.z,transform:`translate(${R.positionAbsolute.x}px,${R.positionAbsolute.y}px)`,pointerEvents:G?"all":"none",visibility:K?"visible":"hidden",..._.style,...z},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:V,onMouseMove:P,onMouseLeave:Q,onContextMenu:ee,onClick:oe,onDoubleClick:se,onKeyDown:D?ce:void 0,tabIndex:D?0:void 0,onFocus:D?fe:void 0,role:_.ariaRole??(D?"group":void 0),"aria-roledescription":"node","aria-describedby":S?void 0:`${Kj}-${w}`,"aria-label":_.ariaLabel,..._.domAttributes,children:u.jsx(Gz,{value:e,children:u.jsx(L,{id:e,data:_.data,type:B,positionAbsoluteX:R.positionAbsolute.x,positionAbsoluteY:R.positionAbsolute.y,selected:_.selected??!1,selectable:I,draggable:M,deletable:_.deletable??!0,isConnectable:H,sourcePosition:_.sourcePosition,targetPosition:_.targetPosition,dragging:q,dragHandle:_.dragHandle,zIndex:R.z,parentId:_.parentId,...$})})})}var u8=j.memo(c8);const d8=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function aE(e){const{nodesDraggable:t,nodesConnectable:s,nodesFocusable:r,elementsSelectable:i,onError:l}=Ve(d8,it),d=r8(e.onlyRenderVisibleElements),f=o8();return u.jsx("div",{className:"react-flow__nodes",style:Ef,children:d.map(m=>u.jsx(u8,{id:m,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:f,nodesDraggable:t,nodesConnectable:s,nodesFocusable:r,elementsSelectable:i,nodeClickDistance:e.nodeClickDistance,onError:l},m))})}aE.displayName="NodeRenderer";const f8=j.memo(aE);function h8(e){return Ve(j.useCallback(s=>{if(!e)return s.edges.map(i=>i.id);const r=[];if(s.width&&s.height)for(const i of s.edges){const l=s.nodeLookup.get(i.source),d=s.nodeLookup.get(i.target);l&&d&&pL({sourceNode:l,targetNode:d,width:s.width,height:s.height,transform:s.transform})&&r.push(i.id)}return r},[e]),it)}const m8=({color:e="none",strokeWidth:t=1})=>{const s={strokeWidth:t,...e&&{stroke:e}};return u.jsx("polyline",{className:"arrow",style:s,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},p8=({color:e="none",strokeWidth:t=1})=>{const s={strokeWidth:t,...e&&{stroke:e,fill:e}};return u.jsx("polyline",{className:"arrowclosed",style:s,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},NS={[rc.Arrow]:m8,[rc.ArrowClosed]:p8};function g8(e){const t=ot();return j.useMemo(()=>{var i,l;return Object.prototype.hasOwnProperty.call(NS,e)?NS[e]:((l=(i=t.getState()).onError)==null||l.call(i,"009",hs.error009(e)),null)},[e])}const x8=({id:e,type:t,color:s,width:r=12.5,height:i=12.5,markerUnits:l="strokeWidth",strokeWidth:d,orient:f="auto-start-reverse"})=>{const m=g8(t);return m?u.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${i}`,viewBox:"-10 -10 20 20",markerUnits:l,orient:f,refX:"0",refY:"0",children:u.jsx(m,{color:s,strokeWidth:d})}):null},rE=({defaultColor:e,rfId:t})=>{const s=Ve(l=>l.edges),r=Ve(l=>l.defaultEdgeOptions),i=j.useMemo(()=>NL(s,{id:t,defaultColor:e,defaultMarkerStart:r==null?void 0:r.markerStart,defaultMarkerEnd:r==null?void 0:r.markerEnd}),[s,r,t,e]);return i.length?u.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:u.jsx("defs",{children:i.map(l=>u.jsx(x8,{id:l.id,type:l.type,color:l.color,width:l.width,height:l.height,markerUnits:l.markerUnits,strokeWidth:l.strokeWidth,orient:l.orient},l.id))})}):null};rE.displayName="MarkerDefinitions";var y8=j.memo(rE);function iE({x:e,y:t,label:s,labelStyle:r,labelShowBg:i=!0,labelBgStyle:l,labelBgPadding:d=[2,4],labelBgBorderRadius:f=2,children:m,className:h,...v}){const[g,y]=j.useState({x:1,y:0,width:0,height:0}),b=bt(["react-flow__edge-textwrapper",h]),S=j.useRef(null);return j.useEffect(()=>{if(S.current){const w=S.current.getBBox();y({x:w.x,y:w.y,width:w.width,height:w.height})}},[s]),s?u.jsxs("g",{transform:`translate(${e-g.width/2} ${t-g.height/2})`,className:b,visibility:g.width?"visible":"hidden",...v,children:[i&&u.jsx("rect",{width:g.width+2*d[0],x:-d[0],y:-d[1],height:g.height+2*d[1],className:"react-flow__edge-textbg",style:l,rx:f,ry:f}),u.jsx("text",{className:"react-flow__edge-text",y:g.height/2,dy:"0.3em",ref:S,style:r,children:s}),m]}):null}iE.displayName="EdgeText";const v8=j.memo(iE);function Cf({path:e,labelX:t,labelY:s,label:r,labelStyle:i,labelShowBg:l,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:m,interactionWidth:h=20,...v}){return u.jsxs(u.Fragment,{children:[u.jsx("path",{...v,d:e,fill:"none",className:bt(["react-flow__edge-path",v.className])}),h?u.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:h,className:"react-flow__edge-interaction"}):null,r&&Vn(t)&&Vn(s)?u.jsx(v8,{x:t,y:s,label:r,labelStyle:i,labelShowBg:l,labelBgStyle:d,labelBgPadding:f,labelBgBorderRadius:m}):null]})}function jS({pos:e,x1:t,y1:s,x2:r,y2:i}){return e===we.Left||e===we.Right?[.5*(t+r),s]:[t,.5*(s+i)]}function oE({sourceX:e,sourceY:t,sourcePosition:s=we.Bottom,targetX:r,targetY:i,targetPosition:l=we.Top}){const[d,f]=jS({pos:s,x1:e,y1:t,x2:r,y2:i}),[m,h]=jS({pos:l,x1:r,y1:i,x2:e,y2:t}),[v,g,y,b]=Mj({sourceX:e,sourceY:t,targetX:r,targetY:i,sourceControlX:d,sourceControlY:f,targetControlX:m,targetControlY:h});return[`M${e},${t} C${d},${f} ${m},${h} ${r},${i}`,v,g,y,b]}function lE(e){return j.memo(({id:t,sourceX:s,sourceY:r,targetX:i,targetY:l,sourcePosition:d,targetPosition:f,label:m,labelStyle:h,labelShowBg:v,labelBgStyle:g,labelBgPadding:y,labelBgBorderRadius:b,style:S,markerEnd:w,markerStart:N,interactionWidth:C})=>{const[T,_,R]=oE({sourceX:s,sourceY:r,sourcePosition:d,targetX:i,targetY:l,targetPosition:f}),O=e.isInternal?void 0:t;return u.jsx(Cf,{id:O,path:T,labelX:_,labelY:R,label:m,labelStyle:h,labelShowBg:v,labelBgStyle:g,labelBgPadding:y,labelBgBorderRadius:b,style:S,markerEnd:w,markerStart:N,interactionWidth:C})})}const b8=lE({isInternal:!1}),cE=lE({isInternal:!0});b8.displayName="SimpleBezierEdge";cE.displayName="SimpleBezierEdgeInternal";function uE(e){return j.memo(({id:t,sourceX:s,sourceY:r,targetX:i,targetY:l,label:d,labelStyle:f,labelShowBg:m,labelBgStyle:h,labelBgPadding:v,labelBgBorderRadius:g,style:y,sourcePosition:b=we.Bottom,targetPosition:S=we.Top,markerEnd:w,markerStart:N,pathOptions:C,interactionWidth:T})=>{const[_,R,O]=fg({sourceX:s,sourceY:r,sourcePosition:b,targetX:i,targetY:l,targetPosition:S,borderRadius:C==null?void 0:C.borderRadius,offset:C==null?void 0:C.offset,stepPosition:C==null?void 0:C.stepPosition}),B=e.isInternal?void 0:t;return u.jsx(Cf,{id:B,path:_,labelX:R,labelY:O,label:d,labelStyle:f,labelShowBg:m,labelBgStyle:h,labelBgPadding:v,labelBgBorderRadius:g,style:y,markerEnd:w,markerStart:N,interactionWidth:T})})}const dE=uE({isInternal:!1}),fE=uE({isInternal:!0});dE.displayName="SmoothStepEdge";fE.displayName="SmoothStepEdgeInternal";function hE(e){return j.memo(({id:t,...s})=>{var i;const r=e.isInternal?void 0:t;return u.jsx(dE,{...s,id:r,pathOptions:j.useMemo(()=>{var l;return{borderRadius:0,offset:(l=s.pathOptions)==null?void 0:l.offset}},[(i=s.pathOptions)==null?void 0:i.offset])})})}const S8=hE({isInternal:!1}),mE=hE({isInternal:!0});S8.displayName="StepEdge";mE.displayName="StepEdgeInternal";function pE(e){return j.memo(({id:t,sourceX:s,sourceY:r,targetX:i,targetY:l,label:d,labelStyle:f,labelShowBg:m,labelBgStyle:h,labelBgPadding:v,labelBgBorderRadius:g,style:y,markerEnd:b,markerStart:S,interactionWidth:w})=>{const[N,C,T]=Dj({sourceX:s,sourceY:r,targetX:i,targetY:l}),_=e.isInternal?void 0:t;return u.jsx(Cf,{id:_,path:N,labelX:C,labelY:T,label:d,labelStyle:f,labelShowBg:m,labelBgStyle:h,labelBgPadding:v,labelBgBorderRadius:g,style:y,markerEnd:b,markerStart:S,interactionWidth:w})})}const w8=pE({isInternal:!1}),gE=pE({isInternal:!0});w8.displayName="StraightEdge";gE.displayName="StraightEdgeInternal";function xE(e){return j.memo(({id:t,sourceX:s,sourceY:r,targetX:i,targetY:l,sourcePosition:d=we.Bottom,targetPosition:f=we.Top,label:m,labelStyle:h,labelShowBg:v,labelBgStyle:g,labelBgPadding:y,labelBgBorderRadius:b,style:S,markerEnd:w,markerStart:N,pathOptions:C,interactionWidth:T})=>{const[_,R,O]=kj({sourceX:s,sourceY:r,sourcePosition:d,targetX:i,targetY:l,targetPosition:f,curvature:C==null?void 0:C.curvature}),B=e.isInternal?void 0:t;return u.jsx(Cf,{id:B,path:_,labelX:R,labelY:O,label:m,labelStyle:h,labelShowBg:v,labelBgStyle:g,labelBgPadding:y,labelBgBorderRadius:b,style:S,markerEnd:w,markerStart:N,interactionWidth:T})})}const N8=xE({isInternal:!1}),yE=xE({isInternal:!0});N8.displayName="BezierEdge";yE.displayName="BezierEdgeInternal";const ES={default:yE,straight:gE,step:mE,smoothstep:fE,simplebezier:cE},CS={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},j8=(e,t,s)=>s===we.Left?e-t:s===we.Right?e+t:e,E8=(e,t,s)=>s===we.Top?e-t:s===we.Bottom?e+t:e,_S="react-flow__edgeupdater";function RS({position:e,centerX:t,centerY:s,radius:r=10,onMouseDown:i,onMouseEnter:l,onMouseOut:d,type:f}){return u.jsx("circle",{onMouseDown:i,onMouseEnter:l,onMouseOut:d,className:bt([_S,`${_S}-${f}`]),cx:j8(t,r,e),cy:E8(s,r,e),r,stroke:"transparent",fill:"transparent"})}function C8({isReconnectable:e,reconnectRadius:t,edge:s,sourceX:r,sourceY:i,targetX:l,targetY:d,sourcePosition:f,targetPosition:m,onReconnect:h,onReconnectStart:v,onReconnectEnd:g,setReconnecting:y,setUpdateHover:b}){const S=ot(),w=(R,O)=>{if(R.button!==0)return;const{autoPanOnConnect:B,domNode:L,connectionMode:M,connectionRadius:I,lib:H,onConnectStart:D,cancelConnection:Y,nodeLookup:K,rfId:U,panBy:q,updateConnection:A}=S.getState(),$=O.type==="target",z=(P,Q)=>{y(!1),g==null||g(P,s,O.type,Q)},G=P=>h==null?void 0:h(s,P),V=(P,Q)=>{y(!0),v==null||v(R,s,O.type),D==null||D(P,Q)};pg.onPointerDown(R.nativeEvent,{autoPanOnConnect:B,connectionMode:M,connectionRadius:I,domNode:L,handleId:O.id,nodeId:O.nodeId,nodeLookup:K,isTarget:$,edgeUpdaterType:O.type,lib:H,flowId:U,cancelConnection:Y,panBy:q,isValidConnection:(...P)=>{var Q,ee;return((ee=(Q=S.getState()).isValidConnection)==null?void 0:ee.call(Q,...P))??!0},onConnect:G,onConnectStart:V,onConnectEnd:(...P)=>{var Q,ee;return(ee=(Q=S.getState()).onConnectEnd)==null?void 0:ee.call(Q,...P)},onReconnectEnd:z,updateConnection:A,getTransform:()=>S.getState().transform,getFromHandle:()=>S.getState().connection.fromHandle,dragThreshold:S.getState().connectionDragThreshold,handleDomNode:R.currentTarget})},N=R=>w(R,{nodeId:s.target,id:s.targetHandle??null,type:"target"}),C=R=>w(R,{nodeId:s.source,id:s.sourceHandle??null,type:"source"}),T=()=>b(!0),_=()=>b(!1);return u.jsxs(u.Fragment,{children:[(e===!0||e==="source")&&u.jsx(RS,{position:f,centerX:r,centerY:i,radius:t,onMouseDown:N,onMouseEnter:T,onMouseOut:_,type:"source"}),(e===!0||e==="target")&&u.jsx(RS,{position:m,centerX:l,centerY:d,radius:t,onMouseDown:C,onMouseEnter:T,onMouseOut:_,type:"target"})]})}function _8({id:e,edgesFocusable:t,edgesReconnectable:s,elementsSelectable:r,onClick:i,onDoubleClick:l,onContextMenu:d,onMouseEnter:f,onMouseMove:m,onMouseLeave:h,reconnectRadius:v,onReconnect:g,onReconnectStart:y,onReconnectEnd:b,rfId:S,edgeTypes:w,noPanClassName:N,onError:C,disableKeyboardA11y:T}){let _=Ve(ye=>ye.edgeLookup.get(e));const R=Ve(ye=>ye.defaultEdgeOptions);_=R?{...R,..._}:_;let O=_.type||"default",B=(w==null?void 0:w[O])||ES[O];B===void 0&&(C==null||C("011",hs.error011(O)),O="default",B=(w==null?void 0:w.default)||ES.default);const L=!!(_.focusable||t&&typeof _.focusable>"u"),M=typeof g<"u"&&(_.reconnectable||s&&typeof _.reconnectable>"u"),I=!!(_.selectable||r&&typeof _.selectable>"u"),H=j.useRef(null),[D,Y]=j.useState(!1),[K,U]=j.useState(!1),q=ot(),{zIndex:A,sourceX:$,sourceY:z,targetX:G,targetY:V,sourcePosition:P,targetPosition:Q}=Ve(j.useCallback(ye=>{const ve=ye.nodeLookup.get(_.source),de=ye.nodeLookup.get(_.target);if(!ve||!de)return{zIndex:_.zIndex,...CS};const Ae=wL({id:e,sourceNode:ve,targetNode:de,sourceHandle:_.sourceHandle||null,targetHandle:_.targetHandle||null,connectionMode:ye.connectionMode,onError:C});return{zIndex:mL({selected:_.selected,zIndex:_.zIndex,sourceNode:ve,targetNode:de,elevateOnSelect:ye.elevateEdgesOnSelect,zIndexMode:ye.zIndexMode}),...Ae||CS}},[_.source,_.target,_.sourceHandle,_.targetHandle,_.selected,_.zIndex]),it),ee=j.useMemo(()=>_.markerStart?`url('#${hg(_.markerStart,S)}')`:void 0,[_.markerStart,S]),se=j.useMemo(()=>_.markerEnd?`url('#${hg(_.markerEnd,S)}')`:void 0,[_.markerEnd,S]);if(_.hidden||$===null||z===null||G===null||V===null)return null;const oe=ye=>{var Re;const{addSelectedEdges:ve,unselectNodesAndEdges:de,multiSelectionActive:Ae}=q.getState();I&&(q.setState({nodesSelectionActive:!1}),_.selected&&Ae?(de({nodes:[],edges:[_]}),(Re=H.current)==null||Re.blur()):ve([e])),i&&i(ye,_)},ce=l?ye=>{l(ye,{..._})}:void 0,fe=d?ye=>{d(ye,{..._})}:void 0,ue=f?ye=>{f(ye,{..._})}:void 0,he=m?ye=>{m(ye,{..._})}:void 0,Ce=h?ye=>{h(ye,{..._})}:void 0,Se=ye=>{var ve;if(!T&&xj.includes(ye.key)&&I){const{unselectNodesAndEdges:de,addSelectedEdges:Ae}=q.getState();ye.key==="Escape"?((ve=H.current)==null||ve.blur(),de({edges:[_]})):Ae([e])}};return u.jsx("svg",{style:{zIndex:A},children:u.jsxs("g",{className:bt(["react-flow__edge",`react-flow__edge-${O}`,_.className,N,{selected:_.selected,animated:_.animated,inactive:!I&&!i,updating:D,selectable:I}]),onClick:oe,onDoubleClick:ce,onContextMenu:fe,onMouseEnter:ue,onMouseMove:he,onMouseLeave:Ce,onKeyDown:L?Se:void 0,tabIndex:L?0:void 0,role:_.ariaRole??(L?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":_.ariaLabel===null?void 0:_.ariaLabel||`Edge from ${_.source} to ${_.target}`,"aria-describedby":L?`${Fj}-${S}`:void 0,ref:H,..._.domAttributes,children:[!K&&u.jsx(B,{id:e,source:_.source,target:_.target,type:_.type,selected:_.selected,animated:_.animated,selectable:I,deletable:_.deletable??!0,label:_.label,labelStyle:_.labelStyle,labelShowBg:_.labelShowBg,labelBgStyle:_.labelBgStyle,labelBgPadding:_.labelBgPadding,labelBgBorderRadius:_.labelBgBorderRadius,sourceX:$,sourceY:z,targetX:G,targetY:V,sourcePosition:P,targetPosition:Q,data:_.data,style:_.style,sourceHandleId:_.sourceHandle,targetHandleId:_.targetHandle,markerStart:ee,markerEnd:se,pathOptions:"pathOptions"in _?_.pathOptions:void 0,interactionWidth:_.interactionWidth}),M&&u.jsx(C8,{edge:_,isReconnectable:M,reconnectRadius:v,onReconnect:g,onReconnectStart:y,onReconnectEnd:b,sourceX:$,sourceY:z,targetX:G,targetY:V,sourcePosition:P,targetPosition:Q,setUpdateHover:Y,setReconnecting:U})]})})}var R8=j.memo(_8);const T8=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function vE({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:s,edgeTypes:r,noPanClassName:i,onReconnect:l,onEdgeContextMenu:d,onEdgeMouseEnter:f,onEdgeMouseMove:m,onEdgeMouseLeave:h,onEdgeClick:v,reconnectRadius:g,onEdgeDoubleClick:y,onReconnectStart:b,onReconnectEnd:S,disableKeyboardA11y:w}){const{edgesFocusable:N,edgesReconnectable:C,elementsSelectable:T,onError:_}=Ve(T8,it),R=h8(t);return u.jsxs("div",{className:"react-flow__edges",children:[u.jsx(y8,{defaultColor:e,rfId:s}),R.map(O=>u.jsx(R8,{id:O,edgesFocusable:N,edgesReconnectable:C,elementsSelectable:T,noPanClassName:i,onReconnect:l,onContextMenu:d,onMouseEnter:f,onMouseMove:m,onMouseLeave:h,onClick:v,reconnectRadius:g,onDoubleClick:y,onReconnectStart:b,onReconnectEnd:S,rfId:s,onError:_,edgeTypes:r,disableKeyboardA11y:w},O))]})}vE.displayName="EdgeRenderer";const A8=j.memo(vE),M8=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function k8({children:e}){const t=Ve(M8);return u.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:t},children:e})}function O8(e){const t=c0(),s=j.useRef(!1);j.useEffect(()=>{!s.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),s.current=!0)},[e,t.viewportInitialized])}const D8=e=>{var t;return(t=e.panZoom)==null?void 0:t.syncViewport};function L8(e){const t=Ve(D8),s=ot();return j.useEffect(()=>{e&&(t==null||t(e),s.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function z8(e){return e.connection.inProgress?{...e.connection,to:Nc(e.connection.to,e.transform)}:{...e.connection}}function P8(e){return z8}function I8(e){const t=P8();return Ve(t,it)}const B8=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function H8({containerStyle:e,style:t,type:s,component:r}){const{nodesConnectable:i,width:l,height:d,isValid:f,inProgress:m}=Ve(B8,it);return!(l&&i&&m)?null:u.jsx("svg",{style:e,width:l,height:d,className:"react-flow__connectionline react-flow__container",children:u.jsx("g",{className:bt(["react-flow__connection",bj(f)]),children:u.jsx(bE,{style:t,type:s,CustomComponent:r,isValid:f})})})}const bE=({style:e,type:t=Da.Bezier,CustomComponent:s,isValid:r})=>{const{inProgress:i,from:l,fromNode:d,fromHandle:f,fromPosition:m,to:h,toNode:v,toHandle:g,toPosition:y,pointer:b}=I8();if(!i)return;if(s)return u.jsx(s,{connectionLineType:t,connectionLineStyle:e,fromNode:d,fromHandle:f,fromX:l.x,fromY:l.y,toX:h.x,toY:h.y,fromPosition:m,toPosition:y,connectionStatus:bj(r),toNode:v,toHandle:g,pointer:b});let S="";const w={sourceX:l.x,sourceY:l.y,sourcePosition:m,targetX:h.x,targetY:h.y,targetPosition:y};switch(t){case Da.Bezier:[S]=kj(w);break;case Da.SimpleBezier:[S]=oE(w);break;case Da.Step:[S]=fg({...w,borderRadius:0});break;case Da.SmoothStep:[S]=fg(w);break;default:[S]=Dj(w)}return u.jsx("path",{d:S,fill:"none",className:"react-flow__connection-path",style:e})};bE.displayName="ConnectionLine";const U8={};function TS(e=U8){j.useRef(e),ot(),j.useEffect(()=>{},[e])}function $8(){ot(),j.useRef(!1),j.useEffect(()=>{},[])}function SE({nodeTypes:e,edgeTypes:t,onInit:s,onNodeClick:r,onEdgeClick:i,onNodeDoubleClick:l,onEdgeDoubleClick:d,onNodeMouseEnter:f,onNodeMouseMove:m,onNodeMouseLeave:h,onNodeContextMenu:v,onSelectionContextMenu:g,onSelectionStart:y,onSelectionEnd:b,connectionLineType:S,connectionLineStyle:w,connectionLineComponent:N,connectionLineContainerStyle:C,selectionKeyCode:T,selectionOnDrag:_,selectionMode:R,multiSelectionKeyCode:O,panActivationKeyCode:B,zoomActivationKeyCode:L,deleteKeyCode:M,onlyRenderVisibleElements:I,elementsSelectable:H,defaultViewport:D,translateExtent:Y,minZoom:K,maxZoom:U,preventScrolling:q,defaultMarkerColor:A,zoomOnScroll:$,zoomOnPinch:z,panOnScroll:G,panOnScrollSpeed:V,panOnScrollMode:P,zoomOnDoubleClick:Q,panOnDrag:ee,onPaneClick:se,onPaneMouseEnter:oe,onPaneMouseMove:ce,onPaneMouseLeave:fe,onPaneScroll:ue,onPaneContextMenu:he,paneClickDistance:Ce,nodeClickDistance:Se,onEdgeContextMenu:ye,onEdgeMouseEnter:ve,onEdgeMouseMove:de,onEdgeMouseLeave:Ae,reconnectRadius:Re,onReconnect:Be,onReconnectStart:St,onReconnectEnd:dt,noDragClassName:fn,noWheelClassName:jn,noPanClassName:ps,disableKeyboardA11y:Fn,nodeExtent:Me,rfId:ft,viewport:kt,onViewportChange:Xn}){return TS(e),TS(t),$8(),O8(s),L8(kt),u.jsx(s8,{onPaneClick:se,onPaneMouseEnter:oe,onPaneMouseMove:ce,onPaneMouseLeave:fe,onPaneContextMenu:he,onPaneScroll:ue,paneClickDistance:Ce,deleteKeyCode:M,selectionKeyCode:T,selectionOnDrag:_,selectionMode:R,onSelectionStart:y,onSelectionEnd:b,multiSelectionKeyCode:O,panActivationKeyCode:B,zoomActivationKeyCode:L,elementsSelectable:H,zoomOnScroll:$,zoomOnPinch:z,zoomOnDoubleClick:Q,panOnScroll:G,panOnScrollSpeed:V,panOnScrollMode:P,panOnDrag:ee,defaultViewport:D,translateExtent:Y,minZoom:K,maxZoom:U,onSelectionContextMenu:g,preventScrolling:q,noDragClassName:fn,noWheelClassName:jn,noPanClassName:ps,disableKeyboardA11y:Fn,onViewportChange:Xn,isControlledViewport:!!kt,children:u.jsxs(k8,{children:[u.jsx(A8,{edgeTypes:t,onEdgeClick:i,onEdgeDoubleClick:d,onReconnect:Be,onReconnectStart:St,onReconnectEnd:dt,onlyRenderVisibleElements:I,onEdgeContextMenu:ye,onEdgeMouseEnter:ve,onEdgeMouseMove:de,onEdgeMouseLeave:Ae,reconnectRadius:Re,defaultMarkerColor:A,noPanClassName:ps,disableKeyboardA11y:Fn,rfId:ft}),u.jsx(H8,{style:w,type:S,component:N,containerStyle:C}),u.jsx("div",{className:"react-flow__edgelabel-renderer"}),u.jsx(f8,{nodeTypes:e,onNodeClick:r,onNodeDoubleClick:l,onNodeMouseEnter:f,onNodeMouseMove:m,onNodeMouseLeave:h,onNodeContextMenu:v,nodeClickDistance:Se,onlyRenderVisibleElements:I,noPanClassName:ps,noDragClassName:fn,disableKeyboardA11y:Fn,nodeExtent:Me,rfId:ft}),u.jsx("div",{className:"react-flow__viewport-portal"})]})})}SE.displayName="GraphView";const q8=j.memo(SE),AS=({nodes:e,edges:t,defaultNodes:s,defaultEdges:r,width:i,height:l,fitView:d,fitViewOptions:f,minZoom:m=.5,maxZoom:h=2,nodeOrigin:v,nodeExtent:g,zIndexMode:y="basic"}={})=>{const b=new Map,S=new Map,w=new Map,N=new Map,C=r??t??[],T=s??e??[],_=v??[0,0],R=g??sc;Pj(w,N,C);const O=mg(T,b,S,{nodeOrigin:_,nodeExtent:R,zIndexMode:y});let B=[0,0,1];if(d&&i&&l){const L=Sc(b,{filter:D=>!!((D.width||D.initialWidth)&&(D.height||D.initialHeight))}),{x:M,y:I,zoom:H}=n0(L,i,l,m,h,(f==null?void 0:f.padding)??.1);B=[M,I,H]}return{rfId:"1",width:i??0,height:l??0,transform:B,nodes:T,nodesInitialized:O,nodeLookup:b,parentLookup:S,edges:C,edgeLookup:N,connectionLookup:w,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:s!==void 0,hasDefaultEdges:r!==void 0,panZoom:null,minZoom:m,maxZoom:h,translateExtent:sc,nodeExtent:R,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:bo.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:_,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:d??!1,fitViewOptions:f,fitViewResolver:null,connection:{...vj},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:lL,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:yj,zIndexMode:y,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},V8=({nodes:e,edges:t,defaultNodes:s,defaultEdges:r,width:i,height:l,fitView:d,fitViewOptions:f,minZoom:m,maxZoom:h,nodeOrigin:v,nodeExtent:g,zIndexMode:y})=>iz((b,S)=>{async function w(){const{nodeLookup:N,panZoom:C,fitViewOptions:T,fitViewResolver:_,width:R,height:O,minZoom:B,maxZoom:L}=S();C&&(await iL({nodes:N,width:R,height:O,panZoom:C,minZoom:B,maxZoom:L},T),_==null||_.resolve(!0),b({fitViewResolver:null}))}return{...AS({nodes:e,edges:t,width:i,height:l,fitView:d,fitViewOptions:f,minZoom:m,maxZoom:h,nodeOrigin:v,nodeExtent:g,defaultNodes:s,defaultEdges:r,zIndexMode:y}),setNodes:N=>{const{nodeLookup:C,parentLookup:T,nodeOrigin:_,elevateNodesOnSelect:R,fitViewQueued:O,zIndexMode:B}=S(),L=mg(N,C,T,{nodeOrigin:_,nodeExtent:g,elevateNodesOnSelect:R,checkEquality:!0,zIndexMode:B});O&&L?(w(),b({nodes:N,nodesInitialized:L,fitViewQueued:!1,fitViewOptions:void 0})):b({nodes:N,nodesInitialized:L})},setEdges:N=>{const{connectionLookup:C,edgeLookup:T}=S();Pj(C,T,N),b({edges:N})},setDefaultNodesAndEdges:(N,C)=>{if(N){const{setNodes:T}=S();T(N),b({hasDefaultNodes:!0})}if(C){const{setEdges:T}=S();T(C),b({hasDefaultEdges:!0})}},updateNodeInternals:N=>{const{triggerNodeChanges:C,nodeLookup:T,parentLookup:_,domNode:R,nodeOrigin:O,nodeExtent:B,debug:L,fitViewQueued:M,zIndexMode:I}=S(),{changes:H,updatedInternals:D}=AL(N,T,_,R,O,B,I);D&&(CL(T,_,{nodeOrigin:O,nodeExtent:B,zIndexMode:I}),M?(w(),b({fitViewQueued:!1,fitViewOptions:void 0})):b({}),(H==null?void 0:H.length)>0&&(L&&console.log("React Flow: trigger node changes",H),C==null||C(H)))},updateNodePositions:(N,C=!1)=>{const T=[];let _=[];const{nodeLookup:R,triggerNodeChanges:O,connection:B,updateConnection:L,onNodesChangeMiddlewareMap:M}=S();for(const[I,H]of N){const D=R.get(I),Y=!!(D!=null&&D.expandParent&&(D!=null&&D.parentId)&&(H!=null&&H.position)),K={id:I,type:"position",position:Y?{x:Math.max(0,H.position.x),y:Math.max(0,H.position.y)}:H.position,dragging:C};if(D&&B.inProgress&&B.fromNode.id===D.id){const U=ni(D,B.fromHandle,we.Left,!0);L({...B,from:U})}Y&&D.parentId&&T.push({id:I,parentId:D.parentId,rect:{...H.internals.positionAbsolute,width:H.measured.width??0,height:H.measured.height??0}}),_.push(K)}if(T.length>0){const{parentLookup:I,nodeOrigin:H}=S(),D=l0(T,R,I,H);_.push(...D)}for(const I of M.values())_=I(_);O(_)},triggerNodeChanges:N=>{const{onNodesChange:C,setNodes:T,nodes:_,hasDefaultNodes:R,debug:O}=S();if(N!=null&&N.length){if(R){const B=_z(N,_);T(B)}O&&console.log("React Flow: trigger node changes",N),C==null||C(N)}},triggerEdgeChanges:N=>{const{onEdgesChange:C,setEdges:T,edges:_,hasDefaultEdges:R,debug:O}=S();if(N!=null&&N.length){if(R){const B=Rz(N,_);T(B)}O&&console.log("React Flow: trigger edge changes",N),C==null||C(N)}},addSelectedNodes:N=>{const{multiSelectionActive:C,edgeLookup:T,nodeLookup:_,triggerNodeChanges:R,triggerEdgeChanges:O}=S();if(C){const B=N.map(L=>Rr(L,!0));R(B);return}R(Ji(_,new Set([...N]),!0)),O(Ji(T))},addSelectedEdges:N=>{const{multiSelectionActive:C,edgeLookup:T,nodeLookup:_,triggerNodeChanges:R,triggerEdgeChanges:O}=S();if(C){const B=N.map(L=>Rr(L,!0));O(B);return}O(Ji(T,new Set([...N]))),R(Ji(_,new Set,!0))},unselectNodesAndEdges:({nodes:N,edges:C}={})=>{const{edges:T,nodes:_,nodeLookup:R,triggerNodeChanges:O,triggerEdgeChanges:B}=S(),L=N||_,M=C||T,I=[];for(const D of L){if(!D.selected)continue;const Y=R.get(D.id);Y&&(Y.selected=!1),I.push(Rr(D.id,!1))}const H=[];for(const D of M)D.selected&&H.push(Rr(D.id,!1));O(I),B(H)},setMinZoom:N=>{const{panZoom:C,maxZoom:T}=S();C==null||C.setScaleExtent([N,T]),b({minZoom:N})},setMaxZoom:N=>{const{panZoom:C,minZoom:T}=S();C==null||C.setScaleExtent([T,N]),b({maxZoom:N})},setTranslateExtent:N=>{var C;(C=S().panZoom)==null||C.setTranslateExtent(N),b({translateExtent:N})},resetSelectedElements:()=>{const{edges:N,nodes:C,triggerNodeChanges:T,triggerEdgeChanges:_,elementsSelectable:R}=S();if(!R)return;const O=C.reduce((L,M)=>M.selected?[...L,Rr(M.id,!1)]:L,[]),B=N.reduce((L,M)=>M.selected?[...L,Rr(M.id,!1)]:L,[]);T(O),_(B)},setNodeExtent:N=>{const{nodes:C,nodeLookup:T,parentLookup:_,nodeOrigin:R,elevateNodesOnSelect:O,nodeExtent:B,zIndexMode:L}=S();N[0][0]===B[0][0]&&N[0][1]===B[0][1]&&N[1][0]===B[1][0]&&N[1][1]===B[1][1]||(mg(C,T,_,{nodeOrigin:R,nodeExtent:N,elevateNodesOnSelect:O,checkEquality:!1,zIndexMode:L}),b({nodeExtent:N}))},panBy:N=>{const{transform:C,width:T,height:_,panZoom:R,translateExtent:O}=S();return ML({delta:N,panZoom:R,transform:C,translateExtent:O,width:T,height:_})},setCenter:async(N,C,T)=>{const{width:_,height:R,maxZoom:O,panZoom:B}=S();if(!B)return Promise.resolve(!1);const L=typeof(T==null?void 0:T.zoom)<"u"?T.zoom:O;return await B.setViewport({x:_/2-N*L,y:R/2-C*L,zoom:L},{duration:T==null?void 0:T.duration,ease:T==null?void 0:T.ease,interpolate:T==null?void 0:T.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{b({connection:{...vj}})},updateConnection:N=>{b({connection:N})},reset:()=>b({...AS()})}},Object.is);function G8({initialNodes:e,initialEdges:t,defaultNodes:s,defaultEdges:r,initialWidth:i,initialHeight:l,initialMinZoom:d,initialMaxZoom:f,initialFitViewOptions:m,fitView:h,nodeOrigin:v,nodeExtent:g,zIndexMode:y,children:b}){const[S]=j.useState(()=>V8({nodes:e,edges:t,defaultNodes:s,defaultEdges:r,width:i,height:l,fitView:h,minZoom:d,maxZoom:f,fitViewOptions:m,nodeOrigin:v,nodeExtent:g,zIndexMode:y}));return u.jsx(oz,{value:S,children:u.jsx(kz,{children:b})})}function Y8({children:e,nodes:t,edges:s,defaultNodes:r,defaultEdges:i,width:l,height:d,fitView:f,fitViewOptions:m,minZoom:h,maxZoom:v,nodeOrigin:g,nodeExtent:y,zIndexMode:b}){return j.useContext(Nf)?u.jsx(u.Fragment,{children:e}):u.jsx(G8,{initialNodes:t,initialEdges:s,defaultNodes:r,defaultEdges:i,initialWidth:l,initialHeight:d,fitView:f,initialFitViewOptions:m,initialMinZoom:h,initialMaxZoom:v,nodeOrigin:g,nodeExtent:y,zIndexMode:b,children:e})}const Q8={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function K8({nodes:e,edges:t,defaultNodes:s,defaultEdges:r,className:i,nodeTypes:l,edgeTypes:d,onNodeClick:f,onEdgeClick:m,onInit:h,onMove:v,onMoveStart:g,onMoveEnd:y,onConnect:b,onConnectStart:S,onConnectEnd:w,onClickConnectStart:N,onClickConnectEnd:C,onNodeMouseEnter:T,onNodeMouseMove:_,onNodeMouseLeave:R,onNodeContextMenu:O,onNodeDoubleClick:B,onNodeDragStart:L,onNodeDrag:M,onNodeDragStop:I,onNodesDelete:H,onEdgesDelete:D,onDelete:Y,onSelectionChange:K,onSelectionDragStart:U,onSelectionDrag:q,onSelectionDragStop:A,onSelectionContextMenu:$,onSelectionStart:z,onSelectionEnd:G,onBeforeDelete:V,connectionMode:P,connectionLineType:Q=Da.Bezier,connectionLineStyle:ee,connectionLineComponent:se,connectionLineContainerStyle:oe,deleteKeyCode:ce="Backspace",selectionKeyCode:fe="Shift",selectionOnDrag:ue=!1,selectionMode:he=ac.Full,panActivationKeyCode:Ce="Space",multiSelectionKeyCode:Se=oc()?"Meta":"Control",zoomActivationKeyCode:ye=oc()?"Meta":"Control",snapToGrid:ve,snapGrid:de,onlyRenderVisibleElements:Ae=!1,selectNodesOnDrag:Re,nodesDraggable:Be,autoPanOnNodeFocus:St,nodesConnectable:dt,nodesFocusable:fn,nodeOrigin:jn=Xj,edgesFocusable:ps,edgesReconnectable:Fn,elementsSelectable:Me=!0,defaultViewport:ft=bz,minZoom:kt=.5,maxZoom:Xn=2,translateExtent:nr=sc,preventScrolling:Rf=!0,nodeExtent:ri,defaultMarkerColor:Tf="#b1b1b7",zoomOnScroll:Af=!0,zoomOnPinch:sr=!0,panOnScroll:$t=!1,panOnScrollSpeed:Zn=.5,panOnScrollMode:qt=Fr.Free,zoomOnDoubleClick:Mf=!0,panOnDrag:kf=!0,onPaneClick:Of,onPaneMouseEnter:ii,onPaneMouseMove:oi,onPaneMouseLeave:li,onPaneScroll:gs,onPaneContextMenu:ci,paneClickDistance:ar=1,nodeClickDistance:Df=0,children:jc,onReconnect:_o,onReconnectStart:rr,onReconnectEnd:Lf,onEdgeContextMenu:Ec,onEdgeDoubleClick:Cc,onEdgeMouseEnter:_c,onEdgeMouseMove:Ro,onEdgeMouseLeave:To,reconnectRadius:Rc=10,onNodesChange:Tc,onEdgesChange:Wn,noDragClassName:wt="nodrag",noWheelClassName:It="nowheel",noPanClassName:xs="nopan",fitView:ui,fitViewOptions:Ac,connectOnClick:zf,attributionPosition:Mc,proOptions:ir,defaultEdgeOptions:Ao,elevateNodesOnSelect:Ws=!0,elevateEdgesOnSelect:Js=!1,disableKeyboardA11y:ea=!1,autoPanOnConnect:ta,autoPanOnNodeDrag:pt,autoPanSpeed:kc,connectionRadius:Oc,isValidConnection:ys,onError:na,style:Pf,id:Mo,nodeDragThreshold:Dc,connectionDragThreshold:If,viewport:di,onViewportChange:fi,width:zn,height:Zt,colorMode:Lc="light",debug:Bf,onScroll:sa,ariaLabelConfig:zc,zIndexMode:or="basic",...Hf},Wt){const lr=Mo||"1",Pc=jz(Lc),ko=j.useCallback(vs=>{vs.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),sa==null||sa(vs)},[sa]);return u.jsx("div",{"data-testid":"rf__wrapper",...Hf,onScroll:ko,style:{...Pf,...Q8},ref:Wt,className:bt(["react-flow",i,Pc]),id:Mo,role:"application",children:u.jsxs(Y8,{nodes:e,edges:t,width:zn,height:Zt,fitView:ui,fitViewOptions:Ac,minZoom:kt,maxZoom:Xn,nodeOrigin:jn,nodeExtent:ri,zIndexMode:or,children:[u.jsx(q8,{onInit:h,onNodeClick:f,onEdgeClick:m,onNodeMouseEnter:T,onNodeMouseMove:_,onNodeMouseLeave:R,onNodeContextMenu:O,onNodeDoubleClick:B,nodeTypes:l,edgeTypes:d,connectionLineType:Q,connectionLineStyle:ee,connectionLineComponent:se,connectionLineContainerStyle:oe,selectionKeyCode:fe,selectionOnDrag:ue,selectionMode:he,deleteKeyCode:ce,multiSelectionKeyCode:Se,panActivationKeyCode:Ce,zoomActivationKeyCode:ye,onlyRenderVisibleElements:Ae,defaultViewport:ft,translateExtent:nr,minZoom:kt,maxZoom:Xn,preventScrolling:Rf,zoomOnScroll:Af,zoomOnPinch:sr,zoomOnDoubleClick:Mf,panOnScroll:$t,panOnScrollSpeed:Zn,panOnScrollMode:qt,panOnDrag:kf,onPaneClick:Of,onPaneMouseEnter:ii,onPaneMouseMove:oi,onPaneMouseLeave:li,onPaneScroll:gs,onPaneContextMenu:ci,paneClickDistance:ar,nodeClickDistance:Df,onSelectionContextMenu:$,onSelectionStart:z,onSelectionEnd:G,onReconnect:_o,onReconnectStart:rr,onReconnectEnd:Lf,onEdgeContextMenu:Ec,onEdgeDoubleClick:Cc,onEdgeMouseEnter:_c,onEdgeMouseMove:Ro,onEdgeMouseLeave:To,reconnectRadius:Rc,defaultMarkerColor:Tf,noDragClassName:wt,noWheelClassName:It,noPanClassName:xs,rfId:lr,disableKeyboardA11y:ea,nodeExtent:ri,viewport:di,onViewportChange:fi}),u.jsx(Nz,{nodes:e,edges:t,defaultNodes:s,defaultEdges:r,onConnect:b,onConnectStart:S,onConnectEnd:w,onClickConnectStart:N,onClickConnectEnd:C,nodesDraggable:Be,autoPanOnNodeFocus:St,nodesConnectable:dt,nodesFocusable:fn,edgesFocusable:ps,edgesReconnectable:Fn,elementsSelectable:Me,elevateNodesOnSelect:Ws,elevateEdgesOnSelect:Js,minZoom:kt,maxZoom:Xn,nodeExtent:ri,onNodesChange:Tc,onEdgesChange:Wn,snapToGrid:ve,snapGrid:de,connectionMode:P,translateExtent:nr,connectOnClick:zf,defaultEdgeOptions:Ao,fitView:ui,fitViewOptions:Ac,onNodesDelete:H,onEdgesDelete:D,onDelete:Y,onNodeDragStart:L,onNodeDrag:M,onNodeDragStop:I,onSelectionDrag:q,onSelectionDragStart:U,onSelectionDragStop:A,onMove:v,onMoveStart:g,onMoveEnd:y,noPanClassName:xs,nodeOrigin:jn,rfId:lr,autoPanOnConnect:ta,autoPanOnNodeDrag:pt,autoPanSpeed:kc,onError:na,connectionRadius:Oc,isValidConnection:ys,selectNodesOnDrag:Re,nodeDragThreshold:Dc,connectionDragThreshold:If,onBeforeDelete:V,debug:Bf,ariaLabelConfig:zc,zIndexMode:or}),u.jsx(vz,{onSelectionChange:K}),jc,u.jsx(mz,{proOptions:ir,position:Mc}),u.jsx(hz,{rfId:lr,disableKeyboardA11y:ea})]})})}var wE=Wj(K8);function F8({dimensions:e,lineWidth:t,variant:s,className:r}){return u.jsx("path",{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:bt(["react-flow__background-pattern",s,r])})}function X8({radius:e,className:t}){return u.jsx("circle",{cx:e,cy:e,r:e,className:bt(["react-flow__background-pattern","dots",t])})}var Za;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(Za||(Za={}));const Z8={[Za.Dots]:1,[Za.Lines]:1,[Za.Cross]:6},W8=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function NE({id:e,variant:t=Za.Dots,gap:s=20,size:r,lineWidth:i=1,offset:l=0,color:d,bgColor:f,style:m,className:h,patternClassName:v}){const g=j.useRef(null),{transform:y,patternId:b}=Ve(W8,it),S=r||Z8[t],w=t===Za.Dots,N=t===Za.Cross,C=Array.isArray(s)?s:[s,s],T=[C[0]*y[2]||1,C[1]*y[2]||1],_=S*y[2],R=Array.isArray(l)?l:[l,l],O=N?[_,_]:T,B=[R[0]*y[2]||1+O[0]/2,R[1]*y[2]||1+O[1]/2],L=`${b}${e||""}`;return u.jsxs("svg",{className:bt(["react-flow__background",h]),style:{...m,...Ef,"--xy-background-color-props":f,"--xy-background-pattern-color-props":d},ref:g,"data-testid":"rf__background",children:[u.jsx("pattern",{id:L,x:y[0]%T[0],y:y[1]%T[1],width:T[0],height:T[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${B[0]},-${B[1]})`,children:w?u.jsx(X8,{radius:_/2,className:v}):u.jsx(F8,{dimensions:O,lineWidth:i,variant:t,className:v})}),u.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${L})`})]})}NE.displayName="Background";const J8=j.memo(NE);function e6(){return u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:u.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function t6(){return u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:u.jsx("path",{d:"M0 0h32v4.2H0z"})})}function n6(){return u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:u.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 s6(){return u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:u.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 a6(){return u.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:u.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 vd({children:e,className:t,...s}){return u.jsx("button",{type:"button",className:bt(["react-flow__controls-button",t]),...s,children:e})}const r6=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function jE({style:e,showZoom:t=!0,showFitView:s=!0,showInteractive:r=!0,fitViewOptions:i,onZoomIn:l,onZoomOut:d,onFitView:f,onInteractiveChange:m,className:h,children:v,position:g="bottom-left",orientation:y="vertical","aria-label":b}){const S=ot(),{isInteractive:w,minZoomReached:N,maxZoomReached:C,ariaLabelConfig:T}=Ve(r6,it),{zoomIn:_,zoomOut:R,fitView:O}=c0(),B=()=>{_(),l==null||l()},L=()=>{R(),d==null||d()},M=()=>{O(i),f==null||f()},I=()=>{S.setState({nodesDraggable:!w,nodesConnectable:!w,elementsSelectable:!w}),m==null||m(!w)},H=y==="horizontal"?"horizontal":"vertical";return u.jsxs(jf,{className:bt(["react-flow__controls",H,h]),position:g,style:e,"data-testid":"rf__controls","aria-label":b??T["controls.ariaLabel"],children:[t&&u.jsxs(u.Fragment,{children:[u.jsx(vd,{onClick:B,className:"react-flow__controls-zoomin",title:T["controls.zoomIn.ariaLabel"],"aria-label":T["controls.zoomIn.ariaLabel"],disabled:C,children:u.jsx(e6,{})}),u.jsx(vd,{onClick:L,className:"react-flow__controls-zoomout",title:T["controls.zoomOut.ariaLabel"],"aria-label":T["controls.zoomOut.ariaLabel"],disabled:N,children:u.jsx(t6,{})})]}),s&&u.jsx(vd,{className:"react-flow__controls-fitview",onClick:M,title:T["controls.fitView.ariaLabel"],"aria-label":T["controls.fitView.ariaLabel"],children:u.jsx(n6,{})}),r&&u.jsx(vd,{className:"react-flow__controls-interactive",onClick:I,title:T["controls.interactive.ariaLabel"],"aria-label":T["controls.interactive.ariaLabel"],children:w?u.jsx(a6,{}):u.jsx(s6,{})}),v]})}jE.displayName="Controls";const EE=j.memo(jE);function i6({id:e,x:t,y:s,width:r,height:i,style:l,color:d,strokeColor:f,strokeWidth:m,className:h,borderRadius:v,shapeRendering:g,selected:y,onClick:b}){const{background:S,backgroundColor:w}=l||{},N=d||S||w;return u.jsx("rect",{className:bt(["react-flow__minimap-node",{selected:y},h]),x:t,y:s,rx:v,ry:v,width:r,height:i,style:{fill:N,stroke:f,strokeWidth:m},shapeRendering:g,onClick:b?C=>b(C,e):void 0})}const o6=j.memo(i6),l6=e=>e.nodes.map(t=>t.id),Mp=e=>e instanceof Function?e:()=>e;function c6({nodeStrokeColor:e,nodeColor:t,nodeClassName:s="",nodeBorderRadius:r=5,nodeStrokeWidth:i,nodeComponent:l=o6,onClick:d}){const f=Ve(l6,it),m=Mp(t),h=Mp(e),v=Mp(s),g=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return u.jsx(u.Fragment,{children:f.map(y=>u.jsx(d6,{id:y,nodeColorFunc:m,nodeStrokeColorFunc:h,nodeClassNameFunc:v,nodeBorderRadius:r,nodeStrokeWidth:i,NodeComponent:l,onClick:d,shapeRendering:g},y))})}function u6({id:e,nodeColorFunc:t,nodeStrokeColorFunc:s,nodeClassNameFunc:r,nodeBorderRadius:i,nodeStrokeWidth:l,shapeRendering:d,NodeComponent:f,onClick:m}){const{node:h,x:v,y:g,width:y,height:b}=Ve(S=>{const w=S.nodeLookup.get(e);if(!w)return{node:void 0,x:0,y:0,width:0,height:0};const N=w.internals.userNode,{x:C,y:T}=w.internals.positionAbsolute,{width:_,height:R}=Zs(N);return{node:N,x:C,y:T,width:_,height:R}},it);return!h||h.hidden||!Cj(h)?null:u.jsx(f,{x:v,y:g,width:y,height:b,style:h.style,selected:!!h.selected,className:r(h),color:t(h),borderRadius:i,strokeColor:s(h),strokeWidth:l,shapeRendering:d,onClick:m,id:h.id})}const d6=j.memo(u6);var f6=j.memo(c6);const h6=200,m6=150,p6=e=>!e.hidden,g6=e=>{const 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]};return{viewBB:t,boundingRect:e.nodeLookup.size>0?Ej(Sc(e.nodeLookup,{filter:p6}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},x6="react-flow__minimap-desc";function CE({style:e,className:t,nodeStrokeColor:s,nodeColor:r,nodeClassName:i="",nodeBorderRadius:l=5,nodeStrokeWidth:d,nodeComponent:f,bgColor:m,maskColor:h,maskStrokeColor:v,maskStrokeWidth:g,position:y="bottom-right",onClick:b,onNodeClick:S,pannable:w=!1,zoomable:N=!1,ariaLabel:C,inversePan:T,zoomStep:_=1,offsetScale:R=5}){const O=ot(),B=j.useRef(null),{boundingRect:L,viewBB:M,rfId:I,panZoom:H,translateExtent:D,flowWidth:Y,flowHeight:K,ariaLabelConfig:U}=Ve(g6,it),q=(e==null?void 0:e.width)??h6,A=(e==null?void 0:e.height)??m6,$=L.width/q,z=L.height/A,G=Math.max($,z),V=G*q,P=G*A,Q=R*G,ee=L.x-(V-L.width)/2-Q,se=L.y-(P-L.height)/2-Q,oe=V+Q*2,ce=P+Q*2,fe=`${x6}-${I}`,ue=j.useRef(0),he=j.useRef();ue.current=G,j.useEffect(()=>{if(B.current&&H)return he.current=HL({domNode:B.current,panZoom:H,getTransform:()=>O.getState().transform,getViewScale:()=>ue.current}),()=>{var ve;(ve=he.current)==null||ve.destroy()}},[H]),j.useEffect(()=>{var ve;(ve=he.current)==null||ve.update({translateExtent:D,width:Y,height:K,inversePan:T,pannable:w,zoomStep:_,zoomable:N})},[w,N,T,_,D,Y,K]);const Ce=b?ve=>{var Re;const[de,Ae]=((Re=he.current)==null?void 0:Re.pointer(ve))||[0,0];b(ve,{x:de,y:Ae})}:void 0,Se=S?j.useCallback((ve,de)=>{const Ae=O.getState().nodeLookup.get(de).internals.userNode;S(ve,Ae)},[]):void 0,ye=C??U["minimap.ariaLabel"];return u.jsx(jf,{position:y,style:{...e,"--xy-minimap-background-color-props":typeof m=="string"?m:void 0,"--xy-minimap-mask-background-color-props":typeof h=="string"?h:void 0,"--xy-minimap-mask-stroke-color-props":typeof v=="string"?v:void 0,"--xy-minimap-mask-stroke-width-props":typeof g=="number"?g*G:void 0,"--xy-minimap-node-background-color-props":typeof r=="string"?r:void 0,"--xy-minimap-node-stroke-color-props":typeof s=="string"?s:void 0,"--xy-minimap-node-stroke-width-props":typeof d=="number"?d:void 0},className:bt(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:u.jsxs("svg",{width:q,height:A,viewBox:`${ee} ${se} ${oe} ${ce}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":fe,ref:B,onClick:Ce,children:[ye&&u.jsx("title",{id:fe,children:ye}),u.jsx(f6,{onClick:Se,nodeColor:r,nodeStrokeColor:s,nodeBorderRadius:l,nodeClassName:i,nodeStrokeWidth:d,nodeComponent:f}),u.jsx("path",{className:"react-flow__minimap-mask",d:`M${ee-Q},${se-Q}h${oe+Q*2}v${ce+Q*2}h${-oe-Q*2}z
|
|
221
221
|
M${M.x},${M.y}h${M.width}v${M.height}h${-M.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}CE.displayName="MiniMap";j.memo(CE);const y6=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,v6={[jo.Line]:"right",[jo.Handle]:"bottom-right"};function b6({nodeId:e,position:t,variant:s=jo.Handle,className:r,style:i=void 0,children:l,color:d,minWidth:f=10,minHeight:m=10,maxWidth:h=Number.MAX_VALUE,maxHeight:v=Number.MAX_VALUE,keepAspectRatio:g=!1,resizeDirection:y,autoScale:b=!0,shouldResize:S,onResizeStart:w,onResize:N,onResizeEnd:C}){const T=nE(),_=typeof e=="string"?e:T,R=ot(),O=j.useRef(null),B=s===jo.Handle,L=Ve(j.useCallback(y6(B&&b),[B,b]),it),M=j.useRef(null),I=t??v6[s];j.useEffect(()=>{if(!(!O.current||!_))return M.current||(M.current=ez({domNode:O.current,nodeId:_,getStoreItems:()=>{const{nodeLookup:D,transform:Y,snapGrid:K,snapToGrid:U,nodeOrigin:q,domNode:A}=R.getState();return{nodeLookup:D,transform:Y,snapGrid:K,snapToGrid:U,nodeOrigin:q,paneDomNode:A}},onChange:(D,Y)=>{const{triggerNodeChanges:K,nodeLookup:U,parentLookup:q,nodeOrigin:A}=R.getState(),$=[],z={x:D.x,y:D.y},G=U.get(_);if(G&&G.expandParent&&G.parentId){const V=G.origin??A,P=D.width??G.measured.width??0,Q=D.height??G.measured.height??0,ee={id:G.id,parentId:G.parentId,rect:{width:P,height:Q,..._j({x:D.x??G.position.x,y:D.y??G.position.y},{width:P,height:Q},G.parentId,U,V)}},se=l0([ee],U,q,A);$.push(...se),z.x=D.x?Math.max(V[0]*P,D.x):void 0,z.y=D.y?Math.max(V[1]*Q,D.y):void 0}if(z.x!==void 0&&z.y!==void 0){const V={id:_,type:"position",position:{...z}};$.push(V)}if(D.width!==void 0&&D.height!==void 0){const P={id:_,type:"dimensions",resizing:!0,setAttributes:y?y==="horizontal"?"width":"height":!0,dimensions:{width:D.width,height:D.height}};$.push(P)}for(const V of Y){const P={...V,type:"position"};$.push(P)}K($)},onEnd:({width:D,height:Y})=>{const K={id:_,type:"dimensions",resizing:!1,dimensions:{width:D,height:Y}};R.getState().triggerNodeChanges([K])}})),M.current.update({controlPosition:I,boundaries:{minWidth:f,minHeight:m,maxWidth:h,maxHeight:v},keepAspectRatio:g,resizeDirection:y,onResizeStart:w,onResize:N,onResizeEnd:C,shouldResize:S}),()=>{var D;(D=M.current)==null||D.destroy()}},[I,f,m,h,v,g,w,N,C,S]);const H=I.split("-");return u.jsx("div",{className:bt(["react-flow__resize-control","nodrag",...H,s,r]),ref:O,style:{...i,scale:L,...d&&{[B?"backgroundColor":"borderColor"]:d}},children:l})}j.memo(b6);async function S6(e){const t=await fetch(`/api/rigs/${encodeURIComponent(e)}/graph`);if(!t.ok)throw new Error(`HTTP ${t.status}`);return t.json()}function w6(e){return Tt({queryKey:["rig",e,"graph"],queryFn:()=>S6(e),enabled:!!e,refetchInterval:3e4})}const N6=100;function j6(e){const t=Ct(),[s,r]=j.useState(!1),[i,l]=j.useState(!1),d=j.useRef(!1),f=j.useRef(null),m=j.useCallback(()=>{e&&(f.current||(f.current=setTimeout(()=>{f.current=null,t.invalidateQueries({queryKey:["rig",e,"graph"]})},N6)))},[e,t]);return j.useEffect(()=>{if(!e){r(!1),l(!1);return}d.current=!1,r(!1),l(!1);const h=new EventSource(`/api/events?rigId=${e}`);return h.addEventListener("open",()=>{r(!0),d.current&&(l(!1),d.current=!1,m())}),h.addEventListener("message",()=>{m()}),h.addEventListener("error",()=>{r(!1),l(!0),d.current=!0}),()=>{h.close(),f.current&&(clearTimeout(f.current),f.current=null)}},[e,m]),{connected:s,reconnecting:i}}const Zi="#546073",kl={type:rc.ArrowClosed,color:Zi,width:12,height:12};function E6(e){switch(e){case"delegates_to":return{style:{stroke:Zi,strokeWidth:1.5},animated:!1,type:"smoothstep",pathOptions:{borderRadius:18,offset:20},markerEnd:kl,label:void 0};case"spawned_by":return{style:{stroke:Zi,strokeWidth:1.5,strokeDasharray:"6 3"},animated:!1,type:"smoothstep",pathOptions:{borderRadius:18,offset:20},markerEnd:kl,label:void 0};case"can_observe":return{style:{stroke:Zi,strokeWidth:1,strokeDasharray:"4 2"},animated:!1,type:"smoothstep",pathOptions:{borderRadius:18,offset:20},markerEnd:kl,label:void 0};case"uses":return{style:{stroke:Zi,strokeWidth:1,strokeDasharray:"2 2"},animated:!1,type:"smoothstep",pathOptions:{borderRadius:18,offset:20},markerEnd:kl,label:void 0};default:return{style:{stroke:Zi,strokeWidth:1},animated:!1,type:"smoothstep",pathOptions:{borderRadius:18,offset:20},markerEnd:kl,label:void 0}}}function MS(e){return e.type==="group"||e.type==="podGroup"}const d0=240,f0=160,sf=3,_E=36,RE=32,TE=28,AE=44,C6=28,_6=120,R6=0,T6=new Set(["delegates_to","spawned_by"]);function A6(e,t){if(e.length<=1)return e;const s=new Set(e.filter(h=>MS(h)).map(h=>h.id)),r=new Map;for(const h of e)typeof h.parentId!="string"||!s.has(h.parentId)||(r.has(h.parentId)||r.set(h.parentId,[]),r.get(h.parentId).push(h));const i=[],l=new Map;for(const h of e){if(MS(h)){const v=r.get(h.id)??[],{width:g,height:y}=k6(v.length);i.push({id:h.id,kind:"group",node:h,width:g,height:y,members:v}),l.set(h.id,h.id);for(const b of v)l.set(b.id,h.id);continue}typeof h.parentId=="string"&&s.has(h.parentId)||(i.push({id:h.id,kind:"standalone",node:h,width:d0,height:f0,members:[]}),l.set(h.id,h.id))}if(i.length===0)return e;const d=M6(t,l),f=L6(i,d),m=new Map;for(const h of e)m.set(h.id,{...h});for(const h of i){const v=f.get(h.id);if(!v)continue;if(h.kind==="standalone"){const y=m.get(h.node.id);y.position={x:v.x,y:v.y};continue}const g=m.get(h.node.id);g.position={x:v.x,y:v.y},g.initialWidth=h.width,g.initialHeight=h.height,g.style={...g.style??{},width:h.width,height:h.height,background:"linear-gradient(180deg, rgba(84, 96, 115, 0.08) 0px, rgba(84, 96, 115, 0.08) 32px, rgba(255, 255, 255, 0.22) 32px, rgba(255, 255, 255, 0.22) 100%)",border:"1px dashed rgba(84, 96, 115, 0.45)",boxShadow:"0 0 0 1px rgba(84, 96, 115, 0.10)"};for(let y=0;y<h.members.length;y+=1){const b=h.members[y],S=m.get(b.id);S.position=O6(y)}}return e.map(h=>m.get(h.id)??h)}function M6(e,t){const s=kS(e.filter(r=>T6.has(D6(r))),t);return s.length>0?s:kS(e,t)}function kS(e,t){const s=new Map;for(const r of e){const i=t.get(r.source),l=t.get(r.target);if(!i||!l||i===l)continue;const d=`${i}->${l}`;s.has(d)||s.set(d,{source:i,target:l})}return Array.from(s.values())}function k6(e){const t=Math.max(e,1),s=Math.min(t,sf),r=Math.ceil(t/sf),i=s*d0+Math.max(s-1,0)*_E,l=r*f0+Math.max(r-1,0)*RE;return{width:i+TE*2,height:l+AE+C6}}function O6(e){const t=e%sf,s=Math.floor(e/sf);return{x:TE+t*(d0+_E),y:AE+s*(f0+RE)}}function D6(e){var t;return((t=e.data)==null?void 0:t.kind)??e.label??""}function L6(e,t){const s=new Map(e.map(b=>[b.id,b])),r=new Map,i=new Map,l=[],d=new Set;for(const b of e)r.set(b.id,new Set),i.set(b.id,0);for(const b of t)!s.has(b.source)||!s.has(b.target)||r.get(b.source).has(b.target)||(r.get(b.source).add(b.target),i.set(b.target,(i.get(b.target)??0)+1));const f=e.filter(b=>{var S;return(i.get(b.id)??0)===0&&(((S=r.get(b.id))==null?void 0:S.size)??0)>0}).map(b=>b.id).sort((b,S)=>bd(b,S,r,e)),m=e.filter(b=>{var S;return(i.get(b.id)??0)===0&&(((S=r.get(b.id))==null?void 0:S.size)??0)===0}).map(b=>b.id).sort((b,S)=>bd(b,S,r,e)),h=b=>{const S=new Map(i),w=[...b],N=new Set(w);for(;w.length>0;){const C=w.shift();if(d.has(C))continue;d.add(C),l.push(C);const T=Array.from(r.get(C)??[]).sort((R,O)=>bd(R,O,r,e));for(const R of T)S.set(R,(S.get(R)??1)-1);const _=T.filter(R=>(S.get(R)??0)===0&&!d.has(R)&&!N.has(R));for(const R of _)w.push(R),N.add(R)}};h(f),h(m);const v=e.map(b=>b.id).filter(b=>!d.has(b)).sort((b,S)=>bd(b,S,r,e));l.push(...v);const g=new Map;let y=0;for(const b of l){const S=s.get(b);S&&(g.set(S.id,{x:R6,y}),y+=S.height+_6)}return g}function bd(e,t,s,r){var d,f;const i=((d=s.get(e))==null?void 0:d.size)??0,l=((f=s.get(t))==null?void 0:f.size)??0;return i!==l?l-i:r.findIndex(m=>m.id===e)-r.findIndex(m=>m.id===t)}function z6(e){return e==="architect"||e==="lead"||e==="orchestrator"}function P6(e){switch(e){case"ready":return"ready";case"pending":return"launching";case"failed":return"failed";default:return"stopped"}}function I6(e){switch(e){case"ready":return"bg-green-500";case"pending":return"bg-amber-500";case"failed":return"bg-red-500";default:return"bg-stone-400"}}function B6({data:e}){var O,B,L,M,I;const t=j.useRef(e.startupStatus),s=j.useRef(null),[r,i]=j.useState(!1),[l,d]=j.useState(null),f=z6(e.role),m=e.nodeKind==="infrastructure";j.useEffect(()=>{if(t.current!==e.startupStatus&&t.current!==null){i(!0);const H=setTimeout(()=>i(!1),600);return t.current=e.startupStatus,()=>clearTimeout(H)}t.current=e.startupStatus},[e.startupStatus]),j.useEffect(()=>()=>{s.current&&clearTimeout(s.current)},[]);const h=[e.runtime,e.model].filter(Boolean).join(" · "),v=Qr(e.logicalId),g=P6(e.startupStatus),y=I6(e.startupStatus),b=e.placementState==="selected"?"target":e.placementState==="available"?"avail":null,S=[e.canonicalSessionName?`Session: ${e.canonicalSessionName}`:null,h?`Runtime: ${h}`:null,e.resolvedSpecName?`Spec: ${e.resolvedSpecName}`:null,e.profile?`Profile: ${e.profile}`:null,typeof e.edgeCount=="number"?`Edges: ${e.edgeCount}`:null].filter(H=>!!H),w=S.join(`
|
|
222
|
-
`),N=H=>{s.current&&clearTimeout(s.current),d(H),s.current=setTimeout(()=>{d(D=>D===H?null:D),s.current=null},900)},C=async H=>{var Y;H.stopPropagation();const D=e.canonicalSessionName??((Y=e.binding)==null?void 0:Y.tmuxSession);D&&(await ds(`tmux attach -t ${D}`),N("attach"))},T=async H=>{var D;if(H.stopPropagation(),!(!((D=e.binding)!=null&&D.cmuxSurface)||!e.rigId))try{(await fetch(`/api/rigs/${encodeURIComponent(e.rigId)}/nodes/${encodeURIComponent(e.logicalId)}/focus`,{method:"POST"})).ok&&N("cmux")}catch{}},_=async H=>{H.stopPropagation(),e.resumeToken&&(e.runtime==="claude-code"?(await ds(`claude --resume ${e.resumeToken}`),N("resume")):e.runtime==="codex"&&(await ds(`codex resume ${e.resumeToken}`),N("resume")))},R=H=>`px-1.5 py-0.5 border font-mono text-[7px] uppercase transition-colors ${l===H?"bg-stone-900 text-white border-stone-900":"bg-white text-stone-900 border-stone-300 hover:bg-stone-100"}`;return u.jsxs("div",{className:`group bg-white border min-w-[200px] hard-shadow relative ${e.placementState==="selected"?"border-emerald-600 ring-2 ring-emerald-400/70 shadow-[0_0_0_3px_rgba(52,211,153,0.12)]":e.placementState==="available"?"border-emerald-500 ring-1 ring-emerald-300/70":"border-stone-900"}`,"data-testid":"rig-node",title:w||void 0,children:[u.jsx(Wa,{type:"target",position:we.Top}),u.jsxs("div",{className:`px-3 py-1 font-mono text-[10px] flex justify-between items-center ${m?"bg-stone-500 text-white border-b border-stone-900":f?"bg-stone-900 text-white":"bg-stone-200 text-stone-900 border-b border-stone-900"}`,children:[u.jsx("span",{className:"font-bold truncate",children:v}),u.jsx("span",{className:`inline-flex h-2.5 w-2.5 rounded-full border border-white/50 ${y} ${r?"status-changed":""}`,"data-testid":`status-dot-${e.logicalId}`,"aria-label":g,title:g})]}),u.jsxs("div",{className:"p-3 space-y-2",children:[h&&u.jsxs("div",{className:"font-mono text-[8px] text-stone-500",children:["RUNTIME: ",h]}),e.resolvedSpecName&&u.jsxs("div",{className:"font-mono text-[8px] text-stone-400","data-testid":"spec-hint",children:[e.resolvedSpecName,e.profile?` · ${e.profile}`:""]}),e.contextAvailability==="known"&&e.contextFresh&&typeof e.contextUsedPercentage=="number"?u.jsxs("div",{className:"font-mono text-[8px] text-stone-500","data-testid":"context-badge",children:["CTX ",e.contextUsedPercentage,"%"]}):u.jsx("div",{className:"font-mono text-[8px] text-stone-300","data-testid":"context-badge-unknown",children:"CTX unknown"}),e.restoreOutcome&&e.restoreOutcome!=="n-a"&&u.jsxs("div",{className:"font-mono text-[8px] text-stone-500",children:["RESTORE: ",e.restoreOutcome]}),e.packageRefs&&e.packageRefs.length>0&&u.jsxs("div",{"data-testid":"package-badge",title:e.packageRefs.join(", "),className:"font-mono text-[8px] text-stone-400",onClick:H=>H.stopPropagation(),onKeyDown:H=>H.stopPropagation(),children:["PKG ",e.packageRefs.length]}),e.startupStatus==="failed"&&u.jsxs("div",{className:"stamp-badge",children:[u.jsx("div",{className:"w-2 h-2 rounded-full bg-red-500"}),u.jsx("span",{className:"text-red-600",children:"FAILED"})]}),(e.canonicalSessionName??((O=e.binding)==null?void 0:O.tmuxSession)??e.resumeToken??((B=e.binding)==null?void 0:B.cmuxSurface))&&u.jsxs("div",{"data-testid":"node-toolbar",className:"flex flex-wrap gap-1 pt-1",onClick:H=>H.stopPropagation(),onKeyDown:H=>H.stopPropagation(),children:[(e.canonicalSessionName??((L=e.binding)==null?void 0:L.tmuxSession))&&u.jsx("button",{onClick:C,"data-testid":"toolbar-copy-attach",className:R("attach"),title:`tmux attach -t ${e.canonicalSessionName??((M=e.binding)==null?void 0:M.tmuxSession)??"?"}`,children:l==="attach"?"copied":"tmux"}),((I=e.binding)==null?void 0:I.cmuxSurface)&&u.jsx("button",{onClick:T,"data-testid":"toolbar-cmux-focus",className:R("cmux"),children:l==="cmux"?"opened":"cmux"}),e.resumeToken&&e.runtime&&e.runtime!=="terminal"&&u.jsx("button",{onClick:_,"data-testid":"toolbar-copy-resume",className:R("resume"),children:l==="resume"?"copied":"resume"})]}),b&&u.jsx("div",{className:"pt-1",children:u.jsx("span",{"data-testid":`placement-chip-${e.logicalId}`,className:`inline-flex items-center border px-1.5 py-0.5 font-mono text-[7px] uppercase tracking-[0.12em] ${e.placementState==="selected"?"border-emerald-700 bg-emerald-700 text-white":"border-emerald-300 bg-emerald-50 text-emerald-800"}`,children:b})})]}),S.length>0&&u.jsx("div",{"data-testid":"node-hover-hint",className:"pointer-events-none absolute left-2 top-full z-20 mt-2 hidden min-w-[180px] border border-stone-900 bg-white px-2 py-1 font-mono text-[8px] text-stone-700 shadow-[4px_4px_0_rgba(28,25,23,0.14)] group-hover:block",children:S.map(H=>u.jsx("div",{children:H},H))}),u.jsx(Wa,{type:"source",position:we.Bottom})]})}const H6=Zw("relative w-full p-4 bg-surface-low border-l-2 border-l-stone-900 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-on-surface",{variants:{variant:{default:"bg-background text-foreground",destructive:"text-destructive [&>svg]:text-destructive"}},defaultVariants:{variant:"default"}}),Qt=j.forwardRef(({className:e,variant:t,...s},r)=>u.jsx("div",{ref:r,role:"alert",className:Te(H6({variant:t}),e),...s}));Qt.displayName="Alert";const U6=j.forwardRef(({className:e,...t},s)=>u.jsx("h5",{ref:s,className:Te("mb-1 font-medium leading-none tracking-tight",e),...t}));U6.displayName="AlertTitle";const Kt=j.forwardRef(({className:e,...t},s)=>u.jsx("div",{ref:s,className:Te("text-sm [&_p]:leading-relaxed",e),...t}));Kt.displayName="AlertDescription";function $6({data:e}){const t=e.podDisplayName??e.podNamespace??cs(e.logicalId)??us(e.podId??e.logicalId);return u.jsx("div",{"data-testid":"pod-group-node",className:`w-full h-full relative pointer-events-auto ${e.placementState==="selected"?"ring-2 ring-emerald-500/80 shadow-[0_0_0_4px_rgba(52,211,153,0.12)]":e.placementState==="available"?"ring-1 ring-emerald-300/80":""}`,children:u.jsx("div",{className:"absolute left-4 top-3 inline-flex items-center font-mono text-[12px] font-bold leading-none tracking-[0.08em] text-stone-800",children:`${t} pod`})})}function q6({data:e}){const t=e.session;return u.jsxs("div",{"data-testid":"discovered-graph-node",className:"border-dashed border-2 border-foreground/30 bg-surface-low/50 p-spacing-3 min-w-[180px]",children:[u.jsx(Wa,{type:"target",position:we.Top,className:"opacity-0"}),u.jsxs("div",{className:"text-label-sm font-mono uppercase mb-spacing-1",children:[t.tmuxSession,":",t.tmuxPane]}),u.jsxs("div",{className:"flex gap-spacing-2 items-center mb-spacing-1",children:[u.jsx("span",{className:"text-label-sm uppercase text-foreground-muted",children:t.runtimeHint}),u.jsx("span",{className:"text-label-sm text-foreground-muted",children:t.confidence})]}),t.cwd&&u.jsx("div",{className:"text-label-sm font-mono text-foreground-muted truncate",children:t.cwd}),u.jsx(Wa,{type:"source",position:we.Bottom,className:"opacity-0"})]})}const V6={rigNode:B6,discoveredNode:q6,podGroup:$6};function G6(){return u.jsxs("div",{className:"flex flex-col items-center justify-center h-full relative text-foreground-muted","data-testid":"empty-topology",children:[u.jsxs("svg",{className:"absolute inset-0 w-full h-full",viewBox:"0 0 400 300",fill:"none",style:{opacity:.08},children:[u.jsx("rect",{x:"160",y:"60",width:"80",height:"40",stroke:"currentColor",strokeWidth:"1"}),u.jsx("rect",{x:"60",y:"180",width:"80",height:"40",stroke:"currentColor",strokeWidth:"1"}),u.jsx("rect",{x:"260",y:"180",width:"80",height:"40",stroke:"currentColor",strokeWidth:"1"}),u.jsx("line",{x1:"200",y1:"100",x2:"100",y2:"180",stroke:"currentColor",strokeWidth:"1",strokeDasharray:"4 4"}),u.jsx("line",{x1:"200",y1:"100",x2:"300",y2:"180",stroke:"currentColor",strokeWidth:"1",strokeDasharray:"4 4"})]}),u.jsx("div",{className:"relative z-10 text-center",children:u.jsx("h2",{className:"text-headline-md uppercase",children:"EMPTY TOPOLOGY"})})]})}function Y6({rigId:e,rigName:t=null,showDiscovered:s=!0}){const{data:r,isPending:i,error:l}=w6(e??""),d=Z3(s),f=(r==null?void 0:r.nodes)??[],m=(r==null?void 0:r.edges)??[],h=(l==null?void 0:l.message)??null,{reconnecting:v}=j6(e),[g,y]=j.useState(null),b=j.useRef(null),S=j.useRef(null),w=e!==null&&S.current!==e;j.useEffect(()=>{e&&f.length>0&&S.current!==e&&(S.current=e)},[e,f.length]);const N=j.useCallback(K=>{b.current&&clearTimeout(b.current),y(K),b.current=setTimeout(()=>{y(null),b.current=null},3e3)},[]);j.useEffect(()=>()=>{b.current&&clearTimeout(b.current)},[]);const C=j.useMemo(()=>m.map(K=>{var A;const U=((A=K.data)==null?void 0:A.kind)??K.label??"delegates_to",q=E6(U);return{...K,...q,className:w?"edge-draw-in":void 0,style:{...q.style,animationDelay:w?`${Math.min(f.length*50+100,2e3)}ms`:void 0}}}),[m,w,f.length]),T=j.useMemo(()=>{const K=new Map;for(const U of f){const q=U.data;if((U.type==="podGroup"||U.type==="group")&&(q!=null&&q.podId)){K.set(q.podId,{displayName:q.podLabel??q.podNamespace??cs(q.logicalId)??us(q.podId),namespace:q.podNamespace??q.logicalId??null});continue}const A=(q==null?void 0:q.podId)??null;if(!A)continue;const $=(q==null?void 0:q.podNamespace)??cs(q==null?void 0:q.logicalId)??null,z=(q==null?void 0:q.podLabel)??$??us(A);K.has(A)||K.set(A,{displayName:z,namespace:$})}return K},[f]),{selection:_,setSelection:R}=tr(),{selectedDiscoveredId:O,placementTarget:B,setPlacementTarget:L}=y4(),M=(_==null?void 0:_.type)==="discovery"&&!!O,I=j.useMemo(()=>{const K=new Map;for(const z of f){if(!z.parentId)continue;const G=typeof z.data=="object"&&z.data!==null&&"logicalId"in z.data?z.data.logicalId:null,V=typeof z.data=="object"&&z.data!==null&&"podId"in z.data?z.data.podId:null,P=cs(G)??us(V);P&&!K.has(z.parentId)&&K.set(z.parentId,P)}const q=A6(f,m).map((z,G)=>({...z,data:(()=>{if(z.type==="podGroup"||z.type==="group"){const V=z.data,P=(V==null?void 0:V.podId)??null,Q=(B==null?void 0:B.kind)==="pod"&&P!==null&&B.podId===P;return{...z.data??{},podDisplayName:K.get(z.id)??null,placementState:M?Q?"selected":"available":null}}if(z.type==="rigNode"){const V=z.data,P=!(V!=null&&V.binding)&&!(V!=null&&V.canonicalSessionName),Q=(B==null?void 0:B.kind)==="node"&&(V==null?void 0:V.logicalId)!==void 0&&B.logicalId===V.logicalId;return{...z.data??{},placementState:M?Q?"selected":P?"available":null:null}}return z.data})(),className:w?"node-enter":void 0,style:{...z.style??{},animationDelay:w?`${Math.min(G*50,2e3)}ms`:void 0}})),A=q.reduce((z,G)=>{var V;return Math.max(z,((V=G.position)==null?void 0:V.y)??0)},0),$=d.map((z,G)=>({id:`discovered-${z.id}`,type:"discoveredNode",position:{x:300,y:A+200+G*150},data:{session:z}}));return[...q,...$]},[f,m,w,d,M,B]),{setSelectedNode:H}=v4(),D=t!=null&&t.trim()?t:e?Gs(e):null,Y=j.useCallback(async(K,U)=>{var A;if(!e)return;if(M){if(U.type==="podGroup"||U.type==="group"){const $=U.data,z=($==null?void 0:$.podId)??null,G=z?T.get(z):null,V=!!(z&&(G!=null&&G.namespace));L({kind:"pod",rigId:e,podId:z??"",podNamespace:(G==null?void 0:G.namespace)??null,podLabel:(G==null?void 0:G.displayName)??null,eligible:V,...V?{}:{reason:"This pod cannot receive a new node yet."}});return}if(U.type==="rigNode"){const $=U.data,z=!$.binding&&!$.canonicalSessionName;L({kind:"node",rigId:e,logicalId:$.logicalId,eligible:z,...z?{}:{reason:"This node is already claimed."}});return}}if(U.type==="podGroup"||U.type==="group"){R({type:"rig",rigId:e});return}const q=U.data;if(H({rigId:e,logicalId:q.logicalId}),!((A=q.binding)!=null&&A.cmuxSurface)){N({text:"Not bound to cmux surface",type:"info"});return}try{const $=await fetch(`/api/rigs/${encodeURIComponent(e)}/nodes/${encodeURIComponent(q.logicalId)}/focus`,{method:"POST"});if(!$.ok){N({text:"Focus failed",type:"error"});return}const z=await $.json();z.ok===!1&&z.code==="unavailable"?N({text:"cmux not connected",type:"error"}):z.ok?N({text:"Focused",type:"success"}):N({text:"Focus failed",type:"error"})}catch{N({text:"Focus failed",type:"error"})}},[M,T,e,L,H,R,N]);return e===null?u.jsx("div",{className:"p-spacing-6 text-foreground-muted",children:"No rig selected"}):i?u.jsxs("div",{className:"p-spacing-6","data-testid":"graph-loading",children:[u.jsx("div",{className:"h-8 w-48 animate-pulse-tactical mb-spacing-4"}),u.jsx("div",{className:"h-64 animate-pulse-tactical"})]}):h?u.jsx("div",{className:"p-spacing-6",children:u.jsx(Qt,{"data-testid":"graph-error",children:u.jsxs(Kt,{children:["Error: ",h]})})}):I.length===0?u.jsx(G6,{}):u.jsxs("div",{className:"w-full h-full relative","data-testid":"graph-view","data-animated":w?"true":"false",children:[u.jsx("div",{className:"absolute top-4 left-4 w-3 h-3 reg-mark",children:u.jsx("div",{className:"reg-tl"})}),u.jsx("div",{className:"absolute top-4 right-4 w-3 h-3",children:u.jsx("div",{className:"reg-tr"})}),u.jsx("div",{className:"absolute bottom-4 left-4 w-3 h-3",children:u.jsx("div",{className:"reg-bl"})}),u.jsx("div",{className:"absolute bottom-4 right-4 w-3 h-3",children:u.jsx("div",{className:"reg-br"})}),D&&u.jsx("div",{"data-testid":"rig-stamp-watermark",className:"stamp-watermark text-3xl left-[20%] top-[35%]",children:D}),v&&u.jsx("div",{className:"absolute top-spacing-4 right-spacing-4 z-20",children:u.jsx(Qt,{children:u.jsx(Kt,{className:"text-warning",children:"Reconnecting..."})})}),g&&u.jsx("div",{className:`absolute top-spacing-4 left-spacing-4 z-20 px-spacing-4 py-spacing-2 font-mono text-[10px] border ${g.type==="success"?"bg-white border-stone-900 text-stone-900":g.type==="error"?"bg-tertiary/10 border-tertiary text-tertiary":"bg-white border-stone-300 text-stone-600"}`,children:g.text}),M&&u.jsx("div",{"data-testid":"graph-placement-banner",className:"absolute top-spacing-4 left-1/2 z-20 -translate-x-1/2 border border-emerald-300/90 bg-[rgba(236,253,245,0.92)] px-3.5 py-2 font-mono text-[10px] text-emerald-950 shadow-[0_12px_28px_rgba(34,197,94,0.14)] backdrop-blur-sm",children:"PLACEMENT MODE · click an available node to bind, or click a pod to add a new node."}),u.jsx(wE,{nodes:I,edges:C,nodeTypes:V6,onNodeClick:Y,nodesDraggable:!1,selectionOnDrag:!1,panOnDrag:!0,fitView:!0,fitViewOptions:{padding:.16,maxZoom:1.15},className:"relative z-10",proOptions:{hideAttribution:!0},minZoom:.3,maxZoom:1.5,children:u.jsx(EE,{})})]})}function h0(){const{openExplorer:e}=x4(),{setSelection:t}=tr();return u.jsx("div",{"data-testid":"workspace-home",className:"flex h-full min-h-[420px] flex-col items-center justify-center bg-[radial-gradient(circle_at_top,rgba(245,244,240,0.85),rgba(244,242,236,0.55)_32%,rgba(243,241,236,0.22)_58%,transparent_72%)] px-8 text-center",children:u.jsxs("div",{className:"max-w-xl space-y-3",children:[u.jsx("p",{className:"font-mono text-[10px] uppercase tracking-[0.18em] text-stone-500",children:"Explorer-Driven Workspace"}),u.jsx("h1",{className:"font-headline text-2xl font-bold uppercase tracking-tight text-stone-900",children:"Select a rig from the explorer to inspect its topology."}),u.jsxs("p",{className:"text-sm text-stone-600",children:["Use ",u.jsx("span",{className:"font-mono text-stone-800",children:"Specs"})," to import a rig spec or run bootstrap, and use the ",u.jsx("span",{className:"font-mono text-stone-800",children:"Discovery"})," drawer to place running sessions."]}),u.jsxs("div",{className:"flex items-center justify-center gap-3 pt-2",children:[u.jsx("button",{type:"button","data-testid":"workspace-open-explorer",onClick:e,className:"border border-stone-300 px-4 py-2 font-mono text-[10px] uppercase tracking-[0.14em] text-stone-700 transition-colors hover:bg-stone-100",children:"Explore"}),u.jsx("button",{type:"button","data-testid":"workspace-open-specs",onClick:()=>t({type:"specs"}),className:"border border-stone-300 px-4 py-2 font-mono text-[10px] uppercase tracking-[0.14em] text-stone-700 transition-colors hover:bg-stone-100",children:"Open Specs"}),u.jsx("button",{type:"button","data-testid":"workspace-open-discovery",onClick:()=>t({type:"discovery"}),className:"border border-stone-300 px-4 py-2 font-mono text-[10px] uppercase tracking-[0.14em] text-stone-700 transition-colors hover:bg-stone-100",children:"Open Discovery"})]})]})})}function Q6(e){switch(e){case"launched":return"text-success";case"failed":return"text-destructive";default:return"text-foreground-muted"}}const m0=j.forwardRef(({className:e,type:t,...s},r)=>u.jsx("input",{type:t,className:Te("flex h-11 w-full border border-stone-300/55 bg-white/85 px-4 py-2 text-base text-foreground placeholder:text-foreground-muted/60 transition-colors duration-150 focus-visible:outline-none focus-visible:border-stone-900/35 focus-visible:ring-2 focus-visible:ring-stone-900/10 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...s}));m0.displayName="Input";const p0=j.forwardRef(({className:e,...t},s)=>u.jsx("textarea",{className:Te("flex min-h-[80px] w-full border border-stone-300/55 bg-white/85 px-4 py-3 text-base text-on-surface font-mono placeholder:text-stone-400 transition-all duration-150 focus-visible:outline-none focus-visible:border-stone-900/35 focus-visible:ring-2 focus-visible:ring-stone-900/10 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:s,...t}));p0.displayName="Textarea";function rt({children:e,className:t,innerClassName:s}){return u.jsx("div",{"data-testid":"workspace-page",className:Te("w-full flex-1 overflow-y-auto lg:pl-[var(--workspace-left-offset,0px)] lg:pr-[var(--workspace-right-offset,0px)]",t),children:u.jsx("div",{"data-testid":"workspace-page-inner",className:Te("mx-auto w-full max-w-[960px] px-4 py-6 sm:px-6 sm:py-8 md:px-8 lg:px-10",s),children:e})})}const g0=j.forwardRef(({className:e,...t},s)=>u.jsx("div",{className:"relative w-full overflow-auto",children:u.jsx("table",{ref:s,className:Te("w-full caption-bottom text-sm",e),...t})}));g0.displayName="Table";const x0=j.forwardRef(({className:e,...t},s)=>u.jsx("thead",{ref:s,className:Te("bg-surface-low [&_tr]:border-b [&_tr]:border-stone-300",e),...t}));x0.displayName="TableHeader";const y0=j.forwardRef(({className:e,...t},s)=>u.jsx("tbody",{ref:s,className:Te("[&_tr:last-child]:border-0",e),...t}));y0.displayName="TableBody";const K6=j.forwardRef(({className:e,...t},s)=>u.jsx("tfoot",{ref:s,className:Te("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",e),...t}));K6.displayName="TableFooter";const cc=j.forwardRef(({className:e,...t},s)=>u.jsx("tr",{ref:s,className:Te("border-b border-stone-200 transition-colors duration-150 hover:bg-surface-low data-[state=selected]:bg-surface-mid odd:bg-surface-low/50",e),...t}));cc.displayName="TableRow";const Or=j.forwardRef(({className:e,...t},s)=>u.jsx("th",{ref:s,className:Te("h-12 px-4 text-left align-middle font-medium text-foreground-muted uppercase text-label-md tracking-[0.04em] [&:has([role=checkbox])]:pr-0",e),...t}));Or.displayName="TableHead";const Dr=j.forwardRef(({className:e,...t},s)=>u.jsx("td",{ref:s,className:Te("p-4 align-middle [&:has([role=checkbox])]:pr-0",e),...t}));Dr.displayName="TableCell";const F6=j.forwardRef(({className:e,...t},s)=>u.jsx("caption",{ref:s,className:Te("mt-4 text-sm text-foreground-muted",e),...t}));F6.displayName="TableCaption";function Yn({eyebrow:e,title:t,description:s,actions:r}){return u.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-end lg:justify-between",children:[u.jsxs("div",{className:"space-y-3",children:[u.jsx("p",{className:"font-mono text-[10px] uppercase tracking-[0.18em] text-stone-500",children:e}),u.jsx("h2",{className:"text-2xl font-bold uppercase tracking-[0.04em] text-stone-900 sm:text-3xl",children:t}),s&&u.jsx("p",{className:"max-w-2xl text-base leading-8 text-stone-600",children:s})]}),r?u.jsx("div",{className:"flex flex-wrap gap-2",children:r}):null]})}function ME({steps:e,currentStep:t,errorAtStep:s=0,"data-testid":r}){const i=s||t;return u.jsx("div",{className:"flex flex-wrap items-center gap-2 sm:gap-3","data-testid":r,children:e.map((l,d)=>{const f=i>l.num,m=i===l.num,h=i<l.num,v=f?"done":m?"active":"upcoming";return u.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[u.jsxs("div",{"data-testid":`step-${l.num}`,"data-step-state":v,className:Te("inline-flex min-h-0 items-center gap-2 border-b-2 px-1 py-1 font-mono text-[10px] uppercase tracking-[0.16em] transition-colors",f&&"border-primary/35 text-foreground-muted",m&&"border-stone-900 text-foreground",h&&"border-transparent text-foreground-muted/35"),children:[u.jsxs("span",{className:"text-[9px] tracking-[0.22em]",children:[f?"✓ ":"",String(l.num).padStart(2,"0")]}),u.jsx("span",{className:"text-[10px] leading-none tracking-[0.2em]",children:l.label})]}),d<e.length-1?u.jsx("div",{"aria-hidden":"true",className:Te("h-px w-4 shrink-0 sm:w-6",f?"bg-primary/35":"bg-stone-300/45")}):null]},l.num)})})}function Ln({title:e,description:t,children:s,className:r}){return u.jsxs("section",{className:Te("space-y-4 border border-stone-300/45 bg-[rgba(255,255,255,0.62)] p-5 shadow-[0_1px_0_rgba(255,255,255,0.95)_inset,0_10px_26px_rgba(34,34,24,0.035)] sm:p-6",r),children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx("div",{className:"font-mono text-[10px] uppercase tracking-[0.18em] text-stone-500",children:e}),t?u.jsx("p",{className:"text-base leading-8 text-stone-600",children:t}):null]}),s]})}function _f({children:e}){return u.jsx("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:e})}function Ut({label:e,value:t,testId:s}){return u.jsxs("div",{className:"border border-stone-300/35 bg-white/10 px-4 py-4",children:[u.jsx("div",{className:"font-mono text-[8px] uppercase tracking-[0.16em] text-stone-500",children:e}),u.jsx("div",{"data-testid":s,className:"mt-2 text-2xl font-semibold uppercase tracking-[0.04em] text-stone-900",children:t})]})}function kE({title:e,testId:t,children:s}){return u.jsx(Ln,{title:e,children:u.jsx("pre",{"data-testid":t,className:"overflow-x-auto border border-stone-300/45 bg-white/75 p-4 text-xs leading-6 text-stone-800",children:s})})}const X6=[{num:1,label:"VALIDATE RIGSPEC"},{num:2,label:"PREFLIGHT"},{num:3,label:"INSTANTIATE"}];function Z6(e){switch(e){case"input":case"validating":return 1;case"valid":case"preflight":return 2;case"preflight_done":case"instantiating":case"done":return 3;case"error":return 0}}function W6({onBack:e}={}){const t=TM(),{currentRigDraft:s,selectedRigDraft:r,saveRigDraft:i,rememberRigDraft:l,clearSelectedRigDraft:d}=Co(),[f,m]=j.useState(()=>(r==null?void 0:r.yaml)??(s==null?void 0:s.yaml)??""),[h,v]=j.useState(""),[g,y]=j.useState("input"),[b,S]=j.useState(0),[w,N]=j.useState([]),[C,T]=j.useState([]),[_,R]=j.useState(null);j.useEffect(()=>{i(f)},[i,f]),j.useEffect(()=>{r&&(m(r.yaml),d())},[d,r]);const O=async()=>{l(f),y("validating"),N([]);try{const I=await(await fetch("/api/rigs/import/validate",{method:"POST",headers:{"Content-Type":"text/yaml"},body:f})).json();I.valid?y("valid"):(N(I.errors??["Validation failed"]),S(1),y("error"))}catch{N(["Validation request failed"]),S(1),y("error")}},B=async()=>{y("preflight"),N([]),T([]);try{const M={"Content-Type":"text/yaml"};h&&(M["X-Rig-Root"]=h);const H=await(await fetch("/api/rigs/import/preflight",{method:"POST",headers:M,body:f})).json();T(H.warnings??[]),H.errors&&H.errors.length>0?(N(H.errors),S(2),y("error")):y("preflight_done")}catch{N(["Preflight request failed"]),S(2),y("error")}},L=async()=>{y("instantiating"),N([]);try{const M=await t.mutateAsync({yaml:f,rigRoot:h.trim()||void 0});R(M),y("done")}catch(M){M instanceof Jp?(M.code==="cycle_error"?N(["Cycle detected in rig topology"]):N(M.errors),T(M.warnings)):N([M instanceof Error?M.message:"Instantiate request failed"]),S(3),y("error")}};return u.jsx(rt,{children:u.jsxs("div",{"data-testid":"import-flow",className:"space-y-8",children:[u.jsx(Yn,{eyebrow:"Rig Import",title:"Import Rig",description:"Validate a RigSpec, run preflight checks, then instantiate a topology from YAML."}),u.jsx(ME,{"data-testid":"step-indicator",steps:X6,currentStep:Z6(g),errorAtStep:g==="error"?b:0}),g==="input"&&u.jsxs(Ln,{title:"Rig YAML",description:"Paste a rig spec and optionally provide a rig root to anchor relative references during import.",children:[u.jsx(p0,{"data-testid":"yaml-input",value:f,onChange:M=>m(M.target.value),placeholder:"Paste YAML rig spec here...",rows:14,className:"font-mono text-body-sm mb-spacing-4"}),u.jsxs("div",{className:"mb-spacing-4",children:[u.jsx("label",{className:"text-label-sm text-foreground-muted uppercase tracking-[0.04em] block mb-spacing-1",children:"RIG ROOT (OPTIONAL)"}),u.jsx(m0,{"data-testid":"rig-root-input",type:"text",value:h,onChange:M=>v(M.target.value),placeholder:"/path/to/rig/root",className:"font-mono text-body-sm"})]}),u.jsx(Ne,{variant:"tactical","data-testid":"validate-btn",onClick:O,disabled:!f.trim(),children:"VALIDATE RIGSPEC"})]}),g==="validating"&&u.jsx("div",{className:"text-label-md text-foreground-muted",children:"Validating..."}),g==="valid"&&u.jsxs(Ln,{title:"Validation Passed",description:"The RigSpec is valid. Run preflight checks before you instantiate it.",children:[u.jsx(Qt,{className:"mb-spacing-4","data-testid":"valid-message",children:u.jsx(Kt,{className:"text-primary",children:"RigSpec valid. Run preflight checks?"})}),u.jsx(Ne,{variant:"tactical","data-testid":"preflight-btn",onClick:B,children:"RUN PREFLIGHT"})]}),g==="preflight"&&u.jsx("div",{className:"text-label-md text-foreground-muted",children:"Running preflight..."}),g==="preflight_done"&&u.jsxs(Ln,{title:"Preflight Results",description:"Review warnings before you instantiate the rig into live runtime sessions.",children:[C.length>0&&u.jsx(Qt,{className:"mb-spacing-4","data-testid":"preflight-warnings",children:u.jsxs(Kt,{className:"text-warning",children:[u.jsx("div",{className:"text-label-md uppercase mb-spacing-1",children:"WARNINGS"}),C.map((M,I)=>u.jsxs("div",{children:["— ",M]},I))]})}),u.jsx(Qt,{className:"mb-spacing-4","data-testid":"preflight-ready",children:u.jsx(Kt,{className:"text-primary",children:"Preflight passed. Ready to instantiate."})}),u.jsx(Ne,{variant:"tactical","data-testid":"instantiate-btn",onClick:L,children:"INSTANTIATE"})]}),g==="instantiating"&&u.jsx("div",{className:"text-label-md text-foreground-muted",children:"Instantiating..."}),g==="done"&&_&&u.jsx(Ln,{title:"Instantiate Result",description:"The daemon returned per-node launch status for the imported topology.",className:"space-y-4",children:u.jsxs("div",{"data-testid":"import-result",children:[u.jsx(Qt,{className:"mb-spacing-4",children:u.jsxs(Kt,{children:[u.jsx("span",{className:"text-primary font-mono",children:_.specName}),u.jsxs("span",{className:"text-foreground-muted",children:[" (",_.rigId,")"]})]})}),u.jsxs(g0,{children:[u.jsx(x0,{children:u.jsxs(cc,{children:[u.jsx(Or,{children:"NODE"}),u.jsx(Or,{children:"STATUS"})]})}),u.jsx(y0,{children:_.nodes.map(M=>u.jsxs(cc,{children:[u.jsx(Dr,{className:"font-mono",children:M.logicalId}),u.jsx(Dr,{children:u.jsx("span",{className:`font-mono ${Q6(M.status)}`,"data-testid":`inst-status-${M.logicalId}`,children:M.status})})]},M.logicalId))})]}),e?u.jsx("div",{className:"mt-spacing-6",children:u.jsx(Ne,{variant:"ghost",onClick:e,children:"Close"})}):null]})}),g==="error"&&u.jsx(Ln,{title:"Import Errors",description:"Fix the reported issues, then retry the import flow.",children:u.jsxs("div",{"data-testid":"import-errors",children:[C.length>0&&u.jsx(Qt,{className:"mb-spacing-2","data-testid":"error-warnings",children:u.jsxs(Kt,{className:"text-warning",children:[u.jsx("div",{className:"text-label-md uppercase mb-spacing-1",children:"WARNINGS"}),C.map((M,I)=>u.jsxs("div",{children:["— ",M]},I))]})}),w.map((M,I)=>u.jsx(Qt,{className:"mb-spacing-2",children:u.jsx(Kt,{className:"text-destructive",children:M})},I)),u.jsx(Ne,{variant:"tactical",className:"mt-spacing-4",onClick:()=>{y("input"),N([]),T([]),R(null),S(0),v("")},children:"TRY AGAIN"})]})})]})})}async function J6(){const e=await fetch("/api/packages/summary");if(!e.ok)throw new Error(`HTTP ${e.status}`);return e.json()}function eP(){return Tt({queryKey:["packages"],queryFn:J6})}function tP(e){switch(e){case"applied":return"bg-success";case"rolled_back":return"bg-warning";case"failed":return"bg-destructive";default:return"bg-foreground-muted-on-dark"}}function nP(e){switch(e){case"applied":return"APPLIED";case"rolled_back":return"ROLLED BACK";case"failed":return"FAILED";default:return"NONE"}}function sP({pkg:e,onSelect:t}){return u.jsxs("div",{"data-testid":"package-card",role:"link",tabIndex:0,className:"card-dark p-spacing-6 mb-spacing-3 cursor-pointer",onClick:()=>t(e.id),onKeyDown:s=>{s.key==="Enter"&&t(e.id)},children:[u.jsxs("div",{className:"flex items-baseline justify-between mb-spacing-2",children:[u.jsx("h3",{className:"text-headline-md uppercase",children:e.name}),u.jsxs("span",{className:"text-label-md font-mono text-foreground-muted-on-dark",children:["v",e.version]})]}),e.summary&&u.jsx("p",{className:"text-body-sm text-foreground-muted-on-dark mb-spacing-4",children:e.summary}),u.jsx("div",{className:"flex items-center gap-spacing-4 text-label-sm",children:u.jsxs("span",{className:"text-foreground-muted-on-dark",children:["SOURCE ",u.jsx("span",{className:"font-mono text-foreground-on-dark",children:e.sourceRef})]})}),u.jsxs("div",{className:"flex items-center gap-spacing-4 mt-spacing-3 text-label-sm",children:[u.jsxs("span",{className:"text-foreground-muted-on-dark",children:["INSTALLS ",u.jsx("span",{className:"font-mono text-foreground-on-dark","data-testid":"install-count",children:e.installCount})]}),u.jsxs("span",{className:"flex items-center gap-spacing-1",children:[u.jsx("span",{className:Te("inline-block w-[6px] h-[6px]",tP(e.latestInstallStatus))}),u.jsx("span",{className:"text-foreground-muted-on-dark","data-testid":"install-status",children:nP(e.latestInstallStatus)})]})]})]})}function aP(){const e=Xt(),{data:t,isPending:s,error:r}=eP(),i=t?[...t].sort((l,d)=>d.createdAt.localeCompare(l.createdAt)):[];return s?u.jsx(rt,{children:u.jsxs("div",{"data-testid":"packages-loading",children:[u.jsxs("div",{className:"flex justify-between mb-spacing-6",children:[u.jsx("div",{className:"h-8 w-32 shimmer"}),u.jsx("div",{className:"h-8 w-28 shimmer"})]}),[1,2].map(l=>u.jsxs("div",{className:"card-dark p-spacing-6 mb-spacing-3",children:[u.jsx("div",{className:"h-6 w-48 shimmer-dark mb-spacing-4"}),u.jsx("div",{className:"h-12 shimmer-dark mb-spacing-4"}),u.jsx("div",{className:"h-4 w-64 shimmer-dark"})]},l))]})}):r?u.jsx(rt,{children:u.jsx("div",{children:u.jsx(Qt,{"data-testid":"packages-error",children:u.jsx(Kt,{children:r.message})})})}):i.length===0?u.jsx(rt,{children:u.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[60vh]","data-testid":"packages-empty",children:[u.jsx("h2",{className:"text-display-lg text-foreground mb-spacing-4",children:"NO LEGACY PACKAGE INSTALLS"}),u.jsx("p",{className:"text-body-md text-foreground-muted mb-spacing-8",children:"Legacy package tools remain available for bootstrap internals while Specs becomes the main authoring surface."}),u.jsxs("div",{className:"flex flex-col items-center gap-spacing-3",children:[u.jsx(Ne,{variant:"default",size:"lg","data-testid":"empty-import-btn",onClick:()=>e({to:"/import"}),children:"IMPORT RIGSPEC"}),u.jsx(Ne,{variant:"ghost",size:"lg","data-testid":"empty-bootstrap-btn",onClick:()=>e({to:"/bootstrap"}),children:"BOOTSTRAP"})]})]})}):u.jsx(rt,{children:u.jsxs("div",{children:[u.jsxs("div",{className:"flex justify-between items-baseline mb-spacing-6",children:[u.jsxs("div",{children:[u.jsx("h2",{className:"text-headline-lg uppercase",children:"LEGACY PACKAGE TOOLS"}),u.jsxs("p",{className:"text-label-md text-foreground-muted font-grotesk mt-spacing-1",children:[i.length," legacy package install",i.length!==1?"s":""," retained for bootstrap internals"]})]}),u.jsxs("div",{className:"flex flex-col items-end gap-spacing-2",children:[u.jsx(Ne,{variant:"default",size:"sm","data-testid":"header-import-btn",onClick:()=>e({to:"/import"}),children:"IMPORT RIGSPEC"}),u.jsx(Ne,{variant:"ghost",size:"sm","data-testid":"header-bootstrap-btn",onClick:()=>e({to:"/bootstrap"}),children:"BOOTSTRAP"})]})]}),i.map(l=>u.jsx(sP,{pkg:l,onSelect:d=>e({to:"/packages/$packageId",params:{packageId:d}})},l.id))]})})}const rP=[{num:1,label:"ENTER"},{num:2,label:"VALIDATE"},{num:3,label:"CONFIGURE"},{num:4,label:"PLAN"},{num:5,label:"APPLY"}];function iP(e){switch(e){case"enter":return 1;case"validating":case"validated":return 2;case"configure":return 3;case"planning":case"planned":return 4;case"applying":case"done":return 5;case"error":return 0}}function oP({currentStep:e,errorAtStep:t}){const s=e==="error"?t:iP(e);return u.jsx("div",{className:"flex items-center gap-spacing-2 mb-spacing-8 p-spacing-4 inset-light flex-wrap","data-testid":"step-indicator",children:rP.map((r,i)=>{const l=s>r.num,d=s===r.num;return u.jsxs("div",{className:"flex items-center gap-spacing-2",children:[i>0&&u.jsx("div",{className:`w-6 h-px mx-spacing-1 ${l?"bg-primary/40":"bg-foreground-muted/20"}`}),u.jsxs("span",{"data-testid":`step-${r.num}`,className:Te("text-label-sm uppercase tracking-[0.04em] font-mono px-spacing-2 py-spacing-1 transition-colors whitespace-nowrap",l?"text-foreground-muted":d?"text-foreground bg-foreground/10":"text-foreground-muted/30"),children:[l?"✓":""," [ ",r.num," ",r.label," ]"]})]},r.num)})})}function lP(e){switch(e){case"approved":return"text-success";case"rejected":return"text-warning";case"deferred":return"text-foreground-muted";case"conflict":return"text-destructive";case"noop":return"text-foreground-muted/50";default:return""}}function cP(e){switch(e){case"approved":return"bg-success/8";case"rejected":return"bg-warning/8";case"deferred":return"bg-foreground-muted/4";case"conflict":return"bg-destructive/8";default:return""}}function uP(){const e=Xt(),[t,s]=j.useState(""),[r,i]=j.useState("enter"),[l,d]=j.useState(0),[f,m]=j.useState([]),[h,v]=j.useState(null),[g,y]=j.useState("claude-code"),[b,S]=j.useState("."),[w,N]=j.useState(""),[C,T]=j.useState(!1),[_,R]=j.useState(null),[O,B]=j.useState(null),L=async()=>{i("validating"),m([]);try{const Y=await(await fetch("/api/packages/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceRef:t})})).json();Y.valid?(v(Y.manifest),i("validated")):(m(Y.errors??[Y.error??"Validation failed"]),d(2),i("error"))}catch{m(["Validation request failed"]),d(2),i("error")}},M=async()=>{i("planning"),m([]);try{const D=await fetch("/api/packages/plan",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceRef:t,targetRoot:b,runtime:g,roleName:w||void 0,allowMerge:C})});if(!D.ok){const K=await D.json();m(K.errors??[K.error??"Plan failed"]),d(4),i("error");return}const Y=await D.json();R(Y),i("planned")}catch{m(["Plan request failed"]),d(4),i("error")}},I=async()=>{i("applying"),m([]);try{const D=await fetch("/api/packages/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceRef:t,targetRoot:b,runtime:g,roleName:w||void 0,allowMerge:C})}),Y=await D.json();if(D.status>=400){m(Y.errors??[Y.error??"Install failed"]),d(5),i("error");return}B(Y),i("done")}catch{m(["Install request failed"]),d(5),i("error")}},H=((_==null?void 0:_.conflicts)??0)>0;return u.jsx(rt,{children:u.jsxs("div",{"data-testid":"install-flow",children:[u.jsx("div",{className:"mb-spacing-8",children:u.jsxs("div",{children:[u.jsx("h2",{className:"text-headline-lg uppercase tracking-[0.06em]",children:"INSTALL PACKAGE (Legacy)"}),u.jsx("p",{className:"text-label-md text-foreground-muted font-grotesk mt-spacing-1",children:"Validate, configure, and apply an agent package"})]})}),u.jsx(oP,{currentStep:r,errorAtStep:l}),r==="enter"&&u.jsxs("div",{children:[u.jsx("label",{className:"text-label-md text-foreground-muted uppercase tracking-[0.04em] block mb-spacing-2",children:"PACKAGE PATH"}),u.jsx("input",{"data-testid":"source-path-input",type:"text",value:t,onChange:D=>s(D.target.value),placeholder:"/path/to/package",className:"w-full bg-transparent border-b border-foreground/20 focus:border-foreground px-0 py-spacing-2 text-body-md font-mono outline-none transition-colors"}),u.jsx(Ne,{variant:"tactical","data-testid":"validate-btn",onClick:L,disabled:!t.trim(),className:"mt-spacing-4",children:"VALIDATE"})]}),r==="validating"&&u.jsx("div",{className:"text-label-md text-foreground-muted","data-testid":"validating-indicator",children:"Validating..."}),r==="validated"&&h&&u.jsxs("div",{"data-testid":"manifest-summary",children:[u.jsxs("div",{className:"card-dark p-spacing-4 mb-spacing-4",children:[u.jsxs("div",{className:"flex items-baseline justify-between mb-spacing-2",children:[u.jsx("span",{className:"text-headline-md uppercase",children:h.name}),u.jsxs("span",{className:"font-mono text-foreground-muted-on-dark",children:["v",h.version]})]}),u.jsx("p",{className:"text-body-sm text-foreground-muted-on-dark mb-spacing-3",children:h.summary}),u.jsxs("div",{className:"flex flex-wrap gap-spacing-3 text-label-sm",children:[u.jsxs("span",{children:["Skills: ",u.jsx("span",{className:"font-mono text-foreground-on-dark",children:h.exportCounts.skills})]}),u.jsxs("span",{children:["Guidance: ",u.jsx("span",{className:"font-mono text-foreground-on-dark",children:h.exportCounts.guidance})]}),u.jsxs("span",{children:["Agents: ",u.jsx("span",{className:"font-mono text-foreground-on-dark",children:h.exportCounts.agents})]}),u.jsxs("span",{children:["Hooks: ",u.jsx("span",{className:"font-mono text-foreground-on-dark",children:h.exportCounts.hooks})]}),u.jsxs("span",{children:["Runtimes: ",u.jsx("span",{className:"font-mono text-foreground-on-dark",children:h.runtimes.join(", ")})]})]})]}),u.jsx(Ne,{variant:"tactical","data-testid":"configure-btn",onClick:()=>i("configure"),children:"CONFIGURE"})]}),r==="configure"&&h&&u.jsxs("div",{"data-testid":"configure-step",children:[u.jsxs("div",{className:"space-y-spacing-4 mb-spacing-6",children:[u.jsxs("div",{children:[u.jsx("label",{className:"text-label-sm text-foreground-muted uppercase tracking-[0.04em] block mb-spacing-1",children:"RUNTIME"}),u.jsx("select",{"data-testid":"runtime-select",value:g,onChange:D=>y(D.target.value),className:"bg-transparent border-b border-foreground/20 py-spacing-1 text-body-md font-mono outline-none",children:h.runtimes.map(D=>u.jsx("option",{value:D,children:D},D))})]}),u.jsxs("div",{children:[u.jsx("label",{className:"text-label-sm text-foreground-muted uppercase tracking-[0.04em] block mb-spacing-1",children:"TARGET ROOT"}),u.jsx("input",{"data-testid":"target-root-input",type:"text",value:b,onChange:D=>S(D.target.value),className:"w-full bg-transparent border-b border-foreground/20 px-0 py-spacing-1 text-body-md font-mono outline-none"})]}),h.roles.length>0&&u.jsxs("div",{children:[u.jsx("label",{className:"text-label-sm text-foreground-muted uppercase tracking-[0.04em] block mb-spacing-1",children:"ROLE"}),u.jsxs("select",{"data-testid":"role-select",value:w,onChange:D=>N(D.target.value),className:"bg-transparent border-b border-foreground/20 py-spacing-1 text-body-md font-mono outline-none",children:[u.jsx("option",{value:"",children:"All exports"}),h.roles.map(D=>u.jsxs("option",{value:D.name,children:[D.name,D.description?` — ${D.description}`:""]},D.name))]})]}),u.jsxs("div",{className:"flex items-center gap-spacing-2",children:[u.jsx("input",{"data-testid":"allow-merge-toggle",type:"checkbox",checked:C,onChange:D=>T(D.target.checked),className:"accent-primary"}),u.jsx("label",{className:"text-label-sm text-foreground-muted",children:"Allow managed block merges into existing files"})]}),(h.requirements.cliTools.length>0||h.requirements.systemPackages.length>0)&&u.jsxs("div",{"data-testid":"requirements-section",className:"p-spacing-3 bg-foreground/4",children:[u.jsx("span",{className:"text-label-sm text-foreground-muted uppercase block mb-spacing-1",children:"REQUIREMENTS"}),h.requirements.cliTools.map(D=>u.jsxs("div",{className:"text-body-sm font-mono",children:["CLI: ",D.name]},D.name)),h.requirements.systemPackages.map(D=>u.jsxs("div",{className:"text-body-sm font-mono",children:["System: ",D.name]},D.name))]})]}),u.jsx(Ne,{variant:"tactical","data-testid":"plan-btn",onClick:M,children:"PREVIEW PLAN"})]}),r==="planning"&&u.jsx("div",{className:"text-label-md text-foreground-muted","data-testid":"planning-indicator",children:"Planning..."}),r==="planned"&&_&&u.jsxs("div",{"data-testid":"plan-preview",children:[u.jsxs("div",{className:"flex flex-wrap gap-spacing-4 mb-spacing-4 text-label-sm",children:[u.jsxs("span",{children:["Approved: ",u.jsx("span",{className:"font-mono text-success","data-testid":"plan-actionable",children:_.actionable})]}),u.jsxs("span",{children:["Deferred: ",u.jsx("span",{className:"font-mono text-foreground-muted","data-testid":"plan-deferred",children:_.deferred})]}),u.jsxs("span",{children:["Conflicts: ",u.jsx("span",{className:"font-mono text-destructive","data-testid":"plan-conflicts",children:_.conflicts})]}),u.jsxs("span",{children:["No-ops: ",u.jsx("span",{className:"font-mono","data-testid":"plan-noops",children:_.noOps})]}),_.rejected>0&&u.jsxs("span",{children:["Rejected: ",u.jsx("span",{className:"font-mono text-warning","data-testid":"plan-rejected",children:_.rejected})]})]}),H&&u.jsx(Qt,{className:"mb-spacing-4","data-testid":"conflict-warning",children:u.jsx(Kt,{className:"text-destructive",children:"Conflicts detected — resolve before applying"})}),u.jsxs(g0,{children:[u.jsx(x0,{children:u.jsxs(cc,{children:[u.jsx(Or,{children:"TYPE"}),u.jsx(Or,{children:"NAME"}),u.jsx(Or,{children:"STATUS"}),u.jsx(Or,{children:"TARGET"})]})}),u.jsx(y0,{children:_.entries.map((D,Y)=>u.jsxs(cc,{className:cP(D.policyStatus),"data-testid":"plan-entry","data-policy-status":D.policyStatus,children:[u.jsx(Dr,{className:"font-mono text-label-sm",children:D.exportType}),u.jsx(Dr,{className:"font-mono text-label-sm",children:D.exportName}),u.jsxs(Dr,{className:Te("font-mono text-label-sm uppercase",lP(D.policyStatus)),children:[D.policyStatus,D.deferReason&&u.jsxs("span",{className:"text-foreground-muted normal-case",children:[" — ",D.deferReason]}),D.conflict&&u.jsxs("span",{className:"text-destructive normal-case",children:[" — ",D.conflict.reason]})]}),u.jsx(Dr,{className:"font-mono text-label-sm text-foreground-muted truncate max-w-[200px]",children:D.targetPath||"—"})]},Y))})]}),u.jsx("div",{className:"mt-spacing-4",children:u.jsx(Ne,{variant:"tactical","data-testid":"apply-btn",onClick:I,disabled:H,title:H?"Resolve conflicts before applying":void 0,children:"APPLY"})})]}),r==="applying"&&u.jsx("div",{className:"text-label-md text-foreground-muted","data-testid":"applying-indicator",children:"Applying..."}),r==="done"&&O&&u.jsxs("div",{"data-testid":"install-result",children:[u.jsx(Qt,{className:"mb-spacing-4",children:u.jsxs(Kt,{children:[u.jsx("span",{className:"text-primary font-mono",children:O.packageName}),u.jsx("span",{className:"text-foreground-muted",children:" installed as "}),u.jsx("span",{className:"font-mono","data-testid":"result-install-id",children:O.installId})]})}),u.jsxs("div",{className:"flex gap-spacing-4 text-label-sm mb-spacing-4",children:[u.jsxs("span",{children:["Applied: ",u.jsx("span",{className:"font-mono text-success","data-testid":"result-applied",children:O.applied.length})]}),u.jsxs("span",{children:["Deferred: ",u.jsx("span",{className:"font-mono text-foreground-muted","data-testid":"result-deferred",children:O.deferred.length})]}),u.jsxs("span",{children:["Verified: ",u.jsx("span",{className:Te("font-mono",O.verification.passed?"text-success":"text-destructive"),"data-testid":"result-verified",children:O.verification.passed?"PASS":"FAIL"})]})]}),u.jsx("div",{className:"flex gap-spacing-3",children:u.jsx(Ne,{variant:"tactical","data-testid":"detail-link",onClick:()=>e({to:"/packages/$packageId",params:{packageId:O.packageId}}),children:"VIEW INSTALL DETAILS"})})]}),r==="error"&&u.jsxs("div",{"data-testid":"install-errors",children:[f.map((D,Y)=>u.jsx(Qt,{className:"mb-spacing-2",children:u.jsx(Kt,{className:"text-destructive",children:D})},Y)),u.jsx(Ne,{variant:"tactical",className:"mt-spacing-4","data-testid":"try-again-btn",onClick:()=>{i("enter"),m([]),v(null),R(null),B(null),d(0)},children:"TRY AGAIN"})]})]})})}function dP(e){return Tt({queryKey:["packages",e],queryFn:async()=>{const t=await fetch(`/api/packages/${e}`);if(!t.ok)throw new Error(`HTTP ${t.status}`);return t.json()},enabled:!!e})}function fP(e){return Tt({queryKey:["packages",e,"installs"],queryFn:async()=>{const t=await fetch(`/api/packages/${e}/installs`);if(!t.ok)throw new Error(`HTTP ${t.status}`);return t.json()},enabled:!!e})}function hP(e){return Tt({queryKey:["installs",e,"journal"],queryFn:async()=>{const t=await fetch(`/api/packages/installs/${e}/journal`);if(!t.ok)throw new Error(`HTTP ${t.status}`);return t.json()},enabled:!!e})}function mP(e){const t=Ct();return Pt({mutationFn:async s=>{const r=await fetch(`/api/packages/${s}/rollback`,{method:"POST"});if(!r.ok)throw new Error(`HTTP ${r.status}`);return r.json()},onSuccess:()=>{t.invalidateQueries({queryKey:["packages",e,"installs"]}),t.invalidateQueries({queryKey:["installs"]})}})}function pP(e){switch(e){case"applied":return"bg-success";case"rolled_back":return"bg-warning";case"failed":return"bg-destructive";default:return"bg-foreground-muted"}}function gP(e){switch(e){case"applied":return"APPLIED";case"rolled_back":return"ROLLED BACK";case"failed":return"FAILED";default:return e.toUpperCase()}}function xP({installId:e}){const{data:t,isPending:s,isError:r}=hP(e);return s?u.jsx("div",{className:"pl-spacing-6 py-spacing-2 text-label-sm text-foreground-muted",children:"Loading journal..."}):r?u.jsx("div",{className:"pl-spacing-6 py-spacing-2 text-label-sm text-destructive","data-testid":"journal-error",children:"Failed to load journal entries"}):!t||t.length===0?u.jsx("div",{className:"pl-spacing-6 py-spacing-2 text-label-sm text-foreground-muted",children:"No journal entries"}):u.jsx("div",{className:"pl-spacing-6 py-spacing-2 space-y-spacing-1","data-testid":"journal-entries",children:t.map(i=>u.jsxs("div",{"data-testid":"journal-entry",className:"flex items-center gap-spacing-3 text-label-sm font-mono py-spacing-1 border-b border-foreground/6 last:border-0",children:[u.jsx("span",{className:"text-foreground-muted w-6 text-right",children:i.seq}),u.jsx("span",{className:"uppercase",children:i.action}),u.jsx("span",{className:"text-foreground-muted",children:i.exportType}),u.jsx("span",{className:"text-foreground-muted truncate max-w-[200px]",children:i.targetPath}),u.jsx("span",{className:"text-foreground-muted ml-auto",children:i.status})]},i.id))})}function yP({install:e,onRollback:t}){const[s,r]=j.useState(!1);return u.jsxs("div",{"data-testid":"install-row",className:"card-dark p-spacing-4 mb-spacing-2",children:[u.jsxs("div",{className:"flex items-center gap-spacing-4",children:[u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsxs("div",{className:"flex items-center gap-spacing-3 mb-spacing-1",children:[u.jsx("span",{className:"font-mono text-label-sm text-foreground-muted",children:e.createdAt}),u.jsx("span",{"data-testid":"install-status-badge",className:Te("inline-block px-spacing-2 py-px text-label-sm uppercase",pP(e.status)),children:gP(e.status)})]}),u.jsx("div",{className:"text-label-sm font-mono text-foreground-muted-on-dark",children:e.targetRoot}),u.jsxs("div",{className:"flex items-center gap-spacing-3 mt-spacing-1 text-label-sm",children:[u.jsxs("span",{"data-testid":"applied-count",children:[u.jsx("span",{className:"font-mono",children:e.appliedCount})," applied"]}),u.jsx("span",{"data-testid":"deferred-placeholder",className:"text-foreground-muted",children:"— deferred"})]})]}),u.jsxs("div",{className:"flex items-center gap-spacing-2 shrink-0",children:[u.jsx(Ne,{variant:"tactical",size:"sm","data-testid":"expand-btn",onClick:()=>r(!s),children:s?"COLLAPSE":"EXPAND"}),e.status==="applied"&&u.jsx(Ne,{variant:"tactical",size:"sm","data-testid":"rollback-btn",onClick:()=>t(e.id),children:"ROLLBACK"})]})]}),s&&u.jsx(xP,{installId:e.id})]})}function vP(){var w;const{packageId:e}=cf({strict:!1}),{data:t,isPending:s,error:r}=dP(e),{data:i,isPending:l,error:d}=fP(e),f=mP(e),[m,h]=j.useState(null),[v,g]=j.useState(!1),y=N=>{h(N),g(!0)},b=()=>{m&&f.mutate(m,{onSuccess:()=>{g(!1),h(null)}})};if(s||l)return u.jsx(rt,{children:u.jsxs("div",{"data-testid":"detail-loading",children:[u.jsx("div",{className:"h-8 w-48 shimmer mb-spacing-4"}),u.jsxs("div",{className:"card-dark p-spacing-6 mb-spacing-4",children:[u.jsx("div",{className:"h-6 w-64 shimmer-dark mb-spacing-3"}),u.jsx("div",{className:"h-4 w-full shimmer-dark"})]})]})});if(r)return u.jsx(rt,{children:u.jsx("div",{"data-testid":"detail-error",children:u.jsx("p",{className:"text-destructive",children:r.message})})});if(d)return u.jsx(rt,{children:u.jsx("div",{"data-testid":"installs-error",children:u.jsx("p",{className:"text-destructive",children:"Failed to load install history"})})});const S=i??[];return u.jsx(rt,{children:u.jsxs("div",{children:[t&&u.jsxs("div",{className:"card-dark p-spacing-6 mb-spacing-6","data-testid":"package-header",children:[u.jsxs("div",{className:"flex items-baseline justify-between mb-spacing-2",children:[u.jsxs("h2",{className:"text-headline-lg uppercase",children:[t.name," (Legacy)"]}),u.jsxs("span",{className:"text-label-md font-mono text-foreground-muted-on-dark",children:["v",t.version]})]}),u.jsxs("div",{className:"text-label-sm text-foreground-muted-on-dark mb-spacing-2",children:["SOURCE"," ",u.jsx("span",{className:"font-mono text-foreground-on-dark","data-testid":"package-source",children:t.sourceRef})]}),t.summary&&u.jsx("p",{className:"text-body-sm text-foreground-muted-on-dark",children:t.summary})]}),u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-4",children:"INSTALL HISTORY"}),S.length===0?u.jsx("div",{"data-testid":"empty-installs",className:"text-body-md text-foreground-muted",children:"No installs yet"}):u.jsx("div",{"data-testid":"install-list",children:S.map(N=>u.jsx(yP,{install:N,onRollback:y},N.id))}),u.jsx(Gd,{open:v,onOpenChange:N=>{f.isPending||(g(N),N||f.reset())},children:u.jsxs(Kl,{"data-testid":"rollback-dialog",onPointerDownOutside:N=>{f.isPending&&N.preventDefault()},onEscapeKeyDown:N=>{f.isPending&&N.preventDefault()},hideCloseButton:f.isPending,children:[u.jsxs(Fl,{children:[u.jsx(Zl,{className:"text-headline-md uppercase",children:"CONFIRM ROLLBACK"}),u.jsx(Wl,{children:"This will roll back the install and restore previous file states. This action cannot be undone."})]}),f.isError&&u.jsxs("p",{className:"text-destructive text-label-sm","data-testid":"rollback-error",children:["Rollback failed: ",((w=f.error)==null?void 0:w.message)??"Unknown error"]}),u.jsxs(Xl,{children:[u.jsx(Ne,{variant:"ghost",onClick:()=>{f.reset(),g(!1)},"data-testid":"rollback-cancel",disabled:f.isPending,children:"CANCEL"}),u.jsx(Ne,{variant:"destructive",onClick:b,"data-testid":"rollback-confirm",disabled:f.isPending,children:f.isPending?"ROLLING BACK...":"ROLLBACK"})]})]})})]})})}function bP(e){switch(e){case"installed":return"bg-success";case"missing":return"bg-destructive";case"unsupported":return"bg-warning";case"unknown":return"bg-warning";default:return"bg-foreground-muted"}}function SP(e){switch(e){case"installed":return"OK";case"missing":return"MISSING";case"unsupported":return"MANUAL";case"unknown":return"UNKNOWN";default:return e.toUpperCase()}}function wP({results:e}){return e.length===0?u.jsx("div",{className:"text-body-sm text-foreground-muted","data-testid":"no-requirements",children:"No requirements declared."}):u.jsx("div",{className:"space-y-spacing-1","data-testid":"requirements-panel",children:e.map(t=>u.jsxs("div",{"data-testid":"requirement-row",className:"flex items-center gap-spacing-3 py-spacing-1 text-label-sm font-mono",children:[u.jsx("span",{"data-testid":"requirement-dot",className:Te("w-2 h-2 shrink-0",bP(t.status))}),u.jsx("span",{"data-testid":"requirement-status",className:"w-16 uppercase",children:SP(t.status)}),u.jsx("span",{className:"text-foreground-muted w-24",children:t.kind}),u.jsx("span",{children:t.name}),t.detectedPath&&u.jsx("span",{className:"text-foreground-muted ml-auto truncate max-w-[200px]",children:t.detectedPath})]},`${t.kind}:${t.name}`))})}function OE(e,t){var r,i;const s=((r=e.stages)==null?void 0:r.flatMap(l=>{const d=l.detail;if(!d)return[];const f=[];return Array.isArray(d.errors)&&f.push(...d.errors.filter(m=>typeof m=="string")),typeof d.error=="string"&&f.push(d.error),f}))??[];return((i=e.errors)==null?void 0:i.find(l=>typeof l=="string"))??s[0]??e.error??`HTTP ${t}`}function NP(){return Pt({mutationFn:async({sourceRef:e})=>{const t=await fetch("/api/bootstrap/plan",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceRef:e})});if(!t.ok){const s=await t.json().catch(()=>({})),r=new Error(OE(s,t.status));throw r.data=s,r}return t.json()}})}function jP(){const e=Ct();return Pt({mutationFn:async({sourceRef:t,autoApprove:s,approvedActionKeys:r})=>{const i=await fetch("/api/bootstrap/apply",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceRef:t,autoApprove:s,approvedActionKeys:r})}),l=await i.json();if(!i.ok){const d=new Error(OE(l,i.status));throw d.data=l,d}return l},onSuccess:()=>{e.invalidateQueries({queryKey:["rigs","summary"]})}})}const EP=["ENTER","PLAN","REVIEW","APPLY"],CP=EP.map((e,t)=>({num:t+1,label:e}));function _P(e){switch(e){case"enter":return 1;case"planning":return 2;case"planned":return 3;case"applying":return 4;case"done":case"error":return 4;default:return 1}}function RP(){const e=Xt(),{bootstrapSourceRef:t,setBootstrapSourceRef:s}=Co(),[r,i]=j.useState("enter"),[l,d]=j.useState(()=>t),[f,m]=j.useState(null),[h,v]=j.useState(new Set),[g,y]=j.useState(!1),[b,S]=j.useState(null),w=NP(),N=jP();j.useEffect(()=>{s(l)},[s,l]);const C=async()=>{if(l.trim()){i("planning");try{const K=await w.mutateAsync({sourceRef:l.trim()});m(K),v(new Set(K.actionKeys??[])),i("planned")}catch(K){S(K.message),i("error")}}},T=async()=>{i("applying");try{const K=await N.mutateAsync({sourceRef:l.trim(),autoApprove:g,approvedActionKeys:g?void 0:[...h]});m(K),i("done")}catch(K){S(K.message),i("error")}},_=()=>{i("enter"),d(""),m(null),v(new Set),y(!1),S(null),w.reset(),N.reset()},R=f==null?void 0:f.stages.find(K=>K.stage==="probe_requirements"),O=R==null?void 0:R.detail,B=(O==null?void 0:O.results)??[],L=f==null?void 0:f.stages.find(K=>K.stage==="build_install_plan"),M=L==null?void 0:L.detail,I=(M==null?void 0:M.actions)??[],H=(L==null?void 0:L.status)==="blocked",Y=I.some(K=>K.classification!=="manual_only"&&K.commandPreview)&&h.size===0&&!g;return u.jsx(rt,{children:u.jsxs("div",{"data-testid":"bootstrap-wizard",className:"space-y-8",children:[u.jsx(Yn,{eyebrow:"Bootstrap",title:"Bootstrap",description:"Plan environment requirements, approve install actions, then import the rig into a running topology."}),u.jsx(ME,{"data-testid":"step-indicator",steps:CP,currentStep:_P(r)}),r==="enter"&&u.jsx(Ln,{title:"Source",description:"Provide a rig spec or bundle path. Bootstrap will inspect requirements before it imports anything.",children:u.jsxs("div",{"data-testid":"step-enter",children:[u.jsx("label",{className:"text-label-md uppercase block mb-spacing-2",children:"SPEC OR BUNDLE PATH"}),u.jsx(m0,{"data-testid":"spec-input",type:"text",value:l,onChange:K=>d(K.target.value),placeholder:"/path/to/rig.yaml or /path/to/bundle.rigbundle",className:"font-mono text-body-md"}),u.jsxs("p",{className:"text-label-sm text-foreground-muted mt-spacing-1",children:["Accepts .yaml rig specs or .rigbundle archives."," ",u.jsx("span",{role:"link",tabIndex:0,className:"text-primary cursor-pointer","data-testid":"inspect-link",onClick:()=>e({to:"/bundles/inspect"}),onKeyDown:K=>{K.key==="Enter"&&e({to:"/bundles/inspect"})},children:"Inspect a bundle first →"})]}),u.jsx("div",{className:"mt-spacing-4",children:u.jsx(Ne,{variant:"tactical",onClick:C,disabled:!l.trim(),"data-testid":"plan-btn",children:"PLAN"})})]})}),r==="planning"&&u.jsx("div",{"data-testid":"step-planning",className:"text-body-md text-foreground-muted",children:"Planning..."}),r==="planned"&&f&&u.jsx(Ln,{title:"Plan Review",description:"Review requirement probe results and approve the install actions that bootstrap should execute.",children:u.jsxs("div",{"data-testid":"step-planned",children:[u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"STAGES"}),u.jsx("div",{className:"space-y-spacing-1 mb-spacing-6","data-testid":"stage-list",children:f.stages.map(K=>u.jsxs("div",{className:"flex items-center gap-spacing-3 text-label-sm font-mono","data-testid":"stage-row",children:[u.jsx("span",{className:K.status==="ok"?"text-success":K.status==="blocked"?"text-warning":"text-foreground-muted",children:K.status.toUpperCase()}),u.jsx("span",{children:K.stage})]},K.stage))}),B.length>0&&u.jsxs(u.Fragment,{children:[u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"REQUIREMENTS"}),u.jsx("div",{className:"mb-spacing-6",children:u.jsx(wP,{results:B})})]}),I.length>0&&u.jsxs(u.Fragment,{children:[u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"ACTIONS"}),u.jsx("div",{className:"space-y-spacing-1 mb-spacing-4",children:I.map(K=>u.jsxs("label",{className:"flex items-center gap-spacing-3 text-label-sm font-mono cursor-pointer",children:[u.jsx("input",{type:"checkbox",checked:g||h.has(K.key),disabled:g||K.classification==="manual_only",onChange:U=>{const q=new Set(h);U.target.checked?q.add(K.key):q.delete(K.key),v(q)}}),u.jsx("span",{className:K.classification==="manual_only"?"text-warning":"",children:K.requirementName}),K.commandPreview&&u.jsx("span",{className:"text-foreground-muted",children:K.commandPreview})]},K.key))}),u.jsxs("label",{className:"flex items-center gap-spacing-2 text-label-sm mb-spacing-4",children:[u.jsx("input",{type:"checkbox",checked:g,onChange:K=>y(K.target.checked)}),"Auto-approve all trusted actions"]})]}),H&&u.jsx("div",{className:"text-warning text-label-sm mb-spacing-4","data-testid":"blocked-warning",children:"Manual requirements must be resolved before bootstrap can proceed."}),f.warnings.length>0&&u.jsx("div",{className:"mb-spacing-4",children:f.warnings.map((K,U)=>u.jsx("div",{className:"text-warning text-label-sm",children:K},U))}),u.jsx(Ne,{variant:"tactical",onClick:T,disabled:H||Y,title:H?"Manual requirements must be resolved":Y?"Select actions to approve":void 0,"data-testid":"apply-btn",children:"APPLY"})]})}),r==="applying"&&f&&u.jsx(Ln,{title:"Applying",description:"Bootstrap is executing the approved actions and importing the rig.",children:u.jsxs("div",{"data-testid":"step-applying",children:[u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"APPLYING"}),u.jsxs("div",{className:"space-y-spacing-1 mb-spacing-4","data-testid":"applying-checklist",children:[f.stages.map(K=>u.jsxs("div",{className:"flex items-center gap-spacing-3 text-label-sm font-mono",children:[u.jsx("span",{className:"text-foreground-muted",children:"○"}),u.jsx("span",{children:K.stage})]},K.stage)),u.jsxs("div",{className:"flex items-center gap-spacing-3 text-label-sm font-mono",children:[u.jsx("span",{className:"text-foreground-muted",children:"○"}),u.jsx("span",{children:"execute_external_installs"})]}),u.jsxs("div",{className:"flex items-center gap-spacing-3 text-label-sm font-mono",children:[u.jsx("span",{className:"text-foreground-muted",children:"○"}),u.jsx("span",{children:"install_packages"})]}),u.jsxs("div",{className:"flex items-center gap-spacing-3 text-label-sm font-mono",children:[u.jsx("span",{className:"text-foreground-muted",children:"○"}),u.jsx("span",{children:"import_rig"})]})]}),u.jsx("p",{className:"text-body-sm text-foreground-muted",children:"Bootstrapping..."})]})}),r==="done"&&f&&u.jsx(Ln,{title:"Result",description:"Bootstrap finished and returned the managed rig identity.",children:u.jsxs("div",{"data-testid":"step-done",children:[u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:f.status==="completed"?"BOOTSTRAP COMPLETE":"BOOTSTRAP PARTIAL"}),u.jsxs("div",{className:"text-label-sm font-mono space-y-spacing-1 mb-spacing-4",children:[u.jsxs("div",{children:["Status: ",u.jsx("span",{className:f.status==="completed"?"text-success":"text-warning",children:f.status.toUpperCase()})]}),f.rigId&&u.jsxs("div",{"data-testid":"result-rig-id",children:["Rig: ",f.rigId]})]}),f.rigId&&u.jsx(Ne,{variant:"tactical","data-testid":"view-rig-btn",onClick:()=>e({to:"/rigs/$rigId",params:{rigId:f.rigId}}),children:"VIEW RIG"})]})}),r==="error"&&u.jsx(Ln,{title:"Bootstrap Error",description:"Bootstrap could not complete. Fix the issue and retry the plan.",children:u.jsxs("div",{"data-testid":"step-error",children:[u.jsx("p",{className:"text-destructive text-body-md mb-spacing-4",children:b}),u.jsx(Ne,{variant:"tactical",onClick:_,"data-testid":"try-again-btn",children:"TRY AGAIN"})]})})]})})}function TP(){const{currentAgentDraft:e,selectedAgentDraft:t,saveAgentDraft:s,rememberAgentDraft:r,clearSelectedAgentDraft:i}=Co(),[l,d]=j.useState(()=>(t==null?void 0:t.yaml)??(e==null?void 0:e.yaml)??""),[f,m]=j.useState("idle"),[h,v]=j.useState([]);j.useEffect(()=>{s(l)},[s,l]),j.useEffect(()=>{t&&(d(t.yaml),i())},[i,t]);const g=async()=>{r(l),m("pending"),v([]);try{const y=await fetch("/api/agents/validate",{method:"POST",headers:{"Content-Type":"text/yaml"},body:l}),b=await y.json().catch(()=>({}));if(y.ok&&b.valid){m("valid");return}v(b.errors??["Validation failed"]),m("invalid")}catch{v(["Validation request failed"]),m("error")}};return u.jsx(rt,{children:u.jsxs("div",{"data-testid":"agent-spec-validate-flow",className:"space-y-8",children:[u.jsx(Yn,{eyebrow:"Agent Spec Validation",title:"VALIDATE AGENT",description:"Check an AgentSpec before you use it in a rig."}),u.jsxs(Ln,{title:"Agent YAML",description:"Paste or refine an AgentSpec draft, then validate it against the daemon contract.",children:[u.jsx(p0,{"data-testid":"agent-spec-yaml-input",value:l,onChange:y=>d(y.target.value),placeholder:"Paste agent.yaml here...",rows:16,className:"bg-background font-mono text-body-sm"}),u.jsx("div",{className:"flex flex-wrap gap-2",children:u.jsx(Ne,{variant:"tactical","data-testid":"agent-spec-validate-btn",onClick:g,disabled:!l.trim()||f==="pending",children:f==="pending"?"VALIDATING...":"VALIDATE AGENTSPEC"})}),f==="valid"&&u.jsx(Qt,{className:"mt-spacing-1","data-testid":"agent-spec-valid",children:u.jsx(Kt,{className:"text-primary",children:"AgentSpec valid."})}),(f==="invalid"||f==="error")&&u.jsx(Qt,{className:"mt-spacing-1","data-testid":"agent-spec-invalid",children:u.jsx(Kt,{children:u.jsx("ul",{className:"list-disc pl-5",children:h.map(y=>u.jsx("li",{children:y},y))})})})]})]})})}async function AP(e,t="draft"){var r;const s=await fetch("/api/specs/review/rig",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({yaml:e,sourceState:t})});if(!s.ok){const i=await s.json().catch(()=>({}));throw new Error(((r=i.errors)==null?void 0:r.join("; "))??`HTTP ${s.status}`)}return s.json()}async function MP(e,t="draft"){var r;const s=await fetch("/api/specs/review/agent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({yaml:e,sourceState:t})});if(!s.ok){const i=await s.json().catch(()=>({}));throw new Error(((r=i.errors)==null?void 0:r.join("; "))??`HTTP ${s.status}`)}return s.json()}function DE(e){let t=0;for(let s=0;s<e.length;s++)t=(t<<5)-t+e.charCodeAt(s)|0;return t}function kP(e,t="draft"){return Tt({queryKey:["spec-review","rig",e?DE(e):null,t],queryFn:()=>AP(e,t),enabled:!!e})}function OP(e,t="draft"){return Tt({queryKey:["spec-review","agent",e?DE(e):null,t],queryFn:()=>MP(e,t),enabled:!!e})}const DP=160,LP=48,OS=200,zP=100;function PP(e){switch(e){case"claude-code":return"#d4c4a8";case"codex":return"#b8c9d4";case"terminal":return"#c4c4c4";default:return"#e0ddd4"}}function IP(e){const t=new Map,s=[];for(const l of e)l.pod?(t.has(l.pod)||t.set(l.pod,[]),t.get(l.pod).push(l)):s.push(l);const r=[];let i=0;for(const[,l]of t)l.forEach((d,f)=>{r.push({id:d.id,x:f*OS,y:i})}),i+=zP;return s.forEach((l,d)=>{r.push({id:l.id,x:d*OS,y:i})}),r}function BP({graph:e,testId:t}){const s=e??{nodes:[],edges:[]},{nodes:r,edges:i}=j.useMemo(()=>{const l=IP(s.nodes),d=new Map(l.map(h=>[h.id,h])),f=s.nodes.map(h=>{const v=d.get(h.id)??{x:0,y:0};return{id:h.id,type:"default",position:{x:v.x,y:v.y},data:{label:`${h.pod?`${h.pod} / `:""}${h.label}`},style:{backgroundColor:PP(h.runtime),border:"1px solid #8a8577",fontSize:11,fontFamily:"monospace",width:DP,height:LP}}}),m=s.edges.map((h,v)=>({id:`e-${v}`,source:h.source,target:h.target,label:h.kind,labelStyle:{fontSize:9,fontFamily:"monospace"},style:{strokeDasharray:"4 4",stroke:"#8a8577"}}));return{nodes:f,edges:m}},[s]);return u.jsx("div",{"data-testid":t??"spec-topology-preview",className:"w-full h-[400px] bg-stone-50 border border-stone-200",children:u.jsxs(wE,{nodes:r,edges:i,fitView:!0,nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,proOptions:{hideAttribution:!0},children:[u.jsx(J8,{gap:20,size:.5,color:"#d4d0c8"}),u.jsx(EE,{showInteractive:!1})]})})}function LE({review:e,yaml:t,testIdPrefix:s="",yamlTestId:r,onMemberClick:i}){const[l,d]=j.useState("topology"),f=(e==null?void 0:e.pods)??[],m=(e==null?void 0:e.nodes)??[],h=(e==null?void 0:e.edges)??[],v=s?`${s}-`:"";return u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"flex gap-1 border-b border-stone-200",children:["topology","configuration","yaml"].map(g=>u.jsx("button",{"data-testid":`${v}tab-${g}`,onClick:()=>d(g),className:`px-3 py-1.5 font-mono text-[10px] uppercase tracking-wider transition-colors ${l===g?"border-b-2 border-stone-900 text-stone-900 font-bold":"text-stone-500 hover:text-stone-700"}`,children:g},g))}),l==="topology"&&e&&u.jsx(BP,{graph:e.graph,testId:`${v}topology-preview`}),l==="configuration"&&e&&u.jsxs("div",{"data-testid":`${v}config-tables`,className:"space-y-4",children:[e.format==="pod_aware"&&f.map(g=>u.jsxs("div",{className:"border border-stone-200 p-3",children:[u.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:g.label??g.id}),u.jsxs("table",{className:"w-full font-mono text-[10px]",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"border-b border-stone-200 text-stone-500",children:[u.jsx("th",{className:"text-left py-1",children:"Member"}),u.jsx("th",{className:"text-left py-1",children:"Agent Ref"}),u.jsx("th",{className:"text-left py-1",children:"Runtime"}),u.jsx("th",{className:"text-left py-1",children:"Profile"})]})}),u.jsx("tbody",{children:g.members.map(y=>u.jsxs("tr",{className:"border-b border-stone-100",children:[u.jsx("td",{className:"py-1",children:u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{children:y.id}),i&&u.jsx(Ne,{variant:"outline",size:"sm","data-testid":`${v}member-open-agent-${g.id}-${y.id}`,className:"h-6 px-2 font-mono text-[9px] uppercase tracking-[0.12em]",onClick:()=>i(g.id,y),children:"Agent Spec"})]})}),u.jsx("td",{className:"py-1 text-stone-600",children:y.agentRef}),u.jsx("td",{className:"py-1",children:y.runtime}),u.jsx("td",{className:"py-1 text-stone-500",children:y.profile??"—"})]},y.id))})]})]},g.id)),e.format==="legacy"&&m.length>0&&u.jsxs("div",{className:"border border-stone-200 p-3",children:[u.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:"Nodes"}),u.jsxs("table",{className:"w-full font-mono text-[10px]",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"border-b border-stone-200 text-stone-500",children:[u.jsx("th",{className:"text-left py-1",children:"ID"}),u.jsx("th",{className:"text-left py-1",children:"Runtime"}),u.jsx("th",{className:"text-left py-1",children:"Role"})]})}),u.jsx("tbody",{children:m.map(g=>u.jsxs("tr",{className:"border-b border-stone-100",children:[u.jsx("td",{className:"py-1",children:g.id}),u.jsx("td",{className:"py-1",children:g.runtime}),u.jsx("td",{className:"py-1 text-stone-500",children:g.role??"—"})]},g.id))})]})]}),h.length>0&&u.jsxs("div",{className:"border border-stone-200 p-3",children:[u.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:e.format==="pod_aware"?"Cross-Pod Edges":"Edges"}),u.jsxs("table",{className:"w-full font-mono text-[10px]",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"border-b border-stone-200 text-stone-500",children:[u.jsx("th",{className:"text-left py-1",children:"From"}),u.jsx("th",{className:"text-left py-1",children:"To"}),u.jsx("th",{className:"text-left py-1",children:"Kind"})]})}),u.jsx("tbody",{children:h.map((g,y)=>u.jsxs("tr",{className:"border-b border-stone-100",children:[u.jsx("td",{className:"py-1",children:g.from}),u.jsx("td",{className:"py-1",children:g.to}),u.jsx("td",{className:"py-1 text-stone-500",children:g.kind})]},y))})]})]})]}),l==="yaml"&&u.jsx(kE,{title:"YAML Preview",testId:r??`${v}spec-yaml`,children:t})]})}function HP(){const e=Xt(),{selectedRigDraft:t,currentRigDraft:s}=Co(),r=t??s,{data:i,isLoading:l,error:d}=kP((r==null?void 0:r.yaml)??null),f=(i==null?void 0:i.pods)??[],m=(i==null?void 0:i.nodes)??[],h=(i==null?void 0:i.edges)??[];return r?u.jsx(rt,{children:u.jsxs("div",{"data-testid":"rig-spec-review",className:"space-y-6",children:[u.jsx(Yn,{eyebrow:"Rig Spec Review",title:(i==null?void 0:i.name)??r.label,description:(i==null?void 0:i.summary)??"Review the spec structure before import or bootstrap.",actions:u.jsxs(u.Fragment,{children:[u.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>e({to:"/import"}),children:"Open In Import"}),u.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>e({to:"/bootstrap"}),children:"Bootstrap"})]})}),i&&u.jsxs(_f,{children:[u.jsx(Ut,{label:"Format",value:i.format==="pod_aware"?"Pod-Aware":"Legacy",testId:"rig-spec-summary-format"}),u.jsx(Ut,{label:i.format==="pod_aware"?"Pods":"Nodes",value:i.format==="pod_aware"?f.length:m.length,testId:"rig-spec-summary-pods"}),u.jsx(Ut,{label:"Members",value:i.format==="pod_aware"?f.reduce((v,g)=>v+g.members.length,0):m.length,testId:"rig-spec-summary-members"}),u.jsx(Ut,{label:"Edges",value:h.length+(i.format==="pod_aware"?f.reduce((v,g)=>{var y;return v+(((y=g.edges)==null?void 0:y.length)??0)},0):0),testId:"rig-spec-summary-edges"})]}),l&&u.jsx("div",{className:"font-mono text-[10px] text-stone-400",children:"Loading review..."}),d&&u.jsx("div",{className:"p-3 bg-red-50 border border-red-200 font-mono text-[10px] text-red-700",children:d.message}),u.jsx(LE,{review:i,yaml:r.yaml,yamlTestId:"rig-spec-yaml"})]})}):u.jsx(rt,{children:u.jsxs("div",{"data-testid":"rig-spec-review-empty",className:"space-y-5",children:[u.jsx(Yn,{eyebrow:"Rig Spec Review",title:"No RigSpec Selected",description:"Choose a current or recent rig draft from the Specs drawer to review it here before you import or bootstrap it."}),u.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>e({to:"/import"}),children:"Open Import"})]})})}function v0({review:e,yaml:t,testIdPrefix:s="agent"}){const r=(e==null?void 0:e.profiles)??[],i=(e==null?void 0:e.resources)??{skills:[],guidance:[],hooks:[]},l=(e==null?void 0:e.startup)??{files:[],actions:[]};return u.jsxs(u.Fragment,{children:[r.length>0&&u.jsxs("div",{"data-testid":`${s}-profiles-section`,className:"border border-stone-200 p-3",children:[u.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:"Profiles"}),u.jsx("div",{className:"space-y-1",children:r.map(d=>u.jsxs("div",{className:"font-mono text-[10px] flex justify-between",children:[u.jsx("span",{className:"font-bold",children:d.name}),d.description&&u.jsx("span",{className:"text-stone-500",children:d.description})]},d.name))})]}),u.jsxs("div",{"data-testid":`${s}-resources-section`,className:"border border-stone-200 p-3",children:[u.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:"Resources"}),u.jsxs("div",{className:"space-y-2 font-mono text-[10px]",children:[i.skills.length>0&&u.jsxs("div",{children:[u.jsx("span",{className:"text-stone-500",children:"Skills:"})," ",i.skills.map((d,f)=>u.jsx("span",{className:"inline-block bg-stone-100 px-1.5 py-0.5 mr-1 mb-0.5",children:d},f))]}),i.guidance.length>0&&u.jsxs("div",{children:[u.jsx("span",{className:"text-stone-500",children:"Guidance:"})," ",i.guidance.map((d,f)=>u.jsx("span",{className:"inline-block bg-stone-100 px-1.5 py-0.5 mr-1 mb-0.5",children:d},f))]}),i.hooks.length>0&&u.jsxs("div",{children:[u.jsx("span",{className:"text-stone-500",children:"Hooks:"})," ",i.hooks.join(", ")]})]})]}),(l.files.length>0||l.actions.length>0)&&u.jsxs("div",{"data-testid":`${s}-startup-section`,className:"border border-stone-200 p-3",children:[u.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:"Startup"}),l.files.length>0&&u.jsxs("div",{className:"mb-2",children:[u.jsx("div",{className:"font-mono text-[9px] text-stone-500 uppercase mb-1",children:"Files"}),l.files.map((d,f)=>u.jsxs("div",{className:"font-mono text-[10px]",children:[d.path," ",d.required&&u.jsx("span",{className:"text-red-500 text-[8px]",children:"REQUIRED"})]},f))]}),l.actions.length>0&&u.jsxs("div",{children:[u.jsx("div",{className:"font-mono text-[9px] text-stone-500 uppercase mb-1",children:"Actions"}),l.actions.map((d,f)=>u.jsxs("div",{className:"font-mono text-[10px]",children:[u.jsxs("span",{className:"text-stone-500",children:[d.type,":"]})," ",d.value]},f))]})]}),u.jsx(kE,{title:"YAML Preview",testId:`${s}-spec-yaml`,children:t})]})}function UP(){const e=Xt(),{selectedAgentDraft:t,currentAgentDraft:s}=Co(),r=t??s,{data:i,isLoading:l,error:d}=OP((r==null?void 0:r.yaml)??null);return r?u.jsx(rt,{children:u.jsxs("div",{"data-testid":"agent-spec-review",className:"space-y-6",children:[u.jsx(Yn,{eyebrow:"Agent Spec Review",title:(i==null?void 0:i.name)??r.label,description:(i==null?void 0:i.description)??"Review the agent spec structure before validation.",actions:u.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>e({to:"/agents/validate"}),children:"Open In Validate"})}),i&&u.jsxs(_f,{children:[u.jsx(Ut,{label:"Format",value:"AgentSpec",testId:"agent-spec-summary-format"}),u.jsx(Ut,{label:"Version",value:i.version,testId:"agent-spec-summary-version"}),u.jsx(Ut,{label:"Profiles",value:(i.profiles??[]).length,testId:"agent-spec-summary-profiles"}),u.jsx(Ut,{label:"Skills",value:(i.resources??{skills:[]}).skills.length,testId:"agent-spec-summary-skills"})]}),l&&u.jsx("div",{className:"font-mono text-[10px] text-stone-400",children:"Loading review..."}),d&&u.jsx("div",{className:"p-3 bg-red-50 border border-red-200 font-mono text-[10px] text-red-700",children:d.message}),u.jsx(v0,{review:i,yaml:r.yaml,testIdPrefix:"agent"})]})}):u.jsx(rt,{children:u.jsxs("div",{"data-testid":"agent-spec-review-empty",className:"space-y-5",children:[u.jsx(Yn,{eyebrow:"Agent Spec Review",title:"No AgentSpec Selected",description:"Choose a current or recent agent draft from the Specs drawer to review it here before you validate it."}),u.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>e({to:"/agents/validate"}),children:"Open Validate"})]})})}function $P(){return Pt({mutationFn:async({bundlePath:e})=>{const t=await fetch("/api/bundles/inspect",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({bundlePath:e})}),s=await t.json();if(s.error)throw new Error(s.error);if(!t.ok)throw new Error(`HTTP ${t.status}`);return s}})}function qP(){return Pt({mutationFn:async({bundlePath:e,plan:t,autoApprove:s,targetRoot:r})=>{const i=await fetch("/api/bundles/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({bundlePath:e,plan:t,autoApprove:s,targetRoot:r})}),l=await i.json();if(!i.ok)throw new Error(l.error??`HTTP ${i.status}`);return l}})}function VP(){var l,d;const[e,t]=j.useState(""),s=$P(),r=()=>{e.trim()&&s.mutate({bundlePath:e.trim()})},i=s.data;return u.jsx(rt,{children:u.jsxs("div",{"data-testid":"bundle-inspector",children:[u.jsx("h2",{className:"text-headline-lg uppercase mb-spacing-4",children:"INSPECT BUNDLE"}),u.jsxs("div",{className:"mb-spacing-4",children:[u.jsx("label",{className:"text-label-md uppercase block mb-spacing-2",children:"BUNDLE PATH"}),u.jsx("input",{"data-testid":"bundle-path-input",type:"text",value:e,onChange:f=>t(f.target.value),placeholder:"/path/to/my-rig.rigbundle",className:"w-full bg-transparent border-b border-foreground/20 py-spacing-2 text-body-md font-mono focus:outline-none focus:border-primary"}),u.jsx(Ne,{variant:"tactical",onClick:r,disabled:!e.trim()||s.isPending,className:"mt-spacing-3","data-testid":"inspect-btn",children:s.isPending?"INSPECTING...":"INSPECT"})]}),s.isError&&u.jsx("div",{className:"text-destructive text-body-md mb-spacing-4","data-testid":"inspect-error",children:s.error.message}),i&&u.jsxs("div",{"data-testid":"inspect-result",children:[u.jsxs("div",{className:"card-dark p-spacing-4 mb-spacing-4","data-testid":"manifest-summary",children:[u.jsxs("div",{className:"flex items-center gap-spacing-2 mb-spacing-2",children:[u.jsx("h3",{className:"text-headline-md uppercase",children:i.manifest.name}),u.jsxs("span",{className:"text-label-sm font-mono px-spacing-2 py-px bg-foreground/10","data-testid":"schema-badge",children:["v",i.manifest.schemaVersion??1]})]}),u.jsxs("div",{className:"text-label-sm font-mono text-foreground-muted-on-dark",children:["v",i.manifest.version]}),u.jsxs("div",{className:"text-label-sm font-mono text-foreground-muted-on-dark",children:["Spec: ",i.manifest.rigSpec]}),u.jsxs("div",{className:"mt-spacing-2 flex gap-spacing-3",children:[u.jsxs("span",{className:Te("text-label-sm",i.digestValid?"text-success":"text-destructive"),children:["DIGEST: ",i.digestValid?"VALID":"INVALID"]}),u.jsxs("span",{className:Te("text-label-sm",i.integrityResult.passed?"text-success":"text-destructive"),"data-testid":"integrity-status",children:["INTEGRITY: ",i.integrityResult.passed?"PASS":"FAIL"]})]})]}),i.manifest.schemaVersion===2&&i.manifest.agents?u.jsxs(u.Fragment,{children:[u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"AGENTS"}),u.jsx("div",{className:"space-y-spacing-1 mb-spacing-4","data-testid":"agent-list",children:i.manifest.agents.map(f=>u.jsxs("div",{className:"text-label-sm font-mono","data-testid":"agent-entry",children:[f.name," v",f.version," — ",f.path]},f.name))})]}):u.jsxs(u.Fragment,{children:[u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"PACKAGES"}),u.jsx("div",{className:"space-y-spacing-1 mb-spacing-4","data-testid":"package-list",children:(i.manifest.packages??[]).map(f=>u.jsxs("div",{className:"text-label-sm font-mono","data-testid":"package-entry",children:[f.name," v",f.version," — ",f.path]},f.name))})]}),i.integrityResult&&u.jsxs(u.Fragment,{children:[u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"FILE INTEGRITY"}),u.jsxs("div",{className:"space-y-spacing-1 mb-spacing-4","data-testid":"file-integrity",children:[Object.keys((i.manifest.packages??i.manifest.agents??[]).length>0?((d=(l=i.manifest)==null?void 0:l.integrity)==null?void 0:d.files)??{}:{}).map(f=>{const m=i.integrityResult.mismatches.includes(f),h=i.integrityResult.missing.includes(f),v=m?"MISMATCH":h?"MISSING":"OK";return u.jsxs("div",{className:"flex items-center gap-spacing-3 text-label-sm font-mono","data-testid":"file-row",children:[u.jsx("span",{className:Te("w-2 h-2",v==="OK"?"bg-success":"bg-destructive"),"data-testid":"file-dot"}),u.jsx("span",{children:f}),u.jsx("span",{className:"text-foreground-muted ml-auto",children:v})]},f)}),i.integrityResult.extra.map(f=>u.jsxs("div",{className:"flex items-center gap-spacing-3 text-label-sm font-mono","data-testid":"file-row",children:[u.jsx("span",{className:"w-2 h-2 bg-warning","data-testid":"file-dot"}),u.jsx("span",{children:f}),u.jsx("span",{className:"text-foreground-muted ml-auto",children:"EXTRA"})]},f))]})]}),u.jsx(Ne,{variant:"tactical","data-testid":"install-btn",onClick:()=>window.location.href=`/bundles/install?bundlePath=${encodeURIComponent(e)}`,children:"INSTALL THIS BUNDLE"})]})]})})}function GP(){const e=Xt(),[t,s]=j.useState("enter"),r=typeof window<"u"?new URLSearchParams(window.location.search):null,[i,l]=j.useState((r==null?void 0:r.get("bundlePath"))??""),[d,f]=j.useState(""),[m,h]=j.useState(null),[v,g]=j.useState(null),y=qP(),b=async()=>{if(i.trim()){s("planning");try{const w=await y.mutateAsync({bundlePath:i.trim(),plan:!0});h(w),s("planned")}catch(w){g(w.message),s("error")}}},S=async()=>{if(d.trim()){s("applying");try{const w=await y.mutateAsync({bundlePath:i.trim(),autoApprove:!0,targetRoot:d.trim()});h(w),s("done")}catch(w){g(w.message),s("error")}}};return u.jsx(rt,{children:u.jsxs("div",{"data-testid":"bundle-install-flow",children:[u.jsx("h2",{className:"text-headline-lg uppercase mb-spacing-4",children:"INSTALL BUNDLE"}),t==="enter"&&u.jsxs("div",{"data-testid":"step-enter",children:[u.jsx("label",{className:"text-label-md uppercase block mb-spacing-2",children:"BUNDLE PATH"}),u.jsx("input",{"data-testid":"bundle-input",type:"text",value:i,onChange:w=>l(w.target.value),placeholder:"/path/to/my-rig.rigbundle",className:"w-full bg-transparent border-b border-foreground/20 py-spacing-2 text-body-md font-mono focus:outline-none focus:border-primary mb-spacing-4"}),u.jsx("label",{className:"text-label-md uppercase block mb-spacing-2",children:"TARGET ROOT"}),u.jsx("input",{"data-testid":"target-input",type:"text",value:d,onChange:w=>f(w.target.value),placeholder:"/path/to/target/project",className:"w-full bg-transparent border-b border-foreground/20 py-spacing-2 text-body-md font-mono focus:outline-none focus:border-primary mb-spacing-4"}),u.jsx(Ne,{variant:"tactical",onClick:b,disabled:!i.trim(),"data-testid":"plan-btn",children:"PLAN"})]}),t==="planning"&&u.jsx("div",{"data-testid":"step-planning",className:"text-foreground-muted",children:"Planning..."}),t==="planned"&&m&&u.jsxs("div",{"data-testid":"step-planned",children:[u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"PLAN"}),u.jsx("div",{className:"space-y-spacing-1 mb-spacing-4",children:m.stages.map(w=>u.jsxs("div",{className:"text-label-sm font-mono",children:[u.jsx("span",{className:w.status==="ok"?"text-success":"text-foreground-muted",children:w.status.toUpperCase()})," ",w.stage]},w.stage))}),u.jsx(Ne,{variant:"tactical",onClick:S,disabled:!d.trim(),"data-testid":"apply-btn",children:"APPLY"})]}),t==="applying"&&u.jsx("div",{"data-testid":"step-applying",className:"text-foreground-muted",children:"Installing..."}),t==="done"&&m&&u.jsxs("div",{"data-testid":"step-done",children:[u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"COMPLETE"}),u.jsxs("div",{className:"text-label-sm font-mono",children:["Status: ",u.jsx("span",{className:"text-success",children:m.status.toUpperCase()}),m.stages.some(w=>{var N;return((N=w.detail)==null?void 0:N.source)==="pod_bundle"})?u.jsx("span",{className:"ml-spacing-2 text-primary","data-testid":"bundle-type-label",children:"Pod-aware bundle"}):u.jsx("span",{className:"ml-spacing-2 text-foreground-muted","data-testid":"bundle-type-label",children:"Legacy bundle"})]}),m.rigId&&u.jsxs("div",{className:"text-label-sm font-mono","data-testid":"result-rig-id",children:["Rig: ",m.rigId]}),m.rigId&&u.jsx(Ne,{variant:"tactical",className:"mt-spacing-3",onClick:()=>e({to:"/rigs/$rigId",params:{rigId:m.rigId}}),children:"VIEW RIG"})]}),t==="error"&&u.jsxs("div",{"data-testid":"step-error",children:[u.jsx("p",{className:"text-destructive text-body-md mb-spacing-4",children:v}),u.jsx(Ne,{variant:"tactical",onClick:()=>{s("enter"),g(null),y.reset()},"data-testid":"try-again-btn",children:"TRY AGAIN"})]})]})})}function zE({sourcePath:e,sourceState:t}){return u.jsxs("div",{className:"font-mono text-[9px] text-stone-500","data-testid":"library-provenance",children:["Source: ",e," · ",t]})}function YP({review:e}){const t=Xt(),s=e.profiles??[],r=e.resources??{skills:[]};return u.jsx(rt,{children:u.jsxs("div",{"data-testid":"library-review-agent",className:"space-y-6",children:[u.jsx(Yn,{eyebrow:"Library — Agent Spec",title:e.name,description:e.description??"Agent spec from library.",actions:u.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>t({to:"/agents/validate"}),children:"Validate"})}),u.jsx(zE,{sourcePath:e.sourcePath,sourceState:e.sourceState}),u.jsxs(_f,{children:[u.jsx(Ut,{label:"Format",value:"AgentSpec",testId:"lib-agent-format"}),u.jsx(Ut,{label:"Version",value:e.version,testId:"lib-agent-version"}),u.jsx(Ut,{label:"Profiles",value:s.length,testId:"lib-agent-profiles"}),u.jsx(Ut,{label:"Skills",value:r.skills.length,testId:"lib-agent-skills"})]}),u.jsx(v0,{review:e,yaml:e.raw,testIdPrefix:"lib-agent"})]})})}function QP({review:e}){const t=Xt(),{data:s=[]}=Yd("agent"),r=new Map(s.map(m=>[m.name,m])),i=e.pods??[],l=e.nodes??[],d=e.edges??[],f=m=>{const h=m.match(/^local:agents\/([^/]+)$/);return h!=null&&h[1]?r.get(h[1])??null:null};return u.jsx(rt,{children:u.jsxs("div",{"data-testid":"library-review-rig",className:"space-y-6",children:[u.jsx(Yn,{eyebrow:"Library — Rig Spec",title:e.name,description:e.summary??"Rig spec from library.",actions:u.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>t({to:"/import"}),children:"Import"})}),u.jsx(zE,{sourcePath:e.sourcePath,sourceState:e.sourceState}),u.jsxs(_f,{children:[u.jsx(Ut,{label:"Format",value:e.format==="pod_aware"?"Pod-Aware":"Legacy",testId:"lib-rig-format"}),u.jsx(Ut,{label:e.format==="pod_aware"?"Pods":"Nodes",value:e.format==="pod_aware"?i.length:l.length,testId:"lib-rig-pods"}),u.jsx(Ut,{label:"Members",value:e.format==="pod_aware"?i.reduce((m,h)=>m+h.members.length,0):l.length,testId:"lib-rig-members"}),u.jsx(Ut,{label:"Edges",value:d.length+(e.format==="pod_aware"?i.reduce((m,h)=>{var v;return m+(((v=h.edges)==null?void 0:v.length)??0)},0):0),testId:"lib-rig-edges"})]}),u.jsx(LE,{review:e,yaml:e.raw,testIdPrefix:"lib",yamlTestId:"lib-rig-yaml",onMemberClick:(m,h)=>{const v=f(h.agentRef);v&&t({to:"/specs/library/$entryId",params:{entryId:v.id}})}})]})})}function KP({entryId:e}){const t=Xt(),{data:s,isLoading:r,error:i}=Yg(e);return r?u.jsx(rt,{children:u.jsx("div",{className:"font-mono text-[10px] text-stone-400",children:"Loading spec review..."})}):i||!s?u.jsx(rt,{children:u.jsxs("div",{"data-testid":"library-review-error",className:"space-y-4",children:[u.jsx(Yn,{eyebrow:"Library",title:"Spec Not Found",description:(i==null?void 0:i.message)??"Could not load spec."}),u.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>t({to:"/specs"}),children:"Back to Specs"})]})}):s.kind==="agent"?u.jsx(YP,{review:s}):u.jsx(QP,{review:s})}function FP(e){if(!e)return null;const t=e.match(/^local:agents\/([^/]+)$/);return(t==null?void 0:t[1])??null}function XP({agentRef:e}){const t=FP(e),{data:s=[],isLoading:r}=Yd("agent"),i=t?s.filter(m=>m.name===t):[],l=i.length===1?i[0].id:null,{data:d,isLoading:f}=Yg(l);return t?r||f?u.jsx("div",{className:"p-4 font-mono text-[10px] text-stone-400",children:"Loading agent spec..."}):i.length===0?u.jsx("div",{"data-testid":"agent-spec-unavailable",className:"p-4 font-mono text-[10px] text-stone-400",children:"No agent spec available"}):i.length>1?u.jsxs("div",{"data-testid":"agent-spec-ambiguous",className:"p-4 font-mono text-[10px] text-amber-600",children:["Agent spec ambiguous (",i.length,' matches for "',t,'")']}):!d||d.kind!=="agent"?u.jsx("div",{"data-testid":"agent-spec-unavailable",className:"p-4 font-mono text-[10px] text-stone-400",children:"No agent spec available"}):u.jsx(v0,{review:d,yaml:d.raw,testIdPrefix:"live-agent"}):u.jsx("div",{"data-testid":"agent-spec-unavailable",className:"p-4 font-mono text-[10px] text-stone-400",children:"No agent spec available"})}function ZP({rigId:e,logicalId:t}){const{data:s,isLoading:r,error:i}=DN(e,t),[l,d]=j.useState("identity"),f=s?s.nodeKind!=="infrastructure":!0,m=f?["identity","agent-spec","startup","transcript"]:["identity","startup","transcript"];return u.jsx(rt,{children:u.jsxs("div",{"data-testid":"live-node-details",className:"space-y-6",children:[u.jsx(Yn,{eyebrow:"Live Node Details",title:(s==null?void 0:s.canonicalSessionName)??t,description:`${(s==null?void 0:s.rigName)??e} / ${(s==null?void 0:s.podNamespace)??cs(t)??us((s==null?void 0:s.podId)??null)} / ${t}`}),r&&u.jsx("div",{className:"font-mono text-[10px] text-stone-400",children:"Loading..."}),i&&u.jsx("div",{className:"p-3 bg-red-50 border border-red-200 font-mono text-[10px] text-red-700",children:i.message}),u.jsx("div",{className:"flex gap-1 border-b border-stone-200",children:m.map(h=>u.jsx("button",{"data-testid":`live-tab-${h}`,onClick:()=>d(h),className:`px-3 py-1.5 font-mono text-[10px] uppercase tracking-wider transition-colors ${l===h?"border-b-2 border-stone-900 text-stone-900 font-bold":"text-stone-500 hover:text-stone-700"}`,children:h.replace("-"," ")},h))}),s&&l==="identity"&&u.jsx(LN,{peers:s.peers,edges:s.edges,transcript:s.transcript,compactSpec:s.compactSpec,contextUsage:s.contextUsage}),s&&l==="agent-spec"&&f&&u.jsx(XP,{agentRef:s.agentRef}),s&&l==="startup"&&u.jsx("div",{"data-testid":"live-startup-section",className:"space-y-4",children:s.startupFiles.length>0&&u.jsxs("div",{className:"border border-stone-200 p-3",children:[u.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:"Startup Files"}),s.startupFiles.map((h,v)=>u.jsxs("div",{className:"font-mono text-[10px]",children:[h.path," ",u.jsxs("span",{className:"text-stone-400",children:["(",h.deliveryHint,")"]}),h.required&&u.jsx("span",{className:"text-red-500 text-[8px] ml-1",children:"REQUIRED"})]},v))]})}),s&&l==="transcript"&&u.jsx("div",{"data-testid":"live-transcript-section",className:"space-y-4",children:s.transcript.enabled?u.jsxs("div",{className:"border border-stone-200 p-3",children:[u.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:"Transcript"}),u.jsx("div",{className:"font-mono text-[10px] text-stone-700",children:s.transcript.path}),s.transcript.tailCommand&&u.jsx("code",{className:"block mt-1 font-mono text-[9px] text-stone-500 bg-stone-100 px-2 py-1",children:s.transcript.tailCommand})]}):u.jsx("div",{className:"font-mono text-[10px] text-stone-400 p-4",children:"Transcript capture not enabled"})})]})})}function WP(e){switch(e){case"claude-code":return"text-primary";case"codex":return"text-accent";case"terminal":return"text-foreground";default:return"text-foreground-muted"}}function JP(e){switch(e){case"claude-code":return"Claude Code";case"codex":return"Codex";case"terminal":return"Terminal";default:return"Unknown"}}function eI(e){return`'${e.replace(/'/g,"'\\''")}'`}function tI(e){const t=e.tmuxWindow?`${e.tmuxSession}:${e.tmuxWindow}`:e.tmuxSession;return`tmux attach -t ${eI(t)}`}function DS({label:e,activeLabel:t,onClick:s,testId:r}){const[i,l]=j.useState(!1),d=j.useRef(null);j.useEffect(()=>()=>{d.current&&clearTimeout(d.current)},[]);const f=async()=>{await s()&&(l(!0),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{l(!1),d.current=null},900))};return u.jsx("button",{type:"button","data-testid":r,onClick:()=>{f()},className:Te("px-spacing-2 py-1 border font-mono text-[10px] uppercase transition-colors duration-150 ease-tactical",i?"bg-stone-900 text-white border-stone-900":"bg-white text-stone-900 border-stone-300 hover:bg-stone-100"),children:i?t:e})}function nI({session:e,onAdopt:t}){return u.jsx("div",{"data-testid":"discovered-node",className:Te("border-dashed border border-foreground/20 bg-[rgba(255,255,255,0.72)] px-spacing-4 py-spacing-3 mb-spacing-2 shadow-[0_10px_28px_rgba(20,20,20,0.04)] backdrop-blur-sm"),children:u.jsxs("div",{className:"flex flex-col gap-spacing-3 lg:flex-row lg:items-center lg:justify-between",children:[u.jsxs("div",{className:"min-w-0 flex-1",children:[u.jsxs("div",{className:"flex flex-wrap items-center gap-x-spacing-3 gap-y-spacing-1",children:[u.jsx("div",{"data-testid":"runtime-badge",className:Te("text-[10px] uppercase tracking-[0.08em]",WP(e.runtimeHint)),children:JP(e.runtimeHint)}),u.jsx("div",{"data-testid":"session-name",className:"font-mono text-[13px] leading-5 text-foreground",title:e.tmuxSession,children:e.tmuxSession}),e.confidence==="medium"?u.jsx("div",{"data-testid":"runtime-inferred-note",className:"text-[10px] uppercase tracking-[0.08em] text-foreground-muted",children:"runtime inferred"}):null]}),e.cwd?u.jsxs("div",{className:"mt-spacing-2 min-w-0",children:[u.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-foreground-muted",children:"cwd"}),u.jsx("div",{className:"font-mono text-[12px] leading-5 text-foreground-muted truncate",title:e.cwd,children:e.cwd})]}):null]}),u.jsxs("div",{className:"flex flex-wrap items-center gap-spacing-2 lg:justify-end",children:[u.jsx(DS,{label:"copy tmux",activeLabel:"copied",testId:"copy-tmux-btn",onClick:async()=>await ds(tI(e))}),e.cwd?u.jsx(DS,{label:"copy cwd",activeLabel:"copied",testId:"copy-cwd-btn",onClick:async()=>await ds(e.cwd??"")}):null,u.jsx(Ne,{variant:"tactical",size:"sm","data-testid":"adopt-btn",onClick:()=>t(e.id),children:"ADOPT"})]})]})})}function sI(){const[e,t]=j.useState(null),[s,r]=j.useState(!1),i=j.useCallback(async()=>{r(!0);try{const l=await fetch("/api/discovery/draft-rig",{method:"POST"});if(!l.ok){t(`# Error: draft generation failed (HTTP ${l.status})`);return}const d=await l.text();t(d)}catch{t("# Error: failed to reach daemon")}finally{r(!1)}},[]);return u.jsxs("div",{className:"mt-spacing-4 border-t border-foreground/10 pt-spacing-4","data-testid":"generate-draft-section",children:[u.jsx(Ne,{variant:"tactical",onClick:i,disabled:s,"data-testid":"generate-draft-btn",className:"mb-spacing-3",children:s?"GENERATING...":"GENERATE RIG SPEC"}),e&&(()=>{const l=e.split(`
|
|
222
|
+
`),N=H=>{s.current&&clearTimeout(s.current),d(H),s.current=setTimeout(()=>{d(D=>D===H?null:D),s.current=null},900)},C=async H=>{var Y;H.stopPropagation();const D=e.canonicalSessionName??((Y=e.binding)==null?void 0:Y.tmuxSession);D&&(await ds(`tmux attach -t ${D}`),N("attach"))},T=async H=>{var D;if(H.stopPropagation(),!(!((D=e.binding)!=null&&D.cmuxSurface)||!e.rigId))try{(await fetch(`/api/rigs/${encodeURIComponent(e.rigId)}/nodes/${encodeURIComponent(e.logicalId)}/focus`,{method:"POST"})).ok&&N("cmux")}catch{}},_=async H=>{H.stopPropagation(),e.resumeToken&&(e.runtime==="claude-code"?(await ds(`claude --resume ${e.resumeToken}`),N("resume")):e.runtime==="codex"&&(await ds(`codex resume ${e.resumeToken}`),N("resume")))},R=H=>`px-1.5 py-0.5 border font-mono text-[7px] uppercase transition-colors ${l===H?"bg-stone-900 text-white border-stone-900":"bg-white text-stone-900 border-stone-300 hover:bg-stone-100"}`;return u.jsxs("div",{className:`group bg-white border min-w-[200px] hard-shadow relative ${e.placementState==="selected"?"border-emerald-600 ring-2 ring-emerald-400/70 shadow-[0_0_0_3px_rgba(52,211,153,0.12)]":e.placementState==="available"?"border-emerald-500 ring-1 ring-emerald-300/70":"border-stone-900"}`,"data-testid":"rig-node",title:w||void 0,children:[u.jsx(Wa,{type:"target",position:we.Top}),u.jsxs("div",{className:`px-3 py-1 font-mono text-[10px] flex justify-between items-center ${m?"bg-stone-500 text-white border-b border-stone-900":f?"bg-stone-900 text-white":"bg-stone-200 text-stone-900 border-b border-stone-900"}`,children:[u.jsx("span",{className:"font-bold truncate",children:v}),u.jsx("span",{className:`inline-flex h-2.5 w-2.5 rounded-full border border-white/50 ${y} ${r?"status-changed":""}`,"data-testid":`status-dot-${e.logicalId}`,"aria-label":g,title:g})]}),u.jsxs("div",{className:"p-3 space-y-2",children:[h&&u.jsxs("div",{className:"font-mono text-[8px] text-stone-500",children:["RUNTIME: ",h]}),e.resolvedSpecName&&u.jsxs("div",{className:"font-mono text-[8px] text-stone-400","data-testid":"spec-hint",children:[e.resolvedSpecName,e.profile?` · ${e.profile}`:""]}),e.contextAvailability==="known"&&e.contextFresh&&typeof e.contextUsedPercentage=="number"?u.jsxs("div",{className:"font-mono text-[8px] text-stone-500","data-testid":"context-badge",children:["CTX ",e.contextUsedPercentage,"%"]}):u.jsx("div",{className:"font-mono text-[8px] text-stone-300","data-testid":"context-badge-unknown",children:"CTX unknown"}),e.restoreOutcome&&e.restoreOutcome!=="n-a"&&u.jsxs("div",{className:"font-mono text-[8px] text-stone-500",children:["RESTORE: ",e.restoreOutcome]}),e.packageRefs&&e.packageRefs.length>0&&u.jsxs("div",{"data-testid":"package-badge",title:e.packageRefs.join(", "),className:"font-mono text-[8px] text-stone-400",onClick:H=>H.stopPropagation(),onKeyDown:H=>H.stopPropagation(),children:["PKG ",e.packageRefs.length]}),e.startupStatus==="failed"&&u.jsxs("div",{className:"stamp-badge",children:[u.jsx("div",{className:"w-2 h-2 rounded-full bg-red-500"}),u.jsx("span",{className:"text-red-600",children:"FAILED"})]}),(e.canonicalSessionName??((O=e.binding)==null?void 0:O.tmuxSession)??e.resumeToken??((B=e.binding)==null?void 0:B.cmuxSurface))&&u.jsxs("div",{"data-testid":"node-toolbar",className:"flex flex-wrap gap-1 pt-1",onClick:H=>H.stopPropagation(),onKeyDown:H=>H.stopPropagation(),children:[(e.canonicalSessionName??((L=e.binding)==null?void 0:L.tmuxSession))&&u.jsx("button",{onClick:C,"data-testid":"toolbar-copy-attach",className:R("attach"),title:`tmux attach -t ${e.canonicalSessionName??((M=e.binding)==null?void 0:M.tmuxSession)??"?"}`,children:l==="attach"?"copied":"tmux"}),((I=e.binding)==null?void 0:I.cmuxSurface)&&u.jsx("button",{onClick:T,"data-testid":"toolbar-cmux-focus",className:R("cmux"),children:l==="cmux"?"opened":"cmux"}),e.resumeToken&&e.runtime&&e.runtime!=="terminal"&&u.jsx("button",{onClick:_,"data-testid":"toolbar-copy-resume",className:R("resume"),children:l==="resume"?"copied":"resume"})]}),b&&u.jsx("div",{className:"pt-1",children:u.jsx("span",{"data-testid":`placement-chip-${e.logicalId}`,className:`inline-flex items-center border px-1.5 py-0.5 font-mono text-[7px] uppercase tracking-[0.12em] ${e.placementState==="selected"?"border-emerald-700 bg-emerald-700 text-white":"border-emerald-300 bg-emerald-50 text-emerald-800"}`,children:b})})]}),S.length>0&&u.jsx("div",{"data-testid":"node-hover-hint",className:"pointer-events-none absolute left-2 top-full z-20 mt-2 hidden min-w-[180px] border border-stone-900 bg-white px-2 py-1 font-mono text-[8px] text-stone-700 shadow-[4px_4px_0_rgba(28,25,23,0.14)] group-hover:block",children:S.map(H=>u.jsx("div",{children:H},H))}),u.jsx(Wa,{type:"source",position:we.Bottom})]})}const H6=Zw("relative w-full p-4 bg-surface-low border-l-2 border-l-stone-900 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-on-surface",{variants:{variant:{default:"bg-background text-foreground",destructive:"text-destructive [&>svg]:text-destructive"}},defaultVariants:{variant:"default"}}),Qt=j.forwardRef(({className:e,variant:t,...s},r)=>u.jsx("div",{ref:r,role:"alert",className:Te(H6({variant:t}),e),...s}));Qt.displayName="Alert";const U6=j.forwardRef(({className:e,...t},s)=>u.jsx("h5",{ref:s,className:Te("mb-1 font-medium leading-none tracking-tight",e),...t}));U6.displayName="AlertTitle";const Kt=j.forwardRef(({className:e,...t},s)=>u.jsx("div",{ref:s,className:Te("text-sm [&_p]:leading-relaxed",e),...t}));Kt.displayName="AlertDescription";function $6({data:e}){const t=e.podDisplayName??e.podNamespace??cs(e.logicalId)??us(e.podId??e.logicalId);return u.jsx("div",{"data-testid":"pod-group-node",className:`w-full h-full relative pointer-events-auto ${e.placementState==="selected"?"ring-2 ring-emerald-500/80 shadow-[0_0_0_4px_rgba(52,211,153,0.12)]":e.placementState==="available"?"ring-1 ring-emerald-300/80":""}`,children:u.jsx("div",{className:"absolute left-4 top-3 inline-flex items-center font-mono text-[12px] font-bold leading-none tracking-[0.08em] text-stone-800",children:`${t} pod`})})}function q6({data:e}){const t=e.session;return u.jsxs("div",{"data-testid":"discovered-graph-node",className:"border-dashed border-2 border-foreground/30 bg-surface-low/50 p-spacing-3 min-w-[180px]",children:[u.jsx(Wa,{type:"target",position:we.Top,className:"opacity-0"}),u.jsxs("div",{className:"text-label-sm font-mono uppercase mb-spacing-1",children:[t.tmuxSession,":",t.tmuxPane]}),u.jsxs("div",{className:"flex gap-spacing-2 items-center mb-spacing-1",children:[u.jsx("span",{className:"text-label-sm uppercase text-foreground-muted",children:t.runtimeHint}),u.jsx("span",{className:"text-label-sm text-foreground-muted",children:t.confidence})]}),t.cwd&&u.jsx("div",{className:"text-label-sm font-mono text-foreground-muted truncate",children:t.cwd}),u.jsx(Wa,{type:"source",position:we.Bottom,className:"opacity-0"})]})}const V6={rigNode:B6,discoveredNode:q6,podGroup:$6};function G6(){return u.jsxs("div",{className:"flex flex-col items-center justify-center h-full relative text-foreground-muted","data-testid":"empty-topology",children:[u.jsxs("svg",{className:"absolute inset-0 w-full h-full",viewBox:"0 0 400 300",fill:"none",style:{opacity:.08},children:[u.jsx("rect",{x:"160",y:"60",width:"80",height:"40",stroke:"currentColor",strokeWidth:"1"}),u.jsx("rect",{x:"60",y:"180",width:"80",height:"40",stroke:"currentColor",strokeWidth:"1"}),u.jsx("rect",{x:"260",y:"180",width:"80",height:"40",stroke:"currentColor",strokeWidth:"1"}),u.jsx("line",{x1:"200",y1:"100",x2:"100",y2:"180",stroke:"currentColor",strokeWidth:"1",strokeDasharray:"4 4"}),u.jsx("line",{x1:"200",y1:"100",x2:"300",y2:"180",stroke:"currentColor",strokeWidth:"1",strokeDasharray:"4 4"})]}),u.jsx("div",{className:"relative z-10 text-center",children:u.jsx("h2",{className:"text-headline-md uppercase",children:"EMPTY TOPOLOGY"})})]})}function Y6({rigId:e,rigName:t=null,showDiscovered:s=!0}){const{data:r,isPending:i,error:l}=w6(e??""),d=Z3(s),f=(r==null?void 0:r.nodes)??[],m=(r==null?void 0:r.edges)??[],h=(l==null?void 0:l.message)??null,{reconnecting:v}=j6(e),[g,y]=j.useState(null),b=j.useRef(null),S=j.useRef(null),w=e!==null&&S.current!==e;j.useEffect(()=>{e&&f.length>0&&S.current!==e&&(S.current=e)},[e,f.length]);const N=j.useCallback(K=>{b.current&&clearTimeout(b.current),y(K),b.current=setTimeout(()=>{y(null),b.current=null},3e3)},[]);j.useEffect(()=>()=>{b.current&&clearTimeout(b.current)},[]);const C=j.useMemo(()=>m.map(K=>{var A;const U=((A=K.data)==null?void 0:A.kind)??K.label??"delegates_to",q=E6(U);return{...K,...q,className:w?"edge-draw-in":void 0,style:{...q.style,animationDelay:w?`${Math.min(f.length*50+100,2e3)}ms`:void 0}}}),[m,w,f.length]),T=j.useMemo(()=>{const K=new Map;for(const U of f){const q=U.data;if((U.type==="podGroup"||U.type==="group")&&(q!=null&&q.podId)){K.set(q.podId,{displayName:q.podLabel??q.podNamespace??cs(q.logicalId)??us(q.podId),namespace:q.podNamespace??q.logicalId??null});continue}const A=(q==null?void 0:q.podId)??null;if(!A)continue;const $=(q==null?void 0:q.podNamespace)??cs(q==null?void 0:q.logicalId)??null,z=(q==null?void 0:q.podLabel)??$??us(A);K.has(A)||K.set(A,{displayName:z,namespace:$})}return K},[f]),{selection:_,setSelection:R}=tr(),{selectedDiscoveredId:O,placementTarget:B,setPlacementTarget:L}=y4(),M=(_==null?void 0:_.type)==="discovery"&&!!O,I=j.useMemo(()=>{const K=new Map;for(const z of f){if(!z.parentId)continue;const G=typeof z.data=="object"&&z.data!==null&&"logicalId"in z.data?z.data.logicalId:null,V=typeof z.data=="object"&&z.data!==null&&"podId"in z.data?z.data.podId:null,P=cs(G)??us(V);P&&!K.has(z.parentId)&&K.set(z.parentId,P)}const q=A6(f,m).map((z,G)=>({...z,data:(()=>{if(z.type==="podGroup"||z.type==="group"){const V=z.data,P=(V==null?void 0:V.podId)??null,Q=(B==null?void 0:B.kind)==="pod"&&P!==null&&B.podId===P;return{...z.data??{},podDisplayName:K.get(z.id)??null,placementState:M?Q?"selected":"available":null}}if(z.type==="rigNode"){const V=z.data,P=!(V!=null&&V.binding)&&!(V!=null&&V.canonicalSessionName),Q=(B==null?void 0:B.kind)==="node"&&(V==null?void 0:V.logicalId)!==void 0&&B.logicalId===V.logicalId;return{...z.data??{},placementState:M?Q?"selected":P?"available":null:null}}return z.data})(),className:w?"node-enter":void 0,style:{...z.style??{},animationDelay:w?`${Math.min(G*50,2e3)}ms`:void 0}})),A=q.reduce((z,G)=>{var V;return Math.max(z,((V=G.position)==null?void 0:V.y)??0)},0),$=d.map((z,G)=>({id:`discovered-${z.id}`,type:"discoveredNode",position:{x:300,y:A+200+G*150},data:{session:z}}));return[...q,...$]},[f,m,w,d,M,B]),{setSelectedNode:H}=v4(),D=t!=null&&t.trim()?t:e?Gs(e):null,Y=j.useCallback(async(K,U)=>{var A;if(!e)return;if(M){if(U.type==="podGroup"||U.type==="group"){const $=U.data,z=($==null?void 0:$.podId)??null,G=z?T.get(z):null,V=!!(z&&(G!=null&&G.namespace));L({kind:"pod",rigId:e,podId:z??"",podNamespace:(G==null?void 0:G.namespace)??null,podLabel:(G==null?void 0:G.displayName)??null,eligible:V,...V?{}:{reason:"This pod cannot receive a new node yet."}});return}if(U.type==="rigNode"){const $=U.data,z=!$.binding&&!$.canonicalSessionName;L({kind:"node",rigId:e,logicalId:$.logicalId,eligible:z,...z?{}:{reason:"This node is already claimed."}});return}}if(U.type==="podGroup"||U.type==="group"){R({type:"rig",rigId:e});return}const q=U.data;if(H({rigId:e,logicalId:q.logicalId}),!((A=q.binding)!=null&&A.cmuxSurface)){N({text:"Not bound to cmux surface",type:"info"});return}try{const $=await fetch(`/api/rigs/${encodeURIComponent(e)}/nodes/${encodeURIComponent(q.logicalId)}/focus`,{method:"POST"});if(!$.ok){N({text:"Focus failed",type:"error"});return}const z=await $.json();z.ok===!1&&z.code==="unavailable"?N({text:"cmux not connected",type:"error"}):z.ok?N({text:"Focused",type:"success"}):N({text:"Focus failed",type:"error"})}catch{N({text:"Focus failed",type:"error"})}},[M,T,e,L,H,R,N]);return e===null?u.jsx("div",{className:"p-spacing-6 text-foreground-muted",children:"No rig selected"}):i?u.jsxs("div",{className:"p-spacing-6","data-testid":"graph-loading",children:[u.jsx("div",{className:"h-8 w-48 animate-pulse-tactical mb-spacing-4"}),u.jsx("div",{className:"h-64 animate-pulse-tactical"})]}):h?u.jsx("div",{className:"p-spacing-6",children:u.jsx(Qt,{"data-testid":"graph-error",children:u.jsxs(Kt,{children:["Error: ",h]})})}):I.length===0?u.jsx(G6,{}):u.jsxs("div",{className:"w-full h-full relative","data-testid":"graph-view","data-animated":w?"true":"false",children:[u.jsx("div",{className:"absolute top-4 left-4 w-3 h-3 reg-mark",children:u.jsx("div",{className:"reg-tl"})}),u.jsx("div",{className:"absolute top-4 right-4 w-3 h-3",children:u.jsx("div",{className:"reg-tr"})}),u.jsx("div",{className:"absolute bottom-4 left-4 w-3 h-3",children:u.jsx("div",{className:"reg-bl"})}),u.jsx("div",{className:"absolute bottom-4 right-4 w-3 h-3",children:u.jsx("div",{className:"reg-br"})}),D&&u.jsx("div",{"data-testid":"rig-stamp-watermark",className:"stamp-watermark text-3xl left-[20%] top-[35%]",children:D}),v&&u.jsx("div",{className:"absolute top-spacing-4 right-spacing-4 z-20",children:u.jsx(Qt,{children:u.jsx(Kt,{className:"text-warning",children:"Live updates disconnected from daemon — reconnecting..."})})}),g&&u.jsx("div",{className:`absolute top-spacing-4 left-spacing-4 z-20 px-spacing-4 py-spacing-2 font-mono text-[10px] border ${g.type==="success"?"bg-white border-stone-900 text-stone-900":g.type==="error"?"bg-tertiary/10 border-tertiary text-tertiary":"bg-white border-stone-300 text-stone-600"}`,children:g.text}),M&&u.jsx("div",{"data-testid":"graph-placement-banner",className:"absolute top-spacing-4 left-1/2 z-20 -translate-x-1/2 border border-emerald-300/90 bg-[rgba(236,253,245,0.92)] px-3.5 py-2 font-mono text-[10px] text-emerald-950 shadow-[0_12px_28px_rgba(34,197,94,0.14)] backdrop-blur-sm",children:"PLACEMENT MODE · click an available node to bind, or click a pod to add a new node."}),u.jsx(wE,{nodes:I,edges:C,nodeTypes:V6,onNodeClick:Y,nodesDraggable:!1,selectionOnDrag:!1,panOnDrag:!0,fitView:!0,fitViewOptions:{padding:.16,maxZoom:1.15},className:"relative z-10",proOptions:{hideAttribution:!0},minZoom:.3,maxZoom:1.5,children:u.jsx(EE,{})})]})}function h0(){const{openExplorer:e}=x4(),{setSelection:t}=tr();return u.jsx("div",{"data-testid":"workspace-home",className:"flex h-full min-h-[420px] flex-col items-center justify-center bg-[radial-gradient(circle_at_top,rgba(245,244,240,0.85),rgba(244,242,236,0.55)_32%,rgba(243,241,236,0.22)_58%,transparent_72%)] px-8 text-center",children:u.jsxs("div",{className:"max-w-xl space-y-3",children:[u.jsx("p",{className:"font-mono text-[10px] uppercase tracking-[0.18em] text-stone-500",children:"Explorer-Driven Workspace"}),u.jsx("h1",{className:"font-headline text-2xl font-bold uppercase tracking-tight text-stone-900",children:"Select a rig from the explorer to inspect its topology."}),u.jsxs("p",{className:"text-sm text-stone-600",children:["Use ",u.jsx("span",{className:"font-mono text-stone-800",children:"Specs"})," to import a rig spec or run bootstrap, and use the ",u.jsx("span",{className:"font-mono text-stone-800",children:"Discovery"})," drawer to place running sessions."]}),u.jsxs("div",{className:"flex items-center justify-center gap-3 pt-2",children:[u.jsx("button",{type:"button","data-testid":"workspace-open-explorer",onClick:e,className:"border border-stone-300 px-4 py-2 font-mono text-[10px] uppercase tracking-[0.14em] text-stone-700 transition-colors hover:bg-stone-100",children:"Explore"}),u.jsx("button",{type:"button","data-testid":"workspace-open-specs",onClick:()=>t({type:"specs"}),className:"border border-stone-300 px-4 py-2 font-mono text-[10px] uppercase tracking-[0.14em] text-stone-700 transition-colors hover:bg-stone-100",children:"Open Specs"}),u.jsx("button",{type:"button","data-testid":"workspace-open-discovery",onClick:()=>t({type:"discovery"}),className:"border border-stone-300 px-4 py-2 font-mono text-[10px] uppercase tracking-[0.14em] text-stone-700 transition-colors hover:bg-stone-100",children:"Open Discovery"})]})]})})}function Q6(e){switch(e){case"launched":return"text-success";case"failed":return"text-destructive";default:return"text-foreground-muted"}}const m0=j.forwardRef(({className:e,type:t,...s},r)=>u.jsx("input",{type:t,className:Te("flex h-11 w-full border border-stone-300/55 bg-white/85 px-4 py-2 text-base text-foreground placeholder:text-foreground-muted/60 transition-colors duration-150 focus-visible:outline-none focus-visible:border-stone-900/35 focus-visible:ring-2 focus-visible:ring-stone-900/10 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...s}));m0.displayName="Input";const p0=j.forwardRef(({className:e,...t},s)=>u.jsx("textarea",{className:Te("flex min-h-[80px] w-full border border-stone-300/55 bg-white/85 px-4 py-3 text-base text-on-surface font-mono placeholder:text-stone-400 transition-all duration-150 focus-visible:outline-none focus-visible:border-stone-900/35 focus-visible:ring-2 focus-visible:ring-stone-900/10 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:s,...t}));p0.displayName="Textarea";function rt({children:e,className:t,innerClassName:s}){return u.jsx("div",{"data-testid":"workspace-page",className:Te("w-full flex-1 overflow-y-auto lg:pl-[var(--workspace-left-offset,0px)] lg:pr-[var(--workspace-right-offset,0px)]",t),children:u.jsx("div",{"data-testid":"workspace-page-inner",className:Te("mx-auto w-full max-w-[960px] px-4 py-6 sm:px-6 sm:py-8 md:px-8 lg:px-10",s),children:e})})}const g0=j.forwardRef(({className:e,...t},s)=>u.jsx("div",{className:"relative w-full overflow-auto",children:u.jsx("table",{ref:s,className:Te("w-full caption-bottom text-sm",e),...t})}));g0.displayName="Table";const x0=j.forwardRef(({className:e,...t},s)=>u.jsx("thead",{ref:s,className:Te("bg-surface-low [&_tr]:border-b [&_tr]:border-stone-300",e),...t}));x0.displayName="TableHeader";const y0=j.forwardRef(({className:e,...t},s)=>u.jsx("tbody",{ref:s,className:Te("[&_tr:last-child]:border-0",e),...t}));y0.displayName="TableBody";const K6=j.forwardRef(({className:e,...t},s)=>u.jsx("tfoot",{ref:s,className:Te("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",e),...t}));K6.displayName="TableFooter";const cc=j.forwardRef(({className:e,...t},s)=>u.jsx("tr",{ref:s,className:Te("border-b border-stone-200 transition-colors duration-150 hover:bg-surface-low data-[state=selected]:bg-surface-mid odd:bg-surface-low/50",e),...t}));cc.displayName="TableRow";const Or=j.forwardRef(({className:e,...t},s)=>u.jsx("th",{ref:s,className:Te("h-12 px-4 text-left align-middle font-medium text-foreground-muted uppercase text-label-md tracking-[0.04em] [&:has([role=checkbox])]:pr-0",e),...t}));Or.displayName="TableHead";const Dr=j.forwardRef(({className:e,...t},s)=>u.jsx("td",{ref:s,className:Te("p-4 align-middle [&:has([role=checkbox])]:pr-0",e),...t}));Dr.displayName="TableCell";const F6=j.forwardRef(({className:e,...t},s)=>u.jsx("caption",{ref:s,className:Te("mt-4 text-sm text-foreground-muted",e),...t}));F6.displayName="TableCaption";function Yn({eyebrow:e,title:t,description:s,actions:r}){return u.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-end lg:justify-between",children:[u.jsxs("div",{className:"space-y-3",children:[u.jsx("p",{className:"font-mono text-[10px] uppercase tracking-[0.18em] text-stone-500",children:e}),u.jsx("h2",{className:"text-2xl font-bold uppercase tracking-[0.04em] text-stone-900 sm:text-3xl",children:t}),s&&u.jsx("p",{className:"max-w-2xl text-base leading-8 text-stone-600",children:s})]}),r?u.jsx("div",{className:"flex flex-wrap gap-2",children:r}):null]})}function ME({steps:e,currentStep:t,errorAtStep:s=0,"data-testid":r}){const i=s||t;return u.jsx("div",{className:"flex flex-wrap items-center gap-2 sm:gap-3","data-testid":r,children:e.map((l,d)=>{const f=i>l.num,m=i===l.num,h=i<l.num,v=f?"done":m?"active":"upcoming";return u.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[u.jsxs("div",{"data-testid":`step-${l.num}`,"data-step-state":v,className:Te("inline-flex min-h-0 items-center gap-2 border-b-2 px-1 py-1 font-mono text-[10px] uppercase tracking-[0.16em] transition-colors",f&&"border-primary/35 text-foreground-muted",m&&"border-stone-900 text-foreground",h&&"border-transparent text-foreground-muted/35"),children:[u.jsxs("span",{className:"text-[9px] tracking-[0.22em]",children:[f?"✓ ":"",String(l.num).padStart(2,"0")]}),u.jsx("span",{className:"text-[10px] leading-none tracking-[0.2em]",children:l.label})]}),d<e.length-1?u.jsx("div",{"aria-hidden":"true",className:Te("h-px w-4 shrink-0 sm:w-6",f?"bg-primary/35":"bg-stone-300/45")}):null]},l.num)})})}function Ln({title:e,description:t,children:s,className:r}){return u.jsxs("section",{className:Te("space-y-4 border border-stone-300/45 bg-[rgba(255,255,255,0.62)] p-5 shadow-[0_1px_0_rgba(255,255,255,0.95)_inset,0_10px_26px_rgba(34,34,24,0.035)] sm:p-6",r),children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx("div",{className:"font-mono text-[10px] uppercase tracking-[0.18em] text-stone-500",children:e}),t?u.jsx("p",{className:"text-base leading-8 text-stone-600",children:t}):null]}),s]})}function _f({children:e}){return u.jsx("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:e})}function Ut({label:e,value:t,testId:s}){return u.jsxs("div",{className:"border border-stone-300/35 bg-white/10 px-4 py-4",children:[u.jsx("div",{className:"font-mono text-[8px] uppercase tracking-[0.16em] text-stone-500",children:e}),u.jsx("div",{"data-testid":s,className:"mt-2 text-2xl font-semibold uppercase tracking-[0.04em] text-stone-900",children:t})]})}function kE({title:e,testId:t,children:s}){return u.jsx(Ln,{title:e,children:u.jsx("pre",{"data-testid":t,className:"overflow-x-auto border border-stone-300/45 bg-white/75 p-4 text-xs leading-6 text-stone-800",children:s})})}const X6=[{num:1,label:"VALIDATE RIGSPEC"},{num:2,label:"PREFLIGHT"},{num:3,label:"INSTANTIATE"}];function Z6(e){switch(e){case"input":case"validating":return 1;case"valid":case"preflight":return 2;case"preflight_done":case"instantiating":case"done":return 3;case"error":return 0}}function W6({onBack:e}={}){const t=TM(),{currentRigDraft:s,selectedRigDraft:r,saveRigDraft:i,rememberRigDraft:l,clearSelectedRigDraft:d}=Co(),[f,m]=j.useState(()=>(r==null?void 0:r.yaml)??(s==null?void 0:s.yaml)??""),[h,v]=j.useState(""),[g,y]=j.useState("input"),[b,S]=j.useState(0),[w,N]=j.useState([]),[C,T]=j.useState([]),[_,R]=j.useState(null);j.useEffect(()=>{i(f)},[i,f]),j.useEffect(()=>{r&&(m(r.yaml),d())},[d,r]);const O=async()=>{l(f),y("validating"),N([]);try{const I=await(await fetch("/api/rigs/import/validate",{method:"POST",headers:{"Content-Type":"text/yaml"},body:f})).json();I.valid?y("valid"):(N(I.errors??["Validation failed"]),S(1),y("error"))}catch{N(["Validation request failed"]),S(1),y("error")}},B=async()=>{y("preflight"),N([]),T([]);try{const M={"Content-Type":"text/yaml"};h&&(M["X-Rig-Root"]=h);const H=await(await fetch("/api/rigs/import/preflight",{method:"POST",headers:M,body:f})).json();T(H.warnings??[]),H.errors&&H.errors.length>0?(N(H.errors),S(2),y("error")):y("preflight_done")}catch{N(["Preflight request failed"]),S(2),y("error")}},L=async()=>{y("instantiating"),N([]);try{const M=await t.mutateAsync({yaml:f,rigRoot:h.trim()||void 0});R(M),y("done")}catch(M){M instanceof Jp?(M.code==="cycle_error"?N(["Cycle detected in rig topology"]):N(M.errors),T(M.warnings)):N([M instanceof Error?M.message:"Instantiate request failed"]),S(3),y("error")}};return u.jsx(rt,{children:u.jsxs("div",{"data-testid":"import-flow",className:"space-y-8",children:[u.jsx(Yn,{eyebrow:"Rig Import",title:"Import Rig",description:"Validate a RigSpec, run preflight checks, then instantiate a topology from YAML."}),u.jsx(ME,{"data-testid":"step-indicator",steps:X6,currentStep:Z6(g),errorAtStep:g==="error"?b:0}),g==="input"&&u.jsxs(Ln,{title:"Rig YAML",description:"Paste a rig spec and optionally provide a rig root to anchor relative references during import.",children:[u.jsx(p0,{"data-testid":"yaml-input",value:f,onChange:M=>m(M.target.value),placeholder:"Paste YAML rig spec here...",rows:14,className:"font-mono text-body-sm mb-spacing-4"}),u.jsxs("div",{className:"mb-spacing-4",children:[u.jsx("label",{className:"text-label-sm text-foreground-muted uppercase tracking-[0.04em] block mb-spacing-1",children:"RIG ROOT (OPTIONAL)"}),u.jsx(m0,{"data-testid":"rig-root-input",type:"text",value:h,onChange:M=>v(M.target.value),placeholder:"/path/to/rig/root",className:"font-mono text-body-sm"})]}),u.jsx(Ne,{variant:"tactical","data-testid":"validate-btn",onClick:O,disabled:!f.trim(),children:"VALIDATE RIGSPEC"})]}),g==="validating"&&u.jsx("div",{className:"text-label-md text-foreground-muted",children:"Validating..."}),g==="valid"&&u.jsxs(Ln,{title:"Validation Passed",description:"The RigSpec is valid. Run preflight checks before you instantiate it.",children:[u.jsx(Qt,{className:"mb-spacing-4","data-testid":"valid-message",children:u.jsx(Kt,{className:"text-primary",children:"RigSpec valid. Run preflight checks?"})}),u.jsx(Ne,{variant:"tactical","data-testid":"preflight-btn",onClick:B,children:"RUN PREFLIGHT"})]}),g==="preflight"&&u.jsx("div",{className:"text-label-md text-foreground-muted",children:"Running preflight..."}),g==="preflight_done"&&u.jsxs(Ln,{title:"Preflight Results",description:"Review warnings before you instantiate the rig into live runtime sessions.",children:[C.length>0&&u.jsx(Qt,{className:"mb-spacing-4","data-testid":"preflight-warnings",children:u.jsxs(Kt,{className:"text-warning",children:[u.jsx("div",{className:"text-label-md uppercase mb-spacing-1",children:"WARNINGS"}),C.map((M,I)=>u.jsxs("div",{children:["— ",M]},I))]})}),u.jsx(Qt,{className:"mb-spacing-4","data-testid":"preflight-ready",children:u.jsx(Kt,{className:"text-primary",children:"Preflight passed. Ready to instantiate."})}),u.jsx(Ne,{variant:"tactical","data-testid":"instantiate-btn",onClick:L,children:"INSTANTIATE"})]}),g==="instantiating"&&u.jsx("div",{className:"text-label-md text-foreground-muted",children:"Instantiating..."}),g==="done"&&_&&u.jsx(Ln,{title:"Instantiate Result",description:"The daemon returned per-node launch status for the imported topology.",className:"space-y-4",children:u.jsxs("div",{"data-testid":"import-result",children:[u.jsx(Qt,{className:"mb-spacing-4",children:u.jsxs(Kt,{children:[u.jsx("span",{className:"text-primary font-mono",children:_.specName}),u.jsxs("span",{className:"text-foreground-muted",children:[" (",_.rigId,")"]})]})}),u.jsxs(g0,{children:[u.jsx(x0,{children:u.jsxs(cc,{children:[u.jsx(Or,{children:"NODE"}),u.jsx(Or,{children:"STATUS"})]})}),u.jsx(y0,{children:_.nodes.map(M=>u.jsxs(cc,{children:[u.jsx(Dr,{className:"font-mono",children:M.logicalId}),u.jsx(Dr,{children:u.jsx("span",{className:`font-mono ${Q6(M.status)}`,"data-testid":`inst-status-${M.logicalId}`,children:M.status})})]},M.logicalId))})]}),e?u.jsx("div",{className:"mt-spacing-6",children:u.jsx(Ne,{variant:"ghost",onClick:e,children:"Close"})}):null]})}),g==="error"&&u.jsx(Ln,{title:"Import Errors",description:"Fix the reported issues, then retry the import flow.",children:u.jsxs("div",{"data-testid":"import-errors",children:[C.length>0&&u.jsx(Qt,{className:"mb-spacing-2","data-testid":"error-warnings",children:u.jsxs(Kt,{className:"text-warning",children:[u.jsx("div",{className:"text-label-md uppercase mb-spacing-1",children:"WARNINGS"}),C.map((M,I)=>u.jsxs("div",{children:["— ",M]},I))]})}),w.map((M,I)=>u.jsx(Qt,{className:"mb-spacing-2",children:u.jsx(Kt,{className:"text-destructive",children:M})},I)),u.jsx(Ne,{variant:"tactical",className:"mt-spacing-4",onClick:()=>{y("input"),N([]),T([]),R(null),S(0),v("")},children:"TRY AGAIN"})]})})]})})}async function J6(){const e=await fetch("/api/packages/summary");if(!e.ok)throw new Error(`HTTP ${e.status}`);return e.json()}function eP(){return Tt({queryKey:["packages"],queryFn:J6})}function tP(e){switch(e){case"applied":return"bg-success";case"rolled_back":return"bg-warning";case"failed":return"bg-destructive";default:return"bg-foreground-muted-on-dark"}}function nP(e){switch(e){case"applied":return"APPLIED";case"rolled_back":return"ROLLED BACK";case"failed":return"FAILED";default:return"NONE"}}function sP({pkg:e,onSelect:t}){return u.jsxs("div",{"data-testid":"package-card",role:"link",tabIndex:0,className:"card-dark p-spacing-6 mb-spacing-3 cursor-pointer",onClick:()=>t(e.id),onKeyDown:s=>{s.key==="Enter"&&t(e.id)},children:[u.jsxs("div",{className:"flex items-baseline justify-between mb-spacing-2",children:[u.jsx("h3",{className:"text-headline-md uppercase",children:e.name}),u.jsxs("span",{className:"text-label-md font-mono text-foreground-muted-on-dark",children:["v",e.version]})]}),e.summary&&u.jsx("p",{className:"text-body-sm text-foreground-muted-on-dark mb-spacing-4",children:e.summary}),u.jsx("div",{className:"flex items-center gap-spacing-4 text-label-sm",children:u.jsxs("span",{className:"text-foreground-muted-on-dark",children:["SOURCE ",u.jsx("span",{className:"font-mono text-foreground-on-dark",children:e.sourceRef})]})}),u.jsxs("div",{className:"flex items-center gap-spacing-4 mt-spacing-3 text-label-sm",children:[u.jsxs("span",{className:"text-foreground-muted-on-dark",children:["INSTALLS ",u.jsx("span",{className:"font-mono text-foreground-on-dark","data-testid":"install-count",children:e.installCount})]}),u.jsxs("span",{className:"flex items-center gap-spacing-1",children:[u.jsx("span",{className:Te("inline-block w-[6px] h-[6px]",tP(e.latestInstallStatus))}),u.jsx("span",{className:"text-foreground-muted-on-dark","data-testid":"install-status",children:nP(e.latestInstallStatus)})]})]})]})}function aP(){const e=Xt(),{data:t,isPending:s,error:r}=eP(),i=t?[...t].sort((l,d)=>d.createdAt.localeCompare(l.createdAt)):[];return s?u.jsx(rt,{children:u.jsxs("div",{"data-testid":"packages-loading",children:[u.jsxs("div",{className:"flex justify-between mb-spacing-6",children:[u.jsx("div",{className:"h-8 w-32 shimmer"}),u.jsx("div",{className:"h-8 w-28 shimmer"})]}),[1,2].map(l=>u.jsxs("div",{className:"card-dark p-spacing-6 mb-spacing-3",children:[u.jsx("div",{className:"h-6 w-48 shimmer-dark mb-spacing-4"}),u.jsx("div",{className:"h-12 shimmer-dark mb-spacing-4"}),u.jsx("div",{className:"h-4 w-64 shimmer-dark"})]},l))]})}):r?u.jsx(rt,{children:u.jsx("div",{children:u.jsx(Qt,{"data-testid":"packages-error",children:u.jsx(Kt,{children:r.message})})})}):i.length===0?u.jsx(rt,{children:u.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[60vh]","data-testid":"packages-empty",children:[u.jsx("h2",{className:"text-display-lg text-foreground mb-spacing-4",children:"NO LEGACY PACKAGE INSTALLS"}),u.jsx("p",{className:"text-body-md text-foreground-muted mb-spacing-8",children:"Legacy package tools remain available for bootstrap internals while Specs becomes the main authoring surface."}),u.jsxs("div",{className:"flex flex-col items-center gap-spacing-3",children:[u.jsx(Ne,{variant:"default",size:"lg","data-testid":"empty-import-btn",onClick:()=>e({to:"/import"}),children:"IMPORT RIGSPEC"}),u.jsx(Ne,{variant:"ghost",size:"lg","data-testid":"empty-bootstrap-btn",onClick:()=>e({to:"/bootstrap"}),children:"BOOTSTRAP"})]})]})}):u.jsx(rt,{children:u.jsxs("div",{children:[u.jsxs("div",{className:"flex justify-between items-baseline mb-spacing-6",children:[u.jsxs("div",{children:[u.jsx("h2",{className:"text-headline-lg uppercase",children:"LEGACY PACKAGE TOOLS"}),u.jsxs("p",{className:"text-label-md text-foreground-muted font-grotesk mt-spacing-1",children:[i.length," legacy package install",i.length!==1?"s":""," retained for bootstrap internals"]})]}),u.jsxs("div",{className:"flex flex-col items-end gap-spacing-2",children:[u.jsx(Ne,{variant:"default",size:"sm","data-testid":"header-import-btn",onClick:()=>e({to:"/import"}),children:"IMPORT RIGSPEC"}),u.jsx(Ne,{variant:"ghost",size:"sm","data-testid":"header-bootstrap-btn",onClick:()=>e({to:"/bootstrap"}),children:"BOOTSTRAP"})]})]}),i.map(l=>u.jsx(sP,{pkg:l,onSelect:d=>e({to:"/packages/$packageId",params:{packageId:d}})},l.id))]})})}const rP=[{num:1,label:"ENTER"},{num:2,label:"VALIDATE"},{num:3,label:"CONFIGURE"},{num:4,label:"PLAN"},{num:5,label:"APPLY"}];function iP(e){switch(e){case"enter":return 1;case"validating":case"validated":return 2;case"configure":return 3;case"planning":case"planned":return 4;case"applying":case"done":return 5;case"error":return 0}}function oP({currentStep:e,errorAtStep:t}){const s=e==="error"?t:iP(e);return u.jsx("div",{className:"flex items-center gap-spacing-2 mb-spacing-8 p-spacing-4 inset-light flex-wrap","data-testid":"step-indicator",children:rP.map((r,i)=>{const l=s>r.num,d=s===r.num;return u.jsxs("div",{className:"flex items-center gap-spacing-2",children:[i>0&&u.jsx("div",{className:`w-6 h-px mx-spacing-1 ${l?"bg-primary/40":"bg-foreground-muted/20"}`}),u.jsxs("span",{"data-testid":`step-${r.num}`,className:Te("text-label-sm uppercase tracking-[0.04em] font-mono px-spacing-2 py-spacing-1 transition-colors whitespace-nowrap",l?"text-foreground-muted":d?"text-foreground bg-foreground/10":"text-foreground-muted/30"),children:[l?"✓":""," [ ",r.num," ",r.label," ]"]})]},r.num)})})}function lP(e){switch(e){case"approved":return"text-success";case"rejected":return"text-warning";case"deferred":return"text-foreground-muted";case"conflict":return"text-destructive";case"noop":return"text-foreground-muted/50";default:return""}}function cP(e){switch(e){case"approved":return"bg-success/8";case"rejected":return"bg-warning/8";case"deferred":return"bg-foreground-muted/4";case"conflict":return"bg-destructive/8";default:return""}}function uP(){const e=Xt(),[t,s]=j.useState(""),[r,i]=j.useState("enter"),[l,d]=j.useState(0),[f,m]=j.useState([]),[h,v]=j.useState(null),[g,y]=j.useState("claude-code"),[b,S]=j.useState("."),[w,N]=j.useState(""),[C,T]=j.useState(!1),[_,R]=j.useState(null),[O,B]=j.useState(null),L=async()=>{i("validating"),m([]);try{const Y=await(await fetch("/api/packages/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceRef:t})})).json();Y.valid?(v(Y.manifest),i("validated")):(m(Y.errors??[Y.error??"Validation failed"]),d(2),i("error"))}catch{m(["Validation request failed"]),d(2),i("error")}},M=async()=>{i("planning"),m([]);try{const D=await fetch("/api/packages/plan",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceRef:t,targetRoot:b,runtime:g,roleName:w||void 0,allowMerge:C})});if(!D.ok){const K=await D.json();m(K.errors??[K.error??"Plan failed"]),d(4),i("error");return}const Y=await D.json();R(Y),i("planned")}catch{m(["Plan request failed"]),d(4),i("error")}},I=async()=>{i("applying"),m([]);try{const D=await fetch("/api/packages/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceRef:t,targetRoot:b,runtime:g,roleName:w||void 0,allowMerge:C})}),Y=await D.json();if(D.status>=400){m(Y.errors??[Y.error??"Install failed"]),d(5),i("error");return}B(Y),i("done")}catch{m(["Install request failed"]),d(5),i("error")}},H=((_==null?void 0:_.conflicts)??0)>0;return u.jsx(rt,{children:u.jsxs("div",{"data-testid":"install-flow",children:[u.jsx("div",{className:"mb-spacing-8",children:u.jsxs("div",{children:[u.jsx("h2",{className:"text-headline-lg uppercase tracking-[0.06em]",children:"INSTALL PACKAGE (Legacy)"}),u.jsx("p",{className:"text-label-md text-foreground-muted font-grotesk mt-spacing-1",children:"Validate, configure, and apply an agent package"})]})}),u.jsx(oP,{currentStep:r,errorAtStep:l}),r==="enter"&&u.jsxs("div",{children:[u.jsx("label",{className:"text-label-md text-foreground-muted uppercase tracking-[0.04em] block mb-spacing-2",children:"PACKAGE PATH"}),u.jsx("input",{"data-testid":"source-path-input",type:"text",value:t,onChange:D=>s(D.target.value),placeholder:"/path/to/package",className:"w-full bg-transparent border-b border-foreground/20 focus:border-foreground px-0 py-spacing-2 text-body-md font-mono outline-none transition-colors"}),u.jsx(Ne,{variant:"tactical","data-testid":"validate-btn",onClick:L,disabled:!t.trim(),className:"mt-spacing-4",children:"VALIDATE"})]}),r==="validating"&&u.jsx("div",{className:"text-label-md text-foreground-muted","data-testid":"validating-indicator",children:"Validating..."}),r==="validated"&&h&&u.jsxs("div",{"data-testid":"manifest-summary",children:[u.jsxs("div",{className:"card-dark p-spacing-4 mb-spacing-4",children:[u.jsxs("div",{className:"flex items-baseline justify-between mb-spacing-2",children:[u.jsx("span",{className:"text-headline-md uppercase",children:h.name}),u.jsxs("span",{className:"font-mono text-foreground-muted-on-dark",children:["v",h.version]})]}),u.jsx("p",{className:"text-body-sm text-foreground-muted-on-dark mb-spacing-3",children:h.summary}),u.jsxs("div",{className:"flex flex-wrap gap-spacing-3 text-label-sm",children:[u.jsxs("span",{children:["Skills: ",u.jsx("span",{className:"font-mono text-foreground-on-dark",children:h.exportCounts.skills})]}),u.jsxs("span",{children:["Guidance: ",u.jsx("span",{className:"font-mono text-foreground-on-dark",children:h.exportCounts.guidance})]}),u.jsxs("span",{children:["Agents: ",u.jsx("span",{className:"font-mono text-foreground-on-dark",children:h.exportCounts.agents})]}),u.jsxs("span",{children:["Hooks: ",u.jsx("span",{className:"font-mono text-foreground-on-dark",children:h.exportCounts.hooks})]}),u.jsxs("span",{children:["Runtimes: ",u.jsx("span",{className:"font-mono text-foreground-on-dark",children:h.runtimes.join(", ")})]})]})]}),u.jsx(Ne,{variant:"tactical","data-testid":"configure-btn",onClick:()=>i("configure"),children:"CONFIGURE"})]}),r==="configure"&&h&&u.jsxs("div",{"data-testid":"configure-step",children:[u.jsxs("div",{className:"space-y-spacing-4 mb-spacing-6",children:[u.jsxs("div",{children:[u.jsx("label",{className:"text-label-sm text-foreground-muted uppercase tracking-[0.04em] block mb-spacing-1",children:"RUNTIME"}),u.jsx("select",{"data-testid":"runtime-select",value:g,onChange:D=>y(D.target.value),className:"bg-transparent border-b border-foreground/20 py-spacing-1 text-body-md font-mono outline-none",children:h.runtimes.map(D=>u.jsx("option",{value:D,children:D},D))})]}),u.jsxs("div",{children:[u.jsx("label",{className:"text-label-sm text-foreground-muted uppercase tracking-[0.04em] block mb-spacing-1",children:"TARGET ROOT"}),u.jsx("input",{"data-testid":"target-root-input",type:"text",value:b,onChange:D=>S(D.target.value),className:"w-full bg-transparent border-b border-foreground/20 px-0 py-spacing-1 text-body-md font-mono outline-none"})]}),h.roles.length>0&&u.jsxs("div",{children:[u.jsx("label",{className:"text-label-sm text-foreground-muted uppercase tracking-[0.04em] block mb-spacing-1",children:"ROLE"}),u.jsxs("select",{"data-testid":"role-select",value:w,onChange:D=>N(D.target.value),className:"bg-transparent border-b border-foreground/20 py-spacing-1 text-body-md font-mono outline-none",children:[u.jsx("option",{value:"",children:"All exports"}),h.roles.map(D=>u.jsxs("option",{value:D.name,children:[D.name,D.description?` — ${D.description}`:""]},D.name))]})]}),u.jsxs("div",{className:"flex items-center gap-spacing-2",children:[u.jsx("input",{"data-testid":"allow-merge-toggle",type:"checkbox",checked:C,onChange:D=>T(D.target.checked),className:"accent-primary"}),u.jsx("label",{className:"text-label-sm text-foreground-muted",children:"Allow managed block merges into existing files"})]}),(h.requirements.cliTools.length>0||h.requirements.systemPackages.length>0)&&u.jsxs("div",{"data-testid":"requirements-section",className:"p-spacing-3 bg-foreground/4",children:[u.jsx("span",{className:"text-label-sm text-foreground-muted uppercase block mb-spacing-1",children:"REQUIREMENTS"}),h.requirements.cliTools.map(D=>u.jsxs("div",{className:"text-body-sm font-mono",children:["CLI: ",D.name]},D.name)),h.requirements.systemPackages.map(D=>u.jsxs("div",{className:"text-body-sm font-mono",children:["System: ",D.name]},D.name))]})]}),u.jsx(Ne,{variant:"tactical","data-testid":"plan-btn",onClick:M,children:"PREVIEW PLAN"})]}),r==="planning"&&u.jsx("div",{className:"text-label-md text-foreground-muted","data-testid":"planning-indicator",children:"Planning..."}),r==="planned"&&_&&u.jsxs("div",{"data-testid":"plan-preview",children:[u.jsxs("div",{className:"flex flex-wrap gap-spacing-4 mb-spacing-4 text-label-sm",children:[u.jsxs("span",{children:["Approved: ",u.jsx("span",{className:"font-mono text-success","data-testid":"plan-actionable",children:_.actionable})]}),u.jsxs("span",{children:["Deferred: ",u.jsx("span",{className:"font-mono text-foreground-muted","data-testid":"plan-deferred",children:_.deferred})]}),u.jsxs("span",{children:["Conflicts: ",u.jsx("span",{className:"font-mono text-destructive","data-testid":"plan-conflicts",children:_.conflicts})]}),u.jsxs("span",{children:["No-ops: ",u.jsx("span",{className:"font-mono","data-testid":"plan-noops",children:_.noOps})]}),_.rejected>0&&u.jsxs("span",{children:["Rejected: ",u.jsx("span",{className:"font-mono text-warning","data-testid":"plan-rejected",children:_.rejected})]})]}),H&&u.jsx(Qt,{className:"mb-spacing-4","data-testid":"conflict-warning",children:u.jsx(Kt,{className:"text-destructive",children:"Conflicts detected — resolve before applying"})}),u.jsxs(g0,{children:[u.jsx(x0,{children:u.jsxs(cc,{children:[u.jsx(Or,{children:"TYPE"}),u.jsx(Or,{children:"NAME"}),u.jsx(Or,{children:"STATUS"}),u.jsx(Or,{children:"TARGET"})]})}),u.jsx(y0,{children:_.entries.map((D,Y)=>u.jsxs(cc,{className:cP(D.policyStatus),"data-testid":"plan-entry","data-policy-status":D.policyStatus,children:[u.jsx(Dr,{className:"font-mono text-label-sm",children:D.exportType}),u.jsx(Dr,{className:"font-mono text-label-sm",children:D.exportName}),u.jsxs(Dr,{className:Te("font-mono text-label-sm uppercase",lP(D.policyStatus)),children:[D.policyStatus,D.deferReason&&u.jsxs("span",{className:"text-foreground-muted normal-case",children:[" — ",D.deferReason]}),D.conflict&&u.jsxs("span",{className:"text-destructive normal-case",children:[" — ",D.conflict.reason]})]}),u.jsx(Dr,{className:"font-mono text-label-sm text-foreground-muted truncate max-w-[200px]",children:D.targetPath||"—"})]},Y))})]}),u.jsx("div",{className:"mt-spacing-4",children:u.jsx(Ne,{variant:"tactical","data-testid":"apply-btn",onClick:I,disabled:H,title:H?"Resolve conflicts before applying":void 0,children:"APPLY"})})]}),r==="applying"&&u.jsx("div",{className:"text-label-md text-foreground-muted","data-testid":"applying-indicator",children:"Applying..."}),r==="done"&&O&&u.jsxs("div",{"data-testid":"install-result",children:[u.jsx(Qt,{className:"mb-spacing-4",children:u.jsxs(Kt,{children:[u.jsx("span",{className:"text-primary font-mono",children:O.packageName}),u.jsx("span",{className:"text-foreground-muted",children:" installed as "}),u.jsx("span",{className:"font-mono","data-testid":"result-install-id",children:O.installId})]})}),u.jsxs("div",{className:"flex gap-spacing-4 text-label-sm mb-spacing-4",children:[u.jsxs("span",{children:["Applied: ",u.jsx("span",{className:"font-mono text-success","data-testid":"result-applied",children:O.applied.length})]}),u.jsxs("span",{children:["Deferred: ",u.jsx("span",{className:"font-mono text-foreground-muted","data-testid":"result-deferred",children:O.deferred.length})]}),u.jsxs("span",{children:["Verified: ",u.jsx("span",{className:Te("font-mono",O.verification.passed?"text-success":"text-destructive"),"data-testid":"result-verified",children:O.verification.passed?"PASS":"FAIL"})]})]}),u.jsx("div",{className:"flex gap-spacing-3",children:u.jsx(Ne,{variant:"tactical","data-testid":"detail-link",onClick:()=>e({to:"/packages/$packageId",params:{packageId:O.packageId}}),children:"VIEW INSTALL DETAILS"})})]}),r==="error"&&u.jsxs("div",{"data-testid":"install-errors",children:[f.map((D,Y)=>u.jsx(Qt,{className:"mb-spacing-2",children:u.jsx(Kt,{className:"text-destructive",children:D})},Y)),u.jsx(Ne,{variant:"tactical",className:"mt-spacing-4","data-testid":"try-again-btn",onClick:()=>{i("enter"),m([]),v(null),R(null),B(null),d(0)},children:"TRY AGAIN"})]})]})})}function dP(e){return Tt({queryKey:["packages",e],queryFn:async()=>{const t=await fetch(`/api/packages/${e}`);if(!t.ok)throw new Error(`HTTP ${t.status}`);return t.json()},enabled:!!e})}function fP(e){return Tt({queryKey:["packages",e,"installs"],queryFn:async()=>{const t=await fetch(`/api/packages/${e}/installs`);if(!t.ok)throw new Error(`HTTP ${t.status}`);return t.json()},enabled:!!e})}function hP(e){return Tt({queryKey:["installs",e,"journal"],queryFn:async()=>{const t=await fetch(`/api/packages/installs/${e}/journal`);if(!t.ok)throw new Error(`HTTP ${t.status}`);return t.json()},enabled:!!e})}function mP(e){const t=Ct();return Pt({mutationFn:async s=>{const r=await fetch(`/api/packages/${s}/rollback`,{method:"POST"});if(!r.ok)throw new Error(`HTTP ${r.status}`);return r.json()},onSuccess:()=>{t.invalidateQueries({queryKey:["packages",e,"installs"]}),t.invalidateQueries({queryKey:["installs"]})}})}function pP(e){switch(e){case"applied":return"bg-success";case"rolled_back":return"bg-warning";case"failed":return"bg-destructive";default:return"bg-foreground-muted"}}function gP(e){switch(e){case"applied":return"APPLIED";case"rolled_back":return"ROLLED BACK";case"failed":return"FAILED";default:return e.toUpperCase()}}function xP({installId:e}){const{data:t,isPending:s,isError:r}=hP(e);return s?u.jsx("div",{className:"pl-spacing-6 py-spacing-2 text-label-sm text-foreground-muted",children:"Loading journal..."}):r?u.jsx("div",{className:"pl-spacing-6 py-spacing-2 text-label-sm text-destructive","data-testid":"journal-error",children:"Failed to load journal entries"}):!t||t.length===0?u.jsx("div",{className:"pl-spacing-6 py-spacing-2 text-label-sm text-foreground-muted",children:"No journal entries"}):u.jsx("div",{className:"pl-spacing-6 py-spacing-2 space-y-spacing-1","data-testid":"journal-entries",children:t.map(i=>u.jsxs("div",{"data-testid":"journal-entry",className:"flex items-center gap-spacing-3 text-label-sm font-mono py-spacing-1 border-b border-foreground/6 last:border-0",children:[u.jsx("span",{className:"text-foreground-muted w-6 text-right",children:i.seq}),u.jsx("span",{className:"uppercase",children:i.action}),u.jsx("span",{className:"text-foreground-muted",children:i.exportType}),u.jsx("span",{className:"text-foreground-muted truncate max-w-[200px]",children:i.targetPath}),u.jsx("span",{className:"text-foreground-muted ml-auto",children:i.status})]},i.id))})}function yP({install:e,onRollback:t}){const[s,r]=j.useState(!1);return u.jsxs("div",{"data-testid":"install-row",className:"card-dark p-spacing-4 mb-spacing-2",children:[u.jsxs("div",{className:"flex items-center gap-spacing-4",children:[u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsxs("div",{className:"flex items-center gap-spacing-3 mb-spacing-1",children:[u.jsx("span",{className:"font-mono text-label-sm text-foreground-muted",children:e.createdAt}),u.jsx("span",{"data-testid":"install-status-badge",className:Te("inline-block px-spacing-2 py-px text-label-sm uppercase",pP(e.status)),children:gP(e.status)})]}),u.jsx("div",{className:"text-label-sm font-mono text-foreground-muted-on-dark",children:e.targetRoot}),u.jsxs("div",{className:"flex items-center gap-spacing-3 mt-spacing-1 text-label-sm",children:[u.jsxs("span",{"data-testid":"applied-count",children:[u.jsx("span",{className:"font-mono",children:e.appliedCount})," applied"]}),u.jsx("span",{"data-testid":"deferred-placeholder",className:"text-foreground-muted",children:"— deferred"})]})]}),u.jsxs("div",{className:"flex items-center gap-spacing-2 shrink-0",children:[u.jsx(Ne,{variant:"tactical",size:"sm","data-testid":"expand-btn",onClick:()=>r(!s),children:s?"COLLAPSE":"EXPAND"}),e.status==="applied"&&u.jsx(Ne,{variant:"tactical",size:"sm","data-testid":"rollback-btn",onClick:()=>t(e.id),children:"ROLLBACK"})]})]}),s&&u.jsx(xP,{installId:e.id})]})}function vP(){var w;const{packageId:e}=cf({strict:!1}),{data:t,isPending:s,error:r}=dP(e),{data:i,isPending:l,error:d}=fP(e),f=mP(e),[m,h]=j.useState(null),[v,g]=j.useState(!1),y=N=>{h(N),g(!0)},b=()=>{m&&f.mutate(m,{onSuccess:()=>{g(!1),h(null)}})};if(s||l)return u.jsx(rt,{children:u.jsxs("div",{"data-testid":"detail-loading",children:[u.jsx("div",{className:"h-8 w-48 shimmer mb-spacing-4"}),u.jsxs("div",{className:"card-dark p-spacing-6 mb-spacing-4",children:[u.jsx("div",{className:"h-6 w-64 shimmer-dark mb-spacing-3"}),u.jsx("div",{className:"h-4 w-full shimmer-dark"})]})]})});if(r)return u.jsx(rt,{children:u.jsx("div",{"data-testid":"detail-error",children:u.jsx("p",{className:"text-destructive",children:r.message})})});if(d)return u.jsx(rt,{children:u.jsx("div",{"data-testid":"installs-error",children:u.jsx("p",{className:"text-destructive",children:"Failed to load install history"})})});const S=i??[];return u.jsx(rt,{children:u.jsxs("div",{children:[t&&u.jsxs("div",{className:"card-dark p-spacing-6 mb-spacing-6","data-testid":"package-header",children:[u.jsxs("div",{className:"flex items-baseline justify-between mb-spacing-2",children:[u.jsxs("h2",{className:"text-headline-lg uppercase",children:[t.name," (Legacy)"]}),u.jsxs("span",{className:"text-label-md font-mono text-foreground-muted-on-dark",children:["v",t.version]})]}),u.jsxs("div",{className:"text-label-sm text-foreground-muted-on-dark mb-spacing-2",children:["SOURCE"," ",u.jsx("span",{className:"font-mono text-foreground-on-dark","data-testid":"package-source",children:t.sourceRef})]}),t.summary&&u.jsx("p",{className:"text-body-sm text-foreground-muted-on-dark",children:t.summary})]}),u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-4",children:"INSTALL HISTORY"}),S.length===0?u.jsx("div",{"data-testid":"empty-installs",className:"text-body-md text-foreground-muted",children:"No installs yet"}):u.jsx("div",{"data-testid":"install-list",children:S.map(N=>u.jsx(yP,{install:N,onRollback:y},N.id))}),u.jsx(Gd,{open:v,onOpenChange:N=>{f.isPending||(g(N),N||f.reset())},children:u.jsxs(Kl,{"data-testid":"rollback-dialog",onPointerDownOutside:N=>{f.isPending&&N.preventDefault()},onEscapeKeyDown:N=>{f.isPending&&N.preventDefault()},hideCloseButton:f.isPending,children:[u.jsxs(Fl,{children:[u.jsx(Zl,{className:"text-headline-md uppercase",children:"CONFIRM ROLLBACK"}),u.jsx(Wl,{children:"This will roll back the install and restore previous file states. This action cannot be undone."})]}),f.isError&&u.jsxs("p",{className:"text-destructive text-label-sm","data-testid":"rollback-error",children:["Rollback failed: ",((w=f.error)==null?void 0:w.message)??"Unknown error"]}),u.jsxs(Xl,{children:[u.jsx(Ne,{variant:"ghost",onClick:()=>{f.reset(),g(!1)},"data-testid":"rollback-cancel",disabled:f.isPending,children:"CANCEL"}),u.jsx(Ne,{variant:"destructive",onClick:b,"data-testid":"rollback-confirm",disabled:f.isPending,children:f.isPending?"ROLLING BACK...":"ROLLBACK"})]})]})})]})})}function bP(e){switch(e){case"installed":return"bg-success";case"missing":return"bg-destructive";case"unsupported":return"bg-warning";case"unknown":return"bg-warning";default:return"bg-foreground-muted"}}function SP(e){switch(e){case"installed":return"OK";case"missing":return"MISSING";case"unsupported":return"MANUAL";case"unknown":return"UNKNOWN";default:return e.toUpperCase()}}function wP({results:e}){return e.length===0?u.jsx("div",{className:"text-body-sm text-foreground-muted","data-testid":"no-requirements",children:"No requirements declared."}):u.jsx("div",{className:"space-y-spacing-1","data-testid":"requirements-panel",children:e.map(t=>u.jsxs("div",{"data-testid":"requirement-row",className:"flex items-center gap-spacing-3 py-spacing-1 text-label-sm font-mono",children:[u.jsx("span",{"data-testid":"requirement-dot",className:Te("w-2 h-2 shrink-0",bP(t.status))}),u.jsx("span",{"data-testid":"requirement-status",className:"w-16 uppercase",children:SP(t.status)}),u.jsx("span",{className:"text-foreground-muted w-24",children:t.kind}),u.jsx("span",{children:t.name}),t.detectedPath&&u.jsx("span",{className:"text-foreground-muted ml-auto truncate max-w-[200px]",children:t.detectedPath})]},`${t.kind}:${t.name}`))})}function OE(e,t){var r,i;const s=((r=e.stages)==null?void 0:r.flatMap(l=>{const d=l.detail;if(!d)return[];const f=[];return Array.isArray(d.errors)&&f.push(...d.errors.filter(m=>typeof m=="string")),typeof d.error=="string"&&f.push(d.error),f}))??[];return((i=e.errors)==null?void 0:i.find(l=>typeof l=="string"))??s[0]??e.error??`HTTP ${t}`}function NP(){return Pt({mutationFn:async({sourceRef:e})=>{const t=await fetch("/api/bootstrap/plan",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceRef:e})});if(!t.ok){const s=await t.json().catch(()=>({})),r=new Error(OE(s,t.status));throw r.data=s,r}return t.json()}})}function jP(){const e=Ct();return Pt({mutationFn:async({sourceRef:t,autoApprove:s,approvedActionKeys:r})=>{const i=await fetch("/api/bootstrap/apply",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sourceRef:t,autoApprove:s,approvedActionKeys:r})}),l=await i.json();if(!i.ok){const d=new Error(OE(l,i.status));throw d.data=l,d}return l},onSuccess:()=>{e.invalidateQueries({queryKey:["rigs","summary"]})}})}const EP=["ENTER","PLAN","REVIEW","APPLY"],CP=EP.map((e,t)=>({num:t+1,label:e}));function _P(e){switch(e){case"enter":return 1;case"planning":return 2;case"planned":return 3;case"applying":return 4;case"done":case"error":return 4;default:return 1}}function RP(){const e=Xt(),{bootstrapSourceRef:t,setBootstrapSourceRef:s}=Co(),[r,i]=j.useState("enter"),[l,d]=j.useState(()=>t),[f,m]=j.useState(null),[h,v]=j.useState(new Set),[g,y]=j.useState(!1),[b,S]=j.useState(null),w=NP(),N=jP();j.useEffect(()=>{s(l)},[s,l]);const C=async()=>{if(l.trim()){i("planning");try{const K=await w.mutateAsync({sourceRef:l.trim()});m(K),v(new Set(K.actionKeys??[])),i("planned")}catch(K){S(K.message),i("error")}}},T=async()=>{i("applying");try{const K=await N.mutateAsync({sourceRef:l.trim(),autoApprove:g,approvedActionKeys:g?void 0:[...h]});m(K),i("done")}catch(K){S(K.message),i("error")}},_=()=>{i("enter"),d(""),m(null),v(new Set),y(!1),S(null),w.reset(),N.reset()},R=f==null?void 0:f.stages.find(K=>K.stage==="probe_requirements"),O=R==null?void 0:R.detail,B=(O==null?void 0:O.results)??[],L=f==null?void 0:f.stages.find(K=>K.stage==="build_install_plan"),M=L==null?void 0:L.detail,I=(M==null?void 0:M.actions)??[],H=(L==null?void 0:L.status)==="blocked",Y=I.some(K=>K.classification!=="manual_only"&&K.commandPreview)&&h.size===0&&!g;return u.jsx(rt,{children:u.jsxs("div",{"data-testid":"bootstrap-wizard",className:"space-y-8",children:[u.jsx(Yn,{eyebrow:"Bootstrap",title:"Bootstrap",description:"Plan environment requirements, approve install actions, then import the rig into a running topology."}),u.jsx(ME,{"data-testid":"step-indicator",steps:CP,currentStep:_P(r)}),r==="enter"&&u.jsx(Ln,{title:"Source",description:"Provide a rig spec or bundle path. Bootstrap will inspect requirements before it imports anything.",children:u.jsxs("div",{"data-testid":"step-enter",children:[u.jsx("label",{className:"text-label-md uppercase block mb-spacing-2",children:"SPEC OR BUNDLE PATH"}),u.jsx(m0,{"data-testid":"spec-input",type:"text",value:l,onChange:K=>d(K.target.value),placeholder:"/path/to/rig.yaml or /path/to/bundle.rigbundle",className:"font-mono text-body-md"}),u.jsxs("p",{className:"text-label-sm text-foreground-muted mt-spacing-1",children:["Accepts .yaml rig specs or .rigbundle archives."," ",u.jsx("span",{role:"link",tabIndex:0,className:"text-primary cursor-pointer","data-testid":"inspect-link",onClick:()=>e({to:"/bundles/inspect"}),onKeyDown:K=>{K.key==="Enter"&&e({to:"/bundles/inspect"})},children:"Inspect a bundle first →"})]}),u.jsx("div",{className:"mt-spacing-4",children:u.jsx(Ne,{variant:"tactical",onClick:C,disabled:!l.trim(),"data-testid":"plan-btn",children:"PLAN"})})]})}),r==="planning"&&u.jsx("div",{"data-testid":"step-planning",className:"text-body-md text-foreground-muted",children:"Planning..."}),r==="planned"&&f&&u.jsx(Ln,{title:"Plan Review",description:"Review requirement probe results and approve the install actions that bootstrap should execute.",children:u.jsxs("div",{"data-testid":"step-planned",children:[u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"STAGES"}),u.jsx("div",{className:"space-y-spacing-1 mb-spacing-6","data-testid":"stage-list",children:f.stages.map(K=>u.jsxs("div",{className:"flex items-center gap-spacing-3 text-label-sm font-mono","data-testid":"stage-row",children:[u.jsx("span",{className:K.status==="ok"?"text-success":K.status==="blocked"?"text-warning":"text-foreground-muted",children:K.status.toUpperCase()}),u.jsx("span",{children:K.stage})]},K.stage))}),B.length>0&&u.jsxs(u.Fragment,{children:[u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"REQUIREMENTS"}),u.jsx("div",{className:"mb-spacing-6",children:u.jsx(wP,{results:B})})]}),I.length>0&&u.jsxs(u.Fragment,{children:[u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"ACTIONS"}),u.jsx("div",{className:"space-y-spacing-1 mb-spacing-4",children:I.map(K=>u.jsxs("label",{className:"flex items-center gap-spacing-3 text-label-sm font-mono cursor-pointer",children:[u.jsx("input",{type:"checkbox",checked:g||h.has(K.key),disabled:g||K.classification==="manual_only",onChange:U=>{const q=new Set(h);U.target.checked?q.add(K.key):q.delete(K.key),v(q)}}),u.jsx("span",{className:K.classification==="manual_only"?"text-warning":"",children:K.requirementName}),K.commandPreview&&u.jsx("span",{className:"text-foreground-muted",children:K.commandPreview})]},K.key))}),u.jsxs("label",{className:"flex items-center gap-spacing-2 text-label-sm mb-spacing-4",children:[u.jsx("input",{type:"checkbox",checked:g,onChange:K=>y(K.target.checked)}),"Auto-approve all trusted actions"]})]}),H&&u.jsx("div",{className:"text-warning text-label-sm mb-spacing-4","data-testid":"blocked-warning",children:"Manual requirements must be resolved before bootstrap can proceed."}),f.warnings.length>0&&u.jsx("div",{className:"mb-spacing-4",children:f.warnings.map((K,U)=>u.jsx("div",{className:"text-warning text-label-sm",children:K},U))}),u.jsx(Ne,{variant:"tactical",onClick:T,disabled:H||Y,title:H?"Manual requirements must be resolved":Y?"Select actions to approve":void 0,"data-testid":"apply-btn",children:"APPLY"})]})}),r==="applying"&&f&&u.jsx(Ln,{title:"Applying",description:"Bootstrap is executing the approved actions and importing the rig.",children:u.jsxs("div",{"data-testid":"step-applying",children:[u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"APPLYING"}),u.jsxs("div",{className:"space-y-spacing-1 mb-spacing-4","data-testid":"applying-checklist",children:[f.stages.map(K=>u.jsxs("div",{className:"flex items-center gap-spacing-3 text-label-sm font-mono",children:[u.jsx("span",{className:"text-foreground-muted",children:"○"}),u.jsx("span",{children:K.stage})]},K.stage)),u.jsxs("div",{className:"flex items-center gap-spacing-3 text-label-sm font-mono",children:[u.jsx("span",{className:"text-foreground-muted",children:"○"}),u.jsx("span",{children:"execute_external_installs"})]}),u.jsxs("div",{className:"flex items-center gap-spacing-3 text-label-sm font-mono",children:[u.jsx("span",{className:"text-foreground-muted",children:"○"}),u.jsx("span",{children:"install_packages"})]}),u.jsxs("div",{className:"flex items-center gap-spacing-3 text-label-sm font-mono",children:[u.jsx("span",{className:"text-foreground-muted",children:"○"}),u.jsx("span",{children:"import_rig"})]})]}),u.jsx("p",{className:"text-body-sm text-foreground-muted",children:"Bootstrapping..."})]})}),r==="done"&&f&&u.jsx(Ln,{title:"Result",description:"Bootstrap finished and returned the managed rig identity.",children:u.jsxs("div",{"data-testid":"step-done",children:[u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:f.status==="completed"?"BOOTSTRAP COMPLETE":"BOOTSTRAP PARTIAL"}),u.jsxs("div",{className:"text-label-sm font-mono space-y-spacing-1 mb-spacing-4",children:[u.jsxs("div",{children:["Status: ",u.jsx("span",{className:f.status==="completed"?"text-success":"text-warning",children:f.status.toUpperCase()})]}),f.rigId&&u.jsxs("div",{"data-testid":"result-rig-id",children:["Rig: ",f.rigId]})]}),f.rigId&&u.jsx(Ne,{variant:"tactical","data-testid":"view-rig-btn",onClick:()=>e({to:"/rigs/$rigId",params:{rigId:f.rigId}}),children:"VIEW RIG"})]})}),r==="error"&&u.jsx(Ln,{title:"Bootstrap Error",description:"Bootstrap could not complete. Fix the issue and retry the plan.",children:u.jsxs("div",{"data-testid":"step-error",children:[u.jsx("p",{className:"text-destructive text-body-md mb-spacing-4",children:b}),u.jsx(Ne,{variant:"tactical",onClick:_,"data-testid":"try-again-btn",children:"TRY AGAIN"})]})})]})})}function TP(){const{currentAgentDraft:e,selectedAgentDraft:t,saveAgentDraft:s,rememberAgentDraft:r,clearSelectedAgentDraft:i}=Co(),[l,d]=j.useState(()=>(t==null?void 0:t.yaml)??(e==null?void 0:e.yaml)??""),[f,m]=j.useState("idle"),[h,v]=j.useState([]);j.useEffect(()=>{s(l)},[s,l]),j.useEffect(()=>{t&&(d(t.yaml),i())},[i,t]);const g=async()=>{r(l),m("pending"),v([]);try{const y=await fetch("/api/agents/validate",{method:"POST",headers:{"Content-Type":"text/yaml"},body:l}),b=await y.json().catch(()=>({}));if(y.ok&&b.valid){m("valid");return}v(b.errors??["Validation failed"]),m("invalid")}catch{v(["Validation request failed"]),m("error")}};return u.jsx(rt,{children:u.jsxs("div",{"data-testid":"agent-spec-validate-flow",className:"space-y-8",children:[u.jsx(Yn,{eyebrow:"Agent Spec Validation",title:"VALIDATE AGENT",description:"Check an AgentSpec before you use it in a rig."}),u.jsxs(Ln,{title:"Agent YAML",description:"Paste or refine an AgentSpec draft, then validate it against the daemon contract.",children:[u.jsx(p0,{"data-testid":"agent-spec-yaml-input",value:l,onChange:y=>d(y.target.value),placeholder:"Paste agent.yaml here...",rows:16,className:"bg-background font-mono text-body-sm"}),u.jsx("div",{className:"flex flex-wrap gap-2",children:u.jsx(Ne,{variant:"tactical","data-testid":"agent-spec-validate-btn",onClick:g,disabled:!l.trim()||f==="pending",children:f==="pending"?"VALIDATING...":"VALIDATE AGENTSPEC"})}),f==="valid"&&u.jsx(Qt,{className:"mt-spacing-1","data-testid":"agent-spec-valid",children:u.jsx(Kt,{className:"text-primary",children:"AgentSpec valid."})}),(f==="invalid"||f==="error")&&u.jsx(Qt,{className:"mt-spacing-1","data-testid":"agent-spec-invalid",children:u.jsx(Kt,{children:u.jsx("ul",{className:"list-disc pl-5",children:h.map(y=>u.jsx("li",{children:y},y))})})})]})]})})}async function AP(e,t="draft"){var r;const s=await fetch("/api/specs/review/rig",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({yaml:e,sourceState:t})});if(!s.ok){const i=await s.json().catch(()=>({}));throw new Error(((r=i.errors)==null?void 0:r.join("; "))??`HTTP ${s.status}`)}return s.json()}async function MP(e,t="draft"){var r;const s=await fetch("/api/specs/review/agent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({yaml:e,sourceState:t})});if(!s.ok){const i=await s.json().catch(()=>({}));throw new Error(((r=i.errors)==null?void 0:r.join("; "))??`HTTP ${s.status}`)}return s.json()}function DE(e){let t=0;for(let s=0;s<e.length;s++)t=(t<<5)-t+e.charCodeAt(s)|0;return t}function kP(e,t="draft"){return Tt({queryKey:["spec-review","rig",e?DE(e):null,t],queryFn:()=>AP(e,t),enabled:!!e})}function OP(e,t="draft"){return Tt({queryKey:["spec-review","agent",e?DE(e):null,t],queryFn:()=>MP(e,t),enabled:!!e})}const DP=160,LP=48,OS=200,zP=100;function PP(e){switch(e){case"claude-code":return"#d4c4a8";case"codex":return"#b8c9d4";case"terminal":return"#c4c4c4";default:return"#e0ddd4"}}function IP(e){const t=new Map,s=[];for(const l of e)l.pod?(t.has(l.pod)||t.set(l.pod,[]),t.get(l.pod).push(l)):s.push(l);const r=[];let i=0;for(const[,l]of t)l.forEach((d,f)=>{r.push({id:d.id,x:f*OS,y:i})}),i+=zP;return s.forEach((l,d)=>{r.push({id:l.id,x:d*OS,y:i})}),r}function BP({graph:e,testId:t}){const s=e??{nodes:[],edges:[]},{nodes:r,edges:i}=j.useMemo(()=>{const l=IP(s.nodes),d=new Map(l.map(h=>[h.id,h])),f=s.nodes.map(h=>{const v=d.get(h.id)??{x:0,y:0};return{id:h.id,type:"default",position:{x:v.x,y:v.y},data:{label:`${h.pod?`${h.pod} / `:""}${h.label}`},style:{backgroundColor:PP(h.runtime),border:"1px solid #8a8577",fontSize:11,fontFamily:"monospace",width:DP,height:LP}}}),m=s.edges.map((h,v)=>({id:`e-${v}`,source:h.source,target:h.target,label:h.kind,labelStyle:{fontSize:9,fontFamily:"monospace"},style:{strokeDasharray:"4 4",stroke:"#8a8577"}}));return{nodes:f,edges:m}},[s]);return u.jsx("div",{"data-testid":t??"spec-topology-preview",className:"w-full h-[400px] bg-stone-50 border border-stone-200",children:u.jsxs(wE,{nodes:r,edges:i,fitView:!0,nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,proOptions:{hideAttribution:!0},children:[u.jsx(J8,{gap:20,size:.5,color:"#d4d0c8"}),u.jsx(EE,{showInteractive:!1})]})})}function LE({review:e,yaml:t,testIdPrefix:s="",yamlTestId:r,onMemberClick:i}){const[l,d]=j.useState("topology"),f=(e==null?void 0:e.pods)??[],m=(e==null?void 0:e.nodes)??[],h=(e==null?void 0:e.edges)??[],v=s?`${s}-`:"";return u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"flex gap-1 border-b border-stone-200",children:["topology","configuration","yaml"].map(g=>u.jsx("button",{"data-testid":`${v}tab-${g}`,onClick:()=>d(g),className:`px-3 py-1.5 font-mono text-[10px] uppercase tracking-wider transition-colors ${l===g?"border-b-2 border-stone-900 text-stone-900 font-bold":"text-stone-500 hover:text-stone-700"}`,children:g},g))}),l==="topology"&&e&&u.jsx(BP,{graph:e.graph,testId:`${v}topology-preview`}),l==="configuration"&&e&&u.jsxs("div",{"data-testid":`${v}config-tables`,className:"space-y-4",children:[e.format==="pod_aware"&&f.map(g=>u.jsxs("div",{className:"border border-stone-200 p-3",children:[u.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:g.label??g.id}),u.jsxs("table",{className:"w-full font-mono text-[10px]",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"border-b border-stone-200 text-stone-500",children:[u.jsx("th",{className:"text-left py-1",children:"Member"}),u.jsx("th",{className:"text-left py-1",children:"Agent Ref"}),u.jsx("th",{className:"text-left py-1",children:"Runtime"}),u.jsx("th",{className:"text-left py-1",children:"Profile"})]})}),u.jsx("tbody",{children:g.members.map(y=>u.jsxs("tr",{className:"border-b border-stone-100",children:[u.jsx("td",{className:"py-1",children:u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{children:y.id}),i&&u.jsx(Ne,{variant:"outline",size:"sm","data-testid":`${v}member-open-agent-${g.id}-${y.id}`,className:"h-6 px-2 font-mono text-[9px] uppercase tracking-[0.12em]",onClick:()=>i(g.id,y),children:"Agent Spec"})]})}),u.jsx("td",{className:"py-1 text-stone-600",children:y.agentRef}),u.jsx("td",{className:"py-1",children:y.runtime}),u.jsx("td",{className:"py-1 text-stone-500",children:y.profile??"—"})]},y.id))})]})]},g.id)),e.format==="legacy"&&m.length>0&&u.jsxs("div",{className:"border border-stone-200 p-3",children:[u.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:"Nodes"}),u.jsxs("table",{className:"w-full font-mono text-[10px]",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"border-b border-stone-200 text-stone-500",children:[u.jsx("th",{className:"text-left py-1",children:"ID"}),u.jsx("th",{className:"text-left py-1",children:"Runtime"}),u.jsx("th",{className:"text-left py-1",children:"Role"})]})}),u.jsx("tbody",{children:m.map(g=>u.jsxs("tr",{className:"border-b border-stone-100",children:[u.jsx("td",{className:"py-1",children:g.id}),u.jsx("td",{className:"py-1",children:g.runtime}),u.jsx("td",{className:"py-1 text-stone-500",children:g.role??"—"})]},g.id))})]})]}),h.length>0&&u.jsxs("div",{className:"border border-stone-200 p-3",children:[u.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:e.format==="pod_aware"?"Cross-Pod Edges":"Edges"}),u.jsxs("table",{className:"w-full font-mono text-[10px]",children:[u.jsx("thead",{children:u.jsxs("tr",{className:"border-b border-stone-200 text-stone-500",children:[u.jsx("th",{className:"text-left py-1",children:"From"}),u.jsx("th",{className:"text-left py-1",children:"To"}),u.jsx("th",{className:"text-left py-1",children:"Kind"})]})}),u.jsx("tbody",{children:h.map((g,y)=>u.jsxs("tr",{className:"border-b border-stone-100",children:[u.jsx("td",{className:"py-1",children:g.from}),u.jsx("td",{className:"py-1",children:g.to}),u.jsx("td",{className:"py-1 text-stone-500",children:g.kind})]},y))})]})]})]}),l==="yaml"&&u.jsx(kE,{title:"YAML Preview",testId:r??`${v}spec-yaml`,children:t})]})}function HP(){const e=Xt(),{selectedRigDraft:t,currentRigDraft:s}=Co(),r=t??s,{data:i,isLoading:l,error:d}=kP((r==null?void 0:r.yaml)??null),f=(i==null?void 0:i.pods)??[],m=(i==null?void 0:i.nodes)??[],h=(i==null?void 0:i.edges)??[];return r?u.jsx(rt,{children:u.jsxs("div",{"data-testid":"rig-spec-review",className:"space-y-6",children:[u.jsx(Yn,{eyebrow:"Rig Spec Review",title:(i==null?void 0:i.name)??r.label,description:(i==null?void 0:i.summary)??"Review the spec structure before import or bootstrap.",actions:u.jsxs(u.Fragment,{children:[u.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>e({to:"/import"}),children:"Open In Import"}),u.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>e({to:"/bootstrap"}),children:"Bootstrap"})]})}),i&&u.jsxs(_f,{children:[u.jsx(Ut,{label:"Format",value:i.format==="pod_aware"?"Pod-Aware":"Legacy",testId:"rig-spec-summary-format"}),u.jsx(Ut,{label:i.format==="pod_aware"?"Pods":"Nodes",value:i.format==="pod_aware"?f.length:m.length,testId:"rig-spec-summary-pods"}),u.jsx(Ut,{label:"Members",value:i.format==="pod_aware"?f.reduce((v,g)=>v+g.members.length,0):m.length,testId:"rig-spec-summary-members"}),u.jsx(Ut,{label:"Edges",value:h.length+(i.format==="pod_aware"?f.reduce((v,g)=>{var y;return v+(((y=g.edges)==null?void 0:y.length)??0)},0):0),testId:"rig-spec-summary-edges"})]}),l&&u.jsx("div",{className:"font-mono text-[10px] text-stone-400",children:"Loading review..."}),d&&u.jsx("div",{className:"p-3 bg-red-50 border border-red-200 font-mono text-[10px] text-red-700",children:d.message}),u.jsx(LE,{review:i,yaml:r.yaml,yamlTestId:"rig-spec-yaml"})]})}):u.jsx(rt,{children:u.jsxs("div",{"data-testid":"rig-spec-review-empty",className:"space-y-5",children:[u.jsx(Yn,{eyebrow:"Rig Spec Review",title:"No RigSpec Selected",description:"Choose a current or recent rig draft from the Specs drawer to review it here before you import or bootstrap it."}),u.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>e({to:"/import"}),children:"Open Import"})]})})}function v0({review:e,yaml:t,testIdPrefix:s="agent"}){const r=(e==null?void 0:e.profiles)??[],i=(e==null?void 0:e.resources)??{skills:[],guidance:[],hooks:[]},l=(e==null?void 0:e.startup)??{files:[],actions:[]};return u.jsxs(u.Fragment,{children:[r.length>0&&u.jsxs("div",{"data-testid":`${s}-profiles-section`,className:"border border-stone-200 p-3",children:[u.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:"Profiles"}),u.jsx("div",{className:"space-y-1",children:r.map(d=>u.jsxs("div",{className:"font-mono text-[10px] flex justify-between",children:[u.jsx("span",{className:"font-bold",children:d.name}),d.description&&u.jsx("span",{className:"text-stone-500",children:d.description})]},d.name))})]}),u.jsxs("div",{"data-testid":`${s}-resources-section`,className:"border border-stone-200 p-3",children:[u.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:"Resources"}),u.jsxs("div",{className:"space-y-2 font-mono text-[10px]",children:[i.skills.length>0&&u.jsxs("div",{children:[u.jsx("span",{className:"text-stone-500",children:"Skills:"})," ",i.skills.map((d,f)=>u.jsx("span",{className:"inline-block bg-stone-100 px-1.5 py-0.5 mr-1 mb-0.5",children:d},f))]}),i.guidance.length>0&&u.jsxs("div",{children:[u.jsx("span",{className:"text-stone-500",children:"Guidance:"})," ",i.guidance.map((d,f)=>u.jsx("span",{className:"inline-block bg-stone-100 px-1.5 py-0.5 mr-1 mb-0.5",children:d},f))]}),i.hooks.length>0&&u.jsxs("div",{children:[u.jsx("span",{className:"text-stone-500",children:"Hooks:"})," ",i.hooks.join(", ")]})]})]}),(l.files.length>0||l.actions.length>0)&&u.jsxs("div",{"data-testid":`${s}-startup-section`,className:"border border-stone-200 p-3",children:[u.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:"Startup"}),l.files.length>0&&u.jsxs("div",{className:"mb-2",children:[u.jsx("div",{className:"font-mono text-[9px] text-stone-500 uppercase mb-1",children:"Files"}),l.files.map((d,f)=>u.jsxs("div",{className:"font-mono text-[10px]",children:[d.path," ",d.required&&u.jsx("span",{className:"text-red-500 text-[8px]",children:"REQUIRED"})]},f))]}),l.actions.length>0&&u.jsxs("div",{children:[u.jsx("div",{className:"font-mono text-[9px] text-stone-500 uppercase mb-1",children:"Actions"}),l.actions.map((d,f)=>u.jsxs("div",{className:"font-mono text-[10px]",children:[u.jsxs("span",{className:"text-stone-500",children:[d.type,":"]})," ",d.value]},f))]})]}),u.jsx(kE,{title:"YAML Preview",testId:`${s}-spec-yaml`,children:t})]})}function UP(){const e=Xt(),{selectedAgentDraft:t,currentAgentDraft:s}=Co(),r=t??s,{data:i,isLoading:l,error:d}=OP((r==null?void 0:r.yaml)??null);return r?u.jsx(rt,{children:u.jsxs("div",{"data-testid":"agent-spec-review",className:"space-y-6",children:[u.jsx(Yn,{eyebrow:"Agent Spec Review",title:(i==null?void 0:i.name)??r.label,description:(i==null?void 0:i.description)??"Review the agent spec structure before validation.",actions:u.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>e({to:"/agents/validate"}),children:"Open In Validate"})}),i&&u.jsxs(_f,{children:[u.jsx(Ut,{label:"Format",value:"AgentSpec",testId:"agent-spec-summary-format"}),u.jsx(Ut,{label:"Version",value:i.version,testId:"agent-spec-summary-version"}),u.jsx(Ut,{label:"Profiles",value:(i.profiles??[]).length,testId:"agent-spec-summary-profiles"}),u.jsx(Ut,{label:"Skills",value:(i.resources??{skills:[]}).skills.length,testId:"agent-spec-summary-skills"})]}),l&&u.jsx("div",{className:"font-mono text-[10px] text-stone-400",children:"Loading review..."}),d&&u.jsx("div",{className:"p-3 bg-red-50 border border-red-200 font-mono text-[10px] text-red-700",children:d.message}),u.jsx(v0,{review:i,yaml:r.yaml,testIdPrefix:"agent"})]})}):u.jsx(rt,{children:u.jsxs("div",{"data-testid":"agent-spec-review-empty",className:"space-y-5",children:[u.jsx(Yn,{eyebrow:"Agent Spec Review",title:"No AgentSpec Selected",description:"Choose a current or recent agent draft from the Specs drawer to review it here before you validate it."}),u.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>e({to:"/agents/validate"}),children:"Open Validate"})]})})}function $P(){return Pt({mutationFn:async({bundlePath:e})=>{const t=await fetch("/api/bundles/inspect",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({bundlePath:e})}),s=await t.json();if(s.error)throw new Error(s.error);if(!t.ok)throw new Error(`HTTP ${t.status}`);return s}})}function qP(){return Pt({mutationFn:async({bundlePath:e,plan:t,autoApprove:s,targetRoot:r})=>{const i=await fetch("/api/bundles/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({bundlePath:e,plan:t,autoApprove:s,targetRoot:r})}),l=await i.json();if(!i.ok)throw new Error(l.error??`HTTP ${i.status}`);return l}})}function VP(){var l,d;const[e,t]=j.useState(""),s=$P(),r=()=>{e.trim()&&s.mutate({bundlePath:e.trim()})},i=s.data;return u.jsx(rt,{children:u.jsxs("div",{"data-testid":"bundle-inspector",children:[u.jsx("h2",{className:"text-headline-lg uppercase mb-spacing-4",children:"INSPECT BUNDLE"}),u.jsxs("div",{className:"mb-spacing-4",children:[u.jsx("label",{className:"text-label-md uppercase block mb-spacing-2",children:"BUNDLE PATH"}),u.jsx("input",{"data-testid":"bundle-path-input",type:"text",value:e,onChange:f=>t(f.target.value),placeholder:"/path/to/my-rig.rigbundle",className:"w-full bg-transparent border-b border-foreground/20 py-spacing-2 text-body-md font-mono focus:outline-none focus:border-primary"}),u.jsx(Ne,{variant:"tactical",onClick:r,disabled:!e.trim()||s.isPending,className:"mt-spacing-3","data-testid":"inspect-btn",children:s.isPending?"INSPECTING...":"INSPECT"})]}),s.isError&&u.jsx("div",{className:"text-destructive text-body-md mb-spacing-4","data-testid":"inspect-error",children:s.error.message}),i&&u.jsxs("div",{"data-testid":"inspect-result",children:[u.jsxs("div",{className:"card-dark p-spacing-4 mb-spacing-4","data-testid":"manifest-summary",children:[u.jsxs("div",{className:"flex items-center gap-spacing-2 mb-spacing-2",children:[u.jsx("h3",{className:"text-headline-md uppercase",children:i.manifest.name}),u.jsxs("span",{className:"text-label-sm font-mono px-spacing-2 py-px bg-foreground/10","data-testid":"schema-badge",children:["v",i.manifest.schemaVersion??1]})]}),u.jsxs("div",{className:"text-label-sm font-mono text-foreground-muted-on-dark",children:["v",i.manifest.version]}),u.jsxs("div",{className:"text-label-sm font-mono text-foreground-muted-on-dark",children:["Spec: ",i.manifest.rigSpec]}),u.jsxs("div",{className:"mt-spacing-2 flex gap-spacing-3",children:[u.jsxs("span",{className:Te("text-label-sm",i.digestValid?"text-success":"text-destructive"),children:["DIGEST: ",i.digestValid?"VALID":"INVALID"]}),u.jsxs("span",{className:Te("text-label-sm",i.integrityResult.passed?"text-success":"text-destructive"),"data-testid":"integrity-status",children:["INTEGRITY: ",i.integrityResult.passed?"PASS":"FAIL"]})]})]}),i.manifest.schemaVersion===2&&i.manifest.agents?u.jsxs(u.Fragment,{children:[u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"AGENTS"}),u.jsx("div",{className:"space-y-spacing-1 mb-spacing-4","data-testid":"agent-list",children:i.manifest.agents.map(f=>u.jsxs("div",{className:"text-label-sm font-mono","data-testid":"agent-entry",children:[f.name," v",f.version," — ",f.path]},f.name))})]}):u.jsxs(u.Fragment,{children:[u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"PACKAGES"}),u.jsx("div",{className:"space-y-spacing-1 mb-spacing-4","data-testid":"package-list",children:(i.manifest.packages??[]).map(f=>u.jsxs("div",{className:"text-label-sm font-mono","data-testid":"package-entry",children:[f.name," v",f.version," — ",f.path]},f.name))})]}),i.integrityResult&&u.jsxs(u.Fragment,{children:[u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"FILE INTEGRITY"}),u.jsxs("div",{className:"space-y-spacing-1 mb-spacing-4","data-testid":"file-integrity",children:[Object.keys((i.manifest.packages??i.manifest.agents??[]).length>0?((d=(l=i.manifest)==null?void 0:l.integrity)==null?void 0:d.files)??{}:{}).map(f=>{const m=i.integrityResult.mismatches.includes(f),h=i.integrityResult.missing.includes(f),v=m?"MISMATCH":h?"MISSING":"OK";return u.jsxs("div",{className:"flex items-center gap-spacing-3 text-label-sm font-mono","data-testid":"file-row",children:[u.jsx("span",{className:Te("w-2 h-2",v==="OK"?"bg-success":"bg-destructive"),"data-testid":"file-dot"}),u.jsx("span",{children:f}),u.jsx("span",{className:"text-foreground-muted ml-auto",children:v})]},f)}),i.integrityResult.extra.map(f=>u.jsxs("div",{className:"flex items-center gap-spacing-3 text-label-sm font-mono","data-testid":"file-row",children:[u.jsx("span",{className:"w-2 h-2 bg-warning","data-testid":"file-dot"}),u.jsx("span",{children:f}),u.jsx("span",{className:"text-foreground-muted ml-auto",children:"EXTRA"})]},f))]})]}),u.jsx(Ne,{variant:"tactical","data-testid":"install-btn",onClick:()=>window.location.href=`/bundles/install?bundlePath=${encodeURIComponent(e)}`,children:"INSTALL THIS BUNDLE"})]})]})})}function GP(){const e=Xt(),[t,s]=j.useState("enter"),r=typeof window<"u"?new URLSearchParams(window.location.search):null,[i,l]=j.useState((r==null?void 0:r.get("bundlePath"))??""),[d,f]=j.useState(""),[m,h]=j.useState(null),[v,g]=j.useState(null),y=qP(),b=async()=>{if(i.trim()){s("planning");try{const w=await y.mutateAsync({bundlePath:i.trim(),plan:!0});h(w),s("planned")}catch(w){g(w.message),s("error")}}},S=async()=>{if(d.trim()){s("applying");try{const w=await y.mutateAsync({bundlePath:i.trim(),autoApprove:!0,targetRoot:d.trim()});h(w),s("done")}catch(w){g(w.message),s("error")}}};return u.jsx(rt,{children:u.jsxs("div",{"data-testid":"bundle-install-flow",children:[u.jsx("h2",{className:"text-headline-lg uppercase mb-spacing-4",children:"INSTALL BUNDLE"}),t==="enter"&&u.jsxs("div",{"data-testid":"step-enter",children:[u.jsx("label",{className:"text-label-md uppercase block mb-spacing-2",children:"BUNDLE PATH"}),u.jsx("input",{"data-testid":"bundle-input",type:"text",value:i,onChange:w=>l(w.target.value),placeholder:"/path/to/my-rig.rigbundle",className:"w-full bg-transparent border-b border-foreground/20 py-spacing-2 text-body-md font-mono focus:outline-none focus:border-primary mb-spacing-4"}),u.jsx("label",{className:"text-label-md uppercase block mb-spacing-2",children:"TARGET ROOT"}),u.jsx("input",{"data-testid":"target-input",type:"text",value:d,onChange:w=>f(w.target.value),placeholder:"/path/to/target/project",className:"w-full bg-transparent border-b border-foreground/20 py-spacing-2 text-body-md font-mono focus:outline-none focus:border-primary mb-spacing-4"}),u.jsx(Ne,{variant:"tactical",onClick:b,disabled:!i.trim(),"data-testid":"plan-btn",children:"PLAN"})]}),t==="planning"&&u.jsx("div",{"data-testid":"step-planning",className:"text-foreground-muted",children:"Planning..."}),t==="planned"&&m&&u.jsxs("div",{"data-testid":"step-planned",children:[u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"PLAN"}),u.jsx("div",{className:"space-y-spacing-1 mb-spacing-4",children:m.stages.map(w=>u.jsxs("div",{className:"text-label-sm font-mono",children:[u.jsx("span",{className:w.status==="ok"?"text-success":"text-foreground-muted",children:w.status.toUpperCase()})," ",w.stage]},w.stage))}),u.jsx(Ne,{variant:"tactical",onClick:S,disabled:!d.trim(),"data-testid":"apply-btn",children:"APPLY"})]}),t==="applying"&&u.jsx("div",{"data-testid":"step-applying",className:"text-foreground-muted",children:"Installing..."}),t==="done"&&m&&u.jsxs("div",{"data-testid":"step-done",children:[u.jsx("h3",{className:"text-headline-md uppercase mb-spacing-3",children:"COMPLETE"}),u.jsxs("div",{className:"text-label-sm font-mono",children:["Status: ",u.jsx("span",{className:"text-success",children:m.status.toUpperCase()}),m.stages.some(w=>{var N;return((N=w.detail)==null?void 0:N.source)==="pod_bundle"})?u.jsx("span",{className:"ml-spacing-2 text-primary","data-testid":"bundle-type-label",children:"Pod-aware bundle"}):u.jsx("span",{className:"ml-spacing-2 text-foreground-muted","data-testid":"bundle-type-label",children:"Legacy bundle"})]}),m.rigId&&u.jsxs("div",{className:"text-label-sm font-mono","data-testid":"result-rig-id",children:["Rig: ",m.rigId]}),m.rigId&&u.jsx(Ne,{variant:"tactical",className:"mt-spacing-3",onClick:()=>e({to:"/rigs/$rigId",params:{rigId:m.rigId}}),children:"VIEW RIG"})]}),t==="error"&&u.jsxs("div",{"data-testid":"step-error",children:[u.jsx("p",{className:"text-destructive text-body-md mb-spacing-4",children:v}),u.jsx(Ne,{variant:"tactical",onClick:()=>{s("enter"),g(null),y.reset()},"data-testid":"try-again-btn",children:"TRY AGAIN"})]})]})})}function zE({sourcePath:e,sourceState:t}){return u.jsxs("div",{className:"font-mono text-[9px] text-stone-500","data-testid":"library-provenance",children:["Source: ",e," · ",t]})}function YP({review:e}){const t=Xt(),s=e.profiles??[],r=e.resources??{skills:[]};return u.jsx(rt,{children:u.jsxs("div",{"data-testid":"library-review-agent",className:"space-y-6",children:[u.jsx(Yn,{eyebrow:"Library — Agent Spec",title:e.name,description:e.description??"Agent spec from library.",actions:u.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>t({to:"/agents/validate"}),children:"Validate"})}),u.jsx(zE,{sourcePath:e.sourcePath,sourceState:e.sourceState}),u.jsxs(_f,{children:[u.jsx(Ut,{label:"Format",value:"AgentSpec",testId:"lib-agent-format"}),u.jsx(Ut,{label:"Version",value:e.version,testId:"lib-agent-version"}),u.jsx(Ut,{label:"Profiles",value:s.length,testId:"lib-agent-profiles"}),u.jsx(Ut,{label:"Skills",value:r.skills.length,testId:"lib-agent-skills"})]}),u.jsx(v0,{review:e,yaml:e.raw,testIdPrefix:"lib-agent"})]})})}function QP({review:e}){const t=Xt(),{data:s=[]}=Yd("agent"),r=new Map(s.map(m=>[m.name,m])),i=e.pods??[],l=e.nodes??[],d=e.edges??[],f=m=>{const h=m.match(/^local:agents\/([^/]+)$/);return h!=null&&h[1]?r.get(h[1])??null:null};return u.jsx(rt,{children:u.jsxs("div",{"data-testid":"library-review-rig",className:"space-y-6",children:[u.jsx(Yn,{eyebrow:"Library — Rig Spec",title:e.name,description:e.summary??"Rig spec from library.",actions:u.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>t({to:"/import"}),children:"Import"})}),u.jsx(zE,{sourcePath:e.sourcePath,sourceState:e.sourceState}),u.jsxs(_f,{children:[u.jsx(Ut,{label:"Format",value:e.format==="pod_aware"?"Pod-Aware":"Legacy",testId:"lib-rig-format"}),u.jsx(Ut,{label:e.format==="pod_aware"?"Pods":"Nodes",value:e.format==="pod_aware"?i.length:l.length,testId:"lib-rig-pods"}),u.jsx(Ut,{label:"Members",value:e.format==="pod_aware"?i.reduce((m,h)=>m+h.members.length,0):l.length,testId:"lib-rig-members"}),u.jsx(Ut,{label:"Edges",value:d.length+(e.format==="pod_aware"?i.reduce((m,h)=>{var v;return m+(((v=h.edges)==null?void 0:v.length)??0)},0):0),testId:"lib-rig-edges"})]}),u.jsx(LE,{review:e,yaml:e.raw,testIdPrefix:"lib",yamlTestId:"lib-rig-yaml",onMemberClick:(m,h)=>{const v=f(h.agentRef);v&&t({to:"/specs/library/$entryId",params:{entryId:v.id}})}})]})})}function KP({entryId:e}){const t=Xt(),{data:s,isLoading:r,error:i}=Yg(e);return r?u.jsx(rt,{children:u.jsx("div",{className:"font-mono text-[10px] text-stone-400",children:"Loading spec review..."})}):i||!s?u.jsx(rt,{children:u.jsxs("div",{"data-testid":"library-review-error",className:"space-y-4",children:[u.jsx(Yn,{eyebrow:"Library",title:"Spec Not Found",description:(i==null?void 0:i.message)??"Could not load spec."}),u.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>t({to:"/specs"}),children:"Back to Specs"})]})}):s.kind==="agent"?u.jsx(YP,{review:s}):u.jsx(QP,{review:s})}function FP(e){if(!e)return null;const t=e.match(/^local:agents\/([^/]+)$/);return(t==null?void 0:t[1])??null}function XP({agentRef:e}){const t=FP(e),{data:s=[],isLoading:r}=Yd("agent"),i=t?s.filter(m=>m.name===t):[],l=i.length===1?i[0].id:null,{data:d,isLoading:f}=Yg(l);return t?r||f?u.jsx("div",{className:"p-4 font-mono text-[10px] text-stone-400",children:"Loading agent spec..."}):i.length===0?u.jsx("div",{"data-testid":"agent-spec-unavailable",className:"p-4 font-mono text-[10px] text-stone-400",children:"No agent spec available"}):i.length>1?u.jsxs("div",{"data-testid":"agent-spec-ambiguous",className:"p-4 font-mono text-[10px] text-amber-600",children:["Agent spec ambiguous (",i.length,' matches for "',t,'")']}):!d||d.kind!=="agent"?u.jsx("div",{"data-testid":"agent-spec-unavailable",className:"p-4 font-mono text-[10px] text-stone-400",children:"No agent spec available"}):u.jsx(v0,{review:d,yaml:d.raw,testIdPrefix:"live-agent"}):u.jsx("div",{"data-testid":"agent-spec-unavailable",className:"p-4 font-mono text-[10px] text-stone-400",children:"No agent spec available"})}function ZP({rigId:e,logicalId:t}){const{data:s,isLoading:r,error:i}=DN(e,t),[l,d]=j.useState("identity"),f=s?s.nodeKind!=="infrastructure":!0,m=f?["identity","agent-spec","startup","transcript"]:["identity","startup","transcript"];return u.jsx(rt,{children:u.jsxs("div",{"data-testid":"live-node-details",className:"space-y-6",children:[u.jsx(Yn,{eyebrow:"Live Node Details",title:(s==null?void 0:s.canonicalSessionName)??t,description:`${(s==null?void 0:s.rigName)??e} / ${(s==null?void 0:s.podNamespace)??cs(t)??us((s==null?void 0:s.podId)??null)} / ${t}`}),r&&u.jsx("div",{className:"font-mono text-[10px] text-stone-400",children:"Loading..."}),i&&u.jsx("div",{className:"p-3 bg-red-50 border border-red-200 font-mono text-[10px] text-red-700",children:i.message}),u.jsx("div",{className:"flex gap-1 border-b border-stone-200",children:m.map(h=>u.jsx("button",{"data-testid":`live-tab-${h}`,onClick:()=>d(h),className:`px-3 py-1.5 font-mono text-[10px] uppercase tracking-wider transition-colors ${l===h?"border-b-2 border-stone-900 text-stone-900 font-bold":"text-stone-500 hover:text-stone-700"}`,children:h.replace("-"," ")},h))}),s&&l==="identity"&&u.jsx(LN,{peers:s.peers,edges:s.edges,transcript:s.transcript,compactSpec:s.compactSpec,contextUsage:s.contextUsage}),s&&l==="agent-spec"&&f&&u.jsx(XP,{agentRef:s.agentRef}),s&&l==="startup"&&u.jsx("div",{"data-testid":"live-startup-section",className:"space-y-4",children:s.startupFiles.length>0&&u.jsxs("div",{className:"border border-stone-200 p-3",children:[u.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:"Startup Files"}),s.startupFiles.map((h,v)=>u.jsxs("div",{className:"font-mono text-[10px]",children:[h.path," ",u.jsxs("span",{className:"text-stone-400",children:["(",h.deliveryHint,")"]}),h.required&&u.jsx("span",{className:"text-red-500 text-[8px] ml-1",children:"REQUIRED"})]},v))]})}),s&&l==="transcript"&&u.jsx("div",{"data-testid":"live-transcript-section",className:"space-y-4",children:s.transcript.enabled?u.jsxs("div",{className:"border border-stone-200 p-3",children:[u.jsx("div",{className:"font-mono text-xs font-bold mb-2",children:"Transcript"}),u.jsx("div",{className:"font-mono text-[10px] text-stone-700",children:s.transcript.path}),s.transcript.tailCommand&&u.jsx("code",{className:"block mt-1 font-mono text-[9px] text-stone-500 bg-stone-100 px-2 py-1",children:s.transcript.tailCommand})]}):u.jsx("div",{className:"font-mono text-[10px] text-stone-400 p-4",children:"Transcript capture not enabled"})})]})})}function WP(e){switch(e){case"claude-code":return"text-primary";case"codex":return"text-accent";case"terminal":return"text-foreground";default:return"text-foreground-muted"}}function JP(e){switch(e){case"claude-code":return"Claude Code";case"codex":return"Codex";case"terminal":return"Terminal";default:return"Unknown"}}function eI(e){return`'${e.replace(/'/g,"'\\''")}'`}function tI(e){const t=e.tmuxWindow?`${e.tmuxSession}:${e.tmuxWindow}`:e.tmuxSession;return`tmux attach -t ${eI(t)}`}function DS({label:e,activeLabel:t,onClick:s,testId:r}){const[i,l]=j.useState(!1),d=j.useRef(null);j.useEffect(()=>()=>{d.current&&clearTimeout(d.current)},[]);const f=async()=>{await s()&&(l(!0),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{l(!1),d.current=null},900))};return u.jsx("button",{type:"button","data-testid":r,onClick:()=>{f()},className:Te("px-spacing-2 py-1 border font-mono text-[10px] uppercase transition-colors duration-150 ease-tactical",i?"bg-stone-900 text-white border-stone-900":"bg-white text-stone-900 border-stone-300 hover:bg-stone-100"),children:i?t:e})}function nI({session:e,onAdopt:t}){return u.jsx("div",{"data-testid":"discovered-node",className:Te("border-dashed border border-foreground/20 bg-[rgba(255,255,255,0.72)] px-spacing-4 py-spacing-3 mb-spacing-2 shadow-[0_10px_28px_rgba(20,20,20,0.04)] backdrop-blur-sm"),children:u.jsxs("div",{className:"flex flex-col gap-spacing-3 lg:flex-row lg:items-center lg:justify-between",children:[u.jsxs("div",{className:"min-w-0 flex-1",children:[u.jsxs("div",{className:"flex flex-wrap items-center gap-x-spacing-3 gap-y-spacing-1",children:[u.jsx("div",{"data-testid":"runtime-badge",className:Te("text-[10px] uppercase tracking-[0.08em]",WP(e.runtimeHint)),children:JP(e.runtimeHint)}),u.jsx("div",{"data-testid":"session-name",className:"font-mono text-[13px] leading-5 text-foreground",title:e.tmuxSession,children:e.tmuxSession}),e.confidence==="medium"?u.jsx("div",{"data-testid":"runtime-inferred-note",className:"text-[10px] uppercase tracking-[0.08em] text-foreground-muted",children:"runtime inferred"}):null]}),e.cwd?u.jsxs("div",{className:"mt-spacing-2 min-w-0",children:[u.jsx("div",{className:"text-[10px] uppercase tracking-[0.08em] text-foreground-muted",children:"cwd"}),u.jsx("div",{className:"font-mono text-[12px] leading-5 text-foreground-muted truncate",title:e.cwd,children:e.cwd})]}):null]}),u.jsxs("div",{className:"flex flex-wrap items-center gap-spacing-2 lg:justify-end",children:[u.jsx(DS,{label:"copy tmux",activeLabel:"copied",testId:"copy-tmux-btn",onClick:async()=>await ds(tI(e))}),e.cwd?u.jsx(DS,{label:"copy cwd",activeLabel:"copied",testId:"copy-cwd-btn",onClick:async()=>await ds(e.cwd??"")}):null,u.jsx(Ne,{variant:"tactical",size:"sm","data-testid":"adopt-btn",onClick:()=>t(e.id),children:"ADOPT"})]})]})})}function sI(){const[e,t]=j.useState(null),[s,r]=j.useState(!1),i=j.useCallback(async()=>{r(!0);try{const l=await fetch("/api/discovery/draft-rig",{method:"POST"});if(!l.ok){t(`# Error: draft generation failed (HTTP ${l.status})`);return}const d=await l.text();t(d)}catch{t("# Error: failed to reach daemon")}finally{r(!1)}},[]);return u.jsxs("div",{className:"mt-spacing-4 border-t border-foreground/10 pt-spacing-4","data-testid":"generate-draft-section",children:[u.jsx(Ne,{variant:"tactical",onClick:i,disabled:s,"data-testid":"generate-draft-btn",className:"mb-spacing-3",children:s?"GENERATING...":"GENERATE RIG SPEC"}),e&&(()=>{const l=e.split(`
|
|
223
223
|
`),d=l.filter(m=>m.startsWith("# WARNING:")).map(m=>m.replace(/^# WARNING:\s*/,"")),f=l.filter(m=>!m.startsWith("# WARNING:")).join(`
|
|
224
224
|
`).trim();return u.jsxs("div",{className:"relative",children:[d.length>0&&u.jsx("div",{className:"mb-spacing-2 p-spacing-2 bg-warning/10 border border-warning/30 text-label-sm","data-testid":"draft-warnings",children:d.map((m,h)=>u.jsx("div",{className:"text-warning font-mono",children:m},h))}),u.jsx("pre",{className:"bg-surface-low p-spacing-3 text-label-sm font-mono overflow-x-auto max-h-64 border border-foreground/10","data-testid":"draft-yaml",children:f}),u.jsx("button",{onClick:()=>{var m;return(m=navigator.clipboard)==null?void 0:m.writeText(e)},className:"absolute top-2 right-2 text-label-sm text-foreground-muted hover:text-foreground","data-testid":"copy-draft-btn",children:"COPY"})]})})()]})}function aI(){var T,_;const{data:e=[]}=Gg({status:"active",runtimeHint:["claude-code","codex"],minConfidence:"medium"}),t=zN(),{data:s=[]}=xc(),r=W3(),i=e,[l,d]=j.useState(null),[f,m]=j.useState(!1),[h,v]=j.useState(""),[g,y]=j.useState(""),b=R=>{d(R),m(!0),v(""),y(""),r.reset()},S=()=>{m(!1),d(null)},w=()=>{!l||!h||!g.trim()||r.mutate({discoveredId:l,rigId:h,logicalId:g.trim()},{onSuccess:S})},N=((T=r.error)==null?void 0:T.message)??null,C=r.isPending;return u.jsx(rt,{children:u.jsxs("div",{"data-testid":"discovery-overlay",children:[u.jsxs("div",{children:[u.jsxs("div",{className:"flex flex-col gap-spacing-4 border-b border-foreground/10 pb-spacing-5 sm:flex-row sm:items-end sm:justify-between",children:[u.jsxs("div",{className:"max-w-[620px]",children:[u.jsx("h2",{className:"text-headline-lg uppercase",children:"DISCOVERY"}),u.jsx("p",{className:"mt-spacing-1 text-body-md text-foreground-muted",children:"Running agent sessions currently visible on this machine. Copy a tmux attach command, review the working directory, or adopt the session into a rig."})]}),u.jsx(Ne,{variant:"ghost",size:"sm","data-testid":"scan-now-btn",disabled:t.isPending,onClick:()=>t.mutate(),children:t.isPending?"SCANNING...":"SCAN NOW"})]}),t.isError?u.jsxs("div",{className:"mt-spacing-4 text-label-sm text-destructive","data-testid":"scan-error",children:["Discovery scan failed: ",(_=t.error)==null?void 0:_.message]}):null,i.length===0?u.jsx("div",{className:"py-spacing-8","data-testid":"discovery-empty",children:u.jsx("p",{className:"text-body-md text-foreground-muted",children:"No running Claude or Codex sessions are currently visible."})}):u.jsxs("div",{className:"mt-spacing-6 space-y-spacing-3","data-testid":"discovery-active-section",children:[u.jsxs("div",{className:"mb-spacing-2",children:[u.jsx("h3",{className:"text-headline-sm uppercase",children:"Running agents"}),u.jsxs("p",{className:"text-label-md text-foreground-muted",children:[i.length," session",i.length!==1?"s":""," available to inspect or adopt"]})]}),i.map(R=>u.jsx(nI,{session:R,onAdopt:b},R.id))]}),u.jsx(sI,{})]}),u.jsx(Gd,{open:f,onOpenChange:m,children:u.jsxs(Kl,{"data-testid":"adopt-dialog",children:[u.jsxs(Fl,{children:[u.jsx(Zl,{className:"text-headline-md uppercase",children:"ADOPT SESSION"}),u.jsx(Wl,{children:"Bind this session to an existing logical node in the rig."})]}),u.jsxs("div",{className:"space-y-spacing-3",children:[u.jsxs("div",{children:[u.jsx("label",{className:"text-label-sm uppercase block mb-spacing-1",children:"RIG"}),u.jsxs("select",{"data-testid":"adopt-rig-input",value:h,onChange:R=>v(R.target.value),className:"w-full bg-white border-b border-outline py-spacing-1 text-body-md font-mono focus:outline-none focus:border-stone-900 appearance-none cursor-pointer",children:[u.jsx("option",{value:"",children:"Select a rig..."}),s.map(R=>u.jsxs("option",{value:R.id,children:[R.name," (",R.nodeCount," nodes)"]},R.id))]})]}),u.jsxs("div",{children:[u.jsx("label",{className:"text-label-sm uppercase block mb-spacing-1",children:"LOGICAL ID (required)"}),u.jsx("input",{"data-testid":"adopt-logical-input",type:"text",value:g,onChange:R=>y(R.target.value),className:"w-full bg-transparent border-b border-foreground/20 py-spacing-1 text-body-md font-mono focus:outline-none focus:border-primary"}),u.jsx("p",{className:"mt-spacing-1 text-label-sm text-foreground-muted",children:"Enter the logical ID of an existing node in the target rig. For pod placement, use the Discovery drawer instead."})]})]}),N&&u.jsx("p",{className:"text-destructive text-label-sm","data-testid":"adopt-error",children:N}),u.jsxs(Xl,{children:[u.jsx(Ne,{variant:"ghost",onClick:()=>m(!1),children:"CANCEL"}),u.jsx(Ne,{variant:"tactical",onClick:w,disabled:!h||!g.trim()||C,"data-testid":"adopt-confirm",children:C?"ADOPTING...":"ADOPT"})]})]})})]})})}const Mt=GR({component:()=>u.jsx(AT,{client:$T,children:u.jsx(w4,{children:u.jsx(pw,{})})})}),rI=At({getParentRoute:()=>Mt,path:"/",component:h0});function iI(){var r;const{rigId:e}=PE.useParams(),{data:t}=xc(),s=(r=t==null?void 0:t.find(i=>i.id===e))==null?void 0:r.name;return u.jsx("div",{className:"flex flex-col flex-1 h-full",children:u.jsx("div",{className:"flex-1 min-h-[400px] relative",children:u.jsx(Y6,{rigId:e,rigName:s??null,showDiscovered:!1})})})}const PE=At({getParentRoute:()=>Mt,path:"/rigs/$rigId",component:iI}),oI=At({getParentRoute:()=>Mt,path:"/import",component:W6}),lI=At({getParentRoute:()=>Mt,path:"/packages",component:aP}),cI=At({getParentRoute:()=>Mt,path:"/packages/install",component:uP}),uI=At({getParentRoute:()=>Mt,path:"/bootstrap",component:RP}),dI=At({getParentRoute:()=>Mt,path:"/agents/validate",component:TP});function fI(){const{setSelection:e}=tr();return j.useEffect(()=>{e({type:"discovery"})},[e]),u.jsx(h0,{})}function hI(){const{setSelection:e}=tr();return j.useEffect(()=>{e({type:"specs"})},[e]),u.jsx(h0,{})}function mI(){const{setSelection:e}=tr();return j.useEffect(()=>{e({type:"specs"})},[e]),u.jsx(HP,{})}function pI(){const{setSelection:e}=tr();return j.useEffect(()=>{e({type:"specs"})},[e]),u.jsx(UP,{})}const gI=At({getParentRoute:()=>Mt,path:"/discovery",component:fI}),xI=At({getParentRoute:()=>Mt,path:"/specs",component:hI}),yI=At({getParentRoute:()=>Mt,path:"/specs/rig",component:mI}),vI=At({getParentRoute:()=>Mt,path:"/specs/agent",component:pI});function bI(){const{entryId:e}=IE.useParams(),{setSelection:t}=tr();return j.useEffect(()=>{t({type:"specs"})},[t]),u.jsx(KP,{entryId:e})}const IE=At({getParentRoute:()=>Mt,path:"/specs/library/$entryId",component:bI}),SI=At({getParentRoute:()=>Mt,path:"/discovery/inventory",component:aI}),wI=At({getParentRoute:()=>Mt,path:"/bundles/inspect",component:VP}),NI=At({getParentRoute:()=>Mt,path:"/bundles/install",component:GP}),jI=At({getParentRoute:()=>Mt,path:"/packages/$packageId",component:vP}),BE=At({getParentRoute:()=>Mt,path:"/rigs/$rigId/nodes/$logicalId",component:()=>{const{rigId:e,logicalId:t}=BE.useParams();return u.jsx(ZP,{rigId:e,logicalId:decodeURIComponent(t)})}}),EI=Mt.addChildren([rI,PE,oI,lI,cI,jI,uI,dI,xI,yI,vI,IE,gI,SI,wI,NI,BE]),CI=tT({routeTree:EI});function _I(){return u.jsx(aT,{router:CI})}const LS=document.getElementById("root");LS&&n_.createRoot(LS).render(u.jsx(j.StrictMode,{children:u.jsx(_I,{})}));
|